0% found this document useful (0 votes)
55 views30 pages

12-Genetic Algorithm

The document discusses local search algorithms and genetic algorithms. Genetic algorithms are a type of evolutionary algorithm inspired by natural selection, using techniques such as mutation and crossover to evolve solutions to problems over generations. The document provides an example of using a genetic algorithm to solve the 8 queens problem, representing board states as strings, calculating fitness, selecting parents for reproduction, and repeating until finding a solution.

Uploaded by

Muhammad Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views30 pages

12-Genetic Algorithm

The document discusses local search algorithms and genetic algorithms. Genetic algorithms are a type of evolutionary algorithm inspired by natural selection, using techniques such as mutation and crossover to evolve solutions to problems over generations. The document provides an example of using a genetic algorithm to solve the 8 queens problem, representing board states as strings, calculating fitness, selecting parents for reproduction, and repeating until finding a solution.

Uploaded by

Muhammad Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1

Lahore Garrison University


CSC363-Artificial Intelligence
Week-6 Lecture-12
Semester#06
2
Preamble

 Beyond Classical Search: Local Search

 Local Beam Search

 Keeps ‘k’ states for record and jump to best successor per need.

 Stochastic Beam Search – ‘k’ random successors

 Probability – Successor being an increasing function of its value.

Lahore Garrison University


3
Evolutionary Algorithm (Eas)

 Genetic Algorithms (GAs) are search based algorithms based on the concepts of natural selection
and genetics.
 GAs are a subset of a much larger branch of computation known as Evolutionary Computation.
 Evolutionary algorithms have three main characteristics:
 Population-Based The set of current solutions from which new solutions are to be generated is
called the population.
 Fitness-Oriented There is a fitness value associated with each individual solution calculated from
a fitness function. Such fitness value reflects how good the solution is.
 Variation-Driven individual solutions will undergo a number of variations to generate new
solutions.

Lahore Garrison University


4
Genetic Algorithm(John Holland)

 GA is based on Darwin’s theory of evolution.


 It is a slow gradual process that works by making changes to the making slight and slow
changes.
 makes slight changes to its solutions slowly until getting the best solution.
 This algorithm reflects the process of natural selection where the fittest individuals are
selected for reproduction in order to produce offspring of the next generation

Lahore Garrison University


5

Lahore Garrison University


6
Initial Population

 The process begins with a set of individuals which is called a Population.


 An individual is characterized by a set of parameters (variables) known as Genes.
 Genes are joined into a string to form a Chromosome (solution).
 Fitness Function
 (also known as the Evaluation Function) evaluates how close a given solution is to the
optimum solution of the desired problem. It determines how fit a solution is

Lahore Garrison University


7
Selection

 The idea of selection phase is to select the fittest individuals and let them pass their genes
to the next generation.
 Two pairs of individuals (parents) are selected based on their fitness scores. Individuals
with high fitness have more chance to be selected for reproduction.
 Crossover
 also called recombination, is a genetic operator used to combine the genetic information of two
parents to generate new offspring. ...

Lahore Garrison University


8
Example (Crossover)

 For example, consider the crossover point to be 3 as shown below:

Offspring are created by exchanging the genes of The new offspring are


parents among themselves until the crossover added to the population.
point is reached.

Lahore Garrison University


9
Mutation

 In certain new offspring formed, some of their genes can be subjected to a mutation with a low
random probability. This implies that some of the bits in the bit string can be flipped.

 Mutation occurs to maintain diversity within the population and prevent premature convergence.

Lahore Garrison University


10
Mutation

 Note that without mutation the offspring will have all of its properties from its parents. To
add new features to such offspring, mutation took place
 The individual after mutation is called mutant.

Lahore Garrison University


11
Genetic Algorithm

 A variant of Stochastic Beam Search


 Successor states are generated by combining two parent states.
 Whereas, previous algorithms modified a single state.
 Begins;
set of random ‘k’ states known as “Population”.
 Each state is represented by a string over a finite alphabet.
 A string of 0s and 1s.
 Each state is known as an “Individual”.
 Each state is rated by the Objective Function or “Fitness Function”.

Lahore Garrison University


12
Solving the 8-Queen problem using the
Genetic Algorithm

 Step 1: Representing individuals


 Step 2: Generating and initial Population
 Step 3: Applying a Fitness Function
 Step 4: Selecting parents for mating in accordance to their fitness
 Step 5:Crossove of parents to produce new generation
 Step 6: Mutation of new generation to bring diversity
 Step 7: Repeat until solution is reached

Lahore Garrison University


13
Step 1: Representing individuals

Lahore Garrison University


14
Step 2: Generating and initial Population

Lahore Garrison University


15
Step 3: Applying a Fitness Function

Lahore Garrison University


16
Step 3: Applying a Fitness Function

Total = 23

Lahore Garrison University


17
Step 3: Applying a Fitness Function (Cont.)

Total =
78

Lahore Garrison University


18
Step 4: Selection

Lahore Garrison University


19
Step 4: Selection (Cont.)

Lahore Garrison University


20
Step 5: Crossover

Lahore Garrison University


21
Step 6: Mutation

Lahore Garrison University


22
Step 7: Repeat

Lahore Garrison University


23
Genetic Algorithm – Example 8-Queens

 An 8-queens state must specify the positions of 8-Queens.


 Each in a column of 8-squares.
 Requires 8 x log2 8 = 24 bits.
 State should be represented as 8-digits (1 to 8).
 A fitness function should return higher values for better states.
 We choose number of nonattacking pairs of queens.
 Values of four states are 24, 23, 20 and 11 in current problem.
 Probability of being chosen is directly proportional to Fitness score.

Lahore Garrison University


24
Genetic Algorithm - Example

Lahore Garrison University


25
Properties of similarity

 Combine an uphill tendency with random exploration and exchange of information among
parallel search threads.
 Advantage, genetic algorithm comes from the crossover operation.
 If the positions of the genetic code are permuted initially in a random order, a crossover
conveys no advantage.
 Raises the level of granularity.
 A useful block can be combined with other blocks to construct a solution.

Lahore Garrison University


26

Algorithm

Lahore Garrison University


27

Lahore Garrison University


28
Lesson Preview

 Beyond Classical Search: Local Search


 Genetic Algorithm – A variant of Stochastic Beam Search
 Generates successor states by combining two parent states.
 Analogy to natural selection.
 8-Queens problem
 Initial population
 Fitness function
 Selection
 Crossover
 Mutation
Lahore Garrison University
29
Next Lesson Preview

 Adversarial Search

 Games

 Optimal decisions in games

 Alpha-Beta Pruning

Lahore Garrison University


30
References

 To cover this topic, different reference material has been used for consultation.

 Artificial Intelligence: A Modern Approach by Stuart J. Russell and Peter Norvig, 3 rd edition,

2010. Chapter # 4 – 4.1-4.3

 Google search engine

Lahore Garrison University

You might also like