expected_counts[model.get_compartment_id(A)] = N_measurements * rateA / (rateB + rateE + rateA) expected_counts[model.get_compartment_id(B)] = N_measurements * rateB / (rateB + rateE + rateA) expected_counts[model.get_compartment_id(E)] = N_measurements * rateE / (rateB + rateE + rateA) 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)
# 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]) #if _r < n_row-1: # [ x.set_visible(False) for x in ax[i].xaxis.get_major_ticks() ] pl.xlim([0, 35]) pl.xticks([0, 10, 20, 30]) 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/linlin_shutdown_model_all_confirmed_fit_after_feb_12.png", dpi=300) pl.gcf().savefig("model_fit_figures/SI_Fig_06.png", dpi=300) if not loaded_fits: with open('fit_parameters/shutdown_model_all_provinces_after_feb_12.p', 'wb') as f: pickle.dump(fit_parameters, f) pl.show()