SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GammaProcess.java
1/*
2 * Class: GammaProcess
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 Pierre Tremblay, Jean-Sébastien Parent & Maxime Dion
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.randvar.*;
29import umontreal.ssj.probdist.GammaDist;
30import umontreal.ssj.util.Num;
31
48public class GammaProcess extends StochasticProcess {
49 // Make sure that process is strictly increasing: when two successive steps
50 // are equal, reset the new one to old*(1 + EPS)
51 protected static final double EPS = 1.0e-15;
52 protected boolean usesAnti = false;
53
54 protected RandomStream stream; // used in the generatePath(), so must be kept
55 protected GammaGen Ggen;
56 protected double mu, nu;
57 protected double muOverNu, mu2OverNu;
58
59 // For precomputations for standard GP
60 protected double[] mu2dtOverNu;
61
62 protected void setLarger(double[] path, int left, int mid, int right) {
63 /*
64 * make sure that path[left] < path[mid] < path[right] by adding a small epsilon
65 * to the last two
66 */
67 double myEps;
68 if (path[left] >= 0)
69 myEps = EPS;
70 else
71 myEps = -EPS;
72 path[mid] = path[left] * (1.0 + myEps);
73 if (path[mid] >= path[right])
74 path[right] = path[mid] * (1.0 + myEps);
75 }
76
77 protected double setLarger(double[] path, int left, int right) {
78 /*
79 * make sure that path[left] < s < path[right] by adding a small epsilon to the
80 * last two; return s.
81 */
82 double myEps;
83 if (path[left] >= 0)
84 myEps = EPS;
85 else
86 myEps = -EPS;
87 double s = path[left] * (1.0 + myEps);
88 if (s >= path[right])
89 path[right] = s * (1.0 + myEps);
90 return s;
91 }
92
93 protected double setLarger(double v) {
94 /* return a number that is slightly larger than v */
95 if (v >= 0)
96 return v * (1.0 + EPS) + Num.DBL_EPSILON;
97 else
98 return v * (1.0 - EPS);
99 }
100
108 public GammaProcess(double s0, double mu, double nu, RandomStream stream) {
109 this(s0, mu, nu, new GammaGen(stream, 1.0));
110// Note that the parameters (the 1.0) supplied to
111// the GammaGen constructors are meaningless.
112// The 'real' parameters are supplied at time of generation
113 }
114
126 public GammaProcess(double s0, double mu, double nu, GammaGen Ggen) {
127 this.mu = mu;
128 this.nu = nu;
129 this.x0 = s0;
130 this.Ggen = Ggen;
131 stream = Ggen.getStream();
132 }
133
134 public double nextObservation() {
135 double s = path[observationIndex];
136 double v = s;
137 s += Ggen.nextDouble(stream, mu2dtOverNu[observationIndex], muOverNu);
138 if (s <= v)
139 s = setLarger(v);
140 observationIndex++;
141 observationCounter = observationIndex;
142 path[observationIndex] = s;
143 return s;
144 }
145
154 public double nextObservation(double nextT) {
155 // This method is useful for generating variance gamma processes
156 double s = path[observationIndex];
157 double v = s;
158 double previousT = t[observationIndex];
159 observationIndex++;
160 observationCounter = observationIndex;
161 t[observationIndex] = nextT;
162 double dt = nextT - previousT;
163 s += Ggen.nextDouble(stream, mu2OverNu * dt, muOverNu);
164 if (s <= v)
165 s = setLarger(v);
166 path[observationIndex] = s;
167 return s;
168 }
169
179 public double[] generatePath() {
180 double s = x0;
181 double v;
182 for (int i = 0; i < d; i++) {
183 v = s;
184 s += Ggen.nextDouble(stream, mu2dtOverNu[i], muOverNu);
185 if (s <= v)
186 s = setLarger(v);
187 path[i + 1] = s;
188 }
189 observationIndex = d;
190 observationCounter = d;
191 return path;
192 }
193
203 public double[] generatePath(double[] uniform01) {
204 double s = x0;
205 double v;
206 for (int i = 0; i < d; i++) {
207 v = s;
208 s += GammaDist.inverseF(mu2dtOverNu[i], muOverNu, 10, uniform01[i]);
209 if (s <= v)
210 s = setLarger(v);
211 path[i + 1] = s;
212 }
213 observationIndex = d;
214 observationCounter = d;
215 return path;
216 }
217
224 public void setParams(double s0, double mu, double nu) {
225 this.x0 = s0;
226 this.mu = mu;
227 this.nu = nu;
228 if (observationTimesSet)
229 init(); // Otherwise no need to.
230 }
231
235 public double getMu() {
236 return mu;
237 }
238
242 public double getNu() {
243 return nu;
244 }
245
251 public void setStream(RandomStream stream) {
252 this.stream = stream;
253 Ggen.setStream(stream);
254 }
255
260 return stream;
261 }
262
263 protected void init() {
264 // init of StochasticProcess only sets path[0] = x0 if observation times are
265 // set.
266 super.init();
267 muOverNu = mu / nu;
268 mu2OverNu = mu * mu / nu;
269 mu2dtOverNu = new double[d];
270 if (observationTimesSet) {
271 for (int i = 0; i < d; i++)
272 mu2dtOverNu[i] = mu2OverNu * (t[i + 1] - t[i]);
273 }
274 }
275
276}
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 for the gamma distribution.
Definition GammaGen.java:47
double nextObservation()
Generates and returns the next observation of the stochastic process.
GammaProcess(double s0, double mu, double nu, GammaGen Ggen)
Constructs a new GammaProcess with parameters , and initial value .
double[] generatePath(double[] uniform01)
Generates, returns and saves the path .
RandomStream getStream()
Returns the umontreal.ssj.rng.RandomStream stream.
double getMu()
Returns the value of the parameter .
void setParams(double s0, double mu, double nu)
Sets the parameters , and of the process.
double nextObservation(double nextT)
Generates and returns the next observation at time , using the previous observation time defined ea...
GammaProcess(double s0, double mu, double nu, RandomStream stream)
Constructs a new GammaProcess with parameters , and initial value .
void setStream(RandomStream stream)
Resets the umontreal.ssj.rng.RandomStream of the.
double[] generatePath()
Generates, returns and saves the path .
double getNu()
Returns the value of the parameter .
Abstract base class for a stochastic process sampled (or observed) at a finite number of time points...
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static final double DBL_EPSILON
Difference between 1.0 and the smallest double greater than 1.0.
Definition Num.java:90
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...