MCPcopy
hub / github.com/trevorstephens/gplearn / export_graphviz

Method export_graphviz

gplearn/_program.py:263–321  ·  view source on GitHub ↗

Returns a string, Graphviz script for visualizing the program. Parameters ---------- fade_nodes : list, optional A list of node indices to fade out for showing which were removed during evolution. Returns ------- output : stri

(self, fade_nodes=None)

Source from the content-addressed store, hash-verified

261 return output
262
263 def export_graphviz(self, fade_nodes=None):
264 """Returns a string, Graphviz script for visualizing the program.
265
266 Parameters
267 ----------
268 fade_nodes : list, optional
269 A list of node indices to fade out for showing which were removed
270 during evolution.
271
272 Returns
273 -------
274 output : string
275 The Graphviz script to plot the tree representation of the program.
276
277 """
278 terminals = []
279 if fade_nodes is None:
280 fade_nodes = []
281 output = 'digraph program {\nnode [style=filled]\n'
282 for i, node in enumerate(self.program):
283 fill = '#cecece'
284 if isinstance(node, _Function):
285 if i not in fade_nodes:
286 fill = '#136ed4'
287 terminals.append([node.arity, i])
288 output += ('%d [label="%s", fillcolor="%s"] ;\n'
289 % (i, node.name, fill))
290 else:
291 if i not in fade_nodes:
292 fill = '#60a6f6'
293 if isinstance(node, int):
294 if self.feature_names is None:
295 feature_name = 'X%s' % node
296 else:
297 feature_name = self.feature_names[node]
298 output += ('%d [label="%s", fillcolor="%s"] ;\n'
299 % (i, feature_name, fill))
300 else:
301 output += ('%d [label="%.3f", fillcolor="%s"] ;\n'
302 % (i, node, fill))
303 if i == 0:
304 # A degenerative program of only one node
305 return output + '}'
306 terminals[-1][0] -= 1
307 terminals[-1].append(i)
308 while terminals[-1][0] == 0:
309 output += '%d -> %d ;\n' % (terminals[-1][1],
310 terminals[-1][-1])
311 terminals[-1].pop()
312 if len(terminals[-1]) == 2:
313 parent = terminals[-1][-1]
314 terminals.pop()
315 if not terminals:
316 return output + '}'
317 terminals[-1].append(parent)
318 terminals[-1][0] -= 1
319
320 # We should never get here

Callers 4

test_symbolic_regressorFunction · 0.80
test_custom_functionsFunction · 0.80
test_symbolic_classifierFunction · 0.80
test_export_graphvizFunction · 0.80

Calls

no outgoing calls

Tested by 4

test_symbolic_regressorFunction · 0.64
test_custom_functionsFunction · 0.64
test_symbolic_classifierFunction · 0.64
test_export_graphvizFunction · 0.64