Commit 46af850b authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Benchmark for ER models. Reorganization of benchmarks. Tests.

parent 7aa17e74
julia script.jl SIR|ER to run benchmarks
......@@ -4,14 +4,39 @@ import BenchmarkTools: mean
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
bound_time = 200.0
l_var = ["S", "I", "R"]
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
if ARGS[1] == "SIR"
bound_time = 200.0
l_var = ["S", "I", "R"]
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
model_col_buffer = SIR_col_buffer
model_row_buffer = SIR_row_buffer
elseif ARGS[1] == "ER"
l_var = ["E","S","ES","P"]
bound_time = 20.0
load_model("_bench_perf_test/ER_col_buffer")
ER_col_buffer.time_bound = bound_time
set_observed_var!(ER_col_buffer, l_var)
load_model("_bench_perf_test/ER_row_buffer")
ER_row_buffer.time_bound = bound_time
set_observed_var!(ER_row_buffer, l_var)
model_col_buffer = ER_col_buffer
model_row_buffer = ER_row_buffer
else
error("Unavailable model")
end
println("Col buffer:")
MarkovProcesses.load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
function access_trajectory_col(m::Model)
res = 0
n_sim = 100
......@@ -23,15 +48,12 @@ function access_trajectory_col(m::Model)
return res
end
# Bench
@timev access_trajectory_col(SIR_col_buffer)
b1_col = @benchmark access_trajectory_col($SIR_col_buffer)
@timev access_trajectory_col(model_col_buffer)
b1_col = @benchmark access_trajectory_col($model_col_buffer)
@show minimum(b1_col), mean(b1_col), maximum(b1_col)
println("Row buffer:")
MarkovProcesses.load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
function access_trajectory_row(m::Model)
res = 0
n_sim = 100
......@@ -43,7 +65,7 @@ function access_trajectory_row(m::Model)
return res
end
# Bench
@timev access_trajectory_row(SIR_row_buffer)
b1_row = @benchmark access_trajectory_row($SIR_row_buffer)
@timev access_trajectory_row(model_row_buffer)
b1_row = @benchmark access_trajectory_row($model_row_buffer)
@show minimum(b1_row), mean(b1_row), maximum(b1_row)
using BenchmarkTools
import BenchmarkTools: mean
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
l_var = ["S", "I", "R"]
bound_time = 200.0
nbr_sim = 10000
if ARGS[1] == "SIR"
l_var = ["S", "I", "R"]
bound_time = 200.0
load_model("_bench_perf_test/SIR_col")
SIR_col.time_bound = bound_time
set_observed_var!(SIR_col, l_var)
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
model_col = SIR_col
model_col_buffer = SIR_col_buffer
model_row_buffer = SIR_row_buffer
elseif ARGS[1] == "ER"
l_var = ["E","S","ES","P"]
bound_time = 20.0
nbr_sim = 10000
load_model("_bench_perf_test/SIR_col")
SIR_col.time_bound = bound_time
set_observed_var!(SIR_col, l_var)
load_model("_bench_perf_test/ER_col")
ER_col.time_bound = bound_time
set_observed_var!(ER_col, l_var)
load_model("_bench_perf_test/ER_col_buffer")
ER_col_buffer.time_bound = bound_time
set_observed_var!(ER_col_buffer, l_var)
load_model("_bench_perf_test/ER_row_buffer")
ER_row_buffer.time_bound = bound_time
set_observed_var!(ER_row_buffer, l_var)
model_col = ER_col
model_col_buffer = ER_col_buffer
model_row_buffer = ER_row_buffer
else
error("Unavailable model")
end
nbr_sim = 10000
println("Col")
b1_col = @benchmark for i = 1:$(nbr_sim) _simulate_col($SIR_col) end
@timev _simulate_col(SIR_col)
b1_col = @benchmark for i = 1:$(nbr_sim) _simulate_col($model_col) end
@timev _simulate_col(model_col)
@show minimum(b1_col), mean(b1_col), maximum(b1_col)
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
println("Col + buffer:")
b1_col_buffer = @benchmark for i = 1:$(nbr_sim) _simulate_col_buffer($SIR_col_buffer) end
@timev _simulate_col_buffer(SIR_col_buffer)
b1_col_buffer = @benchmark for i = 1:$(nbr_sim) _simulate_col_buffer($model_col_buffer) end
@timev _simulate_col_buffer(model_col_buffer)
@show minimum(b1_col_buffer), mean(b1_col_buffer), maximum(b1_col_buffer)
println("Col + buffer_10:")
b1_col_buffer_10 = @benchmark for i = 1:$(nbr_sim) _simulate_col_buffer($SIR_col_buffer; buffer_size = 10) end
@timev _simulate_col_buffer(SIR_col_buffer; buffer_size = 10)
b1_col_buffer_10 = @benchmark for i = 1:$(nbr_sim) _simulate_col_buffer($model_col_buffer; buffer_size = 10) end
@timev _simulate_col_buffer(model_col_buffer; buffer_size = 10)
@show minimum(b1_col_buffer_10), mean(b1_col_buffer_10), maximum(b1_col_buffer_10)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
println("Row + buffer:")
b1_row_buffer = @benchmark for i = 1:$(nbr_sim) _simulate_row_buffer($SIR_row_buffer) end
@timev _simulate_row_buffer(SIR_row_buffer)
b1_row_buffer = @benchmark for i = 1:$(nbr_sim) _simulate_row_buffer($model_row_buffer) end
@timev _simulate_row_buffer(model_row_buffer)
@show minimum(b1_row_buffer), mean(b1_row_buffer), maximum(b1_row_buffer)
println("Row + buffer_10:")
b1_row_buffer_10 = @benchmark for i = 1:$(nbr_sim) _simulate_row_buffer($SIR_row_buffer; buffer_size = 10) end
@timev _simulate_row_buffer(SIR_row_buffer; buffer_size = 10)
b1_row_buffer_10 = @benchmark for i = 1:$(nbr_sim) _simulate_row_buffer($model_row_buffer; buffer_size = 10) end
@timev _simulate_row_buffer(model_row_buffer; buffer_size = 10)
@show minimum(b1_row_buffer_10), mean(b1_row_buffer_10), maximum(b1_row_buffer_10)
println("Row + buffer_100:")
b1_row_buffer_100 = @benchmark for i = 1:$(nbr_sim) _simulate_row_buffer($model_row_buffer; buffer_size = 100) end
@timev _simulate_row_buffer(model_row_buffer; buffer_size = 100)
@show minimum(b1_row_buffer_100), mean(b1_row_buffer_100), maximum(b1_row_buffer_100)
......@@ -4,14 +4,39 @@ import BenchmarkTools: mean
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
l_var = ["S", "I", "R"]
bound_time = 200.0
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
if ARGS[1] == "SIR"
bound_time = 200.0
l_var = ["S", "I", "R"]
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
model_col_buffer = SIR_col_buffer
model_row_buffer = SIR_row_buffer
elseif ARGS[1] == "ER"
l_var = ["E","S","ES","P"]
bound_time = 20.0
load_model("_bench_perf_test/ER_col_buffer")
ER_col_buffer.time_bound = bound_time
set_observed_var!(ER_col_buffer, l_var)
load_model("_bench_perf_test/ER_row_buffer")
ER_row_buffer.time_bound = bound_time
set_observed_var!(ER_row_buffer, l_var)
model_col_buffer = ER_col_buffer
model_row_buffer = ER_row_buffer
else
error("Unavailable model")
end
println("Col buffer:")
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
function random_trajectory_value_col(m::ContinuousTimeModel)
σ = _simulate_col_buffer(m)
n_states = get_states_number(σ)
......@@ -24,15 +49,12 @@ function random_trajectory_value_col(m::ContinuousTimeModel)
return res
end
# Bench
@timev random_trajectory_value_col(SIR_col_buffer)
b1_col_buffer = @benchmark random_trajectory_value_col($SIR_col_buffer)
@timev random_trajectory_value_col(model_col_buffer)
b1_col_buffer = @benchmark random_trajectory_value_col($model_col_buffer)
@show minimum(b1_col_buffer), mean(b1_col_buffer), maximum(b1_col_buffer)
println("Row buffer:")
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
function random_trajectory_value_row(m::ContinuousTimeModel)
σ = _simulate_row_buffer(m)
n_states = get_states_number(σ)
......@@ -45,7 +67,7 @@ function random_trajectory_value_row(m::ContinuousTimeModel)
return res
end
# Bench
@timev random_trajectory_value_row(SIR_row_buffer)
b1_row_buffer = @benchmark random_trajectory_value_row($SIR_row_buffer)
@timev random_trajectory_value_row(model_row_buffer)
b1_row_buffer = @benchmark random_trajectory_value_row($model_row_buffer)
@show minimum(b1_row_buffer), mean(b1_row_buffer), maximum(b1_row_buffer)
......@@ -4,14 +4,39 @@ import BenchmarkTools: mean
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
bound_time = 200.0
l_var = ["S", "I", "R"]
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
if ARGS[1] == "SIR"
bound_time = 200.0
l_var = ["S", "I", "R"]
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
model_col_buffer = SIR_col_buffer
model_row_buffer = SIR_row_buffer
elseif ARGS[1] == "ER"
l_var = ["E","S","ES","P"]
bound_time = 20.0
load_model("_bench_perf_test/ER_col_buffer")
ER_col_buffer.time_bound = bound_time
set_observed_var!(ER_col_buffer, l_var)
load_model("_bench_perf_test/ER_row_buffer")
ER_row_buffer.time_bound = bound_time
set_observed_var!(ER_row_buffer, l_var)
model_col_buffer = ER_col_buffer
model_row_buffer = ER_row_buffer
else
error("Unavailable model")
end
println("Col buffer:")
MarkovProcesses.load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
function read_trajectory_col(m::Model)
res = 0
σ = _simulate_col_buffer(m)
......@@ -25,15 +50,12 @@ function read_trajectory_col(m::Model)
return res
end
# Bench
@timev read_trajectory_col(SIR_col_buffer)
b1_col = @benchmark read_trajectory_col($SIR_col_buffer)
@timev read_trajectory_col(model_col_buffer)
b1_col = @benchmark read_trajectory_col($model_col_buffer)
@show minimum(b1_col), mean(b1_col), maximum(b1_col)
println("Row buffer:")
MarkovProcesses.load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
function read_trajectory_row(m::Model)
res = 0
σ = _simulate_row_buffer(m)
......@@ -47,7 +69,7 @@ function read_trajectory_row(m::Model)
return res
end
# Bench
@timev read_trajectory_row(SIR_row_buffer)
b1_row = @benchmark read_trajectory_row($SIR_row_buffer)
@timev read_trajectory_row(model_row_buffer)
b1_row = @benchmark read_trajectory_row($model_row_buffer)
@show minimum(b1_row), mean(b1_row), maximum(b1_row)
using BenchmarkTools
import BenchmarkTools: mean
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
if ARGS[1] == "SIR"
l_var = ["S", "I", "R"]
bound_time = 200.0
load_model("_bench_perf_test/SIR_col")
SIR_col.time_bound = bound_time
set_observed_var!(SIR_col, l_var)
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
model_col = SIR_col
model_col_buffer = SIR_col_buffer
model_row_buffer = SIR_row_buffer
elseif ARGS[1] == "ER"
l_var = ["E","S","ES","P"]
bound_time = 20.0
nbr_sim = 10000
load_model("_bench_perf_test/ER_col")
ER_col.time_bound = bound_time
set_observed_var!(ER_col, l_var)
load_model("_bench_perf_test/ER_col_buffer")
ER_col_buffer.time_bound = bound_time
set_observed_var!(ER_col_buffer, l_var)
load_model("_bench_perf_test/ER_row_buffer")
ER_row_buffer.time_bound = bound_time
set_observed_var!(ER_row_buffer, l_var)
model_col = ER_col
model_col_buffer = ER_col_buffer
model_row_buffer = ER_row_buffer
else
error("Unavailable model")
end
nbr_sim = 10000
println("Col")
b1_col = @benchmark _simulate_col($model_col)
@timev _simulate_col(model_col)
@show minimum(b1_col), mean(b1_col), maximum(b1_col)
println("Col + buffer:")
b1_col_buffer = @benchmark _simulate_col_buffer($model_col_buffer)
@timev _simulate_col_buffer(model_col_buffer)
@show minimum(b1_col_buffer), mean(b1_col_buffer), maximum(b1_col_buffer)
println("Col + buffer_10:")
b1_col_buffer_10 = @benchmark _simulate_col_buffer($model_col_buffer; buffer_size = 10)
@timev _simulate_col_buffer(model_col_buffer; buffer_size = 10)
@show minimum(b1_col_buffer_10), mean(b1_col_buffer_10), maximum(b1_col_buffer_10)
println("Row + buffer:")
b1_row_buffer = @benchmark _simulate_row_buffer($model_row_buffer)
@timev _simulate_row_buffer(model_row_buffer)
@show minimum(b1_row_buffer), mean(b1_row_buffer), maximum(b1_row_buffer)
println("Row + buffer_10:")
b1_row_buffer_10 = @benchmark _simulate_row_buffer($model_row_buffer; buffer_size = 10)
@timev _simulate_row_buffer(model_row_buffer; buffer_size = 10)
@show minimum(b1_row_buffer_10), mean(b1_row_buffer_10), maximum(b1_row_buffer_10)
using BenchmarkTools
import BenchmarkTools: mean
using MarkovProcesses
include(get_module_path() * "/core/_tests_simulate.jl")
BenchmarkTools.DEFAULT_PARAMETERS.samples = 20000
l_var = ["S", "I", "R"]
bound_time = 200.0
load_model("_bench_perf_test/SIR_col")
SIR_col.time_bound = bound_time
set_observed_var!(SIR_col, l_var)
println("Col")
b1_col = @benchmark _simulate_col($SIR_col)
@timev _simulate_col(SIR_col)
@show minimum(b1_col), mean(b1_col), maximum(b1_col)
load_model("_bench_perf_test/SIR_col_buffer")
SIR_col_buffer.time_bound = bound_time
set_observed_var!(SIR_col_buffer, l_var)
println("Col + buffer:")
b1_col_buffer = @benchmark _simulate_col_buffer($SIR_col_buffer)
@timev _simulate_col_buffer(SIR_col_buffer)
@show minimum(b1_col_buffer), mean(b1_col_buffer), maximum(b1_col_buffer)
println("Col + buffer_10:")
b1_col_buffer_10 = @benchmark _simulate_col_buffer($SIR_col_buffer; buffer_size = 10)
@timev _simulate_col_buffer(SIR_col_buffer; buffer_size = 10)
@show minimum(b1_col_buffer_10), mean(b1_col_buffer_10), maximum(b1_col_buffer_10)
load_model("_bench_perf_test/SIR_row_buffer")
SIR_row_buffer.time_bound = bound_time
set_observed_var!(SIR_row_buffer, l_var)
println("Row + buffer:")
b1_row_buffer = @benchmark _simulate_row_buffer($SIR_row_buffer)
@timev _simulate_row_buffer(SIR_row_buffer)
@show minimum(b1_row_buffer), mean(b1_row_buffer), maximum(b1_row_buffer)
println("Row + buffer_10:")
b1_row_buffer_10 = @benchmark _simulate_row_buffer($SIR_row_buffer; buffer_size = 10)
@timev _simulate_row_buffer(SIR_row_buffer; buffer_size = 10)
@show minimum(b1_row_buffer_10), mean(b1_row_buffer_10), maximum(b1_row_buffer_10)
import StaticArrays: SVector, SMatrix, @SMatrix
d=4
k=3
dict_var = Dict("E" => 1, "S" => 2, "ES" => 3, "P" => 4)
dict_p = Dict("k1" => 1, "k2" => 2, "k3" => 3)
l_tr = ["R1","R2","R3"]
p = [1.0, 1.0, 1.0]
x0 = [100, 100, 0, 0]
t0 = 0.0
function ER_col_f!(xnplus1::Vector{Int}, tnplus1::Vector{Float64}, tr::Vector{String},
xn::AbstractVector{Int}, tn::Float64, p::Vector{Float64})
a1 = p[1] * xn[1] * xn[2]
a2 = p[2] * xn[3]
a3 = p[3] * xn[3]
l_a = SVector(a1, a2, a3)
asum = sum(l_a)
l_nu = @SMatrix [-1 1 1;
-1 1 0;
1 -1 -1;
0 0 1]
u1, u2 = rand(), rand()
tau = - log(u1) / asum
b_inf = 0.0
b_sup = a1
reaction = 0
for i = 1:3
if b_inf < asum*u2 < b_sup
reaction = i
break
end
b_inf += l_a[i]
b_sup += l_a[i+1]
end
nu = @view l_nu[:,reaction]
for i = 1:4
xnplus1[i] = xn[i]+nu[i]
end
tnplus1[1] = tn + tau
tr[1] = "R$(reaction)"
end
is_absorbing_ER_col(p::Vector{Float64},xn::AbstractVector{Int}) =
(p[1]*xn[1]*xn[2] + (p[2]+p[3])*xn[3]) === 0.0
g = ["P"]
ER_col = CTMC(d,k,dict_var,dict_p,l_tr,p,x0,t0,ER_col_f!,is_absorbing_ER_col; g=g)
export ER_col
import StaticArrays: SVector, SMatrix, @SMatrix
d=4
k=3
dict_var = Dict("E" => 1, "S" => 2, "ES" => 3, "P" => 4)
dict_p = Dict("k1" => 1, "k2" => 2, "k3" => 3)
l_tr = ["R1","R2","R3"]
p = [1.0, 1.0, 1.0]
x0 = [100, 100, 0, 0]
t0 = 0.0
function ER_col_buffer_f!(mat_x::Matrix{Int}, l_t::Vector{Float64}, l_tr::Vector{String}, idx::Int,
xn::AbstractVector{Int}, tn::Float64, p::Vector{Float64})
a1 = p[1] * xn[1] * xn[2]
a2 = p[2] * xn[3]
a3 = p[3] * xn[3]
l_a = SVector(a1, a2, a3)
asum = sum(l_a)
l_nu = @SMatrix [-1 1 1;
-1 1 0;
1 -1 -1;
0 0 1]
u1, u2 = rand(), rand()
tau = - log(u1) / asum
b_inf = 0.0
b_sup = a1
reaction = 0
for i = 1:3
if b_inf < asum*u2 < b_sup
reaction = i
break
end
b_inf += l_a[i]
b_sup += l_a[i+1]
end
nu = @view l_nu[:,reaction] # macro for avoiding a copy
for i = 1:4
mat_x[i,idx] = xn[i]+nu[i]
end
l_t[idx] = tn + tau
l_tr[idx] = "R$(reaction)"
end
is_absorbing_ER_col_buffer(p::Vector{Float64},xn::AbstractVector{Int}) =
(p[1]*xn[1]*xn[2] + (p[2]+p[3])*xn[3]) === 0.0
g = ["P"]
ER_col_buffer = CTMC(d,k,dict_var,dict_p,l_tr,p,x0,t0,ER_col_buffer_f!,is_absorbing_ER_col_buffer; g=g)
export ER_col_buffer
import StaticArrays: SVector, SMatrix, @SMatrix
d=4
k=3
dict_var = Dict("E" => 1, "S" => 2, "ES" => 3, "P" => 4)
dict_p = Dict("k1" => 1, "k2" => 2, "k3" => 3)
l_tr = ["R1","R2","R3"]
p = [1.0, 1.0, 1.0]
x0 = [100, 100, 0, 0]
t0 = 0.0
function ER_row_buffer_f!(mat_x::Matrix{Int}, l_t::Vector{Float64}, l_tr::Vector{String}, idx::Int,
xn::AbstractVector{Int}, tn::Float64, p::Vector{Float64})
a1 = p[1] * xn[1] * xn[2]
a2 = p[2] * xn[3]
a3 = p[3] * xn[3]
l_a = SVector(a1, a2, a3)
asum = sum(l_a)
l_nu = @SMatrix [-1 1 1;
-1 1 0;
1 -1 -1;
0 0 1]
u1, u2 = rand(), rand()
tau = - log(u1) / asum
b_inf = 0.0
b_sup = a1
reaction = 0
for i = 1:3
if b_inf < asum*u2 < b_sup
reaction = i
break
end
b_inf += l_a[i]
b_sup += l_a[i+1]
end