Playing around with genetic programming. Program will make a formula which approximates the input sequence.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Joshua Moerman d91027933c Adds the operator % in genome. Some other stuff. 7 years ago
lib Adds the operator % in genome. Some other stuff. 7 years ago
src Adds the operator % in genome. Some other stuff. 7 years ago
.gitignore Initial commit 8 years ago
CMakeLists.txt Merges the lib and include dir 7 years ago
README.md Initial commit 8 years ago

README.md

Genetic Sequence Formulizer

This program will take a sequence entered by the user and tries to find a formula producing this sequence. I made this to play around with genetic programming. Inspired by the following two talks:

I used a technique similar to the one described in the first presentation (the one called single), as it seemed to be the easiest one. The nice thing is that there is always just one parent, but there are inactive genes which are allowed to mutate freely.

Examples

Some actual output of the program (truncated):

$ ./main 0 0 0 0 0 0 0
your input:	0, 0, 0, 0, 0, 0, 0, 
formula:	(x-x)*x
continuation:	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...

$ ./main 1 2 3
your input:	1, 2, 3, 
formula:	((x-18)/(x-18))+x
continuation:	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ...

$ ./main 1 2 4 8
your input:	1, 2, 4, 8, 
formula:	2^x
continuation:	1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, ...

$ ./main 37
your input:	37, 
formula:	(10+12)+15
continuation:	37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 

Notes

  • The algorithm does not yet simplify the formula (I should take this into account when scoring the genes).
  • The sequences are 0-based.
  • The constants used in the genes are bound to 20 (so in the last example, it needed multiple constants added).
  • It treats 1/0 as INT_MAX (we need some safety as we evaluate randomly generated expressions).
  • I may be using some c++14 features. Install a new clang or gcc to get this awesomeness.