diff --git a/algorithms/_utils_abc.jl b/algorithms/_utils_abc.jl index d2b4afce8554df186199aebe22f6b2ccaf10b348..ec6e0f6b6cd7901276e304ea437149c74c75b421 100644 --- a/algorithms/_utils_abc.jl +++ b/algorithms/_utils_abc.jl @@ -5,8 +5,8 @@ function _init_abc_automaton!(mat_p_old::Matrix{Float64}, vec_dist::Vector{Float for i = eachindex(vec_dist) draw!(vec_p, pm) mat_p_old[:,i] = vec_p - σ = simulate(pm, vec_p) - vec_dist[i] = σ.S[str_var_aut] + S = volatile_simulate(pm, vec_p) + vec_dist[i] = S[str_var_aut] end end @@ -88,8 +88,8 @@ function _update_param!(mat_p::Matrix{Float64}, vec_dist::Vector{Float64}, if !insupport(pm, vec_p_prime) continue end - σ = simulate(pm, vec_p_prime) - dist_sim = σ.S[str_var_aut] + S = volatile_simulate(pm, vec_p_prime) + dist_sim = S[str_var_aut] nbr_sim += 1 end diff --git a/core/model.jl b/core/model.jl index c8404b717dac6e1a3e9235d83d6750633373d9b5..de7d6adaad5d6b2537dee4cea611e5abeb234bec 100644 --- a/core/model.jl +++ b/core/model.jl @@ -245,7 +245,13 @@ function simulate(product::SynchronizedModel; p::Union{Nothing,AbstractVector{Fl end return SynchronizedTrajectory(Sn, product, values, times, transitions) end +""" + `volatile_simulate(sm::SynchronizedModel; p, verbose)` +Simulates a model synchronized with an automaton but does not store the values of the simulation +in order to improve performance. +It returns the last state of the simulation `S::StateLHA` not a trajectory `σ::SynchronizedTrajectory`. +""" function volatile_simulate(product::SynchronizedModel; p::Union{Nothing,AbstractVector{Float64}} = nothing, verbose::Bool = false) m = product.m @@ -311,6 +317,20 @@ function simulate(pm::ParametricModel, p_prior::AbstractVector{Float64}) return simulate(pm.m; p = full_p) end +""" + `volatile_simulate(pm::ParametricModel, p_prior::AbstractVector{Float64}) + +A volatile version of `simulate(pm::ParametricModel, p_prior::AbstractVector{Float64})`. +The model in pm should be of type SynchronizedModel (`typeof(pm.m) <: SynchronizedModel`). +It returns `S::StateLHA`, not a trajectory. +""" +function volatile_simulate(pm::ParametricModel, p_prior::AbstractVector{Float64}) + @assert typeof(pm.m) <: SynchronizedModel + full_p = copy(get_proba_model(pm).p) + full_p[pm._param_idx] = p_prior + + return volatile_simulate(pm.m; p = full_p) +end """ `distribute_mean_value_lha(sm::SynchronizedModel, str_var::String, nbr_stim::Int)`