Skip to content

_lds

Korobov / R_d (a.k.a. KGF) low-discrepancy sequence in pure numpy.

Generates the additive recurrence x_n = (offset + n * alpha) mod 1 with alpha_i = (1/g)^(i+1) and g the unique positive root of g^(D+1) = g + 1 (see https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/).

quasirandom_kgf(N, D)

Return the Nth KGF point (1-indexed) in D dimensions.

Source code in chmpy/sampling/_lds.py
def quasirandom_kgf(N: int, D: int) -> np.ndarray:
    """Return the ``N``th KGF point (1-indexed) in ``D`` dimensions."""
    a = _alpha(D)
    return (_OFFSET + a * (N + 1)) % 1.0

quasirandom_kgf_batch(L, U, D)

Return KGF points for the inclusive seed range [L, U].

Source code in chmpy/sampling/_lds.py
def quasirandom_kgf_batch(L: int, U: int, D: int) -> np.ndarray:
    """Return KGF points for the inclusive seed range ``[L, U]``."""
    a = _alpha(D)
    n = np.arange(L, U + 1, dtype=np.float64)
    return (_OFFSET + a[np.newaxis, :] * (n[:, np.newaxis] + 1.0)) % 1.0