Example #1
0
def run_example(directory, abc=False):
    os.chdir(directory)
    os.system("./main -s 0 -t 8")
    if directory == "StraightLine":
        print("Figure 1 in the paper has been zoomed in.")

    if abc:
        dn4.postprocess_abc(rng_seed=0)
    else:
        dn4.postprocess(rng_seed=0)

    exec(open("display.py").read())
    os.chdir("..")
Example #2
0
def postprocess():

    # Postprocess DNest4 output
    dn4.postprocess(plot=False)

    # Load the data
    f = open("data.yaml")
    data = yaml.load(f, Loader=yaml.SafeLoader)
    f.close()

    # Plot the forecast
    posterior_sample = dn4.my_loadtxt("posterior_sample.txt")
    amount = posterior_sample[:, -1]
    amount = np.sort(amount)
    n = len(amount)
    indices = [int(0.1 * n), int(0.5 * n), int(0.9 * n)]
    future_tips = amount
    quantiles = future_tips[indices]

    print("")
    print(
        "Assuming things keep rolling along more or less as they have been, I")
    print("predict, with 90% probability, that you'll receive between")
    print(np.round(quantiles[0], 2),
          "and",
          np.round(quantiles[2], 2),
          "LBC",
          end=" ")
    print("over the next month.")

    # plt.hist(future_tips, 500, density=True)
    # plt.xlabel("Future tips over next month (LBC)")
    # plt.ylabel("Probability Density")
    # plt.show()

    return quantiles
Example #3
0
import dnest4.classic as dn4
dn4.postprocess()

import matplotlib.pyplot as plt
posterior_sample = dn4.my_loadtxt("posterior_sample.txt")

# Plot some curves through the data
x_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
y_data = [1.0, 3.8, 3.7, 3.8, 2.9, 2.4, 2.0, 1.3, 0.4, -0.2]
plt.plot(x_data, y_data, "o")

for i in range(0, 10):
    plt.plot(x_data, posterior_sample[i, 2:], color="g", alpha=0.2)

plt.show()

Example #4
0
import dnest4.classic as dn4

dn4.postprocess(single_precision=True, cut=0)
import display
Example #5
0
#!/usr/bin/python
import dnest4.classic as dn4
dn4.postprocess(single_precision=True)
import display
import numpy as np

posterior_sample = dn4.my_loadtxt("posterior_sample.txt")
indices = dn4.load_column_names("posterior_sample.txt")

# Extract column by name
#print("Indices")
#print(indices)

#plt.show()
print(indices)
print(type(indices))

print("Length of the dictionanry : ", len(indices))

I = indices.get('indices')

print("Items of the dictionanry : ", indices.items())

Z = indices.get('colnames')
print("Colnames: ", Z)
print("Type of Colnames: ", type(Z))
print("Type of items : ", type(I))
print("Type of Posterior  ", type(posterior_sample))

index = 'log_a[2]'
print("Index: ", I['log_a[2]'])
Example #6
0
import corner
import dnest4.classic as dn4
import matplotlib.pyplot as plt
import numpy as np

# DNest4 postprocessing
dn4.postprocess(cut=0.0)

# Corner plot
posterior_sample = dn4.my_loadtxt("posterior_sample.txt")
corner.corner(posterior_sample, plot_contours=False, plot_density=False)
plt.show()

# Correlation matrix
plt.imshow(np.corrcoef(posterior_sample.T),
           cmap="coolwarm",
           vmin=-1.0,
           vmax=1.0,
           interpolation="nearest")
plt.show()
Example #7
0
import dnest4.classic as dn4
dn4.postprocess()

Example #8
0
    A, P, phi = 5*rng.randn(), -0.05*np.log(rng.rand()), 2*np.pi*rng.rand()
    data["y"] = A*np.sin(2*np.pi*data["t"]/P + phi) + rng.randn(data["N"])

    # Create model
    model = bd.Model()

    # Sinusoid parameters
    model.add_node(bd.Node("A", bd.Normal(0.0, 5.0)))
    model.add_node(bd.Node("P", bd.Exponential(0.05)))
    model.add_node(bd.Node("phi", bd.Uniform(0.0, 2.0*np.pi)))

    # Data nodes
    for i in range(0, data["N"]):
        name = "y{i}".format(i=i)
        mean = "A*sin(2*M_PI*t{i}/P + phi)".format(i=i)
        model.add_node(bd.Node(name, bd.Normal(mean, 1.0), observed=True))

    # Create the C++ code
    bd.generate_h(model, data)
    bd.generate_cpp(model, data)

    # Compile the C++ code so it's ready to go
    os.system("make")
    os.system("nice -n19 ./main")

    f.write(str(dn4.postprocess(plot=False)[1]) + "\n")
    f.flush()

f.close()

Example #9
0
import corner
import dnest4.classic as dn4
import matplotlib.pyplot as plt
import numpy as np

dn4.postprocess(rng_seed=0)
posterior_sample = dn4.my_loadtxt("posterior_sample.txt")

# Do corner plot
#colnames = dn4.load_column_names("posterior_sample.txt")["colnames"]
#corner.corner(posterior_sample, labels=colnames)
#plt.savefig("corner.png")
#plt.show()

# Corner plot for V2

# Fonts
plt.rcParams["font.family"] = "serif"
plt.rcParams["font.size"] = 16
plt.rc("text", usetex=True)
#plt.rcParams["axes.labelpad"] = 24

posterior_sample = posterior_sample[:, [0, 1, 2, 3, 6, 7, 8, 9, 10]]
fig = corner.corner(posterior_sample,
                    labels=[
                        "$A_0$ (km/s)", "$A_1$ (km/s)", "$\\phi_0$ (deg)",
                        "$\\phi_1$ (deg)", "$\\sigma_0$ (km/s)",
                        "$\\sigma_1$ (km/s)", "$\\gamma_0$", "$\\gamma_1$",
                        "$p_{\\rm subs}$"
                    ],
                    plot_contours=False,
Example #10
0
import dnest4.classic as dn4
dn4.postprocess(single_precision=True, cut=0)
import display

Example #11
0
import dnest4.classic as dn4
dn4.postprocess(single_precision=True)
import display

Example #12
0
def amorph_postprocess():
    dn4.postprocess()

    from . import display
    display.display()