src.policies.single_policy_functions

Define policy functions and helper functions.

All public functions have the same first arguments which will not be documented in individual docstrings:

  • states (pandas.DataFrame): A sid states DataFrame

  • contacts (pandas.Series): A Series with the same index as states.

  • seed (int): A seed for the random state.

Moreover, all public functions return a pandas.Series with the same index as states.

All other arguments must be documented.

Module Contents

Functions

shut_down_model(states, contacts, seed, is_recurrent, params=None)

Set all contacts to zero independent of incoming contacts.

reduce_recurrent_model(states, contacts, seed, multiplier, params=None)

Reduce the number of recurrent contacts taking place by a multiplier.

reduce_work_model(states, contacts, seed, attend_multiplier, is_recurrent, hygiene_multiplier, params=None)

Reduce contacts for the working population.

_process_multiplier(states, multiplier, name)

reopen_other_model(states, contacts, seed, start_multiplier, end_multiplier, start_date, end_date, is_recurrent, params=None)

Reduce non-work contacts to active people in gradual opening or closing phase.

_interpolate_activity_level(date, start_multiplier, end_multiplier, start_date, end_date)

Calculate an activity level in a gradual reopening or closing phase.

mixed_educ_policy(states, contacts, seed, group_id_column, always_attend_query, a_b_query, non_a_b_attend, hygiene_multiplier, a_b_rhythm='weekly', params=None)

Apply a education policy, including potential emergency care and A/B mode.

_identify_who_attends_because_of_a_b_schooling(states, a_b_query, a_b_rhythm)

Identify who attends school because (s)he is a student in A/B mode.

shut_down_model(states, contacts, seed, is_recurrent, params=None)[source]

Set all contacts to zero independent of incoming contacts.

reduce_recurrent_model(states, contacts, seed, multiplier, params=None)[source]

Reduce the number of recurrent contacts taking place by a multiplier.

For recurrent contacts the contacts Series is boolean. Therefore, simply multiplying the number of contacts with it would not have an effect on the number of contacts taking place. Instead we make a random share of individuals scheduled to participate not participate.

Parameters

multiplier (float or pd.Series) – Must be smaller or equal to one. If a Series is supplied the index must be dates.

Returns

same index as states. For a multiplier fraction

of the population the contacts have been set to False. The more individuals already had a False there, the smaller the effect.

Return type

reduced (pandas.Series)

reduce_work_model(states, contacts, seed, attend_multiplier, is_recurrent, hygiene_multiplier, params=None)[source]

Reduce contacts for the working population.

Parameters
  • attend_multiplier (float, pandas.Series, pandas.DataFrame) – share of workers that have work contacts. If it is a Series or DataFrame, the index must be dates. If it is a DataFrame the columns must be the values of the “state” column in the states.

  • hygiene_multiplier (float, or pandas.Series) – Degree to which contacts at work can still lead to infection. Must be smaller or equal to one. If a Series is supplied the index must be dates.

  • is_recurrent (bool) – True if the contact model is recurrent

_process_multiplier(states, multiplier, name)[source]
reopen_other_model(states, contacts, seed, start_multiplier, end_multiplier, start_date, end_date, is_recurrent, params=None)[source]

Reduce non-work contacts to active people in gradual opening or closing phase.

This is for example used to model the gradual reopening after the first lockdown in Germany (End of April 2020 to beginning of October 2020).

Parameters
  • start_multiplier (float) – Activity level at start.

  • end_multiplier (float) – Activity level at end.

  • start_date (str or pandas.Timestamp) – Date at which the interpolation phase starts.

  • end_date (str or pandas.Timestamp) – Date at which the interpolation phase ends.

_interpolate_activity_level(date, start_multiplier, end_multiplier, start_date, end_date)[source]

Calculate an activity level in a gradual reopening or closing phase.

Parameters
  • date (str or pandas.Timestamp) – Date at which activity level is calculated.

  • start_multiplier (float) – Activity at start.

  • end_multiplier (float) – Activity level at end.

  • start_date (str or pandas.Timestamp) – Date at which the interpolation phase starts.

  • end_date (str or pandas.Timestamp) – Date at which the interpolation phase ends.

Returns

The interpolated activity level.

Return type

float

mixed_educ_policy(states, contacts, seed, group_id_column, always_attend_query, a_b_query, non_a_b_attend, hygiene_multiplier, a_b_rhythm='weekly', params=None)[source]

Apply a education policy, including potential emergency care and A/B mode.

Parameters
  • group_id_column (str) – name of the column identifying which indivdiuals attend class together, i.e. the assort by column of the current contact model. We assume that the column identifying which individuals belong to the A or B group is group_id_column + “_a_b”.

  • always_attend_query (str, optional) – query string that identifies children always going to school. This allows to model emergency care. If None is given no emergency care is implemented.

  • a_b_query (str or bool) – pandas query string identifying the children that are taught in split classes. If True, all children are covered by A/B schooling, if False, no A/B schooling is in order. If a string, it is interpreted as a query string identifying the children that are subject to A/B schooling

  • non_a_b_attend (bool) – if True, children not selected by the a_b_query attend school normally. If False, children not selected by the a_b_query and not among the always attend children stay home.

  • hygiene_multiplier (float) – Applied to all children that still attend educational facilities.

  • a_b_rhythm (str, optional) – one of “weekly” or “daily”. Default is weekly. If weekly, A/B students rotate between attending and not attending on a weekly basis. If daily, A/B students rotate between attending and not attending on a daily basis.

_identify_who_attends_because_of_a_b_schooling(states, a_b_query, a_b_rhythm)[source]

Identify who attends school because (s)he is a student in A/B mode.

We can ignore educ workers here because they are already covered in attends_always. Same for children coverey by emergency care.

Returns

True for individuals that

are in rotating split classes and whose half of class is attending today.

Return type

attends_because_of_a_b_schooling (pandas.Series)