24package umontreal.ssj.stochprocess;
26import umontreal.ssj.rng.*;
27import umontreal.ssj.util.DMatrix;
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.randvar.*;
30import cern.colt.matrix.DoubleMatrix2D;
31import cern.colt.matrix.impl.DenseDoubleMatrix2D;
32import cern.colt.matrix.linalg.CholeskyDecomposition;
62 protected double[] mu;
63 protected double[] sigma;
64 protected double[][] corrZ;
65 protected DoubleMatrix2D covZ;
66 protected DoubleMatrix2D covZCholDecomp;
67 protected CholeskyDecomposition decomp;
68 protected boolean covZiSCholDecomp;
71 protected double[] dt, sqrdt;
73 protected MultivariateBrownianMotion() {
115 if (!covZiSCholDecomp)
117 initCovZCholDecomp();
119 for (
int i = 0; i < c; i++) {
121 for (
int k = 0; k < c; k++)
122 z += covZCholDecomp.getQuick(i, k) * gen.nextDouble();
123 obs[i] = path[c * observationIndex + i] + mu[i] * dt[observationIndex] + sqrdt[observationIndex] * z;
124 path[c * (observationIndex + 1) + i] = obs[i];
137 double[] obs =
new double[c];
152 if (!covZiSCholDecomp)
153 initCovZCholDecomp();
154 t[observationIndex + 1] = nextTime;
156 for (
int i = 0; i < c; i++) {
158 for (
int k = 0; k < c; k++)
159 z += covZCholDecomp.getQuick(i, k) * gen.nextDouble();
160 obs[i] = path[c * observationIndex + i] + mu[i] * (t[observationIndex + 1] - t[observationIndex])
161 + Math.sqrt(t[observationIndex + 1] - t[observationIndex]) * z;
162 path[c * (observationIndex + 1) + i] = obs[i];
175 double[] obs =
new double[c];
177 if (!covZiSCholDecomp)
178 initCovZCholDecomp();
180 for (
int i = 0; i < c; i++) {
182 for (
int k = 0; k < c; k++)
183 z += covZCholDecomp.getQuick(i, k) * gen.nextDouble();
184 obs[i] = x[i] + mu[i] * dt + Math.sqrt(dt) * z;
191 double[] u =
new double[c * d];
192 for (
int i = 0; i < c * d; i++)
193 u[i] = gen.nextDouble();
202 if (!covZiSCholDecomp) {
204 initCovZCholDecomp();
207 double[] QMCpointsPart =
new double[c];
208 for (
int i = 0; i < c; i++)
210 for (
int j = 0; j < d; j++) {
211 for (
int i = 0; i < c; i++)
212 QMCpointsPart[i] = uniform01[j * c + i];
213 for (
int i = 0; i < c; i++) {
215 for (
int k = 0; k < c; k++)
216 z += covZCholDecomp.getQuick(i, k) * QMCpointsPart[k];
217 path[c * (j + 1) + i] = path[c * j + i] + mu[i] * dt[j] + sqrdt[j] * z;
220 observationIndex = d;
225 gen.setStream(stream);
240 public void setParams(
int c,
double x0[],
double mu[],
double sigma[],
double corrZ[][]) {
248 throw new IllegalArgumentException(
249 "x0 dimension : " + x0.length +
" is smaller than the process dimension : " + c);
251 throw new IllegalArgumentException(
252 "mu dimension : " + mu.length +
" is smaller than the process dimension : " + c);
253 if (sigma.length < c)
254 throw new IllegalArgumentException(
255 "sigma dimension : " + sigma.length +
" is smaller than the process dimension : " + c);
256 if ((corrZ.length < c) || (corrZ[0].length < c))
257 throw new IllegalArgumentException(
"corrZ dimensions : " + corrZ.length +
"x" + corrZ[0].length
258 +
" are smaller than the process dimension : " + c);
259 covZ =
new DenseDoubleMatrix2D(c, c);
261 covZiSCholDecomp =
false;
263 if (observationTimesSet)
275 public void setParams(
double x0[],
double mu[],
double sigma[]) {
279 covZ =
new DenseDoubleMatrix2D(c, c);
281 covZiSCholDecomp =
false;
283 if (observationTimesSet)
291 gen.setStream(stream);
298 return gen.getStream();
311 protected void init() {
313 dt =
new double[d + 1];
314 sqrdt =
new double[d + 1];
315 for (
int j = 0; j < d; j++) {
316 dt[j] = t[j + 1] - t[j];
317 sqrdt[j] = Math.sqrt(dt[j]);
321 protected void initCovZCholDecomp() {
322 covZCholDecomp =
new DenseDoubleMatrix2D(c, c);
323 covZCholDecomp = DMatrix.CholeskyDecompose(covZ);
324 covZiSCholDecomp =
true;
327 protected void initCovZ() {
328 for (
int i = 0; i < c; i++)
329 for (
int j = 0; j < c; j++)
330 covZ.setQuick(i, j, corrZ[i][j] * sigma[i] * sigma[j]);
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a (page 80)).
This class implements methods for generating random variates from the normal distribution .
RandomStream getStream()
Returns the random stream of the normal generator.
double[] generatePath(RandomStream stream)
Same as generatePath(), but first resets the stream to stream.
void setParams(double x0[], double mu[], double sigma[])
Sets the dimension , the initial value.
void setStream(RandomStream stream)
Resets the random stream of the normal generator to stream.
void nextObservationVector(double[] obs)
Generates and returns in obs the next observation.
double[] generatePath()
Generates, returns, and saves the sample path.
double[] generatePath(double[] uniform01)
Same as generatePath() but requires a vector of uniform random numbers which are used to generate the...
NormalGen getGen()
Returns the normal random variate generator used.
double[] nextObservationVector(double nextTime, double[] obs)
Generates and returns the vector of next observations, at time , using the previous observation time...
MultivariateBrownianMotion(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ, RandomStream stream)
Constructs a new MultivariateBrownianMotion with parameters.
void setParams(int c, double x0[], double mu[], double sigma[], double corrZ[][])
Sets the dimension , the initial value.
double[] getMu()
Returns the vector mu.
double[] nextObservationVector(double x[], double dt)
Generates an observation (vector) of the process in dt time units, assuming that the process has (vec...
double[] nextObservationVector()
Generates and returns the next observation of the multivariate stochastic process in a vector create...
MultivariateBrownianMotion(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ, NormalGen gen)
Constructs a new MultivariateBrownianMotion with parameters.
This class is a multivariate version of StochasticProcess where the process evolves in the -dimension...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...