Skip to content
Snippets Groups Projects
Commit 3e6718b7 authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Fix in simulation of macro generated models. Small changes with variables...

Fix in simulation of macro generated models. Small changes with variables types of the pkg. Small change in test of macro models.
parent 80eb2e36
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,8 @@ export Distribution, Product, Uniform, Normal ...@@ -13,7 +13,8 @@ export Distribution, Product, Uniform, Normal
# Common types and constructors # Common types and constructors
export Observations, AbstractTrajectory, Trajectory, SynchronizedTrajectory export Observations, AbstractTrajectory, Trajectory, SynchronizedTrajectory
export Model, ContinuousTimeModel, SynchronizedModel, ParametricModel export Model, ContinuousTimeModel, SynchronizedModel, ParametricModel
export LHA, StateLHA, Edge export VariableModel, ParameterModel, Transition
export LHA, StateLHA, Edge, Location, VariableAutomaton
# Trajectory related methods # Trajectory related methods
export +, -, δ, dist_lp export +, -, δ, dist_lp
......
...@@ -5,11 +5,11 @@ import Distributions: Distribution, Univariate, Continuous, UnivariateDistributi ...@@ -5,11 +5,11 @@ import Distributions: Distribution, Univariate, Continuous, UnivariateDistributi
abstract type Model end abstract type Model end
abstract type AbstractTrajectory end abstract type AbstractTrajectory end
const VariableModel = Symbol
const ParameterModel = Symbol
const Transition = Union{Symbol,Nothing} const Transition = Union{Symbol,Nothing}
const Location = Symbol const Location = Symbol
const VariableAutomaton = Symbol const VariableAutomaton = Symbol
const VariableModel = Symbol
const ParameterModel = Symbol
mutable struct ContinuousTimeModel <: Model mutable struct ContinuousTimeModel <: Model
name::String name::String
......
...@@ -341,13 +341,20 @@ end ...@@ -341,13 +341,20 @@ end
Distribute over workers the computation of the mean value Distribute over workers the computation of the mean value
of a LHA over `nbr_sim` simulations of the model. of a LHA over `nbr_sim` simulations of the model.
""" """
function distribute_mean_value_lha(sm::SynchronizedModel, sym_var::Union{VariableAutomaton,Vector{VariableAutomaton}}, nbr_sim::Int) function distribute_mean_value_lha(sm::SynchronizedModel, sym_var::VariableAutomaton, nbr_sim::Int)
sum_val = @distributed (+) for i = 1:nbr_sim sum_val = @distributed (+) for i = 1:nbr_sim
volatile_simulate(sm)[sym_var] volatile_simulate(sm)[sym_var]
end end
return sum_val / nbr_sim return sum_val / nbr_sim
end end
function distribute_mean_value_lha(sm::SynchronizedModel, sym_var::Vector{VariableAutomaton}, nbr_sim::Int)
sum_val = @distributed (+) for i = 1:nbr_sim
volatile_simulate(sm)[sym_var]
end
return sum_val / nbr_sim
end
function mean_value_lha(sm::SynchronizedModel, sym_var::VariableAutomaton, nbr_sim::Int) function mean_value_lha(sm::SynchronizedModel, sym_var::VariableAutomaton, nbr_sim::Int)
sum_val = 0.0 sum_val = 0.0
for i = 1:nbr_sim for i = 1:nbr_sim
......
...@@ -102,7 +102,7 @@ macro network_model(expr_network,expr_name...) ...@@ -102,7 +102,7 @@ macro network_model(expr_network,expr_name...)
nbr_rand = rand(1:1000) nbr_rand = rand(1:1000)
nbr_reactions = length(list_expr_reactions) nbr_reactions = length(list_expr_reactions)
basename_func = "$(replace(model_name, ' '=>'_'))_$(nbr_rand)" basename_func = "$(replace(model_name, ' '=>'_'))_$(nbr_rand)"
expr_model_f! = "function $(basename_func)_f!(xnplus1::Vector{Int}, l_t::Vector{Float64}, l_tr::Vector{Union{Nothing,String}}, xn::Vector{Int}, tn::Float64, p::Vector{Float64})\n\t" expr_model_f! = "function $(basename_func)_f!(xnplus1::Vector{Int}, l_t::Vector{Float64}, l_tr::Vector{Transition}, xn::Vector{Int}, tn::Float64, p::Vector{Float64})\n\t"
# Computation of nu and propensity functions in f! # Computation of nu and propensity functions in f!
str_l_a = "l_a = (" str_l_a = "l_a = ("
str_test_isabsorbing = "@inbounds(" str_test_isabsorbing = "@inbounds("
......
...@@ -7,6 +7,7 @@ model_SIR = @network_model begin ...@@ -7,6 +7,7 @@ model_SIR = @network_model begin
end "SIR" end "SIR"
set_x0!(model_SIR, [95,5,0]) set_x0!(model_SIR, [95,5,0])
set_param!(model_SIR, [0.012, 0.05]) set_param!(model_SIR, [0.012, 0.05])
simulate(model_SIR)
model_unnamed_SIR = @network_model begin model_unnamed_SIR = @network_model begin
R1: (S+I => 2I, ki*S*I) R1: (S+I => 2I, ki*S*I)
...@@ -14,6 +15,7 @@ model_unnamed_SIR = @network_model begin ...@@ -14,6 +15,7 @@ model_unnamed_SIR = @network_model begin
end end
set_x0!(model_unnamed_SIR, [95,5,0]) set_x0!(model_unnamed_SIR, [95,5,0])
set_param!(model_unnamed_SIR, [0.012, 0.05]) set_param!(model_unnamed_SIR, [0.012, 0.05])
simulate(model_unnamed_SIR)
model_ER = @network_model begin model_ER = @network_model begin
R1: (E+S => ES, k1*E*S) R1: (E+S => ES, k1*E*S)
...@@ -22,6 +24,7 @@ model_ER = @network_model begin ...@@ -22,6 +24,7 @@ model_ER = @network_model begin
end "ER" end "ER"
set_x0!(model_ER, [100,100,0,0]) set_x0!(model_ER, [100,100,0,0])
set_param!(model_ER, [1.0,1.0,1.0]) set_param!(model_ER, [1.0,1.0,1.0])
simulate(model_ER)
return true return true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment