SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DigitalSequence.java
1/*
2 * Class: DigitalSequence
3 * Description: abstract class with methods specific to digital sequences
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
36public abstract class DigitalSequence extends DigitalNet {
37
43 public abstract void extendSequence(int k);
44
45 private int[][] copyDigitalShift(int[][] S) {
46 // Copy the shift S into T and returns T.
47 if (S == null)
48 return null;
49 int[][] T = new int[S.length][S[0].length];
50 for (int i = 0; i < S.length; ++i)
51 for (int j = 0; j < S[0].length; ++j)
52 T[i][j] = S[i][j];
53 return T;
54 }
55
56 private DigitalNet initNetVar(boolean shiftFlag) {
57 // Initializes the net for the two toNet methods below.
58 DigitalNet net = new DigitalNet();
59 if (shiftFlag)
60 net.dim = dim + 1;
61 else
62 net.dim = dim;
63 net.numPoints = numPoints;
64 net.numCols = numCols;
65 net.numRows = numRows;
66 net.outDigits = outDigits;
67 net.normFactor = normFactor;
68 net.b = b;
69 net.factor = new double[outDigits];
70 for (int i = 0; i < outDigits; i++)
71 net.factor[i] = factor[i];
72 net.genMat = new int[net.dim * numCols][numRows];
73 net.shiftStream = shiftStream;
74 net.capacityShift = capacityShift;
75 net.dimShift = dimShift;
76 net.digitalShift = copyDigitalShift(digitalShift);
77 if (shiftFlag && shiftStream != null) {
78 net.addRandomShift(dimShift, dimShift + 1, shiftStream);
79 }
80 return net;
81 }
82
87 public DigitalNet toNet() {
88 DigitalNet net = initNetVar(false);
89 final int N = dim * numCols;
90 for (int i = 0; i < N; i++)
91 for (int j = 0; j < numRows; j++)
92 net.genMat[i][j] = genMat[i][j];
93 return net;
94 }
95
112 DigitalNet net = initNetVar(true);
113 int j, c, l, start;
114
115 /* Shift all coordinates from the sequence by 1 dimension */
116 for (j = dim; j >= 1; j--) {
117 start = j * numCols;
118 for (c = 0; c < numCols; c++)
119 for (l = 0; l < numRows; l++)
120 net.genMat[start + c][l] = genMat[start - numCols + c][l];
121 }
122
123 // j = 0: initialize C_0 to the reflected identity.
124 for (c = 0; c < numCols; c++) {
125 for (l = 0; l < numRows; l++)
126 net.genMat[c][l] = 0;
127 net.genMat[c][numCols - c - 1] = 1;
128 }
129 return net;
130 }
131
147
161
162 // ************************************************************************
163
164 protected class DigitalNetIteratorShiftGenerators extends DigitalNetIterator {
165 // Similar to DigitalNetIterator; the first coordinate
166 // of point i is i/n, and all the others are shifted one position
167 // to the right. The points have dimension = dim + 1.
168
169 public DigitalNetIteratorShiftGenerators() {
170 super();
171 dimS = dim + 1;
172 if (digitalShift != null && dimShift < dimS)
174 init2();
175 }
176
177 public void init() { // This method is necessary to overload
178 } // the init() of DigitalNetIterator
179
180 public void init2() { // See constructor
182 }
183
184 public void setCurPointIndex(int i) {
185 if (i == 0) {
187 return;
188 }
189 curPointIndex = i;
190 curCoordIndex = 0;
191
192 // Digits of Gray code, used to reconstruct cachedCurPoint.
193 idigits = intToDigitsGray(b, i, numCols, bdigit, gdigit);
194 int c, j, l, sum;
195 for (j = 1; j <= dim; j++) {
196 for (l = 0; l < outDigits; l++) {
197 if (digitalShift == null)
198 sum = 0;
199 else
200 sum = digitalShift[j][l];
201 if (l < numRows)
202 for (c = 0; c < idigits; c++)
203 sum += genMat[(j - 1) * numCols + c][l] * gdigit[c];
204 cachedCurPoint[j * outDigits + l] = sum % b;
205 }
206 }
207 // The case j = 0
208 for (l = 0; l < outDigits; l++) {
209 if (digitalShift == null)
210 sum = 0;
211 else
212 sum = digitalShift[0][l];
213 if (l < numRows)
214 for (c = 0; c < idigits; c++)
215 if (l == numCols - c - 1)
216 sum += gdigit[c];
217 cachedCurPoint[l] = sum % b;
218 }
219 }
220
221 public int resetToNextPoint() {
222 // incremental computation.
224 curCoordIndex = 0;
226 return curPointIndex;
227
228 // Update the digital expansion of i in base b, and find the
229 // position of change in the Gray code. Set all digits == b-1 to 0
230 // and increase the first one after by 1.
231 int pos; // Position of change in the Gray code.
232 for (pos = 0; gdigit[pos] == b - 1; pos++)
233 gdigit[pos] = 0;
234 gdigit[pos]++;
235
236 // Update the cachedCurPoint by adding the column of the gener.
237 // matrix that corresponds to the Gray code digit that has changed.
238 // The digital shift is already incorporated in the cached point.
239 int c, j, l;
240 int lsup = numRows; // Max index l
241 if (outDigits < numRows)
242 lsup = outDigits;
243 for (j = 1; j <= dim; j++) {
244 for (l = 0; l < lsup; l++) {
245 cachedCurPoint[j * outDigits + l] += genMat[(j - 1) * numCols + pos][l];
246 cachedCurPoint[j * outDigits + l] %= b;
247 }
248 }
249 // The case j = 0
250 l = numCols - pos - 1;
251 if (l < lsup) {
252 cachedCurPoint[l] += 1;
253 cachedCurPoint[l] %= b;
254 }
255
256 return curPointIndex;
257 }
258 }
259
260 // ************************************************************************
261
262 protected class DigitalNetIteratorShiftNoGray extends DigitalNetIterator {
263 // Similar to DigitalNetIterator; the first coordinate
264 // of point i is i/n, and all the others are shifted one position
265 // to the right. The points have dimension = dim + 1.
266
267 public DigitalNetIteratorShiftNoGray() {
268 super();
269 dimS = dim + 1;
270 if (digitalShift != null && dimShift < dimS)
272 init2();
273 }
274
275 public void init() { // This method is necessary to overload
276 } // the init() of DigitalNetIterator
277
278 public void init2() { // See constructor
280 }
281
282 public void setCurPointIndex(int i) {
283 if (i == 0) {
285 return;
286 }
287 curPointIndex = i;
288 curCoordIndex = 0;
289
290 // Convert i to b-ary representation, put digits in bdigit.
291 idigits = intToDigitsGray(b, i, numCols, bdigit, gdigit);
292 int c, j, l, sum;
293 for (j = 1; j <= dim; j++) {
294 for (l = 0; l < outDigits; l++) {
295 if (digitalShift == null)
296 sum = 0;
297 else
298 sum = digitalShift[j][l];
299 if (l < numRows)
300 for (c = 0; c < idigits; c++) {
301 sum += genMat[(j - 1) * numCols + c][l] * bdigit[c];
302 sum %= b;
303 }
304 cachedCurPoint[j * outDigits + l] = sum;
305 }
306 }
307 // The case j = 0
308 for (l = 0; l < outDigits; l++) {
309 if (digitalShift == null)
310 sum = 0;
311 else
312 sum = digitalShift[0][l];
313 if (l < numRows)
314 for (c = 0; c < idigits; c++)
315 if (l == numCols - c - 1)
316 sum += bdigit[c];
317 cachedCurPoint[l] = sum % b;
318 }
319 }
320
321 public int resetToNextPoint() {
323 curCoordIndex = 0;
325 return curPointIndex;
326
327 // Find the position of change in the digits of curPointIndex in base
328 // b. Set all digits = b-1 to 0; increase the first one after by 1.
329 int pos;
330 for (pos = 0; bdigit[pos] == b - 1; pos++)
331 bdigit[pos] = 0;
332 bdigit[pos]++;
333
334 // Update the digital expansion of curPointIndex in base b.
335 // Update the cachedCurPoint by adding 1 unit at the digit pos.
336 // If pos > 0, remove b-1 units in the positions < pos. Since
337 // calculations are mod b, this is equivalent to adding 1 unit.
338 // The digital shift is already incorporated in the cached point.
339 int c, j, l;
340 int lsup = numRows; // Max index l
341 if (outDigits < numRows)
342 lsup = outDigits;
343 for (j = 1; j <= dim; j++) {
344 for (l = 0; l < lsup; l++) {
345 for (c = 0; c <= pos; c++)
346 cachedCurPoint[j * outDigits + l] += genMat[(j - 1) * numCols + c][l];
347 cachedCurPoint[j * outDigits + l] %= b;
348 }
349 }
350 // The case j = 0
351 for (l = 0; l < lsup; l++) {
352 for (c = 0; c <= pos; c++)
353 if (l == numCols - c - 1) {
354 cachedCurPoint[l] += 1;
355 cachedCurPoint[l] %= b;
356 }
357 }
358
359 return curPointIndex;
360 }
361
362 }
363}
void resetCurPointIndex()
Resets both the current point index and the current coordinate to 0.
This class provides the basic structures for storing and manipulating linear digital nets in base ,...
DigitalNet()
Empty constructor.
void setCurPointIndex(int i)
Resets the current point index to i and current coordinate to 0.
int resetToNextPoint()
Resets the current point index to the next one and current coordinate to 0, and returns the new curre...
int resetToNextPoint()
Resets the current point index to the next one and current coordinate to 0, and returns the new curre...
void setCurPointIndex(int i)
Resets the current point index to i and current coordinate to 0.
This abstract class describes methods specific to digital sequences.
DigitalNet toNetShiftCj()
Transforms this digital sequence into a digital net by adding one dimension and shifting all coordina...
abstract void extendSequence(int k)
Increases the number of points to from now on.
PointSetIterator iteratorShift()
Similar to iterator, except that the first coordinate of the points is , the second coordinate is obt...
DigitalNet toNet()
Transforms this digital sequence into a digital net without changing the coordinates of the points.
PointSetIterator iteratorShiftNoGray()
This iterator shifts all coordinates of each point one position to the right and sets the first coord...
int curPointIndex
Index of the current point.
int curCoordIndex
Index of the current coordinate.
int dimShift
Current dimension of the shift.
void addRandomShift()
Same as addRandomShift(0, dim), where dim is the dimension of the point set.
int numPoints
Number of points.
int capacityShift
Number of array elements in the shift vector, always >= dimShift.
int dim
Dimension of the points.
RandomStream shiftStream
Stream used to generate the random shifts.
This is the interface for iterators that permit one to go through the points of a PointSet and the su...