LatinHypercubeSampler

class LatinHypercubeSampler(model, **kwargs)[source]

Bases: OneshotSampler

Sampler using Latin Hypercube Sampling (LHS).

LHS is a stratified sampling method that generates sample points that are more evenly distributed across the hypercube than standard random sampling. This implementation uses scipy.stats.qmc.LatinHypercube.

Parameters:

model (Model)

generate(N, d, key=None, **kwargs)[source]

Generate samples using Latin Hypercube Sampling.

Parameters:
  • N (int) – Number of samples.

  • D (int) – Dimensionality (number of parameters).

  • key (jnp.ndarray) – The JAX key,

  • d (int)

Returns:

Samples in the unit hypercube [0, 1)^D.

Return type:

jnp.ndarray

cdf(theta)

Evaluate the cumulative distribution function (CDF) for the model parameters.

This computes the probability \(P(X \leq \theta)\) and lazily compiles the evaluation graph using jax.jit on the first call.

Parameters:

theta (jax.numpy.ndarray) – The parameter values to evaluate.

Returns:

The evaluated CDF probabilities, bounded between \(0\) and \(1\).

Return type:

jax.numpy.ndarray

execute(*, N=100, batch_size=1, key=None, **kwargs)

Generate and evaluate a batch of points in one execution.

Parameters:
  • N (int, default=100) – The total number of samples to generate and simulate.

  • batch_size (int, default=1) – The number of points to simulate in each iteration.

  • **kwargs – Additional arguments passed to the generate() method.

Returns:

A tuple containing the evaluated physical parameters and a placeholder for backend results.

Return type:

tuple[jax.numpy.ndarray, None]

expensive: bool = False
icdf(u)

Evaluate the inverse cumulative distribution function (ICDF), or quantile function.

This computes \(\theta = F^{-1}(u)\) and lazily compiles the evaluation graph using jax.jit on the first call.

Parameters:

u (jax.numpy.ndarray) – The probability values to evaluate, typically uniformly distributed between \(0\) and \(1\).

Returns:

The corresponding parameter values \(\theta\).

Return type:

jax.numpy.ndarray

log_prior(theta)

Evaluate the log-prior probability \(\log P(\theta)\) of the model parameters.

The prior is calculated by summing the log-probabilities of the flat parameter vector. The JAX graph is lazily compiled on the first call.

Parameters:

theta (jax.numpy.ndarray) – The parameter values to evaluate.

Returns:

The scalar log-prior probability.

Return type:

float or jax.numpy.ndarray

model_features(theta)

Extract the RF features from the model for a given set of parameters.

This function maps the parameters into the model, simulates it over the defined frequency band, and extracts the target specifications. The entire extraction pipeline is vectorized over the batch dimension and lazily compiled via jax.jit(jax.vmap(...)).

Parameters:

theta (jax.numpy.ndarray) – A 1D array of a single parameter set, or a 2D array representing a batch of parameters.

Returns:

The extracted model features. Matches the batch dimension of theta.

Return type:

jax.numpy.ndarray

Raises:

RuntimeError – If frequency or features were not provided during initialization.

static read_results(stream)

Reconstruct backend optimization or sampling results from a bytes stream.

Parameters:

stream (BytesIO) – The open byte stream to read from.

Returns:

The deserialized Python objects.

Return type:

Any

run(*, plot=None, output_path=None, load_previous=False, save_results=True, save_figures=True, **kwargs)

Execute the sampling process.

This method handles plotting setup, optional recovery from previous runs, delegates the core algorithm to the subclass’s sample() method, and packages the final results.

Parameters:
  • plot (str or list[str], optional) – Specific features to plot live during the sampling loop and save as PNG images.

  • output_path (str, optional) – The directory where results, numpy crash-checkpoints, and figures should be saved.

  • load_previous (bool, default=False) – If True and output_path is provided, it will attempt to load and return an existing sample_results.hdf5 file instead of re-running the sampling.

  • save_results (bool, default=True) – Whether to save the final SampleResults object to an HDF5 file.

  • save_figures (bool, default=True) – Whether to save the generated plots to disk.

  • **kwargs – Additional arguments passed directly to the subclass’s sample() method.

Returns:

The comprehensive results object containing the evaluated parameters and their corresponding extracted features.

Return type:

SampleResults

update(theta)

Evaluate new parameters and update the internal sampling state.

This function is central to active learning and iterative sampling backends. It extracts the features for the provided parameters, appends the data to the internal tracking arrays, updates any configured live plots, and (if expensive=True) automatically saves intermediate crash-recovery checkpoints to disk using native NumPy serialization.

Parameters:

theta (jax.numpy.ndarray) – A 1D array of a single parameter set, or a 2D array representing a batch of parameters to simulate.

Return type:

None

static write_results(stream, results)

Encode backend optimization or sampling results into a bytes stream.

Parameters:
  • stream (BytesIO) – The open byte stream to write to.

  • results (Any) – The data structure containing the backend results.

Notes

The default implementation uses jsonpickle for robust, research-grade serialization of complex Python objects.

sampled_params: Array | None
sampled_features: Array | None
feature_plotters: list[LivePlotter]