1 / 41

Artificial Intelligence Lecture No. 31

Artificial Intelligence Lecture No. 31. Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan. Summary of Previous Lecture. Unsupervised learning Unsupervised learning Approaches

tyne
Télécharger la présentation

Artificial Intelligence Lecture No. 31

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Artificial IntelligenceLecture No. 31 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan.

  2. Summary of Previous Lecture • Unsupervised learning • Unsupervised learning Approaches • Self Organizing Map (SOM)

  3. Today’s Lecture • Genetic algorithms • GA Requirements • Theory of Evolution • GA Strengths • GA Weaknesses

  4. Genetic algorithms • Genetic algorithms were formally introduced in the United States in the 1970s by John Holland at University of Michigan. • The continuing price/performance improvements of computational systems has made them attractive for some types of optimization. • In particular, genetic algorithms work very well on mixed (continuous and discrete), combinatorial problems. They are less susceptible to getting 'stuck' at local optima than gradient search methods. But they tend to be computationally expensive.

  5. Genetic Algorithms • Genetic algorithms are a particular class of evolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover (also called recombination).

  6. What is GA • Genetic algorithms are implemented as a computer simulation in which a population of abstract representations (called chromosomes or the genotype or the genome) of candidate solutions (called individuals, creatures, or phenotypes) to an optimization problem evolves toward better solutions. • Traditionally, solutions are represented in binary as strings of 0s and 1s, but other encodings are also possible.

  7. What is GA • The evolution usually starts from a population of randomly generated individuals and happens in generations. • In each generation, the fitness of every individual in the population is evaluated, multiple individuals are selected from the current population (based on their fitness), and modified (recombined and possibly mutated) to form a new population.

  8. What is GA • The new population is then used in the next iteration of the algorithm. • Commonly, the algorithm terminates when either a maximum number of generations has been produced, or a satisfactory fitness level has been reached for the population. • If the algorithm has terminated due to a maximum number of generations, a satisfactory solution may or may not have been reached.

  9. Chromosome, Genes andGenomes

  10. Genotype and Phenotype • Genotype: – Particular set of genes in a genome • Phenotype: – Physical characteristic of the genotype (smart, beautiful, healthy, etc.)

  11. GA Requirements • A typical genetic algorithm requires two things to be defined: • a genetic representation of the solution domain, and • a fitness function to evaluate the solution domain. • A standard representation of the solution is as an array of bits. Arrays of other types and structures can be used in essentially the same way. • The main property that makes these genetic representations convenient is that their parts are easily allied due to their fixed size, that facilitates simple crossover operation. • Variable length representations may also be used, but crossover implementation is more complex in this case. • Tree-like representations are explored in Genetic programming.

  12. Representation 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 ...

  13. GA Requirements • The fitness function is defined over the genetic representation and measures the quality of the represented solution. • The fitness function is always problem dependent. • For instance, we want to maximize the total value of objects that we can put in a knapsack of some fixed capacity. • A representation of a solution might be an array of bits, where each bit represents a different object, and the value of the bit (0 or 1) represents whether or not the object is in the knapsack. • Not every such representation is valid, as the size of objects may exceed the capacity of the knapsack. • The fitness of the solution is the sum of values of all objects in the knapsack if the representation is valid, or 0 otherwise. In some problems, it is hard or even impossible to define the fitness expression; in these cases, interactive genetic algorithms are used.

  14. A fitness function

  15. Basics of GA • The most common type of genetic algorithm works like this: • a population is created with a group of individuals created randomly. • The individuals in the population are then evaluated. • The evaluation function is provided by the programmer and gives the individuals a score based on how well they perform at the given task. • Two individuals are then selected based on their fitness, the higher the fitness, the higher the chance of being selected. • These individuals then "reproduce" to create one or more offspring, after which the offspring are mutated randomly. • This continues until a suitable solution has been found or a certain number of generations have passed, depending on the needs of the programmer.

  16. Theory of Evolution • Every organism has unique attributes that can be transmitted to its offspring • Offspring are unique and have attributes from each parent • Selective breeding can be used to manage changes from one generation to the next • Nature applies certain pressures that cause individuals to evolve over time

  17. Evolutionary Pressures • Environment • Creatures must work to survive by finding resources like food and water • Competition • Creatures within the same species compete with each other on similar tasks • Rivalry • Different species affect each other by direct confrontation (e.g. hunting) or indirectly by fighting for the same resources

  18. Natural Selection • Creatures that are not good at completing tasks like hunting have fewer chances of having offspring • Creatures that are successful in completing basic tasks are more likely to transmit their attributes to the next generation since there will be more creatures born that can survive and pass on these attributes

  19. Genetic Algorithmic Process • Potential solution for problem domains are encoded using machine representation (e.g. bit strings) that supports variation and selection operations • Mating and mutation operations produce new generation of solutions from parent encodings • Fitness function judges the individuals that are “best” suited (e.g. most appropriate problem solution) for “survival”

  20. Initialization • Initial population must be a representative sample of the search space • Random initialization can be a good idea (if the sample is large enough) • Random number generator can not be biased • Can reuse or seed population with existing genotypes based on algorithms or expert opinion or previous evolutionary cycles

  21. Evaluation • Each member of the population can be seen as candidate solution to a problem • The fitness function determines the quality of each solution • The fitness function takes a phenotype and returns a floating point number as its score • It is problem dependent so can be very simple • It can be a bottleneck if it is not carefully thought out (there are magic ways to create them)

  22. Selection • Want to give preference to “better” individuals to add to mating pool • If entire population ends up being selected it may be desirable to conduct a tournament to order individuals in population • Would like to keep the best in the mating pool and drop the worst (elitism) • Elitism is trade-off with search space completeness

  23. Crossover • In reproduction the genetic codes of both parents are combined to create offspring • A crossover has no impact on the mating pool • Would like to keep 60/40 split between parent contributions • 95/5 splits negate the benefits of crossover

  24. Crossover • If we have selected two strings A = 11111 and B = 00000 • We might choose a uniformly random site (e.g. position 3) and trade bits • This would create two new strings A’ =11100 and B’ = 00011 • These new strings might then be added to the mating pool if they are “fit”

  25. Mutation • Mutations happen at the genome level (rarely and not good) and the genotype level (better for the GA process) • Mutation is important for maintaining diversity in the genetic code • In humans, mutation was responsible for the evolution of intelligence • Example: The occasional (low probably) alteration of a bit position in a string

  26. Operators • Selection and mutation • When used together give us a genetic algorithm equivalent of to parallel, noise tolerant, hill climbing algorithm • Selection, crossover, and mutation • Provide an insurance policy against losing population diversity and avoiding some of the pitfalls of ordinary “hill climbing”

  27. Replacement • Determine when to insert new offspring into the mating pool and which individuals to drop out based on fitness • Steady state evolution calls for the same number of individuals in the population, so each new offspring processed one at a time so fit individuals can remain a long time • In generational evolution, the offspring are placed into a new population with all other offspring (genetic code only survives in kids)

  28. Genetic Algorithm Set time t = 0 Initialize population P(t) While termination condition not met Evaluate fitness of each member of P(t) Select members from P(t) based on fitness Produce offspring from the selected pairs Replace members of P(t) with better offspring Set time t = t + 1

  29. Why use genetic algorithms? • They can solve hard problems • Easy to interface genetic algorithms to existing simulations and models • GA’s are extensible • GA’s are easy to hybridize • GA’s work by sampling, so populations can be sized to detect differences with specified error rates • Use little problem specific code

  30. Traveling Salesman Problem • To use a genetic algorithm to solve the traveling salesman problem we could begin by creating a population of candidate solutions • We need to define mutation, crossover, and selection methods to aid in evolving a solution from this population • At random pick two solutions and combine them to create a child solution, then a fitness function is used to rank the solutions

  31. Traveling Salesman Problem • For crossover we might take two paths (P1 and P2) break them at arbitrary points and define new solutions Left1+Right2 and Left2+Right1 • For mutation we might randomly switch two cites in an existing path

  32. Evolve Algorithm for TSP • Set up initial population • For G generations • Create M mutations and add them to the population • Subject mutations to population constraints and determine their relative fitness • Create C crossovers and add them to the population • Subject crossovers to population constraints and determine their relative fitness

  33. Solving TSP using GA Steps: • Create group of random tours • Stored as sequence of numbers (parents) • Choose 2 of the better solutions • Combine and create new sequences (children) • Problems here: • City 1 repeated in Child 1 • City 5 repeated in Child 2

  34. Modifications Needed • Algorithm must not allow repeated cities • Also, order must be considered • 12345 is same as 32154 • Based upon these considerations, a computer model for N cities can be created • Gets quite detailed

  35. Genetic Algorithm Example Parent A Parent B A B A B E E C C D D

  36. Genetic Algorithm Example Combined Path B A B A A B A B E B C A A B D

  37. Genetic Algorithm Example Child B A B A B E C A B D

  38. Mutations Chance of 1 in 50 to introduce a mutation to the next generation (the child if it replaces a parent, or the first parent) R1 R2 E B F D G A C E A G D F B C

  39. GA Strengths • Do well at avoiding local minima and can often times find near optimal solutions since search is not restricted to small search areas • Easy to extend by creating custom operators • Perform well for global optimizations • Work required to choose representations and conversion routines is acceptable

  40. GA Weaknesses • Do not take advantage of domain knowledge • Not very efficient at local optimization (fine tuning solutions) • Randomness inherent in GA make them hard to predict (solutions can take a long time to stumble upon) • Require entire populations to work (takes lots of time and memory) and may not work well for real-time applications

  41. Summery of Today’s Lecture • Genetic algorithms • GA Requirements • Theory of Evolution • GA Strengths • GA Weaknesses

More Related