Skip to content

Commit

Permalink
Testing a fix by truncating cdf to precision.
Browse files Browse the repository at this point in the history
  • Loading branch information
gokuld committed Jun 1, 2023
1 parent 005edbe commit 61f2de5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pymc/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,21 @@ def check_selfconsistency_discrete_icdf(
distribution: Distribution,
domain: Domain,
paramdomains: Dict[str, Domain],
decimal: Optional[int] = None,
n_samples: int = 100,
) -> None:
"""
Check that the icdf and logcdf functions of the distribution are
consistent for a sample of values in the domain of the
distribution.
"""

def ftrunc(values, decimal=0):
return np.trunc(values * 10**decimal) / (10**decimal)

if decimal is None:
decimal = select_by_precision(float64=6, float32=3)

dist = create_dist_from_paramdomains(distribution, paramdomains)

value = pt.TensorType(dtype="float64", shape=[])("value")
Expand All @@ -726,7 +734,7 @@ def check_selfconsistency_discrete_icdf(
with pytensor.config.change_flags(mode=Mode("py")):
expected_value = value
computed_value = dist_icdf_fn(
**point, value=np.exp(dist_logcdf_fn(**point, value=value))
**point, value=ftrunc(np.exp(dist_logcdf_fn(**point, value=value)), decimal=decimal)
)
npt.assert_almost_equal(
expected_value,
Expand Down

0 comments on commit 61f2de5

Please sign in to comment.