ARTIFICAL INTELLIGENCE
(R18 III(II Sem))
Department of computer science and
engineering (AI/ML)
Session 9
by
Asst.Prof.M.Gokilavani
VITS
3/4/2023 Department of CSE (AI/ML) 1
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.
3/4/2023 Department of CSE (AI/ML) 2
Topics covered in session 9
3/4/2023 Department of CSE (AI/ML) 3
• Problem solving by search-I: Introduction to AI, Intelligent
Agents.
• Problem solving by search-II: Problem solving agents, searching
for solutions
• Uniformed search strategies: BFS, Uniform cost search, DFS,
Iterative deepening Depth-first search, Bidirectional search,
• Informed ( Heuristic) search strategies: Greedy best-first search,
A* search, Heuristic functions
• Beyond classical search: Hill- climbing Search, Simulated annealing
search, Local search in continuous spaces, Searching with non-
deterministic Actions, searching with partial observations, online
search agents and unknown environments.
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
3/4/2023 4
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.
3/4/2023 5
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
3/4/2023 6
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.
3/4/2023 Department of CSE (AI/ML) 7
Types of Hill Climbing Algorithm
• Simple hill Climbing
• Steepest-Ascent hill-climbing
• Stochastic hill Climbing
• Random-restart hill climbing
3/4/2023 Department of CSE (AI/ML) 8
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
3/4/2023 Department of CSE (AI/ML) 9
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.
3/4/2023 10
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.
3/4/2023 Department of CSE (AI/ML) 11
3/4/2023 Department of CSE (AI/ML) 12
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.
3/4/2023 13
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.
3/4/2023 14
Department of CSE (AI/ML)
Simulated Annealing
3/4/2023 Department of CSE (AI/ML) 15
• 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.
• 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.
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.
3/4/2023 16
Department of CSE (AI/ML)
State-space Diagram for Hill Climbing
3/4/2023 Department of CSE (AI/ML) 17
• 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.
3/4/2023 18
Department of CSE (AI/ML)
Genetic Algorithm
3/4/2023 Department of CSE (AI/ML) 19
3/4/2023 Department of CSE (AI/ML) 20
3/4/2023 Department of CSE (AI/ML) 21
Topics to be covered in next session 10
• Local Search in Continuous Spaces
3/4/2023 Department of CSE (AI/ML) 22
Thank you!!!

AI_Session 9 Hill climbing algorithm.pptx

  • 1.
    ARTIFICAL INTELLIGENCE (R18 III(IISem)) Department of computer science and engineering (AI/ML) Session 9 by Asst.Prof.M.Gokilavani VITS 3/4/2023 Department of CSE (AI/ML) 1
  • 2.
    TEXTBOOK: • Artificial IntelligenceA 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. 3/4/2023 Department of CSE (AI/ML) 2
  • 3.
    Topics covered insession 9 3/4/2023 Department of CSE (AI/ML) 3 • Problem solving by search-I: Introduction to AI, Intelligent Agents. • Problem solving by search-II: Problem solving agents, searching for solutions • Uniformed search strategies: BFS, Uniform cost search, DFS, Iterative deepening Depth-first search, Bidirectional search, • Informed ( Heuristic) search strategies: Greedy best-first search, A* search, Heuristic functions • Beyond classical search: Hill- climbing Search, Simulated annealing search, Local search in continuous spaces, Searching with non- deterministic Actions, searching with partial observations, online search agents and unknown environments.
  • 4.
    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 3/4/2023 4 Department of CSE (AI/ML)
  • 5.
    Local Search Algorithmsand 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. 3/4/2023 5 Department of CSE (AI/ML)
  • 6.
    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 3/4/2023 6 Department of CSE (AI/ML)
  • 7.
    Features of HillClimbing 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. 3/4/2023 Department of CSE (AI/ML) 7
  • 8.
    Types of HillClimbing Algorithm • Simple hill Climbing • Steepest-Ascent hill-climbing • Stochastic hill Climbing • Random-restart hill climbing 3/4/2023 Department of CSE (AI/ML) 8
  • 9.
    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 3/4/2023 Department of CSE (AI/ML) 9
  • 10.
    Algorithm • Define thecurrent 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. 3/4/2023 10 Department of CSE (AI/ML)
  • 11.
    Example • Key pointwhile 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. 3/4/2023 Department of CSE (AI/ML) 11
  • 12.
    3/4/2023 Department ofCSE (AI/ML) 12
  • 13.
    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. 3/4/2023 13 Department of CSE (AI/ML)
  • 14.
    Algorithm • Create aCURRENT 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. 3/4/2023 14 Department of CSE (AI/ML)
  • 15.
    Simulated Annealing 3/4/2023 Departmentof CSE (AI/ML) 15 • 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. • 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.
  • 16.
    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. 3/4/2023 16 Department of CSE (AI/ML)
  • 17.
    State-space Diagram forHill Climbing 3/4/2023 Department of CSE (AI/ML) 17
  • 18.
    • 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. 3/4/2023 18 Department of CSE (AI/ML)
  • 19.
  • 20.
    3/4/2023 Department ofCSE (AI/ML) 20
  • 21.
    3/4/2023 Department ofCSE (AI/ML) 21
  • 22.
    Topics to becovered in next session 10 • Local Search in Continuous Spaces 3/4/2023 Department of CSE (AI/ML) 22 Thank you!!!