Non-linear regression using Genetic Programming

De
Aller à la navigation Aller à la recherche

The objective of this example is to find back the following non-linear equation: y=4*sin(3*x)+x*x/10

Non-Linear Function

Here is a good 1 minute run with seed 2, obtained with the (regression.ez code).

If you don't have an NVIDIA GPGPU card on your machine, please compile with:

$ easena ./regression.ez -gp ; make

and launched with:

$ ./regression --nbCPUThreads 20

If you have a multi-core CPU, EASEA parallelizes will parallelize over several threads using OpenMP. In order to use up to 20 threads (depending on the number of cores of your CPU), you can launch the program with:

$ ./regression --nbCPUThreads 20

If you have a machine with ann NVIDIA GPGPU card, make sure that the NVIDIA CUDA development environment is correctly installed (obtainable for free on the NVIDIA website) and compile with:

$ easena ./regression.ez -cuda_gp ; make

You can launch with the same line:

$ ./regression --nbCPUThreads 20

collet@biplan:~/regression$ easena ./regression.ez -gp ; make ;./regression --nbCPUThreads 20 --plotStats 0 --seed 2
EASENA version: 2.19 (RE)
Compiled with GP template

CONGRATULATIONS !!!
Target file(s) generation succeeded without warnings.
You can now type "make" to compile your project.
g++ -fopenmp -O2 -g -Wall -fmessage-length=0 -I/biolo/easea/easea//libeasea/include -I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/   -c -o regression.o regression.cpp
g++ -fopenmp -O2 -g -Wall -fmessage-length=0 -I/biolo/easea/easea//libeasea/include -I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/   -c -o regressionIndividual.o regressionIndividual.cpp
g++ -o regression regression.o regressionIndividual.o   -g /biolo/easea/easea//libeasea//libeasea.a -lpthread -fopenmp
------------------------------------------------------------------------------------------------
|GENER.|    ELAPSED    |    PLANNED    |     ACTUAL    |BEST INDIVIDUAL|  AVG  | WORST | STAND |
|NUMBER|     TIME      | EVALUATION NB | EVALUATION NB |    FITNESS    |FITNESS|FITNESS|  DEV  |
------------------------------------------------------------------------------------------------
      0	         0.074s	          50000	          48604	3.476540039e+03	1.5e+04	1.2e+06	2.5e+08
      1	         0.348s	         100000	          97721	2.629287354e+03	4.0e+03	3.6e+02	1.2e+04
      2	         0.663s	         150000	         146667	2.627041016e+03	3.6e+03	2.0e+02	1.7e+04
      3	         1.004s	         200000	         195655	2.598434570e+03	3.5e+03	1.4e+02	8.5e+03
      4	         1.449s	         250000	         244934	2.597528564e+03	3.4e+03	3.0e+02	7.8e+03
      5	         2.075s	         300000	         294291	2.412631348e+03	3.1e+03	4.5e+02	2.5e+04
      6	         2.628s	         350000	         343754	2.256219971e+03	2.9e+03	4.7e+02	3.0e+04
      7	         3.356s	         400000	         393360	1.988074951e+03	2.7e+03	2.8e+02	8.1e+03
      8	         4.265s	         450000	         443077	1.972303467e+03	2.6e+03	1.5e+02	4.9e+03
      9	         5.178s	         500000	         492790	1.603686401e+03	2.6e+03	1.8e+02	5.9e+03
     10	         6.108s	         550000	         542498	1.317219116e+03	2.5e+03	2.4e+02	7.3e+03
     11	         6.995s	         600000	         592211	1.603133087e+02	2.4e+03	3.2e+02	1.5e+04
     12	         7.852s	         650000	         641891	1.603133087e+02	2.2e+03	3.6e+02	1.0e+04
     13	         8.809s	         700000	         691607	1.327802887e+02	2.0e+03	4.1e+02	1.5e+04
     14	         9.806s	         750000	         741346	8.705255127e+01	1.8e+03	4.8e+02	1.5e+04
     15	        10.866s	         800000	         791084	7.755667114e+01	1.5e+03	5.4e+02	1.0e+04
     16	        11.848s	         850000	         840789	8.454118729e+00	1.2e+03	7.3e+02	1.5e+04
     17	        12.857s	         900000	         890480	8.454118729e+00	9.6e+02	8.1e+02	1.5e+04
     18	        14.025s	         950000	         940150	8.454118729e+00	7.4e+02	8.1e+02	1.5e+04
     19	        15.204s	        1000000	         989832	6.428004265e+00	5.5e+02	7.8e+02	1.1e+04
     20	        16.360s	        1050000	        1039494	6.253423691e+00	4.3e+02	7.7e+02	3.9e+04
     21	        17.519s	        1100000	        1089163	6.253423691e+00	3.6e+02	7.5e+02	1.5e+04
     22	        18.666s	        1150000	        1138833	6.231546402e+00	3.1e+02	7.4e+02	1.5e+04
     23	        19.824s	        1200000	        1188477	6.231546402e+00	2.9e+02	7.6e+02	1.5e+04
     24	        20.880s	        1250000	        1238179	6.231546402e+00	2.8e+02	8.0e+02	1.6e+04
     25	        21.847s	        1300000	        1287843	6.230583191e+00	2.8e+02	8.3e+02	1.6e+04
     26	        22.852s	        1350000	        1337423	6.230583191e+00	2.6e+02	8.0e+02	1.9e+04
     27	        23.923s	        1400000	        1387031	6.230583191e+00	2.4e+02	7.7e+02	1.5e+04
     28	        25.038s	        1450000	        1436694	6.230583191e+00	2.3e+02	7.4e+02	1.5e+04
     29	        26.115s	        1500000	        1486339	6.230583191e+00	2.3e+02	7.4e+02	1.7e+04
     30	        27.165s	        1550000	        1535970	1.726973772e+00	2.3e+02	7.4e+02	1.4e+04
     31	        28.218s	        1600000	        1585632	1.726973772e+00	2.4e+02	7.4e+02	1.5e+04
     32	        29.239s	        1650000	        1635278	1.726973772e+00	2.3e+02	7.5e+02	2.2e+04
     33	        30.265s	        1700000	        1684903	1.726973772e+00	2.4e+02	7.5e+02	1.8e+04
     34	        31.286s	        1750000	        1734602	1.716903687e+00	2.4e+02	7.5e+02	1.5e+04
     35	        32.302s	        1800000	        1784250	1.716903687e+00	2.6e+02	7.9e+02	1.6e+04
     36	        33.335s	        1850000	        1833942	1.704545975e+00	2.7e+02	8.2e+02	2.2e+04
     37	        34.422s	        1900000	        1883652	1.136579871e+00	2.4e+02	7.7e+02	1.3e+04
     38	        35.510s	        1950000	        1933347	1.136579871e+00	2.3e+02	7.7e+02	2.1e+04
     39	        36.628s	        2000000	        1983073	1.121906757e+00	2.3e+02	7.6e+02	2.0e+04
     40	        37.740s	        2050000	        2032784	1.121906757e+00	2.3e+02	7.7e+02	3.0e+04
     41	        38.842s	        2100000	        2082499	1.121906757e+00	2.2e+02	7.5e+02	2.5e+04
     42	        39.940s	        2150000	        2132195	1.114099026e+00	2.2e+02	8.0e+02	6.1e+04
     43	        41.037s	        2200000	        2181887	1.114099026e+00	2.2e+02	7.6e+02	2.1e+04
     44	        42.178s	        2250000	        2231600	1.114099026e+00	2.2e+02	7.4e+02	1.6e+04
     45	        43.340s	        2300000	        2281319	1.114099026e+00	2.2e+02	7.4e+02	1.9e+04
     46	        44.489s	        2350000	        2331011	1.114099026e+00	2.2e+02	7.5e+02	2.1e+04
     47	        45.593s	        2400000	        2380697	1.114099026e+00	2.2e+02	7.4e+02	1.5e+04
     48	        46.736s	        2450000	        2430423	1.114099026e+00	2.2e+02	7.6e+02	3.6e+04
     49	        47.903s	        2500000	        2480129	1.114099026e+00	2.1e+02	7.3e+02	1.5e+04
     50	        49.079s	        2550000	        2529836	1.114099026e+00	2.2e+02	7.4e+02	2.0e+04
     51	        50.260s	        2600000	        2579537	1.114099026e+00	2.2e+02	7.5e+02	2.0e+04
     52	        51.449s	        2650000	        2629255	2.936421037e-01	2.2e+02	7.4e+02	3.1e+04
     53	        52.645s	        2700000	        2678981	2.936421037e-01	2.2e+02	7.5e+02	2.0e+04
     54	        53.861s	        2750000	        2728678	2.936421037e-01	2.2e+02	7.8e+02	3.6e+04
     55	        55.088s	        2800000	        2778398	2.936421037e-01	2.2e+02	7.4e+02	1.5e+04
     56	        56.319s	        2850000	        2828100	2.936421037e-01	2.2e+02	7.5e+02	2.1e+04
     57	        57.481s	        2900000	        2877787	2.936421037e-01	2.2e+02	7.5e+02	3.0e+04
     58	        58.653s	        2950000	        2927521	2.936421037e-01	2.2e+02	7.3e+02	1.5e+04
     59	        59.855s	        3000000	        2977250	2.936421037e-01	2.2e+02	7.5e+02	3.0e+04
     60	        61.075s	        3050000	        3026988	2.936421037e-01	2.2e+02	7.5e+02	1.5e+04
Time Over
Time Limit was 60 seconds
EASEA LOG [INFO]: Seed: 2
EASEA LOG [INFO]: Best fitness: 0.293642
EASEA LOG [INFO]: Elapsed time: 61.0758
Now serializing individual (((sin((x)/(0.333335)))*(((0.632737)/(0.175179))+((0.322471)/(0.831035))))+((((0.857195)*(0.361795))
*((x)*(x)))*(0.322471)))
----------
y=(((sin((x)/(0.333335)))*(((0.632737)/(0.175179))+((0.322471)/(0.831035))))+((((0.857195)*(0.361795))*((x)*(x)))*(0.322471)))
----------
collet@biplan:~/regression$

Simplifying the expression of the found function (using any online function simplifier yields:

y=3.99998 * sin(2.99998 * x)+0.10000 * x^2

If we assume that (due to rounding errors) 3.99998 is the same as 4 and that 2.99998 is the same as 3, the found function is the same as the original function:

y=4*sin(3*x)+x*x/10

This can be seen if we print the found function in black over the original function in red: Found Function in black over the original function in red

Please note that this function is not polynomial, and even though it has a periodic component, it cannot be found using a Fourier transfrom (due to the added parabola).

It will be of course difficult to find more difficult functions, but this example shows the potential of Genetic Programming for non-linear regression.