Exemple #1
0
    def figure(self):
        fig, ax = self._new_plot()
        opt = self.plot_options
        summary = []

        # Best-fit point
        best_fit_x = stats.best_fit(self.chisq, self.xdata)
        best_fit_y = stats.best_fit(self.chisq, self.ydata)
        summary.append("Best-fit point (x,y): {}, {}".format(best_fit_x, best_fit_y))
        if opt.show_best_fit:
            pm.plot_data(best_fit_x, best_fit_y, schemes.best_fit)

        # Posterior mean
        posterior_mean_x = stats.posterior_mean(self.posterior, self.xdata)
        posterior_mean_y = stats.posterior_mean(self.posterior, self.ydata)
        summary.append("Posterior mean (x,y): {}, {}".format(posterior_mean_x, posterior_mean_y))
        if opt.show_posterior_mean:
            pm.plot_data(posterior_mean_x, posterior_mean_y, schemes.posterior_mean)

        # Profile likelihood
        prof_data = two_dim.profile_like(
                self.xdata,
                self.ydata,
                self.chisq,
                nbins=opt.nbins,
                bin_limits=opt.bin_limits)

        if opt.show_prof_like:
            pm.plot_image(
                    prof_data.prof_like,
                    opt.bin_limits,
                    opt.plot_limits,
                    schemes.prof_like)

        levels = [two_dim.critical_prof_like(aa) for aa in opt.alpha]

        if opt.show_conf_intervals:
            pm.plot_contour(
                    prof_data.prof_like,
                    levels,
                    schemes.prof_like,
                    bin_limits=opt.bin_limits)

        # Add legend
        pm.legend(opt.leg_title, opt.leg_position)

        return self.plot_data(figure=fig, summary=summary)
Exemple #2
0
    def figure(self):
        fig, ax = self._new_plot()
        opt = self.plot_options
        summary = []

        # Best-fit point
        best_fit_x = stats.best_fit(self.chisq, self.xdata)
        best_fit_y = stats.best_fit(self.chisq, self.ydata)
        summary.append("Best-fit point (x,y): {}, {}".format(
            best_fit_x, best_fit_y))
        if opt.show_best_fit:
            pm.plot_data(best_fit_x, best_fit_y, schemes.best_fit)

        # Posterior mean
        posterior_mean_x = stats.posterior_mean(self.posterior, self.xdata)
        posterior_mean_y = stats.posterior_mean(self.posterior, self.ydata)
        summary.append("Posterior mean (x,y): {}, {}".format(
            posterior_mean_x, posterior_mean_y))
        if opt.show_posterior_mean:
            pm.plot_data(posterior_mean_x, posterior_mean_y,
                         schemes.posterior_mean)

        # Profile likelihood
        prof_data = two_dim.profile_like(self.xdata,
                                         self.ydata,
                                         self.chisq,
                                         nbins=opt.nbins,
                                         bin_limits=opt.bin_limits)

        if opt.show_prof_like:
            pm.plot_image(prof_data.prof_like, opt.bin_limits, opt.plot_limits,
                          schemes.prof_like)

        levels = [two_dim.critical_prof_like(aa) for aa in opt.alpha]

        if opt.show_conf_intervals:
            pm.plot_contour(prof_data.prof_like,
                            levels,
                            schemes.prof_like,
                            bin_limits=opt.bin_limits)

        # Add legend
        pm.legend(opt.leg_title, opt.leg_position)

        return self.plot_data(figure=fig, summary=summary)
Exemple #3
0
    def figure(self):
        fig, ax = self._new_plot()
        opt = self.plot_options
        summary = []

        # Best-fit point
        best_fit_x = stats.best_fit(self.chisq, self.xdata)
        best_fit_y = stats.best_fit(self.chisq, self.ydata)
        summary.append("Best-fit point (x,y): {}, {}".format(
            best_fit_x, best_fit_y))
        if opt.show_best_fit:
            pm.plot_data(best_fit_x, best_fit_y, schemes.best_fit)

        # Posterior mean
        posterior_mean_x = stats.posterior_mean(self.posterior, self.xdata)
        posterior_mean_y = stats.posterior_mean(self.posterior, self.ydata)
        summary.append("Posterior mean (x,y): {}, {}".format(
            posterior_mean_x, posterior_mean_y))
        if opt.show_posterior_mean:
            pm.plot_data(posterior_mean_x, posterior_mean_y,
                         schemes.posterior_mean)

        # Plot scatter of points.
        sc = plt.scatter(self.xdata,
                         self.ydata,
                         s=schemes.scatter.size,
                         c=self.zdata,
                         marker=schemes.scatter.symbol,
                         cmap=schemes.scatter.colour_map,
                         norm=None,
                         vmin=None,
                         vmax=None,
                         alpha=0.5,
                         linewidths=None,
                         verts=None)

        # Plot a colour bar
        cb = plt.colorbar(sc, orientation='horizontal', shrink=0.5)
        # Colour bar label
        cb.ax.set_xlabel(opt.zlabel)
        # Set reasonable number of ticks
        cb.locator = MaxNLocator(4)
        cb.update_ticks()

        # Credible regions
        pdf_data = two_dim.posterior_pdf(self.xdata,
                                         self.ydata,
                                         self.posterior,
                                         nbins=opt.nbins,
                                         bin_limits=opt.bin_limits)

        levels = [
            two_dim.critical_density(pdf_data.pdf, aa) for aa in opt.alpha
        ]

        # Make sure pdf is correctly normalised
        pdf = pdf_data.pdf
        pdf = pdf / pdf.sum()

        if opt.show_credible_regions:
            pm.plot_contour(pdf,
                            levels,
                            schemes.posterior,
                            bin_limits=opt.bin_limits)

        # Confidence interval
        prof_data = two_dim.profile_like(self.xdata,
                                         self.ydata,
                                         self.chisq,
                                         nbins=opt.nbins,
                                         bin_limits=opt.bin_limits)

        levels = [two_dim.critical_prof_like(aa) for aa in opt.alpha]

        if opt.show_conf_intervals:
            pm.plot_contour(prof_data.prof_like,
                            levels,
                            schemes.prof_like,
                            bin_limits=opt.bin_limits)

        # Add legend
        pm.legend(opt.leg_title, opt.leg_position)

        return self.plot_data(figure=fig, summary=summary)
Exemple #4
0
    def figure(self):
        fig, ax = self._new_plot()
        opt = self.plot_options
        summary = []

        # Best-fit point
        best_fit_x = stats.best_fit(self.chisq, self.xdata)
        best_fit_y = stats.best_fit(self.chisq, self.ydata)
        summary.append("Best-fit point (x,y): {}, {}".format(best_fit_x, best_fit_y))
        if opt.show_best_fit:
            pm.plot_data(best_fit_x, best_fit_y, schemes.best_fit)

        # Posterior mean
        posterior_mean_x = stats.posterior_mean(self.posterior, self.xdata)
        posterior_mean_y = stats.posterior_mean(self.posterior, self.ydata)
        summary.append("Posterior mean (x,y): {}, {}".format(posterior_mean_x, posterior_mean_y))
        if opt.show_posterior_mean:
            pm.plot_data(posterior_mean_x, posterior_mean_y, schemes.posterior_mean)

        # Plot scatter of points.
        sc = plt.scatter(
                self.xdata,
                self.ydata,
                s=schemes.scatter.size,
                c=self.zdata,
                marker=schemes.scatter.symbol,
                cmap=schemes.scatter.colour_map,
                norm=None,
                vmin=None,
                vmax=None,
                alpha=0.5,
                linewidths=None,
                verts=None)

        # Plot a colour bar
        cb = plt.colorbar(sc, orientation='horizontal', shrink=0.5)
        # Colour bar label
        cb.ax.set_xlabel(opt.zlabel)
        # Set reasonable number of ticks
        cb.locator = MaxNLocator(4)
        cb.update_ticks()

        # Credible regions
        pdf_data = two_dim.posterior_pdf(
                self.xdata,
                self.ydata,
                self.posterior,
                nbins=opt.nbins,
                bin_limits=opt.bin_limits)

        levels = [two_dim.critical_density(pdf_data.pdf, aa) for aa in opt.alpha]

        # Make sure pdf is correctly normalised
        pdf = pdf_data.pdf
        pdf = pdf / pdf.sum()

        if opt.show_credible_regions:
            pm.plot_contour(
                    pdf,
                    levels,
                    schemes.posterior,
                    bin_limits=opt.bin_limits)

        # Confidence interval        
        prof_data = two_dim.profile_like(
                self.xdata,
                self.ydata,
                self.chisq,
                nbins=opt.nbins,
                bin_limits=opt.bin_limits)

        levels = [two_dim.critical_prof_like(aa) for aa in opt.alpha]

        if opt.show_conf_intervals:
            pm.plot_contour(
                    prof_data.prof_like,
                    levels,
                    schemes.prof_like,
                    bin_limits=opt.bin_limits)

        # Add legend
        pm.legend(opt.leg_title, opt.leg_position)

        return self.plot_data(figure=fig, summary=summary)