Pymc3: pymc not using ElemwiseCategorical for missing categorical values

Created on 1 Jul 2016  路  5Comments  路  Source: pymc-devs/pymc3

Hi, I was trying to run the following code:

import numpy as np
import pymc3 as pmc

x_missing = np.ma.masked_values([0, 2, 0, 1, 0, -999, 0, 1, -999], value=-999)
x_not_missing = [0, 2, 0, 1, 0, 0, 0, 1, 1]

N = len(x_not_missing)

model = pmc.Model()

with model:
    a = pmc.Dirichlet('a', np.ones(3))
    x = pmc.Categorical('x3', p=a, shape=N, observed=x_missing)


    trace = pmc.sample(1000, step=pmc.Metropolis())
pmc.traceplot(trace)

And get the following output (with error)

Applied stickbreaking-transform to a and added transformed a_stickbreaking to model.
Assigned NUTS to a_stickbreaking
Assigned Metropolis to x3_missing
(...)
IndexError: index 3 is out of bounds for size 3 (...)

However, if I change the observed to x_not_missing, it works fine. Reading #1095, I see that it's most likely because PyMC assigns Metropolis to the x3_missing variable, which is categorical.

Most helpful comment

I see the problem. The missing values are being attributed with the distribution NoDistribution, as we do with missing data. Will fix.

All 5 comments

You have a mistake in your code. You should be passing a as the p argument to x.

Thanks for noticing! It was an artifact of my attempt to reduce the code to the minimal example. Just updated it, shouldn't interfere with the issue.

EDIT: The error message changes because we then revert to #881, but if we add step=pmc.Metropolis() we get the original error back. Edited in the main code.

I'm having the same issue here

I see the problem. The missing values are being attributed with the distribution NoDistribution, as we do with missing data. Will fix.

I tested it locally and it is not an issue anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fonnesbeck picture fonnesbeck  路  3Comments

aseyboldt picture aseyboldt  路  5Comments

ricardoV94 picture ricardoV94  路  3Comments

parashardhapola picture parashardhapola  路  4Comments

aakhmetz picture aakhmetz  路  4Comments