List of usage examples for org.apache.commons.math3.linear LUDecomposition getU
public RealMatrix getU()
From source file:com.ibm.bi.dml.runtime.matrix.data.LibCommonsMath.java
/** * Function to perform LU decomposition on a given matrix. * /*from w w w.j av a 2 s. com*/ * @param in * @return * @throws DMLRuntimeException */ private static MatrixBlock[] computeLU(MatrixObject in) throws DMLRuntimeException { if (in.getNumRows() != in.getNumColumns()) { throw new DMLRuntimeException( "LU Decomposition can only be done on a square matrix. Input matrix is rectangular (rows=" + in.getNumRows() + ", cols=" + in.getNumColumns() + ")"); } Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in); // Perform LUP decomposition LUDecomposition ludecompose = new LUDecomposition(matrixInput); RealMatrix P = ludecompose.getP(); RealMatrix L = ludecompose.getL(); RealMatrix U = ludecompose.getU(); // Read the results into native format MatrixBlock mbP = DataConverter.convertToMatrixBlock(P.getData()); MatrixBlock mbL = DataConverter.convertToMatrixBlock(L.getData()); MatrixBlock mbU = DataConverter.convertToMatrixBlock(U.getData()); return new MatrixBlock[] { mbP, mbL, mbU }; }
From source file:com.opengamma.strata.math.impl.linearalgebra.LUDecompositionCommonsResult.java
/** * @param lu The result of the LU decomposition, not null. $\mathbf{L}$ cannot be singular. *//*from w ww .j ava 2 s. co m*/ public LUDecompositionCommonsResult(LUDecomposition lu) { ArgChecker.notNull(lu, "LU decomposition"); ArgChecker.notNull(lu.getL(), "Matrix is singular; could not perform LU decomposition"); _determinant = lu.getDeterminant(); _l = CommonsMathWrapper.unwrap(lu.getL()); _p = CommonsMathWrapper.unwrap(lu.getP()); _pivot = lu.getPivot(); _solver = lu.getSolver(); _u = CommonsMathWrapper.unwrap(lu.getU()); }
From source file:org.eclipse.dataset.LinearAlgebra.java
/** * Calculate LU decomposition A = P^-1 L U * @param a//from w w w .j a v a2 s .co m * @return array of L, U and P */ public static Dataset[] calcLUDecomposition(Dataset a) { LUDecomposition lud = new LUDecomposition(createRealMatrix(a)); return new Dataset[] { createDataset(lud.getL()), createDataset(lud.getU()), createDataset(lud.getP()) }; }
From source file:org.meteoinfo.math.linalg.LinalgUtil.java
/** * Calculates the LUP-decomposition of a square matrix. * The LUP-decomposition of a matrix A consists of three matrices L, U and P that satisfy: * PA = LU. L is lower triangular (with unit diagonal terms), U is upper triangular and P is * a permutation matrix. All matrices are mm. * @param a Given matrix.// w ww .j a v a2 s.c o m * @return Result P/L/U arrays. */ public static Array[] lu(Array a) { Array Pa = Array.factory(DataType.DOUBLE, a.getShape()); Array La = Array.factory(DataType.DOUBLE, a.getShape()); Array Ua = Array.factory(DataType.DOUBLE, a.getShape()); double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a); RealMatrix matrix = new Array2DRowRealMatrix(aa, false); LUDecomposition decomposition = new LUDecomposition(matrix); RealMatrix P = decomposition.getP(); RealMatrix L = decomposition.getL(); RealMatrix U = decomposition.getU(); int n = L.getColumnDimension(); int m = L.getRowDimension(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Pa.setDouble(i * n + j, P.getEntry(i, j)); La.setDouble(i * n + j, L.getEntry(i, j)); Ua.setDouble(i * n + j, U.getEntry(i, j)); } } return new Array[] { Pa, La, Ua }; }
From source file:org.ujmp.commonsmath.AbstractCommonsMathDenseDoubleMatrix2D.java
public Matrix[] lu() { LUDecomposition lu = new LUDecomposition(matrix); Matrix l = CommonsMathDenseDoubleMatrix2DFactory.INSTANCE.dense(lu.getL()); Matrix u = CommonsMathDenseDoubleMatrix2DFactory.INSTANCE.dense(lu.getU()); Matrix p = CommonsMathDenseDoubleMatrix2DFactory.INSTANCE.dense(lu.getP()); return new Matrix[] { l, u, p }; }
From source file:pl.matrix.core.MatrixCalculator.java
public List<Matrix> calculateLUDecomposition(Matrix a) { RealMatrix aRealMatrix = a.toRealMatrix(); LUDecomposition lu = new LUDecomposition(aRealMatrix); List<Matrix> result = new ArrayList<>(); result.add(new Matrix(lu.getL())); result.add(new Matrix(lu.getU())); return result; }