# Sampling using NUTS - Turing

**URL:** <https://discourse.julialang.org/t/sampling-using-nuts-turing/102347>\
**Category:** New to Julia\
**Tags:** turing\
**Created:** [August 1, 2023, 11:16am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347 "2023-08-01T11:16:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [August 1, 2023, 11:16am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/1 "2023-08-01T11:16:24Z")

</div>

I have these two settings `NUTS(500, 0.65)` and `NUTS(0, 0.65)` and get very different results. Is it expected? if yes why?

I was expecting both to be similar if not exact as both run for 1500 particles.

```julia
chain = sample(model, NUTS(500, 0.65), MCMCThreads(), 1000, 1; save_state = true)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c3472f060d42825a249b3f2e8dcc2336fdd9b81.png)

```julia
chain = sample(model, NUTS(0, 0.65), MCMCThreads(), 1500, 1; save_state = true)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/d/e/decba4517a647475aefb65b70b1863cc1babc04f.png)

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 1, 2023, 3:12pm UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/2 "2023-08-01T15:12:31Z")

</div>

> [@Sahil\_Khan](#):
>
> Is it expected? if yes why?

Yes, the NUTS algorithm spends a bunch of effort to find an appropriate step size and mass matrix and to get into the high probability region during warmup, you have told it to do no warmup at all and that will be basically disastrous. I typically do 100-500 warmup steps as a matter of course.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [August 2, 2023, 8:12am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/3 "2023-08-02T08:12:56Z")

</div>

ohh okay. Is there any percentage wrt iteration number for warmup or 100-500 works for even long iterations?

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 2, 2023, 8:18am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/4 "2023-08-02T08:18:27Z")

</div>

It’s not so much percentage it’s just that the warmup needs to go far enough that it has converged into the high probability region. what determines the needed steps is the geometry of the high probability manifold. If it requires a lot of curving around in high dimensional space then it will need more time if it’s a simple low dimensional model it may converge faster.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [August 2, 2023, 8:19am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/5 "2023-08-02T08:19:59Z")

</div>

okay. I understand

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [August 2, 2023, 8:20am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/6 "2023-08-02T08:20:56Z")

</div>

Is there any way that we do these warmup but can still get chain plot from 0 rather from end of warm up?

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 2, 2023, 8:23am UTC](https://discourse.julialang.org/t/sampling-using-nuts-turing/102347/7 "2023-08-02T08:23:16Z")

</div>

I’m not sure. During warmup the process is adaptive and doesn’t have a stationary distribution yet. You normally don’t want those steps.
