Debian Codegraph @

src/test/dr/math/ProcrustesTest.java

raw symbols SCIP
1 package test.dr.math;
2
3 import dr.math.Procrustes;
4 import dr.math.matrixAlgebra.Matrix;
5 import org.apache.commons.math.linear.Array2DRowRealMatrix;
6 import org.apache.commons.math.linear.RealMatrix;
7
8 /* R test code
9
10 library(MCMCpack)
11 set.seed(666)
12 Xstar = matrix(runif(9,-10,10), nrow=3)
13 X = matrix(runif(9,-2,2), nrow=3)
14 out.0 = procrustes(X, Xstar, F, F)
15 out.1 = procrustes(X, Xstar, T, F)
16 out.2 = procrustes(X, Xstar, F, T)
17
18 */
19
20 /**
21 * @author Marc A. Suchard
22 * @author Andrew Rambaut
23 */
24 public class ProcrustesTest extends MathTestCase {
25
26 public void testProcrustes() {
27 double tolerance = 1E-4;
28 runTest(X, Xstar, gldStd[0], false, false, tolerance, "No translation, no dilation");
29 runTest(X, Xstar, gldStd[1], true, false, tolerance, "Yes translation, no dilation");
30 runTest(X, Xstar, gldStd[2], false, true, tolerance, "No translation, yes dilation");
31
32 }
33
34 private void runTest(double[][] X, double[][] Xstar, double[][] goldStandard,
35 boolean allowTranslation, boolean allowDilation, double tolerance, String header) {
36
37 RealMatrix rmX = new Array2DRowRealMatrix(X);
38 RealMatrix rmXstar = new Array2DRowRealMatrix(Xstar);
39 Procrustes procrustes = new Procrustes(rmX, rmXstar, allowTranslation, allowDilation);
40 RealMatrix rmXnew = procrustes.procrustinate(rmX);
41
42 System.out.println(header);
43 System.out.print("Translation:\n" + new Matrix(procrustes.getTranslation().getData()));
44 System.out.println("Dilation = " + procrustes.getDilation());
45 System.out.println("Xnew:");
46 System.out.println(new Matrix(rmXnew.getData()));
47 assertEquals(rmXnew.getData(), goldStandard, tolerance);
48 }
49
50 private static double[][] X = {
51 { -0.9602155, -1.617021, 1.245026 },
52 { 1.1035723, -1.431346, -1.853811 },
53 { -1.9344838, -1.155495, 1.566550 }
54 };
55
56
57 private static double[][] Xstar = {
58 { 5.487370, -5.973453, 9.57456879 },
59 { -6.055516, -2.775111, -0.03772582 },
60 { 9.560277, 4.852239, -9.73368329 }
61 };
62
63 private static double[][][] gldStd = {
64 {
65 { 2.062008, -0.8829124, 0.2354720 }, // No translation, no dilation
66 { -1.456369, -2.1056073, 0.3855449 },
67 { 2.669785, -0.3375384, -0.5383219 },
68 },
69 {
70 { 3.9949788, -1.2385190, 0.1258216 },
71 { 0.3349586, -1.9233277, 0.3040794 },
72 { 4.6621931, -0.7344788, -0.6267413 }
73 },
74 {
75
76 { 6.682553, -2.861341, 0.7631174 },
77 { -4.719800, -6.823849, 1.2494734 },
78 { 8.652235, -1.093894, -1.7445929 },
79 }
80 };
81 }