github ↗
docs menu

Module Norn.Evidence

Evidence: the normalising constant of a posterior, with its draws.

For a prior π and a likelihood L the evidence is Z = ∫ L π, the posterior's normaliser and the probability of the data under the model. Norn.Nested and Norn.Smc estimate it, and their particles weighted by the posterior are its sample.

#type ('u, 'f, 'd) t

The type for evidence estimates over positions 'u.

#val log_evidence : ('u, 'f, 'd) t -> (float, 'f, 'd) Nx.t

log_evidence z is the estimate of ln Z, a scalar.

#val error : ('u, 'f, 'd) t -> (float, 'f, 'd) Nx.t

error z is the estimate's standard error in ln Z, a scalar.

#val information : ('u, 'f, 'd) t -> (float, 'f, 'd) Nx.t

information z is H, the posterior's Kullback-Leibler divergence from the prior in nats, E_post (ln L) - ln Z: how much the data narrowed the prior.

#val sample : ('u, 'f, 'd) t -> ('u, 'f, 'd) Weighted.t

sample z is draws weighted by the posterior, their log weights normalised.

#val expectation : ('u, 'd) Nx.Ptree.t -> ('u -> (float, 'f, 'd) Nx.t) -> ('u, 'f, 'd) t -> (float, 'f, 'd) Nx.t * (float, 'f, 'd) Nx.t

expectation u f z is the posterior expectation of f, a map of one draw to a tensor, under z's sample, and its standard error, element by element. f runs under Rune.vmap, once for all draws.

The error starts from a standard deviation. For tempering it is the variance between M chains, with its factor M / (M - 1). For nested sampling it is the spread of the expectation over 100 runs resampled by lineage, the draws that descend from one starting point (Norn.Nested.state's lineage) taken together, each resample's volumes recomputed from the draws it holds: slice moves correlate a replacement with the point it starts from, and the resampling keeps those draws together. This construction is our own and its calibration is measured, not proven; 100 resamples leave the standard deviation about 7% Monte Carlo error.

A spread over resampled lineages is scaled by K / (K - 1), K the effective_groups, the small-sample factor the variance between groups carries (Cameron and Miller 2015, §VI). The error is the standard deviation times t / 1.96, t the 0.975 quantile of Student's t with K - 1 degrees of freedom, so ± 1.96 errors is the 95% interval of that t pivot; K - 1 degrees of freedom is a heuristic for groups of unequal mass. At K <= 1 the error is inf. A small K means few groups carry the posterior and the interval is wide: for nested sampling, double the live points until K is large, as Lee and Whiteley (2018, §6.2) double a particle filter's particles until its estimated variance is small enough.

#val effective_groups : ('u, 'f, 'd) t -> (float, 'f, 'd) Nx.t

effective_groups z is K = (Σ_g W_g)² / Σ_g W_g², a scalar, W_g the posterior mass of the independent group g: nested sampling's lineages, tempering's chains. It is 1 when one group carries the whole sample and the number of groups when they carry equal mass.

Why a run stopped

#type stop =
  1. #| Converged
    (*

    The run finished: nested sampling's live points could add less than its tolerance to ln Z, tempering reached β = 1.

    *)
  2. #| Remaining of float
    (*

    Nested sampling's budget ran out while its live points could still add up to this many nats to ln Z.

    *)
  3. #| Temperature of float
    (*

    Tempering's budget ran out at this temperature β < 1: the estimate is of ln ∫ L^β π, the sample of its tempered posterior.

    *)

The type for the reasons a run stopped. A spent budget is a result, not an error: the estimate so far, with how far it fell short.

#val stop : ('u, 'f, 'd) t -> stop

stop z is why the run that gave z stopped. It reads z's tensors, so it waits for a computation that produces them.

Structure and formatting

#val ptree : ('u, 'd) Nx.Ptree.t -> (('u, 'f, 'd) t, 'd) Nx.Ptree.t

ptree u is the structure of evidence estimates over u, so a compiled function may return one.

#val pp : Stdlib.Format.formatter -> ('u, 'f, 'd) t -> unit

pp formats an estimate as ln Z = -412.31 ± 0.08, H = 5.20 nats, followed, for a spent budget, by , budget spent with 0.52 nats left or , budget spent at β = 0.73.