Skip to content

Commit 19fb50b

Browse files
Merge pull request #145 from Vaibhavdixit02/bayesupdate
Update and add timings bayes parameter estimation
2 parents fed07c2 + b5c560b commit 19fb50b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Cairo = "0.8, 1.0"
5555
CuArrays = "1.4, 2.0"
5656
DecFP = "0.4"
5757
Decimals = "0.4"
58-
DiffEqBayes = "2.1"
58+
DiffEqBayes = "2.8"
5959
DiffEqBiological = "4.0"
6060
DiffEqCallbacks = "2.9"
6161
DiffEqDevTools = "2.15"

tutorials/models/06-pendulum_bayesian_inference.jmd

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Bayesian Inference on a Pendulum using Turing.jl
2+
title: Bayesian Inference on a Pendulum using DiffEqBayes.jl
33
author: Vaibhav Dixit
44
---
55

66
### Set up simple pendulum problem
77

88
```julia
9-
using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots
9+
using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots, BenchmarkTools, TransformVariables
1010
```
1111

1212
Let's define our simple pendulum problem. Here our pendulum has a drag term `ω`
@@ -76,7 +76,7 @@ length of the pendulum L is probably around 3.0:
7676
priors = [Uniform(0.1,3.0), Normal(3.0,1.0)]
7777
```
7878

79-
Finally let's run the estimation routine from DiffEqBayes.jl using the Turing.jl backend
79+
Finally let's run the estimation routine from DiffEqBayes.jl with the Turing.jl backend to check if we indeed recover the parameters!
8080

8181
```julia
8282
bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;num_samples=10_000,
@@ -104,3 +104,20 @@ plot(bayesian_result, colordim = :parameter)
104104
Notice that after awhile these chains converge to a "fuzzy line", meaning it
105105
found the area with the most likelihood and then starts to sample around there,
106106
which builds a posterior distribution around the true mean.
107+
108+
DiffEqBayes.jl allows the choice of using Stan.jl, Turing.jl and DynamicHMC.jl for MCMC, you can also use ApproxBayes.jl for Approximate Bayesian computation algorithms.
109+
Let's compare the timings across the different MCMC backends. We'll stick with the default arguments and 10,000 samples in each since there is a lot of room for micro-optimization
110+
specific to each package and algorithm combinations, you might want to do your own experiments for specific problems to get better understanding of the performance.
111+
112+
```julia
113+
@btime bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;syms = [:omega,:L],num_samples=10_000)
114+
```
115+
116+
```julia
117+
@btime bayesian_result = stan_inference(prob1,t,data,priors;num_samples=10_000)
118+
```
119+
120+
```julia
121+
@btime bayesian_result = dynamichmc_inference(prob1,Tsit5(),t,data,priors,as(Vector, asℝ₊, 1))
122+
```
123+

0 commit comments

Comments
 (0)