Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for a large number of params, avoid copying array. #86

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
* combined with the thing that can find derivatives.
*
* Can be used with a LeastSquaresProblem, a LeastSquaresFactory, or a LeastSquaresBuilder.
*
* This version that works with MultivariateVectorFunction
* @see DifferentiatorMultivariateJacobianFunction for version that works with MultivariateFunction
*/
public class DifferentiatorVectorMultivariateJacobianFunction implements MultivariateJacobianFunction {
/**
Expand All @@ -50,9 +47,6 @@ public class DifferentiatorVectorMultivariateJacobianFunction implements Multiva
*
* @param function the function to turn into a jacobian
* @param differentiator the differentiator to find the derivative
*
* This version that works with MultivariateFunction
* @see DifferentiatorVectorMultivariateJacobianFunction for version that works with MultivariateVectorFunction
*/
public DifferentiatorVectorMultivariateJacobianFunction(MultivariateVectorFunction function, UnivariateVectorFunctionDifferentiator differentiator) {
this.function = function;
Expand All @@ -64,23 +58,22 @@ public DifferentiatorVectorMultivariateJacobianFunction(MultivariateVectorFuncti
*/
@Override
public Pair<RealVector, RealMatrix> value(RealVector point) {
RealVector value = new ArrayRealVector(function.value(point.toArray()));
double[] testArray = point.toArray();
RealVector value = new ArrayRealVector(function.value(testArray));
RealMatrix jacobian = new Array2DRowRealMatrix(value.getDimension(), point.getDimension());

for(int column = 0; column < point.getDimension(); column++) {
final int columnFinal = column;
double originalPoint = point.getEntry(column);
double[] partialDerivatives = getPartialDerivative(testPoint -> {

point.setEntry(columnFinal, testPoint);

double[] testPointValue = function.value(point.toArray());
testArray[columnFinal] = testPoint;

point.setEntry(columnFinal, originalPoint); //set it back

return testPointValue;
return function.value(testArray);
}, originalPoint);

testArray[column] = originalPoint; //set it back

jacobian.setColumn(column, partialDerivatives);
}

Expand Down