Skip to content

Commit 4605595

Browse files
larryshamalamaricardoV94
authored andcommitted
Revert "Refactoring _print_name for certain RVs and specifying rv_type in their distributions"
This reverts commit 652c9de
1 parent 2dc49e5 commit 4605595

File tree

7 files changed

+60
-162
lines changed

7 files changed

+60
-162
lines changed

pymc/distributions/continuous.py

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,21 @@
3535
from aesara.tensor.math import tanh
3636
from aesara.tensor.random.basic import (
3737
BetaRV,
38-
CauchyRV,
39-
HalfCauchyRV,
40-
HalfNormalRV,
41-
LogNormalRV,
42-
NormalRV,
43-
UniformRV,
38+
cauchy,
4439
chisquare,
4540
exponential,
4641
gamma,
4742
gumbel,
43+
halfcauchy,
44+
halfnormal,
4845
invgamma,
4946
laplace,
5047
logistic,
48+
lognormal,
5149
normal,
5250
pareto,
5351
triangular,
52+
uniform,
5453
vonmises,
5554
)
5655
from aesara.tensor.random.op import RandomVariable
@@ -253,13 +252,6 @@ def get_tau_sigma(tau=None, sigma=None):
253252
return floatX(tau), floatX(sigma)
254253

255254

256-
class PyMCUniformRV(UniformRV):
257-
_print_name = ("Uniform", "\\operatorname{Uniform}")
258-
259-
260-
pymc_uniform = PyMCUniformRV()
261-
262-
263255
class Uniform(BoundedContinuous):
264256
r"""
265257
Continuous uniform log-likelihood.
@@ -303,8 +295,7 @@ class Uniform(BoundedContinuous):
303295
upper : tensor_like of float, default 1
304296
Upper limit.
305297
"""
306-
rv_op = pymc_uniform
307-
rv_type = UniformRV
298+
rv_op = uniform
308299
bound_args_indices = (3, 4) # Lower, Upper
309300

310301
@classmethod
@@ -488,13 +479,6 @@ def logcdf(value):
488479
return at.switch(at.lt(value, np.inf), -np.inf, at.switch(at.eq(value, np.inf), 0, -np.inf))
489480

490481

491-
class PyMCNormalRV(NormalRV):
492-
_print_name = ("Normal", "\\operatorname{Normal}")
493-
494-
495-
pymc_normal = PyMCNormalRV()
496-
497-
498482
class Normal(Continuous):
499483
r"""
500484
Univariate normal log-likelihood.
@@ -560,8 +544,7 @@ class Normal(Continuous):
560544
with pm.Model():
561545
x = pm.Normal('x', mu=0, tau=1/23)
562546
"""
563-
rv_op = pymc_normal
564-
rv_type = NormalRV
547+
rv_op = normal
565548

566549
@classmethod
567550
def dist(cls, mu=0, sigma=None, tau=None, **kwargs):
@@ -818,13 +801,6 @@ def truncated_normal_default_transform(op, rv):
818801
return bounded_cont_transform(op, rv, TruncatedNormal.bound_args_indices)
819802

820803

821-
class PyMCHalfNormalRV(HalfNormalRV):
822-
_print_name = ("HalfNormal", "\\operatorname{HalfNormal}")
823-
824-
825-
pymc_halfnormal = PyMCHalfNormalRV()
826-
827-
828804
class HalfNormal(PositiveContinuous):
829805
r"""
830806
Half-normal log-likelihood.
@@ -891,8 +867,7 @@ class HalfNormal(PositiveContinuous):
891867
with pm.Model():
892868
x = pm.HalfNormal('x', tau=1/15)
893869
"""
894-
rv_op = pymc_halfnormal
895-
rv_type = HalfNormalRV
870+
rv_op = halfnormal
896871

897872
@classmethod
898873
def dist(cls, sigma=None, tau=None, *args, **kwargs):
@@ -1715,13 +1690,6 @@ def logp(value, b, kappa, mu):
17151690
return check_parameters(res, 0 < b, 0 < kappa, msg="b > 0, kappa > 0")
17161691

17171692

1718-
class PyMCLogNormalRV(LogNormalRV):
1719-
_print_name = ("LogNormal", "\\operatorname{LogNormal}")
1720-
1721-
1722-
pymc_lognormal = PyMCLogNormalRV()
1723-
1724-
17251693
class LogNormal(PositiveContinuous):
17261694
r"""
17271695
Log-normal log-likelihood.
@@ -1790,8 +1758,7 @@ class LogNormal(PositiveContinuous):
17901758
x = pm.LogNormal('x', mu=2, tau=1/100)
17911759
"""
17921760

1793-
rv_op = pymc_lognormal
1794-
rv_type = LogNormalRV
1761+
rv_op = lognormal
17951762

17961763
@classmethod
17971764
def dist(cls, mu=0, sigma=None, tau=None, *args, **kwargs):
@@ -2082,13 +2049,6 @@ def pareto_default_transform(op, rv):
20822049
return bounded_cont_transform(op, rv, Pareto.bound_args_indices)
20832050

20842051

2085-
class PyMCCauchyRV(CauchyRV):
2086-
_print_name = ("Cauchy", "\\operatorname{Cauchy}")
2087-
2088-
2089-
pymc_cauchy = PyMCCauchyRV()
2090-
2091-
20922052
class Cauchy(Continuous):
20932053
r"""
20942054
Cauchy log-likelihood.
@@ -2135,8 +2095,7 @@ class Cauchy(Continuous):
21352095
beta : tensor_like of float
21362096
Scale parameter > 0.
21372097
"""
2138-
rv_op = pymc_cauchy
2139-
rv_type = CauchyRV
2098+
rv_op = cauchy
21402099

21412100
@classmethod
21422101
def dist(cls, alpha, beta, *args, **kwargs):
@@ -2174,13 +2133,6 @@ def logcdf(value, alpha, beta):
21742133
)
21752134

21762135

2177-
class PyMCHalfCauchyRV(HalfCauchyRV):
2178-
_print_name = ("HalfCauchy", "\\operatorname{HalfCauchy}")
2179-
2180-
2181-
pymc_halfcauchy = PyMCHalfCauchyRV()
2182-
2183-
21842136
class HalfCauchy(PositiveContinuous):
21852137
r"""
21862138
Half-Cauchy log-likelihood.
@@ -2220,8 +2172,7 @@ class HalfCauchy(PositiveContinuous):
22202172
beta : tensor_like of float
22212173
Scale parameter (beta > 0).
22222174
"""
2223-
rv_op = pymc_halfcauchy
2224-
rv_type = HalfCauchyRV
2175+
rv_op = halfcauchy
22252176

22262177
@classmethod
22272178
def dist(cls, beta, *args, **kwargs):
@@ -3991,7 +3942,7 @@ class PolyaGammaRV(RandomVariable):
39913942
ndim_supp = 0
39923943
ndims_params = [0, 0]
39933944
dtype = "floatX"
3994-
_print_name = ("PolyaGamma", "\\operatorname{PolyaGamma}")
3945+
_print_name = ("PG", "\\operatorname{PG}")
39953946

39963947
def __call__(self, h=1.0, z=0.0, size=None, **kwargs):
39973948
return super().__call__(h, z, size=size, **kwargs)

pymc/distributions/discrete.py

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
import numpy as np
1818

1919
from aesara.tensor.random.basic import (
20-
GeometricRV,
21-
HyperGeometricRV,
22-
NegBinomialRV,
23-
PoissonRV,
2420
RandomVariable,
2521
ScipyRandomVariable,
2622
bernoulli,
2723
betabinom,
2824
binomial,
2925
categorical,
26+
geometric,
27+
hypergeometric,
28+
nbinom,
29+
poisson,
3030
)
3131
from scipy import stats
3232

@@ -560,13 +560,6 @@ def logcdf(value, q, beta):
560560
return check_parameters(res, 0 < q, q < 1, 0 < beta, msg="0 < q < 1, beta > 0")
561561

562562

563-
class PyMCPoissonRV(PoissonRV):
564-
_print_name = ("Poisson", "\\operatorname{Poisson}")
565-
566-
567-
pymc_poisson = PyMCPoissonRV()
568-
569-
570563
class Poisson(Discrete):
571564
R"""
572565
Poisson log-likelihood.
@@ -612,8 +605,7 @@ class Poisson(Discrete):
612605
The Poisson distribution can be derived as a limiting case of the
613606
binomial distribution.
614607
"""
615-
rv_op = pymc_poisson
616-
rv_type = PoissonRV
608+
rv_op = poisson
617609

618610
@classmethod
619611
def dist(cls, mu, *args, **kwargs):
@@ -682,13 +674,6 @@ def logcdf(value, mu):
682674
return check_parameters(res, 0 <= mu, msg="mu >= 0")
683675

684676

685-
class PyMCNegativeBinomialRV(NegBinomialRV):
686-
_print_name = ("NegBinom", "\\operatorname{NegBinom}")
687-
688-
689-
pymc_nbinom = PyMCNegativeBinomialRV()
690-
691-
692677
class NegativeBinomial(Discrete):
693678
R"""
694679
Negative binomial log-likelihood.
@@ -761,8 +746,7 @@ def NegBinom(a, m, x):
761746
n : tensor_like of float
762747
Alternative number of target success trials (n > 0)
763748
"""
764-
rv_op = pymc_nbinom
765-
rv_type = NegBinomialRV
749+
rv_op = nbinom
766750

767751
@classmethod
768752
def dist(cls, mu=None, alpha=None, p=None, n=None, *args, **kwargs):
@@ -863,13 +847,6 @@ def logcdf(value, n, p):
863847
)
864848

865849

866-
class PyMCGeometricRV(GeometricRV):
867-
_print_name = ("Geometric", "\\operatorname{Geometric}")
868-
869-
870-
pymc_geometric = PyMCGeometricRV()
871-
872-
873850
class Geometric(Discrete):
874851
R"""
875852
Geometric log-likelihood.
@@ -909,8 +886,7 @@ class Geometric(Discrete):
909886
Probability of success on an individual trial (0 < p <= 1).
910887
"""
911888

912-
rv_op = pymc_geometric
913-
rv_type = GeometricRV
889+
rv_op = geometric
914890

915891
@classmethod
916892
def dist(cls, p, *args, **kwargs):
@@ -980,13 +956,6 @@ def logcdf(value, p):
980956
)
981957

982958

983-
class PyMCHyperGeometricRV(HyperGeometricRV):
984-
_print_name = ("HyperGeometric", "\\operatorname{HyperGeometric}")
985-
986-
987-
pymc_hypergeometric = PyMCHyperGeometricRV()
988-
989-
990959
class HyperGeometric(Discrete):
991960
R"""
992961
Discrete hypergeometric distribution.
@@ -1035,8 +1004,7 @@ class HyperGeometric(Discrete):
10351004
Number of samples drawn from the population (0 <= n <= N)
10361005
"""
10371006

1038-
rv_op = pymc_hypergeometric
1039-
rv_type = HyperGeometricRV
1007+
rv_op = hypergeometric
10401008

10411009
@classmethod
10421010
def dist(cls, N, k, n, *args, **kwargs):

pymc/distributions/distribution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def _random(*args, **kwargs):
102102
clsdict["random"] = _random
103103

104104
rv_op = clsdict.setdefault("rv_op", None)
105-
rv_type = clsdict.setdefault("rv_type", None)
105+
rv_type = None
106106

107-
if rv_type is None and isinstance(rv_op, RandomVariable):
107+
if isinstance(rv_op, RandomVariable):
108108
rv_type = type(rv_op)
109109
clsdict["rv_type"] = rv_type
110110

pymc/distributions/multivariate.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232
from aesara.sparse.basic import sp_sum
3333
from aesara.tensor import gammaln, sigmoid
3434
from aesara.tensor.nlinalg import det, eigh, matrix_inverse, trace
35-
from aesara.tensor.random.basic import (
36-
DirichletRV,
37-
MvNormalRV,
38-
multinomial,
39-
multivariate_normal,
40-
)
35+
from aesara.tensor.random.basic import dirichlet, multinomial, multivariate_normal
4136
from aesara.tensor.random.op import RandomVariable, default_supp_shape_from_params
4237
from aesara.tensor.random.utils import broadcast_params
4338
from aesara.tensor.slinalg import Cholesky, SolveTriangular
@@ -195,13 +190,6 @@ def quaddist_tau(delta, chol_mat):
195190
return quaddist, logdet, ok
196191

197192

198-
class PyMCMvNormalRV(MvNormalRV):
199-
_print_name = ("MvNormal", "\\operatorname{MvNormal}")
200-
201-
202-
pymc_multivariate_normal = PyMCMvNormalRV()
203-
204-
205193
class MvNormal(Continuous):
206194
r"""
207195
Multivariate normal log-likelihood.
@@ -266,8 +254,7 @@ class MvNormal(Continuous):
266254
vals_raw = pm.Normal('vals_raw', mu=0, sigma=1, shape=(5, 3))
267255
vals = pm.Deterministic('vals', at.dot(chol, vals_raw.T).T)
268256
"""
269-
rv_op = pymc_multivariate_normal
270-
rv_type = MvNormalRV
257+
rv_op = multivariate_normal
271258

272259
@classmethod
273260
def dist(cls, mu, cov=None, tau=None, chol=None, lower=True, **kwargs):
@@ -449,13 +436,6 @@ def logp(value, nu, mu, scale):
449436
)
450437

451438

452-
class PyMCDirichletRV(DirichletRV):
453-
_print_name = ("Dirichlet", "\\operatorname{Dirichlet}")
454-
455-
456-
pymc_dirichlet = PyMCDirichletRV()
457-
458-
459439
class Dirichlet(SimplexContinuous):
460440
r"""
461441
Dirichlet log-likelihood.
@@ -480,8 +460,7 @@ class Dirichlet(SimplexContinuous):
480460
Concentration parameters (a > 0). The number of categories is given by the
481461
length of the last axis.
482462
"""
483-
rv_op = pymc_dirichlet
484-
rv_type = DirichletRV
463+
rv_op = dirichlet
485464

486465
@classmethod
487466
def dist(cls, a, **kwargs):

pymc/tests/distributions/test_logprob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_ignore_logprob_basic():
320320
new_x = ignore_logprob(x)
321321
assert new_x is not x
322322
assert isinstance(new_x.owner.op, Normal)
323-
assert type(new_x.owner.op).__name__ == "UnmeasurablePyMCNormalRV"
323+
assert type(new_x.owner.op).__name__ == "UnmeasurableNormalRV"
324324
# Confirm that it does not have measurable output
325325
assert get_measurable_outputs(new_x.owner.op, new_x.owner) is None
326326

pymc/tests/test_aesaraf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from aeppl.logprob import ParameterValueError
2626
from aesara.compile.builders import OpFromGraph
2727
from aesara.graph.basic import Variable, equal_computations
28-
from aesara.tensor.random.basic import NormalRV, normal, uniform
28+
from aesara.tensor.random.basic import normal, uniform
2929
from aesara.tensor.random.op import RandomVariable
3030
from aesara.tensor.random.var import RandomStateSharedVariable
3131
from aesara.tensor.subtensor import AdvancedIncSubtensor, AdvancedIncSubtensor1
@@ -405,7 +405,7 @@ def test_rvs_to_value_vars_unvalued_rv():
405405
res_y = res.owner.inputs[1]
406406
# Graph should have be cloned, and therefore y and res_y should have different ids
407407
assert res_y is not y
408-
assert isinstance(res_y.owner.op, NormalRV)
408+
assert res_y.owner.op == at.random.normal
409409
assert res_y.owner.inputs[3] is x_value
410410

411411

0 commit comments

Comments
 (0)