-
Bentriou Mahmoud authored
This commit groups the change operated to the creation of models and simulate function of a ContinuousTimeModel. The general idea is to create a concrete type and a simulate function per model creation by metaprogramming. - Now, ContinuousTimeModel is an abstract type. Each creation of a model defines a concrete type T <: ContinuousTimeModel by meta programming. - f! and isabsorbing ContinuousTimeModel fields are Symbols. - simulate(::ContinuousTimeModel) is run by multiple dispatch, according to the type of the model. Can't run the whole tests for now but unit/simulate_available_models.jl runs properly (i've updated the list of models in this commit), and I've manually checked in the repl that simulations run correctly (distributed / plots).
Bentriou Mahmoud authoredThis commit groups the change operated to the creation of models and simulate function of a ContinuousTimeModel. The general idea is to create a concrete type and a simulate function per model creation by metaprogramming. - Now, ContinuousTimeModel is an abstract type. Each creation of a model defines a concrete type T <: ContinuousTimeModel by meta programming. - f! and isabsorbing ContinuousTimeModel fields are Symbols. - simulate(::ContinuousTimeModel) is run by multiple dispatch, according to the type of the model. Can't run the whole tests for now but unit/simulate_available_models.jl runs properly (i've updated the list of models in this commit), and I've manually checked in the repl that simulations run correctly (distributed / plots).
poisson.jl 1.31 KiB
import StaticArrays: SVector, SMatrix, @SVector, @SMatrix
import Distributions: Poisson, rand
d=1
k=1
dict_var_poisson = Dict(:N => 1)
dict_p_poisson = Dict(:λ => 1)
l_tr_poisson = [:R]
p_poisson = [5.0]
x0_poisson = [0]
t0_poisson = 0.0
@everywhere function Poisson_f!(xnplus1::Vector{Int}, l_t::Vector{Float64}, l_tr::Vector{Transition},
xn::Vector{Int}, tn::Float64, p::Vector{Float64})
u1 = rand()
tau = (-log(u1)/p[1])
xnplus1[1] += 1
l_t[1] = tn + tau
l_tr[1] = :R
end
@everywhere isabsorbing_Poisson(p::Vector{Float64}, xn::Vector{Int}) = p[1] === 0.0
g_poisson = [:N]
@everywhere @eval $(MarkovProcesses.generate_code_model_type_def(:PoissonModel))
@everywhere @eval $(MarkovProcesses.generate_code_model_type_constructor(:PoissonModel))
@everywhere @eval $(MarkovProcesses.generate_code_simulation(:PoissonModel, :Poisson_f!, :isabsorbing_Poisson))
poisson = PoissonModel(d, k, dict_var_poisson, dict_p_poisson, l_tr_poisson,
p_poisson, x0_poisson, t0_poisson,
:Poisson_f!, :isabsorbing_Poisson; g=g_poisson, time_bound=1.0)
function create_poisson(new_p::Vector{Float64})
poisson_new = deepcopy(poisson)
@assert length(poisson_new.p) == length(new_p)
set_param!(poisson_new, new_p)
return poisson_new
end