Search in sources :

Example 1 with CholeskyDecomposition

use of org.apache.ignite.ml.math.decompositions.CholeskyDecomposition in project ignite by apache.

the class IgniteCholeskyDecompositionBenchmark method runCholeskyDecomposition.

/**
 * Based on CholeskyDecompositionTest.
 */
private void runCholeskyDecomposition() {
    final DataChanger.Scale scale = new DataChanger.Scale();
    Matrix m = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { { 2.0d, -1.0d, 0.0d }, { -1.0d, 2.0d, -1.0d }, { 0.0d, -1.0d, 2.0d } }));
    CholeskyDecomposition dec = new CholeskyDecomposition(m);
    dec.getL();
    dec.getLT();
    Matrix bs = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { { 4.0, -6.0, 7.0 }, { 1.0, 1.0, 1.0 } })).transpose();
    dec.solve(bs);
    Vector b = new DenseLocalOnHeapVector(scale.mutate(new double[] { 4.0, -6.0, 7.0 }));
    dec.solve(b);
    dec.destroy();
}
Also used : CholeskyDecomposition(org.apache.ignite.ml.math.decompositions.CholeskyDecomposition) DataChanger(org.apache.ignite.yardstick.ml.DataChanger) Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) Vector(org.apache.ignite.ml.math.Vector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)

Example 2 with CholeskyDecomposition

use of org.apache.ignite.ml.math.decompositions.CholeskyDecomposition in project ignite by apache.

the class CholeskyDecompositionExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) {
    System.out.println(">>> Cholesky decomposition example started.");
    // Let's compute a Cholesky decomposition of Hermitian matrix m:
    // m = l l^{*}, where
    // l is a lower triangular matrix
    // l^{*} is its conjugate transpose
    DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] { { 2.0d, -1.0d, 0.0d }, { -1.0d, 2.0d, -1.0d }, { 0.0d, -1.0d, 2.0d } });
    System.out.println("\n>>> Matrix m for decomposition: ");
    Tracer.showAscii(m);
    // This decomposition is useful when dealing with systems of linear equations of the form
    // m x = b where m is a Hermitian matrix.
    // For such systems Cholesky decomposition provides
    // more effective method of solving compared to LU decomposition.
    // Suppose we want to solve system
    // m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs
    // as a matrix of the form
    // (b1, b2, ..., bm)
    // to the method Cholesky::solve which returns solutions in the form
    // (sol1, sol2, ..., solm)
    CholeskyDecomposition dec = new CholeskyDecomposition(m);
    System.out.println("\n>>> Made decomposition m = l * l^{*}.");
    System.out.println(">>> Matrix l is ");
    Tracer.showAscii(dec.getL());
    System.out.println(">>> Matrix l^{*} is ");
    Tracer.showAscii(dec.getLT());
    Matrix bs = new DenseLocalOnHeapMatrix(new double[][] { { 4.0, -6.0, 7.0 }, { 1.0, 1.0, 1.0 } }).transpose();
    System.out.println("\n>>> Solving systems of linear equations of the form m x = b for various bs represented by columns of matrix");
    Tracer.showAscii(bs);
    Matrix sol = dec.solve(bs);
    System.out.println("\n>>> List of solutions: ");
    for (int i = 0; i < sol.columnSize(); i++) Tracer.showAscii(sol.viewColumn(i));
    System.out.println("\n>>> Cholesky decomposition example completed.");
}
Also used : CholeskyDecomposition(org.apache.ignite.ml.math.decompositions.CholeskyDecomposition) Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)

Aggregations

Matrix (org.apache.ignite.ml.math.Matrix)2 CholeskyDecomposition (org.apache.ignite.ml.math.decompositions.CholeskyDecomposition)2 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)2 Vector (org.apache.ignite.ml.math.Vector)1 DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)1 DataChanger (org.apache.ignite.yardstick.ml.DataChanger)1