Unit-1 Merged
Unit-1 Merged
Unit-1 Merged
INTRODUCTION
What Is AI? A Branch Of Computer Science That Uses Computational Models To Perform
Tasks That Previously Required Human Intelligence.
(Or)
AI Is The Study Of Making Computers Do Things That At The Moment People Do Better.
History Of AI
1950-1956 - Alan Turning published his work “Computer Machinery and Intelligence”
which eventually became the turning test, which experts used to measure computer
intelligence
1955 - John Mc Carthy Coined The AI Term and is also known as the father of AI
1958 - John Mccarthy Created LISP
1980 - John Searle AI Term Minda, Brains And Programs
1994 - Raj Reddy. The first winner to get a turning award and also known as the father
of Indian AI
1943 - Warren Mcculloch And Western Pitts Created A Model Of Artificial Neurons
1951 - Marvin Minsky And Dear Edmonds Built The First Neural Computer Which
Is Called SNARC
Prolog - Programming In Logic
LISP→LIST Processing
Prolog Is Used In Creating Artificial Intelligence It Relies On The User To Specify The
Rules And Facts About A Situation Along With The End Goal Otherwise Known As A
Query.
1958 - LISP Programming Language – John Mc Carthy
→ Advice Taker Program
→ Published Is A Program With Common Sense
1961 - Allen Newell And Herbert
↳ GPS (General Problem Solves)
↳ Imitate Human Problem-Solving Protocols
1963 - Mccarthy Used J. A. Robinson's
↳ Discovery Of Resolution Method.
↳ Re Construct The " Advice Taker " Programs
1
Introduction To Artificial Intelligence CAI
Intelligent Systems:
To design intelligent systems, it is important to categorize them into four categories (Luger and
Stubberfield 1993), (Russell and Norvig, 2003)
1. Systems that think like humans
2. Systems that think rationally
3. Systems that behave like humans
4. Systems that behave rationally
1. Systems that think like humans - Acting humanly: The Turing Test approach
The Turing Test, proposed by Alan Turing (1950), was designed to provide a satisfactory
operational definition of intelligence.
The computer would need to possess the following capabilities:
Natural language processing to enable it to communicate successfully in English;
Automated reasoning to use the stored information to answer questions and draw new
conclusions;
Machine learning to adapt to new circumstances and to detect and extrapolate patterns.
2. Systems that think rationally - Thinking humanly: The cognitive modeling approach
If we are going to say that a given program thinks like a human, we must have some
way of determining how humans think.
2
Introduction To Artificial Intelligence CAI
There are three ways to do this: through introspection—trying to catch our own
thoughts as they go by; through psychological experiments—observing a person in
action; and through brain imaging—observing the brain in action.
Once we have a sufficiently precise theory of the mind, it becomes possible to express
the theory as a computer program.
A rational agent is one that acts so as to achieve the best outcome or, when there is
uncertainty, the best-expected outcome.
2) Mathematics
3) Economics
4) Neuroscience
5) Psychology
3
Introduction To Artificial Intelligence CAI
6) Computer engineering
7) Linguistics
1) Philosophy
The AI point of view is that philosophical theories are useful to include human-level
artificial systems and provide a basis for designing systems with beliefs, do reasoning,
and planning.
A key problem for both AI and philosophy is understanding common sense knowledge
and abilities.
2) Mathematics
Fundamental ideas of AI required a level of mathematical formalization in three areas:
logic, computation, and probability.
AI systems use formal logical methods and Boolean logic, analysis of limits to what
can be computed, probability theory, uncertainty that forms the basis for most modern
approaches to AI, fuzzy logic, etc.,
It is about structure, developing principles that remain true even if you make any
alteration in the components.
3) Economy
In financial economics, there is a wide use of AI in making decisions about trading in
financial securities like stocks based on a prediction of their prices.
It can increase efficiency and improve the decision-making process by analyzing large
amounts of data.
AI deployment can increase overall productivity and create new products, leading to
job creation and economic growth.
4) Neuroscience
Neuroscience studies are characterized for recording high dimensional and complex
brain data, making the data analysis computationally expensive and time-consuming.
4
Introduction To Artificial Intelligence CAI
5) Psychology
Since psychology is the study of the human brain and its nature, and AI is the branch
that deals with the intelligence in machines, so for understand the intelligence of a
machine we must compare it with human intelligence.
7) Linguistics
AI aims at simulating human intelligence by computer. Language is one of the primary
expressions of human intelligence.
Natural Language Processing (NLP) is used to refer to all processes related to the
analysis of texts in natural language - imitation of a human language by a machine.
AI systems should be capable of decerning from data (or) experience and adapting their
behavior accordingly. this enables them to improve performance over time and handle new
situations More efficiency.
5
Introduction To Artificial Intelligence CAI
2. Complexity
AI problems often involve dealing with complex Systems (or) large amounts of Death. AI
systems must be able to handle this complexity efficiently to produce Meaningful results.
3. Uncertainty
AI systems frequently operate in an environment where outcomes are uncertain (or) incomplete
information is available. They must be equipped to make decisions (or) predictions under Such
Conditions.
4. Dynamism:
Environments in which AI Systems Operate Can Change Over time. these changes may occur
unpredictably (or) according to specific rules, requiring AI Systems, to Continually adjust thin
Strategies (or) Models.
5. Interactivity:-
Many AI applications Involve interaction with users(or) other agents. Effective AI Systems
should be able to perceive, interpret & respond to these Interactions in a Meaningful way.
6. Context-dependent:-
The Behaviour (or) performance of AI systems may depend on the Contest on which they
operate understanding and appropriately responding to different contexts is essential for
achieving desired outcomes.
7. Multi-disciplinary:-
AI problems often require knowledge and techniques from multiple disciplines, including
Computer Science, mathematics, statistics, psychology, and more. Integrating insights from
these diverse fields & is necessary for developing effective Al Solutions.
8. Goal-oriented Design:-
AI systems are typically designed to achieve specific objectives (or ) goals. Designing AI
systems with clear objectives in mind helps guide the development processes and ensure that
the. Systems are focused on achieving meaningful outcomes.
These characteristics Collective Collectively shape the Challenges and opportunities involved
in developing and deploying AI Systems across various domains and applications.
6
Introduction To Artificial Intelligence CAI
1) Human-Agent: A human agent has eyes, ears, and other organs that work for sensors, and
the hand, legs, and vocal tract work for actuators.
2) Robotic Agent: A robotic agent can have cameras, an infrared range finder, NLP for sensors,
and various motors for actuators.
3) Software Agent: Software agents can have keystrokes, file contents as sensory input act on
those inputs, and display output on the screen.
A sensor is a device that detects and responds to some type of input from the physical
environment. The output is generally a signal that is converted to a human-readable
display at the sensor location or transmitted electronically over a network for reading
or further processing.
The following are examples of sensors.
7
Introduction To Artificial Intelligence CAI
1) Temperature Sensor.
2) Proximity Sensor.
3) Accelerometer.
5) Pressure Sensor.
6) Light Sensor.
7) Ultrasonic Sensor.
8) Smoke sensor
9) Alcohol Sensor.
2) Stepper motors
3) Jackscrews
The agent function for an agent specifies the action taken by the agent in response to
any percept sequence.
A rational agent acts so as to maximize the expected value of the performance measure,
given the percept sequence it has seen so far.
There exists a variety of basic agent-program designs reflecting the kind of information
made explicit and used in the decision process.
The appropriate design of the agent program depends on the nature of the environment.
8
Introduction To Artificial Intelligence CAI
EXAMPLE:-
The Vacuum Cleaner Worlds-
This particular world has two locations Square A and Square B.
the vacuum agent perceives which Square it is in and whether there is dirt in the Square
It Can Choose to Move left, Move right, Suck up the dirt , or Do nothing.
A A B
The agent work:- if the Current Square is dirty, then Suck otherwise move to the Other Square.
Right
[A, Clean], [A, clean] [A, Clean]
Right
[A, Clean], [A, clean] [A, Clean]
9
Introduction To Artificial Intelligence CAI
It can also be described as a software entity that conducts operations in the place of
users or programs after sensing the environment.
In designing an agent, the first step must always be to specify the complete task
environment.
Rationality
Rationality depends on four things:
1) The performance measure that defines the criterion of success.
A rational agent not only to gather information but also to learn as much as possible
from what it perceives.
The agent’s initial configuration could reflect some prior knowledge of the
environment, but as the agent gains experience this may be modified and augmented.
10
Introduction To Artificial Intelligence CAI
After sufficient experience of its environment, the behavior of a rational agent can
become effectively independent of its prior knowledge.
Hence, the incorporation of learning allows one to design a single rational agent that
will succeed in a vast variety of environments.
We group all these under the heading of the task environment, called PEAS
(Performance, Environment, Actuators, Sensors).
In designing an agent, the first step must always be to specify the complete task
environment.
11
Introduction To Artificial Intelligence CAI
12
Introduction To Artificial Intelligence CAI
3) Goal-based agents
4) Utility-based agents
1. Simple reflex agents
The simplest kind of agent is the simple reflex agent. These agents select actions on the
basis of the current percept, ignoring the rest of the percept history.
It acts according to a rule whose condition matches the current state, as defined by the
percept. The following is the schematic diagram for a simple reflex agent.
13
Introduction To Artificial Intelligence CAI
The agent will work only if the correct decision can be made on the basis of only the
current percept—that is, only if the environment is fully observable.
The following is the schematic diagram for the Model-based reflex agent.
14
Introduction To Artificial Intelligence CAI
3. Goal-based agents
Goal-based agents expand the capabilities of the model-based agent by having the "goal"
information. They choose an action, so that they can achieve the goal.
These agents may have to consider a long sequence of possible actions before deciding whether
the goal is achieved or not.
15
Introduction To Artificial Intelligence CAI
PROBLEM-SOLVING AGENTS
Therefore, a problem-solving agent is a goal-driven agent and focuses on satisfying the goal.
16
Introduction To Artificial Intelligence CAI
PROBLEM DEFINITION
To build a system to solve a particular problem, we need to do four things:
(i) Define the problem precisely. This definition must include specification of the initial
situations and also final situations that constitute (i.e.) acceptable solutions to the problem.
(ii) Analyze the problem (i.e.) important features that have an immense (i.e.) huge impact on
the appropriateness of various techniques for solving the problems.
(iii) Isolate and represent the knowledge to solve the problem.
(iv) Choose the best problem–solving techniques and apply them to the particular
problem.
Note: Initial state, actions, and transition model together define the state-space of the
problem implicitly. The space of a problem is a set of all states which can be reached from the
initial state followed by any sequence of actions. The state space forms a directed map or graph
where nodes are the states, links between the nodes are actions, and the path is a sequence of
states connected by the sequence of actions.
Search: It identifies all the best possible sequences of actions to reach the goal state
from the current state. It takes a problem as an input and returns a solution as its output.
17
Introduction To Artificial Intelligence CAI
Solution: It finds the best algorithm out of various algorithms, which may be proven
as the best optimal solution.
Execution: It executes the best optimal solution from the searching algorithms to reach
the goal state from the current state.
Example Problems
There are two types of problem approaches:
Toy Problem: It is a concise and exact description of the problem that is used by the
researchers to compare the performance of algorithms.
Real-world Problem: It is real-world-based problems that require solutions. Unlike a
toy problem, it does not depend on descriptions, but we can have a general formulation
of the problem.
Some Toy Problems
8 Puzzle Problem: Here, we have a 3×3 matrix with movable tiles numbered from 1
to 8 with a blank space. The tile adjacent to the blank space can slide into that space.
The objective is to reach a specified goal state similar to the goal state, as shown in the
below figure.
In the figure, our task is to convert the current state into goal state by sliding digits into
the blank space.
In the above figure, our task is to convert the current(Start) state into the goal state by
sliding digits into the blank space.
18
Introduction To Artificial Intelligence CAI
Transition Model: It returns the resulting state as per the given state and actions.
Goal test: It identifies whether we have reached the correct goal state.
Path cost: The path cost is the number of steps in the path where the cost of each step
is 1.
Note: The 8-puzzle problem is a type of sliding-block problem that is used for testing
new search algorithms in artificial intelligence.
8-queens problem: This problem aims to place eight queens on a chessboard in an
order where no queen may attack another. A queen can attack other queens either
diagonally or in the same row and column.
From the following figure, we can understand the problem as well as its correct solution.
19
Introduction To Artificial Intelligence CAI
It is noticed from the above figure that each queen is set on the chessboard in a position where
no other queen is placed diagonally, in the same row or column. Therefore, it is the right
approach to the 8-queens problem.
For this problem, there are two main kinds of formulation:
1. Incremental formulation: It starts from an empty state where the operator augments a
queen at each step.
The following steps are involved in this formulation:
i. States: Arrangement of any 0 to 8 queens on the chessboard
ii. Initial State: An empty chessboard
iii. Actions: Add a queen to any empty box.
iv. Transition model: Returns the chessboard with the queen added in a box.
v. Goal test: Checks whether 8-queens are placed on the chessboard without any attack.
vi. Path cost: There is no need for path cost because only final states are counted.
vii. In this formulation, there is approximately a 1.8 x 1014 possible sequence to
investigate.
2. Complete-state formulation: It starts with all the 8-queens on the chessboard and moves
them around, saving from the attacks.
The following steps are involved in this formulation
States: Arrangement of all the 8 queens one per column with no queen attacking the
other queen.
Actions: Move the queen to the location where it is safe from the attacks.
This formulation is better than the incremental formulation as it reduces the state space
from 1.8 x 1014 to 2057, and it is easy to find the solutions.
20
Introduction To Artificial Intelligence CAI
21
Introduction To Artificial Intelligence CAI
22
Introduction To Artificial Intelligence CAI
23
Searching- Searching for solutions, uniformed search strategies – Breadth-first search, depth-
first Search. Search with partial information (Heuristic search) Hill climbing, A*, AO*
Algorithms, Problem reduction, Game Playing-Adversial search, Games, mini-max algorithm,
optimal decisions in multiplayer games, Problem in Game playing, Alpha-Beta pruning,
Evaluation functions.
Having formulated some problems, we now need to solve them. This is done by a search
through the state space.
search techniques that use an explicit search tree that is generated by the initial state
and the successor function that together define the state space.
In general, we may have a search graph rather than a search tree, when the same state
can be reached from multiple paths.
The root of the search tree is a search node corresponding to the initial state. The first
step is to test whether this is a goal state. his is done by expanding the current state.
that is, applying the successor function to the current state. thereby generating a new
set of states.
We continue choosing, testing, and expanding until either a solution is found or there
are no more states to be expanded. The choice of which state to expand is determined
by the search strategy.
state space:
Search Strategy:
It is important to distinguish between the state space and the search tree. For the route-
finding problem, there are only 20 states in the state space, one for each city. But there are an
infinite number of paths in this state space, so the search tree has an infinite number of nodes.
There are many ways to represent nodes, but we will assume that a node is a data
structure with five components:
STATE: the state in the state space to which the node corresponds;
PARENT-NODE: the node in the search tree that generated this node:
ACTION: the action that was applied to the parent to generate the node:
PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to the
node, as indicated by the parent pointers.
DEPTH: the number of steps along the path from the initial state.
the collection of nodes that have been generated but not yet expanded collection is
called the fringe. Each element of the fringe is a leaf node, that is, a node with no successors
in the tree.
function TREE-SEARCH(problem, strategy) returns a solution, or failure initialize the search tree
using the initial state of problem
Loop Do
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
Measuring Problem-Solving Performance
Depth-First Search A*
This uninformed search (also called blind search). The term means that they have no additional
information about states beyond that provided in the problem definition. All they can do is
generate successors and distinguish a goal state from a nongoal state. All search strategies are
distinguished by the order in which nodes are expanded.
Breadth-first search(BFS)
Breadth-first search is a simple strategy in which the root node is expanded first, then
all the
successors of the root node are expanded next, then their successors, and so on.
In general, all the nodes are expanded at a given depth in the search tree before any
nodes at the next level are expanded.
Breadth-first search can be implemented by calling TREE-SEARCH with an empty
fringe that is a first-in-first-out (FIFO) queue, assuring that the nodes that are visited
first will be expanded first. (left-right)
In other words, calling TREE-SEARCH(problem, FIFO-QUEUE()) re-
results in a breadth-first search The FIFO queue puts all newly generated
successors at the end of the queue.
which means that shallow nodes are expanded before deeper nodes.
We can easily see that it is complete if the shallowest goal node is at some finite depth
d. breadth-first search will eventually find it after expanding all shallower nodes
(provided the branching factor b is finite).
The shallowest goal node is not necessarily the optimal one; technically, breadth-first
search is optimal if the path cost is a non-decreasing function of the depth of the node.
(For example, when all actions have the same cost.)
So far, the news about the breadth-first search has been good. To see why it is not always
the strategy of choice, we have to consider the amount of time and memory it takes to
complete a search.
To do this, we consider a hypothetical state space where every state has b successors.
The root of the search tree generates b nodes at the first level, each of which generates
& more nodes, for a total of b² at the second level.
Each of these generates & more nodes, yielding b nodes at the third level, and so on.
Now suppose that the solution is at depth d.
d= depth of shallowest
Advantages:
Disadvantages:
It requires lots of memory since each level of the tree must be saved in memory to
expand to the next level.
BFS needs lots of time if the solution is far away from the root node.
Example:
In the below tree structure, we have shown the traversing of the tree using the BFS algorithm
from the root node S to goal node K. The BFS search algorithm traverses in layers, so it will
follow the path which is shown by the dotted arrow, and the traversed path will be:
1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Time Complexity: The time Complexity of the BFS algorithm can be obtained by the number
of nodes traversed in BFS until the shallowest Node. Where the d= depth of shallowest solution
and b is a node at every state.
Space Complexity: The space complexity of the BFS algorithm is given by the Memory size
of the frontier which is O(bd).
Completeness: BFS is complete, which means if the shallowest goal node is at some finite
depth, then BFS will find a solution.
Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of the node.
Depth-first Search
Note: Backtracking is an algorithm technique for finding all possible solutions using recursion.
Advantage:
o DFS requires very little memory as it only needs to store a stack of the nodes on the
path from the root node to the current node.
o It takes less time to reach the goal node than the BFS algorithm (if it traverses in the
right path).
Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee of
finding a solution.
o The DFS algorithm goes for deep-down searching and sometime it may go to the
infinite loop.
Example:
In the below search tree, we have shown the flow of the depth-first search, and it will follow
the order:
It will start searching from root node S, and traverse A, then B, then D, and E, after traversing
E, it will backtrack the tree as E has no other successor, and still the goal node is not found.
After backtracking it will traverse node C and then G, and here it will terminate as it found the
goal node.
Completeness: The DFS search algorithm is complete within finite state space as it will
expand every node within a limited search tree.
Time Complexity: The time complexity of DFS will be equivalent to the node traversed by
the algorithm. It is given by:
Where m= maximum depth of any node, and this can be much larger than d (Shallowest
solution depth)
Space Complexity: The DFS algorithm needs to store only a single path from the root node,
hence space complexity of DFS is equivalent to the size of the fringe set, which is O(bm).
Optimal: The DFS search algorithm is non-optimal, as it may generate a large number of steps
or high cost to reach the goal node.
The informed search algorithm is more useful for large search spaces.
Heuristic (enabling someone to discover) is a function used to find the most promising
path.
An informed search algorithm uses the idea of heuristics for searching. So it is also
called Heuristic search.
It takes the current state as the starting state and produces the estimation of how close
a state is, to the goal state.
The heuristic method, however, might not always give the best solution, but it
guarantees to find a good solution in a reasonable time.
The heuristic function 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.
Heuristic function is given as h(n) <= h*(n)
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should
be less than or equal to the estimated cost.
There are two algorithms in informed search.
o Hill climbing search Algorithm
o A* Search Algorithm
o AO* Search Algorithm
Hill-Climbing search
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.
At each step the current node is replaced by the best neighbor; in this version, that means the
neighbor with the highest VALUE, but if a heuristic cost estimate h is used, we would find the
neighbor with the lowest h.
Features of Hill climbing
Generate and test variants.
Greedy approach.
No backtracking.
function HILL-CLIMBING(problem) returns a state that is a local maximum
current ←MAKE-NODE(problem.INITIAL-STATE)
loop do
neighbor ←a highest-valued successor of current
if neighbor.VALUE ≤ current.VALUE then return current.STATE
current←neighbor
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.
3. Ridges:
A ridge is a special form of the local maximum. It has an area which is higher than its
surrounding areas, but it has a slope, and cannot be reached in a single move.
2. Simulated Annealing:
A* Search Algorithm
A* search is the most commonly known form of best-first search.
It uses heuristic function h(n), and cost to reach the node n from the start state
g(n).
It has combined features of UCS and greedy best-first search, by which it solves
the problem efficiently.
A* search algorithm finds the shortest path through the search space using the
heuristic function.
This search algorithm expands less search tree and provides optimal result
faster.
A* algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
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.
Algorithm of A*
search:
Step 1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stop.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation function
(g+h), if node n is the 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 the
evaluation function for n' and place it 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.
Step 6: Return to Step 2.
Advantages:
A* search algorithm is the best algorithm than other search algorithms.
A* search algorithm is optimal and complete.
This algorithm can solve very complex problems.
Disadvantages:
It does not always produce the shortest path as it mostly based on heuristics and
approximation.
A* search algorithm has some complexity issues.
The main drawback of A* is memory requirement as it keeps all generated
nodes in the memory, so it is not practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value
of all states is given in 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 the start state.
Here we will use the OPEN and CLOSED list.
Solution:
Iteration 4 will give the final result, as
Time Complexity: The time complexity of A* search algorithm depends on heuristic function,
and the number of nodes expanded is exponential to the depth of solution d. So the time
complexity is O(b^d), where b is the branching factor.
AO* algorithm
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 .
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 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.
Difference between the A* Algorithm and AO* algorithm
A* algorithm and AO* algorithm both works on the best first search.
They are both informed search and works on given heuristics values.
A* always gives the optimal solutionn 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.
opposite to the A* algorithm, the AO* algorithm cannot go into an endless
loop.
Example:
Here in the above example below the Node which is given is the heuristic value i.e h(n). Edge
length is considered as 1.
Step 1
=6
=8
So, by calculation, A⇢B path is chosen which is the minimum path, i.e f(A⇢B)
Step-2
AO* Algorithm (Step-2)
f(B⇢E) = 1 + 7
=8
f(B⇢f) = 1 + 9
= 10
So, by above calculation B⇢E path is chosen which is minimum path, i.e f(B⇢E)
because B's heuristic value is different from its actual value The heuristic is
updated and the minimum cost path is selected. The minimum value in our situation is 8.
Therefore, the heuristic for A must be updated due to the change in B's heuristic.
=1+8
=9
Step 3
f(C⇢G) = 1 + 3
=4
f(C⇢H+I) = g(h) + h(h) + g(i) + h(i)
=2
f(C⇢H+I) is selected as the path with the lowest cost and the heuristic is also left unchanged
because it matches the actual cost. Paths H & I are solved because the heuristic for those paths
is 0,
f(D⇢J) = 1 + 0
=1
=1+2+1+1
=5
as we can see path f(A⇢C+D) is solved and this tree has become a solved tree now.
In simple words, the main flow of this algorithm is that we have to find firstly level 1st heuristic
value and then level 2nd and after that update the values with going upward means towards
the root node.
Problem Reduction in AI
We already know about the divide and conquer strategy, a solution to a problem can
be obtained by decomposing it into smaller sub-problems.
Each of these sub-problems can then be solved to get its sub-solution.
These sub-solutions can then be recombined to get a solution as a whole. That is called
Problem Reduction.
This method generates arcs which are called AND arcs.
One AND arc may point to any number of successor nodes, all of which must be solved
for an arc to point to a solution.
2. Loop until the starting node is labeled SOLVED or until its cost goes above FUTILITY:
(i) Traverse the graph, starting at the initial node and following the current best path and
accumulate the set of nodes that are on that path and have not yet been expanded.
(ii) Pick one of these unexpanded nodes and expand it. If there are no successors, assign
FUTILITY as the value of this node. Otherwise, add its successors to the graph and for each of
EXAMPLE: 1
STEP 1:
STEP 2:
.
STEP 3:
STEP4:
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 –
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.
1. 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.
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.
Figure 1: Before backing-up of values
Figure 2: After backing-up of values We assume that PLAYER1 will start the game.
1. Advancement of AI: the creation of new algorithms and techniques that can be applied
to other areas of AI.
2. Education and training: Game playing can be used to teach AI techniques and
algorithms to students and professionals, as well as to provide training for military and
emergency response personnel.
3. Research: provides an opportunity to study and develop new techniques for decision-
making and problem-solving.
4. Real-world applications: The techniques and algorithms developed for game playing
can be applied to real-world applications, such as robotics, autonomous systems, and
decision support systems.
1. Limited scope: game playing may not be well-suited for other types of applications
and may need to be adapted or modified for different domains.
Adversarial search
Adversarial search is a fundamental concept in artificial intelligence, and its importance cannot
be overstated. It plays a pivotal role in two major domains:
1. Game-Playing
2. Decision-Making
Adversarial search is most relevant in competitive scenarios where multiple agents have
conflicting goals. In these scenarios:
Each agent strives to maximize their own utility or minimize their own loss.
The actions of one agent directly influence the outcomes and goals of other agents.
The agents may have incomplete information about each other's strategies, leading to
strategic uncertainty.
They are graphical structures that depict the possible moves and counter-moves of each player
in a sequential manner. In a game tree:
Edges emanating from a node represent possible moves that a player can make.
The tree branches out to represent various game states that result from different player
decisions.
By traversing and evaluating this tree, AI systems can systematically explore different game
scenarios, assess the consequences of different moves, and ultimately identify the optimal
strategy.
The working of the minimax algorithm can be easily described using an example.
Below we have taken an example of game-tree which represents the two-player
game.
In this example, there are two players one is called Maximizer and the other is called
Minimizer.
The maximizer will try to get the Maximum possible score, and the 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 value
and backtrack the tree until the initial state occurs. The following are the main steps
involved in solving the two-player game tree:
Step-1: Suppose the maximizer takes the first turn which has the worst-case initial value =-
infinity, and the minimizer will take the next turn which has the worst-case initial value =
+infinity.
Step 2: initial value of the Maximizer and determine the higher nodes values. It will find the
maximum among the all.
Step 3: In the next step, it's a turn for the minimizer, so it will compare all node values
Step 4: Now it's a turn for Maximizer, and it will again choose the maximum of all node's value
and find the maximum value for the root node
Complete- The Min-Max algorithm is Complete. It will find a solution (if exists),
in the finite search tree.
Optimal- The Min-Max algorithm is optimal if both opponents are playing
optimally.
Time complexity- As it performs DFS for the game tree, the time complexity of
the Min-Max algorithm is O(bm), where b is the branching factor of the game tree,
and m is the maximum depth of the tree.
Space Complexity- The space complexity of the Mini-max algorithm is also
similar to DFS which is O(bm).
Alpha-Beta Pruning
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 -∞.
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 +∞.
1. α>=β
Let's take an example of a two-player search tree to understand the workings of Alpha-beta
pruning
Step 1: At the first step the, Max player will start first move from node A where α= -∞ and β=
+∞, these values of alpha and beta are passed down to node B where again α= -∞ and β= +∞,
and Node B passes the same value to its child D.
Step 2:
Step 3:
Step 4:
Step 5:
Final output:
Rules to find good ordering:
The optimal solution becomes a contingent strategy when specifies MAX(the player
on our side)’s move in the initial state, then Max moves to the states resulting in
every possible response by MIN. Then MAX’s moves in the states result from every
possible response by MIN to those moves, and so on.
The minimax algorithm explores the game tree from top to bottom in-depth
first. The temporal complexity of the minimax method is O if the maximum
depth of the tree is m and there are b legal moves at each point (bm).
the space complexity is O(bm), while for an algorithm that generates actions
one at a time, the space complexity is O(m)
Evaluation Function
But in the real world when we are creating a program to play Tic-Tac-Toe,
Chess, Backgammon, etc
we need to implement a function that calculates the value of the board
depending on the placement of pieces on the board.
This function is often known as the Evaluation Function. It is sometimes
also called a Heuristic Function.
The evaluation function is unique for every type of game. In this post, the
evaluation function for the game Tic-Tac-Toe is discussed.
The basic idea behind the evaluation function is to give a high value for a
board if the maximizer turns or a low value for the board if the minimizer
turns.
For this scenario let us consider X as the maximizer and O as the minimizer.
Let us build our evaluation function:
function for the game Tic-Tac-Toe is discussed.
For this scenario let us consider X as the maximizer and O as the minimizer.
Let us build our evaluation function :
TimeComplexity: O(max(row,col))
Auxiliary Space: O(1)
UNIT - III
Types of Knowledge in AI
1. Declarative Knowledge:
Declarative knowledge is the ability to understand something.
It contains ideas, facts, and objects.
Declarative sentences are used to express descriptive knowledge, which is also known
as descriptive knowledge.
It is less complicated than procedural programming
Games are modeled as a Search problem and a heuristic evaluation function, which
are the two primary variables that aid in the modeling and solving of games in AI.
2. Procedural Knowledge:
It's sometimes referred to as "imperative knowledge."
Procedure knowledge is a form of knowledge that entails knowing how to do
something.
It can be used to complete any assignment.
It has rules, plans, procedures, and agendas, among other things.
The use of procedural knowledge is contingent on the job at hand.
3. Meta-knowledge:
Meta-knowledge is information about other sorts of knowledge.
4. Heuristic understanding:
Heuristic knowledge is the sum of the knowledge of a group of specialists in a certain
field or subject.
Heuristic knowledge refers to rules of thumb that are based on prior experiences, and
awareness of methodologies, and are likely to work but not guarantee
5. Structural knowledge:
Basic problem-solving knowledge is structural knowledge.
It describes the connections between distinct concepts such as kind, part of, and
grouping.
It is a term that describes the relationship between two or more concepts or objects.
AI knowledge cycle:
To show intelligent behavior, an artificial intelligence system must have the following
components:
Perception
Learning
Knowledge Representation and Reasoning
Planning
Execution
predicate logic
First-order logic (FOL), also known as predicate logic or first-order predicate calculus, is a
powerful framework used in various fields such as mathematics, philosophy, linguistics, and
computer science. In artificial intelligence (AI), FOL plays a crucial role in knowledge
representation, automated reasoning, and natural language processing.
The key components of FOL include constants, variables, predicates, functions, quantifiers,
and logical connectives.
1. Constants: Constants represent specific objects within the domain of discourse. For
example, in a given domain, Alice, 2, and NewYork could be constants.
2. Variables: Variables stand for unspecified objects in the domain. Commonly used
symbols for variables include x, y, and z.
3. Predicates: Predicates are functions that return true or false, representing properties
of objects or relationships between them. For example, Likes(Alice, Bob) indicates
that Alice likes Bob, and GreaterThan(x, 2) means that x is greater than 2.
4. Functions: Functions map objects to other objects. For instance, MotherOf(x) might
denote the mother of x.
5. Quantifiers: Quantifiers specify the scope of variables. The two main quantifiers are:
Universal Quantifier (∀): Indicates that a predicate applies to all elements in
the domain.
o For example, ∀x (Person(x) → Mortal(x)) means “All persons are
mortal.”
Existential Quantifier (∃): Indicates that there is at least one element in the
domain for which the predicate holds.
o For example, ∃x (Person(x) ∧ Likes(x, IceCream)) means “There
exists a person who likes ice cream.”
6. Logical Connectives:
– ako / subc (links two class frames, one of which is a subclass of the other e.g.,
science_faculty class is ako of faculty class),
– is_a / inst ( connects a particular instance of a class frame e.g., Renuka is_a
science_faculty)
– a_part_of (connects two class frames one of which is contained in another e.g., faculty
class is_part_of department class).
Property link of semantic net is replaced by SLOT fields.
● A frame may have any number of slots needed for describing the object. e.g.,
– faculty frame may have a name, age, address, qualification, etc as slot names.
● Each frame includes two basic elements: slots and facets.
– Each slot may contain one or more facets (called fillers) which may take many
forms such as
Inheritance in Frames
• Suppose we want to know the nationality or phone of an instance-frame frame13 of
Renuka.
• This information is not given in this frame.
• Search will start from frame13 in an upward direction till we get our answer or have
reached the root frame.
• The first argument is the frame's name and the second argument is a list of slot - facet
pairs.
Constraint propagation
Constraint propagation is a fundamental concept in constraint satisfaction problems
(CSPs). A CSP involves variables that must be assigned values from a given domain while
satisfying a set of constraints. Constraint propagation aims to simplify these problems by
reducing the domains of variables, thereby making the search for solutions more efficient.
Key Concepts
Variables: Elements that need to be assigned values.
Domains: Possible values that can be assigned to the variables.
Constraints: Rules that define permissible combinations of values for the variables.
Example
Consider a simple CSP with two variables, X and Y, each with domains {1, 2, 3}, and a
constraint X ≠ Y. Constraint propagation will iteratively reduce the domains as follows:
If X is assigned 1, then Y cannot be 1, so Y's domain becomes {2, 3}.
If Y is then assigned 2, X cannot be 2, so X's domain is reduced to {1, 3}.
This process continues until a stable state is reached.
Scheduling
In scheduling problems, tasks must be assigned to time slots without conflicts. Constraint
propagation helps by reducing the possible time slots for each task based on constraints like
availability and dependencies.
Planning
AI planning involves creating a sequence of actions to achieve a goal. Constraint
propagation simplifies the planning process by reducing the possible actions at each step,
ensuring that the resulting plan satisfies all constraints.
Resource Allocation
In resource allocation problems, resources must be assigned to tasks in a way that meets all
constraints, such as capacity limits and priority rules. Constraint propagation helps by
narrowing down the possible assignments, making the search for an optimal allocation
more efficient.
Review Of Probability
Probabilistic reasoning is a way of knowledge representation where we apply the concept of probability
to indicate the uncertainty in knowledge.
In probabilistic reasoning, we combine probability theory with logic to handle the uncertainty.
We use probability in probabilistic reasoning because it provides a way to handle the uncertainty.
In the real world, there are lots of scenarios, where the certainty of something is not confirmed, such
as "It will rain today," "behavior of someone for some situations," or "A match between two teams or
two players." These are probable sentences for which we can assume that it will happen but are not sure
about it, so here we use probabilistic reasoning.
Need for probabilistic reasoning in AI:
When there are unpredictable outcomes.
When specifications or possibilities of predicates become too large to handle.
When an unknown error occurs during an experiment.
In probabilistic reasoning, there are two ways to solve problems with uncertain knowledge:
1) Bayes' rule
2) Bayesian Statistics
Common terms used in probabilistic reasoning:
Probability: Probability can be defined as a chance that an uncertain event will occur. It is the
numerical measure of the likelihood that an event will occur. The value of probability always remains
between 0 and 1 that represent ideal uncertainties.
0 ≤ P(A) ≤ 1, where P(A) is the probability of an event A.
P(A) = 0, indicates total uncertainty in an event A.
P(A) =1, indicates total certainty in an event A.
How we can work out the likelihood of two events occurring together given
their base and conditional probabilities?
P(a | b) = P(a b)^/ P(b)......1
P(b | a) =P(a ^b)/ P(a)......2
P(a ^b) = P(a | b)P(b) =P(b | a)P(a).........3
So in our toy example 1:
P(toothache ^ cavity) = P(toothache | cavity)P(cavity)
= P(cavity | toothache)P(toothache)
Random variables: Variables in probability theory, their names begin with an uppercase letter.
E.g. Total; Die1.
By convention, propositions of the form A=true are abbreviated simply as a, while A = false
is abbreviated as ¬a.
Probability distribution: When we assume a predefined ordering on the domain of a random
variable
Eg. P(Wether = sunny) = 0.6, P(Wether = rain) = 0.1, P(Weather = cloudy) = 0.29, P(Weather
= snow) = 0.01. As an abbreviation: P(Weather) = . .
Probability density function (pdfs):
Joint probability distribution: It is the notation for the distribution of multiple variables. e.g.
P(Weather, Cavity
Full joint probability distribution: The joint distribution for all of the random variables
e.g. if the variables are Cavity, Toothache, and Weather, then the full joint distribution is given
by P(Cavity, Toothache, Weather).
Bayes' theorem:
Bayes' theorem is also known as Bayes' rule, Bayes' law, or Bayesian reasoning, which
determines the probability of an event with uncertain knowledge.
In probability theory, it relates the conditional probability and marginal probabilities of two
random events.
Bayes' theorem was named after the British mathematician Thomas Bayes. The Bayesian
inference is an application of Bayes' theorem, which is fundamental to Bayesian statistics.
It is a way to calculate the value of P(B|A) with the knowledge of P(A|B).
Bayes' theorem allows updating the probability prediction of an event by observing new
information of the real world.
Example: If cancer corresponds to one's age then by using Bayes' theorem, we can determine
the probability of cancer more accurately with the help of age.
Bayes' theorem can be derived using product rule and conditional probability of event A with
known event B:
As from product rule we can write:
1. P(A ⋀ B)= P(A|B) P(B) or
Similarly, the probability of event B with known event A:
1. P(A ⋀ B)= P(B|A) P(A)
Equating right-hand side of both equations, we will get:
The above equation (a) is called Bayes' rule or Bayes' theorem. This equation is the basis of
most modern AI systems for probabilistic inference.
It shows the simple relationship between joint and conditional probabilities. Here,
P(A|B) is known as posterior
P(B|A) is called the likelihood
P(A) is called the prior probability
P(B) is called marginal probability, pure probability of evidence.
In equation (a), in general, we can write P (B) = P(A)*P(B|Ai), hence the Bayes' rule can be
written as:
Where A1, A2, A3,........, An is a set of mutually exclusive and exhaustive events.
Example-1:
Question: what is the probability that a patient has diseases meningitis with a stiff neck?
Given Data:
A doctor is aware that disease meningitis causes a patient to have a stiff neck, and it occurs
80% of the time. He is also aware of some more facts, which are given as follows:
o The Known probability that a patient has meningitis disease is 1/30,000.
o The Known probability that a patient has a stiff neck is 2%.
Let a be the proposition that patient has stiff neck and b be the proposition that patient has
meningitis. , so we can calculate the following as:
P(a|b) = 0.8
P(b) = 1/30000
P(a)= .02
Hence, we can assume that 1 patient out of 750 patients has meningitis disease with a stiff neck.
•
LOGIC CONCEPTS: First-order logic, Inference In First-Order Logic, Propositional Vs.
First-order inference, Unification & Lifts Forward Chaining, Backward Chaining, Resolution,
Learning From Observation Inductive Learning, Decision Trees, Explanation Based Learning,
Statistical Learning Methods, and Reinforcement Learning.
Propositional
Feature Logic First-Order Logic
Limited to
Expressive, can represent
Expressiveness true/false
relationships and properties
statements
Combines
Syntax propositions using Uses predicates and quantifiers
logical connectives
Simple problems
Complex problems (e.g., AI
Use Cases (e.g., circuit design,
reasoning, ontology modeling)
rule-based systems)
Unification
Unification is finding a substitute that makes two separate logical atomic expressions
identical. The substitution process is necessary for unification.
It accepts two literals as input and uses substitution to make them identical.
Example: P(x, y), and P(a, f(z)).
P(x,y).........(i)
P(a,f(z)).........(ii)
Substitute x with a, and y with f(z) in the first expression, and it will be represented
as a/x and f(z)/y.
The first expression will be identical to the second with both replacements, and the
substitution set will be: [a/x, f(z)/y].
The following are some fundamental requirements for unification:
Atoms or expressions with various predicate symbols can never be united.
Both phrases must have the same number of arguments.
If two comparable variables appear in the same expression, unification will fail.
Algorithm: Unify(Ψ1, Ψ2)
Step. 1: If Ψ1 or Ψ2 is a variable or constant, then:
a) If Ψ1 or Ψ2 are identical, then return NIL.
b) Else if Ψ1 is a variable,
a. then if Ψ1 occurs in Ψ2, then return FAIL
b. Else return { (Ψ2/ Ψ1)}.
c) Else if Ψ2 is a variable,
a. If Ψ2 occurs in Ψ1 then return FAILURE,
b. Else return {( Ψ1 / Ψ2)}.
d) Else return FAILURE.
Step.2: If the initial Predicate symbol in Ψ1 and Ψ2 are not the same, then return FAILURE.
Step. 3: IF Ψ1 and Ψ2 have a different number of arguments, then return FAILURE.
Step. 4: Set Substitution set(SUBST) to NIL.
Step. 5: For i=1 to the number of elements in Ψ1.
a) Call the Unify function with the ith element of Ψ1 and ith element of Ψ2, and put the result
into S.
b) If S = failure then returns Failure
c) If S ≠ NIL then do,
a. Apply S to the remainder of both L1 and L2.
b. SUBST= APPEND(S, SUBST).
Step-2
Step-3
Backward Chaining:
Backward chaining is also known as a backward deduction or backward reasoning method
when using an inference engine. A backward chaining algorithm is a form of reasoning, which
starts with the goal and works backward, chaining through rules to find known facts that
support the goal.
Step-2:
Step-3:
Step-4:
Step-5:
Resolution
Resolution is a theorem-proving technique that proceeds proofs by contradictions.
Resolution is used if there are various statements are given, and we need to prove a conclusion
of those statements.
Unification is a key concept in proofs by resolutions.
Resolution is a single inference rule that can efficiently operate on the conjunctive normal
form or clausal form.
a proposition formula which is always false is called a Contradictions
sa proposition formula which is always true is called a tautology
Steps for Resolution:
1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF
3. Negate the statement that needs to be proved (proof by contradiction)
4. Draw a resolution graph (unification).
Example:
1. John likes all kinds of food.
2. Apples and vegetables are food
3. Anything anyone eats and is not killed is food.
4. Anil eats peanuts and is still alive
5. Harry eats everything that Anil eats.
Prove by resolution that:
6. John likes peanuts.
Step-1: Conversion of Facts into FOL
In the first step, we will convert all the given statements into their first-order logic.
So, to solve such problems there is a technique which is called as Attribute selection measure
or ASM.
By this measurement, we can easily select the best attribute for the nodes of the tree. There are
two popular techniques for ASM, which are:
1. Information Gain:
o Information gain is the measurement of changes in entropy after the segmentation of a
dataset based on an attribute.
o It calculates how much information a feature provides us about a class.
o A decision tree algorithm always tries to maximize the value of information gain, and
a node/attribute having the highest information gain is split first. It can be calculated
using the below formula:
o Information Gain= Entropy(S)- [(Weighted Avg) *Entropy(each feature) ]
(or)
Information Gain= Entropy(S)- [p(s/w=yes) *Entropy(s/w=yes)-p(s/w=no) *Entropy(s/w=no) ]
Note: it is applied for both weak and strong
2. Entropy: Entropy is a metric to measure the impurity in a given attribute. It specifies
randomness in data. Entropy can be calculated as:
What is learning?
AI learning processes focus on processing a collection of input-output pairs for a specific function and
predicting the outputs for new inputs.
To understand the different types of AI learning models, we can use two of the main elements of human
learning processes: knowledge and feedback.
From the knowledge perspective, learning models can be classified based on the representation of input and
output data points.
In terms of feedback, AI learning models can be classified based on the interactions with the outside
environment, users, and other external factors.
AI Learning Models: Knowledge-Based Classification
AI learning models can be classified into two main types: inductive and deductive.
Inductive Learning: This type of AI learning model is based on inferring a general rule from datasets of
input-output pairs.
Deductive Learning: This type of AI learning technique starts with a series of rules and infers new rules
that are more efficient in the context of a specific AI algorithm. Explanation-Based Learning(EBL) EBL
extracts general rules from examples by “generalizing” the explanation.
AI Learning Models: Feedback-Based Classification
Unsupervised Learning: Unsupervised models focus on learning a pattern in the input data without any
external feedback. Clustering is a classic example of an unsupervised learning models.
Supervised Learning: Supervised learning models use external feedback to learning functions that map
inputs to output observations. In those models, the external environment acts as a “teacher” of the AI
algorithms.
Semi-supervised Learning: Semi-supervised learning uses a set of curated, labeled data and tries to infer
new labels/attributes on new data sets. Semi-supervised learning models are a solid middle ground between
supervised and unsupervised models.
Reinforcement Learning: Reinforcement learning models use opposite dynamics such as rewards and
punishment to “reinforce” different types of knowledge. This type of learning technique is becoming really
popular in modern AI solutions.