Representation and Search

advertisement
Artificial Intelligence
as
Representation and Search
Representation
• The purpose of representation is to abstract out the
problem features which are non-essential to
solving the problem and to capture those features
which are essential.
• An example is “blocks worlds” where the problem
is to construct a sequence of actions for a robot
arm to transform the initial arrangement of blocks
into a goal arrangement.
– Essential Features
• Which blocks are on top of which blocks
• Which blocks are clear
• Which blocks are on table
Blocks World Representations
• Predicate Calculus
– Predicates : Clear(a), Ontable(a), On(b,a)
– Rules : X ¬Y on(Y,X)  Clear(X)
• Arrays or Strings
– Stack : ABC
• State Space Graph
– Graph with 3 blocks
– Start and Goal states
Natural Language Understanding
Semantic Net Representation
vertebrate
isa
feathers
small
bird
covering
flies
property
isa
bluebird
size
color
blue
Tic Tac Toe Representation
X
O
O
R1
R2
R3
C1
C2
C3
D1
D2
O
O
X
O
O
X
X
O
OO
XO
X
O
X
O
Blocks World Search
Find path from Start State to Goal State
Backtrack Search for BW3 solution
Private Function extend() As Boolean
Dim ex As Boolean = False
Dim children As New Stack(Of String)
If ns.Count = 0 Then
lbHistory.Items.Add("Goal unreachable ")
Return ex
Exit Function
ElseIf nextV = CInt(goal) Then
lbHistory.Items.Add("Path to goal: " & showS(s))
Return ex
Exit Function
End If
ex = True
children = NextChildren()
If children.Count = 0 Then
'backtrack
While s.Count > 0 And nextV = s.Peek
de.Push(nextV)
labels(CInt(nextV)) = "D"
s.Pop() 'remove first element of s
ns.Pop() 'remove first element of ns
nextV = ns.Peek
End While
s.Push(nextV)
labels(nextV) = "S"
Else
'next level
Dim nc As Stack(Of String) = NextChildren()
For Each state In nc
'save children on ns
ns.Push(state)
Next
nextV = ns.Pop
'get next child
s.Push(nextV)
labels(nextV) = "S"
End If
Return ex
End Function
Backtrack Search for BW3 solution
Semantic Net Search
find attributes of specified object – CLIPS implementation
Semantic Net Search
find attributes of specified object – CLIPS implementation
BFS Semantic Net
•
•
(deftemplate concept (slot cid) (slot name) (slot depth))
(deftemplate link (slot start) (slot end) (slot linkName))
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
(deffacts snet
(concept (cid 1) (name bluebird) (depth -1))
(concept (cid 2) (name small) (depth -1))
(concept (cid 3) (name blue) (depth -1))
(concept (cid 4) (name feathers) (depth -1))
(concept (cid 5) (name bird) (depth -1))
(concept (cid 6) (name flies) (depth -1))
(concept (cid 7) (name vertebrate) (depth -1))
(link (start 1) (end 2) (linkName size))
(link (start 1) (end 3) (linkName color))
(link (start 1) (end 5) (linkName isa))
(link (start 5) (end 4) (linkName covering))
(link (start 5) (end 6) (linkName property))
(link (start 5) (end 7) (linkName isa))
)
•
•
•
•
•
(defrule initsearch
(concept (cid 1) (name ?n) (depth -1))
=>
(assert (concept (cid 1) (name ?n) (depth 0)) )
)
•
•
•
•
•
•
•
•
•
•
(defrule search
(concept (cid ?s) (name ?n) (depth ?d))
(test (> ?d -1))
(concept (cid ?e) (name ?m) (depth -1))
(link (start ?s) (end ?e) (linkName ?x))
=>
(bind ?dep (+ ?d 1))
(assert (concept (cid ?e) (name ?m) (depth ?dep)))
(printout t "Name : " ?m " , relation: " ?x " , depth : " ?dep crlf)
)
BFS Semantic Net
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
CLIPS (V6.20 03/31/02)
CLIPS> (load SemanticNet2.txt)
Defining deftemplate: concept
Defining deftemplate: link
Defining deffacts: snet
Defining defrule: initsearch +j
Defining defrule: search +j+j+j
TRUE
CLIPS> (reset)
CLIPS> (run)
Name : bird , relation: isa , depth : 1
Name : vertebrate , relation: isa , depth : 2
Name : flies , relation: property , depth : 2
Name : feathers , relation: covering , depth : 2
Name : blue , relation: color , depth : 1
Name : small , relation: size , depth : 1
CLIPS>
Tic Tac Toe Search
Tic Tac Toe Search
If Start then
Mark Center
Else
Find Row, Column or Diagonal which is a win
for Player and Mark
Else
Find Row, Column or Diagonal which is a win
for opponent and Mark
Else
Construct a Fork if possible .. Etc.
Download