예제 #1
0
def fit(argv):

    initializeDetector(det, )
    initializeWaveform(wf, results[wf_idx]['x'])

    # Create a model object and a sampler
    model = Model()
    sampler = dnest4.DNest4Sampler(model,
                                   backend=dnest4.backends.CSVBackend(".",
                                                                      sep=" "))

    seed = 1234
    np.random.seed(seed)
    # Set up the sampler. The first argument is max_num_levels
    gen = sampler.sample(max_num_levels=100,
                         num_steps=1000000,
                         new_level_interval=100000,
                         num_per_step=10000,
                         thread_steps=100,
                         num_particles=5,
                         lam=10,
                         beta=100,
                         seed=seed)

    # Do the sampling (one iteration here = one particle save)
    for i, sample in enumerate(gen):
        print("# Saved {k} particles.".format(k=(i + 1)))

    # Run the postprocessing
    dnest4.postprocess()
예제 #2
0
def main(idx=0):
    time.sleep(120)
    directory = "chan672_wfs"
    os.chdir(directory)
    for root, dirs, files in os.walk("."):
        for wf in dirs:
            index = "wf" + str(idx)
            if wf == index:
                os.chdir(wf)
                loop = 1
                while loop == 1:
                    dn4.postprocess(plot=False)
                    post = np.loadtxt("posterior_sample.txt")
                    if len(post) < 10:
                        time.sleep(120)
                    else:
                        os.chdir("../..")
                        return
예제 #3
0
파일: base.py 프로젝트: sjmeijer/waffle
    def dnest_postprocess(self, directory):
        # Moves into the result directory to postprocess, then moves back to wherever we were
        # TODO: Should probably check that directories and files are valid...

        old_dir = os.getcwd()
        os.chdir(directory)
        logZ, info, weights = None, None, None
        try:
            logZ, info, weights = dnest4.postprocess(plot=False)
        except IndexError as e:
            print(e)
            print(F"There was an issue looking at the result in {directory}")
            print('\033[91m' +
                  "I'll try to keep going but this looks serious..." +
                  '\033[0m')
            import time
            time.sleep(3)
        os.chdir(old_dir)

        return logZ, info, weights
예제 #4
0
import dnest4
dnest4.postprocess(single_precision=True)
import display

예제 #5
0
from dnest4 import postprocess
import sys
options = sys.argv

if 'no' in options:
    plot = False
else:
    plot = True

if 'pvc' in options:
    while True:
        logz, H, logx_samples, posterior = postprocess(plot=plot)
else:
    logz, H, logx_samples, posterior = postprocess(plot=plot)

if posterior.shape[0] > 5:
    from display import DisplayResults
    res = DisplayResults(options)
else:
    print 'Too few samples, keep running the model'
예제 #6
0
        Generate from the heavy-tailed distribution.
        """
        a = np.random.randn()
        b = np.random.rand()
        t = a/np.sqrt(-np.log(b))
        n = np.random.randn()
        return 10.0**(1.5 - 3*np.abs(t))*n

    def wrap(self, x, a, b):
        assert b > a
        return (x - a)%(b - a) + a

# Create a model object and a sampler
model = Model()
sampler = dnest4.DNest4Sampler(model,
                               backend=dnest4.backends.CSVBackend(".",
                                                                  sep=" "))

# Set up the sampler. The first argument is max_num_levels
gen = sampler.sample(max_num_levels=30, num_steps=1000, new_level_interval=10000,
                      num_per_step=10000, thread_steps=100,
                      num_particles=5, lam=10, beta=100, seed=1234)

# Do the sampling (one iteration here = one particle save)
for i, sample in enumerate(gen):
    print("# Saved {k} particles.".format(k=(i+1)))

# Run the postprocessing
dnest4.postprocess()

예제 #7
0
import dnest4 as dn4
import os
for root, dirs, files in os.walk("."):
    for wf in dirs:
        os.chdir(wf)
        dn4.postprocess(plot=False)
        os.chdir("..")
    exit()

예제 #8
0
# Set up the sampler. The first argument is max_num_levels
gen = sampler.sample(max_num_levels=30,
                     num_steps=1000,
                     new_level_interval=10000,
                     num_per_step=10000,
                     thread_steps=100,
                     num_particles=5,
                     lam=10,
                     beta=100)

# Do the sampling (one iteration here = one particle save)
for sample in enumerate(gen):
    pass

# Run the postprocessing to get marginal likelihood and generate posterior samples
logZdnest4, infogaindnest4, _ = dnest4.postprocess(plot=False)

postsamples = np.loadtxt('posterior_sample.txt')

print('Marginalised evidence is {}'.format(logZdnest4))

print('Number of posterior samples is {}'.format(postsamples.shape[0]))

# plot posterior samples (if corner.py is installed)
try:
    import matplotlib as mpl
    mpl.use("Agg")  # force Matplotlib backend to Agg
    import corner  # import corner.py
except ImportError:
    sys.exit(1)
예제 #9
0
The PostBlobby3D class is very simple. However, it is useful for organisational
purposes of the Blobby3D output. In this script, I created a PostBlobby3D
object and plotted a handful of sample attributes.

@author: Mathew Varidel

"""

import numpy as np
import matplotlib.pyplot as plt

import dnest4 as dn4
from pyblobby3d import PostBlobby3D

dn4.postprocess()

post_b3d = PostBlobby3D(samples_path='posterior_sample.txt',
                        data_path='data.txt',
                        var_path='var.txt',
                        metadata_path='metadata.txt',
                        nlines=2)

# choose a sample
sample = 0

# Plot maps for sample
fig, ax = plt.subplots(1, 4)

ax[0].set_title(r'H$\alpha$ Flux')
ax[0].imshow(np.log10(post_b3d.maps[sample, 0]),
import dnest4
dnest4.postprocess()

예제 #11
0
        return norm - 0.5*chisq

# Create a model object and a sampler
model = DNest4Model()
sampler = dnest4.DNest4Sampler(model, backend=dnest4.backends.CSVBackend(".", sep=" "))

# Set up the sampler. The first argument is max_num_levels
gen = sampler.sample(max_num_levels=30, num_steps=1000, new_level_interval=10000,
                     num_per_step=10000, thread_steps=100, num_particles=5, lam=10, beta=100)

# Do the sampling (one iteration here = one particle save)
for sample in enumerate(gen):
    pass

# Run the postprocessing to get marginal likelihood and generate posterior samples
logZdnest4, infogaindnest4, _ = dnest4.postprocess(plot=False);

postsamples = np.loadtxt('posterior_sample.txt')

print('Marginalised evidence is {}'.format(logZdnest4))

print('Number of posterior samples is {}'.format(postsamples.shape[0]))

# plot posterior samples (if corner.py is installed)
try:
    import matplotlib as mpl
    mpl.use("Agg") # force Matplotlib backend to Agg
    import corner # import corner.py
except ImportError:
    sys.exit(1)
예제 #12
0
def postprocess(argv):

  # Run the postprocessing
  dnest4.postprocess()
예제 #13
0
def postprocess(argv):

    # Run the postprocessing
    dnest4.postprocess()