Skip to content

Wrong test values in Categorical distribution #3156

Closed
@plison

Description

@plison

The test values for the Categorical distribution are incorrect:

import pymc3 as pm
import theano

probs_X = theano.shared(np.array([0.5, 0.5]))
probs_Y = theano.shared(np.array([[0.33, 0.33,0.34], [0.25, 0.25, 0.5]]))

values_X = np.array([0, 0, 1])
with pm.Model() as model:
    X = pm.Categorical("X", p=probs_X, observed=values_X) 
    Y = pm.Categorical("Y", p=probs_Y[X])
    print("Default value:", Y.distribution.default())

gives for some strange reason the value:

Default value: 8

This incorrect value breaks the model, giving an infinite log-probability for the Y variable:

model.check_test_point()
Y        -inf
X   -2.080000

I'm using the latest development version of PyMC3, on Github.

I checked the code by I don't quite understand what is going on. The default value seems to be derived from the mode, which is in the case of the Categorical is the argmax of the probability vector. But this argmax is not actually computed, what is retrieved is the tag.test_value attribute of the mode tensor variable. I have absolutely no clue as to why this test value gives 8 in this case...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions