-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix logging of closure limits #34
Changes from 4 commits
3e811ab
69778ea
71ceda1
6d8ed9c
80a785a
b860eb0
c653b1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,32 @@ make_response_threshold_event <- function(response_threshold) { | |
} | ||
|
||
event_function <- function(time, state, parameters) { | ||
# prevent flipping switch when checkEventFunc runs | ||
# turn closure and excess hospitalisation switch on | ||
# NOTE: prevent flipping switch when checkEventFunc runs | ||
# NOTE: prevent response activation if epdedemic is not growing | ||
state <- array( | ||
state, | ||
c(N_AGE_GROUPS, N_MODEL_COMPARTMENTS, N_ECON_STRATA, N_VACCINE_STRATA) | ||
) | ||
cm <- parameters[["contact_matrix"]] %*% diag(parameters[["demography"]]) | ||
rt <- r_eff(parameters[["r0"]], state, cm) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to get a "r_greater_than_one" check function written at some point that could be much faster than doing this accurately - would be good to get some profiles done at some point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would that be a simple wrapper around this operation, or is there something more complex I'm missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something more complex - we don't care about the eigenvalues very much - we just care about the sign of the leading one. (Much) faster algorithms exist for finding the leading eigenvalue and I think we can generalise that (or find an existing generalisation) if we just care about the sign. But no point doing any of that unless this is actually a timesink, hence the suggestion of profiling first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have thoughts on this that open up another can of worms related to the I've worked out a relatively simple mathematical expression for the eigenvalue here: https://hackmd.io/xfzSdlY-SnGblvP8aOA7Fw, as a precursor to calculating |
||
|
||
# NOTE: to ensure only first hosp threshold crossing is logged | ||
is_hosp_switch_on <- rlang::env_get(parameters[["mutables"]], "hosp_switch") | ||
|
||
if (time != parameters[["min_time"]] && !is_hosp_switch_on) { | ||
rlang::env_bind( | ||
parameters[["mutables"]], | ||
switch = TRUE, hosp_switch = TRUE, | ||
closure_time_start = time | ||
rlang::env_poke( | ||
parameters[["mutables"]], "hosp_switch", TRUE | ||
) | ||
|
||
# NOTE: trigger response and log closure start time only if | ||
# epidemic is growing | ||
if (rt >= 1.0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also be checking somewhere here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that The sequence of events is:
I have split up the two switches in |
||
rlang::env_bind( | ||
parameters[["mutables"]], | ||
switch = TRUE, | ||
closure_time_start = time | ||
) | ||
} | ||
} | ||
as.numeric(state) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If neither of these inputs never change is it better perhaps to compute in parameter set up once rather than adding this matrix multiplication to every root check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to
parameters
.