"R2": [0, 1000], "W1": [1, 200] } true_params = {"R1": 10, "Q1": 0.001, "alpha1": 0.8} param_names = ["R1", "Q1", "alpha1"] sim = EIS_genetics() normaliser = EIS(circuit=ZARC, parameter_bounds=bounds, parameter_names=param_names, test=True, fitting=True) sim1 = normaliser.simulate([true_params[x] for x in param_names], omegas) fig, ax = plt.subplots(1, 2) sim.plot_data(sim.dict_simulation(ZARC, omegas, [], [true_params[x] for x in param_names], param_names), ax[1], label="Analytic frequency simulation") num_oscillations = 3 time_start = 0 sampling_rate = 200 def cpe1(denom, i, charge_array, time_array, dt): total = 0 if i != 0: time_array = np.flip(time_array) total = np.sum(np.multiply(time_array, charge_array)) return dt * total / denom
circuit_artist(translator.translate_tree(scores["circuits"][i][0])) plt.show() for i in range(1, 6): file_name = "Best_candidates/AIC_best_candidates_dict_{0}_8_gen_3.npy".format( i) results_dict = np.load(file_name, allow_pickle=True).item() #print(results_dict[0]["scores"]) fig, ax = plt.subplots(2, 5) for j in range(0, len(results_dict["scores"])): translator = EIS() simulator = EIS_genetics() translated_circuit, params = translator.translate_tree( results_dict["models"][j], get_param_list=True) print(len(results_dict["parameters"][j])) print(len(params)) circuit_artist(translated_circuit, ax[0, j]) try: sim_data = simulator.tree_simulation(results_dict["models"][j], frequencies, results_dict["data"], results_dict["parameters"][j]) simulator.plot_data(results_dict["data"], ax[1, j]) simulator.plot_data(sim_data, ax[1, j]) except: print(file_name) ax[0, j].set_title(results_dict["scores"][j]) plt.show()
results_dict["models"][j], get_param_list=True) #translated_circuit={'z1': {'p1': [['C1', ("Q1", "alpha1")], ['R1', "C6"]], # 'p2': {'p1': [{'p1': "C7", 'p2': 'R2'}, [{'p1': 'C8', 'p2': 'R3'}, {'p1': 'C2', 'p2': ("Q2", "alpha2")}]], 'p2': ["C5", 'C3']}}, # 'z2': 'C4', 'z0': 'R0'} print(translated_circuit) #print(translated_circuit) #print(len(results_dict["parameters"][j])) #print(len(params)) circuit_artist(translated_circuit, ax[0][j]) ax[0][j].set_axis_off() sim_data = simulator.tree_simulation(results_dict["models"][j], frequencies, results_dict["data"], results_dict["parameters"][j]) simulator.plot_data(results_dict["data"], ax[1][j], label="Target") simulator.plot_data(sim_data, ax[1][j], label="Sim") ax[1][j].set_xlabel("$Z_r$") ax[1][j].set_ylabel("-$Z_i$") sim_dict = dict(zip(params, results_dict["parameters"][j])) #for i in range(5, 9): # sim_dict["C"+str(i)]=1 td = time_domain(translated_circuit, params=sim_dict) c, t, p = td.simulate() plt.plot(p, c) plt.show() ax[0][j].set_title(round(results_dict["scores"][j], 2)) ax[1][2].legend() plt.show()
potential_period = np.where((ss_time > 0.5 * k * (interval)) & (ss_time < (k + 1) * interval * 0.5)) ax[1].plot(ss_time[potential_period], subbed[potential_period]) subbed_interval = subbed[potential_period] cross_times[k - 2] = ss_time[np.where(subbed == min(subbed_interval))][0] if k - 2 == (cross_loc): break ax[1].axvline(cross_times[cross_loc]) ax[0].axvline(cross_times[cross_loc]) plt.show() t_cross = cross_times[cross_loc] magnitude = max(ss_potential) / max(ss_current) phase_numerator = 2 * math.pi * t_cross - t_end - t0 phase_denom = t_end - t0 phase = phase_numerator / phase_denom calculated_impede = magnitude * np.exp(1j * phase) impede[j, 0] = np.real(calculated_impede) impede[j, 1] = np.imag(calculated_impede) impede[j, 2] = np.real(z_freq) impede[j, 3] = np.imag(z_freq) ax[0].set_xlabel("$Z_r$") ax[0].set_ylabel("$-Z_i$") ax[1].set_xlabel("$Z_r$") ax[1].set_ylabel("$-Z_i$") sim.plot_data(impede[:, 2:], ax[1], label="FT method") sim.plot_data(impede[:, :2], ax[1], label="Amp+phase method") ax[1].legend() ax[0].legend() plt.show()