t, series, steps, events = M.getStats() 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()
wl = fim - inicio nw = 1 tpars = [(1, 1), (0, 5e-6), (.9999, .0002)] tlims = [(0, 1), (0, 5e-6), (.9999, 1.0001)] inits = [1 - dt['I'][0], dt['I'][0], 0] dt2 = copy.deepcopy(dt) # print inits F = FitModel(5000, model, inits, fim - inicio, tnames, pnames, wl, nw, verbose=1, burnin=1000, constraints=[]) F.set_priors(tdists=[st.beta, st.uniform, st.uniform], tpars=tpars, tlims=tlims, pdists=[st.beta] * nph, ppars=[(1, 1)] * nph, plims=[(0, 1)] * nph) F.run(dt, 'DREAM', likvar=1e-9,
P.vlines(t0s, 0, top, colors='g') P.vlines(tfs, 0, top, colors='r') P.legend([pnames[1]]) P.show() #Priors and limits for all countries tpars = [ (2, 1) ] * nt #[(1, 2),(1, 2),(1, 2),(1, 2),(1, 2), (2, 1),(1, 2),(1, 2), (2, 1), (1, 2),] tlims = [(0, 1)] * nt 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,
'''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()
propf = (f1, f2, f3, f4, f5) tmat = np.array([[-1, 0, 0, 0, 0], [1, -1, 0, -1, 0], [0, 1, -1, 0, 0], [0, 0, 0, 1, -1], [0, 0, 1, 0, 1] ]) M = Model(vnames=vnames, rates=r, inits=inits, tmat=tmat, propensity=propf) #t0 = time.time() M.run(tmax=tf, reps=1, viz=0, serial=True) t, series, steps, events = M.getStats() ser = st.nanmean(series, axis=0) #print series.shape return ser d = runModel([beta, alpha, sigma]) dt = {'S': d[:, 0], 'E': d[:, 1], 'I': d[:, 2], 'A': d[:, 3], 'R': d[:, 4]} F = FitModel(300, runModel, inits, tf, ['beta', 'alpha', 'sigma'], ['S', 'E', 'I', 'A', 'R'], wl=7, nw=20, verbose=True, 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()