From 7ccf6160ece5504b75a7597a95073833274ba08b Mon Sep 17 00:00:00 2001 From: Mahmoud Bentriou <mahmoud.bentriou@centralesupelec.fr> Date: Thu, 20 May 2021 23:19:10 +0200 Subject: [PATCH] change doc of abc methods --- algorithms/abc_model_choice.jl | 33 ++++++++++++++++----------------- algorithms/abc_smc.jl | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/algorithms/abc_model_choice.jl b/algorithms/abc_model_choice.jl index a1ffede..5760591 100644 --- a/algorithms/abc_model_choice.jl +++ b/algorithms/abc_model_choice.jl @@ -23,10 +23,10 @@ function getproperty(dataset::AbcModelChoiceDataset, sym::Symbol) end """ - `abc_model_choice_dataset(models, models_prior, - summary_stats_observations, - summary_stats_func::Function, distance_func::Function, - k::Int, N_ref::Int; dir_results::Union{Nothing,String} = nothing)` + abc_model_choice_dataset(models, models_prior, + summary_stats_observations, + summary_stats_func::Function, distance_func::Function, + k::Int, N_ref::Int; dir_results::Union{Nothing,String} = nothing) Creates a reference table for ABC model choice. @@ -56,10 +56,10 @@ function abc_model_choice_dataset(models::Vector{<:Union{Model,ParametricModel}} end """ - `abc_model_choice_dataset(models, models_prior, - summary_stats_observations, - summary_stats_func::Function, distance_func::Function, - k::Int, N_ref::Int; dir_results::Union{Nothing,String} = nothing)` + abc_model_choice_dataset(models, + summary_stats_observations, + summary_stats_func::Function, distance_func::Function, + k::Int, N_ref::Int; dir_results::Union{Nothing,String} = nothing) Creates a reference table for ABC model choice with discrete uniform prior distribution over the models. """ @@ -161,10 +161,10 @@ function _distributed_abc_model_choice_dataset(models::Vector{<:Union{Model,Para end """ - `rf_abc_model_choice(models, summary_stats_observations, - summary_stats_func::Function, N_ref::Int; - k::Int = N_ref, distance_func::Function = (x,y) -> 1, - hyperparameters_range::Dict)` + rf_abc_model_choice(models, summary_stats_observations, + summary_stats_func::Function, N_ref::Int; + k::Int = N_ref, distance_func::Function = (x,y) -> 1, + hyperparameters_range::Dict) Run the Random Forest Approximate Bayesian Computation model choice method. @@ -179,8 +179,8 @@ The optional arguments are: * `k`: the k nearest samples from the observations to keep in the reference table (by default: k = N_ref) * `distance_func`: the distance function, has to be defined if k < N_ref * `hyperparameters_range`: a dict with the hyperparameters range values for the cross validation -fit of the Random Forest (by default: `Dict(:n_estimators => [200], :min_samples_leaf => [1], :min_samples_split => [2])`). -See scikit-learn documentation of RandomForestClassifier for the hyperparameters name. + fit of the Random Forest (by default: `Dict(:n_estimators => [200], :min_samples_leaf => [1], :min_samples_split => [2])`). + See scikit-learn documentation of RandomForestClassifier for the hyperparameters name. The result is a `RandomForestABC` object with fields: * `reference_table` an AbcModelChoiceDataset that corresponds to the reference table of the algorithm, @@ -205,11 +205,10 @@ function rf_abc_model_choice(models::Vector{<:Union{Model,ParametricModel}}, end """ - `posterior_proba_model(rf_abc::RandomForestABC)` + posterior_proba_model(rf_abc::RandomForestABC) -Estimates the posterior probability of the model with the Random Forest ABC method. +Estimates the posterior probability of the model ``P(M = \\widehat{M}(s_{obs}) | s_{obs})`` with the Random Forest ABC method. """ -# P(m = m^(ss_obs) | ss_obs) estimate function posterior_proba_model(rf_abc::RandomForestABC) oob_votes = rf_abc.clf.oob_decision_function_ y_pred_oob = argmax.([oob_votes[i,:] for i = 1:size(oob_votes)[1]]) diff --git a/algorithms/abc_smc.jl b/algorithms/abc_smc.jl index 23f5dd3..fe74b14 100644 --- a/algorithms/abc_smc.jl +++ b/algorithms/abc_smc.jl @@ -24,6 +24,12 @@ struct ResultAbc weights::Vector{Float64} l_ess::Vector{Float64} end +""" + automaton_abc(pm::ParametricModel, l_obs, func_dist; nbr_particles, alpha, kernel_type, NT + duration_time, bound_sim, sym_var_aut, verbose) + +Run the Automaton-ABC-SMC algorithm with the pm parametric model. `pm.m` has to be a `SynchronizedModel`. +""" function automaton_abc(pm::ParametricModel; nbr_particles::Int = 100, tolerance::Float64 = 0.0, alpha::Float64 = 0.75, kernel_type = "mvnormal", @@ -57,18 +63,19 @@ function automaton_abc(pm::ParametricModel; end """ - `abc_smc(pm::ParametricModel, l_obs, func_dist; nbr_particles, alpha, kernel_type, NT - duration_tiùe, bound_sim, sym_var_aut, verbose)` + abc_smc(pm::ParametricModel, l_obs, func_dist; nbr_particles, alpha, kernel_type, NT + duration_time, bound_sim, sym_var_aut, verbose) Run the ABC-SMC algorithm with the pm parametric model. + `func_dist(l_sim, l_obs)` is the distance function between simulations and observation, -it corresponds to \$\rho(\eta(y_sim), \eta(y_exp))\$. +it corresponds to ``\\rho(\\eta(y_sim), \\eta(y_exp))\\``. `l_obs::Vector{<:T2}` is a collection of observations. `dist` must have a signature of the form `func_dist(l_sim::Vector{T1}, l_obs::Vector{T2})`. -If pm is defined on a ContinuousTimeModel, then `T1` should verify `T1 <: Trajectory`. -!!! Distance function and distributed ABC +If `pm` is defined on a `ContinuousTimeModel`, then `T1` should verify `T1 <: Trajectory`. +!!! Distance function and distributed ABC If you use `abc_smc` with multiple workers, `dist` has to be defined on every workers by using @everywhere. -- GitLab