25package umontreal.ssj.stochprocess;
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.randvar.*;
30import umontreal.ssj.util.Num;
53 protected double mu2OverNu, mu2dTOverNu;
54 protected double[] bMu2dtOverNuL,
56 protected int[] wIndexList;
57 protected int bridgeCounter = -1;
81 super(s0, mu, nu, Ggen);
84 this.stream = Ggen.getStream();
89 if (bridgeCounter == -1) {
90 s = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
96 int j = bridgeCounter * 3;
97 int oldIndexL = wIndexList[j];
98 int newIndex = wIndexList[j + 1];
99 int oldIndexR = wIndexList[j + 2];
101 double y = Bgen.nextDouble(stream, bMu2dtOverNuL[newIndex], bMu2dtOverNuR[newIndex], 0.0, 1.0);
102 s = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
104 if (s <= path[oldIndexL])
105 s = setLarger(path, oldIndexL, oldIndexR);
107 observationIndex = newIndex;
109 observationCounter = bridgeCounter + 1;
110 path[observationIndex] = s;
116 if (bridgeCounter == -1) {
118 mu2dTOverNu = mu2OverNu * (t[d] - t[0]);
119 s = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
123 observationIndex = d;
125 int j = bridgeCounter * 3;
126 int oldIndexL = wIndexList[j];
127 int newIndex = wIndexList[j + 1];
128 int oldIndexR = wIndexList[j + 2];
131 bMu2dtOverNuL[newIndex] = mu2OverNu * (t[newIndex] - t[oldIndexL]);
132 bMu2dtOverNuR[newIndex] = mu2OverNu * (t[oldIndexR] - t[newIndex]);
134 double y = Bgen.nextDouble(stream, bMu2dtOverNuL[newIndex], bMu2dtOverNuR[newIndex], 0.0, 1.0);
136 s = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
138 if (s <= path[oldIndexL])
139 s = setLarger(path, oldIndexL, oldIndexR);
141 observationIndex = newIndex;
143 observationCounter = bridgeCounter + 1;
144 path[observationIndex] = s;
149 int oldIndexL, oldIndexR, newIndex;
153 for (
int j = 0; j < 3 * (d - 1); j += 3) {
154 oldIndexL = wIndexList[j];
155 newIndex = wIndexList[j + 1];
156 oldIndexR = wIndexList[j + 2];
158 y =
BetaDist.
inverseF(bMu2dtOverNuL[newIndex], bMu2dtOverNuR[newIndex], 8, uniform01[1 + j / 3]);
160 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
162 if (path[newIndex] <= path[oldIndexL])
163 setLarger(path, oldIndexL, newIndex, oldIndexR);
166 observationIndex = d;
167 observationCounter = d;
172 int oldIndexL, oldIndexR, newIndex;
175 path[d] = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
176 for (
int j = 0; j < 3 * (d - 1); j += 3) {
177 oldIndexL = wIndexList[j];
178 newIndex = wIndexList[j + 1];
179 oldIndexR = wIndexList[j + 2];
181 y = Bgen.nextDouble(stream, bMu2dtOverNuL[newIndex], bMu2dtOverNuR[newIndex], 0.0, 1.0);
182 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
184 if (path[newIndex] <= path[oldIndexL])
185 setLarger(path, oldIndexL, newIndex, oldIndexR);
188 observationIndex = d;
189 observationCounter = d;
194 observationIndex = 0;
195 observationCounter = 0;
199 protected void init() {
201 if (observationTimesSet) {
204 bMu2dtOverNuL =
new double[d + 1];
205 bMu2dtOverNuR =
new double[d + 1];
206 wIndexList =
new int[3 * d];
208 int[] ptIndex =
new int[d + 1];
209 int indexCounter = 0;
210 int newIndex, oldLeft, oldRight;
215 mu2OverNu = mu * mu / nu;
216 mu2dTOverNu = mu2OverNu * (t[d] - t[0]);
218 for (
int powOfTwo = 1; powOfTwo <= d / 2; powOfTwo *= 2) {
220 for (
int j = powOfTwo; j >= 1; j--) {
221 ptIndex[2 * j] = ptIndex[j];
225 for (
int j = 1; j <= powOfTwo; j++) {
228 newIndex = (int) (0.5 * (ptIndex[oldLeft] + ptIndex[oldRight]));
230 bMu2dtOverNuL[newIndex] = mu * mu * (t[newIndex] - t[ptIndex[oldLeft]]) / nu;
231 bMu2dtOverNuR[newIndex] = mu * mu * (t[ptIndex[oldRight]] - t[newIndex]) / nu;
233 ptIndex[oldLeft + 1] = newIndex;
234 wIndexList[indexCounter] = ptIndex[oldLeft];
235 wIndexList[indexCounter + 1] = newIndex;
236 wIndexList[indexCounter + 2] = ptIndex[oldRight];
242 for (
int k = 1; k < d; k++) {
243 if (ptIndex[k - 1] + 1 < ptIndex[k]) {
246 bMu2dtOverNuL[ptIndex[k - 1] + 1] = mu * mu * (t[ptIndex[k - 1] + 1] - t[ptIndex[k - 1]]) / nu;
247 bMu2dtOverNuR[ptIndex[k - 1] + 1] = mu * mu * (t[ptIndex[k]] - t[ptIndex[k - 1] + 1]) / nu;
249 wIndexList[indexCounter] = ptIndex[k] - 2;
250 wIndexList[indexCounter + 1] = ptIndex[k] - 1;
251 wIndexList[indexCounter + 2] = ptIndex[k];
265 super.setStream(stream);
267 this.stream = stream;
Extends the class ContinuousDistribution for the beta distribution.
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 .
This class implements random variate generators with the beta distribution with shape parameters and...
This class implements random variate generators for the gamma distribution.
void setStream(RandomStream stream)
Sets the umontreal.ssj.rng.RandomStream used by this generator to stream.
double nextObservation()
Generates and returns the next observation of the stochastic process.
GammaProcessBridge(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcessBridge with parameters , and initial value .
double nextObservation(double nextT)
Generates and returns the next observation at time , using the previous observation time defined ea...
void resetStartProcess()
Resets the observation counter to its initial value , so that the current observation becomes .
double[] generatePath(double[] uniform01)
Generates, returns and saves the path .
double[] generatePath()
Generates, returns and saves the path .
GammaProcessBridge(double s0, double mu, double nu, GammaGen Ggen, BetaGen Bgen)
Constructs a new GammaProcessBridge.
void setStream(RandomStream stream)
Resets the umontreal.ssj.rng.RandomStream of the.
GammaProcess(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcess with parameters , and initial value .
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...