-
Notifications
You must be signed in to change notification settings - Fork 20
1279 minor additions to how infections work #1320
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
Open
DavidKerkmann
wants to merge
15
commits into
main
Choose a base branch
from
1279-minor-additions-to-how-infections-work
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ee81819
refactor
xsaschako 2fb9b00
Improve infection draw, rename infectivity and related functions
DavidKerkmann 24f4e4d
Quick naming fixes
DavidKerkmann 98b415b
merge main
DavidKerkmann 77ae766
Fix vaccination time dependency
DavidKerkmann 763be59
Changed multiply function in time.h
DavidKerkmann f3abc80
Small update to function description
DavidKerkmann 8f66c0b
Merge branch 'main' into 1279-minor-additions-to-how-infections-work
DavidKerkmann 42cbb92
merge main
DavidKerkmann 6bc0825
Improvements according to review --- IGNORE ---
DavidKerkmann 2e2d7f6
Merge main
DavidKerkmann 5bbecd0
Finish relative time of first state inclusion
DavidKerkmann 625177b
Fix renaming bug after merge
DavidKerkmann 1c61f85
Remove shift_init_date function
DavidKerkmann 13221f9
Merge branch 'main' into 1279-minor-additions-to-how-infections-work
DavidKerkmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,15 @@ namespace mio | |
| namespace abm | ||
| { | ||
|
|
||
| /** | ||
| * @brief Represents a transition between infection states with duration and probability. | ||
| */ | ||
| struct StateTransition { | ||
| InfectionState from_state; | ||
| InfectionState to_state; | ||
| TimeSpan duration; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment what the duration is (I guess it's duration in the from state?) |
||
| }; | ||
|
|
||
| /** | ||
| * @brief Models the ViralLoad for an Infection, modelled on a log_10 scale. | ||
| * Based on https://www.science.org/doi/full/10.1126/science.abi5273 | ||
|
|
@@ -58,6 +67,13 @@ struct ViralLoad { | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Distributions of the relative time that people have been in their initial infection state at the beginning of the simulation. | ||
| * Values have to be within [0, 1]. | ||
| * This makes it possible to draw from a user-defined distribution instead of drawing from a uniform distribution. | ||
| */ | ||
| using InitialInfectionStateDistribution = CustomIndexArray<AbstractParameterDistribution, VirusVariant, AgeGroup>; | ||
|
|
||
| class Infection | ||
| { | ||
| public: | ||
|
|
@@ -77,24 +93,43 @@ class Infection | |
| TimePoint start_date, InfectionState start_state = InfectionState::Exposed, | ||
| ProtectionEvent latest_protection = {ProtectionType::NoProtection, TimePoint(0)}, bool detected = false); | ||
|
|
||
| /** | ||
| * @brief Create an Infection for a single Person with a time spent in the given initial state that is drawn from the given distribution. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] virus Virus type of the Infection. | ||
| * @param[in] age AgeGroup to determine the ViralLoad course. | ||
| * @param[in] params Parameters of the Model. | ||
| * @param[in] init_date Date of initializing the Infection. | ||
| * @param[in] init_state #InfectionState at time of initializing the Infection. | ||
| * @param[in] init_state_dist Distribution to draw the relative time spent in the initial state from. Values have to be within [0, 1]. | ||
| * @param[in] latest_protection The pair value of last ProtectionType (previous Infection/Vaccination) and TimePoint of that protection. | ||
| * @param[in] detected If the Infection is detected. | ||
| */ | ||
| Infection(PersonalRandomNumberGenerator& rng, VirusVariant virus, AgeGroup age, const Parameters& params, | ||
| TimePoint init_date, InfectionState init_state, const InitialInfectionStateDistribution& init_state_dist, | ||
| ProtectionEvent latest_protection = {ProtectionType::NoProtection, TimePoint(0)}, bool detected = false); | ||
|
|
||
| /** | ||
| * @brief Gets the ViralLoad of the Infection at a given TimePoint. | ||
| * @param[in] t TimePoint of querry. | ||
| */ | ||
| ScalarType get_viral_load(TimePoint t) const; | ||
|
|
||
| /** | ||
| * @brief Get infectivity at a given time. | ||
| * @brief Get viral shed at a specific time. | ||
| * Computed depending on current ViralLoad and individual invlogit function of each Person | ||
| * corresponding to https://www.science.org/doi/full/10.1126/science.abi5273 | ||
| * The mapping corresponds to Fig. 2 C. | ||
| * Formula of invlogit function can be found here: | ||
| * https://github.com/VirologyCharite/SARS-CoV-2-VL-paper/tree/main | ||
| * in ExtendedMethods.html, Section 3.1.2.1. | ||
| * * Also in accordance to Fig. 3d of another publication: | ||
| * https://www.nature.com/articles/s41564-022-01105-z/figures/3 | ||
| * The result is in arbitrary units and has to be scaled to the rate "infections per day". | ||
| * @param[in] t TimePoint of the querry. | ||
| * @return Infectivity at given TimePoint. | ||
| * @return Viral shed at given TimePoint. | ||
| */ | ||
| ScalarType get_infectivity(TimePoint t) const; | ||
| ScalarType get_viral_shed(TimePoint t) const; | ||
|
|
||
| /** | ||
| * @brief: Get VirusVariant. | ||
|
|
@@ -133,7 +168,7 @@ class Infection | |
| .add("viral_load", m_viral_load) | ||
| .add("log_norm_alpha", m_log_norm_alpha) | ||
| .add("log_norm_beta", m_log_norm_beta) | ||
| .add("individual_virus_shed_factor", m_individual_virus_shed_factor) | ||
| .add("individual_viral_shed_factor", m_individual_viral_shed_factor) | ||
| .add("detected", m_detected); | ||
| } | ||
|
|
||
|
|
@@ -164,8 +199,7 @@ class Infection | |
| * InfectedSymptoms -> Infected_Severe or InfectedSymptoms -> Recovered, | ||
| * InfectedSevere -> InfectedCritical or InfectedSevere -> Recovered or InfectedSevere -> Dead, | ||
| * InfectedCritical -> Recovered or InfectedCritical -> Dead, | ||
| * with artifical, hardcoded probabilites, until either Recoverd or Dead is reached. | ||
| * This is subject to change when parameter distributions for these transitions are implemented. | ||
| * until either Recoverd or Dead is reached. | ||
| * The duration in each #InfectionState is taken from the respective parameter. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] age AgeGroup of the Person. | ||
|
|
@@ -192,12 +226,97 @@ class Infection | |
| TimePoint draw_infection_course_backward(PersonalRandomNumberGenerator& rng, AgeGroup age, const Parameters& params, | ||
| TimePoint init_date, InfectionState init_state); | ||
|
|
||
| /** | ||
| * @brief Initialize the viral load parameters for the infection. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] virus Virus type of the Infection. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @param[in] latest_protection Latest protection against Infection. | ||
| */ | ||
| void initialize_viral_load(PersonalRandomNumberGenerator& rng, VirusVariant virus, AgeGroup age, | ||
| const Parameters& params, ProtectionEvent latest_protection); | ||
|
|
||
| /** | ||
| * @brief Initialize the viral shed parameters and individual factor for the infection. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] virus Virus type of the Infection. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| */ | ||
| void initialize_viral_shed(PersonalRandomNumberGenerator& rng, VirusVariant virus, AgeGroup age, | ||
| const Parameters& params); | ||
|
|
||
| /** | ||
| * @brief Get the forward transition from a given infection state. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @param[in] current_state Current infection state. | ||
| * @param[in] current_time Current time point. | ||
| * @param[in] latest_protection Latest protection against Infection. | ||
| * @return StateTransition representing the next transition. | ||
| */ | ||
| StateTransition get_forward_transition(PersonalRandomNumberGenerator& rng, AgeGroup age, const Parameters& params, | ||
| InfectionState current_state, TimePoint current_time, | ||
| ProtectionEvent latest_protection) const; | ||
|
|
||
| /** | ||
| * @brief Get the backward transition from a given infection state. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @param[in] current_state Current infection state. | ||
| * @return StateTransition representing the previous transition. | ||
| */ | ||
| StateTransition get_backward_transition(PersonalRandomNumberGenerator& rng, AgeGroup age, const Parameters& params, | ||
| InfectionState current_state) const; | ||
|
|
||
| /** | ||
| * @brief Get the backward transition from recovered state. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @return StateTransition representing the transition that led to recovery. | ||
| */ | ||
| StateTransition get_recovered_backward_transition(PersonalRandomNumberGenerator& rng, AgeGroup age, | ||
| const Parameters& params) const; | ||
|
|
||
| /** | ||
| * @brief Get the backward transition from dead state. | ||
| * @param[inout] rng PersonalRandomNumberGenerator of the Person. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @return StateTransition representing the transition that led to death. | ||
| */ | ||
| StateTransition get_dead_backward_transition(PersonalRandomNumberGenerator& rng, AgeGroup age, | ||
| const Parameters& params) const; | ||
|
|
||
| /** | ||
| * @brief Calculate the overall death probability for the infection. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] params Parameters of the Model. | ||
| * @return The probability of death for this infection. | ||
| */ | ||
| ScalarType calculate_death_probability(AgeGroup age, const Parameters& params) const; | ||
|
|
||
| /** | ||
| * @brief Get the severity protection factor based on latest protection. | ||
| * @param[in] params Parameters of the Model. | ||
| * @param[in] latest_protection Latest protection against Infection. | ||
| * @param[in] age AgeGroup of the Person. | ||
| * @param[in] current_time Current time point. | ||
| * @return The protection factor against severe outcomes. | ||
| */ | ||
| ScalarType get_severity_protection_factor(const Parameters& params, ProtectionEvent latest_protection, AgeGroup age, | ||
| TimePoint current_time) const; | ||
|
|
||
| std::vector<std::pair<TimePoint, InfectionState>> m_infection_course; ///< Start date of each #InfectionState. | ||
| VirusVariant m_virus_variant; ///< Variant of the Infection. | ||
| ViralLoad m_viral_load; ///< ViralLoad of the Infection. | ||
| ScalarType m_log_norm_alpha, | ||
| m_log_norm_beta; ///< Parameters for the infectivity mapping, which is modelled through an invlogit function. | ||
| ScalarType m_individual_virus_shed_factor; ///< Individual virus shed factor. | ||
| m_log_norm_beta; ///< Parameters for the viral shed mapping, which is modelled through an invlogit function. | ||
| ScalarType m_individual_viral_shed_factor; ///< Individual viral shed factor. | ||
| bool m_detected; ///< Whether an Infection is detected or not. | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the probability in this object?