Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 230 additions & 32 deletions html/models/06-pendulum_bayesian_inference.html

Large diffs are not rendered by default.

356 changes: 356 additions & 0 deletions html/models/jl_yGNNUY/06-pendulum_bayesian_inference_3_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
384 changes: 384 additions & 0 deletions html/models/jl_yGNNUY/06-pendulum_bayesian_inference_5_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,472 changes: 3,472 additions & 0 deletions html/models/jl_yGNNUY/06-pendulum_bayesian_inference_8_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,011 changes: 3,011 additions & 0 deletions html/models/jl_yGNNUY/06-pendulum_bayesian_inference_9_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
415 changes: 415 additions & 0 deletions markdown/models/06-pendulum_bayesian_inference.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 34 additions & 7 deletions notebook/models/06-pendulum_bayesian_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{
"cell_type": "markdown",
"source": [
"# Bayesian Inference on a Pendulum using Turing.jl\n### Vaibhav Dixit\n\n### Set up simple pendulum problem"
"# Bayesian Inference on a Pendulum using DiffEqBayes.jl\n### Vaibhav Dixit\n\n### Set up simple pendulum problem"
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots"
"using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots, BenchmarkTools, TransformVariables, CmdStan, DynamicHMC"
],
"metadata": {},
"execution_count": null
Expand Down Expand Up @@ -99,7 +99,7 @@
{
"cell_type": "markdown",
"source": [
"Finally let's run the estimation routine from DiffEqBayes.jl using the Turing.jl backend"
"Finally let's run the estimation routine from DiffEqBayes.jl with the Turing.jl backend to check if we indeed recover the parameters!"
],
"metadata": {}
},
Expand Down Expand Up @@ -147,9 +147,36 @@
{
"cell_type": "markdown",
"source": [
"Notice that after awhile these chains converge to a \"fuzzy line\", meaning it\nfound the area with the most likelihood and then starts to sample around there,\nwhich builds a posterior distribution around the true mean."
"Notice that after awhile these chains converge to a \"fuzzy line\", meaning it\nfound the area with the most likelihood and then starts to sample around there,\nwhich builds a posterior distribution around the true mean.\n\nDiffEqBayes.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.\nLet'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\nspecific to each package and algorithm combinations, you might want to do your own experiments for specific problems to get better understanding of the performance."
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"@btime bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;syms = [:omega,:L],num_samples=10_000)"
],
"metadata": {},
"execution_count": null
},
{
"outputs": [],
"cell_type": "code",
"source": [
"@btime bayesian_result = stan_inference(prob1,t,data,priors;num_samples=10_000,printsummary=false)"
],
"metadata": {},
"execution_count": null
},
{
"outputs": [],
"cell_type": "code",
"source": [
"@btime bayesian_result = dynamichmc_inference(prob1,Tsit5(),t,data,priors;num_samples = 10_000)"
],
"metadata": {},
"execution_count": null
}
],
"nbformat_minor": 2,
Expand All @@ -158,11 +185,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.1.1"
"version": "1.4.0"
},
"kernelspec": {
"name": "julia-1.1",
"display_name": "Julia 1.1.1",
"name": "julia-1.4",
"display_name": "Julia 1.4.0",
"language": "julia"
}
},
Expand Down
11 changes: 10 additions & 1 deletion script/models/06-pendulum_bayesian_inference.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots
using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots, BenchmarkTools, TransformVariables, CmdStan, DynamicHMC


function pendulum(du,u,p,t)
Expand Down Expand Up @@ -38,3 +38,12 @@ plot(bayesian_result)

plot(bayesian_result, colordim = :parameter)


@btime bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;syms = [:omega,:L],num_samples=10_000)


@btime bayesian_result = stan_inference(prob1,t,data,priors;num_samples=10_000,printsummary=false)


@btime bayesian_result = dynamichmc_inference(prob1,Tsit5(),t,data,priors;num_samples = 10_000)

13 changes: 6 additions & 7 deletions tutorials/models/06-pendulum_bayesian_inference.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author: Vaibhav Dixit
### Set up simple pendulum problem

```julia
using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots, BenchmarkTools, TransformVariables
using DiffEqBayes, OrdinaryDiffEq, RecursiveArrayTools, Distributions, Plots, StatsPlots, BenchmarkTools, TransformVariables, CmdStan, DynamicHMC
```

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

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

```julia
bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;num_samples=10_000,
Expand Down Expand Up @@ -105,19 +105,18 @@ Notice that after awhile these chains converge to a "fuzzy line", meaning it
found the area with the most likelihood and then starts to sample around there,
which builds a posterior distribution around the true mean.

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

```julia
@btime bayesian_result = turing_inference(prob1,Tsit5(),t,data,priors;syms = [:omega,:L],num_samples=10_000)
```

```julia
@btime bayesian_result = stan_inference(prob1,t,data,priors;num_samples=10_000)
@btime bayesian_result = stan_inference(prob1,t,data,priors;num_samples=10_000,printsummary=false)
```

```julia
@btime bayesian_result = dynamichmc_inference(prob1,Tsit5(),t,data,priors,as(Vector, asℝ₊, 1))
@btime bayesian_result = dynamichmc_inference(prob1,Tsit5(),t,data,priors;num_samples = 10_000)
```