This Python module comprises a modified Genetic Algorithm where a new intermediate step, gene variation, is introduced, and a mutation defined by a Gaussian distribution with a standard deviation that adjusts based on the results of each generation. It is capable of optimizing multiple parameters (even in cases of correlation between them - in such instances, it is advisable to maintain a high number of generations).
Mathematical background and performance test: click here
Installation:
Download the latest release, extract it, enter the extracted file, and run the following command via the console.
python setup.py install
mGA = modifiedGA.algorithm( popSize, nGen, nVar, mins, maxs, problem, optimType, info )
Required parameters:
popSize
: Population size (must be at least 10)nGen
: Number of generationsnVar
: Number of variablesmins
: Minimum value in the parameter space of possible values for the variablesmaxs
: Maximum value in the parameter space of possible values for the variablesproblem
: The function to be used in optimization
Important
- The values of
mins
andmaxs
should consist of as many asnVar
value. - The
problem
should take list of variables as parameters and return the result of the function.
Non-required parameters:
seed
(integer) : Sets the initial value of the random number generator as a function of the given number. Using the same seed will always yield the same result.optimType
: Optimization type - 'minimum' or 'maximum' (defaul value is 'minimum')- 'minimum', optimizes the problem to the minimum value.
- 'maximum', optimizes the problem to the maximum value.
info
(bool) : Enable or disable showing information during calculation (default value is True).
results, values = mGA.optimize()
It returns the most optimal result and the parameters associated with this results.
mGA.saveResults( name, graph, xlabel, ylabel, title )
Non-required parameters:
name
: Name of the file/graph which the results will be written (default value is "results")graph
: Specifies whether to create a plot (default value is False)xlabel
: Label of the x-axis on the graph (default value is "Generations")ylabel
: Label of the y-axis on the graph (default value is "Fitness")title
: Title of the graph (default is empty)
Important
The matplotlib module must be installed to plot graphs