SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DiscShiftBaker1.java
1/*
2 * Class: DiscShiftBaker1
3 * Description: computes a discrepancy for a randomly shifted, then baker
4 folded point set
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author Richard Simard
10 * @since January 2009
11
12 * SSJ is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License (GPL) as published by the
14 * Free Software Foundation, either version 3 of the License, or
15 * any later version.
16
17 * SSJ is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21
22 * A copy of the GNU General Public License is available at
23 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
24 */
25package umontreal.ssj.discrepancy;
26
27import umontreal.ssj.hups.PointSet;
28import umontreal.ssj.util.Num;
29
80public class DiscShiftBaker1 extends Discrepancy {
81
82 static protected double[] setC(double gam) { // dimension = 1
83 double[] C = new double[3];
84 double v = gam * gam;
85 C[0] = v * 4.0 / 3.0;
86 v = v * v;
87 C[1] = v / 9.0;
88 C[2] = v * 16.0 / 45.0;
89 return C;
90 }
91
92 static protected void setC(double[] C1, double[] C2, double[] C3, double[] gam, int s) {
93 for (int i = 0; i < s; i++) {
94 double v = gam[i] * gam[i];
95 C1[i] = v * 4.0 / 3.0;
96 v = v * v;
97 C2[i] = v / 9.0;
98 C3[i] = v * 16.0 / 45.0;
99 }
100 }
101
107 public DiscShiftBaker1(double[][] points, int n, int s) {
108 super(points, n, s);
109 }
110
116 public DiscShiftBaker1(double[][] points, int n, int s, double[] gamma) {
117 super(points, n, s, gamma);
118 }
119
126 public DiscShiftBaker1(int n, int s, double[] gamma) {
127 super(n, s, gamma);
128 }
129
135 super(set);
136 }
137
143 }
144
151 public double compute(double[][] points, int n, int s) {
152 setONES(s);
153 return compute(points, n, s, ONES);
154 }
155
161 public double compute(double[][] points, int n, int s, double[] gamma) {
162 double[] C1 = new double[s];
163 double[] C2 = new double[s];
164 double[] C3 = new double[s];
165 setC(C1, C2, C3, gamma, s);
166
167 double pol1 = -1.0 / 30.0; // BernoulliPoly(4, 0);
168 double pol2 = 7.0 / 240.0; // BernoulliPoly(4, 0.5);
169 double pol3 = 1.0 / 42.0; // BernoulliPoly(6, 0);
170 double pol4 = -31.0 / 1344.0; // BernoulliPoly(6, 0.5);
171
172 double prod = 1.0;
173 double temp;
174 for (int r = 0; r < s; ++r) {
175 temp = C1[r] * (pol1 - pol2) + C2[r] * (7.0 * pol1 - 2.0 * pol2) + C3[r] * (pol3 - pol4);
176 prod *= 1.0 - temp;
177 }
178 double disc = prod / n;
179
180 double sum = 0.0;
181 for (int i = 0; i < n - 1; ++i) {
182 for (int j = i + 1; j < n; ++j) {
183 prod = 1.0;
184 for (int r = 0; r < s; ++r) {
185 double u = points[i][r] - points[j][r];
186 if (u < 0.0)
187 u += 1.0;
188 pol1 = ((u - 2.0) * u + 1.0) * u * u - UNTRENTE; // Bernoulli(4,u)
189 double v = u - 0.5;
190 if (v < 0.0)
191 v += 1.0;
192 pol2 = ((v - 2.0) * v + 1.0) * v * v - UNTRENTE; // Bernoulli(4,v)
193
194 // Bernoulli (6, u) and Bernoulli (6, v)
195 pol3 = (((u - 3.0) * u + 2.5) * u * u - 0.5) * u * u + QUARAN;
196 pol4 = (((v - 3.0) * v + 2.5) * v * v - 0.5) * v * v + QUARAN;
197
198 temp = C1[r] * (pol1 - pol2) + C2[r] * (7.0 * pol1 - 2.0 * pol2) + C3[r] * (pol3 - pol4);
199 prod *= 1.0 - temp;
200 }
201 sum += prod;
202 }
203 }
204
205 disc += 2.0 * sum / ((long) n * n) - 1.0;
206 if (disc < 0.0)
207 return -1.0;
208 return Math.sqrt(disc);
209 }
210
216 public double compute(double[] T, int n) {
217 return compute(T, n, 1.0);
218 }
219
225 public double compute(double[] T, int n, double gamma) {
226 double[] C = setC(gamma);
227 double C1 = C[0];
228 double C2 = C[1];
229 double C3 = C[2];
230
231 double pol1 = -1.0 / 30.0; // BernoulliPoly(4, 0);
232 double pol2 = 7.0 / 240.0; // BernoulliPoly(4, 0.5);
233 double temp = C1 * (pol1 - pol2) + C2 * (7.0 * pol1 - 2.0 * pol2) + C3 * (1.0 / 42.0 + 31.0 / 1344.0);
234 double disc = -temp / n;
235
236 double sum = 0.0;
237 for (int i = 0; i < n - 1; ++i) {
238 for (int j = i + 1; j < n; ++j) {
239 double h = T[i] - T[j];
240 if (h < 0.0)
241 h += 1.0;
242 pol1 = ((h - 2.0) * h + 1.0) * h * h - UNTRENTE; // Bernoulli(4,h)
243 double v = h - 0.5;
244 if (v < 0.0)
245 v += 1.0;
246 pol2 = ((v - 2.0) * v + 1.0) * v * v - UNTRENTE; // Bernoulli(4,v)
247 temp = C1 * (pol1 - pol2) + C2 * (7.0 * pol1 - 2.0 * pol2);
248 // Bernoulli (6, h) and Bernoulli (6, v)
249 pol1 = (((h - 3.0) * h + 2.5) * h * h - 0.5) * h * h + QUARAN;
250 pol2 = (((v - 3.0) * v + 2.5) * v * v - 0.5) * v * v + QUARAN;
251 temp += C3 * (pol1 - pol2);
252 sum -= temp;
253 }
254 }
255
256 disc += 2.0 * sum / ((long) n * n);
257 if (disc < 0.0)
258 return -1.0;
259 return Math.sqrt(disc);
260 }
261
262}
double compute(double[] T, int n)
Computes the discrepancy ( baker1dim1 ) for the first points of in 1 dimension, with weight .
DiscShiftBaker1(int n, int s, double[] gamma)
The number of points is , the dimension , and the.
double compute(double[] T, int n, double gamma)
Computes the discrepancy ( baker1dim1 ) for the first points of in 1 dimension, with weight gamma.
double compute(double[][] points, int n, int s, double[] gamma)
Computes the discrepancy ( baker1 ) for the first points of points in dimension and with weight ga...
DiscShiftBaker1(double[][] points, int n, int s, double[] gamma)
Constructor with the points points[i] in dimensions, with weights gamma[r-1].
double compute(double[][] points, int n, int s)
Computes the discrepancy ( baker1 ) for the -dimensional points of set points, containing.
DiscShiftBaker1(PointSet set)
Constructor with the point set set.
DiscShiftBaker1(double[][] points, int n, int s)
Constructor with the points points[i] in dimensions, with all the weights .
Discrepancy(double[][] points, int n, int s)
Constructor with the points points[i] in dimensions.
double compute()
Computes the discrepancy of all the points in maximal dimension (dimension of the points).
This abstract class represents a general point set.
Definition PointSet.java:99