GithubHelp home page GithubHelp logo

macpan2helpers's Introduction

macpan2helpers

This is a companion package to macpan2. Please install that package first.

Installation

User should install with the following command:

remotes::install_github("canmod/macpan2helpers")

macpan2helpers's People

Contributors

bbolker avatar stevencarlislewalker avatar papsti avatar

Watchers

 avatar  avatar Michael WZ Li avatar David Earn avatar

macpan2helpers's Issues

help with `mk_calibrate`?

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?

nicer edge labels in `visCompartment()`

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.

small vis issues with open systems

(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:

Screenshot from 2023-06-24 19-09-57

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)

Screenshot from 2023-06-24 19-11-24

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 ...)

mk_calibrate issues

  • make debug emit exact expressions (with or without explanations interspersed?)
  • move to macpan2? change name/make it a method?
  • document transformations (state var X -> X_sim, automatic rbind(), automatic obj_fun -> -sum(log_lik) ...)

add hierarchical info to `visCompartments()`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.