About Bayesian Neural Network


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

The model looks like this

sampling result

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

Then I am a bit confused with the part, how to construct the part of prediction with the posterior…
Thanks a lot in advance.


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=.