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

Different formats for output data? #77

Open
marialma opened this issue Mar 15, 2021 · 6 comments
Open

Different formats for output data? #77

marialma opened this issue Mar 15, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@marialma
Copy link

Hi individual team! I had a question/ request about the output formats

Instead of generating a data frame that contains the counts of each compartment at each time step, I'm interested in creating a data frame that shows each individual's status at each time point. Is there a way to do this within the Render class?

@giovannic
Copy link
Member

Hi Maria,

Nope, we don't have that implemented at the moment.

For your case I'd recommend implementing a new renderer. Something like,

CategoryRender <- R6::R6Class(
  'CategoryRender',
  private = list(
    .output = NULL, # a char matrix representing the state of every individual at each timestep
    .categories = NULL
  ),
  public = list(
    initialize = function(timesteps, n_individuals, categories) {
      private$.categories <- categories
      private$.output <- matrix(NA, nrow = timesteps, ncol = n_individuals)
    },

    render = function(category_variable, timestep) {
      for (category in private$.categories) {
        private$.output[timestep, category_variable$get_index_of(category)$to_vector()] <- category
      }
    },

    #' @description
    #' Make a dataframe for the render
    to_dataframe = function() {
      # turn your private$.output into the dataframe you want :)
    }
  )
)

If it works well for you we're happy to accept a pull request :)

@marialma
Copy link
Author

Thank you! I'll give it a shot and report back 😄

@giovannic
Copy link
Member

Great! LMK

@slwu89
Copy link
Collaborator

slwu89 commented Dec 18, 2021

This is becoming relevant again to output population NAT for safir to calculate seroprevalence. @giovannic I'm assigning myself to this, I'll get to it in the next few weeks.

  1. Double renderer should be store a matrix, rows are persons, columns are timesteps, so that insertion is fastest (matrices stored column major). Remember to set storage.mode to the proper integer type, or could just do it in C++ and return NumericMatrix.
  2. Same for integer variable renderer.

One thing to be aware of is that if we resize variables mid-simulation, the size of rendered objects changes. Not sure yet how to deal with that, for now I'll assume we're not using resizable variables. One nice feature would be to only output at some subset of time points, such as every integer day, for models which update with small dt.

@giovannic
Copy link
Member

Very cool!

if we resize variables mid-simulation

That's cool, let's not support resizeable variables until we understand what works for standard variables

@slwu89
Copy link
Collaborator

slwu89 commented Dec 21, 2021

That's cool, let's not support resizeable variables until we understand what works for standard variables

We may not even need to do anything, based on what Azra and Alexandra need in safir, we can just do the appropriate summary of data in the render process as double_count_render_process_daily in this vignette! https://mrc-ide.github.io/safir/articles/vaccine_notypes.html#run-safir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants