You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2011/09/21 05:45:37 UTC
svn commit: r1173481 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/filter/
main/java/org/apache/commons/math/linear/
test/java/org/apache/commons/math/linear/
Author: celestin
Date: Wed Sep 21 03:45:37 2011
New Revision: 1173481
URL: http://svn.apache.org/viewvc?rev=1173481&view=rev
Log:
Merged CholeskyDecomposition and CholeskyDecompositionImpl (see MATH-662).
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java
- copied, changed from r1173471, commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionTest.java
- copied, changed from r1173475, commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java
Removed:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/filter/KalmanFilter.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/filter/KalmanFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/filter/KalmanFilter.java?rev=1173481&r1=1173480&r2=1173481&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/filter/KalmanFilter.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/filter/KalmanFilter.java Wed Sep 21 03:45:37 2011
@@ -19,7 +19,7 @@ package org.apache.commons.math.filter;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.ArrayRealVector;
-import org.apache.commons.math.linear.CholeskyDecompositionImpl;
+import org.apache.commons.math.linear.CholeskyDecomposition;
import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.MatrixDimensionMismatchException;
import org.apache.commons.math.linear.MatrixUtils;
@@ -355,7 +355,7 @@ public class KalmanFilter {
// invert S
// as the error covariance matrix is a symmetric positive
// semi-definite matrix, we can use the cholesky decomposition
- DecompositionSolver solver = new CholeskyDecompositionImpl(s).getSolver();
+ DecompositionSolver solver = new CholeskyDecomposition(s).getSolver();
RealMatrix invertedS = solver.getInverse();
// Inn = z(k) - H * xHat(k)-
Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java (from r1173471, commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java&r1=1173471&r2=1173481&rev=1173481&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java Wed Sep 21 03:45:37 2011
@@ -26,13 +26,26 @@ import org.apache.commons.math.util.Fast
* <p>The Cholesky decomposition of a real symmetric positive-definite
* matrix A consists of a lower triangular matrix L with same size such
* that: A = LL<sup>T</sup>. In a sense, this is the square root of A.</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, with the
+ * following changes:</p>
+ * <ul>
+ * <li>a {@link #getLT() getLT} method has been added,</li>
+ * <li>the {@code isspd} method has been removed, since the constructor of
+ * this class throws a {@link NonPositiveDefiniteMatrixException} when a
+ * matrix cannot be decomposed,</li>
+ * <li>a {@link #getDeterminant() getDeterminant} method has been added,</li>
+ * <li>the {@code solve} method has been replaced by a {@link #getSolver()
+ * getSolver} method and the equivalent method provided by the returned
+ * {@link DecompositionSolver}.</li>
+ * </ul>
*
* @see <a href="http://mathworld.wolfram.com/CholeskyDecomposition.html">MathWorld</a>
* @see <a href="http://en.wikipedia.org/wiki/Cholesky_decomposition">Wikipedia</a>
* @version $Id$
* @since 2.0
*/
-public class CholeskyDecompositionImpl implements CholeskyDecomposition {
+public class CholeskyDecomposition {
/**
* Default threshold above which off-diagonal elements are considered too different
* and matrix not symmetric.
@@ -68,7 +81,7 @@ public class CholeskyDecompositionImpl i
* @see #DEFAULT_RELATIVE_SYMMETRY_THRESHOLD
* @see #DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD
*/
- public CholeskyDecompositionImpl(final RealMatrix matrix) {
+ public CholeskyDecomposition(final RealMatrix matrix) {
this(matrix, DEFAULT_RELATIVE_SYMMETRY_THRESHOLD,
DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD);
}
@@ -88,7 +101,7 @@ public class CholeskyDecompositionImpl i
* @see #DEFAULT_RELATIVE_SYMMETRY_THRESHOLD
* @see #DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD
*/
- public CholeskyDecompositionImpl(final RealMatrix matrix,
+ public CholeskyDecomposition(final RealMatrix matrix,
final double relativeSymmetryThreshold,
final double absolutePositivityThreshold) {
if (!matrix.isSquare()) {
@@ -142,7 +155,11 @@ public class CholeskyDecompositionImpl i
}
}
- /** {@inheritDoc} */
+ /**
+ * Returns the matrix L of the decomposition.
+ * <p>L is an lower-triangular matrix</p>
+ * @return the L matrix
+ */
public RealMatrix getL() {
if (cachedL == null) {
cachedL = getLT().transpose();
@@ -150,7 +167,11 @@ public class CholeskyDecompositionImpl i
return cachedL;
}
- /** {@inheritDoc} */
+ /**
+ * Returns the transpose of the matrix L of the decomposition.
+ * <p>L<sup>T</sup> is an upper-triangular matrix</p>
+ * @return the transpose of the matrix L of the decomposition
+ */
public RealMatrix getLT() {
if (cachedLT == null) {
@@ -161,7 +182,10 @@ public class CholeskyDecompositionImpl i
return cachedLT;
}
- /** {@inheritDoc} */
+ /**
+ * Return the determinant of the matrix
+ * @return determinant of the matrix
+ */
public double getDeterminant() {
double determinant = 1.0;
for (int i = 0; i < lTData.length; ++i) {
@@ -171,7 +195,10 @@ public class CholeskyDecompositionImpl i
return determinant;
}
- /** {@inheritDoc} */
+ /**
+ * Get a solver for finding the A × X = B solution in least square sense.
+ * @return a solver
+ */
public DecompositionSolver getSolver() {
return new Solver(lTData);
}
Copied: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionTest.java (from r1173475, commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionTest.java?p2=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionTest.java&p1=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java&r1=1173475&r2=1173481&rev=1173481&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionTest.java Wed Sep 21 03:45:37 2011
@@ -20,7 +20,7 @@ package org.apache.commons.math.linear;
import org.junit.Test;
import org.junit.Assert;
-public class CholeskyDecompositionImplTest {
+public class CholeskyDecompositionTest {
private double[][] testData = new double[][] {
{ 1, 2, 4, 7, 11 },
@@ -33,8 +33,8 @@ public class CholeskyDecompositionImplTe
/** test dimensions */
@Test
public void testDimensions() {
- CholeskyDecompositionImpl llt =
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData));
+ CholeskyDecomposition llt =
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(testData));
Assert.assertEquals(testData.length, llt.getL().getRowDimension());
Assert.assertEquals(testData.length, llt.getL().getColumnDimension());
Assert.assertEquals(testData.length, llt.getLT().getRowDimension());
@@ -44,7 +44,7 @@ public class CholeskyDecompositionImplTe
/** test non-square matrix */
@Test(expected = NonSquareMatrixException.class)
public void testNonSquare() {
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(new double[3][2]));
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[3][2]));
}
/** test non-symmetric matrix */
@@ -52,13 +52,13 @@ public class CholeskyDecompositionImplTe
public void testNotSymmetricMatrixException() {
double[][] changed = testData.clone();
changed[0][changed[0].length - 1] += 1.0e-5;
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(changed));
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(changed));
}
/** test non positive definite matrix */
@Test(expected = NonPositiveDefiniteMatrixException.class)
public void testNotPositiveDefinite() {
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(new double[][] {
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][] {
{ 14, 11, 13, 15, 24 },
{ 11, 34, 13, 8, 25 },
{ 13, 13, 14, 15, 21 },
@@ -69,7 +69,7 @@ public class CholeskyDecompositionImplTe
@Test(expected = NonPositiveDefiniteMatrixException.class)
public void testMath274() {
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(new double[][] {
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][] {
{ 0.40434286, -0.09376327, 0.30328980, 0.04909388 },
{-0.09376327, 0.10400408, 0.07137959, 0.04762857 },
{ 0.30328980, 0.07137959, 0.30458776, 0.04882449 },
@@ -82,7 +82,7 @@ public class CholeskyDecompositionImplTe
@Test
public void testAEqualLLT() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- CholeskyDecompositionImpl llt = new CholeskyDecompositionImpl(matrix);
+ CholeskyDecomposition llt = new CholeskyDecomposition(matrix);
RealMatrix l = llt.getL();
RealMatrix lt = llt.getLT();
double norm = l.multiply(lt).subtract(matrix).getNorm();
@@ -93,7 +93,7 @@ public class CholeskyDecompositionImplTe
@Test
public void testLLowerTriangular() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- RealMatrix l = new CholeskyDecompositionImpl(matrix).getL();
+ RealMatrix l = new CholeskyDecomposition(matrix).getL();
for (int i = 0; i < l.getRowDimension(); i++) {
for (int j = i + 1; j < l.getColumnDimension(); j++) {
Assert.assertEquals(0.0, l.getEntry(i, j), 0.0);
@@ -105,7 +105,7 @@ public class CholeskyDecompositionImplTe
@Test
public void testLTTransposed() {
RealMatrix matrix = MatrixUtils.createRealMatrix(testData);
- CholeskyDecompositionImpl llt = new CholeskyDecompositionImpl(matrix);
+ CholeskyDecomposition llt = new CholeskyDecomposition(matrix);
RealMatrix l = llt.getL();
RealMatrix lt = llt.getLT();
double norm = l.subtract(lt.transpose()).getNorm();
@@ -122,8 +122,8 @@ public class CholeskyDecompositionImplTe
{ 7, 8, 9, 10, 0 },
{ 11, 12, 13, 14, 15 }
});
- CholeskyDecompositionImpl llt =
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData));
+ CholeskyDecomposition llt =
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(testData));
// check values against known references
RealMatrix l = llt.getL();
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java?rev=1173481&r1=1173480&r2=1173481&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/CholeskySolverTest.java Wed Sep 21 03:45:37 2011
@@ -36,7 +36,7 @@ public class CholeskySolverTest {
@Test
public void testSolveDimensionErrors() {
DecompositionSolver solver =
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(testData)).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
try {
solver.solve(b);
@@ -62,7 +62,7 @@ public class CholeskySolverTest {
@Test
public void testSolve() {
DecompositionSolver solver =
- new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
+ new CholeskyDecomposition(MatrixUtils.createRealMatrix(testData)).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
{ 78, -13, 1 },
{ 414, -62, -1 },
@@ -106,7 +106,7 @@ public class CholeskySolverTest {
}
private double getDeterminant(RealMatrix m) {
- return new CholeskyDecompositionImpl(m).getDeterminant();
+ return new CholeskyDecomposition(m).getDeterminant();
}
}