ax[i].text(0.97,0.03, r"$N_\mathrm{eff}=%d$" %(params['N'].value), transform=ax[i].transAxes, ha='right', va='bottom', bbox={'facecolor':'w','edgecolor':'w','pad':0} ) pl.xscale('log') pl.yscale('log') ylim = pl.gca().get_ylim() min_ylim = 10**np.floor(np.log(ylim[0])/np.log(10)) max_ylim = 10**np.ceil(np.log(ylim[1])/np.log(10)) if min_ylim < 1: min_ylim = 1 pl.ylim([min_ylim, max_ylim]) pl.xlim([1,35]) if _r < n_row-1: [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ] bp.strip_axis(pl.gca()) pl.gcf().tight_layout() pl.gcf().subplots_adjust(wspace=0.34,hspace=0.3) pl.gcf().savefig("model_fit_figures/quarantine_model_all_confirmed_fit_after_feb_11.png",dpi=300) pl.gcf().savefig("model_fit_figures/SI_Fig_03.png",dpi=300) if not loaded_fits: with open('fit_parameters/quarantined_model_all_provinces_after_feb_12.p','wb') as f: pickle.dump(fit_parameters,f) pl.show()
dtype=float), np.array(self.cascade_size, dtype=float) / self.N if __name__ == "__main__": from sixdegrees.utils import to_networkx_graph from sixdegrees import small_world_network, modular_hierarchical_network import sixdegrees as sixd from bfmplot import pl import netwulf B = 10 L = 3 N = B**L k = 10 mu = -0.8 thresholds = [0.1] * N initially_infected = np.arange(10) #G = to_networkx_graph(*modular_hierarchical_network(B,L,k,mu)) G = to_networkx_graph(*sixd.random_geometric_kleinberg_network(N, k, mu)) Thresh = ThreshModel(G, initially_infected, thresholds) t, a = Thresh.simulate() pl.plot(t, a) pl.ylim([0, 1]) pl.show()
(T_E, I, chi*QT*k0 , T_E, T_I), (T_E, E, chi*QT*k0 , T_E, T_E), #(T_E, S, chi*QT*k0 , T_E, Q), ]) model.set_initial_conditions({ S: int(N*(1 - 0.01)), I: int(N*(0.005)), E: int(N*(0.005)), }) print(model.y0, model.t0) ODE_result = model.integrate(t) for c, res in ODE_result.items(): pl.plot(t, res,label=c,lw=2,alpha=0.3) print(model.y0, model.t0) tt, MF_result = model.simulate(t[-1]) for c, res in MF_result.items(): pl.plot(tt, res,'--',label=c,lw=2,alpha=0.3) #pl.plot(t,label=c) pl.legend() pl.ylim([0,N]) pl.show()
n = 10**5 t = np.linspace(-6, 6, 800) density = np.array([edges(tt) for tt in t]).astype(float) k = (n - 1) * density fig = plt.figure(1, figsize=(8, 4)) ax = fig.add_subplot(1, 2, 1) ax.plot(t, density) plt.xlim(-3, 3) plt.xlabel(r'$t$') plt.ylabel(r'$1 - \Phi\left( t \right)$') ax = fig.add_subplot(1, 2, 2) ax.plot(t, k) plt.xlim(2.5, 4.5) plt.ylim(float((n - 1) * edges(4.5) * 0.9), float(1.1 * (n - 1) * edges(2.5))) ax.set_yscale('log') plt.xlabel(r'$t$') plt.ylabel(r'$E \left[ k \right]$') plt.savefig('figures/edges.pdf') ### variance plot n = 10**5 NMAX = 20 rho = np.linspace(0, 0.5, 200) k = 2**np.arange(0, 10, 2) k = np.array(k, dtype=float) variances = np.zeros((200, 5)) for i in range(200): for j in range(5):
pl.plot(t, res, label=C, lw=1.5, c=bp.colors[iC]) model.set_processes([ (S, I, alpha, I, I), (I, beta, R), (None, gamma, S), ]) result = model.integrate(t) for iC, (C, res) in enumerate(result.items()): pl.plot(t, res, c=bp.colors[iC], ls='-.') bp.strip_axis(pl.gca()) pl.xlim([0, 150]) pl.ylim([0, 1000]) pl.xlabel('time [days]') pl.ylabel('incidence') pl.legend() pl.gcf().tight_layout() pl.gcf().savefig('SIR_birth_model_reimports_zoom.png', dpi=300) pl.xlim([0, max(t)]) pl.ylim([0, max(result_sim['S'])]) pl.gcf().savefig('SIR_birth_model_reimports_all.png', dpi=300) pl.yscale('log') pl.ylim([min(result['I']), max(result_sim['S'])])
b = np.logspace(np.log10(1), np.log10(kmax + 10), 12) pl.hist(k, bins=np.arange(0, kmax, 5), density=True, alpha=1, align='mid', color=bp.brewer_qualitative[1], histtype='step') #pl.hist(k,bins=b,normed=True,alpha=0.5) p = pk(n, t, rho, kmax, X, W) pl.plot(np.arange(kmax), p, lw=1, c=bp.brewer_qualitative[2]) ax.set_yscale('log') #ax.set_xscale('log') #pl.xlim(-2,kmax+10) pl.ylim(10**-6, 0.5) ax.text(0.8, 0.95, '(b)', va='top', ha='left', transform=ax.transAxes) ax.set_xlabel('node degree $k$') ax.set_ylabel('probability density $p_k$') bp.strip_axis(ax) ### proteins print("loading", 'degree_sequences/out.reactome.degree_sequence', '...') k = np.loadtxt('degree_sequences/out.reactome.degree_sequence') k = np.array(k, dtype=int) kmax = np.max(k) + 1 n = len(k) print("fitting...") t = solve_t(np.mean(k), n)
N = pdata['population'] / 1e6 print(p['kappa0'],p['kappa']) Q = (k+k0)/(b+k+k0) P = k0/(k+k0) R0eff = a / (b+k+k0) tabledata.append([titlemap[province], N, Q, P, R0eff, k, k0, I0f, ]) ks.append(k) k0s.append(k0) for i, (_k0, _ks) in enumerate(zip(k0s, ks)): pl.plot([_k0],[_ks],marker=markers[i],color=colors[i],markersize=7) pl.xlim([0,0.14]) pl.ylim([-.05,0.55]) pl.gcf().savefig('model_fit_figures/'+fn+'.png',dpi=300) pl.show() headers = [ 'Province', '$N/10^6$','$Q$', '$P$', '$R_{0,\mathrm{eff}}$', '$\kappa$ [$\mathrm{d}^{-1}$]', '$\kappa_{0}$ [$\mathrm{d}^{-1}$]', '$I_0/X_0$', ] floatfmt = ( "",