Python API

Top-Level

default_backend

NumPy backend for pyhf

default_optimizer

scipy.optimize-based Optimizer using finite differences.

tensorlib

NumPy backend for pyhf

optimizer

scipy.optimize-based Optimizer using finite differences.

get_backend()

Get the current backend and the associated optimizer

set_backend(*args, **kwargs)

Probability Distribution Functions (PDFs)

Normal

The Normal distribution with mean loc and standard deviation scale.

Poisson

The Poisson distribution with rate parameter rate.

Independent

A probability density corresponding to the joint distribution of a batch of identically distributed random variables.

Simultaneous

A probability density corresponding to the joint distribution of multiple non-identical component distributions

Making Models from PDFs

Model

The main pyhf model class.

_ModelConfig

Workspace

A JSON-serializable object that is built from an object that follows the workspace.json schema.

Backends

The computational backends that pyhf provides interfacing for the vector-based calculations.

numpy_backend.numpy_backend

NumPy backend for pyhf

pytorch_backend.pytorch_backend

PyTorch backend for pyhf

tensorflow_backend.tensorflow_backend

TensorFlow backend for pyhf

Optimizers

opt_pytorch.pytorch_optimizer

PyTorch Optimizer Backend.

opt_scipy.scipy_optimizer

scipy.optimize-based Optimizer using finite differences.

opt_tflow.tflow_optimizer

Tensorflow Optimizer Backend.

opt_minuit.minuit_optimizer

MINUIT Optimizer Backend.

Interpolators

code0

The piecewise-linear interpolation strategy.

code1

The piecewise-exponential interpolation strategy.

code2

The quadratic interpolation and linear extrapolation strategy.

code4

The polynomial interpolation and exponential extrapolation strategy.

code4p

The piecewise-linear interpolation strategy, with polynomial at \(\left|a\right| < 1\).

Inference

hypotest(poi_test, data, pdf[, init_pars, …])

Compute \(p\)-values and test statistics for a single value of the parameter of interest.

test_statistics.qmu(mu, data, pdf, …)

The test statistic, \(q_{\mu}\), for establishing an upper limit on the strength parameter, \(\mu\), as defiend in Equation (14) in [1007.1727].

mle.twice_nll(pars, data, pdf)

Twice the negative Log-Likelihood.

mle.fit(data, pdf[, init_pars, par_bounds])

Run a unconstrained maximum likelihood fit.

mle.fixed_poi_fit(poi_val, data, pdf[, …])

Run a maximum likelihood fit with the POI value fixzed.

utils.generate_asimov_data(asimov_mu, data, …)

Compute Asimov Dataset (expected yields at best-fit values) for a given POI value.

utils.pvals_from_teststat(sqrtqmu_v, sqrtqmuA_v)

Compute p-values from test-statistic values.

utils.pvals_from_teststat_expected(sqrtqmuA_v)

Compute the expected \(p\)-values CLsb, CLb and CLs for data corresponding to a given percentile of the alternate hypothesis.

Exceptions

Various exceptions, apart from standard python exceptions, that are raised from using the pyhf API.

InvalidMeasurement

InvalidMeasurement is raised when a specified measurement is invalid given the specification.

InvalidNameReuse

InvalidSpecification

InvalidSpecification is raised when a specification does not validate against the given schema.

InvalidWorkspaceOperation

InvalidWorkspaceOperation is raised when an operation on a workspace fails.

InvalidModel

InvalidModel is raised when a given model does not have the right configuration, even though it validates correctly against the schema.

InvalidModifier

InvalidModifier is raised when an invalid modifier is requested.

InvalidInterpCode

InvalidInterpCode is raised when an invalid/unimplemented interpolation code is requested.

ImportBackendError

MissingLibraries is raised when something is imported by sustained an import error due to missing additional, non-default libraries.

InvalidOptimizer

InvalidOptimizer is raised when trying to set an optimizer that does not exist.

InvalidPdfParameters

InvalidPdfParameters is raised when trying to evaluate a pdf with invalid parameters.

InvalidPdfData

InvalidPdfData is raised when trying to evaluate a pdf with invalid data.

Utilities

load_schema(schema_id[, version])

validate(spec, schema_name[, version])

options_from_eqdelimstring(opts)