IAI&a Module1 Notes
IAI&a Module1 Notes
MODULE 1
In 2004, John McCarthy defined artificial intelligence (AI) as the science and
engineering of making intelligent machines, especially intelligent computer
programs. However, much before this definition was coined, the birth of AI was
marked by Alan Turing’s seminal work, ‘Computing Machinery and Intelligence,’
published in 1950. Alan Turing, also known as the ‘father of computer science,’
CEC, MANGALORE
Introduction to AI and Applications
2
raised questions like ‘Can machines think?’ in this paper. Continuing with his work,
he later proposed the ‘Turing Test’, where a human interrogator would try to
distinguish between a computer and human text response.
Few languages that are popularly used to code AI applications are R, Python and
Java.
From a layman’s view, artificial intelligence (AI), simply means the intelligence
demonstrated by machines that help them to mimic the actions of humans. AI
simulates natural intelligence
in machines that are programmed to learn from experiences, adjust to new
inputs and perform human-like tasks.
NITI Aayog: The National Strategy for Artificial Intelligence has defined AI as
follows:
CEC, MANGALORE
Introduction to AI and Applications
3
AI systems work effectively when fed with a large amount of labelled training
data. This data is thoroughly analysed to discover correlations and patterns.
These patterns are then used to make predictions about future states. For
example, a chatbot fed with examples of text chats can learn to converse with
humans in real-world applications. AI programming focuses on three cognitive
skills: learning, reasoning and self-correction.
Learning Processes
AI programs focus on acquiring data and creating rules for turning that data into
actionable information. Rules, also known as algorithms, provide step-by-step
instructions to complete a specific task.
Reasoning Processes
Self-Correction Processes
AI allows business organizations to gain insights into their operations that they
CEC, MANGALORE
Introduction to AI and Applications
4
may not have been previously aware of. There are numerous tasks that AI-enabled
machines can perform better than humans. This has acted as the driving force for
exploring new business opportunities. It was because of AI that computer software
could be used to connect riders to taxis. Uber, one of the largest companies in the
world, is utilizing sophisticated machine learning algorithms to predict when
people would need a greater number of rides in a particular area so that the
company can get drivers on the road before they are needed.
Artificial intelligence, when used along with machine learning and deep learning
techniques, is quickly evolving to processes massive amounts of data much faster
and makes predictions more accurately than humanly possible. While huge
volumes of data are being generated every day, only AI applications can utilize this
data to quickly turn it into actionable information.
Google has become one of the largest players in AI. It provides a range of online
services by using machine learning to understand how people use their services
and then improving them.
Advantages
4. Can be used 24 X 7.
5. Optimizes tasks by better utilizing resources.
6. Automates complex processes.
7. Minimizes downtime by predicting maintenance needs.
8. Enables companies to produce new products having better quality and speed.
CEC, MANGALORE
Introduction to AI and Applications
5
Disadvantages
In 2017, Google’s CEO, Sundar Pichai, pronounced that Google would operate as an
‘AI first’ company.
Conclusion: Today, every big enterprise has used AI to improve its operations and
gain advantage on their competitors.
Let us analyse the support for the modern field of AI, right from 1943 to the present
day (Fig. 1.1).
CEC, MANGALORE
Introduction to AI and Applications
6
In 1943, Warren McCullough and Walter Pitts wrote a paper that proposed the first
mathematical model for building a neural network.
1950 was a significant year in the field of AI. A series of events took place this year
including the following:
CEC, MANGALORE
Introduction to AI and Applications
7
In 1956, John McCarthy coined the term ‘artificial intelligence’. The scope and
goals of AI were discussed in a conference later. It is from this point that we
consider the birth of artificial intelligence as we know it today.
In the same year, Allen Newell and Herbert Simon demonstrated the first
reasoning program.
In 1959, Allen Newell, Herbert Simon and J.C. Shaw developed the General
Problem Solver (GPS), a program designed to imitate human problem-solving.
In the same year, Arthur Samuel coined the term ‘machine learning’.
In 1969, the first successful expert systems to diagnose blood infections was
developed at Stanford.
In 1980, DEC developed the first successful commercial expert system, R1.
CEC, MANGALORE
Introduction to AI and Applications
8
1987–1993 marked the ‘Second AI Winter.’ In 1992, Japan terminated the FGCS
project owing to failure in meeting its ambitious goals. The US also ended the
project in 1993 after spending nearly $1 billion as the results were far from what
were expected.
In 1997, IBM’s Deep Blue machine could beat world chess champion, Gary
Kasparov.
In 2005, STANLEY, a self-driving car, won the DARPA Grand Challenge. Even the US
military started investing in autonomous robots like Boston Dynamics’ ‘Big Dog’
and iRobot’s ‘PackBot.’
In 2008, Google did a remarkable work in speech recognition and introduced the
feature in its iPhone app.
In 2011, Apple released Siri, an AI-powered virtual assistant that could be used
through its iOS operating system.
In 2012, Andrew Ng, founder of the Google Brain Deep Learning project, fed 10
million YouTube videos as a training set to a neural network and used deep
learning algorithms to enable the neural network to recognize a cat without being
told what a cat is.
In 2014, Google makes the first self-driving car that could pass a state driving test.
In the same year, Amazon released Alexa.
CEC, MANGALORE
Introduction to AI and Applications
9
In 2016 Google DeepMind’s AlphaGo defeated world champion Go player Lee Sedol.
Go is an ancient Chinese game and winning this game was a major breakthrough in
the field of AI.
In the same year, the first ‘robot citizen’, a humanoid robot, Sophia was created that
could perform facial recognition, verbal communication and facial expression.
In 2018, Google released NLP engine BERT that reduced barriers in translation and
understanding by machine learning applications. In the same year, Waymo One
service was launched that allowed users to request a pick-up from one of the
company’s self-driving vehicles.
In 2020, Baidu released its LinearFold AI algorithm to develop a vaccine during
the early stages of the SARS-CoV-2 pandemic.
The algorithm could predict the RNA sequence of the virus in just 27 seconds, 120
times faster than other methods.
Review Questions:
1.Define AI
2. How does AI work?
3.What are three cognitive skills?
L2:
We can classify an artificial intelligent system into one of the following categories
(Fig. 1.2).
CEC, MANGALORE
Introduction to AI and Applications
10
is specifically designed to perform a specific type of task. For example, Siri and Alexa
are weak AI systems. These systems are already trained with appropriate responses
to classify things accordingly. When you instruct Alexa to play a song, it responds by
playing that song.
1.3.2 Strong AI
Strong AI, also known as artificial general intelligence or artificial super intelligence
(ASI) or superintelligence, makes full attempt to resemble the human brain. It
utilizes cognitive skills and fuzzy logic to perform tasks for which it had not been
trained earlier. Such a system needs capability for visual perception, speech
recognition, decision-making and translations between languages.
CEC, MANGALORE
Introduction to AI and Applications
11
As of now, we see general AI only in sci-fi movies, where machines emulate human
intelligence and think strategically to perform complex tasks. However, it is
believed that soon, ASI will surpass the intelligence and ability of the human brain
as demonstrated by HAL, the superhuman, rogue computer assistant in 2001: A
Space Odyssey.
Many people fear that intelligent robots would overrun humanity, but experts says
that we need not worry about it as it is not likely to happen in the near future.
Moreover, artificial intelligence systems can also be categorized into four groups
based on their functionality. This categorization can be given as discussed in
Table 1.1.
TABLE 1.1 Weak AI vs Strong AI
Reactive machines are very basic machines with no memory to store and thus use
past experiences to determine future actions. They just perceive the world and
react to it. IBM’s Deep Blue, which defeated chess grandmaster Kasporov, is such an
example. The AI system sees the pieces on a chess board and responds without
referring to any of its prior experiences. Since it lacks capabilities to store past
experiences, a reactive machine cannot improve with practice. A strong AI program
must pass a Turing Test as well as the Chinese room test.
Reactive machines can perform only a limited number of specialized tasks. Such
machines are more trustworthy and reliable as they react the same way to the
CEC, MANGALORE
Introduction to AI and Applications
12
Deep Blue could only identify the pieces on a chess board and compute its next
move based on the rules of chess and the present positions. The AI application
could not pursue future potential moves by its opponent or plan its own pieces in
a better position. Every move was treated as its own reality, without any
connection with any other previous movement.
Limited memory machines retain data but only for a short period of time and can
use it only for a limited time. They cannot keep adding data permanently to a
library of their experiences. Such systems are usually used in autonomous vehicles
since they need not store data (like recent speed of nearby cars, distance between
cars, the speed limit, etc.) that can help them navigate roads.
AlphaGo also bested world-class competitors of the game, defeating champion Go
player Lee Sedol in 2016.
No doubt, limited memory AI is more complex and is used for better possibilities
than reactive machines. These machines continuously train a model to analyse and
utilize new data. The model also improves using feedback received from humans or
the environment and stored as data.
There are three major machine learning models that applies limited memory
artificial intelligence:
CEC, MANGALORE
Introduction to AI and Applications
13
the next item in a sequence. More recent information is given a higher priority
for prediction than past data. However, this does not mean that past data is not
considered while making predictions.
The theory of mind focuses on imitating the human brain. For this, it forms
representations about the world, starting from thoughts, emotions and memories.
However, such systems are only theoretical as of now but they may become
reality very soon.
These machines must understand thoughts and emotions that affect the
behaviour of one’s self. Theory of Mind machines make decisions keeping in
view the feelings experienced through self-reflection and determination.
1.3.6 Self-Awareness
Once Theory of Mind is established, then the next step would be incorporating self-
awareness in AI systems. Self-awareness in machines enable them to possess
human-level consciousness, understand the current state—its own existence in
the world and use that information to deduce others feelings. Self-AI systems will
be able to understand what others may need. They could interpret user’s feelings
by learning not only what they communicate to them but also how they
communicate it.
Knowledge imbibed by researchers and its learning of the conscious context will
help them to respond to an event. However, such systems do not yet exist but may
become available in the near future.
CEC, MANGALORE
Introduction to AI and Applications
14
Review Questions:
1.What is Weak AI
2. What is Strong AI
3.What is Theory of Mind ?
L3:
1.4 Is Artificial Intelligence Same as Augmented Intelligence and Cognitive
Computing?
Some experts think that artificial intelligence is the same as augmented intelligence.
But this is not true. Let us understand the difference between the two terms.
CEC, MANGALORE
Introduction to AI and Applications
15
implement complex tasks. As of now, though lot of work is being done in this
domain, AI remains within the realm of science fiction. Technologies like quantum
computing can play an important role in making AGI a reality.
Cognitive computing is a term that is especially coined for products and services
that mimic that augments human thought processes.
MACHINE LEARNING
Let us try to understand the term ‘machine learning’ with the help of some
real-world scenarios. Scenario 1: Imagine that you are given the task of
finding the missing number in the series-10,20,30,40, ?
Yes, you are correct. That’s 50. But how did you get the answer?
You quickly did some computations in your mind and observed the pattern in the
data values. The whole idea of machine learning is to imbibe the same thinking
process in machines.
Scenario 2: Before going for playing a cricket match, you always use your past
experiences to understand how a batsman/bowler plays. For example, if you know
a bowler gives a straight ball after every 2 left balls and 1 right ball, then you can
better use this information to prepare yourself for the next ball. In machine
learning, we make machines also to learn from past experience/data.
Scenario 3: When you buy a new mobile phone, you can yourself compute the
price of that phone vis-à-vis the configuration and brand. For example, you know a
phone with 128 GB RAM, stereo speakers, iOS 16, hexacore would cost around
80K. So, given the details, we can predict the price.
Similarly, a machine learning program is developed to predict values based on
CEC, MANGALORE
Introduction to AI and Applications
16
They automatically learn and improve by learning from their output. For this,
humans do not have to write instructions for them to produce the desired
output. They learn by analysing data sets and comparing the final output. In
case of any error, they repeat the learning process until the accuracy of the
outputs improve.
This automation not only saves human time and effort but also makes better
decisions.
Thus, machine learning is an application of artificial intelligence (refer Fig. 1.4) that
enables machines to automatically learn and improve from experiences without
being explicitly programmed.
CEC, MANGALORE
Introduction to AI and Applications
17
Machine learning and artificial intelligence are two different techniques where
machine learning is a tool for achieving artificial intelligence. The aim of AI is to
create intelligent machines that can recognize human speech, have vision to see,
assimilate knowledge, strategize and solve problems as humans do.
Machine learning provides machines the ability to learn, forecast and progress on
their own without specifically being programmed. ML system improves by learning
from more data and experiences.
Imagine you have been given the task of making a robot see, talk, walk, sense and
learn. Which technique will you use—ML or AI? Of course, AI. This is because to
achieve this task, multiple technologies come into picture (like NLP, computer
vision, voice recognition, reinforcement learning, etc). Machine learning is just one
of them that will be used only for learning purpose. Therefore, AI is the superset and
ML is the subset of AI. That is, ML is only a way to achieve AI (Fig. 1.6).
CEC, MANGALORE
Introduction to AI and Applications
18
CEC, MANGALORE
Introduction to AI and Applications
19
future outcomes.
The machine learning algorithm automatically formulates the rules from the
data. Unlike traditional programming, machine learning is an automated process
that adds the capability of embedded analytics in areas including natural
language interfaces, automatic outlier detection, recommendations, etc. All of
these features give better insights and reduce decision bias.
For example, if we give customer demographics and transactions as input and use
historical customer churn rates as output, then the algorithm will formulate a
program (also known as predictive model) that can predict if a customer will
churn or not.
Therefore, the steps to create a model to predict outcomes can be given as follows:
Step 1: Identify the business question you would like to ask. Step 2: Identify the
historical input.
Step 3: Identify the historically observed output (when the condition is true and
when it is false).
Machine learning language goes beyond traditional algorithmic solutions and
trains the machine to solve different complex tasks by itself. Unlike conventional
programming, machine learning uses a pre-written algorithm that learns how to
solve the problem itself. It is a more sophisticated way of solving a problem.
CEC, MANGALORE
Introduction to AI and Applications
20
CEC, MANGALORE
Introduction to AI and Applications
21
In simple words, machine learning techniques are used to feed data in to the
computer so that statistical techniques can be applied to it to help machines ‘learn’
how to solve tasks or which it had not been specifically programmed. These
computers free programmers from writing several lines of code. Machine learning
techniques can be further classified into supervised learning (using labelled data
sets) or unsupervised learning (using unlabelled data sets).
CEC, MANGALORE
Introduction to AI and Applications
22
Features of AI
Baidu, a search engine that works in the Chinese language, has a voice cloning
tool, which can clone human voice with just 3-4 seconds of audio, as opposed to
the previously taken 30 minutes
2. Predict and adapt: AI systems can understand data patterns to make
decisions and predictions.
3. An AI system continuously learns from patterns in data.
CEC, MANGALORE
Introduction to AI and Applications
23
Review Questions:
1.What is ML?
2. What is Deep learning?
3.How does AI work?
L4:
CEC, MANGALORE
Introduction to AI and Applications
24
the body to solve problems or manipulate objects. For example, this kind of
intelligence is mostly used by players and dancers.
Reasoning
It is the set of processes that is used in making decisions and prediction. There
are two types of reasoning—inductive and deductive. The differences between
these two techniques is given in Table 3.1.
TABLE 3.1 Inductive vs Deductive Reasoning
CEC, MANGALORE
Introduction to AI and Applications
25
Learning
CEC, MANGALORE
Introduction to AI and Applications
26
Problem Solving
It is the process in which one tries to find the desired solution in the present
situation by following the path which is blocked by known or unknown hurdles.
Problem solving uses decision-making to select the best suitable alternative to
reach the desired goal.
Perception
Linguistic Intelligence
CEC, MANGALORE
Introduction to AI and Applications
27
Review Questions:
1.What is Problem Solving?
2. What is learning?
3. Differencebetween Human and Machine ?
L5:
may contain other agents. This agent (refer Fig. 3.2) can be anything that is
capable of perceiving its environment. For this, it may have sensors. Agents
CEC, MANGALORE
Introduction to AI and Applications
28
also have effectors that help them to act upon their environment. The different
1. Human agent: A human agent has sensory organs (like eyes, ears, nose, tongue
and skin) that acts as sensors, and other organs such as hands, legs, mouth as
effectors for taking actions.
2. Robotic agent: A robotic agent uses cameras and infrared range finders as
sensors, and various motors and actuators as effectors.
3. Software agent: Such an agent uses bit strings as its programs and
actions.
3.4.1 KeyTerminology
Behaviour of Agent
Percept
Percept Sequence
This is a list of all percepts received by an agent till date.
Agent Function
3.4.2 Rationality
CEC, MANGALORE
Introduction to AI and Applications
29
The agent must perform all the actions to maximize its performance measure
with respect to the percept sequence and the knowledge base that it has.
Therefore, we can say that rationality of an agent depends on the following:
A rational agent (refer Fig. 3.3) always performs the right action in the given
percept sequence to maximize performance. Thus, a problem solved by an agent
is characterized by performance measure, environment, actuators, and sensors
(PEAS).
CEC, MANGALORE
Introduction to AI and Applications
30
Simple reflex agents choose actions based only on the current percept. They are
rational only if they make a correct decision based on the current precept. Their
environment is completely observable.
They work using condition-action rule that maps a state (condition) to an
action. If the condition is true, then the action is taken, else not. However, the
problem with a simple reflex agent is that they succeed only when the
environment is fully observable. If the environment is partially observable, then
the agent may get stuck in infinite loops. In such a situation, the agent can escape
the loop only if it can randomize its actions.
Other issues with such agents are given below.
Model reflex agents (refer Fig. 3.4) use a model of the world to choose their actions.
For this, they need to maintain an internal state. Here, model means knowledge
about ‘how things happen in the world’.
CEC, MANGALORE
Introduction to AI and Applications
31
Goal-Based Agents
Goal means a description of desirable situations. Goal-based agents (refer Fig. 3.5)
choose their actions to achieve goals. This provides more flexibility than reflex
agent as the knowledge supporting a decision is explicitly modeled and permits any
sort of modifications.
Utility-Based Agents
Many a time, goals are either conflicting or are difficult to achieve. In such
situations, utility-based agents (refer Fig. 3.6) can be used to achieve goals that
are more important than others. These agents choose actions based on a
CEC, MANGALORE
Introduction to AI and Applications
32
However, at times, achieving the desired goal is not enough and happiness of the
agent is also important. In such a scenario, utility describes how ‘happy’ the agent
is. A utility agent chooses the action that maximizes the expected utility, that is, the
associated degree of happiness.
Learning Agent
A learning agent (refer Fig. 3.7) learns from its past experiences. It is designed to
possess learning capabilities. Initially, it starts working with basic knowledge and
then acts and adapts automatically through learning.
CEC, MANGALORE
Introduction to AI and Applications
33
Critic (refer Fig. 3.8) is the element that provides feedback to the learning
element, describing how well the agent is doing with respect to a fixed
performance standard.
CEC, MANGALORE
Introduction to AI and Applications
34
For example, a softbot whose job is to scan customer preferences and display
them relevant items works in the real as well as an artificial environment.
CEC, MANGALORE
Introduction to AI and Applications
35
Turing Test
The aim of this test is to fool the tester. If the tester fails to determine whether
the reply is coming from a machine or a human, then the machine is said to be
intelligent.
As stated earlier, environment is the place where the agent would work. It gives
rewards and specifies states and actions of the agents. Although environment in an
AI system is quite vast, we can identify a small number of dimensions to
categorize them as given below.
Discrete/Continuous
While a discrete environment has a finite number of percepts and actions that
can be performed within it, a continuous environment has no such constraints.
CEC, MANGALORE
Introduction to AI and Applications
36
Known Vs Unknown
Observable/Partially Observable
If an agent can determine the complete state of the environment at each time
point from the percepts, then it is said to be observable; otherwise, it is only
partially observable. Correspondingly, in an unobservable environment, the agent
has no sensors. In a fully observable environment, the complete state of the
environment relevant to the choice of action of the agent can be captured using its
sensors.
While a fully observable environment (refer Fig. 3.9) does not require to
maintain the internal state to keep track history of the world, a not fully
observable environment, on the other hand, must maintain an internal state
to keep track of the world. An environment with sensors can be partially
observable because of noise, inaccuracy of the sensors, due to the framework
of the task itself or because parts of the state are missing from the sensor data.
For example, the classic chess game is fully observable as one agent can
perceive the positions and the moves of the other agent. But in the Kriegspiel
version of chess, the game environment is partially observable as only invalid
moves can be observed.
CEC, MANGALORE
Introduction to AI and Applications
37
Static/Dynamic
A static environment does not change when an agent is acting, but a dynamic
environment does. Agents in static environments, therefore, do not take into
account the state of the environment during the action and are thus easy to deal
with. However, in a dynamic environment, agents must consider the world while
performing each action. For example, self-driving cars work in a dynamic
environment, but games like crossword puzzles and chess operate in a static
one.
The environment may contain other agents which may or may not be of the same
kind of the agent. For example, vacuum cleaning environment is a single agent
but a chess game is a two-agent environment.
CEC, MANGALORE
Introduction to AI and Applications
38
competitive environment and two taxi-driving agents must avoid collisions and
work to maximize the performance of both the agents.
Thus, it operates in a cooperative environment.
Accessible/Inaccessible
For example, an empty room whose state can be defined by its temperature is an
example of an accessible environment, whereas information about an event on
the Earth is an inaccessible environment.
Deterministic/Non-deterministic
In a deterministic environment (refer Fig. 3.11), the next state of the environment
can be easily determined by the current state as well as the actions of the agent.
This is not true for a non- deterministic environment. A non-deterministic
environment description maximizes an agent’s performance for all possible
outcome of its actions. Note that in a deterministic, fully observable environment,
the agent does worry about uncertainty.
CEC, MANGALORE
Introduction to AI and Applications
39
For example, the game of ludo is non-deterministic as the dice will generate a
number randomly, creating uncertainty in the environment. On the contrary,
chess can be considered a deterministic environment to a certain extent as the
state of the game can be determined by estimating the other agent’s moves
although there can be uncertainty due to the other agent in the game. Most real-
life situations are so complex that it is not possible to track of all the unobserved
aspects. In such cases, we can consider them as deterministic.
Episodic/Non-episodic
Episodic environments are, therefore, simpler as the agent does not need to think
ahead. There are however, a series of one- shot actions, and only the current
percept is required for the action. On the other hand, in a sequential or non-
episodic environment, an agent requires memory to store past actions so that it can
determine the next best actions. Therefore, the current decision can affect all
future decisions.
CEC, MANGALORE
Introduction to AI and Applications
40
Review Questions:
1.What is Agent?
2. What are the types of Agent?
3. What are the type of Environment ?
L6:
We have read that artificial Intelligence is the study of building rational agents.
These agents make use of some or the other search algorithms in the background
to achieve their tasks. For example, some single-player games like tile games,
Sudoku, crossword, etc., use search algorithms to deduce a particular position in
the game.
1. State space is the set of all possible states that can be attained by an
agent.
2. Start state is the state from where the searching is done.
3. Goal test is a function that checks if the current state is the goal state or not.
CEC, MANGALORE
Introduction to AI and Applications
41
There are many search algorithms but, in this section, we will discuss six of the
most popularly used ones. For better understanding, we will categorize them under
two headings— informed and uninformed as shown in Fig. 3.13.
CEC, MANGALORE
Introduction to AI and Applications
42
In this section, we will read about depth first search, breadth first search and
uniform cost search algorithms. Each of these algorithms has the following
information.
Problem graph, the start node S to the goal node G.
Fringe, which is a data structure to store all the possible states (nodes) that can
be reached from the current state.
Path/Step cost are integers that represent the cost to move from one node to
another node.
In this search algorithm, the tree is traversed from the root node. The key will be
searched till the leaf node of a particular branch. If the key is not found, then the
search process backtracks to the point from where the other branch was left
CEC, MANGALORE
Introduction to AI and Applications
43
unexplored. This process is repeated for that other branch either until the key is
found or the entire tree is completely traversed.
In Fig. 3.14, we can clearly visualize the working of a DFS algorithm. Here,
searching starts from the root node A and then traverses nodes B, D and H. Now, H is
the leaf node, so we retrace the path to reach node B to traverse its unexplored
branch. Nodes E and I are thus traversed. Now, I is the leaf node, so again, the path is
retraced to follow the unexplored branch of node E. As a result, node J is visited and
then it is found that all nodes in branches of node B have been traced. So, the
algorithm will move further by exploring the other untraced branch of the root
node. Here, node C, followed by nodes F, K and G are explored.
From these observations, we can conclude that DFS algorithm occupies a lot of
memory space, and takes a lot of time to execute when the solution is at the
bottom or end of the tree. DFS is implemented using LIFO, that is, stack data
structure.
The time complexity of Depth-First Search (DFS) is O(V + E), where V is the number of
vertices and E is the number of edges, because it visits each vertex and edge at most once.
The space complexity of DFS is O(V) because it uses a stack (either the call stack for
recursive DFS or an explicit stack for iterative DFS) to keep track of the path, and in the
worst case, this stack can hold all the vertices in the graph
Though the DFS algorithm is complete if the search tree is finite and a solution
exists, it is not optimal as the number of steps in reaching the solution, or the cost
spent in reaching it is high.
CEC, MANGALORE
Introduction to AI and Applications
44
Advantages
1. It uses less memory as it stores only the nodes on the path from the root
node to the current node.
2. It takes less time to reach the goal node/state as compared to the BFS algorithm.
Disadvantages
Example: Explore the path that will be explored using the DFS algorithm to reach
node G from S.
DFS creates the same set of nodes as breadth-first method, different order.
CEC, MANGALORE
Introduction to AI and Applications
45
Solution: To explore the path, a search tree for the graph will be created. Since DFS
traverses the tree using the ‘deepest node first’ technique, it would always pick the
deeper branch until it reaches the solution or until all nodes of the current branch
have been traversed. The traversal is shown in blue arrows.
The DFS path can be given as, S -> A -> B -> C -> G
Example: Consider the graph given below and state its DFS traversal.
Solution: We start with node 0. Exploring its branch to node 1, we move to node 2
and node 4. From node 4, we backtrack to node 3. Hence, the DFS path can be given
as, 0 -> 1 -> 2 -> 4 -> 3.
DLS is similar to the DFS algorithm with an addition of a predetermined limit. This
limit helps to overcome the limitations of the infinite path in the DFS. In DLS, the
node at the depth limit will be treated as it is a leaf node (or a node with no
successor nodes).
CEC, MANGALORE
Introduction to AI and Applications
46
1. First, if the problem does not have any solution. This is known as
standard error failure.
2. Second, if the problem does not have any solution within a given depth limit.
This is known as cut-off failure.
3. Third, when the solution is found.
For example, in the tree given in Fig. 3.15, if level is limited to 2, then the search
technique will not go to level 3. Therefore,
nodes E, F, G and H will not be traversed.
Thus, the DLS search algorithm is complete if the solution is present within the
specified depth limit. While time complexity of DLS algorithm is O(bℓ), space
complexity is O(b×ℓ), where l is the depth limit and d is the depth of the tree.
Advantages
CEC, MANGALORE
Introduction to AI and Applications
47
2. If multiple solutions of a problem exist, then DLS may not be able to find the
optimal solution. In other words, the algorithm is not optimal even if ℓ>d.
Example: Traverse the given tree to search node H using DLS with predefined
limit as 2.
The search process then continues to explore nodes B, C, D, and E bat level 1.
Now, we go to level 2 and explore the child nodes of node B. When H is not found
there, a backtrack is done to level 1.
Child nodes of node C are searched to find node H. Finally, node H is found at level 2
as a child node of C and the algorithm terminates.
Example: Traverse the given tree to search node H using DLS with predefined
limit as 2.
Solution: In the tree, node H is not present till level 2, so the algorithm terminates
returning a cutoff failure. The path traversed for searching is marked with a
dashed line.
CEC, MANGALORE
Introduction to AI and Applications
48
This image explains the DLS implementation and could be referred to for better
understanding.
In this algorithm, nodes in the tree are traversed breadthwise to reach the goal
node. Searching begins from the root node and expands the successor node
breadthwise before traversing depth-wise.
As evident from Fig. 3.16, a BFS algorithm starts from the root node A and then
traverses node B followed by node C. This means that children of the root node
are traversed before exploring other nodes on any branch. After traversing all
nodes at a particular level, control then passes to the next level.
Therefore, after node C, all nodes from D to G are traversed. This is followed by
traversal of nodes H to K. Thus, the BFS algorithm explores all neighbour nodes at
the present depth before moving the nodes at the next depth level.
CEC, MANGALORE
Introduction to AI and Applications
49
In Fig. 3.17, BFS algorithm selects a random initial node (also known as source
node or root node) and traverses the graph layer-wise in such a way that all the
nodes and their respective children nodes are visited and explored. Here,
Exploring a node means exploring the adjacent nodes (child nodes) of the
selected node.
Advantages
4. It constructs the shortest path of traversing through the nodes of the graph
so that the graph can be traversed in the smallest number of iterations.
5. The algorithm does not get stuck in an infinite loop.
Disadvantages
1. Since each level of node is saved for creating the next one, it consumes a lot of
memory space. Space requirement to store nodes is exponential.
2. It takes less time if the solution is far away from the root node—at the
CEC, MANGALORE
Introduction to AI and Applications
50
While time complexity is equivalent to the number of nodes traversed in BFS space
complexity, on the other hand, it is equivalent to how large can the fringe get. Due
Solution: The BFS creates a tree and traverses it using the principle
‘shallowest node first’. So, at note S, node D will be traversed followed by node G. Thus,
Path is S -> D -> G
CEC, MANGALORE
Introduction to AI and Applications
51
In a BFS algorithm, nodes in the path = the depth of the shallowest solution = number of
nodes in level .
Example: Consider the graph. Using node A as the source node, traverse the graph and
trace the working of the algorithm using a queue.
Step 2: Remove node ‘a’ from the queue, print it and insert the child nodes of ‘a’ in
the queue. Thus, nodes ‘b’ and ‘c’ are inserted.
Step 3: The queue is not empty and has node ‘b’ and ‘c’. Since ‘b’ is the first node in
the queue, remove it, print it and insert the child nodes of ‘b’ into the queue. That is,
insert node ‘d’ and ‘e’.
Repeat these steps until the queue gets empty. Do not insert those nodes in the
queue that are already visited.
Breadth-First Search Algorithm Pseudocode
CEC, MANGALORE
Introduction to AI and Applications
52
According to the pseudocode, s is the root node of the graph, G. initially, s is inserted
in the queue. Then, all child nodes of ‘s’ are marked. These child nodes are visited
after removing ‘s’ from the queue. At each step of the algorithm, child nodes, w are
inserted into the queue to further visit its child nodes. The process is repeated
under the queue is empty.
BFS is a simple graph traversal method that is widely used in the following areas.
BFS algorithm is used for indexing web pages. In this application, each web page is
considered as a node in a graph.
The algorithm starts traversing from the source page and follows all the links
associated with that page.
For an unweighted graph, the shortest path can be easily calculated by choosing
a path with the least number of edges. BFS algorithm can do this by traversing a
CEC, MANGALORE
Introduction to AI and Applications
53
minimum number of nodes starting from the source node. Similarly, either
breadth- first search or depth-first traversal methods can be used to find a
spanning tree.
Broadcasting
Peer-to-Peer Networking
BFS is used in peer-to-peer network as a traversal method to find all the
neighbouring nodes. For example, BitTorrent uses BFS for peer-to- peer
communication.
Review Questions:
1.What is BFS?
2. What are the types of algorithms?
3. What is DFS ?
4. What is DLS ?
L7:
The UCS algorithm is used to find an optimal solution to the goal state when the
step costs are not the same. In such a scenario, the algorithm computes the
cumulative cost to expand each node from the root node to the goal node. It neither
traverses depth nor breadth, but searches for the next node with the lowest cost.
Sorting is done in increasing cost of the path to a node so that the algorithm can
explore paths in the increasing order of cost. UCS always expands the node with the
least cost.
It is identical to BFS if each transition has the same cost. Remember that,
CEC, MANGALORE
Introduction to AI and Applications
54
cost(root) = 0
In Fig. 3.18, if S is the start node and G is the goal state, then node A is explored as
it has the lowest cost (the other node G has a higher cost). Now, node A has two
child nodes—B and C. C having the lowest step cost is traversed and from there, node
D, followed by G is reached. Though UFS performs well for this algorithm, it may not
work with all cases.
Thus, we see that uniform-cost search (UCS) expands nodes based on their path
costs form the root node. It can be used to traverse any graph/tree where the
optimal cost is the traversal criteria. The uniform-cost search algorithm is
implemented by the priority queue, giving maximum priority to the lowest
cumulative cost. If you observe carefully, you will find that UCS is equivalent to BFS
algorithm if the path cost of all edges is the same.
The UCS algorithm is a complete and optimal algorithm with time and space
complexity and space complexity O(b(c/ε)), where ε is the lowest cost and c is the
optimal cost.
Advantages
1. It finds an optimal solution by considering the least cost at every state.
CEC, MANGALORE
Introduction to AI and Applications
55
2. UCS is complete only if states are finite and if there is no loop with zero weight.
3. UCS is optimal only if there is no negative cost.
Disadvantages
1. The algorithm may get stuck in an infinite loop as it considers only cost and not
the number of steps taken to reach the goal state.
2. It explores nodes in every ‘direction’.
3. It does not have any information about the location of the goal state.
4. It requires more space for storing information about nodes.
5. The UCS must explore all paths including the long ones.
Example: Consider the tree given below and its UCS traversal to reach node G from
S.
Example: Find the path and cost to move from node S to node G in the graph
given below.
Solution: For a better clarity, we can draw an equivalent search tree for the graph.
Using UCS, the path with the least cumulative cost is chosen.
CEC, MANGALORE
Introduction to AI and Applications
56
Cost: 5
The iterative deepening algorithm combines the features of DFS and BFS algorithms
to find out the best depth limit that can be used to implement the DLS algorithm.
IDDFS does so by gradually increasing the limit until the goal is found.
CEC, MANGALORE
Introduction to AI and Applications
57
Advantages
1. It combines the benefits of BFS and DFS search algorithms— fast search and
memory efficiency.
2. The algorithm is complete is if the branching factor is finite.
Disadvantages
Example: Traverse the given tree using the iterative deepening depth-first
search algorithm.
iteration, nodes B and C are traversed at level 1. In the third iteration, nodes D, E,
CEC, MANGALORE
Introduction to AI and Applications
58
The algorithm ends when it finds a solution at depth d. The number of nodes
created at depth d is bd and at depth d-1 is bd-1.
Time complexity of IDDFS algorithm is O(bd) and its space complexity is O(bd),
where b is the branching factor and depth of the tree is d.
In IDDFS, we perform DFS up to a certain ‘limited depth,’ and keep increasing this
‘limited depth’ after every iteration.
Example: Consider the tree given below and demonstrate the application of
IDDFS.
CEC, MANGALORE
Introduction to AI and Applications
59
The algorithm finds the smallest path from the source node to the goal node.
Thus, bidirectional search replaces single search graph with two smaller sub
graphs—one starting from initial or start node to the goal node (termed as forward
search) and the other starting from goal node towards the source node (known as
backward search).
Example: Consider the graph given below and apply bidirectional search on it to
reach goal node 14 from source node 0.
CEC, MANGALORE
Introduction to AI and Applications
60
Solution: Two searches are executed simultaneously-, one from node 0 and the
other from node 14. Both these searches intersect at node 7. At this point, we have
found a path from node 0 to 7 and from node 14 to 7. The search process
terminates successfully, thereby avoiding unnecessary exploration.
Advantages
Disadvantages
1. The algorithm can be used only when the goal state is clearly known.
2. It is difficult to implement.
CEC, MANGALORE
Introduction to AI and Applications
61
When both the starting node and the goal node are unique and completely
defined.
When the branching factor is exactly the same in both directions.
Example: Consider the graph given below and demonstrate the application of
bidirectional search from Start forward search from node 2 and backward
search from node 11.
In the forward search process, nodes 1, 6 and 8 are explored. In the backward
search process, mode 7 is explored. But no intersection node is encountered.
Next explore node 3 while doing a forward search and node 3 while doing a
backward search. Here, we find intersecting node as node 3, so the algorithm
terminates and the path is- 2 -> 1 -> 3-> 7 -> 11.
CEC, MANGALORE
Introduction to AI and Applications
62
The uninformed search algorithms that we have learnt so far had no knowledge
about search space. But informed search algorithm, as the name suggests,
contains some information about how far we are from the goal, cost of the path,
how to reach the goal, etc. This knowledge helps agents to explore less to the
search space and reach the goal node more efficiently.
The informed search algorithm which is extensively used in a large space is also
known as heuristic search as it uses a heuristic function. The heuristic function
takes the current state of the agent as its input and estimates how close the agent is
from the goal. Though the heuristic method may not always give the best solution,
it is, however, guaranteed to find a good solution in reasonable time.
A heuristic function h(n), calculates the cost of an optimal path between the pair of
states. The value of the heuristic function is always positive. We can write,
This means that the heuristic cost should be less than or equal to the
estimated cost.
Heuristic search is the simplest form of heuristic search algorithms that expands
nodes based on their heuristic value
h(n). The algorithm maintains two lists—OPEN and CLOSED. All nodes that have
already been expanded are placed in the CLOSED list, while others that have not
CEC, MANGALORE
Introduction to AI and Applications
63
On each iteration, nodes with the lowest heuristic value are expanded. Then, the
heuristic function is applied to the child nodes and they are placed in the open list
according to their heuristic value. The shorter paths are saved and the longer ones
are disposed. The process continues unit a goal state is found.
Step 3: From the OPEN list, remove the node having the lowest value of h(n), and
insert it in the CLOSED list.
Step 4: Expand the node (removed in Step 3) and generate its successors.
Step 5: Check each successor to find if it is the goal node or not. If any successor
node is found to be the goal node, then return success and terminate the search,
else go to Step 6.
CEC, MANGALORE
Introduction to AI and Applications
64
Step 6: Check if each successor node is in either OPEN or CLOSED list. If the node
is not present in any of the lists, then
add it to the OPEN list.
Step 7: Go to Step 2.
Advantages
Disadvantages
Example: Consider the tree given below and traverse it using greedy best-first
search algorithm.
Solution:
CEC, MANGALORE
Introduction to AI and Applications
65
Hence the final solution path will be: S----> B----->F---- > G
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.
The worst-case time complexity and space complexity of greedy best first search is
O(bm) where, m is the maximum depth of the search space. Although the
algorithm is complete, it can, at times, behave like an incomplete algorithm even
if the given state space is finite. This makes the Greedy best first search algorithm
not an optimal one.
Example: Apply greedy best first search algorithm on the graph given below to
reach node I from node S.
CEC, MANGALORE
Introduction to AI and Applications
66
Solution: Add node S in the CLOSED list and place its successors in the OPEN list.
Open [A, B, C], Closed [S]
Remove A from the OPEN list as it has minimum h(n), place it in CLOSED list and
put its successors in the OPEN list.
Remove C from the OPEN list as it has minimum h(n), place it in CLOSED list and put
its successors in the OPEN list.
Remove B from the OPEN list as it has minimum h(n), place it in CLOSED list and
put its successors in the OPEN list.
CEC, MANGALORE
Introduction to AI and Applications
67
uses heuristic function h(n), and g(n) which specifies the cost to reach the node n
from the start state (refer Fig. 3.19). It solves the searching problem efficiently by
expanding less search tree to find shortest path and give an optimal result faster.
That is, it avoids expanding paths that are already expensive, but expands most
promising paths first.
The A search algorithm, uses search heuristic as well as the cost to reach the
node. Sum of both the costs gives a number.
Review Questions:
1.What is Greedy search?
2. What are the types of informed search algorithms?
3. What is Bidirectional search?
CEC, MANGALORE
Introduction to AI and Applications
68
L8:
4.Knowledge Representation
4.1 Introduction
Although this all looks like a fantastic development, we agree that it is not easy to
make machines that behave exactly like humans. This is because humans have
conscience and this conscience develops gradually in us with our knowledge,
experiences and memories.
Knowledge of real world plays a crucial role in intelligence and creating AI agents
that demonstrate intelligent behaviour. Such an agent acts by sensing its
environment and using knowledge to act intelligently. However, for this, the
knowledge or experience about the input is mandatory. The relationship between
knowledge and intelligence can be clearly understood from Fig. 4.1. You can see that
if we remove the knowledge component, then the decision maker will not be able to
sense the environment accurately and take appropriate decisions.
CEC, MANGALORE
Introduction to AI and Applications
69
Humans are best at understanding, reasoning and interpreting things they know
(knowledge). Humans use their knowledge to perform various actions in the real
world. But how machines perform actions, comes under the domain of
Knowledge representation is not just storing data in a database. It goes beyond this
aspect to facilitate an intelligent machine to learn from that knowledge and
experiences so that it can behave intelligently like a human.
CEC, MANGALORE
Introduction to AI and Applications
70
1. Object: Information and facts about all objects (relevant in context). For
example, in a self-driving car, vehicles and roads are objects.
2. Events: Information and facts about actions which occur in the real world.
For example, in a self-driving car, an event can be applying breaks when an
object comes in front of it.
3. Performance: The manner in which actions are performed. It describes the
behaviour related to how to do things.
4. Meta-knowledge: It is the knowledge about knowledge (what we know).
5. Facts: Facts are the truths about the real world that needs to be represented
for an intelligent agent.
6. Knowledge base: It is the most important component of a knowledge-
based agent that stores a group of sentences (technical sentences, not
simple English language ones).
We know that knowledge is the basic element of our brain as it helps us to know
and understand the things logically and is gained by experiences of facts, data and
situations. A knowledgeable person performs all the actions in a better way.
Everyone has five types of knowledge illustrated in Fig. 4.2 and enumerated as
follows.
CEC, MANGALORE
Introduction to AI and Applications
71
CEC, MANGALORE
Introduction to AI and Applications
72
In AI, knowledge is represented using logic. Every logic has three main elements.
Syntax
Every language has its own syntax to specify the sequence of constructs that
makes a complete sentence in that language. It is therefore not wrong to say that
syntax is the representation of a language.
Semantics
Semantics is used to check if a syntactically correct sentence is logically correct
and meaningful or not. Therefore, semantics defines the sense of the sentence
which relates to the real world. For example, consider the statement:
Logical Inference
An AI system has several components (Fig. 4.3) that helps it to exhibit an intelligent
behaviour. These components include the following:
CEC, MANGALORE
Introduction to AI and Applications
73
Perception
The perception component retrieves data from the environment, discovers the
source(s) of noise, checks if the AI was damaged by anything and defines response
to be given when any sense has been detected. Data from the environment is
gathered using different types of sensors in the form of video, audio, text, time,
temperature or any other sensor-based input.
Learning
The learning component learns from the data that is captured by the perception
component. The aim here is to develop a system that can be taught instead of
being programmed. With learning, the system focuses on self-improvement
through
knowledge acquisition, inference, acquisition of heuristics, faster searches, etc.
CEC, MANGALORE
Introduction to AI and Applications
74
know to behave intelligently. The KRR component also defines how automated
reasoning procedures can make this knowledge available as needed.
CEC, MANGALORE
Introduction to AI and Applications
75
In AI, the agents that mimic a human being’s knowledge are known as knowledge-
based intelligent agents. Such an agent uses its knowledge and reasoning to act
efficiently by making appropriate decisions. A knowledge-based agent, therefore,
does the following:
CEC, MANGALORE
Introduction to AI and Applications
76
Figure 4.5 shows a generalized architecture for a knowledge- based agent (KBA).
According to Fig. 4.5,
Step 1: The KBA perceives the environment to take input from it.
Step 2: This input is taken by the inference engine of KBA.
Step 3: The inference engine interacts with the knowledge base to make decisions
based on the knowledge stored in it.
Note that the learning element of the KBA regularly updates the knowledge base
by learning new knowledge. This knowledge base is nothing but a collection of
sentences (technical information not same as a sentence in English) that are
expressed in a language known as knowledge representation language and
stores fact about the world.
CEC, MANGALORE
Introduction to AI and Applications
77
The inference system derives new sentences from old ones and also facilitates
addition of new sentence(s) to the knowledge base. As stated earlier, a sentence is
a proposition about the world. New information is deduced from the knowledge base
by applying logical rules (either forward chaining or backward chaining).
TELL operation tells the knowledge base what knowledge it already has about
its environment and what additional knowledge it needs to know. TELL is also
used to inform the knowledge base which action was selected and performed by
the agent.
ASK operation asks the knowledge base what action it should perform. The agent
gets its answer from the knowledge base.
Given below is the structure outline of a generic knowledge- based agent program
(Fig. 4.6).
CEC, MANGALORE
Introduction to AI and Applications
78
TELLS the KB what it perceives. For this, the MAKE-PERCEPT- SENTENCE function
is used to generate a sentence that informs about what information the agent had
perceived at the given time.
CEC, MANGALORE
Introduction to AI and Applications
79
TELLS the KB about the action that was chosen. The MAKE- ACTION-SENTENCE
function generates a sentence informing about the chosen action that was
executed.
Knowledge Level
This is the first level of a KBA. In this level, we need to specify what the agent
knows, and what its goals would be. This information is then used to fix the
behaviour of the agent. For example, if an agent has to go from point A to point B
and it knows the optimum way to reach the destination, then this information is
added at the knowledge level (using sentences).
Logical Level
Implementation Level
This is the physical representation of logic and knowledge. At this level, the agent
performs actions according to the knowledge obtained from the logical and
knowledge level. For example, the agent that wants to move from point A to B,
implement the knowledge and logic to reach the destination.
CEC, MANGALORE
Introduction to AI and Applications
80
Declarative Approach
In this approach, the knowledge-based agent is created by initializing it with an
empty knowledge base and then telling the agent all the sentences with which we
want to start with.
These sentences are told to the empty system one by one until the system becomes
knowledgeable enough to deal with the environment.
Procedural Approach
CEC, MANGALORE
Introduction to AI and Applications
81
In this technique, facts about a set of objects are systematically stored using
relations (or tables) in database systems (refer Fig. 4.8). These relations depict
relationship between different entities. However, the main shortcoming of this
approach is that there is little opportunity for inference.
CEC, MANGALORE
Introduction to AI and Applications
82
Inferential Knowledge
Inferential Knowledge Represents Knowledge in the Form of Formal Logic and Can
be Used to Derive More Facts Accurately. For example,
Student(Diya)
Review Questions:
1.What is knowledge representation?
2. What are the types of knowledge?
3. How to design a knowledge based Agent ?
CEC, MANGALORE