Worked exercise In many engineering problems, we need to solve complicated equations (e.g. partial differential eqs). In a general simplified notation, an equation may be written as f(x)=c where c is a real valued constant vector, x is a real valued unknown vector and f is a complicated multimodal function, sometimes not even differentiable. The task is to find x that satisfies the equation. Design an evolutionary algorithm to do this! We know how to solve function optimization by evolutionary algorithms. Can we also solve equations? This problem can be transformed into an unconstrained optimization problem by defining an objective function that has to be mininsed. F(x)=(f(x)-c)^2 So, find x that minimizes F(x). What does it mean to design an evolutionary algorithm? (a) the genotypic representation of an individual (b) the fitness evaluation function for an individual (c) evolutionary operators crossover (recombination) mutation (d) selection scheme (e) stopping criteria Explain all your design choices! Comment on possible problems and weaknesses of the algorithm obtained & give suggestions for potential further improvement. Representation: - Remember: Given a problem, different chromosome representations lead to different search spaces. I.e. they determine what solutions are possible to achieve at all. With a poor representation, good solutions may be lost! (x) real valued representation ( ) bit string representation NB. For bit string representation you would need to decide on a finite length of the string. E.g. if you use 4 bits, you can only have 16 different values. If you use a large number of bits, mutations to the lowest bits will move your search points very little and search gets slower. NB. Hamming cliffs (where you have to flip more than one bit to reach the nearest neighbor) further make binary search difficult. Using Gray coding helps. NB. With real valued representation, the mutation operation does not depend on the bit length. Fitness function: F(x). (The smaller the F(x) the higher the ‘fitness’ – as we do minimisation) Evolutionary operations: - Remember: Even if a solution is representable, it doesn’t mean that it is also reachable. Evolutionary operators need to be designed to allow nonzero probabilities of visiting all search space. Mutation: bell-shaped distributions can be used (x) Gaussian mutation (x) Cauchy mutation - - a mix of Gaussian and Cauchy mutations gives nicely distributed mixes of small and large mutations self-adaptation o improves performance by controlling the spread o reduces user-defined parameters but we must take care to do not let the adaptation parameter go near zero Crossover: - global discrete recombination - OR: incorporate heuristic knowledge about estimated local search landscapes, e.g. quadratic recombination. It can select 3 individuals at random as parents and generate an offspring. See details on the slides for Lecture04. Selection scheme: ( ) roulette wheel selection ( ) roulette wheel selection with fitness scaling (x) tournament selection (x) fitness ranking - - roulette wheel selection is not so good unless fitness scaling is used o because it creates ‘super-individuals’ in early stages of evolution o these dominate and cause slow convergence in later stages tournament selection & elitism, or ranking Stopping criteria (x) set a maximum number of function evaluations (x) stop when the improvement in fitness values over several generations is smaller than a pre-defined threshold. Is it good if we achieve zero error? o What if the data was noisy? Programming exercise Write an evolutionary algorithm to find the maximum of the function f(x,y)=exp(-0.7*(x+2)*(x+2))*exp(-0.9*y*y)+2*exp(-(x-5)*(x-6))*exp(-(y-2)*(y-2)) for values –10<x,y<10. Create two versions: (1) binary representation on e.g. 2x16 bits; (2) real-valued representation. Run a few runs and describe the differences in search behavior. (e.g. how long does it take to find the optimum, does it always find the global optimum, how close it gets to the optimum) Implement it without self-adaptation first. Send me a half page text about your findings. If really desperate, here is some Java code and comments written by Throsten: The code is written to be as simple as possible, to make it easy to read, especially for those that do not usually write in java. A number of things could be done more elegant, modular, and efficient - so don't think this is how you have to do it. For example, the individual class should probably allow any type of linear representation - so that you don't have to change it when you go from binary to real. You could then use factories to create and initialize the individuals - rather than hard-coding this into the EA as is done here. Also, you would probably define an interface for mutation and crossover, and then just use different classes to implement different versions. A. Binary Representation A helper class with some random functions is at http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/RandomHelper.java.html This contains methods for random coin flips, and uniform, normal, and Cauchy distributed numbers. The individuals are stored in this class: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/Individual.java.html And the Evolutionary Algorithm itself is here: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/EA.java.html Finally the Fitness Function: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/binary/FitnessFunction.java.html This also does the conversion from binary to real values - there is no need to do the inverse conversion anywhere in the code ! B. Real Representation The individual class has changed slightly, to allow for the different genotype representation: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/Individual.java.html The fitness function does not need to convert from binary anymore: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1- solutions/real/FitnessFunction.java.html The EA now uses different initialization, crossover and mutation methods (but stays the same otherwise): http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/EA.java.html And the random helper has not changed: http://www.cs.bham.ac.uk/~txs/teaching/2002/evo-computation/03-Tutorial-1solutions/real/RandomHelper.java.html Question. (3-rd year exam question in 2001) The payoff matrix of the N-player iterated prisoner’s dilemma game can be defined as follows: Player A C D Number of cooperators among the remaining N-1 players 0 1 2 N-1 0 2 4 … 2(N-1) 1 3 5 … 2(N-1)+1 All players in an N-player game are treated equally. The payoff matrix is symmetrical to all players. Co-evolutionary learning has often been used to learn strategies for playing such games without any external knowledge injection, starting from a population of random strategies. Design a co-evolutionary algorithm for learning to play the iterated 4-player prisoner’s dilemma game. Question. Suppose you have a genotype of length n. Describe in words, what is the difference between n-1 point crossover and uniform crossover? Question. Different selection operators produce different selection pressure. Explain this in words, in terms of exploration versus exploitation. Give some examples. Question. How is your programming exercise, which involved self-adaptation, coming along? Programming exercise Travelling Salesman Problem Aim: To learn to work with order-based representations in evolutionary algorithms. Task: Write an evolutionary algorithm that finds the minimum tour on a 52 city problem. The location of the towns is given on the next page. Use Cartesian distance measures. Hints: You can cut-and-paste the array initialization for the fitness function straight into your code. The ‘Handbook of Evolutionary Computation’ also contains a description of edgemap based crossover, but it is non-greedy version. Questions: - What is the minimum distance? - How far can you get with crossover only, and with mutation only? Submission procedure: Email half page text on your findings in plain text format to A.Kaban@cs.bham.ac.uk Put ‘EC’ into the subject line. private static double[][] towns = new double [][] { { 565.0, 575.0}, {25.0, 185.0}, {345.0, 750.0}, {945.0, 685.0}, {845.0, 655.0}, {880.0, 660.0}, {25.0, 230.0}, {525.0, 1000.0}, {580.0, 1175.0}, {650.0, 1130.0}, {1605.0, 620.0}, {1220.0, 580.0}, {1465.0, 200.0}, {1530.0, 5.0}, {845.0, 680.0}, {725.0, 370.0}, {145.0, 665.0}, {415.0, 635.0}, {510.0, 875.0}, {560.0, 365.0}, {300.0, 465.0}, {520.0, 585.0}, {480.0, 415.0}, {835.0, 625.0}, {975.0, 580.0}, {1215.0, 245.0}, {1320.0, 315.0}, {1250.0, 400.0}, {660.0, 180.0}, {410.0, 250.0}, {420.0, 555.0}, {575.0, 665.0}, {1150.0, 1160.0}, {700.0, 580.0}, {685.0, 595.0}, {685.0, 610.0}, {770.0, 610.0}, {795.0, 645.0}, {720.0, 635.0}, {760.0, 650.0}, {475.0, 960.0}, {95.0, 260.0}, {875.0, 920.0}, {700.0, 500.0}, {555.0, 815.0}, {830.0, 485.0}, {1170.0, 65.0}, {830.0, 610.0}, {605.0, 625.0}, {595.0, 360.0},{1340.0, 725.0}, {1740.0, 245.0}};