Unit 2 AI
Unit 2 AI
Once a solution is found, the actions it recommends can be carried out. This is
called the execution phase. Thus, we have a simple ―formulate, search, execute‖
design for the agent.
Path cost: It assigns a numeric cost to each path that follows the goal. The
problem solving agent selects a cost function, which reflects its performance
measure.
State-space of a problem is a set of all states which can be reached from
the initial state followed by any sequence of actions. The state-space
forms a directed map or graph where nodes are the states, links between
the nodes are actions, and the path is a sequence of states connected by the
sequence of actions.
Search: It identifies all the best possible sequence of actions to reach the goal
state from the current state. It takes a problem as an input and returns solution as
its output.
Solution: It finds the best algorithm out of various algorithms, which may be
proven as the best optimal solution.
Execution: It executes the best optimal solution from the searching algorithms to
reach the goal state from the current state n goal formulation.
Advantages:
1. Zero Risk
2. 24*7 availability
3. Digital Assistance
Disadvantages:
1. High costs
2. No creativity
3. Unemployment
Example problems:
8 Puzzle Problems:
Here, we have a 3×3 matrix with movable tiles numbered from 1 to 8 with a blank space. The tile
adjacent to the blank space can slide into that space. The objective is to reach a specified goal
state similar to the goal state, as shown in the below figure. The task is to convert the current
state into goal state by sliding digits into the blank space.
Here the task is to convert the current (Start) state into goal state by sliding digits into the blank
space. The problem formulation is as follows:
States: It describes the location of each numbered tiles and the blank tile.
Initial State: We can start from any state as the initial state.
Actions: Here, actions of the blank space is defined, i.e., either left, right, up or
down
Transition Model: It returns the resulting state as per the given state and actions.
Goal test: It identifies whether we have reached the correct goal-state.
Path cost: The path cost is the number of steps in the path where the cost of each
step is 1.
Note: The 8-puzzle problem is a type of sliding-block problem which is used for testing new
search algorithms in artificial intelligence.
8-queens problem:
The aim of this problem is to place eight queens on a chessboard in an order where no
queen may attack another. A queen can attack other queens either diagonally or in same
row and column. From the following figure, we can understand the problem as well as its
correct solution.
It is noticed from the above figure that each queen is set into the chessboard in a position
where no other queen is placed diagonally, in same row or column. Therefore, it is one
right approach to the 8-queens problem. For this problem, there are two main kinds of
formulation: 1. Incremental formulation: It starts from an empty state where the operator
augments a queen at each step. Following steps are involved in this formulation:
States: Arrangement of any 0 to 8 queens on the chessboard
Initial State: An empty chessboard
Actions: Add a queen to any empty box.
Transition model: Returns the chessboard with the queen added in a box.
Goal test: Checks whether 8-queens are placed on the chessboard without
any attack. • Path cost: There is no need for path cost because only final
states are counted. In this formulation, there are approximately 1.8 x 1014
possible sequences to investigate.
Complete-state formulation: It starts with all the 8-queens on the
chessboard and moves them around, saving from the attacks. Following
steps are involved in this formulation
States: Arrangement of all the 8 queens one per column with no queen
attacking the other queen.
Actions: Move the queen at the location where it is safe from the attacks.
This formulation is better than the incremental formulation as it reduces the state space from 1.8
x 1014 to 2057, and it is easy to find the solutions.
Robot navigation:
Here a robot can move in a continuous space with (in principle) an infinite set of possible actions
and states. For a circular robot moving on a flat surface, the space is essentially two-dimensional.
When the robot has arms and legs or wheels that must also be controlled, the search space
becomes many-dimensional. Advanced techniques are required just to make the search space
finite.
Search tree is a tree generated as the search space is traversed. The search space itself is
not necessarily a tree, frequently it is a graph. This tree specifies possible paths through
the search space.
Expansion of nodes occurs as states are explored, the corresponding nodes are expanded
by applying the successor function which generates a new set of (child) nodes.
Fringe (frontier) is the set of nodes not yet visited and newly generated nodes are added
to the fringe.
Search strategy determines the selection of the next node to be expanded. It can be
achieved by ordering the nodes in the fringe – e.g. queue (FIFO), stack (LIFO), ―best‖
node w.r.t. some measure (cost).
A loopy path is a special case of redundant paths, where there are more than one paths
from one state to another (for example, Arad — Sibiu and Arad — Zerind — Oradea —
Sibiu).
The redundant path situation occurs in almost every problem, and often makes the
solution algorithm less efficient, worsening the performance of the searching agent. One
way to eliminate the redundancy is to utilize the advantage given by the problem
definition itself. For example, in the case of traveling from Arad to Bucharest, since the
path costs are additive and step costs are non-negative, only one path among the various
redundant paths has the least cost (and it is the shortest distance between the two states),
and loopy paths are never better than the same path with loops removed.
For each node n of the tree, we have a structure that contains five components:
n.STATE: the state in the state space to which the node corresponds.
n.PARENT: the node in the search tree that generated this node.
n.ACTION: the action that was applied to the parent to generate the node.
n.DEPTH: the depth of the node n, i.e., number of nodes in the path from the rood to this
node n.
n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to
the node, as indicated by the parent pointers.
Well-Defined Problem:
Scope: The problem is sufficiently scoped, meaning it's neither too broad
nor too narrow. It should be manageable for the available AI techniques
and resources.
Relevance: The problem is relevant to the domain or application for which
the AI system is being developed. It should address a real-world need or
challenge.
Much studied in AI
Requires search
Real mechanisms
Advantages:
Clarity: Well-defined problems provide clear goals and guidelines, reducing ambiguity
and ensuring everyone involved understands what needs to be achieved.
Efficiency: With clear objectives and criteria for success, resources can be allocated more
efficiently, and development efforts can be focused on achieving the desired outcomes.
Measurable Progress: Clear success criteria enable progress to be measured objectively,
allowing for effective tracking of advancements and adjustments as needed.
Effective Collaboration: Well-defined problems facilitate collaboration among
multidisciplinary teams, as everyone can work towards a common goal with a shared
understanding of the problem.
Structured Approach: Having a well-defined problem encourages a structured approach
to problem-solving, including the identification of relevant data, algorithms, and
evaluation metrics.
Disadvantages:
Limited Scope: Well-defined problems often have clear boundaries, which can lead to AI
systems being narrowly focused. This can make them less adaptable to new or
unexpected situations outside their defined scope.
Over fitting: AI models optimized for specific well-defined problems may perform
poorly when faced with variations or nuances in real-world data. They may become too
specialized and fail to generalize well to new scenarios.
Lack of Creativity: Well-defined problems typically have predetermined solutions,
leaving little room for creative or innovative approaches. AI systems may struggle to
tackle novel challenges that require thinking outside the box.
Dependency on Data Quality: AI models rely heavily on data, and well-defined problems
often require large, high-quality datasets for training. If the data is biased, incomplete, or
inaccurate, it can lead to biased or unreliable AI outcomes.
A search algorithm that explores a problem space without any specific knowledge or
information about the problem other than the initial state and the possible actions to take.
The uninformed search does not contain any domain knowledge such as closeness, the
location of the goal. It operates in a brute-force way as it only includes information about
how to traverse the tree and how to identify leaf and goal nodes. Uninformed search
applies a way in which search tree is searched without any information about the search
space like initial state operators and test for the goal, so it is also called blind search. It
examines each node of the tree until it achieves the goal node.
Informed Search:
The algorithms of an informed search contain information regarding the goal state.
Breadth-first Search:
Breadth-first search is the most common search strategy for traversing a tree or graph.
This algorithm searches breadthwise in a tree or graph, so it is called breadth-first search.
BFS algorithm starts searching from the root node of the tree and expands all successor
nodes at the current level before moving to nodes of next level.
The breadth-first search algorithm is an example of a general-graph search algorithm.
Breadth-first search implemented using FIFO queue data structure.
An algorithm used to find the shortest path from one node to another node in a graph.
Algorithm:
Time Complexity: Time Complexity of BFS algorithm can be obtained by the number of
nodes traversed in BFS until the shallowest Node. Where the d= depth of shallowest
solution and b is a node at every state.
Space Complexity: Space complexity of BFS algorithm is given by the Memory size of
frontier which is O (bd).
Completeness: BFS is complete, which means if the shallowest goal node is at some
finite depth, then BFS will find a solution.
Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of the
node.
Advantages:
Disadvantages:
It requires lots of memory since each level of the tree must be saved into
memory to expand the next level.
BFS needs lots of time if the solution is far away from the root node.
Uniform-cost search is a searching algorithm used for traversing a weighted tree or graph. This
algorithm comes into play when a different cost is available for each edge. The primary goal of
the uniform-cost search is to find a path to the goal node which has the lowest cumulative cost.
Uniform-cost search expands nodes according to their path costs form the root node. It can be
used to solve any graph/tree where the optimal cost is in demand. A uniform-cost search
algorithm is implemented by the priority queue. It gives maximum priority to the lowest
cumulative cost. Uniform cost search is equivalent to BFS algorithm if the path cost of all edges
is the same.
A type of uninformed search that performs a search based on the lowest path cost.
UCS helps us find the path from the starting node to the goal node with the minimum
path cost.
Advantages:
Uniform cost search is optimal because at every state the path with the least cost
is chosen.
Disadvantages:
It does not care about the number of steps involve in searching and only
concerned about path cost. Due to which this algorithm may be stuck in an
infinite loop.
Depth-first Search:
Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
It is called the depth-first search because it starts from the root node and follows each
path to its greatest depth node before moving to the next path.
DFS uses a stack data structure for its implementation.
The process of the DFS algorithm is similar to the BFS algorithm.
Advantages:
DFS requires very less memory as it only needs to store a stack of the nodes on
the path from root node to the current node.
It takes less time to reach to the goal node than BFS algorithm (if it traverses in
the right path).
Disadvantages:
There is the possibility that many states keep re-occurring, and there is no
guarantee of finding the solution.
DFS algorithm goes for deep down searching and sometime it may go to the
infinite loop.
Completeness: DFS search algorithm is complete within finite state space as it
will expand every node within a limited search tree.
Time Complexity: Time complexity of DFS will be equivalent to the node
traversed by the algorithm. It is given by:
Where, m= maximum depth of any node and this can be much larger than d
(Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root
node, hence space complexity of DFS is equivalent to the size of the fringe set,
which is O(bm).
Optimal: DFS search algorithm is non-optimal, as it may generate a large number
of steps or high cost to reach to the goal node.
Standard failure value: It indicates that problem does not have any solution.
Cutoff failure value: It defines no solution for the problem within a given depth
limit.
Advantages:
Disadvantages:
Advantages:
It combines the benefits of BFS and DFS search algorithm in terms of fast search
and memory efficiency.
Disadvantages:
The main drawback of IDDFS is that it repeats all the work of the previous
phase.
Advantages:
Disadvantages: