use of dr.math.matrixAlgebra.SymmetricMatrix in project beast-mcmc by beast-dev.
the class LKJTransformTest method testTransformation.
public void testTransformation() {
System.out.println("\nTest LKJ transform.");
double[] transformedValue = transform.inverse(CPCs, 0, CPCs.length);
double[] inverseTransformedValues = transform.transform(transformedValue, 0, transformedValue.length);
SymmetricMatrix R = compoundCorrelationSymmetricMatrix(transformedValue, dim);
System.out.println("transformedValue=" + R);
try {
assertTrue("Positive Definite", R.isPD());
} catch (IllegalDimension illegalDimension) {
illegalDimension.printStackTrace();
}
System.out.println("iCPC=" + new Matrix(inverseTransformedValues, dim * (dim - 1) / 2, 1));
assertEquals("size CPCs", format.format(CPCs.length), format.format(inverseTransformedValues.length));
for (int k = 0; k < CPCs.length; k++) {
assertEquals("inverse transform k=" + k, format.format(CPCs[k]), format.format(inverseTransformedValues[k]));
}
}
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 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 CorrelationMatrixGibbsOperator 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 CorrelationMatrixGibbsOperator method getOperationScaleMatrixAndSetObservationCount2.
private double[][] getOperationScaleMatrixAndSetObservationCount2() {
// calculate sum-of-the-weighted-squares matrix over tree
double[][] S = new double[dim][dim];
SymmetricMatrix S2;
SymmetricMatrix inverseS2 = null;
// Need to reset, as incrementOuterProduct can be recursive
numberObservations = 0;
// todo zy: outer product
incrementOuterProductWithRescale(S, conjugateWishartProvider);
try {
S2 = new SymmetricMatrix(S);
if (priorInverseScaleMatrix != null) {
// todo zy: new inverse scale matrix = prior inverse scale +
S2 = priorInverseScaleMatrix.add(S2);
// outer product. S2 in add(S2) is the outer produt
}
inverseS2 = (SymmetricMatrix) S2.inverse();
} catch (IllegalDimension illegalDimension) {
illegalDimension.printStackTrace();
}
assert inverseS2 != null;
return inverseS2.toComponents();
}
Aggregations