Top Description Fields Constructors Methods
org.apache.commons.math3.random

public Class HaltonSequenceGenerator

extends Object
implements RandomVectorGenerator
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.random.RandomVectorGenerator
Imports
org.apache.commons.math3.exception.DimensionMismatchException, .NotPositiveException, .NullArgumentException, .OutOfRangeException, org.apache.commons.math3.util.MathUtils

Implementation of a Halton sequence.

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^0
For 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:

Since
3.3
See Also
Halton sequence (Wikipedia), On the Halton sequence and its scramblings

Field Summary

Modifier and TypeField and Description
private final int[]
base

The base numbers for each component.

private int
count

The current index in the sequence.

private final int
dimension

Space dimension.

private static final int[]
PRIMES

The first 40 primes.

private final int[]
weight

The scrambling weights for each component.

private static final int[]
WEIGHTS

The optimal weights used for scrambling of the first 40 dimension.

Constructor Summary

AccessConstructor and Description
public
HaltonSequenceGenerator(final int
the space dimension
dimension
)

Construct a new Halton sequence generator for the given space dimension.

public
HaltonSequenceGenerator(final int
the space dimension
dimension
,
final int[]
the base number for each dimension, entries should be (pairwise) prime, may not be null
bases
,
final int[]
the weights used during scrambling, may be null in which case no scrambling will be performed
weights
)

Construct a new Halton sequence generator with the given base numbers and weights for each dimension.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the index of the next point
getNextIndex
()

Returns the index i of the next point in the Halton sequence that will be returned by calling nextVector().

public double[]
protected int

Returns:

the scrambled digit
scramble
(final int
the dimension index
i
,
final int
the digit index
j
,
final int
the base for this dimension
b
,
final int
the j-th digit
digit
)

Performs scrambling of digit d_j according to the formula:

  ( weight_i * d_j ) mod base
public double[]

Returns:

the i-th point in the Halton sequence
skipTo
(final int
the index in the sequence to skip to
index
)

Skip to the i-th point in the Halton sequence.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseback to summary
private final int[] base

The base numbers for each component.

countback to summary
private int count

The current index in the sequence.

dimensionback to summary
private final int dimension

Space dimension.

PRIMESback to summary
private static final int[] PRIMES

The first 40 primes.

weightback to summary
private final int[] weight

The scrambling weights for each component.

WEIGHTSback to summary
private static final int[] WEIGHTS

The optimal weights used for scrambling of the first 40 dimension.

Constructor Detail

HaltonSequenceGeneratorback to summary
public HaltonSequenceGenerator(final int dimension) throws OutOfRangeException

Construct a new Halton sequence generator for the given space dimension.

Parameters
dimension:int

the space dimension

Exceptions
OutOfRangeException:
if the space dimension is outside the allowed range of [1, 40]
HaltonSequenceGeneratorback to summary
public HaltonSequenceGenerator(final int dimension, final int[] bases, final int[] weights) throws NullArgumentException, OutOfRangeException, DimensionMismatchException

Construct a new Halton sequence generator with the given base numbers and weights for each dimension. The length of the bases array defines the space dimension and is required to be > 0.

Parameters
dimension:int

the space dimension

bases:int[]

the base number for each dimension, entries should be (pairwise) prime, may not be null

weights:int[]

the weights used during scrambling, may be null in which case no scrambling will be performed

Exceptions
NullArgumentException:
if base is null
OutOfRangeException:
if the space dimension is outside the range [1, len], where len refers to the length of the bases array
DimensionMismatchException:
if weights is non-null and the length of the input arrays differ

Method Detail

getNextIndexback to summary
public int getNextIndex()

Returns the index i of the next point in the Halton sequence that will be returned by calling nextVector().

Returns:int

the index of the next point

nextVectorback to summary
public double[] nextVector()

Implements org.apache.commons.math3.random.RandomVectorGenerator.nextVector.

Doc from org.apache.commons.math3.random.RandomVectorGenerator.nextVector.

Generate a random vector.

Returns:double[]

a random vector as an array of double.

scrambleback to summary
protected int scramble(final int i, final int j, final int b, final int digit)

Performs scrambling of digit d_j according to the formula:

  ( weight_i * d_j ) mod base
Implementations can override this method to do a different scrambling.
Parameters
i:int

the dimension index

j:int

the digit index

b:int

the base for this dimension

digit:int

the j-th digit

Returns:int

the scrambled digit

skipToback to summary
public double[] skipTo(final int index) throws NotPositiveException

Skip to the i-th point in the Halton sequence.

This operation can be performed in O(1).

Parameters
index:int

the index in the sequence to skip to

Returns:double[]

the i-th point in the Halton sequence

Exceptions
NotPositiveException:
if index < 0