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.(crp-draw name alpha & {:keys [id]})Seat a customer in the Chinese restaurant process name with
concentration alpha > 0: a spin resolving the table index, an existing
table k with probability ∝ its customers, a new table (index = the number
of tables) ∝ α. :id names the sample site.
Seat a customer in the Chinese restaurant process `name` with concentration `alpha` > 0: a spin resolving the table index, an existing table k with probability ∝ its customers, a new table (index = the number of tables) ∝ α. `:id` names the sample site.
(crp-tables name)The customers at each table of the process name in the current world:
a vector, table k at index k.
The customers at each table of the process `name` in the current world: a vector, table k at index k.
(mem f)f (a function returning a spin or a value) memoized per world: each
argument list is computed once in a particle, and particles forked later
share what was computed before the fork. Returns a function of the same
arguments returning a spin.
`f` (a function returning a spin or a value) memoized per world: each argument list is computed once in a particle, and particles forked later share what was computed before the fork. Returns a function of the same arguments returning a spin.
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 |