karoo_gp/karoo_gp_server.py

90 lines
4.5 KiB
Python
Raw Normal View History

2015-11-04 03:56:07 -07:00
# Karoo GP Server
# Use Genetic Programming for Classification and Symbolic Regression
2017-02-07 01:33:38 -07:00
# by Kai Staats, MSc; see LICENSE.md
# Thanks to Emmanuel Dufourq and Arun Kumar for support during 2014-15 devel; TensorFlow support provided by Iurii Milovanov
2017-06-06 22:12:55 -06:00
# version 1.0.3
2016-07-07 23:00:21 -06:00
'''
2016-07-13 22:43:06 -06:00
A word to the newbie, expert, and brave--
Even if you are highly experienced in Genetic Programming, it is recommended that you review the 'Karoo User Guide'
2016-07-13 22:43:06 -06:00
before running this application. While your computer will not burst into flames nor will the sun collapse into a black
hole if you do not, you will likely find more enjoyment of this particular flavour of GP with a little understanding
of its intent and design.
KAROO GP SERVER
This is the Karoo GP server application. It can be internally scripted, fully command-line configured, or a combination
of both. If this is your first time using Karoo GP, please run the desktop application karoo_gp_main.py first in order
2017-02-07 01:33:38 -07:00
that you come to understand the full functionality of this particular Genetic Programming platform.
2016-07-13 22:43:06 -06:00
To launch Karoo GP server:
$ python karoo_gp_server.py
(or from iPython)
$ run karoo_gp_server.py
Without any arguments, Karoo GP relies entirely upon the scripted settings and the datasets located in karoo_gp/files/.
If you include the path to an external dataset, it will auto-load at launch:
$ python karoo_gp_server.py /[path]/[to_your]/[filename].csv
You can include a number of additional arguments which override the default values, as follows:
-ker [r,c,m] fitness function: (r)egression, (c)lassification, or (m)atching
-typ [f,g,r] Tree type: (f)ull, (g)row, or (r)amped half/half
-bas [3...10] maximum Tree depth for the initial population
-max [3...10] maximum Tree depth for the entire run
-min [3...100] minimum number of nodes
-pop [10...1000] maximum population
-gen [1...100] number of generations
Note that if you include any of the above flags, then you must also include a flag to load an external dataset:
$ python karoo_gp_server.py -ker c -typ r -bas 4 -fil /[path]/[to_your]/[filename].csv
2016-07-07 23:00:21 -06:00
'''
2015-11-04 03:56:07 -07:00
2016-07-13 22:43:06 -06:00
import sys # sys.path.append('modules/') to add the directory 'modules' to the current path
import argparse
2015-11-04 03:56:07 -07:00
import karoo_gp_base_class; gp = karoo_gp_base_class.Base_GP()
2016-07-13 22:43:06 -06:00
ap = argparse.ArgumentParser(description = 'Karoo GP Server')
2017-02-07 01:33:38 -07:00
ap.add_argument('-ker', action = 'store', dest = 'kernel', default = 'm', help = '[c,r,m] fitness function: (r)egression, (c)lassification, or (m)atching')
2016-07-13 22:43:06 -06:00
ap.add_argument('-typ', action = 'store', dest = 'type', default = 'r', help = '[f,g,r] Tree type: (f)ull, (g)row, or (r)amped half/half')
2017-06-06 22:12:55 -06:00
ap.add_argument('-bas', action = 'store', dest = 'depth_base', default = 5, help = '[3...10] maximum Tree depth for the initial population')
ap.add_argument('-max', action = 'store', dest = 'depth_max', default = 5, help = '[3...10] maximum Tree depth for the entire run')
2016-07-13 22:43:06 -06:00
ap.add_argument('-min', action = 'store', dest = 'depth_min', default = 3, help = '[3...100] minimum number of nodes')
ap.add_argument('-pop', action = 'store', dest = 'pop_max', default = 100, help = '[10...1000] maximum population')
2017-06-06 22:12:55 -06:00
ap.add_argument('-gen', action = 'store', dest = 'gen_max', default = 30, help = '[1...100] number of generations')
ap.add_argument('-tor', action = 'store', dest = 'tor_size', default = 10, help = '[1...max pop] tournament size')
2017-02-07 01:33:38 -07:00
ap.add_argument('-fil', action = 'store', dest = 'filename', default = 'files/data_MATCH.csv', help = '/path/to_your/[data].csv')
2016-07-13 22:43:06 -06:00
args = ap.parse_args()
2015-11-04 03:56:07 -07:00
2017-02-07 01:33:38 -07:00
# pass the argparse defaults and/or user inputs to the required variables
2016-07-13 22:43:06 -06:00
gp.kernel = str(args.kernel)
tree_type = str(args.type)
tree_depth_base = int(args.depth_base)
gp.tree_depth_max = int(args.depth_max)
gp.tree_depth_min = int(args.depth_min)
gp.tree_pop_max = int(args.pop_max)
gp.generation_max = int(args.gen_max)
filename = str(args.filename)
2017-02-07 01:33:38 -07:00
gp.display = 's' # display mode is set to (s)ilent
gp.evolve_repro = int(0.1 * gp.tree_pop_max) # quantity of a population generated through Reproduction
gp.evolve_point = int(0.0 * gp.tree_pop_max) # quantity of a population generated through Point Mutation
gp.evolve_branch = int(0.2 * gp.tree_pop_max) # quantity of a population generated through Branch Mutation
gp.evolve_cross = int(0.7 * gp.tree_pop_max) # quantity of a population generated through Crossover
2015-11-04 03:56:07 -07:00
2017-06-06 22:12:55 -06:00
gp.tourn_size = int(args.tor_size) # qty of individuals entered into each tournament; can be adjusted in 'i'nteractive mode
gp.precision = 4 # the number of floating points for the round function in 'fx_fitness_eval'
2015-11-04 03:56:07 -07:00
# run Karoo GP
2016-07-13 22:43:06 -06:00
gp.karoo_gp(tree_type, tree_depth_base, filename)