epiforecasts / EpiNow2

Estimate Realtime Case Counts and Time-varying Epidemiological Parameters
https://epiforecasts.io/EpiNow2/dev/
Other
113 stars 32 forks source link

Functionalise stan code #122

Closed seabbs closed 3 years ago

seabbs commented 4 years ago

The stan code is represented partially in functions and partially within the main model. Several sections (like the mapping from infections -> reports, the GP, update Rt etc) could be easily rewritten into stan functions. This would help support future model developments as adding extensions/reusing code will be easier.

Examples of future extensions this will support are:

medewitt commented 3 years ago

I'm trying to think this through, so this might be half baked, but worth mentioning. In compiling the cmdstanr version you can reference function directories. In theory we could then expose any of the nice functions to users to write their own primary Stan model while pulling functions from EpiNow2...

estimate_infections2.stan (something user made)

functions{
#functions/convolve.stan
}
model{
user written model
}

Then when the user specified the model in the epinow or whatever piece of the API, internally on compile in CmdStanR, they will have those functions.

model <- cmdstanr::cmdstan_model(file.path(app_loc, "estimate_infections2.stan"),
                                     include_paths = file.path(app_loc))
seabbs commented 3 years ago

That sounds extremely useful. As we move forward the model will hopefully become increasingly modular so this be potentially a real benefit.