@Override public void invert(T A_inv) { alg.invert(A_inv); }
/** * Creates a block matrix the same size as A_inv, inverts the matrix and copies the results back * onto A_inv. * * @param A_inv Where the inverted matrix saved. Modified. */ @Override public void invert(DMatrixRMaj A_inv) { blockB.reshape(A_inv.numRows,A_inv.numCols,false); alg.invert(blockB); MatrixOps_DDRB.convert(blockB,A_inv); }
/** * Precomputes the parts of the likelihood functions which can be. Matrix inversion and determinant are the * main parts. */ public void setGaussian(GaussianGmm_F64 gaussian) { this.gaussian = gaussian; if (!solver.setA(gaussian.covariance)) { valid = false; return; } else { valid = true; } solver.invert(invCov); CholeskyDecomposition_F64<DMatrixRMaj> decomposition = solver.getDecomposition(); double det = decomposition.computeDeterminant().real; // (2*PI)^(D/2) has been omitted since it's the same for all the Gaussians and will get normalized out leftSide = 1.0 / Math.sqrt(det); }
/** * Precomputes the parts of the likelihood functions which can be. Matrix inversion and determinant are the * main parts. */ public void setGaussian(GaussianGmm_F64 gaussian) { this.gaussian = gaussian; if (!solver.setA(gaussian.covariance)) { valid = false; return; } else { valid = true; } solver.invert(invCov); CholeskyDecomposition_F64<DMatrixRMaj> decomposition = solver.getDecomposition(); double det = decomposition.computeDeterminant().real; // (2*PI)^(D/2) has been omitted since it's the same for all the Gaussians and will get normalized out leftSide = 1.0 / Math.sqrt(det); }
/** * <p> * Performs a matrix inversion operation on the specified matrix and stores the results * in the same matrix.<br> * <br> * a = a<sup>-1</sup> * </p> * * <p> * If the algorithm could not invert the matrix then false is returned. If it returns true * that just means the algorithm finished. The results could still be bad * because the matrix is singular or nearly singular. * </p> * * @param A The matrix that is to be inverted. Results are stored here. Modified. * @return true if it could invert the matrix false if it could not. */ public static boolean invert( CMatrixRMaj A ) { LinearSolverDense<CMatrixRMaj> solver = LinearSolverFactory_CDRM.lu(A.numRows); if( solver.setA(A) ) { solver.invert(A); } else { return false; } return true; }
/** * <p> * Computes the Moore-Penrose pseudo-inverse:<br> * <br> * pinv(A) = (A<sup>T</sup>A)<sup>-1</sup> A<sup>T</sup><br> * or<br> * pinv(A) = A<sup>T</sup>(AA<sup>T</sup>)<sup>-1</sup><br> * </p> * <p> * Internally it uses {@link SolvePseudoInverseSvd_DDRM} to compute the inverse. For performance reasons, this should only * be used when a matrix is singular or nearly singular. * </p> * @param A A m by n Matrix. Not modified. * @param invA Where the computed pseudo inverse is stored. n by m. Modified. */ public static void pinv(DMatrixRMaj A , DMatrixRMaj invA ) { LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.pseudoInverse(true); if( solver.modifiesA()) A = A.copy(); if( !solver.setA(A) ) throw new IllegalArgumentException("Invert failed, maybe a bug?"); solver.invert(invA); }
/** * Performs a matrix inversion operations that takes advantage of the special * properties of a covariance matrix. * * @param cov A covariance matrix. Not modified. * @param cov_inv The inverse of cov. Modified. * @return true if it could invert the matrix false if it could not. */ public static boolean invert(final DMatrixRMaj cov , final DMatrixRMaj cov_inv ) { if( cov.numCols <= 4 ) { if( cov.numCols != cov.numRows ) { throw new IllegalArgumentException("Must be a square matrix."); } if( cov.numCols >= 2 ) UnrolledInverseFromMinor_DDRM.inv(cov,cov_inv); else cov_inv.data[0] = 1.0/cov.data[0]; } else { LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.symmPosDef(cov.numRows); // wrap it to make sure the covariance is not modified. solver = new LinearSolverSafe<DMatrixRMaj>(solver); if( !solver.setA(cov) ) return false; solver.invert(cov_inv); } return true; }
solver.invert(output); return true;
/** * Creates a random distribution with the specified mean and covariance. The references * to the variables are not saved, their value are copied. * * @param rand Used to create the random numbers for the draw. * @param mean If not null this will be the mean of the distribution, if null then nothing is assigned. * this is useful if someone is being anal about performance and will soon call assignMean() * @param cov The covariance of the distribution */ public MultivariateGaussianDraw( Random rand , DMatrixRMaj mean , DMatrixRMaj cov ) { if( mean != null ) this.mean = new DMatrixRMaj(mean); else this.mean = new DMatrixRMaj(cov.numCols,1); r = new DMatrixRMaj(cov.numRows,1); Q_inv = new DMatrixRMaj(cov.numRows,cov.numCols); solver = LinearSolverFactory_DDRM.chol(cov.numRows); // will invoke decompose in cholesky solver.setA(cov); CholeskyDecomposition<DMatrixRMaj> chol = solver.getDecomposition(); A = chol.getT(null); solver.invert(Q_inv); likelihoodLeft = Math.pow(Math.PI*2,-this.mean.numRows/2.0)*Math.sqrt(CommonOps_DDRM.det(cov)); this.rand = rand; }
/** * Creates a random distribution with the specified mean and covariance. The references * to the variables are not saved, their value are copied. * * @param rand Used to create the random numbers for the draw. * @param mean If not null this will be the mean of the distribution, if null then nothing is assigned. * this is useful if someone is being anal about performance and will soon call assignMean() * @param cov The covariance of the distribution */ public MultivariateGaussianDraw( Random rand , DMatrixRMaj mean , DMatrixRMaj cov ) { if( mean != null ) this.mean = new DMatrixRMaj(mean); else this.mean = new DMatrixRMaj(cov.numCols,1); r = new DMatrixRMaj(cov.numRows,1); Q_inv = new DMatrixRMaj(cov.numRows,cov.numCols); solver = LinearSolverFactory_DDRM.chol(cov.numRows); // will invoke decompose in cholesky solver.setA(cov); CholeskyDecomposition<DMatrixRMaj> chol = solver.getDecomposition(); A = chol.getT(null); solver.invert(Q_inv); likelihoodLeft = Math.pow(Math.PI*2,-this.mean.numRows/2.0)*Math.sqrt(CommonOps_DDRM.det(cov)); this.rand = rand; }
solver.invert(result);
solverPinv.invert(A_temp);
solver.invert(A_inv);