beta = 1  #Transmission coefficient
tau = .2  #infectious period. FIXED
tf = 36
y0 = [.999, 0.001, 0.0]


def model(theta):
    beta = theta[0]

    def sir(y, t):
        '''ODE model'''
        S, I, R = y
        return [-beta * I * S,  #dS/dt
                beta * I * S - tau * I,  #dI/dt
                tau * I]  #dR/dt

    y = odeint(sir, inits, np.arange(0, tf, 1))  #np.arange(t0,tf,step))
    return y


F = FitModel(300, model, y0, tf, ['beta'], ['S', 'I', 'R'],
             wl=36, nw=1, verbose=1, burnin=100)
F.set_priors(tdists=[st.norm], tpars=[(1.1, .2)], tlims=[(0.5, 1.5)],
             pdists=[st.uniform] * 3, ppars=[(0, .1), (0, .1), (.8, .2)], plims=[(0, 1)] * 3)
d = model([1.0])  #simulate some data
noise = st.norm(0, 0.01).rvs(36)
dt = {'I': d[:, 1] + noise}  # add noise
F.run(dt, 'MCMC', likvar=1e-5, pool=True, monitor=[])
#==Uncomment the line below to see plots of the results
F.plot_results()
示例#2
0
    ser = st.nanmean(series, axis=0)
    # print series.shape, ser.shape
    return ser


d = runModel([beta, alpha, sigma])
# ~ import pylab as P
# ~ P.plot(d)
# ~ P.show()

dt = {'S': d[:, 0], 'E': d[:, 1], 'I': d[:, 2], 'A': d[:, 3], 'R': d[:, 4]}
F = FitModel(900,
             runModel,
             inits,
             tf, ['beta', 'alpha', 'sigma'], ['S', 'E', 'I', 'A', 'R'],
             wl=140,
             nw=1,
             verbose=0,
             burnin=100)
F.set_priors(tdists=[st.uniform] * 3,
             tpars=[(0.00001, .0006), (.1, .5), (0.0006, 1)],
             tlims=[(0, .001), (.001, 1), (0, 1)],
             pdists=[st.uniform] * 5,
             ppars=[(0, 500)] * 5,
             plims=[(0, 500)] * 5)

F.run(dt, 'MCMC', likvar=1e1, pool=0, monitor=[])
# ~ print F.optimize(data=dt,p0=[0.1,.5,.1], optimizer='oo',tol=1e-55, verbose=1, plot=1)
# ==Uncomment the line below to see plots of the results
F.plot_results()
示例#3
0
    F = FitModel(1000,
                 model,
                 inits,
                 tf,
                 tnames,
                 pnames,
                 wl,
                 nw,
                 verbose=1,
                 burnin=200,
                 constraints=[])
    F.set_priors(tdists=nt * [st.beta],
                 tpars=tpars,
                 tlims=tlims,
                 pdists=[st.beta] * nph,
                 ppars=[(1, 1)] * nph,
                 plims=[(0, 1)] * nph)

    F.run(dt,
          'DREAM',
          likvar=1e-4,
          pool=False,
          ew=0,
          adjinits=False,
          dbname=modname,
          monitor=['I', 'S'])
    #~ print F.AIC, F.BIC, F.DIC
    #print F.optimize(data=dt,p0=[s0,s1,s2], optimizer='scipy',tol=1e-55, verbose=1, plot=1)
    F.plot_results(['S', 'I'], dbname=modname, savefigs=1)