0% found this document useful (0 votes)
10 views44 pages

TTNT 04

Uploaded by

Sơn Thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views44 pages

TTNT 04

Uploaded by

Sơn Thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Artificial Intelligence

Hai Thi Tuyet Nguyen

1
Outline
CHAPTER 1: INTRODUCTION (CHAPTER 1)
CHAPTER 2: INTELLIGENT AGENTS (CHAPTER 2)
CHAPTER 3: SOLVING PROBLEMS BY SEARCHING (CHAPTER 3)
CHAPTER 4: INFORMED SEARCH (CHAPTER 3)
CHAPTER 5: LOGICAL AGENT (CHAPTER 7)
CHAPTER 6: FIRST-ORDER LOGIC (CHAPTER 8, 9)
CHAPTER 7: QUANTIFYING UNCERTAINTY(CHAPTER 13)
CHAPTER 8: PROBABILISTIC REASONING (CHAPTER 14)
CHAPTER 9: LEARNING FROM EXAMPLES (CHAPTER 18)
2
4.1 Informed search algorithm
1. Best-first search
2. A∗ search
CHAPTER 4: 3. Heuristics
INFORMED SEARCH 4.2 Local search algorithms
1. Hill-climbing
AND EXPLORATION 2. Annealing Simulated
3. Genetic algorithm

3
4.1 Informed search algorithm
1. Best-first search
2. A∗ search
3. Heuristics

4
4.1 Review: Tree search
A strategy is defined by picking the order of node expansion

5
4.1 Best-first search
● Idea: use an evaluation function for each node – estimate of “desirability”
⇒ Expand most desirable unexpanded node

● Implementation:
fringe is a queue sorted in decreasing order of desirability

● Special cases:
○ greedy search
○ A∗ search

6
4.1 Romania with step costs in km

7
4.1 Greedy search
● Evaluation function f(n), heuristic function h(n)
f(n) = h(n)
h(n) = estimate of cost from n to the closest goal
E.g., hSLD(n) = straight-line distance from n to Bucharest

● Greedy search expands the node that appears to be closest to goal

8
4.1 Greedy search example

9
4.1 Greedy search example

10
4.1 Greedy search example

11
4.1 Greedy search example

12
4.1 Properties of greedy search
● Complete: no, can get stuck in loops,
E.g., Iasi → Neamt → Iasi → Neamt →
Complete in finite space with repeated-state checking
● Time: O(bm), but a good heuristic can give dramatic improvement
● Space: O(bm), keeps all nodes in memory
● Optimal: No

13
4.1 Properties of greedy search
● Greedy search found path 1 with path cost as 154: S -> E -> G
● Optimal path with path cost as 137: S -> B -> F -> G

14
4.1 A∗ search
● Idea: avoid expanding paths that are already expensive
● Evaluation function f(n) = g(n) + h(n)
g(n) = cost to reach n
h(n) = estimated cost from n to goal
f(n) = estimated total cost of path through n to goal

15
4.1 A∗ search example

16
4.1 A∗ search example

17
4.1 A∗ search example

18
4.1 A∗ search example

19
4.1 A∗ search example

20
4.1 A∗ search example

21
4.1 Properties of A∗
● Complete: yes, if there are not infinitely many nodes with f ≤ f(G)
● Time: O(bm)
● Space: O(bm), keeps all nodes in memory
● Optimal: optimal if h(n) is admissible

22
4.1 Heuristic functions
● The performance of heuristic search algorithms depends on the quality of the heuristic
function.

● Good heuristics can sometimes be constructed:


○ relaxing the problem definition
○ precomputing solution costs for subproblems in a pattern database
○ learning from experience with the problem class

23
4.1 Heuristic functions
Look at heuristics for the 8-puzzle:
● h1(n) = the number of misplaced tiles.
● h2(n) = the sum of the distances of the tiles
from their goal positions, i.e., Manhattan distances

24
4.1 Heuristic functions

25
4.1 Heuristic functions
Look at heuristics for the 8-puzzle:
● h1(n) = the number of misplaced tiles.
● h2(n) = the sum of the distances of the tiles
from their goal positions, i.e., Manhattan distances

h1(S) = 6
h2(S) = 4+0+3+3+1+0+2+1 = 14

If h2(n) ≥ h1(n) for all n (both admissible) then h2 dominates h1 and is better for search

Given any admissible heuristics ha, hb,


h(n) = max(ha(n), hb(n))
is also admissible and dominates ha, hb
26
4.1 Local search algorithms
● In many optimization problems, the solution is the goal state, not the path
● Then the state space = set of complete configurations,
○ find the optimal configuration, e.g., Travelling Salesperson Problem (TSP)
○ find the configuration satisfying constraints, e.g., timetable
● In these cases, we can use the local search algorithms:
keep a single “current state”, try to improve it

27
4.1 Example: Travelling Salesperson Problem
(TSP)
● Start with the complete tour, perform pairwise exchanges
● Variants of this approach get within 1% of optimal very quickly with thousands of
cities.

28
4.1 Example: n-queens
● Put n queens on an n x n board with no two queens on the same row, column, or
diagonal.
● Move a queen to reduce a number of conflicts

29
4.2 Local search algorithms
State space landscape:
● "location": state
● "elevation": the value of objective function; find the highest peak - a global
maximum

Local search algorithms


1. Hill-climbing
2. Annealing Simulated
3. Genetic algorithm

30
4.2 Hill-Climbing
● Hill climbing known as greedy local search because it grabs a good neighbor state
without thinking ahead about where to go next.
● How it works:
○ continually moves in the direction of increasing value, i.e., uphill.
○ terminates when it reaches a "peak" where no neighbor has a higher value

31
4.2 Hill-Climbing
Hill climbing often gets stuck for the following reasons:
● Local maxima: a peak that is higher than each of its neighboring states, but lower than the global
maximum.
● Ridges: they result in a sequence of local maxima
=> very difficult for greedy algorithms to navigate.
● Plateaux: an area of the state space landscape where the evaluation function is flat

32
4.2 Hill-Climbing
Variants of hill-climbing:
● Stochastic hill climbing: chooses at random from among the uphill moves
● First-choice hill climbing: generates successors randomly until one is generated that is
better than the current state.
● Random-restart hill climbing:
○ it conducts a series of hill-climbing searches from randomly generated initial state, stopping
when a goal is found
● The success of hill climbing depends on the shape of the state-space landscape:
○ if it has few local maxima and plateaux -> random-restart hill climbing will find a good solution
very quickly

33
4.2 Simulated annealing search
● Idea: escape local maxima by allowing some bad moves, but gradually decrease their
size and frequency
○ Simulated annealing search picks a random move.
○ If the move improves the situation, it is accepted.
○ Otherwise, the algorithm accepts the move with some probability.
■ The probability decreases with the “badness” of the move, ΔE by which the evaluation is
worsened.
■ The probability decreases as the “temperature” T goes down

34
4.2 Simulated annealing search

35
4.2 Local beam search
● Idea: 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.

● Problem: quite often, all k states end up on same local hill


● Idea: choose k successors randomly, biased towards good ones ~ stochastic beam
search

36
4.2 Genetic algorithms
● A genetic algorithm (or GA) is a variant of stochastic beam search in which successor
states are generated by combining two parent states

37
4.2 Genetic algorithms (GAs)
(a) GAs begin with a set of k randomly generated states, called the population

38
4.2 Genetic algorithms (GAs)
(b) Each state is rated by the objective function, i.e., the fitness function.

39
4.2 Genetic algorithms (GAs)
(c) 2 pairs are selected at random for reproduction, in accordance with the probabilities in (b)
Each pair to be mated, a crossover point is chosen randomly from the positions in the string.

40
4.2 Genetic algorithms (GAs)
(d) the offspring themselves are created by crossing over the parent strings at the crossover point

41
4.2 Genetic algorithms (GAs)
(e) each location is subject to random mutation with a small independent probability.

42
4.2 Genetic algorithms (GAs)

43
4.2 Genetic algorithms (GAs)

44

You might also like