本文整理汇总了Python中tree.Tree.tree_map_to_string方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.tree_map_to_string方法的具体用法?Python Tree.tree_map_to_string怎么用?Python Tree.tree_map_to_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.tree_map_to_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_fitness
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import tree_map_to_string [as 别名]
def check_fitness(trees):
errors = []
for one_tree in trees:
if len(one_tree.tree_map) == 0:
continue
sum_error = 0
good_individual = True
for i in range(0, len(VARIABLE_VALUES_SET)):
error = Reproductor.get_error(one_tree, TARGET_VALUES[i], VARIABLE_VALUES_SET[i])
if error > ALLOWABLE_ERROR:
good_individual = False
sum_error += error
if isinf(sum_error):
continue
errors.append(sum_error)
if good_individual or sum_error < TARGET_RESULT:
print("RESULT")
print(Tree.tree_map_to_string(one_tree.tree_map))
print(one_tree.init_tree)
one_tree.fitness = sum_error
results.append(one_tree)
print("MIN FITNESS RESULT: ", min(errors))
print "AVERAGE FITNESS: ", sum(errors)/len(errors)
print "length ", len(errors)
print "results "
for r in results:
print "fitness ", r.fitness
print Tree.tree_map_to_string(r.tree_map)
示例2: main
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import tree_map_to_string [as 别名]
def main():
init_population = generate_init_population()
result = False
counter = 0
while counter < ITERATIONS_COUNT:
print("************************************************************************************************************"
"************************************************************************************************************")
print(counter)
best_individuals = deepcopy(reproduce(init_population))
if len(best_individuals) == 0:
print("Reproduction empty")
break
new_generation = deepcopy(create_new_generation(best_individuals))
mutated_trees = deepcopy(mutate_trees(new_generation))
check_fitness(mutated_trees)
init_population = deepcopy(mutated_trees)
if len(init_population) == 0:
print("Empty population")
break
counter += 1
print("End")
if len(results) > 0:
print("")
print "MIN RESULT"
print Tree.tree_map_to_string(min(results))
print min(results).init_tree
print min(results).fitness
示例3: cross
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import tree_map_to_string [as 别名]
def cross(self):
try:
if len(self._parent1.init_tree) <= 1 or len(self._parent2.init_tree) <= 1:
return False
index1 = self._get_index(list(self._parent1.init_tree))
index2 = self._get_index(list(self._parent2.init_tree))
while self.current_recursion_depth < MAX_RECURSION:
if (isinstance(self._parent1.tree_map[index1], TwoVariableFunction) and
isinstance(self._parent2.tree_map[index2], TwoVariableFunction)) or \
(isinstance(self._parent1.tree_map[index1], OneVariableFunction)
and isinstance(self._parent2.tree_map[index2], OneVariableFunction)):
self._parent1.index = index1
self._parent2.index = index2
self._parent1.children = Tree([], {})
self._parent2.children = Tree([], {})
self._parent1.find_children()
self._parent2.find_children()
self._parent1.delete_subtree()
self._parent2.delete_subtree()
self.new_tree1 = self._parent1.add_child_to_tree()
self.new_tree2 = self._parent2.add_child_to_tree()
self.current_recursion_depth = 0
return True
else:
index2 = self._get_index(deepcopy(self._parent2.init_tree))
self.current_recursion_depth += 1
return False
except:
print("Cross except")
print("parent1 ",self._parent1.init_tree)
print(Tree.tree_map_to_string(self._parent1.tree_map))
print("index1 ", index1)
print("parent2 ", self._parent2.init_tree)
print(Tree.tree_map_to_string(self._parent2.tree_map))
print("index2 ", index2)
示例4: generate_init_population
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import tree_map_to_string [as 别名]
def generate_init_population():
trees = []
j = 0
while j < TREE_NUMBER:
depth = (j+1)/2 + 1 # (j+100)/100 + 1
tree_creator = tree_creation.TreeCreator(depth)
if j % 2 == 0:
tree_creator.create(False)
else:
tree_creator.create(True)
t = tree_creator.tree
trees.append(Tree(t.init_tree, t.tree_map))
print(Tree.tree_map_to_string(t.tree_map))
print(t.init_tree)
print("")
j += 1
return trees