Unit 1 2
Unit 1 2
Intelligence
Course Outcomes
CO1 Understanding about concept and definition AI along with
its agents , its structure and environments (L2)
CO2 Apply various AI search algorithms (uninformed, informed,
heuristic, constraint satisfaction, genetic algorithms). (L3)
CO3 Apply the reinforcement learning and natural language
processing in AI. (L3)
CO4 Apply the natural language for communication and
understand the perception of image formation,
reconstruction of 3D world etc., (L3, L2)
CO5 Understand the Robotic perception like planning to move
etc., and to understand the Philosophical foundation of AI.
(L2)
ARTIFICIAL INTELLIGENCE
UNIT-I
Goals of AI
• To Create Expert Systems − The systems which exhibit intelligent behavior, learn,
demonstrate, explain, and advice its users.
• To Implement Human Intelligence in Machines − Creating systems that understand, think,
learn, and behave like humans.
5. A spying aeroplane takes photographs, which are used to figure out spatial information or
map of the areas.
6. Doctors use clinical expert system to diagnose the patient.
7. Police use computer software that can recognize the face of criminal with the stored
portrait made by forensic artist.
8. Speech Recognition − Some intelligent systems are capable of hearing and comprehending
the language in terms of sentences and their meanings while a human talks to it. It can
handle different accents, slang words, noise in the background, change in human’s noise
due to cold, etc.
9. Handwriting Recognition − The handwriting recognition software reads the text written
on paper by a pen or on screen by a stylus. It can recognize the shapes of the letters and
convert it into editable text.
10. Intelligent Robots − Robots are able to perform the tasks given by a human. They have
sensors to detect physical data from the real world such as light, heat, temperature,
movement, sound, bump, and pressure. They have efficient processors, multiple sensors
and huge memory, to exhibit intelligence. In addition, they are capable of learning from
their mistakes and they can adapt to the new environment.
History of AI
At that time high-level computer languages such as FORTRAN, LISP, or COBOL were invented.
And the enthusiasm for AI was very high at that time.
A boom of AI (1980-1987)
1. Year 1980: After AI winter duration, AI came back with "Expert System". Expert systems
were programmed that emulate the decision-making ability of a human expert.
2. In the Year 1980, the first national conference of the American Association of Artificial
Intelligence was held at Stanford University.
STATE OF ART
An agent is anything that can be viewed as perceiving its environment through sensors and
sensor acting upon that environment through actuators.
1. A human agent has eyes, ears, and other organs for sensors and hands, legs, mouth, and
other body parts for actuators.
2. A robotic agent might have cameras and infrared range finders for sensors and various
motors for actuators.
3. A software agent receives keystrokes, file contents, and network packets as sensory
inputs and acts on the environment by displaying on the screen, writing files, and
sending network packets.
FIG:AGENT WORKING
Sensor: Sensor is a device which detects the change in the environment and sends the information
to other electronic devices. An agent observes its environment through sensors.
Actuators: Actuators are the component of machines that converts energy into motion. The
actuators are only responsible for moving and controlling a system. An actuator can be an electric
motor, gears, rails, etc.
Effectors: Effectors are the devices which affect the environment. Effectors can be legs, wheels,
arms, fingers, wings, fins, and display screen.
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
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 program
1. The agent function for an artificial agent will be implemented by an agent program.
2. It is important to keep these two ideas distinct.
3. The agent function is an abstract mathematical description;
4. the agent program is a concrete implementation, running on the agent architecture.
5. To illustrate these ideas, we will use a very simple example-the vacuum-cleaner world
shown in Figure.
6. This particular world has just two locations: squares A and B.
7. The vacuum agent perceives which square it is in and whether there is dirt in
square.
8. It can choose to move left, move right, suck up the dirt, or do nothing.
9. One very simple agent function is the following:
10. if the current square is dirty, then suck, otherwise,
11. it move to the other square.
12. A partial tabulation of this agent function is shown in Figure.
Agent function
Agent program
function Reflex-VACUUM-AGENT ([locations, status]) returns an
action if status = Dirty then return Suck
else if location = A then return Right
elseif location = B then return Left
Intelligent Agents:
An intelligent agent is an autonomous entity which act upon an environment using sensors and
actuators for achieving goals. An intelligent agent may learn from the environment to achieve their
goals. A thermostat is an example of an intelligent agent.
Structure of an AI Agent
The task of AI is to design an agent program which implements the agent function. The structure of
an intelligent agent is a combination of architecture and agent program. It can be viewed as:
Following are the main three terms involved in the structure of an AI agent:
Rational Agent:
A rational agent is an agent which has clear preference, models uncertainty, and acts in a way to
maximize its performance measure with all possible actions.
A rational agent is said to perform the right things. AI is about creating rational agents to use for
game theory and decision theory for various real-world scenarios.
For an AI agent, the rational action is most important because in AI reinforcement learning
algorithm, for each best possible action, agent gets the positive reward and for each wrong action,
an agent gets a negative reward.
Rationality:
The rationality of an agent is measured by its performance measure. Rationality can be judged on
the basis of following points:
Performance measures
PEAS is a type of model on which an AI agent works upon. When we define an AI agent or
rational agent, then we can group its properties under PEAS representation model. It is made up
of four words:
o P: Performance measure
o E: Environment
o A: Actuators
o S: Sensors
Examples:
2) Medical Diagnose
3) Vacuum Cleaner
Performance: Cleanness,Efficiency,Battery life,Security
Environment: Patient,Hospital,Staff
Types of Agents
Agents can be grouped into four classes based on their degree of perceived intelligence and capability :
• Simple Reflex Agents
• Model-Based Reflex Agents
• Goal-Based Agents
• Utility-Based Agents
• Learning Agent
Simple reflex agents ignore the rest of the percept history and act only on the basis of the current percept.
Percept history is the history of all that an agent has perceived to date. The agent function is based on
the condition-action rule. A condition-action rule is a rule that maps a state i.e, condition to an action. If the
condition is true, then the action is taken, else not. This agent function only succeeds when the environment is
fully observable. For simple reflex agents operating in partially observable environments, infinite loops are
often unavoidable. It may be possible to escape from infinite loops if the agent can randomize its actions.
Goal-based agents
These kinds of agents take decisions based on how far they are currently from their goal(description of
desirable situations). Their every action is intended to reduce its distance from the goal. This allows the agent a
way to choose among multiple possibilities, selecting the one which reaches a goal state. The knowledge that
supports its decisions is represented explicitly and can be modified, which makes these agents more flexible.
They usually require search and planning. The goal-based agent’s behavior can easily be changed.
Utility-based agents
The agents which are developed having their end uses as building blocks are called utility-based agents. When
there are multiple possible alternatives, then to decide which one is best, utility-based agents are used. They
choose actions based on a preference (utility) for each state. Sometimes achieving the desired goal is not
enough. We may look for a quicker, safer, cheaper trip to reach a destination. Agent happiness should be taken
into consideration. Utility describes how “happy” the agent is. Because of the uncertainty in the world, a
utility agent chooses the action that maximizes the expected utility. A utility function maps a state onto a real
number which describes the associated degree of happiness.
Learning Agent :
A learning agent in AI is the type of agent that can learn from its past experiences or it has learning
capabilities. It starts to act with basic knowledge and then is able to act and adapt automatically through
learning.
A learning agent has mainly four conceptual components, which are:
1. Learning element: It is responsible for making improvements by learning from the environment
2. Critic: The learning element takes feedback from critics which describes how well the agent is doing with
respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action
4. Problem Generator: This component is responsible for suggesting actions that will lead to new and
informative experiences.
An environment is everything in the world which surrounds the agent, but it is not a part of an
agent itself. An environment can be described as a situation in which an agent is present.
The environment is where agent lives, operate and provide the agent with something to sense and
act upon it. An environment is mostly said to be non-feministic.
An environment is everything in the world which surrounds the agent, but it is not a part of an
agent itself. An environment can be described as a situation in which an agent is present.
The environment is where agent lives, operate and provide the agent with something to sense and
act upon it. An environment is mostly said to be non-feministic.
Features of Environment
An environment can have various features from the point of view of an agent:
1. Fully observable vs Partially Observable
2. Static vs Dynamic
3. Discrete vs Continuous
4. Deterministic vs Stochastic
5. Single-agent vs Multi-agent
6. Episodic vs sequential
7. Known vs Unknown
8. Accessible vs Inaccessible
2. Deterministic vs Stochastic:
1. If an agent's current state and selected action can completely determine the next state of the
environment, then such environment is called a deterministic environment.
2. A stochastic environment is random in nature and cannot be determined completely by an
agent.
3. In a deterministic, fully observable environment, agent does not need to worry about
uncertainty.
3. Episodic vs Sequential:
1. In an episodic environment, there is a series of one-shot actions, and only the current
percept is required for the action.
5. Static vs Dynamic:
1. If the environment can change itself while an agent is deliberating then such environment is
called a dynamic environment else it is called a static environment.
2. Static environments are easy to deal because an agent does not need to continue looking at
the world while deciding for an action.
3. However for dynamic environment, agents need to keep looking at the world at each action.
4. Taxi driving is an example of a dynamic environment whereas Crossword puzzles are an
example of a static environment.
6. Discrete vs Continuous:
1. If in an environment there are a finite number of percepts and actions that can be performed
within it, then such an environment is called a discrete environment else it is called
continuous environment.
2. A chess gamecomes under discrete environment as there is a finite number of moves that
can be performed.
3. A self-driving car is an example of a continuous environment.
7. Known vs Unknown
1. Known and unknown are not actually a feature of an environment, but it is an agent's state
of knowledge to perform an action.
2. In a known environment, the results for all actions are known to the agent. While in
unknown environment, agent needs to learn how it works in order to perform an action.
3. It is quite possible that a known environment to be partially observable and an Unknown
environment to be fully observable.
8. Accessible vs Inaccessible
1. If an agent can obtain complete and accurate information about the state's environment,
then such an environment is called an Accessible environment else it is called inaccessible.
2. An empty room whose state can be defined by its temperature is an example of an
accessible environment.
3. Information about an event on earth is an example of Inaccessible environment.
28 Chapter 1. Introduction
new patterns that help label new examples. Banko and Brill (2001) show that techniques
like this perform even better as the amount of available text goes from a million words to a
billion and that the increase in performance from using more data exceeds any difference in
algorithm choice; a mediocre algorithm with 100 million words of unlabeled training data
outperforms the best known algorithm with 1 million words.
As another example, Hays and Efros (2007) discuss the problem of filling in holes in a
photograph. Suppose you use Photoshop to mask out an ex-friend from a group photo, but
now you need to fill in the masked area with something that matches the background. Hays
and Efros defined an algorithm that searches through a collection of photos to find something
that will match. They found the performance of their algorithm was poor when they used
a collection of only ten thousand photos, but crossed a threshold into excellent performance
when they grew the collection to two million photos.
Work like this suggests that the “knowledge bottleneck” in AI—the problem of how to
express all the knowledge that a system needs—may be solved in many applications by learn-
ing methods rather than hand-coded knowledge engineering, provided the learning algorithms
have enough data to go on (Halevy et al., 2009). Reporters have noticed the surge of new ap-
plications and have written that “AI Winter” may be yielding to a new Spring (Havenstein,
2005). As Kurzweil (2005) writes, “today, many thousands of AI applications are deeply
embedded in the infrastructure of every industry.”
What can AI do today? A concise answer is difficult because there are so many activities in
so many subfields. Here we sample a few applications; others appear throughout the book.
Robotic vehicles: A driverless robotic car named S TANLEY sped through the rough
terrain of the Mojave dessert at 22 mph, finishing the 132-mile course first to win the 2005
DARPA Grand Challenge. S TANLEY is a Volkswagen Touareg outfitted with cameras, radar,
and laser rangefinders to sense the environment and onboard software to command the steer-
ing, braking, and acceleration (Thrun, 2006). The following year CMU’s B OSS won the Ur-
ban Challenge, safely driving in traffic through the streets of a closed Air Force base, obeying
traffic rules and avoiding pedestrians and other vehicles.
Speech recognition: A traveler calling United Airlines to book a flight can have the en-
tire conversation guided by an automated speech recognition and dialog management system.
Autonomous planning and scheduling: A hundred million miles from Earth, NASA’s
Remote Agent program became the first on-board autonomous planning program to control
the scheduling of operations for a spacecraft (Jonsson et al., 2000). R EMOTE AGENT gen-
erated plans from high-level goals specified from the ground and monitored the execution of
those plans—detecting, diagnosing, and recovering from problems as they occurred. Succes-
sor program MAPGEN (Al-Chang et al., 2004) plans the daily operations for NASA’s Mars
Exploration Rovers, and MEXAR2 (Cesta et al., 2007) did mission planning—both logistics
and science planning—for the European Space Agency’s Mars Express mission in 2008.
Section 1.5. Summary 29
Game playing: IBM’s D EEP B LUE became the first computer program to defeat the
world champion in a chess match when it bested Garry Kasparov by a score of 3.5 to 2.5 in
an exhibition match (Goodman and Keene, 1997). Kasparov said that he felt a “new kind of
intelligence” across the board from him. Newsweek magazine described the match as “The
brain’s last stand.” The value of IBM’s stock increased by $18 billion. Human champions
studied Kasparov’s loss and were able to draw a few matches in subsequent years, but the
most recent human-computer matches have been won convincingly by the computer.
Spam fighting: Each day, learning algorithms classify over a billion messages as spam,
saving the recipient from having to waste time deleting what, for many users, could comprise
80% or 90% of all messages, if not classified away by algorithms. Because the spammers are
continually updating their tactics, it is difficult for a static programmed approach to keep up,
and learning algorithms work best (Sahami et al., 1998; Goodman and Heckerman, 2004).
Logistics planning: During the Persian Gulf crisis of 1991, U.S. forces deployed a
Dynamic Analysis and Replanning Tool, DART (Cross and Walker, 1994), to do automated
logistics planning and scheduling for transportation. This involved up to 50,000 vehicles,
cargo, and people at a time, and had to account for starting points, destinations, routes, and
conflict resolution among all parameters. The AI planning techniques generated in hours
a plan that would have taken weeks with older methods. The Defense Advanced Research
Project Agency (DARPA) stated that this single application more than paid back DARPA’s
30-year investment in AI.
Robotics: The iRobot Corporation has sold over two million Roomba robotic vacuum
cleaners for home use. The company also deploys the more rugged PackBot to Iraq and
Afghanistan, where it is used to handle hazardous materials, clear explosives, and identify
the location of snipers.
Machine Translation: A computer program automatically translates from Arabic to
English, allowing an English speaker to see the headline “Ardogan Confirms That Turkey
Would Not Accept Any Pressure, Urging Them to Recognize Cyprus.” The program uses a
statistical model built from examples of Arabic-to-English translations and from examples of
English text totaling two trillion words (Brants et al., 2007). None of the computer scientists
on the team speak Arabic, but they do understand statistics and machine learning algorithms.
These are just a few examples of artificial intelligence systems that exist today. Not
magic or science fiction—but rather science, engineering, and mathematics, to which this
book provides an introduction.
1.5 S UMMARY
This chapter defines AI and establishes the cultural background against which it has devel-
oped. Some of the important points are as follows:
• Different people approach AI with different goals in mind. Two important questions to
ask are: Are you concerned with thinking or behavior? Do you want to model humans
or work from an ideal standard?
UNIT 2
Problem-solving agents:
Search algorithm
A search algorithm is the step-by-step procedure used to locate specific data among a collection of
data. It is considered a fundamental procedure in computing. In computer science, when searching for
data, the difference between a fast application and a slower one often lies in the use of the proper search
algorithm
Search Algorithm Terminologies
1. Search: Searchingis a step by step procedure to solve a search-problem in a given search space. A
search problem can have three main factors:
a. Search Space: Search space represents a set of possible solutions, which a system may
have.
b. Start State: It is a state from where agent begins the search.
c. Goal test: It is a function which observe the current state and returns whether the goal state
is achieved or not.
2. Search tree: A tree representation of search problem is called Search tree. The root of the search
tree is the root node which is corresponding to the initial state.
3. Actions: It gives the description of all the available actions to the agent.
4. Transition model: A description of what each action do, can be represented as a transition model.
5. Path Cost: It is a function which assigns a numeric cost to each path.
6. Solution: It is an action sequence which leads from the start node to the goal node.
7. Optimal Solution: If a solution has the lowest cost among all solutions.
Following are the four essential properties of search algorithms to compare the efficiency of these
algorithms:
Completeness: A search algorithm is said to be complete if it guarantees to return a solution if at least any
solution exists for any random input.
10 Sec
Optimality: If a solution found for an algorithm is guaranteed to be the best solution (lowest path cost)
among all other solutions, then such a solution for is said to be an optimal solution.
Time Complexity: Time complexity is a measure of time for an algorithm to complete its task.
Space Complexity: It is the maximum storage space required at any point during the search, as the
complexity of the problem.
Steps problem-solving in AI
The problem of AI is directly associated with the nature of humans and their activities. So we need a
number of finite steps to solve a problem which makes human easy works.
These are the following steps which require to solve a problem :
• Goal Formulation: This one is the first and simple step in problem-solving. It organizes finite steps to
formulate a target/goals which require some action to achieve the goal. Today the formulation of the
goal is based on AI agents.
• Problem formulation: It is one of the core steps of problem-solving which decides what action
should be taken to achieve the formulated goal. In AI this core part is dependent upon software agent
which consisted of the following components to formulate the associated problem.
EXAMPLE PROBLEMS
a. The problem solving approach has been applied to a vast array of task environments.
i. Some best known problems are summarized below.
b. They are distinguished as toy or real-world problems
1. A Toy problem is intended to illustrate various problem solving
methods. It can be easily used by different researchers to compare the
performance of algorithms.
2. A Real world problem is one whose solutions people actually care
about.
TOY PROBLEMS
1. 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.
2. Initial state: Any state can be designated as initial state.
3. 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 2.3
4. Goal Test : This tests whether all the squares are clean.
5. Path test : Each step costs one ,so that the the path cost is the number of steps in the path.
8-puzzle:
1. An 8-puzzle consists of a 3x3 board with eight numbered tiles and a blank space.
2. A tile adjacent to the blank space can slide into the space. The object is to reach the specific
goal state ,as shown in figure
a. States : A state description specifies the location of each of the eight tiles and the blank in one
of the nine squares.
b. 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.
c. Successor function : This generates the legal states that result from trying the four actions (blank
moves Left,Right,Vp or down).
d. Goal Test : This checks whether the state matches the goal configuration shown in figure
2.4.(Other goal configurations are possible)
e. Path cost: Each step costs 1,so the path cost is the number of steps in the path.
f. The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as
i. test problems for new search algorithms in AI.
g. This general class is known as NP-complete.
h. The 8-puzzle has 9!/2 = 181,440 reachable states and is easily solved.
i. 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.
j. 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.
8- queens problem
1. 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).
2. The following figure shows an attempted solution that fails: the queen in the right most column
is attacked by the queen at the top left.
3. 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.
4. A complete-state formulation starts with all 8 queens on the board and move them around.
5. In either case the path cost is of no interest because only the final state counts.
8-queens problem
The first incremental formulation one might try is the following :
This formulation reduces the 8-queen state space from 3 x 1014 to just 2057,and solutions are easy to
find.
a. For the 100 queens the initial formulation has roughly 10400 states whereas the
improved formulation has about 1052 states.
b. This is a huge reduction, but the improved state space is still too big for the algorithms
to handle.
1. A real world problem is one whose solutions people actually care about.
2. They tend not to have a single agreed upon description, but attempt is made to give general flavor
of their formulation,
The following are the some real world problems,
a. Route Finding Problem
b. Touring Problems
c. Travelling Salesman Problem
d. Robot Navigation
ROUTE-FINDING PROBLEM
1. Route-finding problem is defined in terms of specified locations and transitions along links
between them.
2. Route-finding algorithms are used in a variety of applications, such as routing in computer
networks, military operations planning, and air line travel planning systems.
TOURING PROBLEMS
1. TSP is a touring problem in which each city must be visited exactly once.
2. The aim is to find the shortest tour. The problem is known to be NP-hard.
3. Enormous efforts have been expended to improve the capabilities of TSP algorithms.
4. These algorithms are also used in tasks such as planning movements of automatic circuit-board
drills and of stocking machines on shop floors.
VLSI layout
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 is split into two parts : cell layout and channel routing.
ROBOT NAVIGATION
ROBOT navigation is a generalization of the route-finding problem. Rather than a discrete set of
routes,a robot can move in a continuous space with an infinite set of possible actions and states. For a
circular Robot moving on a flat surface,the space is essentially two-dimensional.
When the robot has arms and legs or wheels that also must be controlled,the search space becomes multi-
dimensional. Advanced techniques are required to make the search space finite.
The example includes assembly of intricate objects such as electric motors. The aim in assembly problems
is to find the order in which to assemble the parts of some objects. If the wrong order is choosen, there
will be no way to add some part later without undoing somework already done.
Another important assembly problem is protein design, in which the goal is to find a sequence of
Amino acids that will be fold into a three-dimensional protein with the right properties to cure some
disease.
INTERNET SEARCHING
In recent years there has been increased demand for software robots that perform Internet searching,
looking for answers to questions, for related information, or for shopping deals.
The searching techniques consider internet as a graph of nodes (pages) connected by links.
The output of problem-solving algorithm is either failure or a solution. (Some algorithms might struck in
an infinite loop and never return an output.)
State Spaces
One general formulation of intelligent action is in terms of a state space. A state contains all of the
information necessary to predict the effects of an action and to determine whether a state satisfies the
goal.
Assumptions of State-space searching :
1. The agent has perfect knowledge of the state space and is planning for the case where it observes
what state it is in: there is full observability.
2. The agent has a set of actions that have known deterministic effects.
3. The agent can determine whether a state satisfies the goal
1. A set of states
2. A distinguished state called the start state
3. For each state, a set of actions available to the agent in that state
4. an action function that, given a state and an action, returns a new state
5. A goal specified as a Boolean function, goal(s)goal(s), that is true when state ss satisfies the
goal, in which case we say that ss is a goal state
6. A criterion that specifies the quality of an acceptable solution. For example, any sequence of
actions that gets the agent to the goal state may be acceptable, or there may be costs associated
with actions and the agent may be required to find a sequence that has minimal total cost. A
solution that is best according to some criterion is called an optimal solution. We do not always
need an optimal solution, for example, we may be satisfied with any solution that is within 10%
of optimal.
Graph Searching
1. The problem of finding a sequence of actions to achieve a goal is abstracted as searching for
paths in directed graphs.
2. To solve a problem, first define the underlying search space and then apply a search
algorithm to that search space.
3. Many problem-solving tasks are transformable into the problem of finding a path in a graph.
A generic algorithm to search for a solution path in a graph. The algorithm calls procedures that can
be coded to implement various search strategies.
FIG: Problem solving by graph searching
The intuitive idea behind the generic search algorithm, given a graph, a start node, and a goal predicate, is to
explore paths incrementally from the start node. This is done by maintaining a frontier (or fringe) of paths
from the start node. The frontier contains all of the paths that could form initial segments of paths from the
start node to a goal node Initially, the frontier contains the trivial path containing just the start node, and no
arcs. As the search proceeds, the frontier expands into the unexplored nodes until a goal node is
encountered. Different search strategies are obtained by providing an appropriate implementation of the
frontier.
1.procedure Search(G,S,goalG,S,goal)
2: Inputs
3: GG: graph with nodes NN and arcs AA
4: ss: start node
5: goal: Boolean function of nodes
6: Output
7: path from ss to a node for which goal is true
8: or ⊥⊥ if there are no solution paths
9: Local
10: Frontier: set of paths
11: Frontier:={⟨s⟩}Frontier:={⟨s⟩}
12: while Frontier≠{}Frontier≠{} do
13: select and remove ⟨n0,…,nk⟩⟨n0,…,nk⟩ from Frontier
14: if goal(nk)goal(nk) then
15: return ⟨n0,…,nk⟩⟨n0,…,nk⟩
16: Frontier:=Frontier∪{⟨n0,…,nk,n⟩:⟨nk,n⟩∈A}Frontier:=Frontier∪{⟨n0,…,nk,n⟩:⟨nk,n⟩∈A}
17: return ⊥⊥
The frontier is a set of paths. Initially, the frontier contains the path of zero cost consisting of just the start
node. At each step, the algorithm removes a path ⟨n0,…,nk⟩⟨n0,…,nk⟩ from the frontier.
If goal(nk)goal(nk) is true (i.e., nknk is a goal node), it has found a solution and returns the
path ⟨n0,…,nk⟩⟨n0,…,nk⟩. Otherwise, the path is extended by one more arc by finding the neighbors
of nknk. For every neighbor nn of nknk, the path ⟨n0,…,nk,n⟩⟨n0,…,nk,n⟩ is added to the frontier. This step
is known as expanding the path ⟨n0,…,nk⟩⟨n0,…,nk⟩.
1.Which path is selected at line 13 defines the search strategy. The selection of a path can affect the
efficiency; see the box for more details on the use of “select”.
2.It is useful to think of the return at line 15 as a temporary return, where a caller can retry the search to
get another answer by continuing the while loop. This can be implemented by having a class that keeps
the state of the search and a search()search() method that returns the next solution.
3.If the procedure returns ⊥⊥ (“bottom”), there are no solutions, or no remaining solutions if the search
has been retried.
4.The algorithm only tests if a path ends in a goal node after the path has been selected from the frontier,
not when it is added to the frontier. There are two important reasons for this. There could be a costly arc
from a node on the frontier to a goal node. The search should not always return the path with this arc,
because a lower-cost solution may exist. This is crucial when the lowest-cost path is required. A second
reason is that it may be expensive to determine whether a node is a goal node, and so this should be
delayed in case the computation is not necessary.
If the node at the end of the selected path is not a goal node and it has no neighbors, then extending the
path means removing the path from the frontier. This outcome is reasonable because this path could not be
part of a path from the start node to a goal node.
Based on the search problems we can classify the search algorithms into uninformed (Blind search)
search and informed search (Heuristic search) algorithms.
Uninformed/Blind Search:
The uninformed search does not contain any domain knowledge such as closeness, the location of the
goal. It operates in a brute-force way as it only includes information about how to traverse the tree and
how to identify leaf and goal nodes. Uninformed search applies a way in which search tree is searched
without any information about the search space like initial state operators and test for the goal, so it is also
called blind search.It examines each node of the tree until it achieves the goal node.
o Breadth-first search
o Depth-first search
o Bidirectional Search
Breadth-first search
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It
starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a ‘search key’), and
explores all of the neighbour nodes at the present depth prior to moving on to the nodes at the next depth
level.
BFS expands the leaf node with the lowest path cost so far, and keeps going until a goal node is
generated. If the path cost simply equals the number of links, we can implement this as a simple queue
(“first in, first out”)..
Depth-first Search
o Depth-first search isa recursive algorithm for traversing a tree or graph data structure.
o It is called the depth-first search because it starts from the root node and follows each path to its
greatest depth node before moving to the next path.
o DFS uses a stack data structure for its implementation.
o DFS requires very less memory as it only needs to store a stack of the nodes on the path from root
node to the current node.
o It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right path).
Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee of finding
the solution.
o DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.
Completeness: DFS search algorithm is complete within finite state space as it will expand every node
within a limited search tree.
Time Complexity: Time complexity of DFS will be equivalent to the node traversed by the algorithm. It
is given by:
Where, m= maximum depth of any node and this can be much larger than d (Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root node, hence space
complexity of DFS is equivalent to the size of the fringe set, which is O(bm).
A depth-limited search algorithm is similar to depth-first search with a predetermined limit. Depth-limited
search can solve the drawback of the infinite path in the Depth-first search. In this algorithm, the node at the
depth limit will treat as it has no successor nodes further.
o Standard failure value: It indicates that problem does not have any solution.
o Cutoff failure value: It defines no solution for the problem within a given depth limit.
Advantages:
Disadvantages:
Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
Advantages:
Disadvantages:
Advantages:
Uniform cost search is optimal because at every state the path with the least cost is chosen.
Disadvantages:
It does not care about the number of steps involve in searching and only concerned about path
cost. Due to which this algorithm may be stuck in an infinite loop.
Best first search
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and
search. Best-first search allows us to take the advantages of both algorithms. With the help of best-first
search, at each step, we can choose the most promising node. In the best first search algorithm, we
expand the node which is closest to the goal node and the closest cost is estimated by heuristic function,
i.e. f(n)= g(n).
o Step 3: Remove the node n, from the OPEN list which has the lowest value of h(n), and places it
in the CLOSED list.
o Step 4: Expand the node n, and generate the successors of node n.
o Step 5: Check each successor of node n, and find whether any node is a goal node or not. If any
successor node is goal node, then return success and terminate the search, else proceed to Step 6.
o Step 6: For each successor node, algorithm checks for evaluation function f(n), and then check if
the node has been in either OPEN or CLOSED list. If the node has not been in both list, then add
it to the OPEN list.
o Step 7: Return to Step 2.
Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is O(bm). Where, m is
the maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
Optimal: Greedy best first search algorithm is not optimal.
A heuristic is a way which might not always be guaranteed for best solutions but guaranteed to find a good
solution in reasonable time.
The informed search algorithm is more useful for large search space. Informed search algorithm uses the
idea of heuristic, so it is also called Heuristic search.
Heuristics function:
Heuristic is a function which is used in Informed Search, and it finds the most promising path. It takes the
current state of the agent as its input and produces the estimation of how close agent is from the goal. The
heuristic method, however, might not always give the best solution, but it guaranteed to find a good solution
in reasonable time. Heuristic function estimates how close a state is to the goal. It is represented by h(n), and
it calculates the cost of an optimal path between the pair of states. The value of the heuristic function is
always positive.
Pure heuristic search is the simplest form of heuristic search algorithms. It expands nodes based on their
heuristic value h(n). It maintains two lists, OPEN and CLOSED list. In the CLOSED list, it places those
nodes which have already expanded and in the OPEN list, it places nodes which have yet not been
expanded.
On each iteration, each node n with the lowest heuristic value is expanded and generates all its successors
and n is placed to the closed list. The algorithm continues unit a goal state is found.
In the informed search we will discuss two main algorithms which are given below:
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and
search. Best-first search allows us to take the advantages of both algorithms. With the help of best-first
search, at each step, we can choose the most promising node. In the best first search algorithm, we expand
the node which is closest to the goal node and the closest cost is estimated by heuristic function, i.e.
f(n)= g(n).
Advantages:
o Best first search can switch between BFS and DFS by gaining the advantages of both the
algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
o It can behave as an unguided depth-first search in the worst case scenario.
o It can get stuck in a loop as DFS.
o This algorithm is not optimal.
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each iteration,
each node is expanded using evaluation function f(n)=h(n) , which is given in the below table.
In this search example, we are using two lists which are OPEN and CLOSED Lists. Following are the
iteration for traversing the above example.
Iteration3: Open[I,G,E,A],Closed[S,B,F]
: Open [I, E, A], Closed [S, B, F, G]
Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is O(b m). Where, m is the
maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we can combine
both costs as following, and this sum is called as a fitness number.
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if
node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each successor
n', check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation function for n'
and place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back pointer
which reflects the lowest g(n') value.
Advantages:
o A* search algorithm is the best algorithm than other search algorithms.
o A* search algorithm is optimal and complete.
o This algorithm can solve very complex problems.
Disadvantages:
o It does not always produce the shortest path as it mostly based on heuristics and approximation.
o A* search algorithm has some complexity issues.
o The main drawback of A* is memory requirement as it keeps all generated nodes in the memory, so
it is not practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value of all states is
given in the below table so we will calculate the f(n) of each state using the formula f(n)= g(n) + h(n), where
g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list.
Solution:
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.
Points to remember:
o A* algorithm returns the path which occurred first, and it does not search for all remaining paths.
o The efficiency of A* algorithm depends on the quality of heuristic.
o A* algorithm expands all nodes which satisfy the condition f(n)<="" li="">
Complete: A* algorithm is complete as long as:
o Admissible: the first condition requires for optimality is that h(n) should be an admissible heuristic
for A* tree search. An admissible heuristic is optimistic in nature.
o Consistency: Second required condition is consistency for only A* graph-search.
If the heuristic function is admissible, then A* tree search will always find the least cost path.
Time Complexity: The time complexity of A* search algorithm depends on heuristic function, and the
number of nodes expanded is exponential to the depth of solution d. So the time complexity is O(b^d),
where b is the branching factor.
1. Recursive best-first search is a simple recursive algorithm that attempts to mimic the
operation of standard best-first search,but using only linear space.
2. The algorithm is shown in below figure.
3. Its structure is similar to that of recursive depth-first search,but rather than continuing indefinitely
down the current path,it keeps track of the f-value of the best alternative path available from any
ancestor of the current node.
4. 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 the
best f-value of its children.
function RFBS( problem, node, f_limit) return a solution or failure and a new f-
cost limit
if GOAL-TEST[problem](STATE[node]) then return node successors
EXPAND(node, problem)
if successors is empty then return failure, ∞
for each s in successors do
f [s] max(g(s) + h(s), f [node])
repeat
best the lowest f-value node in successors
if f [best] > f_limit then return failure, f [best]
alternative the second lowest f-value among successors result, f
[best] RBFS(problem, best, min(f_limit, alternative)) if result
failure then return result
Heuristic Functions
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
Example: 8 Puzzle
Consider the following 8-puzzle problem where we have a start state and a goal state. Our task is to slide the
tiles of the current/start state and place it in an order followed in the goal state. There can be four moves
either left, right, up, or down. There can be several ways to convert the current/start state to the goal state,
but, we can use a heuristic function h(n) to solve the problem more efficiently.
o Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to move in the
search space.
o Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost.
o No backtracking: It does not backtrack the search space, as it does not remember the previous
states.
State-space Diagram for Hill Climbing:
The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a
graph between various states of algorithm and Objective function/Cost.
On Y-axis we have taken the function which can be an objective function or cost function, and state-space
on the x-axis. If the function on Y-axis is cost then, the goal of search is to find the global minimum and
local minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the
global maximum and local maximum.
Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also
another state which is higher than it.
Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest
value of objective function.
Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have
the same value.
Simple hill climbing is the simplest way to implement a hill climbing algorithm. It only evaluates the
neighbor node state at a time and selects the first one which optimizes current cost and set it as a
current state. It only checks it's one successor state, and if it finds better than the current state, then move
else be in the same state. This algorithm has the following features:
The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This algorithm examines all
the neighboring nodes of the current state and selects one neighbor node which is closest to the goal state.
This algorithm consumes more time as it searches for multiple neighbors
Stochastic hill climbing does not examine for all its neighbor before moving. Rather, this search algorithm
selects one neighbor node at random and decides whether to choose it as a current state or examine another
state.
1. Local Maximum: A local maximum is a peak state in the landscape which is better than each of its
neighboring states, but there is another state also present which is higher than the local maximum.
Solution: Backtracking technique can be a solution of the local maximum in state space landscape. Create a
list of the promising path so that the algorithm can backtrack the search space and explore other paths as
well.
2. Plateau: A plateau is the flat area of the search space in which all the neighbor states of the current state
contains the same value, because of this algorithm does not find any best direction to move. A hill-climbing
search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to solve the
problem. Randomly select a state which is far away from the current state so it is possible that the algorithm
could find non-plateau region.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than its
surrounding areas, but itself has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can improve this
problem.
Simulated Annealing:
A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be incomplete
because it can get stuck on a local maximum. And if algorithm applies a random walk, by moving a
successor, then it may complete but not efficient. Simulated Annealing is an algorithm which yields both
efficiency and completeness.
In mechanical term Annealing is a process of hardening a metal or glass to a high temperature then cooling
gradually, so this allows the metal to reach a low-energy crystalline state. The same process is used in
simulated annealing in which the algorithm picks a random move, instead of picking the best move. If the
random move improves the state, then it follows the same path. Otherwise, the algorithm follows the path
which has a probability of less than 1 or it moves downhill and chooses another path.
Relaxed problems
A pure optimization problem is one where all the nodes can give a solution. But the target is to find the best
state out of all according to the objective function. Unfortunately, the pure optimization problem fails to
find high-quality solutions to reach the goal state from the current state.
An objective function is a function whose value is either minimized or maximized in different contexts of
the optimization problems. In the case of search algorithms, an objective function can be the path cost for
reaching the goal node, etc.
The local search algorithm explores the above landscape by finding the following two points:
• Global Minimum: If the elevation corresponds to the cost, then the task is to find the lowest valley, which
is known as Global Minimum.
• Global Maxima: If the elevation corresponds to an objective function, then it finds the highest peak which
is called as Global Maxima. It is the highest point in the valley.
We will understand the working of these points better in Hill-climbing search.
An online search problem must be solved by an agent executing actions, rather than by pure
computation. We assume a deterministic and fully observable environment (Chapter 17 relaxes these
assumptions), but we stipulate that the agent knows only the following: