MCPcopy Create free account
hub / github.com/Morgansy/Genetic-Alpha / __str__

Method __str__

_program.py:313–336  ·  view source on GitHub ↗

Overloads `print` output of the object to resemble a LISP tree.

(self)

Source from the content-addressed store, hash-verified

311 return terminals == [-1]
312
313 def __str__(self):
314 """Overloads `print` output of the object to resemble a LISP tree."""
315 terminals = [0]
316 output = ''
317 for i, node in enumerate(self.program):
318 if isinstance(node, _Function):
319 terminals.append(node.arity)
320 output += node.name + '('
321 else:
322 if isinstance(node, int):
323 if self.feature_names is None:
324 output += 'X%s' % node
325 else:
326 output += self.feature_names[node]
327 else:
328 output += '%.3f' % node
329 terminals[-1] -= 1
330 while terminals[-1] == 0:
331 terminals.pop()
332 terminals[-1] -= 1
333 output += ')'
334 if i != len(self.program) - 1:
335 output += ', '
336 return output
337
338 def export_graphviz(self, fade_nodes=None):
339 """Returns a string, Graphviz script for visualizing the program.

Callers 1

genBetterFormulaFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected