SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DigitalSequenceBase2.java
1/*
2 * Class: DigitalSequenceBase2
3 * Description: abstract class with methods specific to digital sequences
4 in base 2
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
10 * @since
11 *
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 */
26package umontreal.ssj.hups;
27
37public abstract class DigitalSequenceBase2 extends DigitalNetBase2 {
38
44 public abstract void extendSequence(int k);
45
46 private int[] copyDigitalShift(int[] S) {
47 // Copy the shift S into T and returns T.
48 if (S == null)
49 return null;
50 int[] T = new int[S.length];
51 for (int i = 0; i < S.length; ++i)
52 T[i] = S[i];
53 return T;
54 }
55
56 private DigitalNetBase2 initNetVar(boolean shiftFlag) {
57 // Initializes the net for the two toNet methods below.
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.factor = new double[outDigits];
69 net.genMat = new int[net.dim * numCols];
70 net.shiftStream = shiftStream;
71 net.capacityShift = capacityShift;
72 net.dimShift = dimShift;
73 net.digitalShift = copyDigitalShift(digitalShift);
74 if (shiftFlag && shiftStream != null) {
75 net.addRandomShift(dimShift, dimShift + 1, shiftStream);
76 }
77 return net;
78 }
79
87 DigitalNetBase2 net = initNetVar(false);
88 for (int i = 0; i < dim * numCols; i++)
89 net.genMat[i] = genMat[i];
90 return net;
91 }
92
109 DigitalNetBase2 net = initNetVar(true);
110 int c;
111 for (c = (dim + 1) * numCols - 1; c >= numCols; --c)
112 net.genMat[c] = genMat[c - numCols];
113
114 // the first dimension, j = 0.
115 for (c = 0; c < numCols; c++)
116 net.genMat[c] = (1 << (outDigits - numCols + c));
117 return net;
118 }
119
135
149
150 // *******************************************************************
151
152 protected class DigitalNetBase2IteratorShiftGenerators extends DigitalNetBase2Iterator {
153 // Similar to DigitalNetBase2Iterator; the first coordinate
154 // of point i is i/n, and all the others are shifted one position
155 // to the right. The points have one more dimension.
156
157 public DigitalNetBase2IteratorShiftGenerators() {
158 super();
159 dimS = dim + 1;
160 if (digitalShift != null && dimShift < dimS)
163 }
164
165 public void init2() { // This method is necessary to overload
166 } // the init2() of DigitalNetBase2Iterator
167
168 protected void addShiftToCache() {
169 if (digitalShift == null)
170 for (int j = 0; j < dimS; j++)
171 cachedCurPoint[j] = 0;
172 else
173 for (int j = 0; j < dimS; j++)
174 cachedCurPoint[j] = digitalShift[j];
175 }
176
177 public void setCurPointIndex(int i) {
178 if (i == 0) {
180 return;
181 }
182 // Out of order computation, must recompute the cached current
183 // point from scratch.
184 curPointIndex = i;
185 curCoordIndex = 0;
186 addShiftToCache();
187
188 int j;
189 int grayCode = i ^ (i >> 1);
190 int pos = 0; // Position of the bit that is examined.
191 while ((grayCode >> pos) != 0) {
192 if (((grayCode >> pos) & 1) != 0) {
193 cachedCurPoint[0] ^= 1 << (outDigits - numCols + pos);
194 for (j = 1; j <= dim; j++)
195 cachedCurPoint[j] ^= genMat[(j - 1) * numCols + pos];
196 }
197 pos++;
198 }
199 }
200
201 public int resetToNextPoint() {
202 int pos = 0; // Will be position of change in Gray code,
203 // = pos. of first 0 in binary code of point index.
204 while (((curPointIndex >> pos) & 1) != 0)
205 pos++;
206 if (pos < numCols) {
207 // The matrix C for first coord. is a reflected identity.
208 // Col. pos has a 1 in line k-1-pos.
209 cachedCurPoint[0] ^= 1 << (outDigits - numCols + pos);
210 for (int j = 1; j <= dim; j++)
211 cachedCurPoint[j] ^= genMat[(j - 1) * numCols + pos];
212 }
213 curCoordIndex = 0;
214 return ++curPointIndex;
215 }
216
217 }
218
219 // *******************************************************************
220
221 protected class DigitalNetBase2IteratorShiftNoGray extends DigitalNetBase2Iterator {
222 // Similar to DigitalNetBase2IteratorShiftGenerators,
223 // except that the Gray code is not used.
224 private boolean shiftDimFlag = false; // ensures that the random shift
225 // has been initialized with dim + 1 components
226
227 public DigitalNetBase2IteratorShiftNoGray() {
228 super();
229 dimS = dim + 1;
230 if (digitalShift != null && dimShift < dimS)
233 }
234
235 public void init2() { // This method is necessary to overload
236 } // the init2() of DigitalNetBase2Iterator
237
238 protected void addShiftToCache() {
239 if (digitalShift == null)
240 for (int j = 0; j <= dim; j++)
241 cachedCurPoint[j] = 0;
242 else
243 for (int j = 0; j <= dim; j++)
244 cachedCurPoint[j] = digitalShift[j];
245 }
246
247 public void setCurPointIndex(int i) {
248 if (i == 0) {
250 return;
251 }
252 // Out of order computation, must recompute the cached current
253 // point from scratch.
254 curPointIndex = i;
255 curCoordIndex = 0;
256 addShiftToCache();
257
258 int pos = 0; // Position of the bit that is examined.
259 while ((i >> pos) != 0) {
260 if (((i >> pos) & 1) != 0) {
261 cachedCurPoint[0] ^= 1 << (outDigits - numCols + pos);
262 for (int j = 1; j <= dim; j++)
263 cachedCurPoint[j] ^= genMat[(j - 1) * numCols + pos];
264 }
265 pos++;
266 }
267 }
268
269 public int resetToNextPoint() {
270 // Contains the bits of i that changed.
271 if (curPointIndex + 1 >= numPoints)
272 return ++curPointIndex;
273 int diff = curPointIndex ^ (curPointIndex + 1);
274 int pos = 0; // Position of the bit that is examined.
275 while ((diff >> pos) != 0) {
276 if (((diff >> pos) & 1) != 0) {
277 cachedCurPoint[0] ^= 1 << (outDigits - numCols + pos);
278 for (int j = 1; j <= dim; j++)
279 cachedCurPoint[j] ^= genMat[(j - 1) * numCols + pos];
280 }
281 pos++;
282 }
283 curCoordIndex = 0;
284 return ++curPointIndex;
285 }
286 }
287}
void resetCurPointIndex()
Resets both the current point index and the current coordinate to 0.
A special case of DigitalNet for the base .
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 in base.
PointSetIterator iteratorShiftNoGray()
This iterator shifts all coordinates of each point one position to the right and sets the first coord...
DigitalNetBase2 toNet()
Transforms this digital sequence into a digital net without changing the coordinates of the points.
PointSetIterator iteratorShift()
Similar to iterator, except that the first coordinate of the points is , the second coordinate is obt...
DigitalNetBase2 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.
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...