# Turing NUTS chains getting stuck at the parameter bounds

**URL:** https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947
**Category:** General Usage
**Tags:** turing, differentialequation
**Created:** [August 18, 2022, 7:51pm UTC](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947 "2022-08-18T19:51:52Z")
**Posts on this page:** 4
**Page:** 3

<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 20, 2022, 6:44pm UTC](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947/41 "2022-08-20T18:44:55Z")

</div>

Yes, I’m almost sure these are going to have very very different log-density (lp) values. The key here is going to be to initialize within a reasonable neighborhood of the solution. not too tight, because then you have no real convergence diagnostic, but not so loose that things become locally trapped well away from the real high mass region.

Parallel tempering is mainly useful if there is more than one high mass region separated by some “gulfs” that it can’t cross (though I suppose it would probably also help here). I suspect in this model the actual solution is fairly compact and probably tightly peaked. Sometimes it’s funny that a highly identified model can’t be sampled very well because the region of space you have to get into is so small 🙂

---

<div class="post-metadata">

### Author: ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)
#### Post date: [August 20, 2022, 6:50pm UTC](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947/42 "2022-08-20T18:50:00Z")

</div>

Regarding using a transformation, a method I have used is to take bounded priors and transform to R^n, using Turing’s bijector:

```julia
transf = bijector(@Prior) # transforms draws from prior to draws from ℛⁿ 
transformed_prior = transformed(@Prior, transf) # the transformed prior

```

where the original prior is something like

```julia
# prior should be an array of distributions, one for each parameter
lb, ub = PriorSupport() # need these in Prior
macro Prior()
    return :( arraydist([Uniform(lb[i], ub[i]) for i = 1:size(lb,1)]) )
end

```

Then one can sample from the transformed prior using something like

```julia
@model function MSM(m, S, model)
    θt ~ transformed_prior
   <etcetera>

```

---

<div class="post-metadata">

### Author: ![fkrauer](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fkrauer](https://discourse.julialang.org/u/fkrauer)
#### Post date: [August 20, 2022, 6:51pm UTC](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947/43 "2022-08-20T18:51:26Z")

</div>

I have discarded the previous runs, but here is a plot of the :lp values I posted above. The y axis is not labelled unfortunately, but it is `plot(chain[:lp])`. The values are very different for the different chains suggesting they did get stuck in a local mode.  
 ![logposterior](https://global.discourse-cdn.com/julialang/original/3X/b/f/bf4b0d41273419abe9699b8422c30a7449b94282.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 20, 2022, 6:55pm UTC](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947/44 "2022-08-20T18:55:16Z")

</div>

If you want a “tempering like” solution to this… I’ve done something in the past where I create a “tempering parameter”, and after doing all the calculations, you can look in the ` __varinfo__ ` to grab the current lp value, then

```julia
tempering ~ Normal(0,1);
...
temperval = (1 + a * inv_logistic(b * (tempering+c))
curlp = __varinfo__... # I don't remember exactly how to access it.
@addlogprob! -curlp
@addlogprob! curlp/temperval
return temperval

```

when tempering is very negative, temperval is 1, then this is just curlp/1 and you’re sampling from the model you want… when it’s more to the right… you’re sampling from a tempered version of your problem…

Post sampling, you just subset the samples that have temperval sufficiently close to 1.

[Previous page](https://discourse.julialang.org/t/turing-nuts-chains-getting-stuck-at-the-parameter-bounds/85947.md?page=2)
