SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NiedXingSequenceBase2.java
1/*
2 * Class: NiedXingSequenceBase2
3 * Description: Niederreiter-Xing 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 = 32; // Maximum dimension.
45 private static final int NUMCOLS = 30; // Maximum number of columns.
46 private static final boolean isTrans = true;
47
62 public NiedXingSequenceBase2(int k, int w, int dim) {
63 init(k, w, w, dim);
64 }
65
66 public String toString() {
67 StringBuffer sb = new StringBuffer("Niederreiter-Xing sequence:" + PrintfFormat.NEWLINE);
68 sb.append(super.toString());
69 return sb.toString();
70 }
71
72 private void init(int k, int r, int w, int dim) {
73 if ((dim < 1) || (dim > MAXDIM))
74 throw new IllegalArgumentException("Dimension for NiedXingSequenceBase2 must be > 1 and <= " + MAXDIM);
75 if (r < k || w < r || w > MAXBITS || k >= MAXBITS)
76 throw new IllegalArgumentException("One must have k < 31 and k <= r <= w <= 31 for NiedXingSequenceBase2");
77 numCols = k;
78 numRows = r;
79 outDigits = w;
80 numPoints = (1 << k);
81 this.dim = dim;
82 // 1L otherwise gives wrong results for outDigits >= 31
83 normFactor = 1.0 / ((double) (1L << (outDigits)));
84 genMat = new int[dim * numCols];
85 initGenMat();
86 }
87
88 public void extendSequence(int k) {
89 init(k, numRows, outDigits, dim);
90 }
91
92 // Initializes the generator matrices for a sequence.
93 private void initGenMat() {
94 // Compute where we should start reading matrices.
95 /*
96 * Pirsic gives matrices starting at dimension 4; there are j matrices of
97 * dimension j. Thus if we want to use matrices in dimension dim, we must jump
98 * over all matrices of dimension < dim. If they started at dimension 1, there
99 * would be dim*(dim-1)/2 elements to disregard. But the first 3 dimensions are
100 * not there, thus subtract 3*(3 - 1)/2 = 6 to get the starting element of
101 * dimension dim. I also multiply by 2 because the relevant columns are in the
102 * 30 least significant bits of NiedXingMat, but if I understand correctly, SSJ
103 * assumes that they are in bits [31, ..., 1]. At last, I shift right if w < 31
104 * bits.
105 */
106
107 int start;
108 if (dim <= 4)
109 start = 0;
110 else
111 start = ((dim * (dim - 1) / 2) - 6) * NUMCOLS;
112
113 long x;
114 if (isTrans) {
115 for (int j = 0; j < dim; j++)
116 for (int c = 0; c < numCols; c++) {
117 x = NiedXingMatTrans[start + j * NUMCOLS + c];
118 x <<= 1;
119 genMat[j * numCols + c] = (int) (x >> (MAXBITS - outDigits));
120 }
121 } else {
122 for (int j = 0; j < dim; j++)
123 for (int c = 0; c < numCols; c++) {
124 x = NiedXingMat[start + j * NUMCOLS + c];
125 x <<= 1;
126 genMat[j * numCols + c] = (int) (x >> (MAXBITS - outDigits));
127 }
128 }
129 }
130
131 // ******************************************************************
132 // Generator matrices of Niederreite-Xing sequences.
133 // This array stores explicitly NUMCOLS columns in MAXDIM dimensions.
134 // The implemented generator matrices are provided by Gottlieb Pirsic
135 // and were downloaded on 15 July 2004. (RS)
136 // These are the numbers given by Pirsic: I kept the first 30 of each
137 // row vector in each dimension and shifted them to get the 30 most
138 // significant bits. These numbers considered as 30 X 30 bit matrices
139 // are given in matrix NiedXingMat below. The same numbers but transposed
140 // as 30 X 30 bit matrices are given in matrix NiedXingMatTrans below.
141 // According to Yves Edel, the correct matrices for Niederreiter-Xing
142 // are NiedXingMatTrans.
143 //
144 // The matrices were given up to MAXDIM = 32, but the javac compiler
145 // cannot compile code that is too big. So I serialized them in
146 // file NiedXingSequenceBase2.ser. (RS)
147
148 private static int[] NiedXingMat;
149 private static int[] NiedXingMatTrans;
150 private static final int MAXN = 15660;
151
152 static {
153// NiedXingMat = new int[MAXN];
154 NiedXingMatTrans = new int[MAXN];
155
156 try {
157 /*
158 * InputStream is =
159 * NiedXingSequenceBase2.class.getClassLoader().getResourceAsStream (
160 * "umontreal/ssj/hups/dataSer/Nieder/NiedXingSequenceBase2.ser"); if (is ==
161 * null) throw new FileNotFoundException (
162 * "Cannot find NiedXingSequenceBase2.ser"); ObjectInputStream ois = new
163 * ObjectInputStream(is); NiedXingMat = (int[]) ois.readObject(); ois.close();
164 */
165 InputStream is = NiedXingSequenceBase2.class.getClassLoader()
166 .getResourceAsStream("umontreal/ssj/hups/dataSer/Nieder/NiedXingSequenceBase2Trans.ser");
167 if (is == null)
168 throw new FileNotFoundException("Cannot find NiedXingSequenceBase2Trans.ser");
169 ObjectInputStream ois = new ObjectInputStream(is);
170 NiedXingMatTrans = (int[]) ois.readObject();
171 ois.close();
172
173 } catch (FileNotFoundException e) {
174 e.printStackTrace();
175 System.exit(1);
176
177 } catch (IOException e) {
178 e.printStackTrace();
179 System.exit(1);
180
181 } catch (ClassNotFoundException e) {
182 e.printStackTrace();
183 System.exit(1);
184 }
185 }
186}
This abstract class describes methods specific to digital sequences in base.
String toString()
Formats a string that contains information on this digital net.
NiedXingSequenceBase2(int k, int w, int dim)
Constructs a new Niederreiter-Xing digital sequence in base 2 with.
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.