Esempio n. 1
0
    def cornerbound(self, **kwargs):

        dyplot.cornerbound(results=self.samples.results,
                           labels=self.model.parameter_labels_latex,
                           **kwargs)

        self.output.to_figure(structure=None, auto_filename="cornerbound")
Esempio n. 2
0
    def cornerbound(self, **kwargs):

        if conf.instance["general"]["test"]["test_mode"]:
            return None

        dyplot.cornerbound(results=self.samples.results,
                           labels=self.model.parameter_labels_latex,
                           **kwargs)

        self.output.to_figure(structure=None, auto_filename="cornerbound")
        self.mat_plot_1d.figure.close()
Esempio n. 3
0
def test_gaussian():
    logz_tol = 1
    sampler = dynesty.NestedSampler(loglikelihood_gau,
                                    prior_transform_gau,
                                    ndim_gau,
                                    nlive=nlive)
    sampler.run_nested(print_progress=printing)

    # add samples
    # check continuation behavior
    sampler.run_nested(dlogz=0.1, print_progress=printing)

    # get errors
    nerr = 2
    for i in range(nerr):
        sampler.reset()
        sampler.run_nested(print_progress=False)
        results = sampler.results
        pos = results.samples
        wts = np.exp(results.logwt - results.logz[-1])
        mean, cov = dyfunc.mean_and_cov(pos, wts)
        logz = results.logz[-1]
        assert (np.abs(logz - logz_truth_gau) < logz_tol)
    # check summary
    res = sampler.results
    res.summary()

    # check plots
    dyplot.runplot(sampler.results)
    plt.close()
    dyplot.traceplot(sampler.results)
    plt.close()
    dyplot.cornerpoints(sampler.results)
    plt.close()
    dyplot.cornerplot(sampler.results)
    plt.close()
    dyplot.boundplot(sampler.results,
                     dims=(0, 1),
                     it=3000,
                     prior_transform=prior_transform_gau,
                     show_live=True,
                     span=[(-10, 10), (-10, 10)])
    plt.close()
    dyplot.cornerbound(sampler.results,
                       it=3500,
                       prior_transform=prior_transform_gau,
                       show_live=True,
                       span=[(-10, 10), (-10, 10)])
    plt.close()
def plot_status(res, labels=None, periodic=None):
    # Generate a plot of the trace.

    try:
        fig, ax = dyplot.traceplot(res, show_titles=True, trace_cmap="viridis",\
                connect=True, connect_highlight=range(5), labels=labels)
    except:
        # If it hasn't converged enough...
        fig, ax = dyplot.traceplot(res, show_titles=True, trace_cmap="viridis",\
                connect=True, connect_highlight=range(5), labels=labels, \
                kde=False)

    fig.savefig("traceplot.png")

    plt.close(fig)

    # Generate a bounds cornerplot.

    fig, ax = dyplot.cornerbound(res, it=res.niter-1, periodic=periodic, \
            prior_transform=sampler.prior_transform, show_live=True, \
            labels=labels)

    fig.savefig("boundplot.png")

    plt.close(fig)
Esempio n. 5
0
 def cornerbound(self, figsize=(10,10), labels=None):
     
     fig, axes = plt.subplots(self.ndim-1, self.ndim-1,
                              figsize=figsize)
     
     fg, ax = dyplot.cornerbound(self.results, it=1000, labels=labels,
                                 prior_transform=self.prior_tf,
                                 show_live=True, fig=(fig, axes))
Esempio n. 6
0
def test_gaussianx(bound):
    ndim = 3
    rstate = get_rstate()
    g = Gaussian(ndim=ndim)
    sampler = dynesty.NestedSampler(g.loglikelihood,
                                    g.prior_transform,
                                    g.ndim,
                                    nlive=nlive,
                                    rstate=rstate,
                                    bound=bound)
    sampler.run_nested(print_progress=printing)
    results = sampler.results
    dyplot.boundplot(results,
                     dims=(0, 1)[:min(ndim, 2)],
                     it=1000,
                     prior_transform=g.prior_transform,
                     show_live=False)
    dyplot.cornerbound(results,
                       it=3000,
                       prior_transform=g.prior_transform,
                       show_live=False)
Esempio n. 7
0
def draw_cornerbounds(results,
                      nidm,
                      prior_transform,
                      labels=None,
                      figsize=(10, 10),
                      save=False,
                      save_dir='.',
                      suffix='',
                      **kwargs):
    fig, axes = plt.subplots(ndim - 1, ndim - 1, figsize=figsize)
    plot_kw = {'labels': labels, 'it': 1000, 'show_live': True}
    plot_kw.update(kwargs)
    fg, ax = dyplot.cornerbound(self.results,
                                prior_transform=self.prior_tf,
                                fig=(fig, axes),
                                **plot_kw)
    if save:
        plt.savefig(os.path.join(save_dir, "Cornerbound%s.png" % suffix),
                    dpi=120)
        plt.close()
    else:
        plt.show()
Esempio n. 8
0
def test_gaussian(dynamic, periodic, ndim, bound):
    rstate = get_rstate()
    g = Gaussian(ndim=ndim)
    if periodic:
        periodic = [0]
    else:
        periodic = None
    if dynamic:
        sampler = dynesty.DynamicNestedSampler(g.loglikelihood,
                                               g.prior_transform,
                                               g.ndim,
                                               nlive=nlive,
                                               rstate=rstate,
                                               periodic=periodic,
                                               bound=bound)
    else:
        sampler = dynesty.NestedSampler(g.loglikelihood,
                                        g.prior_transform,
                                        g.ndim,
                                        nlive=nlive,
                                        rstate=rstate,
                                        periodic=periodic,
                                        bound=bound)
    sampler.run_nested(print_progress=printing)
    results = sampler.results
    # check plots
    dyplot.runplot(results)
    dyplot.runplot(results, span=[(0., 10.), 0.001, 0.2, (5., 6.)])
    dyplot.runplot(results, logplot=True)
    dyplot.runplot(results,
                   fig=(plt.gcf(), plt.gcf().axes),
                   max_x_ticks=0,
                   max_y_ticks=0)
    plt.close()
    dyplot.traceplot(results)
    dyplot.traceplot(results, smooth=[10] * ndim)
    dyplot.traceplot(results, connect=True)
    dyplot.traceplot(results,
                     fig=(plt.gcf(), plt.gcf().axes),
                     show_titles=True,
                     truths=np.zeros(ndim),
                     verbose=True,
                     max_n_ticks=0)
    plt.close()

    truths = np.zeros(ndim)
    truths[0] = -.1
    span = [[-10, 10]] * ndim
    if ndim > 1:
        truths[1] = .1
        span[1] = .9

    dyplot.cornerplot(results, show_titles=True, truths=truths)
    dyplot.cornerplot(results,
                      smooth=10,
                      verbose=True,
                      hist2d_kwargs=dict(plot_datapoints=True),
                      max_n_ticks=0)
    plt.close()
    if ndim != 1:
        # cornerbound
        dyplot.cornerbound(results,
                           it=500,
                           prior_transform=g.prior_transform,
                           show_live=True,
                           span=span)
        dyplot.cornerbound(results,
                           it=500,
                           show_live=True,
                           span=span,
                           fig=(plt.gcf(), plt.gcf().axes))
        plt.close()
        # boundplot
        dyplot.boundplot(results,
                         dims=(0, 1)[:min(ndim, 2)],
                         it=1000,
                         prior_transform=g.prior_transform,
                         show_live=True,
                         span=span)
        dyplot.boundplot(results, dims=(0, 1)[:min(ndim, 2)], it=1000)
        plt.close()

        # cornerpoints
        dyplot.cornerpoints(results)
        plt.close()
        dyplot.cornerpoints(results, span=span, truths=truths, max_n_ticks=0)
        plt.close()
Esempio n. 9
0
plt.close()
sys.stderr.write('Corner Plot (Contours)\n')
dyplot.cornerplot(sampler.results)
plt.close()
sys.stderr.write('2-D Bound Plot\n')
dyplot.boundplot(sampler.results,
                 dims=(0, 1),
                 it=3000,
                 prior_transform=prior_transform,
                 show_live=True,
                 span=[(-10, 10), (-10, 10)])
plt.close()
sys.stderr.write('Sub-Corner Plot (Bounds)\n')
dyplot.cornerbound(sampler.results,
                   it=3500,
                   prior_transform=prior_transform,
                   show_live=True,
                   span=[(-10, 10), (-10, 10)])
plt.close()

# check various bounding methods
for bound in ['none', 'single', 'multi', 'balls', 'cubes']:
    sys.stderr.write('\n' + bound + '\n')
    sampler = dynesty.NestedSampler(loglikelihood,
                                    prior_transform,
                                    ndim,
                                    nlive=nlive,
                                    bound=bound,
                                    sample='unif')
    sampler.run_nested(print_progress=printing)
    check_results(sampler.results, lz_tol, m_tol, c_tol)