Package: evol
Evolis clear dsl for composable evolutionary algorithms that optimised for joy.InstallationWe currently support python3.6 and python3.7 and you can install it via pip.pip install evolDocumentationFor more details you can read thedocsbut we advice everyone to get start by first checking out the examples in the/examplesdirectory. These stand alone examples should show the spirit of usage better than the docs.The GistThe main idea is that you should be able to define a complex algorithm
in a composable way. To explain what we mean by this:  let's consider
two evolutionary algorithms for travelling salesman problems.The first approach takes a collections of solutions and applies:a survival where only the top 50% solutions survivethe population reproduces using a crossover of genescertain members mutaterepeat this, maybe 1000 times or more!We can also think of another approach:pick the best solution of the populationmake random changes to this parent and generate new solutionsrepeat this, maybe 1000 times or more!One could even combine the two algorithms into a new one:run algorithm 1 50 timesrun algorithm 2 10 timesrepeat this, maybe 1000 times or more!You might notice that many parts of these algorithms are similar and it
is the goal of this library is to automate these parts. We hope to
provide an API that is fun to use and easy to tweak your heuristics in.A working example of something silimar to what is depicted above is shown below. You can also find this code as an example in the/examples/simple_nonlinear.py.importrandomfromevolimportPopulation,Evolutionrandom.seed(42)defrandom_start():"""This function generates a random (x,y) coordinate"""return(random.random()-0.5)*20,(random.random()-0.5)*20deffunc_to_optimise(xy):"""This is the function we want to optimise (maximize)"""x,y=xyreturn-(1-x)**2-2*(2-x**2)**2defpick_random_parents(pop):"""This is how we are going to select parents from the population"""mom=random.choice(pop)dad=random.choice(pop)returnmom,daddefmake_child(mom,dad):"""This function describes how two candidates combine into a new candidateNote that the output is a tuple, just like the output of `random_start`We leave it to the developer to ensure that chromosomes are of the same type"""child_x=(mom[0]+dad[0])/2child_y=(mom[1]+dad[1])/2returnchild_x,child_ydefadd_noise(chromosome,sigma):"""This is a function that will add some noise to the chromosome."""new_x=chromosome[0]+(random.random()-0.5)*sigmanew_y=chromosome[1]+(random.random()-0.5)*sigmareturnnew_x,new_y# We start by defining a population with candidates.pop=Population(chromosomes=[random_start()for_inrange(200)],eval_function=func_to_optimise,maximize=True)# We define a sequence of steps to change these candidatesevo1=(Evolution().survive(fraction=0.5).breed(parent_picker=pick_random_parents,combiner=make_child).mutate(func=add_noise,sigma=1))# We define another sequence of steps to change these candidatesevo2=(Evolution().survive(n=1).breed(parent_picker=pick_random_parents,combiner=make_child).mutate(func=add_noise,sigma=0.2))# We are combining two evolutions into a third one. You don't have to# but this approach demonstrates the flexibility of the library.evo3=(Evolution().repeat(evo1,n=50).repeat(evo2,n=10).evaluate())# In this step we are telling evol to apply the evolutions# to the population of candidates.pop=pop.evolve(evo3,n=5)print(f"the best score found:{max([i.fitnessforiinpop])}")Getting StartedThe best place to get started is the/examplesfolder on github.
This folder contains self contained examples that work out of the
box.How does it compare to ...... deap?We think our library is more composable and pythonic while not removing any functionality. Our library may be a bit slower though.... hyperopt?Since we force the user to make the actual algorithm we are less black boxy. Hyperopt is meant for hyperparameter tuning for machine learning and has better support for search in scikit learn.... inspyred?The library offers a simple way to get started but it seems the project is less actively maintained than ours.