Saquib Ali
Artificial Intelligence Notes
Module-III
Mini-Max Algorithm
o Mini-max algorithm is a recursive or backtracking
algorithm which is used in decision-making and game
theory. It provides an optimal move for the player
assuming that opponent is also playing optimally.
o Mini-Max algorithm uses recursion to search through the
game-tree.
o Min-Max algorithm is mostly used for game playing in
AI. Such as Chess, Checkers, tic-tac-toe, go, and various
tow-players game. This Algorithm computes the
minimax decision for the current state.
o In this algorithm two players play the game, one is called
Step 2: Now, first we find the utilities value for the
MAX and other is called MIN. Maximizer, its initial value is -∞, so we will compare each
o Both the players fight it as the opponent player gets the
value in terminal state with initial value of Maximizer and
minimum benefit while they get the maximum benefit. determines the higher nodes values. It will find the
o Both Players of the game are opponent of each other,
maximum among the all.
where MAX will select the maximized value and MIN
will select the minimized value. o For node D max(-1,- -∞) => max(-1,4)= 4
o The minimax algorithm performs a depth-first search o For Node E max(2, -∞) => max(2, 6)= 6
algorithm for the exploration of the complete game tree. o For Node F max(-3, -∞) => max(-3,-5) = -3
o The minimax algorithm proceeds all the way down to the o For node G max(0, -∞) = max(0, 7) = 7
terminal node of the tree, then backtrack the tree as the
recursion.
Working of Min-Max Algorithm:
o The working of the minimax algorithm can be easily
described using an example. Below we have taken an
example of game-tree which is representing the two-
player game.
o In this example, there are two players one is called
Maximizer and other is called Minimizer.
o Maximizer will try to get the Maximum possible score,
and Minimizer will try to get the minimum possible
score.
Step 3: In the
o This algorithm applies DFS, so in this game-tree, we
next step, it's a turn for minimizer, so it will compare all
have to go all the way through the leaves to reach the
nodes value with +∞, and will find the 3rd layer node values.
terminal nodes.
o For node B= min(4,6) = 4
o At the terminal node, the terminal values are given so we
o For node C= min (-3, 7) = -3
will compare those value and backtrack the tree until the
initial state occurs. Following are the main steps involved
in solving the two-player game tree:
Step-1: In the first step, the algorithm generates the entire
game-tree and apply the utility function to get the utility
values for the terminal states. In the below tree diagram, let's
take A is the initial state of the tree. Suppose maximizer
takes first turn which has worst-case initial value =- infinity,
and minimizer will take next turn which has worst-case
initial value = +infinity.
Step 4: Now it's a turn for Maximizer, and it will again
choose the maximum of all nodes value and find the
maximum value for the root node. In this game tree, there
Saquib Ali
Artificial Intelligence Notes
Module-III
are only 4 layers, hence we reach immediately to the root o Alpha-beta pruning can be applied at any depth of a
node, but in real games, there will be more than 4 layers. tree, and sometimes it not only prune the tree leaves
o For node A max(4, -3)= 4 but also entire sub-tree.
o The two-parameter can be defined as:
a. Alpha: The best (highest-value) choice we
have found so far at any point along the
path of Maximizer. The initial value of
alpha is -∞.
b. Beta: The best (lowest-value) choice we
have found so far at any point along the
path of Minimizer. The initial value of beta
is +∞.
o The Alpha-beta pruning to a standard minimax
algorithm returns the same move as the standard
algorithm does, but it removes all the nodes which
are not really affecting the final decision but making
algorithm slow. Hence by pruning these nodes, it
That was the complete workflow of the minimax two player makes the algorithm fast.
game.
Condition for Alpha-beta pruning:
Properties of Mini-Max algorithm: The main condition which required for alpha-beta pruning
o Complete- Min-Max algorithm is Complete. It will is: α>=β
definitely find a solution (if exist), in the finite
search tree. Key points about alpha-beta pruning:
o Optimal- Min-Max algorithm is optimal if both o The Max player will only update the value of alpha.
opponents are playing optimally. o The Min player will only update the value of beta.
o Time complexity- As it performs DFS for the o While backtracking the tree, the node values will be
game-tree, so the time complexity of Min-Max passed to upper nodes instead of values of alpha and
algorithm is O(bm), where b is branching factor of beta.
the game-tree, and m is the maximum depth of the o We will only pass the alpha, beta values to the child
tree. nodes.
o Space Complexity- Space complexity of Mini-max
algorithm is also similar to DFS which is O(bm). Working of Alpha-Beta Pruning:
Let's take an example of two-player search tree to
Limitation of the minimax Algorithm: understand the working of Alpha-beta pruning
The main drawback of the minimax algorithm is that it gets Step 1: At the first step the, Max player will start first move
really slow for complex games such as Chess, go, etc. This from node A where α= -∞ and β= +∞, these value of alpha
type of games has a huge branching factor, and the player and beta passed down to node B where again α= -∞ and β=
has lots of choices to decide. This limitation of the minimax +∞, and Node B passes the same value to its child D.
algorithm can be improved from alpha-beta pruning.
Alpha-Beta Pruning:
o Alpha-beta pruning is a modified version of the
minimax algorithm. It is an optimization technique for
the minimax algorithm.
o As we have seen in the minimax search algorithm that
the number of game states it has to examine are
exponential in depth of the tree. Since we cannot
eliminate the exponent, but we can cut it to half. Hence
there is a technique by which without checking each
node of the game tree we can compute the correct
minimax decision, and this technique is called pruning.
This involves two threshold parameter Alpha and beta Step 2: At Node D, the value of α will be calculated as its
for future expansion, so it is called alpha-beta pruning. turn for Max. The value of α is compared with firstly 2 and
It is also called as Alpha-Beta Algorithm. then 3, and the max (2, 3) = 3 will be the value of α at node
D and node value will also 3.
Saquib Ali
Artificial Intelligence Notes
Module-III
Step 3: Now algorithm backtrack to node B, where the
value of β will change as this is a turn of Min, Now β= +∞,
will compare with the available subsequent nodes value, i.e.
min (∞, 3) = 3, hence at node B now α= -∞, and β= 3.
Step 7: Node F returns the node value 1 to node C, at C α=
3 and β= +∞, here the value of beta will be changed, it will
In the next step, algorithm traverse the next successor of compare with 1 so min (∞, 1) = 1. Now at C, α=3 and β= 1,
Node B which is node E, and the values of α= -∞, and β= 3 and again it satisfies the condition α>=β, so the next child of
will also be passed. C which is G will be pruned, and the algorithm will not
compute the entire sub-tree G.
Step 4: At node E, Max will take its turn, and the value of
alpha will change. The current value of alpha will be
compared with 5, so max (-∞, 5) = 5, hence at node E α= 5
and β= 3, where α>=β, so the right successor of E will be
pruned, and algorithm will not traverse it, and the value at
node E will be 5.
Step 8: C now returns the value of 1 to A here the best value
for A is max (3, 1) = 3. Following is the final game tree
which is the showing the nodes which are computed and
nodes which has never computed. Hence the optimal value
for the maximizer is 3 for this example.
Step 5: At next step, algorithm again backtrack the tree,
from node B to node A. At node A, the value of alpha will
be changed the maximum available value is 3 as max (-∞,
3)= 3, and β= +∞, these two values now passes to right
successor of A which is Node C.
At node C, α=3 and β= +∞, and the same values will be
passed on to node F.
Step 6: At node F, again the value of α will be compared
with left child which is 0, and max(3,0)= 3, and then
compared with right child which is 1, and max(3,1)= 3 still
α remains 3, but the node value of F will become 1.
Move Ordering in Alpha-Beta pruning:
The effectiveness of alpha-beta pruning is highly dependent
on the order in which each node is examined. Move order is
an important aspect of alpha-beta pruning.
Saquib Ali
Artificial Intelligence Notes
Module-III
It can be of two types: can have around n/2 nodes and second last level n/4
nodes and in BFS we need to have every level one by
o Worst ordering: In some cases, alpha-beta pruning
one in queue).
algorithm does not prune any of the leaves of the tree, IDDFS combines depth-first search’s space-efficiency and
breadth-first search’s fast search (for nodes closer to root).
and works exactly as minimax algorithm. In this case,
How does IDDFS work?
it also consumes more time because of alpha-beta IDDFS calls DFS for different depths starting from an
factors, such a move of pruning is called worst initial value. In every call, DFS is restricted from going
beyond given depth. So basically we do DFS in a BFS
ordering. In this case, the best move occurs on the right fashion.
side of the tree. The time complexity for such an order
Algorithm:
is O(bm). // Returns true if target is reachable from
o Ideal ordering: The ideal ordering for alpha-beta // src within max_depth
pruning occurs when lots of pruning happens in the bool IDDFS(src, target, max_depth)
tree, and best moves occur at the left side of the tree. for limit from 0 to max_depth
if DLS(src, target, limit) == true
We apply DFS hence it first search left of the tree and return true
go deep twice as minimax algorithm in the same return false
amount of time. Complexity in ideal ordering is bool DLS(src, target, limit)
O(bm/2). if (src == target)
Rules to find good ordering: return true;
Following are some rules to find good ordering in alpha-
beta pruning: // If reached the maximum depth,
// stop recursing.
o Occur the best move from the shallowest node. if (limit <= 0)
o Order the nodes in the tree such that the best nodes are return false;
checked first. foreach adjacent i of src
o Use domain knowledge while finding the best move. if DLS(i, target, limit?1)
return true
Ex: for Chess, try order: captures first, then threats,
then forward moves, backward moves. return false
o We can bookkeep the states, as there is a possibility An important thing to note is, we visit top level nodes
that states may repeat. multiple times. The last (or max depth) level is visited
once, second last level is visited twice, and so on. It may
Iterative Deepening Search (IDS) or Iterative Deepening seem expensive, but it turns out to be not so costly, since in
Depth First Search(IDDFS): a tree most of the nodes are in the bottom level. So it does
There are two common ways to traverse a not matter much if the upper levels are visited multiple
graph, BFS and DFS. Considering a Tree (or Graph) of times.
huge height and width, both BFS and DFS are not very Advantages
efficient due to following reasons. o IDS is superior to other search algorithms in a number
1. DFS first traverses nodes going through one adjacent of ways. The first benefit is that it is comprehensive,
of root, then next adjacent. The problem with this which ensures that a solution will be found if one is
approach is, if there is a node close to root, but not in there in the search space. This is so that all nodes
first few subtrees explored by DFS, then DFS reaches under a specific depth limit are investigated before the
that node very late. Also, DFS may not find shortest depth limit is raised by IDS, which does a depth-
path to a node (in terms of number of edges). limited DFS.
2. BFS goes level by level, but requires more space. The o IDS is memory-efficient, which is its second benefit.
space required by DFS is O(d) where d is depth of tree, This is because IDS decreases the algorithm's memory
but space required by BFS is O(n) where n is number needs by not storing every node in the search area in
of nodes in tree (Why? Note that the last level of tree memory. IDS minimises the algorithm's memory
Saquib Ali
Artificial Intelligence Notes
Module-III
footprint by only storing the nodes up to the current 4. Transition Model:
depth limit. The transition model defines the dynamics of
o IDS's ability to be utilised for both tree and graph search the system, specifying how the state changes
is its third benefit. This is due to the fact that IDS is a when an action is applied.
generic search algorithm that works on any search space, It describes the relationship between the
including a tree or a graph. current state, the selected action, and the
Disadvantages resulting new state.
o IDS has the disadvantage of potentially visiting certain
The transition model is used to simulate the
nodes more than once, which might slow down the
search. The benefits of completeness and optimality consequences of actions and predict the
frequently exceed this disadvantage. In addition, by resulting state in the planning process.
employing strategies like memory or caching, the 5. Search Algorithm:
repeated trips can be minimised. The search algorithm determines the strategy
for exploring the space of possible plans or
Planning and component of planning system: sequences of actions.
It systematically explores the search space to
Planning in the context of artificial intelligence (AI) refers find a plan that satisfies the goal while
to the process of determining a sequence of actions or considering constraints and optimizing certain
decisions to achieve a specific goal or solve a problem. It criteria (e.g., plan length, cost).
involves generating a plan, which is a structured Common search algorithms used in planning
representation of the intended course of action, considering include depth-first search, breadth-first search,
the initial state, desired goal, available resources, and A* search, and heuristic search.
constraints. A planning system is an AI system or algorithm
designed to generate plans efficiently. 6. Plan Representation:
A plan is the output of the planning system
and represents the sequence of actions to be
The key components of a planning system:
executed.
1. Initial State: Plans can be represented in various formats,
The initial state defines the starting conditions or the such as action sequences, decision trees, or
current state of the world or system. graphs.
It includes information about the environment, objects, The plan representation should be structured,
their properties, and their relationships. unambiguous, and executable to guide the
execution phase.
The initial state serves as the foundation for the
planning process, determining the context from which 7. Plan Execution and Monitoring:
the plan will be developed. Once a plan is generated, it needs to be
executed in the real or simulated environment.
2. Goal:
The goal specifies the desired state or the outcome that During execution, the actual state of the
the planning system aims to achieve. system is monitored and compared to the
expected states described in the plan.
It represents the condition or set of conditions that the
plan should satisfy or accomplish. Deviations or unexpected events may require
plan adaptation or replanning to handle
The goal provides the direction and purpose for the
dynamic environments.
planning process, guiding the selection of actions and
decisions.
Planning systems find applications in diverse domains,
3. Actions: including robotics, logistics, scheduling, resource allocation,
Actions represent the executable steps or operations that and autonomous systems. They enable AI systems to
can be taken to modify the state of the system. autonomously reason about actions, make decisions, and
Each action typically has preconditions that must be generate effective plans to achieve desired goals in complex
satisfied for the action to be applicable or executable. and uncertain environments.
Actions also have effects, which describe the changes they
induce on the state of the system once executed.
The set of available actions and their properties define
the action space or the range of possible operations in
the planning process.
Saquib Ali
Artificial Intelligence Notes
Module-III
Natural Language Processing: Phonology − It is study of organizing sound
Natural Language Processing (NLP) refers to AI method of systematically.
communicating with an intelligent systems using a natural Morphology − It is a study of construction of words
language such as English. from primitive meaningful units.
Processing of Natural Language is required when you want Morpheme − It is primitive unit of meaning in a
an intelligent system like robot to perform as per your language.
instructions, when you want to hear decision from a Syntax − It refers to arranging words to make a
dialogue based clinical expert system, etc. sentence. It also involves determining the structural
The field of NLP involves making computers to perform role of words in the sentence and in phrases.
useful tasks with the natural languages humans use. The Semantics − It is concerned with the meaning of
input and output of an NLP system can be − words and how to combine words into meaningful
Speech phrases and sentences.
Written Text Pragmatics − It deals with using and understanding
Components of NLP: sentences in different situations and how the
interpretation of the sentence is affected.
1. Natural Language Understanding (NLU) Discourse − It deals with how the immediately
Understanding involves the following tasks − preceding sentence can affect the interpretation of
the next sentence.
Mapping the given input in natural language into
World Knowledge − It includes the general
useful representations.
knowledge about the world.
Analyzing different aspects of the language.
Steps in NLP:
There are general five steps −
2. Natural Language Generation (NLG) Lexical Analysis − It involves identifying and
It is the process of producing meaningful phrases and analyzing the structure of words. Lexicon of a
sentences in the form of natural language from some language means the collection of words and phrases
internal representation. in a language. Lexical analysis is dividing the whole
It involves − chunk of txt into paragraphs, sentences, and words.
Text planning − It includes retrieving the relevant Syntactic Analysis (Parsing) − It involves analysis
content from knowledge base. of words in the sentence for grammar and arranging
Sentence planning − It includes choosing required words in a manner that shows the relationship
words, forming meaningful phrases, setting tone of among the words. The sentence such as “The school
the sentence. goes to boy” is rejected by English syntactic
Text Realization − It is mapping sentence plan into analyzer.
sentence structure.
The NLU is harder than NLG.
Difficulties in NLU:
NL has an extremely rich form and structure. It is very
ambiguous. There can be different levels of ambiguity −
Lexical ambiguity − It is at very primitive level such as
word-level.
For example, treating the word “board” as noun or verb?
Syntax Level ambiguity − A sentence can be parsed in
different ways.
For example, “He lifted the beetle with red cap.” − Did
he use cap to lift the beetle or he lifted a beetle that had
red cap?
Referential ambiguity − Referring to something using
pronouns. For example, Rima went to Gauri. She said,
“I am tired.” − Exactly who is tired?
One input can mean different meanings.
Many inputs can mean the same thing.
Semantic Analysis − It draws the exact meaning or
the dictionary meaning from the text. The text is
NLP Terminology:
checked for meaningfulness. It is done by mapping
Saquib Ali
Artificial Intelligence Notes
Module-III
syntactic structures and objects in the task domain. They are incapable of −
The semantic analyzer disregards sentence such as Substituting human decision makers
“hot ice-cream”. Possessing human capabilities
Discourse Integration − The meaning of any Producing accurate output for inadequate
sentence depends upon the meaning of the sentence knowledge base
just before it. In addition, it also brings about the Refining their own knowledge
meaning of immediately succeeding sentence.
Pragmatic Analysis − During this, what was said is Components of Expert Systems:
re-interpreted on what it actually meant. It involves The components of ES include −
deriving those aspects of language which require Knowledge Base
real world knowledge. Inference Engine
User Interface
Learning common sense:
Common sense is the knowledge that all humans have. Such
knowledge is unspoken and unwritten – we take it for
granted. We acquire it imperceptibly from the day we are
born. For example, “animals don’t drive cars” or “my
mother is older than me”. This knowledge is often used by
human experts even when solving very narrow, domain-
specific tasks. This common-sense knowledge is something
that we learn through experience and curiosity without even
being aware of it. We also acquire a great deal of it in our
lifetimes.
AI systems do not have common sense knowledge and
acquiring it has been seen as important since their 1. Knowledge Base:
beginning. Furthermore, from all the efforts made over It contains domain-specific and high-quality knowledge.
many years, it’s become evident that building common Knowledge is required to exhibit intelligence. The success
sense reasoning systems is a work-intensive and sometimes of any ES majorly depends upon the collection of highly
costly task. In this paper, I show why common sense accurate and precise knowledge. The data is collection of
reasoning is so important, and describe some approaches facts. The information is organized as data and facts about
that have been used to build these systems. These the task domain. Data, information, and past
approaches have enabled common sense reasoning tasks to experience combined together are termed as knowledge.
be used as add-ons to AI client programs – such as Chatbots.
Components of Knowledge Base:
Expert Systems: The knowledge base of an ES is a store of both, factual and
The expert systems are the computer applications developed heuristic knowledge.
to solve complex problems in a particular domain, at the Factual Knowledge − It is the information widely
level of extra-ordinary human intelligence and expertise. accepted by the Knowledge Engineers and scholars
in the task domain.
Characteristics of Expert Systems: Heuristic Knowledge − It is about practice,
High performance accurate judgement, one’s ability of evaluation, and
Understandable guessing.
Reliable Knowledge representation:
Highly responsive It is the method used to organize and formalize the
knowledge in the knowledge base. It is in the form of IF-
Capabilities of Expert Systems: THEN-ELSE rules.
Advising
Instructing and assisting human in decision making
Knowledge Acquisition:
Demonstrating
Deriving a solution
The success of any expert system majorly depends on the
Diagnosing
quality, completeness, and accuracy of the information
Explaining
stored in the knowledge base.
Interpreting input
Predicting results The knowledge base is formed by readings from various
Justifying the conclusion experts, scholars, and the Knowledge Engineers. The
Suggesting alternative options to a problem
Saquib Ali
Artificial Intelligence Notes
Module-III
knowledge engineer is a person with the qualities of
empathy, quick learning, and case analyzing skills.
He acquires information from subject expert by recording,
interviewing, and observing him at work, etc. He then
categorizes and organizes the information in a meaningful
way, in the form of IF-THEN-ELSE rules, to be used by
interference machine. The knowledge engineer also
monitors the development of the ES. 3. User Interface:
User interface provides interaction between user of the ES
2. Inference Engine: and the ES itself. It is generally Natural Language
Use of efficient procedures and rules by the Inference Processing so as to be used by the user who is well-versed in
Engine is essential in deducting a correct, flawless solution. the task domain. The user of the ES need not be necessarily
In case of knowledge-based ES, the Inference Engine an expert in Artificial Intelligence.
acquires and manipulates the knowledge from the It explains how the ES has arrived at a particular
knowledge base to arrive at a particular solution. recommendation. The explanation may appear in the
In case of rule based ES, it − following forms −
Applies rules repeatedly to the facts, which are Natural language displayed on screen.
obtained from earlier rule application. Verbal narrations in natural language.
Adds new knowledge into the knowledge base if Listing of rule numbers displayed on the screen.
required. The user interface makes it easy to trace the credibility of
Resolves rules conflict when multiple rules are the deductions.
applicable to a particular case.
To recommend a solution, the Inference Engine uses the Expert Systems Limitations:
following strategies − No technology can offer easy and complete solution. Large
Forward Chaining systems are costly, require significant development time,
Backward Chaining and computer resources. ESs have their limitations which
Forward Chaining: include −
It is a strategy of an expert system to answer the Limitations of the technology
question, “What can happen next?” Difficult knowledge acquisition
Here, the Inference Engine follows the chain of conditions ES are difficult to maintain
and derivations and finally deduces the outcome. It High development costs
considers all the facts and rules, and sorts them before
concluding to a solution. Perception:
This strategy is followed for working on conclusion, result, Perception in AI implies the ability of machines to use input
or effect. For example, prediction of share market status as data from sensors (e.g., cameras, LiDAR, RADAR,
an effect of changes in interest rates. microphones, wireless signals, tactile sensors, etc.) to learn
about many facets of the world. For example, machine
perception is when it can tell the object’s position or
movement trajectory in the scene.
Backward Chaining:
With this strategy, an expert system finds out the answer to
the question, “Why this happened?” On the basis of what
has already happened, the Inference Engine tries to find out
which conditions could have happened in the past for this
result. This strategy is followed for finding out cause or
reason.
For example, diagnosis of blood cancer in humans.