Hi all,

I was wondering if there is an easy way of imposing bounds/constraints on existing distributions, e.g. for sampling from a normal distribution in an interval [a, b].

Thanks a lot!

Hi all,

I was wondering if there is an easy way of imposing bounds/constraints on existing distributions, e.g. for sampling from a normal distribution in an interval [a, b].

Thanks a lot!

If you are doing MCMC, then it is fine to restrict the support of a distribution to create an unnormalized distribution. I think you can follow the approach in `model2`

of this tutorial or you can define

```
bounded_normal = dist.Normal(0, 1)
bounded_normal.support = constraints.interval(a, b)
x = sample('x', bounded_normal)
```

However, the latter approach does not modify `sample`

method of `dist.Normal`

, so `bounded_normal`

might generate some invalid (out-of-support) samples. To fix that issue, you can specify an initial value for `x`

, for example

```
kernel = NUTS(model, init_strategy=init_to_value(values={'x': (a + b) / 2})
```

Thanks a lot, that will work.