Liking cljdoc? Tell your friends :D

org.replikativ.foerster.smc

Sequential Monte Carlo as a savepoint handler.

The program runs once in a session. The first savepoint it reaches is forked into N worlds, one per particle; every sample site is decided by the scoring policy of foerster.trace and recorded in its world's trace; every observe is scored and then PARKED — its savepoint left pending. When every particle is parked or has returned, the population is resampled (when its ESS is below the threshold, folding the log mean weight into the evidence): the parked savepoints of the chosen ancestors are forked into the next generation's worlds, the old ones are abandoned, and the new ones resume. A particle that returned early is carried along with its final weight. No coordinator, no barrier thread: the barrier is the arrival of the last particle.

Worlds are forks of savepoints, so particles are frozen, coherent worlds (see docs/forking.md) and inherit whatever world state the program holds.

Sequential Monte Carlo as a savepoint handler.

The program runs once in a session. The first savepoint it reaches is
forked into N worlds, one per particle; every sample site is decided by
the scoring policy of `foerster.trace` and recorded in its world's trace;
every observe is scored and then PARKED — its savepoint left pending. When
every particle is parked or has returned, the population is resampled
(when its ESS is below the threshold, folding the log mean weight into the
evidence): the parked savepoints of the chosen ancestors are forked into
the next generation's worlds, the old ones are abandoned, and the new ones
resume. A particle that returned early is carried along with its final
weight. No coordinator, no barrier thread: the barrier is the arrival of
the last particle.

Worlds are forks of savepoints, so particles are frozen, coherent worlds
(see docs/forking.md) and inherit whatever world state the program holds.
raw docstring

pgasclj/s

(pgas model n iterations & [opts])

Particle Gibbs with ancestor sampling (Lindsten et al. 2014): pgibbs whose retained particle redraws its ancestor at every barrier. Improves mixing where plain particle Gibbs degenerates; costs a replay of the retained future per parked particle per barrier.

Particle Gibbs with ancestor sampling (Lindsten et al. 2014): `pgibbs`
whose retained particle redraws its ancestor at every barrier. Improves
mixing where plain particle Gibbs degenerates; costs a replay of the
retained future per parked particle per barrier.
sourceraw docstring

pgibbsclj/s

(pgibbs model n iterations & [opts])

Particle Gibbs (Andrieu et al. 2010) as iterated conditional SMC: each sweep keeps the trajectory drawn from the previous one, and every sweep's particles are pooled, normalized per sweep. opts as for smc.

Particle Gibbs (Andrieu et al. 2010) as iterated conditional SMC: each
sweep keeps the trajectory drawn from the previous one, and every sweep's
particles are pooled, normalized per sweep. `opts` as for `smc`.
sourceraw docstring

pimhclj/s

(pimh model n iterations & [opts])

Particle independent Metropolis-Hastings: each iteration proposes a fresh SMC sweep and accepts it on the ratio of evidence estimates; the current sweep's particles, normalized, are emitted every iteration. opts as for smc.

Particle independent Metropolis-Hastings: each iteration proposes a fresh
SMC sweep and accepts it on the ratio of evidence estimates; the current
sweep's particles, normalized, are emitted every iteration. `opts` as for
`smc`.
sourceraw docstring

retained-choicesclj/s

(retained-choices trace)

{address value} of the unobserved sample sites of trace (a Sample's): the :retained of a conditional sweep that keeps that trajectory.

{address value} of the unobserved sample sites of `trace` (a Sample's):
the `:retained` of a conditional sweep that keeps that trajectory.
sourceraw docstring

smcclj/s

(smc model n & [opts])

Run model (a spin) with n particles. Options: :resample-threshold (ESS fraction, default 0.5), :policy (an foerster.trace/policy, default the prior with no options), :executor for the root world, :root a world to run in instead of a fresh one, :copy? true to make particles by copying worlds (effects.savepoint/copy: a world holding a system that may not be copied is refused, each copy gets an even share of its world's budget; the root must be a world of the session's :scope), and session options (effects.savepoint/open!).

:retained {address value} makes it CONDITIONAL SMC (particle Gibbs): particle 0 follows those choices, every barrier resamples, and particle 0 keeps its own lineage while the other n−1 draw their ancestors. With :ancestor-sampling? true particle 0 instead redraws its ancestor at every barrier, ∝ w_i · p(retained future | particle i's past), the future scored by replaying each particle in a fork on the retained values (PGAS).

Resample-move: :anchors keeps an anchor at latent sites — :all, {:lag L} (those of the last L barriers), a set of addresses, or a predicate of the savepoint — and :rejuvenate {:moves m :propose p} makes every particle take m Metropolis-Hastings moves after each resampling, each replaying from an anchor up to the particle's current barrier (p a proposal as for foerster.trace/mh-step, default the prior). The moves leave the target up to that barrier invariant, so the weights and the evidence estimate are unchanged. Not in copied worlds or with :retained. The measure's :rejuvenation counts :moves, :accepted and :max-anchors, the most anchors alive at a barrier.

SMCP3 (Lew et al. 2023): :smcp3 {:forward K :backward L} gives every particle parked at a barrier a move-reweight step before the resampling decision. (K choices trace) — the particle's foerster.trace/choices and its partial trace — returns {:updates {address value} :log-q lq :reverse u' :log-jacobian lj}: new values for some latent sites (earlier ones included, so K may revise the past), the log density of K's own random choices, the auxiliary value the backward kernel would draw to go back, and an optional log |Jacobian| for a deterministic continuous map. (L choices' u') is the log density of that reverse draw given the new choices. The particle is replayed from the earliest updated site (it needs an anchor there, :anchors) to its barrier, and its weight multiplied by p(x')·L(u'|x') / (p(x)·K(u|x)) · |J|. K draws from foerster.random (it runs in the particle's stream). Sites K does not update are kept, and those the replay reaches afresh are drawn from their prior, as in a move.

:resampling is :systematic (default), :stratified, :residual or :multinomial (measure/resample). The measure's :history has a map per barrier: :ess before resampling, :resampled?, :log-mean-weight (the barrier's factor of the evidence) and, with :genealogy? true, the :ancestors each slot was resampled from.

Resolves an EmpiricalMeasure of Samples (result + trace) whose log-marginal is the SMC evidence estimate. A model with stream sites runs with stream instead.

Run `model` (a spin) with `n` particles. Options: `:resample-threshold`
(ESS fraction, default 0.5), `:policy` (an `foerster.trace/policy`,
default the prior with no options), `:executor` for the root world,
`:root` a world to run in instead of a fresh one, `:copy? true` to make
particles by copying worlds (`effects.savepoint/copy`: a world holding a
system that may not be copied is refused, each copy gets an even share of
its world's budget; the root must be a world of the session's `:scope`),
and session options (`effects.savepoint/open!`).

`:retained` {address value} makes it CONDITIONAL SMC (particle Gibbs):
particle 0 follows those choices, every barrier resamples, and particle 0
keeps its own lineage while the other n−1 draw their ancestors. With
`:ancestor-sampling? true` particle 0 instead redraws its ancestor at every
barrier, ∝ w_i · p(retained future | particle i's past), the future scored
by replaying each particle in a fork on the retained values (PGAS).

Resample-move: `:anchors` keeps an anchor at latent sites — `:all`,
`{:lag L}` (those of the last L barriers), a set of addresses, or a
predicate of the savepoint — and `:rejuvenate {:moves m :propose p}` makes
every particle take m Metropolis-Hastings moves after each resampling,
each replaying from an anchor up to the particle's current barrier (`p` a
proposal as for `foerster.trace/mh-step`, default the prior). The moves
leave the target up to that barrier invariant, so the weights and the
evidence estimate are unchanged. Not in copied worlds or with
`:retained`. The measure's `:rejuvenation` counts `:moves`, `:accepted`
and `:max-anchors`, the most anchors alive at a barrier.

SMCP3 (Lew et al. 2023): `:smcp3 {:forward K :backward L}` gives every
particle parked at a barrier a move-reweight step before the resampling
decision. `(K choices trace)` — the particle's `foerster.trace/choices` and
its partial trace — returns `{:updates {address value} :log-q lq :reverse
u' :log-jacobian lj}`: new values for some latent sites (earlier ones
included, so K may revise the past), the log density of K's own random
choices, the auxiliary value the backward kernel would draw to go back, and
an optional log |Jacobian| for a deterministic continuous map. `(L choices'
u')` is the log density of that reverse draw given the new choices. The
particle is replayed from the earliest updated site (it needs an anchor
there, `:anchors`) to its barrier, and its weight multiplied by
p(x')·L(u'|x') / (p(x)·K(u|x)) · |J|. K draws from `foerster.random` (it
runs in the particle's stream). Sites K does not update are kept, and those
the replay reaches afresh are drawn from their prior, as in a move.

`:resampling` is `:systematic` (default), `:stratified`, `:residual` or
`:multinomial` (`measure/resample`). The measure's `:history` has a map per
barrier: `:ess` before resampling, `:resampled?`, `:log-mean-weight` (the
barrier's factor of the evidence) and, with `:genealogy? true`, the
`:ancestors` each slot was resampled from.

Resolves an `EmpiricalMeasure` of `Sample`s (result + trace) whose
`log-marginal` is the SMC evidence estimate. A model with stream sites
runs with `stream` instead.
sourceraw docstring

start-siteclj/s

The site of a savepoint a program publishes before anything else when each particle must run it from its start: a program whose effects are random without a sample site (a model call, a tool) must not share its prefix. Otherwise the prefix up to the first random choice runs once and is forked.

The site of a savepoint a program publishes before anything else when each
particle must run it from its start: a program whose effects are random
without a sample site (a model call, a tool) must not share its prefix.
Otherwise the prefix up to the first random choice runs once and is
forked.
sourceraw docstring

streamclj/s

(stream model n & [opts])

Online SMC: model marks the sites whose values arrive from outside as stream sites — (sample (normal x 1) :id [:y t] :stream true) — and particles run until each waits at its next one. Resolves a step

{:measure the posterior over the trajectories so far :push (fn [y]) -> CPS resolving the next step, after every particle scored y at its stream site, the population was resampled as needed, and each ran on to its next stream site (or returned) :done? true once every particle has returned (no :push then) :fork (fn []) -> CPS resolving the step of an independent copy of the population: every waiting particle's world is forked, and the copy is pushed, resampled and closed on its own (absent with :anchors, :retained or copied worlds) :close (fn []) giving the worlds back}

Each push costs the particles' work up to their next stream site; nothing already seen is re-run. opts as for smc.

Online SMC: `model` marks the sites whose values arrive from outside as
stream sites — `(sample (normal x 1) :id [:y t] :stream true)` — and
particles run until each waits at its next one. Resolves a step

  {:measure  the posterior over the trajectories so far
   :push     (fn [y]) -> CPS resolving the next step, after every particle
             scored y at its stream site, the population was resampled as
             needed, and each ran on to its next stream site (or returned)
   :done?    true once every particle has returned (no :push then)
   :fork     (fn []) -> CPS resolving the step of an independent copy of
             the population: every waiting particle's world is forked, and
             the copy is pushed, resampled and closed on its own (absent
             with `:anchors`, `:retained` or copied worlds)
   :close    (fn []) giving the worlds back}

Each push costs the particles' work up to their next stream site; nothing
already seen is re-run. `opts` as for `smc`.
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