Skip to content

Changed Categorical to work with multidim p at the logp level reloaded #3386

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 12 commits into from
Feb 28, 2019
Merged
Changes from 7 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
8 changes: 3 additions & 5 deletions pymc3/distributions/discrete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numbers
import numpy as np
import theano
import theano.tensor as tt
Expand Down Expand Up @@ -739,9 +738,7 @@ def logp(self, value):
# We must only check that the values sum to 1 if p comes from a
# tensor variable, i.e. when p is a step_method proposal. In the other
# cases we normalize ourselves
if not isinstance(p_, (numbers.Number,
np.ndarray,
tt.TensorConstant,
if not isinstance(p_, (tt.TensorConstant,
tt.sharedvar.SharedVariable)):
sumto1 = theano.gradient.zero_grad(
tt.le(abs(tt.sum(p_, axis=-1) - 1), 1e-5))
Expand All @@ -751,7 +748,8 @@ def logp(self, value):
sumto1 = True

if p.ndim > 1:
a = tt.log(np.moveaxis(p, -1, 0)[value_clip])
pattern = (p.ndim - 1,) + tuple(range(p.ndim - 1))
a = tt.log(p.dimshuffle(pattern)[value_clip])
else:
a = tt.log(p[value_clip])

Expand Down