Discovering Equations from Data with PythonSymbolic regression, genetic programming and the eqdisco toolbox

Appendix B
From the GP-OLS MATLAB toolbox

The GP-OLS MATLAB toolbox accompanied the paper of Madár, Abonyi and Szeifert [1] and is distributed on the web site of the author’s research group (https://www.abonyilab.com/gp_index). Its documentation describes a population structure that holds the chromosomes, the trees of the individuals, and the symbols, the operators and variables of the equations, and four functions that a program calls in turn: gpols_init(popusize, maxtreedepth, symbols) creates the population variable and random initial trees; gpols_evaluate(popu, ixv, X, Y, Q, opte) determines the linear parameters, applies orthogonal least squares to eliminate subtrees and computes the fitness of the individuals with indices ixv; gpols_mainloop executes one evolutionary loop and steps to the next generation; and the script gpols_result writes the current solution and the final result. The vector opte holds the two parameters of the tree-size penalty, the OLS threshold (a fraction between 0 and 1, or an integer number of terms) and a flag of polynomial evaluation; the optional vector Q turns least squares into weighted least squares.

In eqdisco the whole program is one estimator:

import eqdisco as eq 
 
model = eq.GPOLSRegressor( 
    population_size=50,          # popusize of gpols_init 
    max_depth=5,                 # maxtreedepth of gpols_init 
    functions=("add", "mul"),    # the operator symbols; terminals are the columns of X 
    err_threshold=0.02,          # opte(3), the OLS threshold 
    generations=30,              # the number of gpols_mainloop calls 
    random_state=0, 
).fit(X, y) 
print(model.equation_)           # gpols_result: the best equation 
print(model.gene_table())        # terms, weights and error reduction ratios

Table B.1 maps the elements of the toolbox to eqdisco.

Table B.1. Elements of the GP-OLS MATLAB toolbox and their counterparts in eqdisco.

GP-OLS MATLAB toolbox

eqdisco

gpols_init(popusize, maxtreedepth, symbols)

GPOLSRegressor(population_size, max_depth, functions)

symbols (operators and terminals)

functions; terminals are the columns of X, named by feature_names

gpols_evaluate(popu, ixv, X, Y, Q, opte)

fit(X, y); every new individual is evaluated internally

opte(1:2), tree-size penalty

parsimony, max_genes, max_depth, model_selection

opte(3), OLS threshold

err_threshold (a fraction of the explained variance)

opte(4), polynomial evaluation

functions=("add", "mul"), the default

Q, weighted least squares

not provided in version 1.0

gpols_mainloop

generations, patience, time_limit

gpols_result

equation_, gene_table(), history_, pareto_front_

lagged regressors built by hand

NARXRegressor(GPOLSRegressor(...), na, nb, nk)

–

backward_check=True: removal of collinear terms

–

err_guided: ERR-guided variation (experimental)

–

CooperativeOLSRegressor: a shared library of terms

Differences in behavior. Five differences should be known when results of the two implementations are compared.