[MATH-1051] Fix EigenDecomposition for certain non-symmetric matrices.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1537611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-10-31 20:06:15 +00:00
parent 5bbbe7709f
commit bda25b4029
3 changed files with 30 additions and 8 deletions

View File

@ -51,6 +51,10 @@ If the output is not quite correct, check for invisible trailing spaces!
</properties>
<body>
<release version="x.y" date="TBD" description="TBD">
<action dev="tn" type="fix" issue="MATH-1051">
"EigenDecomposition" may have failed to compute the decomposition for certain
non-symmetric matrices. Port of the respective bugfix in Jama-1.0.3.
</action>
<action dev="erans" type="fix" issue="MATH-1047">
Check for overflow in methods "pow" (class "o.a.c.m.util.ArithmeticUtils").
</action>

View File

@ -364,14 +364,12 @@ class SchurTransformer {
q = matrixT[k + 1][k - 1];
r = notlast ? matrixT[k + 2][k - 1] : 0.0;
shift.x = FastMath.abs(p) + FastMath.abs(q) + FastMath.abs(r);
if (!Precision.equals(shift.x, 0.0, epsilon)) {
p = p / shift.x;
q = q / shift.x;
r = r / shift.x;
if (Precision.equals(shift.x, 0.0, epsilon)) {
continue;
}
}
if (shift.x == 0.0) {
break;
p = p / shift.x;
q = q / shift.x;
r = r / shift.x;
}
double s = FastMath.sqrt(p * p + q * q + r * r);
if (p < 0.0) {

View File

@ -436,7 +436,27 @@ public class EigenDecompositionTest {
checkUnsymmetricMatrix(m);
}
}
/**
* Tests the porting of a bugfix in Jama-1.0.3 (from changelog):
*
* Patched hqr2 method in Jama.EigenvalueDecomposition to avoid infinite loop;
* Thanks Frederic Devernay <frederic.devernay@m4x.org>
*/
@Test
public void testMath1051() {
double[][] data = {
{0,0,0,0,0},
{0,0,0,0,1},
{0,0,0,1,0},
{1,1,0,0,1},
{1,0,1,0,1}
};
RealMatrix m = MatrixUtils.createRealMatrix(data);
checkUnsymmetricMatrix(m);
}
@Test
@Ignore
public void testNormalDistributionUnsymmetricMatrix() {