Skip to content

Commit a3e44a3

Browse files
committed
demographics
1 parent 6d9f1a6 commit a3e44a3

10 files changed

+1516
-995
lines changed

Epidemiology101.ipynb

+85-69
Large diffs are not rendered by default.

Epidemiology102.ipynb

+252-132
Large diffs are not rendered by default.

Epidemiology103.ipynb

+160-154
Large diffs are not rendered by default.

Epidemiology104.ipynb

+62-51
Large diffs are not rendered by default.

Epidemiology105.ipynb

+96-70
Large diffs are not rendered by default.

Epidemiology202.ipynb

+100-399
Large diffs are not rendered by default.

Epidemiology301.ipynb

+98-118
Large diffs are not rendered by default.

Epidemiology304.ipynb

+624
Large diffs are not rendered by default.

d4sci.mplstyle

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ figure.subplot.left: 0.08
4040
figure.subplot.right: 0.95
4141
figure.subplot.bottom: 0.07
4242
figure.figsize: 12.8, 8.8
43-
figure.dpi: 300
43+
figure.dpi: 70

old/EpiModel.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def add_spontaneous(self, source, target, rate):
7676
"""
7777
self.transitions.add_edge(source, target, rate=rate)
7878

79+
def add_birth_rate(self, rate):
80+
for comp in self.transitions.nodes():
81+
self.transitions.nodes[comp]['birth']=rate
82+
83+
def add_death_rate(self, rate):
84+
for comp in self.transitions.nodes():
85+
self.transitions.nodes[comp]['death']=rate
86+
7987
def add_vaccination(self, source, target, rate, start):
8088
"""
8189
Add a vaccination transition between two compartments
@@ -187,7 +195,19 @@ def _new_cases(self, population, time, pos):
187195

188196
diff[pos[source]] -= rate
189197
diff[pos[target]] += rate
190-
198+
199+
# Population dynamics
200+
for comp, data in self.transitions.nodes(data=True):
201+
comp_id = pos[comp]
202+
203+
if "birth" in data:
204+
births = population[comp_id]*data["birth"]
205+
diff[comp_id] += births
206+
207+
if "death" in data:
208+
deaths = population[comp_id]*data["death"]
209+
diff[comp_id] -= deaths
210+
191211
return diff
192212

193213
def plot(self, title=None, normed=True, **kwargs):
@@ -277,6 +297,7 @@ def simulate(self, timesteps, t_min=1, seasonality=None, **kwargs):
277297
N = np.sum(pop)
278298

279299

300+
# Disease dynamics
280301
for comp in comps:
281302
trans = list(self.transitions.edges(comp, data=True))
282303

@@ -286,6 +307,10 @@ def simulate(self, timesteps, t_min=1, seasonality=None, **kwargs):
286307
source = pos[comp]
287308
target = pos[node_j]
288309

310+
311+
if pop[source] == 0:
312+
continue
313+
289314
rate = data['rate']
290315

291316
if 'start' in data and data['start'] >= t:
@@ -317,6 +342,18 @@ def simulate(self, timesteps, t_min=1, seasonality=None, **kwargs):
317342
for i in range(len(delta)):
318343
new_pop[i] += delta[i]
319344

345+
# Population dynamics
346+
for comp, data in self.transitions.nodes(data=True):
347+
comp_id = pos[comp]
348+
349+
if "birth" in data:
350+
births = np.random.binomial(pop[comp_id], data["birth"])
351+
new_pop[comp_id] += births
352+
353+
if "death" in data:
354+
deaths = np.random.binomial(pop[comp_id], data["death"])
355+
new_pop[comp_id] -= deaths
356+
320357
values.append(new_pop)
321358

322359
values = np.array(values)

0 commit comments

Comments
 (0)