Skip to content

Commit

Permalink
Merge branch 'main' into multimodal_base
Browse files Browse the repository at this point in the history
  • Loading branch information
alicjapolanska committed Aug 8, 2024
2 parents 8d1a860 + 6e29129 commit b1560e1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
|github| |tests| |docs| |codecov| |pypi| |licence| |arxiv1| |arxiv2| |arxiv3| |arxiv4|


.. |logo| image:: ./docs/assets/harm_badge_simple.svg
:width: 32
:height: 32
:align: center
|logo|

|logo| Harmonic
.. |logo| image:: /docs/assets/harm_badge_simple.svg
:width: 90
=================================================================================================================

``harmonic`` is an open source, well tested and documented Python implementation of the *learnt harmonic mean estimator* (`McEwen et al. 2021 <https://arxiv.org/abs/2111.12720>`_) to compute the marginal likelihood (Bayesian evidence), required for Bayesian model selection.
Expand Down
2 changes: 1 addition & 1 deletion examples/rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def ln_prior_uniform(x, xmin=-10.0, xmax=10.0, ymin=-5.0, ymax=15.0):
"""Compute log_e of uniform prior.
"""Compute log_e uniform prior.
Args:
Expand Down
2 changes: 1 addition & 1 deletion harmonic/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def compute_ln_inv_evidence_errors(self):
if np.abs(ratio - 1.0) > 1e-8:
ln_evidence_err_neg = np.log(1.0 - ratio)
else:
ln_evidence_err_neg = np.NINF
ln_evidence_err_neg = -np.inf

ln_evidence_err_pos = np.log(1.0 + ratio)

Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-core.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
numpy <= 1.26.4
setuptools==68.0.0
wheel==0.41.0
cython>=0.29.30
Expand Down
13 changes: 7 additions & 6 deletions tests/test_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def test_add_chains():

assert np.exp(cal_ev.ln_evidence_inv) == pytest.approx(0.159438606)
assert np.exp(cal_ev.ln_evidence_inv_var) == pytest.approx(1.164628268e-07)
assert np.exp(cal_ev.ln_evidence_inv_var_var)**0.5 == pytest.approx(1.142786462e-08)
assert np.exp(cal_ev.ln_evidence_inv_var_var) ** 0.5 == pytest.approx(
1.142786462e-08
)

nsamples1 = 300
chains1 = ch.Chains(ndim)
Expand All @@ -155,7 +157,7 @@ def test_add_chains():

assert np.exp(ev.ln_evidence_inv) == pytest.approx(0.159438606)
assert np.exp(ev.ln_evidence_inv_var) == pytest.approx(1.164628268e-07)
assert np.exp(ev.ln_evidence_inv_var_var)**0.5 == pytest.approx(1.142786462e-08)
assert np.exp(ev.ln_evidence_inv_var_var) ** 0.5 == pytest.approx(1.142786462e-08)

return

Expand Down Expand Up @@ -250,7 +252,7 @@ def test_compute_ln_inv_evidence_errors(model):
ev.ln_evidence_inv_var = ln_ev_inv_var

zeta_neg, zeta_pos = ev.compute_ln_inv_evidence_errors()
assert zeta_neg == np.NINF
assert zeta_neg == -np.inf
assert zeta_pos == pytest.approx(np.log(2.0))

# Check case where ln_ev_inv_var = ln_ev_inv
Expand Down Expand Up @@ -310,9 +312,7 @@ def test_compute_bayes_factors():
ev2.chains_added = True

bf12_check = ev2_inv / ev1_inv * (1.0 + ev2_inv_var / ev2_inv**2)
bf12_var_check = (
ev1_inv**2 * ev2_inv_var + ev2_inv**2 * ev1_inv_var
) / ev1_inv**4
bf12_var_check = (ev1_inv**2 * ev2_inv_var + ev2_inv**2 * ev1_inv_var) / ev1_inv**4

(bf12, bf12_std) = cbe.compute_bayes_factor(ev1, ev2)

Expand All @@ -335,6 +335,7 @@ def test_compute_bayes_factors():
assert bf12 == pytest.approx(evidence)
assert bf12_std == pytest.approx(evidence_std)


@pytest.mark.parametrize("model", models_to_test_2)
def test_serialization(model):
nchains = 200
Expand Down

0 comments on commit b1560e1

Please sign in to comment.