0

This is about using cellular automata model to simulate the suspectible, infection, recovery population. I tried to plot a graph in jupyter notebook to find the daily infected population and recovery population across time. However, the code does not seem to work and returns "<Figure size 432x288 with 0 Axes>". May I know what's wrong with my code ?

Nr = 100; Nc = 100; T = 100 #number of row # number of columns
recovery = 7
N = Nr * Nc 
s = zeros((Nr, Nc)) #status
R = zeros((Nr, Nc)) #Recovery time recoverage stage

SP = zeros(T) #suspectible population
RP = zeros(T) #recovered
IP = zeros(T) #infected
NP = zeros(T) #new patient


sd = 0.3 #reduced prob for 30% of getting infected

for i in range(50): #50 people getting infected
    indr = randint(1,Nr-2) #initial infeceted population, avoid boundaries, top & bottom, left & right
    indc = randint(1,Nc-2) 
    s[indr,indc] = 1
    R[indr,indc] = 1


D = zeros((Nr, Nc)) #dummy space

for t in range(1,T):
    for i in range(Nc):
        for j in range(Nr):
            D[i,j] = s[i,j] # use dummy space to store status s

    for i in range(1, Nc-1):
        for j in range(1,Nr - 1): 
            
            if s[i,j] == 0: # me not infected
                num_inf = 0
                for n in [s[i+1,j],s[i-1,j],s[i,j+1],s[i,j-1]]:
                    if n==1: #all top, left, right, bottom infected
                        num_inf = num_inf + 1
                p = num_inf/4 * sd
                tmp = rand() #surrounding factors are random
                if tmp <=p: #other factors that affect if being infected
                    D[i,j] = 1; NP[t] = NP[t]+1 #D[i,j] = me get infected
                    R[i,j] = 1

            if s[i,j] == 1:
                R[i,j] = R[i,j] + 1 #increase recovery date
                R[i,j] = min(recovery, R[i,j])
            if R[i,j] == recovery:
                D[i,j] = 2
    for i in range(Nc):
        for j in range(Nr):
            s[i,j] = D[i,j] 
            
for p in range (T):
        if D[i,j]==2:
            plot(RP[p], T, 'bo') #recovered
        elif D[i,j]==1:
            plot(IP[p],T,'ro') #cumulative
        else:
            plot(SP[p],T,'go') #susceptible
            
clf()
plt.show()
    

0 Answers0