Module 3 Notes_Part1
Module 3 Notes_Part1
• Text book 1: Chapter 4 – 4.1, 4.2 Chapter 7- 7.1, 7.2, 7.3, 7.4, 7.5
• h(n) = estimated cost of the cheapest path from the state at node n to
a goal state.
• (Notice that h(n) takes a node as input, but, unlike g(n), it depends only
on the state at that node.)
• For example, in Romania, one might estimate the cost of the cheapest
path from Arad to Bucharest via the straight-line distance from Arad
to Bucharest.
• 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.
• Thus, it evaluates nodes by using just the heuristic function; that is, f(n) =
h(n).
• Let us see how this works for route-finding problems in Romania; we use
the straight-line distance heuristic, which we will call .
• The first node to be expanded from Arad will be Sibiu because it is closer
to Bucharest than either Zerind or Timisoara.
• It is not optimal, however: the path via Sibiu and Fagaras to Bucharest is
32 kilometers longer than the path through Rimnicu Vilcea and Pitesti.
• This shows why the algorithm is called ―greedy‖—at each step it tries
to get as close to the goal as it can.
• The algorithm will never find this solution, however, because expanding
Neamt puts Iasi back into the frontier, Iasi is closer to Fagaras than Vaslui
is, and so Iasi will be expanded again, leading to an infinite loop. (The
graph search version is complete in finite spaces, but not in infinite ones.)
• The worst-case time and space complexity for the tree version is )
where m is the maximum depth of the search space.
• 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: f(n) = g(n) + h(n) .
BAD402 Artificial Intelligence Module 3_Part 1
• 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,
• It turns out that this strategy is more than just reasonable: provided that
the heuristic function h(n) satisfies certain conditions, A∗ search is both
complete and optimal.
• Because g(n) is the actual cost to reach n along the current path, and
f(n) = g(n) + h(n),
• A heuristic h(n) is consistent if, for every node n and every successor n’
of n generated by any action a, the estimated cost of reaching the goal
from n is no greater than the step cost of getting to n’ plus the estimated
cost of reaching the goal from n’ :
• The first step is to establish the following: if h(n) is consistent, then the
values of f(n) along any path are nondecreasing. The proof follows
directly from the definition of consistency.
• IDA∗ is practical for many problems with unit step costs and avoids
the substantial overhead associated with keeping a sorted queue of
nodes.
• If the current node exceeds this limit, the recursion unwinds back to
the alternative path.
• 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 is somewhat more efficient than IDA∗, but still suffers from
excessive node regeneration.
• In the example in Figure 3.27, RBFS follows the path via Rimnicu
Vilcea, then ―changes its mind‖ and tries Fagaras, and then changes its
mind back again.
• These mind changes occur because every time the current best path is
extended, its f-value is likely to increase—h is usually less optimistic for
nodes closer to the goal.
• When this happens, the second-best path might become the best path,
so the search has to backtrack to follow it.
BAD402 Artificial Intelligence Module 3_Part 1
Heuristic Functions
• As mentioned in Section 3.2, the object of the puzzle is to slide the tiles
horizontally or vertically into the empty space until the configuration
matches the goal configuration (Figure 3.28).
• There is a long history of such heuristics for the 15-puzzle; here are two
commonly used candidates:
• h1 = the number of misplaced tiles. For Figure 3.28, 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.
BAD402 Artificial Intelligence Module 3_Part 1
• h2 is also admissible because all any move can do is move one tile one
step closer to the goal.
• Figure 3.29 gives the average number of nodes generated by each strategy
and the effective branching factor.
• The results suggest that h2 is better than h1, and is far better than using
iterative deepening search.
• Even for small problems with d = 12, A∗ with h2 is 50,000 times more
efficient than uninformed iterative deepening search.
• 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 wumpus can be shot by an agent, but the agent has only one
arrow.
• Some rooms contain bottomless pits that will trap anyone who wanders
into these rooms (except for the wumpus, which is too big to fall in).
• Performance measure: +1000 for climbing out of the cave with the gold,–
1000 for falling into a pit or being eaten by the wumpus,–1 for each
action taken and–10 for using up the arrow.
• The game ends either when the agent dies or when the agent climbs out
of the cave.
BAD402 Artificial Intelligence Module 3_Part 1
• Environment: A 4×4 grid of rooms. The agent always starts in the square
labeled [1,1], facing to the right. In addition, each square other than the
start can be a pit, with probability 0.2.
• Sensors: The agent has five sensors, each of which gives a single bit of
information:– In the square containing the wumpus and in the directly
(not diagonally) adjacent squares, the agent will perceive a Stench.
• – In the square where the gold is, the agent will perceive a Glitter.
7.3 Logic
• we said that knowledge bases consist of sentences. These sentences are
expressed according to the syntax of the representation language, which
specifies all the sentences that are well formed.
• The notion of syntax is clear enough in ordinary arithmetic: ―x + y = 4‖ is
a well-formed sentence, whereas ―x4y+ =‖ is not.
• A logic must also define the semantics or meaning of sentences.
• The semantics defines the truth of each sentence with respect to each
possible world.
• For example, the semantics for arithmetic specifies that the sentence ―x +
y = 4‖ is true in a world where x is 2 and y is 2, but false in a world
where x is 1 and y is 1.
• In standard logics, every sentence must be either true or false in each
possible world—there is no ―in between.
BAD402 Artificial Intelligence Module 3_Part 1
• Formally, the possible models are just all possible assignments of real
numbers to the variables x and y.
• Each such assignment fixes the truth of any sentence of arithmetic whose
variables are x and y.
• Now that we have a notion of truth, we are ready to talk about logical
reasoning.
• Consider the situation in Figure 7.3(b): the agent has detected nothing
in [1,1] and a breeze in [2,1].
• Each of the three squares might or might not contain a pit, so (for the
purposes of this example) there are = 8 possible models.
• The KB is false in models that contradict what the agent knows— for
example, the KB is false in any model in which [1,2] contains a pit,
because there is no breeze in [1,1].
• There are in fact just three models in which the KB is true, and these are
shown surrounded by a solid line in Figure 7.5.
• The preceding example not only illustrates entailment but also shows how
the definition of entailment can be applied to derive conclusions—that
is, to carry out logical inference.
• For real haystacks, which are finite in extent, it seems obvious that a
systematic examination can always decide whether the needle is in the
haystack.
• Fortunately, there are complete inference procedures for logics that are
sufficiently expressive to handle many knowledge bases.
• A simple answer is that the agent’s sensors create the connection. For
example, our wumpus-world agent has a smell sensor.
• Thus, the meaning and truth of percept sentences are defined by the
processes of sensing and sentence construction that produce them.
• What about the rest of the agent’s knowledge, such as its belief that
wumpuses cause smells in adjacent squares? This is not a direct
representation of a single percept, but a general rule—derived, perhaps,
from perceptual experience but not identical to a statement of that
experience.
7.4.1 Syntax
• Each such symbol stands for a proposition that can be true or false.
• We use symbols that start with an uppercase letter and may contain
other letters or subscripts, for example: P, Q, R, W1,3 and North.
BAD402 Artificial Intelligence Module 3_Part 1
• The names are arbitrary but are often chosen to have some mnemonic
value—we use W1,3 to stand for the proposition that the wumpus is in
[1,3].
• (Remember that symbols such as W1,3 are atomic, i.e., W, 1, and 3 are
not meaningful parts of the symbol.)
• There are two proposition symbols with fixed meanings: True is the
always-true proposition and False is the always-false proposition.
7.4.2 Semantics
• For example, if the sentences in the knowledge base make use of the
proposition symbols P1,2, P2,2, and P3,1, then one possible model is m1
= {P1,2 = false, P2,2 = false, P3,1 = true} . With three proposition
symbols, there are = 8 possible models—exactly those depicted in
Figure 7.5.
• The semantics for propositional logic must specify how to compute the
truth value of any sentence, given a model. This is done recursively.
• All sentences are constructed from atomic sentences and the five
connectives; therefore, we need to specify how to compute the truth
of atomic sentences and how to compute the truth of sentences
formed with each of the five connectives.
• For complex sentences, we have five rules, which hold for any sub
sentences P and Q in any model m (here ―iff‖ means ―if and only if‖):
• The rules can also be expressed with truth tables that specify the truth
value of a complex sentence for each possible assignment of truth
values to its components.
• Truth tables for the five connectives are given in Figure 7.8.
• From these tables, the truth value of any sentence s can be computed with
respect to any model m by a simple recursive evaluation.
• The truth tables for ―and,‖ ―or,‖ and ―not‖ are in close accord with our
intuitions about the English words.
BAD402 Artificial Intelligence Module 3_Part 1
• There is no consensus on the symbol for exclusive or; some choices are
∨˙ or = or ⊕.
• The truth table for ⇒ may not quite fit one’s intuitive understanding of
―P implies Q‖ or ―if P then Q.‖
• For one thing, propositional logic does not require any relation of
causation or relevance between P and Q.
• Many of the rules of the wumpus world are best written using ⇔. For
example, a square is breezy if a neighboring square has a pit, and a
square is breezy only if a neighboring square has a pit.