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


Python Tree.create方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create [as 别名]
class Individual:
  STANDING_LIMITS = {'min': 1, 'max': 10, 'starting': 5}

  def __init__(self, exp_class, exp_args=[]):
    self.exp_class = exp_class
    self.exp_args = exp_args
    self._error = 0
    self._standing = None

  @property
  def error(self):
    return self._error

  @property
  def standing(self):
    return self._standing

  def increment_standing(self):
    self._standing = min(self._standing + 1, self.STANDING_LIMITS['max'])

  def decrement_standing(self):
    self._standing = max(self._standing - 1, self.STANDING_LIMITS['min'])

  def init_experiment(self):
    self._error = 0
    self.experiment = self.exp_class(*self.exp_args)
    self.experiment.initialize()
  
  def generate(self, extra_terminal_set=[], extra_function_set=[], tree_depth=3, tree_function_bias=1):
    self._standing = self.STANDING_LIMITS['starting']
    self.init_experiment()
    self.tree = Tree()
    self.tree.create(self.experiment.get_terminal_set() + extra_terminal_set,
                     self.experiment.get_function_set() + extra_function_set,
                     function_bias=tree_function_bias, max_depth=tree_depth)

  def clone(self):
    clone = self.__class__(self.exp_class, self.exp_args)
    clone._standing = self._standing
    clone.init_experiment()
    clone.tree = Tree()
    clone.tree.clone(self.tree)
    return clone

  def mutate(self):
    mutant = self.__class__(self.exp_class, self.exp_args)
    mutant._standing = self._standing
    mutant.init_experiment()
    mutant.tree = Tree()
    mutant.tree.mutate(self.tree)
    return mutant

  def reproduce(self, other_individual):
    child = self.__class__(self.exp_class, self.exp_args)
    child._standing = int(numpy.average([self._standing, other_individual._standing]))
    child.init_experiment()
    child.tree = Tree()
    child.tree.subtree_crossover(self.tree, other_individual.tree)
    return child

  def get_func(self, function_name):
    return self.experiment.function_lookup(function_name)

  def evaluate(self):
    loop = True
    while loop:
      self._error += self.experiment.norm_error(self.tree.execute(self))
      loop = self.experiment.next()

  def evaluate_data(self):
    samples = []
    loop = True
    self.experiment.initialize()
    while loop:
      actual_value = self.tree.execute(self)
      sample = {'value': actual_value, 'error': self.experiment.norm_error(actual_value)}
      if self.experiment.index() != None:
        sample['index'] = self.experiment.index()
      samples.append(sample)
      loop = self.experiment.next()
    return samples

  def simplify(self):
    self.tree.simplify(self)
开发者ID:dougsc,项目名称:gp,代码行数:86,代码来源:individual.py

示例2: Tree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import create [as 别名]
from tree import Tree
from linkedlist import LinkedList
tree = Tree()
tree.create()

def createDepthLinkedList():
	nodesAtDepth = LinkedList()
	nodesAtDepth.insertNode(tree.root.data)
	q=[]
	q.append(tree.root)
	
	depthLinkedList =[nodesAtDepth]
	condition = True
	while condition:
		children = []
		while (q):
			node= q.pop(0)
			if(node.left != None):
				children.append(node.left)
			if(node.right != None):
				children.append(node.right)
		condition = True if children else False
		if(condition):
			nodesAtDepth = LinkedList()
			for node in children:
				nodesAtDepth.insertNode(node.data)
			depthLinkedList.append(nodesAtDepth)
			q.extend(children)
	for linkedlist in depthLinkedList:
		 linkedlist.display()
开发者ID:nirmalvp,项目名称:algos,代码行数:32,代码来源:linkedlistdepth.py


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