sequince.steps.weighting#
Attributes#
Classes#
Apply a complete sequential-target log-weight increment. |
|
Backward-compatible name for callable likelihood increments. |
|
Base class for tempered weighting steps. |
|
Apply tempering by scaling log-weight increments with a beta schedule. |
|
Apply fixed beta increments up to |
|
Adaptively choose the next beta using an ESS-like target. |
Functions#
|
Return a power-law schedule for an evolving target ESS ratio. |
Module Contents#
- sequince.steps.weighting.IncrementFn#
- sequince.steps.weighting.BetaSchedule#
- sequince.steps.weighting.TargetESSRatio#
- sequince.steps.weighting.logger#
- sequince.steps.weighting.evolving_target_ess_ratio(start, end, *, rate=1.0, max_beta=1.0)[source]#
Return a power-law schedule for an evolving target ESS ratio.
The schedule evolves from
starttoendas the beta moves from zero tomax_beta. Betas outside that interval are clipped to the corresponding endpoint. Values ofrategreater than one delay the transition, while values below one accelerate it.- Parameters:
- Return type:
- class sequince.steps.weighting.IncrementalWeighting(log_increment_fn, *, normalize_after=True)[source]#
Bases:
sequince.steps.base.SMCStepApply a complete sequential-target log-weight increment.
A callable can have signature
(particles,)or(particles, context). ASequentialTargetsupplies its current complete increment and participates in evaluation caching.- Parameters:
log_increment_fn (IncrementFn | sequince.target.SequentialTarget)
normalize_after (bool)
- initialize_functional_state_and_context(state, context)[source]#
Attach a cached target evaluation before functional compilation.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext]
- apply(state, context, rng)[source]#
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
rng (orng.RandomGenerator)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, dict[str, Any]]
- class sequince.steps.weighting.LogLikelihoodWeighting(log_increment_fn, *, normalize_after=True)[source]#
Bases:
IncrementalWeightingBackward-compatible name for callable likelihood increments.
- Parameters:
log_increment_fn (IncrementFn | sequince.target.SequentialTarget)
normalize_after (bool)
- class sequince.steps.weighting.BaseTemperedStep(log_increment_fn, *, normalize_after=True, refresh_components=())[source]#
Bases:
sequince.steps.base.SMCStepBase class for tempered weighting steps.
This provides common functionality for tempering steps that apply log-weight increments scaled by a beta schedule (e.g.
TemperedWeightingandAdaptiveTemperedWeighting). It does not implement the logic for determining the beta schedule itself, which is left to subclasses.- Parameters:
log_increment_fn (IncrementFn | sequince.target.TemperedTarget)
normalize_after (bool)
refresh_components (collections.abc.Collection[str])
- initialize_functional_state_and_context(state, context)[source]#
Attach a cached target evaluation before functional compilation.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext]
- evaluate_log_increment(state, context)[source]#
Return increments and attach a missing target evaluation.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
- Return type:
tuple[sequince.typing.Array | float, sequince.state.ParticleState, sequince.steps.base.StepContext]
- initialize_metadata(state, context)[source]#
Initialize metadata related to tempering.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext]
- initialize_functional_metadata(state, metadata)[source]#
Initialize fixed-shape tempering metadata on the array backend.
- Parameters:
state (sequince.state.ParticleState)
metadata (collections.abc.Mapping[str, Any])
- Return type:
collections.abc.Mapping[str, Any]
- class sequince.steps.weighting.TemperedWeighting(log_increment_fn, beta_schedule, *, normalize_after=True, clip_beta=None, refresh_components=())[source]#
Bases:
BaseTemperedStepApply tempering by scaling log-weight increments with a beta schedule.
Both the increment callable and the beta schedule accept the current
StepContextwhen they require it.- Parameters:
log_increment_fn (IncrementFn | sequince.target.TemperedTarget)
beta_schedule (BetaSchedule)
normalize_after (bool)
refresh_components (collections.abc.Collection[str])
- apply(state, context, rng)[source]#
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
rng (orng.RandomGenerator)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, dict[str, Any]]
- class sequince.steps.weighting.FixedTemperedWeighting(log_increment_fn, *, beta_increment, max_beta=1.0, normalize_after=True, refresh_components=())[source]#
Bases:
BaseTemperedStepApply fixed beta increments up to
max_beta(default 1.0).Clip the final increment and request a stop after that iteration. The maximum must be finite and positive.
- Parameters:
log_increment_fn (IncrementFn | sequince.target.TemperedTarget)
beta_increment (float)
max_beta (float)
normalize_after (bool)
refresh_components (collections.abc.Collection[str])
- apply(state, context, rng)[source]#
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
rng (orng.RandomGenerator)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, dict[str, Any]]
- apply_functional(state, context, random_state)[source]#
Apply fixed tempering without host scalar conversions.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
random_state (Any)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, Any, dict[str, Any]]
- class sequince.steps.weighting.AdaptiveTemperedWeighting(log_increment_fn, *, target_ess_ratio=0.7, max_beta=1.0, min_delta=0.0001, max_delta=None, normalize_after=True, max_bisection_iter=30, criterion='ess', refresh_components=())[source]#
Bases:
BaseTemperedStepAdaptively choose the next beta using an ESS-like target.
The beta increment is chosen such that the effective sample size (ESS) ratio after weighting, or the conditional ESS (CESS) ratio implied by a proposed increment, reaches the specified target value (
target_ess_ratio), up to the maximum beta (max_beta). If the maximum beta is reached while advancing the schedule, the SMC run is requested to stop after the current iteration finishes.- Parameters:
log_increment_fn (IncrementFn | sequince.target.TemperedTarget) – A callable or
TemperedTargetproviding log-weight increments.target_ess_ratio (TargetESSRatio) – The target ESS ratio (ESS / n) to achieve after weighting, or a callable that returns the target for the current beta. The callable may optionally also accept the current
StepContext. Each resolved target must be in the interval (0, 1].max_beta (float) – The maximum beta to reach; once this beta is reached, the SMC run is requested to stop after the current iteration.
min_delta (float) – The minimum beta increment to apply at each step.
max_delta (float | None) – Optional maximum beta increment to apply at each step.
normalize_after (bool) – Whether to normalize the particle weights after updating.
max_bisection_iter (int) – The maximum number of bisection iterations to perform when finding the beta increment.
criterion (Literal['ess', 'cess']) – Criterion used when selecting the beta increment.
"ess"targets the ESS ratio after weighting."cess"targets the conditional ESS ratio induced by the proposed incremental weights.refresh_components (collections.abc.Collection[str])
Notes
The returned particle state and current step context record
beta,delta_beta,ess_ratio, andcess_ratio. Active updates also recordtarget_ess_ratio.- initialize_functional_metadata(state, metadata)[source]#
Initialize fixed-shape adaptive tempering metadata.
- Parameters:
state (sequince.state.ParticleState)
metadata (collections.abc.Mapping[str, Any])
- Return type:
collections.abc.Mapping[str, Any]
- apply(state, context, rng)[source]#
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
rng (orng.RandomGenerator)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, dict[str, Any]]
- apply_functional(state, context, random_state)[source]#
Apply adaptive tempering while explicitly threading random state.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.base.StepContext)
random_state (Any)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.base.StepContext, Any, dict[str, Any]]