Skip to content

Commit

Permalink
improve testing and stability
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Jun 28, 2024
1 parent 567b0d4 commit caa13de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hierarc/Sampling/Distributions/anisotropy_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def draw_anisotropy(
else:
a_ani_draw = np.random.normal(a_ani, a_ani_sigma)
if a_ani_draw < self._a_ani_min or a_ani_draw > self._a_ani_max:
return self.draw_anisotropy(a_ani, a_ani_sigma)
return self.draw_anisotropy(a_ani, a_ani_sigma, beta_inf, beta_inf_sigma)
kwargs_return["a_ani"] = a_ani_draw
else:
kwargs_return["a_ani"] = a_ani
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy.testing as npt
from hierarc.Sampling.Distributions.anisotropy_distributions import (
AnisotropyDistribution,
)
Expand Down Expand Up @@ -47,3 +48,44 @@ def test_draw_anisotropy(self):
)
kwargs_drawn = ani_dist.draw_anisotropy()
assert "a_ani" not in kwargs_drawn

ani_dist = AnisotropyDistribution(
anisotropy_model="GOM",
anisotropy_sampling=True,
distribution_function="NONE",
kwargs_anisotropy_min=None,
kwargs_anisotropy_max=None,
)
kwargs_drawn = ani_dist.draw_anisotropy(a_ani=1, beta_inf=0.9)
assert kwargs_drawn["a_ani"] == 1
assert kwargs_drawn["beta_inf"] == 0.9

kwargs_anisotropy = {
"a_ani": 1,
"beta_inf": 0.8,
"a_ani_sigma": 2,
"beta_inf_sigma": 2,
}

for i in range(100):
kwargs_drawn = self._ani_dist.draw_anisotropy(**kwargs_anisotropy)

def test_raises(self):

with npt.assert_raises(ValueError):
kwargs_anisotropy = {
"a_ani": -1,
"beta_inf": 0.8,
"a_ani_sigma": 0.1,
"beta_inf_sigma": 0.2,
}
kwargs_drawn = self._ani_dist.draw_anisotropy(**kwargs_anisotropy)

with npt.assert_raises(ValueError):
kwargs_anisotropy = {
"a_ani": 1,
"beta_inf": -1,
"a_ani_sigma": 0.1,
"beta_inf_sigma": 0.2,
}
kwargs_drawn = self._ani_dist.draw_anisotropy(**kwargs_anisotropy)

0 comments on commit caa13de

Please sign in to comment.