A generic evolutionary algorithm for function optimisation.
Project description
Evolutionary-Optimization
A generic evolutionary algorithm for function optimization.
Introduction
This package allows the user to optimise a function using an evolutionary algorithm. An evolutionary algorithm uses the principles of evolution to find optimal solutions.
Using the Package
Getting Started
To get started with this package install this package:
pip install evolutionary-optimization-algorithm
Running Experiments
To run the code type the following in your terminal. The default experiment is a simple optimization of the $x^{2}$ using integers.
run_evolution
The parameters used for the run can be edited within the main.py file.
Personalising Experiments
To personalise your experiment you can either use the prebuilt phenotypes and genotypes using our interface, or you can build your own. To do so, you simply need to create a new phenotype / genotype class that inherits from the corresponding abstract class and implement the methods to suit your needs. You can mimic the structure of the main script to run your own experiments, like so:
genotype_class = Genotype.get_genotype(Genotypes.<your_phenotype>)
phenotype_class = Phenotype.get_phenotype(Phenotypes.<your_genotype>)
fitness_function_class = FitnessFunction.get_fitness_function(FitnessFunctions.<your_fitness_function>)
fitness_function_instance = fitness_function_class()
evolutionary_algorithm = Evolution(
phenotype=phenotype_class(genotype_class()),
number_of_individuals=<desired_number_of_individuals>,
number_of_generations=<desired_number_of_generations>,
fitness_function=fitness_function_instance,
ratio_of_elite_individuals=<desired_elitism_ratio>
)
You can also plot your fitness over time and the phenotype over time:
evolutionary_algorithm.plot_fitness_score_over_time()
phenotype_function_points_tuple = generate_points_for_function(
phenotype=evolutionary_algorithm.population.best_individual,
bottom_plotting_limit=-10,
upper_plotting_limit=10,
number_of_points=100,
)
evolutionary_algorithm.plot_phenotype_function_and_best_individuals(phenotype_function_points_tuple)
or plot a gif of the algorithm over time:
evolutionary_algorithm.create_gif(phenotype_function_points_tuple)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for evolutionary-optimization-algorithm-3.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 160719bebed183d4612c3a843056a67e4e9d533592257bd1d880d2b7c9e85bd2 |
|
MD5 | 33b6479df61ed6be2992ca464dfc43be |
|
BLAKE2b-256 | d3275697800e9e35e813cbd704496f70fca7670555579c4543f357dbe07ae2ce |
Hashes for evolutionary_optimization_algorithm-3.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50dd184c1e377d7c9abd87333a3afb45fef7902b30b4c74e8ee1053a4251e69e |
|
MD5 | 12a78856be99e6d31b4036b21caa4fb8 |
|
BLAKE2b-256 | 595e55ee65c17d2c8bfe14ad6d97dd28e24d1c79bfc7de9eebf3e9941bf1eed9 |