Skip to content

Add functions to accelerate number of hospitalizations #140

@gvegayon

Description

@gvegayon

It can be hard to extract the number of hospitalizations in some models. Right now, the approach has been: (a) extract the transition matrix, (b) keep all transitions that go from state s (s!="Hospitalized") to state "hospitalize", and (c) collapse that by date. In the case of running multiple simulations, this adds overhead, as just outputting all the transitions can be time and memory-consuming.

Implementation

Instead, we could have a built-in function in the model that either automatically stores transitions to hospitalization states or leverages the data in the transition matrix. The function could be included in the inherited models like:

template<typename TSeq>
class DataBase<TSeq> {
private:

  ...

public:

  ...

  /** Get the hospitalization incidence */
  void get_hospitalizations(
    std::vector< int > & date, ///< Date of the hospitalization
    std::vector< int > & virus_id, ///< Virus at the time of hospitalization
    std::vector< int > & hospitalizations_counts ///< Total hospitalizations
  ) const;

}

This would also require adding the hospitalizations entry to the make_saver, as well as to the write_data() function, like we did with #138. And the implementation is something like the following:

template<typename TSeq>
inline void DataBase<TSeq>::get_hospitalizations(...)
{
  return model->get_hospitalizations(...);
}

This would then require implementing a virtual method for the model class to be defined by each inherited class. Something like this:

template<typename TSeq>
class Model {
private:
  ...

public:
  ...
  
  virtual void get_hospitalization(...);

}

With the default implementation similar to the following

template<typename TSeq>
inline void Model<TSeq>::get_hospitalization(...)
{
  throw "This model does not have an implementation of the method `get_hospitalization()`."
}

So then users could do model.get_db().get_hospitalizations()

Testing

For the testing, we can do the following:

  1. Run a simulation with one of the models that contains hospitalizations.
  2. Extract both the transition matrix and the hospitalizations.
  3. Compute the hospitalizations using the transition matrix.
  4. The ones computed using the transition matrix should match those from the get_hospitalizations

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions