Prior sampling¶
prior_draws generates independent joint draws from a program's retained
conditional priors. It uses the same named draw laws and data dependencies as
fitting, including normalized measure-valued draw boundaries. Its dependency
projection omits downstream responses without evaluating their likelihoods.
import torch
from quivers.dsl import loads
from quivers.inference import prior_draws
program = loads("""object R : Real 1
program model : R -> R
sample scale <- LogNormal(loc=0.0, scale=0.3)
sample b <- Normal(loc=0.0, scale=scale)
observe y <- Normal(loc=b, scale=1.0)
return b
export model
""").morphism
draws = prior_draws(program, torch.zeros(1, 1), num_samples=8, seed=12)
assert draws.samples["b"].shape == (1, 8)
The singleton leading axis of PriorDraws preserves the common output layout;
it is not a Markov chain. Prior views reuse predictive, likelihood, and summary
methods and do not report MCMC convergence statistics for independent samples.
An authored score is a global potential. Independent forward sampling cannot
normalize an arbitrary potential, so the ancestral method refuses it. Pass a
configured MCMC driver to prior_draws(..., method=driver) to perform
factor-conditioned prior-only inference; the returned MCMCResult then has
genuine chain provenance and the driver's own budgets.
prior
¶
Independent ancestral prior draws and explicit factor-conditioned alternatives.
PriorMode
¶
Fit observations, additionally retain independent priors, or fit priors only.
PriorDraws
didactic-model
¶
PriorDraws(*, samples: Mapping[str, Tensor] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), num_samples: int)
Bases: ValueModel
Independent ancestral samples, without MCMC convergence statistics.
| PARAMETER | DESCRIPTION |
|---|---|
samples
|
Constrained latent samples with axes
TYPE:
|
num_samples
|
Number of independently generated joint prior draws.
TYPE:
|
num_chains
property
¶
Return the singleton layout axis, which has no chain diagnostics.
| RETURNS | DESCRIPTION |
|---|---|
int
|
One independent-draw layout axis, not a Markov chain. |
prior_draws
¶
prior_draws(model: MonadicProgram, input: Tensor, observations: Mapping[str, Tensor] | None = None, *, num_samples: int = 100, seed: int = 0, method: Literal['ancestral'] | MCMC = 'ancestral') -> PriorDraws | MCMCResult
Sample the retained prior without evaluating observation likelihoods.
Ancestral sampling draws every proper conditional prior once per joint draw. Arbitrary explicit score potentials require the explicitly selected MCMC alternative because their normalized law is not an ancestral kernel. Existing measure-valued draw boundaries retain their normalizing semantics.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Compiled model with its original priors and support constraints.
TYPE:
|
input
|
One execution's input.
TYPE:
|
observations
|
Covariates and retained observations needed by data-dependent priors.
TYPE:
|
num_samples
|
Positive number of independent draws under the ancestral method.
TYPE:
|
seed
|
Isolated CPU random stream; the caller's state is restored.
TYPE:
|
method
|
Independent forward sampling, or a configured Markov-chain driver for priors containing explicit potentials. The latter retains its budgets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PriorDraws or MCMCResult
|
Samples with honest provenance and constrained event coordinates. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the independent budget is invalid or an active potential precludes independent ancestral sampling. |
TypeError
|
If an unsupported sampling method is requested. |
Source code in src/quivers/inference/prior.py
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 203 204 205 206 207 208 | |