SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GammaProcessPCABridge.java
1/*
2 * Class: GammaProcessPCABridge
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Jean-Sébastien Parent and Maxime Dion
9 * @since july 2008
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.stochprocess;
26
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.randvar.*;
30
39 protected BrownianMotionBridge BMBridge;
40 protected double mu2OverNu, mu2dTOverNu;
41 protected double[] bMu2dtOverNuL, // For precomputations for G Bridge
42 bMu2dtOverNuR;
43 protected int[] wIndexList;
44
53 public GammaProcessPCABridge(double s0, double mu, double nu, RandomStream stream) {
54 super(s0, mu, nu, stream);
55 this.BMBridge = new BrownianMotionBridge(0.0, 0.0, Math.sqrt(nu), stream);
56 }
57
58 public double[] generatePath(double[] uniform01) {
59 // uniformsV[] of size d+1, but element 0 never used.
60 double[] uniformsV = new double[d + 1];
61
62 // generate BrownianMotion PCA path
63 double[] BMPCApath = BMPCA.generatePath(uniform01);
64 int oldIndexL;
65 int newIndex;
66 int oldIndexR;
67 double temp, y;
68 // Transform BMPCA points to uniforms using an inverse bridge.
69 for (int j = 0; j < 3 * (d - 1); j += 3) {
70 oldIndexL = BMBridge.wIndexList[j];
71 newIndex = BMBridge.wIndexList[j + 1];
72 oldIndexR = BMBridge.wIndexList[j + 2];
73
74 temp = BMPCApath[newIndex] - BMPCApath[oldIndexL];
75 temp -= (BMPCApath[oldIndexR] - BMPCApath[oldIndexL]) * BMBridge.wMuDt[newIndex];
76 temp /= BMBridge.wSqrtDt[newIndex];
77 uniformsV[newIndex] = NormalDist.cdf01(temp);
78 }
79 double dT = BMPCA.t[d] - BMPCA.t[0];
80 uniformsV[d] = NormalDist.cdf01((BMPCApath[d] - BMPCApath[0] - BMPCA.mu * dT) / (BMPCA.sigma * Math.sqrt(dT)));
81
82 // Reconstruct the bridge for the GammaProcess from the Brownian uniforms.
83 path[0] = x0;
84 path[d] = x0 + GammaDist.inverseF(mu2dTOverNu, muOverNu, 10, uniformsV[d]);
85 for (int j = 0; j < 3 * (d - 1); j += 3) {
86 oldIndexL = wIndexList[j];
87 newIndex = wIndexList[j + 1];
88 oldIndexR = wIndexList[j + 2];
89
90 y = BetaDist.inverseF(bMu2dtOverNuL[newIndex], bMu2dtOverNuR[newIndex], 8, uniformsV[newIndex]);
91
92 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
93 }
94 observationIndex = d;
95 observationCounter = d;
96 return path;
97 }
98
99 public double[] generatePath() {
100 double[] u = new double[d];
101 for (int i = 0; i < d; i++)
102 u[i] = stream.nextDouble();
103 return generatePath(u);
104 }
105
106 public void setParams(double s0, double mu, double nu) {
107 super.setParams(s0, mu, nu);
108 BMBridge.setParams(0.0, 0.0, Math.sqrt(nu));
109 BMPCA.setParams(0.0, 0.0, Math.sqrt(nu));
110 }
111
112 public void setObservationTimes(double[] t, int d) {
113 super.setObservationTimes(t, d);
114 BMBridge.setObservationTimes(t, d);
115 }
116
121 return BMPCA;
122 }
123
124 protected void init() {
125 super.init();
126 if (observationTimesSet) {
127
128 // Quantities for gamma bridge process
129 bMu2dtOverNuL = new double[d + 1];
130 bMu2dtOverNuR = new double[d + 1];
131 wIndexList = new int[3 * d];
132
133 int[] ptIndex = new int[d + 1];
134 int indexCounter = 0;
135 int newIndex, oldLeft, oldRight;
136
137 ptIndex[0] = 0;
138 ptIndex[1] = d;
139
140 mu2OverNu = mu * mu / nu;
141 mu2dTOverNu = mu2OverNu * (t[d] - t[0]);
142
143 for (int powOfTwo = 1; powOfTwo <= d / 2; powOfTwo *= 2) {
144 /* Make room in the indexing array "ptIndex" */
145 for (int j = powOfTwo; j >= 1; j--) {
146 ptIndex[2 * j] = ptIndex[j];
147 }
148
149 /* Insert new indices and Calculate constants */
150 for (int j = 1; j <= powOfTwo; j++) {
151 oldLeft = 2 * j - 2;
152 oldRight = 2 * j;
153 newIndex = (int) (0.5 * (ptIndex[oldLeft] + ptIndex[oldRight]));
154
155 bMu2dtOverNuL[newIndex] = mu * mu * (t[newIndex] - t[ptIndex[oldLeft]]) / nu;
156 bMu2dtOverNuR[newIndex] = mu * mu * (t[ptIndex[oldRight]] - t[newIndex]) / nu;
157
158 ptIndex[oldLeft + 1] = newIndex;
159 wIndexList[indexCounter] = ptIndex[oldLeft];
160 wIndexList[indexCounter + 1] = newIndex;
161 wIndexList[indexCounter + 2] = ptIndex[oldRight];
162
163 indexCounter += 3;
164 }
165 }
166 /* Check if there are holes remaining and fill them */
167 for (int k = 1; k < d; k++) {
168 if (ptIndex[k - 1] + 1 < ptIndex[k]) {
169 // there is a hole between (k-1) and k.
170
171 bMu2dtOverNuL[ptIndex[k - 1] + 1] = mu * mu * (t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]]) / nu;
172 bMu2dtOverNuR[ptIndex[k - 1] + 1] = mu * mu * (t[ptIndex[k]] - t[ptIndex[k - 1] + 1]) / nu;
173
174 wIndexList[indexCounter] = ptIndex[k] - 2;
175 wIndexList[indexCounter + 1] = ptIndex[k] - 1;
176 wIndexList[indexCounter + 2] = ptIndex[k];
177 indexCounter += 3;
178 }
179 }
180 }
181 }
182
183}
Extends the class ContinuousDistribution for the beta distribution.
Definition BetaDist.java:54
double inverseF(double u)
Returns the inverse distribution function .
Extends the class ContinuousDistribution for the gamma distribution tjoh95a  (page 337) with shape pa...
double inverseF(double u)
Returns the inverse distribution function .
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double cdf01(double x)
Same as cdf(0, 1, x).
Represents a Brownian motion process sampled using the bridge sampling technique (see for example.
A Brownian motion process sampled using the principal component decomposition (PCA) fgla04a,...
void setObservationTimes(double[] t, int d)
Sets the observation times of the GammaProcessPCA and the.
BrownianMotionPCA getBMPCA()
Returns the inner BrownianMotionPCA.
double[] generatePath(double[] uniform01)
Generates, returns and saves the path .
void setParams(double s0, double mu, double nu)
Sets the parameters s0, and to new values, and sets the variance parameters of the BrownianMotionPC...
GammaProcessPCABridge(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcessPCABridge with parameters , and initial value .
double[] generatePath()
Generates, returns and saves the path .
GammaProcessPCA(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcessPCA with parameters , and initial value .
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...