Markov kernels: transitions that leave the posterior invariant, which
foerster.moves.transition prepares and runs over traces — as chains
(foerster.core/kernel-infer) and as moves of populations
(foerster.program/move). They compose: cycle runs parts in turn,
mixture picks one by fixed weights.
A proposal of a site's value is not a kernel: see foerster.proposal.
Markov kernels: transitions that leave the posterior invariant, which `foerster.moves.transition` prepares and runs over traces — as chains (`foerster.core/kernel-infer`) and as moves of populations (`foerster.program/move`). They compose: `cycle` runs parts in turn, `mixture` picks one by fixed weights. A proposal of a site's value is not a kernel: see `foerster.proposal`.
(block-gibbs-kernel num-iterations
block-selector
block-kernels
address-classifier
&
[opts])Create a BlockGibbsKernel for block Gibbs sampling: address-classifier
(fn [address entry]) assigns latent sites to block ids, block-selector
picks a block id per iteration, and block-kernels {block-id kernel}
moves the block (the prior kernel, or a symmetric kernel). A move that
changes which sites belong to the moved block is rejected: its reverse
would move a different block.
Output options (all Markov-chain kernels): :samples :final (default)
emits each chain's last state; :samples :all emits every state after
the first :burn moves, equally weighted — an MCMC estimate from few
chains instead of one draw per chain.
Create a BlockGibbsKernel for block Gibbs sampling: `address-classifier`
(fn [address entry]) assigns latent sites to block ids, `block-selector`
picks a block id per iteration, and `block-kernels` {block-id kernel}
moves the block (the prior kernel, or a symmetric kernel). A move that
changes which sites belong to the moved block is rejected: its reverse
would move a different block.
Output options (all Markov-chain kernels): `:samples :final` (default)
emits each chain's last state; `:samples :all` emits every state after
the first `:burn` moves, equally weighted — an MCMC estimate from few
chains instead of one draw per chain.(cycle num-iterations kernels & [opts])A Markov-chain kernel that, num-iterations times, runs each of kernels
in turn — each for its own iterations: (cycle 100 [(hmc-kernel 1 …)
(single-site-mh-kernel 5)]) is a hundred rounds of one HMC move and five
single-site moves. A composition of kernels that leave the posterior
invariant leaves it invariant. Output options as for every chain kernel.
A Markov-chain kernel that, `num-iterations` times, runs each of `kernels` in turn — each for its own iterations: (cycle 100 [(hmc-kernel 1 …) (single-site-mh-kernel 5)]) is a hundred rounds of one HMC move and five single-site moves. A composition of kernels that leave the posterior invariant leaves it invariant. Output options as for every chain kernel.
(delayed-acceptance-kernel
num-iterations
coarse
&
[{:keys [scales steps step-size] :or {scales 0.1 step-size 0.1} :as opts}])Two-stage delayed acceptance on block sites (foerster.moves.block-mh/da-move):
coarse {address (fn [θ] log density)} is a cheap approximation of the
posterior of each named block (a surrogate, a coarser model, a Laplace
fit). Each iteration walks :steps random-walk steps of :scales on it,
then runs the program once and accepts on the program's ratio corrected by
the coarse one, so the chain targets the program's exact posterior; a
poor coarse density lowers acceptance. It must be positive wherever the
posterior is: a chain at a state of zero coarse density is refused
(foerster.moves.block-mh/coarse-support). Other latents get single-site
random-walk moves (:step-size). Output options as for every chain kernel.
Two-stage delayed acceptance on block sites (`foerster.moves.block-mh/da-move`):
`coarse` {address (fn [θ] log density)} is a cheap approximation of the
posterior of each named block (a surrogate, a coarser model, a Laplace
fit). Each iteration walks `:steps` random-walk steps of `:scales` on it,
then runs the program once and accepts on the program's ratio corrected by
the coarse one, so the chain targets the program's exact posterior; a
poor coarse density lowers acceptance. It must be positive wherever the
posterior is: a chain at a state of zero coarse density is refused
(`foerster.moves.block-mh/coarse-support`). Other latents get single-site
random-walk moves (`:step-size`). Output options as for every chain kernel.(finite-gibbs-kernel num-iterations address & [opts])Exact conditional draws at one fixed finite-support sample address. Other latent values and the scored site structure must remain unchanged across candidates; unsupported structure/support changes are refused. Keyed sites update their key; other sites replay from a valid anchor. Output options are :samples and :burn, as for single-site-mh-kernel. Compose fixed addresses with cycle/mixture for multiple-site sweeps.
Exact conditional draws at one fixed finite-support sample address. Other latent values and the scored site structure must remain unchanged across candidates; unsupported structure/support changes are refused. Keyed sites update their key; other sites replay from a valid anchor. Output options are :samples and :burn, as for single-site-mh-kernel. Compose fixed addresses with cycle/mixture for multiple-site sweeps.
(hmc-kernel num-iterations
&
[{:keys [step-size steps] :or {step-size 0.1 steps 10} :as opts}])Hamiltonian Monte Carlo on the block sites of a program
(foerster.block), within Gibbs: every iteration moves each block site by
HMC (:step-size, :steps leapfrog steps) and one other latent site by
single-site MH (foerster.moves.hmc/within-gibbs). Output options as for every
Markov-chain kernel.
Hamiltonian Monte Carlo on the block sites of a program (`foerster.block`), within Gibbs: every iteration moves each block site by HMC (`:step-size`, `:steps` leapfrog steps) and one other latent site by single-site MH (`foerster.moves.hmc/within-gibbs`). Output options as for every Markov-chain kernel.
(involutive-kernel num-iterations move & [opts])A Markov-chain kernel making num-iterations involutive MH moves
(foerster.moves.involutive/step): move is {:propose :log-q :involution},
optionally :check?. It composes with the other chain kernels through
cycle and mixture. Chains only: population programs refuse it, since
it gives back the state it leaves. Output options as for every chain
kernel.
A Markov-chain kernel making `num-iterations` involutive MH moves
(`foerster.moves.involutive/step`): `move` is {:propose :log-q :involution},
optionally :check?. It composes with the other chain kernels through
`cycle` and `mixture`. Chains only: population programs refuse it, since
it gives back the state it leaves. Output options as for every chain
kernel.(mixture num-iterations weighted & [opts])A Markov-chain kernel that, num-iterations times, picks one of the
kernels in weighted ([[w kernel] …]) with probability ∝ w and runs it
for its own iterations. A mixture of kernels that leave the posterior
invariant leaves it invariant (with weights that do not depend on the
state). Output options as for every chain kernel.
A Markov-chain kernel that, `num-iterations` times, picks one of the kernels in `weighted` ([[w kernel] …]) with probability ∝ w and runs it for its own iterations. A mixture of kernels that leave the posterior invariant leaves it invariant (with weights that do not depend on the state). Output options as for every chain kernel.
(nuts-kernel num-iterations
&
[{:keys [target-accept max-depth metric step-size inverse-metric
jitter]
:or {target-accept 0.8 max-depth 10 metric :variance jitter true}
:as opts}])The No-U-Turn sampler on block sites (foerster.moves.nuts), within Gibbs: the
first :burn iterations adapt the step size (to :target-accept, default
0.8) and a diagonal metric, and are dropped; :max-depth (10) bounds a
trajectory at 2^depth leapfrog steps; :metric estimates the metric from
the warm-up positions' variance (:variance, Stan's) or from positions
and gradients (:fisher, nutpie's). A block's target must be its
complete conditional. Output options as for every chain kernel.
:step-size (default 0.1) and :inverse-metric (the diagonal of M⁻¹ in
θ, default ones) set where a chain starts — each a value for every block
site or a map {address value} — and warm-up adapts from there; with
:burn 0 NUTS runs frozen at them, a fixed invariant kernel, as a
population move needs. Every retained draw's :sampler-stats give the
:step-size and :inverse-metric it ran with as such maps, so a warmed-up
run's values start a second, frozen one.
:jitter (true) starts each chain driven by this kernel (kernel-infer,
infer :nuts) at its block sites' values plus a uniform jitter in
(−2, 2) per coordinate of θ, as Stan's random initialization; false
starts exactly at :init. It stays on with :burn 0, where every draw
is kept: resuming a frozen chain from a posterior draw (:init that
draw, the exported :step-size and :inverse-metric) needs :jitter false. A population move never jitters.
The No-U-Turn sampler on block sites (`foerster.moves.nuts`), within Gibbs: the
first `:burn` iterations adapt the step size (to `:target-accept`, default
0.8) and a diagonal metric, and are dropped; `:max-depth` (10) bounds a
trajectory at 2^depth leapfrog steps; `:metric` estimates the metric from
the warm-up positions' variance (`:variance`, Stan's) or from positions
and gradients (`:fisher`, nutpie's). A block's target must be its
complete conditional. Output options as for every chain kernel.
`:step-size` (default 0.1) and `:inverse-metric` (the diagonal of M⁻¹ in
θ, default ones) set where a chain starts — each a value for every block
site or a map {address value} — and warm-up adapts from there; with
`:burn 0` NUTS runs frozen at them, a fixed invariant kernel, as a
population move needs. Every retained draw's `:sampler-stats` give the
`:step-size` and `:inverse-metric` it ran with as such maps, so a warmed-up
run's values start a second, frozen one.
`:jitter` (true) starts each chain driven by this kernel (`kernel-infer`,
`infer :nuts`) at its block sites' values plus a uniform jitter in
(−2, 2) per coordinate of θ, as Stan's random initialization; `false`
starts exactly at `:init`. It stays on with `:burn 0`, where every draw
is kept: resuming a frozen chain from a posterior draw (`:init` that
draw, the exported `:step-size` and `:inverse-metric`) needs `:jitter
false`. A population move never jitters.Protocol for block-level proposal kernels.
Protocol for block-level proposal kernels.
(propose-block this trace block-addresses)Returns {addr -> proposed-value} for addresses in this block.
Returns {addr -> proposed-value} for addresses in this block.
Protocol for selecting which block to update at each iteration.
Protocol for selecting which block to update at each iteration.
(select-block this trace iteration)Returns block-id (keyword) for which block to update this iteration.
Returns block-id (keyword) for which block to update this iteration.
Descriptions of Markov transitions. Fixed-tuning transitions preserve their target under the individual kernel's assumptions; warm-up is not an evidence-estimating inference algorithm.
Descriptions of Markov transitions. Fixed-tuning transitions preserve their target under the individual kernel's assumptions; warm-up is not an evidence-estimating inference algorithm.
(transition-id this)The transition family compiled by foerster.moves.transition.
The transition family compiled by foerster.moves.transition.
(proposal-mh-kernel num-iterations proposal & [{:keys [args] :as opts}])A Markov-chain kernel making num-iterations MH moves with the proposal
program proposal (foerster.runtime.gfi/mh-proposal: a function of the current
choices and :args returning a spin that proposes model addresses). It
composes through cycle and mixture; chains only, as
involutive-kernel. Output options as for every chain kernel.
A Markov-chain kernel making `num-iterations` MH moves with the proposal program `proposal` (`foerster.runtime.gfi/mh-proposal`: a function of the current choices and `:args` returning a spin that proposes model addresses). It composes through `cycle` and `mixture`; chains only, as `involutive-kernel`. Output options as for every chain kernel.
Marks a PBlockKernel whose proposal is symmetric, q(x' | x) = q(x | x'):
block Gibbs accepts its moves on the ratio of target densities alone. A
kernel that is not symmetric has no place in block Gibbs; propose it with
gfi/mh-proposal (a proposal program, scored both ways) or as an
involutive move instead.
Marks a `PBlockKernel` whose proposal is symmetric, q(x' | x) = q(x | x'): block Gibbs accepts its moves on the ratio of target densities alone. A kernel that is not symmetric has no place in block Gibbs; propose it with `gfi/mh-proposal` (a proposal program, scored both ways) or as an involutive move instead.
(random-walk-block-kernel & [{:keys [step-size] :or {step-size 0.1}}])(random-walk-mh-kernel num-iterations
&
[{:keys [step-size] :or {step-size 0.1} :as opts}])Create RandomWalkMHKernel for continuous variables.
Metropolis-Hastings with a symmetric Gaussian proposal on one unobserved
site per iteration; the program is replayed from that site with every other
site held at its trace value and rescored, and the proposal is accepted on
the ratio of joint densities (see foerster.runtime.trace/mh-log-ratio). A
discrete site gets a prior proposal instead of a step.
Output options (all Markov-chain kernels): :samples :final (default)
emits each chain's last state; :samples :all emits every state after
the first :burn moves, equally weighted — an MCMC estimate from few
chains instead of one draw per chain.
Create RandomWalkMHKernel for continuous variables. Metropolis-Hastings with a symmetric Gaussian proposal on one unobserved site per iteration; the program is replayed from that site with every other site held at its trace value and rescored, and the proposal is accepted on the ratio of joint densities (see `foerster.runtime.trace/mh-log-ratio`). A discrete site gets a prior proposal instead of a step. Output options (all Markov-chain kernels): `:samples :final` (default) emits each chain's last state; `:samples :all` emits every state after the first `:burn` moves, equally weighted — an MCMC estimate from few chains instead of one draw per chain.
(single-site-mh-kernel num-iterations & [opts])Create SingleSiteMHKernel for lightweight Metropolis-Hastings.
Output options (all Markov-chain kernels): :samples :final (default)
emits each chain's last state; :samples :all emits every state after
the first :burn moves, equally weighted — an MCMC estimate from few
chains instead of one draw per chain.
Create SingleSiteMHKernel for lightweight Metropolis-Hastings. Output options (all Markov-chain kernels): `:samples :final` (default) emits each chain's last state; `:samples :all` emits every state after the first `:burn` moves, equally weighted — an MCMC estimate from few chains instead of one draw per chain.
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 |