# Insights from Dynamic HMC animation

**URL:** <https://discourse.mc-stan.org/t/insights-from-dynamic-hmc-animation/17998>\
**Category:** Algorithms\
**Created:** [September 13, 2020, 12:27am UTC](https://discourse.mc-stan.org/t/insights-from-dynamic-hmc-animation/17998 "2020-09-13T00:27:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyunji.moon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/hyunji.moon/32/9781_2.png) [@hyunji.moon](https://discourse.mc-stan.org/u/hyunji.moon)\
**Post date:** [September 13, 2020, 12:27am UTC](https://discourse.mc-stan.org/t/insights-from-dynamic-hmc-animation/17998/1 "2020-09-13T00:27:47Z")

</div>

Could anyone share their opinion on what insights could be gain from [this](https://www.youtube.com/watch?v=ggjKV4vP3pY&ab_channel=TokyoStan) Dyanmic HMC from Mulivariate Gaussian animation by @betanalpha? I am adding some questions but I look forward to any general comments.

[![](https://img.youtube.com/vi/ggjKV4vP3pY/maxresdefault.jpg "Dynamic Hamiltonian Monte Carlo targeting a Multivariate Gaussian Distribution") ](https://www.youtube.com/watch?v=ggjKV4vP3pY)

1. Is this algorithm NUTS? If so, which algorithm (1 to 6 from [this](http://www.stat.columbia.edu/~gelman/research/published/nuts.pdf) paper) would it be?

From the animation, the number of steps change, which could be observed in NUTS. Also it runs forwards and backwards.

1. How are the new initial points selected at every iteration (in 19s and 28s)?

2. any possible explanation on how underlying distribution is affecting the sampling results? For example, balanced direction changes due to symmetry in gaussian.

This [slide](https://avehtari.github.io/masterclass/slides_hmc.pdf) from @avehtari summarizes HMC nicely.

---

<div class="post-metadata">

**Author:** ![yiyuezhuo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yiyuezhuo/32/9335_2.png) [@yiyuezhuo](https://discourse.mc-stan.org/u/yiyuezhuo)\
**Post date:** [September 13, 2020, 5:10am UTC](https://discourse.mc-stan.org/t/insights-from-dynamic-hmc-animation/17998/2 "2020-09-13T05:10:54Z")

</div>

1. Algorithm 2 = Algorithm 3 except later will be more efficient. Algorithm 2/3 + Algorithm 4 + … = Algorithm 6. And since this video just shows the sampling phase, you don’t know if some sampler parameter is given by hand or algorithm so it may be 2, 3, 6.

2. This is described detailly by your cited paper.

3. You may be interested in this demo:

[https://chi-feng.github.io/mcmc-demo/app.html?algorithm=HamiltonianMC&target=banana](https://chi-feng.github.io/mcmc-demo/app.html?algorithm=HamiltonianMC&target=banana)

which run multiple samplers on different target distributions.

---

<div class="post-metadata">

**Author:** ![betanalpha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/betanalpha/32/4_2.png) [@betanalpha](https://discourse.mc-stan.org/u/betanalpha)\
**Post date:** [September 16, 2020, 12:37am UTC](https://discourse.mc-stan.org/t/insights-from-dynamic-hmc-animation/17998/3 "2020-09-16T00:37:06Z")

</div>

@hyunji.moon The trajectories created in this video are actual trajectories created by the dynamic Hamiltonian Monte Carlo algorithm in Stan\*. In particular the Stan implementation has evolved quite a bit since the original No-U-Turn sampler paper.  
The best way to think about the algorithm is in two stages – first sampling a numerical trajectory that contains the initial point and then sampling a new point within that trajectory based on the local error in the Hamiltonian function. See also the accompanying video that shows divergent trajectories [https://www.youtube.com/watch?v=1TKhH81k7QA](https://www.youtube.com/watch?v=1TKhH81k7QA).

For many more details see [https://arxiv.org/abs/1701.02434](https://arxiv.org/abs/1701.02434), especially the appendix which includes detailed proofs for the invariance of the target distribution.

\*Technically these trajectories are from a slightly older version of Stan before we added in more termination checks to avoid unnecessarily long trajectories, such as the few seen in the video. In the current version of Stan all of the trajectories will be approximately the same size for a normal target density function.
