List of usage examples for org.apache.commons.math3.linear QRDecomposition getH
public RealMatrix getH()
From source file:com.ibm.bi.dml.runtime.matrix.data.LibCommonsMath.java
/** * Function to perform QR decomposition on a given matrix. * //from w ww .j a v a 2s.co m * @param in * @return * @throws DMLRuntimeException */ private static MatrixBlock[] computeQR(MatrixObject in) throws DMLRuntimeException { Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in); // Perform QR decomposition QRDecomposition qrdecompose = new QRDecomposition(matrixInput); RealMatrix H = qrdecompose.getH(); RealMatrix R = qrdecompose.getR(); // Read the results into native format MatrixBlock mbH = DataConverter.convertToMatrixBlock(H.getData()); MatrixBlock mbR = DataConverter.convertToMatrixBlock(R.getData()); return new MatrixBlock[] { mbH, mbR }; }
From source file:com.joptimizer.algebra.QRSparseFactorizationTest.java
public void testDecompose() throws Exception { log.debug("testDecompose"); final double[][] A = new double[][] { { 1, 0, 0, 2 }, { 0, 0, 2, 0 }, { 2, 3, 0, 0 }, { 0, 0, 4, 4 } }; double[][] EQ = { { 0.447214, -0.894427, 0., 0. }, { 0., 0., 0.447214, -0.894427 }, { 0.894427, 0.447214, 0., 0. }, { 0., 0., 0.894427, 0.447214 } }; double[][] ER = { { 2.23607, 2.68328, 0., 0.894427 }, { 0., 1.34164, 0., -1.78885 }, { 0., 0., 4.47214, 3.57771 }, { 0., 0., 0., 1.78885 } }; QRDecomposition dFact = new QRDecomposition(new Array2DRowRealMatrix(A)); RealMatrix Q = dFact.getQ();/*from w w w.j ava 2 s . c o m*/ RealMatrix R = dFact.getR(); RealMatrix H = dFact.getH(); log.debug("Q: " + ArrayUtils.toString(Q.getData())); log.debug("R: " + ArrayUtils.toString(R.getData())); //log.debug("H: " + ArrayUtils.toString(H.getData())); SparseDoubleMatrix2D S = new SparseDoubleMatrix2D(A); QRSparseFactorization qr = new QRSparseFactorization(S); qr.factorize(); log.debug("R: " + ArrayUtils.toString(qr.getR().toArray())); for (int i = 0; i < R.getRowDimension(); i++) { for (int j = 0; j < R.getColumnDimension(); j++) { assertEquals(ER[i][j], qr.getR().getQuick(i, j), 1.e-5); } } assertTrue(qr.hasFullRank()); }