SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NI3.java
1/*
2 * Class: NI3
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.probdist.*;
28
53public class NI3 extends NortaInitDisc {
54 private double tolerance; /*
55 * Desired accuracy for the root-finder algorithm (epsilon in paragraph
56 * "Method NI3" of section 3 in paper).
57 */
58
66 public NI3(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr, double tolerance) {
67 super(rX, dist1, dist2, tr);
68 this.tolerance = tolerance;
70 }
71
75 public double computeCorr() {
76 final double ITMAX = 100; // Maximum number of iterations.
77 double xl, xh; /*
78 * Left and right endpoints of the root bracket at all iterations.
79 */
80 double b = 0.0; // The returned solution.
81 double f, df; // Function and its derivative evaluations.
82 double dx; // Correction term.
87 double dxold; // The root correction at one iteration before the last one.
88 double temp;// The root at one iteration before the last one.
89 double ccc = rX * sd1 * sd2 + mu1 * mu2; // Precompute constant.
90
91 if (rX == 0.0)
92 return 0.0;
93 if (rX > 0.0) { // Orient the search
94 xl = 0.0;
95 xh = 1.0;
96 } else {
97 xl = -1.0;
98 xh = 0.0;
99 }
100
101 b = 2 * Math.sin(Math.PI * rX / 6); // Initial guess
102 dxold = xh - xl;
103 dx = dxold;
104 f = integ(b) - ccc;
105 df = deriv(b);
106
107 for (int i = 1; i <= ITMAX; i++) { // Begin the search
108 if ((((b - xh) * df - f) * ((b - xl) * df - f) > 0.0) || (Math.abs(2.0 * f) > Math.abs(dxold * df))) {
109 // Do bisection if solution is out of range
110 // or not decreasing fast enough
111 dxold = dx;
112 dx = 0.5 * (xh - xl);
113 b = xl + dx;
114 if (xl == b) // Change in root is negligible.
115 return b; // Accept this root
116 } else {
117 dxold = dx;
118 dx = f / df;
119 temp = b;
120 b -= dx;
121 if (temp == b)
122 return b;
123 }
124 if (Math.abs(dx) < tolerance)
125 return b; // Convergence check
126 f = integ(b) - ccc;
127 df = deriv(b);
128 if (f < 0.0)
129 xl = b; // Maintain the brackets on the root
130 else
131 xh = b;
132 }
133 return b;
134 }
135
136 public String toString() {
137 // To display the inputs.
138 String desc = super.toString();
139 desc += "tolerance : " + tolerance + "\n";
140 return desc;
141 }
142
143}
Classes implementing discrete distributions over the integers should inherit from this class.
NI3(double rX, DiscreteDistributionInt dist1, DiscreteDistributionInt dist2, double tr, double tolerance)
Constructor with the target rank correlation rX, the two discrete marginals dist1 and dist2,...
Definition NI3.java:66
double computeCorr()
Computes and returns the correlation using algorithm NI3.
Definition NI3.java:75
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:
double integ(double r)
Computes the function.