Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bounds and psi param for hurdle #537

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/gallery/chisquared.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ for nu in nus:

```{eval-rst}
======== ==========================================
Support :math:`x \in (0, \infty)`
Support :math:`x \in [0, \infty)`
Mean :math:`\nu`
Variance :math:`2\nu`
======== ==========================================
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/gallery/exponential.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ for beta in betas:

```{eval-rst}
======== ==========================================
Support :math:`x \in (0, \infty)`
Support :math:`x \in [0, \infty)`
Mean :math:`\frac{1}{\lambda}`
Variance :math:`\frac{1}{\lambda^2}`
======== ==========================================
Expand Down
2 changes: 1 addition & 1 deletion preliz/distributions/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def nb_entropy(alpha, beta):

@nb.vectorize(nopython=True, cache=True)
def nb_logpdf(x, alpha, beta):
if x < 0 or x > 1:
if x <= 0 or x >= 1:
return -np.inf
else:
beta_ = gammaln(alpha) + gammaln(beta) - gammaln(alpha + beta)
Expand Down
2 changes: 1 addition & 1 deletion preliz/distributions/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def nb_ppf(q, alpha, beta, lower, upper):

@nb.vectorize(nopython=True, cache=True)
def nb_logpdf(x, alpha, beta):
if x < 0:
if x <= 0:
return -np.inf
else:
x = x / (1 / beta)
Expand Down
8 changes: 4 additions & 4 deletions preliz/distributions/hurdle.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ class Hurdle(DistributionTransformer):
Expected proportion of the base distribution (0 < psi < 1)
"""

def __init__(self, dist, psi, **kwargs):
def __init__(self, dist, psi=None, **kwargs):
self.dist = dist
self.psi = psi
super().__init__()
self._parametrization(**kwargs)
self._parametrization(psi, **kwargs)

def _parametrization(self, **kwargs):
def _parametrization(self, psi=None, **kwargs):
dist_params = []
if not kwargs:
if hasattr(self.dist, "params"):
Expand All @@ -65,6 +64,7 @@ def _parametrization(self, **kwargs):
dist_params.append(value)
setattr(self, key, value)

self.psi = psi
self.params = (*dist_params, self.psi)
self.param_names = (*self.dist.param_names, "psi")
if all_not_none(*dist_params):
Expand Down
2 changes: 1 addition & 1 deletion preliz/distributions/kumaraswamy.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def nb_entropy(a, b):

@nb.vectorize(nopython=True, cache=True)
def nb_logpdf(x, a, b):
if x < 0 or x > 1:
if x <= 0 or x >= 1:
return -np.inf
else:
return np.log(a * b) + xlogy((a - 1), x) + xlog1py((b - 1), -(x**a))
Expand Down
7 changes: 6 additions & 1 deletion preliz/tests/test_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@
{"loc": 0, "scale": 2},
), # not in scipy
(InverseGamma, stats.invgamma, {"alpha": 5, "beta": 2}, {"a": 5, "scale": 2}),
(Kumaraswamy, stats.beta, {"a": 1, "b": 5}, {"a": 1, "b": 5}), # not in scipy
(
Kumaraswamy,
stats.beta,
{"a": 1.00000001, "b": 5},
{"a": 1.00000001, "b": 5},
), # not in scipy
(Laplace, stats.laplace, {"mu": 2.5, "b": 4}, {"loc": 2.5, "scale": 4}),
(LogLogistic, stats.fisk, {"alpha": 1, "beta": 8}, {"c": 8}),
(Logistic, stats.logistic, {"mu": 2.5, "s": 4}, {"loc": 2.5, "scale": 4}),
Expand Down
Loading