You are on page 1of 290

Artificial Intelligence (KCS-071)

4th year (Semester – VII)


Session – 2023 - 24
Unit – I

Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
What is AI ?

• Artificial Intelligence is concerned with the


design of intelligence in an artificial device.
• The term was coined by McCarthy in 1956.
• There are two ideas in the definition.
• 1. Intelligence
• 2. artificial device

Artificial Intelligence, KCS-071, Manoj


1/6/2024 2
Mishra
What is intelligence?

• Is it that which characterize humans? Or is there an


absolute standard of judgment?


• Accordingly there are two possibilities:

– –A system with intelligence is expected to behave as


intelligently as a human
– – A system with intelligence is expected to behave in the
best possible manner
• – Secondly what type of behavior are we talking about?
– – Are we looking at the thought process or reasoning ability
of the system?
– – Or are we only interested in the final manifestations of
the system in terms of its actions?

Artificial Intelligence, KCS-071, Manoj


1/6/2024 3
Mishra
What is AI?
• It is the study of how to make computers do
things which, at moment, people do better
• In other words, it is concerned with designing
intelligent computer systems that exhibit
intelligence associated with human beings

Artificial Intelligence, KCS-071, Manoj


1/6/2024 4
Mishra
Difference: Natural Vs Artificial
Intelligence
S.No. Natural Intelligence Artificial Intelligence

1 Natural Programmed by human beings

2 Increases with experience and Nothing called hereditary but systems


also hereditary do learn from experience

3 No one is an expert. A better Expert systems are made which have


solution can always be obtained the capability of many individual
from another human beings. person’s experience and ideas

4 Intelligence increases by AI capabilities can be increased by other


supervised or unsupervised means apart from supervised and
teaching unsupervised teaching

Artificial Intelligence, KCS-071, Manoj


1/6/2024 5
Mishra
Strong AI
• It makes the bold claim that computers can be
made to think on a level at least equal to
humans
• Strong AI research deals with creating AI that
can truly reason and solve problems
• It is believed that computers intelligence will
eventually exceed than that of human beings
• In strong AI, programs are themselves the
explanations
Artificial Intelligence, KCS-071, Manoj
1/6/2024 6
Mishra
Weak AI
• It simply states that some “thinking like”
features can be added to computers to make
them more useful tool
• Weak AI research deals with creating AI that
can reason and solve problems in a limited
domain
• Hence, such machines would act as if it was
intelligent but it would not possess true
intelligence

Artificial Intelligence, KCS-071, Manoj


1/6/2024 7
Mishra
Foundations of AI
• The following disciplines contributed ideas,
viewpoints and techniques to AI.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 8
Mishra
Philosophy (428 B.C. – present)
• Can formal rules be used to draw valid conclusions?
• How does the mental mind arise from a physical brain?
• Where does the knowledge come from?
• How does knowledge lead to action?

Philosophers made AI conceivable by considering the


ideas that the mind is in some ways like a machine.
It operates on knowledge encoded in some internal
language and that thought can be used to choose what
action is to be taken.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 9
Mishra
Mathematics (800 B.C.- present)
• What are the formal rules to draw valid conclusions?
• What can be computed?
• How do we reason with uncertain information?

Philosophers staked out most of the important ideas of AI, but


the leap to a formal science required a level of mathematical
formalization in three fundamental areas:
– Logic – propositional or Boolean logic.
– Computation – algorithm.
– Probability – helps to deal with uncertain measurements.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 10
Mishra
Mathematics (800 - present)
Mathematicians provided the tools to
manipulate statements of logical certainty as
well as uncertain, probabilistic statements.
They also set the groundwork for
understanding computation and reasoning
about algorithms.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 11
Mishra
Economics (1776 - present)
• How should we make decisions so as to
maximize payoff?
• How should we do this when others may not
go along?
• How should we do this when the payoff may
be far in the future?

Economists formalized the problem of making


decisions that maximize the expected
outcome to the decision-maker.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 12
Mishra
Neuroscience (1861 - present)
• How do brains process information?

Neuroscience is the study of the nervous


system, particularly the brain.
The exact way in which the brain enables
thought is one of the greatest mysteries of
science.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 13
Mishra
Psychology (1879 - present)
• How do humans and animals think and act?

Psychologists adopted the idea that humans


and animals can be considered information
processing machines.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 14
Mishra
Computer Engineering (1940 -
present)
• How can we build an efficient computer?

For artificial intelligence to succeed, two things are needed:


– Intelligence and
– Artifacts - manufactured article
The computer has been the artifact of choice.

Computer engineers provided the artifacts that make AI


applications possible. The great advances in speed and
memory of the computer have made AI programs to be run.
AI also owes a debt to the software side of computer science,
which has supplied the operating systems, programming
languages, and tools needed to write modern programs.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 15
Mishra
Control Theory (1948 - present)
• How can artifacts operate under their own control?
Control theory has made possible the designing of devices
that act optimally on the basis of feedback from the
environment.
Control theory and AI are two different fields of science.
Control theory used calculus and matrix algebra to solve
problems.
AI researchers used the tools of logical inference and
computation to consider some problems such as language,
vision, and planning, that fell completely outside the
control theorist’s purview.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 16
Mishra
Linguistics (1957 - present)
• How does language relate to thought?

Linguists showed that language use fits into


this model.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 17
Mishra
What is Turing Test?
• The Turing test, proposed by Alan Turing (1950),
was designed to provide a satisfactory
operational definition of intelligence.
• The test is designed to determine whether a
machine exhibits human-like intelligence or not.
• Turing Test doesn't necessarily mean that a
machine possesses full human-level intelligence
or consciousness; it only indicates that the
machine can simulate human-like conversation
effectively.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 18
Mishra
The Turing Test Approach
• The computer would need to possess the
following capabilities to pass the Turing test:
– Natural Language Processing: To understand the
natural language and communicate successfully in
English.
– Knowledge representation: To store what it knows
or hears.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 19
Mishra
The Turing Test Approach
– Automated reasoning: To use the stored
information to answer questions. It must be able
to reason out and draw new conclusions.
– Machine learning: To adapt to the new changes
and detect the patterns.
– Computer vision: To detect and perceive objects.
– Robotics: To manipulate objects and move about.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 20
Mishra
Applications of AI
• General Problem Solving:
– It involves solving of broad range of problems
which includes reasoning about physical objects
and their relationships to each other as well as
reasoning about actions and their consequences.
– Several specific problems such as water jug
problem, travelling salesman problem etc. can be
solved by AI machines.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 21
Mishra
Applications of AI
• Expert Systems:
– These are AI programs which act as intelligent advisor
or consultant in a specific domain or specified areas.
– Expert systems do not replace an expert in that
domain but make available their knowledge and
experience.
– Expert systems have been built that can diagnose
diseases and recommend medicines.
– Expert systems are also available for computer
configuration and financial planning.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 22
Mishra
Applications of AI
• Natural language Processing:
– Natural language means the native language i.e.,
the language one speaks.
– The term natural language is used to distinguish it
from the computer input terms and language
modeled on natural human languages.
– Computer’s language (machine language) is quite
complex.
– For the computer to understand natural language
is equally complex at present.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 23
Mishra
Applications of AI
– In order to understand natural language it must
know how to generate, understand and translate.
– So, a natural language computer is the computer
which interacts through natural language.
– Hence it must have a parser, a knowledge
representation system and an output translator.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 24
Mishra
Applications of AI
• Computer Vision:
– Computer vision is the science and technology of
machines that see.
– Computer vision is concerned with the theory and
technology for building artificial systems that obtain
information from images or multi-dimensional data.
– Computer vision is a technique for a computer system
to search beyond the data it is given and to find out
almost the real world by analyzing and evaluating
visual information.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 25
Mishra
Applications of AI
• Robotics:
– Robotics is field of engineering devoted to
duplicating the physical capabilities of human
being; attempts to mimic human mental abilities.
– They differ from AI programs which usually
operate in computer-simulated world whereas
robots operate in physical world.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 26
Mishra
Applications of AI
• Others:
– As AI is a developing field it is expected that there
are many areas in which AI techniques of
simulation of sophisticated and intelligent
behaviour will be used in near future.
– For ex., game playing in one such area.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 27
Mishra
Agent

Artificial Intelligence, KCS-071, Manoj


1/6/2024 28
Mishra
Agent Contd..
• Agents can be classified into different types
based on their characteristics, such as
whether they are reactive or proactive,
whether they have a fixed or dynamic
environment, and whether they are single or
multi-agent systems.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 29
Mishra
Reactive Agents
• Reactive agents are those that respond to
immediate stimuli from their environment and
take actions based on those stimuli.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 30
Mishra
Proactive agents
• Proactive agents, on the other hand, take
initiative and plan ahead to achieve their
goals.
• The environment in which an agent operates
can also be fixed or dynamic. Fixed
environments have a static set of rules that do
not change, while dynamic environments are
constantly changing and require agents to
adapt to new situations.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 31
Mishra
Multi-agent systems
• Multi-agent systems involve multiple agents
working together to achieve a common goal.
• These agents may have to coordinate their
actions and communicate with each other to
achieve their objectives.
• Agents are used in a variety of applications,
including robotics, gaming, and intelligent
systems. They can be implemented using
different programming languages and techniques,
including machine learning and natural language
processing.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 32
Mishra
•An agent is anything that can be viewed as:
Perceiving its environment through sensors and
Acting upon that environment through actuators

Artificial Intelligence, KCS-071, Manoj


1/6/2024 33
Mishra
Agent Components

• Perception or Sensing
– Sensors and perception mechanisms
– Preprocessing and data acquisition
• Decision Making
– Decision-making process
– Action selection strategies
– Deliberation and reasoning
• Action Execution
– Actuators and effectors
– Motor control and execution of actions

Artificial Intelligence, KCS-071, Manoj


1/6/2024 34
Mishra
Structure of an AI Agent

• To understand the structure of Intelligent Agents, we


should be familiar with Architecture and Agent programs.
• Architecture is the machinery that the agent executes on. It
is a device with sensors and actuators, for example, a
robotic car, a camera, and a PC.
• An agent program is an implementation of an agent
function.
• An agent function is a map from the percept
sequence(history of all that an agent has perceived to date)
to an action.

Agent = Architecture + Agent Program

Artificial Intelligence, KCS-071, Manoj


1/6/2024 35
Mishra
Agent Architectures
1. Reactive Architectures:
• Reactive architectures, also known as behavior-
based architectures, focus on immediate actions
based on the current percept.
• These architectures directly map percepts to
actions without explicitly considering internal
states or future consequences.
• Reactive agents are responsive and can make
quick decisions in real-time environments.
• They are suitable for tasks that require fast
responses and have a limited number of states.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 36
Mishra
2. Deliberative Architectures:

• Deliberative architectures involve careful


consideration and planning before making
decisions.
• These architectures maintain an internal model of
the environment and use it for decision-making.
• Deliberative agents can think ahead, plan, and
evaluate multiple alternatives before selecting an
action.
• They are well-suited for tasks that require long-
term planning and consideration of different
possible outcomes.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 37
Mishra
3. Hybrid Architectures:
• Hybrid architectures combine elements from
both reactive and deliberative approaches.
• These architectures leverage the strengths of
both reactive and deliberative agents to handle
complex environments and dynamic situations.
• Hybrid agents can react quickly to immediate
stimuli while also making thoughtful decisions
based on internal models and goals.
• They are versatile and can adapt to a wide range
of scenarios.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 38
Mishra
Examples:
• Reactive Architecture Example: Consider a simple vacuum
cleaning robot that moves in a direction as soon as it
detects dirt. It doesn't plan its path; it just reacts to the
immediate percept (dirt detection).
• Deliberative Architecture Example: A chess-playing agent
that explores multiple possible moves, simulating each
move's consequences several steps ahead using a search
algorithm like Minimax, to select the best move.
• Hybrid Architecture Example: An autonomous vehicle that
employs reactive behaviors for avoiding immediate
obstacles but also considers a deliberative component for
planning complex maneuvers, such as merging onto a
highway.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 39
Mishra
Example of Agents in AI
There are many examples of agents in artificial
intelligence as:
• Intelligent personal assistants
• Autonomous robots
• Gaming agents
• Fraud detection agents
• Traffic management agents
• A software agent
• A Robotic agent

Artificial Intelligence, KCS-071, Manoj


1/6/2024 40
Mishra
Intelligent personal assistants:
• These are agents that are designed to help
users with various tasks, such as scheduling
appointments, sending messages, and setting
reminders. Examples of intelligent personal
assistants include Siri, Alexa, and Google
Assistant.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 41
Mishra
Autonomous robots:
• These are agents that are designed to operate
autonomously in the physical world. They can
perform tasks such as cleaning, sorting, and
delivering goods. Examples of autonomous
robots include the Roomba vacuum cleaner
and the Amazon delivery robot.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 42
Mishra
Gaming agents:
• These are agents that are designed to play
games, either against human opponents or
other agents. Examples of gaming agents
include chess-playing agents and poker-
playing agents.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 43
Mishra
Fraud detection agents:
• These are agents that are designed to detect
fraudulent behavior in financial transactions.
They can analyze patterns of behavior to
identify suspicious activity and alert
authorities. Examples of fraud detection
agents include those used by banks and credit
card companies.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 44
Mishra
Traffic management agents:
• These are agents that are designed to manage
traffic flow in cities. They can monitor traffic
patterns, adjust traffic lights, and reroute
vehicles to minimize congestion. Examples of
traffic management agents include those used
in smart cities around the world.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 45
Mishra
Software agent
• A software agent has Keystrokes, file contents,
received network packages that act as sensors
and displays on the screen, files, and sent
network packets acting as actuators.
• A Human-agent has eyes, ears, and other
organs which act as sensors, and hands, legs,
mouth, and other body parts act as actuators.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 46
Mishra
Robotic agent
• A Robotic agent has Cameras and infrared
range finders which act as sensors and various
motors act as actuators.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 47
Mishra
Characteristics of an Agent

Artificial Intelligence, KCS-071, Manoj


1/6/2024 48
Mishra
Intelligent Agents
• The word “agent” is derived from the concept of
agency which means employing someone to act
on behalf of the user.
• In other words, an agent is someone with
expertise who is entrusted to act on our behalf.
• An agent is something that can be viewed as
perceiving its environment through sensors and
acting upon that environment through actuators.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 49
Mishra
Intelligent Agents
• A human agent has eyes, ears and other
organs for sensors and body parts like hands,
legs, mouth etc. for actuators.
• . A software agent receives keystrokes, file
contents and network packets as sensory
inputs and acts on the environment by
displaying on the screen, writing files and
sending network packets

Artificial Intelligence, KCS-071, Manoj


1/6/2024 50
Mishra
Intelligent Agents
• Computer agents (or software agents) have several
characteristics which distinguish them from mere
programs. They are:
– Capability to work on their own (autonomy)
– Perceiving their environment
– Persisting over a prolonged time period
– Adapting to change (adaptability)
– Ability to learn
– Capable of taking on another’s goal (goal oriented)
– Transportable over networks (mobility)
– Ability to interact with humans, systems and other agents
(communicative)

Artificial Intelligence, KCS-071, Manoj


1/6/2024 51
Mishra
Intelligent Agents
• In AI, we use the term “intelligent agent” which
represent a new technology for software programs.
• An intelligent agent is a software entity which senses
its environment and then carries out some set of
operations on behalf of a user (or a program), with
some degree of autonomy, and in doing so employs
some knowledge or representation of the user’s goals
or desires.
• In other words, intelligent agents are software
programs which work in the background to carry out
specific, repetitive, predictable task for an individual
user, business processor software application.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 52
Mishra
Key Components of Intelligent Agents:
• Perception: Agents gather information about their environment
using sensors or perceptual mechanisms. This data may include raw
sensory input, processed data, or information received from other
agents.
• Decision-Making: Based on the information received from
perception, the agent engages in decision-making. This involves
reasoning about the current state of the environment, its own
internal knowledge, and possibly historical data to determine the
most suitable action to take.
• Action: Agents interact with the environment by performing actions
through actuators or effectors. These actions could involve physical
movements, changes in the agent's internal state, communication
with other agents, or any other relevant activities.
• Learning: Some intelligent agents can adapt and improve their
decision-making abilities over time through learning. Learning
agents use data from interactions with the environment to modify
their behavior, refine their strategies, and optimize their actions for
better performance.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 53
Mishra
Characteristics of Intelligent Agents:
• Autonomy: Intelligent agents operate independently and make decisions
without direct human intervention. They have the capability to adapt to
changing situations and adjust their actions accordingly.
• Goal-Oriented: Agents are designed with specific goals or objectives in
mind. Their actions are aimed at achieving these goals, which could range
from solving complex problems to performing routine tasks efficiently.
• Adaptability: Intelligent agents can adapt to varying and unpredictable
environments. They can adjust their strategies and actions based on
changes in their environment or the outcomes of their previous actions.
• Interaction: Agents interact with their environment, which can include
other agents, objects, and systems. These interactions allow them to
gather information, receive feedback, and influence the state of the
environment.
• Situational Awareness: Agents have the ability to perceive and
understand their surroundings. They process sensory data to create an
internal representation of the environment, which aids in decision-
making.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 54
Mishra
Examples of Intelligent Agents:

• Autonomous Driving Systems: Self-driving cars use sensors to perceive


the road and surrounding vehicles, process this information to make
driving decisions, and control the car's movements accordingly.
• Virtual Personal Assistants: AI-powered virtual assistants like Siri, Google
Assistant, and Alexa interact with users, process their queries, and
perform tasks such as setting reminders, answering questions, and
controlling smart home devices.
• Game-Playing Agents: AI agents developed to play games like chess, Go,
and poker can analyze the game state, predict opponents' moves, and
make decisions to maximize their chances of winning.
• Industrial Robots: Robots in manufacturing plants can perceive their
environment through sensors, make decisions about tasks like assembly or
welding, and execute precise movements to perform those tasks.
• Recommendation Systems: Online platforms use intelligent agents to
analyze user preferences and behavior, then suggest relevant products,
content, or connections.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 55
Mishra
Types of Environments:

• Fully Observable Environment: In a fully observable environment,


the agent has access to complete and accurate information about
the current state of the environment at any given time. The agent's
sensors provide a comprehensive view of the environment's state.
Chess is an example of a fully observable environment, as both
players have complete information about the current state of the
game.
• Partially Observable Environment: In a partially observable
environment, the agent's sensors provide incomplete or uncertain
information about the environment. The agent must maintain an
internal representation of the environment based on its
observations and use this representation to make decisions.
Autonomous driving in real-world traffic is an example of a partially
observable environment due to limited sensor range and
occlusions.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 56
Mishra
Types of Environments: Contd..
• Deterministic Environment: In a deterministic
environment, the outcomes of the agent's actions are
completely determined by the current state of the
environment and the agent's actions. There is no
randomness or uncertainty involved. An agent playing a
game of tic-tac-toe in a deterministic environment can
predict the consequences of its actions with certainty.
• Stochastic Environment: In a stochastic environment, there
is an element of randomness or uncertainty in the
outcomes of the agent's actions. The same action taken in
the same state might lead to different outcomes due to
probabilistic factors. A robot navigating through a crowded
area where pedestrians might change their paths
unexpectedly is an example of a stochastic environment.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 57
Mishra
Types of Environments: Contd..
• Episodic Environment: In an episodic environment, the
agent's actions do not depend on previous actions or
states. Each episode is treated as an isolated unit, and
the agent's actions are influenced only by the current
episode's state. A crossword puzzle solver is an
example of an agent operating in an episodic
environment, as each puzzle is self-contained.
• Sequential Environment: In a sequential environment,
the agent's actions have consequences that affect
future states. The agent must consider the long-term
implications of its decisions. Chess and other strategy
games are examples of sequential environments,
where each move impacts the subsequent game state.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 58
Mishra
Examples of Different Types of Environments:
• Example of a Fully Observable Environment:
– Chess: Both players can see the entire board and all pieces, making the
environment fully observable.
• Example of a Partially Observable Environment:
– Autonomous Driving: A self-driving car's sensors provide data about nearby
vehicles and obstacles, but it can't perceive every detail of the entire
environment.
• Example of a Deterministic Environment:
– Robotics Assembly Line: A robotic arm in an assembly line performs the same
sequence of actions every time it receives the same inputs.
• Example of a Stochastic Environment:
– Stock Market Trading: Predicting stock price movements involves dealing with
uncertainty due to various factors affecting market dynamics.
• Example of an Episodic Environment:
– Solitaire Card Game: Each game of solitaire is independent of previous games,
and the agent's actions are based on the current card layout.
• Example of a Sequential Environment:
– Poker: In poker, each player's actions impact the subsequent rounds and
influence the final outcome of the game.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 59
Mishra
Role of Intelligent Agent in AI Systems:
• Decision-Making and Problem Solving
• Adaptation to Changing Environments
• Automation of Complex Tasks
• Interaction with Users and Systems
• Data Analysis and Learning
• Decision Support Systems
• Multi-Agent Collaboration
• Real-World Applications
• Research and Innovation
Artificial Intelligence, KCS-071, Manoj
1/6/2024 60
Mishra
Structure of Intelligent Agents
• A simple agent program can be defined mathematically
as an agent function which maps every possible
percepts sequence to a possible action the agent can
perform or to a coefficient, feedback element, function
or constant that affect actual actions.
• Agent function is an abstract concept as it could
incorporate various principles of decision making like
calculation of utility of individual options, deduction
over logic rules, fuzzy logic, etc.
• The agent program will run on some sort of computing
device called the architecture.
• Hence, agent = architecture + program.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 61
Mishra
Classes of Intelligent Agents
• A general learning agent can be classified into
five classes based on their degree of perceived
intelligence and capability:
– Simple reflex agents
– Model-based reflex agents
– Goal-based agents
– Utility-based agents
– Learning agents

Artificial Intelligence, KCS-071, Manoj


1/6/2024 62
Mishra
Simple reflex agents
• Simple reflex agents act only on the basis of
the current percept, ignoring the rest of the
percept history.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 63
Mishra
1. Simple Reflex agent:
The Simple reflex agents are the simplest agents.
These agents take decisions on:
• The basis of the current percepts and ignore the rest of
the percept history.
• These agents only succeed in the fully observable
environment.
• The Simple reflex agent does not consider any part of
percepts history during their decision and action
process.
• The Simple reflex agent works on Condition-action
rule, which means it maps the current state to action.
Such as a Room Cleaner agent, it works only if there is
dirt in the room.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 64
Mishra
Problems for the simple reflex agent design
approach:

• They have very limited intelligence


• They do not have knowledge of non-perceptual parts
of the current state
• Mostly too big to generate and to store.
• Not adaptive to changes in the environment.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 65
Mishra
Artificial Intelligence, KCS-071, Manoj
1/6/2024 66
Mishra
Model-based reflex agents
• A model-based agent can handle a partially
observable environment.
• Its current state is stored inside the agent
maintaining some kind of structure which
describes the part of the world which cannot
be seen.
• This knowledge about “how the world works”
is called a model of the world, hence the
name “model-based agent”.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 67
Mishra
2. Model-based reflex agent

• The Model-based agent can work in a partially


observable environment, and track the situation.
• A model-based agent has two important factors:
Model: It is knowledge about "how things happen
in the world," so it is called a Model-based agent.
Internal State: It is a representation of the current
state based on percept history.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 68
Mishra
Model-based reflex agent Contd..
• These agents have the model, "which is
knowledge of the world" and based on the
model they perform actions.
• Updating the agent state requires
information about:
• How the world evolves
• How the agent's action affects the world.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 69
Mishra
Artificial Intelligence, KCS-071, Manoj
1/6/2024 70
Mishra
Goal-based agents
• Goal-based agents further expand on the
capabilities of the model-based agents, by
using “goal” information.
• Goal information describes situations that are
desirable.
• This allows the agent a way to choose among
multiple possibilities, selecting the one which
reaches a goal state.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 71
Mishra
3. Goal-based agents
• The knowledge of the current state environment is not
always sufficient to decide for an agent to what to do.
• The agent needs to know its goal which describes
desirable situations.
• 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. Such considerations of different
scenario are called searching and planning, which
makes an agent proactive.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 72
Mishra
Artificial Intelligence, KCS-071, Manoj
1/6/2024 73
Mishra
Utility-based agents
• A rational utility-based agent chooses the action
that maximizes the expected utility of the action
outcomes – that is, the agent expects to derive,
on average, given the probabilities and utilities of
each outcome.
• A utility-based agent has to model and keep track
of its environment, tasks that have involved a
great deal of research on perception,
representation, reasoning and learning.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 74
Mishra
4. Utility-based agents
• These agents are similar to the goal-based agent
but provide an extra component of utility
measurement which makes them different by
providing a measure of success at a given state.
• Utility-based agent act based not only goals but
also the best way to achieve the goal.
• The Utility-based agent is useful when there are
multiple possible alternatives, and an agent has
to choose in order to perform the best action.
• The utility function maps each state to a real
number to check how efficiently each action
achieves the goals.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 75
Mishra
Artificial Intelligence, KCS-071, Manoj
1/6/2024 76
Mishra
Learning agents
• The learning element which is responsible for
making improvements uses feedback from the
“critic” on how the agent is doing and
determines how the performance element
which is responsible for selecting external
actions should be modified to do better in the
future.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 77
Mishra
5. Learning Agents

• A learning agent in AI is the type of agent


which can learn from its past experiences, or it
has learning capabilities.
• It starts to act with basic knowledge and then
able to act and adapt automatically through
learning.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 78
Mishra
5. Learning Agents Contd…
• A learning agent has mainly four conceptual components, which
are:
• 1. Learning element: It is responsible for making improvements by
learning from environment
• 2. Critic: Learning element takes feedback from critic which
describes that how well the agent is doing with respect to a fixed
performance standard.
• 3. Performance element: It is responsible for selecting external
action
• 4. Problem generator: This component is responsible for suggesting
actions that will lead to new and informative experiences

Hence, learning agents are able to learn, analyze performance, and


look for new ways to improve the performance.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 79
Mishra
Artificial Intelligence, KCS-071, Manoj
1/6/2024 80
Mishra
Problem Solving Approach to Typical AI Problems.

• There are basically three types of problem in artificial


intelligence:
1. Ignorable: In which solution steps can be ignored.
2. Recoverable: In which solution steps can be undone.
3. Irrecoverable: Solution steps cannot be undo.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 81
Mishra
Steps problem-solving in AI:
• The problem of AI is directly associated with the nature of
humans and their activities. So we need a number of finite
steps to solve a problem which makes human easy works.
• These are the following steps which require to solve a
problem :
• Problem definition: Detailed specification of inputs and
acceptable system solutions.
• Problem analysis: Analyse the problem thoroughly.
• Knowledge Representation: collect detailed information
about the problem and define all possible techniques.
• Problem-solving: Selection of best techniques.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 82
Mishra
Components to formulate the associated problem:
• Initial State: This state requires an initial state for the problem
which starts the AI agent towards a specified goal. In this state new
methods also initialize problem domain solving by a specific class.
• Action: This stage of problem formulation works with function with
a specific class taken from the initial state and all possible actions
done in this stage.
• Transition: This stage of problem formulation integrates the actual
action done by the previous action stage and collects the final stage
to forward it to their next stage.
• Goal test: This stage determines that the specified goal achieved by
the integrated transition model or not, whenever the goal achieves
stop the action and forward into the next stage to determines the
cost to achieve the goal.
• Path costing: This component of problem-solving numerical
assigned what will be the cost to achieve the goal. It requires all
hardware software and human working cost.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 83
Mishra
Computer Vision [Short Notes]
• Computer vision is a field that includes methods for
acquiring, processing, analyzing and understanding
images and, in general, high-dimensional data from the
real world in order to produce numerical or symbolic
information, ex., in the form of decisions.
• A theme in the development of this field has been to
duplicate the abilities of human vision by electronically
perceiving and understanding an image.
• This image understanding can be seen as the
perception of symbolic information from image data
using models constructed with the aid of geometry,
physics, statistics and learning theory.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 84
Mishra
Computer Vision [Short Notes]
• In AI, computer vision is studied as matrix of intensity
values.
• A visual scene may be encoded by sensors and represented
as matrix of intensity values.
• These are processed by detectors that search for primitive
picture components like line segments, simple curves,
corners, etc.
• These in turn are processed to infer information regarding
the objects of the scene.
• The ultimate aim is to represent the scene by a suitable
model.
• Useful applications of computer vision can be aerial
photographs, remote sensing, finger prints, paperless
banking, surveillance, etc.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 85
Mishra
Natural Language Processing (NLP)
[Short Notes]
• Natural language processing is a theoretically
motivated range of computational techniques for
analyzing and representing naturally occurring
texts at one or more levels of linguistic analysis
for the purpose of achieving human-like language
processing for a range of tasks or applications.
• NLP is the computerized approach to analyzing
text that is based on both a set of theories and a
set of technologies.
Artificial Intelligence, KCS-071, Manoj
1/6/2024 86
Mishra
Natural Language Processing (NLP)
[Short Notes]
• NLP is considered a sub-field of artificial
intelligence and linguistics.
• Natural language issues hold applicability,
particularly in the areas of text mining, search
engines, automatic summarization,
information retrieval, speech synthesis and
algorithms employed to determine the
content of text streams in computational
linguistics.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 87
Mishra
Problem-Solving Approach to Typical AI
Problems
• Understand the Problem: Before diving into solving a problem,
ensure you have a clear understanding of the problem statement
and its requirements. Define the problem's inputs, outputs,
constraints, and objectives.
• Model the Problem: Represent the problem in a suitable format,
such as graphs, matrices, logical expressions, or other relevant data
structures. Choose a representation that simplifies the problem and
makes it amenable to algorithmic solutions.
• Choose an Algorithmic Approach: Depending on the nature of the
problem, choose an appropriate algorithmic approach. Common
approaches include search algorithms, optimization techniques,
machine learning, and constraint satisfaction.
• Develop the Algorithm: Implement or adapt an algorithm that
addresses the problem. This might involve designing and coding
data structures, decision-making rules, and computation steps.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 88
Mishra
Problem-Solving Approach to Typical AI
Problems Contd..
• Implement Heuristics (If Needed): For complex problems where finding
an optimal solution is challenging, heuristics can be used to guide the
search process. Heuristics are rules or strategies that prioritize certain
paths or solutions.
• Test and Debug: Implement test cases to verify the correctness of your
algorithm's implementation. Debug any errors or unexpected behaviors
that arise during testing.
• Optimize and Refine: If your initial solution is not efficient or doesn't meet
performance requirements, consider optimizing it. Optimization might
involve improving algorithmic complexity, memory usage, or execution
speed.
• Evaluate the Solution: Measure the effectiveness of your solution using
appropriate metrics. For example, accuracy for classification problems,
convergence rate for optimization, or efficiency for search algorithms.
• Iterate and Improve: If the solution doesn't meet your desired outcomes
or if there's room for improvement, iterate on your approach. This might
involve revisiting the problem statement, trying alternative algorithms, or
refining heuristics.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 89
Mishra
Problem-Solving Approach to Typical AI Problems
Contd..

• Scale and Generalize: Ensure that your solution


can handle different scenarios and scales.
Solutions that work well on small instances of a
problem might need adaptations to handle larger
or more complex instances.
• Document Your Solution: Properly document
your approach, implementation, assumptions,
and results. Good documentation ensures that
others can understand, reproduce, and build
upon your work.

Artificial Intelligence, KCS-071, Manoj


1/6/2024 90
Mishra
Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 1
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
State Space Search
• Formulate a problem as a state space search by
showing the legal problem states, the legal operators,
and the initial and goal states.
• A state is defined by the specification of the values of
all attributes of interest in the world.
• An operator changes one state into the other; it has a
precondition which is the value of certain attributes
prior to the application of the operator, and a set of
effects, which are the attributes altered by the
operator.
• The initial state is where you start.
• The goal state is the partial description of the solution.

1/6/2024 A.I., KCS-071, Manoj Mishra 92


State Space Search: Contd..
• In state space search, a problem is typically
represented as a set of states, where each
state represents a specific configuration,
situation, or snapshot of the problem at a
particular point in time.
• These states are interconnected through
various actions or transitions, which define
how the system can move from one state to
another.

1/6/2024 A.I., KCS-071, Manoj Mishra 93


State Space Search: Contd..
• The primary objective of state space search is
to find a sequence of actions or transitions
that lead from an initial state to a goal state,
while satisfying certain constraints or criteria.
This sequence of actions represents the
solution to the problem or the path to the
desired outcome.

1/6/2024 A.I., KCS-071, Manoj Mishra 94


Key components and concepts in state space
search include:
• Initial State: The starting point of the problem-
solving process, representing the initial
configuration of the system.
• Goal State: The desired or target state that the
system is trying to reach. The search algorithm
aims to find a path from the initial state to the
goal state.
• Actions/Transitions: The set of permissible
actions or transitions that can be applied to move
from one state to another. These actions define
the problem's dynamics and constraints
1/6/2024 A.I., KCS-071, Manoj Mishra 95
Key components and concepts in state
space search include: Contd..
• State Space: The entire set of possible states that
can be explored during the search process. It
includes both the initial state and all possible
states that can be reached from it.
• Search Algorithm: The method or strategy used
to explore the state space efficiently and find a
solution or a path to the goal state. Common
search algorithms include depth-first search,
breadth-first search, A* search, and more.
• Path: A sequence of actions or transitions that
lead from the initial state to a goal state. The
quality of the path may vary depending on the
specific problem-solving criteria.
1/6/2024 A.I., KCS-071, Manoj Mishra 96
Classification of State Space Search
• There are two classes of state space search.
They are:
– Uninformed or Blind search
– Informed or Heuristic search

1/6/2024 A.I., KCS-071, Manoj Mishra 97


Uninformed Search Strategies
• Uninformed search strategies also called blind search,
are methods that have no additional information about
states beyond that provided in the problem definition.
• In other words, a blind or uninformed search algorithm
is one which uses no information other than the initial
state, the search operators and a test for a solution.
• A blind search proceeds in a systematic way by
exploring nodes in a predetermined order or by
selecting nodes at random.
• Uninformed search strategies generate successors and
distinguish a goal state from a non goal state.

1/6/2024 A.I., KCS-071, Manoj Mishra 98


Uninformed Search Strategies
• The common methods of uninformed search
are:
– Breadth-first search(BFS)
– Uniform-cost search(UCS)
– Depth-first search(DFS)
– Depth limited search(DLS)
– Iterative deepening depth first search(IDDFS)

1/6/2024 A.I., KCS-071, Manoj Mishra 99


Breadth-first search (BFS)
• Breadth-first search is the simplest form of uninformed
search.
• In this type of search 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.
• Thus, although the search may be an extremely long
one, it is guaranteed eventually to find the shortest
possible solution sequence, if any solution exists.

1/6/2024 A.I., KCS-071, Manoj Mishra 100


Breadth-first search (BFS)
• Following points are to be noted for breadth-first
search method:
– It is simple and systematic search strategy as it
considers all nodes at level 1 and then all the states at
level 2 and so on.
– If any solution exists, breadth first search is
guaranteed to find it.
– If there are several solutions then breadth-first search
will always find the shallowest goal state first. If the
cost of a solution is a non-decreasing function of the
depth, then it will always find the cheapest solution.

1/6/2024 A.I., KCS-071, Manoj Mishra 101


Breadth-first search (BFS)

1/6/2024 A.I., KCS-071, Manoj Mishra 102


Advantages of BFS
• BFS will not get trapped exploring a blind alley.
• If any solution exists, this method is
guaranteed to find it.

1/6/2024 A.I., KCS-071, Manoj Mishra 103


Disadvantages of BFS
• The amount of time needed to generate all
the nodes is considerable.
• The searching process remembers all
unwanted nodes which is of no practical use
for the search.

1/6/2024 A.I., KCS-071, Manoj Mishra 104


Uniform-Cost Search
• The breadth-first algorithm can be generalized slightly
to solve the problem of finding the cheapest path from
the start state to a goal state.
• A non-negative cost is associated with every arc joining
two nodes; the cost of a solution path is then the sum
of the arc costs along the path.
• The generalized algorithm is called a uniform-cost
search.
• If all arcs have equal cost, the algorithm reduces to
breadth-first search.
• Uniform-cost search does not care about the number
of steps in a path but only about their total cost.

1/6/2024 A.I., KCS-071, Manoj Mishra 105


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 2
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Depth-first search (DFS)
• The depth-first search is characterized by the
expansion of the most recently generated, or deepest
node, first.
• Following points are to be noted for depth-first search
method:
– It has a modest memory requirement. It only needs to
store the path from the root to the leaf node as well as the
unexpanded nodes.
– Depth-first search is neither complete nor optimal. If
depth-first search goes down an infinite branch, it will not
terminate unless a goal state is found. Even if a solution is
found, there may be a better solution at a higher level in
the tree.

1/6/2024 A.I., KCS-071, Manoj Mishra 107


Depth-first search (DFS)

1/6/2024 A.I., KCS-071, Manoj Mishra 108


Advantages of DFS
• DFS requires less memory since the only
nodes on the current path are stored.
• It is by chance that we may find a solution
without examining much of the search space.

1/6/2024 A.I., KCS-071, Manoj Mishra 109


Disadvantages of DFS
• This type of search can go on and on, deeper
and deeper into the search space and we can
get lost (blind alley).

1/6/2024 A.I., KCS-071, Manoj Mishra 110


Comparison between BFS and DFS
S.No. BFS DFS
1 No blind alley exists. Blind alley exists.
2 If a solution exists, it will be found. Even if a solution exists, it explores one
branch only and it may declare failure.
Chance of success becomes still less when
loop exists.
3 May find many solutions. If many It stops after one solution is found.
solution exists, minimal solution Minimal solution may not be found as it
can be found. explores only one branch.
4 Require more memory because all Requires less memory because only one
the off-springs of the tree must be branch is scanned. It stops after solution
explored one level n before a is found.
solution on level (n+1) is to be
examined.

1/6/2024 A.I., KCS-071, Manoj Mishra 111


Depth-Limited Search
• The depth-first search has an inclination to search
deeper and deeper into the state space until a
success occurs (that is a solution is found) or a
blind alley is encountered.
• In order to prevent the algorithm from blindly
searching too deep into the state space, which
may prove to be rather useless venture, a depth
cutoff d is usually specified and a backtrack is
enforced whenever depth d is reached.

1/6/2024 A.I., KCS-071, Manoj Mishra 112


Depth-Limited Search
• It is clear that if d is too low the algorithm
terminates without finding a solution.
• On the other hand, if d is too high the algorithm
terminates as soon as it finds some solution, but
in this case it might expand too many nodes.
• Unfortunately, it is not always possible to make a
correct prediction of d. This fact puts a practical
difficulty on the usability of this technique.

1/6/2024 A.I., KCS-071, Manoj Mishra 113


Depth-First Iterative Deepening
(DFID)
• The problem with depth-first search is that the search
can go down an infinite branch and thus never return.
• This problem can be avoided by imposing a depth-limit
which terminates the search at that depth.
• However, the next question is to decide a suitable
depth-limit.
• To overcome this problem there is another search
method called iterative deepening.
• Iterative deepening search is a general strategy often
used in combination with depth-first search that finds
the best depth limit.
1/6/2024 A.I., KCS-071, Manoj Mishra 114
Depth-First Iterative Deepening
(DFID)
• This method enjoys the memory requirements of
depth-first search while guaranteeing that a goal node
of minimal depth will be found (if a goal exists).
• This search method simply tries all possible depth
limits; first 0, then 1, then 2, etc. until a solution is
found.
• In iterative deepening, successive depth-first searches
are conducted – each with depth bounds increasing by
1 – until a goal node is found.
• Hence, iterative deepening combines the benefits of
depth-first and breadth-first search.

1/6/2024 A.I., KCS-071, Manoj Mishra 115


Depth-First Iterative Deepening
(DFID)
• Like depth-first search, its memory requirements are
very modest.
• Like breadth-first search, it is complete when the
branching factor is finite and optimal when the path
cost is a non decreasing function of the depth of the
node.
• Iterative deepening search is analogous to breadth-first
search in that it explores a complete layer of new
nodes at each iteration before going to the next layer.
• Note:
– In general, iterative deepening is the preferred uninformed
search method when there is a large search space and the
depth of the solution is not known.
1/6/2024 A.I., KCS-071, Manoj Mishra 116
Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 3
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Bi-directional Search
• The idea behind bi-directional search is to run two
simultaneous searches – one forward from the initial
state and the other backward from the goal, stopping
when two searches meet in the middle.
• A search algorithm has to be selected for each half.
• Bi-directional search is implemented by having one or
both of the searches check each node before it is
expanded to see if it is in the fringe of the other search
tree; if so, a solution has been found.
• The most difficult case for bidirectional search is when
the goal test gives only on implicit description of some
possibly large set of goal states.

A.I., KCS-071, Manoj Mishra 118


Example
• Consider a simple graph representing a
network of cities connected by roads. You
want to find the shortest path from City A to
City D using a bi-directional search.

A.I., KCS-071, Manoj Mishra 119


Solution
• A, B, C, D, and E represent cities.
• S represents the starting city.
• The goal is to find the shortest path from City A
to City D.
• Bi-directional Search:
• Initialize two search queues: one starting from
City A (forward search) and the other starting
from City D (backward search).
• Forward Queue: [A]
• Backward Queue: [D]

A.I., KCS-071, Manoj Mishra 120


• Perform the search simultaneously from both directions
until they meet in the middle or one of them finds the goal.
– Forward Search:
• Expand City A. The possible neighbors are B and S. Add them to the
forward queue.
• Forward Queue: [B, S]
– Backward Search:
• Expand City D. The possible neighbors are E and C. Add them to the
backward queue.
• Backward Queue: [E, C]
– Forward Search:
• Expand B. The possible neighbor is A (already visited) and D (found in
the backward search). Goal found!
• Forward Queue: [S]
• Backward Queue: [E, C]
• Combine the paths from both directions to form the final
path. In this case, the path is A -> B -> D.

A.I., KCS-071, Manoj Mishra 121


Informed Search Strategies
• In the blind search, the number of nodes
expanded before reaching a solution may
become prohibitively large to non-trivial
problems.
• Because the order of expanding the nodes is
purely arbitrary and does not use any properties
of the problem being solved, too many nodes
may be expanded.
• In such cases, we may run out of time or space,
or both, even in simple problem.
A.I., KCS-071, Manoj Mishra 122
Informed Search Strategies
• Information about the particular problem domain
can often be invoked to reduce the search.
• The techniques for doing so usually require
additional information about the properties of
the specific domain which is built into the state
and operator definitions.
• Information of this sort is called heuristic
information and the search methods using this
information is called heuristic search or informed
search.
A.I., KCS-071, Manoj Mishra 123
Informed Search Strategies
• A heuristic search could be any information,
say a simple number representing how good
or bad that path is likely to be.
• Heuristic search methods helps in deciding:
– which node to expand next, instead of
depth/breadth first-type of expansion.
– which successor(s) of the node to be generated
instead of blindly generating all possible
successors of that node, thus pruning the search
tree.
A.I., KCS-071, Manoj Mishra 124
Heuristic Functions
• Heuristic means “rule of thumb”.
• Heuristics are criteria, methods or principles
for deciding which among several alternative
courses of action promises to be the most
effective in order to achieve some goal.
• In heuristic search or informed search,
heuristics are used to identify the most
promising search path.

A.I., KCS-071, Manoj Mishra 125


Heuristic Functions
• A heuristic function is a function that maps from
problem state description to measure desirability,
usually represented as number weights.
• The value of a heuristic function at a given node
in the search process gives a good estimate of
that node being on the desired path to solution.
• A heuristic function at a node ‘n’ is an estimate of
the optimum cost from the current node to a
goal. It is denoted by h(n).
– i.e., h(n) = estimated cost of the cheapest path from
node n to a goal node.

A.I., KCS-071, Manoj Mishra 126


Best-First Search
• Best-first is an instance of the general TREE-
SEARCH or GRAPH-SEARCH algorithm in which
a node is selected for expansion based on
evaluation function, f(n).
• Traditionally, the node with the lowest
evaluation is selected for expansion because
the evaluation measures distance to the goal.
• The algorithm maintains a priority queue of
nodes to be explored.

A.I., KCS-071, Manoj Mishra 127


Greedy Best-First Search
• Greedy best-first search tries to expand the
node that is closest to the goal, on the
grounds that is likely to lead to a solution
quickly.
• Thus, it evaluates nodes by using just the
heuristic function: f(n) = h(n).
• The resulting algorithm is not optimal.
• The algorithm is also incomplete, and it may
fail to find a solution even if one exists.
A.I., KCS-071, Manoj Mishra 128
A* Search Algorithm
• A* algorithm is a best-first search algorithm in which
the cost associated with a node is
f(n) = g(n) + h(n)
where g(n) is the cost of path from the initial state to node n
and h(n) is the heuristic estimate of the cost of a path from
node n to a goal.
• Since g(n) gives the path cost from the start node to
node ‘n’ and h(n) is the estimated cost of the cheapest
path from ‘n’ to the goal, we have,
f(n) = estimated cost of the cheapest solution through n

A.I., KCS-071, Manoj Mishra 129


A* Search Algorithm
• The following are some of the features of A* search
algorithm:
– At each point a node with lowest ‘f’ value is chosen for
expansion. Ties among nodes of equal ‘f’ value should be
broken in favour of nodes with lower ‘h’ values.
– The algorithm terminates when a goal node is chosen for
expansion.
– A* algorithm guides an optimal path to a goal if the heuristic
function h(n) is admissible, meaning it never overestimates
actual cost.
– A* algorithm expands fewest number of nodes.
– The main drawback of A* algorithm and indeed of any best-first
search is its memory requirement. Since at least the entire open
list must be saved, A* algorithm is severely space-limited.

A.I., KCS-071, Manoj Mishra 130


Solution Steps of A* Algo.
1. initialize the open list with the 'S' cell and its
associated cost (g-value) and heuristic (h-value).
2. While the open list is not empty:
• Choose the cell with the lowest f-value (f(n) = g(n) +
h(n)) from the open list.
• Expand this cell and calculate the f-values of its
neighbors.
• Add neighbors to the open list if they are not blocked
and have a lower f-value.
3. Repeat the above steps until you reach the 'G' cell.

A.I., KCS-071, Manoj Mishra 131


Example

A.I., KCS-071, Manoj Mishra 132


A.I., KCS-071, Manoj Mishra 133
AO* algorithm
• Best-first search is what the AO* algorithm does.
The AO* method divides any given difficult
problem into a smaller group of problems that
are then resolved using the AND-OR graph
concept. AND OR graphs are specialized graphs
that are used in problems that can be divided into
smaller problems. The AND side of the graph
represents a set of tasks that must be completed
to achieve the main goal, while the OR side of the
graph represents different methods for
accomplishing the same main goal.
1/6/2024 A.I., KCS-071, Manoj Mishra 134
1/6/2024 A.I., KCS-071, Manoj Mishra 135
AO* Contd..
• In the above figure, the buying of a car may be broken
down into smaller problems or tasks that can be
accomplished to achieve the main goal in the above
figure, which is an example of a simple AND-OR graph.
• The other task is to either steal a car that will help us
accomplish the main goal or use your own money to
purchase a car that will accomplish the main goal. The
AND symbol is used to indicate the AND part of the
graphs, which refers to the need that all subproblems
containing the AND to be resolved before the
preceding node or issue may be finished.

1/6/2024 A.I., KCS-071, Manoj Mishra 136


AO* Contd..
• The start state and the target state are already
known in the knowledge-based search
strategy known as the AO* algorithm, and the
best path is identified by heuristics. The
informed search technique considerably
reduces the algorithm’s time complexity. The
AO* algorithm is far more effective in
searching AND-OR trees than the A*
algorithm.

1/6/2024 A.I., KCS-071, Manoj Mishra 137


Working of AO* algorithm:

• The evaluation function in AO* looks like this:


f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the
current node.
h(n) = estimated cost from the current node
to the goal state.

1/6/2024 A.I., KCS-071, Manoj Mishra 138


Example:
Here in the example below the Node which is given is the heuristic value i.e h(n).
Edge length is considered as 1

1/6/2024 A.I., KCS-071, Manoj Mishra 139


Solution: Step 1

1/6/2024 A.I., KCS-071, Manoj Mishra 140


Solution Step 1: Contd..
• Start from node A, f(A⇢B) = g(B) + h(B) = 1 + 5
……here g(n)=1 is taken by default for path
cost = 6
• f(A⇢C+D) = g(c) + h(c) + g(d) + h(d) = 1 + 2 + 1
+ 4 ……here we have added C & D because
they are in AND = 8
• So, by calculation A⇢B path is chosen which is
the minimum path, i.e f(A⇢B)

1/6/2024 A.I., KCS-071, Manoj Mishra 141


Solution Step 2

1/6/2024 A.I., KCS-071, Manoj Mishra 142


Solution Step 2: Contd..
• According to the answer of step 1, explore node B Here the
value of E & F are calculated as follows,
• f(B⇢E) = g(e) + h(e) f(B⇢E) = 1 + 7 = 8
• f(B⇢f) = g(f) + h(f) 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.
• So we need to calculate it again. f(A⇢B) = g(B) + updated
h(B) = 1 + 8 = 9 We have Updated all values in the above
tree.

1/6/2024 A.I., KCS-071, Manoj Mishra 143


Solution Step 3

1/6/2024 A.I., KCS-071, Manoj Mishra 144


Solution Step 3: Contd..
• By comparing f(A⇢B) & f(A⇢C+D) f(A⇢C+D) is shown to be
smaller. i.e 8 < 9 Now explore f(A⇢C+D) So, the current
node is C
• f(C⇢G) = g(g) + h(g) f(C⇢G) = 1 + 3 = 4
• f(C⇢H+I) = g(h) + h(h) + g(i) + h(i) f(C⇢H+I) = 1 + 0 + 1 + 0
……here we have added H & I because they are in AND = 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, but Path A⇢D needs to be calculated
because it has an AND.
• f(D⇢J) = g(j) + h(j) f(D⇢J) = 1 + 0 = 1 the heuristic of node
D needs to be updated to 1.
• f(A⇢C+D) = g(c) + h(c) + g(d) + h(d) = 1 + 2 + 1 + 1 = 5
1/6/2024 A.I., KCS-071, Manoj Mishra 145
Step3 Contd..
• As we can see that path f(A⇢C+D) is get
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.

1/6/2024 A.I., KCS-071, Manoj Mishra 146


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 solution but AO* doesn’t
guarantee to give the optimal solution.
• Once AO* got a solution doesn’t explore all possible
paths but A* explores all paths.
• When compared to the A* algorithm, the AO*
algorithm uses less memory.
• opposite to the A* algorithm, the AO* algorithm
cannot go into an endless loop.

1/6/2024 A.I., KCS-071, Manoj Mishra 147


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 4
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Local Search Algorithms
• Local search algorithms operate using a single
current state, rather than multiple paths, and
generally move only to neighbors of that state.
• Local search methods work on complete state
formulations.
• They keep only a small number of nodes in
memory.
• Typically, the paths followed by the search are
not retained.
A.I., KCS-071, Manoj Mishra 149
Local Search Algorithms
• Although local search algorithms are not
systematic, they have two key advantages:
– They use very little memory – usually a constant
amount, and
– They can often find reasonable solutions in large or
infinite (continuous) state spaces for which systematic
algorithms are unsuitable.
• In addition to finding goals, local search
algorithms are useful for solving pure
optimization problems in which the aim is to find
the best state according to an objective function.

A.I., KCS-071, Manoj Mishra 150


Local Search Algorithms
• One way to visualize iterative improvements
algorithm is to imagine every possible state
laid out on a landscape with the height of
each state corresponding to its goodness.
• Optimal solutions will appear as the highest
points.
• Iterative improvement works by moving
around on the landscape seeking out the
peaks by looking only at the local vicinity.

A.I., KCS-071, Manoj Mishra 151


Local Search Algorithms
• To understand local search, we will find it very useful to
consider the state space landscape as shown in the figure.
• In the figure,
– A landscape has both “location” (defined by the state) and
“elevation” (defined by the value of the heuristic cost function
or objective function).
– If elevation corresponds to cost, then the aim is to find the
lowest valley – a global minimum.
– If elevation corresponds to an objective function, then the aim is
to find the highest peak – a global maximum.
– A complete search algorithm always finds a goal if one exists.
– An optimal algorithm always finds a global minimum /
maximum.

A.I., KCS-071, Manoj Mishra 152


Hill Climbing Search
• It is simply a loop that continually moves in
the direction of increasing value – that is,
uphill.
• It terminates when it reaches a “peak” where
no neighbor has a higher value.
• In other words, hill climbing search iteratively
maximize “value” of current state, by
replacing it by successor state that has highest
value, as long as possible.

A.I., KCS-071, Manoj Mishra 153


Hill Climbing Search
• The algorithm does not maintain a search
tree, so the current node data structure need
only record the state and its objective function
value.
• Hill climbing does not look ahead beyond the
immediate neighbors of the current state.
• In simple terms, no search tree is maintained
in this algorithm.

A.I., KCS-071, Manoj Mishra 154


Hill Climbing Search
• Algorithm:
– Step 1: Determine successors of current state.
– Step 2: Choose successor of maximum goodness
(break ties randomly).
– Step 3: If goodness of best successor is less than
current state’s goodness, stop.
– Step 4: Otherwise make best successor the
current state and go to step 1.

A.I., KCS-071, Manoj Mishra 155


Hill Climbing Search
• Hill climbing is sometimes called greedy local
search because it grabs a good neighbor state
without thinking ahead about where to go
next.
• Hill climbing often makes very rapid progress
towards a solution, because it is usually quite
easy to improve a bad state.

A.I., KCS-071, Manoj Mishra 156


Hill Climbing Search
• Unfortunately, hill climbing often gets stuck for
the following reasons:
– Local maxima: A local maximum is a peak that is
higher than each of its neighboring states, but lower
than global maximum. Here, once the top of a hill is
reached the algorithm will halt since every possible
step leads down.
– Ridges: Ridges result in a sequence of local maxima
that is very difficult for greedy algorithms to navigate.
If the landscape contains ridges, local improvements
may follow a zigzag path up the ridge, slowing down
the search.

A.I., KCS-071, Manoj Mishra 157


Hill Climbing Search
– Plateaux: A plateau is an area of the state space
landscape where the evaluation function is flat. It
can be a flat local maximum, from which no uphill
exit exists, or a shoulder, from which it is possible
to make progress.
• Note:
– If the landscape is flat, meaning many states have the same
goodness, algorithm degenerates to a random walk.
– Shape of state space landscape strongly influences the success
of the search process. A very spiky surface which is flat in
between the spikes will be very difficult to solve.

A.I., KCS-071, Manoj Mishra 158


Hill Climbing Search
• Hill climbing is named after those situations where the
biggest number is the best (benefit rather than the
cost).
• If the algorithm is constantly following the direction
which gives the fastest rate of increase, then it is called
steepest ascent hill climbing.
• In case the lowest cost is the best then this is down hill
algorithm.
• However, the algorithm is prepared to back up and try
a different path if the steepest one leads to a dead end.
That is why the hill climbing is called steepest rise with
back tracking search method.

A.I., KCS-071, Manoj Mishra 159


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 5
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Comparison of search methods
• Each search procedure discussed till now has an
advantage as discussed below:
– Non-deterministic (Blind) search is good when we are
not sure whether depth-first or breadth-first would be
better.
– Depth-first is good when unproductive partial paths
are never too long or if we always prefer to work from
the state we generated last.
– Breadth-first is good when the branching factor is
never too long or if we prefer status which were
generated earlier in time.
– Hill climbing is good when we prefer any state which
looks better than the current state, according to some
heuristic function.
A.I., KCS-071, Manoj Mishra 161
Comparison of search methods
– Both simple hill climbing and steepest ascent hill
climbing may fail to find a solution. Either algorithm
may terminate by not finding a goal state but by
getting to a state from which no better states can be
generated.
– Best-first search is good when there is a natural
measure of goal distance and a good partial path may
look like a bad option before more promising partial
paths are played out or in other words, when state
preference rules prefer the state with highest heuristic
score. Best-first search finds the optimal solution but
this is not the case always.
– A* search is both complete and optimal. It finds the
cheapest solution.
A.I., KCS-071, Manoj Mishra 162
Adversarial Search
• Game playing is a search technique and is often called
adversarial search.
• Competitive environments, in which the agent’s goals
are in conflict, give rise to adversarial search.
• While we are doing our best to find solution, our
opponent (i.e., adversary) is trying to beat us. Hence,
the opponent not only introduces uncertainty but also
wants to win.
• Therefore, adversarial search technique is a mixture of
reasoning and creativity and needs the best of human
intelligence.

A.I., KCS-071, Manoj Mishra 163


Adversarial Search
• Game playing can be formally defined as a
kind of search problem with the following
components:
– Initial state of the game
– Operators defining legal moves
– Successor function
– Terminal test defining end of game state
– Goal test
– Path cost/utility/pay-off function

A.I., KCS-071, Manoj Mishra 164


Adversarial Search
• In AI, games are usually of a rather specialized kind –
what game theorists call deterministic, turn-taking,
two-player, zero-sum games of perfect information.
• In simple language, this means that the game is
deterministic and has fully observable environments in
which there are two agents whose actions must
alternate and in which utility values at the end of the
game are always equal and opposite.
• Games like chess and checkers are perfect information
deterministic games whereas games like scrabble and
bridge are imperfect information.

A.I., KCS-071, Manoj Mishra 165


Game Trees
• The above category of games can be represented
as a tree where the nodes represent the current
state of the game and the arcs represent the
moves.
• The game tree consists of all possible moves for
the current players starting at the root and all
possible moves for the next player as the children
of these nodes, and so forth, as far into the
future of the game as desired.
• Each individual move by one player is called a
“ply”.

A.I., KCS-071, Manoj Mishra 166


Game Trees
• The leaves of the game tree represent terminal
positions as one where the outcome of the game
is clear (a win, a loss, a draw, a pay-off).
• Each terminal position has a score.
• High scores are good for one of the player, called
the MAX player.
• The other player, called MIN player, tries to
minimize the score.
• For ex., we may associate 1 with a win, 0 with a
draw and -1 with a loss for MAX.

A.I., KCS-071, Manoj Mishra 167


Minimax Procedure
• The heuristic search techniques are not
directly applicable to the search for a winning
strategy in board games.
• The basic difficulty is that there is not a single
searcher for the path from source to goal
state.
• Rather, games involve two players determined
to defeat each other. This fundamentally alters
the nature of the search to be conducted.

A.I., KCS-071, Manoj Mishra 168


Minimax Procedure
• The minimax search procedure is a depth-first, depth-
limited search procedure.
• The procedure is based on the idea that we start at the
current position and use the plausible-move generator to
generate the set of possible successor positions.
• Then we apply the static evaluation function to those
positions and simply choose the best one.
• In other words, the plausible-move generator generates the
necessary states for further evaluation and the static
evaluation function ranks each of the positions.
• After this is done, we can back that value up to the starting
position to represent our evaluation of it.

A.I., KCS-071, Manoj Mishra 169


Minimax Procedure
• Hence we have two heuristic rules which state:
– When A has the option to move, he will always choose
the alternative which leads to the MAXIMUM benefits
to him, that is, he will move to the subsequent state
with the largest value of fj.
– When B has option to move, he will always choose the
alternative which leads to the MINIMUM benefits for
player A, that is, he will move to the subsequent state
with the smallest value of fj.

A.I., KCS-071, Manoj Mishra 170


Minimax Procedure
• This process is repeated for as many ply as time
permits.
• The more accurate evaluations that are produced
can be used to choose the correct move at the
top level.
• The alteration of maximizing and minimizing at
alternate ply when evaluations are being pushed
back up corresponds to the opposing strategies of
the two players. Hence this method is called
minimax.
A.I., KCS-071, Manoj Mishra 171
Minimax Procedure
• Features of minimax procedure:
– It assumes a perfect opponent, that is the player B
never makes a bad move from his point of view.
– The larger the number of look-ahead ply, the more
information can be brought to bear in evaluating the
current move.
• In the extreme case of a very simple game in
which an exhaustive search is possible, all nodes
are evaluated, and the win/loss/draw information
can be propagated back up the tree to indicate
precisely the optimum move for player A.

A.I., KCS-071, Manoj Mishra 172


Minimax Procedure
• Limitations of minimax procedure:
– The effectiveness of minimax procedure is limited
by the depth of the game tree, which itself is
limited by the time needed to construct and
analyze it (the time increases exponentially with
the depth of the tree).
– There is another risk involved in the minimax
heuristic: a rapid tie between the assigned and
actual value to static evaluation function fails to
decide the expansion of the game tree.

A.I., KCS-071, Manoj Mishra 173


Example:
• Consider a game which has 4 final states and
paths to reach final state are from root to 4
leaves of a perfect binary tree as shown
below. Assume you are the maximizing player
and you get the first chance to move, i.e., you
are at the root and your opponent at next
level. Which move you would make as a
maximizing player considering that your
opponent also plays optimally?
1/6/2024 A.I., KCS-071, Manoj Mishra 174
1/6/2024 A.I., KCS-071, Manoj Mishra 175
Solution
• Since this is a backtracking based algorithm, it tries all
possible moves, then backtracks and makes a decision.
• Maximizer goes LEFT: It is now the minimizers turn. The
minimizer now has a choice between 3 and 5. Being the
minimizer it will definitely choose the least among both,
that is 3
• Maximizer goes RIGHT: It is now the minimizers turn. The
minimizer now has a choice between 2 and 9. He will
choose 2 as it is the least among the two values.
• Being the maximizer you would choose the larger value
that is 3. Hence the optimal move for the maximizer is to go
LEFT and the optimal value is 3.
• Now the game tree looks like below :

1/6/2024 A.I., KCS-071, Manoj Mishra 176


Solution:Contd..
The above tree shows two possible scores when maximizer makes left and right
moves.
Note: Even though there is a value of 9 on the right subtree, the minimizer will never
pick that. We must always assume that our opponent plays optimally.

1/6/2024 A.I., KCS-071, Manoj Mishra 177


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – II
Lecture – 6
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Alpha-Beta Pruning
• Alpha-Beta pruning is a method that reduces the
number of nodes explored in minimax strategy.
• It reduces the time required for the search and it
must be restricted so that no time is to be wasted
searching moves that are obviously bad for the
current player.
• The exact implementation of alpha-beta keeps
track of the best move for each side as it moves
throughout the tree.
Artificial Intelligence, KCS-071, Manoj
1/6/2024
Mishra
Alpha-Beta Pruning
• In this process, the minimax procedure works
under two bounds, one for each player.
• It requires the maintenance of two threshold
values, one representing the lower bound on the
value that a maximizing node may ultimately be
assigned (call it alpha) and another representing
an upper bound on the value that a minimizing
node may be assigned (call it beta).
• So, the alpha-beta pruning is a form of branch
and bound technique.
Artificial Intelligence, KCS-071, Manoj
1/6/2024
Mishra
Alpha-Beta Pruning
• Alpha is defined as the lower limit (bound) on
the value of the maximize or accordingly the
value of alpha will assume the largest of the
minimum values generated from expanding
successive B nodes at a given level (ply).
• Once a successor node from any B node at
that level is evaluated as less than alpha, that
node and all its successor may be pruned.

Artificial Intelligence, KCS-071, Manoj


1/6/2024
Mishra
Alpha-Beta Pruning
• Alpha-beta pruning can be applied to trees of any
depth, and it is often possible to prune entire sub
trees rather than just leaves.
• The general principle is this:
– “Consider a node ‘n’ somewhere in the tree, such that
player has a choice of moving to that node. If player
has a better choice ‘m’ either at the parent node of ‘n’
or at any choice point further up, then ‘n’ will never
be reached in actual ply. So once we have found out
enough about ‘n’ by examining some of its
descendants to reach this conclusion, we can prune
it.”

Artificial Intelligence, KCS-071, Manoj


1/6/2024
Mishra
Alpha-Beta Pruning
• Illustration of Alpha-Beta pruning (or cut-off):
– The two golden rules that are used in the alpha-
beta cut-off strategy are:
• R1: for maximizers, if the static evaluation function
value formed at any node is less than the alpha-
value, reject it.
• R2: for minimizers, if the static evaluation function
value found at any node is greater than the beta-
value, reject it.

Artificial Intelligence, KCS-071, Manoj


1/6/2024
Mishra
Alpha-Beta Pruning
• Effectiveness of Alpha-Beta algorithm:
– The effectiveness of alpha-beta procedure depends
greatly on the order in which the paths are examined.
– In case if the worst paths are examined first, then no
cutoffs will occur at all.
– However, if the best path is known in advance, so that
we may examine it first, the search process would not
be needed.
– However, if we know how effective the pruning
technique is in the perfect case, we would have an
upper bound on its performance in other situations.
Artificial Intelligence, KCS-071, Manoj
1/6/2024
Mishra
Example

1/6/2024 A.I., KCS-071, Manoj Mishra 185


solution
• The initial call starts from A. The value of alpha here is
-INFINITY and the value of beta is +INFINITY. These
values are passed down to subsequent nodes in the
tree. At A the maximizer must choose max of B and C,
so A calls B first At B it the minimizer must choose min
of D and E and hence calls D first.At D, it looks at its left
child which is a leaf node. This node returns a value of
3. Now the value of alpha at D is max( -INF, 3) which is
3.To decide whether its worth looking at its right node
or not, it checks the condition beta<=alpha. This is false
since beta = +INF and alpha = 3. So it continues the
search.

1/6/2024 A.I., KCS-071, Manoj Mishra 186


Solution Contd..
• D now looks at its right child which returns a value of
5.At D, alpha = max(3, 5) which is 5. Now the value of
node D is 5D returns a value of 5 to B. At B, beta = min(
+INF, 5) which is 5. The minimizer is now guaranteed a
value of 5 or lesser. B now calls E to see if he can get a
lower value than 5.At E the values of alpha and beta is
not -INF and +INF but instead -INF and 5 respectively,
because the value of beta was changed at B and that is
what B passed down to ENow E looks at its left child
which is 6. At E, alpha = max(-INF, 6) which is 6. Here
the condition becomes true. beta is 5 and alpha is 6. So
beta<=alpha is true. Hence it breaks and E returns 6 to
B.

1/6/2024 A.I., KCS-071, Manoj Mishra 187


Solution Contd..
• Note how it did not matter what the value of E‘s
right child is. It could have been +INF or -INF, it
still wouldn’t matter, We never even had to look
at it because the minimizer was guaranteed a
value of 5 or lesser. So as soon as the maximizer
saw the 6 he knew the minimizer would never
come this way because he can get a 5 on the left
side of B. This way we didn’t have to look at that
9 and hence saved computation time.E returns a
value of 6 to B. At B, beta = min( 5, 6) which is
5.The value of node B is also 5

1/6/2024 A.I., KCS-071, Manoj Mishra 188


So far this is how our game tree looks. The 9 is crossed out
because it was never computed .

1/6/2024 A.I., KCS-071, Manoj Mishra 189


Solution Contd..
• B returns 5 to A. At A, alpha = max( -INF, 5)
which is 5. Now the maximizer is guaranteed a
value of 5 or greater. A now calls C to see if it
can get a higher value than 5.At C, alpha = 5
and beta = +INF. C calls FAt F, alpha = 5 and
beta = +INF. F looks at its left child which is a
1. alpha = max( 5, 1) which is still 5.F looks at
its right child which is a 2. Hence the best
value of this node is 2. Alpha still remains 5
1/6/2024 A.I., KCS-071, Manoj Mishra 190
Solution Contd…
• F returns a value of 2 to C. At C, beta = min( +INF, 2).
The condition beta <= alpha becomes true as beta = 2
and alpha = 5. So it breaks and it does not even have to
compute the entire sub-tree of G.The intuition behind
this break-off is that, at C the minimizer was
guaranteed a value of 2 or lesser. But the maximizer
was already guaranteed a value of 5 if he choose B. So
why would the maximizer ever choose C and get a
value less than 2 ? Again you can see that it did not
matter what those last 2 values were. We also saved a
lot of computation by skipping a whole sub-tree.C now
returns a value of 2 to A. Therefore the best value at A
is max( 5, 2) which is a 5.Hence the optimal value that
the maximizer can get is 5

1/6/2024 A.I., KCS-071, Manoj Mishra 191


This is how our final game tree looks like. As you can see G has
been crossed out as it was never computed.

1/6/2024 A.I., KCS-071, Manoj Mishra 192


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023- 24
Unit – III
Lecture – 1
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
KNOWLEDGE REPRESENTATION:TOPICS

First order Predicate Logic

Prolog Programming, Unification

Forward Chaining, Backward Chaining, Resolution

Knowledge Representation

Ontological Engineering, categories and objects, events

Mental event and mental objects


Reasoning system for categories

Reasoning with default Information.


Knowledge Representation
• Knowledge Representation (KR) is an area of
artificial intelligence research aimed at
representing knowledge in symbols to facilitate
inferencing from those knowledge elements,
creating new elements of knowledge.
• The KR can be made to be independent of the
underlying knowledge model or knowledge base
system (KBS) such as a semantic network.

A.I., KCS-071, Manoj Mishra 195


Knowledge Representation
• The primary component of a knowledge-
based agent is its knowledge-base.
– A knowledge-base is a set of sentences.
– Each sentence is expressed in a language called
the knowledge representation language.
– Sentences represent some assertions about the
world.
– There must be mechanisms to derive new
sentences from old ones. This process is known as
inferencing or reasoning.

A.I., KCS-071, Manoj Mishra 196


Knowledge Representation
– Inference must obey the primary requirement that
the new sentences should follow logically from
the previous ones.
– Logic is the primary vehicle for representing and
reasoning about knowledge.
– The advantage of using formal logic as a language
of AI is that it is precise and definite.

A.I., KCS-071, Manoj Mishra 197


Knowledge Representation
• A logic consists of two parts – a language and a method
of reasoning.
• The logical language, in turn, has two aspects, syntax
and semantics.
• Thus to specify or define a particular logic, one needs
to specify three things.
– Syntax: Syntax specifies the symbols in the
language and how they can be combined to form
sentences. Hence, facts about the world are represented
as sentences in logic. It is the atomic symbols of the logical
language, and the rules for constructing well-formed, non-
atomic expressions (symbol structures) of the logic.

A.I., KCS-071, Manoj Mishra 198


Knowledge Representation
– Semantics: It is the meaning of the atomic
symbols of the logic, and the rules for
determining the meanings of non-atomic expressions
of the logic. It specifies what facts in the world a
sentence refers to. A fact is a claim about the world,
and may be true or false.
– Syntactic Inference Method: The rules for
determining a subset of
logical expressions, called theorems of the logic. It
refers to mechanical method for computing (deriving)
new (true) sentences from existing ones.

A.I., KCS-071, Manoj Mishra 199


Characteristics of Knowledge
Representation (KR)
• A good knowledge representation covers six
basic characteristics:
– Coverage – which means the KR covers a
breadth and depth of information.
Without a wide coverage, the KR cannot
determine anything or resolve ambiguities.
– Understandable by humans – KR is viewed as a
natural language,
so the logic should flow freely. It should have
simple primitives that combine in complex forms.

A.I., KCS-071, Manoj Mishra 200


Characteristics of Knowledge
Representation (KR)
– Consistency - By being consistent, the KR can
eliminate redundant or conflicting
knowledge.
– Efficient
– Easiness – for modifying and updating.
– Supports the intelligent activity - which uses the
knowledge base.

A.I., KCS-071, Manoj Mishra 201


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – III
Lecture – 2
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Propositional Logic
• Propositional logic is concerned with
propositions and their interrelationships.
• A proposition is a possible condition of the
world about which we want to say something.
• The condition need not be true in order for us
to talk about it.
• In fact, we might want to say that it is false or
that it is true if some other proposition is true.

A.I., KCS-071, Manoj Mishra 203


Propositional Logic
• In propositional logic, there are two types of
sentences:
– Simple sentences: Simple sentences express
“atomic” propositions about
the world.
– Compound sentences: Compound sentences
express logical
relationships between the simpler sentences of
which they are composed.

A.I., KCS-071, Manoj Mishra 204


Propositional Logic
• There are six types of compound sentences,
viz., negations(¬), conjunctions(˄),
disjunctions(˅), implications(→),
reductions(←) and equivalences(↔).
• Operator precedence: ¬
˄
˅
→←↔
The above is the hierarchy of precedence of operators.

A.I., KCS-071, Manoj Mishra 205


Propositional Logic
• An interpretation for propositional logic is a mapping
assigning a truth value to each of the simple sentences
of the language.
• The assignment shown below is an example of
interpretation ‘i’ on a particular logical language.
pi = true
qi = false
ri = true
• We say that the interpretation ‘i’ satisfies a sentence if
and only if it is true under that interpretation.

A.I., KCS-071, Manoj Mishra 206


Validity, Satisfiability, Unsatisfiability,
Contingent
• Valid: A sentence is valid if and only if it is
satisfied by every interpretation. The
following sentence is valid.
p ˅ ¬p
• Satisfiable: A sentence is satisfiable if and
only if it is satisfied by at least one
interpretation.
A sentence is falsifiable if and only
if there is at least one interpretation that makes it
false.
A.I., KCS-071, Manoj Mishra 207
Validity, Satisfiability, Unsatisfiability,
Contingent
• Unsatisfiable: A sentence is unsatisfiable if
and only if it is not satisfied by
any interpretation. The following sentence is
unsatisfiable.
p ˄ ¬p
• Contingent: A sentence is contingent if and
only if it is both satisfiable and
falsifiable, i.e., it is neither valid nor
unsatisfiable.

A.I., KCS-071, Manoj Mishra 208


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – III
Lecture – 3
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Predicate Logic
• A predicate is a verb phrase template that
describes property of objects, or a relationship
among objects represented by the variables.
• The propositional logic is not powerful enough
to represent all types of assertions that are
used in computer science and mathematics, or
to express certain types of relationship
between propositions such as equivalence.

A.I., KCS-071, Manoj Mishra 210


Predicate Logic
• To cope up with deficiencies of propositional logic, two
new features are introduced: predicates and
quantifiers.
– For ex., the sentence “The car Tom is driving is blue”, “The
sky is blue” and “The cover of this book is blue” come from
the template “is blue”. The phrase “is blue” is a predicate
and it describes the property of being blue.
– Predicates are often given a name. For ex., “B” can be used
to represent the predicate “is blue” among others. If we
adopt B as the name for the predicate “is blue”, sentences
that assert an object “is blue” can be represented as B(x)
where ‘x’ represents an arbitrary object. B(x) reads as “x is
blue”.

A.I., KCS-071, Manoj Mishra 211


Representing facts with predicate
logic
• Let us consider a specific example of representing
knowledge using predicate logic.
• Let us consider the following sentences.
1) Marcus was a man.
2) Marcus was a Pompeian.
3) All Pompeians were Romans.
4) Caesar was a ruler.
5) All Romans were either loyal to Caesar or hated him.
6) Everyone is loyal to someone.
7) People only try to assassinate rulers they are not loyal to.
8) Marcus tried to assassinate Caesar.
9) All men are people.

A.I., KCS-071, Manoj Mishra 212


Representing facts with predicate
logic
• These can be represented in predicate logic as follows:
1) man(Marcus)
2) Pompeian(Marcus)
3) ɏx : Pompeian(x) → Roman(x)
4) ruler(Caesar)
5) ɏx : Roman(x) → loyalto(x, Caesar) ˅ hate(x, Caesar)
6) ɏx : →y : loyalto(x, y)
7) ɏx : ɏy : person(x) ˄ ruler(y) ˄ tryassassinate(x, y) →
¬loyalto(x, y)
8) tryassassinate(Marcus, Caesar)
9) ɏx : man(x) → person(x)

A.I., KCS-071, Manoj Mishra 213


Representing facts with predicate
logic
• Now, suppose that we want to use these
statements to answer the question
“Was Marcus loyal to Caesar?”
• It seems that using 7 and 8, we should be able
to prove that “Marcus was not loyal to
Caesar”.
• Now let’s produce a formal proof, reasoning
backward from the desired goal.

A.I., KCS-071, Manoj Mishra 214


Representing facts with predicate
logic
¬loyalto(Marcus, Caesar)
↑ (7, substitution)
person(Marcus) ˄ ruler(Caesar) ˄ tryassassinate(Marcus, Caesar)
↑ (4)
person(Marcus) ˄ tryassassinate(Marcus, Caesar)
↑ (8)
person(Marcus)
↑ (9)
man(Marcus)
↑ (1)
Nil

Since the answer obtained is nil, so the given set of predicates


satisfy the desired goal.
Hence, Marcus was not loyal to Caesar.
A.I., KCS-071, Manoj Mishra
(proved) 215
Representing facts with predicate
logic
• From this simple example, we see that three important
issues must be addressed in the process of converting
English sentences into logical statements and then
using those statements to deduce new ones:
– Many English sentences are ambiguous (for ex., 5, 6 and 7
above). Choosing the correct interpretation may be
difficult.
– There is often a choice of how to represent knowledge.
Simple representations are desirable, but they may
exclude certain kinds of reasoning.
– Even in very simple situations, a set of sentences is unlikely
to contain all the information necessary to reason about
the topic at hand.

A.I., KCS-071, Manoj Mishra 216


Artificial Intelligence (KCS-071)
4th year (Semester – VII)
Session – 2023 - 24
Unit – III
Lecture – 4
Manoj Mishra
Asst. Prof.
CSE Dept.
UCER, Prayagraj
Representing facts with predicate
logic
• An additional problem arises in situations where
we do not know in advance which statements to
deduce.
• In the example just presented, the object was to
answer the question “Was Marcus loyal to
Caesar?”
• How would a program decide whether to prove
loyalto(Marcus, Caesar)
or ¬loyalto(Marcus, Caesar)

A.I, KCS-071, Manoj Mishra 218


Representing facts with predicate
logic
• There are several things it could do.
– It could abandon the strategy we have outlined of
reasoning backward from a proposed truth to the
axioms and instead try to reason forward and see
which answer it gets to. The problem with this
approach is that, in general, the branching factor
going forward from the axioms is so great that it
would probably not get to either answer in any
reasonable amount of time.

A.I, KCS-071, Manoj Mishra 219


Representing facts with predicate
logic
– A second thing it could do is use some sort of heuristic
rules for deciding which answer is more likely and
then try to prove that one first. If it fails to find a proof
after some reasonable amount of effort, it can try the
other answer.
– Another thing it could do is simply try to prove both
answers simultaneously and stop when one effort is
successful. Even here, however, if there is not enough
information available to answer the question with
certainty, the program may never halt.
– A fourth strategy is to try both to prove one another
and to disprove it, and to use information gained in
one of the processes to guide the other.

A.I, KCS-071, Manoj Mishra 220


Representing facts with predicate
logic
• Let us try another example
“Did Marcus hate Caesar?”
• Now, let us try to prove “Marcus hated Caesar”

hate(Marcus, Caesar)
↑(5, substitution)
Roman(Marcus) ˄ ¬loyalto(Marcus, Caesar)
↑(3, substitution)
Pompeian(Marcus) ˄ ¬loyalto(Marcus, Caesar)
↑(2)

A.I, KCS-071, Manoj Mishra 221


Representing facts with predicate
logic
¬loyalto(Marcus, Caesar)
↑ (7, substitution)
person(Marcus) ˄ ruler(Caesar) ˄ tryassassinate(Marcus, Caesar)
↑ (4)
person(Marcus) ˄ tryassassinate(Marcus, Caesar)
↑ (8)
person(Marcus)
↑ (9)
man(Marcus)
↑ (1)
Nil

Since the answer obtained is nil, so the given set of predicates


satisfy the desired goal.
Hence, Marcus hated Caesar. (proved)
A.I, KCS-071, Manoj Mishra 222
Computable functions and predicates
• Suppose we want to express simple facts, such
as greater-than and less-than relationships,
which is shown as below.
gt(1,0) lt(0,1)
gt(2,1) lt(1,2)
gt(3,2) lt(2,3)
• Such relationships representation are called as
computable predicates. These predicates
evaluate rules and return true or false.
A.I, KCS-071, Manoj Mishra 223
Computable functions and predicates
• Let us consider the following set of facts, again
involving Marcus:
1) Marcus was a man.
2) Marcus was a Pompeian.
3) Marcus was born in 40 A.D.
4) All men are mortal.
5) All Pompeians died when the volcano erupted in 79 A.D.
6) No mortal lives longer than 150 years.
7) It is now 1991.
8) Alive means not dead.
9) If someone dies, then he is dead at all later times.

A.I, KCS-071, Manoj Mishra 224


Computable functions and predicates
• These can be represented in predicate logic as follows:
1) man(Marcus)
2) Pompeian(Marcus)
3) born(Marcus, 40)
4) ɏx : man(x) → mortal(x)
5) erupted(volcano, 79) ˄ ɏx : [Pompeian(x) →
died(x, 79)]
6) ɏx : ɏt1 : ɏt2 : mortal(x) ˄ born(x, t1) ˄ gt(t2 – t1, 150)
→ dead(x, t2)
7) now = 1991
8) ɏx : ɏt : [alive(x, t) → ¬dead(x, t)] ˄ [¬dead(x, t) → alive(x, t)]
9) ɏx : ɏt1 : ɏt2 : died(x, t1) ˄ gt(t2, t1) → dead(x, t2)

A.I, KCS-071, Manoj Mishra 225


Computable functions and predicates
• Now let’s attempt to answer the question
“Is Marcus alive?”
• Now, let us try to prove “Marcus is not alive”.
¬alive(Marcus, now)
↑ (8, substitution)
dead(Marcus, now)
↑ (9, substitution)
died(Marcus, t1) ˄ gt(now, t1)
↑ (5, substitution)
Pompeian(Marcus) ˄ gt(now, 79)
↑ (2)
gt(now, 79)
` ↑ (7, substitute equals)
gt(1991, 79)
↑ (compute gt)
Nil
Since the answer obtained is nil, so the given set of predicates satisfy the desired
goal.
A.I, KCS-071, Manoj Mishra 226
Hence, Marcus is not alive. (proved)
Computable functions and predicates
• Another way of proving that “Marcus is not alive”.
¬alive(Marcus, now)
↑ (8, substitution)
dead(Marcus, now)
↑ (6, substitution)
mortal(Marcus) ˄ born(Marcus, t1) ˄ gt(now – t1, 150)
↑ (4, substitution)
man(Marcus) ˄ born(Marcus, t1) ˄ gt(now – t1, 150)
↑ (1)
born(Marcus, t1) ˄ gt(now – t1, 150)
↑ (3)
gt(now – 40, 150)
` ↑ (7, substitute equals)
gt(1991 – 40, 150)
↑ (compute minus)
gt(1951, 150)
↑ (compute gt)
Nil
Since the answer obtained is nil, so the given set of predicates satisfy the desired goal.
Hence, Marcus is not alive. (proved)

A.I, KCS-071, Manoj Mishra 227


ARTIFICIAL INTELLIGENCE
Artificial Intelligence(AI)

UNIT-3
KNOWLEDGE
REPRESENTATION

Manoj Mishra (Asst. Professor)


Department of Computer Science & Engineering
United College of Engineering & Research,
Prayagraj
KNOWLEDGE REPRESENTATION

•Knowledge representation and reasoning (KR, KRR) is the part of


Artificial intelligence which concerned with AI agents thinking and how
thinking contributes to intelligent behavior of agents.

•It is responsible for representing information about the real world so that
a computer can understand and can utilize this knowledge to solve the
complex real world problems such as diagnosis a medical condition or
communicating with humans in natural language.

•It is also a way which describes how we can represent knowledge in


artificial intelligence. Knowledge representation is not just storing data
into some database, but it also enables an intelligent machine to learn
from that knowledge and experiences so that it can behave intelligently
like a human.
Following are the kind of knowledge which needs to be represented in
AI systems:

Object: All the facts about objects in our world domain. E.g., Guitars
contains strings, trumpets are brass instruments.

Events: Events are the actions which occur in our world.

Performance: It describe behavior which involves knowledge about


how to do things.

Meta-knowledge: It is knowledge about what we know.


Facts: Facts are the truths about the real world and what we
represent.

Knowledge-Base: The central component of the knowledge-


based agents is the knowledge base. It is represented as KB.
The Knowledgebase is a group of the Sentences (Here,
sentences are used as a technical term and not identical with
the English language).

Knowledge: Knowledge is awareness or familiarity gained by


experiences of facts, data, and situations. Following are the
types of knowledge in artificial intelligence:
Types of knowledge:

Declarative Knowledge:
•Declarative knowledge is to know about something.
•It includes concepts, facts, and objects.
•It is also called descriptive knowledge and expressed in declarative
sentences.
•It is simpler than procedural language.

2. Procedural Knowledge
•It is also known as imperative knowledge.
•Procedural knowledge is a type of knowledge which is responsible for
knowing how to do something.
•It can be directly applied to any task.
•It includes rules, strategies, procedures, agendas, etc.
•Procedural knowledge depends on the task on which it can be applied.
Meta-knowledge:
Knowledge about the other types of knowledge is called Meta-knowledge.

4. Heuristic knowledge:
•Heuristic knowledge is representing knowledge of some experts in a filed
or subject.
•Heuristic knowledge is rules of thumb based on previous experiences,
awareness of approaches, and which are good to work but not guaranteed.

5. Structural knowledge:
•Structural knowledge is basic knowledge to problem-solving.
•It describes relationships between various concepts such as kind of, part of,
and grouping of something.
•It describes the relationship that exists between concepts or objects.
Approaches to knowledge representation:

Simple relational knowledge:


It is the simplest way of storing facts which uses the relational method, and
each fact about a set of the object is set out systematically in columns.
This approach of knowledge representation is famous in database systems
where the relationship between different entities is represented.

This approach has little opportunity for inference.


Inheritable knowledge:

•In the inheritable knowledge approach, all data must be stored into a hierarchy
of classes.
•All classes should be arranged in a generalized form or a hierarchal manner. In
this approach, we apply inheritance property. Elements inherit values from
other members of a class.
•This approach contains inheritable knowledge which shows a relation between
instance and class, and it is called instance relation.
•Every individual frame can represent the collection of attributes and its value.
In this approach, objects and values are represented in Boxed nodes.
•We use Arrows which point from objects to their values.
Inferential knowledge:
•Inferential knowledge approach represents knowledge in the form
of formal logics.
•This approach can be used to derive more facts.
•It guaranteed correctness.

Example: Let's suppose there are two statements:


Marcus is a man
All men are mortal
Then it can represent as;

man(Marcus)
∀x = man (x) ----------> mortal (x)s
Procedural knowledge:
•Procedural knowledge approach uses small programs and codes
which describes how to do specific things, and how to proceed.

•In this approach, one important rule is used which is If-Then rule.

•In this knowledge, we can use various coding languages such as


LISP language and Prolog language.

•We can easily represent heuristic or domain-specific knowledge


using this approach. But it is not necessary that we can represent all
cases in this approach.
Requirements for knowledge Representation system:

1. Representational Accuracy:
KR system should have the ability to represent all kind of required
knowledge.

2. Inferential Adequacy:
KR system should have ability to manipulate the representational
structures to produce new knowledge corresponding to existing
structure.

3. Inferential Efficiency:
The ability to direct the inferential knowledge mechanism into the
most productive directions by storing appropriate guides.

4. Acquisitional efficiency- The ability to acquire the new knowledge


easily using automatic methods.
Techniques of knowledge representation

There are mainly four ways of knowledge representation which are given as
follows:
Logical Representation
Semantic Network Representation
Frame Representation
Production Rules
Fig: Knowledge representation Technique
Logical Representation
•Logical representation is a language with some concrete rules which
deals with propositions and has no ambiguity in representation.
•Logical representation means drawing a conclusion based on various
conditions.
•This representation lays down some important communication rules.
•It consists of precisely defined syntax and semantics which supports the
sound inference.
•Each sentence can be translated into logics using syntax and semantics.

Syntax:

•Syntaxes are the rules which decide how we can construct legal
sentences in the logic.
•It determines which symbol we can use in knowledge representation.
•How to write those symbols.
Semantics:
•Semantics are the rules by which we can interpret the sentence in the
logic.
•Semantic also involves assigning a meaning to each sentence.

Logical representation can be categorized into mainly two logics:


Propositional Logics
Predicate logics
Advantages of logical representation:
•Logical representation enables us to do logical reasoning.
•Logical representation is the basis for the programming languages.

Disadvantages of logical Representation:


•Logical representations have some restrictions and are challenging
to work with.
•Logical representation technique may not be very natural, and
inference may not be so efficient.
•Semantic Network Representation

•Semantic networks are alternative of predicate logic for knowledge


representation. In Semantic networks, we can represent our
knowledge in the form of graphical networks.

•This network consists of nodes representing objects and arcs which


describe the relationship between those objects.

•Semantic networks can categorize the object in different forms and


can also link those objects.

•Semantic networks are easy to understand and can be easily


extended.
•This representation consist of mainly two types of relations:
•IS-A relation (Inheritance)
•Kind-of-relation

•Example: Following are some statements which we need to


represent in the form of nodes and arcs.

Statements:
•Jerry is a cat.
•Jerry is a mammal
•Jerry is owned by Priya.
•Jerry is brown colored.
•All Mammals are animal.
In the above diagram, we have represented the different type of
knowledge in the form of nodes and arcs. Each object is
connected with another object by some relation.
Drawbacks in Semantic representation:

•Semantic networks take more computational time at runtime as we


need to traverse the complete network tree to answer some
questions.
•It might be possible in the worst case scenario that after traversing
the entire tree, we find that the solution does not exist in this
network.
•Semantic networks try to model human-like memory (Which has
1015 neurons and links) to store the information, but in practice, it
is not possible to build such a vast semantic network.

•These types of representations are inadequate as they do not have


any equivalent quantifier, e.g., for all, for some, none, etc.
•Semantic networks do not have any standard definition for the
link names.

•These networks are not intelligent and depend on the creator of


the system.

.
Advantages of Semantic network:
•Semantic networks are a natural representation of knowledge.
•Semantic networks convey meaning in a transparent manner.
•These networks are simple and easily understandable
Frame Representation

A frame is a record like structure which consists of a collection of


attributes and its values to describe an entity in the world.

Frames are the AI data structure which divides knowledge into


substructures by representing stereotypes situations.

It consists of a collection of slots and slot values. These slots may


be of any type and sizes. Slots have names and values which are
called facets.

Facets: The various aspects of a slot is known as Facets. Facets are


features of frames which enable us to put constraints on the frames.
Example: IF-NEEDED facts are called when data of any
particular slot is needed. A frame may consist of any number of
slots, and a slot may include any number of facets and facets may
have any number of values. A frame is also known as slot-filter
knowledge representation in artificial intelligence.

Frames are derived from semantic networks and later evolved into
our modern-day classes and objects. A single frame is not much
useful. Frames system consist of a collection of frames which are
connected. In the frame, knowledge about an object or event can
be stored together in the knowledge base. The frame is a type of
technology which is widely used in various applications including
Natural language processing and machine visions.
Advantages of frame representation:
•The frame knowledge representation makes the programming
easier by grouping the related data.
•The frame representation is comparably flexible and used by
many applications in AI.
•It is very easy to add slots for new attribute and relations.
•It is easy to include default data and to search for missing
values.
•Frame representation is easy to understand and visualize.
Disadvantages of frame representation:
•In frame system inference mechanism is not be easily
processed.
•Inference mechanism cannot be smoothly proceeded by frame
representation.
•Frame representation has a much generalized approach.
Production Rules

Production rules system consist of (condition, action) pairs


which mean, "If condition then action".

It has mainly three parts:


The set of production rules
Working Memory
The recognize-act-cycle

•In production rules agent checks for the condition and if the
condition exists then production rule fires and corresponding
action is carried out.
• The condition part of the rule determines which rule may be
applied to a problem. And the action part carries out the
associated problem-solving steps.
•This complete process is called a recognize-act cycle.

•The working memory contains the description of the current


state of problems-solving and rule can write knowledge to the
working memory. This knowledge match and may fire other
rules.
•If there is a new situation (state) generates, then multiple
production rules will be fired together, this is called conflict
set. In this situation, the agent needs to select a rule from these
sets, and it is called a conflict resolution.
Example:
IF (at bus stop AND bus arrives) THEN action (get into the bus)
IF (on the bus AND paid AND empty seat) THEN action (sit down).
IF (on bus AND unpaid) THEN action (pay charges).
IF (bus arrives at destination) THEN action (get down from the bus).
Advantages of Production rule:
The production rules are expressed in natural language.
The production rules are highly modular, so we can easily
remove, add or modify an individual rule.

Disadvantages of Production rule:


Production rule system does not exhibit any learning
capabilities, as it does not store the result of the problem
for the future uses.

During the execution of the program, many rules may be


active hence rule-based production systems are inefficient.
First-Order logic:

First-order logic is also known as Predicate logic or First-order predicate logic (FOI).
First-order logic is a powerful language that develops information about the objects in a
more easy way and can also express the relationship between those objects.

It is an extension to propositional logic.

FOL is sufficiently expressive to represent the natural language statements in a concise


way.

First-order logic (like natural language) does not only assume that the world contains
facts like propositional logic but also assumes the following things in the world:

Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation
such as: the sister of, brother of, has color, comes between
Function: Father of, best friend, third inning of, end of, ......
As a natural language, first-order logic also has two main parts: Syntax &
Semantics
What is Unification?
•Unification is a process of making two different logical atomic expressions identical by finding
a substitution. Unification depends on the substitution process.
•It takes two literals as input and makes them identical using substitution.
•Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it can be
expressed as UNIFY(Ψ1, Ψ2).
•Example: Find the MGU for Unify{King(x), King(John)}
Let Ψ1 = King(x), Ψ2 = King(John),
Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and both
expressions will be identical.
•Substitution θ = {John/x} is a unifier for these atoms and applying this substitution,
and both expressions will be identical.
•The UNIFY algorithm is used for unification, which takes two atomic sentences and
returns a unifier for those sentences (If any exist).
•Unification is a key component of all first-order inference algorithms.
•It returns fail if the expressions do not match with each other.
•The substitution variables are called Most General Unifier or MGU.
•E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
•In this example, we need to make both above statements identical to each other. For
this, we will perform the substitution.
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.
With both the substitutions, the first expression will be identical to the second expression and
the substitution set will be: [a/x, f(z)/y].

Conditions for Unification:


Following are some basic conditions for unification:
•Predicate symbol must be same, atoms or expression with different predicate symbol can
never be unified.
•Number of Arguments in both expressions must be identical.
•Unification will fail if there are two similar variables present in the same expression.
Implementation of the Algorithm
•Step.1: Initialize the substitution set to be empty.
•Step.2: Recursively unify atomic sentences:
•Check for Identical expression match.
•If one expression is a variable vi, and the other is a term ti which does not
contain variable vi, then:
•Substitute ti / vi in the existing substitutions
•Add ti /vi to the substitution setlist.
•If both the expressions are functions, then function name must be similar, and
the number of arguments must be the same in both the expression.
Introduction to Inference in AI

•In the field of Artificial Intelligence, inference is the process


of drawing logical conclusions from available knowledge or
facts.
•Two common strategies for performing inference in AI are:
forward chaining and
backward chaining.
•These methods are used to make decisions, answer queries,
or solve problems by applying logical rules to a set of facts or
initial conditions.
Forward- Chaining & Backward- Chaining

Forward Chaining:
Forward chaining is a data-driven approach to reasoning and inference.
It starts with the available facts and uses rules and knowledge to
derive new conclusions until a desired goal or conclusion is reached.
Key Steps in Forward-Chaining:
Initialization: Start with an initial set of facts or data.
Rule Application: Apply rules and knowledge to derive new facts or
conclusions.
Conflict Resolution: If multiple rules can be applied, resolve conflicts
by selecting the most appropriate rule.
Update Knowledge Base: Add newly derived facts to the knowledge
base.
Repeat: Continue this process until the goal is achieved or no further
rules can be applied.
Example of Forward Chaining

Scenario: Diagnosis of a medical condition.


Initial Facts:
The patient has a high fever.
The patient has a sore throat.
Rules:
1- If the patient has a high fever and a sore throat, then it might be a
sign of a viral infection.
2- If the patient has a viral infection, they should rest and drink fluids.
Forward Chaining Steps:
Start with the initial facts: high fever and sore throat.
Apply rule 1: A viral infection is suggested.
Update knowledge base with the derived fact.
Apply rule 2: The patient should rest and drink fluids.

In this case, forward chaining leads to the conclusion that the patient
should rest and drink fluids as a treatment for the viral infection.
Backward Chaining

Backward chaining is a goal-driven approach to reasoning and


inference. It starts with a goal or query and works backward to
determine the sequence of facts and rules needed to satisfy that
goal.
key steps in backward chaining:

Goal Setting: Begin with a specific goal or query.


Rule Selection: Select a rule that can help achieve the goal.
Subgoal Generation: Break down the goal into subgoals or
conditions that need to be satisfied.
Recursion: Apply backward chaining recursively to satisfy subgoals.
Termination: Continue until a set of facts and rules that can satisfy
the original goal is determined.
Example of Backward Chaining

Scenario: Booking a flight.


Goal: Book a flight from New York to London.
Rules:
If you want to book a flight from City A to City B, you need to find an
available flight.
Backward Chaining Steps:
Start with the goal: Book a flight from New York to London.
Apply rule 1 to generate a subgoal: Find an available flight from New
York to London.
Apply backward chaining recursively to find available flights.

Backward chaining guides the reasoning process toward the goal of


booking a flight from New York to London by breaking it down into
subgoals.
Comparison of Forward Chaining and Backward Chaining

Control Flow: Forward chaining proceeds from known facts to goals,


while backward chaining starts with the goal and works backward to
the facts.
Goal-Oriented: Backward chaining is goal-oriented and focuses on
reaching a specific target, while forward chaining is data-driven and
may explore various conclusions.
Rule Selection: Forward chaining selects rules based on available data,
while backward chaining selects rules based on the goal.
Use Cases: Forward chaining is commonly used in expert systems and
diagnostics, while backward chaining is prevalent in decision support
systems and planning.
Efficiency: The choice between the two depends on the problem;
backward chaining can be more efficient for problems with complex
goals.
Resolution

Resolution is a fundamental and powerful inference rule used in the


field of artificial intelligence and automated reasoning. It is a technique
primarily employed in the context of propositional logic and first-order
logic for logical deduction and theorem proving. Resolution is based on
the concept of refutation, which means proving the negation of a given
statement or goal.
Resolution Principle:
To derive a new clause (a disjunction of literals), resolve two clauses by
selecting complementary literals and then removing those literals.
Here's a step-by-step explanation of the resolution process:
Clause Selection: Choose two clauses that you want to resolve. These
clauses should have at least one complementary literal, i.e., one literal
should be the negation of the other.
Resolution Operation: Apply the resolution operation by unifying the
two clauses and removing the complementary literals. This unification
process generates a resolvent, which is a new clause containing the
remaining literals.
Adding Resolvent: Add the resolvent to the set of clauses.
Repeat: Continue the process until you either derive the empty clause
(representing a contradiction) or until no more resolutions can be
performed.
Example of Resolution

Let's illustrate the resolution process with an example:


Clauses:
(A ∨ B)
(¬B ∨ C)
(¬A ∨ D)
(¬C ∨ ¬D)
Goal: Prove ¬A (i.e., show that A is false).
Resolution Steps:

1- Select clauses (1) and (3) for resolution:


(A ∨ B)
(¬A ∨ D)
2- Apply resolution with A and ¬A:
(B ∨ D)
3- Add the resolvent to the set of clauses:
(B ∨ D)
4- Select clauses (2) and (4) for resolution:
(¬B ∨ C)
(¬C ∨ ¬D)
5- Apply resolution with ¬B and ¬D:
(¬B ∨ ¬D)
Resolution Steps (Contd….)

6- Add the resolvent to the set of clauses:


(¬B ∨ ¬D)
7- Select clauses (3) and (5) for resolution:
(¬A ∨ D)
(¬B ∨ ¬D)
8- Apply resolution with D and ¬D (complementary literals):
(¬A ∨ ¬B)
9- Add the resolvent to the set of clauses:
(¬A ∨ ¬B)
10- Select clauses (1) and (9) for resolution:
(A ∨ B)
(¬A ∨ ¬B)
11- Apply resolution with A and ¬A (complementary literals):
(B ∨ ¬B)
At this point, we have derived the empty clause (B ∨ ¬B), which
represents a contradiction. Therefore, the original goal ¬A has been
proven, which means that A is false.
Key Applications of Resolution

Theorem Proving: Resolution is used in automated theorem proving to


determine the validity of a logical statement or to establish the truth
or falsehood of a given proposition.
Logic Programming: It plays a crucial role in logic programming
languages like Prolog, where it is used to evaluate logical queries and
goals.
Natural Language Processing: Resolution can be applied to natural
language processing tasks, such as semantic analysis and text
understanding, to draw inferences from textual data.
Knowledge Representation: In knowledge-based systems and expert
systems, resolution is used to deduce facts and draw conclusions
based on a knowledge base of rules and facts.
Circuit Verification: Resolution can be used to verify the correctness of
digital circuits by checking for inconsistencies and contradictions in the
circuit design.
Knowledge representation

Knowledge representation is a critical component of artificial


intelligence (AI) systems. It involves the organization and
structuring of information to enable reasoning and problem-
solving.
Approaches to Knowledge Representation:
•Object-Oriented Design
•Top-Down Design
•Bottom-Up Design
Object-Oriented Design (OOD)

Object-Oriented Design (OOD) is a software engineering methodology that has been


adapted for knowledge representation in AI. In OOD, the world is represented as a
collection of objects that interact with each other. These objects encapsulate both
data (attributes) and behavior (methods). Key concepts in OOD include:
Classes: Classes are templates for objects and define their attributes and methods.
Objects: Objects are instances of classes and represent specific entities in the world.
Inheritance: Inheritance allows for the creation of new classes based on existing ones,
promoting code reuse.
Polymorphism: Polymorphism enables different classes to be treated as instances of a
common superclass, facilitating flexibility and extensibility.
Encapsulation: Encapsulation restricts access to certain data and methods, providing
control and security.
Top-Down Design

Top-Down Design is an approach to knowledge representation that starts with a high-


level, abstract view of the world and progressively refines it into more detailed and
specific representations. The key steps in Top-Down Design are as follows:
Problem Identification: Begin by identifying the problem you want to solve or the
domain you want to model.
High-Level Abstraction: Create a high-level, abstract representation of the problem,
often using ontologies or domain-specific languages.
Decomposition: Decompose the high-level abstraction into smaller, more manageable
components.
Refinement: Refine each component, adding details and specifying relationships
between them.
Implementation: Implement the detailed representations using appropriate data
structures and programming constructs.
Top-Down Design is useful when you have a clear understanding of the problem and
can define a high-level model. It promotes a structured and organized approach to
knowledge representation.
Bottom-Up Design

Bottom-Up Design is an approach that starts with specific


observations or data and builds higher-level representations from
these details. The key steps in Bottom-Up Design are as follows:
Data Collection: Collect and analyze data, observations, or facts from
the real world or a problem domain.
Pattern Recognition: Identify patterns, relationships, and structures
within the collected data.
Generalization: Generalize from the observed patterns to create
higher-level, more abstract representations.
Inference and Abstraction: Infer additional information and abstract
concepts from the observed data.
Modeling: Create a knowledge representation based on the derived
abstractions and relationships.
Bottom-Up Design Contd..

Bottom-Up Design is useful when you have a large amount of data or


when the problem domain is not well understood. It allows you to

build a representation that emerges from the data .


Choosing the Right Approach

Top-Down Design is suitable when you have a clear


understanding of the problem and can design a high-level
model that encompasses it.
Bottom-Up Design is preferable when you have a lot of data
or when you need to discover patterns and relationships
within the data.
Hybrid Approaches can combine the strengths of both
methods by first designing a high-level abstraction and then
refining it based on data-driven insights.
Introduction to Ontological Engineering

•Ontological engineering is a discipline within artificial intelligence (AI)


and knowledge representation that focuses on designing and building
ontologies.
•An ontology is a formal and explicit specification of the concepts,
relationships, and properties within a particular domain of knowledge.
•Ontological engineering plays a critical role in AI, enabling the
representation of complex knowledge structures and the development
of reasoning systems.
Categories in Ontological Engineering:

In the context of ontological engineering, categories represent a


fundamental way of classifying and organizing objects, events, and
concepts within a domain.
Categories help in structuring knowledge, and they can be hierarchical
or have various relationships.
Different aspects of categories:
1- Objects
Objects refer to tangible entities within a domain. For example, in a
medical ontology, objects could include "patients," "diseases," or
"medications." Objects are often categorized based on their properties
and relationships.
Categories in Ontological Engineering:( Contd..)

2- Events
Events represent occurrences or happenings within a domain. In a financial
ontology, events might include "stock market crashes" or "economic recessions."
Events are usually related to the objects and concepts in the ontology.
3. Mental Events and Mental Objects
In some knowledge representations, mental events and mental objects are
included to account for cognitive and psychological aspects. Mental events can
include "thoughts" or "perceptions," while mental objects may be "beliefs" or
"emotions."
4. Reasoning Systems for Categories
Ontological engineering also involves the development of reasoning systems that
can manipulate and make inferences about categories within the ontology. These
reasoning systems rely on formal logic, rule-based reasoning, or probabilistic
methods to perform tasks such as classification, deduction, and query answering.
Default Information:

In AI and knowledge representation, default information is used to make inferences


when complete, explicit information is lacking. Default reasoning allows AI systems to
draw conclusions that are not necessarily guaranteed but are generally accepted as
plausible.
Types of Defaults
1. Presumption (Entailment)
Presumption involves assuming that if certain conditions or facts are true, a conclusion
can be presumed to be true. For example, if someone is a vegetarian (condition), you
can presume they don't eat meat (conclusion).
2. Relevance
Relevance reasoning identifies relevant information to a query or conclusion. For
instance, when asked about someone's favorite food, it's relevant to consider their
nationality.
3. Specificity
Specificity reasoning involves being more specific when making inferences. For
example, if someone is a vegetarian but loves sushi, their dietary preference may be
more specific than the general presumption.
Applications of Default Reasoning

Default reasoning is applied in various AI domains:


Expert Systems: In expert systems, default rules are used to
make educated guesses and recommendations when experts'
knowledge is incomplete.
Natural Language Processing: In natural language
understanding, default inferences are made to fill gaps in text
or speech.
Cognitive Modeling: Cognitive models use default reasoning
to simulate human-like thinking and adapt to new
information.

You might also like