当前位置: 首页>>代码示例>>Python>>正文


Python Tree.tree_map_to_string方法代码示例

本文整理汇总了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)
开发者ID:Mirann,项目名称:Genetic,代码行数:30,代码来源:__init__.py

示例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
开发者ID:Mirann,项目名称:Genetic,代码行数:35,代码来源:__init__.py

示例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)
开发者ID:Mirann,项目名称:Genetic,代码行数:41,代码来源:crossover.py

示例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
开发者ID:Mirann,项目名称:Genetic,代码行数:19,代码来源:__init__.py


注:本文中的tree.Tree.tree_map_to_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。