Posterior sampling¶
ds.inference.sample draws from the posterior of a MAP fit with MCMC,
and ds.inference.mcmc_report checks the draws. See
posterior sampling.
diff_soup.inference.sample
¶
sample(problem: Any, fit: Any = None, *, kernel: str = 'nuts', chains: int = 4, draws: int = 1000, warmup: int = 200, adapt: Optional[str] = 'pooled', mass: str = 'diag', step_size: Optional[float] = None, max_tree_depth: int = 10, key: Array, preconditioner: Any = 'laplace', curvature: str = 'observed', chain_map: Optional[str] = None, **kernel_options) -> Draws
Draw from the posterior of a MAP problem with MCMC, with the chains started near the fit.
Each chain starts from the fit plus random noise of half a standard deviation per coordinate, and every draw is in the parameters' own coordinates. It is refused in a run of several processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Any
|
An |
required |
fit
|
Any
|
The |
None
|
kernel
|
str
|
|
'nuts'
|
chains
|
int
|
The number of chains. |
4
|
draws
|
int
|
The number of draws kept per chain. |
1000
|
warmup
|
int
|
The number of steps before the kept draws, which random-walk chains discard and NUTS chains spend adapting, keeping their last state. |
200
|
adapt
|
Optional[str]
|
How NUTS adapts, |
'pooled'
|
mass
|
str
|
The mass matrix NUTS adapts, |
'diag'
|
step_size
|
Optional[float]
|
The NUTS step size adaptation starts from, 1.0 when |
None
|
max_tree_depth
|
int
|
The most times a NUTS trajectory doubles in one draw. |
10
|
key
|
Array
|
The JAX random key that fixes the draws. |
required |
preconditioner
|
Any
|
|
'laplace'
|
curvature
|
str
|
The curvature of that Laplace approximation, |
'observed'
|
chain_map
|
Optional[str]
|
How the chains run, |
None
|
**kernel_options
|
|
{}
|
Returns:
| Type | Description |
|---|---|
Draws
|
The |
diff_soup.inference.Draws
dataclass
¶
The MCMC draws of sample, in the parameters' own coordinates.
draws[handle] returns the draws of one parameter, or a dictionary by member for a parameter
that varies by member.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
Array
|
The draws, shaped |
names |
tuple
|
The label of each parameter column of |
info |
dict
|
Sampler statistics per draw, |
chain_map |
str
|
How the chains ran, |
diff_soup.inference.mcmc_report
¶
mcmc_report(draws: Any, *, rhat_max: float = 1.01, ess_floor: float = 400.0) -> McmcReport
Check MCMC draws for convergence and effective sample size, per parameter.
The diagnostics are the rank-normalized split R-hat and the bulk and tail effective sample sizes. Each chain is split in half, so one chain is enough, and every chain needs at least eight draws.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draws
|
Any
|
The |
required |
rhat_max
|
float
|
The largest split R-hat that passes. |
1.01
|
ess_floor
|
float
|
The smallest bulk or tail effective sample size that passes. |
400.0
|
Returns:
| Type | Description |
|---|---|
McmcReport
|
An |