geppy.support package

Submodules

geppy.support.simplification module

This module simplification provides utility functions for symbolic simplification of GEP individuals, which may be used in postprocessing.

geppy.support.simplification.DEFAULT_SYMBOLIC_FUNCTION_MAP = {'abs': <built-in function abs>, 'add': <built-in function add>, 'and_': <sphinx.ext.autodoc.importer._MockObject object>, 'cos': <sphinx.ext.autodoc.importer._MockObject object>, 'floordiv': <built-in function floordiv>, 'log': <sphinx.ext.autodoc.importer._MockObject object>, 'mul': <built-in function mul>, 'neg': <built-in function neg>, 'not_': <sphinx.ext.autodoc.importer._MockObject object>, 'or_': <sphinx.ext.autodoc.importer._MockObject object>, 'pow': <built-in function pow>, 'protected_div': <built-in function truediv>, 'sin': <sphinx.ext.autodoc.importer._MockObject object>, 'sub': <built-in function sub>, 'tan': <sphinx.ext.autodoc.importer._MockObject object>, 'truediv': <built-in function truediv>}

Currently, it is defined as:

DEFAULT_SYMBOLIC_FUNCTION_MAP = {
    operator.and_.__name__: sp.And,
    operator.or_.__name__: sp.Or,
    operator.not_.__name__: sp.Not,
    operator.add.__name__: operator.add,
    operator.sub.__name__: operator.sub,
    operator.mul.__name__: operator.mul,
    operator.neg.__name__: operator.neg,
    operator.pow.__name__: operator.pow,
    operator.abs.__name__: operator.abs,
    operator.floordiv.__name__: operator.floordiv,
    operator.truediv.__name__: operator.truediv,
    'protected_div': operator.truediv,
    math.log.__name__: sp.log,
    math.sin.__name__: sp.sin,
    math.cos.__name__: sp.cos,
    math.tan.__name__: sp.tan
}
geppy.support.simplification.simplify(genome, symbolic_function_map=None)[source]

Compile the primitive tree into a (possibly simplified) symbolic expression.

Parameters:
  • genomeKExpression, Gene, or Chromosome, the genotype of an individual
  • symbolic_function_map – dict, maps each function name in the primitive set to a symbolic version
Returns:

a (simplified) symbol expression

For example, add(sub(3, 3), x) may be simplified to x. This simplify() function can be used to postprocess the best individual obtained in GEP for a simplified representation. Some Python functions like operator.add() can be used directly in sympy. However, there are also functions that have their own symbolic versions to be used in sympy, like the operator.and_(), which should be replaced by sympy.And(). In such a case, we may provide a map symbolic_function_map={operator.and_.__name__, sympy.And} supposing the function primitive encapsulating operator.and_() uses its default name.

Such simplification doesn’t affect GEP at all. It should be used as a postprocessing step to simplify the final solution evolved by GEP.

Note

If the symbolic_function_map argument remains as the default value None, then a default map DEFAULT_SYMBOLIC_FUNCTION_MAP is used, which contains common name-to-symbolic function mappings, including the arithmetic operators and Boolean logic operators..

Note

This function depends on the sympy module. You can find it here.

geppy.support.visualization module

This module visualization provides utility functions to visualization the expression tree from a given K-expression, a gene or a chromosome in GEP.

geppy.support.visualization.graph(genome, label_renaming_map=None)[source]

Construct the graph of a genome. It returns in order a node list, an edge list, and a dictionary of the per node labels. The node are represented by numbers, the edges are tuples connecting two nodes (number), and the labels are values of a dictionary for which keys are the node numbers.

Parameters:
  • genomeKExpression, Gene, or Chromosome, the genotype of an individual
  • label_renaming_map – dict, which maps the old name of a primitive (or a linking function) to a new one for better visualization. The default label for each node is just the name of the primitive placed on this node. For example, you may provide renamed_labels={'and_': 'and'}.
Returns:

A node list, an edge list, and a dictionary of labels.

You can visualize a genome and export the tree visualization to an image file directly using the export_expression_tree() function.

geppy.support.visualization.export_expression_tree(genome, label_renaming_map=None, file='tree.png')[source]

Construct the graph of a genome and then export it to a file.

Parameters:
  • genomeKExpression, Gene, or Chromosome, the genotype of an individual
  • label_renaming_map – dict, which maps the old name of a primitive (or a linking function) to a new one for better visualization. The default label for each node is just the name of the primitive placed on this node. For example, you may provide renamed_labels={'and_': 'and'}.
  • file – str, the file path to draw the expression tree, which may be a relative or absolute one. If no extension is included in file, then the default extension ‘png’ is used.

Note

This function currently depends on the graphviz module to render the tree. Please first install the graphviz module before using this function. Alternatively, you can always obtain the raw graph data with the graph() function, then postprocess the data and render them with other tools as you want.

Module contents