Skip to content

Commit 613857d

Browse files
tvwengerricardoV94
authored andcommitted
Update PyTensor dependency
1 parent 7c0a095 commit 613857d

File tree

10 files changed

+52
-61
lines changed

10 files changed

+52
-61
lines changed

conda-envs/environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- numpy>=1.15.0
1515
- pandas>=0.24.0
1616
- pip
17-
- pytensor>=2.16.1,<2.17
17+
- pytensor>=2.17.0,<2.18
1818
- python-graphviz
1919
- networkx
2020
- scipy>=1.4.1

conda-envs/environment-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- numpy>=1.15.0
1313
- pandas>=0.24.0
1414
- pip
15-
- pytensor>=2.16.1,<2.17
15+
- pytensor>=2.17.0,<2.18
1616
- python-graphviz
1717
- scipy>=1.4.1
1818
- typing-extensions>=3.7.4

conda-envs/environment-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- numpy>=1.15.0
1818
- pandas>=0.24.0
1919
- pip
20-
- pytensor>=2.16.1,<2.17
20+
- pytensor>=2.17.0,<2.18
2121
- python-graphviz
2222
- networkx
2323
- scipy>=1.4.1

conda-envs/windows-environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- numpy>=1.15.0
1515
- pandas>=0.24.0
1616
- pip
17-
- pytensor>=2.16.1,<2.17
17+
- pytensor>=2.17.0,<2.18
1818
- python-graphviz
1919
- networkx
2020
- scipy>=1.4.1

conda-envs/windows-environment-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
- numpy>=1.15.0
1818
- pandas>=0.24.0
1919
- pip
20-
- pytensor>=2.16.1,<2.17
20+
- pytensor>=2.17.0,<2.18
2121
- python-graphviz
2222
- networkx
2323
- scipy>=1.4.1

pymc/distributions/continuous.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
from pytensor.tensor.math import tanh
3737
from pytensor.tensor.random.basic import (
3838
BetaRV,
39+
_gamma,
3940
cauchy,
4041
chisquare,
4142
exponential,
42-
gamma,
4343
gumbel,
4444
halfcauchy,
4545
halfnormal,
@@ -2201,16 +2201,17 @@ class Gamma(PositiveContinuous):
22012201
sigma : tensor_like of float, optional
22022202
Alternative scale parameter (sigma > 0).
22032203
"""
2204-
rv_op = gamma
2204+
# gamma is temporarily a deprecation wrapper in PyTensor
2205+
rv_op = _gamma
22052206

22062207
@classmethod
22072208
def dist(cls, alpha=None, beta=None, mu=None, sigma=None, **kwargs):
22082209
alpha, beta = cls.get_alpha_beta(alpha, beta, mu, sigma)
22092210
alpha = pt.as_tensor_variable(floatX(alpha))
22102211
beta = pt.as_tensor_variable(floatX(beta))
2211-
2212-
# The PyTensor `GammaRV` `Op` will invert the `beta` parameter itself
2213-
return super().dist([alpha, beta], **kwargs)
2212+
# PyTensor gamma op is parametrized in terms of scale (1/beta)
2213+
scale = pt.reciprocal(beta)
2214+
return super().dist([alpha, scale], **kwargs)
22142215

22152216
@classmethod
22162217
def get_alpha_beta(cls, alpha=None, beta=None, mu=None, sigma=None):
@@ -2232,15 +2233,14 @@ def get_alpha_beta(cls, alpha=None, beta=None, mu=None, sigma=None):
22322233

22332234
return alpha, beta
22342235

2235-
def moment(rv, size, alpha, inv_beta):
2236-
# The PyTensor `GammaRV` `Op` inverts the `beta` parameter itself
2237-
mean = alpha * inv_beta
2236+
def moment(rv, size, alpha, scale):
2237+
mean = alpha * scale
22382238
if not rv_size_is_none(size):
22392239
mean = pt.full(size, mean)
22402240
return mean
22412241

2242-
def logp(value, alpha, inv_beta):
2243-
beta = pt.reciprocal(inv_beta)
2242+
def logp(value, alpha, scale):
2243+
beta = pt.reciprocal(scale)
22442244
res = -pt.gammaln(alpha) + logpow(beta, alpha) - beta * value + logpow(value, alpha - 1)
22452245
res = pt.switch(pt.ge(value, 0.0), res, -np.inf)
22462246
return check_parameters(
@@ -2250,14 +2250,13 @@ def logp(value, alpha, inv_beta):
22502250
msg="alpha > 0, beta > 0",
22512251
)
22522252

2253-
def logcdf(value, alpha, inv_beta):
2254-
beta = pt.reciprocal(inv_beta)
2253+
def logcdf(value, alpha, scale):
2254+
beta = pt.reciprocal(scale)
22552255
res = pt.switch(
22562256
pt.lt(value, 0),
22572257
-np.inf,
22582258
pt.log(pt.gammainc(alpha, beta * value)),
22592259
)
2260-
22612260
return check_parameters(res, 0 < alpha, 0 < beta, msg="alpha > 0, beta > 0")
22622261

22632262

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ numpydoc
1818
pandas>=0.24.0
1919
polyagamma
2020
pre-commit>=2.8.0
21-
pytensor>=2.16.1,<2.17
21+
pytensor>=2.17.0,<2.18
2222
pytest-cov>=2.5
2323
pytest>=3.0
2424
scipy>=1.4.1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ cloudpickle
44
fastprogress>=0.2.0
55
numpy>=1.15.0
66
pandas>=0.24.0
7-
pytensor>=2.16.1,<2.17
7+
pytensor>=2.17.0,<2.18
88
scipy>=1.4.1
99
typing-extensions>=3.7.4

tests/distributions/test_continuous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ class TestHalfCauchy(BaseTestDistributionRandom):
21992199
class TestGamma(BaseTestDistributionRandom):
22002200
pymc_dist = pm.Gamma
22012201
pymc_dist_params = {"alpha": 2.0, "beta": 5.0}
2202-
expected_rv_op_params = {"alpha": 2.0, "beta": 1 / 5.0}
2202+
expected_rv_op_params = {"shape": 2.0, "scale": 1 / 5.0}
22032203
reference_dist_params = {"shape": 2.0, "scale": 1 / 5.0}
22042204
reference_dist = seeded_numpy_distribution_builder("gamma")
22052205
checks_to_run = [

tests/logprob/test_mixture.py

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@
6262

6363

6464
def test_mixture_basics():
65-
srng = pt.random.RandomStream(29833)
66-
6765
def create_mix_model(size, axis):
68-
X_rv = srng.normal(0, 1, size=size, name="X")
69-
Y_rv = srng.gamma(0.5, 0.5, size=size, name="Y")
66+
X_rv = pt.random.normal(0, 1, size=size, name="X")
67+
Y_rv = pt.random.gamma(0.5, scale=2.0, size=size, name="Y")
7068

7169
p_at = pt.scalar("p")
7270
p_at.tag.test_value = 0.5
7371

74-
I_rv = srng.bernoulli(p_at, size=size, name="I")
72+
I_rv = pt.random.bernoulli(p_at, size=size, name="I")
7573
i_vv = I_rv.clone()
7674
i_vv.name = "i"
7775

@@ -119,15 +117,13 @@ def create_mix_model(size, axis):
119117
],
120118
)
121119
def test_compute_test_value(op_constructor):
122-
srng = pt.random.RandomStream(29833)
123-
124-
X_rv = srng.normal(0, 1, name="X")
125-
Y_rv = srng.gamma(0.5, 0.5, name="Y")
120+
X_rv = pt.random.normal(0, 1, name="X")
121+
Y_rv = pt.random.gamma(0.5, scale=2.0, name="Y")
126122

127123
p_at = pt.scalar("p")
128124
p_at.tag.test_value = 0.3
129125

130-
I_rv = srng.bernoulli(p_at, name="I")
126+
I_rv = pt.random.bernoulli(p_at, name="I")
131127

132128
i_vv = I_rv.clone()
133129
i_vv.name = "i"
@@ -160,20 +156,18 @@ def test_compute_test_value(op_constructor):
160156
],
161157
)
162158
def test_hetero_mixture_binomial(p_val, size, supported):
163-
srng = pt.random.RandomStream(29833)
164-
165-
X_rv = srng.normal(0, 1, size=size, name="X")
166-
Y_rv = srng.gamma(0.5, 0.5, size=size, name="Y")
159+
X_rv = pt.random.normal(0, 1, size=size, name="X")
160+
Y_rv = pt.random.gamma(0.5, scale=2.0, size=size, name="Y")
167161

168162
if np.ndim(p_val) == 0:
169163
p_at = pt.scalar("p")
170164
p_at.tag.test_value = p_val
171-
I_rv = srng.bernoulli(p_at, size=size, name="I")
165+
I_rv = pt.random.bernoulli(p_at, size=size, name="I")
172166
p_val_1 = p_val
173167
else:
174168
p_at = pt.vector("p")
175169
p_at.tag.test_value = np.array(p_val, dtype=pytensor.config.floatX)
176-
I_rv = srng.categorical(p_at, size=size, name="I")
170+
I_rv = pt.random.categorical(p_at, size=size, name="I")
177171
p_val_1 = p_val[1]
178172

179173
i_vv = I_rv.clone()
@@ -203,7 +197,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
203197

204198
bern_sp = sp.bernoulli(p_val_1)
205199
norm_sp = sp.norm(loc=0, scale=1)
206-
gamma_sp = sp.gamma(0.5, scale=1.0 / 0.5)
200+
gamma_sp = sp.gamma(0.5, scale=2.0)
207201

208202
for i in range(10):
209203
i_val = bern_sp.rvs(size=size, random_state=test_val_rng)
@@ -230,7 +224,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
230224
),
231225
(
232226
np.array(0.5, dtype=pytensor.config.floatX),
233-
np.array(0.5, dtype=pytensor.config.floatX),
227+
np.array(2.0, dtype=pytensor.config.floatX),
234228
),
235229
(
236230
np.array(100, dtype=pytensor.config.floatX),
@@ -251,7 +245,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
251245
),
252246
(
253247
np.array([0.5], dtype=pytensor.config.floatX),
254-
np.array(0.5, dtype=pytensor.config.floatX),
248+
np.array(2.0, dtype=pytensor.config.floatX),
255249
),
256250
(
257251
np.array([100], dtype=pytensor.config.floatX),
@@ -272,7 +266,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
272266
),
273267
(
274268
np.array([0.5], dtype=pytensor.config.floatX),
275-
np.array(0.5, dtype=pytensor.config.floatX),
269+
np.array(2.0, dtype=pytensor.config.floatX),
276270
),
277271
(
278272
np.array([100], dtype=pytensor.config.floatX),
@@ -293,7 +287,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
293287
),
294288
(
295289
np.array(0.5, dtype=pytensor.config.floatX),
296-
np.array(0.5, dtype=pytensor.config.floatX),
290+
np.array(2.0, dtype=pytensor.config.floatX),
297291
),
298292
(
299293
np.array(100, dtype=pytensor.config.floatX),
@@ -314,7 +308,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
314308
),
315309
(
316310
np.array(0.5, dtype=pytensor.config.floatX),
317-
np.array(0.5, dtype=pytensor.config.floatX),
311+
np.array(2.0, dtype=pytensor.config.floatX),
318312
),
319313
(
320314
np.array(100, dtype=pytensor.config.floatX),
@@ -335,7 +329,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
335329
),
336330
(
337331
np.array(0.5, dtype=pytensor.config.floatX),
338-
np.array(0.5, dtype=pytensor.config.floatX),
332+
np.array(2.0, dtype=pytensor.config.floatX),
339333
),
340334
(
341335
np.array(100, dtype=pytensor.config.floatX),
@@ -361,7 +355,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
361355
),
362356
(
363357
np.array(0.5, dtype=pytensor.config.floatX),
364-
np.array(0.5, dtype=pytensor.config.floatX),
358+
np.array(2.0, dtype=pytensor.config.floatX),
365359
),
366360
(
367361
np.array(100, dtype=pytensor.config.floatX),
@@ -384,7 +378,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
384378
),
385379
(
386380
np.array(0.5, dtype=pytensor.config.floatX),
387-
np.array(0.5, dtype=pytensor.config.floatX),
381+
np.array(2.0, dtype=pytensor.config.floatX),
388382
),
389383
(
390384
np.array(100, dtype=pytensor.config.floatX),
@@ -405,7 +399,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
405399
),
406400
(
407401
np.array(0.5, dtype=pytensor.config.floatX),
408-
np.array(0.5, dtype=pytensor.config.floatX),
402+
np.array(2.0, dtype=pytensor.config.floatX),
409403
),
410404
(
411405
np.array(100, dtype=pytensor.config.floatX),
@@ -426,7 +420,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
426420
),
427421
(
428422
np.array(0.5, dtype=pytensor.config.floatX),
429-
np.array(0.5, dtype=pytensor.config.floatX),
423+
np.array(2.0, dtype=pytensor.config.floatX),
430424
),
431425
(
432426
np.array(100, dtype=pytensor.config.floatX),
@@ -447,7 +441,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
447441
),
448442
(
449443
np.array([0.5], dtype=pytensor.config.floatX),
450-
np.array(0.5, dtype=pytensor.config.floatX),
444+
np.array(2.0, dtype=pytensor.config.floatX),
451445
),
452446
(
453447
np.array([100], dtype=pytensor.config.floatX),
@@ -468,7 +462,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
468462
),
469463
(
470464
np.array([0.5, 1], dtype=pytensor.config.floatX),
471-
np.array([0.5, 1], dtype=pytensor.config.floatX),
465+
np.array([2.0, 1], dtype=pytensor.config.floatX),
472466
),
473467
(
474468
np.array([100, 1000], dtype=pytensor.config.floatX),
@@ -489,7 +483,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
489483
),
490484
(
491485
np.array([0.5, 1], dtype=pytensor.config.floatX),
492-
np.array([0.5, 1], dtype=pytensor.config.floatX),
486+
np.array([2.0, 1], dtype=pytensor.config.floatX),
493487
),
494488
(
495489
np.array([100, 1000], dtype=pytensor.config.floatX),
@@ -510,7 +504,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
510504
),
511505
(
512506
np.array(0.5, dtype=pytensor.config.floatX),
513-
np.array(0.5, dtype=pytensor.config.floatX),
507+
np.array(2.0, dtype=pytensor.config.floatX),
514508
),
515509
(
516510
np.array(100, dtype=pytensor.config.floatX),
@@ -531,7 +525,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
531525
),
532526
(
533527
np.array(0.5, dtype=pytensor.config.floatX),
534-
np.array(0.5, dtype=pytensor.config.floatX),
528+
np.array(2.0, dtype=pytensor.config.floatX),
535529
),
536530
(
537531
np.array(100, dtype=pytensor.config.floatX),
@@ -552,7 +546,7 @@ def test_hetero_mixture_binomial(p_val, size, supported):
552546
),
553547
(
554548
np.array(0.5, dtype=pytensor.config.floatX),
555-
np.array(0.5, dtype=pytensor.config.floatX),
549+
np.array(2.0, dtype=pytensor.config.floatX),
556550
),
557551
(
558552
np.array(100, dtype=pytensor.config.floatX),
@@ -570,16 +564,14 @@ def test_hetero_mixture_binomial(p_val, size, supported):
570564
def test_hetero_mixture_categorical(
571565
X_args, Y_args, Z_args, p_val, comp_size, idx_size, extra_indices, join_axis, supported
572566
):
573-
srng = pt.random.RandomStream(29833)
574-
575-
X_rv = srng.normal(*X_args, size=comp_size, name="X")
576-
Y_rv = srng.gamma(*Y_args, size=comp_size, name="Y")
577-
Z_rv = srng.normal(*Z_args, size=comp_size, name="Z")
567+
X_rv = pt.random.normal(*X_args, size=comp_size, name="X")
568+
Y_rv = pt.random.gamma(Y_args[0], scale=Y_args[1], size=comp_size, name="Y")
569+
Z_rv = pt.random.normal(*Z_args, size=comp_size, name="Z")
578570

579571
p_at = pt.as_tensor(p_val).type()
580572
p_at.name = "p"
581573
p_at.tag.test_value = np.array(p_val, dtype=pytensor.config.floatX)
582-
I_rv = srng.categorical(p_at, size=idx_size, name="I")
574+
I_rv = pt.random.categorical(p_at, size=idx_size, name="I")
583575

584576
i_vv = I_rv.clone()
585577
i_vv.name = "i"
@@ -612,7 +604,7 @@ def test_hetero_mixture_categorical(
612604
test_val_rng = np.random.RandomState(3238)
613605

614606
norm_1_sp = sp.norm(loc=X_args[0], scale=X_args[1])
615-
gamma_sp = sp.gamma(Y_args[0], scale=1 / Y_args[1])
607+
gamma_sp = sp.gamma(Y_args[0], scale=Y_args[1])
616608
norm_2_sp = sp.norm(loc=Z_args[0], scale=Z_args[1])
617609

618610
# Handle scipy annoying squeeze of random draws

0 commit comments

Comments
 (0)