Module-3{MQP Chatgpt answers}
Module-3{MQP Chatgpt answers}
chatgpt.com/c/678d0889-bab8-8009-9ab1-ee3fe1c5f664
A heuristic function, h(n), is an estimate of the cost to reach the goal state from node
n. It is used in informed search algorithms to guide the search process effectively and
efficiently. A good heuristic function can significantly reduce the computational effort by
helping the algorithm prioritize the most promising paths.
A Search Algorithm*
The A search algorithm* is one of the most popular informed search methods. It
minimizes the total estimated solution cost by combining the actual cost g(n) to reach a
node and the estimated cost h(n) to get from that node to the goal. The evaluation
function is defined as:
f(n)=g(n)+h(n)
Where:
1/21
1. Initialization:
Remove the node with the lowest f(n) value from the open list.
Add this node to the closed list (indicating it has been explored).
3. Goal Check:
If the current node is the goal, return the path and its cost.
4. Generate Successors:
Continue the process until the goal node is found or the open list is empty.
Properties of A*
1. Optimality:
Advantages
Combines the strengths of uniform-cost search (g(n)) and greedy best-first search
(h(n)).
Finds the least-cost solution efficiently if the heuristic is well-designed.
Limitations
2/21
Illustration of A Search*
Suppose the start node S, goal node G, and intermediate nodes A and B. The heuristic
values h and path costs c are given as:
S 6 -
A 4 2
B 2 3
G 0 1
Steps:
1. Start at S (f(S)=g(S)+h(S)=0+6=6).
2. Expand S and explore A and B.
f(A)=g(A)+h(A)=2+4=6,
f(B)=g(B)+h(B)=3+2=5.
3. Expand B (lower f(n)).
f(G)=g(G)+h(G)=4+0=4.
4. Expand G. The total cost g(G)=4.
Knowledge-Based Agent
3/21
1. Knowledge Base (KB):
Takes input from sensors about the environment and updates the KB using
TELL.
4. Action Execution:
Based on the knowledge in the KB, the agent decides the next action using
ASK and performs it through actuators.
Agent Workflow
1. Perceive: The agent perceives its environment and updates its KB with new
percepts.
2. Reason: The agent queries the KB to determine the best action based on its
knowledge and inference rules.
3. Act: The agent executes the chosen action and updates the KB with its effect.
4/21
lua
+------------------------+
| Environment |
+------------------------+
|
Percepts
|
v
+------------------------+
| Sensors |
+------------------------+
|
+-------v--------+ +----------------------+
| TELL (KB) |<--------+ Knowledge Base (KB) |
+-------+--------+ +----------------------+
|
+---v---+ +-----------------+
| ASK |-------->+ Inference |
+---+---+ +-----------------+
|
Decision
|
v
+------------------------+
| Actuators |
+------------------------+
|
Actions
|
v
+------------------------+
| Environment |
+------------------------+
In the Wumpus World problem, the agent uses its KB to safely navigate a cave with
hazards (e.g., pits and a Wumpus) while searching for gold.
5/21
1. Initial Knowledge:
The agent decides to move, grab the gold, or shoot the Wumpus based on its
KB.
This illustrates how a KBA uses TELL to update its knowledge and ASK to decide on
actions.
Environment Setup
6/21
The agent's goal is to:
Performance Measures
+1000: Reward for finding and exiting with the gold.
-1000: Penalty for being eaten by the Wumpus or falling into a pit.
-10: Penalty for shooting an arrow.
-1: Penalty for each step taken.
Percepts
The agent's sensors provide percepts that help it infer the state of the environment.
Each percept is based on the current room:
Actions
The agent can perform the following actions:
7/21
5. Discrete: The grid world is finite and well-defined.
Aspect Description
Performance Maximize score by finding gold and exiting safely while avoiding
penalties.
Environment 4x4 grid, hazards (pits, Wumpus), gold, agent starting at [1,1].
The agent uses a knowledge base (KB) and logical inference to decide its actions. It
performs the following steps iteratively:
Example Execution
8/21
Step 4: Infer and Act
diff
+-----+-----+-----+-----+
| | W | | |
| | | | |
+-----+-----+-----+-----+
| | | P | |
| | | | |
+-----+-----+-----+-----+
| | | | |
| G | | | |
+-----+-----+-----+-----+
| A | | | |
| | | | |
+-----+-----+-----+-----+
Key Takeaways
9/21
It serves as a benchmark problem for evaluating knowledge-based agents.
The syntax defines the rules for constructing valid sentences in propositional logic.
Components of Syntax
1. Atomic Sentences:
10/21
Truth Values
T T F T T T T
T F F F T F F
F T T F T T F
F F T F F T T
Scenario
Syntax
Semantics
Key Takeaways
11/21
3. Propositional logic enables reasoning by combining atomic facts with logical rules.
2/2
Key Components
1. Knowledge Base (KB):
Derives new facts from the existing KB using logical reasoning (e.g., Modus
Ponens, resolution).
3. TELL and ASK Functions:
The agent works in a loop, performing three main steps: PERCEIVE, REASON, and
ACT.
12/21
sql
1. TELL Function
2. ASK Function
13/21
Scenario
Execution Flow
1. PERCEIVE:
1. Modularity:
New facts and rules can be added easily.
2. Reasoning Power:
Combines existing knowledge to derive new facts.
3. Dynamic Updates:
Percepts and actions dynamically modify the KB.
Conclusion
The Knowledge-Based Agent framework, along with TELL and ASK functions, enables
intelligent decision-making by combining logical reasoning and dynamic knowledge
updates. It is highly effective in complex, partially observable environments like the
Wumpus World.
14/21
Characteristics of Wumpus World
1. Partially Observable:
The agent's actions depend on the order and history of previous actions.
4. Static:
The environment does not change except for the Wumpus being killed.
5. Discrete:
The environment consists of a finite grid (4x4), with clearly defined rooms.
Atomic Propositions:
Rules:
Bi,j⇔(Pi−1,j∨Pi+1,j∨Pi,j−1∨Pi,j+1)
2. A room is stenched if and only if a Wumpus is in an adjacent room:
Si,j⇔(Wi−1,j∨Wi+1,j∨Wi,j−1∨Wi,j+1)
3. The Wumpus exists in exactly one room:
W1,1∨W1,2∨⋯∨W4,4
(and only one of these is true).
15/21
4. Adjacent rooms to a non-stenched room cannot contain the Wumpus:
¬Si,j⇒(¬Wi−1,j∧¬Wi+1,j∧¬Wi,j−1∧¬Wi,j+1)
Given Information:
Logical Steps:
Final KB Representation
1. S1,2: True (percept in room [1,2]).
2. ¬S2,1: True (percept in room [2,1]).
3. S1,2⇔(W1,1∨W1,3∨W2,2).
4. ¬S2,1⇒(¬W1,1∧¬W2,2∧¬W3,1).
The agent uses this reasoning to safely infer that the Wumpus is in room (1,3).
16/21
Solution using A Search Algorithm*
Given:
1. Heuristic values:
a=14, b=12, c=11, d=6, e=4, f=11, z=0
2. Costs (edges):
Costs are labeled on the graph edges.
Terminology:
Initialization:
1. Start: a
2. Goal: z
3. Open List: [a] (nodes to be explored)
4. Closed List: [] (nodes already explored)
17/21
2. Expand c: Neighbors are b,d,e:
f(b)=g(c)+cost(c,b)+h(b)=3+12+12=27 (already in Open List, no update).
f(d)=g(c)+cost(c,d)+h(d)=3+7+6=16.
f(e)=g(c)+cost(c,e)+h(e)=3+10+4=17.
18/21
Step Open List Closed List
1 [c,b] [a]
2 [d,e,b] [a,c]
3 [e,b] [a,c,d]
4 [z,b,f] [a,c,d,e]
In the below graph, find the path from A to G. Using Greedy Best First
search and A* search algorithm. The values in the table represent heuristic
values of reaching the goal node G pass current node.
Solution
Given:
1. Graph:
Nodes: A,B,C,D,E,F,G.
Directed edges are labeled in the graph.
2. Heuristic Values (h(n)):
A=5, B=6, C=4, D=3, E=3, F=1, G=0.
Approach:
1. Always expand the node with the smallest heuristic value h(n).
2. Ignore g(n) (cost so far).
Steps:
1. Start at A, h(A)=5.
Neighbors: B,C.
Choose C (h(C)=4).
19/21
2. At C, h(C)=4.
Neighbors: E.
Choose E (h(E)=3).
3. At E, h(E)=3.
Neighbors: G.
Choose G (h(G)=0).
4. Goal G reached.
Path: A→C→E→G.
Cost: Not calculated (GBFS ignores edge costs).
2. A Search Algorithm*
Approach:
Steps:
1. Start at A:
20/21
4. At G:
Goal reached.
Path: A→C→E→G.
Cost: g(G)=7.
Summary
A* Search A→C→E→G 7
21/21