49 protected double[] imu2;
50 protected double[] imuLambdaZ;
51 protected double[] imuOver2LambdaZ;
53 protected int[] wIndexList;
54 protected int bridgeCounter = -1;
62 super(s0, delta, gamma, stream, otherStream);
63 numberOfRandomStreams = 2;
75 for (
int j = 0; j < d; j++)
85 public double[]
generatePath(
double[] unifNorm,
double[] unifOther) {
90 normalGen.setStream(stream);
96 for (
int j = 0; j < d; j++)
99 stream = cacheStreamNormal;
100 normalGen.setStream(stream);
101 otherStream = cacheStreamOther;
110 if (bridgeCounter == -1) {
111 double temp = delta * (t[d] - t[0]);
114 observationIndex = d;
116 int j = bridgeCounter * 3;
117 int oldIndexL = wIndexList[j];
118 int newIndex = wIndexList[j + 1];
119 int oldIndexR = wIndexList[j + 2];
122 double q = normalGen.nextDouble();
125 double z = path[oldIndexR];
126 double mu = imu[newIndex];
127 double muLambda = imuLambdaZ[newIndex] / z;
128 double mu2 = imu2[newIndex];
129 double muOver2Lambda = imuOver2LambdaZ[newIndex] * z;
131 double root = mu + muOver2Lambda * mu * q - muOver2Lambda * Math.sqrt(4. * muLambda * q + mu2 * q * q);
132 double probabilityRoot1 = mu * (1. + root) / (1. + mu) / (root + mu);
134 if (otherStream.nextDouble() > probabilityRoot1)
136 s = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) / (1.0 + root);
138 observationIndex = newIndex;
140 observationCounter = bridgeCounter + 1;
141 path[observationIndex] = s;
146 observationIndex = 0;
147 observationCounter = 0;
151 protected void init() {
160 if (observationTimesSet) {
161 wIndexList =
new int[3 * d];
163 int[] ptIndex =
new int[d + 1];
164 int indexCounter = 0;
165 int newIndex, oldIndexL, oldIndexR;
171 imu =
new double[d + 1];
172 ilam =
new double[d + 1];
173 imu2 =
new double[d + 1];
174 imuLambdaZ =
new double[d + 1];
175 imuOver2LambdaZ =
new double[d + 1];
177 for (
int powOfTwo = 1; powOfTwo <= d / 2; powOfTwo *= 2) {
179 for (
int j = powOfTwo; j >= 1; j--)
180 ptIndex[2 * j] = ptIndex[j];
183 for (
int j = 1; j <= powOfTwo; j++) {
184 oldIndexL = 2 * j - 2;
186 newIndex = (int) (0.5 * (ptIndex[oldIndexL] + ptIndex[oldIndexR]));
188 tauX = t[newIndex] - t[ptIndex[oldIndexL]];
189 tauY = t[ptIndex[oldIndexR]] - t[newIndex];
191 lambdaZ = delta * delta * tauY * tauY;
193 ilam[newIndex] = lambdaZ;
194 imu2[newIndex] = mu * mu;
195 imuLambdaZ[newIndex] = mu * lambdaZ;
196 imuOver2LambdaZ[newIndex] = mu / 2. / lambdaZ;
198 ptIndex[oldIndexL + 1] = newIndex;
199 wIndexList[indexCounter] = ptIndex[oldIndexL];
200 wIndexList[indexCounter + 1] = newIndex;
201 wIndexList[indexCounter + 2] = ptIndex[oldIndexR];
208 for (
int k = 1; k < d; k++) {
209 if (ptIndex[k - 1] + 1 < ptIndex[k]) {
212 tauX = t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]];
213 tauY = t[ptIndex[k]] - t[ptIndex[k - 1] + 1];
215 lambdaZ = delta * delta * tauY * tauY;
216 imu[ptIndex[k - 1] + 1] = mu;
217 ilam[ptIndex[k - 1] + 1] = lambdaZ;
218 imu2[ptIndex[k - 1] + 1] = mu * mu;
219 imuLambdaZ[ptIndex[k - 1] + 1] = mu * lambdaZ;
220 imuOver2LambdaZ[ptIndex[k - 1] + 1] = mu / 2. / lambdaZ;
222 wIndexList[indexCounter] = ptIndex[k] - 2;
223 wIndexList[indexCounter + 1] = ptIndex[k] - 1;
224 wIndexList[indexCounter + 2] = ptIndex[k];
235 if (stream != otherStream)
236 throw new IllegalStateException(
"Two different streams or more are present");
244 this.stream = stream;
245 this.otherStream = otherStream;
246 normalGen.setStream(stream);
static double nextDouble(RandomStream s, NormalGen sn, double mu, double lambda)
Generates a new variate from the inverse gaussian distribution with parameters mu and lambda,...