/** * Returns the Hessenberg matrix H of the transform. * * @return the H matrix */ public RealMatrix getH() { if (cachedH == null) { int m = householderVectors.Length; double[][] h = Java.CreateArray <double[][]>(m, m);// new double[m][m]; for (int i = 0; i < m; ++i) { if (i > 0) { // copy the entry of the lower sub-diagonal h[i][i - 1] = householderVectors[i][i - 1]; } // copy upper triangular part of the matrix for (int j = i; j < m; ++j) { h[i][j] = householderVectors[i][j]; } } cachedH = MatrixUtils.CreateRealMatrix(h); } // return the cached matrix return(cachedH); }
/** * 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 Exception("SingularMatrixException"); } int m = realEigenvalues.Length; double[][] invData = Java.CreateArray <double[][]>(m, m);// new double[m][m]; for (int i = 0; i < m; ++i) { double[] invI = invData[i]; for (int j = 0; j < m; ++j) { double invIJ = 0; for (int k = 0; k < m; ++k) { double[] vK = eigenvectors[k].getDataRef(); invIJ += vK[i] * vK[j] / realEigenvalues[k]; } invI[j] = invIJ; } } return(MatrixUtils.CreateRealMatrix(invData)); }
public override RealMatrix outerProduct(RealVector v) { if (v is ArrayRealVector) { double[] vData = ((ArrayRealVector)v).data; int m = data.Length; int n = vData.Length; RealMatrix @out = MatrixUtils.CreateRealMatrix(m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { @out.setEntry(i, j, data[i] * vData[j]); } } return(@out); } else { int m = data.Length; int n = v.getDimension(); RealMatrix @out = MatrixUtils.CreateRealMatrix(m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { @out.setEntry(i, j, data[i] * v.getEntry(j)); } } return(@out); } }
/** * Returns the matrix P of the transform. * <p>P is an orthogonal matrix, i.e. its inverse is also its transpose.</p> * * @return the P matrix */ public RealMatrix getP() { if (cachedP == null) { cachedP = MatrixUtils.CreateRealMatrix(matrixP); } return(cachedP); }
/** * Returns the quasi-triangular Schur matrix T of the transform. * * @return the T matrix */ public RealMatrix getT() { if (cachedT == null) { cachedT = MatrixUtils.CreateRealMatrix(matrixT); } // return the cached matrix return(cachedT); }
/** * Gets the matrix V of the decomposition. * V is an orthogonal matrix, i.e. its transpose is also its inverse. * The columns of V are the eigenvectors of the original matrix. * No assumption is made about the orientation of the system axes formed * by the columns of V (e.g. in a 3-dimension space, V can form a left- * or right-handed system). * * @return the V matrix. */ public RealMatrix getV() { if (cachedV == null) { int m = eigenvectors.Length; cachedV = MatrixUtils.CreateRealMatrix(m, m); for (int k = 0; k < m; ++k) { cachedV.setColumnVector(k, eigenvectors[k]); } } // return the cached matrix return(cachedV); }
/** * Returns the matrix P of the transform. * <p>P is an orthogonal matrix, i.e. its inverse is also its transpose.</p> * * @return the P matrix */ public RealMatrix getP() { if (cachedP == null) { int n = householderVectors.Length; int high = n - 1; double[][] pa = Java.CreateArray <double[][]>(n, n);// new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { pa[i][j] = (i == j) ? 1 : 0; } } for (int m = high - 1; m >= 1; m--) { if (householderVectors[m][m - 1] != 0.0) { for (int i = m + 1; i <= high; i++) { ort[i] = householderVectors[i][m - 1]; } for (int j = m; j <= high; j++) { double g = 0.0; for (int i = m; i <= high; i++) { g += ort[i] * pa[i][j]; } // Double division avoids possible underflow g = (g / ort[m]) / householderVectors[m][m - 1]; for (int i = m; i <= high; i++) { pa[i][j] += g * ort[i]; } } } } cachedP = MatrixUtils.CreateRealMatrix(pa); } return(cachedP); }
/** * Returns the transpose of the matrix Q of the transform. * <p>Q is an orthogonal matrix, i.e. its transpose is also its inverse.</p> * @return the Q matrix */ public RealMatrix getQT() { if (cachedQt == null) { int m = householderVectors.Length; var qta = Java.CreateArray <double[][]>(m, m); // build up first part of the matrix by applying Householder transforms for (int k = m - 1; k >= 1; --k) { double[] hK = householderVectors[k - 1]; qta[k][k] = 1; if (hK[k] != 0.0) { double inv = 1.0 / (secondary[k - 1] * hK[k]); double beta = 1.0 / secondary[k - 1]; qta[k][k] = 1 + beta * hK[k]; for (int i = k + 1; i < m; ++i) { qta[k][i] = beta * hK[i]; } for (int j = k + 1; j < m; ++j) { beta = 0; for (int i = k + 1; i < m; ++i) { beta += qta[j][i] * hK[i]; } beta *= inv; qta[j][k] = beta * hK[k]; for (int i = k + 1; i < m; ++i) { qta[j][i] += beta * hK[i]; } } } } qta[0][0] = 1; cachedQt = MatrixUtils.CreateRealMatrix(qta); } // return the cached matrix return(cachedQt); }
/** * Returns the tridiagonal matrix T of the transform. * @return the T matrix */ public RealMatrix getT() { if (cachedT == null) { int m = main.Length; double[][] ta = Java.CreateArray <double[][]>(m, m); for (int i = 0; i < m; ++i) { ta[i][i] = main[i]; if (i > 0) { ta[i][i - 1] = secondary[i - 1]; } if (i < main.Length - 1) { ta[i][i + 1] = secondary[i]; } } cachedT = MatrixUtils.CreateRealMatrix(ta); } // return the cached matrix return(cachedT); }