Search in sources :

Example 1 with LUDecomposition

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.");
}
Also used : Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) LUDecomposition(org.apache.ignite.ml.math.decompositions.LUDecomposition) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)

Example 2 with LUDecomposition

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;
}
Also used : LUDecomposition(org.apache.ignite.ml.math.decompositions.LUDecomposition)

Example 3 with LUDecomposition

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;
}
Also used : Matrix(org.apache.ignite.ml.math.Matrix) LUDecomposition(org.apache.ignite.ml.math.decompositions.LUDecomposition) CardinalityException(org.apache.ignite.ml.math.exceptions.CardinalityException)

Aggregations

LUDecomposition (org.apache.ignite.ml.math.decompositions.LUDecomposition)3 Matrix (org.apache.ignite.ml.math.Matrix)2 CardinalityException (org.apache.ignite.ml.math.exceptions.CardinalityException)1 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)1