You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/03/28 21:06:55 UTC
svn commit: r642357 - in /commons/proper/math/trunk/src:
java/org/apache/commons/math/estimation/AbstractEstimator.java
site/xdoc/changes.xml
test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
Author: luc
Date: Fri Mar 28 13:06:54 2008
New Revision: 642357
URL: http://svn.apache.org/viewvc?rev=642357&view=rev
Log:
fixed crashes in AbstractEstimator when some parameters are bound.
getCovariances() and guessParametersErrors() now only give result
about unbound parameters
JIRA: MATH-200
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java?rev=642357&r1=642356&r2=642357&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java Fri Mar 28 13:06:54 2008
@@ -149,7 +149,7 @@
}
/**
- * Get the covariance matrix of estimated parameters.
+ * Get the covariance matrix of unbound estimated parameters.
* @param problem estimation problem
* @return covariance matrix
* @exception EstimationException if the covariance matrix
@@ -163,7 +163,7 @@
// compute transpose(J).J, avoiding building big intermediate matrices
final int rows = problem.getMeasurements().length;
- final int cols = problem.getAllParameters().length;
+ final int cols = problem.getUnboundParameters().length;
final int max = cols * rows;
double[][] jTj = new double[cols][cols];
for (int i = 0; i < cols; ++i) {
@@ -188,7 +188,7 @@
}
/**
- * Guess the errors in estimated parameters.
+ * Guess the errors in unbound estimated parameters.
* <p>Guessing is covariance-based, it only gives rough order of magnitude.</p>
* @param problem estimation problem
* @return errors in estimated parameters
@@ -199,12 +199,12 @@
public double[] guessParametersErrors(EstimationProblem problem)
throws EstimationException {
int m = problem.getMeasurements().length;
- int p = problem.getAllParameters().length;
+ int p = problem.getUnboundParameters().length;
if (m <= p) {
throw new EstimationException("no degrees of freedom ({0} measurements, {1} parameters)",
new Object[] { new Integer(m), new Integer(p)});
}
- double[] errors = new double[problem.getAllParameters().length];
+ double[] errors = new double[problem.getUnboundParameters().length];
final double c = Math.sqrt(getChiSquare(problem) / (m - p));
double[][] covar = getCovariances(problem);
for (int i = 0; i < errors.length; ++i) {
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=642357&r1=642356&r2=642357&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Mar 28 13:06:54 2008
@@ -51,6 +51,11 @@
detect numerical problems in Q.R decomposition for Levenberg-Marquardt estimator
and report them appropriately
</action>
+ <action dev="luc" type="fix" issue="MATH-200" due-to="Plamen Petrov">
+ fixed several crashes in getCovariances() and guessParametersErrors() in
+ AbstractEstimator when some parameters are bound. The methods now explicitly
+ give result only about unbound parameters.
+ </action>
</release>
<release version="1.2" date="2008-02-24"
description="This release combines bug fixes and new features. Most notable
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java?rev=642357&r1=642356&r2=642357&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java Fri Mar 28 13:06:54 2008
@@ -448,6 +448,44 @@
}
+ public void testBoundParameters() throws EstimationException {
+ EstimatedParameter[] p = {
+ new EstimatedParameter("unbound0", 2, false),
+ new EstimatedParameter("unbound1", 2, false),
+ new EstimatedParameter("bound", 2, true)
+ };
+ LinearProblem problem = new LinearProblem(new LinearMeasurement[] {
+ new LinearMeasurement(new double[] { 1.0, 1.0, 1.0 },
+ new EstimatedParameter[] { p[0], p[1], p[2] },
+ 3.0),
+ new LinearMeasurement(new double[] { 1.0, -1.0, 1.0 },
+ new EstimatedParameter[] { p[0], p[1], p[2] },
+ 1.0),
+ new LinearMeasurement(new double[] { 1.0, 3.0, 2.0 },
+ new EstimatedParameter[] { p[0], p[1], p[2] },
+ 7.0)
+ });
+
+ GaussNewtonEstimator estimator = new GaussNewtonEstimator(100, 1.0e-6, 1.0e-6);
+ estimator.estimate(problem);
+ assertTrue(estimator.getRMS(problem) < 1.0e-10);
+ double[][] covariances = estimator.getCovariances(problem);
+ int i0 = 0, i1 = 1;
+ if (problem.getUnboundParameters()[0].getName().endsWith("1")) {
+ i0 = 1;
+ i1 = 0;
+ }
+ assertEquals(11.0 / 24, covariances[i0][i0], 1.0e-10);
+ assertEquals(-3.0 / 24, covariances[i0][i1], 1.0e-10);
+ assertEquals(-3.0 / 24, covariances[i1][i0], 1.0e-10);
+ assertEquals( 3.0 / 24, covariances[i1][i1], 1.0e-10);
+
+ double[] errors = estimator.guessParametersErrors(problem);
+ assertEquals(0, errors[i0], 1.0e-10);
+ assertEquals(0, errors[i1], 1.0e-10);
+
+ }
+
public void testMaxIterations() {
Circle circle = new Circle(98.680, 47.345);
circle.addPoint( 30.0, 68.0);