ax=plt.gca() ax.set_axis_off() plt.show()""" frequency_powers = np.arange(0, 6, 0.2) frequencies = [10**x for x in frequency_powers] omegas = np.multiply(frequencies, 2 * math.pi) bounds = { "R1": [0, 1000], "Q1": [0, 1e-2], "alpha1": [0.1, 0.9], "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
ax=plt.gca() ax.set_axis_off() plt.show()""" frequency_powers=np.arange(1, 2, 0.2) frequencies=[10**x for x in frequency_powers] omegas=np.multiply(frequencies, 2*math.pi) bounds={ "R1":[0, 1000], "Q1":[0, 1e-2], "alpha1":[0.1, 0.9], "R2":[0, 1000], "W1":[1, 200] } true_params={"R1":10, "Q1":0.001, "alpha1":0.5} param_names=["R1", "Q1", "alpha1"] sim=EIS_genetics() fig, ax=plt.subplots() #sim.plot_data(sim.dict_simulation(ZARC, frequencies, [], [true_params[x] for x in param_names], param_names),ax) num_oscillations=5 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
from EIS_class import EIS import numpy as np import matplotlib.pyplot as plt from EIS_optimiser import EIS_optimiser, EIS_genetics from circuit_drawer import circuit_artist frequency_powers = np.arange(1, 6, 0.1) frequencies = [10**x for x in frequency_powers] for i in range(1, 6): file_name = "Best_candidates/round_2/{1}/Best_candidates_dict_{0}_12_gen.npy".format( i, "AIC") results_dict = np.load(file_name, allow_pickle=True).item() #print(results_dict[0]["scores"]) 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) #translated_circuit={'z1': {'p1': {'p1': [[{'p1': {'p1': ['C1', 'R1'], 'p2': {'p1': 'R2', 'p2': 'C2'}}, 'p2': {'p1': 'W1', 'p2': 'R3'}}, {'p1': 'W2', 'p2': 'C3'}], ["C12", "C13"]], 'p2': ['W3', 'C4']}, 'p2': {'p1': ('Q1', 'alpha1'), 'p2': 'R4'}}, 'z2': {'p1': 'R5', 'p2': {'p1': "C14", 'p2': 'W4'}}, 'z0': 'R0'} print(len(results_dict["parameters"][j])) print(len(params)) circuit_artist(translated_circuit) netlist = EIS(circuit=translated_circuit, construct_netlist=True) netlist_keys = list(netlist.netlist_dict.keys()) net_dict = netlist.netlist_dict cpe_num = 0 for key in netlist_keys:
#plt.plot(noisy_data[:,0], -noisy_data[:,1]) #plt.show() for methods in ["None"]: results_list = [] results_circuit = [] true_score = [] for i in range(0, 5): noisy_data = np.column_stack( (optim.add_noise(sim[:, 0], sigma), optim.add_noise(sim[:, 1], sigma))) #print(sigma, optim.get_std(noisy_data, sim), optim.optimise(noisy_data, sigma,"minimisation", [true_params[x] for x in param_names])) #gene_test=EIS_genetics(generation_size=8, generation_test=True, selection="bayes_factors")#, generation_test_save="Generation_images/Bayes_factor_randles_test/round_1/") #gene_test.evolve(frequencies, noisy_data) gene_test = EIS_genetics(generation_size=12, generation_test=False, selection=methods, initial_tree_size=1, best_record=True, num_top_circuits=6) value, _ = gene_test.assess_score(randles, param_names, frequencies, noisy_data, score_func=methods) print(value, "value") true_score.append(value) num_generations = 5 gene_test.evolve(frequencies, noisy_data, num_generations=num_generations) np.save( "Best_candidates/round_3/{0}/Best_candidates_dict_{1}_12_gen.npy".
file_name = "Best_candidates/round_3/{1}/Best_candidates_dict_{0}_12_gen.npy".format( i, "None") results_dict = np.load(file_name, allow_pickle=True).item() #print(results_dict[0]["scores"]) fig = plt.figure() ax = [[0 for x in range(0, 6)] for y in range(0, 3)] gs = fig.add_gridspec(3, 6) for m in range(0, 2): for j in range(0, 6): ax[m][j] = fig.add_subplot(gs[m, j]) td_ax = fig.add_subplot(gs[2, :]) #plt.show() 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) #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"],
ax=plt.gca() ax.set_axis_off() plt.show()""" frequency_powers = np.arange(0, 6, 0.2) frequencies = [10**x for x in frequency_powers] omegas = np.multiply(frequencies, 2 * math.pi) bounds = { "R1": [0, 1000], "Q1": [0, 1e-2], "alpha1": [0.1, 0.9], "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[0], label="Analytic frequency simulation") num_oscillations = 3 time_start = 0 sampling_rate = 200 def cpe1(denom, i, charge_array, time_array, dt): total = 0