SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NI2b.java
1/*
2 * Class: NI2b
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.util.*;
28import umontreal.ssj.probdist.*;
29
50public class NI2b extends NortaInitDisc {
51 private int m; /*
52 * Number of subintervals for the integration = max. number of iterations (also
53 * named m in the paper, paragraph "Method NI2" of section 3).
54 */
55 private double delta; /*
56 * Small positive parameter to make sure that rho_m is not too close to 1 or -1;
57 * (also named delta in the paper, paragraph "Method NI2" of section 3)
58 */
59
66 public NI2b(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr, int m,
67 double delta) {
68 super(rX, dist1, dist2, tr);
69 this.m = m;
70 this.delta = delta;
72 }
73
77 public double computeCorr() {
78 // x, y and c oefficients used for quadratic interpolation
79 double[] x = new double[3];
80 double[] y = new double[3];
81 double[] c = new double[3];
82 double xtemp = 0.0, temp = 0.0; /*
83 * Values of rho and the recursive quantity I_k, given in paragraph "Method NI2"
84 * of section 3 in the paper,2 iterations before the last one.
85 */
86 double xold, iold; /*
87 * Values of rho and I_k at one iteration before the last one.
88 */
89 double xnew, inew; // rho and I_k at the last iteration.
90 double dold, dmid, dnew; /*
91 * Values of the derivative function g' at points xold, xmid (xold+h) and xnew.
92 * They correspond to g'(rho_0+2kh-2h), g'(rho_0+2kh-h) and g'(rho_0+2kh) in the
93 * formula of I_k in the paper (paragraph "Method NI2" of section 3).
94 */
95 double h = (1 - delta) / (2 * m); /*
96 * Step size for the integration-grid spacing (2*h). It corresponds to h given
97 * in the third paragraph of section 4 in the paper
98 */
99 double b = 0.0; // The returned solution.
100 double rho1 = 0.0; // The initial guess.
101 double intg1 = mu1 * mu2; // Computes g_r(rho1).
102 double gr = rX * sd1 * sd2 + mu1 * mu2; /*
103 * Target value; integ(rho) = gr is equivalent to rho = the solution.
104 */
105 // Pre-compute constants
106 double hd3 = h / 3;
107 double h2 = 2 * h;
108
109 if (intg1 == gr)
110 return rho1;
111
112 if (0 < rX && rX < 1) { // Do search between 0 and rho_m=1-delta
113 xold = rho1;
114 dold = deriv(xold);
115 iold = intg1;
116
117 for (int i = 1; i <= m; i++) { // Begin the search
118 dmid = deriv(xold + h);
119 xnew = xold + h2;
120 dnew = deriv(xnew);
121 inew = iold + hd3 * (dold + 4 * dmid + dnew);
122 if (inew >= gr) { // The root is in current bracketing interval
123 // Compute the parameters of quadratic interpolation
124 x[0] = xtemp;
125 x[1] = xold;
126 x[2] = xnew;
127 y[0] = temp;
128 y[1] = iold;
129 y[2] = inew;
130 Misc.interpol(2, x, y, c);
131 b = (c[2] * (xtemp + xold) - c[1]
132 + Math.sqrt((c[1] - c[2] * (xtemp + xold)) * (c[1] - c[2] * (xtemp + xold))
133 - 4 * c[2] * (c[0] - c[1] * xtemp + c[2] * xtemp * xold - gr)))
134 / (2 * c[2]);
135 return b;
136 }
137 xtemp = xold;
138 temp = iold;
139 xold = xnew;
140 dold = dnew;
141 iold = inew;
142 }
143 // Integration up to 1-delta did not bracket root
144 // return 1-delta/2 ( = midpoint of current bracketing interval)
145 b = 1 - delta / 2;
146 }
147
148 if (-1 < rX && rX < 0) { // Do search between rho_m=-1+delta and 0
149 xold = rho1;
150 dold = deriv(xold);
151 iold = intg1;
152
153 for (int i = 1; i <= m; i++) { // Begin the search
154 dmid = deriv(xold - h);
155 xnew = xold - h2;
156 dnew = deriv(xnew);
157 inew = iold - hd3 * (dold + 4 * dmid + dnew);
158 if (inew <= gr) { // The root is in current bracketing interval
159 // Compute the parameters of quadratic interpolation
160 x[0] = xnew;
161 x[1] = xold;
162 x[2] = xtemp;
163 y[0] = inew;
164 y[1] = iold;
165 y[2] = temp;
166 Misc.interpol(2, x, y, c);
167 b = (c[2] * (xnew + xold) - c[1]
168 + Math.sqrt((c[1] - c[2] * (xnew + xold)) * (c[1] - c[2] * (xnew + xold))
169 - 4 * c[2] * (c[0] - c[1] * xnew + c[2] * xnew * xold - gr)))
170 / (2 * c[2]);
171 return b;
172 }
173 xtemp = xold;
174 temp = iold;
175 xold = xnew;
176 dold = dnew;
177 iold = inew;
178 }
179 // Integration up to -1+delta did not bracket root
180 b = -1 + delta / 2; // return 1-delta/2
181 // ( = midpoint of current bracketing interval )
182 }
183 return b;
184 }
185
186 public String toString() {
187 String desc = super.toString();
188 desc += "m : " + m + "\n";
189 desc += "delta : " + delta + "\n";
190 return desc;
191 }
192
193}
Classes implementing discrete distributions over the integers should inherit from this class.
double computeCorr()
Computes and returns the correlation using the algorithm NI2b.
Definition NI2b.java:77
NI2b(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr, int m, double delta)
Constructor with the target rank correlation rX, the two discrete marginals dist1 and dist2,...
Definition NI2b.java:66
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:
This class provides miscellaneous functions that are hard to classify.
Definition Misc.java:33
static void interpol(int n, double[] X, double[] Y, double[] C)
Computes the Newton interpolating polynomial.
Definition Misc.java:221