Skip to content

Commit

Permalink
Doctest fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bocklund committed Jul 12, 2024
1 parent 709f593 commit d9e91a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions espei/priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class rv_zero(object):
--------
>>> import numpy as np
>>> rv = rv_zero()
>>> np.isclose(rv.logpdf(-np.inf), 0.0)
>>> bool(np.isclose(rv.logpdf(-np.inf), 0.0))
True
>>> np.isclose(rv.logpdf(1.0), 0.0)
>>> bool(np.isclose(rv.logpdf(1.0), 0.0))
True
>>> np.isclose(rv.logpdf(0.0), 0.0)
>>> bool(np.isclose(rv.logpdf(0.0), 0.0))
True
"""
Expand All @@ -41,16 +41,16 @@ class DistributionParameter(object):
Examples
--------
>>> dp = DistributionParameter(5.0, 'absolute') # always get back 5
>>> dp.value(1.0) == 5.0
>>> bool(dp.value(1.0) == 5.0)
True
>>> dp = DistributionParameter(-2.0, 'relative') # multiply by -2
>>> dp.value(2.0) == -4.0
>>> bool(dp.value(2.0) == -4.0)
True
>>> dp = DistributionParameter(-1.0, 'shift_absolute') # subtract 1
>>> dp.value(2.0) == 1.0
>>> bool(dp.value(2.0) == 1.0)
True
>>> dp = DistributionParameter(-0.5, 'shift_relative') # subtract 1/2 value
>>> dp.value(2.0) == 1.0
>>> bool(dp.value(2.0) == 1.0)
True
"""
Expand Down Expand Up @@ -155,9 +155,9 @@ def get_prior(self, value):
>>> import numpy as np
>>> from espei.priors import PriorSpec
>>> tri_spec = {'name': 'triangular', 'loc_shift_relative': -0.5, 'scale_shift_relative': 0.5, 'c': 0.5}
>>> np.isneginf(PriorSpec(**tri_spec).get_prior(10).logpdf(5.1))
>>> bool(np.isneginf(PriorSpec(**tri_spec).get_prior(10).logpdf(5.1)))
False
>>> np.isneginf(PriorSpec(**tri_spec).get_prior(10).logpdf(4.9))
>>> bool(np.isneginf(PriorSpec(**tri_spec).get_prior(10).logpdf(4.9)))
True
"""
Expand Down
2 changes: 1 addition & 1 deletion espei/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def optimal_parameters(trace_array, lnprob_array, kth=0):
>>> from espei.utils import optimal_parameters
>>> trace = np.array([[[1, 0], [2, 0], [3, 0], [0, 0]], [[0, 2], [0, 4], [0, 6], [0, 0]]]) # 3 iterations of 4 allocated
>>> lnprob = np.array([[-6, -4, -2, 0], [-3, -1, -2, 0]])
>>> np.all(np.isclose(optimal_parameters(trace, lnprob), np.array([0, 4])))
>>> bool(np.all(np.isclose(optimal_parameters(trace, lnprob), np.array([0, 4]))))
True
"""
Expand Down

0 comments on commit d9e91a8

Please sign in to comment.