prophys.engine

prophys.engine#

Compiled models, fitting, operational surrogates and diagnostics.

CompiledModel (from ProbabilityModel.compile() or compile_model()) is the evaluation interface of a model: log densities, samples, expectations, probabilities, quantiles and tail risk of any attribute. Around it:

The diagnostic result classes are frozen dataclasses deriving from Report, with a readable str() and a JSON ready to_dict().

Classes

CompiledModel

A probability model compiled into an evaluation interface that works with jax.jit and jax.grad.

CalibrationResult

Result of calibrate(), finetune() or fit_distribution().

OptimizationResult

Result of a design optimization with optimize().

OperationalSurrogate

A trained surrogate of a whole model's predictive distribution, with guarded fallback.

OperationalAnswer

Answers to a batch of queries from OperationalSurrogate.answer().

Guard

Gate values per row of a batch of queries, from OperationalSurrogate.guard().

AmortizationCard

Training and acceptance record of an OperationalSurrogate.

BreakEvenEstimate

Whether amortizing a model pays off, from measured or estimated costs.

Report

Base class of every diagnostic result in prophys.engine.

EstimateWithError

A Monte Carlo estimate of a mean, probability or quantile with its sampling error.

TailRiskEstimate

Value at Risk and Conditional Value at Risk estimates with the CVaR's standard error.

ParameterUncertainty

Standard errors, covariance and correlations of fitted parameters (Laplace approximation).

DerivedUncertainty

Delta method standard errors of a quantity derived from the fitted parameters.

ProfileLikelihood

Profile log likelihood of one parameter with its likelihood ratio interval.

LocalSensitivity

Derivatives and elasticities of one model statistic with respect to the parameters.

SobolSensitivity

First order and total order Sobol indices of an attribute over its uncertain inputs.

InformationCriteria

Information criteria (AIC, AICc and BIC) of a fitted model, from information_criteria().

PredictiveScore

Expected log predictive density estimated by WAIC or PSIS LOO, from waic() or loo().

ModelComparison

Ranking of models by a predictive score, with each model's difference from the best.

CalibrationReport

Probability integral transform (PIT) calibration of a predictive distribution.

CrpsScore

Continuous ranked probability score (CRPS) of a predictive distribution, from crps().

PosteriorPredictiveCheck

Posterior predictive check of one summary statistic, from posterior_predictive_check().

Functions

compile_model

Compile a probability model.

calibrate

Fit the parameters of a compiled model to observations of one attribute.

finetune

Jointly fit a compiled model against observations of several attributes.

fit_distribution

Fit the Param leaves of a standalone distribution to data by maximum likelihood.

optimize

Minimize a scalar objective over design parameters, with inequality constraints.

amortize

Train an operational surrogate of one attribute's predictive distribution over an envelope.

break_even

Estimate whether amortizing an attribute pays off, before training anything.

finite_difference_check

Compare the automatic gradient of fn against central finite differences.

check_identifiability

Check whether a loss history is still improving at the end of a fit.

confidence_interval

Confidence interval estimate +/- z * std_error from normal theory.

assess

Estimate a statistic of a model attribute together with its Monte Carlo error.

mean_error

Sample mean of draws with its batch means standard error.

quantile_error

Sample q quantile of draws with its Maritz and Jarrett standard error.

cvar_error

Upper tail CVaR of draws at level alpha, with its influence function error.

required_samples

Number of draws needed to reach a target relative error, extrapolated from an estimate.

negative_log_likelihood

Build the negative log likelihood that finetune() minimizes.

laplace_covariance

Laplace (observed information) covariance of parameters at the minimum of a loss.

parameter_uncertainty

Compute standard errors and correlations of a fit's parameters (Laplace approximation).

propagate

Propagate parameter uncertainty into a derived quantity by the delta method.

profile_likelihood

Profile the log likelihood in one parameter and read off its likelihood ratio interval.

local_sensitivity

Compute derivatives and elasticities of a model statistic with respect to its parameters.

sobol_sensitivity

Compute variance based (Sobol) sensitivity indices of an attribute to its uncertain inputs.

sample_parameters

Draw parameter vectors from the Laplace (Gaussian) approximation of the fit.

pointwise_log_likelihood

Log likelihood of every observation under every parameter draw.

information_criteria

Compute AIC, AICc and BIC for a fit of a compiled model to observations.

waic

Score predictive accuracy with the Widely Applicable Information Criterion (WAIC).

loo

Estimate leave one out predictive accuracy by Pareto smoothed importance sampling (PSIS LOO).

compare

Rank models by predictive score, with the standard error of each difference.

calibration

Test whether the predictive distribution is calibrated against observations (PIT).

crps

Score the predictive distribution with the continuous ranked probability score (CRPS).

posterior_predictive_check

Compare a summary statistic of the data against replicate datasets simulated from the model.

report_card

Run every applicable goodness of fit diagnostic for one fitted attribute.

Constants and objects

FALLBACK_REASONS

Built-in immutable sequence.