Skip to content

trying to fix #2298 #2299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions pymc3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,17 @@ def __call__(self, *args, **kwargs):
compilef = fastfn


def _get_scaling(total_size, data):
def _get_scaling(total_size, shape, ndim):
"""
Gets scaling constant for logp

Parameters
----------
total_size : int or list[int]
data : n-dimentional tensor
shape : shape
shape to scale
ndim : int
ndim hint

Returns
-------
Expand All @@ -798,16 +802,15 @@ def _get_scaling(total_size, data):
if total_size is None:
coef = pm.floatX(1)
elif isinstance(total_size, int):
if data.ndim >= 1:
denom = data.shape[0]
if ndim >= 1:
denom = shape[0]
else:
denom = 1
coef = pm.floatX(total_size) / pm.floatX(denom)
elif isinstance(total_size, (list, tuple)):
if not all(isinstance(i, int) for i in total_size if (i is not Ellipsis and i is not None)):
raise TypeError('Unrecognized `total_size` type, expected '
'int or list of ints, got %r' % total_size)
shape = data.shape
if Ellipsis in total_size:
sep = total_size.index(Ellipsis)
begin = total_size[:sep]
Expand All @@ -817,7 +820,7 @@ def _get_scaling(total_size, data):
else:
begin = total_size
end = []
if (len(begin) + len(end)) > data.ndim:
if (len(begin) + len(end)) > ndim:
raise ValueError('Length of `total_size` is too big, '
'number of scalings is bigger that ndim, got %r' % total_size)
elif (len(begin) + len(end)) == 0:
Expand Down Expand Up @@ -866,7 +869,7 @@ def __init__(self, type=None, owner=None, index=None, name=None,
self.logp_elemwiset = distribution.logp(self)
self.total_size = total_size
self.model = model
self.scaling = _get_scaling(total_size, self)
self.scaling = _get_scaling(total_size, self.shape, self.ndim)

incorporate_methods(source=distribution, destination=self,
methods=['random'],
Expand Down Expand Up @@ -972,7 +975,7 @@ def __init__(self, type=None, owner=None, index=None, name=None, data=None,
theano.gof.Apply(theano.compile.view_op,
inputs=[data], outputs=[self])
self.tag.test_value = theano.compile.view_op(data).tag.test_value
self.scaling = _get_scaling(total_size, data)
self.scaling = _get_scaling(total_size, data.shape, data.ndim)

def _repr_latex_(self, name=None, dist=None):
if self.distribution is None:
Expand Down Expand Up @@ -1016,6 +1019,7 @@ def __init__(self, name, data, distribution, total_size=None, model=None):
self.total_size = total_size
self.model = model
self.distribution = distribution
self.scaling = _get_scaling(total_size, self.logp_elemwiset.shape, self.logp_elemwiset.ndim)


def Deterministic(name, var, model=None):
Expand Down Expand Up @@ -1093,7 +1097,7 @@ def __init__(self, type=None, owner=None, index=None, name=None,
theano.Apply(theano.compile.view_op, inputs=[
normalRV], outputs=[self])
self.tag.test_value = normalRV.tag.test_value

self.scaling = _get_scaling(total_size, self.shape, self.ndim)
incorporate_methods(source=distribution, destination=self,
methods=['random'],
wrapper=InstanceMethod)
Expand Down