hal-cgp icon indicating copy to clipboard operation
hal-cgp copied to clipboard

Exclude certain terms in fomulae

Open timomit opened this issue 4 years ago • 2 comments

Is it possible to tell CGP to exclude certain terms/operations in the formulae, for instance avoid to high exponents?

timomit avatar Apr 19 '21 12:04 timomit

Atm the easiest way to deal with this is probably within the objective function, ie by penalizing such terms with a fitness penalty eg:

def objective(individual):

    f = individual.to_numpy()
    f_sympy = individual.to_sympy()

# your normal evaluation
    individual.fitness = evaluate(f)
# penalize high exponents
    if exponent_too_high(f_sympy)
        individual.fitness -= penalty
   
    return individual

Where exponent_to_high is a function that evaluates your sympy expression, according to your criteria (my guess is that for the high exponents you would have to use sympy log, however this obviously depends on the exact problem)

Another way, if expression in general get "too complex" is to reduce the length of the genome (n_rows and n_columns).

Currently we don't have a built-in feature for measuring expression complexity yet, however this for sure is on the list for future extensions.

HenrikMettler avatar Apr 19 '21 13:04 HenrikMettler

it would certainly make for an interesting example to show how one can add a penalty term in the objective which is, for example, exponential in the largest exponent of the expression. anyone up for this? happy to review the corresponding PR ;)

jakobj avatar Apr 21 '21 18:04 jakobj