Machine Intelligence
Preethi.P
Assistant Professor
Department of Computer Science & Engineering
Machine Intelligence
SEARCH
Search problems involve an agent that is given an initial
state and a goal state, and it returns a solution of how to
get from the initial to the goal.
A Search Problem
Agen
t
Machine Intelligence
SEARCH Problem - Example
15 Puzzle Problem A Maze
Google Maps
Machine Intelligence
Terminologies
Agent :
Agent is an entity that perceives its environment and acts
upon that environment.
AGENT FUNCTION and AGENT PROGRAM
The agent function is an abstract mathematical description;
The agent program is a concrete implementation, running within some physical system.
Machine Intelligence
Terminologies
State :
State is a configuration of the agent and its environment
Example : Each of the following diagrams represent a different state
State x State y State z
Machine Intelligence
Terminologies
Initial State :
Initial state is the state in which the agent begins.
Example : Let's say the following state is the initial state:
State x
Machine Intelligence
Terminologies
Actions :
Actions choices that can be made in a state.
More precisely, actions can be defined as a function - ACTION(s)
ACTIONS(s) returns the set of actions that can be executed in state s
Machine Intelligence
Terminologies
Transition Model :
Transition Model is a description of what state results from performing any
applicable action in any state.
More precisely, the transition model can be defined as a function - Results(s,a)
RESULT(s, a) returns the state resulting from performing action a in state s
Machine Intelligence
Terminologies
Transition Model Example:
Machine Intelligence
Terminologies
State Space
State Space is the set of all states reachable from the initial state by any
sequence of actions.
Machine Intelligence
Terminologies
State Space
The state space can be visualized as a directed graph with states,
represented as nodes, and actions, represented as arrows between nodes.
Machine Intelligence
Terminologies
Goal Test
Goal Test is a way to determine whether a given state is a goal state.
Some problems may have one goal whereas, in some complex problems there
could be multiple goals.
Machine Intelligence
Terminologies
Path Cost
Path Cost is a numerical cost
associated with a given path.
Find a Solution that minimizes the path
cost for example takes less time,
consuming less resources and so on.
Example : In the graph, we can
imagine each of the actions associated
with a state carry a cost. Some actions
could be cheaper/costlier than others.
Machine Intelligence
Terminologies
Path Cost
For some simpler problems like 15-
puzzle, we can simplify the diagram
and assume each of the actions carry
the same cost.
In 15-puzzle problem it doesn't matter
whether we are moving right or left or
up or down. The only thing that matters
is the number of steps that we take in
order to move from Initial state to goal
state.
Machine Intelligence
Formalizing a search problem
These terminologies form the basis of how we can define a search
problem. The search problem has following 5 components :
1. Initial State: the state the agent starts.
2. Actions: the set of actions that can be executed at a
state. State Space
3. Transition model: returns the state that results from doing
The state space forms a
an action in a state.
directed network or
4. Goal test: determines whether a given state is a goal state. graph in which the
5. Path Cost: function that assigns a numeric cost to a path. nodes are states and the
links between nodes are
Step cost: cost of taking a single action. actions.
The goal ultimately is to find a solution. Not just some
solution but an optimal one.
Machine Intelligence
Solution
Solution
Solution is a sequence of actions that leads from the initial state to a goal
state.
Optimal Solution
Optimal solution is a solution that has the lowest path cost among all
solutions.
Machine Intelligence
Examples
Analyze and Formulate the search problem
(Provide values of the following components :
1. State
2. Initial State
3. Actions
4. Goal Test
5. Path Cost)
Machine Intelligence
Let’s Analyze
8 Puzzle Problem
Machine Intelligence
Let’s Analyze
Rubik's Cube
Machine Intelligence
Let’s Analyze
8 Queens Problem
Machine Intelligence
Problem Solving Agents - Steps in Problem Solving
Goal Formulation Goal formulation is based on the current situation and the
agent’s performance measure.
Problem Formulation Problem formulation is the process of deciding what
actions and states to consider, given a goal.
Assumptions about the Under these assumptions, the solution to any problem is a
environment fixed sequence of actions.
Search Strategy The process of looking for a sequence of actions that reaches
the goal is called search.
Once a solution is found, the actions the search algorithm
Execution recommends can be carried out.
Machine Intelligence
Search Algorithm - Approach
How we will begin to Solve the Problem???
Start with a State (Initial State)
Take action(s)
Get more states to
Explore
repeat the process.. continue until you achieve
the goal/ exhaust all options(no solution)
Machine Intelligence
Frontier
● We are going to consider all of the available options(states to be
explored) to be stored inside of a single data structure called the
frontier.
● Frontier could be a Stack or a queue or priority queue etc.
● The frontier is going to represent all of the things that we could explore
next, that we haven't yet explored or visited.
● Hence in our approach, we're going to begin this search algorithm by
starting with a frontier that just contains one state.
● The frontier is going to contain the initial state because at the beginning,
that's the only state we know about.
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
TREE-SEARCH(problem):
• Start with a frontier that contains the initial state.
• Repeat:
If the frontier is empty:
return no solution;
else
- Remove a node from the frontier.
- If node contains goal state(perform goal test):
return the solution;
else
Expand node, add resulting nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
A
B Start with a frontier that
contains the initial state.
C D
E F
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform
goal test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
B
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform goa
test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform
goal test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Queue)
A
C D
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform goa
test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Queue)
A
D
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform
goal test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier(Queue)
A
D E
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform goa
test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier(Queue)
A
E
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform
goal test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier(Queue)
A
E F
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform goa
test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
Example :
Find a path from A to E.
Frontier(Queue)
A
F
B Repeat:
If the frontier is empty:
return no solution;
else
C D - Remove a node from the frontier.
- If node contains goal state(perform
goal test):
return the solution;
else
E F Expand node, add resulting
nodes to the frontier
Machine Intelligence
Approach - The general TREE-SEARCH algorithm
What could go wrong??
B
C D
E F
Machine Intelligence
The new algorithm : GRAPH -SEARCH
Algorithms that forget their history are doomed to repeat it. The way to avoid
exploring redundant paths is to remember where one has been. To do this, we
augment the TREE -SEARCH algorithm with a data structure called the explored
set (also known as the closed list), which remembers every expanded node.
Newly generated nodes that match previously generated nodes—ones in the
explored set or the frontier—can be discarded instead of being added to the
frontier. The new algorithm is called GRAPH -SEARCH.
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
A
B Start with a frontier that
contains the initial state.
C D Explored Set
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
C D Explored Set
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
B
C D Explored Set
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier
A
C D Explored Set
A B
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
D C
C D Explored Set
A B
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
C
C D Explored Set
A B D
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
F C
C D Explored Set
A B D
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
C
C D Explored Set
A B D F
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
C D Explored Set
A B D F C
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
E
C D Explored Set
A B D F C
E F
Machine Intelligence
Approach - The general GRAPH -SEARCH algorithm
Example :
Find a path from A to E.
Frontier (Stack)
A
C D Explored Set
A B D F C E
E F
Machine Intelligence
Graph Search Example
Machine Intelligence
Parameters to define a good strategy
• The goodness of your strategy is evaluated along the following dimensions -
TIME SPACE OPTIMALITY
COMPLETENESS
COMPLEXITY COMPLEXITY
does it always
maximum number does it always
find a number of nodes
of find least cost
solution if generated
nodes in memory solution
one exists?
These two criteria are measured in terms of
■ b: maximum branching factor of the search tree
■ d: depth of the least-cost solution
■ m: maximum depth of the state space (may be ∞)
Machine Intelligence
Types of Search Strategies/Algorithms
All search strategies are distinguished by
the order in which nodes are expanded.
Machine Intelligence
References
● https://cse.iitrpr.ac.in/ckn/courses/s2016/csl452/w2.pdf
● https://online-learning.harvard.edu/course/cs50s-introduction-artificial-
intelligence-python?delta=0
● https://sites.fas.harvard.edu/~cscie119/lectures/search.pdf
● https://courses.cs.washington.edu/courses/cse473/14sp/slides/2-
statespace-search.pdf