Example #1
0
 def __init__(self, **kwargs):
     if "initial_circuit" not in kwargs:
         kwargs["initial_circuit"] = False
     if "initial_tree_size" not in kwargs:
         kwargs["initial_tree_size"] = 4
     if "maximum_mutation_size" not in kwargs:
         kwargs["maximum_mutation_size"] = 3
     if "minimum_replacement_depth" not in kwargs:
         kwargs["minimum_replacement_depth"] = 1
     if "generation_size" not in kwargs:
         kwargs["generation_size"] = 4
     if "generation_test" not in kwargs:
         kwargs["generation_test"] = False
     elif "generation_test_save" not in kwargs:
         kwargs["generation_test_save"] = False
     elif kwargs["generation_size"] % 2 != 0:
         kwargs["generation_size"] += 1
     if "selection" not in kwargs:
         kwargs["selection"] = "bayes_factors"
     if "best_record" not in kwargs:
         kwargs["best_record"] = False
     elif kwargs["best_record"] == True:
         self.best_array = []
         self.best_circuits = []
     if "num_top_circuits" not in kwargs:
         kwargs["num_top_circuits"] = 10
     if kwargs["initial_circuit"] == False:
         initial_generation = []  #
         random_constructor = EIS()
         for i in range(0, kwargs["generation_size"]):
             initial_generation.append(
                 random_constructor.random_circuit_tree(
                     kwargs["initial_tree_size"]))
     self.options = kwargs
     self.initial_generation = initial_generation
     self.best_candidates = {
         "scores": np.array([]),
         "models": [],
         "parameters": [],
         "data": []
     }
     self.count = 0
Example #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,
test=EIS()
from circuit_drawer import circuit_artist
hard_tree={"root_series":{"left_paralell":{
                        "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)