Debian Codegraph @

src/test/dr/multidimensionalscaling/MDSRotationTest.java

raw symbols SCIP
1 /*
2 * MDSTest.java
3 *
4 * Copyright (c) 2002-2014 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package test.dr.multidimensionalscaling;
27
28 import dr.inference.operators.EllipticalSliceOperator;
29 import dr.math.MathUtils;
30 import dr.math.matrixAlgebra.Vector;
31 import test.dr.math.MathTestCase;
32
33 /**
34 * @author Marc A. Suchard
35 */
36 public class MDSRotationTest extends MathTestCase {
37
38
39 private static final double tolerance = 1E-6;
40
41 public void testRotation() {
42 final int dim = 3;
43 final int length = 2;
44
45 MathUtils.setSeed(666);
46
47 double[] x = new double[dim * length];
48 for (int i = 0; i < x.length; ++i) {
49 x[i] = 10.0 * MathUtils.nextGaussian();
50 }
51
52 System.err.println("Starting vector: " + new Vector(x));
53
54 double[] initialLength = new double[length];
55 for (int i = 0; i < length; ++i) {
56 initialLength[i] = norm(x, i * dim, dim);
57 System.err.println("\tlength = " + initialLength[i]);
58 }
59
60 EllipticalSliceOperator.transformPoint(x, false, true, dim);
61
62 System.err.println("Ending vector : " + new Vector(x));
63
64 double[] finalLength = new double[length];
65 for (int i = 0; i < length; ++i) {
66 finalLength[i] = norm(x, i * dim, dim);
67 System.err.println("\tlength = " + finalLength[i]);
68 }
69
70 assertEquals(initialLength, finalLength, tolerance);
71
72 }
73
74 private double norm(double[] x, int offset, int dim) {
75 double sum = 0.0;
76 for (int i = 0; i < dim; ++i) {
77 sum += x[offset + i] * x[offset + i];
78 }
79 return Math.sqrt(sum);
80 }
81
82 // public void testInitialization() {
83 // if (mds != null) {
84 // int i = mds.initialize(2, 100, 0);
85 // assertEquals(i, 0);
86 // i = mds.initialize(2, 100, 0);
87 // assertEquals(i, 1);
88 // } else {
89 // System.out.println("testInitialization skipped");
90 // }
91 //
92 // }
93 //
94 // public void testMakeDirty() {
95 // if (mds != null) {
96 // mds.makeDirty(0);
97 // } else {
98 // System.out.println("testMakeDirty skipped");
99 // }
100 //
101 // }
102
103
104 }