The structure of a model, read from its source: which sites it has, what each one reads, and the facts an inference plan can be derived from.
analyze walks the macro-expanded body of a model (a spin form, or the
forms inside one) and returns its site graph:
{:sites {n {:kind :latent | :observed | :factor :address [:y i] ; the :id form, symbols are loop variables; ; [:loc line col] for a site without :id :dist {:ctor normal :args [{:form mu :reads #{0} :exact 0} …]} :reads #{0} ; sites its distribution's arguments read :control #{} ; sites that decide whether it runs :loops [2]}} ; enclosing loops, innermost last :loops {2 {:bindings [i] :sites #{1} :carried #{} :kind :plate | :sequential}} ; :carried: its sites a later iteration reads :unknown [{:reason :closure :form …}]}
A site's value reads the sites its arguments were computed from: the
analysis follows locals through let, loop, if and calls, over-approximating
a call's result as reading everything its arguments read. A loop whose
recurring values read none of its own sites runs independent iterations (a
plate); otherwise it is sequential. What the walk cannot see — a site in a
closure, which the spin macro cannot see either — is listed under
:unknown, never guessed.
facts derives from the graph: the support of each site, finite latent
sites, plates, conjugate pairs (foerster.conjugate's families, in the form
foerster.conjugate would collapse) and Markov blankets. explain prints
both.
The structure of a model, read from its source: which sites it has, what
each one reads, and the facts an inference plan can be derived from.
`analyze` walks the macro-expanded body of a model (a `spin` form, or the
forms inside one) and returns its site graph:
{:sites {n {:kind :latent | :observed | :factor
:address [:y i] ; the :id form, symbols are loop variables;
; [:loc line col] for a site without :id
:dist {:ctor normal :args [{:form mu :reads #{0} :exact 0} …]}
:reads #{0} ; sites its distribution's arguments read
:control #{} ; sites that decide whether it runs
:loops [2]}} ; enclosing loops, innermost last
:loops {2 {:bindings [i] :sites #{1} :carried #{} :kind :plate | :sequential}}
; :carried: its sites a later iteration reads
:unknown [{:reason :closure :form …}]}
A site's value reads the sites its arguments were computed from: the
analysis follows locals through let, loop, if and calls, over-approximating
a call's result as reading everything its arguments read. A loop whose
recurring values read none of its own sites runs independent iterations (a
plate); otherwise it is sequential. What the walk cannot see — a site in a
closure, which the spin macro cannot see either — is listed under
`:unknown`, never guessed.
`facts` derives from the graph: the support of each site, finite latent
sites, plates, conjugate pairs (`foerster.conjugate`'s families, in the form
`foerster.conjugate` would collapse) and Markov blankets. `explain` prints
both.(analyze & body)The site graph of the model body (a spin form or the forms inside one),
analyzed where it is written. Locals in scope are its inputs.
The site graph of the model `body` (a `spin` form or the forms inside one), analyzed where it is written. Locals in scope are its inputs.
(analyze-form form)(analyze-form form {:keys [ns locals] :or {ns *ns*}})The site graph of a model's body form (see the namespace doc), symbols
resolved in ns (default *ns*). locals are the model's inputs: names
bound outside the form, which read no site.
The site graph of a model's body `form` (see the namespace doc), symbols resolved in `ns` (default `*ns*`). `locals` are the model's inputs: names bound outside the form, which read no site.
(children sites n)The sites that read site n, or run only depending on it.
The sites that read site `n`, or run only depending on it.
Prior constructor → likelihood constructor → [the likelihood argument the
parameter must be, exactly; foerster.conjugate family].
Prior constructor → likelihood constructor → [the likelihood argument the parameter must be, exactly; `foerster.conjugate` family].
(explain g)A readable account of the graph g and its facts.
A readable account of the graph `g` and its facts.
(facts {:keys [sites loops unknown]})Facts about the model the graph g describes, as a vector of maps.
Facts about the model the graph `g` describes, as a vector of maps.
(graph-of f)The site graph a model carries, or nil.
The site graph a `model` carries, or nil.
Families foerster.conjugate implements.
Families `foerster.conjugate` implements.
(model args & body)(fn args (spin body…)), carrying the site graph of body as metadata
(graph-of): a model whose structure inference can read.
`(fn args (spin body…))`, carrying the site graph of `body` as metadata (`graph-of`): a model whose structure inference can read.
The support of a distribution, by its constructor in foerster.dist.
The support of a distribution, by its constructor in `foerster.dist`.
(walk {:keys [env state] :as st} form)The value form computes, recording the sites it runs into (:state st).
The value `form` computes, recording the sites it runs into `(:state st)`.
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 |