Beispiel #1
0
Datei: tree.py Projekt: dougsc/gp
 def _simplify(self, node, function_lookup):
   if len(node['lower_nodes']) == 0:
     return
   terminal_value_count = filter(lambda x:TerminalSet.is_terminal_value(x['node']), node['lower_nodes'])
   if node['node']['arity'] == terminal_value_count:
     value = self.execute_node(node, function_lookup, args=map(lambda x:x['node']['value'], node['lower_nodes']))
     self.log().debug('Replacing existing node: %s' % pformat(node['node']))
     node['lower_nodes'] = []
     node['node'] = TerminalSet.terminal_value(value)
     self.log().debug(' -- with node: %s' % pformat(node['node']))
     self.is_simplified = False
   else:
     map(lambda x:self._simplify(x, function_lookup), node['lower_nodes'])
Beispiel #2
0
Datei: tree.py Projekt: dougsc/gp
  def _create_new_node(self, depth, node):
    node_set = []
    if depth == 1:
      node_set = self.function_set
    elif depth >= self.max_depth:
      node_set = self.terminal_set
    else:
      node_set = self.function_set * self.function_bias + self.terminal_set

    chosen_node = random.choice(node_set)
    if not chosen_node.has_key('name'):
      # this needs converting to a named node
      value = chosen_node['function'](*chosen_node['args'])
      chosen_node = TerminalSet.terminal_value(value)

    node['node'] = chosen_node
    node['lower_nodes'] = []
    node['depth'] = depth
Beispiel #3
0
def t_basic_terminals():
  ts = TerminalSet(__name__)
  ts.add_terminal_function(name='rand_int', func_ref=t_basic_rand_int, value_type='int', args=[0,9])
  return ts