A* Search Algorithm in Artificial Intelligence, Exams of Algorithms and Programming

The A* Search Algorithm, a popular algorithm in artificial intelligence used for finding optimal paths in a state space graph. It covers uninformed and informed search, heuristics, greedy search, and the combination of uniform-cost search and greedy search in A*. The document also discusses the termination, optimality, admissibility, and consistency of A* search.

Typology: Exams

2021/2022

Uploaded on 09/27/2022

rexana
rexana šŸ‡¬šŸ‡§

4.7

(11)

215 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Search
Lecture Attendance: http://bit.ly/3GEMoKZ
State space graph.
Given a task, model of world appropriate to task.
Search Tree.
Representation of all plans
(also paths through state space graph.)
Uninformed Search.
Depth First Search.
Good space bound, ā€œleftmostā€ exploration seems bad.
Breadth First Search.
Bad space bound, finds plan with fewest number of actions.
Uniform Cost Search.
Bad space bounds, finds optimal plan.
Demo: L3D1
Informed Search
Search Heuristics
11.2
5
10
A heuristic is:
IA function that estimates how close a state
is to a goal
IDesigned for a particular search problem
IExamples: Euclidean distance for pathing.
Manhattan distance.
Example: Heuristic Function
Example: Heuristic Function
Heuristic: the number of the largest pancake that is still out of place
Greedy Search
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download A* Search Algorithm in Artificial Intelligence and more Exams Algorithms and Programming in PDF only on Docsity!

Search

Lecture Attendance: http://bit.ly/3GEMoKZState space graph.Given a task, model of world appropriate to task.Search Tree.Representation of all plans

(also paths through state space graph.) Uninformed Search.Depth First Search.

Good space bound, ā€œleftmostā€ exploration seems bad. Breadth First Search.

Bad space bound, finds plan with fewest number of actions. Uniform Cost Search.

Bad space bounds, finds optimal plan. Demo: L3D

Informed Search

Search Heuristics

A heuristic is:^ I

A function that

estimates

how close a state

is to a goal I^

Designed for a particular search problem I^

Examples:

Euclidean distance for pathing.

Manhattan distance.

Example: Heuristic Function

Example: Heuristic Function

Heuristic: the number of the largest pancake that is still out of place

Greedy Search

Greedy Search

Expand the node that seems closest to the goal?

What can go wrong?

Greedy: 140 + 99 + 211 = 450Better: 140+80+97+101 = 418

Greedy Search

Strategy: expand a node that (you think) is closest to a goal state.Heuristic: estimate of distance to nearest goal for each state

Wildest dream:Perfect heuristic. A common case:

Best-first takes you straight to the (wrong) goal Worst-case:

Like a badly-guided DFS

[Democontours greedy empty (L3D3)][Demo: contours greedy pacman small maze (L3D4)]

Video of Demo Contours Greedy (Empty)

Video of Demo Contours Greedy (pacman/small)

A* Search

A* Search

UCS

Greedy

A*

Optimality of A* Tree Search

Optimality of A* Tree Search: Blocking

Claim: Goal

A^

is expanded before

B

with

g

(B

)^ >

g(

A)

Proof:

Definition of f-cost:

g

(n

h(

n)

Admissibility of

h(

n)

āˆ— h (n

h = 0 at a goal

Imagine B is on the fringe.

Some ancestor

n^

of A is on the fringe, too (maybe A!)

Claim:

n^

will be expanded before B

f(n) is less or equal to f(A)

since

f^ (

n) =

g(

n) +

h(

n)

f^ (

A)

f(A) is less than f(B)

since

g(

A) +

<^

g(

B) +

h(

B)

All ancestors of A expand before B.A expands before B.

A* search is optimal.

Properties of A*

UCS

A*

UCS vs A* Contours

Uniform-cost expands equally in allā€œdirectionsā€.A* expands mainly toward the goal, butdoes hedge its bets to ensure optimality

[Demo: contours UCS / greedy / A* empty (L3D1)][Demo: contours A* pacmansmall maze (L3D5)]

Video of Demo Contours (Empty) – UCS

Video of Demo Contours (Empty) – Greedy

Video of Demo Contours (Empty) – A*

Video of Demo Contours: Pacman A*

Comparison

Uniform Cost Greedy

A*

A* Applications

A* Applications

Video gamesPathing / routing problemsResource planning problemsRobot motion planningLanguage analysisMachine translationSpeech recognition[Demo: UCS / A * pacman tinymaze (L3D6,L3D7)][Demo: guess algorithm EmptyShallow/Deep (L3D8)]

Video of Demo Pacman (Tiny Maze) – UCS / A*

8 Puzzle III

How about using the actual cost as aheuristic?Would it be admissible?Would we save on nodes expanded?What’s wrong with it?

With A*: a trade-off between quality of estimate and work per node^ I

As heuristics get closer to the true cost, expand fewer nodes, butmore work per node to compute the heuristic itself.

Semi-Lattice of Heuristics

Trivial Heuristics, Dominance

exact^ zero ha

hb

hc

max(

ha

,^ h

)b

Dominance:

ha

hc

if āˆ€n

:^ h

(na

)^ ≄

hc

(n

Heuristics form a semi-lattice:Max of admissible heuristics is admissible.Trivial heuristicsBottom of lattice is the zero heuristic.

(what does this give us?)Top of lattice is the exact heuristic

Graph Search

Tree Search: Extra Work!

Search TreeState Graph

Failure to detect repeated statescan cause exponentially morework.

Graph Search

In BFS, for example, we shouldn’t bother expanding the circled nodes(why?)

Graph Search

Idea: never expand a state twiceHow to implement:Tree search + set of expanded states (ā€œclosed setā€)Expand the search tree node-by-node, but...Before expanding a node,

check if state was never been expanded beforeIf yes skip it, else add to closed set and expand. Important:

store the closed set as a set, not a list

Can graph search wreck completeness? Why/why not?How about optimality?

A* Graph Search Gone Wrong?

Is^

h(

Ā·)^ admissible? Yes. Will exploring w.r..t

h(

B) +

g(

n)

be optimal?

Expand

S

A^ and

B^

in fringe!

Expands

B

, since

h(

B) +

g(

B) =

<^

h(

A) +

g(

A)

C^

in fringe with key, 3

+^

h(

C) =

G^

in fringe with key, 5. Could have been there in 4.

Consistency of Heuristics

A h =^

h^ =

h^ =

C G

Main idea: est. heuristic costs

actual costs

Admissibility:

h

(x)

cost to goal.

Consistency:

h

(x)

h(

y)

cost

(x

,^ y

heuristic ā€œarcā€ cost

actual arc cost

Consistent

admissible? Yes? No?

Consistent: f value along a path neverdecreasesAdmissible:^ f

(C

h(

C) +

f^ (A

h(

A) =

Consistent:

f^ (

A) =

<^

f^ (

C)

Claim: If

y^

is expanded due to

x,

f^ (

y)

f^ (

x)

Proof:^ f

(y

g(

x) +

cost

(x

,^ y

h(

y)

≄^

g(

x) +

h(

x)

āˆ’^

h(

y) +

h(

y) =

g(

x) +

h(

x) =

f^ (

x)

The ā€œestimateā€ of plan cost keeps rising as you progress.

Optimality of A* Graph Search

Optimality of A* Graph Search

Sketch: consider what A* does with aconsistent heuristic:Fact 1: In tree search, A* expands nodes inincreasing total f value (f-contours)Fact 2: For every state

s, the optimal path is

discovered.Result: A* graph search is optimalFact 1 Proof. Previous slide.

Proof of A* optimality.

v

s

x

g Start (v^ )

g(x

)

pathCost(

v^ ,^ s

)

cost(

x,^ s)

Fact 2: The optimal path is discovered to every state

s.

Proof: Consider first error.State

s^

discovered from

x.

Optimal path is from

y^

6 =^

x.

There is a vertex

v^

in the optimal path to

y^

in fringe.

s^ in fringe with key

f^ (

s) =

g(

x) +

cost

(x

,^ s) +

h(

s).

v^ in fringe with key

f^ (

v^ ) =

g(

v^ ) +

h(

v^ )

h(

v^ )

āˆ’^

h(

s)^

≤^

pathCost

(v

,^ s

)^ by induction.

g(

v^ ) +

pathCost

(v^

,^ s)

g(

x) +

cost

(x

,^ s)

f^ (

v^ )

f^ (

s)

But then

v^

would have been expanded before

s!