AI Notes
AI Notes
UNIT 1
Introduction: Definition of AI, History of AI, nature of AI problems, examples of AI
problems. Problem solving by search: Uninformed Search: Depth First Search (DFS),
Breadth First Search (BFS). Informed Search: Best First Search, A*. Local Search: Hill
Climbing. Problem Reduction Search: AO*. Population Based Search: Ant Colony
Optimization, Genetic Algorithm. Game Playing:MinMax Algorithm, Alpha-Beta Pruning.
UNIT 2
Knowledge Representation: Types of Knowledge, Knowledge Representation
Techniques/schemes: Propositional Logic, Predicate Logic, Semantic nets, Frames.
Knowledge representation issues. Rule based systems.
UNIT 3
Reasoning under Uncertainty: Basics of Probability Theory, Probabilistic Reasoning,
Bayesian Reasoning, Dempster-Shafer Theory. Planning: Introduction to Planning,
Representation of Planning, Partial-order Planning.
UNIT 4
Learning: Introduction to Learning, Types of Learning: Learning by Induction, Rote
Learning, Symbol Based Learning, Identification Trees, Explanation Based Learning,
Transformational Analogy, Introduction to Neural Networks, Expert Systems, Current
trends in Artificial Intelligence
List of Program:
1. Write a Program to Implement Breadth First Search using Python.
2. Write a Program to Implement Depth First Search using Python.
3. Write a Program to Implement Tic-Tac-Toe game using Python.
4. Write a Program to Implement 8-Puzzle problem using Python.
5. Write a Program to Implement Water-Jug problem using Python.
6. Write a Program to Implement Travelling Salesman Problem using Python.
7. Write a Program to Implement Tower of Hanoi using Python.
8. Write a Program to Implement Monkey Banana Problem using Python.
9. Write a Program to Implement Missionaries-Cannibals Problems using Python.
10. Write a Program to Implement 8-Queens Problem using Python.
25 Marks
5 presentation
5 assignment
5 Internal
10 presence
Unit 1
16/Jan/2024
AI is one of the latest fields of science and engineering. Term AI or Artificial Intelligence
introduced in 1956. AI currently covered a huge variety of subfields, ranging from the
general (learning and perception) to the specific, such as playing chess, proving
mathematical theorems, writing poetry, driving a car on a crowded street, and
diagnosing diseases. AI is relevant to any intellectual task, that’s why we can say it is a
universal field.
· Intelligence is the ability to acquire, understand and apply the knowledge to achieve
goals in the world.
· AI is the study of the mental faculties through the use of computational models
· AI program will demonstrate a high level of intelligence that equals or exceeds the
intelligence required of a human in performing some tasks.
· It can be described as an attempt to build machines that like humans can think and
act, able to learn and use knowledge to solve problems on their own.
History
He published the first universal formal language and showed that math itself is either
flawed or allows for unprovable but true statements.
· In 1936, Alan Turing's work during World War II laid the foundation for computer
science and AI, and invented a Turing machine.
· In 1956, John McCarthy introduced the term "Artificial Intelligence" as the topic of the
Dartmouth Conference, the first conference devoted to the subject.
Application of AI:
Disease Diagnosis: AI systems can analyze medical data, such as images and
patient records, to assist in diagnosing diseases like cancer or identifying anomalies.
Finance:
Retail:
Customer Service:
Voice Assistants: Virtual assistants like Siri and Alexa use natural language
processing to understand and respond to voice commands.
Education:
Automated Grading: AI can automate the grading process for assessments and
provide immediate feedback to students.
Transportation:
Manufacturing:
Quality Control: Computer vision systems inspect products for defects on the
production line, ensuring high-quality output.
Marketing:
Market Forecasting: AI models can predict market trends and consumer behavior,
helping businesses make informed decisions.
Human Resources:
Cybersecurity:
Threat Detection: AI systems analyze network traffic and user behavior to detect
and respond to cybersecurity threats in real-time.
Crop Monitoring: Computer vision helps monitor crop health and identify diseases
or pests early on.
Environmental Conservation:
a. Requires a model for human cognition. Precise enough models allow simulation by
computers.
b. Focus is not just on behavior and I/O, but looks like reasoning process.
c. Goal is not just to produce human-like behavior but to produce a sequence of steps
of the reasoning process, similar to the steps followed by a human in solving the same
task.
a. The study of mental faculties through the use of computational models; that it is, the
study of computations that make it possible to perceive reason and act.
a. The art of creating machines that perform functions requiring intelligence when
performed by people; that it is the study of, how to make computers do things which, at
the moment, people do better.
b. Focus is on action, and not intelligent behavior centered around the representation of
the world
The interrogator tries to determine which the person is and which the machine is.
The machine tries to fool the interrogator to believe that it is the human, and the
person also tries to convince the interrogator that it is the human.
If the machine succeeds in fooling the interrogator, then conclude that the
machine is intelligent.
Strong AI makes the bold claim that computers can be made to think on a level
(at least) equal to humans.
AI problems
AI problems can be broadly categorized based on the type of intelligence. Here are
some common types of problems in the field of Artificial Intelligence:
Clustering Problems: Grouping similar data points together based on certain features.
Ex: Customer segmentation, document clustering, anomaly detection.
Computer Vision Problems: Processing and interpreting visual information from the
world. Ex: Object detection, facial recognition, image segmentation.
Generative Problems: Creating new, meaningful data that resembles a given dataset.
Ex: Generative Adversarial Networks (GANs) for image synthesis, text generation.
Anomaly Detection: Identifying patterns or instances that deviate significantly from the
norm. Ex: Fraud detection, network intrusion detection.
Optimization Problems: Finding the best solution from a set of possible solutions.
Nature of AI Problems
Understanding AI Problems
1. AI lacks Transparency
One of the biggest challenges of AI is that AI and its core component of deep learning
models, neural networks, etc. are complicated and difficult to understand. This renders
a lack of transparency on the premise of how AI draws the conclusion, its mechanism of
using algorithms or making biased decisions, etc.
Example: One of the best examples of AI Problems is the Black box problem.
This is one of the top challenges of AI that the world is constantly debating about. The
process of task automation powered by AI can result in a negative impact on human
workers. This has become a pressing issue as almost every industry adopts technology
for automating tasks.
AI-powered technologies, machines and robots have come about with a high potential
of being more dexterous and smarter at tasks that may require massive human work.
Example: One of the most recent examples would be US companies laying off about
3900 people due to AI integration in May, as reported by a Chicago-based firm
Challenger, Gray & Christmas, Inc.
This is a long-debated concern and one of the biggest AI problems. AI tools collect data
from the user of the AI-powered technology or program.
AI systems collect personal data to train the models for a more customized user
experience for the users. This often raises the question of how and where such data is
used, and the data collected may not be secured.
Example: The finest example of this AI problem may be the case that occurred in 2023
with ChatGPT, wherein a bug incident exposed an active user's chat history to some
other users.
Hence, data, especially confidential and sensitive data, are not secure in AI and AI tools
cannot be considered an accountable tool for securing personal information.
4. Responsibility Issue
With the implementation of AI technology, the issue of identifying the factor responsible
for any hardware malfunction has become relatively difficult. In AI there is a
responsibility gap in AI-powered technology and machine.
Example: In self-driving cars when accidents occur it becomes complicated to identify
the causal factor of the accident. Whether it is a malfunction in the data or the machines
in the car, etc. when the vehicle's performances are modelled and designed on the
basis of the data fed to the machine.
5. Ethical Challenges
One of the top AI problems is the ethical issue. Developers are designing and grooming
chatbots with the potential of generating human-like conversation, making it difficult to
discern between real human customer support and a machine.
AI works on algorithms that are fed with data for training, and AI makes predictions
based on the training it receives. These predictions are labelled based on the data
assumption. This leaves the scope for bias and inaccuracy which is one of the most
prominent challenges of AI.
6. AI is expensive
One of the most pressing and challenging AI problems is its cost, as adopting AI and
deploying AI-powered machines and technologies requires expertise and field experts.
Also, AI works on a colossal amount of data that requires great computational power.
22/1/2024
The basic crux of artificial intelligence is to solve problems just like humans.
In this article, I am going to discuss the various searching techniques that are used to
solve a problem.
Completeness
A search algorithm is said to be complete when it gives a solution or returns any
solution for a given random input.
Optimality
If a solution found is best (lowest path cost) among all the solutions identified, then that
solution is said to be an optimal one.
Time complexity
The time taken by an algorithm to complete its task is called time complexity. If the
algorithm completes a task in a lesser amount of time, then it is an efficient one.
Space complexity
It is the maximum storage or memory taken by the algorithm at any time while
searching.
These properties are
also used to compare the efficiency of the different types of searching algorithms.
● Uninformed search
● Informed search
The uninformed search algorithm does not have any domain knowledge such
as closeness, location of the goal state, etc. it behaves in a brute-force way.
It only knows the information about how to traverse the given tree and how to
find the goal state. This algorithm is also known as the Blind search algorithm
or Brute -Force algorithm.
They are-
● Breadth-first search
● Depth-first search
● Depth-limited search
● Iterative deepening depth-first search
● Bidirectional search
● Uniform cost search
1. Breadth-first search
It is of the most common search strategies. It generally starts from the root node and
examines the neighbor nodes and then moves to the next level. It uses First-in First-out
(FIFO) strategy as it gives the shortest path to achieving the solution.
BFS is used where the given problem is very small and space complexity is not
considered.
Here, let’s take node A as the start state and node F as the goal state.
The BFS algorithm starts with the start state and then goes to the next level and visits
the node until it reaches the goal state.
In this example, it starts from A and then travel to the next level and visits B and C and
then
travel to the next level and visits D, E, F and G. Here, the goal state is defined as F. So,
the traversal will stop at F.
Complexities
The time complexity of the BFS algorithm is represented in the form of O(V + E), where
V is the number of nodes and E is the number of edges.
Python Code:
graph = {
'5' : ['3','7'],
'3' : ['2', '4'],
'7' : ['8'],
'2' : [],
'4' : ['8'],
'8' : []
}
# Driver Code
print("Following is the Breadth-First Search")
bfs(visited, graph, '5') # function calling
Advantages of BFS
Disadvantages of BFS
● BFS stores all the nodes in the current level and then go to the next level. It
requires a lot of memory to store the nodes.
● BFS takes more time
to reach the goal state which is far away.
2. Depth-first search
The depth-first search uses Last-in, First-out (LIFO) strategy and hence it can be
implemented by using stack. DFS uses backtracking. That is, it starts from the initial
state and explores each path to its greatest depth before it moves to the next path.
DFS will follow
Here, it starts from the start state A and then travels to B and then it goes to D. After
reaching
D, it backtracks to B. B is already visited, hence it goes to the next depth E and then
backtracks to B. as it is already visited, it goes back to A. A is already visited. So, it
goes to C and then to F. F is our goal state and it stops there.
Python Code
graph = {
'A' : ['B','C'],
'B' : ['D', 'E'],
'C' : ['F', 'G'],
'D' : [],
'E' : [],
'F' : [],
'G' : []
}
goal = 'F'
visited = set()
def dfs(visited, graph, node):
if node not in visited:
print (node)
visited.add(node)
for neighbour in graph[node]:
if goal in visited:
break
else:
dfs(visited, graph, neighbour)
dfs(visited, graph, 'A')
The time complexity of the DFS algorithm is O(V+E), where V is the number of vertices
and E is the number of edges in the graph.
Disadvantages of DFS
29/Jan/2024
Uninformed search algorithms look for all possible solutions of the problem in search
space without having any additional knowledge about search space. But an informed
search algorithm contains a list of knowledge such as how far we are from the goal,
path cost, how to reach the goal node, etc. This knowledge helps agents to explore less
of the search space and find the goal node.
Algorithms have information on the goal state which helps in more efficient searching.
This information is obtained by a function that estimates how close a state is to the goal
state.
Informed search in AI is a type of search algorithm that uses additional information to
guide the search process, allowing for more efficient problem-solving compared to
uninformed search algorithms.
Heuristics function: Heuristic is a function which is used in Informed Search, and it
finds the most promising path. It takes the current state of the agent as its input and
produces the estimation of how close the agent is from the goal. The heuristic method,
however, might not always give the best solution, but it is guaranteed to find a good
solution in reasonable time. Heuristic function estimates how close a state is to the goal.
It is represented by h(n), and it calculates the cost of an optimal path between the pair
of states. The value of the heuristic function is always positive.
Pure Heuristic Search
An informed search algorithm employed in artificial intelligence which expands nodes
based on heuristic values is called a pure heuristic search algorithm. These algorithms
use heuristics, which are shortcuts or general rules of thumb that direct the search
process in the direction of the desired state. In addition, pure heuristic search algorithms
use domain-specific knowledge to increase search efficiency instead of uninformed
search algorithms, which have no prior knowledge of the problem area.
The A* algorithm is one of the most widely used pure heuristic search methods. The
cost of moving from the current state to the objective state is estimated by the A*
algorithm using a heuristic function.
In the informed search we will discuss two main algorithms which are given below:
○ A* Search Algorithm
Greedy best-first search algorithm always selects the path which appears best at that
moment. It is the combination of depth-first search and breadth-first search algorithms.
It uses the heuristic function and search. Best-first search allows us to take the
advantages of both algorithms. With the help of best-first search, at each step, we can
choose the most promising node. In the best first search algorithm, we expand the node
which is closest to the goal node and the closest cost is estimated by heuristic function,
i.e.
1. f(n)= g(n).
○ Step 3: Remove the node n, from the OPEN list which has the lowest value of
h(n), and places it in the CLOSED list.
○ Step 5: Check each successor of node n, and find whether any node is a goal
node or not. If any successor node is goal node, then return success and
terminate the search, else proceed to Step 6.
○ Step 6: For each successor node, algorithm checks for evaluation function f(n),
and then check if the node has been in either OPEN or CLOSED list. If the node
has not been in both list, then add it to the OPEN list.
Advantages:
○ Best first search can switch between BFS and DFS by gaining the advantages of
both the algorithms.
Disadvantages:
Example:
Consider the below search problem, and we will traverse it using greedy best-first
search. At each iteration, each node is expanded using evaluation function f(n)=h(n) ,
which is given in the below table.
In this search example, we are using two lists which are OPEN and CLOSED Lists.
Following are the iteration for traversing the above example.
Expand the nodes of S and put in the CLOSED list
Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is
O(bm). Where, m is the maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is
finite.
In A* search algorithm, we use search heuristic as well as the cost to reach the node.
Hence we can combine both costs as following, and this sum is called as a fitness
number.
At each point in the search space, only those node is expanded which have the lowest
value of f(n), and the algorithm terminates when the goal node is found.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and
stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation
function (g+h), if node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list.
For each successor n', check whether n' is already in the OPEN or CLOSED list, if not
then compute evaluation function for n' and place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to
the back pointer which reflects the lowest g(n') value.
Advantages:
Disadvantages:
○ It does not always produce the shortest path as it mostly based on heuristics and
approximation.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic
value of all states is given in the below table so we will calculate the f(n) of each state
using the formula f(n)= g(n) + h(n), where g(n) is the cost to reach any node from start
state.
Here we will use OPEN and CLOSED list.
Solution:
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration4 will give the final result, as S--->A--->C--->G it provides the optimal path with
cost 6.
Points to remember:
○ A* algorithm returns the path which occurred first, and it does not search for all
remaining paths.
○ Admissible: the first condition requires for optimality is that h(n) should be an
admissible heuristic for A* tree search. An admissible heuristic is optimistic in
nature.
If the heuristic function is admissible, then A* tree search will always find the least cost
path.
○ It is also called greedy local search as it only looks to its good immediate
neighbor state and not beyond that.
○ A node of hill climbing algorithm has two components which are state and value.
○ In this algorithm, we don't need to maintain and handle the search tree or graph
as it only keeps a single current state.
○ Generate and Test variant: Hill Climbing is the variant of Generate and Test
method. The Generate and Test method produce feedback which helps to decide
which direction to move in the search space.
On Y-axis we have taken the function which can be an objective function or cost
function, and state-space on the x-axis. If the function on Y-axis is cost then, the goal of
search is to find the global minimum and local minimum. If the function of Y-axis is
Objective function, then the goal of the search is to find the global maximum and local
maximum.
Global Maximum: Global maximum is the best possible state of state space landscape.
It has the highest value of objective function.
Flat local maximum: It is a flat space in the landscape where all the neighbor states of
current states have the same value.
○ Steepest-Ascent hill-climbing:
Simple hill climbing is the simplest way to implement a hill climbing algorithm. It only
evaluates the neighbor node state at a time and selects the first one which
optimizes current cost and set it as a current state. It only checks it's one successor
state, and if it finds better than the current state, then move else be in the same state.
This algorithm has the following features:
○ Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
○ Step 2: Loop Until a solution is found or there is no new operator left to apply.
b. Else if it is better than the current state then assign new state as a current
state.
c. Else if not better than the current state, then return to step2.
○ Step 5: Exit.
○ Step 1: Evaluate the initial state, if it is goal state then return success and stop,
else make current state as initial state.
○ Step 2: Loop until a solution is found or the current state does not change.
a. Let SUCC be a state such that any successor of the current state will be
better than it.
e. If the SUCC is better than the current state, then set current state to
SUCC.
○ Step 5: Exit.
Stochastic hill climbing does not examine for all its neighbor before moving. Rather, this
search algorithm selects one neighbor node at random and decides whether to choose
it as a current state or examine another state.
2. Plateau: A plateau is the flat area of the search space in which all the neighbor
states of the current state contains the same value, because of this algorithm does not
find any best direction to move. A hill-climbing search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while
searching, to solve the problem. Randomly select a state which is far away from the
current state so it is possible that the algorithm could find non-plateau region.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is
higher than its surrounding areas, but itself has a slope, and cannot be reached in a
single move.
A hill-climbing algorithm which never makes a move towards a lower value guaranteed
to be incomplete because it can get stuck on a local maximum. And if algorithm applies
a random walk, by moving a successor, then it may complete but not efficient.
Simulated Annealing is an algorithm which yields both efficiency and completeness.
Problem Reduction:
Problem reduction is an algorithm design technique that takes a complex problem and
reduces it to a simpler one. The simpler problem is then solved and the solution of the
simpler problem is then transformed to the solution of the original problem.
Problem reduction is a powerful technique that can be used to simplify complex
problems and make them easier to solve. It can also be used to reduce the time and
space complexity of algorithms.
Approach 1:
To solve the problem one can iterate through the multiples of the bigger element (say X)
until that is also a multiple of the other element. This can be written as follows:
Select the bigger element (say X here).
Iterate through the multiples of X:
If this is also a multiple of Y, return this as the answer.
Otherwise, continue the traversal.
Algorithm:
Algorithm LCM(X, Y):
if Y > X:
swap X and Y
end if
for i = 1 to Y:
if X*i is divisible by Y
return X*i
end if
end for
Python Program
def LCM(x, y):
if y > x:
x, y = y, x
if (x*i) % y == 0:
return i*x
return x*y
print(LCM(10, 15))
Time Complexity: O(Y) as the loop can iterate for maximum Y times [because
X*Y is always divisible by Y]
Auxiliary Space: O(1)
AO* Algorithm:
Best-first search is what the AO* algorithm does. The AO* method divides any given
difficult problem into a smaller group of problems that are then resolved using the AND-
OR graph concept. AND OR graphs are specialized graphs that are used in problems
that can be divided into smaller problems. The AND side of the graph represents a set
of tasks that must be completed to achieve the main goal, while the OR side of the
graph represents different methods for accomplishing the same main goal.
In the above figure, the buying of a car may be broken down into smaller problems or
tasks that can be accomplished to achieve the main goal in the above figure, which is
an example of a simple AND-OR graph. The other task is to either steal a car that will
help us accomplish the main goal or use your own money to purchase a car that will
accomplish the main goal. The AND symbol is used to indicate the AND part of the
graphs, which refers to the need that all subproblems containing the AND to be resolved
before the preceding node or issue may be finished.
The start state and the target state are already known in the knowledge-based search
strategy known as the AO* algorithm, and the best path is identified by heuristics. The
informed search technique considerably reduces the algorithm’s time complexity. The
AO* algorithm is far more effective in searching AND-OR trees than the A* algorithm.
Working of AO* algorithm:
The evaluation function in AO* looks like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.
● They are both informed search and work on given heuristics values.
● A* always gives the optimal solution but AO* doesn’t guarantee to give the
optimal solution.
● Once AO* got a solution doesn’t explore all possible paths but A* explores all
paths.
● When compared to the A* algorithm, the AO* algorithm uses less memory.
Key concepts:
Benefits:
Examples:
Applications:
Inspiration:
Imagine a colony of ants searching for food. They explore randomly at first, leaving a
trail of pheromones along their paths. When an ant finds food, it returns to the nest,
reinforcing the pheromone trail with its own scent. As more ants find the food source,
they follow the stronger pheromone trail, ultimately leading to the shortest and most
efficient path.
Algorithm:
In ACO, artificial ants mimic this behavior. They move through a virtual "world"
represented as a graph, with nodes representing cities or tasks and edges representing
connections between them. Each ant:
Applications:
● Traveling salesman problem: finding the shortest route to visit all cities once.
● Vehicle routing: optimizing delivery routes.
● Scheduling: assigning tasks to machines or people efficiently.
● Telecommunication network optimization: finding efficient routing paths for
data packets.
Advantages:
Disadvantages:
Genetic Algorithms
Genetic Algorithms (GAs) are powerful tools in the AI toolbox, particularly for
optimization problems. They work by mimicking the process of natural selection,
where "fitter" solutions survive and reproduce, leading to better solutions over
generations. Here's a deeper look:
How it works:
Applications in AI:
Strengths:
Weaknesses:
● Neural networks excel at learning complex patterns from data but may require
substantial training data and struggle with optimization problems.
● Reinforcement learning can find optimal solutions, but the learning process can
be slow and require interaction with the environment.
● GAs offer a unique balance between exploration and exploitation, making them
valuable for diverse AI applications.
Game Playing
Game Playing is an important domain of artificial intelligence. Games don’t require
much knowledge; the only knowledge we need to provide is the rules, legal moves and
the conditions of winning or losing the game. Both players try to win the game. So, both
of them try to make the best move possible at each turn. Searching techniques like
BFS(Breadth First Search) are not accurate for this as the branching factor is very high,
so searching will take a lot of time. So, we need another search procedures that
improve –
● Generate procedure so that only good moves are generated.
● Test procedure so that the best move can be explored first.
Game playing is a popular application of artificial intelligence that involves the
development of computer programs to play games, such as chess, checkers, or Go.
The goal of game playing in artificial intelligence is to develop algorithms that can learn
how to play games and make decisions that will lead to winning outcomes.
● One of the earliest examples of successful game playing AI is the chess program
Deep Blue, developed by IBM, which defeated the world champion Garry
Kasparov in 1997. Since then, AI has been applied to a wide range of games,
including two-player games, multiplayer games, and video games.
There are two main approaches to game playing in AI, rule-based systems and machine
learning-based systems.
1. Rule-based systems use a set of fixed rules to play the game.
2. Machine learning-based systems use algorithms to learn from experience
and make decisions based on that experience.
In recent years, machine learning-based systems have become increasingly popular, as
they are able to learn from experience and improve over time, making them well-suited
for complex games such as Go. For example, AlphaGo, developed by DeepMind, was
the first machine learning-based system to defeat a world champion in the game of Go.
Game playing in AI is an active area of research and has many practical applications,
including game development, education, and military training. By simulating game
playing scenarios, AI algorithms can be used to develop more effective decision-making
systems for real-world applications.
Mini-Max Algorithm in Artificial Intelligence
○ 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 the opponent is also playing optimally.
○ Mini-Max algorithm uses recursion to search through the game-tree.
○ The Min-Max algorithm is mostly used for game playing in AI. Such as Chess,
Checkers, tic-tac-toe, go, and various two-players games. This Algorithm
computes the minimax decision for the current state.
○ In this algorithm two players play the game, one is called MAX and other is called
MIN.
○ Both the players fight it as the opponent player gets the minimum benefit while
they get the maximum benefit.
○ Both Players of the game are opponent of each other, where MAX will select the
maximized value and MIN will select the minimized value.
○ The minimax algorithm performs a depth-first search algorithm for the exploration
of the complete game tree.
○ The minimax algorithm proceeds all the way down to the terminal node of the
tree, then backtrack the tree as the recursion.
Initial call:
Minimax(node, 3, true)
○ In this example, there are two players, one is called Maximizer and the other is
called Minimizer.
○ Maximizer will try to get the Maximum possible score, and Minimizer will try to get
the minimum possible score.
○ This algorithm applies DFS, so in this game-tree, we have to go all the way
through the leaves to reach the terminal nodes.
○ At the terminal node, the terminal values are given so we will compare those
values 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 2:
Now, first we find the utilities value for the Maximizer, its initial value is -, so we will compare each va
○ Time complexity- As it performs DFS for the game-tree, so the time complexity
of Min-Max algorithm is O(bm), where b is branching factor of the game-tree, and
m is the maximum depth of the tree.
Alpha-Beta Pruning
○ 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 for future expansion, so it is called alpha-
beta pruning. It is also called as Alpha-Beta Algorithm.
○ Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not
only prune the tree leaves but also entire sub-tree.
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 + .
○ 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 makes the algorithm fast.
○ While backtracking the tree, the node values will be passed to upper nodes
instead of values of alpha and beta.
○ We will only pass the alpha, beta values to the child nodes.
Let's take an example of two-player search tree to understand the working of Alpha-beta
pruning
Step 1:
At the first step the, Max player will start first move from node A where = - and = +, these value of alph
Step 2: At Node D, the value of α will be calculated as its turn for Max. The value of α is
compared with firstly 2 and then 3, and the max (2, 3) = 3 will be the value of α at node
D and node value will also 3.
Step 3:
Now algorithm backtrack to node B, where the value of will change as this is a turn of Min, Now = +, w
In the next step, algorithm traverse the next successor of Node B which is node E, and the values of = -, and = 3
Step 4:
At node E, Max will take its turn, and the value of alpha will change. The current value of alpha will be
Step 5:
At next step, algorithm again backtrack the tree, from node B to node A. At node A, the value of alpha
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.
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 w
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.
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.
○ Worst ordering: In some cases, alpha-beta pruning algorithm does not prune
any of the leaves of the tree, and works exactly as minimax algorithm. In this
case, it also consumes more time because of alpha-beta factors, such a move of
pruning is called worst ordering. In this case, the best move occurs on the right
side of the tree. The time complexity for such an order is O(bm).
○ Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of
pruning happens in the tree, and best moves occur at the left side of the tree. We
apply DFS hence it first search left of the tree and go deep twice as minimax
algorithm in the same amount of time. Complexity in ideal ordering is O(bm/2).
○ Order the nodes in the tree such that the best nodes are checked first.
○ Use domain knowledge while finding the best move. Ex: for Chess, try order:
captures first, then threats, then forward moves, backward moves.
○ We can bookkeep the states, as there is a possibility that states may repeat.
What is knowledge representation?
What to Represent:
○ Object: All the facts about objects in our world domain. E.g., Guitars contains
strings, trumpets are brass instruments.
Types of knowledge
1. Declarative Knowledge:
2. Procedural Knowledge
3. Meta-knowledge:
4. Heuristic knowledge:
5. Structural knowledge:
○ It describes relationships between various concepts such as kind of, part of, and
grouping of something.
○ It describes the relationship that exists between concepts or objects.
Knowledge of real-worlds plays a vital role in intelligence and same for creating artificial
intelligence. Knowledge plays an important role in demonstrating intelligent behavior in
AI agents. An agent is only able to accurately act on some input when he has some
knowledge or experience about that input.
Let's suppose if you met some person who is speaking in a language which you don't
know, then how you will able to act on that. The same thing applies to the intelligent
behavior of the agents.
As we can see in below diagram, there is one decision maker which act by sensing the
environment and using knowledge. But if the knowledge part will not present then, it
cannot display intelligent behavior.
AI knowledge cycle:
An Artificial intelligence system has the following components for displaying intelligent
behavior:
○ Perception
○ Learning
○ Planning
○ Execution
The above diagram is showing how an AI system can interact with the real world and
what components help it to show intelligence. AI system has Perception component by
which it retrieves information from its environment. It can be visual, audio or another
form of sensory input. The learning component is responsible for learning from data
captured by Perception comportment. In the complete cycle, the main components are
knowledge representation and Reasoning. These two components are involved in
showing the intelligence in machine-like humans. These two components are
independent with each other but also coupled together. The planning and execution
depend on analysis of Knowledge representation and reasoning.
There are mainly four approaches to knowledge representation, which are given below:
○ It is the simplest way of storing facts which uses the relational method, and each
fact about a set of the object is set out systematically in columns.
Player1 65 23
Player2 58 18
Player3 75 24
2. Inheritable knowledge:
○ In the inheritable knowledge approach, all data must be stored into a hierarchy of
classes.
○ Every individual frame can represent the collection of attributes and its value.
○ Example:
3. Inferential knowledge:
○ Inferential knowledge approach represents knowledge in the form of formal
logics.
○ It guaranteed correctness.
a. Marcus is a man
man(Marcus)
4. Procedural knowledge:
○ In this knowledge, we can use various coding languages such as LISP language
and Prolog language.
○ But it is not necessary that we can represent all cases in this approach.
1. 1. Representational Accuracy:
KR system should have the ability to represent all kind of required knowledge.
2. 2. Inferential Adequacy:
KR system should have ability to manipulate the representational structures to
produce new knowledge corresponding to existing structure.
3. 3. Inferential Efficiency:
The ability to direct the inferential knowledge mechanism into the most
productive directions by storing appropriate guides.
There are mainly four ways of knowledge representation which are given as follows:
1. Logical Representation
3. Frame Representation
4. Production Rules
1. Logical Representation
Logical representation is a language with some concrete rules which deals with
propositions and has no ambiguity in representation. Logical representation means
drawing a conclusion based on various conditions. This representation lays down some
important communication rules. It consists of precisely defined syntax and semantics
which supports the sound inference. Each sentence can be translated into logics using
syntax and semantics.
Syntax:
○ Syntaxes are the rules which decide how we can construct legal sentences in the
logic.
Semantics:
○ Semantics are the rules by which we can interpret the sentence in the logic.
a. Propositional Logics
b. Predicate logics
1. Logical representations have some restrictions and are challenging to work with.
2. Logical representation technique may not be very natural, and inference may not
be so efficient.
Example: Following are some statements which we need to represent in the form of
nodes and arcs.
Statements:
a. Jerry is a cat.
b. Jerry is a mammal
In the above diagram, we have represented the different type of knowledge in the form
of nodes and arcs. Each object is connected with another object by some relation.
2. Semantic networks try to model human-like memory (Which has 1015 neurons
and links) to store the information, but in practice, it is not possible to build such a
vast semantic network.
4. Semantic networks do not have any standard definition for the link names.
5. These networks are not intelligent and depend on the creator of the system.
3. Frame Representation
A frame is a record like structure which consists of a collection of attributes and its
values to describe an entity in the world. Frames are the AI data structure which divides
knowledge into substructures by representing stereotypes situations. It consists of a
collection of slots and slot values. These slots may be of any type and sizes. Slots have
names and values which are called facets.
Facets: The various aspects of a slot is known as Facets. Facets are features of
frames which enable us to put constraints on the frames. Example: IF-NEEDED facts
are called when data of any particular slot is needed. A frame may consist of any
number of slots, and a slot may include any number of facets and facets may have any
number of values. A frame is also known as slot-filter knowledge representation in
artificial intelligence.
Frames are derived from semantic networks and later evolved into our modern-day
classes and objects. A single frame is not much useful. Frames system consist of a
collection of frames which are connected. In the frame, knowledge about an object or
event can be stored together in the knowledge base. The frame is a type of technology
which is widely used in various applications including Natural language processing and
machine visions.
Example: 1
Slots Filters
Page 1152
Example 2:
Let's suppose we are taking an entity, Peter. Peter is an engineer as a profession, and
his age is 25, he lives in city London, and the country is England. So following is the
frame representation for this:
Slots Filter
Name Peter
Profession Doctor
Age 25
Weight 78
4. Production Rules
Production rules system consist of (condition, action) pairs which mean, "If condition
then action". It has mainly three parts:
○ Working Memory
○ The recognize-act-cycle
In production rules agent checks for the condition and if the condition exists then
production rule fires and corresponding action is carried out. The condition part of the
rule determines which rule may be applied to a problem. And the action part carries out
the associated problem-solving steps. This complete process is called a recognize-act
cycle.
The working memory contains the description of the current state of problems-solving
and rule can write knowledge to the working memory. This knowledge match and may
fire other rules.
If there is a new situation (state) generates, then multiple production rules will be fired
together, this is called conflict set. In this situation, the agent needs to select a rule from
these sets, and it is called a conflict resolution.
Example:
○ IF (at bus stop AND bus arrives) THEN action (get into the bus)
○ IF (on the bus AND paid AND empty seat) THEN action (sit down).
○ IF (bus arrives at destination) THEN action (get down from the bus).
2. The production rules are highly modular, so we can easily remove, add or modify
an individual rule.
1. Production rule system does not exhibit any learning capabilities, as it does not
store the result of the problem for the future uses.
2. During the execution of the program, many rules may be active hence rule-based
production systems are inefficient.
Propositional logic in Artificial intelligence
Propositional logic (PL) is the simplest form of logic where all the statements are made
by propositions. A proposition is a declarative statement which is either true or false. It
is a technique of knowledge representation in logical and mathematical form.
Example:
1. a) It is Sunday.
2. b) The Sun rises from West (False proposition)
3. c) 3+3= 7(False proposition)
4. d) 5 is a prime number.
The syntax of propositional logic defines the allowable sentences for the knowledge
representation. There are two types of Propositions:
a. Atomic Propositions
b. Compound propositions
○ Atomic Proposition: Atomic propositions are the simple propositions. It consists
of a single proposition symbol. These are the sentences which must be either
true or false.
Example:
Example:
Logical Connectives:
In propositional logic, we need to know the truth values of propositions in all possible
scenarios. We can combine all the possible combination with logical connectives, and
the representation of these combinations in a tabular format is called Truth table.
Following are the truth table for all logical connectives:
Truth table with three propositions:
We can build a proposition composing three propositions P, Q, and R. This truth table is
made-up of 8n Tuples as we have taken three proposition symbols.
Precedence of connectives:
Just like arithmetic operators, there is a precedence order for propositional connectors
or logical operators. This order should be followed while evaluating a propositional
problem. Following is the list of the precedence order for operators:
Precedence Operators
Logical equivalence:
Logical equivalence is one of the features of propositional logic. Two propositions are
said to be logically equivalent if and only if the columns in the truth table are identical to
each other.
Let's take two propositions A and B, so for logical equivalence, we can write it as AB. In below truth table we ca
Properties of Operators:
○ Commutativity:
○ P Q= Q P, or
○P Q = Q P.
○ Associativity:
○ (P Q) R= P (Q R),
○ (P Q) R= P (Q R)
○ Identity element:
○ P True = P,
○ P True= True.
○ Distributive:
○ P (Q R) = (P Q) (P R).
○
P (Q R) = (P Q) (P R).
○ DE Morgan's Law:
○ ¬ (P Q) = (¬P) (¬Q)
○¬ (P Q) = (¬ P) (¬Q).
○ Double-negation elimination:
○ ¬ (¬P) = P.
○ We cannot represent relations like ALL, some, or none with propositional logic.
Example:
a. All the girls are intelligent.
b. Some apples are sweet.
○ Propositional logic has limited expressive power.
○ In propositional logic, we cannot describe statements in terms of their properties
or logical relationships.
Predicate Logic
Predicate Logic deals with predicates, which are propositions, consist of variables.
Quantifier:
The variable of predicates is quantified by quantifiers. There are two types of quantifier
in predicate logic - Existential Quantifier and Universal Quantifier.
Existential Quantifier:
If p(x) is a proposition over the universe U. Then it is denoted as x p(x) and read as "There exists at least one val
There are several ways to write a proposition, with an existential quantifier, i.e.,
(xA)p(x) or xA such that p (x) or (x)p(x) or p(x) is true for some x A.
Universal Quantifier:
If p(x) is a proposition over the universe U. Then it is denoted as x,p(x) and read as "For every xU,p(x) is true."
The two rules for negation of quantified proposition are as follows. These are also called
DeMorgan's Law.
Sol:
~.x p(x) y q(y))
2. (xU) (x+6=25)
Sol:
~( xU) (x+6=25)
3. ~( x p(x) y q(y)
Sol:
~( x p(x) y q(y))
The proposition which contains both universal and existential quantifiers, the order of those quantifiers can't be e
Example: Write the negation for each of the following. Determine whether the resulting
statement is true or false. Assume U = R.
2
1. x m(x <m)
2 2 2
Sol: Negation of x m(x <m) is x m (x m). The meaning of x m (x
2m) is that there exists for some x such that x
2m, for every m. The statement is true as there is some greater x such that x
m, for every m.
2
2. m x(x <m)
2
Sol: Negation of m x (x <m) is mx (x 2 m). The meaning of mx (x 2
2m) is that for every m, there exists for some x such that x
2m. The statement is true as for every m, there exists for some greater x such that x
m.
Addressing these knowledge representation issues is critical for advancing the field of
AI. By developing more expressive, efficient, and comprehensive knowledge
representation techniques, we can pave the way for the creation of truly intelligent and
versatile AI systems capable of reasoning, learning, and interacting with the world in a
more human-like manner.
A set of facts
These facts are assertions or anything that is relevant to the beginning state
of the system.
Set of Rules
This set contains all the actions that should be performed within the scope of
a problem and defines how to act on the assertion set. In the set of rules facts
are represented in an IF-THEN form.
work?
Rule-based systems in AI outlines triggers & the actions that should follow (or
are triggered). For example, a trigger might be an email containing the word
“invoice”. An action might then be to forward the email to the finance team.
These rules most often take the form of "if" statements. "IF" outlines the
trigger, "THEN" specifies the action to complete. So, if you want to create a
rule-based system capable of handling 100 different actions, you’d have to
write 100 different rules. If you want to then update the system and add
actions, then you would need to write new rules.
In short, you use rules to tell a machine what to do, and the machine will do
exactly as you tell it. From there, rule-based systems will execute the actions
until you tell it to stop.
But remember: if you tell it to do something incorrectly, it will do it incorrectly.
The database
In a rule based based approach the database has a set of facts that are used
to compare against the IF (condition) part of the rules that are held in the
knowledge base.
Explanation facilities
The explanation facilities make it possible for the user to ask the expert
system how a specific conclusion was reached and why a specific fact is
required. The expert system needs to be able to explain its reasoning and
justify its advice, analysis, or conclusion.
User interface
In a rule based approach the user interface is the means through which the
user seeking a solution to a problem communicates with the expert system.
The communication should be as meaningful and friendly as possible and the
user interface should be as intuitive as possible.
These five elements are critical for any rule-based system. They are the core
components of the rule-based system. But the system might have some
additional components as well. A couple of these components could be the
external interface and the working memory.
External interface
The external interface enables an expert system to work with external data
files and programs that are written in conventional programming languages
like C, Pascal, FORTRAN and Basic.
Working memory
The working memory stores temporary information and data.