1
2
3
4
5
6
7
8
9
10
11
12
13 __docformat__ = "restructuredtext en"
14 """
15 Example of an SEIR model with two Infectious classes: subclinical(Is) and clinical(Ic)
16 Is
17 / \
18 S -> E R
19 \ /
20 Ic
21
22 States:
23 S: Susceptible
24 E: Exposed
25 Is: Infectious subclinical
26 Ic: Infectious clinical
27 R: Recovered
28
29 Transition rates:
30 b,ks,kc,rs,rc = (0.001, 0.1, 0.1, 0.01, .01)
31 Transitions:
32 S -> E : b*S*(Is+Ic)
33 E -> Is : ks*E
34 E -> Ic : kc*E
35 Is -> R : rs*Is
36 Ic -> R : rc*Ic
37
38 """
39 from gillespie import Model
40 import time
41
42 from numpy import array
43 vnames = ['S','E','Is','Ic','R']
44
45
46 r = (0.001, 0.1, 0.1, 0.01, .01)
47 ini = (490,0,0,10,0)
48
50 -def f2(r,ini):return r[1]*ini[1]
51 -def f3(r,ini):return r[2]*ini[1]
52 -def f4(r,ini):return r[3]*ini[2]
53 -def f5(r,ini):return r[4]*ini[3]
54
55 propf = (f1,f2,f3,f4,f5)
56
57 tmat = array([[-1, 0, 0, 0, 0],
58 [ 1,-1,-1, 0, 0],
59 [ 0, 1, 0,-1, 0],
60 [ 0, 0, 1, 0,-1],
61 [ 0, 0, 0, 1, 1]])
62 M=Model(vnames=vnames,rates = r,inits=ini,tmat=tmat,propensity=propf)
63 t0 = time.time()
64 M.run(tmax=80,reps=100,viz=0,serial=True)
65 print 'total time: ',time.time()-t0, ' seconds.'
66 t,series,steps = M.getStats()
67 print steps,'steps'
68
69 from pylab import plot , show, legend, errorbar
70
71 plot(t,series.mean(axis=0),'-o')
72 legend(vnames,loc=0)
73 show()
74