Author: celestin
Date: Sat Sep 24 04:28:36 2011
New Revision: 1175099
URL: http://svn.apache.org/viewvc?rev=1175099&view=rev
Log:
Merged LUDecomposition and LUDecompositionImpl (see MATH-662).
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecomposition.java
- copied, changed from r1174531,
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionTest.java
- copied, changed from r1174531,
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java
Removed:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
Copied:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecomposition.java
(from r1174531,
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecomposition.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecomposition.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java&r1=1174531&r2=1175099&rev=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecomposition.java
Sat Sep 24 04:28:36 2011
@@ -22,24 +22,38 @@ import org.apache.commons.math.util.Fast
/**
* Calculates the LUP-decomposition of a square matrix.
- * <p>The LUP-decomposition of a matrix A consists of three matrices
- * L, U and P that satisfy: PA = LU, L is lower triangular, and U is
- * upper triangular and P is a permutation matrix. All matrices are
- * m×m.</p>
+ * <p>The LUP-decomposition of a matrix A consists of three matrices L, U and
+ * P that satisfy: P×A = L×U. L is lower triangular (with unit
+ * diagonal terms), U is upper triangular and P is a permutation matrix. All
+ * matrices are m×m.</p>
* <p>As shown by the presence of the P matrix, this decomposition is
* implemented using partial pivoting.</p>
+ * <p>This class is based on the class with similar name from the
+ * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> library.</p>
+ * <ul>
+ * <li>a {@link #getP() getP} method has been added,</li>
+ * <li>the {@code det} method has been renamed as {@link #getDeterminant()
+ * getDeterminant},</li>
+ * <li>the {@code getDoublePivot} method has been removed (but the int based
+ * {@link #getPivot() getPivot} method has been kept),</li>
+ * <li>the {@code solve} and {@code isNonSingular} methods have been replaced
+ * by a {@link #getSolver() getSolver} method and the equivalent methods
+ * provided by the returned {@link DecompositionSolver}.</li>
+ * </ul>
*
+ * @see <a
href="http://mathworld.wolfram.com/LUDecomposition.html">MathWorld</a>
+ * @see <a href="http://en.wikipedia.org/wiki/LU_decomposition">Wikipedia</a>
* @version $Id$
- * @since 2.0
+ * @since 2.0 (changed to concrete class in 3.0)
*/
-public class LUDecompositionImpl implements LUDecomposition {
+public class LUDecomposition {
/** Default bound to determine effective singularity in LU decomposition.
*/
private static final double DEFAULT_TOO_SMALL = 1e-11;
/** Entries of LU decomposition. */
- private final double lu[][];
- /** Pivot permutation associated with LU decomposition */
+ private final double[][] lu;
+ /** Pivot permutation associated with LU decomposition. */
private final int[] pivot;
- /** Parity of the permutation associated with the LU decomposition */
+ /** Parity of the permutation associated with the LU decomposition. */
private boolean even;
/** Singularity indicator. */
private boolean singular;
@@ -58,7 +72,7 @@ public class LUDecompositionImpl impleme
* @param matrix Matrix to decompose.
* @throws NonSquareMatrixException if matrix is not square.
*/
- public LUDecompositionImpl(RealMatrix matrix) {
+ public LUDecomposition(RealMatrix matrix) {
this(matrix, DEFAULT_TOO_SMALL);
}
@@ -69,7 +83,7 @@ public class LUDecompositionImpl impleme
* under which a matrix is considered singular
* @throws NonSquareMatrixException if matrix is not square
*/
- public LUDecompositionImpl(RealMatrix matrix, double singularityThreshold)
{
+ public LUDecomposition(RealMatrix matrix, double singularityThreshold) {
if (!matrix.isSquare()) {
throw new NonSquareMatrixException(matrix.getRowDimension(),
matrix.getColumnDimension());
@@ -150,7 +164,11 @@ public class LUDecompositionImpl impleme
}
}
- /** {@inheritDoc} */
+ /**
+ * Returns the matrix L of the decomposition.
+ * <p>L is a lower-triangular matrix</p>
+ * @return the L matrix (or null if decomposed matrix is singular)
+ */
public RealMatrix getL() {
if ((cachedL == null) && !singular) {
final int m = pivot.length;
@@ -166,7 +184,11 @@ public class LUDecompositionImpl impleme
return cachedL;
}
- /** {@inheritDoc} */
+ /**
+ * Returns the matrix U of the decomposition.
+ * <p>U is an upper-triangular matrix</p>
+ * @return the U matrix (or null if decomposed matrix is singular)
+ */
public RealMatrix getU() {
if ((cachedU == null) && !singular) {
final int m = pivot.length;
@@ -181,7 +203,15 @@ public class LUDecompositionImpl impleme
return cachedU;
}
- /** {@inheritDoc} */
+ /**
+ * Returns the P rows permutation matrix.
+ * <p>P is a sparse matrix with exactly one element set to 1.0 in
+ * each row and each column, all other elements being set to 0.0.</p>
+ * <p>The positions of the 1 elements are given by the {@link #getPivot()
+ * pivot permutation vector}.</p>
+ * @return the P rows permutation matrix (or null if decomposed matrix is
singular)
+ * @see #getPivot()
+ */
public RealMatrix getP() {
if ((cachedP == null) && !singular) {
final int m = pivot.length;
@@ -193,12 +223,19 @@ public class LUDecompositionImpl impleme
return cachedP;
}
- /** {@inheritDoc} */
+ /**
+ * Returns the pivot permutation vector.
+ * @return the pivot permutation vector
+ * @see #getP()
+ */
public int[] getPivot() {
return pivot.clone();
}
- /** {@inheritDoc} */
+ /**
+ * Return the determinant of the matrix
+ * @return determinant of the matrix
+ */
public double getDeterminant() {
if (singular) {
return 0;
@@ -212,7 +249,11 @@ public class LUDecompositionImpl impleme
}
}
- /** {@inheritDoc} */
+ /**
+ * Get a solver for finding the A × X = B solution in exact linear
+ * sense.
+ * @return a solver
+ */
public DecompositionSolver getSolver() {
return new Solver(lu, pivot, singular);
}
@@ -221,7 +262,7 @@ public class LUDecompositionImpl impleme
private static class Solver implements DecompositionSolver {
/** Entries of LU decomposition. */
- private final double lu[][];
+ private final double[][] lu;
/** Pivot permutation associated with LU decomposition. */
private final int[] pivot;
@@ -284,61 +325,6 @@ public class LUDecompositionImpl impleme
}
/** {@inheritDoc} */
- public double[][] solve(double[][] b) {
-
- final int m = pivot.length;
- if (b.length != m) {
- throw new DimensionMismatchException(b.length, m);
- }
- if (singular) {
- throw new SingularMatrixException();
- }
-
- final int nColB = b[0].length;
-
- // Apply permutations to b
- final double[][] bp = new double[m][nColB];
- for (int row = 0; row < m; row++) {
- final double[] bpRow = bp[row];
- final int pRow = pivot[row];
- for (int col = 0; col < nColB; col++) {
- bpRow[col] = b[pRow][col];
- }
- }
-
- // Solve LY = b
- for (int col = 0; col < m; col++) {
- final double[] bpCol = bp[col];
- for (int i = col + 1; i < m; i++) {
- final double[] bpI = bp[i];
- final double luICol = lu[i][col];
- for (int j = 0; j < nColB; j++) {
- bpI[j] -= bpCol[j] * luICol;
- }
- }
- }
-
- // Solve UX = Y
- for (int col = m - 1; col >= 0; col--) {
- final double[] bpCol = bp[col];
- final double luDiag = lu[col][col];
- for (int j = 0; j < nColB; j++) {
- bpCol[j] /= luDiag;
- }
- for (int i = 0; i < col; i++) {
- final double[] bpI = bp[i];
- final double luICol = lu[i][col];
- for (int j = 0; j < nColB; j++) {
- bpI[j] -= bpCol[j] * luICol;
- }
- }
- }
-
- return bp;
-
- }
-
- /** {@inheritDoc} */
public RealMatrix solve(RealMatrix b) {
final int m = pivot.length;
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
Sat Sep 24 04:28:36 2011
@@ -22,7 +22,7 @@ import org.apache.commons.math.exception
import
org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
import org.apache.commons.math.exception.util.LocalizedFormats;
-import org.apache.commons.math.linear.LUDecompositionImpl;
+import org.apache.commons.math.linear.LUDecomposition;
import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.optimization.ConvergenceChecker;
@@ -212,7 +212,7 @@ public abstract class AbstractLeastSquar
// Compute the covariances matrix.
final DecompositionSolver solver
- = new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj),
threshold).getSolver();
+ = new LUDecomposition(MatrixUtils.createRealMatrix(jTj),
threshold).getSolver();
return solver.getInverse().getData();
}
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
Sat Sep 24 04:28:36 2011
@@ -22,7 +22,7 @@ import org.apache.commons.math.exception
import org.apache.commons.math.linear.ArrayRealVector;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.DecompositionSolver;
-import org.apache.commons.math.linear.LUDecompositionImpl;
+import org.apache.commons.math.linear.LUDecomposition;
import org.apache.commons.math.linear.QRDecompositionImpl;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.SingularMatrixException;
@@ -144,7 +144,7 @@ public class GaussNewtonOptimizer extend
// solve the linearized least squares problem
RealMatrix mA = new BlockRealMatrix(a);
DecompositionSolver solver = useLU ?
- new LUDecompositionImpl(mA).getSolver() :
+ new LUDecomposition(mA).getSolver() :
new QRDecompositionImpl(mA).getSolver();
final double[] dX = solver.solve(new ArrayRealVector(b,
false)).toArray();
// update the estimated parameters
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/GLSMultipleLinearRegression.java
Sat Sep 24 04:28:36 2011
@@ -16,7 +16,7 @@
*/
package org.apache.commons.math.stat.regression;
-import org.apache.commons.math.linear.LUDecompositionImpl;
+import org.apache.commons.math.linear.LUDecomposition;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.RealVector;
@@ -78,7 +78,7 @@ public class GLSMultipleLinearRegression
*/
protected RealMatrix getOmegaInverse() {
if (OmegaInverse == null) {
- OmegaInverse = new
LUDecompositionImpl(Omega).getSolver().getInverse();
+ OmegaInverse = new LUDecomposition(Omega).getSolver().getInverse();
}
return OmegaInverse;
}
@@ -95,7 +95,7 @@ public class GLSMultipleLinearRegression
RealMatrix OI = getOmegaInverse();
RealMatrix XT = X.transpose();
RealMatrix XTOIX = XT.multiply(OI).multiply(X);
- RealMatrix inverse = new
LUDecompositionImpl(XTOIX).getSolver().getInverse();
+ RealMatrix inverse = new
LUDecomposition(XTOIX).getSolver().getInverse();
return inverse.multiply(XT).multiply(OI).operate(Y);
}
@@ -110,7 +110,7 @@ public class GLSMultipleLinearRegression
protected RealMatrix calculateBetaVariance() {
RealMatrix OI = getOmegaInverse();
RealMatrix XTOIX = X.transpose().multiply(OI).multiply(X);
- return new LUDecompositionImpl(XTOIX).getSolver().getInverse();
+ return new LUDecomposition(XTOIX).getSolver().getInverse();
}
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/regression/OLSMultipleLinearRegression.java
Sat Sep 24 04:28:36 2011
@@ -17,7 +17,7 @@
package org.apache.commons.math.stat.regression;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
-import org.apache.commons.math.linear.LUDecompositionImpl;
+import org.apache.commons.math.linear.LUDecomposition;
import org.apache.commons.math.linear.QRDecomposition;
import org.apache.commons.math.linear.QRDecompositionImpl;
import org.apache.commons.math.linear.RealMatrix;
@@ -226,7 +226,7 @@ public class OLSMultipleLinearRegression
protected RealMatrix calculateBetaVariance() {
int p = X.getColumnDimension();
RealMatrix Raug = qr.getR().getSubMatrix(0, p - 1 , 0, p - 1);
- RealMatrix Rinv = new
LUDecompositionImpl(Raug).getSolver().getInverse();
+ RealMatrix Rinv = new LUDecomposition(Raug).getSolver().getInverse();
return Rinv.multiply(Rinv.transpose());
}
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
Sat Sep 24 04:28:36 2011
@@ -333,8 +333,8 @@ public final class Array2DRowRealMatrixT
@Test
public void testTranspose() {
RealMatrix m = new Array2DRowRealMatrix(testData);
- RealMatrix mIT = new
LUDecompositionImpl(m).getSolver().getInverse().transpose();
- RealMatrix mTI = new
LUDecompositionImpl(m.transpose()).getSolver().getInverse();
+ RealMatrix mIT = new
LUDecomposition(m).getSolver().getInverse().transpose();
+ RealMatrix mTI = new
LUDecomposition(m.transpose()).getSolver().getInverse();
TestUtils.assertEquals("inverse-transpose", mIT, mTI, normTolerance);
m = new Array2DRowRealMatrix(testData2);
RealMatrix mt = new Array2DRowRealMatrix(testData2T);
@@ -429,7 +429,7 @@ public final class Array2DRowRealMatrixT
Assert.assertEquals(2, p.getRowDimension());
Assert.assertEquals(2, p.getColumnDimension());
// Invert p
- RealMatrix pInverse = new
LUDecompositionImpl(p).getSolver().getInverse();
+ RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();
Assert.assertEquals(2, pInverse.getRowDimension());
Assert.assertEquals(2, pInverse.getColumnDimension());
@@ -437,7 +437,7 @@ public final class Array2DRowRealMatrixT
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
RealMatrix coefficients = new Array2DRowRealMatrix(coefficientsData);
RealVector constants = new ArrayRealVector(new double[]{1, -2, 1},
false);
- RealVector solution = new
LUDecompositionImpl(coefficients).getSolver().solve(constants);
+ RealVector solution = new
LUDecomposition(coefficients).getSolver().solve(constants);
final double cst0 = constants.getEntry(0);
final double cst1 = constants.getEntry(1);
final double cst2 = constants.getEntry(2);
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
Sat Sep 24 04:28:36 2011
@@ -383,8 +383,8 @@ public final class BlockRealMatrixTest {
@Test
public void testTranspose() {
RealMatrix m = new BlockRealMatrix(testData);
- RealMatrix mIT = new
LUDecompositionImpl(m).getSolver().getInverse().transpose();
- RealMatrix mTI = new
LUDecompositionImpl(m.transpose()).getSolver().getInverse();
+ RealMatrix mIT = new
LUDecomposition(m).getSolver().getInverse().transpose();
+ RealMatrix mTI = new
LUDecomposition(m.transpose()).getSolver().getInverse();
assertClose(mIT, mTI, normTolerance);
m = new BlockRealMatrix(testData2);
RealMatrix mt = new BlockRealMatrix(testData2T);
@@ -474,7 +474,7 @@ public final class BlockRealMatrixTest {
Assert.assertEquals(2, p.getRowDimension());
Assert.assertEquals(2, p.getColumnDimension());
// Invert p
- RealMatrix pInverse = new
LUDecompositionImpl(p).getSolver().getInverse();
+ RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();
Assert.assertEquals(2, pInverse.getRowDimension());
Assert.assertEquals(2, pInverse.getColumnDimension());
@@ -482,7 +482,7 @@ public final class BlockRealMatrixTest {
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
RealMatrix coefficients = new BlockRealMatrix(coefficientsData);
RealVector constants = new ArrayRealVector(new double[]{1, -2, 1},
false);
- RealVector solution = new
LUDecompositionImpl(coefficients).getSolver().solve(constants);
+ RealVector solution = new
LUDecomposition(coefficients).getSolver().solve(constants);
final double cst0 = constants.getEntry(0);
final double cst1 = constants.getEntry(1);
final double cst2 = constants.getEntry(2);
Copied:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionTest.java
(from r1174531,
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionTest.java?p2=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionTest.java&p1=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java&r1=1174531&r2=1175099&rev=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionImplTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUDecompositionTest.java
Sat Sep 24 04:28:36 2011
@@ -20,7 +20,7 @@ package org.apache.commons.math.linear;
import org.junit.Test;
import org.junit.Assert;
-public class LUDecompositionImplTest {
+public class LUDecompositionTest {
private double[][] testData = {
{ 1.0, 2.0, 3.0},
{ 2.0, 5.0, 3.0},
@@ -57,7 +57,7 @@ public class LUDecompositionImplTest {
@Test
public void testDimensions() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- LUDecomposition LU = new LUDecompositionImpl(matrix);
+ LUDecomposition LU = new LUDecomposition(matrix);
Assert.assertEquals(testData.length, LU.getL().getRowDimension());
Assert.assertEquals(testData.length, LU.getL().getColumnDimension());
Assert.assertEquals(testData.length, LU.getU().getRowDimension());
@@ -71,7 +71,7 @@ public class LUDecompositionImplTest {
@Test
public void testNonSquare() {
try {
- new LUDecompositionImpl(MatrixUtils.createRealMatrix(new
double[3][2]));
+ new LUDecomposition(MatrixUtils.createRealMatrix(new
double[3][2]));
Assert.fail("Expecting NonSquareMatrixException");
} catch (NonSquareMatrixException ime) {
// expected behavior
@@ -82,7 +82,7 @@ public class LUDecompositionImplTest {
@Test
public void testPAEqualLU() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- LUDecomposition lu = new LUDecompositionImpl(matrix);
+ LUDecomposition lu = new LUDecomposition(matrix);
RealMatrix l = lu.getL();
RealMatrix u = lu.getU();
RealMatrix p = lu.getP();
@@ -90,7 +90,7 @@ public class LUDecompositionImplTest {
Assert.assertEquals(0, norm, normTolerance);
matrix = MatrixUtils.createRealMatrix(testDataMinus);
- lu = new LUDecompositionImpl(matrix);
+ lu = new LUDecomposition(matrix);
l = lu.getL();
u = lu.getU();
p = lu.getP();
@@ -98,7 +98,7 @@ public class LUDecompositionImplTest {
Assert.assertEquals(0, norm, normTolerance);
matrix = MatrixUtils.createRealIdentityMatrix(17);
- lu = new LUDecompositionImpl(matrix);
+ lu = new LUDecomposition(matrix);
l = lu.getL();
u = lu.getU();
p = lu.getP();
@@ -106,14 +106,14 @@ public class LUDecompositionImplTest {
Assert.assertEquals(0, norm, normTolerance);
matrix = MatrixUtils.createRealMatrix(singular);
- lu = new LUDecompositionImpl(matrix);
+ lu = new LUDecomposition(matrix);
Assert.assertFalse(lu.getSolver().isNonSingular());
Assert.assertNull(lu.getL());
Assert.assertNull(lu.getU());
Assert.assertNull(lu.getP());
matrix = MatrixUtils.createRealMatrix(bigSingular);
- lu = new LUDecompositionImpl(matrix);
+ lu = new LUDecomposition(matrix);
Assert.assertFalse(lu.getSolver().isNonSingular());
Assert.assertNull(lu.getL());
Assert.assertNull(lu.getU());
@@ -125,7 +125,7 @@ public class LUDecompositionImplTest {
@Test
public void testLLowerTriangular() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- RealMatrix l = new LUDecompositionImpl(matrix).getL();
+ RealMatrix l = new LUDecomposition(matrix).getL();
for (int i = 0; i < l.getRowDimension(); i++) {
Assert.assertEquals(l.getEntry(i, i), 1, entryTolerance);
for (int j = i + 1; j < l.getColumnDimension(); j++) {
@@ -138,7 +138,7 @@ public class LUDecompositionImplTest {
@Test
public void testUUpperTriangular() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- RealMatrix u = new LUDecompositionImpl(matrix).getU();
+ RealMatrix u = new LUDecomposition(matrix).getU();
for (int i = 0; i < u.getRowDimension(); i++) {
for (int j = 0; j < i; j++) {
Assert.assertEquals(u.getEntry(i, j), 0, entryTolerance);
@@ -150,7 +150,7 @@ public class LUDecompositionImplTest {
@Test
public void testPPermutation() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- RealMatrix p = new LUDecompositionImpl(matrix).getP();
+ RealMatrix p = new LUDecomposition(matrix).getP();
RealMatrix ppT = p.multiply(p.transpose());
RealMatrix id =
MatrixUtils.createRealIdentityMatrix(p.getRowDimension());
@@ -200,11 +200,11 @@ public class LUDecompositionImplTest {
@Test
public void testSingular() {
LUDecomposition lu =
- new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData));
+ new LUDecomposition(MatrixUtils.createRealMatrix(testData));
Assert.assertTrue(lu.getSolver().isNonSingular());
- lu = new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular));
+ lu = new LUDecomposition(MatrixUtils.createRealMatrix(singular));
Assert.assertFalse(lu.getSolver().isNonSingular());
- lu = new
LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular));
+ lu = new LUDecomposition(MatrixUtils.createRealMatrix(bigSingular));
Assert.assertFalse(lu.getSolver().isNonSingular());
}
@@ -212,7 +212,7 @@ public class LUDecompositionImplTest {
@Test
public void testMatricesValues1() {
LUDecomposition lu =
- new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData));
+ new LUDecomposition(MatrixUtils.createRealMatrix(testData));
RealMatrix lRef = MatrixUtils.createRealMatrix(new double[][] {
{ 1.0, 0.0, 0.0 },
{ 0.5, 1.0, 0.0 },
@@ -253,7 +253,7 @@ public class LUDecompositionImplTest {
@Test
public void testMatricesValues2() {
LUDecomposition lu =
- new LUDecompositionImpl(MatrixUtils.createRealMatrix(luData));
+ new LUDecomposition(MatrixUtils.createRealMatrix(luData));
RealMatrix lRef = MatrixUtils.createRealMatrix(new double[][] {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/LUSolverTest.java
Sat Sep 24 04:28:36 2011
@@ -54,19 +54,19 @@ public class LUSolverTest {
{ 2.0, 5.0, 3.0},
{ 4.000001, 9.0, 9.0}
});
- Assert.assertFalse(new LUDecompositionImpl(matrix,
1.0e-5).getSolver().isNonSingular());
- Assert.assertTrue(new LUDecompositionImpl(matrix,
1.0e-10).getSolver().isNonSingular());
+ Assert.assertFalse(new LUDecomposition(matrix,
1.0e-5).getSolver().isNonSingular());
+ Assert.assertTrue(new LUDecomposition(matrix,
1.0e-10).getSolver().isNonSingular());
}
/** test singular */
@Test
public void testSingular() {
DecompositionSolver solver =
- new
LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
+ new
LUDecomposition(MatrixUtils.createRealMatrix(testData)).getSolver();
Assert.assertTrue(solver.isNonSingular());
- solver = new
LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)).getSolver();
+ solver = new
LUDecomposition(MatrixUtils.createRealMatrix(singular)).getSolver();
Assert.assertFalse(solver.isNonSingular());
- solver = new
LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular)).getSolver();
+ solver = new
LUDecomposition(MatrixUtils.createRealMatrix(bigSingular)).getSolver();
Assert.assertFalse(solver.isNonSingular());
}
@@ -74,7 +74,7 @@ public class LUSolverTest {
@Test
public void testSolveDimensionErrors() {
DecompositionSolver solver =
- new
LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
+ new
LUDecomposition(MatrixUtils.createRealMatrix(testData)).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
try {
solver.solve(b);
@@ -100,7 +100,7 @@ public class LUSolverTest {
@Test
public void testSolveSingularityErrors() {
DecompositionSolver solver =
- new
LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)).getSolver();
+ new
LUDecomposition(MatrixUtils.createRealMatrix(singular)).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
try {
solver.solve(b);
@@ -126,7 +126,7 @@ public class LUSolverTest {
@Test
public void testSolve() {
DecompositionSolver solver =
- new
LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
+ new
LUDecomposition(MatrixUtils.createRealMatrix(testData)).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
{ 1, 0 }, { 2, -5 }, { 3, 1 }
});
@@ -164,6 +164,6 @@ public class LUSolverTest {
}
private double getDeterminant(RealMatrix m) {
- return new LUDecompositionImpl(m).getDeterminant();
+ return new LUDecomposition(m).getDeterminant();
}
}
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java?rev=1175099&r1=1175098&r2=1175099&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
Sat Sep 24 04:28:36 2011
@@ -283,8 +283,8 @@ public final class SparseRealMatrixTest
@Test
public void testTranspose() {
RealMatrix m = createSparseMatrix(testData);
- RealMatrix mIT = new
LUDecompositionImpl(m).getSolver().getInverse().transpose();
- RealMatrix mTI = new
LUDecompositionImpl(m.transpose()).getSolver().getInverse();
+ RealMatrix mIT = new
LUDecomposition(m).getSolver().getInverse().transpose();
+ RealMatrix mTI = new
LUDecomposition(m.transpose()).getSolver().getInverse();
assertClose("inverse-transpose", mIT, mTI, normTolerance);
m = createSparseMatrix(testData2);
RealMatrix mt = createSparseMatrix(testData2T);
@@ -379,7 +379,7 @@ public final class SparseRealMatrixTest
Assert.assertEquals(2, p.getRowDimension());
Assert.assertEquals(2, p.getColumnDimension());
// Invert p
- RealMatrix pInverse = new
LUDecompositionImpl(p).getSolver().getInverse();
+ RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();
Assert.assertEquals(2, pInverse.getRowDimension());
Assert.assertEquals(2, pInverse.getColumnDimension());
@@ -388,7 +388,7 @@ public final class SparseRealMatrixTest
{ 4, -3, -5 } };
RealMatrix coefficients = createSparseMatrix(coefficientsData);
RealVector constants = new ArrayRealVector(new double[]{ 1, -2, 1 },
false);
- RealVector solution = new
LUDecompositionImpl(coefficients).getSolver().solve(constants);
+ RealVector solution = new
LUDecomposition(coefficients).getSolver().solve(constants);
final double cst0 = constants.getEntry(0);
final double cst1 = constants.getEntry(1);
final double cst2 = constants.getEntry(2);