MATH-602
Inverse condition number. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1157345 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9edd2f24d7
commit
cec75d74f8
|
@ -545,6 +545,17 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
return singularValues[0] / singularValues[n - 1];
|
return singularValues[0] / singularValues[n - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the inverse of the condition number.
|
||||||
|
* In cases of rank deficiency, the {@link #getConditionNumber() condition
|
||||||
|
* number} will become undefined.
|
||||||
|
*
|
||||||
|
* @return the inverse of the condition number.
|
||||||
|
*/
|
||||||
|
public double getInverseConditionNumber() {
|
||||||
|
return singularValues[n - 1] / singularValues[0];
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public int getRank() {
|
public int getRank() {
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
|
@ -298,6 +298,13 @@ public class SingularValueDecompositionImplTest {
|
||||||
Assert.assertEquals(3.0, svd.getConditionNumber(), 1.5e-15);
|
Assert.assertEquals(3.0, svd.getConditionNumber(), 1.5e-15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInverseConditionNumber() {
|
||||||
|
SingularValueDecompositionImpl svd =
|
||||||
|
new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare));
|
||||||
|
Assert.assertEquals(1.0/3.0, svd.getInverseConditionNumber(), 1.5e-15);
|
||||||
|
}
|
||||||
|
|
||||||
private RealMatrix createTestMatrix(final Random r, final int rows, final int columns,
|
private RealMatrix createTestMatrix(final Random r, final int rows, final int columns,
|
||||||
final double[] singularValues) {
|
final double[] singularValues) {
|
||||||
final RealMatrix u =
|
final RealMatrix u =
|
||||||
|
|
Loading…
Reference in New Issue