SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
StochasticProcess.java
1/*
2 * Class: StochasticProcess
3 * Description: Base class for all stochastic processes
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.RandomStream;
28
51
52public abstract class StochasticProcess {
53
54 protected boolean observationTimesSet = false; // Used in some subclasses
55 // to make sure 'setObservationTimes' has been invoked before calling 'init'.
56
57 protected double x0 = 0.0; // Default Initial Value of the process
58 protected int d = -1; // Number of observation times
59 protected int observationIndex = 0; // Index of last generated obs. time
60 protected int observationCounter = 0; // Counts how many observations have
61 // been generated so far. Useful when they are not generated in
62 // chronological order.
63 protected double[] t; // Observation times
64 protected double[] path; // Observations of the process (skeleton).
65 // protected RandomStream stream; // Random stream used to generate the process
66 protected int[] observationIndexFromCounter; // Links counter# to index#
67
73 public void setObservationTimes(double[] T, int d) {
74 if (d <= 0)
75 throw new IllegalArgumentException("Number of observation times d <= 0");
76 this.d = d;
77 observationTimesSet = true;
78
79 // Copy of the observation times
80 this.t = new double[d + 1];
81 System.arraycopy(T, 0, this.t, 0, d + 1);
82
83 // Test chronological order
84 for (int i = 0; i < d; i++) {
85 if (T[i + 1] < T[i])
86 throw new IllegalArgumentException("Observation times T[] are not time-ordered");
87 }
88
89 // Construction of 'path' object
90 // We do not do it in 'init()' because we do not want to change the
91 // path object if the user only calls 'setParams'
92 path = new double[d + 1];
93
94 // Process-specific initialization; usually precomputes quantities
95 // that depend on the observation times.
96 init();
97 }
98
104 public void setObservationTimes(double delta, int d) {
105 t = new double[d + 1];
106 for (int i = 0; i <= d; i++)
107 t[i] = i * delta;
109 }
110
120 public double[] getObservationTimes() {
121 return t;
122 }
123
129 return d;
130 }
131
137 public abstract double[] generatePath();
138
142 public double[] generatePath(RandomStream stream) {
143 setStream(stream);
144 return generatePath();
145 }
146
153 public double[] getPath() {
154 return path;
155 }
156
164 public void getSubpath(double[] subpath, int[] pathIndices) {
165 for (int j = 0; j < subpath.length; j++) {
166 subpath[j] = path[pathIndices[j]];
167 }
168 }
169
175 public double getObservation(int j) {
176 return path[j];
177 }
178
185 public void resetStartProcess() {
186 observationIndex = 0;
187 observationCounter = 0;
188 }
189
195 public boolean hasNextObservation() {
196 if (observationCounter < d)
197 return true;
198 else
199 return false;
200 }
201
214 public double nextObservation() {
215 throw new UnsupportedOperationException("Method not defined in this class");
216 }
217
224 return observationIndex;
225 }
226
230 public double getCurrentObservation() {
231 return path[observationIndex];
232 }
233
237 public double getX0() {
238 return x0;
239 }
240
245 public void setX0(double s0) {
246 x0 = s0;
247 init();
248 }
249
253 public abstract void setStream(RandomStream stream);
254
258 public abstract RandomStream getStream();
259
260 /***
261 * Called by 'setObservationTimes' to initialize arrays and precompute constants
262 * to speed up execution. See overriding method 'init' in subclasses for details
263 ***/
264 protected void init() {
265 if (observationTimesSet) // If observation times are not defined, do nothing.
266 path[0] = x0;
267 // We do this here because the s0 parameter may have changed through
268 // a call to the 'setParams' method.
269 }
270
284 return observationIndexFromCounter;
285 }
286
287}
Abstract base class for a stochastic process sampled (or observed) at a finite number of time points...
double getCurrentObservation()
Returns the value of the last generated observation .
double getObservation(int j)
Returns from the current sample path.
void setObservationTimes(double delta, int d)
Sets equidistant observation times at , for.
void setObservationTimes(double[] T, int d)
Sets the observation times of the process to a copy of T, with.
abstract RandomStream getStream()
Returns the random stream of the underlying generator.
int[] getArrayMappingCounterToIndex()
Returns a reference to an array that maps an integer to , the index of the observation correspondin...
double getX0()
Returns the initial value for this process.
double[] getObservationTimes()
Returns a reference to the array that contains the observation times.
void setX0(double s0)
Sets the initial value for this process to s0, and reinitializes.
int getNumObservationTimes()
Returns the number of observation times, excluding the time .
double[] generatePath(RandomStream stream)
Same as generatePath(), but first resets the stream to stream.
abstract void setStream(RandomStream stream)
Resets the random stream of the underlying generator to stream.
double[] getPath()
Returns a reference to the last generated sample path .
void getSubpath(double[] subpath, int[] pathIndices)
Returns in subpath the values of the process at a subset of the observation times,...
void resetStartProcess()
Resets the observation counter to its initial value , so that the current observation becomes .
abstract double[] generatePath()
Generates, returns, and saves the sample path .
int getCurrentObservationIndex()
Returns the value of the index corresponding to the time.
boolean hasNextObservation()
Returns true if , where is the number of observations of the current sample path generated since the...
double nextObservation()
Generates and returns the next observation of the stochastic process.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...