Predictive¶
Predictive draws posterior predictive samples: it repeatedly draws latents from a fitted guide or
a Markov chain Monte Carlo (MCMC) chain and runs the model forward from them, recording every site
(predictive sampling). In a
regression, the draws carry
both the uncertainty in the coefficients and the variation of the response (Gelman et al., 2013),
and can be compared with observations or summarized as predictive intervals.
posterior_expectations instead reads each response's native conditional law
at the retained joint posterior draws. Recorded chains keep separate chain and
draw axes; categorical and ordinal responses return category probabilities.
Other responses use the shared analytic or explicitly budgeted finite-mean
policy. Upstream observed and lexical values remain conditioned, and observed
densities are disabled during this replay. Exact Scan occurrences and their
execution order follow the raw likelihood collector's addressing convention.
See source conditional effects
for the checked model adapter and row-axis contract.
predictive
¶
Posterior predictive sampling.
Given a trained posterior representation (either a variational
guide or an MCMC chain), Predictive repeatedly samples
latents from the posterior and traces the model forward to produce
posterior predictive draws of every site.
Predictive
¶
Predictive(model: MonadicProgram, posterior: Guide | MCMCResult | PriorDraws, num_samples: int | None = None)
Posterior predictive sampler.
Accepts either a trained Guide (variational
posterior), an MCMCResult (Monte Carlo posterior), or independent
PriorDraws from the retained prior law.
Variational case: draws num_samples fresh guide samples.
MCMC case: iterates over the recorded posterior draws (one
forward trace per draw, up to num_samples if specified).
An input of B rows is B independent runs of the model.
A guide's Guide.rsample gives each run its own draw of a site
that is not plated, (batch, *constrained_shape), and one draw
of a plated site that every run shares. An MCMC draw, at
LatentSite.constrained_shape, is one value every run shares.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Generative model.
TYPE:
|
posterior
|
Trained posterior representation.
TYPE:
|
num_samples
|
Number of predictive draws. Defaults to
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in src/quivers/inference/predictive.py
__call__
¶
Draw posterior predictive samples.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Program input. Shape
TYPE:
|
observations
|
Additional observed data to condition on.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
One key per site, holding the stacked trace values:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an |
Source code in src/quivers/inference/predictive.py
posterior_expectations
¶
posterior_expectations(model: MonadicProgram, posterior: Guide | MCMCResult | PriorDraws, x: Tensor, observations: Mapping[str, Tensor] | None = None, *, sites: Sequence[str], num_samples: int | None = None, mc_samples: int | None = None, seed: int = 0) -> dict[str, Tensor]
Collect native conditional response expectations on retained draw axes.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Existing compiled program; no source preparation is performed.
TYPE:
|
posterior
|
Fitted guide or retained constrained joint draws.
TYPE:
|
x
|
One-run execution input. Multiple independent runs require separate requests so their posterior interpretation remains explicit.
TYPE:
|
observations
|
Covariates and optional response values conditioning the replay. Observed densities are not scored. Upstream observed or lexical values retain their ordinary conditioning semantics.
TYPE:
|
sites
|
Distinct response names, including optional exact Scan occurrences.
TYPE:
|
num_samples
|
Maximum leading draws per recorded chain, or fresh guide draws. None retains recorded draws or takes 100 variational draws.
TYPE:
|
mc_samples
|
Explicit finite-moment approximation budget when a native analytic expectation is unavailable, following the shared response-law policy.
TYPE:
|
seed
|
Isolated posterior and response streams; the caller RNG is restored.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
Conditional native means with chain/draw/native batch/event axes. Categorical and ordinal laws return category probabilities. Scan occurrences stack in visitation order, as for raw log likelihoods. |
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If execution/draw axes, selected sites, posterior layout, or response moments are invalid. No response-replication average is substituted for a native analytic expectation. |
Source code in src/quivers/inference/predictive.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
Cited sources¶
Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari, and Donald B. Rubin. Bayesian Data Analysis. Chapman and Hall/CRC, 3 edition, 2013. ISBN 9781439840955. URL: https://www.routledge.com/Bayesian-Data-Analysis/Gelman-Carlin-Stern-Dunson-Vehtari-Rubin/p/book/9781439840955.