예제 #1
0
 def tree_simulation(self, circuit_tree, frequencies, data, param_vals):
     translator = EIS()
     dictionary, params = translator.translate_tree(circuit_tree,
                                                    get_param_list=True)
     sim_class = self.assess_score(dictionary,
                                   params,
                                   frequencies,
                                   data,
                                   get_simulator=True)
     return sim_class.simulate(param_vals, frequencies)
예제 #2
0
 def get_generation_score(self, generation, frequencies, data, selection):
     dictionary_constructor = EIS()
     generation_scores = np.zeros(len(generation))
     returned_params = []
     if self.options["generation_test"] == True:
         returned_data = []
     for i in range(0, len(generation)):
         circuit_dict, param_list = dictionary_constructor.translate_tree(
             generation[i], get_param_list=True)
         if len(param_list) == 1:
             meaningful_circuit = False
             while meaningful_circuit == False:
                 new_try = dictionary_constructor.random_circuit_tree(
                     self.options["initial_tree_size"])
                 circuit_dict, param_list = dictionary_constructor.translate_tree(
                     new_try, get_param_list=True)
                 if len(param_list) > 1:
                     meaningful_circuit = True
                     generation[i] = new_try
         if self.options["generation_test"] == True:
             generation_scores[i], params, sim_data = self.assess_score(
                 circuit_dict,
                 param_list,
                 frequencies,
                 data,
                 score_func=selection)
         else:
             generation_scores[i], params = self.assess_score(
                 circuit_dict,
                 param_list,
                 frequencies,
                 data,
                 score_func=selection)
         returned_params.append(params)
         if self.options["generation_test"] == True:
             returned_data.append(sim_data)
     if self.options["generation_test"] == True:
         return generation_scores, returned_params, returned_data
     else:
         return generation_scores, returned_params,
예제 #3
0
 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))
예제 #4
0
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:
            if "Q" in key:
                cpe_num += 1
        if "gamma1" in netlist_keys:
                        "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)
예제 #6
0
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))