File: CustomModel_example.py

package info (click to toggle)
epigrass 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,924 kB
  • ctags: 790
  • sloc: python: 8,267; makefile: 5
file content (46 lines) | stat: -rw-r--r-- 1,773 bytes parent folder | download | duplicates (4)
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
# This is a custom model to used in place of Epigrass' built-in models. Custom
# models must always be on a file named CustomModel.py and contain at least 
# a function named Model. Both the File name and the function Names are case-sensitive,
# so be careful. Please refer to the manual for intructions on how to write your 
# own custom models.


##### Defining variable names to appear in the database
# Must be listed in the same order of variables they are returned by the model
vnames = ['Exposed','Infectious','Susceptible']

def Model(inits,simstep, totpop,theta=0, npass=0,bi={},bp={},values=()):
        """
        This function implements the SIR model
        - inits = (E,I,S)
        - theta = infectious individuals from neighbor sites
        """
        
        ##### Get state variables' current values
        if simstep == 1: #get initial values
            E,I,S = (bi['e'], bi['i'], bi['s'])
        else: # get last value
            E,I,S = inits
            
        ##### Defining N, the total population     
        N = totpop
        
        ##### Getting values for the model parameters
        beta,alpha,e,r,delta,B,w,p = (bp['beta'],bp['alpha'],bp['e'],bp['r'],bp['delta'],bp['b'],bp['w'],bp['p'])
        
        ##### Defining a Vacination event (optional)
        if bp['vaccineNow']:
            S -= bp['vaccov']*S
        
        ##### Modeling the number of new cases (incidence function)
        Lpos = beta*S*((I+theta)/(N+npass))**alpha #Number of new cases
        
        ##### Epidemiological model (SIR)
        Ipos = (1-r)*I + Lpos
        Spos = S + B - Lpos
        Rpos = N-(Spos+Ipos)

        # Number of infectious individuals commuting.
        migInf = Ipos
        
        return [0,Ipos,Spos], Lpos, migInf