Liking cljdoc? Tell your friends :D

org.replikativ.foerster.effects

Probabilistic programming effects: unified choose primitive.

This provides the fundamental primitive for compositional probabilistic programming:

  • choose: Unified effect for both sampling and observation

A choose site is a savepoint when its world handles :inference/choose (inference: foerster.smc, foerster.trace); otherwise it is forward simulation.

Probabilistic programming effects: unified choose primitive.

This provides the fundamental primitive for compositional probabilistic programming:
- choose: Unified effect for both sampling and observation

A choose site is a savepoint when its world handles `:inference/choose`
(inference: `foerster.smc`, `foerster.trace`); otherwise it is forward
simulation.
raw docstring

chooseclj/s

(choose & _)

Unified primitive for probabilistic choice.

Must only be called inside a spin; outside, this throws.

Examples: ;; Sample from prior (choose (normal 0 1))

;; Observe value (choose (normal 0 1) :observe 1.5)

;; With explicit ID (choose (normal mu sigma) :id :my-param :observe observed)

;; With initial value (the first state of a Markov chain) (choose (normal 0 1) :init 0.5)

Unified primitive for probabilistic choice.

Must only be called inside a spin; outside, this throws.

Examples:
  ;; Sample from prior
  (choose (normal 0 1))

  ;; Observe value
  (choose (normal 0 1) :observe 1.5)

  ;; With explicit ID
  (choose (normal mu sigma) :id :my-param :observe observed)

  ;; With initial value (the first state of a Markov chain)
  (choose (normal 0 1) :init 0.5)
sourceraw docstring

choose-adapterclj/s

(choose-adapter args)

Adapter for choose effect: (choose dist & opts) -> {source, options}

Adapter for choose effect: (choose dist & opts) -> {source, options}
sourceraw docstring

choose-handlerclj/s

PEffectHandler implementation for choose effect.

PEffectHandler implementation for choose effect.
sourceraw docstring

deterministicclj/s

(deterministic & _)

Record value, a quantity computed from the program's choices, in the trace under its :id: it adds no randomness and no weight, and returns value. Posteriors of it are read from the particles' traces (measure/site-value); traces carrying the values a model computed are also what learned proposals train on.

(let [h (sample (dist/normal 1.7 0.1) :id :height) w (sample (dist/normal 70 10) :id :weight)] (deterministic (/ w (* h h)) :id :bmi))

Must only be called inside a spin; outside, this throws.

Record `value`, a quantity computed from the program's choices, in the
trace under its `:id`: it adds no randomness and no weight, and returns
`value`. Posteriors of it are read from the particles' traces
(`measure/site-value`); traces carrying the values a model computed are
also what learned proposals train on.

  (let [h (sample (dist/normal 1.7 0.1) :id :height)
        w (sample (dist/normal 70 10) :id :weight)]
    (deterministic (/ w (* h h)) :id :bmi))

Must only be called inside a spin; outside, this throws.
sourceraw docstring

deterministic-adapterclj/s

(deterministic-adapter [value & opts])
source

deterministic-handlerclj/s

source

factorclj/s

(factor & _)

Multiply the weight of this execution by exp(log-weight): a score that is not the density of a value (a soft constraint, a reward, a likelihood that was computed elsewhere).

(factor w :barrier true) is also a barrier of SMC: particles park there and the population is resampled, as at an observation — a scored step of a program whose data is a score (a verifier's, a value estimate's; see foerster.steer).

Must only be called inside a spin; outside, this throws.

Multiply the weight of this execution by exp(`log-weight`): a score that is
not the density of a value (a soft constraint, a reward, a likelihood that
was computed elsewhere).

`(factor w :barrier true)` is also a barrier of SMC: particles park there
and the population is resampled, as at an observation — a scored step of a
program whose data is a score (a verifier's, a value estimate's; see
`foerster.steer`).

Must only be called inside a spin; outside, this throws.
sourceraw docstring

factor-adapterclj/s

(factor-adapter [log-weight & opts])
source

factor-handlerclj/s

source

intervene!clj/s

(intervene! address value)

Set intervention value (Pearl's do-operator).

This cuts the connection to parent nodes in the graphical model. Used for causal inference and counterfactual queries.

Example: (intervene! :treatment 1.0) ; Force treatment = 1.0 (let [outcome (choose (normal treatment 1))] outcome)

Set intervention value (Pearl's do-operator).

This cuts the connection to parent nodes in the graphical model.
Used for causal inference and counterfactual queries.

Example:
  (intervene! :treatment 1.0)  ; Force treatment = 1.0
  (let [outcome (choose (normal treatment 1))]
    outcome)
sourceraw docstring

observeclj/s

(observe dist value & opts)

Condition on observed value (convenience wrapper around choose).

Examples: (observe (normal mu sigma) observed-value)

Condition on observed value (convenience wrapper around choose).

Examples:
  (observe (normal mu sigma) observed-value)
sourceraw docstring

observe-adapterclj/s

(observe-adapter args)

Adapter for observe effect: (observe dist value & opts) -> {source, options with :observe}

Adapter for observe effect: (observe dist value & opts) -> {source, options with :observe}
sourceraw docstring

register-probabilistic-effects!clj/s

(register-probabilistic-effects!)

Register probabilistic effects with spindel effect system.

Registers choose, sample, and observe effects. This should be called at library initialization time.

Register probabilistic effects with spindel effect system.

Registers choose, sample, and observe effects.
This should be called at library initialization time.
sourceraw docstring

sampleclj/s

(sample dist & opts)

Sample from a distribution (convenience wrapper around choose).

Examples: (sample (normal 0 1)) (sample (uniform 0 1) :id :my-param) (sample (normal 0 1) :id :mu :proposal (normal 0.8 0.5))

:proposal is a distribution a fresh draw under inference comes from instead (a guide, possibly computed from the data: amortized inference); the weight takes log p − log q, so the target is unchanged. Replays, moves and a policy's :draw take precedence.

Sample from a distribution (convenience wrapper around choose).

Examples:
  (sample (normal 0 1))
  (sample (uniform 0 1) :id :my-param)
  (sample (normal 0 1) :id :mu :proposal (normal 0.8 0.5))

`:proposal` is a distribution a fresh draw under inference comes from
instead (a guide, possibly computed from the data: amortized inference);
the weight takes log p − log q, so the target is unchanged. Replays, moves
and a policy's `:draw` take precedence.
sourceraw docstring

sample-adapterclj/s

(sample-adapter args)

Adapter for sample effect: (sample dist & opts) -> {source, options}

Adapter for sample effect: (sample dist & opts) -> {source, options}
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