1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.util;
18
19 import org.hipparchus.exception.MathIllegalArgumentException;
20 import org.hipparchus.linear.MatrixUtils;
21 import org.hipparchus.linear.RealMatrix;
22 import org.hipparchus.linear.RealVector;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 public class JulierUnscentedTransformTest {
27
28
29 @Test(expected = MathIllegalArgumentException.class)
30 public void testWrongStateDimension() {
31 new JulierUnscentedTransform(0);
32 }
33
34
35 @Test
36 public void testWeights() {
37
38
39 final int stateDim = 2;
40 final JulierUnscentedTransform julier = new JulierUnscentedTransform(stateDim, 0.0);
41 final RealVector wc = julier.getWc();
42 final RealVector wm = julier.getWm();
43
44
45 Assert.assertEquals(5, wc.getDimension());
46 Assert.assertEquals(5, wm.getDimension());
47 Assert.assertEquals(0.0, wc.getEntry(0), Double.MIN_VALUE);
48 Assert.assertEquals(0.0, wm.getEntry(0), Double.MIN_VALUE);
49 Assert.assertEquals(0.25, wc.getEntry(1), Double.MIN_VALUE);
50 Assert.assertEquals(0.25, wm.getEntry(1), Double.MIN_VALUE);
51 Assert.assertEquals(0.25, wc.getEntry(2), Double.MIN_VALUE);
52 Assert.assertEquals(0.25, wm.getEntry(2), Double.MIN_VALUE);
53
54 }
55
56
57 @Test
58 public void testUnscentedTransform() {
59
60
61 final int stateDim = 2;
62 final JulierUnscentedTransform julier = new JulierUnscentedTransform(stateDim);
63 final RealVector state = MatrixUtils.createRealVector(new double[] {1.0, 1.0});
64 final RealMatrix covariance = MatrixUtils.createRealDiagonalMatrix(new double[] {0.5, 0.5});
65
66
67 final RealVector[] sigma = julier.unscentedTransform(state, covariance);
68
69
70 Assert.assertEquals(5, sigma.length);
71 checkSigmaPoint(sigma[0], 1.0, 1.0);
72 checkSigmaPoint(sigma[1], 2.0, 1.0);
73 checkSigmaPoint(sigma[2], 1.0, 2.0);
74 checkSigmaPoint(sigma[3], 0.0, 1.0);
75 checkSigmaPoint(sigma[4], 1.0, 0.0);
76
77 }
78
79
80 @Test
81 public void testInverseUnscentedTransform() {
82
83
84 final int stateDim = 2;
85 final JulierUnscentedTransform julier = new JulierUnscentedTransform(stateDim);
86 final RealVector[] sigmaPoints = new RealVector[] {MatrixUtils.createRealVector(new double[] {1.0, 1.0}),
87 MatrixUtils.createRealVector(new double[] {2.0, 1.0}),
88 MatrixUtils.createRealVector(new double[] {1.0, 2.0}),
89 MatrixUtils.createRealVector(new double[] {0.0, 1.0}),
90 MatrixUtils.createRealVector(new double[] {1.0, 0.0})};
91
92 final Pair<RealVector, RealMatrix> inverse = julier.inverseUnscentedTransform(sigmaPoints);
93 final RealVector state = inverse.getFirst();
94 final RealMatrix covariance = inverse.getSecond();
95
96
97 Assert.assertEquals(2, state.getDimension());
98 Assert.assertEquals(1.0, state.getEntry(0), 0.);
99 Assert.assertEquals(1.0, state.getEntry(1), 0.);
100
101 Assert.assertEquals(2, covariance.getColumnDimension());
102 Assert.assertEquals(2, covariance.getRowDimension());
103 Assert.assertEquals(0.5, covariance.getEntry(0, 0), 0.);
104 Assert.assertEquals(0.0, covariance.getEntry(0, 1), 0.);
105 Assert.assertEquals(0.0, covariance.getEntry(1, 0), 0.);
106 Assert.assertEquals(0.5, covariance.getEntry(1, 1), 0.);
107 }
108
109 private static void checkSigmaPoint(final RealVector sigma, final double ref1, final double ref2) {
110 Assert.assertEquals(ref1, sigma.getEntry(0), Double.MIN_VALUE);
111 Assert.assertEquals(ref2, sigma.getEntry(1), Double.MIN_VALUE);
112 }
113
114 }