/** * Get the inverse of the covariance. * <p>The inverse of the covariance matrix is lazily evaluated and cached.</p> * @return inverse of the covariance */ protected RealMatrix getOmegaInverse() { if (OmegaInverse == null) { OmegaInverse = new LUDecompositionImpl(Omega).getSolver().getInverse(); } return OmegaInverse; }
/** {@inheritDoc} */ @Deprecated public double getDeterminant() throws InvalidMatrixException { return new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getDeterminant(); }
/** * Get the inverse of the covariance. * <p>The inverse of the covariance matrix is lazily evaluated and cached.</p> * @return inverse of the covariance */ protected RealMatrix getOmegaInverse() { if (OmegaInverse == null) { OmegaInverse = new LUDecompositionImpl(Omega).getSolver().getInverse(); } return OmegaInverse; }
/** {@inheritDoc} */ @Deprecated public double getDeterminant() throws InvalidMatrixException { return new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getDeterminant(); }
/** {@inheritDoc} */ @Deprecated public RealMatrix inverse() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.getInverse(); }
/** {@inheritDoc} */ @Deprecated public double[] solve(final double[] b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); }
/** {@inheritDoc} */ @Deprecated public boolean isSingular() { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return !lu.isNonSingular(); }
/** {@inheritDoc} */ @Deprecated public RealMatrix solve(final RealMatrix b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); }
/** {@inheritDoc} */ @Deprecated public RealMatrix inverse() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.getInverse(); }
/** {@inheritDoc} */ @Deprecated public boolean isSingular() { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return !lu.isNonSingular(); }
/** {@inheritDoc} */ @Deprecated public double[] solve(final double[] b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); }
/** {@inheritDoc} */ @Deprecated public RealMatrix solve(final RealMatrix b) throws IllegalArgumentException, InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } return lu.solve(b); }
/** * Computes a new * <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf"> * LU decomposition</a> for this matrix, storing the result for use by other methods. * <p> * <strong>Implementation Note</strong>:<br> * Uses <a href="http://www.damtp.cam.ac.uk/user/fdl/people/sd/lectures/nummeth98/linear.htm"> * Crout's algorithm</a>, with partial pivoting.</p> * <p> * <strong>Usage Note</strong>:<br> * This method should rarely be invoked directly. Its only use is * to force recomputation of the LU decomposition when changes have been * made to the underlying data using direct array references. Changes * made using setXxx methods will trigger recomputation when needed * automatically.</p> * * @throws InvalidMatrixException if the matrix is non-square or singular. * @deprecated as of release 2.0, replaced by {@link LUDecomposition} */ @Deprecated public void luDecompose() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } }
/** * Computes a new * <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf"> * LU decomposition</a> for this matrix, storing the result for use by other methods. * <p> * <strong>Implementation Note</strong>:<br> * Uses <a href="http://www.damtp.cam.ac.uk/user/fdl/people/sd/lectures/nummeth98/linear.htm"> * Crout's algorithm</a>, with partial pivoting.</p> * <p> * <strong>Usage Note</strong>:<br> * This method should rarely be invoked directly. Its only use is * to force recomputation of the LU decomposition when changes have been * made to the underlying data using direct array references. Changes * made using setXxx methods will trigger recomputation when needed * automatically.</p> * * @throws InvalidMatrixException if the matrix is non-square or singular. * @deprecated as of release 2.0, replaced by {@link LUDecomposition} */ @Deprecated public void luDecompose() throws InvalidMatrixException { if (lu == null) { lu = new LUDecompositionImpl(this, MathUtils.SAFE_MIN).getSolver(); } }
public static double [] solveMatrix(double [][] coefficientMatrix,double [] rhsVector) { RealVector x = null; try { RealMatrix a = new Array2DRowRealMatrix(coefficientMatrix); RealVector b = new ArrayRealVector(rhsVector); DecompositionSolver solver = new LUDecompositionImpl(a).getSolver(); x = solver.solve(b); } catch(Exception e) { e.printStackTrace(); } double [] result; result=x.toArray(); return result; } }
/** * Calculates the variance on the beta. * <pre> * Var(b)=(X' Omega^-1 X)^-1 * </pre> * @return The beta variance matrix */ @Override protected RealMatrix calculateBetaVariance() { RealMatrix OI = getOmegaInverse(); RealMatrix XTOIX = X.transpose().multiply(OI).multiply(X); return new LUDecompositionImpl(XTOIX).getSolver().getInverse(); }
/** * Calculates the variance on the beta by GLS. * <pre> * Var(b)=(X' Omega^-1 X)^-1 * </pre> * @return The beta variance matrix */ @Override protected RealMatrix calculateBetaVariance() { RealMatrix OI = getOmegaInverse(); RealMatrix XTOIX = X.transpose().multiply(OI).multiply(X); return new LUDecompositionImpl(XTOIX).getSolver().getInverse(); }
private double[] solveLinearEquation( double[][] matrixA, double[] vectorb ) { RealMatrix coefficients = new Array2DRowRealMatrix( matrixA, false ); // LU-decomposition DecompositionSolver solver = new LUDecompositionImpl( coefficients ).getSolver(); RealVector constants = new ArrayRealVector( vectorb, false ); RealVector solution = null; try { solution = solver.solve( constants ); } catch ( SingularMatrixException e ) { LOG.error( e.getLocalizedMessage() ); e.printStackTrace(); } return solution.getData(); }
final double[][] invHess = new LUDecompositionImpl(new Array2DRowRealMatrix(hess)).getSolver().getInverse().getData(); for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) {
/** * <p>Calculates the variance-covariance matrix of the regression parameters. * </p> * <p>Var(b) = (X<sup>T</sup>X)<sup>-1</sup> * </p> * <p>Uses QR decomposition to reduce (X<sup>T</sup>X)<sup>-1</sup> * to (R<sup>T</sup>R)<sup>-1</sup>, with only the top p rows of * R included, where p = the length of the beta vector.</p> * * @return The beta variance-covariance matrix */ @Override 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(); return Rinv.multiply(Rinv.transpose()); }