Skip to content

Commit

Permalink
rename r solver function to R_to_r
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Feb 19, 2024
1 parent 41c1d25 commit e503a62
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion EpiAware/src/EpiAware.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion EpiAware/src/epimodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions EpiAware/src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion EpiAware/test/predictive_checking/fast_approx_for_r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e503a62

Please sign in to comment.