In SymmLQTest, testPreconditionedNormOfResidual() now passes.

Previous failure was due to the test itself, not to the implementation of SymmLQ.
See MATH-770.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1304216 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-03-23 07:50:51 +00:00
parent 97826e4177
commit 20fa2579ec
2 changed files with 35 additions and 3 deletions

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.math3.linear;
import org.apache.commons.math3.analysis.function.Sqrt;
/**
* This class implements the standard Jacobi (diagonal) preconditioner. For a
* matrix A<sub>ij</sub>, this preconditioner is
@ -98,4 +100,34 @@ public class JacobiPreconditioner extends RealLinearOperator {
// Dimension check is carried out by ebeMultiply
return x.ebeDivide(diag);
}
/**
* Returns the square root of {@code this} diagonal operator. More
* precisely, this method returns
* P = diag(1 / &radic;A<sub>11</sub>, 1 / &radic;A<sub>22</sub>, &hellip;).
*
* @return the square root of {@code this} operator
*/
public RealLinearOperator sqrt(){
final RealVector sqrtDiag = diag.map(new Sqrt());
return new RealLinearOperator() {
/** {@inheritDoc} */
@Override
public RealVector operate(final RealVector x) {
return x.ebeDivide(sqrtDiag);
}
/** {@inheritDoc} */
@Override
public int getRowDimension() {
return sqrtDiag.getDimension();
}
/** {@inheritDoc} */
@Override
public int getColumnDimension() {
return sqrtDiag.getDimension();
}
};
}
}

View File

@ -19,7 +19,6 @@ package org.apache.commons.math3.linear;
import java.util.Arrays;
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.MathUnsupportedOperationException;
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.util.IterationEvent;
import org.apache.commons.math3.util.IterationListener;
@ -643,7 +642,8 @@ public class SymmLQTest {
final int n = 5;
final int maxIterations = 100;
final RealLinearOperator a = new HilbertMatrix(n);
final RealLinearOperator m = JacobiPreconditioner.create(a);
final JacobiPreconditioner m = JacobiPreconditioner.create(a);
final RealLinearOperator p = m.sqrt();
final PreconditionedIterativeLinearSolver solver;
final IterationListener listener = new IterationListener() {
@ -653,7 +653,7 @@ public class SymmLQTest {
final RealVector x = evt.getSolution();
final RealVector b = evt.getRightHandSideVector();
final RealVector r = b.subtract(a.operate(x));
final double rnorm = r.getNorm();
final double rnorm = p.operate(r).getNorm();
Assert.assertEquals("iteration performed (residual)",
rnorm, evt.getNormOfResidual(),
FastMath.max(1E-5 * rnorm, 1E-10));