• No results found

Artificial Intelligence

N/A
N/A
Protected

Academic year: 2020

Share "Artificial Intelligence"

Copied!
77
0
0

Loading.... (view fulltext now)

Full text

(1)

Artificial Intelligence

CSAL3243

Dr. Muhammad Humayoun

Assistant Professor

University of Central Punjab, Lahore.

[email protected]

https://sites.google.com/a/ucp.edu.pk/ai/

(2)

INFORMED SEARCH

Chapter 3, Section 3.5

2

Informed (Heuristic) search: search is guided by

(3)

Using problem specific knowledge to aid

searching

• With knowledge, one can search the state space

as if he was given “

hints

” when exploring a maze.

– Heuristic information

in search = Hints

• Leads to dramatic speed up in efficiency.

3 A B C D E F G H I J K L O M N

Search only in

this subtree!!

(4)

4

More formally, why heuristic functions work?

• Previous

: at most

b choices at each node

and a

depth of d

at the goal node

– An uninformed search algorithm would have to,

in the worst case, search around O(b

d

) nodes

before finding a solution (

Exponential Time

Complexity

).

• Heuristics improve the efficiency

of search

algorithms by reducing the effective

branching factor from b to (ideally) a lower

constant b* such that

(5)

Evaluation Function

• An evaluation function 𝑓(𝑛) gives an

estimation

on the “cost” of node 𝑛 in a tree/graph

• So that the node with the least cost among all

possible choices can be

selected for expansion first

• Three approaches to define 𝑓(𝑛)

(6)

Approach 1

𝑓 measures the value of the current state (i.e. its

goodness

”)

• Usually the case when solving

optimization

problems

– Finding a state such that the value of the heuristic

function

𝑓 is optimized

• Often, in these cases, f could be a weighted sum of

a set of component values:

– N-Queens

• Example: the number of queens under attack …

(7)

Approach 2

• Evaluation function 𝑓 measures the

estimated cost of

getting to the goal

from the current state

:

𝑓(𝑛) = 𝑕(𝑛)

• where

𝑕(𝑛) = an estimate of the cost to get

from state 𝑛 to a goal state

(8)

Example 8–Puzzle tree

(9)

Possible heuristics for 8–Puzzle

• h1: The number of misplaced tiles (squares with

number).

• h2: The sum of the distances of the tiles from their

goal positions.

(10)

10

h1: The number of misplaced tiles (not including the blank)

• Only “8” is misplaced

• So the heuristic function evaluates to 1.

• The heuristic is telling us, that it thinks a solution might

be available in just 1 more move.

• Notation: 𝑓(𝑛) = 𝑕(𝑛)

• h(current state) = 1

(11)

11

h2: The sum of the distances of tiles from goal positions

(12)

Approach 3

• Evaluation function 𝑓 measures the estimated cost

of

getting to the goal state from the current state

and

the cost of the existing path to it

:

12

𝑓(𝑛) = 𝑔(𝑛) + 𝑕(𝑛)

where

𝑔(𝑛) = an exact cost to get to 𝑛 (from initial

state)

𝑕(𝑛) = an estimate of the cost to get from

state 𝑛 to a goal state

(13)

Summary of Evaluation / Heuristic Function

• Evaluation function

f(n) = g(n) + h(n)

– g(n) = exact cost so far to reach n

– h(n) = estimated cost to goal from n

– f(n) = estimated total cost of cheapest

path through n to goal

• Special cases:

– Uniform Cost Search

: 𝑓(𝑛) = 𝑔(𝑛)

– Greedy (best-first) Search

: 𝑓(𝑛) = 𝑕(𝑛)

(14)

How it works?

• Idea

: use heuristic function for each node

– that estimates desirability

• Expands most desirable unexpanded node

• Implementation:

– fringe is a queue sorted in order of desirability

• Special cases:

– Uniform Cost Search (uninformed)

– Greedy (best-first) Search (informed)

– A* Search (informed)

(15)

Informed Search Strategies

Greedy Best First Search

(16)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 16 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111

f(n) = h (n) = straight-line distance heuristic

(17)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 17 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(18)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 18 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(19)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 19 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(20)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 20 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(21)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 21 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(22)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 22 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(23)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 23 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(24)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 24 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(25)

Greedy Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 25 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(26)

Greedy Search: Tree Search

26

(27)

Greedy Search: Tree Search

27 A B C E Start 75 118 140 [374] [329] [253]

(28)

Greedy Search: Tree Search

28 A B C E F 99 G A 80 Start 75 118 140 [374] [329] [253] [193] [366] [178]

(29)

Greedy Search: Tree Search

29 A B C E F I 99 211 G A 80 Start Goal 75 118 140 [374] [329] [253] [193] [366] [178] E [0] [253]

(30)

Greedy Search: Tree Search

30 A B C E F I 99 211 G A 80 Start Goal 75 118 140 [374] [329] [253] [193] [366] [178] E [0] [253]

Path cost(A-E-F-I) = 253 + 178 + 0 =

431

dist(A-E-F-I) = 140 + 99 + 211 =

450

(31)

Greedy Search: Optimal?

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 31 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111

f(n) = h (n) = straight-line distance heuristic

dist(A-E-G-H-I) =140+80+97+101=418

140

(32)

Greedy Search: Complete ?

State Heuristic: h(n) A 366 B 374 ** C 250 D 244 E 253 F 178 G 193 H 98 I 0 32 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111

f(n) = h (n) = straight-line distance heuristic

(33)

Greedy Search: Tree Search

33

(34)

Greedy Search: Tree Search

34 A B C E Start 75 118 140 [374] [250] [253]

(35)

Greedy Search: Tree Search

35 A B C E D 111 Start 75 118 140 [374] [250] [253] [244]

(36)

Greedy Search: Tree Search

36 A B C E D 111 Start 75 118 140 [374] [250] [253] [244] C [250] Infinite Branch !

(37)

Greedy Search: Tree Search

37 A B C E D 111 Start 75 118 140 [374] [250] [253] [244] C D [250] [244] Infinite Branch !

(38)

Greedy Search: Tree Search

38 A B C E D 111 Start 75 118 140 [374] [250] [253] [244] C D [250] [244] Infinite Branch !

Even Incomplete in finite state

space much like depth first search

(Complete in finite space with

repeated-state checking)

(39)

Greedy Search: Time and Space

Complexity ?

39 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

• Greedy search is

not optimal.

• Greedy search is

incomplete

• In the worst case, the Time and

Space Complexity of Greedy

Search are both

O(b

m

)

Where b is the branching factor and m

the maximum path length

(40)

Informed Search Strategies

A* Search

(41)

A* (A Star)

• Although Greedy Search can considerably cut the

search time (efficient), it is

neither optimal nor

complete

.

• Uniform Cost Search minimizes the cost

𝑔(𝑛)

from

the initial state to 𝑛.

UCS is optimal and complete

but

not efficient

.

• New Strategy:

Combine Greedy Search and UCS

to

get an efficient algorithm which is

complete

and

optimal

.

(42)

A* (A Star)

• A* uses a heuristic function which combines g(n)

and h(n): 𝑓(𝑛) = 𝑔(𝑛) + 𝑕(𝑛)

• g(n) is the

exact cost to reach node n from the

initial state

. Cost so far up to node n.

• h(n) is an

estimation of the remaining cost to

reach the goal

.

(43)

A* (A Star)

43 n g(n) h(n)

f(n) = g(n)+h(n)

(44)

A* Search

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 44

f(n) = g(n) + h (n)

g(n): is the exact cost to reach node n from the initial state.

A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 140

(45)

A* Search: Tree Search

45

(46)

A* Search: Tree Search

46 A B C E Start 75 118 140 [140+253=393] [75+374=449] [118+329=447]

(47)

A* Search: Tree Search

47 A B C E F 99 G 80 Start 75 118 140 [239+178=417] [220+193=413] [140+253=393] [75+374=449] [118+329=447]

(48)

A* Search: Tree Search

48 A B C E F 99 G 80 Start 75 118 140 H 97 [317+98=415] [140+253=393] [75+374=449] [118+329=447] [239+178=417] [220+193=413]

(49)

A* Search: Tree Search

49 A B C E F I 99 G H 80 Start 97 101 75 118 140 Goal [418+0=418] [140+253=393] [75+374=449] [118+329=447] [317+98=415] [239+178=417] [220+193=413]

(50)

A* Search: Tree Search

50 A B C E F I 99 G H 80 Start 97 101 75 118 140 Goal I [418+0=418] [140+253=393] [75+374=449] [118+329=447] [317+98=415] [239+178=417] [220+193=413] [450+0=450] 211

(51)

A* Search: Tree Search

51 A B C E F I 99 G H 80 Start 97 101 75 118 140 Goal I [418+0=418] [140+253=393] [75+374=449] [118+329=447] [317+98=415] [239+178=417] [220+193=413] [450+0=450] 211

(52)

A* Search: Tree Search

52 A B C E F I 99 G H 80 Start 97 101 75 118 140 Goal I [418+0=418] [140+253=393] [75+374=449] [118+329=447] [317+98=415] [239+178=417] [220+193=413] [450+0=450] 211 dist(A-E-G-H-I) =140+80+97+101=418

(53)

A* with h() not Admissible

If h() overestimates the cost to reach

the goal state

(54)

Admissible Heuristic Functions

• A heuristic 𝑕(𝑛)

is admissible

if 𝑕(𝑛) never

overestimates the cost to reach the goal.

– Admissible heuristics are “optimistic” approximation

• Mathematically h is admissible if

For all n, 𝑕 𝑛 ≤ 𝐶(𝑛)

Where

• n is the node, h is heuristic

• h(n) is the cost indicated by h to reach goal from n

• C(n) is actual cost to reach a goal from n

(55)

Admissible heuristics Examples

• h

SLD

(n) Straight line distance heuristic

– Because never overestimate the actual road distance.

(56)

Admissible Heuristic Functions

• Evaluation function 𝑓(𝑛) = 𝑔(𝑛) + 𝑕(𝑛)

is

admissible

if 𝑕(𝑛) is admissible.

• However, 𝑔(𝑛) is the exact cost to reach node n

from the initial state.

• Therefore, 𝑓(𝑛) never over-estimate the true cost

to reach the goal state through node n.

• Theorem

: If h(n) is admissible, A

*

using

TREE-SEARCH is optimal

(57)

57

Consistent Heuristic

• The admissible heuristic h is

consistent

if for every node

N and every successor N’ of N:

𝑕(𝑁)

𝑐(𝑁, 𝑁’) + 𝑕(𝑁’)

(triangular inequality)

• A

consistent heuristic is admissible

.

• But an

admissible heuristic is not always consistent

N

N’

h(N) h(N’)

(58)

A* Search: if h not admissible

State Heuristic: h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 138 I 0 58 A B D C E F I 99 211 G H 80 Start Goal 97 101 75 118 111 f(n) = g(n) + h (n) – (H-I) Overestimated

g(n): is the exact cost to reach node n from the initial state.

(59)

A* Search: Tree Search

59

(60)

A* Search: Tree Search

60 A B C E Start 75 118 140 [393] [449] [447]

(61)

A* Search: Tree Search

61 A B C E F 99 G 80 Start 75 118 140 [393] [449] [447] [417] [413]

(62)

A* Search: Tree Search

62 A B C E F 99 G 80 Start 75 118 140 [393] [449] [447] [417] [413] H 97 [455]

(63)

A* Search: Tree Search

63 A B C E F 99 G H 80 Start 97 75 118 140 [393] [449] [447] [417] [413] [455] Goal I [450] 211

(64)

A* Search: Tree Search

64 A B C E F 99 G H 80 Start 97 75 118 140 [393] [449] [447] [417] [413] [455] Goal I [450] D [473] 211

(65)

A* Search: Tree Search

65 A B C E F 99 G H 80 Start 97 75 118 140 [393] [449] [447] [417] [413] [455] Goal I [450] D [473] 211

(66)

A* Search: Tree Search

66 A B C E F 99 G H 80 Start 97 75 118 140 [393] [449] [447] [417] [413] [455] Goal I [450] D [473] 211

(67)

A* Search: Tree Search

67 A B C E F 99 G H 80 Start 97 75 118 140 [393] [449] [447] [417] [413] [455] Goal I [450] D [473]

A* not optimal !!!

When heuristic h is not admissible

dist(A-E-F-I) =140+99+211=450

(68)

A* Algorithm

1. Search queue Q is empty.

2. Place the start state s in Q with f value h(s).

3. If Q is empty, return failure.

4. Take node n from Q with lowest f value.

(Keep Q sorted by f values and pick the first element).

5. If n is a goal node, stop and return solution.

6. Generate successors of node n.

7. For each successor n’ of n do:

a) Compute f(n’) = g(n) + h(n’).

b) If n’ is new (never generated before), add n’ to Q.

c) If node n’ is already in Q with a higher f value, replace it with current f(n’)

and place it in sorted order in Q.

End for

(69)

Properties of A*

• Complete?

Yes

– (unless there are infinitely many nodes with f ≤ f(G) )

• Time?

Exponential

– It depends on the

quality of heuristic

but is still

exponential

.

• Space? Keeps all nodes in memory

– O(b

d

)

space complexity

,

– But an iterative deepening version is possible (IDA*).

• Optimal?

Yes

(70)

Conclusions

• Frustration with uninformed search led to the

idea of

using domain specific knowledge

in a search

• so that one can

intelligently explore only the relevant

part

of the search space that has a

good chance of

containing the goal state

.

• These new techniques are called

informed (heuristic)

search strategies

.

• Even though

heuristics improve the performance

of informed search algorithms, they are

still time

consuming

especially for large size instances.

(71)

SLD Heuristic: h()

Straight Line Distances to Bucharest

71

Town

SLD

Arad 366 Bucharest 0 Craiova 160 Dobreta 242 Eforie 161 Fagaras 178 Giurgiu 77 Hirsova 151 Iasi 226 Lugoj 244

Town

SLD

Mehadai 241 Neamt 234 Oradea 380 Pitesti 98 Rimnicu 193 Sibiu 253 Timisoara 329 Urziceni 80 Vaslui 199 Zerind 374

We can use straight line distances as an admissible heuristic as they will never

overestimate the cost to the goal. This is because there is no shorter distance between two

(72)

Distances Between Cities

72

Arad

Bucharest

Oradea Zerind Faragas Neamt Iasi Vaslui Hirsova Eforie Urziceni Giurgui Pitesti Sibiu Dobreta Craiova Rimnicu Mehadia Timisoara Lugoj 87 92 142 86 98 86 211 101 90 99 151 71 75 140 118 111 70 75 120 138 146 97 80 140 80 97 101 Sibiu Rimnicu Pitesti

(73)

Greedy Search in Action …

(74)

74

Press space to see an Greedy search of the Romanian map featured in the previous slide.

Note: Throughout the animation all nodes are labelled with f(n) = h(n). However,we will

be using the abbreviations f, and h to make the notation simpler

Oradea Zerind Fagaras Sibiu Rimnicu Timisoara

Arad

We begin with the initial state of Arad. The straight line distance from Arad to Bucharest (or

h value) is 366 miles. This gives us a total value of ( f = h ) 366 miles. Press space to expand

the initial state of Arad.

F= 366 F= 366 F= 374 F= 374 F= 253 F=253 F= 329 F= 329

Once Arad is expanded we look for the node with the lowest cost. Sibiu has the lowest value for f. (The straight line distance from Sibiu to the goal state is 253 miles. This gives a total

of 253 miles). Press space to move to this node and expand it.

We now expand Sibiu (that is, we expand the node with the lowest value of f ). Press space to continue the search.

F= 178 F= 178 F= 380 F= 380 F= 193 F= 193

We now expand Fagaras (that is, we expand the node with the lowest value of f ). Press space to continue the search.

Bucharest

F= 0

(75)

A* in Action …

(76)

76

Press space to see an A* search of the Romanian map featured in the previous slide. Note:

Throughout the animation all nodes are labelled with f(n) = g(n) + h(n). However,we will

be using the abbreviations f, g and h to make the notation simpler

Oradea Zerind Fagaras Pitesti Sibiu Craiova Rimnicu Timisoara

Bucharest

Arad

We begin with the initial state of Arad. The cost of reaching Arad from Arad (or g value) is 0

miles. The straight line distance from Arad to Bucharest (or h value) is 366 miles. This gives

us a total value of ( f = g + h ) 366 miles. Press space to expand the initial state of Arad.

F= 0 + 366 F= 366 F= 75 + 374 F= 449 F= 140 + 253 F= 393 F= 118 + 329 F= 447

Once Arad is expanded we look for the node with the lowest cost. Sibiu has the lowest value for f. (The cost to reach Sibiu from Arad is 140 miles, and the straight line distance from Sibiu to the goal state is 253 miles. This gives a total of 393 miles). Press space to move to this node and expand it.

We now expand Sibiu (that is, we expand the node with the lowest value of f ). Press space to continue the search.

F= 239 + 178 F= 417 F= 291 + 380 F= 671 F= 220 + 193 F= 413

We now expand Rimnicu (that is, we expand the node with the lowest value of f ). Press space to continue the search.

F= 317 + 98

F= 415

F= 366 + 160

F= 526

Once Rimnicu is expanded we look for the node with the lowest cost. As you can see, Pitesti has the lowest value for f. (The cost to reach Pitesti from Arad is 317 miles, and the straight line distance from Pitesti to the goal state is 98 miles. This gives a total of 415 miles). Press space to move to this node and expand it.

We now expand Pitesti (that is, we expand the node with the lowest value of f ). Press space to continue the search.

We have just expanded a node (Pitesti) that revealed Bucharest, but it has a cost of 418. If there is any other lower cost node (and in this case there is one cheaper node, Fagaras, with a cost of 417) then we need to expand it in case it leads to a better solution to Bucharest than the 418 solution we have already found. Press space to continue.

F= 418 + 0

F= 418

In actual fact, the algorithm will not really recognise that we have found Bucharest. It just keeps expanding the lowest cost nodes (based on f ) until it finds a goal state AND it has the lowest value of f. So, we must now move to Fagaras and expand it. Press space to continue. We now expand Fagaras (that is, we expand the node with the lowest value of f ). Press space to continue the search.

Bucharest

(2)

F= 450 + 0

F= 450

Once Fagaras is expanded we look for the lowest cost node. As you can see, we now have two Bucharest nodes. One of these nodes ( Arad – Sibiu – Rimnicu – Pitesti – Bucharest ) has an f value of 418. The other node (Arad – Sibiu – Fagaras – Bucharest(2) ) has an f value

of 450. We therefore move to the first Bucharest node and expand it. Press space to continue

Bucharest

Bucharest

Bucharest

We have now arrived at Bucharest. As this is the lowest cost node AND the goal state we can terminate the search. If you look back over the slides you will see that the solution

returned by the A* search pattern ( Arad – Sibiu – Rimnicu – Pitesti – Bucharest ), is in fact the optimal solution. Press space to continue with the slideshow.

(77)

Questions

References

Related documents

In this context, a major aspect of Katib C ¸ elebi’s work is his interest in the world outside the Islamic oecoumene (on his biography see Collective work, 1957; for a selection of

As we shall see, there are three 3-tiling configurations: two imprimitive variations of the 2-tiling (see Figure 2.3.3 and Figure 2.3.4), and a primitive configuration that we will

(Y screen will di al plan for co se the Back bu select the “ roll or Decl Elect or De Medical B IMPORT new An click mo NT INST umenos HS you must se You may on isplay your Cu

The college has developed web-based systems to assist faculty: initial verification /attendance, enrollment changes during the term for unofficial withdrawals, and end of term

Figure 2.3 shows an n sub-module, grid-connected PV string. When one sub- module is significantly shaded, its MPP current will differ from the MPP cur- rent of the other,

together at any time during the year and files separately, no deduction is allowed.. • For purposes of a real estate activity, the IRS considers each property as a separate

Ultrathin CVD Cu Seed Layer Formation Using Copper Oxynitride Deposition and Room Temperature Remote Hydrogen Plasma Reduction.. (Article begins on

If you receive this error, please check that the start date entered is within the period of at least one of your professional jobs. If it does, your details may not have been