-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolic_regression.py
36 lines (28 loc) · 1.29 KB
/
symbolic_regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Module contianing a test run of Evolution Strategy and CGP in problem of symbolic regression"""
from algorithms.evolution_strategy import EvolutionStrategy
from reporters.best_individual_reporter import BestIndividualReporter
from evaluators.math_function_evaluator import MathFunctionEvaluator
from mutations.cgp.smart_mutation import CGPSmartMutation
from genotypes.cgp.cgp import CGPIndividual
from genotypes.individual import IndividualGenerator
def main():
"""Run a symbolic regression on "x+y-z" expression using CGP and symbolic regression"""
evaluator = MathFunctionEvaluator('x-8*y-z', [(-1, -1, 5), (-2, -3, 2), (0, -1, -123),
(1, 3, 5), (-2, -1, 0), (2, 3, 2)])
reporters = [BestIndividualReporter()]
cgp_hyperparams = {
'input_len': 3,
'grid_size': (3, 3),
'output_len': 1,
'constant_len': 4,
}
generator = IndividualGenerator(CGPIndividual, cgp_hyperparams)
mutation = CGPSmartMutation(n=1)
max_iterations = 0
parent_count = 1
children_count = 4
alg = EvolutionStrategy(reporters, max_iterations, evaluator, generator,
parent_count, children_count, mutation, elitism=True, target_fitness=0)
alg.run()
if __name__ == '__main__':
main()