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)
| 336 | return output |
| 337 | |
| 338 | def export_graphviz(self, fade_nodes=None): |
| 339 | """Returns a string, Graphviz script for visualizing the program. |
| 340 | |
| 341 | Parameters |
| 342 | ---------- |
| 343 | fade_nodes : list, optional |
| 344 | A list of node indices to fade out for showing which were removed |
| 345 | during evolution. |
| 346 | |
| 347 | Returns |
| 348 | ------- |
| 349 | output : string |
| 350 | The Graphviz script to plot the tree representation of the program. |
| 351 | |
| 352 | """ |
| 353 | terminals = [] |
| 354 | if fade_nodes is None: |
| 355 | fade_nodes = [] |
| 356 | output = 'digraph program {\nnode [style=filled]\n' |
| 357 | for i, node in enumerate(self.program): |
| 358 | fill = '#cecece' |
| 359 | if isinstance(node, _Function): |
| 360 | if i not in fade_nodes: |
| 361 | fill = '#136ed4' |
| 362 | terminals.append([node.arity, i]) |
| 363 | output += ('%d [label="%s", fillcolor="%s"] ;\n' |
| 364 | % (i, node.name, fill)) |
| 365 | else: |
| 366 | if i not in fade_nodes: |
| 367 | fill = '#60a6f6' |
| 368 | if isinstance(node, int): |
| 369 | if self.feature_names is None: |
| 370 | feature_name = 'X%s' % node |
| 371 | else: |
| 372 | feature_name = self.feature_names[node] |
| 373 | output += ('%d [label="%s", fillcolor="%s"] ;\n' |
| 374 | % (i, feature_name, fill)) |
| 375 | else: |
| 376 | output += ('%d [label="%.3f", fillcolor="%s"] ;\n' |
| 377 | % (i, node, fill)) |
| 378 | if i == 0: |
| 379 | # A degenerative program of only one node |
| 380 | return output + '}' |
| 381 | terminals[-1][0] -= 1 |
| 382 | terminals[-1].append(i) |
| 383 | while terminals[-1][0] == 0: |
| 384 | output += '%d -> %d ;\n' % (terminals[-1][1], |
| 385 | terminals[-1][-1]) |
| 386 | terminals[-1].pop() |
| 387 | if len(terminals[-1]) == 2: |
| 388 | parent = terminals[-1][-1] |
| 389 | terminals.pop() |
| 390 | if not terminals: |
| 391 | return output + '}' |
| 392 | terminals[-1].append(parent) |
| 393 | terminals[-1][0] -= 1 |
| 394 | |
| 395 | # We should never get here |
nothing calls this directly
no outgoing calls
no test coverage detected