Exemple #1
0
    def __init__(self, input_file):
        # Load info
        self.info = info(input_file)
        # Setup likelihood
        self.likelihood = likelihood_dict(self.info["likelihoods"])

        # DEBUG
        from plots import plot_likelihood_pdf
        plot_likelihood_pdf(self.likelihood, self.info["params"])
        
        # Setup samples_set and sampler
        self.samples = samples_set(self.info["params"])
        self.sampler = initialise_sampler(self.likelihood.loglik,
                                          lambda x: 1,
                                          self.samples, self.info["params"],
                                          self.info["sampler"],
                                          self.show_updated_info)

        # Room for parallelisation
#        n_processes = 1
#        n_times_pool = 2

        # Fire sampler
        status = self.sampler.run()

        self.final_report()
        return
Exemple #2
0
    def show_updated_info(self):
        import matplotlib.pyplot as plt
        fig = plt.figure()
        ax = fig.add_subplot(111)      
        x = self.samples.params[:self.samples.n_samples][:,0]
        import numpy as np
        t = np.exp(self.samples.logliks[:self.samples.n_samples])
        lims = [(p["prior"]["min"], p["prior"]["max"]) for p in self.info["params"]]
        plt.xlim()
        plt.plot(x, t, "o")
        from plots import plot_likelihood_pdf
        plot_likelihood_pdf(self.likelihood, self.info["params"], ax=ax, show=False)
        # grf prediction
        xpred = np.linspace(sorted(x)[0], sorted(x)[-1], 400)
        xpred = np.linspace(lims[0][0], lims[0][1], 400)
#        tpred = self.sampler.posterior_expected(xpred)
#        spred = np.sqrt(self.sampler.posterior_covariance(xpred))
#        plt.plot(xpred, tpred, "-", color="red")
#        plt.plot(xpred, tpred+2*spred, ":", color="red")
#        plt.plot(xpred, tpred-2*spred, ":", color="red")
        plt.show()