SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BrownianMotionPCAEqualSteps.java
1/*
2 * Class: BrownianMotionPCAEqualSteps
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
38
39 double dt;
40 protected double[][] A; // sigmaCov = AA' (PCA decomposition).
41 protected double[] z; // vector of standard normals.
42 protected boolean isDecompPCA;
43 protected double[] sortedEigenvalues;
44
48 public BrownianMotionPCAEqualSteps(double x0, double mu, double sigma, RandomStream stream) {
49 super(x0, mu, sigma, stream);
50 isDecompPCA = false;
51 }
52
56 public BrownianMotionPCAEqualSteps(double x0, double mu, double sigma, NormalGen gen) {
57 super(x0, mu, sigma, gen);
58 isDecompPCA = false;
59 }
60
61 public double nextObservation() {
62 throw new UnsupportedOperationException("nextObservation() not defined for PCA.");
63 }
64
65 public double[] generatePath() {
66 if (!isDecompPCA) {
67 init();
68 } // if the decomposition is not done, do it...
69 for (int j = 0; j < d; j++)
70 z[j] = gen.nextDouble();
71 for (int j = 0; j < d; j++) {
72 double sum = 0.0;
73 for (int k = 0; k < d; k++)
74 sum += A[j][k] * z[k];
75 path[j + 1] = x0 + mu * t[j + 1] + sum;
76 }
77 observationIndex = d;
78 observationCounter = d;
79 return path;
80 }
81
82 public double[] generatePath(double[] QMCpointsBM) {
83 if (!isDecompPCA) {
84 init();
85 } // if the decomposition is not done, do it...
86 for (int j = 0; j < d; j++)
87 z[j] = NormalDist.inverseF01(QMCpointsBM[j]);
88 for (int j = 0; j < d; j++) {
89 double sum = 0.0;
90 for (int k = 0; k < d; k++)
91 sum += A[j][k] * z[k];
92 path[j + 1] = x0 + mu * t[j + 1] + sum;
93 }
94 observationIndex = d;
95 observationCounter = d;
96 return path;
97 }
98
99 public void setObservationTimes(double[] t, int d) {
100 super.setObservationTimes(t, d);
101 this.dt = t[1] - t[0];
102 for (int i = 1; i < d; i++)
103 if (Math.abs((t[i + 1] - t[i]) / dt - 1.0) > 1e-7)
104 throw new IllegalArgumentException("Not equidistant times");
105 }
106
107 public void setObservationTimes(double dt, int d) {
108 this.dt = dt;
109 super.setObservationTimes(dt, d);
110 }
111
112 protected void init() {
113 super.init();
114 if (observationTimesSet) {
115 final double twoOverSqrt2dP1 = 2.0 / Math.sqrt(2.0 * d + 1.0);
116 final double piOver2dP1 = Math.PI / (2.0 * d + 1.0);
117
118 z = new double[d];
119 // A contains the eigenvectors (as columns), times sqrt(eigenvalues).
120 A = new double[d][d];
121 sortedEigenvalues = new double[d];
122 for (int ic = 1; ic <= d; ic++) {
123 final double tempSin = Math.sin((2 * ic - 1) * piOver2dP1 / 2.0);
124 sortedEigenvalues[ic - 1] = dt / 4.0 / tempSin / tempSin * sigma * sigma;
125 for (int ir = 1; ir <= d; ir++) {
126 A[ir - 1][ic - 1] = twoOverSqrt2dP1 * Math.sin((2 * ic - 1) * piOver2dP1 * ir);
127 A[ir - 1][ic - 1] *= Math.sqrt(sortedEigenvalues[ic - 1]);
128 }
129 }
130 double[][] AA = new double[d][d];
131 for (int ic = 0; ic < d; ic++) {
132 for (int ir = 0; ir < d; ir++) {
133 double sum = 0.0;
134 for (int k = 0; k < d; k++)
135 sum += A[ir][k] * A[ic][k];
136 AA[ir][ic] = sum;
137 }
138 }
139 isDecompPCA = true;
140 }
141 }
142
143 public double[] getSortedEigenvalues() {
144 return sortedEigenvalues;
145 }
146}
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double inverseF01(double u)
Same as inverseF(0, 1, u).
This class implements methods for generating random variates from the normal distribution .
double nextObservation()
Generates and returns the next observation of the stochastic process.
double[] generatePath()
Generates, returns, and saves the sample path .
void setObservationTimes(double[] t, int d)
Sets the observation times of the process to a copy of T, with.
BrownianMotionPCAEqualSteps(double x0, double mu, double sigma, NormalGen gen)
Constructs a new BrownianMotionPCAEqualSteps.
void setObservationTimes(double dt, int d)
Sets equidistant observation times at , for.
double[] generatePath(double[] QMCpointsBM)
Same as generatePath(), but a vector of uniform random numbers must be provided to the method.
BrownianMotionPCAEqualSteps(double x0, double mu, double sigma, RandomStream stream)
Constructs a new BrownianMotionPCAEqualSteps.
BrownianMotion(double x0, double mu, double sigma, RandomStream stream)
Constructs a new BrownianMotion with parameters mu,.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...