SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GammaProcessSymmetricalBridge.java
1/*
2 * Class: GammaProcessSymmetricalBridge
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 * @authors Pierre Tremblay and Jean-Sébastien Parent
9 * @since July 2003
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.*;
30import umontreal.ssj.util.*;
31
45 protected BetaSymmetricalGen BSgen;
46
57 public GammaProcessSymmetricalBridge(double s0, double mu, double nu, RandomStream stream) {
58 this(s0, mu, nu, new GammaGen(stream, new GammaDist(1.0)),
59 new BetaSymmetricalGen(stream, new BetaSymmetricalDist(1.0)));
60 }
61
73 public GammaProcessSymmetricalBridge(double s0, double mu, double nu, GammaGen Ggen, BetaSymmetricalGen BSgen) {
74 super(s0, mu, nu, Ggen, BSgen);
75 this.BSgen = BSgen;
76 BSgen.setStream(Ggen.getStream());
77 }
78
79 public double nextObservation() {
80 double s;
81 if (bridgeCounter == -1) {
82 s = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
83 if (s <= x0)
84 s = setLarger(x0);
85 bridgeCounter = 0;
86 observationIndex = d;
87 } else {
88 int j = bridgeCounter * 3;
89 int oldIndexL = wIndexList[j];
90 int newIndex = wIndexList[j + 1];
91 int oldIndexR = wIndexList[j + 2];
92
93 double y = BSgen.nextDouble(stream, bMu2dtOverNuL[newIndex]);
94
95 s = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
96 if (s <= path[oldIndexL])
97 s = setLarger(path, oldIndexL, oldIndexR);
98 bridgeCounter++;
99 observationIndex = newIndex;
100 }
101 observationCounter = bridgeCounter + 1;
102 path[observationIndex] = s;
103 return s;
104 }
105
106 public double nextObservation(double nextT) {
107 double s;
108 if (bridgeCounter == -1) {
109 t[d] = nextT;
110 mu2dTOverNu = mu2OverNu * (t[d] - t[0]);
111 s = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
112 if (s <= x0)
113 s = setLarger(x0);
114 bridgeCounter = 0;
115 observationIndex = d;
116 } else {
117 int j = bridgeCounter * 3;
118 int oldIndexL = wIndexList[j];
119 int newIndex = wIndexList[j + 1];
120 int oldIndexR = wIndexList[j + 2];
121
122 t[newIndex] = nextT;
123 bMu2dtOverNuL[newIndex] = mu2OverNu * (t[newIndex] - t[oldIndexL]);
124
125 double y = BSgen.nextDouble(stream, bMu2dtOverNuL[newIndex]);
126
127 s = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
128 if (s <= path[oldIndexL])
129 s = setLarger(path, oldIndexL, oldIndexR);
130 bridgeCounter++;
131 observationIndex = newIndex;
132 }
133 observationCounter = bridgeCounter + 1;
134 path[observationIndex] = s;
135 return s;
136 }
137
138 public double[] generatePath() {
139 int oldIndexL, oldIndexR, newIndex;
140
141 path[d] = x0 + Ggen.nextDouble(stream, mu2dTOverNu, muOverNu);
142 for (int j = 0; j < 3 * (d - 1); j += 3) {
143 oldIndexL = wIndexList[j];
144 newIndex = wIndexList[j + 1];
145 oldIndexR = wIndexList[j + 2];
146
147 double y = BSgen.nextDouble(stream, bMu2dtOverNuL[newIndex]);
148
149 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
150 if (path[newIndex] <= path[oldIndexL])
151 setLarger(path, oldIndexL, newIndex, oldIndexR);
152 }
153 observationIndex = d;
154 observationCounter = d;
155 return path;
156 }
157
158 public double[] generatePath(double[] uniform01) {
159 int oldIndexL, oldIndexR, newIndex;
160
161 path[d] = x0 + GammaDist.inverseF(mu2dTOverNu, muOverNu, 10, uniform01[0]);
162 for (int j = 0; j < 3 * (d - 1); j += 3) {
163 oldIndexL = wIndexList[j];
164 newIndex = wIndexList[j + 1];
165 oldIndexR = wIndexList[j + 2];
166
167 double y = BetaSymmetricalDist.inverseF(bMu2dtOverNuL[newIndex], uniform01[1 + j / 3]);
168
169 path[newIndex] = path[oldIndexL] + (path[oldIndexR] - path[oldIndexL]) * y;
170 if (path[newIndex] <= path[oldIndexL])
171 setLarger(path, oldIndexL, newIndex, oldIndexR);
172 }
173 observationIndex = d;
174 observationCounter = d;
175 return path;
176 }
177
178 protected void init() {
179 super.init();
180 if (observationTimesSet) {
181
182 /* Testing to make sure number of observations n = 2^k */
183 int k = 0;
184 int x = d;
185 int y = 1;
186 while (x > 1) {
187 x = x / 2;
188 y = y * 2;
189 k++;
190 }
191 if (y != d)
192 throw new IllegalArgumentException(
193 "GammaProcessSymmetricalBridge:" + "Number 'n' of observation times is not a power of 2");
194
195 /* Testing that time intervals are equidistant */
196 boolean equidistant = true;
197 double macheps = 1.0e-13; // Num.DBL_EPSILON;
198 double dt = t[1] - t[0];
199 for (int i = 1; i < d; i++) {
200 if ((t[i + 1] - t[i]) != dt) { // not equidistant
201 equidistant = false;
202 /*
203 * This compensates the fact that the dt's may be different due to numerical
204 * idiosyncracies
205 */
206 if (dt != 0.0)
207 if (Math.abs((t[i + 1] - t[i]) - dt) / dt <= macheps)
208 equidistant = true;
209 }
210 }
211 if (!equidistant)
212 throw new IllegalArgumentException(
213 "GammaProcessSymmetricalBridge:" + "Observation times of sample paths are not equidistant");
214 }
215 }
216}
Specializes the class BetaDist to the case of a symmetrical beta distribution over the interval ,...
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 symmetrical beta distribution with shape par...
This class implements random variate generators for the gamma distribution.
Definition GammaGen.java:47
GammaProcessBridge(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcessBridge with parameters , and initial value .
GammaProcessSymmetricalBridge(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcessSymmetricalBridge with parameters.
double[] generatePath(double[] uniform01)
Generates, returns and saves the path .
double[] generatePath()
Generates, returns and saves the path .
double nextObservation()
Generates and returns the next observation of the stochastic process.
double nextObservation(double nextT)
Generates and returns the next observation at time , using the previous observation time defined ea...
GammaProcessSymmetricalBridge(double s0, double mu, double nu, GammaGen Ggen, BetaSymmetricalGen BSgen)
Constructs a new GammaProcessSymmetricalBridge with parameters.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...