Skip to content

Commit

Permalink
refactor newton steps to be simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Feb 16, 2024
1 parent dece834 commit 999bd8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
6 changes: 2 additions & 4 deletions EpiAware/src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ function fast_R_to_r_approx(R₀, w::Vector{T}; newton_steps = 1) where {T<:Abst
r_approx = (R₀ - 1) / (R₀ * mean_gen_time)
# Newton's method
for _ = 1:newton_steps
r_approx +=
(1 - R₀ * neg_MGF(r_approx, w)) * neg_MGF(r_approx, w) /
dneg_MGF_dr(r_approx, w)
r_approx -= (R₀ * neg_MGF(r_approx, w) - 1) / (R₀ * dneg_MGF_dr(r_approx, w))
end
return r_approx
end

function fast_R_to_r_approx(R₀, epimodel::AbstractEpiModel; newton_steps = 3)
function fast_R_to_r_approx(R₀, epimodel::AbstractEpiModel; newton_steps = 4)
fast_R_to_r_approx(R₀, epimodel.data.gen_int; newton_steps = newton_steps)
end

Expand Down
11 changes: 3 additions & 8 deletions EpiAware/test/predictive_checking/fast_approx_for_r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ G(r) = \sum_{i=1}^{\infty} w_i e^{-r i}.
```
and
```math
f(r, \mathcal{R}_0) = {1 \over G(r)} - \mathcal{R}_0.
f(r, \mathcal{R}_0) = \mathcal{R}_0 G(r) - 1.
```
then the connection between `R₀` and `r` is given by
```math
Expand All @@ -24,14 +24,9 @@ r_0 = { \mathcal{R}_0 - 1 \over \mathcal{R}_0 \langle W \rangle }.
```
where $\langle W \rangle$ is the mean of the generation interval.
Note that
To rapidly improve the estimate for `r` we use Newton steps given by
```math
\partial_r G(r, \mathcal{R}_0) = - {G'(r) \over G(r)^2} }
```
Therefore, each Newton step is given by
```math
r_{n+1} = r_n + {(1 - \mathcal{R}_0 G(r)) G(r) \over G'(r)}.
r_{n+1} = r_n - {\mathcal{R}_0 G(r) - 1\over \mathcal{R}_0 G'(r)}.
```
=#
Expand Down

0 comments on commit 999bd8e

Please sign in to comment.