/** * Computes the inverse of this diagonal matrix. * * @param threshold Singularity threshold. * @return the inverse of {@code m} * @throws SingularMatrixException if the matrix is singular * @since 3.3 */ public DiagonalMatrix inverse(double threshold) throws SingularMatrixException { if (isSingular(threshold)) { throw new SingularMatrixException(); } final double[] result = new double[data.length]; for (int i = 0; i < data.length; i++) { result[i] = 1.0 / data[i]; } return new DiagonalMatrix(result, false); }
/** * Get the inverse of the decomposed matrix. * * @return the inverse matrix. * @throws SingularMatrixException if the decomposed matrix is singular. */ public RealMatrix getInverse() { if (!isNonSingular()) { throw new SingularMatrixException(); } final int m = realEigenvalues.length; final double[][] invData = new double[m][m]; for (int i = 0; i < m; ++i) { final double[] invI = invData[i]; for (int j = 0; j < m; ++j) { double invIJ = 0; for (int k = 0; k < m; ++k) { final double[] vK = eigenvectors[k].getDataRef(); invIJ += vK[i] * vK[j] / realEigenvalues[k]; } invI[j] = invIJ; } } return MatrixUtils.createRealMatrix(invData); } }
final DecompositionSolver aSolver = aDec.getSolver(); if (!aSolver.isNonSingular()) { throw new SingularMatrixException(); final DecompositionSolver dSolver = dDec.getSolver(); if (!dSolver.isNonSingular()) { throw new SingularMatrixException(); final DecompositionSolver tmp1Solver = tmp1Dec.getSolver(); if (!tmp1Solver.isNonSingular()) { throw new SingularMatrixException(); final DecompositionSolver tmp2Solver = tmp2Dec.getSolver(); if (!tmp2Solver.isNonSingular()) { throw new SingularMatrixException();
private double partialCorrelation(Node x, Node y, List<Node> z) throws SingularMatrixException { if (z.isEmpty()) { double a = covMatrix.getValue(indexMap.get(x), indexMap.get(y)); double b = covMatrix.getValue(indexMap.get(x), indexMap.get(x)); double c = covMatrix.getValue(indexMap.get(y), indexMap.get(y)); if (b * c == 0) throw new SingularMatrixException(); return -a / Math.sqrt(b * c); } else { int[] indices = new int[z.size() + 2]; indices[0] = indexMap.get(x); indices[1] = indexMap.get(y); for (int i = 0; i < z.size(); i++) indices[i + 2] = indexMap.get(z.get(i)); TetradMatrix submatrix = covMatrix.getSubmatrix(indices).getMatrix(); return StatUtils.partialCorrelation(submatrix); } }
private double partialCorrelation(Node x, Node y, List<Node> z) throws SingularMatrixException { if (z.isEmpty()) { double a = covMatrix.getValue(indexMap.get(x), indexMap.get(y)); double b = covMatrix.getValue(indexMap.get(x), indexMap.get(x)); double c = covMatrix.getValue(indexMap.get(y), indexMap.get(y)); if (b * c == 0) throw new SingularMatrixException(); return -a / Math.sqrt(b * c); } else { int[] indices = new int[z.size() + 2]; indices[0] = indexMap.get(x); indices[1] = indexMap.get(y); for (int i = 0; i < z.size(); i++) indices[i + 2] = indexMap.get(z.get(i)); TetradMatrix submatrix = covMatrix.getSubmatrix(indices).getMatrix(); return StatUtils.partialCorrelation(submatrix); } }
/** * Computes the inverse of this diagonal matrix. * * @param threshold Singularity threshold. * @return the inverse of {@code m} * @throws SingularMatrixException if the matrix is singular * @since 3.3 */ public DiagonalMatrix inverse(double threshold) throws SingularMatrixException { if (isSingular(threshold)) { throw new SingularMatrixException(); } final double[] result = new double[data.length]; for (int i = 0; i < data.length; i++) { result[i] = 1.0 / data[i]; } return new DiagonalMatrix(result, false); }
/** * Computes the inverse of this diagonal matrix. * * @param threshold Singularity threshold. * @return the inverse of {@code m} * @throws SingularMatrixException if the matrix is singular * @since 3.3 */ public DiagonalMatrix inverse(double threshold) throws SingularMatrixException { if (isSingular(threshold)) { throw new SingularMatrixException(); } final double[] result = new double[data.length]; for (int i = 0; i < data.length; i++) { result[i] = 1.0 / data[i]; } return new DiagonalMatrix(result, false); }
/** * Get the inverse of the decomposed matrix. * * @return the inverse matrix. * @throws SingularMatrixException if the decomposed matrix is singular. */ public RealMatrix getInverse() { if (!isNonSingular()) { throw new SingularMatrixException(); } final int m = realEigenvalues.length; final double[][] invData = new double[m][m]; for (int i = 0; i < m; ++i) { final double[] invI = invData[i]; for (int j = 0; j < m; ++j) { double invIJ = 0; for (int k = 0; k < m; ++k) { final double[] vK = eigenvectors[k].getDataRef(); invIJ += vK[i] * vK[j] / realEigenvalues[k]; } invI[j] = invIJ; } } return MatrixUtils.createRealMatrix(invData); } }
/** * Get the inverse of the decomposed matrix. * * @return the inverse matrix. * @throws SingularMatrixException if the decomposed matrix is singular. */ public RealMatrix getInverse() { if (!isNonSingular()) { throw new SingularMatrixException(); } final int m = realEigenvalues.length; final double[][] invData = new double[m][m]; for (int i = 0; i < m; ++i) { final double[] invI = invData[i]; for (int j = 0; j < m; ++j) { double invIJ = 0; for (int k = 0; k < m; ++k) { final double[] vK = eigenvectors[k].getDataRef(); invIJ += vK[i] * vK[j] / realEigenvalues[k]; } invI[j] = invIJ; } } return MatrixUtils.createRealMatrix(invData); } }
/** * Get the inverse of the decomposed matrix. * * @return the inverse matrix. * @throws SingularMatrixException if the decomposed matrix is singular. */ public RealMatrix getInverse() { if (!isNonSingular()) { throw new SingularMatrixException(); } final int m = realEigenvalues.length; final double[][] invData = new double[m][m]; for (int i = 0; i < m; ++i) { final double[] invI = invData[i]; for (int j = 0; j < m; ++j) { double invIJ = 0; for (int k = 0; k < m; ++k) { final double[] vK = eigenvectors[k].getDataRef(); invIJ += vK[i] * vK[j] / realEigenvalues[k]; } invI[j] = invIJ; } } return MatrixUtils.createRealMatrix(invData); } }