Prior Distributions#
Priors in Lightning are built around two base classes: AnalyticPrior for
priors with a functional form and TabulatedPrior for empirically derived
priors. New user-specific priors can be added by defining classes that inherit
from one of these base classes and define the evaluate, quantile, and sample
methods.
In the course of normal use, the sample method is the only one likely to be used regularly,
in initializing the mcmc.
- class lightning.priors.base.AnalyticPrior#
Base class for priors with a functional form.
Need only be overwritten if there’s specific requirements for the prior parameters (i.e. b > a for the uniform prior).
Methods
evaluate(x)This function must be overwritten by each specific prior, implementing the PDF.
quantile(q)This function must be overwritten by each specific prior, implementing the quantile function/PPF (the inverse of the CDF).
sample(size[, rng, seed])Sample from the prior.
- __init__(params)#
- __new__(*args, **kwargs)#
- evaluate(x)#
This function must be overwritten by each specific prior, implementing the PDF.
- quantile(q)#
This function must be overwritten by each specific prior, implementing the quantile function/PPF (the inverse of the CDF).
- sample(size, rng=None, seed=None)#
Sample from the prior.
- Parameters:
- sizeint
Number of samples to draw
- rngnumpy.random.Generator
Numpy object for random number generation; see
numpy.random.default_rng()- seedint
Seed for random number generation. If you pass a pre-constructed generator this is ignored.
- Returns:
- samplesnumpy array
Random samples
- class lightning.priors.base.TabulatedPrior#
Base class for tabulated priors.
Keywords are passed on to scipy.interpolate.interp1d.
Methods
evaluate(x)Evaluate the scipy.interpolate.interp1d object representing the PDF on
x.quantile(q)Evaluate the scipy.interpolate.interp1d object representing the quantile function on
q.sample(size[, rng, seed])Sample from the prior.
- __init__(x, y, **kwargs)#
- __new__(*args, **kwargs)#
- evaluate(x)#
Evaluate the scipy.interpolate.interp1d object representing the PDF on
x.
- quantile(q)#
Evaluate the scipy.interpolate.interp1d object representing the quantile function on
q.
- sample(size, rng=None, seed=None)#
Sample from the prior.
- Parameters:
- sizeint
Number of samples to draw
- rngnumpy.random.Generator
Numpy object for random number generation; see
numpy.random.default_rng()- seedint
Seed for random number generation. If you pass a pre-constructed generator this is ignored.
- Returns:
- samplesnumpy array
Random samples
The UniformPrior and NormalPrior classes inherent from AnalyticPrior and
define the uniform and normal distributions, respectively.
- class lightning.priors.UniformPrior#
Bases:
AnalyticPriorUniform prior. Parameters are lower bound a and upper bound b, in that order.
PDF:
\[\begin{split}p(x) = \begin{cases} \frac {1} {b - a} &, ~x \in [a, b) \\ 0 &,~{\rm otherwise} \end{cases}\end{split}\]Quantile function:
\[x(q) = q (b - a) + a\]- __init__(params)#
- __new__(*args, **kwargs)#
- class lightning.priors.NormalPrior#
Bases:
AnalyticPriorNormal prior. Parameters are mu and sigma, in that order.
PDF:
\[p(x) = \frac{1}{\sigma \sqrt{2 \pi}} \exp[- \frac{(x - \mu)^2}{\sigma^2}]\]Quantile function:
\[x(q) = \mu + \sigma \sqrt{2} {\rm erfinv}(2q - 1)\]- __init__(params)#
- __new__(*args, **kwargs)#
Constant parameters in Lightning can be fixed to a single value using the ConstantPrior,
which implements a delta-function-like prior. In practice this isn’t a true prior, but it
tells Lightning not to bother sampling the given parameter and what its value should be.
- class lightning.priors.ConstantPrior#
Bases:
AnalyticPriorDelta function prior. The single parameter is value a.
PDF:
\[\begin{split}p(x) = \begin{cases} 1 &, x = a \\ 0 &, {\rm otherwise} \end{cases}\end{split}\]Quantile function:
\[x(q) = a \forall q\]Holding a parameter constant is not really a prior so much as a reduction in the dimensionality of the problem, so this is basically a dummy prior, which tells the sampler to hold a parameter constant and what its value should be.
- __init__(params)#
- __new__(*args, **kwargs)#