aegis_sim.submodels.infection

Infection manager

Infection status: 0 .. susceptible 1 .. infected -1 .. dead

 1"""Infection manager
 2
 3Infection status:
 4    0 .. susceptible
 5    1 .. infected
 6    -1 .. dead
 7"""
 8
 9import math
10import numpy as np
11from aegis_sim import variables
12
13
14class Infection:
15    """
16
17    GUI
18    Infection is an optional source of mortality.
19    [[FATALITY_RATE]] specifies how deadly the infection is; thus if set to 0, no deaths from infection will occur.
20    The infection modeling is inspired by the SIR (susceptible-infectious-removed) model.
21
22    Individuals cannot gain immunity, thus can get reinfected many times.
23    The probability to die from an infection is constant as long as the individual is infected; there is no incubation period nor disease progression.
24    The same is true for recovering from the disease, which is equal to [[RECOVERY_RATE]].
25
26    Both of these are independent of age and genetics.
27
28    The infectious agent can be transmitted from an individual to an individual but can also be contracted from the environment (and can therefore not be fully eradicated).
29    The probability to acquire the infection from the environment is equal to [[BACKGROUND_INFECTIVITY]], and from other infected individuals it grows with [[TRANSMISSIBILITY]]
30    but also (logistically) with the proportion of the infected population.
31    """
32
33    def __init__(self, BACKGROUND_INFECTIVITY, TRANSMISSIBILITY, RECOVERY_RATE, FATALITY_RATE):
34        self.BACKGROUND_INFECTIVITY = BACKGROUND_INFECTIVITY
35        self.TRANSMISSIBILITY = TRANSMISSIBILITY
36        self.RECOVERY_RATE = RECOVERY_RATE
37        self.FATALITY_RATE = FATALITY_RATE
38
39    def get_infection_probability(self, infection_density):
40        return self.BACKGROUND_INFECTIVITY - 0.5 + 1 / (1 + math.exp(-self.TRANSMISSIBILITY * infection_density))
41
42    def __call__(self, population):
43        """
44        First try infecting susceptible.
45        """
46
47        # TODO Do not change population here, only return new status
48
49        if len(population) == 0:
50            return
51
52        probs = variables.rng.random(len(population))
53
54        # current status
55        infected = population.infection == 1
56        susceptible = population.infection == 0
57
58        # compute infection probability
59        infection_density = infected.sum() / len(population)
60        infection_probability = self.get_infection_probability(infection_density=infection_density)
61
62        # recoveries from old infections
63        population.infection[infected & (probs < self.RECOVERY_RATE)] = 0
64
65        # fatalities
66        # overrides recoveries
67        population.infection[infected & (probs < self.FATALITY_RATE)] = -1
68
69        # new infections
70        population.infection[susceptible & (probs < infection_probability)] = 1
class Infection:
15class Infection:
16    """
17
18    GUI
19    Infection is an optional source of mortality.
20    [[FATALITY_RATE]] specifies how deadly the infection is; thus if set to 0, no deaths from infection will occur.
21    The infection modeling is inspired by the SIR (susceptible-infectious-removed) model.
22
23    Individuals cannot gain immunity, thus can get reinfected many times.
24    The probability to die from an infection is constant as long as the individual is infected; there is no incubation period nor disease progression.
25    The same is true for recovering from the disease, which is equal to [[RECOVERY_RATE]].
26
27    Both of these are independent of age and genetics.
28
29    The infectious agent can be transmitted from an individual to an individual but can also be contracted from the environment (and can therefore not be fully eradicated).
30    The probability to acquire the infection from the environment is equal to [[BACKGROUND_INFECTIVITY]], and from other infected individuals it grows with [[TRANSMISSIBILITY]]
31    but also (logistically) with the proportion of the infected population.
32    """
33
34    def __init__(self, BACKGROUND_INFECTIVITY, TRANSMISSIBILITY, RECOVERY_RATE, FATALITY_RATE):
35        self.BACKGROUND_INFECTIVITY = BACKGROUND_INFECTIVITY
36        self.TRANSMISSIBILITY = TRANSMISSIBILITY
37        self.RECOVERY_RATE = RECOVERY_RATE
38        self.FATALITY_RATE = FATALITY_RATE
39
40    def get_infection_probability(self, infection_density):
41        return self.BACKGROUND_INFECTIVITY - 0.5 + 1 / (1 + math.exp(-self.TRANSMISSIBILITY * infection_density))
42
43    def __call__(self, population):
44        """
45        First try infecting susceptible.
46        """
47
48        # TODO Do not change population here, only return new status
49
50        if len(population) == 0:
51            return
52
53        probs = variables.rng.random(len(population))
54
55        # current status
56        infected = population.infection == 1
57        susceptible = population.infection == 0
58
59        # compute infection probability
60        infection_density = infected.sum() / len(population)
61        infection_probability = self.get_infection_probability(infection_density=infection_density)
62
63        # recoveries from old infections
64        population.infection[infected & (probs < self.RECOVERY_RATE)] = 0
65
66        # fatalities
67        # overrides recoveries
68        population.infection[infected & (probs < self.FATALITY_RATE)] = -1
69
70        # new infections
71        population.infection[susceptible & (probs < infection_probability)] = 1

GUI Infection is an optional source of mortality. [[FATALITY_RATE]] specifies how deadly the infection is; thus if set to 0, no deaths from infection will occur. The infection modeling is inspired by the SIR (susceptible-infectious-removed) model.

Individuals cannot gain immunity, thus can get reinfected many times. The probability to die from an infection is constant as long as the individual is infected; there is no incubation period nor disease progression. The same is true for recovering from the disease, which is equal to [[RECOVERY_RATE]].

Both of these are independent of age and genetics.

The infectious agent can be transmitted from an individual to an individual but can also be contracted from the environment (and can therefore not be fully eradicated). The probability to acquire the infection from the environment is equal to [[BACKGROUND_INFECTIVITY]], and from other infected individuals it grows with [[TRANSMISSIBILITY]] but also (logistically) with the proportion of the infected population.

Infection( BACKGROUND_INFECTIVITY, TRANSMISSIBILITY, RECOVERY_RATE, FATALITY_RATE)
34    def __init__(self, BACKGROUND_INFECTIVITY, TRANSMISSIBILITY, RECOVERY_RATE, FATALITY_RATE):
35        self.BACKGROUND_INFECTIVITY = BACKGROUND_INFECTIVITY
36        self.TRANSMISSIBILITY = TRANSMISSIBILITY
37        self.RECOVERY_RATE = RECOVERY_RATE
38        self.FATALITY_RATE = FATALITY_RATE
BACKGROUND_INFECTIVITY
TRANSMISSIBILITY
RECOVERY_RATE
FATALITY_RATE
def get_infection_probability(self, infection_density):
40    def get_infection_probability(self, infection_density):
41        return self.BACKGROUND_INFECTIVITY - 0.5 + 1 / (1 + math.exp(-self.TRANSMISSIBILITY * infection_density))