Author: luc
Date: Mon Feb 24 14:57:44 2014
New Revision: 1571306
URL: http://svn.apache.org/r1571306
Log:
In LeastSquaresProblem.Evaluation removed the getValue() method.
- The residuals are the really the values of the objective function
that is being minimized.
- Forcing the value to be a real vector and the residual computed
through subtraction is an unnecessary constraint. For example
Rotation.distance() will compute a better residual than
subtracting the quaternion elements of two rotations.
- Method was not used by any optimizer.
JIRA: MATH-1102
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/DenseWeightedEvaluation.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresProblem.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/OptimumImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/EvaluationTest.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/DenseWeightedEvaluation.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/DenseWeightedEvaluation.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/DenseWeightedEvaluation.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/DenseWeightedEvaluation.java
Mon Feb 24 14:57:44 2014
@@ -59,11 +59,6 @@ class DenseWeightedEvaluation extends Ab
return this.weightSqrt.operate(this.unweighted.getResiduals());
}
- /** {@inheritDoc} */
- public RealVector getValue() {
- return this.weightSqrt.operate(unweighted.getValue());
- }
-
/* delegate */
/** {@inheritDoc} */
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java
Mon Feb 24 14:57:44 2014
@@ -216,11 +216,11 @@ public class LeastSquaresFactory {
iteration,
new PointVectorValuePair(
previous.getPoint().toArray(),
- previous.getValue().toArray(),
+ previous.getResiduals().toArray(),
false),
new PointVectorValuePair(
current.getPoint().toArray(),
- current.getValue().toArray(),
+ current.getResiduals().toArray(),
false)
);
}
@@ -344,12 +344,10 @@ public class LeastSquaresFactory {
/** the point of evaluation */
private final RealVector point;
- /** value at point */
- private final RealVector values;
/** deriviative at point */
private final RealMatrix jacobian;
- /** reference to the observed values */
- private final RealVector target;
+ /** the computed residuals. */
+ private final RealVector residuals;
/**
* Create an {@link Evaluation} with no weights.
@@ -364,15 +362,9 @@ public class LeastSquaresFactory {
final RealVector target,
final RealVector point) {
super(target.getDimension());
- this.values = values;
this.jacobian = jacobian;
- this.target = target;
this.point = point;
- }
-
- /** {@inheritDoc} */
- public RealVector getValue() {
- return this.values;
+ this.residuals = target.subtract(values);
}
/** {@inheritDoc} */
@@ -387,7 +379,7 @@ public class LeastSquaresFactory {
/** {@inheritDoc} */
public RealVector getResiduals() {
- return target.subtract(this.getValue());
+ return this.residuals;
}
}
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresProblem.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresProblem.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresProblem.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresProblem.java
Mon Feb 24 14:57:44 2014
@@ -119,13 +119,6 @@ public interface LeastSquaresProblem ext
double getRMS();
/**
- * Get the weighted objective (model) function value.
- *
- * @return the weighted objective function value at the specified
point.
- */
- RealVector getValue();
-
- /**
* Get the weighted Jacobian matrix.
*
* @return the weighted Jacobian: W<sup>1/2</sup> J.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/OptimumImpl.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/OptimumImpl.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/OptimumImpl.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/OptimumImpl.java
Mon Feb 24 14:57:44 2014
@@ -77,11 +77,6 @@ class OptimumImpl implements Optimum {
}
/** {@inheritDoc} */
- public RealVector getValue() {
- return value.getValue();
- }
-
- /** {@inheritDoc} */
public RealMatrix getJacobian() {
return value.getJacobian();
}
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java
Mon Feb 24 14:57:44 2014
@@ -156,7 +156,7 @@ public abstract class AbstractLeastSquar
Assert.assertEquals(0, optimum.getRMS(), TOl);
assertEquals(TOl, optimum.getPoint(), 1.5);
- Assert.assertEquals(3.0, optimum.getValue().getEntry(0), TOl);
+ Assert.assertEquals(0.0, optimum.getResiduals().getEntry(0), TOl);
}
@Test
@@ -169,7 +169,7 @@ public abstract class AbstractLeastSquar
Assert.assertEquals(0, optimum.getRMS(), TOl);
assertEquals(TOl, optimum.getPoint(), 7, 3);
- assertEquals(TOl, optimum.getValue(), 4, 6, 1);
+ assertEquals(TOl, optimum.getResiduals(), 0, 0, 0);
}
@Test
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/EvaluationTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/EvaluationTest.java?rev=1571306&r1=1571305&r2=1571306&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/EvaluationTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fitting/leastsquares/EvaluationTest.java
Mon Feb 24 14:57:44 2014
@@ -141,12 +141,12 @@ public class EvaluationTest {
.evaluate(point);
//action
- RealVector value = evaluation.getValue();
+ RealVector residuals = evaluation.getResiduals();
RealMatrix jacobian = evaluation.getJacobian();
//verify
Assert.assertArrayEquals(evaluation.getPoint().toArray(),
point.toArray(), 0);
- Assert.assertArrayEquals(new double[]{12, 8}, value.toArray(),
Precision.EPSILON);
+ Assert.assertArrayEquals(new double[]{-12, -8}, residuals.toArray(),
Precision.EPSILON);
TestUtils.assertEquals(
"jacobian",
jacobian,