# Improving metropolis-hastings code

**URL:** <https://discourse.julialang.org/t/improving-metropolis-hastings-code/67412>\
**Category:** General Usage\
**Tags:** monte-carlo\
**Created:** [August 31, 2021, 9:16am UTC](https://discourse.julialang.org/t/improving-metropolis-hastings-code/67412 "2021-08-31T09:16:53Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 5, 2021, 3:55pm UTC](https://discourse.julialang.org/t/improving-metropolis-hastings-code/67412/21 "2021-09-05T15:55:58Z")

</div>

> [@marouane](#):
>
> if there is any minimum example for moving the coordinates one at a time

I am not sure about examples _in Julia_. However, pseudo-codes are widely available. If you are into adaptive Metropolis algorithms, you could take a look at the adaptive single component version of [Haario et al. (2005)](https://link.springer.com/article/10.1007%2FBF02789703). I have written it in Julia once, but the replication code is not on Github.

> [@opera\_malenky](#):
>
> an acceptance rate of about 23.4% is often (though certainly not always) optimal.

True for most standard MHs. However, if @marouane is going to use a single component algorithm s/he should be careful. In similar cases, authors tend to aim for a ~44% acceptance rate per parameter.

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [September 6, 2021, 3:22am UTC](https://discourse.julialang.org/t/improving-metropolis-hastings-code/67412/22 "2021-09-06T03:22:16Z")

</div>

This is called Gibbs sampling and is implemented in Turing.jl [here](https://github.com/TuringLang/Turing.jl/tree/master/src/inference).

[Previous page](https://discourse.julialang.org/t/improving-metropolis-hastings-code/67412.md?page=1)
