Methods and catalogs

Statistical methods

The formulas SENTIL uses to turn sampled robustness into a decision: the confidence intervals, the sample-sizing bounds, and the four checking regimes.

Statistical model checking estimates how often a property holds by drawing noisy realizations and scoring each one. A point estimate alone cannot carry a safety argument, so every estimate comes with an interval, and a run can stop early once a sequential test has enough evidence. The formulas below are the ones the engine computes, taken from the core stats module. Where a value is worth pinning down, the reference number is the one the tests assert.

The IntervalMethod default is Wilson. The three checking regimes are the fixed-sample Monte Carlo estimate, Wald's sequential probability ratio test, and the Bayesian sequential test. Each has one entry point: Monitor::check(&trace, &lifting) returns the fixed-sample SmcResult, Monitor::check_sequential(&trace, &lifting, &sprt) runs the SPRT, and Formula::check_bayesian(&trace, &lifting, &bayes) runs the Bayesian test. On the command line the same three are sentil smc with --algo smc, the default, --algo sprt, or --algo bayes; --algo chernoff sizes the run with the bound below before estimating.

Confidence intervals

For successes out of trials at confidence level level, each method returns a [lower, upper] pair clamped to [0,1][0, 1]. Write p^\hat p for the point estimate successes / trials, NN for the trial count, α=1level\alpha = 1 - \text{level}, and z=z(level)z = z(\text{level}) for the two-sided normal critical value.

MethodIntervalWhen to reach for it
Wilson (default)score interval belowthe right choice for most checks
ClopperPearsonexact binomial-tail inversioncoverage must never drop below nominal
JeffreysBeta credible intervala shorter small-sample interval
AgrestiCoulladjusted normal intervala cheap close approximation to Wilson

Wilson score

11+z2/N(p^+z22N±zp^(1p^)N+z24N2)\frac{1}{1 + z^2/N}\left(\hat p + \frac{z^2}{2N} \pm z\sqrt{\frac{\hat p(1 - \hat p)}{N} + \frac{z^2}{4N^2}}\right)

The center is pulled toward 1/21/2 and the half-width shrinks with NN, so the interval stays inside [0,1][0, 1] even at an extreme estimate. With no trials it returns the whole [0,1][0, 1] range.

Clopper-Pearson

The exact interval inverts the binomial tail through the Beta quantile function Bp(a,b)B_p(a, b), the pp-quantile of a Beta(a,b)(a, b):

lower=Bα/2(k,Nk+1),upper=B1α/2(k+1,Nk)\text{lower} = B_{\alpha/2}(k,\, N - k + 1), \qquad \text{upper} = B_{1 - \alpha/2}(k + 1,\, N - k)

with kk the success count. The lower bound is 00 when k=0k = 0 and the upper bound is 11 when k=Nk = N. Coverage never drops below the stated level, at the cost of a wider interval than Wilson.

Jeffreys

The Bayesian interval under a Beta(1/2,1/2)(1/2, 1/2) prior. The posterior is Beta(k+1/2,Nk+1/2)(k + 1/2,\, N - k + 1/2), and the bounds are its α/2\alpha/2 and 1α/21 - \alpha/2 quantiles. It holds coverage near nominal while running shorter than Clopper-Pearson, which matters most at small NN.

Agresti-Coull

Add z2/2z^2/2 pseudo-successes and z2/2z^2/2 pseudo-failures, then apply the plain normal interval to the adjusted counts:

N~=N+z2,p~=k+z2/2N~,p~±zp~(1p~)N~\tilde N = N + z^2, \qquad \tilde p = \frac{k + z^2/2}{\tilde N}, \qquad \tilde p \pm z\sqrt{\frac{\tilde p(1 - \tilde p)}{\tilde N}}

It tracks Wilson closely and is cheaper to compute. At p^=1/2\hat p = 1/2 the adjusted estimate is symmetric, so it coincides with Wilson.

The critical value

z(level)=Φ1 ⁣(12(1+level))z(\text{level}) = \Phi^{-1}\!\left(\tfrac{1}{2}(1 + \text{level})\right), the two-sided normal quantile. The inverse normal CDF is Acklam's rational approximation refined by one Halley step, accurate to about 101210^{-12}.

Reference values, asserted on every commit: wilson(50, 100, 0.95) = [0.403831, 0.596169], clopper_pearson(50, 100, 0.95) = [0.398321, 0.601679], and z(0.95) = 1.959964. Over 4000 batches of 100 draws at p=0.3p = 0.3, Wilson coverage stays within 0.030.03 of 0.950.95 and Clopper-Pearson coverage stays at or above 0.940.94.

Sizing a fixed-sample run

Two bounds answer how many samples a run needs before it starts.

The Chernoff-Hoeffding bound is distribution-free. To land within ϵ\epsilon of the true probability with confidence 1δ1 - \delta:

N=ln(2/δ)2ϵ2N = \left\lceil \frac{\ln(2/\delta)}{2\epsilon^2} \right\rceil

chernoff_hoeffding_samples(0.1, 0.05) returns 185. The parameters are ϵ>0\epsilon > 0 and δ(0,1)\delta \in (0, 1); anything else is an InvalidConfig error.

The Wilson sizing works from the interval the run will report, bounding its worst-case half-width at p^=1/2\hat p = 1/2:

N=z24ϵ2N = \left\lceil \frac{z^2}{4\epsilon^2} \right\rceil

wilson_samples(0.01, 0.95) returns 9604, roughly half the distribution-free count of 18445 for the same target.

Sequential probability ratio test

Wald's SPRT decides H0:pp0H_0: p \le p_0 against H1:pp1H_1: p \ge p_1, stopping as early as the evidence allows, often well before a fixed budget runs out. It carries a running log-likelihood ratio that starts at zero. Each satisfied draw adds lnp1lnp0\ln p_1 - \ln p_0; each unsatisfied draw adds ln(1p1)ln(1p0)\ln(1 - p_1) - \ln(1 - p_0). The two decision bounds are

A=ln1βα,B=lnβ1αA = \ln\frac{1 - \beta}{\alpha}, \qquad B = \ln\frac{\beta}{1 - \alpha}

The test accepts H1H_1 when the ratio reaches AA, accepts H0H_0 when it falls to BB, and reports Inconclusive if neither happens within max_samples. Parameters (SprtConfig): the indifference region 0<p0<p1<10 < p_0 < p_1 < 1, the error bounds α,β(0,1)\alpha, \beta \in (0, 1), the sample cap, and a seed. At p0=0.3p_0 = 0.3, p1=0.7p_1 = 0.7, α=β=0.05\alpha = \beta = 0.05, the measured Type I and Type II rates each stay at or below 0.10.1.

Bayesian sequential test

The Bayesian test decides whether pp meets a threshold θ\theta under a uniform Beta(1,1)(1, 1) prior. After ss successes in nn draws the posterior over pp is Beta(1+s,1+ns)(1 + s,\, 1 + n - s). Let the posterior mass above the threshold be π=P(pθdata)=1Iθ(1+s,1+ns)\pi = P(p \ge \theta \mid \text{data}) = 1 - I_\theta(1 + s,\, 1 + n - s), where II is the regularized incomplete beta function. The Bayes factor for H0:pθH_0: p \ge \theta against H1:p<θH_1: p < \theta divides the posterior odds by the prior odds, which under the uniform prior is (1θ)/θ(1 - \theta)/\theta:

B=π/(1π)(1θ)/θ\mathcal{B} = \frac{\pi / (1 - \pi)}{(1 - \theta)/\theta}

The test reports Holds when B\mathcal{B} reaches the configured cutoff, Fails when 1/B1/\mathcal{B} does, and Inconclusive otherwise. The comparison is cross-multiplied internally, so a posterior mass of zero is handled without dividing by it. Parameters (BayesConfig): the threshold θ(0,1)\theta \in (0, 1), a Bayes-factor cutoff greater than one, the sample cap, and a seed. A larger cutoff demands stronger evidence and spends more samples.

Adaptive multilevel splitting

For a violation probability too small for direct Monte Carlo, below roughly 10610^{-6}, the empirical estimator would need billions of samples to see a single event. Adaptive multilevel splitting advances a population of trajectory particles through nested robustness levels: at each stage the least-robust particles are discarded and the survivors are cloned, so the population stays concentrated on the paths heading toward violation. The estimate is the product of the per-level survival fractions. It runs over a StochasticSystem through Monitor::check_rare, tuned by RareEventConfig (particle count, violation margin, seed), and returns a RareEventResult with a point estimate rather than a confidence interval, since splitting produces no success-over-trials count to invert. The GPU splitting path sits behind the gpu feature.

The intuition and worked runs live in the concept pages: confidence intervals, sequential testing, and rare events. For the configuration structs, see configuration.

Edit this page on GitHub