bingo.symbolic_regression.agraph.simplification_backend package#

Submodules#

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification module#

The core of the built in computer algebra simplification algorithm.

This algorithm is based on the algorithm presented in chapter 3 of Joel Cohen’s book [1].

… [1] Joel S. Cohen (2003) Computer Algebra and Symbolic Computation

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.automatic_simplify(expression)#

A recursive simplification of an expression

Parameters:

expression (Expression) – an expression to be recursively simplified

Return type:

a simplified Expression

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.no_simplification(expression)#

no simplification performed

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_cos(expression)#

simplification of cos operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_cosh(expression)#

simplification of hyperbolic cos operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_difference(expression)#

simplification of subtraction operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_exponential(expression)#

simplification of exp operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_logarithm(expression)#

simplification of log operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_power(expression)#

simplification of power operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_product(expression)#

simplification of multiplication operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_quotient(expression)#

simplification of division operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_sin(expression)#

simplification of sin operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_sinh(expression)#

simplification of hyperbolic sin operators

bingo.symbolic_regression.agraph.simplification_backend.automatic_simplification.simplify_sum(expression)#

simplification of addition operators

bingo.symbolic_regression.agraph.simplification_backend.constant_folding module#

Simplification code for reducing the number of constants in a mathematical expression

bingo.symbolic_regression.agraph.simplification_backend.constant_folding.fold_constants(expression)#

The goal of this function is to combine the constants (and derivative functions from only constant values) in an expression into as few constants as possible.

Parameters:

expression (Expression) – The expression in which the constants will be folded

Return type:

A new expression containing potentially fewer constants

bingo.symbolic_regression.agraph.simplification_backend.expression module#

Definition of a mathematical expression in tree form that can be used for simplification tasks.

class bingo.symbolic_regression.agraph.simplification_backend.expression.Expression(operator, operands)#

Bases: object

A mathematical expression

Parameters:
  • operator (ENUM from operator definitions) – The mathematical operator in the expression.

  • operands (list of Expression or int) – The operands upon which the operator in the expression acts.

property base#

The base x in x^b

property coefficient#

The coefficient A in A*x

copy()#

Shallow copy of the expression

property depends_on#

The constants, integers and variables in subexpressions

property exponent#

The exponent b in x^b

property is_constant_valued#

is the expression derived from solely constant values

is_one()#

is the expression == 1

is_zero()#

is the expression == 0

map(mapped_function)#

Apply a function to all operands of an expression

Parameters:

mapped_function (callable) – The function to be applied to the operands

Return type:

A new expression with mapped operands

property operands#

The operands upon which the expressions operator acts

property operator#

The primary mathematical operation in the expression

property term#

The term x in A*x

bingo.symbolic_regression.agraph.simplification_backend.interpreter module#

This module contains encapsulates the ability to translate equations in the form of AGraphs (specified by a command array) to/from computer algebra system Expressions which are used in the simplification process.

bingo.symbolic_regression.agraph.simplification_backend.interpreter.build_agraph_stack(expression)#

Translate computer algebra system (CAS) expression into a command array

Parameters:

expression (Expression) – A computer algebra system expression

Returns:

command_array – The command array equivalent of expression

Return type:

np.array of int

bingo.symbolic_regression.agraph.simplification_backend.interpreter.build_cas_expression(agraph_stack)#

Translate a command array into computer algebra system (CAS) expression

Parameters:

agraph_stack (AGraph command array) – The command array that encodes an equation

Return type:

CAS Expression

bingo.symbolic_regression.agraph.simplification_backend.optional_expression_modification module#

Simplification operations that are not strictly necessary, but could be performed to maintain a specific canonical structure.

The module constants below control this behavior:

INSERT_SUBTRACTION: Default True.

a + (-1)*b is converted to a - b

REPLACE_INTEGER_POWERS: Default True.

a^5 is converted to (a*a)*(a*a)*a

REPLACE_INTEGERS_WITH_CONSTANTS: Default False

x+x is simplified to 2*x and is converted to c*x

bingo.symbolic_regression.agraph.simplification_backend.optional_expression_modification.optional_modifications(expression)#

Modification of expression using non-essential heuristics

INSERT_SUBTRACTION: Default on

a + (-1)*b is converted to a - b

REPLACE_INTEGER_POWERS: Default on

a^5 is converted to (a*a)*(a*a)*a

REPLACE_INTEGERS_WITH_CONSTANTS: Default off

x+x is simplified to 2*x and is converted to c*x

Parameters:

expression (Expression) – The expression to modify

Return type:

expression with designated simplifications made

bingo.symbolic_regression.agraph.simplification_backend.simplification_backend module#

This module represents the python backend associated with AGraph equation simplification. This backend is used to perform the the simplification of an equation represented by an AGraph. It can be performed based on a simple reduction or a more involved algebraic simplification.

bingo.symbolic_regression.agraph.simplification_backend.simplification_backend.get_utilized_commands(stack)#

Find which commands are utilized

Find the commands (rows) of the stack upon which the last command of the stack depends. This is inclusive of the last command.

Parameters:

stack (Nx3 numpy array of int.) – The command stack associated with an equation. N is the number of commands in the stack.

Returns:

Boolean values for whether each command is utilized.

Return type:

list of bool of length N

bingo.symbolic_regression.agraph.simplification_backend.simplification_backend.reduce_stack(stack)#

Reduces a stack

An acyclic graph is given in stack form. The stack is simplified to consist only of the commands used by the last command.

Parameters:

stack (Nx3 numpy array of int.) – The command stack associated with an equation. N is the number of commands in the stack.

Returns:

a simplified stack where M is the number of used commands

Return type:

Mx3 numpy array of int.

bingo.symbolic_regression.agraph.simplification_backend.simplification_backend.simplify_stack(stack)#

Simplifies a stack based on computational algebra

An acyclic graph is given in stack form. The stack is algebraically simplified and put in a canonical form.

Parameters:

stack (Nx3 numpy array of int.) – The command stack associated with an equation. N is the number of commands in the stack.

Returns:

a simplified stack representing the original equation

Return type:

Mx3 numpy array of int.

bingo.symbolic_regression.agraph.simplification_backend.simplify module#

Bingo’s simplification algorithm using a built-in computer algebra system

bingo.symbolic_regression.agraph.simplification_backend.simplify.simplify(agraph_stack)#

Simplification of an equation (represented by an AGraph command array) using bingo’s built-in computer algebra system

Parameters:

agraph_stack (AGraph command array) – An equation to be simplified

Return type:

The simplified equation

Module contents#