Skip to content
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

Handing products for multiplicative interventions #316

Open
adamkucharski opened this issue Jul 25, 2024 · 2 comments
Open

Handing products for multiplicative interventions #316

adamkucharski opened this issue Jul 25, 2024 · 2 comments

Comments

@adamkucharski
Copy link

adamkucharski commented Jul 25, 2024

Thanks for all your great work on this package. We’ve been looking at combining the {epidemics} package interface (which makes contact matrices, interventions etc. easy for user to define, and can be reused in other packages) with {odin} model implementionss (which are easier to edit and can be passed to {mcstate} etc). One thing that came up is how to implement multiple interventions that multiplicatively reduce the contact rates (e.g. school closures on top of workplace closures).

It's my understanding that prod isn't a valid operation in an odin model, so we've been using log transforms as a work around (full draft vignette here):

  # Contact matrix with time-dependent interventions
  contact_reduction[,] <- if (t > intervention_start[i] && t < intervention_end[i]) (1.0 - intervention_effect[i,j]) else 1
  contact_reduction_log[,] <- log(contact_reduction[i,j] + 1e-10) # Avoid log(0)
  contact_reduction_total_log[] <- sum(contact_reduction_log[,i]) 
  contact_reduction_total[] <- exp(contact_reduction_total_log[i]) 

  # Specify how transmission varies over time
  lambda_prod[, ] <- C[i, j] * I[j] * beta * contact_reduction_total[j] * contact_reduction_total[i]
  lambda[] <- sum(lambda_prod[i, ])

Wanted to check that we weren't missing something more efficient, and to highlight a use case for value of having a prod operation if this is potentially in the pipeline.

@richfitz
Copy link
Member

I have no objections to supporting prod() by extension of sum(), and you are right that this is not easily supported at present. When I saw the title I thought you were looking for matrix multiplication (%*%) which is also something we'd like to support but has proven hard to reason about (#134, #291, and other issues).

Progress is likely to be slow at the moment as we're taking the opportunity to dig the stack out of some pandemic-induced technical debt, but the good news is I'll get this implemented once going through and doing sum() in the new version.

@richfitz
Copy link
Member

This is now supported in odin2 (which will become odin in due course): mrc-ide/odin2#72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants