Priors

Classes for MCMC priors.

UniformPrior

class UniformPrior(lower, upper, initial_guess=None, initial_sigma=None)

Any value evaluated within the bounds (inclusive) are considered equally probable such that when evaluated they return 0. Any value evaluated outside the bounds are considered impossible such that when evaluated they return -inf.

Optional initial parameters are useful when there is an expected value or distribution within the wider uniform bounds. Defining the initial parameters allows for setting the initial positions of the walkers near the likely value while not preventing the walkers from exploring outside of the initial position (but not beyond the lower and upper bounds).

Parameters

lower: float

The lower bound of the prior.

upper: float

The upper bound of the prior.

initial_guess: float, optional, default = None

The expected value of the parameter.

initial_sigma: float, optional, default = None

The expected one-sided sigma of the initial position.

Methods

UniformPrior.from_dict(d)

Instantiates a UniformPrior from the dictionary d.

Parameters

d: dict

Dictionary containing key, value pairs of class parameters.

Returns

UniformPrior

Raises

TypeError

If any required parameter is missing or if any parameter is not of instance int or float.


UniformPrior.draw(n, initial=True)

Draws n samples from the uniform distribution.

Draws from initial_guess +/- initial_sigma if they are both defined. Else, draws between lower and upper.

Parameters

n: int

The number of samples to draw.

initial: bool, optional, default = True

Should the sampled be drawn from initial_guess +/- initial_sigma?

Returns

np.ndarray of float or float

Drawn sample(s) from the uniform distribution.


UniformPrior.evaluate(x)

Evaluates the uniform prior at the value x.

Parameters

x: float

The value to evaluate.

Returns

float

0 if the x is within the bounds else -np.inf.

Examples


GaussianPrior

class GaussianPrior(mu, sigma)

Prior following a normal distribution centered on mu with standard deviation sigma.

Parameters

mu: float

The mean of the distribution.

sigma: float

The standard deviation of the distribution.

Properties

lower: float

The lower 3-sigma bound.

upper: float

The upper 3-sigma bound.


Methods

GaussianPrior.from_dict(d)

Instantiates a GaussianPrior from the dictionary d.

Parameters

d: dict

Dictionary containing key, value pairs of class parameters.

Returns

GaussianPrior

Raises

TypeError

If any required parameter is missing or if any parameter is not of instance int or float.


GaussianPrior.draw(n)

Draws n samples from the Gaussian distribution using: np.random.normal.

Parameters

n: int

The number of samples to draw.

Returns

np.ndarray of float or float

Drawn sample(s) from the Gaussian distribution.\

Examples


GaussianPrior.evaluate(x)

Evaluates the Gaussian prior at the value x.

Parameters

x: float or array_like

The value(s) to evaluate.

Returns

float or np.ndarray

The value(s) of the prior evaluated at x. Includes the normalization constant.


MilkyWayRvPrior

class MilkyWayRvPrior()

Asymmetric Gaussian prior on the Milk Way Rv distribution. Defined in The Gamma-Ray Burst Afterglow Modeling Project: Foundational Statistics and Absorption & Extinction Models (Trotter, 2011), pg. 108.

Attributes

mu: float = 0.4150

sigma_low: float = 0.00779

sigma_high: float = 0.09074

Properties

lower: float

The lower 3-sigma bound.

upper: float

The upper 3-sigma bound.


Methods

MilkyWayRvPrior.from_dict(d)

Instantiates a MilkyWayRvPrior. All required values are fixed. This method takes a dict only for compatibility reasons within the MCMC routine.

Parameters

d: dict

Dummy variable.

Returns

MilkyWayRvPrior


MilkyWayRvPrior.draw(n)

Draws n samples from the asymmetric Gaussian distribution.

Parameters

n: int

The number of samples to draw.

Returns

np.ndarray of float or float

Drawn sample(s) from the asymmetric Gaussian distribution.

Examples


MilkyWayRvPrior.evaluate(x, norm=False)

Evaluates the Gaussian prior at the value x.

Parameters

x: float or array_like

The value(s) to evaluate.

norm: bool, optional, default = False

Should the prior be normalized? Normalization is not required for maximizing likelihoods with MCMC.

Returns

float or np.ndarray

The value(s) of the prior evaluated at x.

Examples

Plot the MilkyWayRvPrior distribution using the draw and evaluate methods.


Last updated