Evolutionary Computations in Python
ECsPy (Evolutionary Computations in Python) is a free, open source framework for creating evolutionary computations in Python. Additionally, ECsPy provides an easy-to-use canonical genetic algorithm (GA), evolution strategy (ES), estimation of distribution algorithm (EDA), differential evolution algorithm (DEA), and particle swarm optimizer (PSO) for users who don’t need much customization. Please see the full documentation for more information.
from random import Random from time import time from ecspy import ec from ecspy import terminators from ecspy import observers def generate_binary(random, args): bits = args.get('num_bits', 8) return [random.choice([0, 1]) for i in xrange(bits)] def evaluate_binary(candidates, args): fitness =  base = args.get('base', 2) for cand in candidates: num = 0 exp = len(cand) - 1 for c in cand: num += c * (base ** exp) exp -= 1 fitness.append(num) return fitness rand = Random() rand.seed(int(time())) ga = ec.GA(rand) ga.observer = observers.screen_observer ga.terminator = terminators.evaluation_termination final_population = ga.evolve(evaluator=evaluate_binary, generator=generate_binary, max_evaluations=1000, num_elites=1, pop_size=100, num_bits=10) for individual in final_population: print(individual)
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.