use of org.apache.ignite.ml.math.decompositions.LUDecomposition in project ignite by apache.
the class LUDecompositionExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String[] args) {
System.out.println(">>> LU decomposition example started.");
// Let's compute a LU decomposition for some (n x n) matrix m:
// m = p l u, where
// p is an (n x n) is a row-permutation matrix
// l is a (n x n) lower triangular matrix
// u is a (n x n) upper triangular matrix
DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] { { 1.0d, 1.0d, -1.0d }, { 1.0d, -2.0d, 3.0d }, { 2.0d, 3.0d, 1.0d } });
System.out.println("\n>>> Matrix m for decomposition: ");
Tracer.showAscii(m);
// This decomposition is useful when dealing with systems of linear equations.
// (see https://en.wikipedia.org/wiki/LU_decomposition)
// suppose we want to solve system
// m x = b for various bs. Then after we computed LU decomposition, we can feed various bs
// as a matrix of the form
// (b1, b2, ..., bm)
// to the method LUDecomposition::solve which returns solutions in the form
// (sol1, sol2, ..., solm)
LUDecomposition dec = new LUDecomposition(m);
System.out.println("\n>>> Made decomposition.");
System.out.println(">>> Matrix getL is ");
Tracer.showAscii(dec.getL());
System.out.println(">>> Matrix getU is ");
Tracer.showAscii(dec.getU());
System.out.println(">>> Matrix getP is ");
Tracer.showAscii(dec.getP());
Matrix bs = new DenseLocalOnHeapMatrix(new double[][] { { 4.0, -6.0, 7.0 }, { 1.0, 1.0, 1.0 } });
System.out.println("\n>>> Matrix to solve: ");
Tracer.showAscii(bs);
Matrix sol = dec.solve(bs.transpose());
System.out.println("\n>>> List of solutions: ");
for (int i = 0; i < sol.columnSize(); i++) Tracer.showAscii(sol.viewColumn(i));
System.out.println("\n>>> LU decomposition example completed.");
}
use of org.apache.ignite.ml.math.decompositions.LUDecomposition in project ignite by apache.
the class AbstractMatrix method determinant.
/** {@inheritDoc} */
@Override
public double determinant() {
//TODO: This decomposition should be cached
LUDecomposition dec = new LUDecomposition(this);
double res = dec.determinant();
dec.destroy();
return res;
}
use of org.apache.ignite.ml.math.decompositions.LUDecomposition in project ignite by apache.
the class AbstractMatrix method inverse.
/** {@inheritDoc} */
@Override
public Matrix inverse() {
if (rowSize() != columnSize())
throw new CardinalityException(rowSize(), columnSize());
//TODO: This decomposition should be cached
LUDecomposition dec = new LUDecomposition(this);
Matrix res = dec.solve(likeIdentity());
dec.destroy();
return res;
}
Aggregations