Liking cljdoc? Tell your friends :D

org.replikativ.foerster.model.conjugate

Conjugate parameters, carried as posteriors instead of sampled.

A static parameter of a conjugate pair need never be drawn: the program holds its posterior as a value, scores each datum under the posterior predictive and updates the posterior in closed form —

(loop [c (conjugate/beta-bernoulli 1 1) remaining (seq ys)] (if remaining (let [y (first remaining)] (observe (conjugate/predictive c) y) (recur (conjugate/update c y) (next remaining))) (sample (conjugate/posterior c) :id :p))) ; the parameter, if needed

— which is exact marginalization (Rao-Blackwellization; the conjugate case of delayed sampling, Murray et al. 2018). Under SMC the parameter cannot degenerate, since it is never resampled, and a streaming program pays the same for it at every step. Every operation is a plain function of plain values, so it composes with any foerster program and inference method.

Families: normal-mean (Normal mean with known observation sd), beta-bernoulli, gamma-poisson (Gamma shape and SCALE, as foerster.dist/gamma) and dirichlet-discrete.

Conjugate parameters, carried as posteriors instead of sampled.

A static parameter of a conjugate pair need never be drawn: the program
holds its posterior as a value, scores each datum under the posterior
predictive and updates the posterior in closed form —

  (loop [c (conjugate/beta-bernoulli 1 1) remaining (seq ys)]
    (if remaining
      (let [y (first remaining)]
        (observe (conjugate/predictive c) y)
        (recur (conjugate/update c y) (next remaining)))
      (sample (conjugate/posterior c) :id :p)))   ; the parameter, if needed

— which is exact marginalization (Rao-Blackwellization; the conjugate case
of delayed sampling, Murray et al. 2018). Under SMC the parameter cannot
degenerate, since it is never resampled, and a streaming program pays the
same for it at every step. Every operation is a plain function of plain
values, so it composes with any foerster program and inference method.

Families: `normal-mean` (Normal mean with known observation sd),
`beta-bernoulli`, `gamma-poisson` (Gamma shape and SCALE, as
`foerster.dist/gamma`) and `dirichlet-discrete`.
raw docstring

org.replikativ.foerster.model.mechanism

Sample sites as structural equations x = f(u), u exogenous noise.

A distribution is read as a mechanism: noise draws u, push computes the value from it, abduct goes back from a value to its noise. For an invertible mechanism (location-scale, inverse CDF of a continuous law) abduction is exact. For a discrete one, many u give the same value, and abduct draws u from its posterior given the value — here under the inverse-CDF convention x = F⁻¹(u), u ~ U(0,1), under which that posterior is uniform on the value's CDF interval. Which convention a discrete site uses changes counterfactual answers and cannot be told from data, so it is fixed here and documented rather than guessed.

Parameters come from the distribution at the site, so replaying a site with its old u under new parents is the counterfactual value.

Sample sites as structural equations x = f(u), u exogenous noise.

A distribution is read as a mechanism: `noise` draws u, `push` computes the
value from it, `abduct` goes back from a value to its noise. For an
invertible mechanism (location-scale, inverse CDF of a continuous law)
abduction is exact. For a discrete one, many u give the same value, and
`abduct` draws u from its posterior given the value — here under the
inverse-CDF convention x = F⁻¹(u), u ~ U(0,1), under which that posterior is
uniform on the value's CDF interval. Which convention a discrete site uses
changes counterfactual answers and cannot be told from data, so it is fixed
here and documented rather than guessed.

Parameters come from the distribution at the site, so replaying a site with
its old u under new parents is the counterfactual value.
raw docstring

org.replikativ.foerster.model.process

Memoization and random processes whose state lives in the particle's world, so it forks with the particle and is discarded with it — Anglican's mem and its Chinese restaurant process, on spindel worlds.

mem turns a spin-returning function into one that computes each argument list once per world: the first call samples, later calls (in the same particle, and in every particle forked after it) return that value. Nonparametric models are written with it, as a stick per index or a mean per cluster:

(let [mean-of (process/mem (fn [k] (spin (sample (dist/normal 0 10) :id [:mean k]))))] (spin … (await (mean-of 3)) …))

Name the sample sites inside a memoized function by its arguments, as above: a value is drawn once, at the first call.

crp-draw seats a customer in a Chinese restaurant process: table k with probability ∝ its customers, a new table ∝ α. The tables live in the world under the process's name; the draw is an ordinary sample site over the existing tables and a new one, so every method — exact enumeration included — handles it.

Memoization and random processes whose state lives in the particle's
world, so it forks with the particle and is discarded with it — Anglican's
`mem` and its Chinese restaurant process, on spindel worlds.

`mem` turns a spin-returning function into one that computes each
argument list once per world: the first call samples, later calls (in the
same particle, and in every particle forked after it) return that value.
Nonparametric models are written with it, as a stick per index or a
mean per cluster:

  (let [mean-of (process/mem (fn [k] (spin (sample (dist/normal 0 10) :id [:mean k]))))]
    (spin … (await (mean-of 3)) …))

Name the sample sites inside a memoized function by its arguments, as
above: a value is drawn once, at the first call.

`crp-draw` seats a customer in a Chinese restaurant process: table k with
probability ∝ its customers, a new table ∝ α. The tables live in the world
under the process's name; the draw is an ordinary sample site over the
existing tables and a new one, so every method — exact enumeration
included — handles it.
raw 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