# CategoricalGibbsMetropolis samples differently when specified explicitly

**URL:** <https://discourse.pymc.io/t/categoricalgibbsmetropolis-samples-differently-when-specified-explicitly/3941>\
**Category:** Questions\
**Created:** [October 8, 2019, 5:56pm UTC](https://discourse.pymc.io/t/categoricalgibbsmetropolis-samples-differently-when-specified-explicitly/3941 "2019-10-08T17:56:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwest](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lwest](https://discourse.pymc.io/u/lwest)\
**Post date:** [October 8, 2019, 5:56pm UTC](https://discourse.pymc.io/t/categoricalgibbsmetropolis-samples-differently-when-specified-explicitly/3941/1 "2019-10-08T17:56:45Z")

</div>

Hi. When a categorical variable is sampler is assigned automatically as CategoricalGibbsMetropolis it seems to behave differently to when specified as a keyword argument.  
E.g.

```
n = 10
X = np.random.rand(n)
K = 1+np.arange(n)*0.1
Y = K[3]*X + np.random.randn(n)*0.01

with pm.Model() as model:
    ind = pm.Categorical('ind', p=np.ones(n)/n)
    k = t.shared(K)
    mu = k[ind]*X  
    y = pm.Normal('y', mu=mu, sd=0.01, observed=Y,shape=n)
    trace = pm.sample(10000) 
    outind = trace.get_values(ind)

```

will return the correctly sampled posterior in the trace.  
Whereas specifying the same sampler explicitly with:

```
step = pm.CategoricalGibbsMetropolis([ind]) 
trace = pm.sample(10000, step=[step])

```

the trace instead returns the prior distribution.  
Why is the prior distribution being returned here? Or am I misunderstanding the step keyword?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 9, 2019, 7:51am UTC](https://discourse.pymc.io/t/categoricalgibbsmetropolis-samples-differently-when-specified-explicitly/3941/2 "2019-10-09T07:51:02Z")

</div>

Hmm, I cannot reproduce the problem, could you please try update to pymc3 master?

---

<div class="post-metadata">

**Author:** ![lwest](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lwest](https://discourse.pymc.io/u/lwest)\
**Post date:** [October 10, 2019, 10:45am UTC](https://discourse.pymc.io/t/categoricalgibbsmetropolis-samples-differently-when-specified-explicitly/3941/3 "2019-10-10T10:45:03Z")

</div>

Yep, that sorted it out thanks.
