Skip to content

Commit

Permalink
Add tests for invalid parameters Uniform, Triangular, DiscreteUniform
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 committed Feb 10, 2021
1 parent a1e753f commit 8581fd0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@ def test_uniform(self):
lambda value, lower, upper: sp.uniform.logcdf(value, lower, upper - lower),
skip_paramdomain_outside_edge_test=True,
)
# Custom logp / logcdf check for invalid parameters
invalid_dist = Uniform.dist(lower=1, upper=0)
assert invalid_dist.logp(0.5).tag.test_value == -np.inf
assert invalid_dist.logcdf(2).tag.test_value == -np.inf

def test_triangular(self):
self.check_logp(
Expand All @@ -817,6 +821,14 @@ def test_triangular(self):
lambda value, c, lower, upper: sp.triang.logcdf(value, c - lower, lower, upper - lower),
skip_paramdomain_outside_edge_test=True,
)
# Custom logp check for invalid value
valid_dist = Triangular.dist(lower=0, upper=1, c=2.0)
assert np.all(valid_dist.logp(np.array([1.9, 2.0, 2.1])).tag.test_value == -np.inf)

# Custom logp / logcdf check for invalid parameters
invalid_dist = Triangular.dist(lower=1, upper=0, c=2.0)
assert invalid_dist.logp(0.5).tag.test_value == -np.inf
assert invalid_dist.logcdf(2).tag.test_value == -np.inf

def test_bound_normal(self):
PositiveNormal = Bound(Normal, lower=0.0)
Expand Down Expand Up @@ -850,6 +862,10 @@ def test_discrete_unif(self):
Rdunif,
{"lower": -Rplusdunif, "upper": Rplusdunif},
)
# Custom logp / logcdf check for invalid parameters
invalid_dist = DiscreteUniform.dist(lower=1, upper=0)
assert invalid_dist.logp(0.5).tag.test_value == -np.inf
assert invalid_dist.logcdf(2).tag.test_value == -np.inf

def test_flat(self):
self.check_logp(Flat, Runif, {}, lambda value: 0)
Expand Down

0 comments on commit 8581fd0

Please sign in to comment.