You are on page 1of 59

 WHAT is AI?

 Definitions vary along two main dimensions


 ones on top are concerned with thought processes and
reasoning, whereas the ones on the bottom address
behaviour
 on the left measure success in terms of fidelity to human
 performance, whereas the ones on the right measure
against an ideal concept of intelligence (RATIONALITY)
 Historically, all four approaches to AI have been followed
 A human-centered approach must be an empirical
science, involving hypothesis and experimental
confirmation. A rationalist approach involves a
combination of mathematics and engineering.

Dr. A. H. Shanthakumara 1 Dept. of CSE


1. Acting humanly: The Turing Test approach:
 The Turing Test, proposed by Alan Turing (1950), was
designed to provide a satisfactory operational definition
of intelligence
 The test he proposed is that the computer should be
interrogated by a human via a teletype, and passes the
test if the interrogator cannot tell if there is a computer
or a human at the other end.

 The computer would need to possess the following


capabilities:
o natural language processing to enable it to
communicate successfully in English (or some other
human language)
o knowledge representation to store information
provided before or during the interrogation
o automated reasoning to use the stored information
to answer questions and to draw new conclusions
o machine learning to adapt to new circumstances
and to detect and extrapolate patterns
 To pass the total Turing Test, the computer will need
 computer vision to perceive objects, and robotics to
move them about.
 The issue of acting like a human comes up primarily
when AI programs have to interact with people

Dr. A. H. Shanthakumara 2 Dept. of CSE


 These programs must behave according to certain
normal conventions of human interaction in order to
make themselves understood
 Problem: Turing test is not reproducible, constructive, or
amenable to mathematical analysis

2. Thinking humanly: The cognitive modelling approach:


 If we are going to say that a given program thinks like a
human, we must have some way of determining how
humans think.
 We need to get inside the actual workings of human
minds.
 There are two ways to do this: through introspection—
trying to catch our own thoughts as they go by—or
through psychological experiments.
 Once we have a sufficiently precise theory of the mind,
it becomes possible to express the theory as a computer
program.
 1960s \cognitive revolution": information-processing
psychology replaced prevailing orthodoxy of
behaviorism
 Requires scientific theories of internal activities of the
brain
 What level of abstraction? \Knowledge" or \circuits"?
 How to validate? Requires
1) Predicting and testing behavior of human subjects
(top-down)
or 2) Direct identification from neurological data
(bottom-up)

Dr. A. H. Shanthakumara 3 Dept. of CSE


 Both approaches (roughly, Cognitive Science and
Cognitive Neuroscience) are now distinct from AI
 Both share with AI the following characteristic:
o the available theories do not explain (or engender)
o anything resembling human-level general
intelligence
 Hence, all three Fields share one principal direction!

3. Thinking rationally: The laws of thought approach


 Normative (or prescriptive) rather than descriptive
 Aristotle: first to attempt to codify "right thinking,
 what are correct arguments/thought processes?
 Several Greek schools developed various forms of logic:
 notation and rules of derivation for thoughts;
 For example, "Socrates is a man; all men are mortal;
therefore Socrates is mortal."
 may or may not have proceeded to the idea of
mechanization
 Direct line through mathematics and philosophy to
modern AI
 Problems:
1) Not all intelligent behavior is mediated by logical
deliberation
2) What is the purpose of thinking? What thoughts
should I have out of all the thoughts (logical or otherwise)
that I could have? (there is a big difference between being
able to solve a problem "in principle" and doing so in
practice)

Dr. A. H. Shanthakumara 4 Dept. of CSE


4. Acting rationally: The rational agent approach
 Acting rationally means acting to achieve one's goals,
given one's beliefs.
 The right thing: that which is expected to maximize goal
achievement, given the available information
 we need the ability to represent knowledge and reason
with it
 We need to be able to generate comprehensible
sentences in natural language
 We need learning not just for erudition,
 We need visual perception
 An agent is just something that perceives and acts
 AI is viewed as the study and construction of rational
agents.
 The study of AI as rational agent design therefore has
two advantages.
 it is more general than the "laws of thought" approach
(correct inference is only a useful mechanism for
achieving rationality)
 it is more amenable to scientific development

Dr. A. H. Shanthakumara 5 Dept. of CSE


 WHAT is Agent?
 An agent is anything that can be viewed as perceiving its
environment through sensors and acting upon that
environment through actuators.

 A robotic agent might have cameras and infrared range


finders for sensors and various motors for actuators
 Percept – the agent’s perceptual inputs percept
sequence is a sequence of everything the agent has ever
perceived
 Agent Function – describes the agent’s behavior
o Maps any given percept sequence to an action
o f : P* -> A
 Agent Program – an implementation of an agent
function for an artificial agent
 Example: Vacuum Cleaner World
o Two locations: squares A and B
A B

Dr. A. H. Shanthakumara 1 Dept. of CSE


 Perceives what square it is in
 Perceives if there is dirt in the current square
o Actions
 move left
 move right
 suck up the dirt
 do nothing
o Agent Function
 If the current square is dirty, then suck,
otherwise move to the other square
 A partial tabulation of this agent function may
be like

 Percept Sequence  Action

 Right
 [A, Clean]
 Suck
 [A, Dirty]
 Left
 [B, Clean]

 [B, Dirty]
 Suck
.
.
 Right
 [A, Clean], [A, Clean]
 Suck
 [A, Clean], [A, Dirty]

Dr. A. H. Shanthakumara 2 Dept. of CSE


o But what is the right way to fill out the table?
o is the agent
 good or bad?
 intelligent or stupid?
o can it be implemented in a small program?

Function Reflex-Vacuum-Agent([location, status]) return an


action
if status == Dirty then return Suck
else if location = A then return Right
else if location = B then return Left

Good Behavior and Rationality:


 Rational Agent – an agent that does the “right” thing
o Every entry in the table for the agent function is
filled out correctly
o Doing the right thing is better than doing the wrong
thing
o What does it mean to do the right thing?
 the right action is the one that will cause the
agent to be most successful
 need some way to measure success
 Performance Measure- A scoring function for
evaluating the environment space
 selection of a performance measure is not
always easy

Dr. A. H. Shanthakumara 3 Dept. of CSE


Rationality: What is rational at any given time depends on
four things:
o The performance measure that defines the
criterion of success.
o The agent's prior knowledge of the environment.
o The actions that the agent can perform.
o The agent's percept sequence to date.
 Rational Agent – for each possible percept sequence, a
rational agent should select an action that is expected to
maximize its performance measure, given the evidence
provided by the percept sequence and whatever built-in
knowledge the agent has.
Omniscience, learning, and autonomy:
 Rationality is not the Omniscience,
o An omniscient agent knows the actual outcome of
its actions and can act accordingly
o rationality does not require omniscience
 Rationality is not the same as perfection
o Rationality maximizes expected performance, while
perfection maximizes actual performance
 Rational agent not only to gather information, but also
to learn as much as possible from what it perceives
 When the agent is being designed, some of the
computation is done by its designers; when it is
deliberating on its next action, the agent does more
computation; and as it learns from experience, it does

Dr. A. H. Shanthakumara 4 Dept. of CSE


even more computation to decide how to modify its
behavior.
 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
 After sufficient experience of its environment, the
behavior of a rational agent can become effectively
independent of its prior knowledge

Dr. A. H. Shanthakumara 5 Dept. of CSE


The Nature of Environments:
 Task environments are essentially the "problems" to
which rational agents are the "solutions."
 Task environments come in a variety of flavors. The
flavor of the task environment directly affects the
appropriate design for the agent program.
Specifying the task environment:
 We had to specify the performance measure, the
environment, and the agent's actuators and sensors. We
will group all these together under the heading of the
task environment
 we call this the PEAS (Performance, Environment,
Actuators, Sensors) description
 Specify the task environment as fully as possible
 Example : an automated taxi driver.
 Fully automated taxi is currently somewhat beyond the
capabilities of existing technology

Dr. A. H. Shanthakumara 1 Dept. of CSE


 Performance measure-Desirable qualities include
getting to the correct destination; minimizing fuel
consumption and wear and tear; minimizing the trip time
cost; minimizing violations of traffic laws and
disturbances to other drivers; maximizing safety and
passenger comfort; maximizing profits
 Environment: Deal with a variety of roads, ranging from
rural lanes and urban alleys. The roads contain other
traffic, pedestrians, stray animals, road works, police
cars, puddles, and potholes. The taxi must also interact
with potential and actual passengers
 Actuators-control over the engine through the

 accelerator and control over steering and braking
 Sensors- One or more controllable TV cameras, the
speedometer, and the odometer. Global positioning
system (GPS) to give it accurate position with respect to
an electronic map, and infrared or sonar sensors to
detect distances to other cars and obstacles. Need a
keyboard or microphone for the passenger request a
destination.
Properties of task environments:
 The range of task environments that might arise in AI is
obviously vast. However, we can, identify a fairly small
number of dimensions to determine the appropriate
agent design

Dr. A. H. Shanthakumara 2 Dept. of CSE


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- Fully
observable
 A task environment is effectively fully observable if the
sensors detect all aspects that are relevant to the choice
of action
 Fully observable environments are convenient because
the agent need not maintain any internal state to keep
track of the world
 An environment might be partially observable because
of noisy and inaccurate sensors or because parts of the
state are simply missing from the sensor data
 for example, a vacuum agent with only a local dirt sensor
cannot tell whether there is dirt in other squares, and an
automated taxi cannot see what other drivers are
thinking
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; otherwise, it is stochastic
 In principle, an agent need not worry about uncertainty
in a fully observable, deterministic environment. If the
environment is partially observable, however then it
could appear to be stochastic

Dr. A. H. Shanthakumara 3 Dept. of CSE


 It is often better to think of an environment as
deterministic or stochastic from the point of view of the
agent.
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.
 The next episode does not depend on the actions taken
in previous episodes.
 The choice of action in each episode depends only on the
episode itself
 In sequential environments, the current decision could
affect all future decisions.
 Chess and taxi driving are sequential
 Episodic environments are much simpler than sequential
environments because the agent does not need to think
ahead
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
 Dynamic environments are continuously asking the
agent what it wants to do; if it hasn’t decided yet, that
counts as deciding to do nothing

Dr. A. H. Shanthakumara 4 Dept. of CSE


 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
Discrete vs. continuous:
 Distinction can be applied to the state of the
environment, to the way time is handled and to the
percepts and actions of the agent
 A chess game has a finite number of distinct states.
 Taxi driving is a state and continuous-time problem

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 a two-agent environment.
 In the taxi-driving environment, on the other hand,
avoiding collisions maximizes the performance measure
of all agents, so it is a partially cooperative multiagent
environment.
 Chess is a competitive multiagent environment, trying to
maximize its performance measure and minimizes
opponent performance measure.

Dr. A. H. Shanthakumara 5 Dept. of CSE



 As one might expect, the hardest case is partially
observable, stochastic, sequential, dynamic, continuous,
and multiagent.
 The properties are not always cut and dried, depend on
how the task environment is defined
 Many environments are episodic at higher levels than
the agent's individual actions

Dr. A. H. Shanthakumara 6 Dept. of CSE


THE STRUCTURE OF AGENTS:
 An agent program that implements the agent function—
the mapping from percepts to actions.
 This program will run on some sort of computing device
with physical sensors and actuators—architecture
 agent = architecture + program .
Agent programs:
 Take the current percept as input from the sensors and
return an action to the actuators.
 if the agent’s actions need to depend on the entire
percept sequence, the agent will have to remember the
percepts
 The key challenge for AI is to find out how to write
programs that, to the extent possible, produce rational
behavior from a small program rather than from a vast
table.
Some challenges:
 (a) no physical agent in this universe will have the space
to store the table,
 (b) the designer would not have time to create the table,
 (c) no agent could ever learn all the right table entries
from its experience, and
 (d) even if the environment is simple enough to yield a
feasible table size, the designer still has no guidance
about how to fill in the table entries.

Dr. A. H. Shanthakumara 1 Dept. of CSE


 we can outline four basic kinds of agent programs that
embody the principles underlying almost all intelligent
systems
 Each kind of agent program combines particular
components in particular ways to generate actions
Simple reflex agents:
 select actions on the basis of the current percept,
ignoring the rest of the percept history.
 Simple reflex behaviors occur even in more complex
environments.

Dr. A. H. Shanthakumara 2 Dept. of CSE


 The INTERPRET-INPUT function generates an abstracted
description of the current state from the Percept
 the RULE-MATCH function returns the first rule in the
set of rules that matches the given state description
 work only if the correct decision can be made on the
basis of only the current percept—that is, only if the
environment is fully observable
 Even a little bit of unobservability can cause serious
trouble.
Model-based reflex agents:
 The agent should maintain some sort of internal state
that depends on the percept history and thereby reflects
at least some of the unobserved aspects of the current
state
 Updating this internal state information as time goes by
requires two kinds of knowledge to be encoded in the
agent program
 First, we need some information about how the world
evolves independently of the agent
 Second, we need some information about how the
agent’s own actions affect the world

Dr. A. H. Shanthakumara 3 Dept. of CSE


 The function UPDATE-STATE is responsible for creating
the new internal state description
 It is seldom possible for the agent to determine the
current state of a partially observable environment
exactly.
Next Class: Goal-based agents, Utility-based agents,Learning agents,
How the components of agents programme work

Dr. A. H. Shanthakumara 4 Dept. of CSE


Goal-based agents:
 Knowing something about the current state of the
environment is not always enough to decide what to do.
 With current state description, the agent needs some
sort of goal information that describes situations that are
desirable

 Sometimes goal-based action selection is


straightforward - when goal satisfaction results
immediately from a single action.
 Sometimes it will be more tricky - when the agent has to
consider long sequences of twists and turns in order to
find a way to achieve the goal.
 Less efficient and more flexible because the knowledge
that supports its decisions is represented explicitly and
can be modified

Dr. A. H. Shanthakumara 1 Dept. of CSE


 Agent’s behavior can easily be changed to go to a
different destination, simply by specifying that
destination as the goal.
 Goals alone are not enough to generate high-quality
behavior in most environments.
Utility-based agents:
 An agent’s utility function is essentially an internalization
of the performance measure.
 If the internal utility function and the external
performance measure are in agreement, then an agent
that chooses actions to maximize its utility will be
rational according to the external performance measure
 The agent expects to derive, on average, given the
probabilities and utilities of each outcome.

Dr. A. H. Shanthakumara 2 Dept. of CSE


 A utility-based agent has many advantages in terms of
flexibility and learning
 In two kinds of cases, goals are inadequate but a utility-
based agent can still make rational decisions.
 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 against the importance of the goals.
Learning agents:
 How the agent programs come into being?

 A learning agent can be divided into four conceptual


components

Dr. A. H. Shanthakumara 3 Dept. of CSE


 Learning element, responsible for making
improvements
 The learning element can make changes to any of the
“knowledge” components
 Performance element responsible for selecting external
actions. it takes in percepts and decides on actions
 The critic tells the learning element how well the agent
is doing with respect to a fixed performance standard
 Problem generator is responsible for suggesting actions
that will lead to new and informative experiences
 if the agent is willing to explore a little and discover much
better actions for the long run
 The problem generator might identify certain areas of
behavior in need of improvement and suggest
experiments
 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.
 A process of modification of each component of the
agent to bring the components into closer agreement
with the available feedback information, thereby
improving the overall performance of the agent.
How the components of agent programs work:
 We can place the representations along an axis of
increasing complexity and expressive power—atomic,
factored, and structured.

Dr. A. H. Shanthakumara 4 Dept. of CSE


 In an atomic representation each state of the world is
indivisible—it has no internal structure.
 factored representation splits up each state into a fixed
set of variables or attributes, each of which can have a
value
 Two different factored states can share some attributes
 Much easier to work out how to turn one state into
another. With factored representations, we can also
represent uncertainty
 Many important areas of AI are based on factored
representations,
 constraint satisfaction algorithms, propositional logic,
planning, Bayesian networks and the machine learning
algorithms
 For many purposes, we need to understand the world as
having things in it that are related to each other, not just
variables with values

Dr. A. H. Shanthakumara 5 Dept. of CSE


 Structured representations underlie relational
databases and first-order logic, first-order probability
models, knowledge-based learning and much of natural
language understanding
 Next Class: Solving problems by Searching: problem-solving agents, well-defined problems
and solutions

Dr. A. H. Shanthakumara 6 Dept. of CSE


• The reflex agents, which base their actions on a direct
mapping from states to actions. Such agents cannot
operate well in environments
• Goal-based agents, consider future actions and the
desirability of their outcomes
• One kind of goal-based agent called a problem-solving
agent, with no internal structure visible to the problem
solving algorithms.
• Uninformed search algorithms-given no information
about the problem other than its definition
• Informed search algorithms-given some guidance on
where to look for solutions.
PROBLEM-SOLVING AGENTS:

• Agent can adopt a goal and aim at satisfying it.


• The agent’s performance measure contains many
factors
• The decision problem is a complex one involving many
tradeoffs
• Goals help organize behaviour by limiting the objectives
that the agent is trying to achieve and hence the
actions it needs to consider
• Goal formulation, is the first step in problem solving,
based on the current situation and the agent’s
performance measure.
• We will consider a goal to be a set of world states.
• The agent’s task is to find out how to act, now and in
the future, so that it reaches a goal state.

Dr. A. H. Shanthakumara 1 Dept. of CSE


o i.e. it needs to decide what sorts of actions and
states it should consider
o There might be too much uncertainty in the world
and there would be too many steps in a solution.
• Problem formulation is the process of deciding what
actions and states to consider, given a goal.
• if the environment is
o unknown, then it is has no choice but to try one of
the actions at random.
o The agent can use available information to
consider subsequent stages
• In general, an agent with several immediate options of
unknown value can decide what to do by first
examining future actions that eventually lead to states
of known value.
• To examining future actions we have to be more
specific about properties of the environment,
• we assume that the environment is
o observable, so the agent always knows the current
state
o discrete, so at any given state there are only
finitely many actions to choose from
o known, so the agent knows which states are
reached by each action.
o deterministic, so each action has exactly one
outcome.
• Under these assumptions, the solution to any problem
is a fixed sequence of actions

Dr. A. H. Shanthakumara 2 Dept. of CSE


• In general it could be a branching strategy that
recommends different actions in the future depending
on what percepts arrive.
• if the agent knows the initial state and the environment
is known and deterministic, it knows exactly where it
will be after the first action and what it will perceive.
• Since only one percept is possible after the first action,
the solution can specify only one possible second
action, and so on.
• The process of looking for a sequence of actions that
reaches the goal is called search.
• A search algorithm takes a problem as input and
returns a solution in the form of an action sequence.
• Once a solution is found, the actions it recommends can
be carried out. This is called the execution phase.
• After formulating a goal and a problem to solve, the
agent calls a search procedure to solve it. It then uses
the solution to guide its actions
• Once the solution has been executed, the agent will
formulate a new goal.

Dr. A. H. Shanthakumara 3 Dept. of CSE


Well-defined problems and solutions:
• A problem can be defined formally by five components:
1. The initial state that the agent starts in: In(Tumkur)
2. A description of the possible actions available to the
agent:
• Given a particular state s, ACTIONS(s) returns the
set of actions that can be executed in s.
• Example: {Go(Sira), Go(Hiriyur), Go(Chitradurga),
Go(Holalkere),….}
3. A description of what each action does; the formal
name for this is the transition model:
• Function RESULT(s, a) that returns the state that
results from doing action a in state s.
• Example: RESULT(In(Sira), Go(Hiriyur))=In(Hiriyur)
• Together, the initial state, actions, and transition model
implicitly define the state space of the problem

Dr. A. H. Shanthakumara 4 Dept. of CSE


• A path in the state space is a sequence of states
connected by a sequence of actions.
4. The goal test, which determines whether a given state
is a goal state. Sometimes there is an explicit set of
possible goal states, and the test simply checks whether
the given state is one of them
• goal=Formulate_Goal(Shivamogga)
5. A path cost function that assigns a numeric cost to each
path:
• function that reflects its own performance
measure
• Can be described as the of the costs of the
individual actions along the path.
• The step cost of taking action a in state s to reach
state s1 is denoted by c(s, a, s1)
• Example: C(Sira,50,Hiriyur)

• A solution to a problem is an action sequence that


leads from the initial state to a goal state.
• Solution quality is measured by the path cost function,
and an optimal solution has the lowest path cost
among all solutions.

Dr. A. H. Shanthakumara 5 Dept. of CSE


Example problem:

• Imagine an agent in the city of Arad, Romania, enjoying


a touring holiday
• The agent to adopt the goal of getting to Bucharest.
• Courses of action that don’t reach Bucharest on time
can be rejected
• The agent will consider actions at the level of driving
from one major town to another. Each state therefore
corresponds to being in a particular town.
• Three roads lead out of Arad, one toward Sibiu, one to
Timisoara, and one to Zerind. None of these achieves
the goal.
• The point of a map is to provide the agent with
information about the states it might get itself into and
the actions it can take

Dr. A. H. Shanthakumara 6 Dept. of CSE


• Must consider subsequent stages of a hypothetical
journey via each of the three towns, trying to find a
journey that eventually gets to Bucharest
• The environment is observable- each city on the map
has a sign indicating its presence to arriving drivers.
• The environment is discrete- each city is connected to a
small number of other cities.
• The environment is known- accurate map suffices to
meet this condition for navigation problems
• The environment is deterministic- if it chooses to drive
from Arad to Sibiu, it does end up in Sibiu.
Problem formulation:
• Initial state, currently in Arad. In(Arad)
• Formulate goal:
o be in Bucharest
• Formulate problem:
o states: various cities
o actions: drive between cities
• Find solution:
o sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
Next class:
Example problems (Self learning)

Searching for Solutions: infrastructure for search algorithms, measuring problem-solving performance

Dr. A. H. Shanthakumara 7 Dept. of CSE


SEARCHING FOR SOLUTIONS:

• A solution is an action sequence


• 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 root node of the tree corresponds to the initial
state (Test whether this is a goal state).
• Expand the current state; that is, applying each legal
action to the current state, thereby generating a new
set of states.
• This is the essence of search—following up one option
now and putting the others aside for later, in case the
first choice does not lead to a solution.
• The set of all leaf nodes available for expansion at any
given point is called the frontier(Open list)
• The process of expanding nodes on the frontier
continues until either a solution is found or there are no
more states to expand

Dr. A. H. Shanthakumara 1 Dept. of CSE


Example:

Dr. A. H. Shanthakumara 2 Dept. of CSE


• Redundant paths are unavoidable.
• Redundant paths can cause a tractable problem to
become intractable(true even for algorithms that know
how to avoid infinite loops)
• The way to avoid exploring redundant paths is to
remember where one has been.
• TREE-SEARCH algorithm with a data structure called the
explored set, which remembers every expanded node
• The frontier separates the state-space graph into the
explored region and the unexplored region

Infrastructure for search algorithms:


• For each node n of the tree, we have a structure that
contains four components:
• n.STATE: the state in the state space to which the node
corresponds;
• n.PARENT: the node in the search tree that generated
this node;
• n.ACTION: the action that was applied to the parent to
generate the node;

Dr. A. H. Shanthakumara 3 Dept. of CSE


• n.PATH-COST: the cost, traditionally denoted by g(n), of
the path from the initial state to the node, as indicated
by the parent pointers.
states vs. nodes:
• A state is a (representation of) a physical configuration
• A node is a data structure constituting part of a search
tree
o includes parent, children, depth, path cost g(x)
• States do not have parents, children, depth, or path
cost!


• The Expand function creates new nodes, filling in the
various fields and using the SuccessorFn of the problem
to create the corresponding states.
• The function CHILD-NODE takes a parent node and an
action and returns the resulting child node:

Dr. A. H. Shanthakumara 4 Dept. of CSE


Measuring problem-solving performance:
• Consider the criteria that might be used to choose
specific search algorithms
• 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
• Time complexity: How long does it take to find a
solution?
• Space complexity: How much memory is needed to
perform the search?
• Time is often measured in terms of the number of
nodes generated during the search, and space in terms
of the maximum number of nodes stored in memory.
• We can use the total cost, which combines the search
cost and the path cost of the solution found.
Next class: Uniformed Search strategies: BFS, uniform-cost search

Dr. A. H. Shanthakumara 5 Dept. of CSE


UNINFORMED SEARCH STRATEGIES:

• The strategies have no additional information about


states beyond that provided in the problem definition
• Will generate successors and distinguish a goal state
from a non-goal state.
• All search strategies are distinguished by the order in
which nodes are expanded.
• Breadth-first search, Uniform-cost search, Depth-first
search, Depth-limited search, Iterative deepening
search
Breadth-first search:
• A simple strategy in which the root node is expanded
first, then all the successors of the root node are
expanded next, then their successors, and so on
• The shallowest unexpanded node is chosen for
expansion
• Uses a FIFO queue for the frontier
• The new nodes (which are always deeper than their
parents) go to the back of the queue, and old nodes,
which are shallower than the new nodes, get expanded
first.
• The goal test is applied to each node when it is
generated rather than when it is selected for
expansion.
• Discards any new path to a state already in the frontier
or explored set

Dr. A. H. Shanthakumara 1 Dept. of CSE


Implementation:
• fringe is a FIFO queue, i.e., new successors go at end

Dr. A. H. Shanthakumara 2 Dept. of CSE


Properties of breadth-first search:
Complete??
• Yes, if the shallowest goal node is at some finite depth
d, breadth-first search will eventually find it after
generating all shallower nodes
Time??
• Imagine searching a uniform tree where every state has
b successors.
• The root of the search tree generates b nodes at the
first level, each of which generates b more nodes
• Now suppose that the solution is at depth d, the total
number of nodes generated is
• 1 + b + b2 + b3 + : : : + bd = O(bd+1), i.e., exp. in d
Space??
• stores every expanded node in the explored set, the
space complexity is always within a factor of b of the
time complexity
• O(bd+1) (keeps every node in memory)
Optimal??
• optimal if the path cost is a nondecreasing function of
the depth of the node. The most common such scenario
is that all actions have the same cost
• Space is the big problem; can easily generate nodes at
100MB/sec
• so 24hrs = 8640GB.

Dr. A. H. Shanthakumara 3 Dept. of CSE


Uniform-cost search:
• When all step costs are equal, breadth-first search is
optimal
• Instead of expanding the shallowest node, uniform-cost
search expands the node n with the lowest path cost
g(n). This is done by storing the frontier as a priority
queue ordered by g.

• Two other significant differences from breadth-first


search:
o The goal test is applied to a node when it is selected
for expansion rather than when it is first generated
o A test is added in case a better path is found to a
node currently on the frontier.
• Uniform-cost search does not care about the number of
steps a path has, but only about their total cost
• Therefore, it will get stuck in an infinite loop if there is a
path with an infinite sequence of zero-cost actions

Dr. A. H. Shanthakumara 4 Dept. of CSE


Properties of Uniform-cost search:
Complete??
• Completeness is guaranteed provided the cost of every
step exceeds some small positive constant ϵ
Time and space??
• Uniform-cost search is guided by path costs rather than
depths, so its complexity is not easily characterized in
terms of b and d. Instead, let C∗ be the cost of the
optimal solution
• With the assumption that every action costs at least ϵ,
worst-case time and space complexity is O(b1+‖C∗/ϵ‖),
which can be much greater than bd.
Optimal??
• Yes, nodes expanded in increasing order of g(n)
• When all step costs are the same, uniform-cost search
is similar to breadth-first search
Next class: DFS, depth-limited search, iterative deepening depth-first search, bidirectional
search, comparing uniformed search strategies

Dr. A. H. Shanthakumara 5 Dept. of CSE


Depth-first search:
• Always expands the deepest node in the current
frontier of the search tree.
• The search proceeds immediately to the deepest level
of the search tree, where the nodes have no successors
• Uses a LIFO Stack- the most recently generated
(deepest unexpanded) node is chosen for expansion
Implementation:
• A recursive function that calls itself on each of its
children in turn.
• fringe = LIFO Stack, i.e., put successors at front

Dr. A. H. Shanthakumara 1 Dept. of CSE


Properties of Depth-first search:
Complete??
• No: fails in infinite-depth spaces, spaces with loops
• Modify to avoid repeated states along path complete
infinite spaces
Time??
• It is bounded by the size of the state space

Dr. A. H. Shanthakumara 2 Dept. of CSE


• O(bm): where m is the maximum depth of any node and
it is terrible if m is much larger than d
• but if solutions are dense, may be much faster than
breadth-first
Space??
• O(bm), i.e., linear space!
Optimal??
• Depth first search will explore the entire left subtree
even if node C is a goal node, which would be a better
solution; hence, depth-first search is not optimal
Depth-limited search:
• It is a depth-first search with a predetermined depth
limit l to solves the infinite-path problem
• Nodes at depth l are treated as if they have no
successors.

Dr. A. H. Shanthakumara 3 Dept. of CSE


• Unfortunately,
o It introduces an additional source of
incompleteness if we choose l < d, that is, the
shallowest goal is beyond the depth limit.
o It is nonoptimal if we choose l > d. Its time
complexity is O(bl) and its space complexity is
O(bl).
Iterative deepening depth-first search:
• A general strategy, used with depth-first tree search,
that finds the best depth limit.
• It does this by gradually increasing the limit—first 0,
then 1, then 2, and so on—until a goal is found.
• Iterative deepening combines the benefits of depth-
first and breadth-first search.

Four iterations of iterative deepening search on a binary


tree:

Dr. A. H. Shanthakumara 4 Dept. of CSE


Properties of iterative deepening search:
• Complete?? It is complete when the branching factor is
finite and optimal when the path cost is a
nondecreasing function of the depth of the node
• Time?? (d + 1)b0 + db1 + (d - 1)b2 + : : : + bd = O(bd)
• Space?? O(bd)
• Optimal?? Yes, if step cost = 1
• Can be modified to explore uniform-cost tree

Dr. A. H. Shanthakumara 5 Dept. of CSE


Bidirectional 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—hoping
that the two searches meet in the middle

• Replace the goal test with a check to see whether the


frontiers of the two searches intersect; if they do, a
solution has been found.
Comparing uninformed search strategies:

Next class: Informed search strategies: Greedy best-first search, A* search,

Dr. A. H. Shanthakumara 6 Dept. of CSE


INFORMED (HEURISTIC) SEARCH STRATEGIES:
• Uses problem-specific knowledge beyond the definition
of the problem itself
• More efficiently than an uninformed strategy.
• Use of f, a heuristic function, instead of g (in uniform-
cost search) to order the priority queue, denoted h(n):
• h(n) = estimated cost of the cheapest path from the
state at node n to a goal state.
• It is arbitrary, nonnegative, problem-specific functions,
with one constraint: if n is a goal node, then h(n)=0.
Greedy best-first search:
• Tries to expand the node that is closest to the goal, on
the grounds that this is likely to lead to a solution
quickly.
• It evaluates nodes by using just the heuristic function;
that is, f(n) = h(n).
Example : route-finding problems in Romania(to find a
path from Arad to Bucharest)
• We use the straight line distance heuristic, which we
will call hSLD
• We need to know the straight-line distances to
Bucharest

Dr. A. H. Shanthakumara 1 Dept. of CSE


Dr. A. H. Shanthakumara 2 Dept. of CSE
• The first node to be expanded from Arad will be Sibiu
because it is closer to Bucharest than either 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.
• Finds a solution without ever expanding a node that is
not on the solution path; hence, its search cost is
minimal
• But not optimal, the path via Sibiu and Fagaras to
Bucharest is 32 kilometers longer than the path through
Rimnicu Vilcea and Pitesti.
• It is also incomplete even in a finite state space (the
problem of getting from Iasi to Fagaras)

Dr. A. H. Shanthakumara 3 Dept. of CSE


• The worst-case
case time and space complexity for the tree
version is O(bm), where m is the maximum depth of the
search space.
Find the route from Tumkur to Shivamogga using Greedy
best first search:
Node hSLD Node hSLD
Tumkur 220 Hosadurga 105
KB Cross 155 Hiriyur 145
Sira 185 Arasikere 110
Tiptur 135 Holalkere 75
Chitradurga 105 Shivamogga 0

A* search: Minimizing the total estimated solution cost:


cost
• It evaluates nodes by combining g(n), the cost to reach
the node, and h(n), the cost to get from the node to the
goal:

Dr. A. H. Shanthakumara 4 Dept. of CSE


• f(n) = g(n) + h(n).
• 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.
• The algorithm is identical to UNIFORM-COST-SEARCH
except that A∗ uses g + h instead of g.

Dr. A. H. Shanthakumara 5 Dept. of CSE


• The tree-search version of A∗ is optimal if h(n) is
admissible, while the graph-search version is optimal if
h(n) is consistent.
• That A∗ search is complete, optimal, and optimally
efficient among all such algorithms is rather satisfying.
• Unfortunately, it does not mean that A∗ is the answer
to all our searching needs.
Find the route from Tumkur to Shivamogga using A∗
search:
Node hSLD Node hSLD
Tumkur 220 Hosadurga 105
KB Cross 155 Hiriyur 145
Sira 185 Arasikere 110
Tiptur 135 Holalkere 75
Chitradurga 105 Shivamogga 0

Dr. A. H. Shanthakumara 6 Dept. of CSE


Next class: Memory-bounded
bounded heuristic search, learning to search better,,

Dr. A. H. Shanthakumara 7 Dept. of CSE


Memory-bounded heuristic search:
∗ (IDA∗
Iterative-deepening A∗ ∗):
• Reduce the memory requirements for A∗ by adapting
the idea of iterative deepening to the heuristic search
context
• The cutoff used is the f-cost (g+h) rather than the depth
• The cutoff value is the smallest f-cost of any node that
exceeded the cutoff on the previous iteration
• It suffers from the real valued costs
Recursive best-first search (RBFS):
• Simple recursive algorithm that attempts to mimic the
operation of standard best-first search
• 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 available from any ancestor of
the current node.

Dr. A. H. Shanthakumara 1 Dept. of CSE



• RBFS is somewhat more efficient than IDA∗, but still
suffers from excessive node regeneration.
• Each mind change, could require many reexpansions of
forgotten nodes to recreate the best path and extend it
one more node
• RBFS is an optimal algorithm if the heuristic function
h(n) is admissible.
• Space complexity is linear in the depth of the deepest
optimal solution

Dr. A. H. Shanthakumara 2 Dept. of CSE


• Time complexity is rather difficult to characterize: it
depends both on the accuracy of the heuristic function
and on how often the best path changes as nodes are
expanded.
Learning to search better:
• Could an agent learn how to search better?
• The answer is yes, and the method rests on an
important concept called the metalevel state space.
• Each state in a metalevel state space captures the
internal (computational) state of a program that is
searching in an object-level state space
• Each action in the metalevel state space is a
computation step that alters the internal state
• Metalevel learning algorithm can learn from the
experiences to avoid exploring unpromising subtrees
• The goal of learning is to minimize the total cost of
problem solving, trading off computational expense and
path cost

Dr. A. H. Shanthakumara 3 Dept. of CSE

You might also like