Ai Merged
Ai Merged
to
Artificial Intelligence
• Module I
• Artificial Intelligence: Introduction
• Intelligent Agents: Agents, Behavior, Nature of Env., Structure of Agents
• Problem Solving by Searching - Problem-Solving Agents, Example Problems,
Searching for Solutions, Uninformed search strategies, Searching with Partial Info
• Module II
• Informed Search & Exploration: Informed (Heuristic) search strategies,
Heuristic functions, Local Search Algorithms & Optimization Problems
• Constraint Satisfaction Problems: Introduction, Backtracking search for
CSPs, Local Search for CSPs
• Adversarial Search: Games, Optimal Decisions in Games, Alpha-Beta
Pruning;
• Knowledge & Reasoning: Knowledge-Based Agents, TheWumpusWorld.
2
Syllabus - 18CS2T29 : Artificial Intelligence
B.Tech – CSE – 6th sem
• Module III
3
Syllabus - 18CS2T29 : Artificial Intelligence
B.Tech – CSE – 6th sem
• Module IV
• Planning: The Planning Problem, Planning with State-Space Search, Partial-
Order Planning, Planning Graphs
• Uncertain Knowledge & Reasoning: Acting under Uncertainty, Bayes Rule & its
use
• Probabilistic Reasoning: Representing Knowledge in an Uncertain Domain,
Semantics of Bayesian Networks
• Module V
• Learning: Learning from Observations, Forms of Learning, Inductive Learning,
• Learning Decision Trees: Statistical Learning, Instance Based Learning, Neural
Networks
• Reinforcement Learning: Passive & Active Reinforcement Learning
• Expert Systems: Introduction, Architecture, Representations.
4
Books
• What is AI
• Four Approaches to AI
▪ Acting Humanly
▪ Thinking Humanly
▪ Acting Rationally
▪ Thinking Rationally
• Foundations of AI
• History of AI
6
What is AI?
7
What is AI?
9
Four Approaches to AI
10
Four Approaches to AI
▪ 3 ways to do this:
• Computer passes the test if the human cannot tell if the written
response is from a computer or human
12
A Computer with AI needs to have below capabilities :
13
Introduction
to
Artificial Intelligence
• What is AI
• Four Approaches to AI
▪ Thinking Humanly
▪ Acting Humanly
▪ Thinking Rationally
▪ Acting Rationally
• Foundations of AI
• History of AI
15
• (3) Think Rationally – The “Laws of thought” approach
(2) Big difference between solving a problem “in principle” than “in practice”
16
• (4) Act Rationally – The “Rational Agent” approach
▪ Agent – “One that Acts” – It perceives the env. through sensors & acts on
the env. through actuators (Ex: Robot, Auto-pilot, Vacuum cleaner…)
▪ Rational Agent – The Agent that acts to achieve the “best outcome”
▪ In case of uncertainty, the “best expected outcome”
▪ All the skills needed for Turing test also applies here
17
Foundations of AI
• Following disciplines have contributed to ideas, viewpoints &
techniques to AI
▪ Philosophy
▪ Made AI conceivable with the idea that “Mind is in someway like a machine”
▪ It operates based on “knowledge”
▪ “Thought” can be used to choose “action”
▪ Mathematics
▪ Provided “tools” to represent & manipulate logically certain or uncertain
statements
▪ Provided algorithms & computations
▪ Economics
▪ Helped in making decision that Maximize the expected outcome
18
Foundations of AI
▪ Neuroscience
▪ Provided the knowledge about “how brain works”
▪ How brain is similar & different from computers
▪ Psychology
▪ Provided the idea that humans & animals can be considered as “info.
processing machines” 19
Foundations of AI
▪ Computer Engg.
▪ Provided highly efficient & powerful machines to “implement AI
applications”
▪ Linguistics
▪ Provided the idea that language for communication can fit into AI
models
20
History of AI
Gestation of AI (1943-55)
• McCulloch & Pitt propose AI based on knowledge of physiology & neurons in brain
• Russel proposed formal analysis
•Turing proposed theory of computation
• Hebb (1949) proposed Hebbian learning on connection between neurons
Birth of AI (1956)
21
History of AI
22
History of AI
• General purpose applications (called weak methods) were unable to handle complex
problems
• Powerful applications using domain-specific knowledge like DENDRAL were needed
• R.I – 1st commercial Expert System started in 1982 – saved $40m per year for the org
• DEC’s AI group installed 40 E.S.s
• 5th Generation project (10 yrs) of Intelligent AI system – started in Japan using prolog
• Introduction to AI
• AI Problems & AI techniques
• Solving problems by searching
• Problem Formulation
• Intelligent Agents:
• Structure of Intelligent agents
• Types of Agents
• Agent Environments
Intelligent Agents
Percept
Agent’s perceptual inputs from env. at any given
instant
Percept sequence
Complete history of everything that the agent has ever
perceived (Ex: temp or location reading at short time intervals…)
Agent function & program
Program
Agent’s behavior is Practically described by (Algorithm)
Perception:
Clean or Dirty?
Where it is in? (location A & B)
---
[A;Clean], [A;Clean], [A;Clean] Right
[A;Clean], [A;Clean], [A;Dirty] Suck
---
Agent Program - implementation
Function Reflex-Vacuum-Agent ([location,state]) return an
action
If state = Dirty then return Suck
else if location = A then return Right // state = Clean
else if location = B then return Left
Concept of Rationality
Rational agent
One that does the right thing (see example below)
Every entry in the agent function table is correct (rational)
What is correct?
The actions that cause the agent to be most successful
Performance measure
An Objective function determines:
Criteria of Success for an agent
Ex: Passed the exam if scored 45%
• Success if 90% clean
Ex. in vacuum-cleaner
We want the “floor clean”
We don’t restrict “how the agent behaves”
Rationality
Ex. An exam
Maximize marks, based on the given questions & own
knowledge
Example rational agent – Vacuum Cleaner
Performance measure
Awards “one point” for each “clean square” at each time step,
measured over 10000 time steps
Software Agents
of images
Task Env Examples- PEAS description
skill
Properties Task environments
This distinction refers not to the env itself but to the agent’s (or
designer’s) state of knowledge about the env
Known env - The outcomes for all actions are known (Ex: Solitaire)
Unknown env - the agent will have to learn how make good
decisions (Ex: new video game)
Structure of agents
Architecture
Agent (Components)
Program
(Algorithm)
•Agent Function
•Agent Program
Structure of agents
Agent = architecture + program
Architecture = the components of agent (sensors, actuators..)
Agent programs
Input for “Agent Program” - only the current percept
Input for “Agent Function” - the entire percept sequence
The agent must remember all of them
Can be implemented as a look up table
P1 P2 P3 Pn Action
Vacuum-World
Agent function mapping percept sequences to actions
partial tabulation
---
[A;Clean], [A;Clean], [A;Clean] Right
[A;Clean], [A;Clean], [A;Dirty] Suck
---
Agent programs
P = the set of possible percepts (Ex: 2 (Clean or Dirty))
T= max length of the percept sequence (Ex- 150)
The total number of percepts it receives
T t 1 2 150
Size of the look up table
t 1
P (Ex- 2 + 2 + … + 2 )
Ex: Chess
P =10, T=150
Intelligent Agents
Four types
Goal-based agents
Utility-based agents
1. Simple reflex agents
1. Simple reflex agents (for fully observable env) Lab
percepts
(size, motion)
RULES:
(1) If small moving object,
then activate SNAP
(2) If large moving object,
then activate AVOID and inhibit SNAP
ELSE (not moving) then NOOP
needed for
completeness Action: SNAP or AVOID or NOOP
Example Reflex Agent With Internal State:
Wall-Following
start
Conclusion
Goal-based agents are less efficient but more flexible
Searching & Planning (Two other sub-fields in AI )
4. Utility-based agents A2
degree of success
4. Utility-based agents A2
When there are several goals & none of them can be achieved with
certainty
Utility provides a way for the decision-making
Learning Agents A2
Suggest actions
Learning Agents A2
Searching
(1) Uninformed (Blind) Search
(2) Informed Search
Example problems
Traveler's route finding problem (Travelling Romania)
Vacuum World
Toy problems
8-Puzzle & 8-Queen
Contents
Example problems
Missionaries & Cannibals
Real-World Problems
Route Finding Problem
6
Traveler's path finding problem
(Travelling Romania)
Goal Formulation:
An agent’s task is simplified if it can formulate a goal based on current
situation & performance measure
Problem Formulation:
Is the process of deciding what type of Actions (driving) & States (Cities)
to consider for a given goal
(Driving from one city to another & reach destination city)
Problem Solving Agents
Let us assume that the env is:
Observable (agent knows current state - current city)
Discrete (finite set of actions to choose from - connected cities)
Known (which states are reached by which action - having map of cities)
Deterministic (Each action has only one outcome)
Step Cost – sum of costs - c(s1, a, s2) - cost of taking action a in state s1 to
reach state s2
Optimal Solution – Has the lowest path cost among all solutions
Ex: In (Arad) is an abstract description excluding many things like Road condition,
Weather, Travel companions, Driving Rules etc..
Example Problems – 8 - Puzzle
State – A state desc. specifies the location of 8 tiles & the blank space
Initial State – Any state can be the initial state
Actions – Movement of the blank space Left, Right, Up & Down
Transition Model – For a given state & action, this returns the
resulting state
Goal Test – Checks if the resulting state matches goal state given below
Path Cost– Each step costs 1 (Path cost is the ‘no. of steps in the path’)
8-Queens problem
Placing 8 queens on a chess board, so that none attacks the other
Problem Formulation
State - Any arrangement of 0 to 8 queens on board
Transition Model –
Returns the board with
a queen added to the specific square
Goal Test– 8 queens on board, none attacked
Missionaries & Cannibals
3 missionaries & 3 cannibals are on one side of a river
The boat can hold 1 or 2 people
Find a way to get everyone to the other side, without ever leaving a
group of missionaries outnumbered by cannibals
Initial State
Any state can be the starting state
Path Cost – Each step costs 1 (Path cost is the ‘no. of steps in the path’)
Real-World Problems
Route Finding Problem - Problem formulation
Used in applications like Driving Directions, Touring, Travelling Salesman
(TSP), ROBOT Navigation etc.. Described by <S, s, O, G>
State Space:
Is a graph :
6. Loop: Go To Step 2
BREADTH-FIRST Search
All the successors of Root node are expended next & then their
successors…so on
All nodes at a given level (depth) are expanded before next level
Pitesti
Bucharest Bucharest
Search Tree – Arad to Bucharest
BREADTH-FIRST Search
New nodes go to the back of the queue & Older nodes are
Expended first FIFO queue O1 O2 N1 N2 N3
Searching an “Uniform tree” where each node has same ‘b’ successors
2 3 d d
Total no. of nodes generated : b (1st level) + b (2nd level) + b + … + b = O (b )
Pitesti
Bucharest Bucharest
BFS on a Graph Start
node
Initialization
// List of nodes to explored next
// If no nodes to explore
DFS have no clear adv. over BFS except for space complexity (for Tree search)
Once a node is expanded it can be removed from memory
Space Complexity: O (bm)
For d=16, DFS needs 156 kb, but BFS - 10 exabytes (7 Trillion times more)
Depth-First Search
Ex: Recursive
Once Expanded, the
node is removed from function call
memory & Frontier
(Open set)
Implemented
using LIFO queue
DEPTH-FIRST Search
DFS on a Graph Start
node
DEPTH
Initialization
// List of nodes to explored next
LIFO
// List of nodes already explored
// If no nodes to explore
Analysis
Solution depth (in levels from root, i.e., edge depth): d
Properties
Backward search
When all step(path) costs are equal => BFS search is the optimal search
Bcoz, shallowest goal node is found first
When steps costs are unequal =>
Uniform-cost search expands the node ‘n’ with the lowest path cost g(n)
instead of the shallowest node
Initialization
Iteration-1
Iter-2
If frontier node has
higher cost, replace it
UNIFORM-COST Search A1
310
278
Final Path: A, C, D, E, G
Comparison of Uninformed search techs
See table below:
b – branching factor
d – depth of the shallowest solution
m – max depth of search tree
l – depth limit
Tradeoff between space and time
Iterative deepening
Perform DFS repeatedly using increasing depth bounds
Works in O(bd) time and O(bd) space
Bi-directional search
Possible only if the operators are reversible
Works in O(bd/2) time and O(bd/2) space
53
Beyond Classical Search – Hill Climbing &
Simulated Annealing
2
Local search algorithms
Advantages –
1. Requires small memory – a constant amount (to store states & values)
2. Can find a reasonable solution in large search space where
systematic algorithms are unsuitable
Local search algorithms
Are useful for solving large search space problems fast
By finding the best state according to “Objective Function”
C A
D E
B E
Heuristic cost function (h) – No. of queen pairs that attack each other
It takes only 5 steps to reach the state in Fig-2 with h=1 (very
nearly a solution)
– HCS makes rapid progress towards solution
HCS: 8-queens problem
Min h
Fig-1
Fig-2
Solution
8-puzzle: HCS stuck at local maximum
1 + 1 + 3 + 1 + 2 + 1 + 1 + 1 + 1= 12
HCS: Algorithm
Solution
Random walk – “Randomly selects a successor” from the
neighborhood
Is complete but inefficient
Gradient descent:
Simulated Annealing –
Shake the ball hard (by increasing the temp in the beginning) &
then gradually reduce the intensity of shaking (reduce the temp)
Simulated Annealing - Algorithm
Solution
Dr. Pulak Sahoo
Associate Professor
Silicon Institute of Technology
Contents
Introduction
Heuristic Function
Greedy Search
A* Search
A* Search – Algorithm
G
S I2 In
H(n)
n
I1
I3
G(n)
Domain Knowledge & Heuristic Function
Operations
Step cost - 1
• Problem definition:
▪ Goal is to find:
▪ A minimum cost “sequence of transitions” to a goal state
Evaluation Function (f(n))
for different search algorithms
• f(n) – Evaluation function (Estimated cost from start node to
goal node thru current node ‘n’)
• h(n) – Heuristics – Estimated cost of how far the goal node is from
current node ‘n’
• g(n) – Cost so far from start node to node ‘n’
• Greedy Search
• f(n) = h(n) // heuristic (estimated cost) to goal node
• Uniform Cost Search
• f(n) = g(n) // path cost so far
• A* Search
• f(n) = h(n) + g(n) // path cost so far + heuristic to goal node
Greedy – Best first search (pg-93)
hsld(In(Arad)) = 366
m
Time & Space complexity for Tree is : O(b )
f(n) - Total cost of path from start node to “goal” through “n”
g(n) - The cost of reaching the node “n” from “start”
h(n) - Estimated cost of the cheapest solution through node
“n” to the goal
STEP-1 (Initialize): <Initialize the node lists - OPEN (currently known but not
evaluated) & CLOSED (already evaluated)>
STEP-2 (Fail): <If nothing in OPEN node list, then terminate with failure>
If OPEN = { }, then terminate with failure
STEP-3 (Select): <If OPEN list has nodes, then select the cheapest cost node>
Select the minimum cost node n from OPEN //like done in route finding problem
Save n in CLOSED // Move n into already evaluated list ‘CLOSED’
STEP-4 (Goal test): <if node n is the goal, stop search, return Success & f(n)>
If n G, terminate with success, return f(n)
STEP-5 (Expand): <Generate the successors of node n>
For each successor m of n // For each of the successors do below steps
// New Node - If m is neither in OPEN or CLOSED => neither known nor evaluated before
If m [OPEN or CLOSED] // g(m) is not yet calculated
// Calculate evaluation function f(m)
Set g(m) = g(n) + Cost (n,m) // Find the distance from start to node m
Set f(m) = g(m) + h(m) // Evaluation function for node m is updated
Insert m in OPEN // Insert m in OPEN (known nodes list)
// Old Node - If m is either in OPEN or in CLOSED => either known or evaluated before
If m [OPEN or CLOSED] // g(m) is already calculated
Set g(m) = min {g(m), g(n) + Cost(n,m)} // set g(m) to lowest value till now
Set f(m) = g(m) + h(m) // Calculate evaluation function f(m)
// If f(m) value of this node is less than earlier nodes at same level
If f(m) has decreased & m CLOSED
move it to OPEN
Operations
Step cost - 1
Greedy Search
A* Search
A* Search – Algorithm
A* Search – Conditions for Optimality
2. Contingency problems
Occurs when the env. is partially observable or when actions are uncertain
After each action the agent needs to verify what effects that action has
caused
Rather than planning for every possible contingency after an action, it is
usually better to start acting and see which contingencies do arise.
37
Constraint Satisfaction
Problems
2
Constraint satisfaction problems (CSPs)
A State (Ex: city (Arad) or water jug (3,2)) contains all of the
info necessary :
to predict the effects of an action
4
Example: Map-Coloring
Australia
7
Varieties of CSPs
Discrete variables
Finite domains:
n variables, domain size d (Ex: map coloring problem)
O(d n) complete assignments
Ex: Boolean CSPs (NP-complete)
Formula "a AND NOT b" is satisfiable because one can find the
values a = TRUE and b = FALSE, which make (a AND NOT b) = TRUE
Infinite domains:
Integers, strings variables etc.
Ex: job scheduling, variables are start/end days for each job
8
Varieties of CSPs
Continuous variables
Ex1: start/end times for Hubble Space Telescope observations (time
is variable in a continuous domain)
Constraints: Alldiff(F,T,U,W,R,O)
Variables: F T U W R O X1 X2 X3 O + O = R + 10 · X1
X1 + W + W = U + 10 · X2
Domains: {0,1,2,3,4,5,6,7,8,9} X2 + T + T = O + 10 · X3
X3 = F, T ≠ 0, F ≠ 0
11
Real-world CSPs
Assignment problems
Ex: who teaches in what class
Timetabling problems
Ex: which class is offered when and where?
Transportation scheduling
Factory scheduling
12
Standard search formulation (incremental)
14
Backtracking search - Algorithm
15
Backtracking example
16
Backtracking example
17
Backtracking example
18
Backtracking example
19
Improving backtracking efficiency
20
Most constrained variable
Most constrained variable:
choose the variable with the fewest legal values
3 2
3 2
3 1
3
3 2 1
3 3 3 2
2
3 3 3
remaining variables
3 2
3 3 2 1
3
3 2 1
3 3 2
3
2
3 3 3
22
Least constraining value
2 constraints - selected
LCV
3 constraints
MCV
24
Forward checking
Idea:
Keep track of remaining legal values for unassigned variables
25
Forward checking
Idea:
Keep track of remaining legal values for unassigned variables
26
Forward checking
Idea:
Keep track of remaining legal values for unassigned variables
27
Constraint propagation
Forward checking propagates information from assigned
to unassigned variables, but doesn't provide early
detection for all failures:
B
R
29
Arc consistency
B
R
30
Arc consistency
To apply to CSPs:
36
Dr. Pulak Sahoo
Associate Professor
Silicon Institute of Technology
Adversarial Search
Introduction
Game Playing
Min-Max Search
Zero sum game - Total payoff to all players is same (0+1, 1+0, ½ + ½)
MAX has 9
possible moves
MIN has 8
possible moves
Optimal Decisions in games
MAX & MIN are playing, MAX responds to all possible moves from MIN
Idea: choose the move with highest minimax value (given by utility/
payoff function) = best achievable move against best play by opponent
This one-move game ends after ½ moves (called Ply) each by MAX & MIN
Recursion proceeds down the leaves of the tree & minimax values
are backed up (in the example it returns value 3)
Note: m – max depth of the tree, b – no. of legal moves at each point
For chess, b ≈ 35, m ≈100 for "reasonable" games exact solution
completely infeasible
// Action – a, State – s, v - utility
// v initialized to -infinity
// v initialized to -infinity
Z = min (2,x,y)
<= 2
No need to
evaluate. Can
Simplified minimax formula is given below be pruned
Consider the 2 unevaluated successors of node ‘A2’ have values ‘x’ & ‘y’
The value of the root node is given below (root value does not depend on
pruned nodes x & y)
MINIMAX (root) = max ( min (3, 12, 8), min (2, x, y), min (14, 5, 2) )
= max ( 3, min (2, x, y), 2)
= max ( 3, z, 2) where z = min (2, x, y) <= 2
= 3
Alpha-Beta Pruning can be applied to tree of any depth
Beta – the value of the best (lowest value) choice we have found
so far at any choice point along the path for MIN
• Introduction
• Knowledge-Based Agents
• Propositional Logic
2
Introduction
• Human beings know things
• Operations
TELL – Add new sentence to KB
ASK – Query what is known
t = t + 1 // Increment time
1. Declarative approach
TELL sentences one-by-one until the agent knows how to
operate
2. Procedural approach
Encodes desired behavior directly into program code
Wumpus World
• A cave containing rooms connected by passageways
Performance measure
• +1000 – Coming out of cave with gold
• -1000 – Falling into Pit or Eaten by Wumpus
• -1 – For each action
• -10 – For using the arrow
• End of game – Agent dies or climbs out of cave
Env
• A 4X4 grid of rooms
• Agent starts in [1,1]
• Location of Gold & Wumpus chosen randomly (except starting
one )
• Each square (except starting one) can be a pit with probability9 0.2
Task Environment Description - PEAS
Actuators
• Agent Moves – Forward, TurnLeft, TurnRight
• Death – Falling into Pit or Eaten by Wumpus (Safe to enter room with dead
wumpus)
• Forward move against wall– Not allowed
• Actions– Grab (pickup gold), Shoot (one Arrow), Climb (out of cave from
[1,1])
• End of game – Agent dies or climbs out of cave
Sensors
• Stench: Perceived in squares containing & adjacent to wumpus
• Breeze: Perceived in squares adjacent to a pit
• Glitter: Perceived in squares containing Gold
• Bump: Perceived when walking into a Wall
10
• Kill Wumpus: Perceived Scream anywhere in the cave
Wumpus World - Steps
12
• In [1,2] perceived Stench & No breeze – denoted by S - [Stench, None, None,
None, None]
• After 5th move perceived [Stench, Breeze, Glitter, None, None] => Found Gold
13
Logic & Deduction
14
Types of Logics
15
1. Propositional Logic
Simple but Powerful
Contains a set of atomic propositions AP
It contains Syntax, Semantics & Entailment -
Syntax - Defines allowable sentences
Sentences – 2 types
Atomic sentence – Single symbol that can be True | False | AP
Ex- P, Q, R, W1,3 (means Wumpus in [1,3]), North…
Complex sentence - ( Sentence ) | [Sentence]
| : Logical Connective like
( (negation), (and) , (or), (if & only if), (implies))
Ex: W1,3 W2,2
Semantics – Defines the rules for determining the truth of the
statement in a given model
Entailment – Relation between 2 successive sentences
16
Inference Rules
17
Inference Rules
2. Unit Resolution:
3. Resolution:
or
19
Propositional Logic
Semantics (Defines the rules for determining the truth of the statement)
Atomic sentence – 2 rules (True & False)
Ex: B1,1 (P1,2 P2,1)
Complex sentence – 5 rules
A square is breezy if the
P is true iff P is false neighboring squares have pit
and vice versa
P Q is true iff both P & Q are true
P Q is true iff either P or Q is true
P Q is true unless P is true & Q is false
P Q is true iff P & Q are both true or both false
Truth Tables - Specify truth value of complex sentence for each possible
value
20
Propositional Logic – Example – Wumpus world
Example-2:
• If the unicorn is mythical, then it is immortal, (premises)
• But, if it is not mythical, then it is a mortal mammal.
• If the unicorn is either immortal (P1 ) or a mammal (P2 ) , then it is
horned (Q) .
• The unicorn is magical if it is horned
P1 P2 … Pn Q 23
Conjunctive Normal Form (CNF)
// Replace all
// De Morgan’s theorem
// in normal form
25
Propositional Logic – Example-1
3rd inference rule (resolution)
// B is resolved away
// Q is resolved away
26
Propositional Logic – Example-2
Problem: Solution: H: It is “Humid” (sentences)
• If it is “Hot”, Then it is “Humid” R: it will “Rain”
• If it is “Humid”, Then it will “Rain” O: It is “Hot”
CNF: Step-1
(eliminate =>)
Apply Resolution
Inference rule on
H,O&R
Resolution rule
27
Propositional Logic – Example-3
28
2. First-order Predicate Logic (FOPL)
31
Example-1
32
Examples-2 Formal definition – using FOPL
33
FOPL – Example-3
Problem:
• Show the validity of the following sentence
• All men are mortal. John is a man. Therefore John is Mortal.
34
FOPL – Example-3
Problem:
• Show the validity of the following sentence
• All men are mortal. John is a man. Therefore John is Mortal.
Replace =>
Negation of Goal
35
FOPL – Example-4
Problem:
• Given the following predicate show how resolution process can be applied
Negation of Goal
36
Forward Chaining
Forward chaining is a data driven method of
Deriving a particular goal
from a given knowledge base & a set of inference rules
The application of inference rules results in new knowledge
which is then added to the knowledge base
Used to answer the question “What can happen next”
The inference engine applies chain of conditions, facts & rules
to arrive at a solution (decision or goal)
37
Forward Chaining
• The system starts from a set of facts & a set of rules
Tries to find ways of using them to deduce a conclusion (goal)
• 1st Step – Take the facts from the fact database & see if any
combination of these matches any of the components of rules in the
rule database
// Fact-1
// Fact-2
// Conclusion added to KB
39
Forward Chaining - Example - Elevator
// Fact-4 added to KB
40
Forward Chaining - Example - Elevator
The system examines the rules & finds that Facts 1 & 2 match the
components of Rule 3
Rule 3 fired & its conclusion “Go to 3rd floor” is added to the facts
database
Note that Fact 3 (today is Tuesday) was ignored because it did not
match the components of any rules
Assuming the elevator is going to the 3rd floor & has reached the
2nd floor, when the button is pressed on the 1st floor
• Question
44
45
And
46
Conclusion
47
Backward Chaining
Backward chaining is a goal driven method of
Deriving a particular goal from a given knowledge base & a set
of inference rules
Inference rules are applied by matching the goal to the results of
the relations stored in the knowledge base
Used to answer the question “Why this happened”
Based on what has already happened, the inference engine tries to
find out which conditions (causes or reasons) could have happened
for this result
48
Backward Chaining
• The system starts from a conclusion (hypothesis to prove or goal)
Tries to show how the conclusion has been reached from the
rules & facts in the database
• Reasoning in this way is called as goal-driven reasoning
• Steps – Start with the goal state & see what actions could lead to
it of the components of rules in the rule database
• Ex:
If the goal state is “blocks arranged on a table”
Then one possible action is to “place a block on the table”
This action may not be possible from the start state
Further actions need to be added before this action
In this way, a plan is formulated starting from the goal & working back
toward the start state 49
Backward Chaining
50
Example - WEATHER FORECAST SYSTEM
52
Example - WEATHER FORECAST SYSTEM
53
Example - WEATHER FORECAST SYSTEM
54
Backward Chaining Example
55
56
57
58
59
60
61
Backward Chaining Algorithm
62
63
Planning
• Representation of Action
• Hierarchical Planning
• Example: House Construction
2
Introduction
• Planning: the task of finding a sequence of actions that will
achieve a given goal when executed from a given world state
• Given are:
• Planning agents :
Construct plans to achieve goals, then executes them
4
Introduction
• Key ideas:
Divide-and-conquer algorithms
Robot Robot
hand
A hand
C B
A B C
START GOAL
Example – The Blocks World
Robot Robot
hand
A hand
C B
A B C
START GOAL
• Fundamental Problem :
The “frame problem” is concerned with the question
Robot Robot
hand
A hand
C B
A B C
START GOAL
on(B, table)
on(A, table) on(C, table)
on(C, A) on(B, C)
hand empty on(A, B)
clear(C) hand empty
clear(B) clear(A)
Rules
R1 : pickup(x)
Precondition & Deletion List: hand empty, on(x,table), clear(x)
Add List: holding(x)
R2 : putdown(x)
Precondition & Deletion List: holding(x)
Add List: hand empty, on(x,table), clear(x)
R3 : stack(x,y) // place x on y
Precondition & Deletion List: holding(x), clear(y)
Add List : on(x,y), clear(x)
R4 : unstack(x,y) // Remove x placed on y
Precondition & Deletion List: on(x,y), clear(x)
Add List: holding(x), clear(y)
Plan for the block world problem
\\ swap cargos
\\ load cargo c into plane p at airport a
13
Example: Spare Tire problem
14
Example: Spare Tire problem
Representation of Action
Example – Transportation (Air Cargo) problem
Op ( ACTION: Go(there),
PRECOND: At(here) Path(here, there),
EFFECT: At(there) At(here) )
Partial Order Planning
Strengths of POP:
• Early pruning of the search space parts in case of irresolvable conflicts
• The solution is partial-order plan (produce flexible plans)
Partial Order Planning
Example – Shoes & Socks Problem
Actions
Op( ACTION: RightShoe, PRECOND: RightSockOn, EFFECT: RightShoeOn)
Op( ACTION: RightSock, EFFECT: RightSockOn)
Op( ACTION: LeftShoe, PRECOND: LeftSockOn, EFFECT: LeftShoeOn)
Op( ACTION: LeftSock, EFFECT: LeftSockOn)
Initial plan
Plan (
STEPS: { S1: Op (ACTION: start),
S2: Op (ACTION: finish, PRECOND: RightShoeOn LeftShoeOn )},
ORDERINGS: {S1 S2}, // S1 should take place before S2
BINDINGS: {},
LINKS: {}
)
Example – Shoes & Socks Problem
Example – Shoes & Socks Problem
Hierarchical Planning
• Hierarchical task network (HTN) planning is an approach to
automated planning in which the dependency among actions can
be given in the form of hierarchically structured networks
• Construction Domain:
Actions: // arrows show dependency
Buy Land: Money Land
Bayesian networks
Drawbacks
Very large & complex belief state representations & Contingency plan
4
Uncertainty-Example
Uncertainty is expressed as A B
Probability theory
Bayesian networks
Certainty factors
6
Reasons for using probability
Theoretical ignorance
Medical science has no complete theory for this domain.
Practical ignorance
Uncertain about a patient condition as so many tests are impossible
to run.
In such judgemental domains like law, business, design.., the
agent’s knowledge is only a degree of belief
Which can be dealt with probability theory
7
1. Probability theory
8
Probability theory - representation
10
Uncertain Knowledge and
Reasoning
Bayesian networks
P(X,Y) = P(X|Y)*P(Y)
14
Bayes’ Rule, Theorem and its use
Bayes Theorem
Toothache Toothache
Cavity 0.04 0.06 // cavity with/wo toothache
Cavity 0.01 0.89 // no cavity
+ 0.064 = 0.28
19
Belief Network for the Burglar alarm
example
P(B) P(E)
0.001 0.002
Burglary Earthquake
B E P(A)
T T 0.95
Alarm T F 0.95
F T 0.29
F F 0.001
A P(J) A P(M)
JohnCalls MaryCalls
T 0.90 T 0.70
F 0.05 F 0.01
20
Example: Burglar alarm at your home
P(B) P(E)
Parent 0.001 0.002
Burglary Earthquake
B E P(A)
T T 0.95
Alarm T F 0.95
F T 0.29
F F 0.001
Child A P(J)
JohnCalls MaryCalls A P(M)
T 0.90 T 0.70
F 0.05 F 0.01
22
Representing the joint probability distribution
Probability of the event that “the alarm has sounded but neither
a burglary nor an earthquake has occurred, and both Mary and
John call”:
P(J M A B E)
= P(J | A) P(M | A) P(A | B E) P(B) P(E)
= 0.9 X 0.7 X 0.001 X 0.999 X 0.998 = 0.00062
23
Bayesian network semantics
26
Learning
• Paradigms of learning
• Supervised & Unsupervised Learning
• Inductive Learning
Decision Tree Induction
• Reinforcement Learning
Introduction
Improves the
Performance
element
Suggests
new actions
Four elements of learning agent
1. Performance element
– It takes the percepts as input & decides on external actions
2. Critic
– Tells the learning element how well the agent is doing
3. Learning element
– Takes feedback on how the agent is doing from Critic
– Determines how the performance element can do better in future
4. Problem generator
– Suggests actions that will lead to new & informative experiences
Paradigms of learning
1. Supervised Learning
– Uses a labeled training set to teach the model to yield the desired output.
– This training dataset includes inputs & correct outputs (labeled by a
friendly teacher) allowing the model to learn over time
2. Unsupervised Learning
– The training dataset are not labeled (output not provided)
– The agent has to discover the patterns within the dataset on its own
3. Inductive Learning
– Is used for generating a set of a classification rules which are of the form
“IF-THEN”
– These rules are produced at each iteration on the dataset & appended to
the existing set of rules
4. Reinforcement Learning
– Helps in taking suitable action to maximize reward in a particular situation
– The agent receives some feedbacks (positive or negative) on its action, but
is not told what is the correct action
1. Supervised learning
• Supervised learning method involves the training of the system or
model where the output labels are provided
• The model is trained with guidance of already known outputs/labels
• to facilitate the prediction of outputs/labels for future unknown
instances (Test Data)
1. SL technique deals with the labeled data where the output data
patterns are known to the system. But, the USL technique works with
unlabeled data
New
examples
h: X Y
Inductive Learning Example – Restaurant selection
Instance Space: Each row is an instance & each column is a feature (attribute)
Label: Last column is the label (or output)
Training Data : Set of instances labeled with target values
Hypothesis Space: Set of all classification rules hi that we allow
Learning
• Paradigms of learning
• Supervised & Unsupervised Learning
• Inductive Learning
Decision Tree Induction
• Reinforcement Learning
Classification by Decision Tree Induction
Labeled
Training
Tuple
15
Example: Finding Customers likely to buy a
computer
16
How are decision trees used for classification?
• A path is traced from the root to a leaf node, which holds the
class or label prediction for that tuple
17
Why DT classifiers so popular?
• The construction of DT classifiers does not require any domain
knowledge or parameter setting
• The learning & classification steps of DT induction are simple & fast
19
The attribute age has the highest information gain (has more
influence on buying decision) & therefore becomes the splitting
attribute at the root node of the DT. Branches are grown for each
outcome of age.
20
Artificial Neural Networks (ANN)
• An artificial neural network (ANN) is an AI based computing
system designed to simulate the way the human brain analyzes
and processes information
• It is used to solve complex problems the same way human’s do
• ANN consists of a pool of processing units (neurons) which
communicate by sending signals to each other over a large
number of weighted connections
x1
x x
x x
x
x
x
x x
x2
5/8/2021
4. Reinforcement Learning
• RL is a feedback-based learning technique in which an agent learns to
behave in an env. by performing the actions & seeing results of actions
• The agent gets positive feedback for each good action & gets negative
feedback or penalty for each bad action
• The agent learns automatically using feedbacks & experience without
any labeled data
• It solves problem with long-term goals, such as game-playing, robotics,
etc.
Reinforcement Learning - Example
The End!!!