public class HaltonSequenceGenerator extends java.lang.Object implements RandomVectorGenerator
A Halton sequence is a low-discrepancy sequence generating points in the interval [0, 1] according to
H(n) = d_0 / b + d_1 / b^2 .... d_j / b^j+1 with n = d_j * b^j-1 + ... d_1 * b + d_0 * b^0For higher dimensions, subsequent prime numbers are used as base, e.g. { 2, 3, 5 } for a Halton sequence in R^3.
Halton sequences are known to suffer from linear correlation for larger prime numbers, thus the individual digits are usually scrambled. This implementation already comes with support for up to 40 dimensions with optimal weight numbers from H. Chi: Scrambled quasirandom sequences and their applications.
The generator supports two modes:
nextVector()
skipTo(int)
Modifier and Type | Field and Description |
---|---|
private int[] |
base
The base numbers for each component.
|
private int |
count
The current index in the sequence.
|
private int |
dimension
Space dimension.
|
private static int[] |
PRIMES
The first 40 primes.
|
private int[] |
weight
The scrambling weights for each component.
|
private static int[] |
WEIGHTS
The optimal weights used for scrambling of the first 40 dimension.
|
Constructor and Description |
---|
HaltonSequenceGenerator(int dimension)
Construct a new Halton sequence generator for the given space dimension.
|
HaltonSequenceGenerator(int dimension,
int[] bases,
int[] weights)
Construct a new Halton sequence generator with the given base numbers and weights for each dimension.
|
Modifier and Type | Method and Description |
---|---|
int |
getNextIndex()
Returns the index i of the next point in the Halton sequence that will be returned
by calling
nextVector() . |
double[] |
nextVector()
Generate a random vector.
|
protected int |
scramble(int i,
int j,
int b,
int digit)
Performs scrambling of digit
d_j according to the formula: |
double[] |
skipTo(int index)
Skip to the i-th point in the Halton sequence.
|
private static final int[] PRIMES
private static final int[] WEIGHTS
private final int dimension
private int count
private final int[] base
private final int[] weight
public HaltonSequenceGenerator(int dimension) throws OutOfRangeException
dimension
- the space dimensionOutOfRangeException
- if the space dimension is outside the allowed range of [1, 40]public HaltonSequenceGenerator(int dimension, int[] bases, int[] weights) throws NullArgumentException, OutOfRangeException, DimensionMismatchException
dimension
- the space dimensionbases
- the base number for each dimension, entries should be (pairwise) prime, may not be nullweights
- the weights used during scrambling, may be null in which case no scrambling will be performedNullArgumentException
- if base is nullOutOfRangeException
- if the space dimension is outside the range [1, len], where
len refers to the length of the bases arrayDimensionMismatchException
- if weights is non-null and the length of the input arrays differpublic double[] nextVector()
nextVector
in interface RandomVectorGenerator
protected int scramble(int i, int j, int b, int digit)
d_j
according to the formula:
( weight_i * d_j ) mod baseImplementations can override this method to do a different scrambling.
i
- the dimension indexj
- the digit indexb
- the base for this dimensiondigit
- the j-th digitpublic double[] skipTo(int index) throws NotPositiveException
This operation can be performed in O(1).
index
- the index in the sequence to skip toNotPositiveException
- if index < 0public int getNextIndex()
nextVector()
.