tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow

Home Page:https://www.tensorflow.org/probability/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TruncatedCauchy gives wrong results sometimes

Joshuaalbert opened this issue · comments

TruncatedCauchy quantile gives NaN for some parameter combinations. Similar to #1788

Numerical stability should be reinforced or it severely limits to usefulness of the distribution.

MVCE

import jax
import jax.numpy as jnp
import pytest
import tensorflow_probability.substrates.jax as tfp

tfpd = tfp.distributions


@pytest.mark.parametrize("scale", [0.1, 1.])
@pytest.mark.parametrize("low", [0.0])
@pytest.mark.parametrize("high", [1e6])
def test_truncated_cauchy(low, high, scale):
    dist = tfpd.TruncatedCauchy(1.0, scale, low=low, high=high)
    u = jnp.linspace(0., 1., 100)

    samples = jax.vmap(dist.quantile)(u)
    assert jnp.all(jnp.isfinite(samples))
    assert jnp.all(samples >= low)
    assert jnp.all(samples <= high)