# Recommended sampler for data with Categorical likelihood

**URL:** <https://discourse.julialang.org/t/recommended-sampler-for-data-with-categorical-likelihood/85820>\
**Category:** Probabilistic Programming\
**Tags:** turing\
**Created:** [August 16, 2022, 12:22pm UTC](https://discourse.julialang.org/t/recommended-sampler-for-data-with-categorical-likelihood/85820 "2022-08-16T12:22:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [August 16, 2022, 12:22pm UTC](https://discourse.julialang.org/t/recommended-sampler-for-data-with-categorical-likelihood/85820/1 "2022-08-16T12:22:54Z")

</div>

The NUTS sampler takes a really long time in this MWE:

```julia
using Distributions
using Turing

d = Categorical([0.7, 0.29, 0.01])
N = 100
Y = rand(d, N)

@model function test(Y)
    p ~ Dirichlet([2,2,2])
    for i in 1:N
        Y[i] ~ Categorical(p)
    end
end

m = test(Y)
chain = sample(m, NUTS(), 1_000)

```

I have thousands of observations for my real problem so I’m going to need to choose a different sampler. I’m hoping someone can provide some suggestions for this kind of problem because I’ve been spoiled by the NUTS sampler just working (for the most part) and not having to tune a different sampler.

---

<div class="post-metadata">

**Author:** ![opera\_malenky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/opera_malenky/32/8213_2.png) [@opera\_malenky](https://discourse.julialang.org/u/opera_malenky)\
**Post date:** [August 16, 2022, 9:36pm UTC](https://discourse.julialang.org/t/recommended-sampler-for-data-with-categorical-likelihood/85820/2 "2022-08-16T21:36:27Z")

</div>

Just to provide another data point, you can see that Dirichlet is still much, much slower than using Beta for an equivalent model:

```julia
@model function test(Y)
    p ~ Dirichlet([2,2])
    for i in 1:N
        Y[i] ~ Categorical(p)
    end
end

m = test(Y)
chain = sample(m, NUTS(), 1_000)

@model function test2(Y)
    p ~ Beta(1,1)
    for i in 1:N
        Y[i] ~ Categorical([p, 1-p])
    end
end

m2 = test2(Y)
chain = sample(m2, NUTS(), 1_000)

# m (Dirichlet) takes 70.5s (10.7 ESS/s)
# m2 (Beta) takes 0.4s (1060 ESS/s)

```

No idea why.
