use of dr.math.matrixAlgebra.Matrix in project beast-mcmc by beast-dev.
the class ProcrustesTest method runTest.
private void runTest(double[][] X, double[][] Xstar, double[][] goldStandard, boolean allowTranslation, boolean allowDilation, double tolerance, String header) {
RealMatrix rmX = new Array2DRowRealMatrix(X);
RealMatrix rmXstar = new Array2DRowRealMatrix(Xstar);
Procrustes procrustes = new Procrustes(rmX, rmXstar, allowTranslation, allowDilation);
RealMatrix rmXnew = procrustes.procrustinate(rmX);
System.out.println(header);
System.out.print("Translation:\n" + new Matrix(procrustes.getTranslation().getData()));
System.out.println("Dilation = " + procrustes.getDilation());
System.out.println("Xnew:");
System.out.println(new Matrix(rmXnew.getData()));
assertEquals(rmXnew.getData(), goldStandard, tolerance);
}
use of dr.math.matrixAlgebra.Matrix in project beast-mcmc by beast-dev.
the class LKJTransformTest method testTransformationRecursion.
public void testTransformationRecursion() {
System.out.println("\nTest LKJ transform.");
double[] transformedValue = transform.inverseRecursion(CPCs, 0, CPCs.length);
double[] transformedValueChol = transform.inverse(CPCs, 0, CPCs.length);
for (int k = 0; k < transformedValueChol.length; k++) {
assertEquals("transform chol rec k=" + k, format.format(transformedValueChol[k]), format.format(transformedValue[k]));
}
double[] inverseTransformedValues = transform.transformRecursion(transformedValue, 0, CPCs.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.Matrix in project beast-mcmc by beast-dev.
the class LKJTransformTest method testJacobianCorrelationToCholesky.
public void testJacobianCorrelationToCholesky() {
System.out.println("\nTest Correlation to Cholesky Jacobian.");
// Matrix
double[] cholValues = transformChol.inverse(CPCs, 0, CPCs.length);
double[][] jacobianMat = transformCorrToChol.computeJacobianMatrixInverse(cholValues);
Matrix Jac = new Matrix(jacobianMat);
System.out.println("Jacobian Matrix=" + Jac.transpose());
assertEquals("size Jacobian Matrix", format.format(dim * (dim - 1) / 2), format.format(Jac.rows()));
assertEquals("size Jacobian Matrix", format.format(dim * (dim - 1) / 2), format.format(Jac.columns()));
// Determinant
double jacobianDet = (new Transform.InverseMultivariate(transformCorrToChol)).getLogJacobian(cholValues, 0, cholValues.length);
double jacobianDetBis = 0;
for (int i = 0; i < jacobianMat[0].length; i++) {
jacobianDetBis += Math.log(jacobianMat[i][i]);
}
System.out.println("Log Jacobiant Det direct=" + jacobianDet);
System.out.println("Log Jacobiant Det matrix=" + jacobianDetBis);
assertEquals("jacobian log det", format.format(jacobianDet), format.format(jacobianDetBis));
}
use of dr.math.matrixAlgebra.Matrix in project beast-mcmc by beast-dev.
the class LKJTransformTest method testJacobian.
public void testJacobian() {
System.out.println("\nTest LKJ Jacobian.");
// Matrix
double[][] jacobianMat = transform.computeJacobianMatrixInverse(CPCs);
Matrix Jac = new Matrix(jacobianMat);
System.out.println("Jacobian Matrix=" + Jac.transpose());
assertEquals("size Jacobian Matrix", format.format(dim * (dim - 1) / 2), format.format(Jac.rows()));
assertEquals("size Jacobian Matrix", format.format(dim * (dim - 1) / 2), format.format(Jac.columns()));
// Determinant
double jacobianDet = (new Transform.InverseMultivariate(transform)).getLogJacobian(CPCs, 0, CPCs.length);
double jacobianDetBis = 0;
for (int i = 0; i < jacobianMat[0].length; i++) {
jacobianDetBis += Math.log(jacobianMat[i][i]);
}
System.out.println("Log Jacobiant Det direct=" + jacobianDet);
System.out.println("Log Jacobiant Det matrix=" + jacobianDetBis);
assertEquals("jacobian log det", format.format(jacobianDet), format.format(jacobianDetBis));
}
use of dr.math.matrixAlgebra.Matrix in project beast-mcmc by beast-dev.
the class LKJTransformTest method testTransformationLimitRecursion.
public void testTransformationLimitRecursion() {
System.out.println("\nTest LKJ transform on the border.");
double[] transformedValue = transform.inverseRecursion(CPCsLimit, 0, CPCsLimit.length);
double[] transformedValueChol = transform.inverse(CPCsLimit, 0, CPCsLimit.length);
for (int k = 0; k < transformedValueChol.length; k++) {
assertEquals("transform chol rec k=" + k, format.format(transformedValueChol[k]), format.format(transformedValue[k]));
}
double[] inverseTransformedValues = transform.transformRecursion(transformedValue, 0, CPCsLimit.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(CPCsLimit.length), format.format(inverseTransformedValues.length));
for (int k = 0; k < CPCsLimit.length; k++) {
assertEquals("inverse transform k=" + k, format.format(CPCsLimit[k]), format.format(inverseTransformedValues[k]));
}
}
Aggregations