def fit(ser, tim):
    y = SEIR_functions.preprocessing(ser)
    x = SEIR_functions.finding_point(ser, tim, 'max')
    #x2=SEIR_functions.finding_point(ser,tim,'slope')
    #x=max(x1,x2)
    '''
    plt.plot(tim[:x],numpy.log(ser[:x]),'b-',label='orginal series')
    '''
    ser = ser[y:x]
    time = tim[y:x]
    '''s=SEIR_functions.fit(ser,time)
    plt.plot(time,SEIR_functions.y_sl(time,s[0],s[1]),'r-',label='fit fn')
    print s[0]
    z=SEIR_functions.Fitt(ser,time)
    print z[0]
    plt.plot(time,SEIR_functions.y_sl(time,z[0],z[1]),'g-',label='Fitt fn')'''

    sl = SEIR_functions.Rcode(time, ser)
    #--------------If needed to check fit
    '''
    plt.plot(time,SEIR_functions.y_sl(time,sl[1],sl[0]),'k-',label='R code')
    plt.legend(loc='best')
    plt.show()
    '''
    #-------------
    return sl
def sim_av(beta1, beta2, tr12, tr21, output):
    series_t1 = []
    series_t2 = []
    series_total = []
    time = []
    count = 0
    num_iter = 0
    while count <= 50:
        (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 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 fit(ser, time):
    y = SEIR_functions.preprocessing(ser)
    x = SEIR_functions.finding_point(ser, time, 'max')
    print np.log(ser)
    plt.plot(time[y:x], np.log(ser[y:x]), 'b-', label='orginal series')
    ser = ser[y:x]
    time = time[y:x]
    sl = SEIR_functions.Rcode(time, ser)
    plt.plot(time,
             SEIR_functions.y_sl(time, sl[1], sl[0]),
             'k-',
             label='R code')
    plt.legend(loc='best')
    plt.show()
    return sl
示例#4
0
def fit((ser, tim)):
    y = SEIR_functions.preprocessing(ser)
    x = SEIR_functions.finding_point(ser, tim, 'max')
    '''
    plt.plot(tim[:x],numpy.log(ser[:x]),'b-',label='orginal series')
    '''
    ser = ser[y:x]
    time = tim[y:x]
    sl = SEIR_functions.Rcode(time, ser)
    #--------------If needed to check fit
    '''
    plt.plot(time,SEIR_functions.y_sl(time,sl[1],sl[0]),'k-',label='R code')
    plt.legend(loc='best')
    plt.show()
    '''
    #-------------
    return sl[1]
示例#5
0
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)]
N2 = 10000
gamma = 0.1
sigma = 1
alpha = 1e-4
#e=0
#------ -------------------------------------------------------------------------------
tr_val = []
total_ro = []
std_ro = []

for e in [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]:
    count = 0
    r = []
    while count < 100:
        (t1ser, t2ser, totser, time) = sfunc.st_sim(beta1, beta2, lam, mu, N1,
                                                    N2, gamma, sigma, e, e,
                                                    alpha)
        '''
        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,alpha)
            if numpy.max(t1ser) > 0.1*N1 and 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)
示例#7
0
sigma=1
#e=0
#------ -------------------------------------------------------------------------------
tr_val=[]
total_ro=[]
std_ro=[]

for e in [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8]:
    count=0
    r=[]
    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')
        '''