def _summary(name, param, posterior, chi_sq): """ Find summary statistics for a single parameter. :param name: Name of parameter :type name: string :param param: Data column of parameter :type param: :param posterior: :type posterior: :param chi_sq: :type chi_sq: :returns: List of summary statistics for a particular parameter :rtype: list """ # Best-fit point bestfit = stats.best_fit(chi_sq, param) # Posterior mean post_mean = stats.posterior_mean(posterior, param) # Credible regions pdf_data = one_dim.posterior_pdf(param, posterior, nbins=default("nbins"), bin_limits=default("bin_limits") ) lower_credible_region = one_dim.credible_region(pdf_data.pdf, pdf_data.bin_centers, alpha=default("alpha")[1], region="lower") upper_credible_region = one_dim.credible_region(pdf_data.pdf, pdf_data.bin_centers, alpha=default("alpha")[1], region="upper") summary = [name, bestfit, post_mean, lower_credible_region, upper_credible_region ] return summary
def __init__(self, data, plot_options): super(OneDimPlot, self).__init__(data, plot_options) opt = self.plot_options # If the user didn't specify bin or plot limits, # we find the extent of the data and use that to set them. extent = np.zeros(4) extent[0] = min(self.xdata) extent[1] = max(self.xdata) extent[2] = 0 extent[3] = 1.2 # Downside of using named tuple is they're immutable # so changing options is (justifiably) annoying. # If this happens a lot (it shouldn't), consider # using a mutable type instead... if self.plot_options.bin_limits is None: self.plot_options = self.plot_options._replace( bin_limits=[extent[0], extent[1]]) if self.plot_options.plot_limits is None: self.plot_options = self.plot_options._replace(plot_limits=extent) # Posterior PDF. Norm by area if not showing profile likelihood, # otherwise norm max value to one. if opt.kde_pdf: # KDE estimate of PDF self.pdf_data = one_dim.kde_posterior_pdf( self.xdata, self.posterior, bin_limits=opt.bin_limits, norm_area=not opt.show_prof_like, bw_method=opt.bw_method) else: # Binned estimate of PDF self.pdf_data = one_dim.posterior_pdf( self.xdata, self.posterior, nbins=opt.nbins, bin_limits=opt.bin_limits, norm_area=not opt.show_prof_like) # Profile likelihood self.prof_data = one_dim.prof_data(self.xdata, self.chisq, nbins=opt.nbins, bin_limits=opt.bin_limits) # Note the best-fit point is calculated using the raw data, # while the mean, median and mode use the binned PDF. # Best-fit point self.best_fit = stats.best_fit(self.chisq, self.xdata) self.summary.append("Best-fit point: {}".format(self.best_fit)) # Posterior mean self.posterior_mean = stats.posterior_mean(*self.pdf_data) self.summary.append("Posterior mean: {}".format(self.posterior_mean)) # Posterior median self.posterior_median = one_dim.posterior_median(*self.pdf_data) self.summary.append("Posterior median: {}".format( self.posterior_median)) # Posterior mode self.posterior_modes = one_dim.posterior_mode(*self.pdf_data) self.summary.append("Posterior mode/s: {}".format( self.posterior_modes))
def __init__(self, data, plot_options): super(OneDimPlot, self).__init__(data, plot_options) opt = self.plot_options # If the user didn't specify bin or plot limits, # we find the extent of the data and use that to set them. extent = np.zeros(4) extent[0] = min(self.xdata) extent[1] = max(self.xdata) extent[2] = 0 extent[3] = 1.2 # Downside of using named tuple is they're immutable # so changing options is (justifiably) annoying. # If this happens a lot (it shouldn't), consider # using a mutable type instead... if self.plot_options.bin_limits is None: self.plot_options = self.plot_options._replace(bin_limits=[extent[0], extent[1]]) if self.plot_options.plot_limits is None: self.plot_options = self.plot_options._replace(plot_limits=extent) # Posterior PDF. Norm by area if not showing profile likelihood, # otherwise norm max value to one. if opt.kde_pdf: # KDE estimate of PDF self.pdf_data = one_dim.kde_posterior_pdf( self.xdata, self.posterior, bin_limits=opt.bin_limits, norm_area=not opt.show_prof_like, bw_method=opt.bw_method, ) else: # Binned estimate of PDF self.pdf_data = one_dim.posterior_pdf( self.xdata, self.posterior, nbins=opt.nbins, bin_limits=opt.bin_limits, norm_area=not opt.show_prof_like ) # Profile likelihood self.prof_data = one_dim.prof_data(self.xdata, self.chisq, nbins=opt.nbins, bin_limits=opt.bin_limits) # Note the best-fit point is calculated using the raw data, # while the mean, median and mode use the binned PDF. # Best-fit point self.best_fit = stats.best_fit(self.chisq, self.xdata) self.summary.append("Best-fit point: {}".format(self.best_fit)) # Posterior mean self.posterior_mean = stats.posterior_mean(*self.pdf_data) self.summary.append("Posterior mean: {}".format(self.posterior_mean)) # Posterior median self.posterior_median = one_dim.posterior_median(*self.pdf_data) self.summary.append("Posterior median: {}".format(self.posterior_median)) # Posterior mode self.posterior_modes = one_dim.posterior_mode(*self.pdf_data) self.summary.append("Posterior mode/s: {}".format(self.posterior_modes))