Skip to content

Commit 60bed0a

Browse files
committed
small fixes and tests
1 parent 3dfa1a2 commit 60bed0a

File tree

12 files changed

+34
-41
lines changed

12 files changed

+34
-41
lines changed

docs/gallery_content.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ Continuous Distributions
282282
+++
283283
Rice
284284

285+
.. grid-item-card::
286+
:link: ./distributions/gallery/scaledinversechisquared.html
287+
:text-align: center
288+
:shadow: none
289+
:class-card: example-gallery
290+
291+
.. image:: distributions/img/ScaledInverseChiSquared.png
292+
:alt: ScaledInverseChiSquared
293+
294+
+++
295+
Scaled-Inverse-Chi-Squared
296+
285297
.. grid-item-card::
286298
:link: ./distributions/gallery/skewnormal.html
287299
:text-align: center

docs/gallery_tags.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ These distributions are defined over a continuous range of values.
3333
- `Normal <./distributions/gallery/normal.html>`_
3434
- `Pareto <./distributions/gallery/pareto.html>`_
3535
- `Rice <./distributions/gallery/rice.html>`_
36+
- `Scaled Inverse Chi-Squared <./distributions/gallery/scaledinversechisquared.html>`_
3637
- `Skew-Normal <./distributions/gallery/skewnormal.html>`_
3738
- `Student's t <./distributions/gallery/students_t.html>`_
3839
- `Skew-Student's t <./distributions/gallery/skew_studentt.html>`_
@@ -106,6 +107,7 @@ Distributions with skewed (non‐symmetric) shapes include:
106107
- `Moyal <./distributions/gallery/moyal.html>`_
107108
- `Pareto <./distributions/gallery/pareto.html>`_
108109
- `Rice <./distributions/gallery/rice.html>`_
110+
- `Scaled Inverse Chi-Squared <./distributions/gallery/scaledinversechisquared.html>`_
109111
- `Skew-Normal <./distributions/gallery/skewnormal.html>`_
110112
- `Skew-Student's t <./distributions/gallery/skew_studentt.html>`_
111113
- `Weibull <./distributions/gallery/weibull.html>`_
@@ -186,6 +188,8 @@ Distributions supported on the non‐negative real numbers.
186188
- `Wald <./distributions/gallery/wald.html>`_
187189
- `Log-Logistic <./distributions/gallery/log_logistic.html>`_
188190
- `Logit-Normal <./distributions/gallery/logit_normal.html>`_
191+
- `Scaled Inverse Chi-Squared <./distributions/gallery/scaledinversechisquared.html>`_
192+
189193

190194
**Discrete:**
191195
- `Bernoulli <./distributions/gallery/bernoulli.html>`_
@@ -243,6 +247,7 @@ The following distributions are univariate (one-dimensional).
243247
- `Normal <./distributions/gallery/normal.html>`_
244248
- `Pareto <./distributions/gallery/pareto.html>`_
245249
- `Rice <./distributions/gallery/rice.html>`_
250+
- `Scaled Inverse Chi-Squared <./distributions/gallery/scaledinversechisquared.html>`_
246251
- `Skew-Normal <./distributions/gallery/skewnormal.html>`_
247252
- `Student's t <./distributions/gallery/students_t.html>`_
248253
- `Skew-Student's t <./distributions/gallery/skew_studentt.html>`_

preliz/distributions/categorical.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from preliz.distributions.distributions import Discrete
55
from preliz.internal.distribution_helper import all_not_none, eps
66
from preliz.internal.optimization import optimize_ml
7-
from preliz.internal.special import expit, logit, xlogx
7+
from preliz.internal.special import expit, logit, ppf_bounds_disc, xlogx
88

99

1010
class Categorical(Discrete):
@@ -64,12 +64,6 @@ def _from_logit_p(self, logit_p):
6464
def _to_logit_p(self, p):
6565
return logit(p)
6666

67-
def _get_frozen(self):
68-
frozen = None
69-
if all_not_none(self.params):
70-
frozen = self.dist(n=1, p=self.p)
71-
return frozen
72-
7367
def _update(self, p):
7468
self.p = np.array(p)
7569
self._n = len(p)
@@ -152,7 +146,7 @@ def nb_cdf(x, p):
152146

153147
def nb_ppf(q, p):
154148
cumsum = np.cumsum(p)
155-
return np.searchsorted(cumsum, q)
149+
return ppf_bounds_disc(np.searchsorted(cumsum, q, side="left"), q, 0, len(p) - 1).astype(int)
156150

157151

158152
@nb.njit(cache=True)

preliz/distributions/chi_squared.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from scipy.special import gammainc, gammaincinv
44

55
from preliz.distributions.distributions import Continuous
6-
from preliz.internal.distribution_helper import all_not_none, eps
6+
from preliz.internal.distribution_helper import eps
77
from preliz.internal.optimization import optimize_ml
88
from preliz.internal.special import cdf_bounds, digamma, gammaln, ppf_bounds_cont, xlogy
99

@@ -56,12 +56,6 @@ def _parametrization(self, nu=None):
5656
if self.nu is not None:
5757
self._update(self.nu)
5858

59-
def _get_frozen(self):
60-
frozen = None
61-
if all_not_none(self.params):
62-
frozen = self.dist(self.nu)
63-
return frozen
64-
6559
def _update(self, nu):
6660
self.nu = np.float64(nu)
6761
self.params = (self.nu,)

preliz/distributions/discrete_uniform.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ def _parametrization(self, lower=None, upper=None):
6161
self.lower = lower
6262
self.upper = upper
6363

64-
def _get_frozen(self):
65-
frozen = None
66-
if all_not_none(self.params):
67-
frozen = self.dist(self.lower, self.upper + 1)
68-
return frozen
69-
7064
def _update(self, lower, upper):
7165
self.lower = np.floor(lower)
7266
self.upper = np.ceil(upper)

preliz/distributions/kumaraswamy.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33

44
from preliz.distributions.distributions import Continuous
5-
from preliz.internal.distribution_helper import all_not_none, eps
5+
from preliz.internal.distribution_helper import eps
66
from preliz.internal.optimization import optimize_ml, optimize_moments
77
from preliz.internal.special import beta, cdf_bounds, digamma, ppf_bounds_cont, xlog1py, xlogy
88

@@ -57,12 +57,6 @@ def _parametrization(self, a=None, b=None):
5757
if (a and b) is not None:
5858
self._update(a, b)
5959

60-
def _get_frozen(self):
61-
frozen = None
62-
if all_not_none(self.params):
63-
frozen = self.dist(self.a, self.b)
64-
return frozen
65-
6660
def _update(self, a, b):
6761
self.a = np.float64(a)
6862
self.b = np.float64(b)

preliz/distributions/logitnormal.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ def _parametrization(self, mu=None, sigma=None, tau=None):
7979
if all_not_none(mu, sigma):
8080
self._update(mu, sigma)
8181

82-
def _get_frozen(self):
83-
frozen = None
84-
if all_not_none(self.params):
85-
frozen = self.dist(self.mu, self.sigma)
86-
return frozen
87-
8882
def _update(self, mu, sigma):
8983
self.mu = np.float64(mu)
9084
self.sigma = np.float64(sigma)

preliz/distributions/zi_negativebinomial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ZeroInflatedNegativeBinomial(Discrete):
4646
======== ==========================
4747
Support :math:`x \in \mathbb{N}_0`
4848
Mean :math:`\psi\mu`
49-
Var .. math::
49+
Variance .. math::
5050
\psi \left(\frac{{\mu^2}}{{\alpha}}\right) +\
5151
\psi \mu + \psi \mu^2 - \psi^2 \mu^2
5252
======== ==========================

preliz/tests/test_non_scipy.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
from scipy import integrate
44
from scipy.stats import kurtosis, skew
55

6-
from preliz.distributions import DiscreteWeibull, ScaledInverseChiSquared
6+
from preliz.distributions import Categorical, DiscreteWeibull, ScaledInverseChiSquared
7+
8+
9+
def test_categorical():
10+
p = [0.2, 0.5, 0.3]
11+
q = [0.2, 0.7, 1]
12+
dist = Categorical(p)
13+
assert dist.p.sum() == 1.0
14+
assert all(dist.pdf([0, 1, 2]) == p)
15+
assert all(dist.cdf([0, 1, 2]) == np.cumsum(p))
16+
assert all(dist.cdf(dist.ppf(q)) == q)
717

818

919
def test_disc_weibull_vs_random():

preliz/unidimensional/maxent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def maxent(
7070
:context: close-figs
7171
:include-source: true
7272
73-
>>>
7473
>>> import preliz as pz
7574
>>> pz.style.use('preliz-doc')
7675
>>> pz.maxent(pz.Gamma(), 1, 8, 0.9)
@@ -82,7 +81,6 @@ def maxent(
8281
:context: close-figs
8382
:include-source: true
8483
85-
>>>
8684
>>> import preliz as pz
8785
>>> pz.style.use('preliz-doc')
8886
>>> pz.maxent(pz.HalfStudentT(nu=4), 0, 12, 0.9)

0 commit comments

Comments
 (0)