Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions examples/plot_realisations_old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import numpy as np
import matplotlib.pyplot as plt
import argparse
import os
import ex_utils

savefigs = True

# Parse arguments.
parser = argparse.ArgumentParser(
"Create violin plot of inverse evidences" + "from many realisations"
)
parser.add_argument(
"filename_realisations",
metavar="filename_realisations",
type=str,
help="Name of file containing realisations",
)
parser.add_argument(
"filename_analytic",
metavar="filename_analytic",
type=str,
help="Name of file containing analytic inverse variance",
)
args = parser.parse_args()

# Load data.
evidence_inv_summary = np.loadtxt(args.filename_realisations)
evidence_inv_realisations = evidence_inv_summary[:, 0]
evidence_inv_var_realisations = evidence_inv_summary[:, 1]
evidence_inv_var_var_realisations = evidence_inv_summary[:, 2]

evidence_inv_analytic = np.loadtxt(args.filename_analytic)

# Plot inverse evidence.
plt.rcParams.update({"font.size": 20})
ax = ex_utils.plot_realisations(
mc_estimates=evidence_inv_realisations,
std_estimated=np.sqrt(np.mean(evidence_inv_var_realisations)),
analytic_val=evidence_inv_analytic,
analytic_text=r"Truth",
)
plt.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
ax.set_ylabel(r"Inverse evidence ($\rho$)")
# ax.set_ylim([0.0, 0.01])

filename_base = os.path.basename(args.filename_realisations)
filename_base_noext = os.path.splitext(filename_base)[0]
if savefigs:
plt.savefig(
"./examples/plots/" + filename_base_noext + "_evidence_inv.png",
bbox_inches="tight",
)

# Plot variance of inverse evidence.
ax = ex_utils.plot_realisations(
mc_estimates=evidence_inv_var_realisations,
std_estimated=np.sqrt(np.mean(evidence_inv_var_var_realisations)),
)
plt.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
ax.set_ylabel(r"Inverse evidence variance ($\sigma^2$)")
# ax.set_ylim([-0.1, 1])

if savefigs:
plt.savefig(
"./examples/plots/" + filename_base_noext + "_evidence_inv_var.png",
bbox_inches="tight",
)

plt.show(block=False)

input("\nPress Enter to continue...")
14 changes: 8 additions & 6 deletions harmonic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,22 @@ def cross_validation(
)
)
hm.logs.debug_log(
"cross_validation: evidence_inv = {}".format(ev.evidence_inv)
"cross_validation: ln_evidence_inv = {}".format(ev.ln_evidence_inv)
)
hm.logs.debug_log(
"cross_validation: evidence_inv_var = {}".format(ev.evidence_inv_var)
"cross_validation: ln_evidence_inv_var = {}".format(
ev.ln_evidence_inv_var
)
)
hm.logs.debug_log(
"cross_validation:"
+ " evidence_inv_var**0.5/evidence_inv = {}".format(
ev.evidence_inv_var**0.5 / ev.evidence_inv
+ " np.exp(ev.ln_evidence_inv_var)**0.5 / np.exp(ev.ln_evidence_inv) = {}".format(
np.exp(ev.ln_evidence_inv_var) ** 0.5 / np.exp(ev.ln_evidence_inv)
)
)
hm.logs.debug_log(
"cross_validation: evidence_inv_var_var = {}".format(
ev.evidence_inv_var_var
"cross_validation: ln_evidence_inv_var_var = {}".format(
ev.ln_evidence_inv_var_var
)
)

Expand Down
3 changes: 2 additions & 1 deletion requirements/requirements-core.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wheels work for the Python versions we support (which is why tests don't fail on Github) but I got this error when using Python 3.13. We don't have support for Python 3.13 anyway so we can also leave this without a pinned version and wait with Python 3.13 support until it's more mature.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy <= 1.26.4
dm-tree==0.1.8 # No mac wheels for latest version 0.1.9 (as of 20/03/2025)
setuptools==68.0.0
wheel==0.41.0
cython>=0.29.30
Expand All @@ -15,4 +16,4 @@ flax
#chex==0.1.6
distrax
cloudpickle
getdist
getdist
Loading