# Truncated Normal

**URL:** <https://discourse.pymc.io/t/truncated-normal/6338>\
**Category:** Questions\
**Created:** [December 1, 2020, 6:13pm UTC](https://discourse.pymc.io/t/truncated-normal/6338 "2020-12-01T18:13:16Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [January 29, 2021, 2:56pm UTC](https://discourse.pymc.io/t/truncated-normal/6338/9 "2021-01-29T14:56:56Z")

</div>

I also get divergence problems when sampling from a HalfNormal

```python
with pm.Model() as m: 
  x = pm.HalfNormal('x', 1) 
  trace = pm.sample() 
  # Divergences

```

I think NUTS is struggling to sample because the peak of the distribution is at the very boundary of the domain. The problems seem to go away if the mean is enough away from the boundary:

```auto
with pm.Model() as m: 
  x = pm.TruncatedNormal('x', lower=0, mu=3, sigma=1) 
  trace = pm.sample() 
  # No Divergences

```

If you want NUTS to sample you might want to give it an extra legroom by tweaking `tune` and `target_accept`:

```python
with pm.Model() as m: 
  x = pm.TruncatedNormal('x', lower=0, mu=0, sd=5) 
  trace = pm.sample(tune=2000, target_accept=.95) 
  # No divergences

```

If anyone else can chime in and confirm this is reasonable behavior from NUTS, that would be really helpful.

This might be related: [Zero-excluding priors are probably a bad idea for hierarchical variance parameters « Statistical Modeling, Causal Inference, and Social Science](https://statmodeling.stat.columbia.edu/2018/05/04/zero-excluding-priors-probably-bad-idea-hierarchical-variance-parameters/)

---

_[View the full topic](https://discourse.pymc.io/t/truncated-normal/6338)._
