SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
InverseGaussianProcessMSH.java
1/*
2 * Class: InverseGaussianProcessMSH
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.*;
30
43public class InverseGaussianProcessMSH extends InverseGaussianProcess {
44
45 // otherStream is used to decide between the two roots in method MSH.
46 protected RandomStream otherStream;
47 // Needed for the MSH method of generating inverse gaussian.
48 protected NormalGen normalGen;
49
54 public InverseGaussianProcessMSH(double s0, double delta, double gamma, RandomStream stream,
55 RandomStream otherStream) {
56 super(); // dummy
57 this.x0 = s0;
58 setParams(delta, gamma);
59 this.stream = stream;
60 this.otherStream = otherStream;
61 normalGen = new NormalGen(stream);
62 numberOfRandomStreams = 2;
63 }
64
71 public double[] generatePath() {
72 double s = x0;
73 for (int i = 0; i < d; i++) {
74 s += InverseGaussianMSHGen.nextDouble(otherStream, normalGen, imu[i], ilam[i]);
75 path[i + 1] = s;
76 }
77 observationIndex = d;
78 observationCounter = d;
79 return path;
80 }
81
88 public double[] generatePath(double[] unifNorm, double[] unifOther) {
89 double s = x0;
90 // The class NonRandomStream is defined below.
91 RandomStream nonRandOther = new NonRandomStream(unifOther);
92 // this.stream should keep in memory the original stream of the Normal.
93 normalGen.setStream(new NonRandomStream(unifNorm));
94 for (int i = 0; i < d; i++) {
95 s += InverseGaussianMSHGen.nextDouble(nonRandOther, normalGen, imu[i], ilam[i]);
96 path[i + 1] = s;
97 }
98 observationIndex = d;
99 observationCounter = d;
100 normalGen.setStream(stream); // reset to original stream
101 return path;
102 }
103
107 public double[] generatePath(double[] uniforms01) {
108 throw new UnsupportedOperationException("Use generatePath with 2 streams");
109 }
110
111 public double nextObservation() {
112 double s = path[observationIndex];
113 s += InverseGaussianMSHGen.nextDouble(otherStream, normalGen, imu[observationIndex], ilam[observationIndex]);
114 observationIndex++;
115 observationCounter = observationIndex;
116 path[observationIndex] = s;
117 return s;
118 }
119
125 if (stream != otherStream)
126 throw new IllegalStateException("Two different streams or more are present");
127 return stream;
128 }
129
133 public void setStream(RandomStream stream, RandomStream otherStream) {
134 super.setStream(stream);
135 normalGen.setStream(stream);
136 setOtherStream(otherStream);
137 }
138
142 public void setStream(RandomStream stream) {
143 super.setStream(stream);
144 normalGen.setStream(stream);
145 setOtherStream(stream);
146 }
147
152 public void setOtherStream(RandomStream otherStream) {
153 this.otherStream = otherStream;
154 }
155
161 return otherStream;
162 }
163
168 public void setNormalGen(NormalGen normalGen) {
169 this.normalGen = normalGen;
170 stream = normalGen.getStream();
171 }
172
177 return normalGen;
178 }
179
186 protected class NonRandomStream implements RandomStream {
187 double[] array;
188 int position;
189
190 public NonRandomStream(double[] array) {
191 this.array = array;
192 position = 0;
193 }
194
195 public NonRandomStream(double value) {
196 this.array = new double[] { value };
197 position = 0;
198 }
199
200 public double nextDouble() {
201 return array[position++];
202 }
203
204 public void nextArrayOfDouble(double[] u, int start, int n) {
205 for (int i = 0; i < n; i++)
206 u[start + i] = array[position++];
207 }
208
209 public void nextArrayOfInt(int i, int j, int[] u, int start, int n) {
210 double diff = (double) (j - i);
211 for (int ii = 0; ii < n; ii++)
212 u[start + ii] = i + (int) Math.round(diff * array[position++]);
213 }
214
215 public int nextInt(int i, int j) {
216 return (int) Math.round((double) (j - i) * array[position]);
217 }
218
219 public void resetNextSubstream() {
220 }
221
222 public void resetStartStream() {
223 position = 0;
224 }
225
226 public void resetStartSubstream() {
227 }
228
229 public String toString() {
230 return new String("NonRandomStream of length " + array.length);
231 }
232 }
233
234}
This class implements inverse gaussian random variate generators using the many-to-one transformation...
static double nextDouble(RandomStream s, NormalGen sn, double mu, double lambda)
Generates a new variate from the inverse gaussian distribution with parameters mu and lambda,...
This class implements methods for generating random variates from the normal distribution .
NonRandomStream: Given a double array, this class will return those values as if it where a random st...
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream:
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .
void nextArrayOfDouble(double[] u, int start, int n)
Generates n (pseudo)random numbers from the uniform distribution and stores them into the array u sta...
void nextArrayOfInt(int i, int j, int[] u, int start, int n)
Generates n (pseudo)random numbers from the discrete uniform distribution over the integers ,...
String toString()
Returns a string containing the current state of this stream.
void resetStartSubstream()
Reinitializes the stream to the beginning of its current substream:
int nextInt(int i, int j)
Returns a (pseudo)random number from the discrete uniform distribution over the integers ,...
double nextObservation()
Generates and returns the next observation of the stochastic process.
void setStream(RandomStream stream, RandomStream otherStream)
Sets the streams.
RandomStream getStream()
Only returns a stream if both inner umontreal.ssj.rng.RandomStream ’s are the same.
void setStream(RandomStream stream)
Sets both inner streams to stream.
InverseGaussianProcessMSH(double s0, double delta, double gamma, RandomStream stream, RandomStream otherStream)
Constructs a new InverseGaussianProcessMSH.
void setNormalGen(NormalGen normalGen)
Sets the normal generator.
void setOtherStream(RandomStream otherStream)
Sets the otherStream, which is the stream used to choose between the two roots in the MSH method.
RandomStream getOtherStream()
Returns the otherStream, which is the stream used to choose between the two quadratic roots from the ...
double[] generatePath(double[] uniforms01)
Not implemented, requires two umontreal.ssj.rng.RandomStream ’s.
double[] generatePath(double[] unifNorm, double[] unifOther)
Instead of using the internal streams to generate the path, uses two arrays of uniforms .
void setParams(double delta, double gamma)
Sets the parameters.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...