Author: luc
Date: Sun Sep 28 08:51:47 2008
New Revision: 699844
URL: http://svn.apache.org/viewvc?rev=699844&view=rev
Log:
pulled some solve-related methods higher in the classes hierarchy
(isNonSinglular(), getInverse())
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/DecompositionSolver.java
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecomposition.java
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecomposition.java
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/DecompositionSolver.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/DecompositionSolver.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/DecompositionSolver.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/DecompositionSolver.java
Sun Sep 28 08:51:47 2008
@@ -45,7 +45,7 @@
* for [EMAIL PROTECTED] LUDecomposition})
*/
void decompose(RealMatrix matrix)
- throws InvalidMatrixException;
+ throws InvalidMatrixException;
/** Solve the linear equation A × X = B.
* <p>The A matrix is implicit here. It <strong>must</strong> have
@@ -58,7 +58,7 @@
* @exception InvalidMatrixException if decomposed matrix is singular
*/
double[] solve(double[] b)
- throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
+ throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
/** Solve the linear equation A × X = B.
* <p>The A matrix is implicit here. It <strong>must</strong> have
@@ -71,7 +71,7 @@
* @exception InvalidMatrixException if decomposed matrix is singular
*/
RealVector solve(RealVector b)
- throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
+ throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
/** Solve the linear equation A × X = B.
* <p>The A matrix is implicit here. It <strong>must</strong> have
@@ -84,6 +84,23 @@
* @exception InvalidMatrixException if decomposed matrix is singular
*/
RealMatrix solve(RealMatrix b)
- throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
+ throws IllegalStateException, IllegalArgumentException,
InvalidMatrixException;
+
+ /**
+ * Check if the decomposed matrix is non-singular.
+ * @return true if the decomposed matrix is non-singular
+ * @exception IllegalStateException if [EMAIL PROTECTED]
+ * DecompositionSolver#decompose(RealMatrix) decompose} has not been called
+ */
+ boolean isNonSingular() throws IllegalStateException;
+
+ /** Get the inverse of the decomposed matrix.
+ * @return inverse matrix
+ * @exception IllegalStateException if [EMAIL PROTECTED]
#decompose(RealMatrix) decompose}
+ * has not been called
+ * @throws InvalidMatrixException if decomposed matrix is singular
+ */
+ RealMatrix getInverse()
+ throws IllegalStateException, InvalidMatrixException;
}
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecomposition.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecomposition.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecomposition.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecomposition.java
Sun Sep 28 08:51:47 2008
@@ -96,15 +96,6 @@
int[] getPivot() throws IllegalStateException;
/**
- * Check if the decomposed matrix is non-singular.
- * @return true if the decomposed matrix is non-singular
- * @exception IllegalStateException if [EMAIL PROTECTED]
- * DecompositionSolver#decompose(RealMatrix) decompose} has not been called
- * @see #getDeterminant()
- */
- boolean isNonSingular() throws IllegalStateException;
-
- /**
* Return the determinant of the matrix
* @return determinant of the matrix
* @exception IllegalStateException if [EMAIL PROTECTED]
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java
Sun Sep 28 08:51:47 2008
@@ -32,7 +32,7 @@
public class LUDecompositionImpl implements LUDecomposition {
/** Serializable version identifier. */
- private static final long serialVersionUID = -9052751605297201067L;
+ private static final long serialVersionUID = 3446121671437672843L;
/** Entries of LU decomposition. */
private double lu[][];
@@ -108,7 +108,7 @@
public void decompose(RealMatrix matrix, double singularityThreshold)
throws InvalidMatrixException {
if (!matrix.isSquare()) {
- throw new InvalidMatrixException("LU decomposition requires that
the matrix be square.");
+ throw new InvalidMatrixException("LU decomposition requires that
the matrix be square");
}
final int m = matrix.getColumnDimension();
lu = matrix.getData();
@@ -413,6 +413,13 @@
}
+ /** [EMAIL PROTECTED] */
+ public RealMatrix getInverse()
+ throws IllegalStateException, InvalidMatrixException {
+ checkDecomposed();
+ return solve(MatrixUtils.createRealIdentityMatrix(pivot.length));
+ }
+
/**
* Check if either [EMAIL PROTECTED] #decompose(RealMatrix)} or [EMAIL
PROTECTED]
* #decompose(RealMatrix, double) has been called.
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecomposition.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecomposition.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecomposition.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecomposition.java
Sun Sep 28 08:51:47 2008
@@ -24,8 +24,12 @@
* <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> library, with the
* following changes:</p>
* <ul>
- * <li>several signatures have been added for the <code>solve</code> methods
(in the superinterface),</code>
- * <li>a <code>decompose</code> method has been added (in the
superinterface),</code>
+ * <li>several signatures have been added for the <code>solve</code> methods
+ * (in the superinterface),</li>
+ * <li>a [EMAIL PROTECTED] DecompositionSolver#decompose(RealMatrix)
decompose} method
+ * has been added (in the superinterface),</li>
+ * <li>the <code>isFullRank</code> method has been replaced by the [EMAIL
PROTECTED]
+ * DecompositionSolver#isNonSingular() isNonSingular} method in the
superinterface.</li>
* </ul>
*
* @see <a
href="http://mathworld.wolfram.com/QRDecomposition.html">MathWorld</a>
@@ -64,12 +68,4 @@
*/
RealMatrix getH() throws IllegalStateException;
- /**
- * Check if the decomposed matrix is full rank.
- * @return true if the decomposed matrix is full rank
- * @exception IllegalStateException if [EMAIL PROTECTED]
- * DecompositionSolver#decompose(RealMatrix) decompose} has not been called
- */
- boolean isFullRank() throws IllegalStateException;
-
}
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java
Sun Sep 28 08:51:47 2008
@@ -36,7 +36,7 @@
public class QRDecompositionImpl implements QRDecomposition {
/** Serializable version identifier. */
- private static final long serialVersionUID = 7560093145655650408L;
+ private static final long serialVersionUID = -5179446891802932307L;
/**
* A packed TRANSPOSED representation of the QR decomposition.
@@ -267,7 +267,7 @@
}
/** [EMAIL PROTECTED] */
- public boolean isFullRank()
+ public boolean isNonSingular()
throws IllegalStateException {
checkDecomposed();
@@ -292,7 +292,7 @@
if (b.length != m) {
throw new IllegalArgumentException("Incorrect row dimension");
}
- if (!isFullRank()) {
+ if (!isNonSingular()) {
throw new InvalidMatrixException("Matrix is rank-deficient");
}
@@ -366,7 +366,7 @@
if (b.getRowDimension() != m) {
throw new IllegalArgumentException("Incorrect row dimension");
}
- if (!isFullRank()) {
+ if (!isNonSingular()) {
throw new InvalidMatrixException("Matrix is rank-deficient");
}
@@ -414,6 +414,13 @@
}
+ /** [EMAIL PROTECTED] */
+ public RealMatrix getInverse()
+ throws IllegalStateException, InvalidMatrixException {
+ checkDecomposed();
+ return solve(MatrixUtils.createRealIdentityMatrix(rDiag.length));
+ }
+
/**
* Check if [EMAIL PROTECTED] #decompose(RealMatrix)} has been called.
* @exception IllegalStateException if [EMAIL PROTECTED]
#decompose(RealMatrix) decompose}
Modified:
commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java?rev=699844&r1=699843&r2=699844&view=diff
==============================================================================
---
commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
(original)
+++
commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/linear/QRDecompositionImplTest.java
Sun Sep 28 08:51:47 2008
@@ -200,16 +200,16 @@
public void testRank() {
QRDecomposition qr =
new QRDecompositionImpl(new RealMatrixImpl(testData3x3NonSingular,
false));
- assertTrue(qr.isFullRank());
+ assertTrue(qr.isNonSingular());
qr = new QRDecompositionImpl(new RealMatrixImpl(testData3x3Singular,
false));
- assertFalse(qr.isFullRank());
+ assertFalse(qr.isNonSingular());
qr = new QRDecompositionImpl(new RealMatrixImpl(testData3x4, false));
- assertFalse(qr.isFullRank());
+ assertFalse(qr.isNonSingular());
qr = new QRDecompositionImpl(new RealMatrixImpl(testData4x3, false));
- assertTrue(qr.isFullRank());
+ assertTrue(qr.isNonSingular());
}
@@ -352,7 +352,7 @@
/** test no call to decompose */
public void testNoDecompose() {
try {
- new QRDecompositionImpl().isFullRank();
+ new QRDecompositionImpl().isNonSingular();
fail("an exception should have been caught");
} catch (IllegalStateException ise) {
// expected behavior