sequince.steps.mutation.base#
Attributes#
Classes#
Base class for mutations that optionally operate in transformed space. |
Functions#
|
|
|
|
|
Module Contents#
- sequince.steps.mutation.base.LogProbFn#
- sequince.steps.mutation.base.PARTICLE_TRANSFORM_KEY = 'particle_transform'#
- sequince.steps.mutation.base.TransformRefit#
- sequince.steps.mutation.base.call_log_prob(fn, position, context)[source]#
- Parameters:
fn (LogProbFn)
position (sequince.typing.Array)
context (sequince.steps.context.StepContext)
- Return type:
Any
- sequince.steps.mutation.base.as_scalar_log_prob(value)[source]#
- Parameters:
value (Any)
- Return type:
- sequince.steps.mutation.base.as_vector_log_prob(value, length)[source]#
- Parameters:
value (Any)
length (int)
- Return type:
- class sequince.steps.mutation.base.MutationStep(log_prob_fn, *, transform=None, transform_refit='always', store_chains=False, metrics=())[source]#
Bases:
sequince.steps.base.SMCStepBase class for mutations that optionally operate in transformed space.
transform_refitcontrols whether a cloned transform is fitted for every mutation call, once per outerStepContext, or only once for the lifetime of this mutation step. A callable can instead request fits based on the particles and context. It is evaluated once per mutation application, including the initial fit, and may consume or reset a trigger stored in the context.- Parameters:
log_prob_fn (Callable[..., sequince.typing.Array | float] | sequince.target.Target)
transform (sequince.transforms.ParticleTransform | None)
transform_refit (TransformRefit)
store_chains (bool)
metrics (tuple[sequince.steps.mutation.metrics.MutationMetric, ...] | list[sequince.steps.mutation.metrics.MutationMetric])
- metrics#
- abstractmethod apply_with_mutation_state(state, context, rng, *, n_steps, mutation_state=None)[source]#
Run transitions within a block without finalizing metrics.
Pass
mutation_state=Noneto initialize a new block; otherwise pass the state returned by the preceding call. The state holds individual metric states and cumulative acceptance bookkeeping. It must belong to the same metric configuration and mutation coordinate space.Returns
(state, context, output, mutation_state). The output’s metrics remain unset, including on the first and zero-step calls. Concrete mutations prepare existing metrics on entry, update state for each transition, and return it explicitly without calling metric.result(). Runtime state must never be stored on the mutation object.Use
applyorapply_with_n_stepsfor a complete standalone block. RepeatedMutationStep uses this method to continue across rounds and finalizes metrics once after the complete block.- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.context.StepContext)
rng (Any)
n_steps (int)
mutation_state (sequince.steps.mutation.metrics.MutationStepState | None)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.context.StepContext, Any, sequince.steps.mutation.metrics.MutationStepState | None]
- apply_with_n_steps(state, context, rng, *, n_steps)[source]#
Run a complete fixed-length block and finalize its configured metrics.
- property store_chains: bool#
Whether full mutation chains are included in step outputs.
- Return type:
- load_state_dict(state)[source]#
Restore the transform cache; legacy empty state clears the cache.
- Parameters:
state (collections.abc.Mapping[str, Any])
- Return type:
None
- initialize_functional_state_and_context(state, context)[source]#
Initialize cached target data and functional transform state.
- Parameters:
state (sequince.state.ParticleState)
context (sequince.steps.context.StepContext)
- Return type:
tuple[sequince.state.ParticleState, sequince.steps.context.StepContext]