Measure abstraction for probabilistic programming.
Measures represent probability distributions over execution traces. This is the foundation for compositional inference algorithms.
Measure abstraction for probabilistic programming. Measures represent probability distributions over execution traces. This is the foundation for compositional inference algorithms.
Effective sample size 1/Σw² of normalized weights (weights/ess).
Effective sample size 1/Σw² of normalized weights (`weights/ess`).
(empirical particles)Create an empirical measure from weighted particles.
particles: vector of [context log-weight] pairs
Create an empirical measure from weighted particles. particles: vector of [context log-weight] pairs
(get-contexts measure)Extract execution contexts from measure.
Extract execution contexts from measure.
(get-log-weights measure)Extract log-weights from measure.
Extract log-weights from measure.
(get-particles measure)The particles of measure: a vector of [context log-weight] pairs.
The particles of `measure`: a vector of [context log-weight] pairs.
(get-trace context)The trace {address -> entry} of a particle (context or Sample).
The trace {address -> entry} of a particle (context or Sample).
(get-value context)Extract the program result from an execution context (or a Sample).
The result is stored in [:inference :result] after execution completes.
Args: context - ExecutionContext from inference
Returns: The value returned by the probabilistic program
Extract the program result from an execution context (or a Sample). The result is stored in [:inference :result] after execution completes. Args: context - ExecutionContext from inference Returns: The value returned by the probabilistic program
(markov-measure particles)(markov-measure particles {:keys [estimator log-normalizer]})Settled chain draws. Their weights combine samples, not evidence estimates,
so log-marginal is nil. A chain method that computes a separate evidence
estimate (parallel tempering's stepping stones) passes it as normalizer
{:estimator e :log-normalizer l}: the contract then names that estimator,
status :estimate, and log-marginal returns it. Either way the draws are
autocorrelated: their weight-based effective-sample-size is not the chain
ESS (see foerster.diagnostics/summary, which uses :chain-lengths).
Settled chain draws. Their weights combine samples, not evidence estimates,
so `log-marginal` is nil. A chain method that computes a separate evidence
estimate (parallel tempering's stepping stones) passes it as `normalizer`
{:estimator e :log-normalizer l}: the contract then names that estimator,
status `:estimate`, and `log-marginal` returns it. Either way the draws are
autocorrelated: their weight-based `effective-sample-size` is not the chain
ESS (see `foerster.diagnostics/summary`, which uses `:chain-lengths`).(multinomial-resample weights n)n indices drawn independently from the normalized weights.
`n` indices drawn independently from the normalized `weights`.
(normalize-log-weights log-weights)Legacy engine selection: equal mass among impossible candidates, or among infinite-weight candidates. This does not make a zero-mass posterior valid.
Legacy engine selection: equal mass among impossible candidates, or among infinite-weight candidates. This does not make a zero-mass posterior valid.
(pick-uniformly v)A uniformly chosen element of a vector, drawn through uniform01.
A uniformly chosen element of a vector, drawn through `uniform01`.
Protocol for probability measures over execution traces.
A measure represents a distribution over execution contexts (traces); inference resolves an EmpiricalMeasure, a weighted particle set.
Protocol for probability measures over execution traces. A measure represents a distribution over execution contexts (traces); inference resolves an EmpiricalMeasure, a weighted particle set.
(effective-sample-size this)Effective sample size (ESS) for particle degeneracy detection.
ESS = (sum w_i)^2 / sum(w_i^2) where w_i are normalized weights.
Low ESS indicates degeneracy -> trigger resampling. For Markov-chain
draws (equal weights) this is the number of draws, not the chain ESS:
use foerster.diagnostics/summary.
Effective sample size (ESS) for particle degeneracy detection. ESS = (sum w_i)^2 / sum(w_i^2) where w_i are normalized weights. Low ESS indicates degeneracy -> trigger resampling. For Markov-chain draws (equal weights) this is the number of draws, not the chain ESS: use `foerster.diagnostics/summary`.
(log-marginal this)Log population mass: log mean weight plus earlier normalizers. Returns nil for explicitly marked chain outputs, which do not estimate evidence. A numerical value alone does not certify its scale or unbiasedness.
Log population mass: log mean weight plus earlier normalizers. Returns nil for explicitly marked chain outputs, which do not estimate evidence. A numerical value alone does not certify its scale or unbiasedness.
(measure-stats this query-fn)Compute statistics over the measure using query-fn.
query-fn: (fn [context] -> value)
Returns map with :mean, :variance, :quantiles, etc. Useful for extracting posterior statistics.
Compute statistics over the measure using query-fn. query-fn: (fn [context] -> value) Returns map with :mean, :variance, :quantiles, etc. Useful for extracting posterior statistics.
(measure-type this)Returns the type of measure: :empirical.
Returns the type of measure: :empirical.
(sample-measure this n)Sample n execution contexts from this measure.
Returns vector of [context log-weight] pairs, drawn according to the weights.
Sample n execution contexts from this measure. Returns vector of [context log-weight] pairs, drawn according to the weights.
(resample scheme weights n)n ancestor indices from the normalized weights by scheme:
:systematic (default), :stratified, :residual or :multinomial.
`n` ancestor indices from the normalized `weights` by `scheme`: `:systematic` (default), `:stratified`, `:residual` or `:multinomial`.
(residual-resample weights n)Residual resampling: ⌊n·wᵢ⌋ copies of each particle, the rest drawn multinomially from the residual weights.
Residual resampling: ⌊n·wᵢ⌋ copies of each particle, the rest drawn multinomially from the residual weights.
(sample-categorical weights)One index drawn from normalized weights, through uniform01.
One index drawn from normalized weights, through `uniform01`.
(sample-particle result trace)A particle that carries only a program result and its trace — what a pooled MCMC estimate keeps per draw, instead of pinning a context.
A particle that carries only a program result and its trace — what a pooled MCMC estimate keeps per draw, instead of pinning a context.
(site-value particle address)The value a particle's site address took: a sample, an observation or a
deterministic value.
The value a particle's site `address` took: a sample, an observation or a `deterministic` value.
(stratified-resample weights n)Stratified resampling: one uniform draw in each of the n strata [i/n, (i+1)/n). Lower variance than multinomial, never more than systematic's failure modes.
Stratified resampling: one uniform draw in each of the n strata [i/n, (i+1)/n). Lower variance than multinomial, never more than systematic's failure modes.
(systematic-resample weights n)Systematic resampling algorithm from Anglican.
Low-variance resampling for particle filters. weights: normalized weights (sum to 1) n: number of particles to sample
Returns vector of indices into original particle vector.
Systematic resampling algorithm from Anglican. Low-variance resampling for particle filters. weights: normalized weights (sum to 1) n: number of particles to sample Returns vector of indices into original particle vector.
(uniform01)One uniform draw from the current generator (foerster.random), so
resampling, ancestor choice, the accept step and the site choice of every
kernel obey random/set-seed! exactly like the program's samples do.
clojure.core/rand did not: it reads Math/random's own unseedable
generator, which made a seeded run reproducible in its prior draws and
random in its resampling and moves.
One uniform draw from the current generator (`foerster.random`), so resampling, ancestor choice, the accept step and the site choice of every kernel obey `random/set-seed!` exactly like the program's samples do. `clojure.core/rand` did not: it reads `Math/random`'s own unseedable generator, which made a seeded run reproducible in its prior draws and random in its resampling and moves.
(weighted-quantiles values weights)A function of p in [0, 1]: the p-quantile of values weighted by the
normalized weights, the smallest value whose cumulative weight reaches p.
A function of p in [0, 1]: the p-quantile of `values` weighted by the normalized `weights`, the smallest value whose cumulative weight reaches p.
(world-descriptors measure)The world descriptors of measure's particles that ran in canonical worlds
(:world-policy :fork), in particle order. Particles of pure inference ran
in no such world, and contribute none.
The world descriptors of `measure`'s particles that ran in canonical worlds (`:world-policy :fork`), in particle order. Particles of pure inference ran in no such world, and contribute none.
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 |