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 main_plot_optimering(): time_points, data_concentration = data() constants, ode_info, data_info = model_info(time_points) results = read_results(constants) coefficients, min_cost_funk, min_viktad_cost_funk = get_min_cost(results) sol_k = solve_ODE(coefficients, constants, ode_info) mat_r = calc_residual(sol_k, constants, data_concentration, data_info) plot_all(constants, sol_k, mat_r, data_concentration, time_points)
def fix_invertibility(matrix): time_points, data_conc = data() constants, ode_info, data_info = model_info(time_points) vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants indent_mat = np.identity(num_coefficient) eigenvalues = np.linalg.eigvals(matrix) min_nonpos_eigenvalue = np.amin(eigenvalues) gamma = -(min_nonpos_eigenvalue - h) fixed_matrix = matrix + gamma * indent_mat return fixed_matrix
def main(): time_points, data_concentration = data() constants, ode_info, data_info = model_info(time_points) for i in range(100): print("runda: " + str(i)) k_array = guess_k_array(i) start_point(k_array, constants, data_concentration, data_info, ode_info) results = iteration(k_array, constants, data_concentration, data_info, ode_info) save_results(results, constants)
def __main__(): geometry = sim.default_geo() data_file = root.TFile.Open("~/hex/berk/nersc/data/jackBig.root") tree = data_file.Get("tree") dummy = rd.supervisor() d = rd.data(tree, dummy) d.stack() for k, event_number in enumerate(events): print("SIMULATING EVENT: " + str(event_number)) simul = sim.simulator(geometry) d = rd.data(tree, simul.supervisor) p, e, vtx = d.get_event_w_shift(event_number, module_box._xwalls, module_box._ywalls, module_box._zwalls) geom = simul.project_event(p, e, vtx) simul.get_stats() simul.supervisor.write()
def corr(): H_inv = h_inverse() Covariance = H_inv time_points, data_conc = data() constants, ode_info, data_info = model_info(time_points) vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants v0 = np.zeros((num_coefficient, 1)) Correlation = np.zeros((num_tidserier, num_coefficient, num_coefficient)) for i in range(num_tidserier): v = v0.copy() v = np.sqrt(np.diag(Covariance[i, :, :])) outer_v = np.outer(v, v) Correlation[i, :, :] = Covariance[i, :, :] / outer_v return Correlation
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 RMS(): S = calc_S_mat() time_points, data_conc = data() constants, ode_info, data_info = model_info(time_points) results = read_results(constants) vald_modell, num_coefficient, num_tidserier, num_tidsteg, h = constants best_coefficients, min_cost_funk, min_viktad_cost_funk = get_min_cost(results) Kinetic_constants = best_coefficients sol_k, krashade = calc_sol_k() suc2, mig1, mig1_phos, X = sol_k Model_values = np.transpose(np.array([suc2, mig1, mig1_phos, X])) rms = np.zeros((2, num_coefficient)) S_square = np.power(S, 2) model_square = np.power(Model_values, 2).reshape(num_tidsteg, num_tidserier) for j in range(2): for i in range(num_coefficient): K_square = np.power(Kinetic_constants, 2) rms[j, i] = math.sqrt((1/num_tidsteg)*np.sum((S_square[j, :, i]*K_square[i]/model_square[:, j]), axis=0)) return rms
def var_K(): H_inv = h_inverse() 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) Kinetic_constants = best_coefficients Var_K = np.zeros((num_tidserier, num_coefficient, 1)) for i in range(num_tidserier): c = np.sqrt(np.diag(H_inv[i, :, :]).reshape(num_coefficient, 1)) for l in np.diag(H_inv[i]): if l < 0: print('COV ej definierad') break for j in range(num_coefficient): if Kinetic_constants[j] == 0: Var_K[i, j] = 0 else: Var_K[i, j] = c[j] / Kinetic_constants[j] return Var_K
import physics import read_data as rd import ROOT as root data_file = root.TFile.Open("~/hex/berk/nersc/data/stephenBig.root") tree = data_file.Get("tree") tree.GetEntry(398) inter = physics.interaction(tree.fsPDG, tree.fsKE) sup = rd.supervisor() d = rd.data(tree, sup) d.draw_characteristic_events() print(inter._particles)