| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
} |