def calc_S_mat(): time_points, data_conc = data() constants, ode_info, data_info = model_info(time_points) vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants results = read_results(constants) sol_k, krashade = calc_sol_k() suc2, mig1, mig1_phos, X = sol_k t_span, t_eval, y0 = ode_info best_coefficients, min_cost_funk, min_viktad_cost_funk = get_min_cost(results) Kinetic_constants = best_coefficients s_suc2 = np.zeros((num_tidsteg, num_coefficient)) s_mig1 = np.zeros((num_tidsteg, num_coefficient)) s_mig1_phos = np.zeros((num_tidsteg, num_coefficient)) s_X = np.zeros((num_tidsteg, num_coefficient)) dy = np.zeros([num_tidserier, num_tidsteg, 1]) for i in range(num_coefficient): d_Kinetic_constants = Kinetic_constants.copy() d_Kinetic_constants[i] = d_Kinetic_constants[i] + h d_solv = integrate.solve_ivp(fun=lambda t, y: model(vald_modell, t, y, d_Kinetic_constants), t_span=t_span, y0=y0, method="RK45", t_eval=t_eval) d_solv_k = np.zeros([num_tidserier, num_tidsteg, 1]) d_solv_k[:, :, 0] = d_solv.y dy_new = dy.copy() dy_new[:] = d_solv_k s_suc2[:, i] = np.transpose((dy_new[0] - suc2) / h) s_mig1[:, i] = np.transpose((dy_new[1] - mig1) / h) s_mig1_phos[:, i] = np.transpose((dy_new[2] - mig1_phos) / h) s_X[:, i] = np.transpose((dy_new[3] - X) / h) S = np.array([s_suc2, s_mig1, s_mig1_phos, s_X]) return S
def solve_ODE(kinetic_constants_0, constants, ode_info): vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants t_span, t_eval, y0 = ode_info sol = integrate.solve_ivp(fun=lambda t, y: model(vald_modell, t, y, kinetic_constants_0), t_span=t_span, y0=y0, method="RK45", t_eval=t_eval) sol_k = np.empty([num_tidserier, len(t_eval), 1]) sol_k[:, :, 0] = sol.y return sol_k
def calc_sol_k(): time_points, data_conc = data() constants, ode_info, data_info = model_info(time_points) vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants results = read_results(constants) best_coefficients, min_cost_funk, min_viktad_cost_funk = get_min_cost(results) t_span, t_eval, y0 = ode_info sol = integrate.solve_ivp(fun=lambda t, y: model(vald_modell, t, y, best_coefficients), t_span=t_span, y0=y0, method="RK45", t_eval=t_eval) sol_k = np.empty([num_tidserier, num_tidsteg, 1]) krashade = False try: sol_k[:, :, 0] = sol.y except ValueError: krashade = True return sol_k, krashade
def calc_sol_k_step(kinetic_constants_0, constants, ode_info): # ODE-lösare för att ta fram modellerade värden för en förskjutning h av respektive parameter. # Steg 3 i optimeringen. vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants t_span, t_eval, y0 = ode_info sol_k_step = np.empty([num_tidserier, num_tidsteg, num_coefficient]) for k in range(num_coefficient): kinetic_constants_step = kinetic_constants_0.copy() kinetic_constants_step[k] = kinetic_constants_step[k] + h sol = integrate.solve_ivp( fun=lambda t, y: model(vald_modell, t, y, kinetic_constants_step), t_span=t_span, y0=y0, method="RK45", t_eval=t_eval) sol_k_step[:, :, k] = sol.y return sol_k_step
def calc_sol_k(kinetic_constants_0, constants, ode_info): # ODE-lösare som beräknar de modellerade värderna givet p stycken koefficienter. # Steg 2 i optimeringen. vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants t_span, t_eval, y0 = ode_info sol = integrate.solve_ivp( fun=lambda t, y: model(vald_modell, t, y, kinetic_constants_0), t_span=t_span, y0=y0, method="RK45", t_eval=t_eval) sol_k = np.empty([num_tidserier, num_tidsteg, 1]) krashade = False try: sol_k[:, :, 0] = sol.y except ValueError: krashade = True return sol_k, krashade