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


Python Function.random_function方法代码示例

本文整理汇总了Python中function.Function.random_function方法的典型用法代码示例。如果您正苦于以下问题:Python Function.random_function方法的具体用法?Python Function.random_function怎么用?Python Function.random_function使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在function.Function的用法示例。


在下文中一共展示了Function.random_function方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grow

# 需要导入模块: from function import Function [as 别名]
# 或者: from function.Function import random_function [as 别名]
    def grow(self, depth=None):
        """ Grows a random child node by 1, limited by `depth` (if provided)
            and arity restrictions.  Returns the new node (or None if no
            node can be expanded).

        Args:
            depth: int (default=None)

        Returns:
            Node instance (or None)
        """
        # Creates a random permutation of child nodes
        nodes_depths = list(self.descendants_and_self_with_depths())
        shuffle(nodes_depths)

        for node, d in nodes_depths:
            if len(node.children) >= node.func.arity:
                continue

            if d >= depth:
                continue

            if d == depth - 1:
                func = Function.random_terminal()
            else:
                func = Function.random_function()
            child = Node(func)
            node.add_child(child)
            return child

        # If no children can be expanded, return None
        return None
开发者ID:mlberkeley,项目名称:genetic-algs,代码行数:34,代码来源:node.py

示例2: create_grow_tree

# 需要导入模块: from function import Function [as 别名]
# 或者: from function.Function import random_function [as 别名]
    def create_grow_tree(depth):
        """ Creates a tree using the grow method with depth `depth`. Note
        that since grow ends when all leaf nodes are 0-arity, it is
        possible that the tree generated by this method has a depth
        less than `depth`.

        Args:
            depth: int

        Returns:
            Node instance
        """
        func = Function.random_function()
        root = Node(func)

        while True:
            if root.grow(depth) is None:
                break

        return root
开发者ID:mlberkeley,项目名称:genetic-algs,代码行数:22,代码来源:tree_methods.py

示例3: create_full_tree

# 需要导入模块: from function import Function [as 别名]
# 或者: from function.Function import random_function [as 别名]
    def create_full_tree(depth):
        """ Creates a tree using the full method with depth `depth`.
            Returns the root node.

        Args:
            depth: int

        Returns:
            Node instance
        """
        if depth == 0:
            # Generate a leaf node
            terminal = Function.random_terminal()
            node = Node(terminal)
            return node
        else:
            # Generate an intermediate node
            func = Function.random_function()
            node = Node(func)

            for _ in range(func.arity):
                node.add_child(TreeMethods.create_full_tree(depth - 1))
            return node
开发者ID:mlberkeley,项目名称:genetic-algs,代码行数:25,代码来源:tree_methods.py


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