Skip to content

Commit f29cf14

Browse files
authored
refactor, small fixes and package updates (#575)
* refactor and small fixes to distributions * black * remove unused kwargs * update packages * update packages * update packages * update test, drop 3.13 * centralize docstrings for common methods * disable lint
1 parent e613494 commit f29cf14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+138
-854
lines changed

.github/workflows/publish-to-test-pypi.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@master
14-
- name: Set up Python 3.10
14+
- name: Set up Python 3.11
1515
uses: actions/setup-python@v3
1616
with:
17-
python-version: "3.10"
17+
python-version: "3.11"
1818

1919
- name: Install pypa/build
2020
run: >-

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: ["3.10", "3.11", "3.12"]
18+
python-version: ["3.11", "3.12"]
1919

2020
name: Set up Python ${{ matrix.python-version }}
2121
steps:

.readthedocs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: 2
55
build:
66
os: ubuntu-22.04
77
tools:
8-
python: "3.10"
8+
python: "3.11"
99

1010
python:
1111
install:

docs/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The Zen of PreliZ
5252

5353
Dependencies
5454
============
55-
PreliZ is tested on Python 3.10+. And depends on ArviZ, matplotlib, NumPy, and SciPy. See `pyproject.toml <https://github.com/arviz-devs/preliz/blob/main/pyproject.toml>`_ for version information.
55+
PreliZ is tested on Python 3.11+. And depends on ArviZ, matplotlib, NumPy, and SciPy. See `pyproject.toml <https://github.com/arviz-devs/preliz/blob/main/pyproject.toml>`_ for version information.
5656

5757

5858

environment-dev.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ channels:
33
- defaults
44
- conda-forge
55
dependencies:
6-
- python >= 3.10.0
6+
- python >= 3.11
77
- pip
8-
- matplotlib>=3.5
8+
- matplotlib>=3.7
99
- numba>=0.59
10-
- numpy>=1.22
11-
- scipy>=1.9.1,<1.13
10+
- numpy>=1.24
11+
- scipy>=1.10.,<1.13
1212
- nbclient<0.6,>=0.2
1313
- ipywidgets
1414
- ipympl

environment-docs.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ channels:
33
- defaults
44
- conda-forge
55
dependencies:
6-
- python >= 3.10
7-
- matplotlib>=3.5
6+
- python >= 3.11
7+
- matplotlib>=3.7
88
- numba>=0.59
9-
- numpy>=1.22
10-
- scipy>=1.9.1,<1.13
9+
- numpy>=1.24
10+
- scipy>=1.10,<1.13
1111
- nbclient<0.6,>=0.2
1212
- ipywidgets
1313
- ipympl

environment.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ channels:
33
- defaults
44
- conda-forge
55
dependencies:
6-
- python >= 3.10
7-
- matplotlib>=3.5
6+
- python >= 3.11
7+
- matplotlib>=3.7
88
- numba>=0.59
9-
- numpy>=1.22
10-
- scipy>=1.9.1, <1.13
9+
- numpy>=1.24
10+
- scipy>=1.10, <1.13

preliz/distributions/asymmetric_laplace.py

-15
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,21 @@ def _update(self, kappa, mu, b):
109109
self.is_frozen = True
110110

111111
def pdf(self, x):
112-
"""
113-
Compute the probability density function (PDF) at a given point x.
114-
"""
115112
x = np.asarray(x)
116113
return np.exp(nb_logpdf(x, self.mu, self.b, self.kappa))
117114

118115
def cdf(self, x):
119-
"""
120-
Compute the cumulative distribution function (CDF) at a given point x.
121-
"""
122116
x = np.asarray(x)
123117
return nb_cdf(x, self.mu, self.b, self.kappa)
124118

125119
def ppf(self, q):
126-
"""
127-
Compute the percent point function (PPF) at a given probability q.
128-
"""
129120
q = np.asarray(q)
130121
return nb_ppf(q, self.mu, self.b, self.kappa)
131122

132123
def logpdf(self, x):
133-
"""
134-
Compute the log probability density function (log PDF) at a given point x.
135-
"""
136124
return nb_logpdf(x, self.mu, self.b, self.kappa)
137125

138126
def _neg_logpdf(self, x):
139-
"""
140-
Compute the neg log_pdf sum for the array x.
141-
"""
142127
return nb_neg_logpdf(x, self.mu, self.b, self.kappa)
143128

144129
def entropy(self):

preliz/distributions/bernoulli.py

-15
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,22 @@ def _fit_mle(self, sample):
9595
optimize_ml(self, sample)
9696

9797
def pdf(self, x):
98-
"""
99-
Compute the probability density function (PDF) at a given point x.
100-
"""
10198
x = np.asarray(x)
10299
return nb_pdf(x, self.p)
103100

104101
def cdf(self, x):
105-
"""
106-
Compute the cumulative distribution function (CDF) at a given point x.
107-
"""
108102
x = np.asarray(x)
109103
return nb_cdf(x, self.p)
110104

111105
def ppf(self, q):
112-
"""
113-
Compute the percent point function (PPF) at a given probability q.
114-
"""
115106
q = np.asarray(q)
116107
return nb_ppf(q, self.p)
117108

118109
def logpdf(self, x):
119-
"""
120-
Compute the log probability density function (log PDF) at a given point x.
121-
"""
122110
x = np.asarray(x)
123111
return nb_logpdf(x, self.p)
124112

125113
def _neg_logpdf(self, x):
126-
"""
127-
Compute the neg log_pdf sum for the array x.
128-
"""
129114
return nb_neg_logpdf(x, self.p)
130115

131116
def entropy(self):

preliz/distributions/beta.py

-15
Original file line numberDiff line numberDiff line change
@@ -144,36 +144,21 @@ def _update(self, alpha, beta):
144144
self.is_frozen = True
145145

146146
def pdf(self, x):
147-
"""
148-
Compute the probability density function (PDF) at a given point x.
149-
"""
150147
x = np.asarray(x)
151148
return np.exp(nb_logpdf(x, self.alpha, self.beta))
152149

153150
def cdf(self, x):
154-
"""
155-
Compute the cumulative distribution function (CDF) at a given point x.
156-
"""
157151
x = np.asarray(x)
158152
return nb_cdf(x, self.alpha, self.beta, self.support[0], self.support[1])
159153

160154
def ppf(self, q):
161-
"""
162-
Compute the percent point function (PPF) at a given probability q.
163-
"""
164155
q = np.asarray(q)
165156
return nb_ppf(q, self.alpha, self.beta, self.support[0], self.support[1])
166157

167158
def logpdf(self, x):
168-
"""
169-
Compute the log probability density function (log PDF) at a given point x.
170-
"""
171159
return nb_logpdf(x, self.alpha, self.beta)
172160

173161
def _neg_logpdf(self, x):
174-
"""
175-
Compute the neg log_pdf sum for the array x.
176-
"""
177162
return nb_neg_logpdf(x, self.alpha, self.beta)
178163

179164
def entropy(self):

preliz/distributions/betabinomial.py

-15
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,10 @@ def _update(self, alpha, beta, n):
7979
self.is_frozen = True
8080

8181
def pdf(self, x):
82-
"""
83-
Compute the probability density function (PDF) at a given point x.
84-
"""
8582
x = np.asarray(x)
8683
return np.exp(self.logpdf(x))
8784

8885
def cdf(self, x):
89-
"""
90-
Compute the cumulative distribution function (CDF) at a given point x.
91-
"""
9286
if isinstance(x, (np.ndarray, list, tuple)):
9387
cdf_values = np.zeros_like(x, dtype=float)
9488
for i, val in enumerate(x):
@@ -100,22 +94,13 @@ def cdf(self, x):
10094
return cdf_bounds(np.sum(self.pdf(x_vals)), x, *self.support)
10195

10296
def ppf(self, q):
103-
"""
104-
Compute the percent point function (PPF) at a given probability q.
105-
"""
10697
q = np.asarray(q)
10798
return find_ppf(self, q)
10899

109100
def logpdf(self, x):
110-
"""
111-
Compute the log probability density function (log PDF) at a given point x.
112-
"""
113101
return nb_logpdf(x, self.alpha, self.beta, self.n, *self.support)
114102

115103
def _neg_logpdf(self, x):
116-
"""
117-
Compute the neg log_pdf sum for the array x.
118-
"""
119104
return nb_neg_logpdf(x, self.alpha, self.beta, self.n, *self.support)
120105

121106
def entropy(self):

preliz/distributions/betascaled.py

-15
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,21 @@ def _to_mu_sigma(self, alpha, beta):
105105
return mu, sigma
106106

107107
def pdf(self, x):
108-
"""
109-
Compute the probability density function (PDF) at a given point x.
110-
"""
111108
x = np.asarray(x)
112109
return np.exp(self.logpdf(x))
113110

114111
def cdf(self, x):
115-
"""
116-
Compute the cumulative distribution function (CDF) at a given point x.
117-
"""
118112
x = np.asarray(x)
119113
return nb_cdf(x, self.alpha, self.beta, self.lower, self.upper)
120114

121115
def ppf(self, q):
122-
"""
123-
Compute the percent point function (PPF) at a given probability q.
124-
"""
125116
q = np.asarray(q)
126117
return nb_ppf(q, self.alpha, self.beta, self.support[0], self.support[1])
127118

128119
def logpdf(self, x):
129-
"""
130-
Compute the log probability density function (log PDF) at a given point x.
131-
"""
132120
return nb_logpdf(x, self.alpha, self.beta, self.lower, self.upper)
133121

134122
def _neg_logpdf(self, x):
135-
"""
136-
Compute the neg log_pdf sum for the array x.
137-
"""
138123
return nb_neg_logpdf(x, self.alpha, self.beta, self.lower, self.upper)
139124

140125
def entropy(self):

preliz/distributions/binomial.py

-15
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,19 @@ def _fit_mle(self, sample):
8080
self._update(*nb_fit_mle(sample))
8181

8282
def pdf(self, x):
83-
"""
84-
Compute the probability density function (PDF) at a given point x.
85-
"""
8683
x = np.asarray(x)
8784
return np.exp(self.logpdf(x))
8885

8986
def cdf(self, x):
90-
"""
91-
Compute the cumulative distribution function (CDF) at a given point x.
92-
"""
9387
return nb_cdf(x, self.n, self.p, self.support[0], self.support[1])
9488

9589
def ppf(self, q):
96-
"""
97-
Compute the percent point function (PPF) at a given probability q.
98-
"""
9990
return nb_ppf(q, self.n, self.p, self.support[0], self.support[1])
10091

10192
def logpdf(self, x):
102-
"""
103-
Compute the log probability density function (log PDF) at a given point x.
104-
"""
10593
return nb_logpdf(x, self.n, self.p)
10694

10795
def _neg_logpdf(self, x):
108-
"""
109-
Compute the neg log_pdf sum for the array x.
110-
"""
11196
return nb_neg_logpdf(x, self.n, self.p)
11297

11398
def entropy(self):

preliz/distributions/categorical.py

-15
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,22 @@ def _update(self, p):
8585
self.is_frozen = True
8686

8787
def pdf(self, x):
88-
"""
89-
Compute the probability density function (PDF) at a given point x.
90-
"""
9188
x = np.atleast_1d(x)
9289
return nb_pdf(x, self.p)
9390

9491
def cdf(self, x):
95-
"""
96-
Compute the cumulative distribution function (CDF) at a given point x.
97-
"""
9892
x = np.atleast_1d(x)
9993
return nb_cdf(x, self.p)
10094

10195
def ppf(self, q):
102-
"""
103-
Compute the percent point function (PPF) at a given probability q.
104-
"""
10596
q = np.atleast_1d(q)
10697
return nb_ppf(q, self.p)
10798

10899
def logpdf(self, x):
109-
"""
110-
Compute the log probability density function (log PDF) at a given point x.
111-
"""
112100
x = np.atleast_1d(x)
113101
return nb_logpdf(x, self.p)
114102

115103
def _neg_logpdf(self, x):
116-
"""
117-
Compute the neg log_pdf sum for the array x.
118-
"""
119104
return nb_neg_logpdf(x, self.p)
120105

121106
def entropy(self):

preliz/distributions/cauchy.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,21 @@ def _update(self, alpha, beta):
6666
self.is_frozen = True
6767

6868
def pdf(self, x):
69-
"""
70-
Compute the probability density function (PDF) at a given point x.
71-
"""
7269
x = np.asarray(x)
7370
return np.exp(nb_logpdf(x, self.alpha, self.beta))
7471

7572
def cdf(self, x):
76-
"""
77-
Compute the cumulative distribution function (CDF) at a given point x.
78-
"""
7973
x = np.asarray(x)
8074
return nb_cdf(x, self.alpha, self.beta)
8175

8276
def ppf(self, q):
83-
"""
84-
Compute the percent point function (PPF) at a given probability q.
85-
"""
8677
q = np.asarray(q)
8778
return nb_ppf(q, self.alpha, self.beta, -np.inf, np.inf)
8879

8980
def logpdf(self, x):
90-
"""
91-
Compute the log probability density function (log PDF) at a given point x.
92-
"""
9381
return nb_logpdf(x, self.alpha, self.beta)
9482

9583
def _neg_logpdf(self, x):
96-
"""
97-
Compute the neg log_pdf sum for the array x.
98-
"""
9984
return nb_neg_logpdf(x, self.alpha, self.beta)
10085

10186
def entropy(self):
@@ -127,7 +112,7 @@ def rvs(self, size=None, random_state=None):
127112
def _fit_moments(self, mean, sigma):
128113
self._update(mean, sigma)
129114

130-
def _fit_mle(self, sample, **kwargs):
115+
def _fit_mle(self, sample):
131116
optimize_ml(self, sample)
132117

133118

0 commit comments

Comments
 (0)