SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NortaInitDisc.java
1/*
2 * Class: NortaInitDisc
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Université de Montréal
7 * Organization: DIRO, Université de Montréal
8 * @author Nabil Channouf
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.probdistmulti.norta;
26
27import umontreal.ssj.probdistmulti.*;
28import umontreal.ssj.probdist.*;
29
74public abstract class NortaInitDisc {
75 protected double rX; // Target rank correlation
76 // Marginal disttributions of r.variables X_1 and X_2
77 protected DiscreteDistributionInt dist1;
78 protected DiscreteDistributionInt dist2;
79 protected double tr; /*
80 * Parameter for the quantile upper limit; used for truncation in the unbounded
81 * case.
82 */
83 protected double mu1, mu2, sd1, sd2; /*
84 * Means and standard deviations of F_1(X_1) and F_2(X_2).
85 */
86
87 private int m1, m2; // Number of support points of the 2 marginals.
88 private double[] p1; // Probability masses of the marginal 1.
89 private double[] p2; // Probability masses of the marginal 2.
90 /*
91 * Quantiles of the cumulative probability masses by the standard normal C.D.F
92 * for the 2 marginals
93 */
94 private double[] z1;
95 private double[] z2;
96
97 private String tabToString(double[] tab, String message) {
98 String desc = message + "\n [";
99 for (int i = 0; i < tab.length; i++)
100 if (i == tab.length - 1)
101 desc += "]\n";
102 else
103 desc += tab[i] + ",";
104 return desc;
105 }
106
112 public NortaInitDisc(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr) {
113 this.rX = rX;
114 this.dist1 = dist1;
115 this.dist2 = dist2;
116 this.tr = tr;
117 }
118
123 public abstract double computeCorr();
124
142 public void computeParams() {
143 m1 = dist1.inverseFInt(tr) + 1;
144 m2 = dist2.inverseFInt(tr) + 1;
145 // Support points of X_1 and X_2
146 int[] y1 = new int[m1];
147 int[] y2 = new int[m2];
148 p1 = new double[m1];
149 p2 = new double[m2];
150 // Cumulative probability masses of X_1 and X_2
151 double[] f1 = new double[m1];
152 double[] f2 = new double[m2];
153 z1 = new double[m1];
154 z2 = new double[m2];
155 double u11 = 0.0, u22 = 0.0;
156
157 // Compute mu1, sd1, p1 and z1 of X_1
158 for (int i = 0; i < m1; i++) {
159 y1[i] = i;
160 p1[i] = dist1.prob(y1[i]);
161 f1[i] = dist1.cdf(y1[i]);
162 z1[i] = NormalDist.inverseF01(f1[i]);
163 if (z1[i] == Double.NEGATIVE_INFINITY)
164 z1[i] = NormalDist.inverseF01(2.2e-308);
165 if (z1[i] == Double.POSITIVE_INFINITY)
166 z1[i] = NormalDist.inverseF01(1.0 - Math.ulp(1.0));
167 mu1 += f1[i] * p1[i];
168 u11 += f1[i] * f1[i] * p1[i];
169 }
170 sd1 = Math.sqrt(u11 - mu1 * mu1);
171
172 // Compute mu2, sd2, p2 and z2 of X_2
173 for (int i = 0; i < m2; i++) {
174 y2[i] = i;
175 p2[i] = dist2.prob(y2[i]);
176 f2[i] = dist2.cdf(y2[i]);
177 z2[i] = NormalDist.inverseF01(f2[i]);
178 if (z2[i] == Double.NEGATIVE_INFINITY)
179 z2[i] = NormalDist.inverseF01(2.2e-308);
180 if (z2[i] == Double.POSITIVE_INFINITY)
181 z2[i] = NormalDist.inverseF01(1.0 - Math.ulp(1.0));
182 mu2 += f2[i] * p2[i];
183 u22 += f2[i] * f2[i] * p2[i];
184 }
185 sd2 = Math.sqrt(u22 - mu2 * mu2);
186 }
187
208 public double integ(double r) {
209 double gr = 0.0; // The returned value.
210 for (int i = 0; i < m1 - 1; i++) {
211 double sum = 0.0;
212 for (int j = 0; j < m2 - 1; j++) {
213 sum += p2[j + 1] * BiNormalDonnellyDist.barF(z1[i], z2[j], r);
214 }
215 gr += p1[i + 1] * sum;
216 }
217 return gr;
218 }
219
234 public double deriv(double r) {
235 double c = Math.sqrt(1.0 - r * r);
236 double c1 = 2 * c * c;
237 double gp = 0.0; // The returned value
238
239 for (int i = 0; i < m1 - 1; i++) {
240 double z1sq = z1[i] * z1[i];
241 double t1 = 2 * r * z1[i];
242 double sum = 0.0;
243 for (int j = 0; j < m2 - 1; j++) {
244 sum += p2[j + 1] * Math.exp((t1 * z2[j] - z1sq - z2[j] * z2[j]) / c1);
245 }
246 gp += p1[i + 1] * sum;
247 }
248 gp = gp / (2.0 * Math.PI * c);
249 return gp;
250 }
251
252 public String toString() {
253 String desc = "";
254 desc += "rX = " + rX + "\n";
255 desc += "tr = " + tr + "\n";
256 desc += "m1 = " + m1 + "\n";
257 desc += "m2 = " + m2 + "\n";
258 desc += "mu1 = " + mu1 + "\n";
259 desc += "mu2 = " + mu2 + "\n";
260 desc += "sd1 = " + sd1 + "\n";
261 desc += "sd2 = " + sd2 + "\n";
262 desc += tabToString(p1, "Table p1 : ");
263 desc += tabToString(z1, "Table z1 : ");
264 desc += tabToString(p2, "Table p2 : ");
265 desc += tabToString(z2, "Table z2 : ");
266 return desc;
267 }
268
269}
Classes implementing discrete distributions over the integers should inherit from this class.
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a  (page 80)).
static double inverseF01(double u)
Same as inverseF(0, 1, u).
Extends the class BiNormalDist for the bivariate normal distribution tjoh72a  (page 84) using a trans...
static double barF(double mu1, double sigma1, double x, double mu2, double sigma2, double y, double rho, int ndig)
Computes the upper binormal distribution function ( cdf3binormal ) with parameters = mu1,...
NortaInitDisc(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr)
Constructor with the target rank correlation rX, the two discrete marginals dist1 and dist2 and the p...
double deriv(double r)
Computes the derivative of , given by.
void computeParams()
Computes the following inputs of each marginal distribution:
abstract double computeCorr()
Computes and returns the correlation .
double integ(double r)
Computes the function.