def __init__(self, mcmc_samples, bin_edges):
"""
Histogram Inference a la Dan Foreman-Mackey
Parameters:
===========
- mcmc_samples: numpy array of shape (Nobs, Nsamples)
MCMC samples for the thing you want to histogram
- bin_edges: numpy.ndarray array
The edges of the histogram bins to use.
"""
self.mcmc_samples = mcmc_samples
self.bin_edges = bin_edges
self.bin_centers = (self.bin_edges[:-1] + self.bin_edges[1:]) / 2
self.bin_widths = np.diff(self.bin_edges)
self.Nbins = self.bin_widths.size
self.Nobs = self.mcmc_samples.shape[0]
# Find which bin each q falls in
self.bin_idx = np.digitize(self.mcmc_samples, self.bin_edges) - 1
# Determine the censoring function for each bin (used in the integral)
self.censor_integrals = np.array([quad(func=self.censoring_fcn,
a=left, b=right)[0] for (left, right) in
zip(self.bin_edges[:-1], self.bin_edges[1:])])
# Set values needed for multinest fitting
self.n_params = self.Nbins
self.param_names = [r'$\theta_{}$'.format(i) for i in range(self.Nbins)]
评论列表
文章目录