# Prior sample from TruncatedNormal gives inf

**URL:** https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316
**Category:** Questions
**Created:** [May 22, 2019, 3:36pm UTC](https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316 "2019-05-22T15:36:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [May 22, 2019, 3:36pm UTC](https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316/1 "2019-05-22T15:36:25Z")

</div>

I have made a model with the following observed value, `obs`:

```auto
 pm.TruncatedNormal("obs", mu=multiplier.T * pred + means_vector, sd=err_sd, observed=self.df['mean_log_gfp_live'].to_numpy(),
                               lower=0.0, upper=12.0)

```

I then sampled from the model using `sample _prior_predictive()`.  
I was quite surprised that many of the sampled values are apparently `np.inf` or `-np.inf`. Shouldn’t this be impossible because of the truncation? Or at best, shouldn’t this give a runtime error?  
When I checked, 1977 of my 5000 samples have at least one of their values (`observed` is a vector of 1043 elements) either `inf` or `-inf`.  
Probably this means there’s something wrong with my model, but this also suggests that this variable can behave oddly in prior sampling.

---

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [May 22, 2019, 3:50pm UTC](https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316/2 "2019-05-22T15:50:48Z")

</div>

The `sd` variable is a `HalfNormal` – is there any chance that this is going awry when I get too high a sample there, and we hit this code in the `TruncatedNormal` sampler:

```auto
      return generate_samples(stats.truncnorm.rvs,
                                a=(a_v - mu_v)/std_v,
                                b=(b_v - mu_v) / std_v,
                                loc=mu_v,
                                scale=std_v,
                                dist_shape=self.shape,
                                size=size,
                                )

```

If that’s the case, should we do something to trap this, even if it’s only trapping infinite outputs from the various `rvs` methods?  
And is there something I should be doing to limit my `err_sd` to keep this from happening?

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [May 25, 2019, 6:01am UTC](https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316/3 "2019-05-25T06:01:38Z")

</div>

hmmm this sounds like a bug.

---

<div class="post-metadata">

### Author: ![rpgoldman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rpgoldman/32/1800_2.png) [@rpgoldman](https://discourse.pymc.io/u/rpgoldman)
#### Post date: [May 27, 2019, 4:53pm UTC](https://discourse.pymc.io/t/prior-sample-from-truncatednormal-gives-inf/3316/4 "2019-05-27T16:53:16Z")

</div>

Thanks for letting me know. I will try to isolate a test case.
