SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
HaltonSequence.java
1/*
2 * Class: HaltonSequence
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
53public class HaltonSequence extends PointSet {
54 private int[] base; // Vector of prime bases.
55 private int[][] permutation; // Digits permutation, for each dimension.
56 private boolean permuted; // Permute digits?
57 private RadicalInverse[] radinv; // Vector of RadicalInverse's.
58 private int[] start; // starting indices
59 private final static int positiveBitMask = ~Integer.reverse(1);
60
66 public HaltonSequence(int dim) {
67 if (dim < 1)
68 throw new IllegalArgumentException("Halton sequence must have positive dimension dim");
69 this.dim = dim;
70 numPoints = Integer.MAX_VALUE;
72 start = new int[dim];
73 java.util.Arrays.fill(start, 0);
74 }
75
84 public void setStart(double[] x0) {
85 for (int i = 0; i < dim; i++)
86 start[i] = RadicalInverse.radicalInverseInteger(base[i], x0[i]);
87 }
88
95 public void init(double[] x0) {
96 radinv = new RadicalInverse[dim];
97 for (int i = 0; i < dim; i++)
98 radinv[i] = new RadicalInverse(base[i], x0[i]);
99 }
100
110 permutation = new int[dim][];
111 for (int i = 0; i < dim; i++) {
112 permutation[i] = new int[base[i]];
114 }
115 permuted = true;
116 }
117
124 public void addFaurePermutations() {
125 permutation = new int[dim][];
126 for (int i = 0; i < dim; i++) {
127 permutation[i] = new int[base[i]];
128 RadicalInverse.getFaurePermutation(base[i], permutation[i]);
129 }
130 permuted = true;
131 }
132
136 public void ErasePermutations() {
137 permuted = false;
138 permutation = null;
139 }
140
141 public int getNumPoints() {
142 return Integer.MAX_VALUE;
143 }
144
145 public double getCoordinate(int i, int j) {
146 if (radinv != null) {
147 if (!permuted) {
148 return radinv[j].nextRadicalInverse();
149 } else {
150 throw new UnsupportedOperationException("Fast radical inverse is not implemented in case of permutation");
151 }
152 } else {
153 int k = start[j] + i;
154 // if overflow, restart at first nonzero point
155 // (Struckmeier restarts at zero)
156 if (k < 0)
157 k = (k & positiveBitMask) + 1;
158 if (permuted)
159 return RadicalInverse.permutedRadicalInverse(base[j], permutation[j], k);
160 else
161 return RadicalInverse.radicalInverse(base[j], k);
162 }
163 }
164}
void ErasePermutations()
Erases the permutations: from now on, the digits will not be permuted.
int getNumPoints()
Returns the number of points.
HaltonSequence(int dim)
Constructs a new Halton sequence in dim dimensions.
void addFaureLemieuxPermutations()
Permutes the digits using permutations from vfau09a  for all coordinates.
void init(double[] x0)
Initializes the Halton sequence starting at point x0.
double getCoordinate(int i, int j)
Returns , the coordinate of the point .
void addFaurePermutations()
Permutes the digits using Faure permutations for all coordinates.
void setStart(double[] x0)
Initializes the Halton sequence starting at point x0.
This abstract class represents a general point set.
Definition PointSet.java:99
int numPoints
Number of points.
int dim
Dimension of the points.
This class implements basic methods for working with radical inverses of integers in an arbitrary bas...
static double permutedRadicalInverse(int b, int[] pi, long i)
Computes the radical inverse of in base , where the digits are permuted using the permutation .
static double radicalInverse(int b, long i)
Computes the radical inverse of in base .
static void getFaureLemieuxPermutation(int coordinate, int[] pi)
Computes the permutations as proposed in vfau09a .
static void getFaurePermutation(int b, int[] pi)
Computes the Faure permutation rfau92a  of the set and puts it in array pi.
static int radicalInverseInteger(int b, double x)
Computes the radical inverse of in base .
static int[] getPrimes(int n)
Provides an elementary method for obtaining the first prime numbers larger than 1.