/** * Returns the current error covariance matrix. * * @return the error covariance matrix */ public double[][] getErrorCovariance() { return errorCovariance.getData(); }
/** * Get the tableau data. * @return tableau data */ protected final double[][] getData() { return tableau.getData(); }
/** * {@inheritDoc} */ public double[][] estimateRegressionParametersVariance() { return calculateBetaVariance().getData(); }
/** * Update the jacobian matrix. * * @throws DimensionMismatchException if the Jacobian dimension does not * match problem dimension. * @deprecated As of 3.1. Please use {@link #computeWeightedJacobian(double[])} * instead. */ @Deprecated protected void updateJacobian() { final RealMatrix weightedJacobian = computeWeightedJacobian(point); weightedResidualJacobian = weightedJacobian.scalarMultiply(-1).getData(); }
protected double[][] evaluate(double[][] d1) throws EvaluationException { Array2DRowRealMatrix temp = new Array2DRowRealMatrix(d1); return temp.transpose().getData(); } };
/** * Gets the square root of each element on the diagonal of the covariance * matrix. * * @return the standard deviations. */ public double[] getStandardDeviations() { final int dim = getDimension(); final double[] std = new double[dim]; final double[][] s = covarianceMatrix.getData(); for (int i = 0; i < dim; i++) { std[i] = FastMath.sqrt(s[i][i]); } return std; }
protected double[][] evaluate(double[][] d1) throws EvaluationException { if (d1.length != d1[0].length) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } Array2DRowRealMatrix temp = new Array2DRowRealMatrix(d1); return MatrixUtils.inverse(temp).getData(); } };
/** * Build a solver from decomposed matrix. * * @param singularValues Singular values. * @param uT U<sup>T</sup> matrix of the decomposition. * @param v V matrix of the decomposition. * @param nonSingular Singularity indicator. * @param tol tolerance for singular values */ private Solver(final double[] singularValues, final RealMatrix uT, final RealMatrix v, final boolean nonSingular, final double tol) { final double[][] suT = uT.getData(); for (int i = 0; i < singularValues.length; ++i) { final double a; if (singularValues[i] > tol) { a = 1 / singularValues[i]; } else { a = 0; } final double[] suTi = suT[i]; for (int j = 0; j < suTi.length; ++j) { suTi[j] *= a; } } pseudoInverse = v.multiply(new Array2DRowRealMatrix(suT, false)); this.nonSingular = nonSingular; }
/** * Build the transformation to Schur form of a general real matrix. * * @param matrix matrix to transform * @throws NonSquareMatrixException if the matrix is not square */ SchurTransformer(final RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } HessenbergTransformer transformer = new HessenbergTransformer(matrix); matrixT = transformer.getH().getData(); matrixP = transformer.getP().getData(); cachedT = null; cachedP = null; cachedPt = null; // transform matrix transform(); }
/** * Build the transformation to bi-diagonal shape of a matrix. * @param matrix the matrix to transform. */ BiDiagonalTransformer(RealMatrix matrix) { final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); final int p = FastMath.min(m, n); householderVectors = matrix.getData(); main = new double[p]; secondary = new double[p - 1]; cachedU = null; cachedB = null; cachedV = null; // transform matrix if (m >= n) { transformToUpperBiDiagonal(); } else { transformToLowerBiDiagonal(); } }
/** * Calculates the QR-decomposition of the given matrix. * * @param matrix The matrix to decompose. * @param threshold Singularity threshold. */ public QRDecomposition(RealMatrix matrix, double threshold) { this.threshold = threshold; final int m = matrix.getRowDimension(); final int n = matrix.getColumnDimension(); qrt = matrix.transpose().getData(); rDiag = new double[FastMath.min(m, n)]; cachedQ = null; cachedQT = null; cachedR = null; cachedH = null; decompose(qrt); }
/** * Transforms the matrix to Schur form and calculates the eigenvalues. * * @param matrix Matrix to transform. * @return the {@link SchurTransformer Shur transform} for this matrix */ private SchurTransformer transformToSchur(final RealMatrix matrix) { final SchurTransformer schurTransform = new SchurTransformer(matrix); final double[][] matT = schurTransform.getT().getData(); realEigenvalues = new double[matT.length]; imagEigenvalues = new double[matT.length]; for (int i = 0; i < realEigenvalues.length; i++) { if (i == (realEigenvalues.length - 1) || Precision.equals(matT[i + 1][i], 0.0, EPSILON)) { realEigenvalues[i] = matT[i][i]; } else { final double x = matT[i + 1][i + 1]; final double p = 0.5 * (matT[i][i] - x); final double z = FastMath.sqrt(FastMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1])); realEigenvalues[i] = x + p; imagEigenvalues[i] = z; realEigenvalues[i + 1] = x + p; imagEigenvalues[i + 1] = -z; i++; } } return schurTransform; }
/** * Build the transformation to Hessenberg form of a general matrix. * * @param matrix matrix to transform * @throws NonSquareMatrixException if the matrix is not square */ HessenbergTransformer(final RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } final int m = matrix.getRowDimension(); householderVectors = matrix.getData(); ort = new double[m]; cachedP = null; cachedPt = null; cachedH = null; // transform matrix transform(); }
/** * Build the transformation to tridiagonal shape of a symmetrical matrix. * <p>The specified matrix is assumed to be symmetrical without any check. * Only the upper triangular part of the matrix is used.</p> * * @param matrix Symmetrical matrix to transform. * @throws NonSquareMatrixException if the matrix is not square. */ TriDiagonalTransformer(RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } final int m = matrix.getRowDimension(); householderVectors = matrix.getData(); main = new double[m]; secondary = new double[m - 1]; cachedQ = null; cachedQt = null; cachedT = null; // transform matrix transform(); }
final double[][] x = b.getData();
/** * Get the covariance matrix of the optimized parameters. * <br/> * Note that this operation involves the inversion of the * <code>J<sup>T</sup>J</code> matrix, where {@code J} is the * Jacobian matrix. * The {@code threshold} parameter is a way for the caller to specify * that the result of this computation should be considered meaningless, * and thus trigger an exception. * * @param params Model parameters. * @param threshold Singularity threshold. * @return the covariance matrix. * @throws org.apache.commons.math3.linear.SingularMatrixException * if the covariance matrix cannot be computed (singular problem). * @since 3.1 */ public double[][] computeCovariances(double[] params, double threshold) { // Set up the Jacobian. final RealMatrix j = computeWeightedJacobian(params); // Compute transpose(J)J. final RealMatrix jTj = j.transpose().multiply(j); // Compute the covariances matrix. final DecompositionSolver solver = new QRDecomposition(jTj, threshold).getSolver(); return solver.getInverse().getData(); }
/** * Get the covariance matrix of the optimized parameters. * <br/> * Note that this operation involves the inversion of the * <code>J<sup>T</sup>J</code> matrix, where {@code J} is the * Jacobian matrix. * The {@code threshold} parameter is a way for the caller to specify * that the result of this computation should be considered meaningless, * and thus trigger an exception. * * @param params Model parameters. * @param threshold Singularity threshold. * @return the covariance matrix. * @throws org.apache.commons.math3.linear.SingularMatrixException * if the covariance matrix cannot be computed (singular problem). */ public double[][] computeCovariances(double[] params, double threshold) { // Set up the Jacobian. final RealMatrix j = computeWeightedJacobian(params); // Compute transpose(J)J. final RealMatrix jTj = j.transpose().multiply(j); // Compute the covariances matrix. final DecompositionSolver solver = new QRDecomposition(jTj, threshold).getSolver(); return solver.getInverse().getData(); }
/** * Calculates the eigen decomposition of the given real matrix. * <p> * Supports decomposition of a general matrix since 3.1. * * @param matrix Matrix to decompose. * @throws MaxCountExceededException if the algorithm fails to converge. * @throws MathArithmeticException if the decomposition of a general matrix * results in a matrix with zero norm * @since 3.1 */ public EigenDecomposition(final RealMatrix matrix) throws MathArithmeticException { final double symTol = 10 * matrix.getRowDimension() * matrix.getColumnDimension() * Precision.EPSILON; isSymmetric = MatrixUtils.isSymmetric(matrix, symTol); if (isSymmetric) { transformToTridiagonal(matrix); findEigenVectors(transformer.getQ().getData()); } else { final SchurTransformer t = transformToSchur(matrix); findEigenVectorsFromSchur(t); } }
lTData = matrix.getData(); cachedL = null; cachedLT = null;