SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DiscShift2.java
1/*
2 * Class: DiscShift2
3 * Description: computes a discrepancy for the randomly shifted points of a set
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 Richard Simard
9 * @since January 2009
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.discrepancy;
25
26import umontreal.ssj.hups.PointSet;
27import umontreal.ssj.util.Num;
28
69public class DiscShift2 extends Discrepancy {
70
71 protected static double[] setC(double gam) {
72 // 1 dimension
73 double[] C = new double[2];
74 double v = gam * gam;
75 C[0] = 0.5 * v;
76 v = v * v;
77 C[1] = v / 12.0;
78 return C;
79 }
80
81 protected static void setC(double[] C1, double[] C2, double[] gam, int s) {
82 for (int i = 0; i < s; i++) {
83 double v = gam[i] * gam[i];
84 C1[i] = 0.5 * v;
85 v = v * v;
86 C2[i] = v / 12.0;
87 }
88 }
89
95 public DiscShift2(double[][] points, int n, int s) {
96 super(points, n, s);
97 }
98
106 public DiscShift2(double[][] points, int n, int s, double[] gamma) {
107 super(points, n, s, gamma);
108 }
109
116 public DiscShift2(int n, int s, double[] gamma) {
117 super(n, s, gamma);
118 }
119
124 public DiscShift2(PointSet set) {
125 super(set);
126 }
127
132 public DiscShift2() {
133 }
134
140 public double compute(double[][] points, int n, int s) {
141 setONES(s);
142 return compute(points, n, s, ONES);
143 }
144
150 public double compute(double[][] points, int n, int s, double[] gamma) {
151 double[] C1 = new double[s];
152 double[] C2 = new double[s];
153 setC(C1, C2, gamma, s);
154
155 double pol1 = UNSIX; // BernoulliPoly(2, 0);
156 double pol2 = -UNTRENTE; // BernoulliPoly(4, 0);
157 double prod = 1.0;
158 for (int r = 0; r < s; ++r)
159 prod *= (1.0 + C1[r] * pol1 - C2[r] * pol2);
160 double disc = prod / n;
161
162 double sum = 0.0;
163 for (int i = 0; i < n - 1; ++i) {
164 for (int j = i + 1; j < n; ++j) {
165 prod = 1.0;
166 for (int r = 0; r < s; ++r) {
167 double u = points[i][r] - points[j][r];
168 if (u < 0.0)
169 u += 1.0;
170 pol1 = u * (u - 1.0) + UNSIX; // Bernoulli(2, u)
171 pol2 = ((u - 2.0) * u + 1.0) * u * u - UNTRENTE; // Bernoulli(4,h)
172 prod *= 1.0 + C1[r] * pol1 - C2[r] * pol2;
173 }
174 sum += prod;
175 }
176 }
177
178 disc += 2.0 * sum / ((long) n * n) - 1.0;
179 if (disc < 0.0)
180 return -1.0;
181 return Math.sqrt(disc);
182 }
183
189 public double compute(double[] T, int n) {
190 return compute(T, n, 1.0);
191 }
192
198 public double compute(double[] T, int n, double gamma) {
199 double pol1 = UNSIX; // BernoulliPoly(2, 0);
200 double pol2 = -UNTRENTE; // BernoulliPoly(4, 0);
201 double[] C = setC(gamma);
202 double C1 = C[0];
203 double C2 = C[1];
204 double disc = (C1 * pol1 - C2 * pol2) / n;
205
206 double sum = 0.0;
207 for (int i = 0; i < n - 1; ++i) {
208 for (int j = i + 1; j < n; ++j) {
209 double u = T[i] - T[j];
210 if (u < 0.0)
211 u += 1.0;
212 pol1 = u * (u - 1.0) + UNSIX; // Bernoulli(2, u)
213 pol2 = ((u - 2.0) * u + 1.0) * u * u - UNTRENTE; // Bernoulli(4,h)
214 sum += (C1 * pol1 - C2 * pol2);
215 }
216 }
217
218 disc += 2.0 * sum / ((long) n * n);
219 if (disc < 0.0)
220 return -1.0;
221 return Math.sqrt(disc);
222 }
223
224}
double compute(double[] T, int n, double gamma)
Computes the discrepancy ( shift2dim1 ) for the first points of in 1 dimension, with weight gamma.
DiscShift2(PointSet set)
Constructor with the point set set.
double compute(double[] T, int n)
Computes the discrepancy ( shift2dim1 ) for the first points of in 1 dimension, with weight .
double compute(double[][] points, int n, int s)
Computes the discrepancy ( shift2 ) for the first points of set points in dimension .
double compute(double[][] points, int n, int s, double[] gamma)
Computes the discrepancy ( shift2 ) for the first points of set points in dimension and with weight...
DiscShift2(double[][] points, int n, int s)
Constructor with the points points[i] in dimension , with all weights .
DiscShift2(int n, int s, double[] gamma)
The number of points is , the dimension , and the.
DiscShift2(double[][] points, int n, int s, double[] gamma)
Constructor with the points points[i] in dimension , with the weights gamma[j-1],...
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