SlideShare a Scribd company logo
1 of 33
Local Search
CSI 341 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Classical Search
The search problems we have considered during the Uninformed/Informed Search have the following properties:
▸Observable
– If an agent’s sensors give it access to the complete state of the environment at each point in time, then we
say that the task environment is fully observable.
▸Deterministic
– If the next state of the environment is completely determined by the current state and action executed by the
agent, then we say the environment is deterministic.
▸Known
– In a known environment, the outcomes for all actions are given and the agent won’t have to learn how it works
in order to make good decisions.
Classical search algorithms explore the search space systematically and the solution of the search problem is a sequence of
actions representing paths from an initial state to the goal state.
2
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Local Search
▸There exists some problems where the path to the goal is irrelevant.
▸For example,
In the 8-queens problem what matters is the final configuration of queens, not the order in which they are added.
▸If the path to the goal does not matter, we might consider a different class of algorithms(Local Search), ones that do not
worry about paths at all.
▸Local search algorithms evaluate and modify one or more current states rather than systematically exploring paths from an
initial state.
▸Local Search
- Keep track of single current state
- Move only to neighboring states
- Path followed by the search are not retained
▸Advantages
- Use very little memory
- Can often find reasonable solutions in large or infinite state spaces for which systematic algorithms are unsuitable
- Useful for solving pure optimization problems, in which the aim is to find the best state according to an objective
function
3
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
State-space Landscape
Components >>
▸Location – state
▸Elevation – heuristic cost function or,
objective function.
An optimal algorithm always finds a global
maximum(for objective function)/minimum(for
heuristic cost function)
▸Local Maxima – a peak that is higher than each of
its neighboring states but lower than the global
maximum
▸Plateaux – a plateau is a flat area of the state-
space landscape. It can be a flat local maximum
from which no uphill exit exists, or a shoulder from
which progress is possible.
4
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Steepest-ascent Version
▸Hill-climbing search algorithm is simply a loop that continually moves in the direction of increasing value - that is uphill.
▸It terminates when it reaches a peak where no neighbor has a higher value.
▸It doesn’t maintain a search tree, so the data structure for the current node need only record the state and the value of the
objective function/heuristic cost function.
▸Can randomly choose among the set of best successors, if multiple have the best value.
▸It doesn’t look ahead beyond the immediate neighbors of the current state.
▸Also known as Greedy Local Search
5
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Example
▸8-queens problem:
- Local search algorithms use a complete-state formulation, where each state has 8-queens on the board one per
columns.
- Successors of a state are all possible states generated by moving a single queen to another square in the same
column. (8x7=56 successors)
- Heuristic cost function h is the number of pairs of queens that are attacking each other, either directly or indirectly.
- The global minima of this heuristic function i.e. zero occurs only at perfect solution.
6
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Local minima, h=1Initial State, h=17
Hill-climbing Search >> 8-puzzle
7
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> 4-queen
8
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Drawbacks
Hill-climbing search often gets stuck for the following reasons:
▸Local Maxima >>
▹It is a peak that is higher than each of its neighboring states but lower than the global maximum.
▹For 8-queens problem at local minima, each move of a single queen makes the situation worse.
▸Ridges >>
▹Sequence of local maxima difficult for greedy algorithms to navigate
▸Plateaux >>
▹A plateau is a flat area of the state-space landscape. If can be a flat
local maximum or, a shoulder.
9
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Local Maxima
10
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Performance
▸Randomly generated 8-queens starting state…
▸14% the time it solves the problem
▸86% of the time it gets stuck at a local minimum
▸However…
- Takes only 4 steps on average when it succeeds
- And 3 on average when it gets stuck
- Not bad (for a state space with 88~17 million states)
11
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Sideway Move version
▸If no downhill (uphill) moves, allow sideways moves in hope that algorithm can escape
- Need to place a limit on the possible number of sideways moves to avoid infinite loops
▸For 8-queens
- Now allow sideways moves with a limit of 100
- Raises percentage of problem instances solved from 14 to 94%
- However….
- 21 steps for every successful solution
- 64 for each failure
12
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Hill-climbing Search >> Variations
▸Stochastic hill-climbing
- Random selection among the uphill/downhill moves.
- The selection probability can vary with the steepness of the uphill move.
Sample Algorithm [Uphill version] >>
13
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
eval(vc) = 107, T = const = 10
Hill-climbing Search >> Variations
▸First-choice hill-climbing
- stochastic hill climbing by generating successors randomly until a better one is found
- Useful when there are a very large number of successors
▸Random-restart hill-climbing
- If at first you don’t succeed, try, try again.
- Tries to avoid getting stuck in local maxima.
14
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Simulated Annealing
15
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸A hill-climbing algorithm that never makes downhill moves(for maximization problem) toward states with lower value(or
higher cost) is guaranteed to be incomplete, because it can get stuck on a local maximum.
▸In contrast, a purely random walk-that is moving to successor chosen uniformly at random from the set of successors-is
complete but extremely inefficient.
▸Simulated Annealing is such an algorithm that combines both hill climbing with a random walk in such a way that yields
both efficiency and completeness.
Simulated Annealing
16
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸In metallurgy, annealing is the process used to temper or harden metals and glass by heating them to a high temperature
and then gradually cooling them, thus allowing the material to reach a low energy crystalline state.
▸The simulated-annealing solution is to start by shaking hard (i.e. high temperature) and then gradually reduce the
intensity of the shaking (i.e. lower the temperature).
▸Instead of picking the best move, it picks a random move.
- If the move improves the situation, it is always accepted.
- Otherwise, the algorithm accepts the move with some probability less than 1.
▸The probability decreases exponentially with the badness of the move – the amount ∆E by which the evaluation is
worsened.
▸The probability also decreases as the temperature T goes down. As a result bad moves more likely to be allowed at the
start when T is high, and they become more unlikely as T decreases.
▸If the schedule lowers T slowly enough, the algorithm will find a global optimum with probability approaching 1.
Simulated Annealing >> Algorithm
17
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Simulated Annealing >> Algorithm
18
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Local Beam Search
19
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Because of memory limitations, we are just maintaining one node in memory in our previous local search algorithms.
▸The local beam search keeps track of k states rather than just one.
▹It begins with k randomly generated states.
▹At each step, all the successors of all k states are generated. If any one is a goal, the algorithm halts. Otherwise it
selects the k best successors from the complete list and repeats.
▸In a random restart search each search process runs independently of the others; while in local beam search useful
information is passed among the parallel search threads.
▸The algorithm quickly abandons unfruitful searches and moves its resources to where the most progress is being made.
▸Problem:
- It can suffer from a lack of diversity among the k states - they can quickly become concentrated in a small region
of the state space, making the search little more than an expensive version of hill-climbing.
▸Solution:
- Stochastic Beam Search : Instead of choosing the best k from the pool of candidate successors, stochastic beam
search chooses k successors at random, with the probability of choosing a given successor being an increasing
function of its value.
Genetic Algorithm (GA)
20
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸A Genetic Algorithm is a variant of stochastic beam search in which successor states are generated by combining two
parents rather than by modifying a single state.
▸Population >> GAs begin with a set of k randomly generated states, called population.
▸Individual >> Each state or, individual is represented as a string over finite alphabet.
For example, 8-queens state must specify the positions of 8-queens, each in a column of 8 squares.
- way 1: a bit string requires 8 x log2(8) = 8 x 3 = 24 bits. (problem: cut in the middle of a digit)
- way 2: a string representing a sequence of 8 digits.
▸Genetic algorithms combine an uphill tendency with random exploration and exchange of
information among parallel search threads.
1 6 2 5 7 4 8 3
Genetic Algorithm (GA) >> Fitness Function
21
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Each state/individual is rated by the objective/fitness function. A fitness function should return higher values for better
states.
For 8-queens, fitness function = number of not-attacking pairs of queens, which has a value of 28 for solution.
▸In this variant, we assume that the probability of being chosen for reproducing is directly proportional to the fitness score.
Genetic Algorithm (GA) >> Reproduction & Crossover
22
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Pairs are selected at random for reproduction, in accordance with the calculated probabilities of the previous step.
▸For each pair to be mated, a crossover point is chosen randomly from the positions in the string.
- In our case, the crossover points are after the third digit in the first pair and after the fifth digit in the second pair.
- In our variant, each mating of two parents produces two offsprings.
Genetic Algorithm (GA) >> Reproduction & Crossover
23
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸The population is quite diverse early on in the process, so crossover frequently takes large steps in the state space early in
the search process and smaller steps later on when most individuals are quite similar.
▸The following figure illustrates that when two parent states are quite different, the crossover operation can produce a state
that is a long way from either parent state.
Genetic Algorithm (GA) >> Mutation
24
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Each location is subject to random mutation with a small independent probability.
▸For 8-queens problem, we need to choose a queen at random and moving it to a random square in its column.
▸In our example, one digit was mutated in the first, third and fourth offspring.
Genetic Algorithm (GA) >> Mutation
25
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Genetic Algorithm (GA) >> Comments
26
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Positive points
- Random exploration can find solutions that local search can’t
- Appealing connection to human programming
▸Negative points
- Large number of tunable parameters
- Lack of good empirical studies comparing to simpler methods
- Useful on some set of problems but no convincing evidence that GAs are better than hill-climbing w/random restarts
in general.
Genetic Algorithm (GA) >> Max One Problem
27
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸The Max-One problem is a very simple problem where evolution is used to find a specific gene.
▸A gene is essentially a piece of text filled with random binary values, binary string.
Start Gene: 1010001010
Target Gene: 1111111111
▸The fitness f of a candidate solution to the Max-One problem is the number of ones in its genetic code.
Genetic Algorithm (GA) >> Max One Problem
28
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸We start with a population of n random strings.
▸Suppose that l=10 and n=6
s1= 1111010101 f (s1) = 7
s2= 0111000101 f (s2) = 5
s3= 1110110101 f (s3) = 7
s4= 0100010011 f (s4) = 4
s5= 1110111101 f (s5) = 8
s6= 0100110000 f (s6) = 3
Genetic Algorithm (GA) >> Selection
29
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸We randomly select a subset of the individuals based on their fitness:
Individual i will have a probability =
𝑓(𝑖)
𝑓(𝑖)𝑖
to be chosen.
s1’= 1111010101(s1)
s2’ = 1110110101(s3)
s3’ = 1110111101(s5)
s4’ = 0111000101 (s2)
s5’ = 0100010011 (s4)
s6’ = 1110111101 (s5)
Genetic Algorithm (GA) >> Crossover
30
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸Next we mate strings for crossover. For each couple we first decide whether to actually perform the crossover or not.
▸If we decide to actually perform crossover, we randomly extract the crossover points.
s1’= 1111010101(s1) s1’’ = 1110110101
s2’ = 1110110101(s3) s2’’ = 1111010101
s3’ = 1110111101(s5) s3’’ = 1110111101
s4’ = 0111000101 (s2) s4’’ = 0111000101
s5’ = 0100010011 (s4) s5’’ = 0100011101
s6’ = 1110111101 (s5) s6’’ = 1110110011
Genetic Algorithm (GA) >> Mutation
31
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
▸For each bit that we are to copy to the new population we allow a small probability of error (for example 0.1)
s1’’ = 1110110101 s1’’’ = 1110100101
s2’’ = 1111010101 s2’’’ = 1111110100
s3’’ = 1110111101 s3’’’ = 1110101111
s4’’ = 0111000101 s4’’’ = 0111000101
s5’’ = 0100011101 s5’’’ = 0100011101
s6’’ = 1110110011 s6’’’ = 1110110001
Go through the same process all over again, until a stopping criterion is met.
Genetic Algorithm (GA) >> Previous Question
32
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
33
THANKS!
Any questions?
You can find me at imam@cse.uiu.ac.bd

More Related Content

What's hot

AI Lecture 4 (informed search and exploration)
AI Lecture 4 (informed search and exploration)AI Lecture 4 (informed search and exploration)
AI Lecture 4 (informed search and exploration)Tajim Md. Niamat Ullah Akhund
 
AI 9 | Bayesian Network and Probabilistic Inference
AI 9 | Bayesian Network and Probabilistic InferenceAI 9 | Bayesian Network and Probabilistic Inference
AI 9 | Bayesian Network and Probabilistic InferenceMohammad Imam Hossain
 
AI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAndrew Ferlitsch
 
Uncertain Knowledge in AI from Object Automation
Uncertain Knowledge in AI from Object Automation Uncertain Knowledge in AI from Object Automation
Uncertain Knowledge in AI from Object Automation Object Automation
 
Temporal difference learning
Temporal difference learningTemporal difference learning
Temporal difference learningJie-Han Chen
 
Resolution method in AI.pptx
Resolution method in AI.pptxResolution method in AI.pptx
Resolution method in AI.pptxAbdullah251975
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligencesandeep54552
 
Artificial Intelligence 1 Planning In The Real World
Artificial Intelligence 1 Planning In The Real WorldArtificial Intelligence 1 Planning In The Real World
Artificial Intelligence 1 Planning In The Real Worldahmad bassiouny
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithmsswapnac12
 
03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic Analysis03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic AnalysisAndres Mendez-Vazquez
 
First order logic
First order logicFirst order logic
First order logicChinmay Patel
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmHema Kashyap
 

What's hot (20)

AI Lecture 4 (informed search and exploration)
AI Lecture 4 (informed search and exploration)AI Lecture 4 (informed search and exploration)
AI Lecture 4 (informed search and exploration)
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Planning
PlanningPlanning
Planning
 
AI 3 | Uninformed Search
AI 3 | Uninformed SearchAI 3 | Uninformed Search
AI 3 | Uninformed Search
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
 
Uncertainty in AI
Uncertainty in AIUncertainty in AI
Uncertainty in AI
 
AI 9 | Bayesian Network and Probabilistic Inference
AI 9 | Bayesian Network and Probabilistic InferenceAI 9 | Bayesian Network and Probabilistic Inference
AI 9 | Bayesian Network and Probabilistic Inference
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
AI - Local Search - Hill Climbing
AI - Local Search - Hill ClimbingAI - Local Search - Hill Climbing
AI - Local Search - Hill Climbing
 
Uncertain Knowledge in AI from Object Automation
Uncertain Knowledge in AI from Object Automation Uncertain Knowledge in AI from Object Automation
Uncertain Knowledge in AI from Object Automation
 
AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)
 
Temporal difference learning
Temporal difference learningTemporal difference learning
Temporal difference learning
 
Resolution method in AI.pptx
Resolution method in AI.pptxResolution method in AI.pptx
Resolution method in AI.pptx
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligence
 
Artificial Intelligence 1 Planning In The Real World
Artificial Intelligence 1 Planning In The Real WorldArtificial Intelligence 1 Planning In The Real World
Artificial Intelligence 1 Planning In The Real World
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
 
Np hard
Np hardNp hard
Np hard
 
03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic Analysis03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic Analysis
 
First order logic
First order logicFirst order logic
First order logic
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithm
 

Similar to AI 5 | Local Search

AI3391 Session 11 Hill climbing algorithm.pptx
AI3391 Session 11 Hill climbing algorithm.pptxAI3391 Session 11 Hill climbing algorithm.pptx
AI3391 Session 11 Hill climbing algorithm.pptxAsst.prof M.Gokilavani
 
Heuristic or informed search
Heuristic or informed searchHeuristic or informed search
Heuristic or informed searchHamzaJaved64
 
Numerical analysis genetic algorithms
Numerical analysis  genetic algorithmsNumerical analysis  genetic algorithms
Numerical analysis genetic algorithmsSHAMJITH KM
 
Optimization technique
Optimization techniqueOptimization technique
Optimization techniqueVimal Patel
 
1582997627872.pdf
1582997627872.pdf1582997627872.pdf
1582997627872.pdfAbhilashJain25
 
AI_Session 9 Hill climbing algorithm.pptx
AI_Session 9 Hill climbing algorithm.pptxAI_Session 9 Hill climbing algorithm.pptx
AI_Session 9 Hill climbing algorithm.pptxAsst.prof M.Gokilavani
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithmMegha Sharma
 
UNIT-5 Optimization (Part-1).ppt
UNIT-5 Optimization (Part-1).pptUNIT-5 Optimization (Part-1).ppt
UNIT-5 Optimization (Part-1).pptTvVignesh3
 
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...Petroleum Training Institute
 
24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptxManiMaran230751
 
simple
simplesimple
simpleavy2cess
 
simple
simplesimple
simpleavy2cess
 
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdf
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdfBio-Inspired Optimization Algorithms_BasicAlgorithms.pdf
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdfNeha Jain jain
 

Similar to AI 5 | Local Search (20)

Informed search
Informed searchInformed search
Informed search
 
AI3391 Session 11 Hill climbing algorithm.pptx
AI3391 Session 11 Hill climbing algorithm.pptxAI3391 Session 11 Hill climbing algorithm.pptx
AI3391 Session 11 Hill climbing algorithm.pptx
 
Heuristic or informed search
Heuristic or informed searchHeuristic or informed search
Heuristic or informed search
 
Numerical analysis genetic algorithms
Numerical analysis  genetic algorithmsNumerical analysis  genetic algorithms
Numerical analysis genetic algorithms
 
Optimization technique
Optimization techniqueOptimization technique
Optimization technique
 
1582997627872.pdf
1582997627872.pdf1582997627872.pdf
1582997627872.pdf
 
AI_Session 9 Hill climbing algorithm.pptx
AI_Session 9 Hill climbing algorithm.pptxAI_Session 9 Hill climbing algorithm.pptx
AI_Session 9 Hill climbing algorithm.pptx
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
 
UNIT-5 Optimization (Part-1).ppt
UNIT-5 Optimization (Part-1).pptUNIT-5 Optimization (Part-1).ppt
UNIT-5 Optimization (Part-1).ppt
 
BGA.pptx
BGA.pptxBGA.pptx
BGA.pptx
 
04-local-search.pdf
04-local-search.pdf04-local-search.pdf
04-local-search.pdf
 
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
 
AI_ppt.pptx
AI_ppt.pptxAI_ppt.pptx
AI_ppt.pptx
 
24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx
 
simple
simplesimple
simple
 
simple
simplesimple
simple
 
Lec 6 bsc csit
Lec 6 bsc csitLec 6 bsc csit
Lec 6 bsc csit
 
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdf
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdfBio-Inspired Optimization Algorithms_BasicAlgorithms.pdf
Bio-Inspired Optimization Algorithms_BasicAlgorithms.pdf
 
AI Lesson 10
AI Lesson 10AI Lesson 10
AI Lesson 10
 
02LocalSearch.pdf
02LocalSearch.pdf02LocalSearch.pdf
02LocalSearch.pdf
 

More from Mohammad Imam Hossain

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6Mohammad Imam Hossain
 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingMohammad Imam Hossain
 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTMohammad Imam Hossain
 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchMohammad Imam Hossain
 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3Mohammad Imam Hossain
 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerMohammad Imam Hossain
 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2Mohammad Imam Hossain
 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1Mohammad Imam Hossain
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionMohammad Imam Hossain
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database TransactionsMohammad Imam Hossain
 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaMohammad Imam Hossain
 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelMohammad Imam Hossain
 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageMohammad Imam Hossain
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsMohammad Imam Hossain
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
 

More from Mohammad Imam Hossain (20)

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path Search
 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3
 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and Conquer
 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2
 
DS & Algo 2 - Recursion
DS & Algo 2 - RecursionDS & Algo 2 - Recursion
DS & Algo 2 - Recursion
 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
 
DBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSDBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMS
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational Schema
 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship Model
 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
 
TOC 10 | Turing Machine
TOC 10 | Turing MachineTOC 10 | Turing Machine
TOC 10 | Turing Machine
 
TOC 9 | Pushdown Automata
TOC 9 | Pushdown AutomataTOC 9 | Pushdown Automata
TOC 9 | Pushdown Automata
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

AI 5 | Local Search

  • 1. Local Search CSI 341 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 2. Classical Search The search problems we have considered during the Uninformed/Informed Search have the following properties: ▸Observable – If an agent’s sensors give it access to the complete state of the environment at each point in time, then we say that the task environment is fully observable. ▸Deterministic – If the next state of the environment is completely determined by the current state and action executed by the agent, then we say the environment is deterministic. ▸Known – In a known environment, the outcomes for all actions are given and the agent won’t have to learn how it works in order to make good decisions. Classical search algorithms explore the search space systematically and the solution of the search problem is a sequence of actions representing paths from an initial state to the goal state. 2 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 3. Local Search ▸There exists some problems where the path to the goal is irrelevant. ▸For example, In the 8-queens problem what matters is the final configuration of queens, not the order in which they are added. ▸If the path to the goal does not matter, we might consider a different class of algorithms(Local Search), ones that do not worry about paths at all. ▸Local search algorithms evaluate and modify one or more current states rather than systematically exploring paths from an initial state. ▸Local Search - Keep track of single current state - Move only to neighboring states - Path followed by the search are not retained ▸Advantages - Use very little memory - Can often find reasonable solutions in large or infinite state spaces for which systematic algorithms are unsuitable - Useful for solving pure optimization problems, in which the aim is to find the best state according to an objective function 3 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 4. State-space Landscape Components >> ▸Location – state ▸Elevation – heuristic cost function or, objective function. An optimal algorithm always finds a global maximum(for objective function)/minimum(for heuristic cost function) ▸Local Maxima – a peak that is higher than each of its neighboring states but lower than the global maximum ▸Plateaux – a plateau is a flat area of the state- space landscape. It can be a flat local maximum from which no uphill exit exists, or a shoulder from which progress is possible. 4 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 5. Hill-climbing Search >> Steepest-ascent Version ▸Hill-climbing search algorithm is simply a loop that continually moves in the direction of increasing value - that is uphill. ▸It terminates when it reaches a peak where no neighbor has a higher value. ▸It doesn’t maintain a search tree, so the data structure for the current node need only record the state and the value of the objective function/heuristic cost function. ▸Can randomly choose among the set of best successors, if multiple have the best value. ▸It doesn’t look ahead beyond the immediate neighbors of the current state. ▸Also known as Greedy Local Search 5 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 6. Hill-climbing Search >> Example ▸8-queens problem: - Local search algorithms use a complete-state formulation, where each state has 8-queens on the board one per columns. - Successors of a state are all possible states generated by moving a single queen to another square in the same column. (8x7=56 successors) - Heuristic cost function h is the number of pairs of queens that are attacking each other, either directly or indirectly. - The global minima of this heuristic function i.e. zero occurs only at perfect solution. 6 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU Local minima, h=1Initial State, h=17
  • 7. Hill-climbing Search >> 8-puzzle 7 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 8. Hill-climbing Search >> 4-queen 8 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 9. Hill-climbing Search >> Drawbacks Hill-climbing search often gets stuck for the following reasons: ▸Local Maxima >> ▹It is a peak that is higher than each of its neighboring states but lower than the global maximum. ▹For 8-queens problem at local minima, each move of a single queen makes the situation worse. ▸Ridges >> ▹Sequence of local maxima difficult for greedy algorithms to navigate ▸Plateaux >> ▹A plateau is a flat area of the state-space landscape. If can be a flat local maximum or, a shoulder. 9 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 10. Hill-climbing Search >> Local Maxima 10 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 11. Hill-climbing Search >> Performance ▸Randomly generated 8-queens starting state… ▸14% the time it solves the problem ▸86% of the time it gets stuck at a local minimum ▸However… - Takes only 4 steps on average when it succeeds - And 3 on average when it gets stuck - Not bad (for a state space with 88~17 million states) 11 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 12. Hill-climbing Search >> Sideway Move version ▸If no downhill (uphill) moves, allow sideways moves in hope that algorithm can escape - Need to place a limit on the possible number of sideways moves to avoid infinite loops ▸For 8-queens - Now allow sideways moves with a limit of 100 - Raises percentage of problem instances solved from 14 to 94% - However…. - 21 steps for every successful solution - 64 for each failure 12 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 13. Hill-climbing Search >> Variations ▸Stochastic hill-climbing - Random selection among the uphill/downhill moves. - The selection probability can vary with the steepness of the uphill move. Sample Algorithm [Uphill version] >> 13 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU eval(vc) = 107, T = const = 10
  • 14. Hill-climbing Search >> Variations ▸First-choice hill-climbing - stochastic hill climbing by generating successors randomly until a better one is found - Useful when there are a very large number of successors ▸Random-restart hill-climbing - If at first you don’t succeed, try, try again. - Tries to avoid getting stuck in local maxima. 14 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 15. Simulated Annealing 15 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸A hill-climbing algorithm that never makes downhill moves(for maximization problem) toward states with lower value(or higher cost) is guaranteed to be incomplete, because it can get stuck on a local maximum. ▸In contrast, a purely random walk-that is moving to successor chosen uniformly at random from the set of successors-is complete but extremely inefficient. ▸Simulated Annealing is such an algorithm that combines both hill climbing with a random walk in such a way that yields both efficiency and completeness.
  • 16. Simulated Annealing 16 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸In metallurgy, annealing is the process used to temper or harden metals and glass by heating them to a high temperature and then gradually cooling them, thus allowing the material to reach a low energy crystalline state. ▸The simulated-annealing solution is to start by shaking hard (i.e. high temperature) and then gradually reduce the intensity of the shaking (i.e. lower the temperature). ▸Instead of picking the best move, it picks a random move. - If the move improves the situation, it is always accepted. - Otherwise, the algorithm accepts the move with some probability less than 1. ▸The probability decreases exponentially with the badness of the move – the amount ∆E by which the evaluation is worsened. ▸The probability also decreases as the temperature T goes down. As a result bad moves more likely to be allowed at the start when T is high, and they become more unlikely as T decreases. ▸If the schedule lowers T slowly enough, the algorithm will find a global optimum with probability approaching 1.
  • 17. Simulated Annealing >> Algorithm 17 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 18. Simulated Annealing >> Algorithm 18 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 19. Local Beam Search 19 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Because of memory limitations, we are just maintaining one node in memory in our previous local search algorithms. ▸The local beam search keeps track of k states rather than just one. ▹It begins with k randomly generated states. ▹At each step, all the successors of all k states are generated. If any one is a goal, the algorithm halts. Otherwise it selects the k best successors from the complete list and repeats. ▸In a random restart search each search process runs independently of the others; while in local beam search useful information is passed among the parallel search threads. ▸The algorithm quickly abandons unfruitful searches and moves its resources to where the most progress is being made. ▸Problem: - It can suffer from a lack of diversity among the k states - they can quickly become concentrated in a small region of the state space, making the search little more than an expensive version of hill-climbing. ▸Solution: - Stochastic Beam Search : Instead of choosing the best k from the pool of candidate successors, stochastic beam search chooses k successors at random, with the probability of choosing a given successor being an increasing function of its value.
  • 20. Genetic Algorithm (GA) 20 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸A Genetic Algorithm is a variant of stochastic beam search in which successor states are generated by combining two parents rather than by modifying a single state. ▸Population >> GAs begin with a set of k randomly generated states, called population. ▸Individual >> Each state or, individual is represented as a string over finite alphabet. For example, 8-queens state must specify the positions of 8-queens, each in a column of 8 squares. - way 1: a bit string requires 8 x log2(8) = 8 x 3 = 24 bits. (problem: cut in the middle of a digit) - way 2: a string representing a sequence of 8 digits. ▸Genetic algorithms combine an uphill tendency with random exploration and exchange of information among parallel search threads. 1 6 2 5 7 4 8 3
  • 21. Genetic Algorithm (GA) >> Fitness Function 21 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Each state/individual is rated by the objective/fitness function. A fitness function should return higher values for better states. For 8-queens, fitness function = number of not-attacking pairs of queens, which has a value of 28 for solution. ▸In this variant, we assume that the probability of being chosen for reproducing is directly proportional to the fitness score.
  • 22. Genetic Algorithm (GA) >> Reproduction & Crossover 22 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Pairs are selected at random for reproduction, in accordance with the calculated probabilities of the previous step. ▸For each pair to be mated, a crossover point is chosen randomly from the positions in the string. - In our case, the crossover points are after the third digit in the first pair and after the fifth digit in the second pair. - In our variant, each mating of two parents produces two offsprings.
  • 23. Genetic Algorithm (GA) >> Reproduction & Crossover 23 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸The population is quite diverse early on in the process, so crossover frequently takes large steps in the state space early in the search process and smaller steps later on when most individuals are quite similar. ▸The following figure illustrates that when two parent states are quite different, the crossover operation can produce a state that is a long way from either parent state.
  • 24. Genetic Algorithm (GA) >> Mutation 24 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Each location is subject to random mutation with a small independent probability. ▸For 8-queens problem, we need to choose a queen at random and moving it to a random square in its column. ▸In our example, one digit was mutated in the first, third and fourth offspring.
  • 25. Genetic Algorithm (GA) >> Mutation 25 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 26. Genetic Algorithm (GA) >> Comments 26 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Positive points - Random exploration can find solutions that local search can’t - Appealing connection to human programming ▸Negative points - Large number of tunable parameters - Lack of good empirical studies comparing to simpler methods - Useful on some set of problems but no convincing evidence that GAs are better than hill-climbing w/random restarts in general.
  • 27. Genetic Algorithm (GA) >> Max One Problem 27 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸The Max-One problem is a very simple problem where evolution is used to find a specific gene. ▸A gene is essentially a piece of text filled with random binary values, binary string. Start Gene: 1010001010 Target Gene: 1111111111 ▸The fitness f of a candidate solution to the Max-One problem is the number of ones in its genetic code.
  • 28. Genetic Algorithm (GA) >> Max One Problem 28 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸We start with a population of n random strings. ▸Suppose that l=10 and n=6 s1= 1111010101 f (s1) = 7 s2= 0111000101 f (s2) = 5 s3= 1110110101 f (s3) = 7 s4= 0100010011 f (s4) = 4 s5= 1110111101 f (s5) = 8 s6= 0100110000 f (s6) = 3
  • 29. Genetic Algorithm (GA) >> Selection 29 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸We randomly select a subset of the individuals based on their fitness: Individual i will have a probability = 𝑓(𝑖) 𝑓(𝑖)𝑖 to be chosen. s1’= 1111010101(s1) s2’ = 1110110101(s3) s3’ = 1110111101(s5) s4’ = 0111000101 (s2) s5’ = 0100010011 (s4) s6’ = 1110111101 (s5)
  • 30. Genetic Algorithm (GA) >> Crossover 30 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸Next we mate strings for crossover. For each couple we first decide whether to actually perform the crossover or not. ▸If we decide to actually perform crossover, we randomly extract the crossover points. s1’= 1111010101(s1) s1’’ = 1110110101 s2’ = 1110110101(s3) s2’’ = 1111010101 s3’ = 1110111101(s5) s3’’ = 1110111101 s4’ = 0111000101 (s2) s4’’ = 0111000101 s5’ = 0100010011 (s4) s5’’ = 0100011101 s6’ = 1110111101 (s5) s6’’ = 1110110011
  • 31. Genetic Algorithm (GA) >> Mutation 31 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU ▸For each bit that we are to copy to the new population we allow a small probability of error (for example 0.1) s1’’ = 1110110101 s1’’’ = 1110100101 s2’’ = 1111010101 s2’’’ = 1111110100 s3’’ = 1110111101 s3’’’ = 1110101111 s4’’ = 0111000101 s4’’’ = 0111000101 s5’’ = 0100011101 s5’’’ = 0100011101 s6’’ = 1110110011 s6’’’ = 1110110001 Go through the same process all over again, until a stopping criterion is met.
  • 32. Genetic Algorithm (GA) >> Previous Question 32 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 33. 33 THANKS! Any questions? You can find me at imam@cse.uiu.ac.bd