SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
VarianceGammaProcessDiffPCA.java
1/*
2 * Class: VarianceGammaProcessDiffPCA
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 2008
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
47 int[] indexEigenUp;
48 int[] indexEigenDw;
49
60 public VarianceGammaProcessDiffPCA(double s0, double theta, double sigma, double nu, RandomStream stream) {
61 super(s0, theta, sigma, nu, new GammaProcessPCA(0.0, 1.0, 1.0, stream),
62 new GammaProcessPCA(0.0, 1.0, 1.0, stream));
63 // Params mu, nu of the 2 gamma processes are redefined in init()
64 // which will be called after a call to 'setObservTimes'
65 }
66
76 public VarianceGammaProcessDiffPCA(double s0, double theta, double sigma, double nu, GammaProcessPCA gpos,
77 GammaProcessPCA gneg) {
78 super(s0, theta, sigma, nu, gpos, gneg); // from VarianceGammaProcessDiff
79 // Params mu, nu of the 2 gamma processes are redefined in init()
80 // which will be called after a call to 'setObservTimes'
81 }
82
87 public double nextObservation() {
88 throw new UnsupportedOperationException("Impossible with PCA, use generatePath() instead.");
89 }
90
91 public double[] generatePath() {
92 double[] u = new double[2 * d];
93 for (int i = 0; i < 2 * d; i++)
94 u[i] = getStream().nextDouble();
95 return generatePath(u);
96 }
97
98 public double[] generatePath(double[] uniform01) {
99 int dd = uniform01.length;
100 int d = dd / 2;
101
102 if (dd % 2 != 0) {
103 throw new IllegalArgumentException("The Array uniform01 must have a even length");
104 }
105
106 double[] QMCpointsUP = new double[d];
107 double[] QMCpointsDW = new double[d];
108
109 for (int i = 0; i < d; i++) {
110 QMCpointsUP[i] = uniform01[indexEigenUp[i]];
111 QMCpointsDW[i] = uniform01[indexEigenDw[i]];
112 }
113 gpos.resetStartProcess();
114 gneg.resetStartProcess();
115
116 double[] pathUP = gpos.generatePath(QMCpointsUP);
117 double[] pathDOWN = gneg.generatePath(QMCpointsDW);
118
119 for (int i = 0; i < d; i++) {
120 path[i + 1] = x0 + pathUP[i + 1] - pathDOWN[i + 1];
121 }
122 observationIndex = d;
123 observationCounter = d;
124 return path;
125 }
126
127 protected void init() {
128 super.init(); // from VarianceGammaProcessDiff
129 if (observationTimesSet) {
130 // Two lines below (casts) should be reinstated after fix inheritance
131 // PCA/PCABridge.
132 double[] eigenValUp = ((GammaProcessPCA) gpos).getBMPCA().getSortedEigenvalues();
133 double[] eigenValDw = ((GammaProcessPCA) gneg).getBMPCA().getSortedEigenvalues();
134 indexEigenUp = new int[d];
135 indexEigenDw = new int[d];
136
137 int iUp = 0;
138 int iDw = 0;
139 for (int iQMC = 0; iQMC < 2 * d; iQMC++) {
140 if (iUp == d) {
141 indexEigenDw[iDw] = iQMC;
142 iDw++;
143 continue;
144 }
145 if (iDw == d) {
146 indexEigenUp[iUp] = iQMC;
147 iUp++;
148 continue;
149 }
150 if (eigenValUp[iUp] >= eigenValDw[iDw]) {
151 indexEigenUp[iUp] = iQMC;
152 iUp++;
153 } else {
154 indexEigenDw[iDw] = iQMC;
155 iDw++;
156 }
157 }
158 }
159
160 }
161
162}
Represents a gamma process sampled using the principal component analysis (PCA).
double[] generatePath()
Generates, returns and saves the path.
double nextObservation()
This method is not implemented is this class since the path cannot be generated sequentially.
double[] generatePath(double[] uniform01)
Similar to the usual generatePath(), but here the uniform random numbers used for the simulation must...
VarianceGammaProcessDiffPCA(double s0, double theta, double sigma, double nu, RandomStream stream)
Constructs a new VarianceGammaProcessDiffPCA with parameters.
VarianceGammaProcessDiffPCA(double s0, double theta, double sigma, double nu, GammaProcessPCA gpos, GammaProcessPCA gneg)
Constructs a new VarianceGammaProcessDiffPCA with parameters.
VarianceGammaProcessDiff(double s0, double theta, double sigma, double nu, RandomStream stream)
Constructs a new VarianceGammaProcessDiff with parameters.
RandomStream getStream()
Returns the RandomStream of the process.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...