SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
MultivariateBrownianMotionPCABigSigma.java
1/*
2 * Class: MultivariateBrownianMotionPCABigSigma
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 Jean-Sébastien Parent
9 * @since 2008
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.stochprocess;
25
26import umontreal.ssj.rng.*;
27import umontreal.ssj.probdist.*;
28import umontreal.ssj.randvar.*;
29import cern.colt.matrix.DoubleMatrix2D;
30import cern.colt.matrix.impl.*;
31import cern.colt.matrix.linalg.*;
32import cern.colt.matrix.doublealgo.*;
33
48public class MultivariateBrownianMotionPCABigSigma extends MultivariateBrownianMotion {
49
50 protected DoubleMatrix2D BigSigma; // Matrice de covariance du vecteur des observ.
51 // BigSigma [i*c+k][j*c+l] = Cov[X_k(t_{i+1}),X_l(t_{j+1})].
52 protected DoubleMatrix2D decompPCABigSigma;
53 protected DoubleMatrix2D C; // C[i,j] = \min(t_{i+1},t_{j+1}).
54 protected DoubleMatrix2D A; // C = AA' (PCA decomposition).
55 protected double[] z, zz; // vector of c*d standard normals.
56 protected boolean decompPCA;
57
68 public MultivariateBrownianMotionPCABigSigma(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ,
69 RandomStream stream) {
70// we cannot call the constructor of MBM class because it sets B to the cholesky decomposition of of CorrZ.
71 this.gen = new NormalGen(stream, new NormalDist());
72 setParams(c, x0, mu, sigma, corrZ);
73 }
74
84 public MultivariateBrownianMotionPCABigSigma(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ,
85 NormalGen gen) {
86// we cannot call the constructor of MBM class because it sets B to the cholesky decomposition of CorrZ.
87 this.gen = gen;
88 setParams(c, x0, mu, sigma, corrZ);
89 }
90
91 public void setParams(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ) {
92 decompPCA = false;
93 super.setParams(c, x0, mu, sigma, corrZ);
94 }
95
96 protected DoubleMatrix2D decompPCA(DoubleMatrix2D BigSigma) {
97 // L'objet SingularValueDecomposition permet de recuperer la matrice
98 // des valeurs propres en ordre decroissant et celle des vecteurs propres de
99 // sigma (pour une matrice symetrique et definie-positive seulement).
100 SingularValueDecomposition sv = new SingularValueDecomposition(BigSigma);
101 DoubleMatrix2D D = sv.getS();
102 // Calculer la racine carree des valeurs propres
103 for (int i = 0; i < D.rows(); ++i)
104 D.setQuick(i, i, Math.sqrt(D.getQuick(i, i)));
105 DoubleMatrix2D P = sv.getV();
106 return P.zMult(D, null);
107// return D;
108 }
109
110 protected void init() {
111 super.init();
112 int g;
113 BigSigma = new DenseDoubleMatrix2D(c * d, c * d);
114 for (int i = 0; i < d; ++i) {
115 for (int j = 0; j < d; ++j) {
116 for (int k = 0; k < c; ++k) {
117 for (int l = 0; l < c; ++l) {
118 g = (i <= j ? i + 1 : j + 1);
119 if (k == l)
120 BigSigma.setQuick(i * c + k, j * c + l, g * sigma[k] * sigma[l] * (t[i + 1] - t[i]));
121 else
122 BigSigma.setQuick(i * c + k, j * c + l, g * covZ.getQuick(k, l) * (t[i + 1] - t[i]));
123 }
124 }
125 }
126 }
127 decompPCABigSigma = decompPCA(BigSigma);
128 decompPCA = true;
129 }
130
131 public double[] generatePath() {
132 double sum = 0.0;
133 int i, j, k;
134 double[] z = new double[c * d];
135 if (!decompPCA) {
136 init();
137 } // if the PCA decomposition has not been changed since the initialisation of the
138 // parameters, it must be done before the path is generated
139 for (i = 0; i < c * d; i++)
140 z[i] = gen.nextDouble();
141
142 for (j = 0; j < d; j++)
143 for (i = 0; i < c; i++) {
144 sum = 0.0;
145 for (k = 0; k < c * d; k++) {
146 sum += decompPCABigSigma.getQuick(c * j + i, k) * z[k];
147 }
148 path[c * (j + 1) + i] = sum + mu[i] * (t[j + 1] - t[0]) + x0[i];
149 }
150
151 observationIndex = d;
152 return path;
153 }
154
155 public double[] generatePath(double[] uniform01) {
156 double sum = 0.0;
157 int i, j, k;
158 if (!decompPCA) {
159 init();
160 } // if the PCA decomposition has not been changed since the initialisation of the
161 // parameters, it must be done before the path is generated
162 for (j = 0; j < d; j++)
163 for (i = 0; i < c; i++) {
164 sum = 0.0;
165 for (k = 0; k < c * d; k++) {
166 sum += decompPCABigSigma.getQuick(c * j + i, k) * uniform01[k];
167 }
168 path[c * (j + 1) + i] = sum + mu[i] * (t[j + 1] - t[0]) + x0[i];
169 }
170
171 observationIndex = d;
172 return path;
173 }
174
175}
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 .
MultivariateBrownianMotionPCABigSigma(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ, RandomStream stream)
Constructs a new MultivariateBrownianMotionPCABigSigma with parameters ,.
MultivariateBrownianMotionPCABigSigma(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ, NormalGen gen)
Constructs a new MultivariateBrownianMotionPCABigSigma with parameters ,.
void setParams(int c, double[] x0, double[] mu, double[] sigma, double[][] corrZ)
Sets the dimension , the initial value.
double[] generatePath(double[] uniform01)
Same as generatePath() but requires a vector of uniform random numbers which are used to generate the...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...