SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NormalInverseGaussianProcess.java
1/*
2 * Class: NormalInverseGaussianProcess
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
9 * @since
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.hups.*;
31
62 protected RandomStream streamIG1; // U[0,1) gen used in the inverse gaussian
63 protected RandomStream streamIG2; // U[0,1) gen used (maybe) in the inverse gaussian
64 protected RandomStream streamBrownian; // U[0,1) gen for the normal "Brownian"
65
66 protected InverseGaussianProcess igProcess;
67 protected NormalGen normalGen;
68 // Randomized time generated by the InverseGaussianProcess.
69 protected double[] stochTime;
70 double[] dt;
71 double[] mudt;
72
73 // Parameters of the normal inverse gaussian
74 protected double mu;
75 protected double delta;
76 protected double alpha;
77 protected double beta;
78 protected double gamma;
79
88 public NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta,
89 RandomStream streamBrownian, InverseGaussianProcess igP) {
90 setParams(x0, alpha, beta, mu, delta);
91 this.streamBrownian = streamBrownian;
92 normalGen = new NormalGen(streamBrownian); // N(0,1)
93 igProcess = igP; // its params will be set in init().
94 this.streamIG1 = igProcess.getStream();
95 this.streamIG2 = streamIG1;
96 }
97
110 public NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta,
111 RandomStream streamBrownian, RandomStream streamIG1, RandomStream streamIG2, String igType) {
112 setParams(x0, alpha, beta, mu, delta);
113 this.streamIG1 = streamIG1;
114 this.streamIG2 = streamIG2;
115 this.streamBrownian = streamBrownian;
116 normalGen = new NormalGen(streamBrownian); // N(0,1)
117
118 // The initial time of igProcess here, 0., is arbitrary:
119 // init() sets igProcess.x0 = t[0].
120 if (igType.compareTo("SEQUENTIAL_SLOW") == 0)
121 // the initial value, 0.0, of the IG will be overriden by
122 // the initial time, when it will be set.
123 igProcess = new InverseGaussianProcess(0.0, delta, gamma, streamIG1);
124 else if (igType.compareTo("SEQUENTIAL_MSH") == 0)
125 igProcess = new InverseGaussianProcessMSH(0.0, delta, gamma, streamIG1, streamIG2);
126 else if (igType.compareTo("BRIDGE") == 0)
127 igProcess = new InverseGaussianProcessBridge(0.0, delta, gamma, streamIG1, streamIG2);
128 else if (igType.compareTo("PCA") == 0)
129 igProcess = new InverseGaussianProcessPCA(0.0, delta, gamma, streamIG1);
130 else
131 throw new IllegalArgumentException("Unrecognized igType");
132 }
133
138 public NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta,
139 RandomStream streamAll, String igType) {
140 this(x0, alpha, beta, mu, delta, streamAll, streamAll, streamAll, igType);
141 }
142
148 public double[] generatePath() {
149 if (igProcess.getNumberOfRandomStreams() != 1)
150 return generatePathTwoIGStreams();
151
152 double x = x0;
153 double[] randomNormal = new double[d];
154 double[] randomIG1 = new double[d];
155 for (int j = 0; j < d; j++) {
156 randomIG1[j] = streamIG1.nextDouble();
157 randomNormal[j] = streamBrownian.nextDouble();
158 }
159
160 stochTime = igProcess.generatePath(randomIG1);
161 for (int j = 0; j < d; j++) {
162 double dy = stochTime[j + 1] - stochTime[j];
163 x += mudt[j] + beta * dy + Math.sqrt(dy) * NormalDistQuick.inverseF01(randomNormal[j]);
164 path[j + 1] = x;
165 }
166 observationIndex = d;
167 return path;
168 }
169
170 protected double[] generatePathTwoIGStreams() {
171 double x = x0;
172 double[] uniformNormal = new double[d];
173 double[] uniformIG1 = new double[d];
174 double[] uniformIG2 = new double[d];
175
176 for (int j = 0; j < d; j++) {
177 uniformIG1[j] = streamIG1.nextDouble();
178 uniformNormal[j] = streamBrownian.nextDouble();
179 uniformIG2[j] = streamIG2.nextDouble();
180 }
181
182 stochTime = igProcess.generatePath(uniformIG1, uniformIG2);
183 for (int j = 0; j < d; j++) {
184 double dy = stochTime[j + 1] - stochTime[j];
185 x += mudt[j] + beta * dy + Math.sqrt(dy) * NormalDistQuick.inverseF01(uniformNormal[j]);
186 path[j + 1] = x;
187 }
188 observationIndex = d;
189 return path;
190 }
191
200 public double nextObservation() {
201 double igNext = igProcess.nextObservation();
202 observationIndex = igProcess.getCurrentObservationIndex();
203 stochTime[observationIndex] = igNext;
204 double dY = igNext - stochTime[0];
205 double dT = t[observationIndex] - t[0];
206 path[observationIndex] = x0 + mu * dT + beta * dY + Math.sqrt(dY) * normalGen.nextDouble();
207 return path[observationIndex];
208 }
209
210 protected void init() {
211 super.init();
212 igProcess.setParams(delta, gamma);
213 if (observationTimesSet) {
214 stochTime = new double[d + 1];
215 stochTime[0] = t[0];
216 dt = new double[d];
217 mudt = new double[d];
218 for (int i = 0; i < d; i++) {
219 dt[i] = t[i + 1] - t[i];
220 mudt[i] = dt[i] * mu;
221 }
222 }
223 }
224
231 public void setObservationTimes(double t[], int d) {
232 super.setObservationTimes(t, d);
233 igProcess.setObservationTimes(t, d);
234 igProcess.x0 = t[0];
235 }
236
240 public void setParams(double x0, double alpha, double beta, double mu, double delta) {
241 // Initializes the parameters of the process
242 if (delta <= 0.0)
243 throw new IllegalArgumentException("delta <= 0");
244 if (alpha <= 0.0)
245 throw new IllegalArgumentException("alpha <= 0");
246 if (Math.abs(beta) >= alpha)
247 throw new IllegalArgumentException("|beta| >= alpha");
248
249 this.x0 = x0;
250 this.mu = mu;
251 this.delta = delta;
252 this.beta = beta;
253 this.alpha = alpha;
254
255 gamma = Math.sqrt(alpha * alpha - beta * beta);
256 if (observationTimesSet)
257 init();
258 }
259
263 public double getAlpha() {
264 return alpha;
265 }
266
270 public double getBeta() {
271 return beta;
272 }
273
277 public double getMu() {
278 return mu;
279 }
280
284 public double getDelta() {
285 return delta;
286 }
287
291 public double getGamma() {
292 return gamma;
293 }
294
298 public double getAnalyticAverage(double time) {
299 return mu * time + delta * time * beta / gamma;
300 }
301
305 public double getAnalyticVariance(double time) {
306 return delta * time * alpha * alpha / gamma / gamma / gamma;
307 }
308
314 if ((streamIG1 != streamIG2) || (streamIG1 != streamBrownian) || (streamIG1 != normalGen.getStream())
315 || (streamIG1 != igProcess.getStream()))
316 throw new UnsupportedOperationException("Two different streams or more are present");
317 return streamIG1;
318 }
319
324 public void setStream(RandomStream stream) {
325 streamIG1 = streamIG2 = streamBrownian = stream;
326 normalGen.setStream(stream);
327 igProcess.setStream(stream);
328 }
329
330}
A variant of the class NormalDist (for the normal distribution with mean and variance ).
static double inverseF01(double u)
Same as inverseF(0.0, 1.0, u).
This class implements methods for generating random variates from the normal distribution .
Samples the path by bridge sampling: first finding the process value at the final time and then the m...
Uses a faster generating method (MSH) rmic76a  than the simple inversion of the distribution function...
Approximates a principal component analysis (PCA) decomposition of the InverseGaussianProcess.
The inverse Gaussian process is a non-decreasing process where the increments are additive and are gi...
double[] generatePath()
Generates, returns, and saves the sample path .
void setParams(double delta, double gamma)
Sets the parameters.
RandomStream getStream()
Returns the random stream of the underlying generator.
double getAnalyticAverage(double time)
Returns the analytic average, which is .
NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta, RandomStream streamBrownian, InverseGaussianProcess igP)
Given an InverseGaussianProcess igP, constructs a new NormalInverseGaussianProcess.
double nextObservation()
Returns the value of the process for the next time step.
NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta, RandomStream streamBrownian, RandomStream streamIG1, RandomStream streamIG2, String igType)
Constructs a new NormalInverseGaussianProcess.
void setParams(double x0, double alpha, double beta, double mu, double delta)
Sets the parameters.
double getAnalyticVariance(double time)
Returns the analytic variance, which is .
RandomStream getStream()
Only returns the stream if all streams are equal, including the stream(s) in the underlying InverseGa...
void setObservationTimes(double t[], int d)
Sets the observation times on the NIG process as usual, but also sets the observation times of the un...
void setStream(RandomStream stream)
Sets all internal streams to stream, including the stream(s) of the underlying InverseGaussianProcess...
NormalInverseGaussianProcess(double x0, double alpha, double beta, double mu, double delta, RandomStream streamAll, String igType)
Same as above, but all umontreal.ssj.rng.RandomStream ’s are set to the same stream,...
Abstract base class for a stochastic process sampled (or observed) at a finite number of time points...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...