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:
parent
97826e4177
commit
20fa2579ec
|
@ -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 / √A<sub>11</sub>, 1 / √A<sub>22</sub>, …).
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue