public class SobolSequenceGenerator extends java.lang.Object implements RandomVectorGenerator
A Sobol sequence is a low-discrepancy sequence with the property that for all values of N, its subsequence (x1, ... xN) has a low discrepancy. It can be used to generate pseudo-random points in a space S, which are equi-distributed.
The implementation already comes with support for up to 1000 dimensions with direction numbers calculated from Stephen Joe and Frances Kuo.
The generator supports two modes:
nextVector()
skipTo(int)
Modifier and Type | Field and Description |
---|---|
private static int |
BITS
The number of bits to use.
|
private int |
count
The current index in the sequence.
|
private int |
dimension
Space dimension.
|
private long[][] |
direction
The direction vector for each component.
|
private static java.lang.String |
FILE_CHARSET
Character set for file input.
|
private static int |
MAX_DIMENSION
The maximum supported space dimension.
|
private static java.lang.String |
RESOURCE_NAME
The resource containing the direction numbers.
|
private static double |
SCALE
The scaling factor.
|
private long[] |
x
The current state.
|
Constructor and Description |
---|
SobolSequenceGenerator(int dimension)
Construct a new Sobol sequence generator for the given space dimension.
|
SobolSequenceGenerator(int dimension,
java.io.InputStream is)
Construct a new Sobol sequence generator for the given space dimension with
direction vectors loaded from the given stream.
|
Modifier and Type | Method and Description |
---|---|
int |
getNextIndex()
Returns the index i of the next point in the Sobol sequence that will be returned
by calling
nextVector() . |
private void |
initDirectionVector(int d,
int a,
int[] m)
Calculate the direction numbers from the given polynomial.
|
private int |
initFromStream(java.io.InputStream is)
Load the direction vector for each dimension from the given stream.
|
double[] |
nextVector()
Generate a random vector.
|
double[] |
skipTo(int index)
Skip to the i-th point in the Sobol sequence.
|
private static final int BITS
private static final double SCALE
private static final int MAX_DIMENSION
private static final java.lang.String RESOURCE_NAME
private static final java.lang.String FILE_CHARSET
private final int dimension
private int count
private final long[][] direction
private final long[] x
public SobolSequenceGenerator(int dimension) throws OutOfRangeException
dimension
- the space dimensionOutOfRangeException
- if the space dimension is outside the allowed range of [1, 1000]public SobolSequenceGenerator(int dimension, java.io.InputStream is) throws NotStrictlyPositiveException, MathParseException, java.io.IOException
The expected format is identical to the files available from Stephen Joe and Frances Kuo. The first line will be ignored as it is assumed to contain only the column headers. The columns are:
d s a m_i 2 1 0 1 3 2 1 1 3
The input stream must be an ASCII text containing one valid direction vector per line.
dimension
- the space dimensionis
- the stream to read the direction vectors fromNotStrictlyPositiveException
- if the space dimension is < 1OutOfRangeException
- if the space dimension is outside the range [1, max], where
max refers to the maximum dimension found in the input streamMathParseException
- if the content in the stream could not be parsed successfullyjava.io.IOException
- if an error occurs while reading from the input streamprivate int initFromStream(java.io.InputStream is) throws MathParseException, java.io.IOException
The input stream must be an ASCII text containing one valid direction vector per line.
is
- the input stream to read the direction vector fromjava.io.IOException
- if the stream could not be readMathParseException
- if the content could not be parsed successfullyprivate void initDirectionVector(int d, int a, int[] m)
d
- the dimension, zero-baseda
- the coefficients of the primitive polynomialm
- the initial direction numberspublic double[] nextVector()
nextVector
in interface RandomVectorGenerator
public 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()
.