Gen's generative function interface over savepoint traces.
Each operation is spindel.trace/run or replay under a policy of
foerster.trace; what this namespace adds is the weight each operation
returns and the discard of update, with Gen's identities (Cusumano-Towner
et al. 2019, q the model's internal proposal, here the prior):
generate(c) w = log p(t) − log q(t; c) = Σ log p of constrained and observed sites assess(choices) w = log p(choices) = the log joint update(t, c) w = log p(t') − log p(t) − log q(fresh choices of t') regenerate(t, s) w = log p(t')/p(t) + log q(t | t')/q(t' | t)
so importance sampling is generate, and MH with a selection is
regenerate accepted on its weight. A model is a spin whose sample sites
are named with :id (or addressed structurally, see addressing/site-address!);
constraints are keyed by those addresses.
Every operation returns a CPS operation (fn [resolve reject]).
simulate, generate and assess run in a root world and savepoint session
of their own (a session runs one computation, and a world hosts one
session); the worlds live until close!.
update and regenerate replay inside the session of the trace they are
given and leave that trace intact: the caller keeps one of the two and gives
the other back with spindel.trace/release!.
Gen's generative function interface over savepoint traces. Each operation is `spindel.trace/run` or `replay` under a policy of `foerster.trace`; what this namespace adds is the weight each operation returns and the discard of `update`, with Gen's identities (Cusumano-Towner et al. 2019, q the model's internal proposal, here the prior): generate(c) w = log p(t) − log q(t; c) = Σ log p of constrained and observed sites assess(choices) w = log p(choices) = the log joint update(t, c) w = log p(t') − log p(t) − log q(fresh choices of t') regenerate(t, s) w = log p(t')/p(t) + log q(t | t')/q(t' | t) so importance sampling is `generate`, and MH with a selection is `regenerate` accepted on its weight. A model is a spin whose sample sites are named with `:id` (or addressed structurally, see `addressing/site-address!`); constraints are keyed by those addresses. Every operation returns a CPS operation `(fn [resolve reject])`. `simulate`, `generate` and `assess` run in a root world and savepoint session of their own (a session runs one computation, and a world hosts one session); the worlds live until `close!`. `update` and `regenerate` replay inside the session of the trace they are given and leave that trace intact: the caller keeps one of the two and gives the other back with `spindel.trace/release!`.
(assess model choices)(assess model choices opts)log p of choices ({address value}), which must fix every sample site the
run reaches. Resolves {:weight w :result r}; the run's session is closed.
log p of `choices` ({address value}), which must fix every sample site the
run reaches. Resolves {:weight w :result r}; the run's session is closed.(close! trace)Give back every world of trace's session: the trace and every trace
replayed from it. Returns a CPS operation.
Give back every world of `trace`'s session: the trace and every trace replayed from it. Returns a CPS operation.
(generate model constraints)(generate model constraints opts)Run model with the sample sites in constraints ({address value}) fixed.
Resolves {:trace t :weight w}, w = Σ log p of the constrained and observed
sites: an importance weight for the prior as proposal.
Run `model` with the sample sites in `constraints` ({address value}) fixed.
Resolves {:trace t :weight w}, w = Σ log p of the constrained and observed
sites: an importance weight for the prior as proposal.(mh trace selection)One Metropolis-Hastings move: regenerate the selection and accept on its
weight. The loser's worlds are given back. Resolves {:trace t :accepted? b}.
One Metropolis-Hastings move: `regenerate` the selection and accept on its
weight. The loser's worlds are given back. Resolves {:trace t :accepted? b}.(regenerate trace selection)Draw the selected sample sites afresh from their priors and run the
computation again from the earliest of them, keeping every other site.
selection is a set of addresses or a selector (spindel.select).
Resolves {:trace t' :weight w}, w = the Metropolis-Hastings log ratio of the move without a site-selection term: accepting on it is MH with this (fixed) selection. Nothing selected resolves {:trace trace :weight 0.0}.
Draw the selected sample sites afresh from their priors and run the
computation again from the earliest of them, keeping every other site.
`selection` is a set of addresses or a selector (`spindel.select`).
Resolves {:trace t' :weight w}, w = the Metropolis-Hastings log ratio of
the move without a site-selection term: accepting on it is MH with this
(fixed) selection. Nothing selected resolves {:trace trace :weight 0.0}.(run-policy model policy)(run-policy model policy opts)Run model under any foerster.trace/policy in a root world and session
of its own (options as for simulate). Resolves the trace.
Run `model` under any `foerster.trace/policy` in a root world and session of its own (options as for `simulate`). Resolves the trace.
(run-policy* model policy)(run-policy* model policy opts)As run-policy, but returns {:session s :operation op}: the session is
known before the run ends, for a caller that must close it whatever
happens to others.
As `run-policy`, but returns {:session s :operation op}: the session is
known before the run ends, for a caller that must close it whatever
happens to others.(simulate model)(simulate model opts)Run model (a spin) drawing every sample site from its prior. Resolves the
trace. Options as for run: :executor and session options.
Run `model` (a spin) drawing every sample site from its prior. Resolves the trace. Options as for `run`: `:executor` and session options.
(update trace constraints)Change the sample sites in constraints ({address value}) and run the
computation again from the earliest of them; every other site keeps its
value, rescored under its distribution as it is now, and a site the
changed control flow reaches for the first time is drawn from its prior.
Resolves {:trace t' :weight w :discard d} where
w = log p(t') − log p(t) − Σ log q of what t' drew afresh
d = {address value} of the choices of t that t' does not keep: the
overwritten values of constrained sites, and the sites no longer
reached.
A constraint on a site trace never reached replays from its first
sample site, so the program can get there.
Change the sample sites in `constraints` ({address value}) and run the
computation again from the earliest of them; every other site keeps its
value, rescored under its distribution as it is now, and a site the
changed control flow reaches for the first time is drawn from its prior.
Resolves {:trace t' :weight w :discard d} where
w = log p(t') − log p(t) − Σ log q of what t' drew afresh
d = {address value} of the choices of t that t' does not keep: the
overwritten values of constrained sites, and the sites no longer
reached.
A constraint on a site `trace` never reached replays from its first
sample site, so the program can get there.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |