Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Computer Science Lecture 6: Genetic Algorithms https://sites.google.com/site/mtsiddiquecs/ai.

Similar presentations


Presentation on theme: "Department of Computer Science Lecture 6: Genetic Algorithms https://sites.google.com/site/mtsiddiquecs/ai."— Presentation transcript:

1 Department of Computer Science Lecture 6: Genetic Algorithms https://sites.google.com/site/mtsiddiquecs/ai

2 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 2 The Traditional Approach  Ask an expert  Adapt existing designs  Trial and error

3 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 3 Comparisons  Traditional  best guess may lead to local, not global optimum  Nature  population of guesses more likely to find a better solution

4 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 4 More Comparisons  Nature  not very efficient at least a 20 year wait between generations not all mating combinations possible  Genetic algorithm  efficient and fast optimization complete in a matter of minutes mating combinations governed only by “fitness”

5 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 5 Real-World Uses of Genetic Algorithms  A heuristic search technique used in computing and Artificial Intelligence to find optimized solutions to search problems using techniques inspired by evolutionary biology: mutation, selection, reproduction [inheritance] and recombination http://brainz.org/15-real-world-applications-genetic-algorithms/

6 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 6 Automotive Design  Using Genetic Algorithms  design composite materials and aerodynamic shapes for race carsrace cars  Design regular means of transportation (including aviation)  Return combinations of best materials and best engineering to provide faster, lighter, more fuel efficient and safer vehicles http://brainz.org/15-real-world-applications-genetic-algorithms/

7 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 7 Engineering Design  optimize the structural and operational design of buildings, factories, machines  design of heat exchangers, robot gripping arms, satellite booms, building trusses, flywheels, turbines

8 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 8 Robotics  optimal designs and components for each specific use  multi-purpose, learning robots

9 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 9 Optimized Telecommunications Routing  allow for dynamic and anticipatory routing of circuits for telecommunicati ons networkstelecommunicati ons networks  GA circuit-search

10 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 10 Joke and Pun Generation  JAPE (automated pun generator) inspired STANDUP program to design communications strategies for people working with children who suffer communications disabilities  GAs that search for jokes and puns.  These clever GAs will let you input a word you wish to pun or a subject you'd like to joke about, and will return a variety of solutions

11 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 11 Finance and Investment Strategies Gene Expression Profiling Computer-Aided Molecular Design Encryption and Code Breaking Computer Gaming Trip, Traffic and Shipment Routing

12 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 12 The Genetic Algorithm Approach  Define limits of variable parameters  Generate a random population of designs  Assess “fitness” of designs  Mate selection  Crossover  Mutation  Reassess fitness of new population

13 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 13 A “Population”

14 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 14 Ranking by Fitness: 14

15 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 15 Mate Selection: 15 Fittest are copied and replaced less-fit

16 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 16 Mate Selection Roulette: 16 Increasing the likelihood but not guaranteeing the fittest reproduction

17 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 17 Crossover: Exchanging information through some part of information (representation)

18 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 18 Mutation : 18 Random change of binary digits from 0 to 1 and vice versa (to avoid local minima)

19 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 19 Best Design

20 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 20 The GA Cycle 20

21 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 21 The Genetic Algorithm  Directed search algorithms based on the mechanics of biological evolution  Developed by John Holland, University of Michigan (1970’s)  To understand the adaptive processes of natural systems  To design artificial systems software that retains the robustness of natural systems http://www.dbai.tuwien.ac.at/staff/musliu/ProblemSolvingAI/Class9GATutorial.ppt

22 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 22 The Genetic Algorithm (cont.)  Provide efficient, effective techniques for optimization and machine learning applications  Widely-used today in business, scientific and engineering circles

23 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 23 Components of a GA A problem to solve, and...  Encoding technique (gene, chromosome)  Initialization procedure (creation)  Evaluation function (environment)  Selection of parents (reproduction)  Genetic operators (mutation, recombination)  Parameter settings (practice and art)

24 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 24 Simple Genetic Algorithm { initialize population; evaluate population; while TerminationCriteriaNotSatisfied { select parents for reproduction; perform recombination and mutation; evaluate population; }

25 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 25 The GA Cycle of Reproduction reproduction population evaluation modification discard deleted members parents children modified children evaluated children

26 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 26 Population Chromosomes could be:  Bit strings (0101... 1100)  Real numbers (43.2 -33.1... 0.0 89.2)  Permutations of element(E11 E3 E7... E1 E15)  Lists of rules (R1 R2 R3... R22 R23)  Program elements (genetic programming) ... any data structure... 26 population

27 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 27 Representation (In case of TSP) Representation is an ordered list of city numbers known as an order-based GA. 1) London 3) Dunedin 5) Beijing 7) Tokyo 2) Venice 4) Singapore 6) Phoenix 8) Victoria CityList1 (3 5 7 2 1 6 4 8) CityList2 (2 5 7 6 8 1 3 4)

28 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 28 Reproduction reproduction population parents children Parents are selected at random with selection chances biased in relation to chromosome evaluations.

29 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 29 Chromosome Modification  Modifications are stochastically triggered  Operator types are:  Mutation  Crossover (recombination) modification children modified children

30 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 30 Mutation Mutation involves reordering of the list: * Before: (5 8 7 2 1 6 3 4) After: (5 8 6 2 1 7 3 4)

31 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 31 Mutation: Local Modification  Causes movement in the search space (local or global)  Restores lost information to the population Before: (1 0 1 1 0 1 1 0) After: (0 1 1 0 0 1 1 0) Before: (1.38 -69.4 326.44 0.1) After: (1.38 -67.5 326.44 0.1)

32 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 32 Crossover: Recombination P1 (0 1 1 0 1 0 0 0) (0 1 0 0 1 0 0 0) C1 P2 (1 1 0 1 1 0 1 0) (1 1 1 1 1 0 1 0) C2 Crossover is a critical feature of genetic algorithms:  It greatly accelerates search early in evolution of a population  It leads to effective combination of schemata (subsolutions on different chromosomes) *

33 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 33 Crossover Crossover combines inversion and recombination: * * Parent1 (3 5 7 2 1 6 4 8) Parent2 (2 5 7 6 8 1 3 4) Child (5 8 7 2 1 6 3 4) This operator is called the Order1 crossover.

34 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 34 Evaluation  The evaluator decodes a chromosome and assigns it a fitness measure  The evaluator is the only link between a classical GA and the problem it is solving evaluation evaluated children modified children

35 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 35 Deletion  Generational GA: entire populations replaced with each iteration  Steady-state GA: a few members replaced each generation population discard discarded members

36 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 36 An Abstract Example 36 Distribution of Individuals in Generation 0 Distribution of Individuals in Generation N

37 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 37 Genetic Algorithm - Example  Goal:  Find the minimum / lowest point  Red line - the best solution  Green line - other solutions http://www.obitko.com/tutorials/genetic-algorithms/ga-basic-description.php

38 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 38 Genetic Algorithm - Example  A set of solutions (represented by chromosomes) called population  Solutions from one population are taken and used to form a new population  This is motivated by a hope, that the new population will be better than the old one  Solutions which are selected to form new solutions (offspring) are selected according to their fitness – (the more suitable they are the more chances they have to reproduce)  This is repeated until some condition (for example number of populations or improvement of the best solution) is satisfied 38

39 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 39 Outline of the Basic Genetic Algorithm 1. [Start] Generate random population of n chromosomes (suitable solutions for the problem) 2. [Fitness] Evaluate the fitness f(x) of each chromosome x in the population 3. [New population] Create a new population by repeating following steps until the new population is complete 1. [Selection] Select two parent chromosomes from a population according to their fitness (the better fitness, the bigger chance to be selected) 2. [Crossover] With a crossover probability cross over the parents to form a new offspring (children). If no crossover was performed, offspring is an exact copy of parents. 3. [Mutation] With a mutation probability mutate new offspring at each locus (position in chromosome). 4. [Accepting] Place new offspring in a new population 4. [Replace] Use new generated population for a further run of algorithm 5. [Test] If the end condition is satisfied, stop, and return the best solution in current population 6. [Loop] Go to step 2 http://www.obitko.com/tutorials/genetic-algorithms/ga-basic-description.php

40 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 40 A Simple Example The Traveling Salesman Problem: Find a tour of a given set of cities so that  each city is visited only once  the total distance traveled is minimized

41 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 41 TSP Example: 30 Cities 41

42 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 42 Solution i (Distance = 941) 42

43 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 43 Solution j (Distance = 800) 43

44 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 44 Solution k (Distance = 652) 44

45 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 45 Best Solution (Distance = 420) 45

46 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 46 Overview of Performance 46

47 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 47 Issues for GA Practitioners  Choosing basic implementation issues:  representation  population size, mutation rate,...  selection, deletion policies  crossover, mutation operators  Termination Criteria  Performance, scalability  Solution is only as good as the evaluation function (often hardest part)

48 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 48 Benefits of Genetic Algorithms  Concept is easy to understand  Modular, separate from application  Supports multi-objective optimization  Good for “noisy” environments  Always an answer; answer gets better with time  Inherently parallel; easily distributed

49 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 49 Benefits of Genetic Algorithms (cont.)  Many ways to speed up and improve a GA- based application as knowledge about problem domain is gained  Easy to exploit previous or alternate solutions  Flexible building blocks for hybrid applications  Substantial history and range of use  Good to find a region of solution including the optimal solution. But slow in giving the optimal solution

50 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 50 When to Use a GA  Alternate solutions are too slow or overly complicated  Need an exploratory tool to examine new approaches  Problem is similar to one that has already been successfully solved by using a GA  Want to hybridize with an existing solution  Benefits of the GA technology meet key problem requirements

51 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 51 Some GA Application Types

52 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 52 Things to concern for GA  How to create chromosomes?  What type of encoding choose?  Crossover  Mutation  How to select parents for crossover?  How to select the better parents for better offspring?

53 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 53 Selection  Chromosomes are selected from the population to be parents to crossover. The problem is how to select these chromosomes  Darwin's evolution theory  the best ones should survive and create new offspring  many methods how to select the best chromosomes  roulette wheel selection, Boltzman selection, tournament selection, rank selection, steady state selection http://www.obitko.com/tutorials/genetic-algorithms/selection.php

54 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 54 Roulette Wheel Selection  Parents are selected according to their fitness.  The better the chromosomes are, the more chances to be selected they have.  Imagine a roulette wheel where are placed all chromosomes in the population, every has its place big accordingly to its fitness function  Then a marble is thrown there and selects the chromosome. Chromosome with bigger fitness will be selected more times.

55 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 55 Roulette Wheel Selection  [Sum] Calculate sum of all chromosome fitnesses in population - sum S.  [Select] Generate random number from interval (0,S) - r.  [Loop] Go through the population and sum fitnesses from 0 - sum s. When the sum s is greater then r, stop and return the chromosome where you are.  Of course, step 1 is performed only once for each population.  Problem: when the fitnesses differs very much  if the best chromosome fitness is 90% of all the roulette wheel then the other chromosomes will have very few chances to be selected

56 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 56 Rank Selection  Rank selection first ranks the population and then every chromosome receives fitness from this ranking.  The worst will have fitness1, second worst 2 etc. and the best will have fitness N (number of chromosomes in population) After this all the chromosomes have a chance to be selected. But this method can lead to slower convergence, because the best chromosomes do not differ so much from other ones.

57 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 57 Steady-State Selection  Main idea of this selection is that big part of chromosomes should survive to next generation.  GA then works in a following way.  In every generation are selected a few (good - with high fitness) chromosomes for creating a new offspring. Then some (bad - with low fitness) chromosomes are removed and the new offspring is placed in their place.  The rest of population survives to new generation.

58 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 58 Elitism  When creating new population by crossover and mutation, we have a big chance, that we will loose the best chromosome.  Elitism is name of method, which first copies the best chromosome (or a few best chromosomes) to new population. The rest is done in classical way.  Elitism can very rapidly increase performance of GA, because it prevents losing the best found solution.

59 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 59 Crossover  if there is no crossover  offspring is exact copy of parents.  If there is a crossover  offspring is made from parts of parents' chromosome.  If crossover probability is 100%  then all offspring is made by crossover.  If it is 0%,  whole new generation is made from exact copies of chromosomes from old population (but this does not mean that the new generation is the same!).

60 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 60 Crossover  Crossover is made in hope that new chromosomes will have good parts of old chromosomes and maybe the new chromosomes will be better.  However it is good to leave some part of population survive to next generation.

61 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 61 Mutation probability  how often will be parts of chromosome mutated  If there is no mutation  offspring is taken after crossover (or copy) without any change.  If mutation is performed,  part of chromosome is changed  If you try to increase mutation probability to 100%, GA will start to behave very strange, nearly like if the mutation probability is 0%. Do you know why?

62 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 62 100% Mutation Probability  If the chromosome is mutated, normally a few bits are changed and so the solution is a bit changed.  But if all bits in chromosome are mutated (because of 100% mutation probability), then the chromosome string is in fact inverted.  Then we have inversion and no mutation, so whole population degenerates very quickly. It behaves like with no mutation because of 0% mutation probability. http://www.obitko.com/tutorials/genetic-algorithms/parameters.php

63 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 63 Genetic Approach When applied to strings of genes, the approaches are classified as genetic algorithms (GA) When applied to pieces of executable programs, the approaches are classified as genetic programming (GP) GP operates at a higher level of abstraction than GA

64 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 64 Examples  Hello World - http://www.generation5.org/content/2003/gahelloworld.asp http://www.generation5.org/content/2003/gahelloworld.asp  http://library.thinkquest.org/29483/genetic_example.sh tml http://library.thinkquest.org/29483/genetic_example.sh tml  www.dbai.tuwien.ac.at/staff/musliu/.../Class9GATutori al.ppt www.dbai.tuwien.ac.at/staff/musliu/.../Class9GATutori al.ppt  http://www.mathworks.com/help/toolbox/gads/f6691.ht ml http://www.mathworks.com/help/toolbox/gads/f6691.ht ml  http://www.youtube.com/watch?v=mec7fYHH5u0&feat ure=related http://www.youtube.com/watch?v=mec7fYHH5u0&feat ure=related  http://www.crhc.illinois.edu/IGATE/ga_example/ga_ex ample.html http://www.crhc.illinois.edu/IGATE/ga_example/ga_ex ample.html

65 © M. Tariq Siddique 2015 Depart of Computer Science | Bahria University 65 References  Wikipedia – Genetic Algorithm  http://www.obitko.com/tutorials/genetic-algorithms/ http://www.obitko.com/tutorials/genetic-algorithms/  http://informatics.indiana.edu/larryy/al4ai/lectures/ 03.IntroToGAs.pdf http://informatics.indiana.edu/larryy/al4ai/lectures/ 03.IntroToGAs.pdf  http://www.ai-junkie.com/ga/intro/gat1.html http://www.ai-junkie.com/ga/intro/gat1.html  http://www.aero.caltech.edu/~tamer/GATutorial.pdf http://www.aero.caltech.edu/~tamer/GATutorial.pdf  http://dces.essex.ac.uk/staff/rpoli/gp-field- guide/toc.html http://dces.essex.ac.uk/staff/rpoli/gp-field- guide/toc.html  http://www.dbai.tuwien.ac.at/staff/musliu/Problem SolvingAI/Class9GATutorial.ppt http://www.dbai.tuwien.ac.at/staff/musliu/Problem SolvingAI/Class9GATutorial.ppt


Download ppt "Department of Computer Science Lecture 6: Genetic Algorithms https://sites.google.com/site/mtsiddiquecs/ai."

Similar presentations


Ads by Google