09/26/2024 Department of CSE (AI/ML) 1
22PCOAM11
INTROUCTION TO ARTIFICAL
INTELLIGENCE (R22 – II (Sem 3)
Department of computer science and
engineering (AIML)
Session 5
by
Asst.Prof.M.Gokilavani
GNITC
09/26/2024 Department of CSE (AI & ML)
TEXTBOOK:
• Artificial Intelligence A modern Approach, Third
Edition, Stuart Russell and Peter Norvig, Pearson
Education.
REFERENCES:
• Artificial Intelligence, 3rd
Edn, E. Rich and K.Knight
(TMH).
• Artificial Intelligence, 3rd
Edn, Patrick Henny Winston,
Pearson Education.
• Artificial Intelligence, Shivani Goel, Pearson Education.
• Artificial Intelligence and Expert Systems- Patterson,
Pearson Education.
2
Topics covered in Unit 1
09/26/2024 Department of CSE (AI & ML) 3
• Introduction to AI : Intelligent Agent
• Problem-Solving Agents
• Searching for Solutions : Breadth-first search
• Depth-first search
• Hill-climbing search
• Simulated annealing search
• Local Search in Continuous Spaces.
09/26/2024 Department of CSE (AI/ML)
Beyond classical search
• We have seen methods that systematically
explore the search space, possibly using
principled pruning (e.g., A*)
What if we have much larger search spaces?
• Search spaces for some real-world problems
may be much larger e.g., 1030,000 states as in
certain reasoning and planning tasks.
• Some of these problems can be solved by
Iterative Improvement Methods
4
09/26/2024 Department of CSE (AI/ML)
Local Search Algorithms and Optimization
Problems
• In many optimization problems the goal state itself is the
solution.
• The state space is a set of complete configurations.
• Search is about finding the optimal configuration (as in
TSP) or just a feasible configuration (as in scheduling
problems).
• In such cases, one can use iterative improvement, or
local search, methods.
• An evaluation, or objective, function h must be available
that measures the quality of each state.
• Main Idea: Start with a random initial configuration and
make small, local changes to it that improve its quality.
5
09/26/2024 Department of CSE (AI/ML)
Hill Climbing Algorithm
• In Hill-Climbing technique, starting at the base of a hill, we
walk upwards until we reach the top of the hill.
• In other words, we start with initial state and we keep
improving the solution until its optimal.
• It's a variation of a generate-and-test algorithm which
discards all states which do not look promising or seem
unlikely to lead us to the goal state.
• To take such decisions, it uses heuristics (an evaluation
function) which indicates how close the current state is to
the goal state.
• Hill-Climbing = generate-and-test + heuristics
6
09/26/2024 Department of CSE (AI/ML)
Features of Hill Climbing
Following are some main features of Hill Climbing
Algorithm:
• Generate and Test variant: Hill Climbing is the
variant of Generate and Test method. The Generate and
Test method produce feedback which helps to decide
which direction to move in the search space.
• Greedy approach: Hill-climbing algorithm search
moves in the direction which optimizes the cost.
• No backtracking: It does not backtrack the search
space, as it does not remember the previous states.
7
09/26/2024 Department of CSE (AI/ML)
Types of Hill Climbing Algorithm
• Simple hill Climbing
• Steepest-Ascent hill-climbing
• Stochastic hill Climbing
• Random-restart hill climbing
8
09/26/2024 Department of CSE (AI/ML)
Simple Hill Climbing
• Simple hill climbing is the simplest way to implement a
hill climbing algorithm.
• It only evaluates the neighbor node state at a time and
selects the first one which optimizes current cost and
set it as a current state.
• It only checks it's one successor state, and if it finds better
than the current state, then move else be in the same state.
• This algorithm has the following features:
• Less time consuming
• Less optimal solution and the solution is not
guaranteed
9
09/26/2024 Department of CSE (AI/ML)
Algorithm
• Define the current state as an initial state
• Loop until the goal state is achieved or no more operators can be
applied on the current state:
– Apply an operation to current state and get a new state
– Compare the new state with the goal
– Quit if the goal state is achieved
– Evaluate new state with heuristic function and compare it with
the current state
– If the newer state is closer to the goal compared to current
state, update the current state
• As we can see, it reaches the goal state with iterative
improvements. In Hill-Climbing algorithm, finding goal is
equivalent to reaching the top of the hill.
10
09/26/2024 Department of CSE (AI/ML)
Example
• Key point while solving any
hill-climbing problem is to
choose an appropriate
heuristic function.
• Let's define such function h:
• h(x) = +1 for all the blocks
in the support structure if
the block is correctly
positioned otherwise -1 for
all the blocks in the
support structure.
11
09/26/2024 Department of CSE (AI/ML) 12
09/26/2024 Department of CSE (AI/ML)
Steepest-ascent Hill climbing
• Steepest-ascent hill climbing is different from simple
hill climbing search.
• Unlike simple hill climbing search, It considers all the
successive nodes, compares them, and choose the node
which is closest to the solution.
• Steepest hill climbing search is similar to best-first
search because it focuses on each node instead of one.
• Note: Both simple, as well as steepest-ascent hill
climbing search, fails when there is no closer node.
13
09/26/2024 Department of CSE (AI/ML)
Algorithm
• Create a CURRENT node and a GOAL node.
• If the CURRENT node=GOAL node,
return GOAL and terminate the search.
• Loop until a better node is not found to reach the
solution.
• If there is any better successor node present,
expand it.
• When the GOAL is attained, return GOAL and
terminate.
14
09/26/2024 Department of CSE (AI/ML)
Stochastic hill climbing
• Stochastic hill climbing does not focus on all the nodes.
• It selects one node at random and decides whether it should
be expanded or search for a better one.
Random-restart hill climbing
• Random-restart algorithm is based on try and try strategy.
• It iteratively searches the node and selects the best one at
each step until the goal is not found.
• The success depends most commonly on the shape of the
hill.
• If there are few plateaus, local maxima, and ridges, it
becomes easy to reach the destination.
15
09/26/2024 Department of CSE (AI/ML)
Simulated Annealing
16
• A hill-climbing algorithm which never
makes a move towards a lower value
guaranteed to be incomplete because it can
get stuck on a local maximum.
• And if algorithm applies a random walk, by
moving a successor, then it may complete
but not efficient.
• Simulated Annealing is an algorithm which
yields both efficiency and completeness.
09/26/2024 Department of CSE (AI/ML)
Simulated Annealing
• In mechanical term Annealing is a process of hardening a
metal or glass to a high temperature then cooling
gradually, so this allows the metal to reach a low-energy
crystalline state.
• The same process is used in simulated annealing in which
the algorithm picks a random move, instead of picking the
best move.
• If the random move improves the state, then it follows the
same path.
• Otherwise, the algorithm follows the path which has a
probability of less than 1 or it moves downhill and
chooses another path.
17
09/26/2024 Department of CSE (AI/ML)
State-space Diagram for Hill Climbing
18
09/26/2024 Department of CSE (AI/ML)
• Local Maximum: Local maximum is a state which is
better than its neighbor states, but there is also another
state which is higher than it.
• Global Maximum: Global maximum is the best possible
state of state space landscape. It has the highest value of
objective function.
• Current state: It is a state in a landscape diagram where
an agent is currently present.
• Flat local maximum: It is a flat space in the landscape
where all the neighbor states of current states have the
same value.
• Shoulder: It is a plateau region which has an uphill edge.
19
09/26/2024 Department of CSE (AI/ML)
Topics to be covered in next session 6
• Local Search in Continuous Spaces
20
Thank you!!!

22PCOAM11 Session 5 Hill climbing algorithm.pptx

  • 1.
    09/26/2024 Department ofCSE (AI/ML) 1 22PCOAM11 INTROUCTION TO ARTIFICAL INTELLIGENCE (R22 – II (Sem 3) Department of computer science and engineering (AIML) Session 5 by Asst.Prof.M.Gokilavani GNITC
  • 2.
    09/26/2024 Department ofCSE (AI & ML) TEXTBOOK: • Artificial Intelligence A modern Approach, Third Edition, Stuart Russell and Peter Norvig, Pearson Education. REFERENCES: • Artificial Intelligence, 3rd Edn, E. Rich and K.Knight (TMH). • Artificial Intelligence, 3rd Edn, Patrick Henny Winston, Pearson Education. • Artificial Intelligence, Shivani Goel, Pearson Education. • Artificial Intelligence and Expert Systems- Patterson, Pearson Education. 2
  • 3.
    Topics covered inUnit 1 09/26/2024 Department of CSE (AI & ML) 3 • Introduction to AI : Intelligent Agent • Problem-Solving Agents • Searching for Solutions : Breadth-first search • Depth-first search • Hill-climbing search • Simulated annealing search • Local Search in Continuous Spaces.
  • 4.
    09/26/2024 Department ofCSE (AI/ML) Beyond classical search • We have seen methods that systematically explore the search space, possibly using principled pruning (e.g., A*) What if we have much larger search spaces? • Search spaces for some real-world problems may be much larger e.g., 1030,000 states as in certain reasoning and planning tasks. • Some of these problems can be solved by Iterative Improvement Methods 4
  • 5.
    09/26/2024 Department ofCSE (AI/ML) Local Search Algorithms and Optimization Problems • In many optimization problems the goal state itself is the solution. • The state space is a set of complete configurations. • Search is about finding the optimal configuration (as in TSP) or just a feasible configuration (as in scheduling problems). • In such cases, one can use iterative improvement, or local search, methods. • An evaluation, or objective, function h must be available that measures the quality of each state. • Main Idea: Start with a random initial configuration and make small, local changes to it that improve its quality. 5
  • 6.
    09/26/2024 Department ofCSE (AI/ML) Hill Climbing Algorithm • In Hill-Climbing technique, starting at the base of a hill, we walk upwards until we reach the top of the hill. • In other words, we start with initial state and we keep improving the solution until its optimal. • It's a variation of a generate-and-test algorithm which discards all states which do not look promising or seem unlikely to lead us to the goal state. • To take such decisions, it uses heuristics (an evaluation function) which indicates how close the current state is to the goal state. • Hill-Climbing = generate-and-test + heuristics 6
  • 7.
    09/26/2024 Department ofCSE (AI/ML) Features of Hill Climbing Following are some main features of Hill Climbing Algorithm: • Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The Generate and Test method produce feedback which helps to decide which direction to move in the search space. • Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost. • No backtracking: It does not backtrack the search space, as it does not remember the previous states. 7
  • 8.
    09/26/2024 Department ofCSE (AI/ML) Types of Hill Climbing Algorithm • Simple hill Climbing • Steepest-Ascent hill-climbing • Stochastic hill Climbing • Random-restart hill climbing 8
  • 9.
    09/26/2024 Department ofCSE (AI/ML) Simple Hill Climbing • Simple hill climbing is the simplest way to implement a hill climbing algorithm. • It only evaluates the neighbor node state at a time and selects the first one which optimizes current cost and set it as a current state. • It only checks it's one successor state, and if it finds better than the current state, then move else be in the same state. • This algorithm has the following features: • Less time consuming • Less optimal solution and the solution is not guaranteed 9
  • 10.
    09/26/2024 Department ofCSE (AI/ML) Algorithm • Define the current state as an initial state • Loop until the goal state is achieved or no more operators can be applied on the current state: – Apply an operation to current state and get a new state – Compare the new state with the goal – Quit if the goal state is achieved – Evaluate new state with heuristic function and compare it with the current state – If the newer state is closer to the goal compared to current state, update the current state • As we can see, it reaches the goal state with iterative improvements. In Hill-Climbing algorithm, finding goal is equivalent to reaching the top of the hill. 10
  • 11.
    09/26/2024 Department ofCSE (AI/ML) Example • Key point while solving any hill-climbing problem is to choose an appropriate heuristic function. • Let's define such function h: • h(x) = +1 for all the blocks in the support structure if the block is correctly positioned otherwise -1 for all the blocks in the support structure. 11
  • 12.
  • 13.
    09/26/2024 Department ofCSE (AI/ML) Steepest-ascent Hill climbing • Steepest-ascent hill climbing is different from simple hill climbing search. • Unlike simple hill climbing search, It considers all the successive nodes, compares them, and choose the node which is closest to the solution. • Steepest hill climbing search is similar to best-first search because it focuses on each node instead of one. • Note: Both simple, as well as steepest-ascent hill climbing search, fails when there is no closer node. 13
  • 14.
    09/26/2024 Department ofCSE (AI/ML) Algorithm • Create a CURRENT node and a GOAL node. • If the CURRENT node=GOAL node, return GOAL and terminate the search. • Loop until a better node is not found to reach the solution. • If there is any better successor node present, expand it. • When the GOAL is attained, return GOAL and terminate. 14
  • 15.
    09/26/2024 Department ofCSE (AI/ML) Stochastic hill climbing • Stochastic hill climbing does not focus on all the nodes. • It selects one node at random and decides whether it should be expanded or search for a better one. Random-restart hill climbing • Random-restart algorithm is based on try and try strategy. • It iteratively searches the node and selects the best one at each step until the goal is not found. • The success depends most commonly on the shape of the hill. • If there are few plateaus, local maxima, and ridges, it becomes easy to reach the destination. 15
  • 16.
    09/26/2024 Department ofCSE (AI/ML) Simulated Annealing 16 • A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be incomplete because it can get stuck on a local maximum. • And if algorithm applies a random walk, by moving a successor, then it may complete but not efficient. • Simulated Annealing is an algorithm which yields both efficiency and completeness.
  • 17.
    09/26/2024 Department ofCSE (AI/ML) Simulated Annealing • In mechanical term Annealing is a process of hardening a metal or glass to a high temperature then cooling gradually, so this allows the metal to reach a low-energy crystalline state. • The same process is used in simulated annealing in which the algorithm picks a random move, instead of picking the best move. • If the random move improves the state, then it follows the same path. • Otherwise, the algorithm follows the path which has a probability of less than 1 or it moves downhill and chooses another path. 17
  • 18.
    09/26/2024 Department ofCSE (AI/ML) State-space Diagram for Hill Climbing 18
  • 19.
    09/26/2024 Department ofCSE (AI/ML) • Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also another state which is higher than it. • Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest value of objective function. • Current state: It is a state in a landscape diagram where an agent is currently present. • Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have the same value. • Shoulder: It is a plateau region which has an uphill edge. 19
  • 20.
    09/26/2024 Department ofCSE (AI/ML) Topics to be covered in next session 6 • Local Search in Continuous Spaces 20 Thank you!!!