Example usage for org.apache.commons.math3.linear CholeskyDecomposition getLT

List of usage examples for org.apache.commons.math3.linear CholeskyDecomposition getLT

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear CholeskyDecomposition getLT.

Prototype

public RealMatrix getLT() 

Source Link

Document

Returns the transpose of the matrix L of the decomposition.

Usage

From source file:com.joptimizer.algebra.CholeskyDecompositionTest.java

/**
 * good decomposition./*from   w  w w  . jav a 2 s.c o  m*/
 */
public void testDecomposition1() throws Exception {
    log.debug("testDecomposition1");
    RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.08073550734687, 1.59028724315583 },
            { 1.59028724315583, 0.3250861184011492 } });
    CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1);
    log.debug("L: " + cFact1.getL());
    log.debug("LT: " + cFact1.getLT());
    // check L.LT-Q=0
    RealMatrix P1Inv = cFact1.getL().multiply(cFact1.getLT());
    double norm1 = P1Inv.subtract(P1).getNorm();
    log.debug("norm1: " + norm1);
    assertTrue(norm1 < 1.E-12);
}

From source file:com.joptimizer.algebra.CholeskyDecompositionTest.java

/**
 * poor decomposition.//w  w  w  . ja  v  a  2s . c  om
 * rescaling can help in doing it better
 */
public void testDecomposition2() throws Exception {
    log.debug("testDecomposition2");
    RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.185301256666552E9, 1.5977225251367908E9 },
            { 1.5977225251367908E9, 3.118660129093004E8 } });
    CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1);
    log.debug("L: " + cFact1.getL());
    log.debug("LT: " + cFact1.getLT());
    // check L.LT-Q=0
    double norm1 = cFact1.getL().multiply(cFact1.getLT()).subtract(P1).getNorm();
    log.debug("norm1: " + norm1);
    assertTrue(norm1 < 1.E-5);

    //poor precision, try to make it better

    //geometric eigenvalues mean
    DescriptiveStatistics ds = new DescriptiveStatistics(new double[] { 8.5E9, 0.00572 });
    RealMatrix P2 = P1.scalarMultiply(1. / ds.getGeometricMean());
    CholeskyDecomposition cFact2 = new CholeskyDecomposition(P2);
    log.debug("L: " + cFact2.getL());
    log.debug("LT: " + cFact2.getLT());
    // check L.LT-Q=0
    double norm2 = cFact2.getL().multiply(cFact2.getLT()).subtract(P2).getNorm();
    log.debug("norm2: " + norm2);
    assertTrue(norm2 < Utils.getDoubleMachineEpsilon());
}

From source file:com.joptimizer.solvers.CholeskyTest.java

/**
 * poor decomposition./*from  w  w  w .ja  v a  2s . c o  m*/
 * rescaling can help in doing it better
 */
public void testDecomposition2() throws Exception {
    log.debug("testDecomposition2");
    RealMatrix P1 = new Array2DRowRealMatrix(new double[][] { { 8.185301256666552E9, 1.5977225251367908E9 },
            { 1.5977225251367908E9, 3.118660129093004E8 } });
    CholeskyDecomposition cFact1 = new CholeskyDecomposition(P1);
    log.debug("L: " + cFact1.getL());
    log.debug("LT: " + cFact1.getLT());
    // check L.LT-Q=0
    double norm1 = cFact1.getL().multiply(cFact1.getLT()).subtract(P1).getNorm();
    log.debug("norm1: " + norm1);
    assertTrue(norm1 < 1.E-5);

    //poor precision, try to make it better

    //geometric eigenvalues mean
    DescriptiveStatistics ds = new DescriptiveStatistics(new double[] { 8.5E9, 0.00572 });
    RealMatrix P2 = P1.scalarMultiply(1. / ds.getGeometricMean());
    CholeskyDecomposition cFact2 = new CholeskyDecomposition(P2);
    log.debug("L: " + cFact2.getL());
    log.debug("LT: " + cFact2.getLT());
    // check L.LT-Q=0
    double norm2 = cFact2.getL().multiply(cFact2.getLT()).subtract(P2).getNorm();
    log.debug("norm2: " + norm2);
    assertTrue(norm2 < 1.E-9);
}

From source file:com.opengamma.strata.math.impl.linearalgebra.CholeskyDecompositionCommonsResult.java

/**
 * Constructor.//from  ww w  .j a va 2  s. c o m
 * @param ch The result of the Cholesky decomposition.
 */
public CholeskyDecompositionCommonsResult(CholeskyDecomposition ch) {
    ArgChecker.notNull(ch, "Cholesky decomposition");
    _determinant = ch.getDeterminant();
    _l = CommonsMathWrapper.unwrap(ch.getL());
    _lt = CommonsMathWrapper.unwrap(ch.getLT());
    _solver = ch.getSolver();
}

From source file:com.analog.lyric.dimple.solvers.sumproduct.customFactors.CustomComplexGaussianPolynomial.java

private Complex[] getSamples(Complex mean, double[][] covar) {
    double[] mean_array = new double[2];
    mean_array[0] = mean.getReal();/*  w w w  .  ja v a  2  s .com*/
    mean_array[1] = mean.getImaginary();
    double[][] samples = new double[covar.length * 2][];

    CholeskyDecomposition cd = new CholeskyDecomposition(wrapRealMatrix(covar));

    double[][] chol = matrixGetDataRef(cd.getLT());

    for (int i = 0; i < chol.length; i++) {
        samples[i * 2] = chol[i].clone();
        samples[i * 2 + 1] = chol[i].clone();

        for (int j = 0; j < samples[i * 2].length; j++) {
            samples[i * 2][j] = samples[i * 2][j] / Math.sqrt(covar.length) + mean_array[j];
            samples[i * 2 + 1][j] = samples[i * 2 + 1][j] / -Math.sqrt(covar.length) + mean_array[j];
        }
    }

    Complex[] retval = new Complex[samples.length];
    for (int i = 0; i < retval.length; i++)
        retval[i] = new Complex(samples[i][0], samples[i][1]);

    return retval;
}