-
Notifications
You must be signed in to change notification settings - Fork 0
/
infected.py
52 lines (33 loc) · 1.63 KB
/
infected.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
import itertools
import numpy as np
class Transmission(object):
""" A container for info related to transmission event """
def __init__(self, infection_id=None, village_id=None):
self.infection_id = infection_id
self.village_id = village_id
@property
def transmitter(self):
return self.infection_id if self.infection_id is not None else ''
class Infected(object):
""" An infected individual aware of its village context """
uid = itertools.count() # unique index generator
internal_contact_rate = 6.0
external_contact_rate = 0.5
def __init__(self, village):
self.ix = next(Infected.uid)
self.village = village
def transmit(self):
""" Challenge local and neighboring villages with infectious contacts """
transmitter_info = Transmission(self.ix, self.village.ix)
n_internal_challenged = np.random.poisson(self.internal_contact_rate)
self.village.challenge(n_internal_challenged, transmitter_info)
n_external_challenged = np.random.poisson(self.external_contact_rate)
if n_external_challenged == 0:
return
n_neighbors = len(self.village.neighbors)
if n_neighbors > 0:
neighbors_challenged = np.random.multinomial(n_external_challenged,
[1./n_neighbors]*n_neighbors)
for nv, nc in zip(self.village.neighbors, neighbors_challenged):
if nc > 0:
nv.challenge(nc, transmitter_info)