For the purposes of learning, i implemented a genetic programming algorithm using syntactic trees to discover mathematical functions that represent the learning of input and output data.
See this example, XOR operator:
[N,x1,x2,Result]
[1,0,0,0],
[2,0,1,1],
[3,1,0,1],
[4,1,1,0],
[5,0,0,0],
[6,0,1,1],
[7,1,0,1],
[8,1,1,0],
[9,0,0,0],
[10,0,1,1],
[11,1,0,1],
[12,1,1,0]
Training with the first 4 registers, the tree found the following function:
((x2-x1) ** (((70-0) * (x1+2))+(Math.tan(x2) * x1)))
Replacing values:
((0-0) ** (((70-0) * (0+2))+(Math.tan(0) * 0))) = 0
((0-1) ** (((70-0) * (1+2))+(Math.tan(0) * 1))) = 1
((1-0) ** (((70-0) * (0+2))+(Math.tan(1) * 0))) = 1
((1-1) ** (((70-0) * (1+2))+(Math.tan(1) * 1))) = 0
We can configure genetic programming with a larger population and different types of mutation to explore better tree generation and faster data approximation.
If you also like genetic programming, you can download the code and implement a better solution.
A online example is here:
https://linuxever-2b066.web.app/
The code is available for download on github:
https://github.com/rennorodrigo/pgeneticareactjs
Top comments (0)