def plot_generation(self, windex, loser_idx, scores, sim_array, generation, data, axes, plot_count): idxes = [windex, loser_idx] titles = ["Winner", "Loser"] dict_constructor = EIS() for i in range(0, len(idxes)): circuit_ax = axes[0][plot_count + i] idx = idxes[i] circuit_dict = dict_constructor.translate_tree(generation[idx]) circuit_artist(circuit_dict, circuit_ax) circuit_ax.set_title(titles[i]) circuit_ax.set_axis_off() data_ax = axes[1][plot_count + i] data_ax.plot(data[:, 0], -data[:, 1]) sim_data = sim_array[idx] data_ax.plot(sim_data[:, 0], -sim_data[:, 1]) data_ax.set_title(round(scores[idx], 3))
import matplotlib.pyplot as plt import numpy as np from EIS_class import EIS from EIS_optimiser import EIS_genetics, EIS_optimiser from circuit_drawer import circuit_artist import math from scipy import special from scipy import fft as syft ZARC = {"z1": ("Q1", "alpha1"), "z2": "R1"} def zarc(frequency, q, alpha, r): return r + (1 / (q * (1j * frequency)**alpha)) """translator=EIS() circuit_artist(ZARC) 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}
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: if "Q" in key: cpe_num += 1 if "gamma1" in netlist_keys: continue f = open("temp_netlist.net", "w") f.write("V1 0 1 1\n") sim_dict = dict(zip(params, results_dict["parameters"][j])) for key in netlist_keys: if "R" in key or "C" in key:
import os import sys dir = os.getcwd() dir_list = dir.split("/") source_list = dir_list[:-1] + ["src"] source_loc = ("/").join(source_list) sys.path.append(source_loc) 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 randles = {"z1": "R0", "z2": {"p1": ("Q1", "alpha1"), "p2": ["R2", "W1"]}} translator = EIS() circuit_artist(randles) ax = plt.gca() ax.set_axis_off() plt.show() frequency_powers = np.arange(1, 6, 0.1) frequencies = [10**x for x in frequency_powers] bounds = { "R1": [0, 1000], "Q1": [0, 1e-2], "alpha1": [0.1, 0.9], "R2": [0, 1000], "W1": [1, 200] } true_params = { "R1": 100, "Q1": 1e-3, "alpha1": 0.5,
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"], 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()
'p2': ('Q1', 'alpha1') }, 'p2': ["R4", { 'p1': 'R3', 'p2': 'W2' }] }, 'z0': 'R0' } """distances_dict={"z1":{"x_pos":1,"y_pos":0.5, "p1": {"name":"R1", "y_pos":0.5+0.25, "x_pos":1}, "p2": {"name":"R2", "y_pos":0.5-0.25, "x_pos":1}}, 'z2':{"x_pos": 2,"y_pos":0.5, "p1": [{"name":"R4", "y_pos":0.5+0.25, "x_pos":2-0.25}, {'p1': {"name":"W1", "y_pos":0.5+0.25+(0.25/2), "x_pos":2+0.25}, 'p2': {"name":"CPE1", "y_pos":0.5+0.25-(0.25/2), "x_pos":2+0.25}, }], 'p2': {'p1': {"name":"R3", "y_pos":0.5-0.25+(0.25/2), "x_pos":2}, 'p2': {"name":"W2", "y_pos":0.5-0.25-(0.25/2), "x_pos":2} } } }""" test = circuit_artist(test_dict)
"left_series":{"left_element":"R", "right_element":"C"}, "right_paralell":{"left_series":{"right_element":"R", "left_element":"R"}, "right_element":"R"}},"right_element":"C"}, } triple_randles={"root_series":{"left_paralell":{"left_element":"R", "right_element":"R"}, "right_series": {"left_paralell":{"left_element":"R", "right_element":"R"}, "right_series": {"left_paralell":{"left_element":"R", "right_element":"R"}, "right_paralell":{"left_element":"R", "right_element":"R"}}}}} z=test.construct_dict_from_tree(triple_randles["root_series"], "root_series") #print(test.random_circuit_tree(3)) random_tree=test.random_circuit_tree(4) #top_key=list(random_tree.keys())[0] #random_dict=test.construct_dict_from_tree(random_tree[top_key], top_key) circuit_artist(test.translate_tree(random_tree)) top_key=test.get_top_key(random_tree) #print(random_tree) #print(random_dict) #print(test.construct_circuit_from_tree_dict(random_dict)) import random get_node=test.find_random_node(random_tree[top_key], random.randint(1, 4), random_tree) new_tree=test.random_circuit_tree(3) crossed_tree=test.crossover(random_tree, new_tree) circuit_artist(test.translate_tree(crossed_tree)) #print("\n") #print(new_tree) #print(replace_tree) #print(get_node)
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] file_name = "AIC_best_scores.npy" scores = np.load(file_name, allow_pickle=True).item() for i in range(0, len(scores["scores"])): #print(scores["scores"][i]) plt.plot(scores["scores"][i]) #plt.axhline(scores["true_score"][i]) plt.show() translator = EIS() print(scores["circuits"][i]) 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))
#plt.show() for i in range(1, 6): file_name = "Best_candidates/round_2/BIC/Best_candidates_dict_{0}_12_gen.npy".format( i) results_dict = np.load(file_name, allow_pickle=True).item() #print(results_dict[0]["scores"]) fig, ax = plt.subplots(2, 6) 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], dpi=500) ax[0, j].set_axis_off() 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], 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$") except: print(file_name)