MATH-377 fixed

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@982507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dimitri Pourbaix 2010-08-05 08:48:00 +00:00
parent b3777d116e
commit c640932de2
5 changed files with 13 additions and 14 deletions

View File

@ -561,7 +561,7 @@ public class EigenDecompositionImpl implements EigenDecomposition {
z[ia][i] = c * z[ia][i] - s * p;
}
}
if (e[i + 1] == 0.0 && i >= j)
if (t == 0.0 && i >= j)
continue;
realEigenvalues[j] -= u;
e[j] = q;

View File

@ -108,7 +108,7 @@ public class SingularValueDecompositionImpl implements
for (int k = 0; k < n; k++) {
matAAT[i][j] += localcopy[i][k] * localcopy[j][k];
}
matAAT[j][i]=matAAT[i][j];
matAAT[j][i]=matAAT[i][j];
}
}
int p;
@ -119,7 +119,6 @@ public class SingularValueDecompositionImpl implements
new Array2DRowRealMatrix(matATA),1.0);
singularValues = eigenDecomposition.getRealEigenvalues();
cachedV = eigenDecomposition.getV();
// compute eigen decomposition of A*A^T
eigenDecomposition = new EigenDecompositionImpl(
new Array2DRowRealMatrix(matAAT),1.0);
@ -141,7 +140,7 @@ public class SingularValueDecompositionImpl implements
singularValues[i] = Math.sqrt(Math.abs(singularValues[i]));
}
// Up to this point, U and V are computed independently of each other.
// There still an sign indetermination of each column of, say, U.
// There still a sign indetermination of each column of, say, U.
// The sign is set such that A.V_i=sigma_i.U_i (i<=p)
// The right sign corresponds to a positive dot product of A.V_i and U_i
for (int i = 0; i < p; i++) {

View File

@ -237,23 +237,20 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul
* @return RMS value
*/
public double getRMS() {
double criterion = 0;
for (int i = 0; i < rows; ++i) {
final double residual = residuals[i];
criterion += residualsWeights[i] * residual * residual;
}
return Math.sqrt(criterion / rows);
return Math.sqrt(getChiSquare() / rows);
}
/**
* Get the Chi-Square value.
* Get a Chi-Square-like value assuming the N residuals follow N
* distinct normal distributions centered on 0 and whose variances are
* the reciprocal of the weights.
* @return chi-square value
*/
public double getChiSquare() {
double chiSquare = 0;
for (int i = 0; i < rows; ++i) {
final double residual = residuals[i];
chiSquare += residual * residual / residualsWeights[i];
chiSquare += residual * residual * residualsWeights[i];
}
return chiSquare;
}

View File

@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="2.2" date="TBD" description="TBD">
<action dev="dimpbx" type="fix" issue="MATH-377">
Fixed bug in chi-square computation in AbstractLeastSquaresOptimizer.
</action>
<action dev="luc" type="add" issue="MATH-400" due-to="J. Lewis Muir">
Added support for Gaussian curve fitting.
</action>

View File

@ -439,8 +439,8 @@ public class LevenbergMarquardtOptimizerTest
assertEquals(cov[0][1], cov[1][0], 1.0e-14);
assertEquals(0.0016, cov[1][1], 0.001);
errors = optimizer.guessParametersErrors();
assertEquals(0.002, errors[0], 0.001);
assertEquals(0.002, errors[1], 0.001);
assertEquals(0.004, errors[0], 0.001);
assertEquals(0.004, errors[1], 0.001);
}