Module Norn.Summary
Summaries of draws, with their findings.
A summary has a row per element of the draws, such as theta[3], and a column per statistic: the mean, the standard deviation, the 5%, 50% and 95% quantiles, the Monte Carlo standard error of the mean, the bulk and tail effective sample sizes and R-hat (Norn.Diag). Its findings are the problems those numbers and the transitions' statistics show, as data: there are no warnings. A summary of weighted draws (of_weighted) has the columns that weights allow, and judges the weights instead of the chains.
Format.printf "%a@." Norn.Summary.pp (Norn.Summary.v schools ~stats post)
type tThe type for summaries.
type finding = - #
| Rhat_high of {- #
path : Nx.Ptree.Path.t; - #
index : int array; - #
rhat : float;
}(*R-hat above
*)1.01: split R-hat without superchains, nested R-hat with them. - #
- #
| Ess_low of {- #
path : Nx.Ptree.Path.t; - #
index : int array; - #
bulk : float; - #
tail : float;
}(*A bulk or tail effective sample size below
*)100per chain, or below400in total with superchains. - #
- #
| Not_finite of {- #
path : Nx.Ptree.Path.t; - #
index : int array; - #
count : int;
}(*
*)countof the element's draws are NaN or infinite: it has no diagnostic. - #
- #
| Constant of {- #
path : Nx.Ptree.Path.t; - #
index : int array;
}(*Every draw of the element is equal: it has no R-hat nor effective size.
*) - #
- #
| Divergent of {}(*
*)countof thetotaltransitions diverged. - #
| Saturated of {}(*
*)countof thetotaltransitions reached their maximum length before they turned. - #
| Ebfmi_low of {}(*A chain's E-BFMI is below
*)0.3. - #
| Pareto_k of {}(*The
*)k̂of the raw weights (Norn.Diag.psis) is abovethreshold,min (1 - 1 / log10 S, 0.7)forSdraws, or NaN, so that estimates from them are unreliable or cannot be judged.
The type for findings. A finding about an element names it by the path of its tensor and its index in the tensor.
The type for where divergences gather: an element whose draws from transitions that diverged have a mean shift standard deviations from its mean, by more than one (Norn.Diag.divergent_shift).
val v :
('u, 'd) Nx.Ptree.t ->
?stats:('f, 'd) Stats.t Draws.t ->
?superchains:int ->
'u Draws.t ->
tv u ?stats ?superchains d summarises the draws d of u. stats, the transitions' statistics, adds the findings on divergences, depth and E-BFMI. superchains takes the chains as that many consecutive groups for Norn.Diag.nested_rhat, which then fills the rhat column.
The statistics are computed at float64, whatever the draws' dtype.
Raises Invalid_argument if the chains have fewer than 4 draws, if superchains does not divide the chains, and as Norn.Diag does for a tensor that is not of a float dtype.
val of_weighted : ('u, 'd) Nx.Ptree.t -> ('u, 'f, 'd) Weighted.t -> tof_weighted u w summarises the weighted draws w of u, their log weights raw: it smooths them as Norn.Diag.psis does, and judges them by the raw weights' k̂. With x_s an element's draws and w̃_s the smoothed weights normalised, its columns are the mean μ = Σ w̃_s x_s, the standard deviation sqrt (Σ w̃_s (x_s - μ)²), the 5%, 50% and 95% quantiles, the Monte Carlo standard error of the mean of independent draws sqrt (Σ w̃_s² (x_s - μ)²), and the mean's effective sample size, the variance over that error squared. A quantile interpolates linearly between the draws of positive weight in order, the j-th at the middle of its weight, w̃_1 + ... + w̃_(j-1) + w̃_j / 2. Its findings are each element's Not_finite and Constant, in row order, then Pareto_k. The statistics are computed at float64.
Raises Invalid_argument if w.log_weights is not of shape [n], or if a tensor of w.values has no leading axis of n, naming the path.
concat ss is the rows and findings of ss, in order: derived quantities summarised beside parameters.
Raises Invalid_argument if the summaries' columns differ, as those of chains and of weighted draws do.
findings s is s's findings, the elements' in row order, then the transitions'.
labels s is s's row labels: an element's path, then its index in brackets for a tensor that is not a scalar, as theta[3] or b[1,0]. At the root path, a tensor is labelled by its index alone, and a scalar value.
val columns : t -> (string * Nx.host Nx.float64_t) listcolumns s is s's columns, each a vector with one element per row: mean, sd, q5, median, q95, mcse, then ess_bulk, ess_tail and rhat for chains, ess for weighted draws.
pp_finding ppf f formats f as a sentence.