You are on page 1of 25

Artificial Intelligence

Searching and AI
Searching falls under Artificial Intelligence (AI).

A major goal of AI is to give computers the ability to


think, or in other words, mimic human behavior.

The problem is, unfortunately, computers don't


function in the same way our minds do.

They require a series of well-reasoned out steps before


finding a solution.
Searching and AI
Your goal, then, is to take a complicated task and
convert it into simpler steps that your computer can
handle.

That conversion from something complex to


something simple which computer can easily solve.
HEURISTICS
 From Greek heuriskein, “to find”.
 Of or relating to a usually speculative formulation
serving as a guide in the investigation or solution
of a problem.
 Computer Science: Relating to or using a
problem-solving technique in which the most
appropriate solution, of several found by
alternative methods, is selected at successive
stages of a program for use in the next step of
the program.
4
HEURISTICS
 the study of methods and rules of discovery and
invention.

 In state space search, heuristics are formalized


as rules for choosing those branches in a state
space that are most likely to lead to an
acceptable problem solution.

5
HEURISTIC SEARCH

 Heuristics and the design of algorithms to implement


heuristic search have been an important part of artificial
intelligence research.

 Game playing and theorem proving require heuristics to


reduce search space to simplify the solution finding.

6
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
 Performance of various heuristics is evaluated for solving the 8-puzzle.

 Figure shows a start and goal state for the 8-puzzle, along with the first
three states generated in the search.

7
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
 The simplest heuristic, counts the tiles out of place in

each state when it is compared with the goal.

 The state that had fewest tiles out of place is probably

closer to the desired goal and would be the best to


examine next.

8
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS

 The distance from the starting state to its descendants

can be measured by maintaining a depth count for


each state. This count is ‘0’ for the beginning state and
may be incremented by 1 for each level of the search.

 It records the actual number of moves that have been

used to go from the starting state in the search space


to each descendant.

9
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS
Let evaluation function f(n), be the sum of two

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

Where:

 g(n) measures the actual length of the path from start state to
any state n.
 h(n) is a heuristic estimate of the distance from the state n to
a goal.

10
IMPLEMENTING HEURISTIC EVALUATION FUNCTIONS

h(n) = 5 h(n) = 3 h(n) = 5

11
• Each state is labeled with a letter and its
heuristic weight, f(n) = g(n) + h(n).

• The number at the top


of each state indicates
the order in which it
was taken off the
OPEN list.

12
Successive stages of OPEN and CLOSED that generates the graph are:

13
14
Best-First Search
Is the new method which combine the advantages of
both depth-first and breadth-first search into single
method.

At each step of the best-first-search process, we select


the most promising of the nodes generated.

This is done by applying appropriate heuristic


function to each of them.
Best-First Search
Then expand the chosen node by using the rules to
generate its successors.

If one of them is a solution we can quit, if not, all


those new nodes are added to the set of nodes
generated so far.

Again the most promising node is selected and the


process continues.
ALGORITHM FOR HEURISTICS SEARCH
Best-First-Search
Best first search uses lists to maintain states:

OPEN LIST to keep track of the current fringe of the

search.
CLOSED LIST to record states already visited.

Algorithm orders the states on OPEN according to some


heuristics estimate of their closeness to a goal.

17
ALGORITHM FOR HEURISTICS SEARCH
Best-First-Search

Each iteration of the loop consider the most promising

state on the OPEN list.

Algorithm sorts and rearrange OPEN in precedence of

lowest heuristics value.

18
BEST-FIRST-SEARCH

19
Explanation-BEST-FIRST-SEARCH

At each iteration best-first–search removes the first element


from the OPEN list. If it meets the goal conditions, the
algorithm returns the solution path that led to the goal.
Each state retains ancestor information to determine if it had
previously been reached by a shorter path and to allow the
algorithm to return the final solution path.
If the first element on OPEN is not a goal, the algorithm
generate its descendants.

20
BEST-FIRST-SEARCH

If a child state is already on OPEN or CLOSED, the


algorithm checks to make sure that the state records the
shorter of the two partial solution paths.

Duplicate states are not retained.

By updating the ancestor history of nodes on OPEN and


CLOSED when they are rediscovered, the algorithm is
more likely to find a shorter path to a goal.

21
BEST-FIRST-SEARCH

Best-first-search applies a heuristic evaluation to the


states on OPEN, and the list is sorted accordingly to the
heuristic values of those states. This brings the best
states to the front of OPEN .

Because these estimates are heuristic in nature, the next


state to be examined may be from any level of the state
space. When OPEN is maintained as a sorted list, it is
referred to as a priority queue.

22
BEST-FIRST-SEARCH

A HYPOTHETICAL SEARCH SPACE


23
BEST-FIRST-SEARCH

TRACES OF OPEN AND CLOSED LISTS


24

You might also like