AI Unit-2
AI Unit-2
RCA-403
Syllabus
UNIT-I INTRODUCTION: - Introduction to Artificial Intelligence, Foundations and
History of Artificial Intelligence, Applications of Artificial Intelligence, Intelligent
Agents, Structure of Intelligent Agents. Computer vision, Natural Language
Possessing.
UNIT-II INTRODUCTION TO SEARCH: - Searching for solutions, uniformed
search strategies, informed search strategies, Local search algorithms and
optimistic problems, Adversarial Search, Search for Games, Alpha - Beta
pruning.
UNIT-III KNOWLEDGE REPRESENTATION & REASONING: - Propositional
logic, Theory of first order logic, Inference in First order logic, Forward &
Backward chaining, Resolution, Probabilistic reasoning, Utility theory, Hidden
Markov Models (HMM), Bayesian Networks.
Syllabus
UNIT-IV MACHINE LEARNING: - Supervised and unsupervised learning,
Decision trees, Statistical learning models, learning with complete data - Naive
Bayes models, Learning with hidden data – EM algorithm, Reinforcement
learning.
Problem solving is the method to reach the desired goal or finding a solution to a
given situation. This method of solving problem through AI involves the process of
defining the search space, deciding start state and goal state and then finding the
path from start state to goal state through search space.
The movement from start state to goal state is guided by set of rules
specifically designed for that particular problem called the production rules. The
production rules are the valid moves described by the problems
Introduction to Search: Problem solving through AI
7 4 2 1 2 3
1 5 8 4
6 3 8 7 6 5
Introduction to Search: Problem solving through AI
Example: 8 Puzzle Problem
States: It specifies the location of each of the 8 tiles and the blank in one of the nice
squares.
Initial state: Any state can be designated as the initial state.
Goal: Many goal configurations are possible one such is shown in the figure
Legal moves ( or state): They generate legal states that result from trying the four
actions-
• Blank moves left
• Blank moves right
• Blank moves up
• Blank moves down
Path cost: Each step costs 1, so the path cost is the number of steps in the path.
Introduction to Search: Problem solving through AI
Example: 8 Puzzle Problem (Search/ State Space Representation)
Toy Problem Vs. Real World Problem
Problem Representation in AI
The most common methods of problem representation in AI are:-
1. State Space Representation
2. Problem Reduction
PRODUCTION SYSTEM
The production system is a model of computation that can be applied to implement
search algorithms and model human problem solving. Such problem solving
knowledge can be packed up in the form of little quanta called productions. It
consists of:
• Set of rules
• Database
• Control strategy
• Rule applier
Problem Representation in AI
Production System: Four classes of production systems
• A monotonic production system
• A non monotonic production system
• A partially commutative production system
• A commutative production system
Advantages of production systems
• Production systems provide an excellent tool for structuring AI programs.
• Production Systems are highly modular because the individual rules can be
added, removed or modified independently.
Disadvantage is the facts that it may be very difficult analyze the flow of control
within a production system because the individual rules don’t call each other.
Problem Representation in AI
Water-Jug Problem:
Statement: We are given 2 jugs, a 4-litre one and a 3-litre one. Neither have any
measuring markers on it. There is a pump that can be used to fill the jugs with water.
How can we get exactly 2 litres of water in to the 4-liter jugs?
PRODUCTION SYSTEM
Problem Representation in AI
Assumptions:
• We can fill a jug from
the pump.
• We can pour water out
of a jug to the ground.
• We can pour water from
one jug to another.
• There is no measuring
device available.
The production rules for
“WATER-JUG” Problem
are formulated as
PRODUCTION SYSTEM
Problem Representation in AI
ASSUMPTION: Consider that both the missionaries (M) and cannibals(C) are on
the same side of the river.
PRODUCTION SYSTEM
Problem Representation in AI
The production rules for
“Missionaries &
Cannibals” Problem are
formulated as
PRODUCTION SYSTEM
Problem Representation in AI
One solution is applying
the rules in the sequence
(5,2,7,10,3,6,3,10,7,10,7).
The solution is presented
in the RHS table
PRODUCTION SYSTEM
AI & Search Process
Searching can be defined as a sequence of steps that transforms the initial state to
the goal state. The searching process in AI can be broadly classified into two major
types:
1. Brute Force Search or uninformed or blind search.
2. Heuristic Search or informed search.
Measuring Problem-Solving Performance
• Completeness
• Optimality
• Time Complexity
• Space Complexity
AI & Search Process
Uninformed or Blind search or Brute Force Search: Uninformed search
algorithms do not have additional information about state or search space other than
how to traverse the tree, so it is also called blind search.
8-Puzzle Problem
Uninformed Search Techniques
Breadth First Search (BFS)
Advantages:
• Finds the path of minimal length to the goal - If there is more than one solution
then BFS can find the minimal one that requires less number of steps.
• If there is a solution, BFS will definitely find it out.
Disadvantages:
• Amount of memory is proportional to the number of nodes stored,
• If the solution is farther away from the root, breath first search will consume
lot of time.
Uninformed Search Techniques
Performance Measure of Breadth First Search (BFS)
• Uniform-cost search expands nodes in order of their cost from the root.
• Uniform-cost is guided by path cost rather than path length like in BFS
• The algorithms starts by expanding the root, then expanding the node with the
lowest cost from the root, the search continues in this manner for all nodes.
The nodes are stored in a priority queue.
• Uniform Cost Search can also be used as Breadth First Search if all the edges
are given a cost of 1.
Uninformed Search Techniques
Uniform Cost Search (UCS): Consider the following State Space Search
Advantages:
• Guaranteed to find the least-cost solution
Disadvantages:
• Exponential storage required.
• Open list must be kept sorted (as a priority queue).
• Must change cost of a node on open if a lower-cost path to it is found.
Uninformed Search Techniques
Performance Measure of Uniform Cost Search (UCS)
• Completeness: It is obvious that UCS is complete if the cost of each step
exceeds some small positive integer, this to prevent infinite loops..
• Optimality: UCS is always optimal in the sense that the node that it always
expands is the node with the least path cost.
• Space complexity: UCS is guided by path cost rather than path length so it is
hard to determine its complexity in terms of b and d, so if we consider C to be
the cost of the optimal solution, and every action costs at least e, then the
algorithm worst case is O(bC/e).
• Time Complexity: O(bC/e)
• DFS progresses by expanding the first child node of the search tree that
appears and thus going deeper and deeper until a goal node is found, or until it
hits a node that has no children. Then the search backtracks, returning to the
most recent node it hasn’t finished exploring. DFS investigated in 19th century
by French Mathematician Charles Pierre as a strategy for solving mazes.
• DFS is implemented using STACK (Last In First Out)
Uninformed Search Techniques
Depth First Search (DFS): Consider the following State Space Search
A
B C
B F G
B F M
B F
B K L
Advantages:
• DFS consumes very less memory space
Disadvantages:
• There is no guarantee of finding the goal node
Uninformed Search Techniques
Performance Measure of Depth First Search(DFS)
Note: b is branching factor and l is the limited depth (l < d) as d is depth of tree
Uninformed Search Techniques
Depth-First Iterative Deepening Search
• It is a search strategy resulting when you combine BFS and DFS, thus
combining the advantages of each strategy, taking the completeness and
optimality of BFS and the modest memory requirements of DFS.
• IDS works by looking for the best search depth d, thus starting with depth
limit 0 and make a BFS and if the search failed it increase the depth limit by 1
and try a BFS again with depth 1 and so on – first d = 0, then 1 then 2 and so
on – until a depth d is reached where a goal is found.
Uninformed Search Techniques
Depth-First Iterative Deepening Search Example:
Uninformed Search Techniques
Performance Measure of Depth-First Iterative Deepening Search (IDS)
Path is SACBHI
Heuristic (Informed) Search Techniques
Best First Search:
Heuristic (Informed) Search Techniques
Best First Search: Find the path using Best First Search!!!
Heuristic (Informed) Search Techniques
Best First Search: Find the path using Best First Search!!!
Heuristic (Informed) Search Techniques
Best First Search:
Advantages:
• It is more efficient than that of BFS and DFS.
• Time complexity of Best first search is much less than Breadth first search.
• The Best first search allows us to switch between paths by gaining the
benefits of both breadth first and depth first search. Because, depth first is
good because a solution can be found without computing all nodes and
Breadth first search is good because it does not get trapped in dead ends.
Disadvantages:
• Sometimes, it covers more distance than our consideration
Heuristic (Informed) Search Techniques
A* Algorithm
• Starting from a specific starting node of a graph, it aims to find a path to the
given goal node having the smallest cost
• A* Algorithm is the specialization of Best First Search in which the cost
associated with a node is f(n) = g(n) + h(n), where g(n) is the cost of the path
from the initial state to node n and h(n) is the heuristic estimate or the cost or a
path from node n to a goal. Thus, f(n) estimates the lowest total cost of any
solution path going through node n. At each point, a node with lowest f value is
chosen for expansion.
• A* algorithm guides an optimal path to a goal if the heuristic function h(n) is
admissible, meaning it never overestimates actual cost
• The * represents that the algorithm is admissible as it guarantees to give optimal
solution.
Heuristic (Informed) Search Techniques
A* Algorithm
Where,
• f(n) = evaluation function.
• g(n) = actual cost of current node from start node.
• h(n) = heuristic value i.e., estimated cost of current node from goal node.
Heuristic (Informed) Search Techniques
A* Algorithm: Consider the following graph, the numbers written on edges
represent the distance between the nodes and the numbers written on nodes
represent the heuristic value.
Find the most cost-effective path to reach from start state A to final state J using A*
Algorithm.
Heuristic (Informed) Search Techniques
A* Algorithm: Consider the following graph, the numbers written on edges
represent the distance between the nodes and the numbers written on nodes
represent the heuristic value.
Find the most cost-effective path to reach from start state S to final state G using
A* Algorithm.
Heuristic (Informed) Search Techniques
A* Algorithm:
Advantages:
• It is complete and optimal.
• It is the best algorithm, there is no other optimal algorithm guaranteed to
expand fewer nodes than A*
Disadvantages:
• Although being the best path finding algorithms, but A* search algorithm
does not produce the shortest path always because it heavily depends/ relies
on heuristics.
Heuristic (Informed) Search Techniques
A* Algorithm:
Advantages:
• It is complete and optimal.
• It is the best algorithm, there is no other optimal algorithm guaranteed to
expand fewer nodes than A*
Disadvantages:
• Although being the best path finding algorithms, but A* search algorithm
does not produce the shortest path always because it heavily depends/ relies
on heuristics.
Heuristic (Informed) Search Techniques
AO* Algorithm is based on problem decomposition i.e. breakdown goal into
simpler sub-goals. This decomposition generates generate arcs called AND arcs
and several arcs may emerge from single node called OR arcs. That’s why called it
AND-OR Graph. It is also called problem reduction search algorithm.
Nodes in the graph point to a number of successor nodes, all of which must
be solved in order for the arc to point to a solution up to its parent nodes. Each
node in the graph will also have a heuristic value associate with it.
f(n) = g(n)+h(n)
It is an efficient method to explore a solution path.
Example: Consider the AO graph given, AO *algorithm expand
next to which node?
Heuristic (Informed) Search Techniques
Advantages:
• It is an efficient method to explore a solution path
• Solution is guaranteed by using AO* algorithm
Disadvantages:
• Sometimes for unsolvable nodes, it can’t find the optimal path. Also, AO*
does not explore all the solution path once it got solution
Adversarial Search
It relates to competitive environment in which the agent goals are conflict giving
rise to adversarial search.
There are two methods for game playing:
1. Min-Max Procedure
2. Alpha-Beta Pruning (Cut-offs)
Min-Max Search: Min-Max strategy is a simple strategy for two player game.
Here, one player is called “maximizer” and the other called “minimizer.
Maximizer tries to maximize its score while minimizer tries to minimize
maximizer’s score.
It is also assumed that the maximizer makes the first move (not essential, as
minimizer can also make first move). The maximizer, always tries to go a position
where the static evaluation function value is the maximum positive value.
Adversarial Search
Min-Max Search: Consider the following tree graph example
The maximizer being the player to make the first move, and will move to node D
because the static evaluation function value for that is maximum. . The same above
figure shows that if the minimizer has to make the first move, it will go to node B
because the static evaluation function value at that node will be advantageous to it.
Once the static evaluation function is applied at the leaf nodes, backing up values
can begin. First we compute the backed-up values at the parents of the leaves.
Adversarial Search
Min-Max Search: Consider the following tree graph example
Adversarial Search - Alpha-Beta Pruning
The method that we are going to look in this article is called alpha-beta pruning. If
we apply alpha-beta pruning to a standard minimax algorithm, it returns the same
move as the standard one, but it removes (prunes) all the nodes that are possibly not
affecting the final decision.
Alpha-Beta pruning is a search algorithm that seeks to decrease the number
of nodes that are evaluated by mini-max algorithm in its search tree.
• α is a value which is best for Max player (highest value)
• β is a value which is best for Min player (lowest value)
Each node will keep its α-β values, and pruning done by following way:
• For Min node, if β<= α of max ancestor, PRUNE.
• For Max node, if β>= α of min ancestor, PRUNE.
Adversarial Search - Alpha-Beta Pruning
Consider the following state space graph, what’s the value of Root?
Adversarial Search - Alpha-Beta Pruning
The optimal value of the maximizer will be 3.
Adversarial Search - Alpha-Beta Pruning
Consider the following state space graph