SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NiedSequenceBase2.java
1/*
2 * Class: NiedSequenceBase2
3 * Description: digital Niederreiter sequences in base 2.
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 java.io.Serializable;
28import java.io.ObjectInputStream;
29import java.io.InputStream;
30import java.io.FileNotFoundException;
31import java.io.IOException;
32import umontreal.ssj.util.PrintfFormat;
33
43
44 private static final int MAXDIM = 318; // Maximum dimension.
45 private static final int NUMCOLS = 30; // Maximum number of columns.
46
58 public NiedSequenceBase2(int k, int w, int dim) {
59 init(k, w, w, dim);
60 }
61
62 public String toString() {
63 StringBuffer sb = new StringBuffer("Niederreiter sequence in base 2" + PrintfFormat.NEWLINE);
64 sb.append(super.toString());
65 return sb.toString();
66 }
67
68 private void init(int k, int r, int w, int dim) {
69 if ((dim < 1) || (dim > MAXDIM))
70 throw new IllegalArgumentException("Dimension for NiedSequenceBase2 must be > 1 and <= " + MAXDIM);
71 if (r < k || w < r || w > MAXBITS || k >= MAXBITS)
72 throw new IllegalArgumentException("One must have k < 31 and k <= r <= w <= 31 for NiedSequenceBase2");
73 numCols = k;
74 numRows = r; // Unused!
75 outDigits = w;
76 numPoints = (1 << k);
77 this.dim = dim;
78 normFactor = 1.0 / ((double) (1L << (outDigits)));
79 genMat = new int[dim * numCols];
80 initGenMat();
81 }
82
83 public void extendSequence(int k) {
84 init(k, numRows, outDigits, dim);
85 }
86
87 // Initializes the generator matrices for a sequence.
88 /*
89 * I multiply by 2 because the relevant columns are in the 30 least significant
90 * bits of NiedMat, but if I understand correctly, SSJ assumes that they are in
91 * bits [31, ..., 1]. Then I shift right if w < 31.
92 */
93 private void initGenMat() {
94 for (int j = 0; j < dim; j++)
95 for (int c = 0; c < numCols; c++) {
96 genMat[j * numCols + c] = NiedMat[j * NUMCOLS + c] << 1;
97 genMat[j * numCols + c] >>= MAXBITS - outDigits;
98 }
99 }
100
101 /*
102 * // Initializes the generator matrices for a net. protected void
103 * initGenMatNet() { int j, c;
104 *
105 * // the first dimension, j = 0. for (c = 0; c < numCols; c++) genMat[c] = (1
106 * << (outDigits-numCols+c));
107 *
108 * for (j = 1; j < dim; j++) for (c = 0; c < numCols; c++) genMat[j*numCols + c]
109 * = 2 * NiedMat[(j - 1)*NUMCOLS + c]; }
110 */
111
112 // ******************************************************************
113 // Generator matrices of Niederreiter sequence.
114 // This array stores explicitly NUMCOLS columns in 318 dimensions.
115
116 private static int[] NiedMat;
117 private static final int MAXN = 9540;
118
119 static {
120 NiedMat = new int[MAXN];
121
122 try {
123 InputStream is = NiedSequenceBase2.class.getClassLoader()
124 .getResourceAsStream("umontreal/ssj/hups/dataSer/Nieder/NiedSequenceBase2.ser");
125 if (is == null)
126 throw new FileNotFoundException("Cannot find NiedSequenceBase2.ser");
127 ObjectInputStream ois = new ObjectInputStream(is);
128 NiedMat = (int[]) ois.readObject();
129 ois.close();
130
131 } catch (FileNotFoundException e) {
132 e.printStackTrace();
133 System.exit(1);
134
135 } catch (IOException e) {
136 e.printStackTrace();
137 System.exit(1);
138
139 } catch (ClassNotFoundException e) {
140 e.printStackTrace();
141 System.exit(1);
142 }
143 }
144
145}
This abstract class describes methods specific to digital sequences in base.
NiedSequenceBase2(int k, int w, int dim)
Constructs a new digital sequence in base 2 from the first.
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.