Disabled random data tests for eigen decomposition, improved checkUnsymmetricMatrix helper.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1374031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f06fe1c098
commit
91d24dcb6f
|
@ -27,6 +27,7 @@ import org.apache.commons.math3.util.Precision;
|
|||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EigenDecompositionTest {
|
||||
|
@ -365,6 +366,7 @@ public class EigenDecompositionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRandomUnsymmetricMatrix() {
|
||||
for (int run = 0; run < 100; run++) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
|
@ -385,6 +387,7 @@ public class EigenDecompositionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testNormalDistributionUnsymmetricMatrix() {
|
||||
for (int run = 0; run < 100; run++) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
|
@ -404,27 +407,32 @@ public class EigenDecompositionTest {
|
|||
checkUnsymmetricMatrix(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks that the eigen decomposition of a general (unsymmetric) matrix is valid by
|
||||
* checking: A*V = V*D
|
||||
*/
|
||||
private void checkUnsymmetricMatrix(final RealMatrix m) {
|
||||
EigenDecomposition ed = new EigenDecomposition(m);
|
||||
try {
|
||||
EigenDecomposition ed = new EigenDecomposition(m);
|
||||
|
||||
RealMatrix d = ed.getD();
|
||||
RealMatrix v = ed.getV();
|
||||
//RealMatrix vT = ed.getVT();
|
||||
RealMatrix d = ed.getD();
|
||||
RealMatrix v = ed.getV();
|
||||
//RealMatrix vT = ed.getVT();
|
||||
|
||||
RealMatrix x = m.multiply(v);
|
||||
RealMatrix y = v.multiply(d);
|
||||
RealMatrix x = m.multiply(v);
|
||||
RealMatrix y = v.multiply(d);
|
||||
|
||||
Assert.assertTrue("The norm of (X-Y) is too large",
|
||||
x.subtract(y).getNorm() < 1000 * Precision.EPSILON * FastMath.max(x.getNorm(), y.getNorm()));
|
||||
double diffNorm = x.subtract(y).getNorm();
|
||||
Assert.assertTrue("The norm of (X-Y) is too large: " + diffNorm + ", matrix=" + m.toString(),
|
||||
x.subtract(y).getNorm() < 1000 * Precision.EPSILON * FastMath.max(x.getNorm(), y.getNorm()));
|
||||
|
||||
RealMatrix invV = new LUDecomposition(v).getSolver().getInverse();
|
||||
double norm = v.multiply(d).multiply(invV).subtract(m).getNorm();
|
||||
Assert.assertEquals(0.0, norm, 1.0e-10);
|
||||
RealMatrix invV = new LUDecomposition(v).getSolver().getInverse();
|
||||
double norm = v.multiply(d).multiply(invV).subtract(m).getNorm();
|
||||
Assert.assertEquals(0.0, norm, 1.0e-10);
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Failed to create EigenDecomposition for matrix " + m.toString() + ", ex=" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/** test eigenvectors */
|
||||
|
|
Loading…
Reference in New Issue