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: floatThe lower bound of the prior.
upper: floatThe upper bound of the prior.
initial_guess: float, optional, default = NoneThe expected value of the parameter.
initial_sigma: float, optional, default = NoneThe expected one-sided sigma of the initial position.
Methods
UniformPrior.from_dict(d)
Instantiates a UniformPrior from the dictionary d.
Parameters
d: dictDictionary containing key, value pairs of class parameters.
Returns
UniformPrior
Raises
TypeErrorIf any required parameter is missing or if any parameter is not of instance
intorfloat.
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: intThe number of samples to draw.
initial: bool, optional, default = TrueShould the sampled be drawn from
initial_guess +/- initial_sigma?
Returns
np.ndarray of floatorfloatDrawn sample(s) from the uniform distribution.
UniformPrior.evaluate(x)
Evaluates the uniform prior at the value x.
Parameters
x: floatThe value to evaluate.
Returns
float
0if thexis 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: floatThe mean of the distribution.
sigma: floatThe standard deviation of the distribution.
Properties
lower: floatThe lower 3-sigma bound.
upper: floatThe upper 3-sigma bound.
Methods
GaussianPrior.from_dict(d)
Instantiates a GaussianPrior from the dictionary d.
Parameters
d: dictDictionary containing key, value pairs of class parameters.
Returns
GaussianPrior
Raises
TypeErrorIf any required parameter is missing or if any parameter is not of instance
intorfloat.
GaussianPrior.draw(n)
Draws n samples from the Gaussian distribution using: np.random.normal.
Parameters
n: intThe number of samples to draw.
Returns
np.ndarray of floatorfloatDrawn sample(s) from the Gaussian distribution.\
Examples
GaussianPrior.evaluate(x)
Evaluates the Gaussian prior at the value x.
Parameters
x: float or array_likeThe value(s) to evaluate.
Returns
floatornp.ndarrayThe 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: floatThe lower 3-sigma bound.
upper: floatThe 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: dictDummy variable.
Returns
MilkyWayRvPrior
MilkyWayRvPrior.draw(n)
Draws n samples from the asymmetric Gaussian distribution.
Parameters
n: intThe number of samples to draw.
Returns
np.ndarray of floatorfloatDrawn 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_likeThe value(s) to evaluate.
norm: bool, optional, default = FalseShould the prior be normalized? Normalization is not required for maximizing likelihoods with MCMC.
Returns
floatornp.ndarrayThe value(s) of the prior evaluated at
x.
Examples
Plot the MilkyWayRvPrior distribution using the draw and evaluate methods.

Last updated