def sim_av(beta1, beta2, tr12, tr21): series_t1 = [] series_t2 = [] series_total = [] time = [] count = 0 num_iter = 0 while count <= 100: (t1ser, t2ser, tot, tim) = SEIR_functions.st_sim(beta1, beta2, lam, mu, N1, N2, gamma, sigma, tr12, tr21) num_iter += 1 if numpy.max(t1ser) > 0.1 * N1 or numpy.max(t2ser) > 0.1 * N2: series_t1.append(t1ser) series_t2.append(t2ser) ''' plt.plot(tim,t1ser) plt.plot(tim,t2ser) plt.show() plt.plot(tim,numpy.log(t1ser)) plt.plot(tim,numpy.log(t2ser)) plt.show() ''' series_total.append(tot) time.append(tim) count += 1 # print "Averaging the iterations" avg_t1 = SEIR_functions.avg_ser(series_t1, time) avg_t2 = SEIR_functions.avg_ser(series_t2, time) avg_tot = SEIR_functions.avg_ser(series_total, time) tim_t1 = avg_t1[1] ser_t1 = avg_t1[0] tim_t2 = avg_t2[1] ser_t2 = avg_t2[0] tim_tot = avg_tot[1] ser_tot = avg_tot[0] print "Number of Iterations", num_iter #print "Size of the total series",(sys.getsizeof(series_total)/sys.maxsize)*100 #----If needed to check ''' plt.plot(tim_t1,ser_t1,'g',label='series1') plt.plot(tim_t2,ser_t2,'r',label='series2') plt.plot(tim_tot,ser_tot,'b',label='total') plt.legend(loc='best') plt.show() ''' #------------- return [(ser_t1, tim_t1), (ser_t2, tim_t2), (ser_tot, tim_tot)]
def sim_av_1(beta1, beta2, tr12, tr21, output): #series_t1=[] #series_t2=[] series_total = [] time = [] count = 0 num_iter = 0 while count <= 50: (t1ser, t2ser, tot, tim) = SIR_functions.st_sim(beta1, beta2, N1, N2, 0, gamma, 0, tr12, tr21, 0) num_iter += 1 if numpy.max(t1ser) > 0.1 * N1 and numpy.max(t2ser) > 0.1 * N2: #series_t1.append(t1ser) #series_t2.append(t2ser) ''' plt.plot(tim,t1ser) plt.plot(tim,t2ser) plt.show() plt.plot(tim,numpy.log(t1ser)) plt.plot(tim,numpy.log(t2ser)) plt.show() ''' series_total.append(tot) time.append(tim) count += 1 print "Number of Iterations", num_iter print "Averaging the iterations" #avg_t1=SEIR_functions.avg_ser(series_t1,time) #avg_t2=SEIR_functions.avg_ser(series_t2,time) avg_tot = SEIR_functions.avg_ser(series_total, time) #tim_t1=avg_t1[1] #ser_t1=avg_t1[0] #tim_t2=avg_t2[1] #ser_t2=avg_t2[0] tim_tot = avg_tot[1] ser_tot = avg_tot[0] print "Size of the total series", (sys.getsizeof(series_total) / sys.maxsize) * 100 #----If needed to check ''' plt.plot(tim_t1,ser_t1,'g',label='series1') plt.plot(tim_t2,ser_t2,'r',label='series2') plt.plot(tim_tot,ser_tot,'b',label='total') plt.legend(loc='best') plt.show() ''' #------------- #return [(ser_t1,tim_t1),(ser_t2,tim_t2),(ser_tot,tim_tot)] output.put([(ser_tot, tim_tot)]) print "Exiting"
def sim_av_1(tr21, beta1=0.8, beta2=1.5): tr12 = tr21 series_t1 = [] series_t2 = [] time = [] count = 0 while count <= 100: (t1ser, t2ser, tot, tim) = SIR_functions.st_sim(beta1, beta2, N1, N2, 0, gamma, 0, tr12, tr21, 0) series_t1.append(t1ser) series_t2.append(t2ser) time.append(tim) count += 1 print "Averaging the iterations" #pool=mp.Pool() #(avg_t1,avg_t2,avg_tot)=pool.map(multi_run_wrapper,[(series_t1,time),(series_t2,time)]) avg_t1 = SEIR_functions.avg_ser(series_t1, time) avg_t2 = SEIR_functions.avg_ser(series_t2, time) #avg_tot=SEIR_functions.avg_ser(series_total,time) tim_t1 = avg_t1[1] ser_t1 = avg_t1[0] tim_t2 = avg_t2[1] ser_t2 = avg_t2[0] #----If needed to check plt.clf() plt.plot(tim_t1, ser_t1, 'g', label='series1') plt.plot(tim_t2, ser_t2, 'r', label='series2') plt.legend(loc='best') plt.xlabel("Time") plt.ylabel("Number of people Infected") plt.title("SIR" + "$\epsilon =$" + str(tr12)) plt.legend(loc='best') plt.savefig('sir' + str(tr12) + '.png', format='png', orientation='landscape') plt.close() return [(ser_t1, tim_t1), (ser_t2, tim_t2)]
while count<50: avg_count=0 total_series=[] time_ser=[] while avg_count<20: (t1ser,t2ser,totser,time)=sfunc.st_sim(beta1,beta2,lam,mu,N1,N2,gamma,sigma,e,e) if numpy.max(t1ser) > 0.1*N1 or numpy.max(t2ser) > 0.1*N2: total_series.append(totser) time_ser.append(time) avg_count += 1 ''' plt.plot(time,t1ser) plt.plot(time,t2ser) plt.show() ''' (ser,time)=sfunc.avg_ser(total_series,time_ser) y=sfunc.preprocessing(ser) x=sfunc.finding_point(ser,time,method='max') ''' plt.plot(time[:x],numpy.log(ser[:x]),'b-',label='orginal series') ''' ser=ser[y:x] t=time[y:x] try: (intercept,slope,rsq)=sfunc.Rcode(t,ser) except: print "Error in fitting, passing on" rsq=0 if rsq>0.75: r.append(slope)