removed all external decomposition solvers
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@731335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e6d73f239
commit
6aa3cd95c3
|
@ -21,7 +21,6 @@ import java.util.Arrays;
|
|||
|
||||
import org.apache.commons.math.linear.InvalidMatrixException;
|
||||
import org.apache.commons.math.linear.LUDecompositionImpl;
|
||||
import org.apache.commons.math.linear.LUSolver;
|
||||
import org.apache.commons.math.linear.MatrixUtils;
|
||||
import org.apache.commons.math.linear.RealMatrix;
|
||||
|
||||
|
@ -183,7 +182,7 @@ public abstract class AbstractEstimator implements Estimator {
|
|||
try {
|
||||
// compute the covariances matrix
|
||||
RealMatrix inverse =
|
||||
new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj))).getInverse();
|
||||
new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj)).getSolver().getInverse();
|
||||
return inverse.getData();
|
||||
} catch (InvalidMatrixException ime) {
|
||||
throw new EstimationException("unable to compute covariances: singular problem",
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.io.Serializable;
|
|||
|
||||
import org.apache.commons.math.linear.InvalidMatrixException;
|
||||
import org.apache.commons.math.linear.LUDecompositionImpl;
|
||||
import org.apache.commons.math.linear.LUSolver;
|
||||
import org.apache.commons.math.linear.MatrixUtils;
|
||||
import org.apache.commons.math.linear.RealMatrix;
|
||||
import org.apache.commons.math.linear.RealVector;
|
||||
|
@ -152,7 +151,7 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa
|
|||
try {
|
||||
|
||||
// solve the linearized least squares problem
|
||||
RealVector dX = new LUSolver(new LUDecompositionImpl(a)).solve(b);
|
||||
RealVector dX = new LUDecompositionImpl(a).getSolver().solve(b);
|
||||
|
||||
// update the estimated parameters
|
||||
for (int i = 0; i < parameters.length; ++i) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
/** Cached LU solver.
|
||||
* @deprecated as of release 2.0, since all methods using this are deprecated
|
||||
*/
|
||||
private LUSolver lu;
|
||||
private DecompositionSolver lu;
|
||||
|
||||
/**
|
||||
* Creates a matrix with no data
|
||||
|
@ -657,7 +657,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
public RealMatrix inverse()
|
||||
throws InvalidMatrixException {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver();
|
||||
}
|
||||
return lu.getInverse();
|
||||
}
|
||||
|
@ -666,10 +666,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
@Deprecated
|
||||
public double getDeterminant()
|
||||
throws InvalidMatrixException {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
}
|
||||
return lu.getDeterminant();
|
||||
return new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getDeterminant();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -681,7 +678,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
@Deprecated
|
||||
public boolean isSingular() {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver();
|
||||
}
|
||||
return !lu.isNonSingular();
|
||||
}
|
||||
|
@ -985,7 +982,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
public double[] solve(final double[] b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver();
|
||||
}
|
||||
return lu.solve(b);
|
||||
}
|
||||
|
@ -995,7 +992,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver();
|
||||
}
|
||||
return lu.solve(b);
|
||||
}
|
||||
|
@ -1023,7 +1020,7 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
|||
public void luDecompose()
|
||||
throws InvalidMatrixException {
|
||||
if (lu == null) {
|
||||
lu = new LUSolver(new LUDecompositionImpl(this, MathUtils.SAFE_MIN));
|
||||
lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
|
||||
/**
|
||||
* Solver using eigen decomposition to solve A × X = B for symmetric matrices A.
|
||||
* <p>This class finds only exact linear solution, i.e. when
|
||||
* ||A × X - B|| is exactly 0.</p>
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class EigenSolver implements DecompositionSolver {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -74798755223915020L;
|
||||
|
||||
/** Underlying solver. */
|
||||
private final DecompositionSolver solver;
|
||||
|
||||
/** Determinant. */
|
||||
private final double determinant;
|
||||
|
||||
/**
|
||||
* Simple constructor.
|
||||
* @param decomposition decomposition to use
|
||||
*/
|
||||
public EigenSolver(final EigenDecomposition decomposition) {
|
||||
this.solver = decomposition.getSolver();
|
||||
this.determinant = decomposition.getDeterminant();
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B for symmetric matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public double[] solve(final double[] b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B for symmetric matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealVector solve(final RealVector b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B for symmetric matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a matrix X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the determinant of the matrix
|
||||
* @return determinant of the matrix
|
||||
* @see #isNonSingular()
|
||||
*/
|
||||
public double getDeterminant() {
|
||||
return determinant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the decomposed matrix is non-singular.
|
||||
* @return true if the decomposed matrix is non-singular
|
||||
*/
|
||||
public boolean isNonSingular() {
|
||||
return solver.isNonSingular();
|
||||
}
|
||||
|
||||
/** Get the inverse of the decomposed matrix.
|
||||
* @return inverse matrix
|
||||
* @throws InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix getInverse()
|
||||
throws InvalidMatrixException {
|
||||
return solver.getInverse();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
|
||||
/**
|
||||
* Solver using LU decomposition to solve A × X = B for square matrices A.
|
||||
* <p>This class finds only exact linear solution, i.e. when
|
||||
* ||A × X - B|| is exactly 0.</p>
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class LUSolver implements DecompositionSolver {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -369589527412301256L;
|
||||
|
||||
/** Underlying solver. */
|
||||
private final DecompositionSolver solver;
|
||||
|
||||
/** Determinant. */
|
||||
private final double determinant;
|
||||
|
||||
/**
|
||||
* Simple constructor.
|
||||
* @param decomposition decomposition to use
|
||||
*/
|
||||
public LUSolver(final LUDecomposition decomposition) {
|
||||
this.solver = decomposition.getSolver();
|
||||
this.determinant = decomposition.getDeterminant();
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B for square matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public double[] solve(final double[] b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
|
||||
/** Solve the linear equation A × X = B for square matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealVector solve(final RealVector b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B for square matrices A.
|
||||
* <p>This method only find exact linear solutions, i.e. solutions for
|
||||
* which ||A × X - B|| is exactly 0.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a matrix X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the decomposed matrix is non-singular.
|
||||
* @return true if the decomposed matrix is non-singular
|
||||
*/
|
||||
public boolean isNonSingular() {
|
||||
return solver.isNonSingular();
|
||||
}
|
||||
|
||||
/** Get the inverse of the decomposed matrix.
|
||||
* @return inverse matrix
|
||||
* @throws InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix getInverse()
|
||||
throws InvalidMatrixException {
|
||||
return solver.getInverse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the determinant of the matrix
|
||||
* @return determinant of the matrix
|
||||
*/
|
||||
public double getDeterminant() {
|
||||
return determinant;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
|
||||
/**
|
||||
* Class using QR decomposition to solve A × X = B in least square sense
|
||||
* for any matrices A.
|
||||
* <p>This class solve A × X = B in least squares sense: it finds X
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class QRSolver implements DecompositionSolver {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -446230688570372107L;
|
||||
|
||||
/** Underlying decomposition. */
|
||||
private final DecompositionSolver solver;
|
||||
|
||||
/**
|
||||
* Simple constructor.
|
||||
* @param decomposition decomposition to use
|
||||
*/
|
||||
public QRSolver(final QRDecomposition decomposition) {
|
||||
this.solver = decomposition.getSolver();
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public double[] solve(final double[] b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealVector solve(final RealVector b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a matrix X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the decomposed matrix is non-singular.
|
||||
* @return true if the decomposed matrix is non-singular
|
||||
*/
|
||||
public boolean isNonSingular() {
|
||||
return solver.isNonSingular();
|
||||
}
|
||||
|
||||
/** Get the pseudo-inverse of the decomposed matrix.
|
||||
* @return inverse matrix
|
||||
* @throws InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix getInverse()
|
||||
throws InvalidMatrixException {
|
||||
return solver.getInverse();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
|
||||
/**
|
||||
* Class using singular value decomposition decomposition to solve A ×
|
||||
* X = B in least square sense for any matrices A.
|
||||
* <p>This class solve A × X = B in least squares sense: it finds X
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
*
|
||||
* @version $Revision: 723496 $ $Date: 2008-12-05 00:48:18 +0100 (ven., 05 déc. 2008) $
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SingularValueSolver implements DecompositionSolver {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 4388219358640335388L;
|
||||
|
||||
/** Underlying solver. */
|
||||
private final DecompositionSolver solver;
|
||||
|
||||
/**
|
||||
* Simple constructor.
|
||||
* @param decomposition decomposition to use
|
||||
*/
|
||||
public SingularValueSolver(final SingularValueDecomposition decomposition) {
|
||||
this.solver = decomposition.getSolver();
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public double[] solve(final double[] b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a vector X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealVector solve(final RealVector b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/** Solve the linear equation A × X = B in least square sense.
|
||||
* <p>The m×n matrix A may not be square, the solution X is
|
||||
* such that ||A × X - B|| is minimal.</p>
|
||||
* @param b right-hand side of the equation A × X = B
|
||||
* @return a matrix X that minimizes the two norm of A × X - B
|
||||
* @exception IllegalArgumentException if matrices dimensions don't match
|
||||
* @exception InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix solve(final RealMatrix b)
|
||||
throws IllegalArgumentException, InvalidMatrixException {
|
||||
return solver.solve(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the decomposed matrix is non-singular.
|
||||
* @return true if the decomposed matrix is non-singular
|
||||
*/
|
||||
public boolean isNonSingular() {
|
||||
return solver.isNonSingular();
|
||||
}
|
||||
|
||||
/** Get the pseudo-inverse of the decomposed matrix.
|
||||
* @return inverse matrix
|
||||
* @throws InvalidMatrixException if decomposed matrix is singular
|
||||
*/
|
||||
public RealMatrix getInverse()
|
||||
throws InvalidMatrixException {
|
||||
return solver.getInverse();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.commons.math.stat.regression;
|
||||
|
||||
import org.apache.commons.math.linear.LUDecompositionImpl;
|
||||
import org.apache.commons.math.linear.LUSolver;
|
||||
import org.apache.commons.math.linear.RealMatrix;
|
||||
import org.apache.commons.math.linear.RealMatrixImpl;
|
||||
|
||||
|
@ -109,7 +108,7 @@ public class GLSMultipleLinearRegression extends AbstractMultipleLinearRegressio
|
|||
protected RealMatrix calculateBetaVariance() {
|
||||
RealMatrix OI = getOmegaInverse();
|
||||
RealMatrix XTOIX = X.transpose().multiply(OI).multiply(X);
|
||||
return new LUSolver(new LUDecompositionImpl(XTOIX)).getInverse();
|
||||
return new LUDecompositionImpl(XTOIX).getSolver().getInverse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -460,7 +460,7 @@ public final class DenseRealMatrixTest extends TestCase {
|
|||
assertEquals(2, p.getRowDimension());
|
||||
assertEquals(2, p.getColumnDimension());
|
||||
// Invert p
|
||||
RealMatrix pInverse = new LUSolver(new LUDecompositionImpl(p)).getInverse();
|
||||
RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
|
||||
assertEquals(2, pInverse.getRowDimension());
|
||||
assertEquals(2, pInverse.getColumnDimension());
|
||||
|
||||
|
@ -468,7 +468,7 @@ public final class DenseRealMatrixTest extends TestCase {
|
|||
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
|
||||
RealMatrix coefficients = new DenseRealMatrix(coefficientsData);
|
||||
double[] constants = {1, -2, 1};
|
||||
double[] solution = new LUSolver(new LUDecompositionImpl(coefficients)).solve(constants);
|
||||
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
|
||||
assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12);
|
||||
assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1], 1E-12);
|
||||
assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class EigenSolverTest extends TestCase {
|
|||
Random r = new Random(9994100315209l);
|
||||
RealMatrix m =
|
||||
EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
|
||||
EigenSolver es = new EigenSolver(new EigenDecompositionImpl(m, MathUtils.SAFE_MIN));
|
||||
DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
|
||||
assertFalse(es.isNonSingular());
|
||||
try {
|
||||
es.getInverse();
|
||||
|
@ -62,7 +62,7 @@ public class EigenSolverTest extends TestCase {
|
|||
Random r = new Random(9994100315209l);
|
||||
RealMatrix m =
|
||||
EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.5, -1.0, -2.0, -3.0 });
|
||||
EigenSolver es = new EigenSolver(new EigenDecompositionImpl(m, MathUtils.SAFE_MIN));
|
||||
DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
|
||||
assertTrue(es.isNonSingular());
|
||||
RealMatrix inverse = es.getInverse();
|
||||
RealMatrix error =
|
||||
|
@ -72,7 +72,7 @@ public class EigenSolverTest extends TestCase {
|
|||
|
||||
/** test solve dimension errors */
|
||||
public void testSolveDimensionErrors() {
|
||||
EigenSolver es = new EigenSolver(new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN));
|
||||
DecompositionSolver es = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
|
||||
try {
|
||||
es.solve(b);
|
||||
|
@ -110,8 +110,7 @@ public class EigenSolverTest extends TestCase {
|
|||
{ 40, 2, 21, 9, 51, 19 },
|
||||
{ 14, -1, 8, 0, 19, 14 }
|
||||
});
|
||||
EigenSolver es = new EigenSolver(new EigenDecompositionImpl(m, MathUtils.SAFE_MIN));
|
||||
assertEquals(184041, es.getDeterminant(), 2.0e-8);
|
||||
DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
|
||||
{ 1561, 269, 188 },
|
||||
{ 69, -21, 70 },
|
||||
|
|
|
@ -62,25 +62,25 @@ public class LUSolverTest extends TestCase {
|
|||
{ 2.0, 5.0, 3.0},
|
||||
{ 4.000001, 9.0, 9.0}
|
||||
});
|
||||
assertFalse(new LUSolver(new LUDecompositionImpl(matrix, 1.0e-5)).isNonSingular());
|
||||
assertTrue(new LUSolver(new LUDecompositionImpl(matrix, 1.0e-10)).isNonSingular());
|
||||
assertFalse(new LUDecompositionImpl(matrix, 1.0e-5).getSolver().isNonSingular());
|
||||
assertTrue(new LUDecompositionImpl(matrix, 1.0e-10).getSolver().isNonSingular());
|
||||
}
|
||||
|
||||
/** test singular */
|
||||
public void testSingular() {
|
||||
LUSolver lu =
|
||||
new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
|
||||
assertTrue(lu.isNonSingular());
|
||||
lu = new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)));
|
||||
assertFalse(lu.isNonSingular());
|
||||
lu = new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular)));
|
||||
assertFalse(lu.isNonSingular());
|
||||
DecompositionSolver solver =
|
||||
new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
|
||||
assertTrue(solver.isNonSingular());
|
||||
solver = new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)).getSolver();
|
||||
assertFalse(solver.isNonSingular());
|
||||
solver = new LUDecompositionImpl(MatrixUtils.createRealMatrix(bigSingular)).getSolver();
|
||||
assertFalse(solver.isNonSingular());
|
||||
}
|
||||
|
||||
/** test solve dimension errors */
|
||||
public void testSolveDimensionErrors() {
|
||||
LUSolver solver =
|
||||
new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
|
||||
DecompositionSolver solver =
|
||||
new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
|
||||
try {
|
||||
solver.solve(b);
|
||||
|
@ -110,8 +110,8 @@ public class LUSolverTest extends TestCase {
|
|||
|
||||
/** test solve singularity errors */
|
||||
public void testSolveSingularityErrors() {
|
||||
LUSolver solver =
|
||||
new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)));
|
||||
DecompositionSolver solver =
|
||||
new LUDecompositionImpl(MatrixUtils.createRealMatrix(singular)).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
|
||||
try {
|
||||
solver.solve(b);
|
||||
|
@ -149,8 +149,8 @@ public class LUSolverTest extends TestCase {
|
|||
|
||||
/** test solve */
|
||||
public void testSolve() {
|
||||
LUSolver solver =
|
||||
new LUSolver(new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)));
|
||||
DecompositionSolver solver =
|
||||
new LUDecompositionImpl(MatrixUtils.createRealMatrix(testData)).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
|
||||
{ 1, 0 }, { 2, -5 }, { 3, 1 }
|
||||
});
|
||||
|
@ -195,7 +195,7 @@ public class LUSolverTest extends TestCase {
|
|||
}
|
||||
|
||||
private double getDeterminant(RealMatrix m) {
|
||||
return new LUSolver(new LUDecompositionImpl(m)).getDeterminant();
|
||||
return new LUDecompositionImpl(m).getDeterminant();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,8 +269,8 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
/** test transpose */
|
||||
public void testTranspose() {
|
||||
RealMatrix m = new RealMatrixImpl(testData);
|
||||
RealMatrix mIT = new LUSolver(new LUDecompositionImpl(m)).getInverse().transpose();
|
||||
RealMatrix mTI = new LUSolver(new LUDecompositionImpl(m.transpose())).getInverse();
|
||||
RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
|
||||
RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
|
||||
assertClose("inverse-transpose", mIT, mTI, normTolerance);
|
||||
m = new RealMatrixImpl(testData2);
|
||||
RealMatrix mt = new RealMatrixImpl(testData2T);
|
||||
|
@ -360,7 +360,7 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
assertEquals(2, p.getRowDimension());
|
||||
assertEquals(2, p.getColumnDimension());
|
||||
// Invert p
|
||||
RealMatrix pInverse = new LUSolver(new LUDecompositionImpl(p)).getInverse();
|
||||
RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
|
||||
assertEquals(2, pInverse.getRowDimension());
|
||||
assertEquals(2, pInverse.getColumnDimension());
|
||||
|
||||
|
@ -368,7 +368,7 @@ public final class RealMatrixImplTest extends TestCase {
|
|||
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
|
||||
RealMatrix coefficients = new RealMatrixImpl(coefficientsData);
|
||||
double[] constants = {1, -2, 1};
|
||||
double[] solution = new LUSolver(new LUDecompositionImpl(coefficients)).solve(constants);
|
||||
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
|
||||
assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12);
|
||||
assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1], 1E-12);
|
||||
assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12);
|
||||
|
|
|
@ -42,8 +42,8 @@ public class SingularValueSolverTest extends TestCase {
|
|||
|
||||
/** test solve dimension errors */
|
||||
public void testSolveDimensionErrors() {
|
||||
SingularValueSolver solver =
|
||||
new SingularValueSolver(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)));
|
||||
DecompositionSolver solver =
|
||||
new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[3][2]);
|
||||
try {
|
||||
solver.solve(b);
|
||||
|
@ -78,7 +78,7 @@ public class SingularValueSolverTest extends TestCase {
|
|||
{ 1.0, 0.0 },
|
||||
{ 0.0, 0.0 }
|
||||
});
|
||||
SingularValueSolver solver = new SingularValueSolver(new SingularValueDecompositionImpl(m));
|
||||
DecompositionSolver solver = new SingularValueDecompositionImpl(m).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
|
||||
try {
|
||||
solver.solve(b);
|
||||
|
@ -116,8 +116,8 @@ public class SingularValueSolverTest extends TestCase {
|
|||
|
||||
/** test solve */
|
||||
public void testSolve() {
|
||||
SingularValueSolver solver =
|
||||
new SingularValueSolver(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)));
|
||||
DecompositionSolver solver =
|
||||
new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getSolver();
|
||||
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
|
||||
{ 1, 2, 3 }, { 0, -5, 1 }
|
||||
});
|
||||
|
|
|
@ -277,8 +277,8 @@ public final class SparseRealMatrixTest extends TestCase {
|
|||
public void testTranspose() {
|
||||
|
||||
RealMatrix m = createSparseMatrix(testData);
|
||||
RealMatrix mIT = new LUSolver(new LUDecompositionImpl(m)).getInverse().transpose();
|
||||
RealMatrix mTI = new LUSolver(new LUDecompositionImpl(m.transpose())).getInverse();
|
||||
RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
|
||||
RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
|
||||
assertClose("inverse-transpose", mIT, mTI, normTolerance);
|
||||
m = createSparseMatrix(testData2);
|
||||
RealMatrix mt = createSparseMatrix(testData2T);
|
||||
|
@ -368,7 +368,7 @@ public final class SparseRealMatrixTest extends TestCase {
|
|||
assertEquals(2, p.getRowDimension());
|
||||
assertEquals(2, p.getColumnDimension());
|
||||
// Invert p
|
||||
RealMatrix pInverse = new LUSolver(new LUDecompositionImpl(p)).getInverse();
|
||||
RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
|
||||
assertEquals(2, pInverse.getRowDimension());
|
||||
assertEquals(2, pInverse.getColumnDimension());
|
||||
|
||||
|
@ -377,7 +377,7 @@ public final class SparseRealMatrixTest extends TestCase {
|
|||
{ 4, -3, -5 } };
|
||||
RealMatrix coefficients = createSparseMatrix(coefficientsData);
|
||||
double[] constants = { 1, -2, 1 };
|
||||
double[] solution = new LUSolver(new LUDecompositionImpl(coefficients)).solve(constants);
|
||||
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
|
||||
assertEquals(2 * solution[0] + 3 * solution[1] - 2 * solution[2],
|
||||
constants[0], 1E-12);
|
||||
assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2],
|
||||
|
|
Loading…
Reference in New Issue