A model whose structure is static given its data, compiled to plain functions of its latent values, and inference on them without worlds, savepoints or continuations.
compile-model reads the model's instance graph (analysis/instance):
every site with a concrete address, a distribution written over constants
and the latent sites before it, and no site whose existence depends on a
value. It returns its latent addresses, a log density of a double array
of their values (the sum of every site's log density, as a run of the
model would score it) and a draw from the prior. rmh runs :rmh's
moves (one latent drawn uniformly, a Gaussian step of :step-size) on
that density: each move evaluates the density once, as Gen's dynamic MH
re-runs its program once, but as compiled code.
A model that does not qualify is refused with the reasons, so a caller can fall back to the general path.
A model whose structure is static given its data, compiled to plain functions of its latent values, and inference on them without worlds, savepoints or continuations. `compile-model` reads the model's instance graph (`analysis/instance`): every site with a concrete address, a distribution written over constants and the latent sites before it, and no site whose existence depends on a value. It returns its latent addresses, a log density of a double array of their values (the sum of every site's log density, as a run of the model would score it) and a draw from the prior. `rmh` runs `:rmh`'s moves (one latent drawn uniformly, a Gaussian step of `:step-size`) on that density: each move evaluates the density once, as Gen's dynamic MH re-runs its program once, but as compiled code. A model that does not qualify is refused with the reasons, so a caller can fall back to the general path.
(compile-model model & args)The model applied to args compiled: {:addresses [a …] :log-density
(fn [^doubles x]) :draw (fn [] ^doubles x)}, latent values in the order of
:addresses. Throws ::not-static with the refusals when it cannot be.
The model applied to `args` compiled: {:addresses [a …] :log-density
(fn [^doubles x]) :draw (fn [] ^doubles x)}, latent values in the order of
:addresses. Throws ::not-static with the `refusals` when it cannot be.(refusals {:keys [sites unknown result]})Why the instance graph g cannot be compiled: a vector of reasons, empty
when it can.
Why the instance graph `g` cannot be compiled: a vector of reasons, empty when it can.
(rmh {:keys [addresses log-density draw result]}
{:keys [iterations burn step-size chains seed]
:or {burn 0 chains 4 step-size 0.1}})Random-walk MH on a compiled model (compile-model), as foerster.core's
:rmh: :chains chains (default 4) of :iterations moves, each moving
one latent drawn uniformly by a Gaussian step of :step-size (default
0.1); every state after the first :burn moves is kept. Each chain draws
from a stream of its own, seeded from :seed (else from the process
generator, in order), and the chains run in parallel. Resolves, as a CPS
operation, an EmpiricalMeasure of the model's results with :chain-lengths;
a sample's trace holds its latent values only.
Random-walk MH on a compiled model (`compile-model`), as `foerster.core`'s `:rmh`: `:chains` chains (default 4) of `:iterations` moves, each moving one latent drawn uniformly by a Gaussian step of `:step-size` (default 0.1); every state after the first `:burn` moves is kept. Each chain draws from a stream of its own, seeded from `:seed` (else from the process generator, in order), and the chains run in parallel. Resolves, as a CPS operation, an EmpiricalMeasure of the model's results with `:chain-lengths`; a sample's trace holds its latent values only.
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 |