Given two reals x
and y
, I want to compute the following function in python:
log Pr [ x <= t <= y ],
where t
is sampled from a normal distribution.
One naive implementation is to use scipy.stats.norm
.
np.log(scipy.stats.norm.cdf(y) - scipy.stats.norm.cdf(x))
Unfortunately, this causes an underflow when x
and y
are far from 0
.
How can one prevent such a numerical error?