Comments (4)
Hey @giovannic !
I've been playing around with a similar root-finding approach to the oneI implemented in the old model for calibrating a run. It is definitely not the most efficient approach, but is flexible, allowing a user to calibrate a specific model run to any number of outputpoints from any output variable. Would be good to hear if you think this kind of approach would be useful to implement in the package, or demonstrate in a vignette? It would be made more efficient if we can get a half decent starting guess for EIR, or the reduce the range of EIRs to search.
Here's a quick example:
library(malariasimulation)
# Objective (internal) function
objective <- function(eir, parameters, target_var, target, target_tt, summary_function, tolerance){
message("Trying EIR: ", round(eir * 365, 4))
p <- parameters %>%
set_equilibrium(init_EIR = eir)
# Setting seed - this might help??
set.seed(1233445)
raw <- malariasimulation::run_simulation(timesteps = timesteps, parameters = p)
summary <- summary_function(raw)
difference <- (summary[target_tt, target_var] - target)
message("Current difference: ", round(difference, 3))
difference[abs(difference) < tolerance] <- 0
difference <- sum(difference)
return(difference)
}
# Calibrate (user facing)
# target_var: Name of variable to calibrate to
# target: target values of target_var to calibrate to
# target_tt: target timesteps at which to match target_var targets
# summary_function: a post-processing function, to allow second order outputs to be calibrated to
# tolerance: the tolerance require for calibration (average error on the same scale as target_var)
calibrate <- function(timesteps, parameters, target_var, target, target_tt, summary_function, tolerance){
uniroot(objective,
interval = c(0.01, 500) / 365,
extendInt = "no",
parameters = parameters,
target_var = target_var,
target = target,
target_tt = target_tt,
summary_function = summary_function,
tolerance = tolerance,
trace = 1)
}
### Example: ##################################################################
# Allow the user to define a processing function for second order output
sf <- function(x){
x$prev_2_10 <- x$n_detect_730_3650 / x$n_730_3650
return(x)
}
# Name the target variable to fit to
target_var <- "prev_2_10"
# Define target (in this case prev) to find
target <- c(0.1, 0.1)
# Time points at which to match target
target_tt <- c(500, 600)
p <- get_parameters(list(human_population = 5000))
timesteps <- 1000
out <- calibrate(timesteps = timesteps,
parameters = p,
target_var = target_var,
target = target,
target_tt = target_tt,
summary_function = sf,
tolerance = 0.001)
pars <- p %>%
set_equilibrium(init_EIR = out$root)
raw <- malariasimulation::run_simulation(timesteps = timesteps, parameters = pars)
summary <- sf(raw)
plot(summary[,c("timestep", target_var)], t = "l", ylim = c(0, 0.3))
points(target ~ target_tt, col = "red", pch = 19)
################################################################################
from malariasimulation.
Here's the output btw to that example. Fitting to two prevalence points (with reasonable tolerance):
from malariasimulation.
Note: if this relies on the ODE to calculate total_M, this may be impossible. Since adult mosquitoes are now modelled individually.
from malariasimulation.
Closing, we would like to implement this in a separate package
from malariasimulation.
Related Issues (20)
- Default outputs
- Min_wait error in set_mass_pev() HOT 1
- Solver failure in dev branch due to model.total_M becoming very large.
- Vector size cannot be NA issue in master branch with simple model run
- Progress bar functionality only works when timesteps is an object in global environment
- Documentation still exists for severe malaria prevalence HOT 1
- Treated infectiousness parameter (ct) appears to be redundant?
- Model changing booster coverage over time using set_pev_epi
- Age-disaggregated outputs can be slow HOT 3
- unclear stochastic behaviour around when interventions are being turned on HOT 2
- rate inputs for create_progression_process are average state residence times HOT 3
- Update the specification format of the TBV
- Age-based coverage of PMC HOT 4
- setting completely correlated interventions does not result in the expected coverage HOT 3
- Add indication of evidence base and WHO position to intervention documentation and vignettes HOT 1
- Add support for probes in the model
- Export run_resumable_simulation into namespace HOT 4
- Should asymptomatic infectivity update at every timestep?
- Model parameter consistency
- Add seasonal/perennial vector mix example to set_carrying_capacity vignette
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from malariasimulation.