Example #1
0
def test_livepoints():
    # Test the providing of initial live-points to the sampler
    ndim = 2
    rstate = get_rstate()
    live_u = rstate.uniform(size=(nlive, ndim))
    live_v = np.array([prior_transform(_) for _ in live_u])
    live_logl = np.array([loglike(_) for _ in live_v])
    live_points = [live_u, live_v, live_logl]
    sampler = dynesty.NestedSampler(loglike,
                                    prior_transform,
                                    ndim,
                                    nlive=nlive,
                                    live_points=live_points,
                                    rstate=rstate)
    sampler.run_nested(print_progress=printing)
    dyutil.unravel_run(sampler.results)
Example #2
0
def test_livepoints():
    # hard test of dynamic sampler with high dlogz_init and small number
    # of live points
    ndim = 2
    rstate = get_rstate()
    live_u = rstate.uniform(size=(ndim, 2))
    live_v = np.array([prior_transform(_) for _ in live_u])
    live_logl = np.array([loglike(_) for _ in live_v])
    live_points = [live_u, live_v, live_logl]
    sampler = dynesty.NestedSampler(loglike,
                                    prior_transform,
                                    ndim,
                                    nlive=nlive,
                                    live_points=live_points,
                                    rstate=rstate)
    sampler.run_nested()
    dyutil.unravel_run(sampler.results)
Example #3
0
def test_unravel():
    # test unravel_run
    ndim = 2
    rstate = get_rstate()
    sampler = dynesty.NestedSampler(loglike,
                                    prior_transform,
                                    ndim,
                                    nlive=nlive,
                                    rstate=rstate)
    sampler.run_nested(print_progress=printing)
    dyutil.unravel_run(sampler.results)

    sampler = dynesty.DynamicNestedSampler(loglike,
                                           prior_transform,
                                           ndim,
                                           nlive=nlive,
                                           rstate=rstate)
    sampler.run_nested(dlogz_init=1, maxcall=1000, print_progress=printing)
    dyutil.unravel_run(sampler.results)
    logps = sampler.results.logl
    dyutil.reweight_run(sampler.results, logps / 4.)
Example #4
0
def test_unravel():
    # hard test of dynamic sampler with high dlogz_init and small number
    # of live points
    ndim = 2
    rstate = get_rstate()
    sampler = dynesty.NestedSampler(loglike,
                                    prior_transform,
                                    ndim,
                                    nlive=nlive,
                                    rstate=rstate)
    sampler.run_nested()
    dyutil.unravel_run(sampler.results)

    sampler = dynesty.DynamicNestedSampler(loglike,
                                           prior_transform,
                                           ndim,
                                           nlive=nlive,
                                           rstate=rstate)
    sampler.run_nested(dlogz_init=1, maxcall=1000)
    dyutil.unravel_run(sampler.results)
    logps = sampler.results.logl
    dyutil.reweight_run(sampler.results, logps / 4.)
Example #5
0
def test_ravel_unravel():
    """ Here I test that ravel/unravel preserves things correctly """
    rstate = get_rstate()
    g = Gaussian()

    dsampler = dynesty.DynamicNestedSampler(g.loglikelihood,
                                            g.prior_transform,
                                            g.ndim,
                                            bound='single',
                                            sample='unif',
                                            rstate=rstate,
                                            nlive=nlive)
    maxiter = 1800
    dsampler.run_nested(maxiter=maxiter,
                        use_stop=False,
                        nlive_batch=100,
                        print_progress=printing)
    dres = dsampler.results

    dres_list = dyfunc.unravel_run(dres)
    dres_merge = dyfunc.merge_runs(dres_list)
    assert np.abs(dres.logz[-1] - dres_merge.logz[-1]) < 0.01