This is a companion package to macpan2
. Please install that package first.
User should install with the following command:
remotes::install_github("canmod/macpan2helpers")
License: GNU General Public License v3.0
This is a companion package to macpan2
. Please install that package first.
User should install with the following command:
remotes::install_github("canmod/macpan2helpers")
The current version of mk_calibrate isn't quite working yet.
library(macpan2helpers)
example("mk_calibrate")
will show the problems. This is the code:
library(macpan2helpers)
setup_sim <- function() {
m <- Compartmental(system.file("starter_models", "sir", package = "macpan2"))
sim <- m$simulators$tmb(
time_steps = 100,
state = c(S = 99, I = 1, R = 0),
flow = c(foi = NA, gamma = 0.1),
beta = 0.2,
N = empty_matrix
)
}
sim <- setup_sim()
mk_calibrate(sim,
data = list(I_obs = rep(0, 100)),
params = list(beta = 0.2, I_sd = 1),
transforms = list(beta = "log", I_sd = "log"),
exprs = list(log_lik ~ dnorm(I_obs, I, I_sd)),
debug = TRUE
)
The debugging output:
add log_lik matrix (empty)
add data matrix: I_obs
add param (scalar placeholder value): I_sd
process expression: log_lik ~ dnorm(I_obs, I, I_sd)
add (empty matrix): I_sim
add I_sim ~ I
add log_lik ~ dnorm(I_obs, rbind_time(I_sim), I_sd)
param_frame:
mat row col default
1 log_beta 0 0 0.2
2 log_I_sd 0 0 1.0
adding transformations
add transformation: Log beta
add transformation: Log I_sd
set obj_fn to -sum(log_lik)
As far as I can tell this is doing the same steps as the calibration vignette, but sim$report(c(1,1))
gives
sim$report(c(0,0))
MACPAN ERROR #20: Can only rbind_time (or rbind_lag) initialized matrices with saved history
<repeated 4 more times>
Error in self$.runner(..., .phases = .phases, .method = "report") :
Error thrown by the TMB engine at the following expression:
log_lik ~ dnorm(I_obs, rbind_time(I_sim), I_sd)
Any ideas?
would be nice for the visNetwork
graphic to read the flow type from sir$flows()
and generate an edge label with the full flow.
for instance, for the sample SIR model, we have
sir$flows()
from to flow type
1 S I foi per_capita
2 I R gamma per_capita
currently, the edges of the compartmental graph are labelled simply with the entry in flow
. it would be clearer if these flows were labelled with the compound entry flow * from
(since type
is per_capita
). we'd have to write a labeller based on type.
(I don't think I have push access to this repo - may I get it?)
library(macpan2)
library(macpan2helpers)
## with birth (D0)/death (D) distinct
sir1 <- Compartmental("examples/sir_open1")
visCompartmental(sir1)
## with all fake compartments distinct
sir2 <- Compartmental("examples/sir_open2")
visCompartmental(sir2)
Setting up an 'open' SIR model (with births/deaths) with separate fake birth and death compartments gives this:
all the correct arrows are actually there, and can be seen if you manipulate the diagram by dragging the boxes around, but the hierarchical layout doesn't do anything about trying to position bins so that arrows don't coincide
Adding a separate fake compartment for birth (D0) and each death flow (D1, D2, D3) gives something prettier (but doing this is annoying)
This is obviously low priority but might be something for a small student project (i.e. see if there's any way to adapt the visNetwork
layout algorithms so we can get something that works better out of the box ...)
debug
emit exact expressions (with or without explanations interspersed?)macpan2
? change name/make it a method?X
-> X_sim
, automatic rbind()
, automatic obj_fun
-> -sum(log_lik)
...)it would be nice to let the user specify the horizontal ordering of compartments based on a specified partition... e.g. have epi partition variables appear left to right so all susceptible compartments in first column, then all exposed compartments, etc.
ideas here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.