Artificial Intelligence1
Artificial Intelligence1
R. K. Dash
Text book- Elaine Rich, Kevin Knight, & Shivashankar B Nair, Artificial Intelligence, McGraw Hill
Reference book- Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach
Search Space Definitions
• Problem formulation
• Describe a general problem as a search problem
• Solution
• Sequence of actions that transitions the world from the initial
state to a goal state
• Solution cost (additive)
• Sum of the cost of operators
• Alternative: sum of distances, number of steps, etc.
• Search
• Process of looking for a solution
• Search algorithm takes problem as input and returns solution
• We are searching through a space of possible states
• Execution
• Process of executing sequence of actions (solution)
Level of the Model
• To test psychological theories of human performance
• To enable computers to understand human reasoning
• To enable people to understand computer reasoning
• To exploit what knowledge we can glean from people
• A set of rules consisting of a left side that determines the applicability of the rule and
and a right side that describes the operations to be performed if the rule applied.
• A control strategy that specifies the order in which rules will be compared to the database
and the way of resolving the conflicts that arise when several rules match at once
• A rule applier
Control strategy
- It must cause motion
- It must be systemic
Example Problems –Water Jug
States: Contents of 4-gallon jug and 3-gallon jug
Operators:
Goal: (2,n)
0 3 2
3 0 9
3 3 2
4 2 7
0 2 5 or 12
2 0 9 or 11
DFS BFS
1. Less memory since the nodes on the 1. More memory since all of the tree that has so far
current path are stored been generated must be stored
2. It may find a solution without examining 2. All parts of the tree must be examined to level n
much of the search space at all. before any nodes on level n+1 can be examined
3. It may follow a single, unfruitful path for 3. It will not get trapped exploring a blind alley
for a long time before the path terminates
in a state that has no successor
4. It can not find multiple solutions 4. It can find multiple solutions
5. It may not find an optimal solution 5. If there is any solution, then it is guaranteed to find it.
DFS BFS If there are multiple solutions, a minimal solution will be
found
Complete N Y
Optimal N N
Heuristic N N
Time bm bd+1
Space bm bd+1
Heuristic search
•
Problem characteristics
• Is the problem decomposable?
• Can solution steps be ignored or undone?
• Is the universe predictable?
• Is a goo solution absolute or relative?
• Is the solution a state or a path?
• Is a large amount of knowledge absolutely required to solve the
problem, or is knowledge important only to constrain the search?
• Does the task require interaction with a person?
Production system characteristics
• Monotonic production system
• The application of a rule never prevents the later application of another rule
that could also have been applied at the the first rule was selected
• Nonmonotonic production system
No Correct Yes
solution?
stop
Hill climbing search- Simple
If (initial _state==goal _state)
return (initial_ state)
Else
current_ state= initial_ state
repeat until (a solution is found or no more new operators left to be applied in the current state)
select an operator that has not yet been applied to current_ state
Apply the selected operator to current _state to produce new _ state
if (new_ state==goal_ state)
return ( new _ state)
else if (h(new _ state) < h(current _ state))
current_ state= new _state
else
continue
Example- Simple hill climbing
A A
6 7 6 7
8 8
B D B D
8 4 1 8 1
C 4 C
7 5 7 5
E H L E H L
F G F G
6 3 2 3 2
6
I J K I J K
Puzzle of four colored block
+1 H -6 G
Heuristic1: (an object is either a block or a
table) +1 G
-5 F
C H C C
B A B A H B
Best-first search
DFS- it allows a solution to be found BSF- it does not get trapped on dead-end paths
without all competing branches having to
be expanded
It stops if there are no successor states The best available state is selected
with better value than the current state
Best-first search algorithm
OPEN=initial _ state
Until ( a goal _ state is found or OPEN=empty)
pick the best node N from OPEN
If N is a goal node
exit with a traced solution path
Remove N from OPEN to CLOSED
Generate successors of N
for each successor of N
if it has not been generated before
evaluate it, add it to OPEN and record its parent
if it has been generated before
change its parent if this new path is better than the previous one
Update the cost of getting to this node and its successors
Example-1 N OPEN CLOSED P
- A10 - -
I [2] J [1]
B C D
[3] [5] K [0]
E [4] F [6]
Example-2 N OPEN CLOSE Parent
A25 -
A 25 -
F [3+3] F [1+3]
G [0+4]
Beam search
• A heuristic approach where only the most promising ß nodes (instead
of all nodes) at each step of the search are retained for further
branching
• ß is called Beam Width
• restricted, or modified, version of either a breadth-first search or a
best-first search
• Beam search is an optimization of best-first search that reduces its
memory requirements
Beam search
OPEN = {initial state}
while OPEN is not empty do
Remove the best node (N) from OPEN
If N is the goal state, backtrace path to N (through recorded parents)
and return path
Create N's successors
Evaluate each successor, add it to OPEN, and record its parent
If |OPEN| > ß , take the best ß nodes (according to heuristic) and
remove the others from the OPEN.
Example- N OPEN
A25
Initial node
A25 B17, C15
A [25]
Goal state C15 D10,E4
A B1, C3 A B1, C3
D2 E2 D2 E2, C3
B [1] C [3]
E3 {} E2 C3
C3 F3, G0
G0 F3
D E F G
• This can happen because the beam width and an inaccurate heuristic function
may cause the algorithm to miss expanding the shortest path
• A more precise heuristic function and a larger beam width can make Beam
Search more likely to find the optimal path to the goal.
Comparison of Search Techniques
DFS BFS Best HC Beam A*
Complete N Y N N N Y
Optimal N N N N N Y
Heuristic N N Y Y Y Y
Time bm bd+1 bm bm nm bm
Space bm bd+1 bm b bn bm
b- branching factor
Goal may be at level d but tree may continue to level m, m>=d
n- number of nodes in OPEN list
Problem reduction
When a problem can be divided into a set of sub problems, where each
sub problem can be solved separately and a combination of these will
be a solution, AND-OR graphs or AND - OR trees are used for
representing the solution.
Problem reduction
• Terminal node Own a cellular phone
• If it is goal state, it is labelled as SOLVED. Else
UNSOLVED or and
B C
B C
SOLVED UNSOLVED
SOLVED UNSOLVED
A SOLVED
A UNSOLVED
B C
B C
SOLVED SOLVED
UNSOLVED UNSOLVED
AO* algorithm
Step-1
•
A [5] A [6]
[9]
B C D
[4 [4
] ]
Step-3 Step-4
Step-5
A A
A
[12] [12]
[12]
B [6] C D [10] B [6] C D [8] B [6] C D [9]
[4] [4] [4]
[10] [8] [9]
G H E F G H E F [4] G H E F [4]
[2] [3]
[5] [7] [4] [4] [5] [7]
[5] [7]
I [2] J [2]
Step-6 I [2] J [1]
A [9] Step-7
A K [0] L [0]
[12]
B [6] C D [8] [12] Step-8
B [6] C D [7] A
[4] [8]
[4]
[8] [8] [12]
G G H
H [3] E F [3] [3] E F [2] B [6] C D [7]
[5] [7] [5] [7]
[4]
[7]
J G H
I [2] [2] M [4] N [1] [3] E F [2]
I [2] J [2] M [4] N [2] [5] [7]
K [0] L [0]
K [0] L [0] O [3] P [0]
AO* algorithm
•
A [5] A [6]
[9]
B C D
[9] [9]
B C D B C D [10]
E F
[4] [4]
A
[12]
B [6] C D [10]
[4]
[10]
G H E F
[5] [7] [4] [4]
A A
[12] [12]
B [6] C D [8] B [6] C D [9]
[4] [4]
[8] [9]
G H F [4] G F [4]
[2] E H [3] E
[5] [7] [5] [7]
K [0] L [0]
A [9] A
[12] [12]
B [6] C D [8] B [6] C D [7]
[4] [4]
[8] [8]
G H G H [3] E [2]
[3] E F [3] F
[5] [7] [5] [7]
B [6] C D [7]
[4]
G H [3] E F [2]
[5] [7]
[12]
B [6] C D [7]
[4]
[7]
G H [3] E F [2]
[5] [7]
Proof /Solve :
R2 R1
R4 R5
Constraint satisfaction problem
OPEN={set of all objects that must have value assigned to them in a complete solution}
While(inconsistency is not detected or OPEN is not empty)
{
select OB from OPEN
Const_set= the set of constraints that apply to OB
if Const_set(OB)!= previous(Const_set(OB)) or First_time(OB)
OPEN= OPEN U Const_set(OB)
remove OB from OPEN
}
If union of constraints discovered above defines a solution
quit and report the solution
Else If union of constraints discovered above defines a contradiction
quit and report the failure
Else
While (a solution is not found or all possible solutions have not been eliminated)
select an object whose value is not yet determined and select a way of strengthening the constraints on that object
recursively invoke constraint satisfaction with the current set of constraints augmented by the strengthening constraint just selected
M=1
S=8 or 9
O= 0 C4 C3 C2 C1
S E ND
N=E+1
+MOR E
C2=1
N+R > 8 M O NE Y
E <> 9
S+M+C3 >9
E=2
M=1, S+C3>8
N=3 C3=0 or 1
R=8 or 9 O=0 or 1
2+D=Y or 2+D=10+Y
2+D=Y 2+D=10+Y
N+R=10+E D=8+Y
R=9 D= 8 or 9
S=8
Y=0 Y=1
M=1
S=8 or 9
C4 C3 C2 C1
O= 0 S E ND
C ROSS N=E+1 +MOR E
+ROADS C2=1
N+R > 8 M O NE Y
DANGER E <> 9
E=5
E=3 E=4
D+5=Y+10
D+4=Y D+4=Y+10 D+5=Y
D+3=Y D+3=Y+10 1+6+R=15
N+R=14 1+5+R=14 N+R=15
N+R=13 D-7=Y R=8
R=9 R=8 R=9
R=9 D=9 D-5=Y
S=8 D-6=Y S=8
S=8 R=8 D=7
D=9 or 8
Y=2
D=9
S=9
Knowledge representation
• Representations and Mapping
• Knowledge is a description of the world. It determines a system’s competence
by what it knows
• Representation is the way knowledge is encoded. It defines a system’s
performance in doing something
Reasoning programs
*
Internal
Facts
* Representation
English English
understanding Representation
English
Representation
Mapping between facts and representation Spot has a tail
Approaches to knowledge representation
• Representational adequacy
• The ability to represent all of the kinds of knowledge that are needed in that
domain
• Inferential adequacy
• The ability to manipulate the representational structures to derive new
structures corresponding to new knowledge inferred from old
• Inferential efficiency
• The ability to incorporate additional information into the knowledge structure
that can be used to focus the attention of the inference mechanisms in the
most promising direction
• Acquisitional efficiency
• The ability to acquire new knowledge using automatic methods wherever
possible rather than reliance on human intervention
Using predicate logic
• Representation of simple facts in logic
• Propositional logic
• Represent real-world facts as logical propositions written as well-formed formulas (wff’s)
in propositional logic
• Demerits
• It is too coarse to easily describe properties of objects
• It lacks the structure to express relations that exists among two or more entities
• It does not permit to make generalized statements about classes of similar objects
Facts Propositional logic
It is raining RAINING
It is sunny SUNNY
If it is raining, then it is not sunny Plato is mortal?
Socrates is a man SOCRATESMAN
Plato is a man PLATOMAN
All men are mortal MORTALMAN
Predicate logic
Predicate logic, first-order logic or quantified logic is a formal language
in which propositions are expressed in terms of predicate, variables and quantifiers.
An atomic sentence is formed from a predicate symbol followed by a parenthesized list of terms
Father(Ram, Hari)
Terms – Function(term,….)
| Constant
| Variable
Predicate Logic
• Terms represent specific objects in the world and can be constants,
variables or functions.
• Predicate Symbols refer to a particular relation among objects.
• Sentences represent facts, and are made of of terms, quantifiers and
predicate symbols.
• Functions allow us to refer to objects indirectly (via some
relationship).
• Quantifiers and variables allow us to refer to a collection of objects
without explicitly naming each object.
•
Definition
•
Quantifier
• Definitions of quantifiers:
∀x P(x) ⇔ P(a) ∧ P(b) ∧ P(c) ∧ …
∃x P(x) ⇔ P(a) ∨ P(b) ∨ P(c) ∨ …
∀x ∀y P(x, y) ⇔ ∀y ∀x P(x, y)
∃x ∃y P(x, y) ⇔ ∃y ∃x P(x, y)
~Pompeiians
Romans
Pompeian
Example-
•
•
Representing Instance and ISA relationship
•
Computable function and predicates
•
•
Proof:
Ram is a B. Tech. student of CET. His branch is IT. He took admission in the year 2017. All the B. Tech. students who
took admission at CET in the year 2016 or later studied through online mode in 2020 due to Covid pandemic.
Prove that Ram studied through online mode.
Online(RAM)
•
3
gt(2017, 2015)
Nil
Resolution
•
Algorithm- Conversion of Predicate to Clause
form
•
•
•
•
•
•
The basic of resolution
Resolution in propositional logic
Input- Set of axioms F
Proposition P
Algorithm –
Convert all the propositions to clause form
negate P and convert the result into clause form
Add ~P to F
Repeat either a contradiction is found or no progress can be made
Select two clause (parent clauses)
Remove them together
If the resolvent is empty clause
contradiction
else
Add it to set of clauses available to procedure
Examlpe-
~R
T
The unification algorithm
• L1= X L2= RAM
RAM/X
L1= IT(x) L2= CSE(SHYAM)
FAIL
L1= IT(x, y) L2=IT(RAM)
FAIL
L1=IT(x, y) L2=(RAM, z)
S=Unify(x, RAM)
S=RAM/x
S=Unify(y, z)
S=FAIL
S=Unify(x, RAM)
S=RAM/x
S=Unify(y, SHYAM)
S={RAM/x, SHYAM/x}
S=Unify(Z, HARI)
S={RAM/x, SHYAM/y, HARI/z}
Resolution in predicate logic
Ram is a student of IT branch. Some students of IT branch are brilliant. Ram is also a brilliant student.
Brilliant students IT branch either get good job or decide that they must pursue higher studies. Ram did not
Get good job.
Prove – Ram pursued higher study
~study(RAM, HS)
RAM/x
. Brilliant(RAM)
~get(RAM, JOB)
IT(RAM)
Ram is a B. Tech. student of CET. His branch is IT. He took admission in the year 2017. All the B. Tech. students
who took admission at CET in the year 2016 or later studied through online mode in 2020 due to Covid
pandemic.
Prove that Ram studied through online mode.
Proof
~Online(RAM)
RAM/x
admission(RAM, 2017)
2017/t1
~Gt(2017,2015)
1. The member of the Elm St. Bridge Club are
Joe, Sally, Bill and Ellen
2. Joe is married to Sallay
3. Bill is Ellen’s brother
4. The spouse of every married person in the
club is also in the club
5. The last meeting of the club was at Joe’s
house
Proof: The last meeting of the club was at
Sally’s house
~Meeting(CLUB, JH)
Club(JOE)
Club(SALLY)
Resolution- Demerits
• The valuable heuristic information that is contained in the original
representation of facts is lost by converting them to clause form
• People do not think in resolution
• Natural deduction
It describes a blend of techniques, used in combination to solve problems that
are not traceable by any one method alone.
One common technique is to talk about objects involved in the predicate and not
the predicate itself.
Representing knowledge using rules
• A Declarative representation is one in which • A Procedural representation is one in which the
knowledge is specified but the use to which thatcontrol information that is necessary to use the
knowledge is to be put in, is not given knowledge is considered to be embedded in the
knowledge itself.
• To use declarative representation, it must be • To use a procedural procedural representation, it
augmented with a program which specifies what must be augmented with an interpreter that
is to be knowledge and how. follows the instructions given in the knowledge.
Logic Programming
•
Differences between logic and PROLOG
representation
PROLOG representation
Quantification is provided implicitly by the way
The variables are interpreted.
(Variables- UPPER CASE letters, Constant- lowercase or
number)
Forward Rules : which encode knowledge about how to respond to certain input configurations.
Backward Rules : which encode knowledge about how to achieve particular goals.
Forward reasoning OR Backward reasoning??
• Are there more possible start states or goal states?
• Move from smaller set of states to larger set of states.
• In which direction is the branching factor (the average number of
nodes that can be reached directly from a single node) greater?
• proceed in the direction with the lower branching factor.
• Will the program be asked to justify its reasoning process to the user?
• What kind of event is going to trigger a problem-solving episode?
• If it is the arrival of a new fact , forward reasoning should be used.
• If it is a query to which response is desired, use backward reasoning.
Matching
• Indexing
• Perform a simple search through all the rules, comparing each one’s
precondition to the current state and extracting all the ones that match.
• Problems-
• It is required to use large number of rules
• It does not guarantee whether a rule’s preconditions are satisfied by a particular state
If X and Y then Z
If Ram will go, I would also go.
If X and Y or A then Z
Control knowledge
• Search control knowledge
• Knowledge about which paths are more likely to lead quickly to goal state is often called search controlled
knowledge
1. Knowledge about which states are more preferable to others.
2. Knowledge about which rule to apply in a given situation.
3. Knowledge about the order in which to pursue subgoals.
4. Knowledge about useful sequences of rules to apply.
• Search control strategy represents knowledge about knowledge and hence, it is also called as meta
knowledge
• SOAR
• general architecture for building intelligent system
• SOAR is based on set of specific, cognitively motivated hypotheses about the structure of human problem
solving
1. Long-Term Memory is stored as a set of productions (or rules).
2. Short-Term Memory (also called working memory) is a buffer and it is analogues to the state description in
problem solving.
3. All problem-solving activity takes place as a state space traversal.
4. All intermediate and final results of problem solving are remembered (or, chunked) for further reference.
Assignment
1. Question- 3, 4, 5, 6, 9 [page# 166-168, Book- Elaine Rich, Kevin
Knight, &Shivashankar B Nair, Artificial Intelligence, McGraw Hill,3rd
ed.,2009 ]
2. Question- 1 [page#192]
Symbolic reasoning under uncertainty
•
•
•
Minimalist reasoning
• Minimal model
• A model is defined to be minimal if there are no other models in which fewer
thing are true
• Closed world assumption
• Its assumptions are not always true in the world
• It is purely syntactic reasoning process
• Limitations
• It operates on individual predicates without considering the interaction among the
predicates
• It assumes that all predicates have all of their instances listed
A(RAM) V B(RAM) Single(RAM) ~Married(RAM)
~A(RAM) Single(HARI) ~Married(HARI)
~B(RAM) SHYAM? SHYAM?
• Circumscription
• The effect of new axioms is to force a minimal interpretation on a selected portion of the knowledge
base
A(RAM) V B(RAM)
Circumscribe only A
this assertation describes those models in which A is true of no one and B is true of at least RAM
Circumscribe only B
this assertation describes those models in which B is true of no one and A is true of at least RAM
Circumscribe A and B together
It describes those models in which
A is true of only RAM and B is true of no one
or
B is true of only RAM and A is true of no one
Implementation issue
• How to derive exactly those nonmonotonic conclusions that are
relevant to solving the problem at hand
• How to update knowledge incrementally as problem solving
progresses
• More than one interpretation of the known facts is licensed by
available inference rules.
• These theories are not computationally effective. None of them are
decidable. Some are semi decidable, but only in their propositional
forms. And none is efficient
Semantic nets Has-part
• Represent knowledge as a graph College Hostel
• Nodes correspond to facts or concepts
• Arcs correspond to relations or associations instance
HARI
Ram is taller than Hari Ram is 6 feet tall and taller and that
he is taller than Hari
RAM HARI
height height
Greater-than
H1 H2
6
Partitioned semantics nets
• Partition the semantic net into
Dogs Bite Mail-carrier
hierarchical set of spaces each
of which corresponds to the isa isa isa
Town-Dogs
isa
isa
form isa isa S1
assailant victim
g d b m
Frames
• A collection of attributes (called slots) and associated values that
describe the entity in the world.
Student
isa: Person
Cardinality: 3000
*Work: Study
Conceptual Dependency
•
Set of primitive acts
with a spoon
Game playing
• Minimax search procedure
• A depth-first, depth-limited search procedure
• Plausible-move generator to generate the set of possible successor positions
• Apply static evaluation function to those positions and choose the best one
• Goal is to maximize the value of static evaluation function of the next board
position
• Auxiliary procedures
• MOVEGEN(position, player) – the plausible move-generator which returns a list of nodes
representing the moves that can be made by player in position
• STATIC((position, player)- the static evaluation function which returns a number
representing the goodness of position from the standpoint of
• DEEP-ENOUGH(position, depth)- it will ignore its position parameter and simply return
TRUE if its depth parameter exceeds constant cut-off values
Algorithm
MINIMAX(position, depth player)
if DEEP-ENOUGH(position, depth)
return Value=STATIC(position, player); path=nil
else
SUCC= MOVEGEN(position, player)
if SUCC=empty
return Value=STATIC(position, player); path=nil
else
BEST-SCORE= STATIC(position, player)
for each element S of SUCC
RESULT-SUCC=MINIMAX(SUCC, depth+1, OPPOSITE(player)
NEW-VALUE=VALUE(RESULT-SUCC)
if NEW-VALUE> BEST-SCORE
BEST-SCORE= NEW-VALUE
BEST-PATH=PATH(RESULT-SUCC)
return
VALUE=BEST-SCORE, PATH=BEST-PATH
Minimax –Example
Max 3 6 The computer can
obtain 6 by
choosing the right
6 hand edge from the
Min 5 3 first node.
Max 1 3 6 0 7
5
5 2 1 3 6 2 0 7
I J M N MINIMZE
(5) (7) (8)
K L
(0) (7)
Iterative deepening search d=0
Iterative deepening search d=1
Iterative deepening search d=2
Iterative Deepening Search d=3
Iterative deepening
Depth-First Iterative Deepening
Iterative_deepening()
Depth=1
Repeat while(true)
Path=DFS(Depth)
If Path= Solution_path
return Solution_path
Else
Depth=Depth+1
• Constraint posting
• To build up a plan incrementally hypothesizing operators
• Partial ordering between operators
• Binding of variables within operators
• Operations
• Step addition
• Promotion
• Declobbering- insert S3 between S1 and S2 such that S2 reasserts some preconditions
that was negated (clobbered) by S1
• Simple establishment
• Separation
TWEAK -algorithm
CLEAR(B) CLEAR(C)
*HOLDING(A) *HOLDING(B)
_____________ _____________
STACK(A,B) STACK(B, C)
_____________ _____________
ARMEMPTY ARMEMPTY
ON(A,B) ON(B, C)
~CLEAR(B) ~CLEAR(C)
~HOLDING(A) ~HOLDING(B)
TWEAK - algorithm
*CLEAR(A) *CLEAR(B)
ONTABLE(A) ONTABLE(B)
*ARMEMPTY *ARMEMPTY
_____________ _____________
PICKUP(A) PICKUP(B)
_____________ _____________
~ONTABLE(A) ~ONTABLE(A)
~ARMEMPTY ~ARMEMPTY
HOLDING(A) HOLDING(B)
TWEAK - algorithm
*CLEAR(A) *ON(X, A)
ONTABLE(A) *CLEAR(x)
*ARMEMPTY *ARMEMPTY
_____________ _____________
PICKUP(A) UNSTACK(x, A)
_____________ _____________
~ONTABLE(A) ~ARMEMPTY
~ARMEMPTY CLEAR(A)
HOLDING(A) HOLDING(A)
~ON(x, A)
TWEAK - algorithm
Declobbering
HOLDING(C)
___________
PUTDOWN(C)
___________
~HOLDING( C)
ONTABLE(x) Solution
ARMEMPTY UNSTACK( C, A)
PUTDOWN( C)
PICKUP(B)
STACK(B, C)
PICKUP(A)
STACK(A, B)
Necessary truth criterion
A proposition P is necessarily true in a state S if and only if the following two conditions are met:
(1) there is a state T equal or necessarily before state S in which P is necessarily asserted;
(2) for every step C possibly to be executed before S and for every proposition Q codesignating with P
and C denies, there is a step W necessarily between C and S which asserts R, a proposition such that R and
codesignates whenever P and Q codesignates.