sequince.posterior#

Attributes#

Classes#

TemperedPosterior

Wrapper exposing posterior building blocks for SMC workflows.

Functions#

draw_additional_samples(*[, log_prior, ...])

Draw additional samples from the current particles to fill up to n_particles.

Module Contents#

sequince.posterior.LogProposalLike#
sequince.posterior.JointLogDensityFn#
class sequince.posterior.TemperedPosterior[source]#

Bases: sequince.target.TemperedTarget

Wrapper exposing posterior building blocks for SMC workflows.

Parameters:
  • log_prior – Callable returning log p(x) for each particle.

  • log_likelihood – Callable returning log l(x) for each particle. May be omitted when log_likelihood_and_proposal is supplied.

  • log_proposal – Optional callable or proposal object returning log q(x). When supplied the intermediate targets follow the bridge q(x)^{1-β} [p(x)L(x)]^{β}.

  • log_proposal_override_key – Context metadata key containing a runtime proposal override.

  • log_likelihood_and_proposal – Alternative to separate likelihood and proposal inputs: a callable returning (log l(x), log q(x)) from shared computation. Accepts particles and optionally context. Requesting either component evaluates and caches both. A runtime proposal override takes precedence over the returned proposal; refreshing only that override skips the joint call.

  • log_density_ratio – Optional direct terminal-to-initial log-density ratio for weighting. Accepts particles and optionally context. When supplied, weighting skips full density preparation; MCMC still evaluates the posterior normally. The callback must account for any runtime proposal override itself.

log_prior: sequince.target.TargetComponentFn#
log_likelihood: sequince.target.TargetComponentFn | None = None#
log_proposal: LogProposalLike | None = None#
log_proposal_override_key: str = 'log_proposal_override'#
log_likelihood_and_proposal: JointLogDensityFn | None = None#
log_density_ratio: sequince.target.TargetComponentFn | None = None#
evaluation_components(context)[source]#

Components needed for a full density evaluation, when known.

These are the components used to compute log_prob, such as during MCMC. They need not include every component the target supports: log_increment is included only when the density itself requires it. Other components can still be requested explicitly through prepare_evaluation(components=...).

When components=None, preparation uses this declaration to complete a partial cache and retain only these components. Returning None preserves the default full-evaluation contract for custom targets.

log_increment(particles, context, *, evaluation=None)[source]#

Return the terminal-to-initial log-density ratio.

log_prob(particles, context, *, evaluation=None)[source]#

Return the interpolated log density at the current beta.

resolve_log_proposal(log_proposal_override=None)[source]#

Return the effective proposal callable for the current evaluation.

Parameters:

log_proposal_override (LogProposalLike | None)

Return type:

sequince.target.TargetComponentFn | None

log_initial(particles, context, *, evaluation=None)[source]#

Return the proposal or prior endpoint log density.

When evaluation is omitted, all posterior components are evaluated from particles. Supplying a matching evaluation avoids recomputing those components.

Parameters:
Return type:

float | Any

log_terminal(particles, context, *, evaluation=None)[source]#

Return the posterior endpoint log density.

When evaluation is omitted, all posterior components are evaluated from particles. Supplying a matching evaluation avoids recomputing those components.

Parameters:
Return type:

float | Any

evaluate(particles, context, *, components=None, evaluation=None)[source]#

Evaluate or refresh posterior components for a particle population.

Parameters:
Return type:

sequince.target.TargetEvaluation

freeze_log_prob(context, *, log_proposal_override=None)[source]#
Parameters:
sequince.posterior.draw_additional_samples(*, log_prior=None, log_likelihood=None, log_proposal=None, posterior=None, result, rng, n_particles, mutation='minipcn', mutation_n_steps=10, mutation_kwargs=None, particle_transform='affine', particle_transform_kwargs=None)[source]#

Draw additional samples from the current particles to fill up to n_particles.

Parameters:
  • log_prior (Callable[..., Any] | None) – Callable evaluating the log prior density log p(x). If posterior is not provided, both log_prior and log_likelihood must be given.

  • log_likelihood (Callable[..., Any] | None) – Callable evaluating the log likelihood log l(x). If posterior is not provided, both log_prior and log_likelihood must be given.

  • log_proposal (Callable[..., Any] | sequince.proposals.ProposalDistribution | None) – Optional callable or proposal object for log q(x) when importance sampling proposals are used.

  • posterior (TemperedPosterior | None) – TemperedPosterior object defining the target distribution.

  • state – Current ParticleState containing particles and weights.

  • context – StepContext providing shared information such as beta.

  • rng (orng.RandomGenerator) – Random number generator.

  • n_particles (int) – Desired total number of particles after drawing additional samples.

  • mutation (sequince.typing.MutationStrategy | None) – Mutation strategy to apply to the new particles.

  • mutation_n_steps (int) – Number of mutation steps to apply if mutation is used.

  • mutation_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the mutation step.

  • particle_transform (sequince.transforms.ParticleTransform | str | None) – ParticleTransform instance or string identifier for the transform to use during mutation. If None, no transform is applied.

  • result (sequince.result.SMCResult)

  • particle_transform_kwargs (dict[str, Any] | None)

Return type:

tuple[sequince.state.ParticleState, sequince.result.SMCResult]