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

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

Introduction

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

Prototype

public double getDeterminant() 

Source Link

Document

Return the determinant of the matrix

Usage

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

/**
 * Constructor./*from   w w  w  . j a  v a  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.joptimizer.functions.SDPLogarithmicBarrier.java

/**
 * @see "S.Boyd and L.Vandenberghe, Convex Optimization, p. 618"
 *///from w  w w .  j  a va 2s .  c o  m
public double value(double[] X) {
    RealMatrix S = buildS(X);
    try {
        CholeskyDecomposition cFact = new CholeskyDecomposition(S);
        double detS = cFact.getDeterminant();
        return -Math.log(detS);
    } catch (NonPositiveDefiniteMatrixException e) {
        return Double.NaN;
    }
}

From source file:org.rhwlab.variationalbayesian.GaussianMixture.java

public void init(int K) {
    this.K = K;/*from ww w.j ava2s .c  om*/
    this.N = new double[K];
    this.m = new RealVector[K];
    inModel = new boolean[K];
    for (int k = 0; k < K; ++k) {
        inModel[k] = true;
    }
    Dln2 = X.getD() * Math.log(2.0);
    Dln2Pi2 = X.getD() * Math.log(2.0 * Math.PI) / 2.0;

    r = new Array2DRowRealMatrix(X.getN(), K);
    if (X instanceof ClusteredDataSource) {
        ClusteredDataSource clSource = (ClusteredDataSource) X;
        for (int n = 0; n < X.getN(); ++n) {
            int cluster = clSource.getCluster(n);
            for (int k = 0; k < K; ++k) {
                if (k == cluster) {
                    r.setEntry(n, k, 1.0);
                } else {
                    r.setEntry(n, k, 0.0);
                }
            }
        }
    } else {
        for (int n = 0; n < X.getN(); ++n) {
            double[] dir = dirichlet(0.001, K);
            for (int k = 0; k < K; ++k) {
                r.setEntry(n, k, dir[k]);
            }
        }
    }
    calculateN();

    if (mu0 == null) {
        mu0 = new ArrayRealVector(X.getD(), 0.0);
    }

    if (W0 == null) {
        W0 = MatrixUtils.createRealIdentityMatrix(X.getD());
        W0 = W0.scalarMultiply(.01);
    }
    CholeskyDecomposition de = new CholeskyDecomposition(W0);
    W0inverse = de.getSolver().getInverse();
    W0det = de.getDeterminant();
    W = new RealMatrix[K];
    Winverse = new RealMatrix[K];
    detW = new double[K];
    detWinv = new double[K];
    /*        
            for (int k=0 ; k<K ; ++k){
    W[k] = W0.copy();
    W[k].scalarMultiply(0.0000000001);
    detW[k] = de.getDeterminant();
            }
     */
    alpha = new double[K];
    beta = new double[K];
    lnLambdaTilde = new double[K];
    nu = new double[K];
    xBar = new RealVector[K];
    for (int k = 0; k < K; ++k) {
        xBar[k] = new ArrayRealVector(X.getD());
        //            nu[k] = nu0 + N[k];
    }
    lnPi = new double[K];
    for (int k = 0; k < K; ++k) {
        //            lnPi[k] = Math.log(N[k]/X.getN());
    }

    S = new RealMatrix[K];
    for (int k = 0; k < K; ++k) {
        S[k] = new Array2DRowRealMatrix(X.getD(), X.getD());
    }

    lnRho = new double[K];
    a0 = new double[K];
    for (int k = 0; k < K; ++k) {
        a0[k] = alpha0;
    }
    C0 = lnC(a0);
    //        alphaBetaNu();
    //        lambdaTilde();
}

From source file:org.rhwlab.variationalbayesian.SuperVoxelGaussianMixture.java

public void init(int K) {
    this.K = K;/*w  ww. j a va 2s. c  om*/
    Dln2 = X.getD() * Math.log(2.0);
    Dln2Pi2 = X.getD() * Math.log(2.0 * Math.PI) / 2.0;

    r = new Array2DRowRealMatrix(X.getN(), K);
    if (mu0 == null) {
        mu0 = new ArrayRealVector(X.getD(), 0.0);
    }
    // initialize the means 

    m = new RealVector[K];
    N = new double[K];
    double Nk = (double) X.getN() / (double) K;
    for (int k = 0; k < K; ++k) {
        m[k] = X.get(k).centroid;
        N[k] = Nk;
    }

    if (W0 == null) {
        W0 = MatrixUtils.createRealIdentityMatrix(X.getD());
        W0 = W0.scalarMultiply(.01);
    }
    CholeskyDecomposition de = new CholeskyDecomposition(W0);
    W0inverse = de.getSolver().getInverse();
    W0det = de.getDeterminant();
    W = new RealMatrix[K];
    detW = new double[K];
    for (int k = 0; k < K; ++k) {
        W[k] = W0.copy();
        detW[k] = de.getDeterminant();
    }

    alpha = new double[K];
    beta = new double[K];
    lnLambdaTilde = new double[K];
    nu = new double[K];
    xBar = new RealVector[K];
    for (int k = 0; k < K; ++k) {
        xBar[k] = new ArrayRealVector(X.getD());
        nu[k] = nu0 + N[k];
    }
    lnPi = new double[K];
    lnPi();
    /*        
            for (k=0 ; k<K ; ++k){
    lnPi[k] = Math.log(N[k]/X.getN());
            }
    */
    S = new RealMatrix[K];
    for (int k = 0; k < K; ++k) {
        S[k] = new Array2DRowRealMatrix(X.getD(), X.getD());
    }

    lnRho = new double[K];
    a0 = new double[K];
    for (int k = 0; k < K; ++k) {
        a0[k] = alpha0;
    }
    C0 = lnC(a0);
    alphaBetaNuLambda();
}