# Bayesian Neural Network

**URL:** https://discourse.julialang.org/t/bayesian-neural-network/79363
**Category:** New to Julia
**Tags:** question, package
**Created:** [April 12, 2022, 3:54am UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363 "2022-04-12T03:54:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 12, 2022, 3:54am UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/1 "2022-04-12T03:54:47Z")

</div>

Hi, I am in the early stage of learning to code Neural Networks using Flux.  
However I thought to use Bayesian Neural Network (BNN), Both for the sake of overcoming the problem of overfitting and need a way to explain model uncertainity.

I have looked for Julia packages used for BNN, and found just two resources to start with:

1. [Bayesian Neural Networks · ADCME](https://docs.juliahub.com/ADCME/b8Ld2/0.5.5/bnn/)
2. [Bayesian Neural Networks](https://turing.ml/dev/tutorials/03-bayesian-neural-network/)

Are these the only two resources available?  
Is there a Flux version of these?  
What are the differences between these two?

Thanks  
Aminath

---

<div class="post-metadata">

### Author: ![Rasmus\_Hoier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasmus_hoier/32/24036_2.png) [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)
#### Post date: [April 12, 2022, 1:42pm UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/2 "2022-04-12T13:42:09Z")

</div>

I don’t think you need a special Flux version. One of the nice things with Julia is that packages generally work well together. The second link you posted shows how to use Flux in conjunction with Turing.

I think I would start with Turing + Flux since they are both very actively maintained. whereas [ADCME’s](https://github.com/kailaix/ADCME.jl) last release is from May 2021. This is not my field, so I don’t know what the main difference between them is.

By the way your first link points to ADCME v0.55 instead of 0.73 and your second link points to Turings dev docs rather than the stable release docs. You can select the version of the documentation from dropdown menus on both pages.

---

<div class="post-metadata">

### Author: ![liamfdoherty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liamfdoherty/32/24516_2.png) [@liamfdoherty](https://discourse.julialang.org/u/liamfdoherty)
#### Post date: [April 12, 2022, 5:06pm UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/3 "2022-04-12T17:06:02Z")

</div>

ADCME is a package which is focused largely on providing automatic differentiation (AD) routines, whereas Turing is a general Probabilistic Programming Language (PPL) that allows you write models that takes priors + data and produce posterior distributions (i.e., in the case of BNNs, take a randomly initialized set of prior parameter distributions and transform them into posterior distributions through neural network training). Flux uses a different backend for AD called [Zygote.jl](https://github.com/FluxML/Zygote.jl), which is just a different AD library to perform backpropagation on your neural net.

I agree that the best way to start is with a combination of Flux and Turing (notice that the Turing tutorial explicitly uses Flux anyway!). These are general and actively maintained libraries that also have the ability to extend easily into other projects you may come across.

TL;DR: ADCME.jl is an AD library first, and Flux already has an AD backend that you don’t need to explicitly worry about when writing Flux code. Turing.jl allows you to turn “standard” networks into Bayesian ones. The Turing.jl tutorial you found is the way to start.

---

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 12, 2022, 9:00pm UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/4 "2022-04-12T21:00:12Z")

</div>

Thank a lot. That clarifies a lot. One more question. I had a bit of experience of using STAN for Bayesian models. It uses NUTS as one of the algorithms. Does Turing.jl also allows for NUTS. Reading through some example codes, I could see HMC (although NUTS is a special version of it). Just curious to know the difference between STAN and Turing.  
Thanks  
Aminath

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [April 12, 2022, 9:24pm UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/5 "2022-04-12T21:24:40Z")

</div>

> [@Aminath\_Shausan](#):
>
> Does Turing.jl also allows for NUTS.

[https://turing.ml/dev/docs/library/#Turing.Inference.NUTS](https://turing.ml/dev/docs/library/#Turing.Inference.NUTS)

---

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 13, 2022, 11:17pm UTC](https://discourse.julialang.org/t/bayesian-neural-network/79363/6 "2022-04-13T23:17:38Z")

</div>

Thanks @dilumaluthge
