コード例 #1
0
ファイル: output_tests.py プロジェクト: vishalbelsare/abcpy
    def test_plot_post_distr(self):
        rng = np.random.RandomState(1)
        weights_identical = np.ones((100, 1))
        params = rng.randn(100, 2, 1, 1)
        weights = np.arange(100).reshape(-1, 1)
        journal = Journal(1)
        journal.add_user_parameters([("par1", params[:, 0]),
                                     ("par2", params[:, 1])])
        journal.add_user_parameters([("par1", params[:, 0]),
                                     ("par2", params[:, 1])])
        journal.add_weights(weights=weights_identical)
        journal.add_weights(weights=weights)
        journal.plot_posterior_distr(single_marginals_only=True, iteration=0)
        journal.plot_posterior_distr(true_parameter_values=[0.5, 0.3],
                                     show_samples=True)
        journal.plot_posterior_distr(double_marginals_only=True,
                                     show_samples=True,
                                     true_parameter_values=[0.5, 0.3])
        journal.plot_posterior_distr(contour_levels=10,
                                     ranges_parameters={"par1": [-1, 1]},
                                     parameters_to_show=["par1"])

        with self.assertRaises(KeyError):
            journal.plot_posterior_distr(parameters_to_show=["par3"])
        with self.assertRaises(RuntimeError):
            journal.plot_posterior_distr(single_marginals_only=True,
                                         double_marginals_only=True)
        with self.assertRaises(RuntimeError):
            journal.plot_posterior_distr(parameters_to_show=["par1"],
                                         double_marginals_only=True)
        with self.assertRaises(RuntimeError):
            journal.plot_posterior_distr(parameters_to_show=["par1"],
                                         true_parameter_values=[0.5, 0.3])
        with self.assertRaises(TypeError):
            journal.plot_posterior_distr(ranges_parameters={"par1": [-1]})
        with self.assertRaises(TypeError):
            journal.plot_posterior_distr(
                ranges_parameters={"par1": np.zeros(1)})
コード例 #2
0
param_names = [r"$\theta_1$", r"$\theta_2$", r"$\sigma_e$", r"$\phi$"]
theta1_min = 1.4
theta1_max = 2.2
theta2_min = 0
theta2_max = 1
sigma_e_min = 1.5
sigma_e_max = 2.5
phi_min = 0
phi_max = 1

ranges = dict([("theta1", [theta1_min, theta1_max]), ("theta2", [theta2_min, theta2_max]),
               ("sigma_e", [sigma_e_min, sigma_e_max]), ("phi", [phi_min, phi_max]), ])

fig, axes = jrnl.plot_posterior_distr(true_parameter_values=theta_obs, show_samples=False, show_density_values=False,
                                      figsize=5, contour_levels=8, write_posterior_mean=False,
                                      ranges_parameters=ranges)

figsize_actual = 2 * len(param_names)
# figsize_actual = 28
label_size = figsize_actual / len(param_names) * 10
title_size = figsize_actual / len(param_names) * 12

fig.suptitle(f"{'ABC' if inference_technique == 'ABC' else 'Exc'}-{technique}", size=title_size)

for j, label in enumerate(param_names):
    # remove exponential notation:
    axes[j, 0].ticklabel_format(style='plain', axis='y', scilimits=(0, 0))
    axes[-1, j].ticklabel_format(style='plain', axis='x')  # , scilimits=(0, 0))
    axes[j, -1].ticklabel_format(style='plain', axis='y', scilimits=(0, 0))