SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
FaureSequence.java
1/*
2 * Class: FaureSequence
3 * Description:
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
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.hups;
26
27import umontreal.ssj.util.PrintfFormat;
28
89public class FaureSequence extends DigitalSequence {
90
91 // Maximum dimension for the case where b is not specified.
92 // Can be extended by extending the precomputed array prime[].
93 private static final int MAXDIM = 500;
94
95 // For storing the generator matrices for given dim and numPoints.
96 private int[][][] v;
97
115 public FaureSequence(int b, int k, int r, int w, int dim) {
116 init(b, k, r, w, dim);
117 }
118
119 private void init(int b, int k, int r, int w, int dim) {
120 if (dim < 1)
121 throw new IllegalArgumentException("Dimension for FaureSequence must be > 1");
122 if ((double) k * Math.log((double) b) > (31.0 * Math.log(2.0)))
123 throw new IllegalArgumentException("Trying to construct a FaureSequence with too many points");
124 if (r < k || w < r)
125 throw new IllegalArgumentException("One must have k <= r <= w for FaureSequence");
126 this.b = b;
127 numCols = k;
128 numRows = r;
129 outDigits = w;
130 this.dim = dim;
131
132 int i, j;
133 numPoints = b;
134 for (i = 1; i < k; i++)
135 numPoints *= b;
136
137 // Compute the normalization factors.
138 normFactor = 1.0 / Math.pow((double) b, (double) outDigits);
139// EpsilonHalf = 0.5*normFactor;
140 double invb = 1.0 / b;
141 factor = new double[outDigits];
142 factor[0] = invb;
143 for (j = 1; j < outDigits; j++)
144 factor[j] = factor[j - 1] * invb;
145
146 genMat = new int[dim * numCols][numRows];
147 initGenMat();
148 }
149
160 public FaureSequence(int n, int dim) {
161 if ((dim < 1) || (dim > MAXDIM))
162 throw new IllegalArgumentException("Dimension for Faure net must be > 1 and < " + MAXDIM);
163 b = getSmallestPrime(dim);
164 numCols = (int) Math.ceil(Math.log((double) n) / Math.log((double) b));
165 outDigits = (int) Math.floor(Math.log((double) (1 << (MAXBITS - 1))) / Math.log((double) b));
166 outDigits = Math.max(outDigits, numCols);
167 numRows = outDigits;
168 init(b, numCols, numRows, outDigits, dim);
169 }
170
171 public String toString() {
172 StringBuffer sb = new StringBuffer("Faure sequence:" + PrintfFormat.NEWLINE);
173 sb.append(super.toString());
174 return sb.toString();
175 }
176
177 public void extendSequence(int k) {
178 init(b, k, numRows, outDigits, dim);
179 }
180
181 // Fills up the generator matrices in genMat for a Faure sequence.
182 // See Glasserman (2004), @cite fGLA04a, page 301.
183 private void initGenMat() {
184 int j, c, l;
185 // Initialize C_0 to the identity (for first coordinate).
186 for (c = 0; c < numCols; c++) {
187 for (l = 0; l < numRows; l++)
188 genMat[c][l] = 0;
189 genMat[c][c] = 1;
190 }
191 // Compute C_1, ... ,C_{dim-1}.
192 for (j = 1; j < dim; j++) {
193 genMat[j * numCols][0] = 1;
194 for (c = 1; c < numCols; c++) {
195 genMat[j * numCols + c][c] = 1;
196 genMat[j * numCols + c][0] = (j * genMat[j * numCols + c - 1][0]) % b;
197 }
198 for (c = 2; c < numCols; c++) {
199 for (l = 1; l < c; l++)
200 genMat[j * numCols + c][l] = (genMat[j * numCols + c - 1][l - 1] + j * genMat[j * numCols + c - 1][l])
201 % b;
202 }
203 for (c = 0; c < numCols; c++)
204 for (l = c + 1; l < numRows; l++)
205 genMat[j * numCols + c][l] = 0;
206 }
207 /*
208 * for (j = 0; j < dim; j++) { for (l = 0; l < numRows; l++) { for (c = 0; c <
209 * numCols; c++) System.out.print (" " + genMat[j*numCols+c][l]);
210 * System.out.println (""); } System.out.println (""); }
211 */
212 }
213
214 /*
215 * // Fills up the generator matrices in genMat for a Faure net. // See
216 * Glasserman (2004), @cite fGLA04a, page 301. protected void initGenMatNet() {
217 * int j, c, l, start; // Initialize C_0 to the reflected identity (for first
218 * coordinate). for (c = 0; c < numCols; c++) { for (l = 0; l < numRows; l++)
219 * genMat[c][l] = 0; genMat[c][numCols-c-1] = 1; } // Initialize C_1 to the
220 * identity (for second coordinate). for (c = 0; c < numCols; c++) { for (l = 0;
221 * l < numRows; l++) genMat[numCols+c][l] = 0; genMat[numCols+c][c] = 1; } //
222 * Compute C_2, ... ,C_{dim-1}. for (j = 2; j < dim; j++) { start = j * numCols;
223 * genMat[start][0] = 1; for (c = 1; c < numCols; c++) { genMat[start+c][c] = 1;
224 * genMat[start+c][0] = ((j-1) * genMat[start+c-1][0]) % b; } for (c = 2; c <
225 * numCols; c++) { for (l = 1; l < c; l++) genMat[start+c][l] =
226 * (genMat[start+c-1][l-1] + (j-1) * genMat[start+c-1][l]) % b; } for (c = 0; c
227 * < numCols; c++) for (l = c+1; l < numRows; l++) genMat[start+c][l] = 0; } }
228 */
229
230 // Returns the smallest prime larger or equal to d.
231 private int getSmallestPrime(int d) {
232 return primes[d - 1];
233 }
234
235 // Gives the appropriate prime base for each dimension.
236 // Perhaps should be internal to getPrime, and non-static, to avoid
237 // wasting time and memory when this array is not needed ???
238 static final int primes[] = { 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11, 13, 13, 17, 17, 17, 17, 19, 19, 23, 23, 23, 23,
239 29, 29, 29, 29, 29, 29, 31, 31, 37, 37, 37, 37, 37, 37, 41, 41, 41, 41, 43, 43, 47, 47, 47, 47, 53, 53, 53, 53,
240 53, 53, 59, 59, 59, 59, 59, 59, 61, 61, 67, 67, 67, 67, 67, 67, 71, 71, 71, 71, 73, 73, 79, 79, 79, 79, 79, 79,
241 83, 83, 83, 83, 89, 89, 89, 89, 89, 89, 97, 97, 97, 97, 97, 97, 97, 97, 101, 101, 101, 101, 103, 103, 107, 107,
242 107, 107, 109, 109, 113, 113, 113, 113, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
243 131, 131, 131, 131, 137, 137, 137, 137, 137, 137, 139, 139, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149,
244 151, 151, 157, 157, 157, 157, 157, 157, 163, 163, 163, 163, 163, 163, 167, 167, 167, 167, 173, 173, 173, 173,
245 173, 173, 179, 179, 179, 179, 179, 179, 181, 181, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 193, 193,
246 197, 197, 197, 197, 199, 199, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211, 223, 223, 223, 223,
247 223, 223, 223, 223, 223, 223, 223, 223, 227, 227, 227, 227, 229, 229, 233, 233, 233, 233, 239, 239, 239, 239,
248 239, 239, 241, 241, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 257, 257, 257, 257, 257, 257, 263, 263,
249 263, 263, 263, 263, 269, 269, 269, 269, 269, 269, 271, 271, 277, 277, 277, 277, 277, 277, 281, 281, 281, 281,
250 283, 283, 293, 293, 293, 293, 293, 293, 293, 293, 293, 293, 307, 307, 307, 307, 307, 307, 307, 307, 307, 307,
251 307, 307, 307, 307, 311, 311, 311, 311, 313, 313, 317, 317, 317, 317, 331, 331, 331, 331, 331, 331, 331, 331,
252 331, 331, 331, 331, 331, 331, 337, 337, 337, 337, 337, 337, 347, 347, 347, 347, 347, 347, 347, 347, 347, 347,
253 349, 349, 353, 353, 353, 353, 359, 359, 359, 359, 359, 359, 367, 367, 367, 367, 367, 367, 367, 367, 373, 373,
254 373, 373, 373, 373, 379, 379, 379, 379, 379, 379, 383, 383, 383, 383, 389, 389, 389, 389, 389, 389, 397, 397,
255 397, 397, 397, 397, 397, 397, 401, 401, 401, 401, 409, 409, 409, 409, 409, 409, 409, 409, 419, 419, 419, 419,
256 419, 419, 419, 419, 419, 419, 421, 421, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 433, 433, 439, 439,
257 439, 439, 439, 439, 443, 443, 443, 443, 449, 449, 449, 449, 449, 449, 457, 457, 457, 457, 457, 457, 457, 457,
258 461, 461, 461, 461, 463, 463, 467, 467, 467, 467, 479, 479, 479, 479, 479, 479, 479, 479, 479, 479, 479, 479,
259 487, 487, 487, 487, 487, 487, 487, 487, 491, 491, 491, 491, 499, 499, 499, 499, 499, 499, 499, 499, 503 };
260
261}
This abstract class describes methods specific to digital sequences.
FaureSequence(int n, int dim)
Same as FaureSequence(b, k, w, w, dim) with base equal to the smallest prime larger or equal to dim,...
FaureSequence(int b, int k, int r, int w, int dim)
Constructs a digital net in base , with points and output digits, in dim dimensions.
String toString()
Formats a string that contains information on this digital net.
void extendSequence(int k)
Increases the number of points to from now on.
static final int MAXBITS
Since Java has no unsigned type, the 32nd bit cannot be used efficiently, so we have only 31 bits.
int numPoints
Number of points.
int dim
Dimension of the points.
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.