1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.random;
18
19 import org.hipparchus.util.FastMath;
20 import org.junit.Assert;
21 import org.junit.Test;
22
23 public class GaussMarkovGeneratorTest {
24
25 @Test
26 public void testExpectation() {
27 final double tau = 3600.0;
28 final double stationarySigma = 0.2;
29 final RandomGenerator random = new Well1024a(0xb8005f29892534a8L);
30 GaussMarkovGenerator gm = new GaussMarkovGenerator(tau,
31 stationarySigma,
32 random);
33 Assert.assertEquals(tau, gm.getTau(), 1.0e-15);
34 Assert.assertEquals(stationarySigma, gm.getStationarySigma(), 1.0e-15);
35
36 double sum = 0;
37 int count = 0;
38 final double deltaT = 0.1;
39 for (double t = 0; t < 1000000; t += deltaT) {
40 sum += gm.next(deltaT);
41
42 ++count;
43 }
44 Assert.assertEquals(0.0, sum / count, 0.014);
45 }
46
47 @Test
48 public void testVariance() {
49 final double tau = 3600.0;
50 final double stationarySigma = 0.2;
51 final RandomGenerator random = new Well1024a(0x09efbd4e87e7791eL);
52 GaussMarkovGenerator gm = new GaussMarkovGenerator(tau,
53 stationarySigma,
54 random);
55
56
57 double sum2 = 0;
58 int count = 0;
59 final double deltaT = 0.1;
60 for (double t = 0; t < 1000000; t += deltaT) {
61 final double v = gm.next(tau);
62 ++count;
63 sum2 += v * v;
64 }
65
66 Assert.assertEquals(gm.getStationarySigma(), FastMath.sqrt(sum2 / count), 3.7e-5);
67
68 }
69
70 }