SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
SearcherCBC.java
1/*
2 * Class: SearcherCBC
3 * Description: searches the best rank-1 lattices with respect to a given
4 discrepancy, using component-by-component (CBC) searches.
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.Rank1Lattice;
28import umontreal.ssj.util.Num;
29
46public class SearcherCBC extends Searcher {
47 protected double[] bestVals; // best value of discr in dim 0, 1, ..., (s-1)
48
49 private double exhaust(int s, boolean relPrime) {
50 int n = disc.getNumPoints();
51 gamma = disc.getGamma();
52 int pos = -1;
53 double err;
54 double best = 0;
55 int i, j;
56 bestAs[0] = 1;
57 bestVals[0] = -1;
58
59 for (j = 1; j < s; j++) {
60 best = Double.MAX_VALUE;
61 pos = -1;
62 for (i = 1; i < n; i++) {
63 if (relPrime) {
64 // Consider only values i relatively prime to n
65 if (power2F) {
66 if ((i & 1) == 0)
67 continue;
68 } else {
69 if (Num.gcd(n, i) != 1)
70 continue;
71 }
72 }
73 bestAs[j] = i;
74 // print (bestAs, j + 1);
75 lat = new Rank1Lattice(n, bestAs, j + 1);
76 err = disc.compute(lat, gamma);
77 if (err < best) {
78 best = err;
79 pos = i;
80 }
81 }
82 bestAs[j] = pos;
83 bestVals[j] = best;
84 }
85
86 bestVal = best;
87 return best;
88 }
89
90 private double random(int s, int k, boolean relPrime) {
91 int n = disc.getNumPoints();
92 if (k >= n)
93 return exhaust(s, relPrime);
94
95 gamma = disc.getGamma();
96 final int nm1 = n - 1;
97 int pos = -1;
98 double err;
99 double best = 0;
100 int i, j;
101 bestAs[0] = 1;
102 bestVals[0] = -1;
103
104 for (j = 1; j < s; j++) {
105 best = Double.MAX_VALUE;
106 i = 0;
107 while (i < k) {
108 if (power2F) {
109 bestAs[j] = gen.nextInt(1, nm1);
110 if (relPrime)
111 bestAs[j] |= 1;
112 } else {
113 do {
114 bestAs[j] = gen.nextInt(1, nm1);
115 } while (relPrime && (Num.gcd(n, bestAs[j]) != 1));
116 }
117 i++;
118 // print (bestAs, j + 1);
119 lat = new Rank1Lattice(n, bestAs, j + 1);
120 err = disc.compute(lat, gamma);
121 if (err < best) {
122 best = err;
123 pos = bestAs[j];
124 }
125 }
126 bestAs[j] = pos;
127 bestVals[j] = best;
128 }
129
130 bestVal = best;
131 return best;
132 }
133
141 public SearcherCBC(Discrepancy disc, boolean primeN) {
142 super(disc, primeN);
143 int s = disc.getDimension();
144 bestVals = new double[s];
145 }
146
158 public double exhaust(int s) {
159 return exhaust(s, false);
160 }
161
166 public double exhaustPrime(int s) {
167 if (primeN)
168 return exhaust(s, false); // all a_j are rel. prime to n
169 else
170 return exhaust(s, true);
171 }
172
182 public double random(int s, int k) {
183 return random(s, k, false);
184 }
185
190 public double randomPrime(int s, int k) {
191 if (primeN)
192 return random(s, k, false); // all a_j are rel. prime to n
193 else
194 return random(s, k, true);
195 }
196
202 public double[] getBestVals() {
203 return bestVals;
204 }
205
206}
This abstract class is the base class of all discrepancy classes.
SearcherCBC(Discrepancy disc, boolean primeN)
The number of points , the dimension , and possibly the weight factors must be given in disc.
double exhaustPrime(int s)
Similar to exhaust(s), except that only values of relatively prime to are considered.
double[] getBestVals()
Returns the best value of the discrepancy found in the last search, in each dimension up to .
double exhaust(int s)
Exhaustive CBC search to find the lattice with the best (the smallest) discrepancy in dimension .
double random(int s, int k)
Random CBC search to find the lattice with the best (the smallest) discrepancy in dimension .
double randomPrime(int s, int k)
Similar to random(s, k), except that only values of relatively prime to are considered.
Searcher(Discrepancy disc, boolean primeN)
The number of points , the dimension , and possibly the weight factors must be given in disc.
This class implements point sets specified by integration lattices of rank 1.
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static int gcd(int x, int y)
Returns the greatest common divisor (gcd) of and .
Definition Num.java:200