Liking cljdoc? Tell your friends :D

org.replikativ.foerster.runtime.gfi

Gen's generative function interface over savepoint traces.

Each operation is spindel.trace/run or replay under a policy of foerster.runtime.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.runtime.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!`.
raw docstring

assessclj/s

(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.
sourceraw docstring

bp__org.replikativ.spindel.effects.await_SLASH_awaitclj

source

bp__org.replikativ.spindel.effects.await_SLASH_await_finalizationclj

source

bp__org.replikativ.spindel.effects.savepoint_SLASH_savepointclj

source

bp__org.replikativ.spindel.effects.track_SLASH_trackclj

source

close!clj/s

(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.
sourceraw docstring

generateclj/s

(generate model constraints)
(generate model constraints {:keys [allow-unvisited?] :as 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.

Every constrained address must be reached by the run; otherwise the run's worlds are closed and the operation rejects with ::unvisited-constraints. :allow-unvisited? true ignores such constraints instead. The other options are those of simulate.

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.

Every constrained address must be reached by the run; otherwise the run's
worlds are closed and the operation rejects with `::unvisited-constraints`.
`:allow-unvisited? true` ignores such constraints instead. The other options
are those of `simulate`.
sourceraw docstring

mhclj/s

(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}.
sourceraw docstring

mh-proposalclj/s

(mh-proposal trace proposal & args)

One Metropolis-Hastings move with a custom proposal: proposal is a function (fn [choices & args]) of the current choices ({address value}) returning a spin whose sample sites are named by the MODEL addresses they propose — any number of them jointly, correlated as the proposal program likes (Gen's metropolis_hastings(trace, proposal, args)).

The proposal runs forward on the current choices (its log density log q(c' | t)), the model is updated with what it proposed (update), and the proposal is assessed on the reverse move, the values it replaced given the new choices (log q(c | t')). Accepted on log α = w(update) + log q(c | t') − log q(c' | t). The proposal must be able to propose the reverse move (it reaches the same addresses from t'). The loser's worlds are given back. Resolves {:trace t :accepted? b}. The proposal's own runs are seeded from the trace's world, so a chain seeded by :seed reproduces its moves.

One Metropolis-Hastings move with a custom proposal: `proposal` is a
function `(fn [choices & args])` of the current choices ({address value})
returning a spin whose sample sites are named by the MODEL addresses they
propose — any number of them jointly, correlated as the proposal program
likes (Gen's `metropolis_hastings(trace, proposal, args)`).

The proposal runs forward on the current choices (its log density
log q(c' | t)), the model is updated with what it proposed (`update`), and
the proposal is assessed on the reverse move, the values it replaced
given the new choices (log q(c | t')). Accepted on
  log α = w(update) + log q(c | t') − log q(c' | t).
The proposal must be able to propose the reverse move (it reaches the same
addresses from t'). The loser's worlds are given back. Resolves
{:trace t :accepted? b}. The proposal's own runs are seeded from the
trace's world, so a chain seeded by `:seed` reproduces its moves.
sourceraw docstring

regenerateclj/s

(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}.
sourceraw docstring

run-policyclj/s

(run-policy model policy)
(run-policy model policy opts)

Run model under any foerster.runtime.trace/policy in a root world and session of its own (options as for simulate). Resolves the trace.

Run `model` under any `foerster.runtime.trace/policy` in a root world and session
of its own (options as for `simulate`). Resolves the trace.
sourceraw docstring

run-policy*clj/s

(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.
sourceraw docstring

simulateclj/s

(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.
sourceraw docstring

updateclj/s

(update trace constraints)
(update trace constraints {:keys [allow-unvisited?]})

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. As in Gen, a kept value is kept even when the change moved it outside its site's support: t' then has density zero and w = −∞. constraints are new values, not new conditioning: a site that was latent stays latent with its new value (so a later move can change it again), and one that was constrained stays constrained. A replay the program aborts resolves with w = −∞ and the program's error under :error.

A constraint on a site trace never reached replays from its first sample site, so the program can get there. A constraint the new run still does not reach is an error (::unvisited-constraints; the replayed worlds are given back) unless :allow-unvisited? true.

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.
As in Gen, a kept value is kept even when the change moved it outside its
site's support: t' then has density zero and w = −∞. `constraints` are new
values, not new conditioning: a site that was latent stays latent with its
new value (so a later move can change it again), and one that was
constrained stays constrained. A replay the program aborts resolves with
w = −∞ and the program's error under `:error`.

A constraint on a site `trace` never reached replays from its first
sample site, so the program can get there. A constraint the new run still
does not reach is an error (`::unvisited-constraints`; the replayed worlds
are given back) unless `:allow-unvisited? true`.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close