Implement an easy to use real-coded genetic algorithm (rcga) library, that is both easy to use and to customise.
A real coded-genetic algorithm is a stochastic optimisation technique that can be used in a wide range of applications, from the design of engineering equipment to the determination of optimal parameters of machine learning algorthms.
The current library has the following features:
- Ability to easily specify a search space from a text file
- Ability to easily specify parameters via a text file
- Different operators for selection, crossover and mutation and ability to extend them
- Can write the results to an excel file, including statistics and the set of parameters used, without overwriting previous executions
Excel file with optimal point and evolution of population fitness with generations. The excel file where results are stored is copied from a defined template (set in inputs.yaml), to a subdirectory in 'outputs/'. The current date_time is used to generate the name of the subdirectory and output file. This prevents accidental overwriting.
-
Search space
User-defined decision variables, including lower and upper bounds, as well as the variable type. Types supported are: float, int, enumerate and binary.
-
Main parameters
- opt_type: type of optimisation -- Possible values: min / max --
- seed: seed number to use when generating random numbers -- Possible values: int / None --
- model_function: name of function to be optimised -- Possible values: str --
- population_size: size of the population -- Possible values: positive int --
- max_generations: maximum number of generations to be executed -- Possible values: positive int --
- elitism_params: Elitism. Maps to parameters below.
- selection_params: Selection. Maps to parameters below.
- crossover_params: Crossover. Maps to parameters below.
- mutation_params: Mutation. Maps to parameters below.
- output_template: name of the excel template for results -- Possible values: str --
- write_to_console: determines whether results are written to the console or not -- Possible values: True / False --
-
Elitism
- use_elitism: decides whether elitism is used or not -- Possible values: True / False --
- elitism_function: name of elitism function used -- Possible values: str --
- n_ind_elitism: number of individuals maintained from one generation to the next -- Possible values: positive int --
-
Selection
- selection_function: name of selection function used -- Possible values: str --
- n_ind_tournament: number of individuals in tournament -- Possible values: int --
- mating_pool_fraction: determines size of mating pool (fraction of population size) -- Possible values: float in interval [0, 1] --
-
Crossover
- crossover_function: name of crossover function used -- Possible values: str --
- alpha: parameter that determines new crossover offspring -- Possible values: float --
- p_crossover: probability of crossover -- Possible values: float in interval [0, 1 --
-
Mutation
- mutation_function: name of mutation function used -- Possible values: str --
- distribution_constant: constant in polynomial mutation -- Possible values: float --
- p_mutation: probability of mutation -- Possible values: float in interval [0, 1] --
- Tournament selection
- Blend-alpha crossover
- Polynomial mutation
- Elitism
Python3 including the libraries:
- math
- os
- os.path
- datetime
- openpyxl
- sys
- copy
- random
This work is still in development.
- Add sql connectivity
- Add more operators
- Add more statistics (especially on operator performance)
- Open ga_main.py and run it.
-
Define a function in model/models.py and set model name in input parameters
-
Define a search space in the inputs file. This corresponds to the set of decision variables
-
Open ga_main.py and run it.