Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical and Artificial Intelligence in Games Lecture 14

Similar presentations

Presentation on theme: "Logical and Artificial Intelligence in Games Lecture 14"— Presentation transcript:

1 Logical and Artificial Intelligence in Games Lecture 14
Genetic Algorithms Logical and Artificial Intelligence in Games Lecture 14

2 Genetic Algorithms What are they? Uses?
Evolutionary algorithms that make use of operations like mutation, recombination, and selection Uses? Difficult search problems Optimization problems Machine learning Adaptive rule-bases

3 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

4 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 (e.g. finding a mate) Rivalry Different species affect each other by direct confrontation (e.g. hunting) or indirectly by fighting for the same resources

5 Natural Selection Creatures that are not good at completing tasks like hunting or mating 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

6 Genetics Genome 基因組 (class) Genomics Alleles 等位基因 Genotype (instance)
Sequence of genes describing the overall structure of the genetic for a particular species Genomics Study of the meaning of the genes for a particular species Alleles 等位基因 Values that can be assigned to a given gene (individual creature) Genotype (instance) Sequence of alleles

7 Physical Properties Phenetics 表型學 Phenome Phenotype 表現某一顯性特徵之生物個體
Study of physical properties and morphology 形態 of creatures independent of genetic information Phenome General structure of creatures body and attributes Phenotype 表現某一顯性特徵之生物個體 Particular instance of phenome realized as a unique creature Product of genotype and environment forces Examples Phenome: Hair color, skin tone, height Phenotype: Black, Dark, 1.75 m

8 Conversions In real-world mapping between genotypes and phenotypes is hard In AI work it can be done by defining a convenient function or even designing encodings by hand It is often easier to adapt genetic operators to work with the evolutionary data structure used to represent the phenotype than to encode and decode phenotypes

9 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”

10 Genetic Algorithm Evolutionary Process
Here’s the generic outline of the evolutionary process in Genetic Algorithm Initialization – A population of individuals is created Selection – Parents are picked from the population Crossover – Their genetic code is combined together to form the child. Mutation – A few genes of the offspring are changed arbitrarily. Replacement – The offspring is potentially reinserted into the population

11 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

12 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 no magic ways to create them)

13 Selection Want to to give preference to “better” individuals to add to mating pool Mating can be sexual or asexual 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

14 Crossover - 1 In sexual reproduction the genetic codes of both parents are combined to create offspring Asexual 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 (too much like asexual reproduction)

15 Crossover - 2 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”

16 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 intelleigence Example: The occasional (low probably) alteration of a bit position in a string

17 Operators Selection and mutation Selection, crossover, 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”

18 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)

19 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 form the selected pairs Replace members of P(t) with better offspring Set time t = t + 1

20 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

21 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 to choose representations and conversion routines is acceptable

22 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

Download ppt "Logical and Artificial Intelligence in Games Lecture 14"

Similar presentations

Ads by Google