AI 3rd Module.pptx
AI 3rd Module.pptx
Text book: Stuart J. Russell and Peter Norvig, Artificial Intelligence, 3rd Edition,
Pearson, 2015
Informed (Heuristic Search Strategies)
• This section shows how an informed search strategy—one that uses
problem-specific knowledge beyond the definition of the problem
itself—can find solutions more efficiently than an uninformed strategy.
• The general approach we consider is called best-first search.
• Best-first search is an instance of the general TREE-SEARCH or
GRAPH-SEARCH algorithm in which a node is selected for expansion
based on an evaluation function, f(n).
• The evaluation function is construed as a cost estimate, so the node with the
lowest evaluation is expanded first.
• The implementation of best-first graph search is identical to that for
uniform-cost search except for the use of f instead of g to order the priority
queue.
Prof. Salma Itagi,Dept. of CSE,SVIT 3
• The choice of f determines the search strategy.
• h(n) = estimated cost of the cheapest path from the state at node n to a
goal state.
• Greedy best-first search tries to expand the node that is closest to the goal, on the
• Thus, it evaluates nodes by using just the heuristic function; that is, f(n) = h(n).
• Greedy search Algorithm ignores the cost of the path that has already been traversed to
reach node n.
1. Initialize a tree with the root node being the start node in the open list.
2. If the open list is empty, return a failure, otherwise, add the current
node to the closed list.
3. Remove the node with the lowest h(x) value from the open list for
exploration.
4. If a child node is the target, return a success. Otherwise, if the node
has not been in either the open or closed list, add it to the open list for
exploration.
C has the lowest cost of 6.
The total cost for the path (P -> C -> U -> S) evaluates to 11. The potential problem with a greedy best-first
search is revealed by the path (P -> R -> E -> S) having a cost of 10, which is lower than
(P -> C -> U -> S).
Greedy best-first search ignored this path because it does not consider the edge weights.
A* search: Minimizing the total estimated solution cost
• The most widely known form of best-first search is called A∗.
• 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)
• Since g(n) gives the path cost from the start node to node n, and h(n) is the estimated cost of
the cheapest path from n to the goal, we have
f(n) = estimated cost of the cheapest solution through n .
• Thus, if we are trying to find the cheapest solution, a reasonable thing to try first is the
node with the lowest value of g(n) + h(n).
• 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.
• The algorithm is identical to UNIFORM-COST-SEARCH except that A∗ uses g + h
instead of g.
|
• 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| :
• This is a form of the general triangle inequality, which stipulates that each side of a triangle cannot be
longer than the sum of the other two sides.
• For an admissible heuristic, the inequality makes perfect sense: if there were a route from n to G n via n| that
was cheaper than h(n), that would violate the property that h(n) is a lower bound on the cost to reach G n .
• The next step is to prove that whenever A ∗ selects a node n for expansion, the optimal path to that node has been
found.
• Were this not the case, there would have to be another frontier node n on the optimal path from the start node to n,
by the graph separation property.
1.Function f(n):
The total estimated cost of the cheapest solution through
node n, defined as:
f(n)=g(n)+h(n)
where g(n) is the cost to reach node n from the start node.
Conclusion
Thus, we have shown that:
f(n′)≥f(n)
IDA* Algorithm
❖ Iterative deepening A (IDA)* is a powerful graph traversal and pathfinding algorithm
designed to find the shortest path in a weighted graph.
1. Initialization: Set the root node as the current node and compute its f-score.
2. Set Threshold: Initialize a threshold based on the f-score of the starting
node.
3. Node Expansion: Expand the current node’s children and calculate their
f-scores.
4. Pruning: If the f-score exceeds the threshold, prune the node and store it for
future exploration.
5. Path Return: Once the goal node is found, return the path from the start
node to the goal.
6. Update Threshold: If the goal is not found, increase the threshold based on
the minimum pruned value and repeat the process.(from step 2)
Graph Problem
Iteration 4:
Iteration 5:
Iteration 6:
Iteration 6:
The memory is full, which means we need to remove the “C” node, because it has the
highest f value, and it means that if we eventually reach the goal from this node the total
cost at best case scenario will be equal to 6, which is worse than we already have.
At this stage, the algorithm terminates, and we have found the shortest path from the “S”
node to the “G” node.
Comparison of IDA*,RBFS and SMA*
Comparison of IDA* and RBFS
Learning to search Better
• Could an agent learn how to search better?
• The answer is yes, and the method rests on an important concept called the metalevel
state space.
• Each state in a metalevel state space captures the internal (computational) state of a
program that is searching in an object-level state space.
• The goal of learning is to minimize the total cost of problem solving, trading off
computational expense and path cost.
CHAPTER 3;3.6:
HEURISTIC FUNCTIONS
The effect of heuristic accuracy on performance
1. Depends on effective branching factor.
❑ A problem with fewer restrictions on the actions is called a relaxed problem. The state-space
graph of the relaxed problem is a super graph of the original state space because the removal of
❑ Hence, the cost of an optimal solution to a relaxed problem is an admissible heuristic for the
original problem.
3. Generating admissible heuristics from subproblems:
Pattern databases
•Relevant Features: Instead of using raw state descriptions (like the full configuration of the puzzle), it’s more effective
to extract features that are predictive of the state’s distance from the goal.
•A common approach to combining features for predicting h(n)is through a linear combination:
h(n)=c1x1(n)+c2x2(n) ;Here, c1nd c2 constants that need to be determined.
• Learning heuristics from experience is a promising approach to enhance informed search strategies. By
leveraging feature extraction, statistical analysis, and machine learning techniques, agents can develop
effective heuristics that significantly improve search efficiency.
CHAPTER 7🡪7.1 to 7.4:
LOGICAL AGENTS:
Knowledge–based agents, The Wumpus world, Logic,
Propositional logic, Reasoning patterns in Propositional Logic
KNOWLEDEGE BASED AGENTS
• The central component of a knowledge-based agent is its knowledge base, or KB.
• A knowledge edge base is a set of sentences.
• Each sentence is expressed in a language called a knowledge representation
language and represents some assertion about the world.
• Sometimes we dignify a sentence with the name axiom, when the sentence is
taken as given without being derived from other sentences.
• There must be a way to add new sentences to the knowledge base and a way to
query what is known.(TELL and ASK). Both operations may involve
inference—that is, deriving new sentences from old.
Each time the agent program is called, it does three things.
2. Second, it ASKs the knowledge base what action it should perform. In the process
of answering this query, extensive reasoning may be done about the current state
of the world, about the outcomes of possible action sequences, and so on.
3. Third, the agent program TELLs the knowledge base which action was chosen,
• MAKE-ACTION-QUERY
constructs a sentence that asks what action should be done at the current time.
Finally,
• MAKE-ACTION-SENTENCE constructs a sentence asserting that the chosen action was
executed.
The details of the inference mechanisms are hidden inside TELL and ASK.
• A knowledge-based agent can be built simply by TELLing it what it needs to know.
• Starting with an empty knowledge base, the agent designer can TELL sentences one
by one until the agent knows how to operate in its environment. This is called the
declarative approach to system building.
• We now understand that a successful agent often combines both declarative and
procedural elements in its design, and that declarative knowledge can often be
compiled into more efficient procedural code.
Environment:
• A 4*4 grid of rooms.
• The agent initially in room square [1, 1], facing toward the right.
• Location of Wumpus and gold are chosen randomly except the first square [1,1].
• Each square of the cave can be a pit with probability 0.2 except the first square.
PEAS for the WUMPUS WORLD PROBLEM(cont..,)
Actuators:
• Left turn, Right turn Move forward ,Grab, Release, Shoot.
Sensors:
• The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not diagonally).
• The agent will perceive breeze if he is in the room directly adjacent to the Pit.
• The agent will perceive the glitter in the room where the gold is present.
• The agent will perceive the bump if he walks into a wall.
• When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere in the cave.
• These percepts can be represented as five element list, in which we will have different indicators for
each sensor.
• Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it can be
represented as
[Stench, Breeze, None, None, None]
WUMPUS WORLD PROPERTIES
• Partially observable: The Wumpus world is partially observable
because the agent can only perceive the close environment such as an
adjacent room.
• Deterministic: It is deterministic, as the result and outcome of the
world are already known.
• Sequential: The order is important, so it is sequential.
• Static: It is static as Wumpus and Pits are not moving.
• Discrete: The environment is discrete.
• One agent: The environment is a single agent as we have one agent
only and Wumpus is not considered as an agent.
Agent's First step:
Initially, the agent is in the first room
or on the square [1,1], and we already
know that this room is safe for the
agent, so to represent on the below
diagram (a) that room is safe we will
add symbol OK.
Symbol A is used to represent agent,
symbol B for the breeze, G for Glitter
or gold, V for the visited room, P for
pits, W for Wumpus.
At Room [1,1] agent does not feel any
breeze or any Stench which means the
adjacent squares are also OK.
Agent's second Step:
2.CONJUNCTION ∧ (and). A sentence whose main connective is ∧, such as W1,3 ∧ P3,1, is called a con junction;
its parts are the conjuncts. (The ∧ looks like an “A” for “And.”)
3. DISJUNCTION ∨ (or). A sentence using ∨, such as (W1,3 ∧ P3,1) ∨ W 2,2
is a disjunction of the disjuncts
(W1,3 ∧ P3,1) and W 2,2.
4. IMPLICATION ⇒ (implies). A sentence such as (W1,3 ∧ P3,1) ⇒ ¬ W 2,2 is called an implication (conditional or
PREMISE)
• Its premise or antecedent is (W1,3 ∧ P3,1), and its conclusion or consequent is ¬W2,2.
• Implications are also known as rules or if–then statements.
• The implication symbol is sometimes written in other books as ⊃ or →.
5. BICONDITIONAL ⇔ (if and only if). The sentence W1,3 ⇔ ¬W2,2 is a biconditional. Some other books write
this as ≡.
Semantics
• The semantics defines the rules for determining the truth of a sentence with respect to a particular
model.
• In propositional logic, a model simply fixes the truth value—true or false—for every proposition
symbol.
• 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}
• The semantics for propositional logic must specify how to compute the truth value of any sentence,
given a model.
• 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.
• Atomic sentences are easy:
• True is true in every model and False is false in every model.
• The truth value of every other proposition symbol must be specified directly in the model. For example,
in the model m1 given earlier, P1,2 is false.
• For complex sentences, we have five rules, which hold for any subsentences P and Q in any model m (here
“iff” means “if and only if”):
• ¬P is true iff P is false in m.
• P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• P ⇒ Q is true unless P is true and Q is false in m.
• P ⇔ Q is true iff P and Q are both true or both false in m.
• 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
A simple Knowledge Base
• The sentences we write will suffice to derive ¬P1,2 (there is no pit in [1,2]) .We label each sentence Ri so
that we can refer to them:
• This has to be stated for each square; for now, we include just the relevant squares:
R2 : B1,1 ⇔ (P1,2 ∨ P2,1) .
R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) .
• The preceding sentences are true in all wumpus worlds.
• Now we include the breeze percepts for the first two squares visited in the specific world
the agent is in R4 : ¬B1,1 . R5 : B2,1 .