Пример #1
0
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as pl
from plot_setup import setup, SQUARE_FIGSIZE, COLORS, savefig

from twod_a import log_p_gauss, run_mcmc

setup()  # initialize the plotting styles
np.random.seed(42)


sigs = 2.0 ** np.arange(-2, 6)

if __name__ == "__main__":
    acc_fracs = np.empty_like(sigs)
    for i, sig in enumerate(sigs):
        _, acc_fracs[i] = run_mcmc(log_p_gauss, np.array([0.0, 0.0]),
                                   prop_sigma=sig)

    fig, ax = pl.subplots(1, 1, figsize=SQUARE_FIGSIZE)
    ax.axhline(0.25, color=COLORS["DATA"])
    ax.plot(sigs, acc_fracs, ".-", color=COLORS["MODEL_2"])
    ax.set_xscale("log")
    ax.set_xlabel(r"$\sigma_q$")
    ax.set_ylabel("acceptance fraction")
    ax.set_xlim(0.2, 40)
    savefig(fig, "tuning.pdf")
Пример #2
0
from twod_a import run_mcmc, log_p_gauss
from plot_setup import setup, COLORS, SQUARE_FIGSIZE, savefig

setup()  # initialize the plotting styles
np.random.seed(42)

x0 = [-4.0, 5.0]

s = SQUARE_FIGSIZE
s[0] *= 2
s[1] *= 0.8
fig, axes = pl.subplots(1, 3, sharex=True, sharey=True, figsize=s)
for n, ax in zip([0.0, -1.0, 2.0], axes):
    chain, _ = run_mcmc(log_p_gauss,
                        np.array(x0),
                        nsteps=2e3,
                        prop_sigma=10**n)
    ax.plot(chain[:, 0], chain[:, 1], "o-", color=COLORS["DATA"], ms=2)
    ax.plot(x0[0], x0[1], "o", color=COLORS["MODEL_1"])
    ax.set_xlim(-6.3, 6.3)
    ax.set_ylim(-6.3, 6.3)
    ax.set_xlabel("$x$")
    ax.annotate(r"$\sigma_q = 10^{{{0:.0f}}}$".format(n), (1, 0),
                xycoords="axes fraction",
                xytext=(-5, 5),
                textcoords="offset points",
                ha="right",
                va="bottom")
    ax.yaxis.set_major_locator(pl.MaxNLocator(5))
    ax.xaxis.set_major_locator(pl.MaxNLocator(5))
Пример #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import corner
import numpy as np

from twod_a import run_mcmc
from plot_setup import setup, savefig

setup()  # initialize the plotting styles
np.random.seed(42)


def log_p_uniform(x):
    if 3 <= x[0] <= 7 and 1 <= x[1] <= 9:
        return 0.0
    return -np.inf


chain, _ = run_mcmc(log_p_uniform, np.array([5.0, 5.0]), nsteps=1e5)
fig = corner.corner(chain, labels=["$x$", "$y$"],
                    range=[(2.5, 7.5), (0.5, 9.5)],
                    plot_density=False, plot_contours=False)
savefig(fig, "twod_b.pdf", dpi=300)
Пример #4
0
from twod_a import run_mcmc, log_p_gauss
from plot_setup import setup, COLORS, SQUARE_FIGSIZE, savefig

setup()  # initialize the plotting styles
np.random.seed(42)


x0 = [-4.0, 5.0]

s = SQUARE_FIGSIZE
s[0] *= 2
s[1] *= 0.8
fig, axes = pl.subplots(1, 3, sharex=True, sharey=True, figsize=s)
for n, ax in zip([0.0, -1.0, 2.0], axes):
    chain, _ = run_mcmc(log_p_gauss, np.array(x0), nsteps=2e3,
                        prop_sigma=10**n)
    ax.plot(chain[:, 0], chain[:, 1], "o-", color=COLORS["DATA"], ms=2)
    ax.plot(x0[0], x0[1], "o", color=COLORS["MODEL_1"])
    ax.set_xlim(-6.3, 6.3)
    ax.set_ylim(-6.3, 6.3)
    ax.set_xlabel("$x$")
    ax.annotate(r"$\sigma_q = 10^{{{0:.0f}}}$".format(n),
                (1, 0), xycoords="axes fraction",
                xytext=(-5, 5), textcoords="offset points",
                ha="right", va="bottom")
    ax.yaxis.set_major_locator(pl.MaxNLocator(5))
    ax.xaxis.set_major_locator(pl.MaxNLocator(5))

axes[0].set_ylabel("$y$")

savefig(fig, "MH_sigma.pdf")