From f43dc4fe1d7b0ac4f41e60443fb3884e4a1871e6 Mon Sep 17 00:00:00 2001 From: Michael Williams Date: Tue, 18 Apr 2023 11:38:17 +0100 Subject: [PATCH 1/2] gw: update figure and font size --- gw/bbh_pp_test/pp_test_results.ipynb | 56 +++++++++++++++++++++------ gw/bns_test/analyse_bns_results.ipynb | 48 ++++++++++++++++++----- 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/gw/bbh_pp_test/pp_test_results.ipynb b/gw/bbh_pp_test/pp_test_results.ipynb index d9c45d7..7a714d9 100644 --- a/gw/bbh_pp_test/pp_test_results.ipynb +++ b/gw/bbh_pp_test/pp_test_results.ipynb @@ -12,7 +12,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import glob\n", @@ -31,7 +33,8 @@ "from utils import configure_plotting, load_json, natural_sort\n", "\n", "configure_plotting(basedir)\n", - "figsize = plt.rcParams['figure.figsize']" + "figsize = plt.rcParams['figure.figsize']\n", + "linewidth = 6.17804" ] }, { @@ -44,7 +47,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "nessai_path = \"outdir_nessai_fix/\"\n", @@ -55,7 +60,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "def load_all_results(base_path, file_extension=\"hdf5\"):\n", @@ -69,7 +76,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "def load_nessai_result_files(base_path):\n", @@ -83,7 +92,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "inessai_results = load_all_results(inessai_path)" @@ -92,7 +103,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "nessai_results = load_all_results(nessai_path)" @@ -101,12 +114,33 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "dynesty_results = load_all_results(dynesty_path)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "fig, _ = make_pp_plot(inessai_results, labels=labels, height=figsize[0], width=figsize[0])\n", + "fig.savefig(f\"figures/pp_plot_inessai.pdf\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Smaller version of P-P plots for appendices" + ] + }, { "cell_type": "code", "execution_count": null, @@ -114,11 +148,11 @@ "outputs": [], "source": [ "for sampler, results in zip(\n", - " [\"inessai\", \"nessai\", \"dynesty\"],\n", - " [inessai_results, nessai_results, dynesty_results]\n", + " [\"nessai\", \"dynesty\"],\n", + " [nessai_results, dynesty_results]\n", "):\n", " print(f\"Sampler: {sampler}\")\n", - " fig, _ = make_pp_plot(results, labels=labels, height=figsize[0], width=figsize[0])\n", + " fig, _ = make_pp_plot(results, labels=labels, height=0.65 * linewidth, width=0.65 * linewidth, legend_fontsize=\"small\")\n", " fig.savefig(f\"figures/pp_plot_{sampler}.pdf\")" ] }, diff --git a/gw/bns_test/analyse_bns_results.ipynb b/gw/bns_test/analyse_bns_results.ipynb index 4bcf51d..d65d8d5 100644 --- a/gw/bns_test/analyse_bns_results.ipynb +++ b/gw/bns_test/analyse_bns_results.ipynb @@ -36,6 +36,9 @@ "from utils import configure_plotting, natural_sort\n", "configure_plotting(basedir)\n", "\n", + "linewidth = 6.17804\n", + "\n", + "\n", "# Disable the bilby plotting style\n", "os.environ[\"BILBY_STYLE\"] = \"none\"\n", "\n", @@ -61,7 +64,9 @@ "cell_type": "code", "execution_count": null, "id": "dd6ac330", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "result_paths = {\n", @@ -76,7 +81,9 @@ "cell_type": "code", "execution_count": null, "id": "4f6e2e52", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "results = {}\n", @@ -94,7 +101,9 @@ "cell_type": "code", "execution_count": null, "id": "f337215a", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "merge_results = {}\n", @@ -281,7 +290,9 @@ "cell_type": "code", "execution_count": null, "id": "bb7fa61b", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "cbc_param_labels = {\n", @@ -327,7 +338,9 @@ "cell_type": "code", "execution_count": null, "id": "e093b013", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "parameters = results_list[0][0].search_parameter_keys\n", @@ -340,13 +353,25 @@ "cell_type": "code", "execution_count": null, "id": "02f393d2", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "with sns.plotting_context(\n", " rc={ \n", - " \"xtick.labelsize\": 16,\n", - " \"ytick.labelsize\": 16,\n", + " \"xtick.labelsize\": 24,\n", + " \"ytick.labelsize\": 24,\n", + " \"xtick.major.size\" : 6,\n", + " \"xtick.major.width\" : 1.0,\n", + " \"xtick.minor.size\" : 3.0,\n", + " \"xtick.minor.width\" : 1.0,\n", + " \"ytick.major.size\" : 6,\n", + " \"ytick.major.width\" : 1.0,\n", + " \"ytick.minor.size\" : 3,\n", + " \"ytick.minor.width\" : 1.0,\n", + " \"lines.linewidth\": 2.0,\n", + " \"patch.linewidth\": 2.0,\n", " }\n", "):\n", "\n", @@ -358,9 +383,10 @@ " titles=False,\n", " fill_contours=False,\n", " smooth=0.95,\n", - " label_kwargs=dict(fontsize=24),\n", + " label_kwargs=dict(fontsize=32),\n", " plot_datapoints=False,\n", " corner_labels=corner_labels,\n", + " labelpad=0.12,\n", " )\n", " axs = fig.get_axes()\n", " for a in axs:\n", @@ -374,7 +400,9 @@ "cell_type": "code", "execution_count": null, "id": "a49b3e45", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "fig.savefig(\"figures/bns_corner_plot.pdf\")" From 75f67e7bd4a20f818f85587569eedb7a28d9219c Mon Sep 17 00:00:00 2001 From: Michael Williams Date: Fri, 7 Jul 2023 13:04:18 +0100 Subject: [PATCH 2/2] Changes for accepted version --- experiments/analytic_results.ipynb | 62 ++++++++++++++------ experiments/config.mk | 2 +- experiments/nlive_comparison_results.ipynb | 4 +- gw/bbh_parallelisation/parallelisation.ipynb | 6 +- gw/bbh_pp_test/inessai.ini | 4 +- gw/bbh_pp_test/pp_test_results.ipynb | 45 +++++++++++--- gw/bns_test/analyse_bns_results.ipynb | 43 ++++++++++++++ gw/bns_test/config.mk | 2 +- gw/bns_test/inessai.ini | 7 +-- gw/bns_test/results/bns_comparison_table.tex | 8 +-- gw/bns_test/results/js_table.tex | 18 +++--- toy_example/toy_example.ipynb | 44 ++++++++++++-- utils.py | 2 +- 13 files changed, 191 insertions(+), 56 deletions(-) diff --git a/experiments/analytic_results.ipynb b/experiments/analytic_results.ipynb index 8e6dd14..446dfa9 100644 --- a/experiments/analytic_results.ipynb +++ b/experiments/analytic_results.ipynb @@ -14,7 +14,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import os\n", @@ -42,10 +44,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "path = './outdir/'\n", + "path = './outdir_rerun/'\n", "gaussian_path = os.path.join(path, f'ins_gaussian_*d', '')\n", "gmm_path = os.path.join(path, f'ins_gmm_paper_*d', '')" ] @@ -53,7 +57,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "gaussian_results = load_all_results(gaussian_path)" @@ -62,7 +68,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "gmm_results = load_all_results(gmm_path)" @@ -71,7 +79,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "possible_dims = np.arange(2, 34, 2)\n", @@ -81,7 +91,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "figsize = ((10 / 13) * default_figsize[0], default_figsize[1] * (1.8 / 5))\n", @@ -127,7 +139,7 @@ " \n", "# h, l = fig.axes[0].get_legend_handles_labels()\n", "# fig.legend(h, l, frameon=False, ncol=2, loc='lower center', bbox_to_anchor=(0.6, -0.05))\n", - "fig.savefig('figures/resampling.pdf')" + "fig.savefig('figures_rerun/resampling.pdf')" ] }, { @@ -140,7 +152,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "gaussian_baseline_path = './outdir/baseline_gaussian_*d/'\n", @@ -152,7 +166,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "gmm_baseline_path = './outdir/baseline_gmm_paper_*'\n", @@ -164,17 +180,21 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "rosenbrock_path = './outdir/ins_rosenbrock_*d/'\n", + "rosenbrock_path = './outdir_rerun/ins_rosenbrock_*d/'\n", "rosenbrock_results = load_all_results(rosenbrock_path, file=\"summary.json\")" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "rosenbrock_baseline_path = './outdir/baseline_rosenbrock_*d/'\n", @@ -184,7 +204,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "all_results = [gaussian_results, gmm_results, rosenbrock_results]\n", @@ -194,7 +216,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "references = [\"gaussian\", \"gaussian\", \"ins\"]\n", @@ -317,7 +341,7 @@ "\n", "# plt.tight_layout()\n", "\n", - "fig.savefig(\"figures/comparison_all.pdf\")\n", + "fig.savefig(\"figures_rerun/comparison_all.pdf\")\n", "\n" ] }, @@ -331,7 +355,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "fig, axs = plt.subplots(1, 2, sharey=True)\n", @@ -372,7 +398,7 @@ "\n", "handles, labels = axs[0].get_legend_handles_labels()\n", "fig.legend(handles, labels, title=\"Dimensions\", ncols=5, loc=\"lower center\", bbox_to_anchor=(0.5, -0.05))\n", - "fig.savefig(\"figures/uncertainty_pp_plots.pdf\")\n", + "fig.savefig(\"figures_rerun/uncertainty_pp_plots.pdf\")\n", "plt.show()" ] }, diff --git a/experiments/config.mk b/experiments/config.mk index ba0f2d1..5860986 100644 --- a/experiments/config.mk +++ b/experiments/config.mk @@ -1,5 +1,5 @@ # General config -OUTDIR=outdir/ +OUTDIR=outdir_rerun/ # Random seed SEED=1234 # Analytic likelihoods config diff --git a/experiments/nlive_comparison_results.ipynb b/experiments/nlive_comparison_results.ipynb index e7f9e64..d58beec 100644 --- a/experiments/nlive_comparison_results.ipynb +++ b/experiments/nlive_comparison_results.ipynb @@ -38,7 +38,7 @@ "metadata": {}, "outputs": [], "source": [ - "path = \"outdir/ins_nlive_gaussian_16d_nlive*\"" + "path = \"outdir_rerun/ins_nlive_gaussian_16d_nlive*\"" ] }, { @@ -141,7 +141,7 @@ "plt.tight_layout()\n", "# plt.subplots_adjust(hspace=0.15)\n", "\n", - "fig.savefig(\"figures/scaling.pdf\", bbox_inches=\"tight\")\n", + "fig.savefig(\"figures_rerun/scaling.pdf\", bbox_inches=\"tight\")\n", "plt.show()" ] }, diff --git a/gw/bbh_parallelisation/parallelisation.ipynb b/gw/bbh_parallelisation/parallelisation.ipynb index 8f67914..50361ad 100644 --- a/gw/bbh_parallelisation/parallelisation.ipynb +++ b/gw/bbh_parallelisation/parallelisation.ipynb @@ -21,7 +21,9 @@ "sys.path.append(basedir)\n", "from utils import configure_plotting, load_json\n", "\n", - "configure_plotting(basedir)" + "configure_plotting(basedir)\n", + "\n", + "os.environ[\"PATH\"] = os.pathsep.join((\"/usr/local/texlive/2022/bin/x86_64-linux\", os.environ[\"PATH\"]))" ] }, { @@ -310,7 +312,7 @@ " \n", "plt.tight_layout()\n", "plt.legend(handles=handles, labels=labels, loc=\"upper right\", ncol=2)\n", - "fig.savefig(\"figures/parallelisation.pdf\", bbox_inches=\"tight\")\n", + "fig.savefig(\"figures_rerun/parallelisation.pdf\", bbox_inches=\"tight\")\n", "# plt.show()" ] }, diff --git a/gw/bbh_pp_test/inessai.ini b/gw/bbh_pp_test/inessai.ini index cf4dae6..e077e3e 100644 --- a/gw/bbh_pp_test/inessai.ini +++ b/gw/bbh_pp_test/inessai.ini @@ -1,7 +1,7 @@ accounting = ligo.dev.o4.cbc.pe.bilby label = inessai -outdir = outdir_inessai +outdir = outdir_inessai_rerun request-memory=20.0 @@ -16,6 +16,8 @@ phase-marginalization=True distance-marginalization=True time-marginalization=True +transfer-files = True + injection-file = precessing_injections.json gaussian-noise = True generation-seed = 12345 diff --git a/gw/bbh_pp_test/pp_test_results.ipynb b/gw/bbh_pp_test/pp_test_results.ipynb index 7a714d9..9be179e 100644 --- a/gw/bbh_pp_test/pp_test_results.ipynb +++ b/gw/bbh_pp_test/pp_test_results.ipynb @@ -34,7 +34,10 @@ "\n", "configure_plotting(basedir)\n", "figsize = plt.rcParams['figure.figsize']\n", - "linewidth = 6.17804" + "linewidth = 6.17804\n", + "\n", + "import os\n", + "os.environ[\"PATH\"] = os.pathsep.join((\"/usr/local/texlive/2022/bin/x86_64-linux\", os.environ[\"PATH\"]))" ] }, { @@ -54,7 +57,7 @@ "source": [ "nessai_path = \"outdir_nessai_fix/\"\n", "dynesty_path = \"outdir_dynesty_precessing/\"\n", - "inessai_path = \"outdir_inessai_A/\"" + "inessai_path = \"outdir_inessai_rerun/\"" ] }, { @@ -85,7 +88,15 @@ " nessai_path = f\"{base_path}/result/*_nessai/result.json\"\n", " nessai_files = natural_sort(glob.glob(nessai_path))\n", " print(f'Found: {len(nessai_files)} nessai results files')\n", - " nessai_results = [load_json(f) for f in nessai_files]\n", + " keys = None\n", + " # nessai_results = [load_json(f) for f in nessai_files]\n", + " nessai_results = []\n", + " for f in nessai_files:\n", + " res = load_json(f)\n", + " if keys is None:\n", + " keys = [k for k in res.keys() if \"time\" in k]\n", + " summary = {k: res[k] for k in keys}\n", + " nessai_results.append(summary)\n", " return nessai_results" ] }, @@ -119,7 +130,9 @@ }, "outputs": [], "source": [ - "dynesty_results = load_all_results(dynesty_path)" + "fig, _ = make_pp_plot(inessai_results, labels=labels, height=figsize[0], width=figsize[0])\n", + "# fig.savefig(f\"figures/pp_plot_inessai.pdf\")\n", + "# fig.savefig(\"figures/pp_plot_inessai.png\", transparent=True, dpi=200)" ] }, { @@ -130,8 +143,7 @@ }, "outputs": [], "source": [ - "fig, _ = make_pp_plot(inessai_results, labels=labels, height=figsize[0], width=figsize[0])\n", - "fig.savefig(f\"figures/pp_plot_inessai.pdf\")" + "dynesty_results = load_all_results(dynesty_path)" ] }, { @@ -339,9 +351,28 @@ "plt.yscale('log')\n", "plt.tight_layout()\n", "plt.grid()\n", - "fig.savefig(\"figures/bbh_comparison.pdf\")" + "fig.savefig(\"figures/bbh_comparison.pdf\")\n", + "fig.savefig(\"figures/bbh_comparison.png\", transparent=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "len(results[\"likelihood_evaluations\"])" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/gw/bns_test/analyse_bns_results.ipynb b/gw/bns_test/analyse_bns_results.ipynb index d65d8d5..30d5ec7 100644 --- a/gw/bns_test/analyse_bns_results.ipynb +++ b/gw/bns_test/analyse_bns_results.ipynb @@ -38,9 +38,12 @@ "\n", "linewidth = 6.17804\n", "\n", + "plt.rcParams['axes.formatter.useoffset'] = False\n", + "\n", "\n", "# Disable the bilby plotting style\n", "os.environ[\"BILBY_STYLE\"] = \"none\"\n", + "os.environ[\"PATH\"] = os.pathsep.join((\"/usr/local/texlive/2022/bin/x86_64-linux\", os.environ[\"PATH\"]))\n", "\n", "from js import calculate_js" ] @@ -114,6 +117,30 @@ "samplers = list(results.keys())" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "36b569ec-d55d-464f-9d61-d712bebdc37c", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "np.median([r.log_evidence for r in results[\"nessai\"]])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "911b7044-8bc3-41e0-a259-5db5d2bad717", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "[r.log_evidence for r in results[\"inessai\"]]" + ] + }, { "cell_type": "markdown", "id": "b2f0d9e6", @@ -183,6 +210,14 @@ "table_results" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "d4fc3835-5c22-42bf-9993-8a77c9dceec8", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -559,6 +594,14 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "706ff6a5-83db-45e9-8415-c24d25c46806", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/gw/bns_test/config.mk b/gw/bns_test/config.mk index d6fbed6..c3db7a3 100644 --- a/gw/bns_test/config.mk +++ b/gw/bns_test/config.mk @@ -1,4 +1,4 @@ # Directories to use for producing results NESSAI_OUTDIR=outdir_nessai_A -INESSAI_OUTDIR=outdir_inessai_P +INESSAI_OUTDIR=outdir_inessai_rerun_C DYNESTY_OUTDIR=outdir_dynesty_2000 diff --git a/gw/bns_test/inessai.ini b/gw/bns_test/inessai.ini index 2a814cd..4ee67ff 100644 --- a/gw/bns_test/inessai.ini +++ b/gw/bns_test/inessai.ini @@ -65,7 +65,7 @@ label=inessai_bns local=False local-generation=False local-plot=False -outdir=outdir_inessai_quantile +outdir=outdir_inessai_batch periodic-restart-time=28800 request-memory=8.0 request-cpus=16 @@ -137,10 +137,9 @@ phase = Uniform(name='phase', minimum=0, maximum=2 * np.pi, boundary='periodic') ################################################################################ sampler=nessai_importance -sampling-seed=None +sampling-seed=190425 n-parallel=4 -sampler-kwargs={'nlive': 6000, 'n_pool': 16, 'draw_constant': True, 'min_samples': 500, 'min_remove': 1, 'stopping_criterion': 'ratio', 'tolerance': 0.0, 'level_method': 'entropy', 'level_kwargs': {'q': 0.5, 'include_likelihood': False}, 'plot_pool': False, 'plot': False, 'clip': True, 'plotting_frequency': 10, 'weighted_kl': True, 'reparam': 'logit', 'redraw_samples': True, 'reset_flows': 8, 'flow_config': {'max_epochs': 500, 'patience': 10, 'batch_size': 6000, 'model_config': {'n_blocks': 6, 'n_neurons': 32, 'n_layers': 2, 'kwargs': {'batch_norm_between_layers': True, 'linear_transform': 'lu', 'pre_transform': 'batch_norm'}}}} - +sampler-kwargs={'nlive': 100000, 'n_pool': 16, 'max_iteration': 10, 'draw_constant': True, 'min_samples': 500, 'min_remove': 1, 'stopping_criterion': 'ratio', 'tolerance': 0.0, 'level_method': 'entropy', 'level_kwargs': {'q': 0.95, 'include_likelihood': False}, 'plot_pool': False, 'plot': False, 'clip': True, 'plotting_frequency': 10, 'weighted_kl': True, 'reparam': 'logit', 'redraw_samples': True, 'reset_flows': 8, 'flow_config': {'max_epochs': 500, 'patience': 10, 'batch_size': 6000, 'model_config': {'n_blocks': 6, 'n_neurons': 32, 'n_layers': 2, 'kwargs': {'batch_norm_between_layers': True, 'linear_transform': 'lu', 'pre_transform': 'batch_norm'}}}} ################################################################################ ## Waveform arguments diff --git a/gw/bns_test/results/bns_comparison_table.tex b/gw/bns_test/results/bns_comparison_table.tex index 8cb0107..09e5a32 100644 --- a/gw/bns_test/results/bns_comparison_table.tex +++ b/gw/bns_test/results/bns_comparison_table.tex @@ -1,9 +1,9 @@ \begin{tabular}{lccc} -\br +\toprule & Wall time [min] & Likelihood evaluations & Effective sample size \\ -\mr +\midrule \codestyle{dynesty} & $376.3 \pm 8.1$ & $\num{4.30e+07}\pm\num{7.12e+04}$ & $13098 \pm 131$ \\ \codestyle{nessai} & $57.9 \pm 8.9$ & $\num{1.42e+06}\pm\num{1.74e+05}$ & $13036 \pm 45$ \\ -\codestyle{i-nessai} & $32.9 \pm 3.8$ & $\num{1.05e+06}\pm\num{8.99e+04}$ & $13933 \pm 2525$ \\ -\br +\codestyle{i-nessai} & $24.3 \pm 3.0$ & $\num{1.01e+06}\pm\num{8.99e+04}$ & $14625 \pm 3539$ \\ +\bottomrule \end{tabular} diff --git a/gw/bns_test/results/js_table.tex b/gw/bns_test/results/js_table.tex index 147dd9c..49e6470 100644 --- a/gw/bns_test/results/js_table.tex +++ b/gw/bns_test/results/js_table.tex @@ -2,14 +2,14 @@ \br & \dynesty-\nessai & \dynesty-\inessai & \nessai-\inessai \\ \mr -$\mathcal{M}$ & $0.61^{0.20}_{-0.20}$ & $0.62^{0.22}_{-0.17}$ & $0.54^{0.21}_{-0.15}$ \\ -$q$ & $0.52^{0.29}_{-0.16}$ & $0.43^{0.16}_{-0.15}$ & $0.30^{0.15}_{-0.12}$ \\ -$\chi_1$ & $2.24^{0.78}_{-0.55}$ & $2.61^{0.71}_{-0.54}$ & $0.59^{0.25}_{-0.16}$ \\ -$\chi_2$ & $1.68^{0.60}_{-0.46}$ & $1.96^{0.82}_{-0.45}$ & $0.84^{0.29}_{-0.28}$ \\ -$\delta$ & $1.37^{0.29}_{-0.28}$ & $1.65^{0.54}_{-0.33}$ & $1.60^{0.50}_{-0.31}$ \\ -$\alpha$ & $1.04^{0.22}_{-0.25}$ & $1.05^{0.24}_{-0.19}$ & $1.11^{0.32}_{-0.19}$ \\ -$\theta_{JN}$ & $0.71^{0.22}_{-0.17}$ & $0.79^{0.33}_{-0.17}$ & $0.73^{0.24}_{-0.19}$ \\ -$\psi$ & $0.18^{0.13}_{-0.06}$ & $0.22^{0.14}_{-0.10}$ & $0.18^{0.11}_{-0.08}$ \\ -$t_\textrm{c}$ & $1.29^{0.42}_{-0.25}$ & $1.60^{0.36}_{-0.27}$ & $1.65^{0.31}_{-0.33}$ \\ +$\mathcal{M}$ & $0.61^{0.20}_{-0.20}$ & $0.69^{0.22}_{-0.19}$ & $0.53^{0.21}_{-0.13}$ \\ +$q$ & $0.52^{0.29}_{-0.16}$ & $0.36^{0.22}_{-0.11}$ & $0.30^{0.18}_{-0.08}$ \\ +$\chi_1$ & $2.24^{0.78}_{-0.55}$ & $2.61^{0.77}_{-0.59}$ & $0.53^{0.27}_{-0.17}$ \\ +$\chi_2$ & $1.68^{0.60}_{-0.46}$ & $1.93^{0.47}_{-0.54}$ & $0.73^{0.22}_{-0.22}$ \\ +$\delta$ & $1.37^{0.29}_{-0.28}$ & $1.47^{0.34}_{-0.28}$ & $1.59^{0.38}_{-0.31}$ \\ +$\alpha$ & $1.04^{0.22}_{-0.25}$ & $1.15^{0.25}_{-0.27}$ & $1.37^{0.30}_{-0.28}$ \\ +$\theta_{JN}$ & $0.71^{0.22}_{-0.17}$ & $0.74^{0.21}_{-0.21}$ & $0.79^{0.26}_{-0.23}$ \\ +$\psi$ & $0.18^{0.13}_{-0.06}$ & $0.21^{0.15}_{-0.09}$ & $0.19^{0.10}_{-0.09}$ \\ +$t_\textrm{c}$ & $1.29^{0.42}_{-0.25}$ & $1.56^{0.31}_{-0.39}$ & $1.57^{0.39}_{-0.33}$ \\ \br \end{tabular} diff --git a/toy_example/toy_example.ipynb b/toy_example/toy_example.ipynb index 550dc02..82b35e6 100644 --- a/toy_example/toy_example.ipynb +++ b/toy_example/toy_example.ipynb @@ -37,7 +37,8 @@ "figsize = plt.rcParams['figure.figsize']\n", "double_figsize = (2.0 * figsize[0], figsize[1])\n", "\n", - "os.makedirs(\"figures\", exist_ok=True)" + "os.makedirs(\"figures\", exist_ok=True)\n", + "os.environ[\"PATH\"] = os.pathsep.join((\"/usr/local/texlive/2022/bin/x86_64-linux\", os.environ[\"PATH\"]))" ] }, { @@ -475,7 +476,6 @@ " level_samples, sample_log_likelihoods, sample_log_priors, label\n", ")\n", "\n", - "\n", "for n in range(n_levels):\n", " previous = str(n - 1)\n", " label = str(n)\n", @@ -498,13 +498,32 @@ "final_log_q = log_meta_proposal(levels, final_samples)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "redraw_samples_dict = {}\n", + "redraw_log_l_dict = {}\n", + "for label, dist in levels.items():\n", + " redraw_samples_dict[label] = dist.rvs(size=nlive)\n", + " redraw_log_l_dict[label] = log_likelihood(redraw_samples_dict[label])\n", + "redraw_samples = np.concatenate([s for s in redraw_samples_dict.values()], axis=0)\n", + "redraw_log_l = log_likelihood(redraw_samples)\n", + "redraw_log_p = log_prior(redraw_samples)\n", + "redraw_log_q = log_meta_proposal(levels, redraw_samples)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "log_posterior_weights = final_log_l + final_log_p - final_log_q\n", + "log_posterior_weights = redraw_log_l + redraw_log_p - redraw_log_q\n", "post_weights = np.exp(log_posterior_weights)\n", "post_weights /= np.sum(post_weights)" ] @@ -545,7 +564,7 @@ "\n", "print(list(axd.keys()))\n", "\n", - "for i, ls in enumerate(level_samples.values()):\n", + "for i, ls in enumerate(redraw_samples_dict.values()):\n", " axd[\"upper\"].scatter(ls[:, 0], ls[:, 1], s=1, color=\"silver\")\n", "theta = np.linspace(0, 2 * np.pi, 1000)\n", "for i, level in enumerate(levels.values()):\n", @@ -563,7 +582,7 @@ "post_range = [-15, 0]\n", "\n", "bins = np.linspace(post_range[0], post_range[1], 32)\n", - "for i, logL in enumerate(sample_log_likelihoods.values()):\n", + "for i, logL in enumerate(redraw_log_l_dict.values()):\n", " axd[\"lower_left\"].hist(logL, bins=bins, color=colours[i], histtype='step', density=True)\n", "# axs[1].plot(lambda_vec, lambda_pdf, c='C1', lw=2.0, ls='--')\n", "axd[\"lower_left\"].set_xlabel(r\"$\\ln \\mathcal{L}$\")\n", @@ -573,7 +592,7 @@ "\n", "# post_range = [-20, final_log_l.max()]\n", "axd[\"lower_right\"].hist(\n", - " final_log_l, 50, density=True, weights=post_weights, histtype=\"stepfilled\",\n", + " redraw_log_l, 50, density=True, weights=post_weights, histtype=\"stepfilled\",\n", " range=post_range, color=colours[1]\n", ")\n", "axd[\"lower_right\"].plot(lambda_vec, lambda_pdf_values, c='C1', ls='--')\n", @@ -630,6 +649,19 @@ "print(f\"Final estimate: {Z_hat} +/- {Z_hat_sigma}\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "Z_hat_redraw = evidence(redraw_log_l, redraw_log_p, redraw_log_q)\n", + "Z_hat_sigma_redraw = np.sqrt(evidence_error(redraw_log_l, redraw_log_p, redraw_log_q))\n", + "print(f\"Redraw estimate: {Z_hat_redraw} +/- {Z_hat_sigma_redraw}\")" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/utils.py b/utils.py index 521a8e5..da23d0b 100644 --- a/utils.py +++ b/utils.py @@ -93,7 +93,7 @@ def find_results_files(path, file="summary.json"): """Find all of the results files""" p = path + "/**/" + file logger.info(f"Searching for: {p}") - files = glob.glob(p, recursive=True) + files = natural_sort(glob.glob(p, recursive=True)) logger.info(f"Found {len(files)} results files") return files