Skip to content

Transmission xnexp

TransmissionXNExp

Bases: Transmission

Source code in june/epidemiology/infection/transmission_xnexp.py
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
class TransmissionXNExp(Transmission):
    """ """
    __slots__ = (
        "time_first_infectious",
        "norm_time",
        "n",
        "alpha",
        "norm",
        "probability",
    )

    def __init__(
        self,
        max_probability: float = 1.0,
        time_first_infectious: float = 2.6,
        norm_time: float = 1.0,
        n: float = 1.0,
        alpha: float = 5.0,
        max_symptoms: str = None,
        asymptomatic_infectious_factor: float = None,
        mild_infectious_factor: float = None,
    ):
        """
        Class that defines the time profile of the infectiousness to be of the form x^n exp(-x/alpha)

        Parameters
        ----------
        max_probability:
            value of the infectiousness at its peak. Used to control the number of super spreaders
        time_first_infectious:
            time at which the person becomes infectious
        norm_time:
            controls the definition of x, x = (time_from_infection - time-first_infectious)/norm_time
        n:
            exponent of x in the x^n exp(-x/alpha) function
        alpha:
            denominator in exponential
        max_symptoms:
            maximum symptoms that the person will ever have, used to lower the infectiousness of
            asymptomatic and mild cases
        asymptomatic_infectious_factor:
            multiplier that lowers the infectiousness of asymptomatic cases
        mild_infectious_factor:
            multiplier that lowers the infectiousness of mild cases

        """
        self.time_first_infectious = time_first_infectious
        self.norm_time = norm_time
        self.n = n
        self.alpha = alpha
        max_delta_time = self.n * self.alpha * self.norm_time
        max_tau = max_delta_time / self.norm_time
        self.norm = max_probability / xnexp(max_tau, self.n, self.alpha)
        self._modify_infectiousness_for_symptoms(
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )
        self.probability = 0.0

    @classmethod
    def from_file(
        cls,
        time_first_infectious: float,
        n: float,
        alpha: float,
        max_symptoms: "SymptomTag" = None,
        config_path: str = default_config_path,
    ) -> "TransmissionXNExp":
        """Generates transmission class from config file

        Args:
            time_first_infectious (float): time at which the person becomes infectious
            n (float): exponent of x in the x^n exp(-x/alpha) function
            alpha (float): denominator in exponential
            max_symptoms ("SymptomTag", optional): maximum symptoms that the person will ever have, used to lower the infectiousness of
        asymptomatic and mild cases (Default value = None)
            config_path (str, optional): (Default value = default_config_path)

        """
        with open(config_path) as f:
            config = yaml.safe_load(f)
        max_probability = CompletionTime.from_dict(config["max_probability"])()
        norm_time = CompletionTime.from_dict(config["norm_time"])()
        asymptomatic_infectious_factor = CompletionTime.from_dict(
            config["asymptomatic_infectious_factor"]
        )()
        mild_infectious_factor = CompletionTime.from_dict(
            config["mild_infectious_factor"]
        )()
        return TransmissionXNExp(
            max_probability=max_probability,
            time_first_infectious=time_first_infectious,
            norm_time=norm_time,
            n=n,
            alpha=alpha,
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )

    @classmethod
    def from_file_linked_symptoms(
        cls,
        time_to_symptoms_onset: float,
        max_symptoms: "SymptomTag" = None,
        config_path: str = default_config_path,
    ) -> "TransmissionXNExp":
        """Generates transmission class from config file

        Args:
            time_to_symptoms_onset (float): 
            max_symptoms ("SymptomTag", optional): maximum symptoms that the person will ever have, used to lower the infectiousness of
        asymptomatic and mild cases (Default value = None)
            config_path (str, optional): (Default value = default_config_path)

        """
        with open(config_path) as f:
            config = yaml.safe_load(f)
        smearing_time_first_infectious = CompletionTime.from_dict(
            config["smearing_time_first_infectious"]
        )()
        time_first_infectious = time_to_symptoms_onset + smearing_time_first_infectious
        smearing_peak_position = CompletionTime.from_dict(
            config["smearing_peak_position"]
        )()
        alpha = CompletionTime.from_dict(config["alpha"])()
        peak_position = (
            time_to_symptoms_onset - time_first_infectious + smearing_peak_position
        )
        n = peak_position / alpha
        max_probability = CompletionTime.from_dict(config["max_probability"])()
        norm_time = CompletionTime.from_dict(config["norm_time"])()
        asymptomatic_infectious_factor = CompletionTime.from_dict(
            config["asymptomatic_infectious_factor"]
        )()
        mild_infectious_factor = CompletionTime.from_dict(
            config["mild_infectious_factor"]
        )()
        return TransmissionXNExp(
            max_probability=max_probability,
            time_first_infectious=time_first_infectious,
            norm_time=norm_time,
            n=n,
            alpha=alpha,
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )

    def update_infection_probability(self, time_from_infection: float):
        """Performs a probability update given time from infection

        Args:
            time_from_infection (float): time elapsed since person became infected (in days).

        """
        self.probability = update_probability(
            time_from_infection,
            self.time_first_infectious,
            self.norm,
            self.norm_time,
            self.alpha,
            self.n,
        )

    def _modify_infectiousness_for_symptoms(
        self, max_symptoms: str, asymptomatic_infectious_factor, mild_infectious_factor
    ):
        """Lowers the infectiousness of asymptomatic and mild cases, by modifying
        self.norm

        Args:
            max_symptoms (str): maximum symptom severity the person will ever have
            asymptomatic_infectious_factor: 
            mild_infectious_factor: 

        """
        if (
            asymptomatic_infectious_factor is not None
            and max_symptoms == "asymptomatic"
        ):
            self.norm *= asymptomatic_infectious_factor
        elif mild_infectious_factor is not None and max_symptoms == "mild":
            self.norm *= mild_infectious_factor

__init__(max_probability=1.0, time_first_infectious=2.6, norm_time=1.0, n=1.0, alpha=5.0, max_symptoms=None, asymptomatic_infectious_factor=None, mild_infectious_factor=None)

Class that defines the time profile of the infectiousness to be of the form x^n exp(-x/alpha)

Parameters

max_probability: value of the infectiousness at its peak. Used to control the number of super spreaders time_first_infectious: time at which the person becomes infectious norm_time: controls the definition of x, x = (time_from_infection - time-first_infectious)/norm_time n: exponent of x in the x^n exp(-x/alpha) function alpha: denominator in exponential max_symptoms: maximum symptoms that the person will ever have, used to lower the infectiousness of asymptomatic and mild cases asymptomatic_infectious_factor: multiplier that lowers the infectiousness of asymptomatic cases mild_infectious_factor: multiplier that lowers the infectiousness of mild cases

Source code in june/epidemiology/infection/transmission_xnexp.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def __init__(
    self,
    max_probability: float = 1.0,
    time_first_infectious: float = 2.6,
    norm_time: float = 1.0,
    n: float = 1.0,
    alpha: float = 5.0,
    max_symptoms: str = None,
    asymptomatic_infectious_factor: float = None,
    mild_infectious_factor: float = None,
):
    """
    Class that defines the time profile of the infectiousness to be of the form x^n exp(-x/alpha)

    Parameters
    ----------
    max_probability:
        value of the infectiousness at its peak. Used to control the number of super spreaders
    time_first_infectious:
        time at which the person becomes infectious
    norm_time:
        controls the definition of x, x = (time_from_infection - time-first_infectious)/norm_time
    n:
        exponent of x in the x^n exp(-x/alpha) function
    alpha:
        denominator in exponential
    max_symptoms:
        maximum symptoms that the person will ever have, used to lower the infectiousness of
        asymptomatic and mild cases
    asymptomatic_infectious_factor:
        multiplier that lowers the infectiousness of asymptomatic cases
    mild_infectious_factor:
        multiplier that lowers the infectiousness of mild cases

    """
    self.time_first_infectious = time_first_infectious
    self.norm_time = norm_time
    self.n = n
    self.alpha = alpha
    max_delta_time = self.n * self.alpha * self.norm_time
    max_tau = max_delta_time / self.norm_time
    self.norm = max_probability / xnexp(max_tau, self.n, self.alpha)
    self._modify_infectiousness_for_symptoms(
        max_symptoms=max_symptoms,
        asymptomatic_infectious_factor=asymptomatic_infectious_factor,
        mild_infectious_factor=mild_infectious_factor,
    )
    self.probability = 0.0

from_file(time_first_infectious, n, alpha, max_symptoms=None, config_path=default_config_path) classmethod

Generates transmission class from config file

Parameters:

Name Type Description Default
time_first_infectious float

time at which the person becomes infectious

required
n float

exponent of x in the x^n exp(-x/alpha) function

required
alpha float

denominator in exponential

required
max_symptoms SymptomTag

maximum symptoms that the person will ever have, used to lower the infectiousness of

None

asymptomatic and mild cases (Default value = None) config_path (str, optional): (Default value = default_config_path)

Source code in june/epidemiology/infection/transmission_xnexp.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@classmethod
def from_file(
    cls,
    time_first_infectious: float,
    n: float,
    alpha: float,
    max_symptoms: "SymptomTag" = None,
    config_path: str = default_config_path,
) -> "TransmissionXNExp":
    """Generates transmission class from config file

    Args:
        time_first_infectious (float): time at which the person becomes infectious
        n (float): exponent of x in the x^n exp(-x/alpha) function
        alpha (float): denominator in exponential
        max_symptoms ("SymptomTag", optional): maximum symptoms that the person will ever have, used to lower the infectiousness of
    asymptomatic and mild cases (Default value = None)
        config_path (str, optional): (Default value = default_config_path)

    """
    with open(config_path) as f:
        config = yaml.safe_load(f)
    max_probability = CompletionTime.from_dict(config["max_probability"])()
    norm_time = CompletionTime.from_dict(config["norm_time"])()
    asymptomatic_infectious_factor = CompletionTime.from_dict(
        config["asymptomatic_infectious_factor"]
    )()
    mild_infectious_factor = CompletionTime.from_dict(
        config["mild_infectious_factor"]
    )()
    return TransmissionXNExp(
        max_probability=max_probability,
        time_first_infectious=time_first_infectious,
        norm_time=norm_time,
        n=n,
        alpha=alpha,
        max_symptoms=max_symptoms,
        asymptomatic_infectious_factor=asymptomatic_infectious_factor,
        mild_infectious_factor=mild_infectious_factor,
    )

from_file_linked_symptoms(time_to_symptoms_onset, max_symptoms=None, config_path=default_config_path) classmethod

Generates transmission class from config file

Parameters:

Name Type Description Default
time_to_symptoms_onset float
required
max_symptoms SymptomTag

maximum symptoms that the person will ever have, used to lower the infectiousness of

None

asymptomatic and mild cases (Default value = None) config_path (str, optional): (Default value = default_config_path)

Source code in june/epidemiology/infection/transmission_xnexp.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
@classmethod
def from_file_linked_symptoms(
    cls,
    time_to_symptoms_onset: float,
    max_symptoms: "SymptomTag" = None,
    config_path: str = default_config_path,
) -> "TransmissionXNExp":
    """Generates transmission class from config file

    Args:
        time_to_symptoms_onset (float): 
        max_symptoms ("SymptomTag", optional): maximum symptoms that the person will ever have, used to lower the infectiousness of
    asymptomatic and mild cases (Default value = None)
        config_path (str, optional): (Default value = default_config_path)

    """
    with open(config_path) as f:
        config = yaml.safe_load(f)
    smearing_time_first_infectious = CompletionTime.from_dict(
        config["smearing_time_first_infectious"]
    )()
    time_first_infectious = time_to_symptoms_onset + smearing_time_first_infectious
    smearing_peak_position = CompletionTime.from_dict(
        config["smearing_peak_position"]
    )()
    alpha = CompletionTime.from_dict(config["alpha"])()
    peak_position = (
        time_to_symptoms_onset - time_first_infectious + smearing_peak_position
    )
    n = peak_position / alpha
    max_probability = CompletionTime.from_dict(config["max_probability"])()
    norm_time = CompletionTime.from_dict(config["norm_time"])()
    asymptomatic_infectious_factor = CompletionTime.from_dict(
        config["asymptomatic_infectious_factor"]
    )()
    mild_infectious_factor = CompletionTime.from_dict(
        config["mild_infectious_factor"]
    )()
    return TransmissionXNExp(
        max_probability=max_probability,
        time_first_infectious=time_first_infectious,
        norm_time=norm_time,
        n=n,
        alpha=alpha,
        max_symptoms=max_symptoms,
        asymptomatic_infectious_factor=asymptomatic_infectious_factor,
        mild_infectious_factor=mild_infectious_factor,
    )

update_infection_probability(time_from_infection)

Performs a probability update given time from infection

Parameters:

Name Type Description Default
time_from_infection float

time elapsed since person became infected (in days).

required
Source code in june/epidemiology/infection/transmission_xnexp.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def update_infection_probability(self, time_from_infection: float):
    """Performs a probability update given time from infection

    Args:
        time_from_infection (float): time elapsed since person became infected (in days).

    """
    self.probability = update_probability(
        time_from_infection,
        self.time_first_infectious,
        self.norm,
        self.norm_time,
        self.alpha,
        self.n,
    )

update_probability(time_from_infection, time_first_infectious, norm, norm_time, alpha, n)

Determines how the infectiousness profile is updated over time

Parameters:

Name Type Description Default
time_from_infection float

time from infection

required
time_first_infectious float

time from infection at which the person becomes infectious

required
norm float

multiplier to the infectiousness profile

required
norm_time float

controls the definition of tau

required
alpha float

demominator in exponential for xnexp function

required
n float

exponent of x in xnexp

required
Source code in june/epidemiology/infection/transmission_xnexp.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@nb.jit(nopython=True)
def update_probability(
    time_from_infection: float,
    time_first_infectious: float,
    norm: float,
    norm_time: float,
    alpha: float,
    n: float,
) -> float:
    """Determines how the infectiousness profile is updated over time

    Args:
        time_from_infection (float): time from infection
        time_first_infectious (float): time from infection at which the person becomes infectious
        norm (float): multiplier to the infectiousness profile
        norm_time (float): controls the definition of tau
        alpha (float): demominator in exponential for xnexp function
        n (float): exponent of x in xnexp

    """

    if time_from_infection > time_first_infectious:
        delta_tau = (time_from_infection - time_first_infectious) / norm_time
        return norm * xnexp(x=delta_tau, n=n, alpha=alpha)
    else:
        return 0.0

xnexp(x, n, alpha)

Implementation of x^n exp(-x/alpha)

Parameters:

Name Type Description Default
x float

x variable

required
n float

exponent of x

required
alpha float

denominator in exponential

required
Source code in june/epidemiology/infection/transmission_xnexp.py
14
15
16
17
18
19
20
21
22
23
24
@nb.jit(nopython=True)
def xnexp(x: float, n: float, alpha: float) -> float:
    """Implementation of x^n exp(-x/alpha)

    Args:
        x (float): x variable
        n (float): exponent of x
        alpha (float): denominator in exponential

    """
    return x**n * np.exp(-x / alpha)