AI notes
AI notes
Course objectives:
Learn the basic principles and theories underlying artificial intelligence, including machine
learning, neural networks, natural language processing, and robotics.
Apply AI techniques to solve real-world problems, including search algorithms, optimization, and
decision-making processes.
Understand the ethical, legal, and societal implications of AI, including topics such as bias,
fairness, accountability, and the impact of AI on the workforce and privacy.
Module-1
Chapter – 1 Introduction: What Is AI? , The State of The Art.
MODULE – 01
CHAPTER – 01
INTRODUCTION
The field of artificial intelligence, or AI, goes further still: it attempts not just to understand but
alsoto build intelligent entities.
AI is one of the newest sciences. Work started in earnest soon after World War II, and the
name itself was coined in 1956.
Along with molecular biology, AI is regularly cited as the "field I would most like to be in" by
scientists in other disciplines.
A student in physics might reasonably feel that all the good ideas have already been taken by
Galileo, Newton, Einstein, and the rest. AI, on the other hand, still has openings for several full-time
Einsteins.
AI systematizes and automates intellectual tasks and is therefore potentially relevant to any sphere
ofhuman intellectual activity. In this sense, it is truly a universal field.
Below definitions 1 2 3 and 4 are concerned with thought processes and reasoning,
Thinking Humanly
Def. 1. “The exciting new effort to make computers think , machines with minds, in the full and literal
sense.” (Haugeland, 1985)
Def. 2. “The automation of activities that we associate with human thinking, activities such as decision-
making, problem solving, learning” (Bellman, 1978)
Thinking Rationally
Def.3 “The study of mental faculties through the use of computational models.” (Charniak and McDermott,
1985)”
Def.4 “The study of the computations that make it possible to perceive, reason, and act.” (Winston, 1992)”
Below definitions 5 6 7 8 address behavior.
Acting Humanly
Def.5 “The art of creating machines that perform functions that require intelligence when performed by
people.” (Kurzweil, 1990)
Def.6 “The study of how to make computers do things at which, at the moment, people are better.” (Rich
and Knight, 1991)
Acting Rationally
Def.7 “Computational Intelligence is the study of the design of intelligent agents.” (Poole et al., 1998)’
Def.8 “AI is concerned with intelligent behavior in artifacts.” (Nilsson, 1998)
NOTE:
Thinking and acting humanly measure success in terms of fidelity to human performance.
Whereas the one against an ideal performance measure, called rationality.
A system is rational if it does the “right”
1. Computer Vision:
o Enables the computer to see and understand visual information.
2. Robotics:
o Allows the computer to manipulate objects and move in its environment.
Learning from Nature: Just as early aviators succeeded by studying aerodynamics instead of
merely copying birds, AI research should focus on understanding intelligence rather than just mimicking
human behavior.
The Turing Test is a way to measure machine intelligence, but real progress in AI might come from
studying and understanding how intelligence actually works, rather than just imitating human behavior.
Goal: To create AI that thinks like humans, we need to understand how humans think.
Methods to Explore Human Thinking:
1. Introspection: Reflecting on our own thoughts.
2. Psychological Experiments: Observing how people behave in different situations.
3. Brain Imaging: Using technology to see how the brain functions during thinking.
Developing AI Programs
Once we have a clear theory of how the mind works, we can turn that theory into a computer
program.
If the program behaves similarly to how humans do in similar situations, it suggests that the
program might be using similar thinking processes.
Cognitive Science
Definition: An interdisciplinary field that combines AI and psychology to study the human mind.
Importance: It helps create testable theories about how we think and learn.
The field is rich enough to require multiple textbooks.
AI and cognitive science benefit from each other’s discoveries, especially in areas like computer
vision, where insights from neuroscience inform computational models.
To develop AI that thinks like humans, we must understand human cognition through observation and
experimentation, and this knowledge can help create better AI systems.
Overview
Development of Logic
Logic and AI
By 1965, there were programs that could theoretically solve any problem described using logical
notation.
o Note: If no solution exists, the program might run indefinitely.
Logicist Tradition in AI
1. Formalizing Knowledge:
o It’s difficult to convert informal knowledge (which is often uncertain) into the strict format
needed for logical notation.
2. Practical Problem Solving:
o Solving a problem “in principle” (theoretically) is different from doing it in practice.
o Even simple problems with a few hundred facts can overwhelm computers unless guided
on how to approach reasoning steps effectively.
The "laws of thought" approach, rooted in logic, aims to create rational AI, but challenges exist in
formalizing human knowledge and applying it effectively in real-world problem solving.
1.1.4 Acting Rationally: The Rational Agent Approach
What is an Agent?
Rational Agent
A rational agent acts to achieve the best outcome, or the best expected outcome in uncertain
situations.
The laws of thought focus on making correct inferences. While reasoning logically is part of being
a rational agent, it's not the only way to act rationally.
Sometimes, there’s no clear right answer, but action is still required. For instance, reflexes, like
pulling your hand away from a hot stove, can be quicker and more effective than deliberate reasoning.
Skills from the Turing Test (like natural language processing and reasoning) help agents make
good decisions.
Learning improves an agent’s ability to act effectively.
1. General Applicability: It encompasses more than just correct reasoning—there are various ways
to achieve rationality.
2. Scientific Foundation: The concept of rationality is mathematically defined and can be
systematically developed into agent designs. In contrast, human behavior is specific to particular
environments and contexts.
Important Note: Achieving perfect rationality (always doing the right thing) is often unrealistic due to
high computational demands in complex environments. However, using perfect rationality as a starting
point simplifies analysis and is useful for foundational concepts.
The rational agent approach in AI focuses on creating agents that act effectively to achieve goals,
incorporating various skills and recognizing that perfect rationality is an ideal rather than a practical reality.
AI has a wide range of applications across various fields. Here are some key examples:
1. Robotic Vehicles
STANLEY: A driverless car that won the 2005 DARPA Grand Challenge by navigating the
Mojave Desert.
BOSS: CMU’s robotic vehicle that won the Urban Challenge in 2007, successfully driving in
traffic while obeying rules and avoiding obstacles.
2. Speech Recognition
Automated systems can manage entire conversations, such as when booking flights with United
Airlines.
NASA’s Remote Agent: The first on-board program to autonomously plan spacecraft operations.
MAPGEN: Plans daily operations for NASA’s Mars rovers.
MEXAR2: Handled mission planning for the European Space Agency’s Mars Express in 2008.
4. Game Playing
IBM’s Deep Blue: The first computer to defeat a world chess champion, Garry Kasparov, in
1997, marking a significant milestone in AI.
5. Spam Fighting
Learning algorithms classify over a billion emails daily as spam, protecting users from irrelevant
messages.
6. Logistics Planning
During the 1991 Persian Gulf crisis, the DART tool automated logistics for U.S. forces, planning
transportation for up to 50,000 vehicles and personnel in hours instead of weeks.
7. Robotics
Roomba: A popular robotic vacuum cleaner with over two million sold.
PackBot: Used in military operations to handle hazardous tasks and locate threats.
8. Machine Translation
AI systems can automatically translate languages, such as Arabic to English, using statistical
models based on vast amounts of text data.
These examples illustrate that AI is not just fiction; it is a practical application of science, engineering, and
mathematics, forming the basis for numerous technologies in use today.
MODULE – 01
CHAPTER – 02
INTELIGENT AGENTS
2.1 AGENTS AND ENVIRONMENT:
Agent Definition…
– is situated in an environment,
– is capable of perceiving its environment, and
– is capable of acting in its environment with the goal of satisfying its design objectives. (or)
Anything that can be viewed as perceiving its environment through sensors and SENSOR acting upon that
environment through actuators.
(OR)
i. Human “agent”:
– environment: physical world;
– sensors: eyes, ears, . . .
– effectors: hands, legs, . . .
ii. Software agent:
– environment: (e.g.) UNIX operating system;
– sensors: keystrokes, file contents, n/w packets . . .
– effectors: rm, chmod, . . .
iii. Robot:
– environment: physical world;
– sensors: sonar, camera;
– effectors: wheels.
Important terms…
Percept:
We use the term percept to refer to the agent's perceptual inputs at any given instant.
Percept Sequence:
An agent's percept sequence is the complete history of everything the agent has ever perceived.
A rational agent is one that does the right thing-conceptually speaking, every entry in the table for
the agent function is filled out correctly.
Obviously, doing the right thing is better than doing the wrong thing. The right action is the one
that will cause the agent to be most successful.
Performance measures:
Rationality :
PEAS Example…
If the next state of the environment is completely determined by the current state and the
action executed by the agent, then we say the environment is deterministic; other-wise, it is
stochastic.
In an episodic task environment, the agent's experience is divided into atomic episodes.
Each episode consists of the agent perceiving and then performing a single action.
Crucially, the next episode does not depend on the actions taken in previous episodes.
In sequential environments, on the other hand, the current decision could affect all
future decisions. Chess and taxi driving are sequential.
A discrete-state environment such as a chess game has a finite number of distinct states.
Chess also has a discrete set of percepts and actions.
Taxi driving is a continuous state and continuous-time problem: the speed and
location of the taxi and of the other
vehicles sweep through a range of continuous values and do so smoothly over time.
Taxi-driving actions are also continuous (steering angles,.)
As one might expect, the hardest case is partially observable, stochastic, sequential,
dynamic, continuous, and Multiagent.
2.4.1..1 The job of AI is to design the agent program that implements the agent function
mapping percepts to actions.
2.4.1..2 Agent = architecture +program
2.4.1..3 The agent programs all have the same skeleton: they take the current percept as input
from the sensors and return an action to the actuators.
2.4.1..4 Notice the difference between the agent program, which takes the current percept
as input, and the agent function, which takes the entire percept history.
Agent Types/Categories…
i. Table-driven agents:
-- use a percept sequence/action table in memory to find the next action. They are implemented by a
(large) lookuptable.
v. Utility-based agents:
--base their decisions on classic axiomatic utility theory in order to act rationally.
Drawbacks:
Table lookup of percept-action pairs defining all possible condition-action rules
necessary to interact in an environment.
Problems :
– Too big to generate and to store (Chess has about 10^120 states, for example)
– No knowledge of non-perceptual parts of the current state
– Not adaptive to changes in the environment; requires entire table to be updated if changes
occur
– Looping: Can't make actions conditional
– Take a long time to build the table
– No autonomy
– Even with learning, need a long time to learn the table entries
Characteristics:
Only works if the environment is fully observable.
Lacking history, easily get stuck in infinite loops.
One solution is to randomize actions.
o That is, the agent should maintain some sort of internal state that depends on the
percept history and therebyreflects at least some of the unobserved aspects of the current state.
o Updating this internal state information as time goes by requires two kinds of
knowledge to be encoded in the agent program
o First, we need some information about how the world evolves independently of the
agent-for example, that an overtaking car generally will be closer behind than it was a moment
ago.
o Second, we need some information about how the agent's own actions affect the world-
for example, that when the agent turns the steering wheel clockwise, the car turns to the right or
that after driving for five minutes northbound on the freeway one is usually about five miles north
of where one was five minutes ago.
This knowledge about "how the world working -whether implemented in simple Boolean circuits
or in complete scientific theories-is called a model of the world. An agent that uses such a
model is called a model-based agent.
The correct decision depends on where the taxi is trying to get to.
In other words, as well as a current state description, the agent needs some sort of
goal information that describes situations that are desirable-for example, being at the passenger's
destination.
The agent program can combine this with information about the results of possible
actions (the same information as was used to update internal state in the reflex agent) in order to
choose actions that achieve the goal.
Search and planning are the subfields of AI devoted to finding action sequences that
achieve the agent’s goals.
Although the goal-based agent appears less efficient, it is more flexible because the
knowledge that supports its decisions is represented explicitly and can be modified.
If it starts to rain, the agent can update its knowledge of how effectively its brakes will
operate; this will automatically cause all of the relevant behaviors to be altered to suit the new
conditions.
Goals alone are not really enough to generate high-quality behavior in most
environments. For example, there are many action sequences that will get the taxi to its destination
(thereby achieving the goal) but some are quicker, safer, more reliable, or cheaper than others.
Goals just provide a crude binary distinction between "happy" and "unhappy" states,
whereas a more general performance measure should allow a comparison of different world
states according to exactly how happythey would make the agent if they could be achieved.
Because "happy" does not sound very scientific, the customary terminology is to say
that if one world state is preferred to another, then it has higher utility for the agent.
A utility function maps a state (or a sequence of states) onto a real number, which
describes the associated degree of happiness.
A complete specification of the utility function allows rational decisions in two kinds
of cases where goals are inadequate.
First, when there are conflicting goals, only some of which can be achieved (for
example, speed and safety), the utility function specifies the appropriate tradeoff.
Second, when there are several goals that the agent can aim for, none of which can be
achieved with certainty, utility provides a way in which the likelihood of success can be weighed up
against the importance of the goals.
Partial observability and stochasticity are ubiquitous in the real world, and so, therefore,
is decision making under uncertainty.
Technically speaking, a rational utility-based agent chooses the action that maximizes
the expected utility of the action outcomes—that is, the utility the agent expects to derive, on
average, given the probabilities and utilities of each outcome.
Vi Learning Agents:
Course objectives:
Learn the basic principles and theories underlying artificial intelligence, including machine learning,
neural networks, natural language processing, and robotics.
Apply AI techniques to solve real-world problems, including search algorithms, optimization, and
decision-making processes.
Understand the ethical, legal, and societal implications of AI, including topics such as bias, fairness,
accountability, and the impact of AI on the workforce and privacy.
ARTIFICIAL
INTELLIGENCE
Module - 2
Syllabus
Solving Problems by searching: Problem Solving Agents, Example problems,
Searching for Solutions, Uninformed Search Strategies
What is Search?
Search is the systematic examination of states to find path from the start/root state to the goal state.
The set of possible states, together with operators defining their connectivity constitute the search space.
The output of a search algorithm is a solution, that is, a path from the initial state to a state that satisfies the
goal test.
Goal formulation, based on the current situation and the agent’s performance measure, is the first step in
problem solving.
The agent’s task is to find out which sequence of actions will get to a goal state.
Problem formulation is the process of deciding what actions and states to consider given a goal.
An agent with several immediate options of unknown value can decide what to do by examining different
possible sequences of actions that leads to the states of known value, and then choosing the best sequence.
The process of looking for sequences actions from the current state to reach the goal state is called search.
The search algorithm takes a problem as input and returns a solution in the form of action sequence.
Once a solution is found, the execution phase consists of carrying out the recommended action..
Simple “formulate, search, execute” design for the agent…
– Static : The entire process carried out without paying attention to changes that might be occurring in the
environment.
– Observable : The initial state is known and the agent’s sensor detects all aspects that are relevant to the choice of
action.
– Discrete : With respect to the state of the environment and percepts and actions so that alternate courses of action
can be taken.
– Deterministic : The next state of the environment is completely determined by the current state and the actions
executed by the agent. Solutions to the problem are single sequence of actions.
i. Initial state
ii. Operator or successor function - for any state x returns s(x), the set of states reachable from x with one action
iii. State space - all states reachable from initial by any sequence of actions
iv. Path - sequence through state space
v. Path cost - function that assigns a cost to a path. Cost of a path is the sum of costs of individual actions along the
path
vi. Goal test - test to determine if at goal state
vii. The step cost of taking action ‘a’ to go from state x to state y is denoted by c(x,a,y). The step cost for Romania are
shown in next figure in route distances. It is assumed that the step costs are non negative.
viii.A solution to the problem is a path from the initial state to a goal state.
ix. An optimal solution has the lowest path cost among all solutions.
Example Problems:
Toy vs Real World problems…
1. Toy Problems:
Example 1: Vaccum world
i. States: The agent is in one of two locations.,each of which might or might not contain dirt. Thus there are 2 x
22 = 8 possible world states.
ii. Initial state: Any state can be designated as initial state.
iii. Successor function : This generates the legal states that results from trying the three actions (left, right, suck).
The complete state space is shown in figure.
iv. Goal Test : This tests whether all the squares are clean.
v. Path test : Each step costs one ,so that the the path cost is the number of steps in the path.
States: integer dirt and robot locations (ignore dirt amounts etc.)
Actions: Left, Right, Suck, NoOp
Goal test: no dirt
Path cost: 1 per action (0 for No Op)
An 8-puzzle consists of a 3x3 board with eight numbered tiles and a blank space.
A tile adjacent to the blank space can slide into the space. The object is to reach the goal state ,as shown in
Figure.
i. States : A state description specifies the location of each of the eight tiles and the blank in one of the nine
squares.
ii. Initial state : Any state can be designated as the initial state. It can be noted that any given goal can be
reached from exactly half of the possible initial states.
iii. Successor function : This generates the legal states that result from trying the four actions(blank moves
Left,Right,Up or down).
Mr. Manjunatha G, Asst. Prof. Dept. Of CSD, PESITM, SHIVAMOGGA Page 6
Artificial intelligence – BCS505B
iv. Goal Test : This checks whether the state matches the goal configuration shown in figure(Other goal
configurations are possible).
v. Path cost : Each step costs 1,so the path cost is the number of steps in the path.
The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as test problems for new
search algorithms in AI. This general class is known as NP-complete.
The 8-puzzle has 9!/2 = 181,440 reachable states and is easily solved.
The 15 puzzle ( 4 x 4 board ) has around 1.3 trillion states, an the random instances can be solved optimally in
few milli seconds by the best search algorithms.
The 24-puzzle (on a 5 x 5 board) has around 1025 states ,and random instances are still quite difficult to solve
optimally with current machines and algorithms.
ii. Actions?: Move blank left, right, up, down (ignore unjamming etc.)
An Incremental formulation involves operators that augments the state description, starting with an empty
state for 8-queens problem, this means each action adds a queen to the state.
A complete-state formulation starts with all 8 queens on the board and moves them around.
In either case the path cost is of no interest because only the final state counts.
States : Arrangements of n queens ( 0 <= n < = 8 ), one per column in the left most columns ,with no queen
attacking another are states.
Successor function : Add a queen to any square in the left most empty column such that it is not attacked by
any other queen.
This formulation reduces the 8-queen state space from 3 x1014 to just 2057,and solutions are easy to find.
2. Real-world Problems:
i. Route finding problem
ii. Airline Travel problem
iii. Touring problems
iv. Travelling salesperson problem
v. VLSI Layout
vi. ROBOT Navigation
vii.Automatic Assembly problem
viii.Internet searching
Route-Finding Problem is defined in terms of specified locations and transitions along links between them.
Route-finding algorithms are used in a variety of applications.
Some, such as Web sites and in-car systems that provide driving directions.
Others, such as routing video streams in computer networks, military operations planning, and airline travel-
planning systems, involve much more complex specifications.
Consider the airline travel problems that must be solved by a travel-planning Web site:
• States: Each state obviously includes a location (e.g., an airport) and the current time. Furthermore, because the cost
of an action (a flight segment) may depend on previous segments, their fare bases, and their status as domestic or
international, the state must record extra information about these “historical” aspects.
• Actions: Take any flight from the current location, in any seat class, leaving after the current time, leaving enough
time for within-airport transfer if needed.
Transition model: The state resulting from taking a flight will have the flight’s destination as the current location and
the flight’s arrival time as the current time.
• Path cost: This depends on monetary cost, waiting time, flight time, customs and immigration procedures, seat
quality, time of day, type of airplane, frequent-flyer mileage awards, and so on.
Touring problems are closely related to route-finding problems, but with an important difference. Consider, for
example, the problem “Visit every city at least once, starting and ending in Bucharest”.
The traveling salesperson problem (TSP) is a touring problem in which each city must be visited exactly
once.
The problem is known to be NP-hard, but an enormous amount of effort has been expended to improve the capabilities
of TSP algorithms.
A VLSI layout problem requires positioning millions of components and connections on a chip to minimize
area, minimize circuit delays, minimize stray capacitances, and maximize manufacturing yield.
The layout problem comes after the logical design phase and is usually split into two parts:
Cell layout
Channel routing.
Cell layout :
In cell layout, the primitive components of the circuit are grouped into cells, each of which performs some
recognized function.
Channel routing :
Channel routing finds a specific route for each wire through the gaps between the cells.
Rather than following a discrete set of routes, a robot can move in a continuous space with (in principle) an
infinite set of possible actions and states.
For a circular robot moving on a flat surface, the space is essentially two-dimensional.
Automatic assembly sequencing of complex objects by a robot was first demonstrated by FREDDY
(Michie, 1972).
In assembly problems, the aim is to find an order in which to assemble the parts of some object. If the
Checking a step in the sequence for feasibility is a difficult geometrical search problem closely related to
robot navigation.
Another important assembly problem is protein design, in which the goal is to find a sequence of amino
acids that will fold into a three-dimensional protein with the right properties to cure some disease.
A solution is an action sequence, so search algorithms work by considering various possible action
sequences.
The possible action sequences starting at the initial state form a search tree with the initial state at
the root; the branches are actions and the nodes correspond to states in the state space of the
problem.
The diagram shows the first few steps in growing the search tree for finding a route from Arad to
Bucharest.
By expanding the current state , and thereby generating a new set of states.
Each of these six nodes is a leaf node, that is, a node with no children in the tree.
The set of all leaf nodes available for expansion at any given
point is called the frontier(Many authors call it the open list)
the frontier of each tree consists of those nodes with bold outlines.
The process of expanding nodes on the frontier continues until either a solution is found or there are
no more states to expand.
Search algorithms all share this basic structure; they vary primarily
according to how they choose which state to expand next—the so-called search strategy.
Loopy paths are a special case of the more general concept of redundant paths, which exist
whenever there is more than one way to get from one state to another.
As every step moves a state from the frontier into the explored region while moving some states
from the unexplored region into the frontier, we see that the algorithm is systematically
examining the states in the state space, one by one, until it finds a solution.
o n.STATE: the state in the state space to which the node corresponds;
o n.PARENT: the node in the search tree that generated this node;
o n.ACTION: the action that was applied to the parent to generate the node;
o n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to
thenode, as indicated by the parent pointers.
Queue :
Now that we have nodes, we need somewhere to put them.
The frontier needs to be stored in such a way that the search algorithm can easily choose the next
node to expand according to its preferred strategy.
• EMPTY (queue) returns true only if there are no more elements in the queue.
• POP (queue) removes the first element of the queue and returns it.
• INSERT (element, queue) inserts an element and returns the resulting queue.
Queues are characterized by the order in which they store the inserted nodes.
The first-in, first-out or FIFO queue, which pops the oldest element of the queue;
LIFO QUEUE the last-in, first-out or LIFO queue (also known as a stack), which pops the newest
element
PRIORITY QUEUE of the queue; and the priority queue, which pops the element of the queue with
the highest priority according to some ordering function.
In general, all the nodes are expanded at a given depth in the search tree before any nodes at the next level are
expanded.
Breath-First-Search is implemented by calling TREE SEARCH with an empty fringe that is a first-in-first out
(FIFO) queue, assuring that the nodes that are visited first will be expanded first.
The FIFO queue puts all newly generated successors at the end of the queue, which means that Shallow nodes
are expanded before deeper nodes.
BFS Algorithm…
Properties of BFS…
2. Uninform-cost Search(UCS)…
Instead of expanding the shallowest node, uniform-cost search expands the node ‘n’ with the lowest path cost.
Uniform-cost search does not care about the number of steps a path has, but only about their total cost.
Expand least-cost unexpanded node.
We think of this as having an evaluation function:g(n), which returns the path cost to a node n.
fringe = queue ordered by evaluation function,lowest first.
Equivalent to breadth-first if step costs all equal
Complete and optimal.
Time and space complexity are as bad as for breadth-first search.
UCS Algorithm:
Process…
Properties of UCS….
4. Depth-Limited Search…
The embarrassing failure of depth-first search in infinite state spaces can be alleviated by supplying depth-first
search with a predetermined depth limit ‘l’.
That is, nodes at depth ‘l’ are DEPTH-LIMITED treated as if they have no successors. This approach is called
depth limited search.
The SEARCH depth limit solves the infinite-path problem.
Unfortunately, it also introduces an additional source of incompleteness if we choose ‘l’ < d, that is, the
shallowest goal is beyond the depth limit. (This is likely when d is unknown.)
In general, iterative deepening is the preferred uninformed search method when the search space is large and
the depth of the solution is not known.
Properties of IDS….
6. Bi-directional search…
The idea behind bidirectional search is to run two simultaneous searches – one forward from the initial state
and the other backward from the goal, stopping when the two searches meet in the middle.
The motivation is that bd/2 + bd/2 much less than or the area of the two small circles is less than the area of one
big circle centered on the start and reaching to the goal.
Example Graph:
ARTIFICIAL
INTELLIGENCE
Module - 3
Syllabus
Chapter : 1 Problem‐solving: Informed Search Strategies, Heuristic functions
Chapter : 2 Logical Agents: Knowledge–based agents, The Wumpus world, Logic,
Propositional logic, Reasoning patterns in Propositional Logic
Heuristic function are the most common form in which additional knowledge is imparted to the
search algorithm.
The figure shows the progress of greedy best-first search using hSLD to find a path from Arad to
Bucharest.
The first node to be expanded from Arad will be Sibiu, because it is closer to Bucharest than either
Zerind or Timisoara.
The next node to be expanded will be Fagaras, because it is closest.
2. A* Search…
A* is very efficient search strategy and it is the most widely used form of best-first search.
Basic idea is to combine uniform cost search and greedy search.
The evaluation function f(n) is obtained by combining g(n) = the cost to reach the node, and h(n) =
the cost to get from the node to the goal :
f(n) = g(n) +
h(n). (or)
□ f (n) = g(n) + h(n) where
– g(n) is path cost of n;
– h(n) is expected cost of cheapest solution from n.
It Aims to minimise overall cost.
Algorithm for A* search stratergy:
Optimality of A*…
A search is both complete and optimal.
The algorithm is identical to UNIFORM-COST-SEARCH except that A uses g + h instead of g.
A* is optimal in precise sense—it is guaranteed to find a minimum cost path to the goal.
There are a set of conditions under which A* will find such a path:
1. Each node in the graph has a finite number of children.
2. All arcs have a cost greater than some positive .
3. For all nodes in the graph h(n) always underestimates the true distance to the goal.
Problems in A*…
Computation time, A’s main drawback.
Because it keeps all generated nodes in memory (as do all GRAPH-SEARCH algorithms), A
usually runsout of space long before it runs out of time.
Its structure is similar to that of a recursive depth first search, but rather than continuing indefinitely
down the current path, it uses the f-limit variable to keep track of the f-value of the best alternative
path.
If the current node exceeds this limit, the recursion unwinds back to the alternative path.
As the recursion unwinds, RBFS replaces the f-value of each node along the path with a backed-up
value—the best f-value of its children.
In this way, RBFS remembers the f-value of the best leaf in the forgotten subtree and can
therefore decide whether it’s worth reexpanding the subtree at some later time.
RBFS Algorithm…
RBFS Evaluation :
RBFS is a bit more efficient than IDA* Still excessive node generation (mind changes).
Like A*, optimal if h(n) is admissible. Space complexity is O(bd).
IDA* retains only one single number (the current f-cost limit).
Time complexity difficult to characterize Depends on accuracy if h(n) and how often best path changes.
IDA* and RBFS suffer from too little memory.
HEURISTIC FUNCTIONS :
The 8-puzzle was one of the earliest heuristic search problems.
The object of the puzzle is to slide the tiles horizontally or vertically into the empty
space until the configuration matches the goal configuration .
The average solution cost for a randomly generated 8-puzzle instance is about 22
steps. The branching factor is about 3.
When the empty tile is in the middle, four moves are possible; when it is in a corner,
two; and when it is along an edge, three.
This means that an exhaustive tree search to depth 22 would look at about
A graph search would cut this down by a factor of about 170,000 because only 9!/2 = 181, 440
distinct states are reachable.
The corresponding number for the 15-puzzle is roughly , so the next order of business is to find a
good heuristic function.
If we want to find the shortest solutions by using A, we need a heuristic function that never
overestimates the number of steps to the goal.
There is a long history of such heuristics for the 15-puzzle; here are two commonly used candidates:
h1 = the number of misplaced tiles. All of the eight tiles are out of position, so the start state would
have h1 = 8.
h1 is an admissible heuristic because it is clear that any tile that is out of place must be moved at least
once.
h2 = the sum of the distances of the tiles from their goal positions.
Because tiles cannot move along diagonals, the distance we will count is the sum of the
horizontal and vertical distances.
This is sometimes called the city block distance or Manhattan distance.
If the total number of nodes generated by A for a particular problem is N and the solution depth is d,
then b is the branching factor that a uniform tree of depth d would have to have in order
to contain N + 1 nodes. Thus,
For example, if A finds a solution at depth 5 using 52 nodes, then the effective branching factor is 1.92.
We have seen that both h1 (misplaced tiles) and h2 (Manhattan distance) are fairly good heuristics
for the 8- puzzle and that h2 is better.
How might one have come up with h2? Is it possible for a computer to invent such a heuristic
mechanically.
h1 and h2 are estimates of the remaining path length for the 8-puzzle, but they are also perfectly
accurate path lengths for simplified versions of the puzzle.
If the rules of the puzzle were changed, so that a tile could move anywhere instead of just to the
adjacent empty square, then h1 would give the exact number of steps in the shortest solution.
Similarly, if a tile could move one square in any direction, even onto an occupied square, then h2
would give the exact number of steps in the shortest solution.
“the cost of an optimal solution to a relaxed problem is an admissible heuristic for the original
problem”.
Furthermore, because the derived heuristic is an exact cost for the relaxed problem, it must obey
the triangle inequality and is therefore consistent .
From (a), we can derive h2 (Manhattan distance). The reasoning is that h2 would be the proper score
if we moved each tile in turn to its destination.
From (c), we can derive h1 (misplaced tiles) because it would be the proper score if tiles could move
to their intended destination in one step.
Admissible heuristics can also be derived from the solution cost of a subproblem of a given problem.
The sub problem involves getting tiles 1, 2, 3, 4 into their correct positions.
Clearly, the cost of the optimal solution of this subproblem is a lower bound on the cost of the
complete problem.
The idea behind pattern databases is to store these exact solution costs for every possible sub
problem instance—in our example, every possible configuration of the four tiles and the blank.
Then we compute an admissible heuristic hdb for each complete state encountered during a search
simply by looking up the corresponding subproblem configuration in the database.
The database itself is constructed by searching back from the goal and recording the cost of each
new pattern encountered .
Each database yields an admissible heuristic, and these heuristics can be combined, and by taking the
maximum value.
A combined heuristic of this kind is much more accurate than the Manhattan distance .
One might wonder whether the heuristics obtained from the 1-2-3-4 database and the 5-6-7-8 could
be added, since the two subproblems seem not to overlap.
So,we record not the total cost of solving the 1-2-3-4 subproblem, but just the number of moves
involving 1- 2-3-4. Then it is easy to see that the sum of the two costs is still a lower bound on the
cost of solving the entire problem.
Each example consists of a state from the solution path and the actual cost of the solution from that
point. From these examples, a learning algorithm can be used to construct a function h(n) that can
(with luck) predict solution costs for other states that arise during search.