CSNB234 ARTIFICIAL INTELLIGENCE

1 / 66

# CSNB234 ARTIFICIAL INTELLIGENCE - PowerPoint PPT Presentation

CSNB234 ARTIFICIAL INTELLIGENCE. Chapter 5 State Space Search. Instructor: Alicia Tang Y. C. State Space Representation.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'CSNB234 ARTIFICIAL INTELLIGENCE' - kenneth-douglas

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

CSNB234ARTIFICIAL INTELLIGENCE

Chapter 5

State Space Search

Instructor: Alicia Tang Y. C.

State Space Representation
• A state space can be considered as consisting of a collection of points, each point corresponding to a state of a problem. So there will be as many number of points in the state space as the number of different possible states of the problem. Thus, a state space is the collection of all possible states, a problem can have. States can be represented as nodes of a tree. The searching of a goal node is by traversing the tree’s nodes using some well-established algorithms.
Defining A Search Problem
• State Space
• is described by
• an initial state space
• a set of possible actions (operators)
• goal state
• Path
• is any sequence of actions that lead from a state to another state and finally reached (hopefully) the goal node
Defining a Search Problem
• Other considerations are:
• Path cost: it is only relevant if there exists more than one path leading to the goal state.
• & certainly that we want the shortest path
• Goal test: it is applicable to single state problem, I.e. only one goal is found in the state space problem
Relationship between Initial states, actions and goal(s)

Initial

States

Actions

Goal(s)

Control

Strategy

Why ‘Search’?
• Search is an important (and powerful ) aspect in AI problem solving
• Search will
• will help to explore alternatives in tree
• will find sequence of steps in a planning situation/case
• All goal-driven activities (such as one used in B. C. reasoning) occur in a state space, and we call the problem a state space problem
Classical Search Domains
• 8-Puzzle
• Water Jug
• Blocks World
• Travelling Salesman
• Maze
• Chess
• Tower of Hanoi
• etc.
An Example of Search Preparation

2

4

8

1

8

7

7

3

2

6

Goal

State

Initial

State

1

5

6

3

4

5

Initial State: The location of each of the 8-puzzle in one of the

nine squares

Path cost: Each step costs 1 point, total path cost will be

equal to the number of steps taken

Goal test: State matches the goal configuration (given board pattern)

Operators: blank moves [1] Left, [2] Right, [3] Up & [4] Down.

S

e

a

r

c

h

A

p

p

r

o

a

c

h

e

s

Test

Search Process

Solution

complete

Comparisons

stop

when all

checked

All possible

solutions are

checked

Blind

optimal

partial

Check only

some

alternatives

Best

among

alternatives

Comparisons

Stop when

solution is

good

enough

Good

enough

Heuristics

Only

promising

solutions

Generate

improved

solutions

Stop when no

improvement

is possible

Optimisation

optimal

Methods of Search (I)

• Popular blind search methods are
• Depth-first
• Bi-directional
• Iterative deepening
• Depth-limited
• Uniform cost

Methods of Search (II)

• Heuristic Search
• Hill-climbing
• Best-first
• Generate & test
• Induction
• Greedy search
• Optimal Searching
• A* search

Methods of search at the first glance

• Depth-first
• explores search tree branch by branch
• examines search tree row by row
• Hill-climbing
• it is depth first but mostpromising child node is examined first
• Best-first
• expands the most promisingpartialpath of all those so far discovered
• A*
• Best-first and Branch and bound algorithm

To be

calculated

Decision required

.… Blind….

• The entire search tree is examined in an orderly manner.
• It can be classified as exhaustive or partial.
• Two well-known partial methods are
• depth-first

DEPTH-FIRST SEARCH(DFS)

A ~ begins at the root node and

works downward to successively

deeper level.

This process continues until a solution is found or backtracking

is forced by reaching a dead end.

Blind ....

DEPTH-FIRST SEARCH

Basic steps used

Delete FIRSTNODE from start of QUEUE

Take children of FIRSTNODE

Add to the front of QUEUE

Put result in NEWQUEUE

(BFS)

A ~ examines all the nodes in a

search tree, beginning with the

root node.

The nodes in each level are

examined completely before moving

to the next level.

The algorithm

Take children of FIRSTNODE

Delete FIRSTNODE from start of QUEUE

Append list of children to the end of QUEUE

Put result in NEWQUEUE

Heuristics Search

• Heuristics search is designed to reduce the amount of search for a solution.
• It is based on rule-of-thumb principle.
• When a problem is presented, such as a goal state is given, this approach tries to reduce the size of the search tree by pruning non promising or inferior nodes.
• It can normally speed up the search process in obtaining a good enough solution.

Benefits of Heuristics

• It has inherent flexibility
• It is better when an optimal/best solution is too costly to generate
• even though it can only produce “good enough” answer
• Simpler for decision maker to understand (especially the managers)
• because they think in the same way as “heuristics” does
A heuristics search in general

Problem: Tic-Tac-Toe

x

x

x

o

o

x

x

o

o

o

o

o

o

o

x

o

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

Consider the Tic-Tac-Toe game

Blind search is surely not practical…

Each nine first moves has eight possible responses,

which in turn have seven continuing moves, and so on.

A simple analysis tells that the number of states to be considered in an exhaustive search is 9 * 8 * 7 *… or 9!

However, symmetry reduction in second level leads to only 12 * 7! (much smaller than above), further reduction in search space will further reduce the number or search required

HILL-CLIMBING SEARCH

Main steps used

Delete FIRSTNODE from start of QUEUE

Take children of FIRSTNODE

Order children with most promising first

Place them at the front of QUEUE

Put result in NEWQUEUE

HILL-CLIMBING SEARCH

A complete function:

Hill-Climbing
• Hill-climbing combines depth-first search with a method for ordering the alternatives by measuring the probability of success at each decision point. In other word it tries to reach a goal by choosing those nodes which are predicted to be nearest to the goal. Quality measurements turn depth-first search into hill-climbing.
Hill-Climbing

It is about fin ding the shortest h(n)

• Earlier slide says that it is quite similar to depth-first blind search.
• However, paths are not selected arbitrarily, but in relationship to their proximity to the desired goal (i.e. how close to it)
• let’s take a look at this tree:
• notice that there are numbersattached nodes
• those are potential numbers of defects in a product
Each production process I, II and III can continue for several stages.
• If this is done by depth-first, it goes to I then to II and then to III .
• In Hill-climbing method, nodes B, C and D are compared, and it starts in branch I (lowest, 8 here).
• Since one defect was not found, backtracking is exercised to branch III. (branch III is done before II, why)?
• The search goes to D and H; backtracking is then done and D, G, J path leads to the desired solution.

Path A--C--F was not visited

therefore much time and cost are saved

This is exactly the aims of ‘heuristics’!

Hill-climbing
• Few more words on hill-climbing method: If we imagine the goal as the top of hill, h(n) as the difference in heights between n and the top, the hill-climbing procedure corresponds to climbing the hill by always going upwards.
Problems with hill-climbing:
• Foothill problem.
• Go up to the top of a hill and not advancing further. - misses the overall maximum
• Plateau problem.
• Problem with multidimensional problem space, i.e. no hill to climb (is flat). Gradient equals to zero. - not informative
• Ridges.
• Where there are steep slopes and the search direction is not towards the way up (but side)
Some solutions to hill-climbing problems are:
• Random restart hill-climbing
• where random initial states are generated
• Simulated annealing
• allow for bad moves as well, where the probability of such a move decreases exponentially with its badness

BEST-FIRST SEARCH

• Based on some heuristics evaluation function
• More flexible than hill-climbing
• An evaluation function is used to assign a score to each candidate node
• Next move is made by selecting the best value node
• It expands the best partial path, for that It could lead to “shortsighted” situation

BEST-FIRST SEARCH

Best-first search has been used in such applications as games and web crawlers

In a web crawler, each web page is treated as a node, and all the hyperlinks on the page are treated as unvisited successor nodes in the search space.

A crawler that uses best-first search generally uses an evaluation function that assigns priority to links based on how closely the contents of their parent page resemble the search query

BEST-FIRST SEARCH

Delete FIRSTNODE from start of QUEUE

Take children of FIRSTNODE

Append children to QUEUE

Order result with most promising first

Put ordered result in NEWQUEUE

[A]

[B D C]

[E I D C]

[I D C]

[D C]

[H G C]

[G C]

[J C]

[A]

[B D C]

[D C E I]

[H G C E I]

[G C E I]

[J C E I]

A

B

13

C

D

11

8

E

I

14

16

23

F

G

5

H

7

Traversing order (i.e. the search path) is

A B D H G J

J

3

If hill climbing is used, the solution path will be

A B E I D H G J (it is longer, less ‘intelligent’)

Optimal Search

• Will produce optimal (best) answer
• Based on some optimisation function
• Mathematical functions are used
• for improvements
• for “optimisation”
BRANCH AND BOUND ALGORITHM
• One way to find optimal paths with less work is to use branch-and-bound.
• It always keeps track of all partial paths contending for further consideration.
• The shortest one is extended one level, creating as many new partial paths.
• Next, these new paths are considered, along with the remaining old ones, again, the shortest is extended.
• The process is repeated until the goal is reached along some path.
Branch-and-Bound
• Keys to remember:
• To turn likely to certain, you have to extend all partial paths until they are as long or longer than the complete path. The reason is that the last step in reaching the goal may be long enough to make the supposed solution longer than one or more partial paths.
• It might be that only a tiny step would extend one of the partial paths to the solution node.
• To be sure that this is not so, instead of terminating when a path is found, you terminate when the shortest partial path is longer than the shortest complete path
An Example for B-N-B

The length of the complete

path from S to G,

S-D-E-F-G is 15.

Similarly, the length of the

partial path S-D-A-B also 15

and any additional movement along a branch will make it longer than 15.

Accordingly, there is no need

to try S-D-A-B any further.

Because it will be longer

than the complete path

Only other paths emerging from S and from S-D-E have to be considered, as they may provide a shorter path.

S

D

A

E

F

B

15

G

15

To conduct a branch-and-bound search:
• Form a one-element queue consisting of zero length path (only root node)
• Until the first path in the queue terminated at the goal node or the queue is empty,
• remove the first path from the queue; create new paths by extending the first path to all the neighbours of the terminal node
• reject all paths with loops
• add the reaming new paths, if any, to the queue
• sort the entire queue by path length with least-cost paths in front
• If the goal is found, announce success; otherwise announce failure.

Solution

Search path to goal node:

[S(0)]

[B(1) A(4)]

[E(3) A(4) F(4)]

[A(4) F(4) I(6) H(7)]

[F(4) C(5) I(6) D(6) H(7)]

[G(5) C(5) I(6) D(6) J(6) H(7)]

Goal node reached and stopped.

A* Search
• All A* algorithms are admissible
• A search algorithm is admissible if it always produces an optimal solution
• The A* search is branch-and-bound, with an estimate of remaining cost combined with dynamic programming principle
• Theorem of A* algorithm
• For each node n, let h*(n) denote the cost of an optimal path from n to a goal node
• The algorithm uses a heuristic function h that satisfies h(n) <= h*(n) for all n in the state space, is admissible

A* SEARCH

Delete FIRSTNODE from start of QUEUE

Append children of FIRSTNODE

Order resulting list according to

cost-so-far + underestimate of remaining cost

Put result in NEWQUEUE

To conduct a A* search:

• Form a one-element queue consisting of zero length path (only root node)
• Until the first path in the queue terminated at the goal node or the queue is empty,
• remove the first path from the queue; create new paths by extending the first path to all the neighbours of the terminal node
• reject all paths with loops
• if two or more paths reach a common node, delete all those paths except the one that reaches the common node with the minimum cost
• sort the entire queue by SUM of the path length and a lower-bound estimate of the cost remaining, with least-cost paths in front
• If the goal is found, announce success; otherwise announce failure.
Function definition in A*
• Consider the evaluation function

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

wheren is any state in the search

g(n)is the cost from the start state

h(n)is the heuristic estimate of the cost

going from n state to goal node

Using A* in 8-puzzle problem

Figure 1 shows a start state and the first set of moves

2

8

3

START

1

6

4

7

5

2

8

3

2

8

3

2

8

3

First level of

The tree search

1

4

1

6

4

1

6

4

7

6

5

7

5

7

5

A2

A3

A1

Which one will the A* takes?

& Why? On what basis it is chosen?

What is the GOAL we wanted to achieve?

i.e. what is the question?

To reach this GOAL state

1

2

3

8

4

7

6

5

Many levels of search and many solutions are possible

to reach the goal state

Using A* in 8-puzzle problem

Figure 2 : Three heuristics applied to states in the 8-puzzle

2

8

3

5

6

0

Recall the goal state

1

6

4

7

5

1

2

3

8

4

2

8

3

3

4

0

7

6

5

1

4

7

6

5

2

8

3

5

6

0

1

6

4

Tiles

out of

place

Sum of

distances

out of place

2 * the no.

of direct tiles

reversals

These are potential

Criteria for the A* formula

7

5

Using A* in 8-puzzle problem

Figure 3 : The heuristic f applied to states in the 8-puzzle

2

8

3

g(n) = 0

1

6

4

7

5

2

8

3

2

8

3

2

8

3

g(n)=1

1

6

4

1

4

1

6

4

7

5

7

6

5

7

5

6

4

f(n)

6

• f(n) = g(n) + h(n)
• where g(n) actual distance from n (cost from start state)
• h(n) the no. of tiles out of place

1

2

3

8

4

GOAL

7

6

5

Exercise #1

List 4(four) criteria that are normally used to evaluate search methods

Exercise #2

List 2(two) limitations of heuristics search methods

• Completeness
• will the solution be eventually found? if there is one at all?
• Space complexity
• how much memory will it need or is necessary?
• Time complexity
• how long will it take to complete the search?
• Optimality
• will the search method find the highest quality of solution path when there are several.

Properties of Search Algorithms

Complete Yes No Yes No

Space Exponential Linear Exponential Linear

Time Exponential Exponential Exponential Exponential

Optimal Yes No Yes No

Bi-directional Search

Blind Search..

• It searches both forward and backward in the same state space (run simultaneously).
• It stops when the two moves meet in the middle.

Start

Goal

A schematic view of ~ that when a branch from the start node meets a

Branch of the goal node, it stops

Iterative Deepening (Korf 1987)

• As depth-first search gets quickly into a deep level in the search space. Depth-first search can get lost deep in the search tree/graph. It may also stuck in infinite path that does not lead to a goal.
• A compromise is to use a depth bound on depth-first :
• the depth bound forces failure on a search path once it gets below certain level

Blind Search..

Blind Search..

Iterative Deepening (Korf 1987)

• The hard part of Depth-limit search is to determine what limit is “good” limit.
• Iterative deepening tries all possible depth limits and pick up the best one!
• Thus:
• It is optimal and complete.
• It uses modest memory.

Blind Search..

Depth-Limited search

• Similar to DFS, except that it avoids the pitfalls of DFS by imposing a cut off on the maximum depth of a given path
• Drawback:
• if a chosen limit is too small, the scheme is not “complete”
• optimality = no

Blind Search..

Uniform Cost Search

• We learnt that BFS finds the shallowest path leading to the goal state
• uniform cost search modifies BFS by expanding only the lowest cost node (n)
• the cost of a path should remain low but not decreasing hence the term “uniform”

Note that if all step costs are equal, this is identical to BFS

Comparison of 6 Blind search methods

Breadth Depth Depth Bi-directional Iterative Uniform

first first -limited cost

Time bd bm bl bd/2 bd bd

Space bd bm bl bd/2 bd bd

Complete yes no yes, l d yes yes yes

Optimal yes no no yes yes yes

Heuristics …

Induction

• Induction means to generalise from a smaller version of the same problem
• Two essential features
• problem must be modelled in terms of the associated data
• induced result must be tested against real examples

Generate & Test

Heuristics …

• The basic idea is to generate possible solutions and devise a test to determine if the solutions are indeed good, i.e. acceptable.
• Steps:
• try to open a path that satisfies the specification
• determine whether the path is plausible, prune it if it is not plausible
• move to the next path
• check whether all specifications have been mentioned. If not, add the next specification and reiterate the steps by returning to first step

Heuristics …

Greedy Search

• There is a heuristic function, h(n), which serves to hold values of prediction of path-cost left to the goal
• Greedy search is to minimise the estimated cost to reach the goal
• Therefore, the node (state) closest to the goal will be expanded first

Heuristics …

Greedy Search

• It resembles DFS in the way that it follows a single path all the way to the goal, if there is no dead end
• Thus, it is incomplete and not optimal
• With good quality heuristic function, however, the space an time complexity can be reduced