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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations