replay

Contents

replay#

hybrid_aif.replay.replay(
system,
params,
observations,
actions,
*,
present=None,
valid=None,
legal=None,
priors=None,
key=None,
externals=None,
metrics=True,
learn=False,
lr=1.0,
prior=None,
support_floor=-27.631021115928547,
lr_by_slot=None,
)[source]#

Drive (system, params) through a recorded trace (design: replay.md R1–R7).

observations maps each modality name to a (T, …) array, as System.infer_states() takes them plus a time axis; actions maps each action node’s name (System.names.actions) to its (T, …) column, as System.act() returns them plus a time axis; each clamps its control node at its tick (the efference copy). present maps a modality to a (T,) bool, whether it was observed at each tick (a modality left out was observed at every tick; None: all were; an unknown key raises); valid is (T,) bool, the non-padding rows (an invalid tick leaves the carry untouched, its outputs unspecified). legal is the per-tick constraint in infer_policies’ spellings with a leading time axis, applied to chosen and action_log_prob: keyed by control node, each entry (T, levels) or (T, H, levels) (a node left out is unrestricted), or a (T, P) bool array over the policy set. priors seeds the first tick, keyed by state factor (None: the initial priors). key drives a stochastic planner and is split per tick; selection is deterministic. externals supplies external:<name> recognition inputs as (T, width) arrays. learn=True runs System.learn() between perception and action from the second tick and returns the final params (and LearnState for gradient slots); a modality absent at a tick (present, or a padded tick) teaches its likelihood slot nothing there; on the amortized path System.learn raises (train with fit_world). prior is the model’s prior params, which a scheduled reduction (System.reduction_period) scores its merges against and returns a killed level to; None takes params, right when the replay starts from the prior and wrong when params were already learned. lr is the learning rate: a nonzero Python number is passed to the compiled scan as a float32 array, so a schedule of rates compiles once, and a Python 0.0 is static (it skips learning at trace time). lr_by_slot is System.learn()’s per-slot rates, passed to every tick’s learn step as given (a Python 0.0 freezes a slot at trace time; {"transition:z:noise": 1.0} learns one factor’s process noise alone, with lr=0.0 for the rest). metrics=False drops the per-tick term trees. On the amortized path the belief half is the per-tick faces (infer_states, update_empirical_prior).

observations is keyed by variable (System.infer_states()). A modality that observes an emission or an action node of the System (System.observes) may leave its variable out of observations, or give None: its datum is then the value of the previous tick, the emission realised from that tick’s posterior and recorded in Replay.emitted (a draw by sample takes a key folded from the tick’s key, which every sampled emission needs; the kernel of an emission that has one lives in params.emission) or that tick’s recorded action, and the modality is absent at the first tick. A datum the trace supplies wins.