0% found this document useful (0 votes)
57 views127 pages

AI notes

Uploaded by

kulsum8792
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views127 pages

AI notes

Uploaded by

kulsum8792
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 127

Artificial intelligence - BCS515B

Course objectives:
 Learn the basic principles and theories underlying artificial intelligence, including machine
learning, neural networks, natural language processing, and robotics.
 Apply AI techniques to solve real-world problems, including search algorithms, optimization, and
decision-making processes.
 Understand the ethical, legal, and societal implications of AI, including topics such as bias,
fairness, accountability, and the impact of AI on the workforce and privacy.

Module-1
Chapter – 1 Introduction: What Is AI? , The State of The Art.

Chapter – 2 Intelligent Agents: Agents and environment, Concept of Rationality, The


nature of environment, the structure of agents

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 1


Artificial intelligence - BCS515B

MODULE – 01
CHAPTER – 01
INTRODUCTION

 The field of artificial intelligence, or AI, goes further still: it attempts not just to understand but
alsoto build intelligent entities.

 AI is one of the newest sciences. Work started in earnest soon after World War II, and the
name itself was coined in 1956.

 Along with molecular biology, AI is regularly cited as the "field I would most like to be in" by
scientists in other disciplines.

 A student in physics might reasonably feel that all the good ideas have already been taken by
Galileo, Newton, Einstein, and the rest. AI, on the other hand, still has openings for several full-time
Einsteins.

 AI systematizes and automates intellectual tasks and is therefore potentially relevant to any sphere
ofhuman intellectual activity. In this sense, it is truly a universal field.

1.1. What is AI?

Below definitions 1 2 3 and 4 are concerned with thought processes and reasoning,
 Thinking Humanly
Def. 1. “The exciting new effort to make computers think , machines with minds, in the full and literal
sense.” (Haugeland, 1985)

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 2


Artificial intelligence - BCS515B

Def. 2. “The automation of activities that we associate with human thinking, activities such as decision-
making, problem solving, learning” (Bellman, 1978)
 Thinking Rationally
Def.3 “The study of mental faculties through the use of computational models.” (Charniak and McDermott,
1985)”
Def.4 “The study of the computations that make it possible to perceive, reason, and act.” (Winston, 1992)”
Below definitions 5 6 7 8 address behavior.
 Acting Humanly
Def.5 “The art of creating machines that perform functions that require intelligence when performed by
people.” (Kurzweil, 1990)
Def.6 “The study of how to make computers do things at which, at the moment, people are better.” (Rich
and Knight, 1991)
 Acting Rationally
Def.7 “Computational Intelligence is the study of the design of intelligent agents.” (Poole et al., 1998)’
Def.8 “AI is concerned with intelligent behavior in artifacts.” (Nilsson, 1998)
NOTE:
 Thinking and acting humanly measure success in terms of fidelity to human performance.
 Whereas the one against an ideal performance measure, called rationality.
 A system is rational if it does the “right”

Views of AI fall into four categories:

1.1.1 Acting humanly: The Turing Test approach

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 3


Artificial intelligence - BCS515B

What is the Turing Test?


 Introduced by: Alan Turing in 1950.
 Purpose: To define intelligence in machines.
 How it Works: A computer passes the test if a human cannot distinguish its written responses
from those of a human after asking questions.

Key Capabilities for the Turing Test

1. Natural Language Processing (NLP):


o Allows the computer to understand and respond in English.
2. Knowledge Representation:
o Enables the storage of facts and information.
3. Automated Reasoning:
o Lets the computer use stored knowledge to answer questions and make conclusions.
4. Machine Learning:
o Helps the computer learn from experience and recognize patterns.

Total Turing Test

 Definition: An enhanced version of turing test that includes:


o Video Interaction: The interrogator can see the subject’s responses.
o Physical Interaction: The interrogator can pass objects to the subject.

Additional Skills Needed

1. Computer Vision:
o Enables the computer to see and understand visual information.
2. Robotics:
o Allows the computer to manipulate objects and move in its environment.

Importance of the Turing Test

 Relevance: It remains a key measure of AI capabilities even decades later.


 Research Focus: Many AI researchers prioritize understanding the principles of intelligence over
just passing the test.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 4


Artificial intelligence - BCS515B

Analogy to Airplane Design

 Learning from Nature: Just as early aviators succeeded by studying aerodynamics instead of
merely copying birds, AI research should focus on understanding intelligence rather than just mimicking
human behavior.

The Turing Test is a way to measure machine intelligence, but real progress in AI might come from
studying and understanding how intelligence actually works, rather than just imitating human behavior.

1.1.2 Thinking Humanly: The Cognitive Modeling Approach

Understanding Human Thought

 Goal: To create AI that thinks like humans, we need to understand how humans think.
 Methods to Explore Human Thinking:
1. Introspection: Reflecting on our own thoughts.
2. Psychological Experiments: Observing how people behave in different situations.
3. Brain Imaging: Using technology to see how the brain functions during thinking.

Developing AI Programs

 Once we have a clear theory of how the mind works, we can turn that theory into a computer
program.
 If the program behaves similarly to how humans do in similar situations, it suggests that the
program might be using similar thinking processes.

Example: General Problem Solver (GPS)

 Creators: Allen Newell and Herbert Simon.


 Focus: They compared how their program solved problems to how humans solved the same
problems, not just whether it got the right answers.

Cognitive Science

 Definition: An interdisciplinary field that combines AI and psychology to study the human mind.
 Importance: It helps create testable theories about how we think and learn.
 The field is rich enough to require multiple textbooks.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 5


Artificial intelligence - BCS515B

Collaboration Between Fields

 AI and cognitive science benefit from each other’s discoveries, especially in areas like computer
vision, where insights from neuroscience inform computational models.

To develop AI that thinks like humans, we must understand human cognition through observation and
experimentation, and this knowledge can help create better AI systems.

1.1.3 Thinking Rationally: The “Laws of Thought” Approach

Overview

 Goal: To understand and model "right thinking" or rational reasoning.


 Historical Background:
o Aristotle: One of the first to define correct reasoning through syllogisms (structured
arguments). Example:
 Premise 1: Socrates is a man.
 Premise 2: All men are mortal.
 Conclusion: Therefore, Socrates is mortal.

Development of Logic

 Field of Logic: The study of reasoning processes initiated by Aristotle.


 19th Century Advances: Logicians created formal notations to describe relationships between
various objects, beyond just numbers (as in arithmetic).

Logic and AI

 By 1965, there were programs that could theoretically solve any problem described using logical
notation.
o Note: If no solution exists, the program might run indefinitely.

Logicist Tradition in AI

 The aim is to use logical programs to develop intelligent systems.

Challenges of the Laws of Thought Approach

1. Formalizing Knowledge:

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 6


Artificial intelligence - BCS515B

o It’s difficult to convert informal knowledge (which is often uncertain) into the strict format
needed for logical notation.
2. Practical Problem Solving:
o Solving a problem “in principle” (theoretically) is different from doing it in practice.
o Even simple problems with a few hundred facts can overwhelm computers unless guided
on how to approach reasoning steps effectively.

The "laws of thought" approach, rooted in logic, aims to create rational AI, but challenges exist in
formalizing human knowledge and applying it effectively in real-world problem solving.
1.1.4 Acting Rationally: The Rational Agent Approach

What is an Agent?

 Definition: An agent is something that acts. In AI, an agent is expected to:


o Operate on its own (autonomously).
o Perceive its environment.
o Persist over time.
o Adapt to changes.
o Create and pursue goals.

Rational Agent

 A rational agent acts to achieve the best outcome, or the best expected outcome in uncertain
situations.

Connection to the Laws of Thought

 The laws of thought focus on making correct inferences. While reasoning logically is part of being
a rational agent, it's not the only way to act rationally.
 Sometimes, there’s no clear right answer, but action is still required. For instance, reflexes, like
pulling your hand away from a hot stove, can be quicker and more effective than deliberate reasoning.

Skills Needed for Rational Action

 Skills from the Turing Test (like natural language processing and reasoning) help agents make
good decisions.
 Learning improves an agent’s ability to act effectively.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 7


Artificial intelligence - BCS515B

Advantages of the Rational-Agent Approach

1. General Applicability: It encompasses more than just correct reasoning—there are various ways
to achieve rationality.
2. Scientific Foundation: The concept of rationality is mathematically defined and can be
systematically developed into agent designs. In contrast, human behavior is specific to particular
environments and contexts.

Important Note: Achieving perfect rationality (always doing the right thing) is often unrealistic due to
high computational demands in complex environments. However, using perfect rationality as a starting
point simplifies analysis and is useful for foundational concepts.

The rational agent approach in AI focuses on creating agents that act effectively to achieve goals,
incorporating various skills and recognizing that perfect rationality is an ideal rather than a practical reality.

1.2 THE STATE OF THE ART:

What Can AI Do Today?

AI has a wide range of applications across various fields. Here are some key examples:

1. Robotic Vehicles

 STANLEY: A driverless car that won the 2005 DARPA Grand Challenge by navigating the
Mojave Desert.
 BOSS: CMU’s robotic vehicle that won the Urban Challenge in 2007, successfully driving in
traffic while obeying rules and avoiding obstacles.

2. Speech Recognition

 Automated systems can manage entire conversations, such as when booking flights with United
Airlines.

3. Autonomous Planning and Scheduling

 NASA’s Remote Agent: The first on-board program to autonomously plan spacecraft operations.
 MAPGEN: Plans daily operations for NASA’s Mars rovers.
 MEXAR2: Handled mission planning for the European Space Agency’s Mars Express in 2008.

4. Game Playing

 IBM’s Deep Blue: The first computer to defeat a world chess champion, Garry Kasparov, in
1997, marking a significant milestone in AI.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 8


Artificial intelligence - BCS515B

5. Spam Fighting

 Learning algorithms classify over a billion emails daily as spam, protecting users from irrelevant
messages.

6. Logistics Planning

 During the 1991 Persian Gulf crisis, the DART tool automated logistics for U.S. forces, planning
transportation for up to 50,000 vehicles and personnel in hours instead of weeks.

7. Robotics

 Roomba: A popular robotic vacuum cleaner with over two million sold.
 PackBot: Used in military operations to handle hazardous tasks and locate threats.

8. Machine Translation

 AI systems can automatically translate languages, such as Arabic to English, using statistical
models based on vast amounts of text data.

These examples illustrate that AI is not just fiction; it is a practical application of science, engineering, and
mathematics, forming the basis for numerous technologies in use today.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 9


Artificial intelligence - BCS515B

MODULE – 01
CHAPTER – 02
INTELIGENT AGENTS
2.1 AGENTS AND ENVIRONMENT:
 Agent Definition…

An agent is a system that:

– is situated in an environment,
– is capable of perceiving its environment, and
– is capable of acting in its environment with the goal of satisfying its design objectives. (or)

Anything that can be viewed as perceiving its environment through sensors and SENSOR acting upon that
environment through actuators.

(OR)

Figure: An agent example representation

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 10


Artificial intelligence - BCS515B

 Examples for different agents:

i. Human “agent”:
– environment: physical world;
– sensors: eyes, ears, . . .
– effectors: hands, legs, . . .
ii. Software agent:
– environment: (e.g.) UNIX operating system;
– sensors: keystrokes, file contents, n/w packets . . .
– effectors: rm, chmod, . . .
iii. Robot:
– environment: physical world;
– sensors: sonar, camera;
– effectors: wheels.

 Important terms…
 Percept:
We use the term percept to refer to the agent's perceptual inputs at any given instant.

 Percept Sequence:
An agent's percept sequence is the complete history of everything the agent has ever perceived.

 Agent function: f:P* →A


Mathematically speaking, we say that an agent's behavior is described by the agent function that
maps any given percept sequence to an action.

 Agent function VS Agent program:


The agent function is an abstract mathematical description; the agent program is a concrete
implementation, running on the agent
architecture.

Example: The vacuum-cleaner world…

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 11


Artificial intelligence - BCS515B

2.2 Concept of Rationality…


 Rational Agent…

A rational agent is one that does the right thing-conceptually speaking, every entry in the table for
the agent function is filled out correctly.

Obviously, doing the right thing is better than doing the wrong thing. The right action is the one
that will cause the agent to be most successful.

 Performance measures:

A performance measure embodies the criterion for success of an agent's behavior.

When an agent is plunked down in an environment, it generates a sequence of actions according to


the percepts it receives.

 This sequence of actions causes the environment to go through a sequence of states. If


the sequence is desirable, then the agent has performed well.

 Rationality :

What is rational at any given time depends on four things:

 The performance measure that defines the criterion of success.


 The agent's prior knowledge of the environment.
 The actions that the agent can perform.
 The agent's percept sequence to date.

 Omniscience, learning, and autonomy…


 An omniscient agent knows the actual outcome of its actions and can act accordingly;
but omniscience is impossible in reality.
 Doing actions in order to modify future percepts-sometimes called information
gathering-is an important partof rationality.
 Our definition requires a rational agent not only to gather information, but also to learn
as much as possible from what it perceives.
 To the extent that an agent relies on the prior knowledge of its designer rather than on
its own percepts, we say that the agent lacks autonomy. A rational agent should be autonomous-it
should learn what it can to compensate for partial or incorrect prior knowledge.

2.3 The Nature of Environments :


 Task environments :
These are essentially the "problems" to which rational agents are the "solutions.“

 Specifying the task environment : PEAS


The rationality of the simple vacuum-cleaner agent, needs specification of …

– the performance measure - P


– the environment - E
– the agent's actuators and sensors - A & S

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 12


Artificial intelligence - BCS515B

PEAS Example…

 Properties of task environments…


I. Fully observable vs. partially observable
II. Deterministic vs. stochastic
III. Episodic vs. sequential
IV. Static vs. dynamic
V. Discrete vs. continuous
VI. Single agent vs. Multiagent

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 13


Artificial intelligence - BCS515B

I. Fully observable vs. partially observable…


 If an agent's sensors give it access to the complete state of the environment at each
point in time, then we saythat the task environment is fully observable.
 A task environment is effectively fully observable if the sensors detect all aspects
that are relevant to the choice of action;
 An environment might be partially observable because of noisy and inaccurate sensors
or because parts of the state are simply missing from the sensor.
II. Deterministic vs. stochastic…

If the next state of the environment is completely determined by the current state and the
action executed by the agent, then we say the environment is deterministic; other-wise, it is
stochastic.

III. Episodic vs. sequential…

 In an episodic task environment, the agent's experience is divided into atomic episodes.
 Each episode consists of the agent perceiving and then performing a single action.
 Crucially, the next episode does not depend on the actions taken in previous episodes.
 In sequential environments, on the other hand, the current decision could affect all
future decisions. Chess and taxi driving are sequential.

IV. Static vs. Dynamic...


 If the environment can change while an agent is deliberating, then we say the
environment is dynamic for that agent; otherwise, it is static.
 Static environments are easy to deal with because the agent need not keep looking at the
world while it is deciding on an action, nor need it worry about the passage of time.
 Dynamic environments, on the other hand, are continuously asking the agent what it
wants to do; if it hasn’t decided yet, that counts as deciding to do nothing.
 If the environment itself does not change with the passage of time but the agent’s
performance score does, then we say the environment is semidynamic. Taxi driving is clearly
dynamic: the other cars and the taxi itself keep moving while the driving algorithm dithers
about what to do next. Chess, when played with a clock, is semidynamic. Crossword puzzles are
static.
V. Discrete vs. continuous…

 A discrete-state environment such as a chess game has a finite number of distinct states.
 Chess also has a discrete set of percepts and actions.
 Taxi driving is a continuous state and continuous-time problem: the speed and
location of the taxi and of the other
 vehicles sweep through a range of continuous values and do so smoothly over time.
 Taxi-driving actions are also continuous (steering angles,.)

VI. Single agent vs. multiagent…

 An agent solving a crossword puzzle by itself is clearly in a single-agent


environment, whereas an agent playing chess is in two agent environment.
Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 14
Artificial intelligence - BCS515B

 As one might expect, the hardest case is partially observable, stochastic, sequential,
dynamic, continuous, and Multiagent.

2.4 The Structure of Agents…


 Agent programs:

2.4.1..1 The job of AI is to design the agent program that implements the agent function
mapping percepts to actions.
2.4.1..2 Agent = architecture +program
2.4.1..3 The agent programs all have the same skeleton: they take the current percept as input
from the sensors and return an action to the actuators.

2.4.1..4 Notice the difference between the agent program, which takes the current percept
as input, and the agent function, which takes the entire percept history.

 Agent Types/Categories…
i. Table-driven agents:
-- use a percept sequence/action table in memory to find the next action. They are implemented by a
(large) lookuptable.

ii. Simple reflex agents:


-- are based on condition-action rules, implemented with an appropriate production system. They
are stateless devices which do not have memory of past world states.

iii. Agents with memory (Model):


-- have internal state, which is used to keep track of past states of the world.

iv. Agents with goals:


-- are agents that, in addition to state information, have goal information that describes desirable
situations. Agents ofthis kind take future events into consideration.

v. Utility-based agents:
--base their decisions on classic axiomatic utility theory in order to act rationally.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 15


Artificial intelligence - BCS515B

vi. Learning Agents:


(a) Table Driven Agent:

 Drawbacks:
 Table lookup of percept-action pairs defining all possible condition-action rules
necessary to interact in an environment.
 Problems :
– Too big to generate and to store (Chess has about 10^120 states, for example)
– No knowledge of non-perceptual parts of the current state
– Not adaptive to changes in the environment; requires entire table to be updated if changes
occur
– Looping: Can't make actions conditional
– Take a long time to build the table
– No autonomy
– Even with learning, need a long time to learn the table entries

(b) Simple Reflex Agent:

 The simplest kind of agent is the simple reflex agent.


 These agents select actions on the basis of the current percept, ignoring the rest of the
percept history. E.g. the vacuum-agent
 Large reduction in possible percept/action situations.
 Implemented through condition-action rules.
 Simple reflex behaviors occur even in more complex environments. Imagine yourself as
the driver of the automated taxi. If the car in front brakes and its brake lights come on, then you
should notice this and initiate braking.
 In other words, some processing is done on the visual input to establish the
condition we call “The car in front is braking.” Then, this triggers some established connection in
the agent program to the action “initiate braking.”
 We call such a connection a condition–action rule,5 written as if car-in-front-is-
braking then initiate- braking.
 Example : Vaccum Cleaner : If dirty then suck

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 16


Artificial intelligence - BCS515B

 Characteristics:
 Only works if the environment is fully observable.
 Lacking history, easily get stuck in infinite loops.
 One solution is to randomize actions.

(c) Model based reflex Agents:


o The most effective way to handle partial observability is for the agent to keep track of
the part of the world it can't see now.

o That is, the agent should maintain some sort of internal state that depends on the
percept history and therebyreflects at least some of the unobserved aspects of the current state.

o Updating this internal state information as time goes by requires two kinds of
knowledge to be encoded in the agent program

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 17


Artificial intelligence - BCS515B

o First, we need some information about how the world evolves independently of the
agent-for example, that an overtaking car generally will be closer behind than it was a moment
ago.
o Second, we need some information about how the agent's own actions affect the world-
for example, that when the agent turns the steering wheel clockwise, the car turns to the right or
that after driving for five minutes northbound on the freeway one is usually about five miles north
of where one was five minutes ago.

This knowledge about "how the world working -whether implemented in simple Boolean circuits
or in complete scientific theories-is called a model of the world. An agent that uses such a
model is called a model-based agent.

iv Goal Based Agents:


 Knowing about the current state of the environment is not always enough to decide
what to do. For example, at a road junction, the taxi can turn left, turn right, or go straight on.

 The correct decision depends on where the taxi is trying to get to.
 In other words, as well as a current state description, the agent needs some sort of
goal information that describes situations that are desirable-for example, being at the passenger's
destination.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 18


Artificial intelligence - BCS515B

 The agent program can combine this with information about the results of possible
actions (the same information as was used to update internal state in the reflex agent) in order to
choose actions that achieve the goal.

 Sometimes goal-based action selection is straightforward—for example, when goal


satisfaction results immediately from a single action. Sometimes it will be more tricky—for
example, when the agent has to consider long sequences of twists and turns in order to find a way to
achieve the goal.

 Search and planning are the subfields of AI devoted to finding action sequences that
achieve the agent’s goals.

 Although the goal-based agent appears less efficient, it is more flexible because the
knowledge that supports its decisions is represented explicitly and can be modified.

 If it starts to rain, the agent can update its knowledge of how effectively its brakes will
operate; this will automatically cause all of the relevant behaviors to be altered to suit the new
conditions.

V Utility based Agents:

 Goals alone are not really enough to generate high-quality behavior in most
environments. For example, there are many action sequences that will get the taxi to its destination
(thereby achieving the goal) but some are quicker, safer, more reliable, or cheaper than others.
 Goals just provide a crude binary distinction between "happy" and "unhappy" states,
whereas a more general performance measure should allow a comparison of different world
states according to exactly how happythey would make the agent if they could be achieved.

 Because "happy" does not sound very scientific, the customary terminology is to say
that if one world state is preferred to another, then it has higher utility for the agent.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 19


Artificial intelligence - BCS515B

 A utility function maps a state (or a sequence of states) onto a real number, which
describes the associated degree of happiness.
 A complete specification of the utility function allows rational decisions in two kinds
of cases where goals are inadequate.

 First, when there are conflicting goals, only some of which can be achieved (for
example, speed and safety), the utility function specifies the appropriate tradeoff.
 Second, when there are several goals that the agent can aim for, none of which can be
achieved with certainty, utility provides a way in which the likelihood of success can be weighed up
against the importance of the goals.
 Partial observability and stochasticity are ubiquitous in the real world, and so, therefore,
is decision making under uncertainty.

 Technically speaking, a rational utility-based agent chooses the action that maximizes
the expected utility of the action outcomes—that is, the utility the agent expects to derive, on
average, given the probabilities and utilities of each outcome.

Vi Learning Agents:

 All agents can improve their performance through learning.


 A learning agent can be divided into four conceptual components as shown in figure:
a. Learning element
b. Performance element
c. Critic
d. Problem generator

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 20


Artificial intelligence - BCS515B

a. Learning element - is responsible for making improvements.


b. Performance element - is responsible for selecting external actions. The performance element
is what we have previously considered to be the entire agent: it takes in percepts and decides on actions.
c. Critic - The learning element uses feedback from the critic on how the agent is doing and
determines how the performance element should be modified to do better in the future.
d. Problem generator - It is responsible for suggesting actions that will lead to new and
informative experiences.

Mr. Manjunatha G, Asst. Professor, Dept. of CS&Design, PESIT&M, Shimoga Page 21


Artificial intelligence – BCS505B

Course objectives:
 Learn the basic principles and theories underlying artificial intelligence, including machine learning,
neural networks, natural language processing, and robotics.
 Apply AI techniques to solve real-world problems, including search algorithms, optimization, and
decision-making processes.
 Understand the ethical, legal, and societal implications of AI, including topics such as bias, fairness,
accountability, and the impact of AI on the workforce and privacy.

ARTIFICIAL
INTELLIGENCE

Module - 2

Syllabus
Solving Problems by searching: Problem Solving Agents, Example problems,
Searching for Solutions, Uninformed Search Strategies

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 1


Artificial intelligence – BCS505B

Solving Problems by searching

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 2


Artificial intelligence – BCS505B

 Problem Solving Agents :


Problem formulation is the process of deciding what actions and states to consider, given a goal .

 An important aspect of intelligence is goal-based problem solving.


 The solution of many problems can be described by finding a sequence of actions that lead to a desirable goal.
 Each action changes the state and the aim is to find the sequence of actions and states that lead from the initial
(start) state to a final (goal) state.

 What is Search?

 Search is the systematic examination of states to find path from the start/root state to the goal state.
 The set of possible states, together with operators defining their connectivity constitute the search space.
 The output of a search algorithm is a solution, that is, a path from the initial state to a state that satisfies the
goal test.

(i) Problem Solving Agents:


 A Problem solving agent is a goal-based agent .It decide what to do by finding sequence of actions that lead to
desirable states.
 The agent can adopt a goal and aim at satisfying it.
Example: From Arad(Romania) to Bucharest

 Goal formulation, based on the current situation and the agent’s performance measure, is the first step in
problem solving.
 The agent’s task is to find out which sequence of actions will get to a goal state.
 Problem formulation is the process of deciding what actions and states to consider given a goal.
 An agent with several immediate options of unknown value can decide what to do by examining different
possible sequences of actions that leads to the states of known value, and then choosing the best sequence.

 The process of looking for sequences actions from the current state to reach the goal state is called search.
 The search algorithm takes a problem as input and returns a solution in the form of action sequence.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 3


Artificial intelligence – BCS505B

 Once a solution is found, the execution phase consists of carrying out the recommended action..
 Simple “formulate, search, execute” design for the agent…

 The agent design assumes the Environment is:

– Static : The entire process carried out without paying attention to changes that might be occurring in the
environment.
– Observable : The initial state is known and the agent’s sensor detects all aspects that are relevant to the choice of
action.
– Discrete : With respect to the state of the environment and percepts and actions so that alternate courses of action
can be taken.
– Deterministic : The next state of the environment is completely determined by the current state and the actions
executed by the agent. Solutions to the problem are single sequence of actions.

(ii) Well-defined problems and solutions:

A well-defined problem can be described by:

i. Initial state
ii. Operator or successor function - for any state x returns s(x), the set of states reachable from x with one action
iii. State space - all states reachable from initial by any sequence of actions
iv. Path - sequence through state space
v. Path cost - function that assigns a cost to a path. Cost of a path is the sum of costs of individual actions along the
path
vi. Goal test - test to determine if at goal state
vii. The step cost of taking action ‘a’ to go from state x to state y is denoted by c(x,a,y). The step cost for Romania are
shown in next figure in route distances. It is assumed that the step costs are non negative.
viii.A solution to the problem is a path from the initial state to a goal state.
ix. An optimal solution has the lowest path cost among all solutions.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 4


Artificial intelligence – BCS505B

 Example Problems:
 Toy vs Real World problems…

 A toy problem is intended to illustrate or exercise various problem-solving methods.


 It can be given a concise, exact description and hence is usable by different researchers to compare the
REALWORLD performance of algorithms.
 A real-world problem is one whose solutions people actually PROBLEM care about. Such problems tend not
to have a single agreed-upon description, but we can give the general flavor of their formulations.

1. Toy Problems:
 Example 1: Vaccum world

i. States: The agent is in one of two locations.,each of which might or might not contain dirt. Thus there are 2 x
22 = 8 possible world states.
ii. Initial state: Any state can be designated as initial state.
iii. Successor function : This generates the legal states that results from trying the three actions (left, right, suck).
The complete state space is shown in figure.
iv. Goal Test : This tests whether all the squares are clean.
v. Path test : Each step costs one ,so that the the path cost is the number of steps in the path.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 5


Artificial intelligence – BCS505B

 States: integer dirt and robot locations (ignore dirt amounts etc.)
 Actions: Left, Right, Suck, NoOp
 Goal test: no dirt
 Path cost: 1 per action (0 for No Op)

Example 2:The 8-puzzle:

 An 8-puzzle consists of a 3x3 board with eight numbered tiles and a blank space.
 A tile adjacent to the blank space can slide into the space. The object is to reach the goal state ,as shown in
Figure.

 The problem formulation is as follows :

i. States : A state description specifies the location of each of the eight tiles and the blank in one of the nine
squares.

ii. Initial state : Any state can be designated as the initial state. It can be noted that any given goal can be
reached from exactly half of the possible initial states.

iii. Successor function : This generates the legal states that result from trying the four actions(blank moves
Left,Right,Up or down).
Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 6
Artificial intelligence – BCS505B

iv. Goal Test : This checks whether the state matches the goal configuration shown in figure(Other goal
configurations are possible).

v. Path cost : Each step costs 1,so the path cost is the number of steps in the path.

 The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as test problems for new
search algorithms in AI. This general class is known as NP-complete.

 The 8-puzzle has 9!/2 = 181,440 reachable states and is easily solved.

 The 15 puzzle ( 4 x 4 board ) has around 1.3 trillion states, an the random instances can be solved optimally in
few milli seconds by the best search algorithms.

 The 24-puzzle (on a 5 x 5 board) has around 1025 states ,and random instances are still quite difficult to solve
optimally with current machines and algorithms.

i. States?: Integer locations of tiles (ignore intermediate positions)

ii. Actions?: Move blank left, right, up, down (ignore unjamming etc.)

iii. Goal test?: Goal state (given).

iv. Path cost?: 1 per move.


[Note: optimal solution of n-Puzzle family is NP-hard]

 Example 3: 8 Queen Problem:


 The goal of 8-queens problem is to place 8 queens on the chessboard such that no queen attacks any other.(A
queen attacks any piece in the same row, column or diagonal).

 An Incremental formulation involves operators that augments the state description, starting with an empty
state for 8-queens problem, this means each action adds a queen to the state.

 A complete-state formulation starts with all 8 queens on the board and moves them around.

 In either case the path cost is of no interest because only the final state counts.

 The first incremental formulation one might try is the following :

i. States : Any arrangement of 0 to 8 queens on board is a state.


ii. Initial state : No queen on the board.
iii. Successor function : Add a queen to any empty square.
iv. Goal Test : 8 queens are on the board, none attacked.
 In this formulation, we have 64, 63…57 = 3 x 1014 possible sequences to investigate.
 A better formulation would prohibit placing a queen in any square that is already attacked.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 7


Artificial intelligence – BCS505B

 States : Arrangements of n queens ( 0 <= n < = 8 ), one per column in the left most columns ,with no queen
attacking another are states.
 Successor function : Add a queen to any square in the left most empty column such that it is not attacked by
any other queen.
 This formulation reduces the 8-queen state space from 3 x1014 to just 2057,and solutions are easy to find.

2. Real-world Problems:
i. Route finding problem
ii. Airline Travel problem
iii. Touring problems
iv. Travelling salesperson problem
v. VLSI Layout
vi. ROBOT Navigation
vii.Automatic Assembly problem
viii.Internet searching

(i) Route-Finding Problem :

 Route-Finding Problem is defined in terms of specified locations and transitions along links between them.
Route-finding algorithms are used in a variety of applications.

 Some, such as Web sites and in-car systems that provide driving directions.

 Others, such as routing video streams in computer networks, military operations planning, and airline travel-
planning systems, involve much more complex specifications.

Consider the airline travel problems that must be solved by a travel-planning Web site:

• States: Each state obviously includes a location (e.g., an airport) and the current time. Furthermore, because the cost
of an action (a flight segment) may depend on previous segments, their fare bases, and their status as domestic or
international, the state must record extra information about these “historical” aspects.

• Initial state: This is specified by the user’s query.

• Actions: Take any flight from the current location, in any seat class, leaving after the current time, leaving enough
time for within-airport transfer if needed.

Transition model: The state resulting from taking a flight will have the flight’s destination as the current location and
the flight’s arrival time as the current time.

• Goal test: Are we at the final destination specified by the user?

• Path cost: This depends on monetary cost, waiting time, flight time, customs and immigration procedures, seat
quality, time of day, type of airplane, frequent-flyer mileage awards, and so on.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 8


Artificial intelligence – BCS505B

(ii) Touring problems :

Touring problems are closely related to route-finding problems, but with an important difference. Consider, for
example, the problem “Visit every city at least once, starting and ending in Bucharest”.

(iii) Traveling Salesperson Problem (TSP) :

 The traveling salesperson problem (TSP) is a touring problem in which each city must be visited exactly
once.

 The aim is to find the shortest tour.

The problem is known to be NP-hard, but an enormous amount of effort has been expended to improve the capabilities
of TSP algorithms.

(iv) VLSI layout problem :

 A VLSI layout problem requires positioning millions of components and connections on a chip to minimize
area, minimize circuit delays, minimize stray capacitances, and maximize manufacturing yield.

 The layout problem comes after the logical design phase and is usually split into two parts:

 Cell layout

 Channel routing.

 Cell layout :

 In cell layout, the primitive components of the circuit are grouped into cells, each of which performs some
recognized function.

 Channel routing :

 Channel routing finds a specific route for each wire through the gaps between the cells.

(v) Robot Navigation :

 Robot navigation is a generalization of the route-finding problem described earlier.

 Rather than following a discrete set of routes, a robot can move in a continuous space with (in principle) an
infinite set of possible actions and states.

 For a circular robot moving on a flat surface, the space is essentially two-dimensional.

(vi) Automatic assembly sequencing :

 Automatic assembly sequencing of complex objects by a robot was first demonstrated by FREDDY
(Michie, 1972).

 Progress since then has been slow but sure.

 In assembly problems, the aim is to find an order in which to assemble the parts of some object. If the

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 9


Artificial intelligence – BCS505B
wrong order is chosen, there will be no way to add some part later in the sequence without undoing some of
the work already done.

 Checking a step in the sequence for feasibility is a difficult geometrical search problem closely related to
robot navigation.

 Another important assembly problem is protein design, in which the goal is to find a sequence of amino
acids that will fold into a three-dimensional protein with the right properties to cure some disease.

 SEARCHING FOR SOLUTIONS:

 A solution is an action sequence, so search algorithms work by considering various possible action
sequences.

 The possible action sequences starting at the initial state form a search tree with the initial state at
the root; the branches are actions and the nodes correspond to states in the state space of the
problem.

 The diagram shows the first few steps in growing the search tree for finding a route from Arad to
Bucharest.

 By expanding the current state , and thereby generating a new set of states.

 Each of these six nodes is a leaf node, that is, a node with no children in the tree.

 The set of all leaf nodes available for expansion at any given
point is called the frontier(Many authors call it the open list)

the frontier of each tree consists of those nodes with bold outlines.

 The process of expanding nodes on the frontier continues until either a solution is found or there are
no more states to expand.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 10


Artificial intelligence – BCS505B

 Search algorithms all share this basic structure; they vary primarily
according to how they choose which state to expand next—the so-called search strategy.

 Loopy paths are a special case of the more general concept of redundant paths, which exist
whenever there is more than one way to get from one state to another.

 As every step moves a state from the frontier into the explored region while moving some states
from the unexplored region into the frontier, we see that the algorithm is systematically
examining the states in the state space, one by one, until it finds a solution.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 11


Artificial intelligence – BCS505B

(i) Infrastructure for search algorithms :


 Search algorithms require a data structure to keep track of the search tree that is being constructed.
 For each node n of the tree, we have a structure that contains four components:

o n.STATE: the state in the state space to which the node corresponds;

o n.PARENT: the node in the search tree that generated this node;

o n.ACTION: the action that was applied to the parent to generate the node;

o n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to
thenode, as indicated by the parent pointers.

 Queue :
 Now that we have nodes, we need somewhere to put them.

 The frontier needs to be stored in such a way that the search algorithm can easily choose the next
node to expand according to its preferred strategy.

 The appropriate data structure for this is a queue.

 The operations on a queue are as follows:

• EMPTY (queue) returns true only if there are no more elements in the queue.

• POP (queue) removes the first element of the queue and returns it.

• INSERT (element, queue) inserts an element and returns the resulting queue.

 Queues are characterized by the order in which they store the inserted nodes.

 Three common variants are

 The first-in, first-out or FIFO queue, which pops the oldest element of the queue;

 LIFO QUEUE the last-in, first-out or LIFO queue (also known as a stack), which pops the newest
element

 PRIORITY QUEUE of the queue; and the priority queue, which pops the element of the queue with
the highest priority according to some ordering function.

(ii) Measuring problem-solving performance:


 Before we get into the design of specific search algorithms, we need to consider the criteria that
might be used to choose among them.

 We can evaluate an algorithm’s performance in four ways:

 Completeness: Is the algorithm guaranteed to find a solution when there is one?

 Optimality: Does the strategy find the optimal solution,

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 12


Artificial intelligence – BCS505B

 Time complexity: How long does it take to find a solution?

 Space complexity: How much memory is needed to perform the search?

 Uninformed Search strategies:


 Uninformed Search Strategies have no additional information about states beyond that provided in the
problem definition.

 There are six uninformed search strategies as given below:


i. Breadth-first search
ii. Uniform-cost search
iii. Depth-first search
iv. Depth-limited search
v. Iterative deepening search
vi. Bi-directional search
1. Breadth-first search (BFS):
 Breadth-first search is a simple strategy in which the root node is expanded first, then all 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.

 Breath-First-Search is implemented by calling TREE SEARCH with an empty fringe that is a first-in-first out
(FIFO) queue, assuring that the nodes that are visited first will be expanded first.

 In other words, calling TREE-SEARCH (problem, FIFO-QUEUE()) results in breadth-first-search.

 The FIFO queue puts all newly generated successors at the end of the queue, which means that Shallow nodes
are expanded before deeper nodes.

 BFS Algorithm…

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 13


Artificial intelligence – BCS505B

Example for BFS Algorithm…

 Properties of BFS…

 Time and memory requirements….

2. Uninform-cost Search(UCS)…
 Instead of expanding the shallowest node, uniform-cost search expands the node ‘n’ with the lowest path cost.
 Uniform-cost search does not care about the number of steps a path has, but only about their total cost.
 Expand least-cost unexpanded node.
 We think of this as having an evaluation function:g(n), which returns the path cost to a node n.
 fringe = queue ordered by evaluation function,lowest first.
 Equivalent to breadth-first if step costs all equal
 Complete and optimal.
 Time and space complexity are as bad as for breadth-first search.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 14


Artificial intelligence – BCS505B

 UCS Algorithm:

 Process…

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 15


Artificial intelligence – BCS505B

 Properties of UCS….

3. Depth First Search(DFS)…


 Depth-first-search always expands the deepest node in the current fringe of the search tree.
 The search proceeds immediately to the deepest level of the search tree, where the nodes have no successors.
 As those nodes are expanded, they are dropped from the fringe ,so then the search “backs up” to the next
shallowest node that still has unexplored successors.
 Implementation:
fringe = LIFO queue, i.e., put successors at front.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 16


Artificial intelligence – BCS505B

 Properties of Depth First Search(DFS):

 Complete? - No: Fails in infinite-depth spaces, spaces


with loops. Modify to avoid repeated states along
Path complete infinite spaces
 Time?? : O(bm): Terrible if m is much larger than ‘d’, but
if solutions are dense, may be much faster than
breadth first search.
 Space?? : O(bm), i.e., linear space!
 Optimal?? : No

4. Depth-Limited Search…
 The embarrassing failure of depth-first search in infinite state spaces can be alleviated by supplying depth-first
search with a predetermined depth limit ‘l’.
 That is, nodes at depth ‘l’ are DEPTH-LIMITED treated as if they have no successors. This approach is called
depth limited search.
 The SEARCH depth limit solves the infinite-path problem.
 Unfortunately, it also introduces an additional source of incompleteness if we choose ‘l’ < d, that is, the

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 17


Artificial intelligence – BCS505B

shallowest goal is beyond the depth limit. (This is likely when d is unknown.)

 Depth-limited search will also be non-optimal if we choose ‘l’ > d.


 Its time complexity is O(b) and its space complexity is O(b). Depth-first search can be viewed as a
special case of depth-limited search with‘l’ =∞.

5. Iterative deepening depth-first search…


 Iterative deepening search (or iterativedeepening-depth-first-search) is a general strategy often used in
combination with depth-first-search,that finds the better depth limit.
 It does this by gradually increasing the limit – first 0,then 1,then 2, and so on – until a goal is found.
 This will occur when the depth limit reaches d, the depth of the shallowest goal node.
 Iterative deepening combines the benefits of depth-first and breadth-first-search.
 Like depth-first-search, its memory requirements are modest;O(bd) to be precise.

 In general, iterative deepening is the preferred uninformed search method when the search space is large and
the depth of the solution is not known.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 18


Artificial intelligence – BCS505B

 Four iterations of iterative deepening search on a binary tree in shown below.

 Properties of IDS….

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 19


Artificial intelligence – BCS505B

6. Bi-directional search…
 The idea behind bidirectional search is to run two simultaneous searches – one forward from the initial state
and the other backward from the goal, stopping when the two searches meet in the middle.

 The motivation is that bd/2 + bd/2 much less than or the area of the two small circles is less than the area of one
big circle centered on the start and reaching to the goal.

 Example Graph:

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 20


Artificial intelligence – BCS505B

2.4.7 Comparing uninformed search strategies…

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 21


Artificial intelligence – BCS505B

ARTIFICIAL
INTELLIGENCE

Module - 3

Syllabus
Chapter : 1 Problem‐solving: Informed Search Strategies, Heuristic functions
Chapter : 2 Logical Agents: Knowledge–based agents, The Wumpus world, Logic,
Propositional logic, Reasoning patterns in Propositional Logic

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 1


Artificial intelligence – BCS505B

Informed or Heuristic search strategies…


 Informed search strategy is one that uses problem-specific knowledge beyond the definition of the
problem itself.
 It can find solutions more efficiently than uninformed strategy.
 Best-first search is an instance of general TREE-SEARCH or GRAPH-SEARCH algorithm in which
a node is selected for expansion based on an evaluation function f(n).
 The node with lowest evaluation is selected for expansion, because the evaluation measures the
distance to the goal.
 This can be implemented using a priority-queue, a data structure that will maintain the fringe in
ascending order of fvalues.
 A heuristic function or simply a heuristic is a function that ranks alternatives in various search
algorithms at each branching step basing on an available information in order to make a decision
which branch is to be followed during a search.
 The key component of Best-first search algorithm is a heuristic function, denoted
by h(n): h(n) = estimated cost of the cheapest path from node n to a goal node.

 Heuristic function are the most common form in which additional knowledge is imparted to the
search algorithm.

 Heuristic Searching methods…


i. Greedy Best First search
ii. A* search
iii. Memory-bounded heuristic search(RBFS)

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 2


Artificial intelligence – BCS505B

1. Greedy Best First search…


 Greedy best-first search tries to expand the node that is closest to the goal, on the grounds that this
is likely to a solution quickly.
 It evaluates the nodes by using the heuristic function f(n) = h(n).
 Taking the example of Route-finding problems in Romania , the goal is to reach Bucharest starting
from the city Arad.
 We need to know the straight-line distances(SLD) to Bucharest from various cities as shown in Figure.
 For example, the initial state is In(Arad) ,and the straight line distance heuristic hSLD(In(Arad)) is
found to be 366.

 The figure shows the progress of greedy best-first search using hSLD to find a path from Arad to
Bucharest.

 The first node to be expanded from Arad will be Sibiu, because it is closer to Bucharest than either

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 3


Artificial intelligence – BCS505B

Zerind or Timisoara.
 The next node to be expanded will be Fagaras, because it is closest.

 Fagaras in turn generates Bucharest, which is the goal.

FINAL PATH : Arad → Sibiu → Fagaras → Bucharest.

 Greedy search Algorithm…

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 4


Artificial intelligence – BCS505B

2. A* Search…

 A* is very efficient search strategy and it is the most widely used form of best-first search.
 Basic idea is to combine uniform cost search and greedy search.
 The evaluation function f(n) is obtained by combining g(n) = the cost to reach the node, and h(n) =
the cost to get from the node to the goal :
f(n) = g(n) +
h(n). (or)
□ f (n) = g(n) + h(n) where
– g(n) is path cost of n;
– h(n) is expected cost of cheapest solution from n.
 It Aims to minimise overall cost.
 Algorithm for A* search stratergy:

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 5


Artificial intelligence – BCS505B

FINAL PATH: Arad →Sibiu →Rimnicu→ Pitesti →Bucharest.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 6


Artificial intelligence – BCS505B

 Optimality of A*…
 A search is both complete and optimal.
 The algorithm is identical to UNIFORM-COST-SEARCH except that A uses g + h instead of g.
 A* is optimal in precise sense—it is guaranteed to find a minimum cost path to the goal.
There are a set of conditions under which A* will find such a path:
1. Each node in the graph has a finite number of children.
2. All arcs have a cost greater than some positive .
3. For all nodes in the graph h(n) always underestimates the true distance to the goal.

 Conditions for the Optimality…


1. The first condition we require for optimality is that h(n) be an admissible
heuristic. An admissible heuristic is one that never overestimates the cost to
reach the goal.
2. A second, slightly stronger condition called consistency (or sometimes monotonicity) is required only
for applications of A to graph search.
 A heuristic h(n) is consistent if, for every node n and every successor n` of n generated by any action
a, the estimated cost of reaching the goal from n is no greater than the step cost of getting to n
plus the estimated cost of reaching the goal from n.

 Problems in A*…
 Computation time, A’s main drawback.
 Because it keeps all generated nodes in memory (as do all GRAPH-SEARCH algorithms), A
usually runsout of space long before it runs out of time.

 For this reason, A is not practical for many largescale problems.


 There are, however, algorithms that overcome the space problem without sacrificing
optimality or completeness, at a small cost in execution time.

3. Memory-bounded Heuristic search…


 Recursive best-first search (RBFS) is a simple recursive algorithm that attempts to
mimic the Operation of standard best-first search, but using only linear space.

 Its structure is similar to that of a recursive depth first search, but rather than continuing indefinitely
down the current path, it uses the f-limit variable to keep track of the f-value of the best alternative
path.
 If the current node exceeds this limit, the recursion unwinds back to the alternative path.
 As the recursion unwinds, RBFS replaces the f-value of each node along the path with a backed-up
value—the best f-value of its children.
 In this way, RBFS remembers the f-value of the best leaf in the forgotten subtree and can
therefore decide whether it’s worth reexpanding the subtree at some later time.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 7


Artificial intelligence – BCS505B

 RBFS Algorithm…

 Stages in RBFS Algorithm…

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 8


Artificial intelligence – BCS505B

 RBFS Evaluation :

 RBFS is a bit more efficient than IDA* Still excessive node generation (mind changes).
 Like A*, optimal if h(n) is admissible. Space complexity is O(bd).
 IDA* retains only one single number (the current f-cost limit).
 Time complexity difficult to characterize Depends on accuracy if h(n) and how often best path changes.
 IDA* and RBFS suffer from too little memory.

HEURISTIC FUNCTIONS :
 The 8-puzzle was one of the earliest heuristic search problems.

 The object of the puzzle is to slide the tiles horizontally or vertically into the empty
space until the configuration matches the goal configuration .
 The average solution cost for a randomly generated 8-puzzle instance is about 22
steps. The branching factor is about 3.
 When the empty tile is in the middle, four moves are possible; when it is in a corner,
two; and when it is along an edge, three.
This means that an exhaustive tree search to depth 22 would look at about

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 9


Artificial intelligence – BCS505B

 A graph search would cut this down by a factor of about 170,000 because only 9!/2 = 181, 440
distinct states are reachable.

 The corresponding number for the 15-puzzle is roughly , so the next order of business is to find a
good heuristic function.

 If we want to find the shortest solutions by using A, we need a heuristic function that never
overestimates the number of steps to the goal.
 There is a long history of such heuristics for the 15-puzzle; here are two commonly used candidates:

 h1 = the number of misplaced tiles. All of the eight tiles are out of position, so the start state would
have h1 = 8.

h1 is an admissible heuristic because it is clear that any tile that is out of place must be moved at least
once.

 h2 = the sum of the distances of the tiles from their goal positions.

Because tiles cannot move along diagonals, the distance we will count is the sum of the
horizontal and vertical distances.
 This is sometimes called the city block distance or Manhattan distance.

(i) The effect of heuristic accuracy on performance :


 One way to characterize the quality of a heuristic is the effective branching factor b.

If the total number of nodes generated by A for a particular problem is N and the solution depth is d,
then b is the branching factor that a uniform tree of depth d would have to have in order
to contain N + 1 nodes. Thus,

 For example, if A finds a solution at depth 5 using 52 nodes, then the effective branching factor is 1.92.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 10


Artificial intelligence – BCS505B

(ii) Generating admissible heuristics from relaxed problems :

 We have seen that both h1 (misplaced tiles) and h2 (Manhattan distance) are fairly good heuristics
for the 8- puzzle and that h2 is better.
 How might one have come up with h2? Is it possible for a computer to invent such a heuristic
mechanically.

h1 and h2 are estimates of the remaining path length for the 8-puzzle, but they are also perfectly
accurate path lengths for simplified versions of the puzzle.
 If the rules of the puzzle were changed, so that a tile could move anywhere instead of just to the
adjacent empty square, then h1 would give the exact number of steps in the shortest solution.
 Similarly, if a tile could move one square in any direction, even onto an occupied square, then h2
would give the exact number of steps in the shortest solution.

 A problem with fewer restrictions on the actions is called a relaxed problem.

“the cost of an optimal solution to a relaxed problem is an admissible heuristic for the original
problem”.

 Furthermore, because the derived heuristic is an exact cost for the relaxed problem, it must obey
the triangle inequality and is therefore consistent .

 If a problem definition is written down in a formal language, it is possible to construct relaxed


problems automatically.
 For example, if the 8-puzzle actions are described as

 A tile can move from square A to square B if


 A is horizontally or vertically adjacent to B and B is blank,
We can generate three relaxed problems by removing one or both of the conditions:

(a) A tile can move from square A to square B if A is adjacent to B.

(b) A tile can move from square A to square B if B is blank.

(c) A tile can move from square A to square B.

From (a), we can derive h2 (Manhattan distance). The reasoning is that h2 would be the proper score
if we moved each tile in turn to its destination.
From (c), we can derive h1 (misplaced tiles) because it would be the proper score if tiles could move
to their intended destination in one step.

(iii) Generating admissible heuristics from subproblems : (Pattern databases)

 Admissible heuristics can also be derived from the solution cost of a subproblem of a given problem.

 For example, a subproblem of the 8-puzzle instance is

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 11


Artificial intelligence – BCS505B

 The sub problem involves getting tiles 1, 2, 3, 4 into their correct positions.

 Clearly, the cost of the optimal solution of this subproblem is a lower bound on the cost of the
complete problem.

 It turns out to be more accurate than Manhattan distance in some cases.

 The idea behind pattern databases is to store these exact solution costs for every possible sub
problem instance—in our example, every possible configuration of the four tiles and the blank.
 Then we compute an admissible heuristic hdb for each complete state encountered during a search
simply by looking up the corresponding subproblem configuration in the database.

 The database itself is constructed by searching back from the goal and recording the cost of each
new pattern encountered .
 Each database yields an admissible heuristic, and these heuristics can be combined, and by taking the
maximum value.
A combined heuristic of this kind is much more accurate than the Manhattan distance .

 One might wonder whether the heuristics obtained from the 1-2-3-4 database and the 5-6-7-8 could
be added, since the two subproblems seem not to overlap.

 Would this still give an admissible heuristic? The answer is no.

 So,we record not the total cost of solving the 1-2-3-4 subproblem, but just the number of moves
involving 1- 2-3-4. Then it is easy to see that the sum of the two costs is still a lower bound on the
cost of solving the entire problem.

 This is the idea behind disjoint pattern databases.

With such databases, it is possible to solve random 15-puzzles in a few milliseconds .

(iv) Learning heuristics from experience:


 Experience” here means solving lots of 8-puzzles, for instance. Each optimal solution to an 8-puzzle
problem provides examples from which h(n) can be learned.

Each example consists of a state from the solution path and the actual cost of the solution from that
point. From these examples, a learning algorithm can be used to construct a function h(n) that can
(with luck) predict solution costs for other states that arise during search.

Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM Page 12

You might also like