Liking cljdoc? Tell your friends :D

org.replikativ.foerster.analysis

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.

Every value also carries its expression of the model's inputs, constants and sites (a site's argument's :expr, sites written {:site n}) as far as the walk can write it: through pure-fns and Math calls, if, and collections. That is the argument's link function; affine reads a + b·x off it.

facts derives from the graph: the support of each site, finite latent sites, plates, conjugate pairs (foerster.conjugate's families, and a Normal mean affine in a Normal prior, :normal-affine with each child's link and the sites it is conditional on) and Markov blankets. A latent site whose value, or a value computed from it, goes anywhere but a distribution's argument or the model's result — an impure call, a closure, the next iteration — escapes and is not collapsed. 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.

Every value also carries its expression of the model's inputs, constants
and sites (a site's argument's `:expr`, sites written {:site n}) as far as
the walk can write it: through `pure-fns` and `Math` calls, `if`, and
collections. That is the argument's link function; `affine` reads a + b·x
off it.

`facts` derives from the graph: the support of each site, finite latent
sites, plates, conjugate pairs (`foerster.conjugate`'s families, and a
Normal mean affine in a Normal prior, `:normal-affine` with each child's
link and the sites it is conditional on) and Markov blankets. A latent
site whose value, or a value computed from it, goes anywhere but a
distribution's argument or the model's result — an impure call, a
closure, the next iteration — escapes and is not collapsed. `explain`
prints both.
raw docstring

affineclj

(affine e n)

[a b] with e = a + b·x, x the value of site n and a, b expressions not mentioning it; nil if e is not affine in it.

[a b] with `e` = a + b·x, x the value of site `n` and a, b expressions
not mentioning it; nil if `e` is not affine in it.
sourceraw docstring

analyzecljmacro

(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.
sourceraw docstring

analyze-formclj

(analyze-form form)
(analyze-form form
              {:keys [ns locals unroll-plates?] given :known :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; known {sym value} those whose values are given (specialize).

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; `known` {sym value} those
whose values are given (`specialize`).
sourceraw docstring

appliedclj

(applied s)

[model args] for a spin a model made, or nil.

[model args] for a spin a `model` made, or nil.
sourceraw docstring

childrenclj

(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.
sourceraw docstring

conjugate-familiesclj

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].
sourceraw docstring

continuousclj

source

explainclj

(explain g)

A readable account of the graph g and its facts.

A readable account of the graph `g` and its facts.
sourceraw docstring

factsclj

(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.
sourceraw docstring

graph-ofclj

(graph-of f)

The site graph a model carries, or nil.

The site graph a `model` carries, or nil.
sourceraw docstring

implemented-familiesclj

Families foerster.conjugate implements.

Families `foerster.conjugate` implements.
sourceraw docstring

instanceclj

(instance model & args)

As specialize, but plates with known control are unrolled too: the model's instance graph for its data, one site per site a run meets. Its size grows with the data; for compiling a density (foerster.compiled).

As `specialize`, but plates with known control are unrolled too: the
model's instance graph for its data, one site per site a run meets. Its
size grows with the data; for compiling a density (`foerster.compiled`).
sourceraw docstring

linearclj

(linear e ns)

{:const a :coefs {n b}} with e = a + Σ b·xₙ over the sites ns it mentions, xₙ the value of site n and a and every b expressions mentioning none of ns; nil if e is not linear in them.

{:const a :coefs {n b}} with `e` = a + Σ b·xₙ over the sites `ns` it
mentions, xₙ the value of site n and a and every b expressions mentioning
none of `ns`; nil if `e` is not linear in them.
sourceraw docstring

modelcljmacro

(model args & body)

(fn args (spin body…)), carrying the site graph of body as metadata (graph-of): a model whose structure inference can read. The spins it makes remember it and their arguments (applied).

`(fn args (spin body…))`, carrying the site graph of `body` as metadata
(`graph-of`): a model whose structure inference can read. The spins it
makes remember it and their arguments (`applied`).
sourceraw docstring

pure-fnsclj

Functions whose result is their expression of their arguments: a value passed to one does not go anywhere else (facts' escape check), and its result has an expression (affine).

Functions whose result is their expression of their arguments: a value
passed to one does not go anywhere else (`facts`' escape check), and its
result has an expression (`affine`).
sourceraw docstring

specializeclj

(specialize model & args)

The site graph of the model applied to args: its inputs are known, so calls of pure-fns on known values are evaluated, an if with a known test walks only the branch taken, and a sequential loop whose control becomes known is unrolled (up to unroll-budget iterations) — its sites get concrete addresses, edges between iterations and :iterations. Plates stay symbolic. The model's parameters must be plain symbols.

The site graph of the `model` applied to `args`: its inputs are known, so
calls of `pure-fns` on known values are evaluated, an `if` with a known test
walks only the branch taken, and a sequential loop whose control becomes
known is unrolled (up to `unroll-budget` iterations) — its sites get
concrete addresses, edges between iterations and `:iterations`. Plates stay
symbolic. The model's parameters must be plain symbols.
sourceraw docstring

supportclj

The support of a distribution, by its constructor in foerster.dist.

The support of a distribution, by its constructor in `foerster.dist`.
sourceraw docstring

unroll-budgetclj

Iterations a sequential loop with known control is unrolled up to.

Iterations a sequential loop with known control is unrolled up to.
sourceraw docstring

walkclj

(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)`.
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