# DynamicHMC or something similar, with mixed variable support Int, Reals

**URL:** https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608
**Category:** Community
**Created:** [February 9, 2019, 5:04pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608 "2019-02-09T17:04:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![francesco.alemanno](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)
#### Post date: [February 9, 2019, 5:04pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608/1 "2019-02-09T17:04:47Z")

</div>

Hello Everyone!

i recently fell in love with Julia, and i was looking for packages that can sample efficiently a boltzmann kind probability distribution:  
p(x) ∼ exp[-H(x)]  
where the variables “x” can be both continuous or discrete.  
I found out about dynamicHMC, but apparently it handles only continuous variables since is demands a gradient…  
Does anyone know about a package that handles the mixed variables case?  
So that i can avoid writing a slower, buggier, simpler (in a bad way) MCMC sampler for my research project…

Thank you in advance!!

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 9, 2019, 5:37pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608/2 "2019-02-09T17:37:43Z")

</div>

It’s not clear what you are asking for, HMC won’t work unless the (log) density is continuous and differentiable — it’s a basic requirement of the algorithm.

You can either

1. marginalize out the discrete part, and use DynamicHMC or any other NUTS variant,
2. use a Gibbs-like sampler with HMC on the continuous part (but for that, you really need to understand the details and tune it yourself),
3. use a gradient-free sampler, eg (RW)MH.

---

<div class="post-metadata">

### Author: ![francesco.alemanno](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)
#### Post date: [February 9, 2019, 5:48pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608/3 "2019-02-09T17:48:32Z")

</div>

Hi Tamas, first of all thanks for answering and for the good work on Julia!

the first option unfortunately cannot be pursued since i need to estimate statistics on composite variables…  
the other options can do, could you recommend some package or combination?

[https://arxiv.org/abs/1311.2166](https://arxiv.org/abs/1311.2166)  
[https://arxiv.org/abs/1705.08510](https://arxiv.org/abs/1705.08510)

Apparently there are ways to augment HMC with discrete variables! very interesting

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 9, 2019, 7:01pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608/4 "2019-02-09T19:01:32Z")

</div>

I think that Klara and Mamba can do combined NUTS-Gibbs steps. But I am not sure.

> **[GitHub - JuliaStats/Klara.jl: MCMC inference in Julia](https://github.com/JuliaStats/Klara.jl)**
>
> MCMC inference in Julia. Contribute to JuliaStats/Klara.jl development by creating an account on GitHub.

> **[GitHub - brian-j-smith/Mamba.jl: Markov chain Monte Carlo (MCMC) for Bayesian...](https://github.com/brian-j-smith/Mamba.jl)**
>
> Markov chain Monte Carlo (MCMC) for Bayesian analysis in julia - GitHub - brian-j-smith/Mamba.jl: Markov chain Monte Carlo (MCMC) for Bayesian analysis in julia

---

<div class="post-metadata">

### Author: ![goedman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goedman/32/217_2.png) [@goedman](https://discourse.julialang.org/u/goedman)
#### Post date: [February 9, 2019, 7:33pm UTC](https://discourse.julialang.org/t/dynamichmc-or-something-similar-with-mixed-variable-support-int-reals/20608/5 "2019-02-09T19:33:22Z")

</div>

[Turing.jl](https://github.com/TuringLang/Turing.jl) supports a Gibbs sampler.
