use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class ModeIndependenceOperator method formXtXInverse.
private double[][] formXtXInverse(double[][] X) {
int N = X.length;
int P = X[0].length;
double[][] matrix = new double[P][P];
for (int i = 0; i < P; i++) {
for (int j = 0; j < P; j++) {
double total = 0.0;
for (int k = 0; k < N; k++) {
total += X[k][i] * X[k][j];
}
matrix[i][j] = total;
}
}
// System.err.println("XtX:");
// System.err.println(new Matrix(matrix));
// Take inverse
matrix = new SymmetricMatrix(matrix).inverse().toComponents();
return matrix;
}
use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class PrecisionMatrixGibbsOperator method setupWishartStatistics.
private void setupWishartStatistics(WishartStatistics priorDistribution) {
this.priorDf = priorDistribution.getDF();
this.priorInverseScaleMatrix = null;
double[][] scale = priorDistribution.getScaleMatrix();
if (scale != null)
this.priorInverseScaleMatrix = (SymmetricMatrix) (new SymmetricMatrix(scale)).inverse();
}
use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class GaussianProcessFromTree method nextRandomFast.
// boolean firstTime=true;
public double[] nextRandomFast() {
double[] random = new double[traitModel.getTreeModel().getExternalNodeCount() * traitModel.getDimTrait()];
NodeRef root = traitModel.getTreeModel().getRoot();
double[] traitStart = traitModel.getPriorMean();
double[][] varianceCholesky = null;
double[][] temp = new SymmetricMatrix(traitModel.getDiffusionModel().getPrecisionmatrix()).inverse().toComponents();
try {
varianceCholesky = (new CholeskyDecomposition(temp).getL());
} catch (IllegalDimension illegalDimension) {
illegalDimension.printStackTrace();
}
// }
if (USE_BUFFER) {
final int length = traitModel.getDimTrait();
final int nodeCount = traitModel.getTreeModel().getNodeCount();
double[] currentValue = new double[(nodeCount + 1) * length];
double[] epsilon = new double[length];
final int priorOffset = nodeCount * length;
System.arraycopy(traitStart, 0, currentValue, priorOffset, length);
nextRandomFast2(currentValue, priorOffset, root, random, varianceCholesky, epsilon);
} else {
nextRandomFast(traitStart, root, random, varianceCholesky);
}
// }
return random;
}
use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class FactorTreeGibbsOperator method getMean.
double[] getMean(int column, double[][] precision) {
Matrix variance = (new SymmetricMatrix(precision)).inverse();
double[] midMean = new double[lfm.getLoadings().getColumnDimension()];
double[] condMean = getTreeMean(column);
double[][] condPrec = getTreePrec(column);
for (int i = 0; i < midMean.length; i++) {
// for (int j = 0; j < midMean.length; j++) {
midMean[i] += condPrec[i][i] * condMean[i];
// }
}
for (int i = 0; i < lfm.getLoadings().getRowDimension(); i++) {
for (int j = 0; j < lfm.getLoadings().getColumnDimension(); j++) {
if (missingIndicator == null || missingIndicator.getParameterValue(column * lfm.getScaledData().getRowDimension() + i) != 1)
midMean[j] += lfm.getScaledData().getParameterValue(i, column) * errorPrec.getParameterValue(i, i) * lfm.getLoadings().getParameterValue(i, j) * pathParameter;
}
}
double[] mean = new double[midMean.length];
for (int i = 0; i < mean.length; i++) {
for (int j = 0; j < mean.length; j++) {
mean[i] += variance.component(i, j) * midMean[j];
}
}
return mean;
}
use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class FactorIndependenceOperator method doOperation.
@Override
public double doOperation() {
setupParameters();
getPrecision(precision);
double[][] variance = (new SymmetricMatrix(precision)).inverse().toComponents();
if (randomScan) {
int i = MathUtils.nextInt(LFM.getFactors().getColumnDimension());
randomDraw(i, variance);
}
for (int i = 0; i < LFM.getFactors().getColumnDimension(); i++) {
randomDraw(i, variance);
}
LFM.getFactors().fireParameterChangedEvent();
//To change body of implemented methods use File | Settings | File Templates.
return 0;
}
Aggregations