This pull request adds a new file priors.py to approxposterior. It defines the Prior base class, which is subclassed to create the UniformPrior and GaussianPrior classes (demonstrated below). Other priors can easily be implemented following these as examples. Note that other than importing this code in the __init__.py, object-oriented priors have not yet been implemented into approxposterior.
As is, the code should be able to reproduce the following example (also included in the doc-strings of this module):
from approxposterior.priors import UniformPrior, GaussianPrior
# Number of numerical samples
N=10000
# Define prior distributions
u = UniformPrior(0.0, 100.0)
g = GaussianPrior(50.0, 10.0)
# Plot histograms
plt.hist(u.random_sample(N), bins = 100, density=True, alpha = 0.5, color="C0");
plt.hist(g.random_sample(N), bins = 100, density=True, alpha = 0.5, color="C1");
# Plot the analytic density
xmin, xmax = plt.xlim();
x = np.linspace(xmin, xmax, 1000);
plt.plot(x, u.dist.pdf(x), c="C0", lw = 3.0, label="uniform")
plt.plot(x, g.dist.pdf(x), c="C1", lw = 3.0, label="normal")
# Tweak plot style
plt.xlabel(r"$x$")
plt.ylabel(r"Prior Probability Density, $\mathcal{P}(x)$")
plt.legend(framealpha=0.0)
This pull request adds a new file
priors.py
toapproxposterior
. It defines thePrior
base class, which is subclassed to create theUniformPrior
andGaussianPrior
classes (demonstrated below). Other priors can easily be implemented following these as examples. Note that other than importing this code in the__init__.py
, object-oriented priors have not yet been implemented intoapproxposterior
.As is, the code should be able to reproduce the following example (also included in the doc-strings of this module):