# Mixture Model fitting with Turing

**URL:** <https://discourse.julialang.org/t/mixture-model-fitting-with-turing/51706>\
**Category:** Probabilistic Programming\
**Tags:** distributions\
**Created:** [December 12, 2020, 9:11am UTC](https://discourse.julialang.org/t/mixture-model-fitting-with-turing/51706 "2020-12-12T09:11:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![asjir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asjir/32/19899_2.png) [@asjir](https://discourse.julialang.org/u/asjir)\
**Post date:** [December 12, 2020, 9:11am UTC](https://discourse.julialang.org/t/mixture-model-fitting-with-turing/51706/1 "2020-12-12T09:11:16Z")

</div>

`logpdf` for a `MixtureModel` fails to differentiate (for me at least with all AD backends), prohibiting use of Hamiltonian MC and its derivatives for fitting models.

The easy workaround is writing `Distributions.logpdf(m::MixtureModel, x::Float64) = log(pdf(m, x))` and the cost of numerical stability is relatively minor.

Googling “turing mixture model” gives [this tutorial](https://turing.ml/dev/tutorials/1-gaussianmixturemodel/) as the first result, so maybe it would be helpful to add a footnote to this tutorial demonstrating how the same can be achieved more efficiently if we don’t need to sample cluster assignments?
