@@ -783,13 +783,17 @@ def __call__(self, *args, **kwargs):
783
783
compilef = fastfn
784
784
785
785
786
- def _get_scaling (total_size , data ):
786
+ def _get_scaling (total_size , shape , ndim ):
787
787
"""
788
+ Gets scaling constant for logp
788
789
789
790
Parameters
790
791
----------
791
792
total_size : int or list[int]
792
- data : n-dimentional tensor
793
+ shape : shape
794
+ shape to scale
795
+ ndim : int
796
+ ndim hint
793
797
794
798
Returns
795
799
-------
@@ -798,16 +802,15 @@ def _get_scaling(total_size, data):
798
802
if total_size is None :
799
803
coef = pm .floatX (1 )
800
804
elif isinstance (total_size , int ):
801
- if data . ndim >= 1 :
802
- denom = data . shape [0 ]
805
+ if ndim >= 1 :
806
+ denom = shape [0 ]
803
807
else :
804
808
denom = 1
805
809
coef = pm .floatX (total_size ) / pm .floatX (denom )
806
810
elif isinstance (total_size , (list , tuple )):
807
811
if not all (isinstance (i , int ) for i in total_size if (i is not Ellipsis and i is not None )):
808
812
raise TypeError ('Unrecognized `total_size` type, expected '
809
813
'int or list of ints, got %r' % total_size )
810
- shape = data .shape
811
814
if Ellipsis in total_size :
812
815
sep = total_size .index (Ellipsis )
813
816
begin = total_size [:sep ]
@@ -817,7 +820,7 @@ def _get_scaling(total_size, data):
817
820
else :
818
821
begin = total_size
819
822
end = []
820
- if (len (begin ) + len (end )) > data . ndim :
823
+ if (len (begin ) + len (end )) > ndim :
821
824
raise ValueError ('Length of `total_size` is too big, '
822
825
'number of scalings is bigger that ndim, got %r' % total_size )
823
826
elif (len (begin ) + len (end )) == 0 :
@@ -866,7 +869,7 @@ def __init__(self, type=None, owner=None, index=None, name=None,
866
869
self .logp_elemwiset = distribution .logp (self )
867
870
self .total_size = total_size
868
871
self .model = model
869
- self .scaling = _get_scaling (total_size , self )
872
+ self .scaling = _get_scaling (total_size , self . shape , self . ndim )
870
873
871
874
incorporate_methods (source = distribution , destination = self ,
872
875
methods = ['random' ],
@@ -972,7 +975,7 @@ def __init__(self, type=None, owner=None, index=None, name=None, data=None,
972
975
theano .gof .Apply (theano .compile .view_op ,
973
976
inputs = [data ], outputs = [self ])
974
977
self .tag .test_value = theano .compile .view_op (data ).tag .test_value
975
- self .scaling = _get_scaling (total_size , data )
978
+ self .scaling = _get_scaling (total_size , data . shape , data . ndim )
976
979
977
980
def _repr_latex_ (self , name = None , dist = None ):
978
981
if self .distribution is None :
@@ -1016,6 +1019,7 @@ def __init__(self, name, data, distribution, total_size=None, model=None):
1016
1019
self .total_size = total_size
1017
1020
self .model = model
1018
1021
self .distribution = distribution
1022
+ self .scaling = _get_scaling (total_size , self .logp_elemwiset .shape , self .logp_elemwiset .ndim )
1019
1023
1020
1024
1021
1025
def Deterministic (name , var , model = None ):
@@ -1093,7 +1097,7 @@ def __init__(self, type=None, owner=None, index=None, name=None,
1093
1097
theano .Apply (theano .compile .view_op , inputs = [
1094
1098
normalRV ], outputs = [self ])
1095
1099
self .tag .test_value = normalRV .tag .test_value
1096
-
1100
+ self . scaling = _get_scaling ( total_size , self . shape , self . ndim )
1097
1101
incorporate_methods (source = distribution , destination = self ,
1098
1102
methods = ['random' ],
1099
1103
wrapper = InstanceMethod )
0 commit comments