Skip to content

Commit da77eab

Browse files
Automatic build\nPublished by build of: SciML/SciMLBenchmarks.jl@3acd389
1 parent ac6eeae commit da77eab

12 files changed

Lines changed: 1996 additions & 1898 deletions

markdown/BayesianInference/DiffEqBayesFitzHughNagumo.md

Lines changed: 557 additions & 535 deletions
Large diffs are not rendered by default.

markdown/BayesianInference/DiffEqBayesLorenz.md

Lines changed: 679 additions & 649 deletions
Large diffs are not rendered by default.

markdown/BayesianInference/DiffEqBayesLotkaVolterra.md

Lines changed: 674 additions & 649 deletions
Large diffs are not rendered by default.
-216 Bytes
Loading
-158 Bytes
Loading
-17 Bytes
Loading
137 Bytes
Loading
-905 Bytes
Loading
-355 Bytes
Loading

script/BayesianInference/DiffEqBayesFitzHughNagumo.jl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,61 @@
22
using DiffEqBayes, BenchmarkTools
33

44

5-
using OrdinaryDiffEq, RecursiveArrayTools, Distributions, ParameterizedFunctions, StanSample, DynamicHMC
5+
using OrdinaryDiffEq, RecursiveArrayTools, Distributions, ParameterizedFunctions,
6+
StanSample, DynamicHMC
67
using Plots, StaticArrays, Turing, LinearAlgebra
78

89

9-
gr(fmt=:png)
10+
gr(fmt = :png)
1011

1112

1213
fitz = @ode_def FitzhughNagumo begin
13-
dv = v - 0.33*v^3 -w + l
14-
dw = τinv*(v + a - b*w)
14+
dv = v - 0.33*v^3 - w + l
15+
dw = τinv*(v + a - b*w)
1516
end a b τinv l
1617

1718

18-
prob_ode_fitzhughnagumo = ODEProblem(fitz, [1.0,1.0], (0.0,10.0), [0.7,0.8,1/12.5,0.5])
19+
prob_ode_fitzhughnagumo = ODEProblem(fitz, [1.0, 1.0], (0.0, 10.0), [0.7, 0.8, 1/12.5, 0.5])
1920
sol = solve(prob_ode_fitzhughnagumo, Tsit5())
2021

2122

22-
sprob_ode_fitzhughnagumo = ODEProblem{false,SciMLBase.FullSpecialize}(fitz, SA[1.0,1.0], (0.0,10.0), SA[0.7,0.8,1/12.5,0.5])
23+
sprob_ode_fitzhughnagumo = ODEProblem{false, SciMLBase.FullSpecialize}(
24+
fitz, SA[1.0, 1.0], (0.0, 10.0), SA[0.7, 0.8, 1 / 12.5, 0.5])
2325
sol = solve(sprob_ode_fitzhughnagumo, Tsit5())
2426

2527

26-
t = collect(range(1,stop=10,length=10))
28+
t = collect(range(1, stop = 10, length = 10))
2729
sig = 0.20
2830
data = convert(Array, VectorOfArray([(sol(t[i]) + sig*randn(2)) for i in 1:length(t)]))
2931

3032

31-
scatter(t, data[1,:])
32-
scatter!(t, data[2,:])
33+
scatter(t, data[1, :])
34+
scatter!(t, data[2, :])
3335
plot!(sol)
3436

3537

36-
priors = [truncated(Normal(1.0,0.5),0,1.5), truncated(Normal(1.0,0.5),0,1.5), truncated(Normal(0.0,0.5),0.0,0.5), truncated(Normal(0.5,0.5),0,1)]
38+
priors = [truncated(Normal(1.0, 0.5), 0, 1.5), truncated(Normal(1.0, 0.5), 0, 1.5),
39+
truncated(Normal(0.0, 0.5), 0.0, 0.5), truncated(Normal(0.5, 0.5), 0, 1)]
3740

3841

39-
@time bayesian_result_stan = stan_inference(prob_ode_fitzhughnagumo,t,data,priors; delta = 0.65, num_samples = 10_000, print_summary=false, vars=(DiffEqBayes.StanODEData(), InverseGamma(2, 3)))
42+
@time bayesian_result_stan = stan_inference(
43+
prob_ode_fitzhughnagumo, t, data, priors; delta = 0.65, num_samples = 10_000,
44+
print_summary = false, vars = (DiffEqBayes.StanODEData(), InverseGamma(2, 3)))
4045

4146

4247
@model function fitlv(data, prob)
4348

4449
# Prior distributions.
4550
σ ~ InverseGamma(2, 3)
46-
a ~ truncated(Normal(1.0,0.5),0,1.5)
47-
b ~ truncated(Normal(1.0,0.5),0,1.5)
48-
τinv ~ truncated(Normal(0.0,0.5),0.0,0.5)
49-
l ~ truncated(Normal(0.5,0.5),0,1)
51+
a ~ truncated(Normal(1.0, 0.5), 0, 1.5)
52+
b ~ truncated(Normal(1.0, 0.5), 0, 1.5)
53+
τinv ~ truncated(Normal(0.0, 0.5), 0.0, 0.5)
54+
l ~ truncated(Normal(0.5, 0.5), 0, 1)
5055

5156
# Simulate Lotka-Volterra model.
52-
p = SA[a,b,τinv,l]
57+
p = SA[a, b, τinv, l]
5358
_prob = remake(prob, p = p)
54-
predicted = solve(_prob, Tsit5(); saveat=t)
59+
predicted = solve(_prob, Tsit5(); saveat = t)
5560

5661
# Observations.
5762
for i in 1:length(predicted)
@@ -63,12 +68,13 @@ end
6368

6469
model = fitlv(data, sprob_ode_fitzhughnagumo)
6570

66-
@time chain = sample(model, Turing.NUTS(0.65), 10000; progress=false)
71+
@time chain = sample(model, Turing.NUTS(0.65), 10000; progress = false)
6772

6873

69-
@time bayesian_result_turing = turing_inference(prob_ode_fitzhughnagumo,Tsit5(),t,data,priors;num_samples = 10_000)
74+
@time bayesian_result_turing = turing_inference(
75+
prob_ode_fitzhughnagumo, Tsit5(), t, data, priors; num_samples = 10_000)
7076

7177

7278
using SciMLBenchmarks
73-
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
79+
SciMLBenchmarks.bench_footer(WEAVE_ARGS[:folder], WEAVE_ARGS[:file])
7480

0 commit comments

Comments
 (0)