AI4_heuristics_part1
Download
Report
Transcript AI4_heuristics_part1
Informed search algorithms
Chapter 4
Modified by Vali Derhami
1/34
Material
• Chapter 4
2/34
Outline
•
•
•
•
•
•
•
•
•
Best-first search
Greedy best-first search
A* search
Heuristics
Local search algorithms
Hill-climbing search
Simulated annealing search
Local beam search
Genetic algorithms
3/34
Review: Tree search
• A search strategy is defined by picking the
order of node expansion
•
4/34
Best-first search
جستجوي اول بهترين
• Idea: use an evaluation function f(n) for each node
– estimate of "desirability"
–
Expand most desirable unexpanded node
• Implementation:
Order the nodes in fringe in decreasing order of
desirability
• Special cases:
– greedy best-first search
– A* search
–
5/34
Romania with step costs in km
6/34
Greedy best-first search
• Evaluation function f(n) = h(n) (heuristic)
= estimate of cost from n to goal
• e.g., hSLD(n) = straight-line distance from n
to Bucharest
• Greedy best-first search expands the node
that appears to be closest to goal
7/34
Greedy best-first search
example
8/34
Greedy best-first search
example
9/34
Greedy best-first search
example
10/34
Greedy best-first search
example
11/34
Properties of greedy best-first
search
• Complete? No – can get stuck in loops,
e.g., Iasi Neamt Iasi Neamt
• Time? O(bm), but a good heuristic can give
dramatic improvement
• Space? O(bm) -- keeps all nodes in
memory
• Optimal? No
12/34
A* search
• Idea: avoid expanding paths that are
already expensive
• Evaluation function f(n) = g(n) + h(n)
• g(n) = cost so far to reach n
– h(n) = estimated cost from n to goal
– f(n) = estimated total cost of path through n to
goal
–
13/34
A* search example
14/34
A* search example
15/34
A* search example
16/34
A* search example
17/34
A* search example
18/34
A* search example
19/34
Admissible heuristics
• A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach
the goal state from n.
An admissible heuristic never overestimates the
cost to reach the goal, i.e., it is optimistic
Example: hSLD(n) (never overestimates the actual
road distance)
• Theorem: If h(n) is admissible, A* using TREESEARCH is optimal
20/34
Optimality of A* (proof)
• Suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.
•
•
•
•
•
•
f(n)= g(n)+h(n)
f(G2) = g(G2)
g(G2) > g(G)
f(G) = g(G)
f(G2) > f(G)=C*
since h(G2) = 0
since G2 is suboptimal
since h(G) = 0
from above
21/34
Optimality of A* (proof)
• Suppose some suboptimal goal G2 has been generated and is in the
fringe. Let n be an unexpanded node in the fringe such that n is on a
shortest path to an optimal goal G.
•
• f(n)= g(n)+h(n)
• f(G2)
> C*=f(G)
(1)
from above
• h(n)
≤ h*(n)
since h is admissible
• g(n) + h(n) ≤ g(n) + h*(n) =C*
• f(n)
≤ C*=f(G),
• (2)
With respect to (1) and (2) , f(G2) > f(n), and A* will never select G2 for
22/34
expansion
عدم بهينگي در جستجوي گراف
• توجه شود كه روش * Aدر جستجوي گراف بهينه نيست
چرا كه در اين روش ممكن است يك مسير بهينه به يك
حالت تكراري كنار گذاشته شود.
• ياداوري :در روش مذكور حالت تكراري شناسايي شود
مسير جديد كشف شده حذف مي گردد.
• راه حل:
• گرهي كه مسير پر هزينه تر دارد كنار گذاشته شود.
• نحوه عملكرد بدان گونه باشد كه تضمين كند مسير بهينه به حالت
تكراري هميشه اولين مسيري است كه دنبال شده است .همانند جستجوي
هزينه يكنواخت
23/34
Consistent heuristics
هيوريستيكهاي سازگار
•
A heuristic is consistent if for every node n, every successor n' of n generated by any
action a,
•
h(n) ≤ c(n,a,n') + h(n')
يعني هميشه حاصلجمع تابع هيوريستيك گره پسين و هزينه رفتن به
.ان از تابع هيوريستيك والد بيشتر يا مساوي است
.» هر هيوريستيك سازگار قابل قبول هم هست
• If h is consistent, we have
•
f(n')
= g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n)
= f(n)
i.e., f(n) is non-decreasing along any path.
•
•
.در طول هر مسيري غير نزولي استf(n) يعني مقدار
Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal
•
24/34
Optimality of A*
• A* expands nodes in order of increasing f value
• Gradually adds "f-contours" of nodes
• Contour i has all nodes with f=fi, where fi < fi+1
•
25/34
*Properties of A
• Complete? Yes (unless there are infinitely many
) )nodes with f ≤ f(G
• Time? Exponential
• Space? Keeps all nodes in memory
الگوريتم بيشتر از آنكه وقت كم بياورد حافظه كم مياورد• .
• Optimal? Yes
•
• در ميان الگوريتمهايي كه مسيرهاي جستجو را از ريشه توسعه مي
دهند هيچ الگوريتم بهينه ديگري نمي تواند تضمين كند كه تعداد گره
هايي كه توسع ميدهد از * Aكمتر باشد
26/34
جستجوی هيوريستيک با حافظه محدود
• الگوريتمهای مطرح شده مشکل حافظه دارند.
• دو الگوريتم برای کاهش حافظه مصرفی
– )*Iterative Deepening A* (IDA
– * SMAمشابه * Aبا اندازه صف کمتر
27/34
)*Iterative Deepening A* (IDA
– تفاوت با روش عميق شونده تکراری
• برش مورد استفاده هزينه fيعنی g+hاست نه عمق.
• هر تکرار از الگوريتم يک جستجوی عمقی است که تا محدوده هزينه f
پيش می رود.
28/34
*Simplified-Memory-Bounded A
)*(SMA
• از همه حافظه موجود استفاده می کند.
• تا جايی که حافظه اجازه می دهد گره ها را گسترش ميدهد.
• هنگامی که حافظه پر شد بدترين گره برگی (لبه) (آنکه
مقدار fباالتری دارد) را حذف می کند (از حافظه پاک می
کند) و مقدار اين گره را به والدش بر ميگرداند.
• سوال :اگر تمام گره های برگی داری fيکسان باشد چه
اتفاقی می افتد؟
• *SMAکامل و بهينه است اگر راه حل دست يافتنی موجود
29/34و راه حل بهينه دست يافتنی باشد.
SMA* Example
حافظه به اندازه 3گره
30/34
SMA* Code
31/34
Admissible heuristics
E.g., for the 8-puzzle:
• h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance مجموع فاصله كاشيها از موقعيتهاي هدفشان
(i.e., no. of squares from desired location of each tile)
• h1(S) = ?
• h2(S) = ?
•
32/34
Admissible heuristics
E.g., for the 8-puzzle:
h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
33/34
Dominance
• effective branching factor b*.
N + 1 = 1 + b* + b*2 + • • • + (b*)d .
N=total number of nodes generated by A*, d= solution depth
,
b* is the branching factor that a uniform tree of depth d would have
to have in order to contain N+ 1 nodes.
• If h2(n) ≥ h1(n) for all n (both admissible)
• then h2 dominates h1 , and h2 is better for search
•
• Typical search costs (average number of nodes expanded):
•
• d=12
IDS = 3,644,035 nodes
*
A (h1) = 227 nodes
A*(h2) = 73 nodes
b*=1.24
• d=24
IDS = too many nodes
*
A (h1) = 39,135 nodes
A*(h2) = 1,641 nodes b*=1.26
34/34