From e503a62a5e1e835a8b142e44a5747cc4400b7f4e Mon Sep 17 00:00:00 2001 From: Samuel Brand Date: Mon, 19 Feb 2024 12:37:09 +0000 Subject: [PATCH] rename `r` solver function to `R_to_r` --- EpiAware/src/EpiAware.jl | 2 +- EpiAware/src/epimodel.jl | 2 +- EpiAware/src/utilities.jl | 13 ++++--------- .../test/predictive_checking/fast_approx_for_r.jl | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/EpiAware/src/EpiAware.jl b/EpiAware/src/EpiAware.jl index c8f754194..360c8118e 100644 --- a/EpiAware/src/EpiAware.jl +++ b/EpiAware/src/EpiAware.jl @@ -38,7 +38,7 @@ export scan, default_rw_priors, neg_MGF, dneg_MGF_dr, - fast_R_to_r_approx + R_to_r # Exported types export EpiData, Renewal, ExpGrowthRate, DirectInfections, AbstractEpiModel diff --git a/EpiAware/src/epimodel.jl b/EpiAware/src/epimodel.jl index 2b1cc8e77..052d9f6f4 100644 --- a/EpiAware/src/epimodel.jl +++ b/EpiAware/src/epimodel.jl @@ -80,7 +80,7 @@ function (epimodel::Renewal)(_Rt, latent_process_aux) I₀ = epimodel.data.transformation(latent_process_aux.init) Rt = epimodel.data.transformation.(_Rt) - r_approx = fast_R_to_r_approx(Rt[1], epimodel) + r_approx = R_to_r(Rt[1], epimodel) init = I₀ * [exp(-r_approx * t) for t = 0:(epimodel.data.len_gen_int-1)] function generate_infs(recent_incidence, Rt) diff --git a/EpiAware/src/utilities.jl b/EpiAware/src/utilities.jl index 641bbd485..9388b87e1 100644 --- a/EpiAware/src/utilities.jl +++ b/EpiAware/src/utilities.jl @@ -131,7 +131,7 @@ function dneg_MGF_dr(r, w::AbstractVector) end """ - fast_R_to_r_approx(R₀, w::Vector{T}; newton_steps = 2, Δd = 1.0) + R_to_r(R₀, w::Vector{T}; newton_steps = 2, Δd = 1.0) This function computes an approximation to the exponential growth rate `r` given the reproductive ratio `R₀` and the discretized generation interval `w` with @@ -156,12 +156,7 @@ The two step approximation is based on: Returns: - The approximate value of `r`. """ -function fast_R_to_r_approx( - R₀, - w::Vector{T}; - newton_steps = 2, - Δd = 1.0, -) where {T<:AbstractFloat} +function R_to_r(R₀, w::Vector{T}; newton_steps = 2, Δd = 1.0) where {T<:AbstractFloat} mean_gen_time = dot(w, 1:length(w)) * Δd # Small r approximation as initial guess r_approx = (R₀ - 1) / (R₀ * mean_gen_time) @@ -172,8 +167,8 @@ function fast_R_to_r_approx( return r_approx end -function fast_R_to_r_approx(R₀, epimodel::AbstractEpiModel; newton_steps = 2, Δd = 1.0) - fast_R_to_r_approx(R₀, epimodel.data.gen_int; newton_steps = newton_steps, Δd = Δd) +function R_to_r(R₀, epimodel::AbstractEpiModel; newton_steps = 2, Δd = 1.0) + R_to_r(R₀, epimodel.data.gen_int; newton_steps = newton_steps, Δd = Δd) end diff --git a/EpiAware/test/predictive_checking/fast_approx_for_r.jl b/EpiAware/test/predictive_checking/fast_approx_for_r.jl index 7235ee44c..f0c314a88 100644 --- a/EpiAware/test/predictive_checking/fast_approx_for_r.jl +++ b/EpiAware/test/predictive_checking/fast_approx_for_r.jl @@ -55,7 +55,7 @@ errors = mapreduce(hcat, doubling_times) do T_2 R0 = growth_rate_to_reproductive_ratio(true_r, w) return map(idxs) do ns - @time r = fast_R_to_r_approx(R0, w, newton_steps = ns) + @time r = R_to_r(R0, w, newton_steps = ns) abs(r - true_r) + jitter end end