sequince.posterior#
Attributes#
Classes#
Wrapper exposing posterior building blocks for SMC workflows. |
Functions#
|
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.TemperedTargetWrapper 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 whenlog_likelihood_and_proposalis supplied.log_proposal – Optional callable or proposal object returning
log q(x). When supplied the intermediate targets follow the bridgeq(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#
- 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_incrementis included only when the density itself requires it. Other components can still be requested explicitly throughprepare_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
evaluationis omitted, all posterior components are evaluated fromparticles. Supplying a matching evaluation avoids recomputing those components.- Parameters:
particles (sequince.typing.Array)
context (sequince.steps.context.StepContext)
evaluation (sequince.target.TargetEvaluation | None)
- Return type:
float | Any
- log_terminal(particles, context, *, evaluation=None)[source]#
Return the posterior endpoint log density.
When
evaluationis omitted, all posterior components are evaluated fromparticles. Supplying a matching evaluation avoids recomputing those components.- Parameters:
particles (sequince.typing.Array)
context (sequince.steps.context.StepContext)
evaluation (sequince.target.TargetEvaluation | None)
- Return type:
float | Any
- evaluate(particles, context, *, components=None, evaluation=None)[source]#
Evaluate or refresh posterior components for a particle population.
- Parameters:
particles (sequince.typing.Array)
context (sequince.steps.context.StepContext)
components (collections.abc.Collection[str] | None)
evaluation (sequince.target.TargetEvaluation | None)
- Return type:
- freeze_log_prob(context, *, log_proposal_override=None)[source]#
- Parameters:
context (sequince.steps.context.StepContext)
log_proposal_override (LogProposalLike | None)
- 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)
- Return type:
tuple[sequince.state.ParticleState, sequince.result.SMCResult]