# About Bayesian Neural Network

**URL:** https://discourse.pymc.io/t/about-bayesian-neural-network/852
**Category:** Questions
**Created:** [February 12, 2018, 2:13am UTC](https://discourse.pymc.io/t/about-bayesian-neural-network/852 "2018-02-12T02:13:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![square](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@square](https://discourse.pymc.io/u/square)
#### Post date: [February 12, 2018, 2:13am UTC](https://discourse.pymc.io/t/about-bayesian-neural-network/852/1 "2018-02-12T02:13:17Z")

</div>

I am trying to construct a Bayesian neural network model for regression problem by referring to the example in the doc [http://docs.pymc.io/notebooks/bayesian\_neural\_network\_advi.html](http://docs.pymc.io/notebooks/bayesian_neural_network_advi.html)

The model looks like this

 ![Q20170211_1](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/1X/079c89b7cd11b2f6280b2a9b1eaf697335154a2b.png)  
sampling result  
 ![Q_20180211_2](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/1X/f3d469eb81dba9270302ef66998ccb8b858df45f.png)

Then I try to do something similar to the doc example, I guess there are two ways to write the function  
The first way shows

 ![Q_20180211_3](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/1X/e4db1e72a0b55186a3a4a3947014f89611ea8d7c.png)  
Then I am a bit confused with the part, how to construct the part of prediction with the posterior…  
Thanks a lot in advance.

---

<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: [February 12, 2018, 6:22am UTC](https://discourse.pymc.io/t/about-bayesian-neural-network/852/2 "2018-02-12T06:22:31Z")

</div>

I think you should do `out = pm.MvNormal('out', mu=regression, cov=R, observed=Y_train)`, there is no observed in your model and training/prediction has no effect.

In general, `sample_ppc` output the ppc of observed RVs by default.  
In you code above, because you did not associate an observed to `out`, the model is sampling from the prior, and the posterior prediction has no output. You can specify a variable to sample from: `ppc = pm.sample_ppc(trace, samples=500, vars=neural_network.out)`  
There is a subtle thing here: I am doing `vars=neural_network.out` because the way you write down the model I am not sure RV `out` is directly available, otherwise you can just do `vars=out`. But if you associate an observed then your code should work without specifying `vars=`.
