CSCI 360 Introduc1on to Ar1ficial Intelligence

CSCI360
Introduc/ontoAr/ficialIntelligence
Week2:ProblemSolvingandOp/miza/on
Instructor:Wei-MinShen
Week4.1
StatusCheckandReview
•  Statuscheck
–  Howisyourproject?
–  Haveyoudoneyourhomework?
–  WhythereisnodiscussiononPiazza?
–  WhythereisnooneshownupforTA?
•  Reviewoflastlecture
•  Whatistoday’slecture?
–  Whataretheexamples?
ConstraintSa/sfac/on(review)
•  Examples:MapColoring,canyouthinkofanother?
•  Howtoformalizetheproblem?
–  Search:variables,domains,constrainedrela/ons
–  Dothesubsetindependent?
–  Doitcontaincycles?
•  Howtosolvetheproblem?(Randomlyor“Best”-First)
–  GlobalBacktracking
•  Ordervariables:themostconstrainedvariablesfirst
•  Sa/sfyoneata/me,ifstuck,backtracking
–  LocalSearch:heuris/c,findthemin-conflictssolu/onlocally
–  Centralizedvs.Distributed(DCOP)
•  HW:Magicsquare,defineitandsolveit
ThisWeek’sLecture(1):Logics
•  Therealworldanditsrepresenta/onbylogics
•  Theworldyoucreatedinsimula/on(e.g.wumpus)
–  Syntax(onpaper,α,β)
–  Seman/cs(inworld/modelM),”sa/sfy”
•  Proposi/onallogic:truthtablefor
–  Theoremproving,inferencerule,resolu/on,hornclause,
forward/backwardchaining,
–  Proposi/onalagent:currentstate,goalstate,localsearch,
globalsearch
•  HW:PLrulesforWumpusorTic-Tac-Toe
ThisWeek’sLecture(2):
First-OrderLogic
•  Syntaxandseman/cs
–  Addvariables(predicates)andquan/fiers
•  Knowledgeengineering
–  Captureandrepresenthumanknowledge,e.g.,usingFOL
•  InferenceinFOL
–  ModusPonenswithvariables
•  Unifica/on:findingthevaluesforvariables
–  1.Forwardchaining
•  E.g.produc/onsystems,ACT,SOAR
–  2.Backwardchaining
•  E.g.,Prolog
–  3.Resolu/on
•  ConverttoCNF,elimina/ngP,-P.
•  HW:FOLrulesforWumpusorTic-Tac-Toe
Today’sLecture
• 
• 
• 
• 
LogicRepresenta/onoftheworld
Proposi/onallogic
First-orderlogic
FOLInferences
KeyConceptsofLogic
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
Syntax
Semantics
Entailment
Inference
Soundness
Completeness
Inference Rules
Normal Forms
Truth Tables
Reasoning
7
KnowledgeandReasoning
• 
• 
• 
• 
• 
• 
Knowledgerepresenta/on
Logicandrepresenta/on
Proposi/onal(Boolean)logic
Normalforms
Inferenceinproposi/onallogic
Wumpusworldexample
8
SymbolsvstheRealWorld
Symbol System
World
Objects:
+BLOCKA+
+BLOCKB+
+BLOCKC+
……
Relations:
P1:(IS_ON +BLOCKA+ +BLOCKB+)
P2:((IS_RED +BLOCKA+)
……
“Knowledge Base”
“Robot Brain”
CS 561, Sessions 10-11
9
Knowledge-BasedAgent
Domain independent algorithms
ASK
Inference engine
TELL
Knowledge Base
Domain specific content
•  Agentthatusespriororacquired
knowledgetoachieveitsgoals
– 
– 
Canmakemoreefficientdecisions
Canmakeinformeddecisions
•  KnowledgeBase(KB):containsasetof
representa/onsoffactsaboutthe
Agent’senvironment
•  Eachrepresenta/oniscalledasentence
•  Usesomeknowledgerepresenta5on
language,toTELLitwhattoknowe.g.,
(temperature72F)
•  ASKagenttoquerywhattodo
•  Agentcanuseinferencetodeducenew
factsfromTELLedfacts
10
Genericknowledge-basedagent
1. 
TELL KB what was perceived
Uses a KRL to insert new sentences, representations of facts, into KB
2. 
ASK KB what to do.
Uses logical reasoning to examine actions and select best.
11
Wumpusworldexample
12
Wumpusworldcharacteriza/on
•  Determinis/c?
•  Accessible?
•  Sta/c?
•  Discrete?
•  Episodic?
13
Wumpusworldcharacteriza/on
•  Determinis/c? Yes–outcomeexactlyspecified.
•  Accessible?
No–onlylocalpercep/on.
•  Sta/c? Yes–Wumpusandpitsdonotmove.
•  Discrete?
Yes
•  Episodic?
(Yes)–becausesta/c.
14
ExampleSolu/onSteps
No perception à 1,2 and 2,1 OK
B in 2,1 à 2,2 or 3,1 P?
Move to 2,1
1,1 V à no P in 1,1
Move to 1,2 (only option)
15
ExampleSolu/onSteps
S in 1,2 and No S when in 2,1 à 1,3 or 1,2 has W
1,2 OK à 1,3 W
No B in 1,2 à 2,2 OK & 3,1 P
16
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
17
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
18
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
19
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
20
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
21
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
22
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
23
ExploringaWumpusworld
A= Agent
B= Breeze
S= Smell
P= Pit
W= Wumpus
OK = Safe
V = Visited
G = Glitter
CS 561, Sessions 10-11
24
OtherTightSpots
CS 561, Sessions 10-11
25
LogicinGeneral
26
Typesoflogic
27
TheSeman/cWall
Physical Symbol System
World
+BLOCKA+
+BLOCKB+
+BLOCKC+
P1:(IS_ON +BLOCKA+ +BLOCKB+)
P2:((IS_RED +BLOCKA+)
CS 561, Sessions 10-11
28
TruthdependsonInterpreta/on
Representa/on1
A
World
B
ON(A,B) T
ON(B,A) F
Representation 2
ON(A,B) F
A
ON(B,A) T
B
CS 561, Sessions 10-11
29
Entailment
30
LogicasaRepresenta/onofaWorld
Representation: Sentences
entails
Sentence
Refers to
(Semantics)
World
Facts
follows
Facts
31
Models(“PossibleWorlds”)
32
Inference
33
“Entail”=\=“Inference”
KB inference α: derived by a procedure
On Paper:
complete
sound
KB entails α
Model of KB is a subset of Model of α
Model of Symbols: M(KB), M(α), …
“possible worlds”?
In the Real World:
34
BasicSymbols
•  Expressionsonlyevaluatetoeither“true”or“false”
• 
• 
• 
• 
• 
• 
P ¬P PVQ
P^Q
P=>Q
PóQ
“Pistrue”
“Pisfalse”
nega/on
“eitherPistrueorQistrueorboth” disjunc/on
“bothPandQaretrue”
conjunc/on
“ifPistrue,thenQistrue”
implica/on
“PandQareeitherbothtrueorbothfalse”equivalence
35
Proposi/onalLogic:Syntax
36
Proposi/onallogic:Seman/cs
37
TruthTables
•  Truthvalue:whetherastatementistrueorfalse.
•  Truthtable:completelistoftruthvaluesforastatement
givenallpossiblevaluesoftheindividualatomic
expressions.
Example:
P
T
T
F
F
Q
T
F
T
F
PVQ
T
T
T
F
38
TruthTablesforBasicConnec/ves
P Q ¬P¬QPVQP^QP=>Q PóQ
T T F
F
T
T
T
T
T F F
T
T
F
F
F
FT T
F
T
F
T
F
F F T
T
F
F
T
T
39
Proposi/onalLogic:
BasicManipula/onRules
•  ¬(¬A)=A •  ¬(A^B)=(¬A)V(¬B)
•  ¬(AVB)=(¬A)^(¬B)
• 
• 
• 
• 
• 
• 
• 
Doublenega/on
Negated“and”
Negated“or”
A^(BVC)=(A^B)V(A^C)
Distribu/vityof^onV
AV(B^C)=(AVB)^(AVC) Distribu/vityofVon^
A=>B=(¬A)VB bydefini/on
¬(A=>B)=A^(¬B)
usingnegatedor
AóB=(A=>B)^(B=>A)
bydefini/on
¬(AóB)=(A^(¬B))V(B^(¬A)) usingnegatedand&or
…
40
Proposi/onalInference:
Enumera/onMethod
true
41
Enumera/on:Solu/on
KB |= alpha?
42
Proposi/onalInference:NormalForms
“product of sums of
simple variables or
negated simple variables”
“sum of products of
simple variables or
negated simple variables”
CS 561, Sessions 10-11
43
DerivingExpressionsfromFunc/ons
•  Givenabooleanfunc/onintruthtableform,findaproposi/onal
logicexpressionforitthatusesonlyV,^and¬
•  Idea:Easilydoitbydisjoiningthe“T”rowsofthetruthtable.
Example:XORfunc/on
P Q RESULT
T T F
T F T
P^(¬Q)
F T T
(¬P)^Q
F F F
RESULT=(P^(¬Q))V((¬P)^Q)
44
AMoreFormalApproach
•  HowToconstructalogicalexpressionindisjunc/venormalform
fromatruthtable?
-  Builda“minterm”foreachrowofthetable,where:
-ForeachvariablewhosevalueisTinthatrow,include
thevariableintheminterm
-ForeachvariablewhosevalueisFinthatrow,include
thenega/onofthevariableintheminterm
-Linkvariablesinmintermbyconjunc/ons
-  Theexpressionconsistsofthedisjunc/onofallminterms
45
Example:AdderwithCarry
Takes3variablesin:x,yandci(carry-in);yields2results:sum(s)andcarry-out(co)
Weuseothernota/ons,hereweassumeT=1,F=0,V=OR,^=AND,¬=NOT.
co is:
s is:
46
Tautologies
•  Logicalexpressionsthatarealwaystrue.Canbesimplified.
Examples:
T
TVA
AV(¬A)
¬(A^(¬A))
AóA
((PVQ)óP)V(¬P^Q)
(PóQ)=>(P=>Q)
47
ValidityandSa/sfiability
B
Theorem
48
LogicProofMethods
49
InferenceRules
50
InferenceRules(cont.)
51
WumpusWorld:example
•  Facts:Perceptsinject(TELL)factsintotheKB
–  [Stenchat1,1and2,1]àS(1,1);S(2,1)
•  Rules:ifsquarehasnostenchthenneitherthesquareoradjacent
squarecontaintheWumpus
–  R1:~S(1,1)è~W(1,1)^~W(1,2)^~W(2,1)
–  R2:~S(2,1)è~W(1,1)^~W(2,1)^~W(2,2)^~W(3,1)
–  …
•  Inference:
–  KBcontains~S(1,1)thenusingModusPonenswecaninfer
~W(1,1)^~W(1,2)^~W(2,1)
–  UsingAnd-Elimina/onwecanget:~W(1,1);~W(1,2);~W(2,1)
–  …
52
Limita/onsofProposi/onalLogic
1.Ithasverylimitedexpressiveness(novariables)
•  Eachrulehastoberepresentedforeachsitua/on:
e.g.,“don’tgoforwardifthewumpusisinfrontofyou”would
takes64rules
2.Itcannotkeeptrackofchanges
•  Ifoneneedstotrackchanges,e.g.,wheretheagenthasbeen
beforethenweneeda/med-versionofeachrule.Totrack100
stepswe’llthenneed6400rulesforthepreviousexample.
Itshardtowriteandmaintainsuchahugerule-base
Inferencebecomesintractable
53
Summary
54
LogicandReasoning
•  Knowledge Base (KB): contains a set of sentences expressed using a
knowledge representation language
•  TELL: operator to add a sentence to the KB
•  ASK: to query the KB
•  Logics are KRLs where conclusions can be drawn
•  Syntax
•  Semantics
•  Entailment: KB |= a iff a is true in all worlds where KB is true
•  Inference: KB |–i a = sentence a can be derived from KB using
procedure i
•  Sound: whenever KB |–i a, then KB |= a is true
•  Complete: whenever KB |= a, then KB |–i a
55
Proposi/onalLogicSyntax
56
Proposi/onalLogicSeman/cs
57
Proposi/onalLogicInferenceRules
CS 561, Session 12-13
58