Commit 047eb00b authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Add function to change observed variables in model + tests

parent eca6a351
......@@ -3,7 +3,7 @@ module MarkovProcesses
import Base: +, -, getfield, getindex
export Model, ContinuousTimeModel, DiscreteTimeModel
export simulate, set_param!, get_param
export simulate, set_param!, get_param, set_observed_var!
export is_bounded
export load_model, get_module_path
include("model.jl")
......
......@@ -78,6 +78,19 @@ function simulate(m::ContinuousTimeModel, n::Int)
return obs
end
function set_observed_var!(m::Model,g::Vector{String})
dobs = length(g)
_map_obs_var_idx = Dict()
_g_idx = Vector{Int}(undef, dobs)
for i = 1:dobs
_g_idx[i] = m.map_var_idx[g[i]] # = ( (g[i] = i-th obs var)::String => idx in state space )
_map_obs_var_idx[g[i]] = i
end
m.g = g
m._g_idx = _g_idx
m._map_obs_var_idx = _map_obs_var_idx
end
is_bounded(m::Model) = m.time_bound < Inf
function check_consistency(m::Model) end
function simulate(m::Model, n::Int; bound::Float64 = Inf)::AbstractObservations end
......
......@@ -7,5 +7,7 @@ using Test
@test include("unit/simulate_sir.jl")
@test include("unit/simulate_sir_bounded.jl")
@test include("unit/simulate_er.jl")
@test include("unit/change_obs_var_sir.jl")
@test include("unit/change_obs_var_sir_2.jl")
end
using MarkovProcesses
load_model("SIR")
σ = simulate(SIR)
set_observed_var!(SIR, ["I", "R"])
d1 = Dict("S" => 1, "I" => 2, "R" => 3)
d2 = Dict("I" => 1, "R" => 2)
bool_test = SIR.g == ["I", "R"] && SIR._g_idx == [2,3] &&
SIR.map_var_idx == d1 &&
SIR._map_obs_var_idx == d2
return bool_test
using MarkovProcesses
load_model("SIR")
σ = simulate(SIR)
set_observed_var!(SIR, ["R", "S"])
d1 = Dict("S" => 1, "I" => 2, "R" => 3)
d2 = Dict("R" => 1, "S" => 2)
bool_test = SIR.g == ["R", "S"] && SIR._g_idx == [3,1] &&
SIR.map_var_idx == d1 &&
SIR._map_obs_var_idx == d2
return bool_test
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment