GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - PytLab/gaft: A Genetic Algorithm Framework in Python (not for production level)

BranchesTags
Open more actions menu

Latest commit

 

History

298 Commits
298 Commits

Folders and files

NameName
Last commit message
Last commit date
docs @ b377642
docs @ b377642
 
 
examples
examples
 
 
gaft
gaft
 
 
gasol
gasol
 
 
.coveragerc
.coveragerc
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
INSTALL.md
INSTALL.md
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.rst
README.rst
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 

Repository files navigation

GAFT

A Genetic Algorithm Framework in pyThon

Build Status Codecov Code Health platform versions Documentation Status

Introduction

GAFT is a general Python Framework for genetic algorithm computation. It provides built-in genetic operators for target optimization and plugin interfaces for users to define your own genetic operators and on-the-fly analysis for algorithm testing.

GAFT is now accelerated using MPI parallelization interfaces. You can run it on your cluster in parallel with MPI environment.

Python Support

GAFT requires Python version 3.x (Python 2.x is not supported).

Installation

  1. Via pip:

    pip install gaft
    
  2. From source:

    python setup.py install
    

If you want GAFT to run in MPI env, please install mpi4py explicitly:

pip install mpi4py

See INSTALL.md for more installation details.

Test

Run unit test:

python setup.py test

Quick start

1. Importing

from gaft import GAEngine
from gaft.components import BinaryIndividual, Population
from gaft.operators import RouletteWheelSelection, UniformCrossover, FlipBitMutation

# Analysis plugin base class.
from gaft.plugin_interfaces.analysis import OnTheFlyAnalysis

2. Define population

indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001)
population = Population(indv_template=indv_template, size=50)
population.init()  # Initialize population with individuals.

3. Create genetic operators

# Use built-in operators here.
selection = RouletteWheelSelection()
crossover = UniformCrossover(pc=0.8, pe=0.5)
mutation = FlipBitMutation(pm=0.1)

4. Create genetic algorithm engine to run optimization

engine = GAEngine(population=population, selection=selection,
                  crossover=crossover, mutation=mutation,
                  analysis=[FitnessStore])

5. Define and register fitness function

@engine.fitness_register
def fitness(indv):
    x, = indv.solution
    return x + 10*sin(5*x) + 7*cos(4*x)

or if you want to minimize it, you can add a minimization decorator on it

@engine.fitness_register
@engine.minimize
def fitness(indv):
    x, = indv.solution
    return x + 10*sin(5*x) + 7*cos(4*x)

6. Define and register an on-the-fly analysis (optional)

@engine.analysis_register
class ConsoleOutput(OnTheFlyAnalysis):
    master_only = True
    interval = 1
    def register_step(self, g, population, engine):
        best_indv = population.best_indv(engine.fitness)
        msg = 'Generation: {}, best fitness: {:.3f}'.format(g, engine.fmax)
        engine.logger.info(msg)

7. Run

if '__main__' == __name__:
    engine.run(ng=100)

8. Evolution curve

https://github.com/PytLab/gaft/blob/master/examples/ex01/envolution_curve.png

9. Optimization animation

https://github.com/PytLab/gaft/blob/master/examples/ex01/animation.gif

See example 01 for a one-dimension search for the global maximum of function f(x) = x + 10sin(5x) + 7cos(4x)

Global maximum search for binary function

https://github.com/PytLab/gaft/blob/master/examples/ex02/surface_animation.gif

See example 02 for a two-dimension search for the global maximum of function f(x, y) = y*sin(2*pi*x) + x*cos(2*pi*y)

Plugins

You can define your own genetic operators for GAFT and run your algorithm test.

The plugin interfaces are defined in /gaft/plugin_interfaces/, you can extend the interface class and define your own analysis class or genetic operator class. The built-in operators and built-in on-the-fly analysis can be treated as an official example for plugins development.

Blogs(Chinese Simplified)

  • GAFT-一个使用Python实现的遗传算法框架
  • 使用MPI并行化遗传算法框架GAFT
  • 遗传算法中几种不同选择算子的比较
  • 遗传算法中适值函数的标定与大变异算法
  • 遗传算法框架GAFT优化小记
  • 机器学习算法实践-Platt SMO和遗传算法优化SVM
  • 遗传算法框架GAFT已支持自定义个体编码方式

TODO

  1. ✅ Parallelization
  2. ✅ Add more built-in genetic operators with different algorithms
  3. 🏃 Add C++ backend(See GASol)

Obtain a copy

The GAFT framework is distributed under the GPLv3 license and can be obtained from the GAFT git repository or PyPI

  • https://github.com/PytLab/gaft
  • https://pypi.python.org/pypi/gaft/

About

A Genetic Algorithm Framework in Python (not for production level)

gaft.readthedocs.io/

Topics

genetic-algorithmglobal-optimizationoptimization-algorithms

Resources

Readme
GPL-3.0 license
Activity

Stars

745 stars

Watchers

30 watching

Forks

213 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.