aspire.samplers.smc.minipcn#
Classes#
MiniPCN SMC sampler. |
Module Contents#
- class aspire.samplers.smc.minipcn.MiniPCNSMC(log_likelihood, log_prior, dims, prior_flow, xp, dtype=None, parameters=None, rng=None, preconditioning_transform=None)[source]#
Bases:
aspire.samplers.smc.base.SMCSamplerMiniPCN SMC sampler.
- Parameters:
log_likelihood (Callable)
log_prior (Callable)
dims (int)
prior_flow (aspire.flows.base.Flow)
xp (Callable)
dtype (Any | str | None)
parameters (list[str] | None)
rng (array_api_compat.numpy.random.Generator | orng.ArrayRNG | None)
preconditioning_transform (Callable | None)
- log_prob(x, beta=None)[source]#
Compute the log probability of the samples.
Input samples are in the transformed space.
- Parameters:
beta (float | None)
- Return type:
Any
- sample(n_samples, n_steps=None, min_beta_step=None, max_beta_step=None, max_n_steps=None, adaptive=True, target_efficiency=0.5, target_efficiency_rate=1.0, n_final_samples=None, sampler_kwargs=None, rng=None, checkpoint_callback=None, checkpoint_every=None, checkpoint_file_path=None, resume_from=None, beta_tolerance=1e-06, store_sample_history=True)[source]#
Sample using the SMC sampler.
- Parameters:
n_samples (
int) – The number of samples (particles) to use in the SMC sampler.n_steps (
int, optional) – The number of SMC iterations to perform. Must be specified ifadaptive=False. Default is None.adaptive (
bool, optional) – Whether to adaptively determine the beta schedule. Default is True.min_beta_step (
float, optional) – The minimum beta step size when using adaptive beta. Default is None, which means no minimum step size.max_beta_step (
float, optional) – The maximum beta step size when using adaptive beta. Default is None, which means no maximum step size.max_n_steps (
int, optional) – The maximum number of SMC iterations to perform when using adaptive beta. Default is None, which means no maximum.target_efficiency (
floatortuple, optional) – The target sample efficiency (ESS / n_samples) to aim for at each SMC iteration. Can be a single float in (0, 1) or a tuple of two floats specifying a range to adapt between. Default is 0.5.target_efficiency_rate (
float, optional) – When using a tuple for target_efficiency, this controls the rate at which the target efficiency adapts from the first value to the second value as beta increases. Default is 1.0 (linear adaptation).n_final_samples (
int, optional) – If specified, the number of final samples to produce after the SMC iterations. If not specified, the number of final samples will be the same as n_samples. Default is None.checkpoint_callback (
callable, optional) – A callback function to call with a checkpoint dictionary at regular intervals during sampling. Default is None (no checkpointing).checkpoint_every (
int, optional) – The number of iterations between checkpoints when using checkpoint callback. Default is None, which means no regular checkpointing.checkpoint_file_path (
str, optional) – If using checkpoint_callback, this can be used to specify a file path to save checkpoints to. Default is None.resume_from (
str,bytes, ordict, optional) – If specified, this can be used to resume sampling from a previous checkpoint. Can be a file path, bytes object, or checkpoint dictionary. Default is None (start from scratch).store_sample_history (
bool, optional) – Whether to store the history of samples at each iteration inself.history.sample_history. Default is True.beta_tolerance (
float, optional) – Tolerance for determining convergence of beta when using adaptive beta. Default is given byDEFAULT_BETA_TOLERANCE.sampler_kwargs (dict | None)
rng (numpy.random.Generator | None)
- Returns:
final_samples – The final samples after running the SMC sampler, with log evidence and log evidence error estimates.
- Return type:
SMCSamples- Raises:
ValueError – If both n_steps is None and adaptive is False, or if target_efficiency is not in (0, 1) when a float, or if target_efficiency tuple is not valid, or if log probabilities contain NaN values.
- mutate(particles, beta, n_steps=None)[source]#
Mutate particles using the MiniPCN sampler.
- Parameters:
particles (
SMCSamples) – The current particles to be mutated.beta (
float) – The current inverse temperature.n_steps (
int, optional) – The number of MCMC steps to take. If None, uses the default fromsampler_kwargs.
- Returns:
The mutated particles.
- Return type:
SMCSamples