# Bound variables misbehaving

**URL:** https://discourse.pymc.io/t/bound-variables-misbehaving/6407
**Category:** Questions
**Created:** [December 9, 2020, 3:31pm UTC](https://discourse.pymc.io/t/bound-variables-misbehaving/6407 "2020-12-09T15:31:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BjornHartmann](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@BjornHartmann](https://discourse.pymc.io/u/BjornHartmann)
#### Post date: [December 9, 2020, 3:31pm UTC](https://discourse.pymc.io/t/bound-variables-misbehaving/6407/1 "2020-12-09T15:31:18Z")

</div>

I am trying to make a callable function where a user can define the parameters of a distribution. I want to prevent any values from going below zero as there is a tt.log operation inside this function.

I was therefore going to use the **pm.Bound** method to do:

`bound_N = pm.Bound(pm.Normal,lower=0)`

There are two issues:

1. The simple bound\_N above gives divergencies for any parameters i.e  
`bound_N('N',mu=3,sd=2)` unless target\_accept is raised to i.e 0.9
2. The result of this bounded normal is completely off if the mean (_mu_) is set to a large number. For example using:

`bound_N('N',mu=1e5,sd=20)` gives the below graph. (having mu=1e4 seems to work)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/8/8b04fb6b615281bc683ae123832954f725f2ec87.png)

Any explanation to this?

---

<div class="post-metadata">

### Author: ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)
#### Post date: [December 10, 2020, 3:19am UTC](https://discourse.pymc.io/t/bound-variables-misbehaving/6407/2 "2020-12-10T03:19:41Z")

</div>

Bounding variables works as advertised, but is a bit of a hack. You’re constructing a normally-distributed variable, “telling” the sampler that the random variable could take on a whole range of values…and then declaring a whole range of values to be out-of-bounds. Sampling likes smooth surfaces (e.g., no sharp corners) and your bounds place a giant wall at zero. That’s likely the source of the divergences (though it would take a bit digging to confirm this). I might suggest using something other than a `pm.normal()`. [`Gamma`](https://docs.pymc.io/api/distributions/continuous.html#pymc3.distributions.continuous.Gamma) or [`Weibull`](https://docs.pymc.io/api/distributions/continuous.html#pymc3.distributions.continuous.Weibull) might be of use because their support is x \in [0, \infty], naturally bounding values to be non-negative.
