75 protected int bridgeCounter = -1;
78 protected double[] wMuDt, wSqrtDt;
79 protected int[] wIndexList, ptIndex;
88 super(x0, mu, sigma, stream);
98 super(x0, mu, sigma, gen);
103 if (bridgeCounter == -1) {
104 x = x0 + mu * (t[d] - t[0]) + wSqrtDt[0] * gen.nextDouble();
106 observationIndex = d;
108 int j = bridgeCounter * 3;
109 int oldIndexL = wIndexList[j];
110 int newIndex = wIndexList[j + 1];
111 int oldIndexR = wIndexList[j + 2];
113 x = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * wMuDt[newIndex]
114 + wSqrtDt[newIndex] * gen.nextDouble();
117 observationIndex = newIndex;
119 observationCounter = bridgeCounter + 1;
120 path[observationIndex] = x;
126 if (bridgeCounter == -1) {
131 wSqrtDt[0] = sigma * Math.sqrt(t[d] - t[0]);
134 x = x0 + mu * (t[d] - t[0]) + wSqrtDt[0] * gen.nextDouble();
137 observationIndex = d;
139 int j = bridgeCounter * 3;
140 int oldIndexL = wIndexList[j];
141 int newIndex = wIndexList[j + 1];
142 int oldIndexR = wIndexList[j + 2];
144 t[newIndex] = nextTime;
146 double dtRL = t[oldIndexR] - t[oldIndexL];
148 wMuDt[newIndex] = (t[newIndex] - t[oldIndexL]) / dtRL;
150 wMuDt[newIndex] = 0.0;
152 wSqrtDt[newIndex] = sigma * Math.sqrt(wMuDt[newIndex] * (t[oldIndexR] - t[newIndex]));
154 x = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * wMuDt[newIndex]
155 + wSqrtDt[newIndex] * gen.nextDouble();
158 observationIndex = newIndex;
160 observationCounter = bridgeCounter + 1;
161 path[observationIndex] = x;
167 int oldIndexL, oldIndexR, newIndex;
168 path[d] = x0 + mu * (t[d] - t[0]) + wSqrtDt[0] * gen.nextDouble();
170 for (
int j = 0; j < 3 * (d - 1); j += 3) {
171 oldIndexL = wIndexList[j];
172 newIndex = wIndexList[j + 1];
173 oldIndexR = wIndexList[j + 2];
175 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * wMuDt[newIndex]
176 + wSqrtDt[newIndex] * gen.nextDouble();
180 observationIndex = d;
181 observationCounter = d;
186 int oldIndexL, oldIndexR, newIndex;
189 for (
int j = 0; j < 3 * (d - 1); j += 3) {
190 oldIndexL = wIndexList[j];
191 newIndex = wIndexList[j + 1];
192 oldIndexR = wIndexList[j + 2];
194 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * wMuDt[newIndex]
199 observationIndex = d;
200 observationCounter = d;
205 observationIndex = 0;
206 observationCounter = 0;
210 protected void init() {
216 wMuDt =
new double[d + 1];
217 wSqrtDt =
new double[d + 1];
218 wIndexList =
new int[3 * (d)];
219 ptIndex =
new int[d + 1];
222 int indexCounter = 0;
223 int newIndex, oldLeft, oldRight;
231 throw new IllegalStateException(
" t[d] < t[0]");
232 wSqrtDt[0] = sigma * Math.sqrt(t[d] - t[0]);
235 for (
int powOfTwo = 1; powOfTwo <= d / 2; powOfTwo *= 2) {
237 for (
int j = powOfTwo; j >= 1; j--) {
238 ptIndex[2 * j] = ptIndex[j];
242 for (
int j = 1; j <= powOfTwo; j++) {
245 newIndex = (int) (0.5 * (ptIndex[oldLeft] + ptIndex[oldRight]));
247 wMuDt[newIndex] = (t[newIndex] - t[ptIndex[oldLeft]]) / (t[ptIndex[oldRight]] - t[ptIndex[oldLeft]]);
248 tem = (t[newIndex] - t[ptIndex[oldLeft]]) * (t[ptIndex[oldRight]] - t[newIndex])
249 / (t[ptIndex[oldRight]] - t[ptIndex[oldLeft]]);
252 if (tem < 0 || tem != tem) {
253 System.out.printf(
"t[newIndex] - t[ptIndex[oldLeft]] = %g%n", t[newIndex] - t[ptIndex[oldLeft]]);
254 System.out.printf(
"t[ptIndex[oldRight]] - t[newIndex] = %g%n", t[ptIndex[oldRight]] - t[newIndex]);
255 System.out.printf(
"t[ptIndex[oldRight]] - t[ptIndex[oldLeft]] = %g%n",
256 t[ptIndex[oldRight]] - t[ptIndex[oldLeft]]);
257 System.out.printf(
"t[ptIndex[oldRight]] = %g%n", t[ptIndex[oldRight]]);
258 System.out.printf(
"t[ptIndex[oldLeft]] = %g%n", t[ptIndex[oldLeft]]);
259 throw new IllegalStateException(
" tem < 0 or NaN");
261 wSqrtDt[newIndex] = sigma * Math.sqrt(tem);
263 ptIndex[oldLeft + 1] = newIndex;
264 wIndexList[indexCounter] = ptIndex[oldLeft];
265 wIndexList[indexCounter + 1] = newIndex;
266 wIndexList[indexCounter + 2] = ptIndex[oldRight];
272 for (
int k = 1; k < d; k++) {
273 if (ptIndex[k - 1] + 1 < ptIndex[k]) {
275 wMuDt[ptIndex[k - 1] + 1] = (t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]])
276 / (t[ptIndex[k]] - t[ptIndex[k - 1]]);
277 tem = (t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]]) * (t[ptIndex[k]] - t[ptIndex[k - 1] + 1])
278 / (t[ptIndex[k]] - t[ptIndex[k - 1]]);
281 if (tem < 0 || tem != tem) {
282 System.out.printf(
"t[ptIndex[k-1]+1] - t[ptIndex[k-1]] = %g%n",
283 t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]]);
284 System.out.printf(
"t[ptIndex[k]] - t[ptIndex[k-1]+1] = %g%n", t[ptIndex[k]] - t[ptIndex[k - 1] + 1]);
285 System.out.printf(
"t[ptIndex[k]] - t[ptIndex[k-1]] = %g%n", t[ptIndex[k]] - t[ptIndex[k - 1]]);
286 System.out.printf(
"t[ptIndex[k]] = %20.16g%n", t[ptIndex[k]]);
287 System.out.printf(
"t[ptIndex[k-1]] = %20.16g%n", t[ptIndex[k - 1]]);
288 throw new IllegalStateException(
" tem < 0 or NaN");
290 wSqrtDt[ptIndex[k - 1] + 1] = sigma * Math.sqrt(tem);
291 wIndexList[indexCounter] = ptIndex[k] - 2;
292 wIndexList[indexCounter + 1] = ptIndex[k] - 1;
293 wIndexList[indexCounter + 2] = ptIndex[k];