def fitfunc_with_jump(vacopt,initial_values,beta,q,midc,exponent,f_A,f_V,sigma,delta,Tmax=382,new_hesitancy=0.1,time_index_jump=get_vaccination_rates_new.len_doses,full_output=False): vacopt = np.asarray(vacopt,dtype=np.float64) Ncomp = 20 ts1 = np.arange(-0, time_index_jump, source2.dt) Y1 = source2.RK4(source2.SYS_ODE_VAX_RK4,initial_values,ts1,vacopt,beta,exponent,midc,source2.mu_A,source2.mu_C,source2.mu_Q,q,sigma,delta,f_A,f_V,source2.number_of_daily_vaccinations) conditions_at_jump = Y1[-1,:] proportion_newly_willing = 1-new_hesitancy/source2.hesitancy for i in [0,3,6,9,12]: number_of_people_to_move = conditions_at_jump[i+1::Ncomp]*proportion_newly_willing conditions_at_jump[i::Ncomp] += number_of_people_to_move conditions_at_jump[i+1::Ncomp] -= number_of_people_to_move ts2 = np.arange(time_index_jump, Tmax, source2.dt) Y2 = source2.RK4(source2.SYS_ODE_VAX_RK4,conditions_at_jump,ts2,vacopt,beta,exponent,midc,source2.mu_A,source2.mu_C,source2.mu_Q,q,sigma,delta,f_A,f_V,source2.number_of_daily_vaccinations) Y = np.r_[Y1,Y2] dead_per_group = Y[-1,17::Ncomp] cases_per_group = dead_per_group + Y[-1,15::Ncomp] + Y[-1,16::Ncomp] + Y[-1,18::Ncomp] + Y[-1,19::Ncomp] infections_per_group = source2.Nsize - Y[-1,0::Ncomp] - Y[-1,1::Ncomp] - Y[-1,2::Ncomp] if full_output: return Y else: return dead_per_group[0],np.sum(dead_per_group[1:9]),np.sum(dead_per_group[9:13]),np.sum(dead_per_group[13:]),cases_per_group[0],np.sum(cases_per_group[1:9]),np.sum(cases_per_group[9:13]),np.sum(cases_per_group[13:]),infections_per_group[0],np.sum(infections_per_group[1:9]),np.sum(infections_per_group[9:13]),np.sum(infections_per_group[13:])
def fitfunc_short(vacopt,initial_values,beta,q,midc,exponent,f_A,f_V,sigma,delta): vacopt = np.asarray(vacopt,dtype=np.float64) Ncomp = 20 ts = np.arange(-0, 365+17, source2.dt) Y = source2.RK4(source2.SYS_ODE_VAX_RK4,initial_values,ts,vacopt,beta,exponent,midc,source2.mu_A,source2.mu_C,source2.mu_Q,q,sigma,delta,f_A,f_V,source2.number_of_daily_vaccinations) dead_per_group = Y[-1,17::Ncomp] cases_per_group = dead_per_group + Y[-1,15::Ncomp] + Y[-1,16::Ncomp] + Y[-1,18::Ncomp] + Y[-1,19::Ncomp] infections_per_group = source2.Nsize - Y[-1,0::Ncomp] - Y[-1,1::Ncomp] - Y[-1,2::Ncomp] return dead_per_group[0],np.sum(dead_per_group[1:9]),np.sum(dead_per_group[9:13]),np.sum(dead_per_group[13:]),cases_per_group[0],np.sum(cases_per_group[1:9]),np.sum(cases_per_group[9:13]),np.sum(cases_per_group[13:]),infections_per_group[0],np.sum(infections_per_group[1:9]),np.sum(infections_per_group[9:13]),np.sum(infections_per_group[13:])
f_V = 1 if dummy == 3: f_A = 1 f_V = 1 q = source2.q_based_on_q17(q17) initial_values = source2.get_initial_values( source2.Nsize, source2.mu_A, source2.mu_C, source2.mu_Q, q, hesitancy=hesitancy, START_DATE_INDEX=source2.index_2020_10_13) Y = source2.RK4(source2.SYS_ODE_VAX_RK4, initial_values, ts, vacopt, beta, exponent, midc, source2.mu_A, source2.mu_C, source2.mu_Q, q, source2.sigma, source2.delta, source2.f_A, source2.f_V, source2.number_of_daily_vaccinations) sol_by_compartment = np.zeros((ts.shape[0], Ncomp), dtype=np.float64) for ii in range(source2.Ncomp): sol_by_compartment[:, ii] = np.sum(Y[:, ii::Ncomp], axis=1) rows.append([source2.last_day_for_fit, source2.hesitancy, f_A, f_V, q17] + param_opt + [sse_opts[counter]] + [ sol_by_compartment[-1, 17] / 1e3, (sol_by_compartment[-1, 15] + sol_by_compartment[-1, 16] + sol_by_compartment[-1, 17] + sol_by_compartment[-1, 18] + sol_by_compartment[-1, 19]) / 1e6 ]) total_C = sol_by_compartment[:, 15] + sol_by_compartment[:, 16]
def fitfunc(vacopt,initial_values,beta,q,midc,exponent,f_A,f_V,sigma,delta): vacopt = np.asarray(vacopt,dtype=np.float64) ts = np.arange(-0, 365+17, source2.dt) Y = source2.RK4(source2.SYS_ODE_VAX_RK4,initial_values,ts,vacopt,beta,exponent,midc,source2.mu_A,source2.mu_C,source2.mu_Q,q,sigma,delta,f_A,f_V,source2.number_of_daily_vaccinations) return Y