def sin_test(n=8,text_position='start'): """Test the stuff from the modules""" from bfmplot import pl import bfmplot as bp import numpy as np #bp.set_color_cycle(bp.cccs_colors) #pl.figure(figsize=bp.phys_rev_column()) pl.figure(figsize=bp.golden_ratio(5)) x = np.linspace(1,5*np.pi,100) for i in range(n): pl.plot(x, 1-np.sin(x[::-1]/np.sqrt(i+1)), marker=bp.markers[i],mfc='w',label='$i=%d$'%i) bp.strip_axis(pl.gca()) leg = pl.legend() bp.align_legend_right(leg) bp.arrow(pl.gca(), r'$i$', (3, 1.8), (6, 0.8), text_position=text_position) pl.xlabel('hello') pl.ylabel('hello') bp.set_n_ticks(pl.gca(), 3, 2) #pl.xscale('log') pl.gcf().tight_layout()
def sin_test(n=8,text_position='start'): pl.figure(figsize=bp.golden_ratio(5)) x = np.linspace(0,5*np.pi,100) for i in range(n): pl.plot(x, 1-np.sin(x[::-1]/np.sqrt(i+1)), marker=bp.markers[i],mfc='w',label='$i=%d$'%i) bp.strip_axis(pl.gca()) leg = pl.legend() bp.align_legend_right(leg) bp.arrow(pl.gca(), r'$i$', (14, 0.8), (10, 0.15), text_position=text_position, rad=0.3) pl.xlabel('this is the x-label') pl.ylabel('this is the y-label') pl.gcf().tight_layout()
def sin_test(n=8, text_position='start', with_legend=True): pl.figure(figsize=bp.golden_ratio(5)) x = np.linspace(0, 5 * np.pi, 100) for i in range(n): pl.plot(x, 1 - np.sin(x[::-1] / np.sqrt(i + 1)), marker=bp.markers[i], mfc='w', label='$i=%d$' % i) bp.strip_axis(pl.gca()) if with_legend: leg = pl.legend() bp.align_legend_right(leg) pl.xlabel('this is the x-label') pl.ylabel('this is the y-label') pl.gca().set_title(name) pl.gcf().tight_layout()
k1 = [] #np_edges = T.get_n_edge_lists(500) for meas in range(N_meas): edges = get_fast_edge_list(N, covariance, t) ks = get_degrees_from_edge_list(N, edges).tolist() k1.extend(ks) k1 = np.array(k1, dtype=int) k1pos = k1[k1 >= 1] import powerlaw results = powerlaw.Fit(k1pos, discrete=True, xmin=1) fig = pl.figure() powerlaw.plot_ccdf(k1pos) #powerlaw.plot_pdf(k1) #pl.hist(k1,bins=np.arange(1,max(k1)+1),histtype='step',density=True) x = np.arange(1, max(k1pos)) results.lognormal.plot_ccdf(ax=pl.gca()) #results.lognormal.plot_pdf(ax=pl.gca()) pl.xscale('log') pl.yscale('log') fig = pl.figure() pl.hist( k1, bins=np.arange(max(k1) + 1), histtype='step',
expected_counts[model.get_compartment_id(C0)] = N_measurements * ((N-1)*rateA / (rateB + rateE + rateA) * probAC0) expected_counts[model.get_compartment_id(C1)] = N_measurements * ((N-1)*rateA / (rateB + rateE + rateA) * probAC1) expected_counts[model.get_compartment_id(D)] = N_measurements * ((N-1)*rateB / (rateB + rateE + rateA) * probBD) expected_counts[model.get_compartment_id(F)] = (N-1) * expected_counts[model.get_compartment_id(E)] expected_counts[model.get_compartment_id(S)] = N_measurements * N - expected_counts.sum() pl.bar(x+width/2, expected_counts, width) pl.xticks(x) pl.gca().set_xticklabels(model.compartments) pl.figure() ndx = np.where(expected_counts==0) counts[ndx] = 1 expected_counts[ndx] = 1 pl.plot(x, np.abs(1-counts/expected_counts)) from scipy.stats import entropy _counts = np.delete(counts,1) _exp_counts = np.delete(expected_counts,1) print(entropy(_counts, _exp_counts)) pl.show()
# I (kappa)-> Q (I, quarantine_rate, Q), ]) I0 = 0.01 model.set_initial_conditions({S: 1 - I0, I: I0}) import numpy as np from bfmplot import pl as plt import bfmplot as bp t = np.linspace(0, 100, 1000) result = model.integrate(t) plt.figure() for compartment, incidence in result.items(): plt.plot(t, incidence, label=compartment) plt.xlabel('time [days]') plt.ylabel('incidence') plt.legend() bp.strip_axis(plt.gca()) plt.gcf().tight_layout() plt.savefig('SEIRQ.png', dpi=300) N = 1000 I0 = 100 model = epk.EpiModel([S, E, I, R, Q], initial_population_size=N)
import numpy as np #import matplotlib.pyplot as plt from bfmplot import pl as plt from ThredgeCorr.basic_patterns import * ### mean degree plots 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
from ThredgeCorr.basic_patterns import * from ThredgeCorr.degree_dist import * import numpy as np import networkx as nx import bfmplot as bp from bfmplot import pl import sys fig = pl.figure(1, figsize=(8, 2.5)) ### high school network print("loading", 'degree_sequences/comm50.degree_sequence', '...') k = np.loadtxt('degree_sequences/comm50.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) rho = solve_rho(np.mean(k), np.mean(k**2), n) ax = fig.add_subplot(1, 3, 1) pl.hist(k, bins=np.arange(0, kmax, 2), density=True, alpha=1, align='left', color=bp.brewer_qualitative[1], label='data', histtype='step') p = pk(n, t, rho, kmax, X, W)