Search in sources :

Example 66 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project tetrad by cmu-phil.

the class SemBicScoreImages3 method logdet.

private double logdet(TetradMatrix m) {
    RealMatrix M = m.getRealMatrix();
    final double tol = 1e-9;
    RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT();
    double sum = 0.0;
    for (int i = 0; i < LT.getRowDimension(); i++) {
        sum += FastMath.log(LT.getEntry(i, i));
    }
    return 2.0 * sum;
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 67 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project tetrad by cmu-phil.

the class DataUtils method times.

private static RealMatrix times(final RealMatrix m, final RealMatrix n) {
    if (m.getColumnDimension() != n.getRowDimension())
        throw new IllegalArgumentException("Incompatible matrices.");
    final int rowDimension = m.getRowDimension();
    final int columnDimension = n.getColumnDimension();
    final RealMatrix out = new BlockRealMatrix(rowDimension, columnDimension);
    final int NTHREADS = Runtime.getRuntime().availableProcessors();
    ForkJoinPool pool = ForkJoinPoolInstance.getInstance().getPool();
    for (int t = 0; t < NTHREADS; t++) {
        final int _t = t;
        Runnable worker = new Runnable() {

            @Override
            public void run() {
                int chunk = rowDimension / NTHREADS + 1;
                for (int row = _t * chunk; row < Math.min((_t + 1) * chunk, rowDimension); row++) {
                    if ((row + 1) % 100 == 0)
                        System.out.println(row + 1);
                    for (int col = 0; col < columnDimension; ++col) {
                        double sum = 0.0D;
                        int commonDimension = m.getColumnDimension();
                        for (int i = 0; i < commonDimension; ++i) {
                            sum += m.getEntry(row, i) * n.getEntry(i, col);
                        }
                        // double sum = m.getRowVector(row).dotProduct(n.getColumnVector(col));
                        out.setEntry(row, col, sum);
                    }
                }
            }
        };
        pool.submit(worker);
    }
    while (!pool.isQuiescent()) {
    }
    return out;
}
Also used : BlockRealMatrix(org.apache.commons.math3.linear.BlockRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) BlockRealMatrix(org.apache.commons.math3.linear.BlockRealMatrix) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 68 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project tetrad by cmu-phil.

the class ConditionalGaussianOtherLikelihood method logdet.

private double logdet(TetradMatrix m) {
    RealMatrix M = m.getRealMatrix();
    final double tol = 1e-9;
    RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT();
    double sum = 0.0;
    for (int i = 0; i < LT.getRowDimension(); i++) {
        sum += FastMath.log(LT.getEntry(i, i));
    }
    return 2.0 * sum;
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 69 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project tetrad by cmu-phil.

the class DiscreteMixedLikelihood method logdet.

private double logdet(TetradMatrix m) {
    RealMatrix M = m.getRealMatrix();
    final double tol = 1e-9;
    RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT();
    double sum = 0.0;
    for (int i = 0; i < LT.getRowDimension(); i++) {
        sum += FastMath.log(LT.getEntry(i, i));
    }
    return 2.0 * sum;
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 70 with Sum

use of org.apache.commons.math3.stat.descriptive.summary.Sum in project tetrad by cmu-phil.

the class ConditionalGaussianLikelihood method logdet.

private double logdet(TetradMatrix m) {
    RealMatrix M = m.getRealMatrix();
    final double tol = 1e-9;
    RealMatrix LT = new org.apache.commons.math3.linear.CholeskyDecomposition(M, tol, tol).getLT();
    double sum = 0.0;
    for (int i = 0; i < LT.getRowDimension(); i++) {
        sum += FastMath.log(LT.getEntry(i, i));
    }
    return 2.0 * sum;
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Aggregations

RealMatrix (org.apache.commons.math3.linear.RealMatrix)22 Collectors (java.util.stream.Collectors)15 java.util (java.util)12 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)12 List (java.util.List)11 IntStream (java.util.stream.IntStream)11 Logger (org.apache.logging.log4j.Logger)11 ArrayList (java.util.ArrayList)9 LogManager (org.apache.logging.log4j.LogManager)9 IOException (java.io.IOException)8 Map (java.util.Map)8 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)8 UserException (org.broadinstitute.hellbender.exceptions.UserException)8 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)8 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)8 Test (org.testng.annotations.Test)8 File (java.io.File)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Arrays (java.util.Arrays)6 Nonnull (javax.annotation.Nonnull)6