11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
+ import warnings
15
+
14
16
from functools import singledispatch
15
17
16
18
import numpy as np
39
41
"logodds" ,
40
42
"Interval" ,
41
43
"log_exp_m1" ,
42
- "univariate_ordered" ,
43
- "multivariate_ordered" ,
44
+ "ordered" ,
44
45
"log" ,
45
46
"sum_to_1" ,
46
- "univariate_sum_to_1" ,
47
- "multivariate_sum_to_1" ,
48
47
"circular" ,
49
48
"CholeskyCovPacked" ,
50
49
"Chain" ,
51
50
"ZeroSumTransform" ,
52
51
]
53
52
54
53
54
+ def __getattr__ (name ):
55
+ if name in ("univariate_ordered" , "multivariate_ordered" ):
56
+ warnings .warn (f"{ name } has been deprecated, use ordered instead." , FutureWarning )
57
+ return ordered
58
+
59
+ if name in ("univariate_sum_to_1, multivariate_sum_to_1" ):
60
+ warnings .warn (f"{ name } has been deprecated, use sum_to_1 instead." , FutureWarning )
61
+ return sum_to_1
62
+
63
+ raise AttributeError (f"module { __name__ } has no attribute { name } " )
64
+
65
+
55
66
@singledispatch
56
67
def _default_transform (op : Op , rv : TensorVariable ):
57
68
"""Return default transform for a given Distribution `Op`"""
@@ -79,13 +90,9 @@ def log_jac_det(self, value, *inputs):
79
90
class Ordered (RVTransform ):
80
91
name = "ordered"
81
92
82
- def __init__ (self , ndim_supp = 0 ):
83
- if ndim_supp > 1 :
84
- raise ValueError (
85
- f"For Ordered transformation number of core dimensions"
86
- f"(ndim_supp) must not exceed 1 but is { ndim_supp } "
87
- )
88
- self .ndim_supp = ndim_supp
93
+ def __init__ (self , ndim_supp = None ):
94
+ if ndim_supp is not None :
95
+ warnings .warn ("ndim_supp argument is deprecated and has no effect" , FutureWarning )
89
96
90
97
def backward (self , value , * inputs ):
91
98
x = pt .zeros (value .shape )
@@ -100,10 +107,7 @@ def forward(self, value, *inputs):
100
107
return y
101
108
102
109
def log_jac_det (self , value , * inputs ):
103
- if self .ndim_supp == 0 :
104
- return pt .sum (value [..., 1 :], axis = - 1 , keepdims = True )
105
- else :
106
- return pt .sum (value [..., 1 :], axis = - 1 )
110
+ return pt .sum (value [..., 1 :], axis = - 1 )
107
111
108
112
109
113
class SumTo1 (RVTransform ):
@@ -114,13 +118,9 @@ class SumTo1(RVTransform):
114
118
115
119
name = "sumto1"
116
120
117
- def __init__ (self , ndim_supp = 0 ):
118
- if ndim_supp > 1 :
119
- raise ValueError (
120
- f"For SumTo1 transformation number of core dimensions"
121
- f"(ndim_supp) must not exceed 1 but is { ndim_supp } "
122
- )
123
- self .ndim_supp = ndim_supp
121
+ def __init__ (self , ndim_supp = None ):
122
+ if ndim_supp is not None :
123
+ warnings .warn ("ndim_supp argument is deprecated and has no effect" , FutureWarning )
124
124
125
125
def backward (self , value , * inputs ):
126
126
remaining = 1 - pt .sum (value [..., :], axis = - 1 , keepdims = True )
@@ -131,10 +131,7 @@ def forward(self, value, *inputs):
131
131
132
132
def log_jac_det (self , value , * inputs ):
133
133
y = pt .zeros (value .shape )
134
- if self .ndim_supp == 0 :
135
- return pt .sum (y , axis = - 1 , keepdims = True )
136
- else :
137
- return pt .sum (y , axis = - 1 )
134
+ return pt .sum (y , axis = - 1 )
138
135
139
136
140
137
class CholeskyCovPacked (RVTransform ):
@@ -359,38 +356,21 @@ def extend_axis_rev(array, axis):
359
356
Instantiation of :class:`pymc.distributions.transforms.LogExpM1`
360
357
for use in the ``transform`` argument of a random variable."""
361
358
362
- univariate_ordered = Ordered (ndim_supp = 0 )
363
- univariate_ordered .__doc__ = """
359
+ # Deprecated
360
+ ordered = Ordered ()
361
+ ordered .__doc__ = """
364
362
Instantiation of :class:`pymc.distributions.transforms.Ordered`
365
- for use in the ``transform`` argument of a univariate random variable."""
366
-
367
- multivariate_ordered = Ordered (ndim_supp = 1 )
368
- multivariate_ordered .__doc__ = """
369
- Instantiation of :class:`pymc.distributions.transforms.Ordered`
370
- for use in the ``transform`` argument of a multivariate random variable."""
363
+ for use in the ``transform`` argument of a random variable."""
371
364
372
365
log = LogTransform ()
373
366
log .__doc__ = """
374
367
Instantiation of :class:`pymc.logprob.transforms.LogTransform`
375
368
for use in the ``transform`` argument of a random variable."""
376
369
377
- univariate_sum_to_1 = SumTo1 (ndim_supp = 0 )
378
- univariate_sum_to_1 .__doc__ = """
379
- Instantiation of :class:`pymc.distributions.transforms.SumTo1`
380
- for use in the ``transform`` argument of a univariate random variable."""
381
-
382
- multivariate_sum_to_1 = SumTo1 (ndim_supp = 1 )
383
- multivariate_sum_to_1 .__doc__ = """
384
- Instantiation of :class:`pymc.distributions.transforms.SumTo1`
385
- for use in the ``transform`` argument of a multivariate random variable."""
386
-
387
- # backwards compatibility
388
- sum_to_1 = SumTo1 (ndim_supp = 1 )
370
+ sum_to_1 = SumTo1 ()
389
371
sum_to_1 .__doc__ = """
390
372
Instantiation of :class:`pymc.distributions.transforms.SumTo1`
391
- for use in the ``transform`` argument of a random variable.
392
- This instantiation is for backwards compatibility only.
393
- Please use `univariate_sum_to_1` or `multivariate_sum_to_1` instead."""
373
+ for use in the ``transform`` argument of a random variable."""
394
374
395
375
circular = CircularTransform ()
396
376
circular .__doc__ = """
0 commit comments