Class SobolSequenceGenerator
- All Implemented Interfaces:
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:
- sequential generation of points:
nextVector()
- random access to the i-th point in the sequence:
skipTo(int)
- Since:
- 3.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
The number of bits to use.private int
The current index in the sequence.private final int
Space dimension.private final long[][]
The direction vector for each component.private static final String
Character set for file input.private static final int
The maximum supported space dimension.private static final String
The resource containing the direction numbers.private static final double
The scaling factor.private final long[]
The current state. -
Constructor Summary
ConstructorsConstructorDescriptionSobolSequenceGenerator
(int dimension) Construct a new Sobol sequence generator for the given space dimension.SobolSequenceGenerator
(int dimension, InputStream is) Construct a new Sobol sequence generator for the given space dimension with direction vectors loaded from the given stream. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the index i of the next point in the Sobol sequence that will be returned by callingnextVector()
.private void
initDirectionVector
(int d, int a, int[] m) Calculate the direction numbers from the given polynomial.private int
Load the direction vector for each dimension from the given stream.double[]
Generate a random vector.double[]
skipTo
(int index) Skip to the i-th point in the Sobol sequence.
-
Field Details
-
BITS
private static final int BITSThe number of bits to use.- See Also:
-
SCALE
private static final double SCALEThe scaling factor. -
MAX_DIMENSION
private static final int MAX_DIMENSIONThe maximum supported space dimension.- See Also:
-
RESOURCE_NAME
The resource containing the direction numbers.- See Also:
-
FILE_CHARSET
Character set for file input.- See Also:
-
dimension
private final int dimensionSpace dimension. -
count
private int countThe current index in the sequence. -
direction
private final long[][] directionThe direction vector for each component. -
x
private final long[] xThe current state.
-
-
Constructor Details
-
SobolSequenceGenerator
Construct a new Sobol sequence generator for the given space dimension.- Parameters:
dimension
- the space dimension- Throws:
OutOfRangeException
- if the space dimension is outside the allowed range of [1, 1000]
-
SobolSequenceGenerator
public SobolSequenceGenerator(int dimension, InputStream is) throws NotStrictlyPositiveException, MathParseException, IOException Construct a new Sobol sequence generator for the given space dimension with direction vectors loaded from the given stream.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: the dimension
- s: the degree of the primitive polynomial
- a: the number representing the coefficients
- m: the list of initial direction numbers
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.
- Parameters:
dimension
- the space dimensionis
- the stream to read the direction vectors from- Throws:
NotStrictlyPositiveException
- 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 successfullyIOException
- if an error occurs while reading from the input stream
-
-
Method Details
-
initFromStream
Load the direction vector for each dimension from the given stream.The input stream must be an ASCII text containing one valid direction vector per line.
- Parameters:
is
- the input stream to read the direction vector from- Returns:
- the last dimension that has been read from the input stream
- Throws:
IOException
- if the stream could not be readMathParseException
- if the content could not be parsed successfully
-
initDirectionVector
private void initDirectionVector(int d, int a, int[] m) Calculate the direction numbers from the given polynomial.- Parameters:
d
- the dimension, zero-baseda
- the coefficients of the primitive polynomialm
- the initial direction numbers
-
nextVector
public double[] nextVector()Generate a random vector.- Specified by:
nextVector
in interfaceRandomVectorGenerator
- Returns:
- a random vector as an array of double.
-
skipTo
Skip to the i-th point in the Sobol sequence.This operation can be performed in O(1).
- Parameters:
index
- the index in the sequence to skip to- Returns:
- the i-th point in the Sobol sequence
- Throws:
NotPositiveException
- if index < 0
-
getNextIndex
public int getNextIndex()Returns the index i of the next point in the Sobol sequence that will be returned by callingnextVector()
.- Returns:
- the index of the next point
-