Skip to content

Commit 713c8c4

Browse files
authored
Merge pull request scipy#21901 from mdhaber/gh21900
MAINT: stats.dpareto_lognorm._cdf: treat special case at x=0
2 parents d821271 + 0d3a863 commit 713c8c4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

scipy/stats/_continuous_distns.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ class dpareto_lognorm_gen(rv_continuous):
18461846
\left( R(y_1) + R(y_2) \right)
18471847
18481848
where :math:`R(t) = \frac{1 - \Phi(t)}{\phi(t)}`,
1849-
:math:`phi` and :math:`Phi` are the normal PDF and CDF, respectively,
1849+
:math:`\phi` and :math:`\Phi` are the normal PDF and CDF, respectively,
18501850
:math:`y_1 = \alpha \sigma - \frac{\log x - \mu}{\sigma}`,
18511851
and :math:`y_2 = \beta \sigma + \frac{\log x - \mu}{\sigma}`
18521852
for real numbers :math:`x` and :math:`\mu`, :math:`\sigma > 0`,
@@ -1923,20 +1923,24 @@ def _logpdf(self, x, u, s, a, b):
19231923
return out[()]
19241924

19251925
def _logcdf(self, x, u, s, a, b):
1926-
log_y, m = np.log(x), u # compare against [1] Eq. 2
1927-
z = (log_y - m) / s
1928-
x1 = a * s - z
1929-
x2 = b * s + z
1930-
t1 = self._logPhi(z)
1931-
t2 = self._logphi(z)
1932-
t3 = (np.log(b) + self._logR(x1))
1933-
t4 = (np.log(a) + self._logR(x2))
1934-
t1, t2, t3, t4, one = np.broadcast_arrays(t1, t2, t3, t4, 1)
1935-
# t3 can be smaller than t4, so we have to consider log of negative number
1936-
# This would be much simpler, but `return_sign` is available, so use it?
1937-
# t5 = sc.logsumexp([t3, t4 + np.pi*1j])
1938-
t5, sign = sc.logsumexp([t3, t4], b=[one, -one], axis=0, return_sign=True)
1939-
return sc.logsumexp([t1, t2 + t5 - np.log(a + b)], b=[one, -one*sign], axis=0)
1926+
with np.errstate(invalid='ignore', divide='ignore'):
1927+
log_y, m = np.log(x), u # compare against [1] Eq. 2
1928+
z = (log_y - m) / s
1929+
x1 = a * s - z
1930+
x2 = b * s + z
1931+
t1 = self._logPhi(z)
1932+
t2 = self._logphi(z)
1933+
t3 = (np.log(b) + self._logR(x1))
1934+
t4 = (np.log(a) + self._logR(x2))
1935+
t1, t2, t3, t4, one = np.broadcast_arrays(t1, t2, t3, t4, 1)
1936+
# t3 can be smaller than t4, so we have to consider log of negative number
1937+
# This would be much simpler, but `return_sign` is available, so use it?
1938+
# t5 = sc.logsumexp([t3, t4 + np.pi*1j])
1939+
t5, sign = sc.logsumexp([t3, t4], b=[one, -one], axis=0, return_sign=True)
1940+
temp = [t1, t2 + t5 - np.log(a + b)]
1941+
out = np.asarray(sc.logsumexp(temp, b=[one, -one*sign], axis=0))
1942+
out[x == 0] = -np.inf
1943+
return out[()]
19401944

19411945
def _logsf(self, x, u, s, a, b):
19421946
return _log1mexp(self._logcdf(x, u, s, a, b))

0 commit comments

Comments
 (0)