/** * 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); }
g6 = guttmanLambda6.value(); }catch(SingularMatrixException ex){ ex.printStackTrace();
private void outputResult() { output = new StringBuilder(); printDoubleArray("expectedPosition: ", expectedPosition); printDoubleArray("linear calculatedPosition: ", linearCalculatedPosition.toArray()); printDoubleArray("non-linear calculatedPosition: ", nonLinearOptimum.getPoint().toArray()); output.append("numberOfIterations: ").append(nonLinearOptimum.getIterations()).append("\n"); output.append("numberOfEvaluations: ").append(nonLinearOptimum.getEvaluations()).append("\n"); try { RealVector standardDeviation = nonLinearOptimum.getSigma(0); printDoubleArray("standardDeviation: ", standardDeviation.toArray()); output.append("Norm of deviation: ").append(standardDeviation.getNorm()).append("\n"); RealMatrix covarianceMatrix = nonLinearOptimum.getCovariances(0); output.append("covarianceMatrix: ").append(covarianceMatrix).append("\n"); } catch (SingularMatrixException e) { System.err.println(e.getMessage()); } System.out.println(output.toString()); }
/** * Computes the standard errors of the item parameter estimates. * * @param x array of item parameter estimates * @return array of item parameter standard errors */ public double[] stdError(double[] x, double[][] hessian){ double[] se = new double[x.length]; try{ // RealMatrix m = new Array2DRowRealMatrix(numericHessian(x)); RealMatrix m = new Array2DRowRealMatrix(hessian); RealMatrix info = new LUDecomposition(m).getSolver().getInverse(); for(int i=0;i<info.getRowDimension();i++){ se[i] = Math.sqrt(info.getEntry(i,i)); } }catch(SingularMatrixException ex){ for(int i=0;i<se.length;i++){ se[i] = Double.NaN; } ex.printStackTrace(); } return se; }
/** * 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); } }