# Can't sample a Beta(70,70) ! (but a beta(60,60) works ?!)

**URL:** <https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467>\
**Category:** Questions\
**Created:** [February 7, 2020, 9:12am UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467 "2020-02-07T09:12:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [February 7, 2020, 9:12am UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/1 "2020-02-07T09:12:46Z")

</div>

While trying some experiment about beta distributions I found thid weird behaviour…

This code works :

```
with pm.Model() as model:
    r0 = pm.Beta('r0',alpha=1+60,beta=1+60)  
        
    trace = pm.sample(chains=1)
_ = pm.traceplot(trace)

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/4/4b013421633917fd9ed7c23c6203bacf321d03ee.png)  
,  
But this one, just changing the alpha & beta params from 60 to 70 :

```
with pm.Model() as model:
    r0 = pm.Beta('r0',alpha=1+70,beta=1+70)  
        
    trace = pm.sample(chains=1)
_ = pm.traceplot(trace) 

```

fails with a : _“ValueError: Bad initial energy: nan. The model might be misspecified.”_

I don’t understand why !? And this is even more strange :  
`r0 = pm.Beta('r0',alpha=1+999,beta=1+999)`  
works !!

Why certain specific parameter values range seem to have problem ?

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![tushar\_chandra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tushar_chandra/32/2547_2.png) [@tushar\_chandra](https://discourse.pymc.io/u/tushar_chandra)\
**Post date:** [February 7, 2020, 4:15pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/2 "2020-02-07T16:15:53Z")

</div>

Hm, I can’t seem to reproduce this, that’s really interesting.

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

Perhaps “bad initial energy” means that the sampler is trying to start in a region of zero probability density. Since this Beta has such tight tails, could it be that an initialization outside roughly (0.3, 0.7) is causing that problem?

---

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [February 7, 2020, 4:28pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/3 "2020-02-07T16:28:07Z")

</div>

Interesting hypothesis, but then :

`r0 = pm.Beta('r0',alpha=1+999,beta=1+999)`

Should be even harder to sample !! (but it works perfectly…)

---

<div class="post-metadata">

**Author:** ![tushar\_chandra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tushar_chandra/32/2547_2.png) [@tushar\_chandra](https://discourse.pymc.io/u/tushar_chandra)\
**Post date:** [February 7, 2020, 4:59pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/4 "2020-02-07T16:59:56Z")

</div>

Yeah, I can’t explain that one 🙂 Perhaps there’s randomness in the initialization? I may just be making that up, though, I could be completely wrong here.

Can you rerun the Beta(70, 70) and see if it still fails?

---

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [February 25, 2020, 1:43pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/5 "2020-02-25T13:43:29Z")

</div>

I’ve restarted my computer, and I still have this weird behavior !

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

[…]

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

And if I change the beta distribution parameters to : (60,60)… it works fine :

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

I have no clue !! Except that it seems not to happen on a another computer (thank @tushar_chandra), which is a nice thing, but I still find this worrying for a futur use of pymc3 in production…)

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [February 27, 2020, 12:55pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/6 "2020-02-27T12:55:05Z")

</div>

I have not been able to reproduce. Have you tried using different random seeds when calling [`pm.sample`](https://docs.pymc.io/api/inference.html#module-pymc3.sampling)? Or set a different `start` and `init` combination?

---

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [February 28, 2020, 9:58am UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/7 "2020-02-28T09:58:56Z")

</div>

No seed where specified , so I guess the starting point is different for each run.  
(I run both version several time with the same weird behavior…)

---

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [March 5, 2020, 2:10pm UTC](https://discourse.pymc.io/t/cant-sample-a-beta-70-70-but-a-beta-60-60-works/4467/8 "2020-03-05T14:10:29Z")

</div>

I have the final answer for that bug !!

I had the latest numpy installed instead of numpy-1.14.3 (recommanded for pymc3).

uninstall numpy then re-install numpy-1.14.3, and this bug desappears…
