pylfi.priors.Prior

class pylfi.priors.Prior(distr_name, *params, name=None, tex=None, **kwargs)[source]

Initialize a prior.

In the Bayesian paradigm, all available information about an unknown parameter is incorporated in a prior probability distribution, which describes the range of possible parameter values.

Parameters
distr_namestr

Any distribution from scipy.stats as a string.

params:

Parameters of the prior distribution. Typically these would be shape parameters or loc and scale passed as positional arguments.

namestr

Name of the unknown parameter, which is used to keep track and access the parameter in the sampling algorithms. Default: None.

texstr, optional

LaTeX typesetting for the parameter name. pyLFI includes procedures for automatically plotting priors and posteriors, and will use the tex name of the parameter as axis labels if provided. Default: None.

kwargs:

kwargs are passed to the scipy distribution methods. Typically these would be loc and scale.

Attributes

distr_name

Name of the scipy.stats distribution.

name

Parameter name.

tex

Parameter name with LaTeX typesetting.

Methods

logpdf(x)

Evaluate the log of the probability density function (pdf).

pdf(x)

Evaluate the probability density function (pdf).

plot_prior(x[, color, facecolor, alpha, ax])

Plot prior pdf or pmf evaluated at x.

pmf(x)

Evaluate the probability mass function (pmf).

rvs([size, seed])

Draw random variate.

rvs(size=None, seed=None)[source]

Draw random variate.

Parameters
size{int, tuple}, optional

Output size of a single random draw. Default: None.

seedint, optional

Seed for reproducibility.

Returns
rvsnumpy.ndarray

Random variables.

pdf(x)[source]

Evaluate the probability density function (pdf).

Method for continuous distributions.

Parameters
xarray_like

Evaluation points.

Returns
pdfnumpy.ndarray

pdf evaluated at x.

logpdf(x)[source]

Evaluate the log of the probability density function (pdf).

Method for continuous distributions.

Parameters
xarray_like

Evaluation points.

Returns
logpdfnumpy.ndarray

Log of pdf evaluated at x.

pmf(x)[source]

Evaluate the probability mass function (pmf).

Method for discrete distributions.

Parameters
xarray_like

Evaluation points.

Returns
pmfnumpy.ndarray

pmf evaluated at x.

property name

Parameter name.

Returns
str
property distr_name

Name of the scipy.stats distribution.

Returns
str
property tex

Parameter name with LaTeX typesetting.

Returns
str
plot_prior(x, color='C0', facecolor='lightblue', alpha=0.5, ax=None, **kwargs)[source]

Plot prior pdf or pmf evaluated at x.

Parameters
xarray_like

Evaluation points.

colorstr, optional

Set the color of the line. Default: C0.

facecolorstr, optional

Set the face color of area under the curve. Default: lightblue.

alphafloat, optional

Set the alpha value used for blending the face color. Must be within the 0-1 range. Default: 0.5.

axmatplotlib.axes.Axes, optional

Pre-existing axes for the plot. Otherwise, call matplotlib.pyplot.gca internally.

kwargs:

kwargs are passed to matplotlib.pyplot.plot.