SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
Discrepancy.java
1/*
2 * Class: Discrepancy
3 * Description: Base class of all discrepancies
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.*;
27import cern.colt.list.DoubleArrayList;
28import umontreal.ssj.util.PrintfFormat;
29
36public abstract class Discrepancy {
37 protected static double[] ONES = { 1 }; // vector of 1, dimension dim
38 protected double[] gamma; // gamma[]: weights, dimension dim
39 protected double[][] Points; // Points[n][s]: n points in s dimensions
40 protected int dim; // Dimension of points
41 protected int numPoints; // Number of points
42// protected boolean primeF; // true if numPoints is prime
43// protected boolean power2F; // true if numPoints is a power of 2
44
45 static final double UNSIX = 1.0 / 6.0;
46 static final double QUARAN = 1.0 / 42.0;
47 static final double UNTRENTE = 1.0 / 30.0;
48 static final double DTIERS = 2.0 / 3.0;
49 static final double STIERS = 7.0 / 3.0;
50 static final double QTIERS = 14.0 / 3.0;
51
52 static protected void setONES(int s) {
53 if (s < ONES.length)
54 return;
55 ONES = new double[s + 1];
56 for (int i = 0; i <= s; i++)
57 ONES[i] = 1.0;
58 }
59
60 protected void appendGamma(StringBuffer sb, double[] gamma, int s) {
61 // append the first s components of gamma to sb
62 if (gamma != null) {
63 for (int j = 0; j < s; ++j)
64 sb.append(" " + gamma[j]);
65 }
66 }
67
68 private void initD(double[][] points, int n, int s, double[] gamma) {
69 setONES(s);
70 if (gamma == null)
71 setGamma(ONES, s);
72 else
73 setGamma(gamma, s);
74 dim = s;
75 numPoints = n;
76 this.Points = points;
77 }
78
86 public Discrepancy(double[][] points, int n, int s) {
87 initD(points, n, s, null);
88 }
89
99 public Discrepancy(double[][] points, int n, int s, double[] gamma) {
100 initD(points, n, s, gamma);
101 }
102
109 public Discrepancy(int n, int s, double[] gamma) {
110 initD(null, n, s, gamma);
111 }
112
117 public Discrepancy(PointSet set) {
118 numPoints = set.getNumPoints();
119 dim = set.getDimension();
120 Points = toArray(set);
121 initD(Points, numPoints, dim, null);
122 }
123
128 public Discrepancy() {
129 }
130
135 public double compute() {
136 return compute(Points, numPoints, dim, gamma);
137 }
138
142 public double compute(int s) {
143 return compute(Points, numPoints, s, gamma);
144 }
145
150 public double compute(double[][] points, int n, int s, double[] gamma) {
151 return -1;
152 }
153
158 public abstract double compute(double[][] points, int n, int s);
159
165 public double compute(double[][] points) {
166 return compute(points, points.length, points[0].length, gamma);
167 }
168
175 public double compute(double[] T, int n) {
176 double[][] p = new double[n][1];
177 for (int i = 0; i < n; ++i)
178 p[i][0] = T[i];
179 return compute(p, n, 1);
180 }
181
186 public double compute(double[] T) {
187 return compute(T, T.length, gamma[0]);
188 }
189
194 public double compute(double[] T, int n, double gamma) {
195 return -1;
196 }
197
202 public double compute(PointSet set, double[] gamma) {
203 int n = set.getNumPoints();
204 int dim = set.getDimension();
205 if (dim > 1) {
206 double[][] points = new double[n][dim];
207 PointSetIterator it = set.iterator();
208 for (int i = 0; i < n; ++i) {
209 it.nextPoint(points[i], dim);
210 }
211 return compute(points, n, dim, gamma);
212 } else {
213 double[] points = new double[n];
214 PointSetIterator it = set.iterator();
215 for (int i = 0; i < n; ++i) {
216 points[i] = it.nextCoordinate();
217 it.resetToNextPoint();
218 }
219 return compute(points, n, gamma[0]);
220 }
221 }
222
227 public double compute(PointSet set) {
228 int dim = set.getDimension();
229 setONES(dim);
230 return compute(set, ONES);
231 }
232
236 public int getNumPoints() {
237 return numPoints;
238 }
239
243 public int getDimension() {
244 return dim;
245 }
246
251 public void setPoints(double[][] points, int n, int s) {
252 initD(points, n, s, null);
253 }
254
259 public void setPoints(double[][] points) {
260 setPoints(points, points.length, points[0].length);
261 }
262
266 public void setGamma(double[] gam, int s) {
267 gamma = gam;
268 }
269
273 public double[] getGamma() {
274 return gamma;
275 }
276
283 public static double[][] toArray(PointSet set) {
284 int n = set.getNumPoints();
285 int dim = set.getDimension();
286 if (dim > 1) {
287 double[][] points = new double[n][dim];
288 PointSetIterator it = set.iterator();
289 for (int i = 0; i < n; ++i)
290 it.nextPoint(points[i], dim);
291 return points;
292
293 } else {
294 double[][] po1 = new double[n][1];
295 PointSetIterator it = set.iterator();
296 for (int i = 0; i < n; ++i) {
297 po1[i][0] = it.nextCoordinate();
298 it.resetToNextPoint();
299 }
300 return po1;
301 }
302 }
303
308 public static DoubleArrayList sort(double[] T, int n) {
309 DoubleArrayList sortedU = new DoubleArrayList(T);
310 sortedU.sortFromTo(0, n - 1);
311 return sortedU;
312 }
313
317 public String toString() {
318 StringBuffer sb = new StringBuffer(getName() + ":" + PrintfFormat.NEWLINE);
319 sb.append("n = " + numPoints + ", dim = " + dim + PrintfFormat.NEWLINE);
320 sb.append("gamma = [");
321 appendGamma(sb, gamma, dim);
322 sb.append(" ]" + PrintfFormat.NEWLINE);
323 return sb.toString();
324 }
325
329 public String formatPoints() {
330 StringBuffer sb = new StringBuffer("Points = [" + PrintfFormat.NEWLINE);
331 if (Points != null) {
332 for (int i = 0; i < Points.length; ++i) {
333 sb.append(" [ " + Points[i][0]);
334 for (int j = 1; j < Points[0].length; ++j)
335 sb.append(", " + Points[i][j]);
336 sb.append(" ]" + PrintfFormat.NEWLINE);
337 }
338 }
339 sb.append(" ]" + PrintfFormat.NEWLINE);
340 return sb.toString();
341 }
342
346 public String getName() {
347 return getClass().getSimpleName();
348 }
349
350}
double compute(PointSet set, double[] gamma)
Computes the discrepancy of all the points in set in the same dimension as the point set and with wei...
double compute(double[] T)
Computes the discrepancy of all the points of T in 1 dimension.
int getDimension()
Returns the dimension of the points .
double compute(double[][] points, int n, int s, double[] gamma)
Computes the discrepancy of the first n points of points in dimension s with weights gamma.
String formatPoints()
Returns all the points of this class.
double compute(int s)
Computes the discrepancy of all the points in dimension .
Discrepancy(int n, int s, double[] gamma)
The number of points is , the dimension , and the.
double compute(double[][] points)
Computes the discrepancy of all the points of points in maximum dimension.
void setPoints(double[][] points)
Sets the points to points.
double compute(double[] T, int n)
Computes the discrepancy of the first n points of T in 1 dimension.
String getName()
Returns the name of the Discrepancy.
String toString()
Returns the parameters of this class.
Discrepancy(double[][] points, int n, int s, double[] gamma)
Constructor with the points points[i] in dimensions and the weight factors gamma[ ],...
Discrepancy(PointSet set)
Constructor with the point set set.
double compute(PointSet set)
Computes the discrepancy of all the points in set in the same dimension as the point set.
static double[][] toArray(PointSet set)
Returns all the points ( -dimensional) of.
Discrepancy(double[][] points, int n, int s)
Constructor with the points points[i] in dimensions.
int getNumPoints()
Returns the number of points .
static DoubleArrayList sort(double[] T, int n)
Sorts the first points of .
double compute(double[] T, int n, double gamma)
Computes the discrepancy of the first n points of T in 1 dimension with weight gamma.
void setGamma(double[] gam, int s)
Sets the weight factors to gam for each dimension up to .
double compute()
Computes the discrepancy of all the points in maximal dimension (dimension of the points).
abstract double compute(double[][] points, int n, int s)
Computes the discrepancy of the first n points of points in dimension s with weights .
void setPoints(double[][] points, int n, int s)
Sets the points to points and the dimension to .
double[] getGamma()
Returns the weight factors gamma for each dimension up to .
This abstract class represents a general point set.
Definition PointSet.java:99
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
int nextPoint(double[] p, int fromDim, int d)
Returns in p the next d coordinates of the current point, starting at coordinate fromDim (i....
int resetToNextPoint()
Increases the current point index by 1 and returns its new value.
double nextCoordinate()
Returns the current coordinate and advances to the next one.