# Bayesian Neural Net with Beta distribution

**URL:** <https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136>\
**Category:** Questions\
**Created:** [June 29, 2017, 2:25pm UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136 "2017-06-29T14:25:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pflip](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pflip](https://discourse.pymc.io/u/Pflip)\
**Post date:** [June 29, 2017, 2:25pm UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/1 "2017-06-29T14:25:41Z")

</div>

Hello there,

I’ve got a question regarding Bayesian Neural Nets which are described [here](http://pymc-devs.github.io/pymc3/notebooks/bayesian_neural_network_opvi-advi.html)

Say I want the distribution for the weights to be a beta distribution instead of a normal distribution for whatever reason.

Then I can do variational inference and sample from the approximation, but my posterior predictive check fails with an error message:

> raise MissingInputError(“Undeclared input”, variable=variable)  
> theano.gof.fg.MissingInputError: Undeclared input

The Error can be traced back to the draw\_values function in /distributions/distribution.py, where the dict “named\_nodes” has extra values that aren’t there for normal distributions like ‘weights2\_log\_\_’ or which are named differently. I think the problem is, that those values can’t be found in the “points” dict at this moment.

My question is therefore: Can I somehow circumvent this problem respectively is there no solution because of the different nature of the distributions? If so, why are they so different?

Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![aseyboldt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aseyboldt/32/5795_2.png) [@aseyboldt](https://discourse.pymc.io/u/aseyboldt)\
**Post date:** [June 29, 2017, 2:47pm UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/2 "2017-06-29T14:47:34Z")

</div>

It is possible that this is a bug in how `draw_values` handles transformed distributions. We made some changes to that pretty recently, and this might have introduced a new issue. Could you post some code that fails in this way, plus the version of theano and pymc3 you are using? That would make debugging much easier.

---

<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:** [June 29, 2017, 4:13pm UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/3 "2017-06-29T16:13:32Z")

</div>

Yeah there is no random method for `TransformedDistribution`. We should probability add that.

---

<div class="post-metadata">

**Author:** ![Pflip](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pflip](https://discourse.pymc.io/u/Pflip)\
**Post date:** [June 30, 2017, 9:32am UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/4 "2017-06-30T09:32:44Z")

</div>

Thanks for your replies!

Unfortunately I cannot post any code at the moment for debugging until monday, but the error should be reproducable by using the linked example and replacing the Normal distributions with Beta distributions.  
I’m using the latest Theano and Pymc3 Version, since I recently upgraded the packages.

---

<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:** [June 30, 2017, 9:43am UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/5 "2017-06-30T09:43:46Z")

</div>

Oh I see, the reason is that the sample from the approximation does not include the transformed variable, you should be able to make it work by replacing the

```python
trace = approx.sample(draws=5000)

```

with

```python
trace = approx.sample(draws=5000, include_transformed=True)

```

---

<div class="post-metadata">

**Author:** ![Pflip](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pflip](https://discourse.pymc.io/u/Pflip)\
**Post date:** [June 30, 2017, 9:49am UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/6 "2017-06-30T09:49:34Z")

</div>

That seems very promising to me, since the transformed variables aren’t present in the points dict.  
I will give it a try as soon as I can and tell you about the results.

Thank you very much for your help!

---

<div class="post-metadata">

**Author:** ![Pflip](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pflip](https://discourse.pymc.io/u/Pflip)\
**Post date:** [July 3, 2017, 11:22am UTC](https://discourse.pymc.io/t/bayesian-neural-net-with-beta-distribution/136/7 "2017-07-03T11:22:31Z")

</div>

That’s exactly what I needed.

Thanks again!
