activelearning.sampler.hypercube_sampler

Classes

HypercubeSampler

Generates candidates by sampling from a bounded hypercube.

Module Contents

class activelearning.sampler.hypercube_sampler.HypercubeSampler(
bounds: Sequence[tuple[float, float]],
num_samples: int,
fidelities: Sequence[int] | dict[int, float] = (DEFAULT_FIDELITY,),
point_strategy: Literal['uniform', 'lhs'] = 'uniform',
)[source]

Bases: activelearning.sampler.sampler.Sampler

Generates candidates by sampling from a bounded hypercube.

This sampler is purely generative: every sample() call draws a new batch of points inside bounds. It supports both point-generation strategy selection and optional fidelity assignment.

  • Point generation: "uniform" for i.i.d. random draws or "lhs" for Latin hypercube sampling.

  • Fidelity assignment: controlled by the type of fidelities.

Parameters:
  • bounds (Sequence[tuple[float, float]]) – Per-dimension (lower, upper) bounds. Each pair must satisfy lower < upper. The length determines input dimensionality.

  • num_samples (int) – Number of candidates to generate per sample() call. Must be > 0.

  • fidelities (Sequence[int] or dict[int, float]) –

    Controls fidelity assignment for each candidate:

    • [DEFAULT_FIDELITY] — the default single-fidelity configuration.

    • [1, 2, 3] — uniform sampling across fidelity levels.

    • {1: 1.0, 2: 5.0} — cost-inverse sampling: each key is a fidelity level and each value is its cost. Candidates are assigned fidelities with probability inversely proportional to cost (cheaper fidelities are sampled more often). All costs must be positive.

  • point_strategy (Literal["uniform", "lhs"]) – How x-values are generated within the hypercube. “uniform” draws i.i.d. uniform samples; “lhs” uses Latin Hypercube Sampling for better space coverage. Defaults to “uniform”.

Raises:

ValueError – If bounds are empty or invalid, num_samples <= 0, or point_strategy is unrecognised.

bounds
num_samples
point_strategy = 'uniform'
sample(
acquisition: Acquisition | None = None,
observations: Iterable[Observation] | None = None,
cost_fn: Callable[[Sequence[Candidate]], list[float]] | None = None,
) → list[Candidate][source]

Generate candidates from the hypercube.

Parameters:
  • acquisition (Optional[Acquisition]) – Unused. Present for interface compatibility. Passing a non-None value raises a UserWarning.

  • observations (Optional[Iterable[Observation]]) – Unused. Present for interface compatibility. Passing a non-None value raises a UserWarning.

  • cost_fn (Optional[Callable[[Sequence[Candidate]], list[float]]]) – Unused. Present for interface compatibility. Passing a non-None value raises a UserWarning.

Returns:

result – num_samples candidates with x as a plain Python list of floats and fidelity drawn from the configured fidelity strategy.

Return type:

list[Candidate]