Skip to content

Commit

Permalink
MAINT: avoid call to deprecated scipy.special.btdtr and `scipy.spec…
Browse files Browse the repository at this point in the history
…ial.btdtri` functions (#884)

* MAINT: avoid call to deprecated `scipy.special.btdtri` function

Replaces the call with the equivalent call to `betaincinv`.

* MAINT: avoid call to deprecated `scipy.special.btdtr` function

* MAINT: avoid importing from `scipy.special._ufuncs`
  • Loading branch information
mj-will authored Jan 9, 2025
1 parent 4882d0b commit 391d359
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions bilby/core/prior/analytical.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import numpy as np
from scipy.special import erfinv
from scipy.special._ufuncs import xlogy, erf, log1p, stdtrit, gammaln, stdtr, \
btdtri, betaln, btdtr, gammaincinv, gammainc
from scipy.special import (
xlogy,
erf,
erfinv,
log1p,
stdtrit,
gammaln,
stdtr,
betaln,
betainc,
betaincinv,
gammaincinv,
gammainc,
)

from .base import Prior
from ..utils import logger
Expand Down Expand Up @@ -967,7 +978,7 @@ def rescale(self, val):
This maps to the inverse CDF. This has been analytically solved for this case.
"""
return btdtri(self.alpha, self.beta, val) * (self.maximum - self.minimum) + self.minimum
return betaincinv(self.alpha, self.beta, val) * (self.maximum - self.minimum) + self.minimum

def prob(self, val):
"""Return the prior probability of val.
Expand Down Expand Up @@ -1014,10 +1025,12 @@ def cdf(self, val):
elif val < self.minimum:
return 0.
else:
return btdtr(self.alpha, self.beta,
(val - self.minimum) / (self.maximum - self.minimum))
return betainc(
self.alpha, self.beta,
(val - self.minimum) / (self.maximum - self.minimum)
)
else:
_cdf = np.nan_to_num(btdtr(self.alpha, self.beta,
_cdf = np.nan_to_num(betainc(self.alpha, self.beta,
(val - self.minimum) / (self.maximum - self.minimum)))
_cdf[val < self.minimum] = 0.
_cdf[val > self.maximum] = 1.
Expand Down

0 comments on commit 391d359

Please sign in to comment.