1.09k likes | 1.35k Views
Logical Agents. Knowledge bases. Knowledge base = set of sentences in a form a l language Decl a r ati v e approach to building an a gent (or other system): T ELL it what it needs to know Then it can A S K itself what to d o — answers should fo l low from the KB
E N D
Knowledge bases • Knowledgebase= setofsentencesina formallanguage • Declarativeapproach to buildingan agent (or other system): TELLitwhat itneedsto know • Then itcan ASKitselfwhat to do—answersshouldfollowfrom theKB • Agents canbeviewedat theknowledgelevel i.e.,what they know,regardless ofhowimplemented • Or at theimplementationlevel i.e., data structures inKBand algorithmsthatmanipulate them
Knowledge-Based Agent • Agent thatuses priororacquired • knowledge to achieve itsgoals • Canmake moreefficientdecisions • Canmake informed decisions • KnowledgeBase (KB): contains a setof representationsof factsabout the Agent’s environment • Each representation iscalleda • sentence • Usesome knowledgerepresentation language,to TELLitwhat to know e.g., (temperature 72F) • ASKagent to querywhatto do • Agent can use inferenceto deducenew facts fromTELLedfacts Domain independentalgorithms ASK Inferenceengine KnowledgeBase TELL Domainspecificcontent
A simple knowledge-based agent • Theagent mustbe able to: • Represent states,actions,etc. • Incorporatenewpercepts • Updateinternalrepresentationsoftheworld • Deducehiddenproperties oftheworld • Deduceappropriate actions
Wumpus World Example • Performance measure • ◦ gold+1000, death-1000 • -1perstep, -10 forusingthe arrow • Environment • Squaresadjacentto wumpusare smelly • Squaresadjacenttopitare breezy • Glitteriff goldisinthe samesquare • Shootingkills wumpusifyou are facing it • Shootingusesup the only arrow • Grabbingpicks upgoldif insame square • Releasingdropsthe goldinsame square • Actuators • Leftturn,Rightturn,Forward, Grab, Release,Shoot • Sensors • Breeze,Glitter,Smell
Wumpus world characterization • Observable? • Deterministic? • Episodic? • Static? • Discrete? • Single-agent?
Wumpus world characterization • Observable?No—only local perception • Deterministic?Yes—outcomes exactly specified • Episodic?No—sequential at the level of actions • Static?Yes—Wumpus and pits do not move • Discrete?Yes • Single-agent?Yes—Wumpus is a feature
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010 10
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Exploring a wumpus world A=Agent B= Breeze S= Smell P= Pit W= Wumpus OK= Safe V = Visited G= Glitter CS561-Lecture09-10-Macskassy-Fall 2010
Other tight spots Breeze in(1,2) and (2,1) no safeactions Assuming pitsuniformly distributed, (2,2) has pitw/ prob 0.86,vs. 0.31 Smellin(1,1) cannotmove Can use a strategy of coercion: shootstraightahead wumpuswas theredeadsafe wumpuswasn't theresafe CS561-Lecture09-10-Macskassy-Fall 2010
Example Solution S in 1,21,3or2,2has W No S in 2,12,2OK 2,2OK1,3W NoB in 1,2&B in2,13,1P CS561-Lecture09-10-Macskassy-Fall 2010
Another example solution No perception1,2and2,1 OK Moveto2,1 Bin 2,12,2or3,1P? 1,1V no P in1,2 Moveto1,2(only option) CS561-Lecture09-10-Macskassy-Fall 2010
Logic in general • Logicsare formal languagesfor representinginformation suchthat conclusions canbedrawn • Syntaxdefinesthe sentencesinthe language • Semanticsdefinethe“meaning” ofsentences; • i.e., define truthof a sentenceinaworld • E.g., thelanguageof arithmetic • x+ 2≥ yisasentence; x2+y> isnot a sentence • x+2≥yistrue iffthenumberx+2isno lessthan thenumber y • x+2≥yistrue inaworld where x=7; y=1 • x+ 2 ≥ yis falseina worldwherex=0;y=6
Types of logic • Logics arecharacterized by what they commit to as “primitives” • Ontological commitment: what exists—facts?objects?time?beliefs? • Epistemologicalcommitment: whatstatesof knowledge?
The Semantic Wall PhysicalSymbol System World +BLOCKA+ +BLOCKB+ +BLOCKC+ P1:(IS_ON+BLOCKA+ +BLOCKB+) P2:((IS_RED+BLOCKA+)
Truth depends on Interpretation Representation1 World A B ON(A,B)T ON(B,A)F ON(A,B) F A ON(B,A) T B
Entailment • Entailmentmeansthatonethingfollowsfromanother: • KB╞α • KnowledgebaseKBentailssentenceα • ifandonlyif(iff) • αistrue inall worldswhere KBis true • E.g.,theKBcontaining“the Giantswon”and“the Reds won” entails“Either theGiantswonortheReds won” • E.g.,x+y=4entails4=x +y • Entailmentisarelationshipbetween sentences(i.e.,syntax) thatis basedonsemantics • Note:brainsprocesssyntax(ofsome sort) • Entailment isdifferentthaninference!
Logic as a representation of the World entails Representation: Sentences Sentence Refersto (Semantics) follows Fact World Facts
Models • Logicianstypicallythinkinterms ofmodels,whichare formally structured worlds withrespectto whichtruth canbeevaluated • We saymisa modelof a sentenceαifαistrue inm • M(α)isthesetof allmodelsofα • ThenKB╞αifand only ifM(KB)µM(α) • E.g. KB= Giants wonand Reds won • α = Giantswon
Entailment in the wumpusworld • Situationafterdetectingnothingin[1,1], movingright, breezein[2,1] • Considerpossiblemodelsfor ?s assuming only pits • 3 Boolean choices8possiblemodels
Wumpus Models KB=wumpus-worldrules +observations
Wumpus Models KB=wumpus-worldrules +observations α1 = “[1,2] issafe",KB╞α 1,proved by modelchecking
Wumpus Models KB=wumpus-worldrules +observations α2 = “[2,2] issafe",KB╞\α 2
Inference • KBα=sentenceαcanbederivedfrom KB byprocedurei • Consequencesof KBare a haystack;αisaneedle. • Entailment=needleinhaystack;inference =finding it • Soundness:iissound if • wheneverKBα,itis alsotrue thatKB╞α • Completeness:iiscompleteif • wheneverKB╞α,itisalsotrue thatKBα • Preview:wewilldefinea logic (first-orderlogic)whichis expressive enough to say almost anything ofinterest, and for which there existsa soundand completeinferenceprocedure. • That is,the procedurewillansweranyquestionwhoseanswer follows from what isknownbytheKB.
Basic symbols • Expressionsonlyevaluate to either“true”or “false.” • PQ “P and Q are either bothtrue orboth false”equivalence
Propositional logic: Syntax • Propositionallogicisthesimplestlogic—illustratesbasicideasThepropositionsymbolsP1,P2 etcaresentences • IfSisasentence,¬Sisasentence(negation) • IfS1 andS2 aresentences,S1∧S2 isasentence(conjunction) • IfS1 andS2 aresentences,S1∨S2 isasentence(disjunction) • IfS1 andS2 aresentences,S1 ⇒ S2 isasentence(implication) • IfS1 andS2 aresentences,S1 ⇔ S2 isasentence(biconditional)
Precedence • Use parentheses • A B C is not allowed
Wumpus world sentences • LetPi;j be true if thereisa pitin[i;j]. • LetBi;j betrue ifthereisa breeze in[i;j]. • P1;1B1;1B2;1 • “Pitscause breezes in adjacentsquares”
Wumpus world sentences • LetPi;j be true if thereisa pitin[i;j]. • LetBi;j betrue ifthereisa breeze in[i;j]. • P1;1B1;1B2;1 • “Pitscause breezes in adjacentsquares” • B1;1 (P1,2 VP2;1) • B2;1 (P1,1 VP2;2 VP311) • “A squareis breezy if andonly if thereis anadjacent pit”
Truth tables for inference Enumeraterows(differentassignmentsto symbols), ifKBistrue inrow, check thatαistoo
Propositional inference: enumeration method Let α=AVBandKB= (AVC)^(BV¬C) Is itthecase thatKB╞α? Check allpossiblemodels—αmust betrue whereverKBistrue
Enumeration: Solution Let α=AVBandKB= (AVC)^(BV¬C) Is itthecase thatKB╞α? Check allpossiblemodels—αmust betrue whereverKBistrue
Inference by enumeration • Depth-firstenumerationofallmodelsissound and complete • O(2n)for nsymbols;problemisco-NP-complete
Propositional inference: normal forms “productofsumsof simple variablesor negated simplevariables” “sumof productsof simple variablesor negatedsimplevariables”
Validity and satisfiability • A sentenceis validifit istrue inallmodels, • e.g., True,AV¬ A, AA,(A^(AB)) B • Validityisconnected toinference viatheDeductionTheorem: • KB╞αifandonlyif(KBα) isvalid • A sentenceis satisfiableifit istrue insomemodel e.g., AVB,C • A sentenceis unsatisfiableifitistrue innomodelse.g., A^ ¬ A • Satisfiabilityisconnectedto inferenceviathe following: • KB╞αif and only if (KB^: ¬ α)isunsatisfiable • i.e., prove αbyreductioadabsurdum
Satisfiability • Related to constraint satisfaction • Given a sentence S, try to find an interpretation I where S is true • Analogous to finding an assignment of values to variables such that the constraint hold • Example problem: scheduling nurses in a hospital • Propositional variables represent for example that Nurse1 is working on Tuesday at 2 • Constraints on the schedule are represented using logical expressions over the variables • Brute force method: enumerate all interpretations and check
Example problem • Imagine that we knew that: • If today is sunny, then Amir will be happy (S H) • If Amir is happy, then the lecture will be good (H G) • Today is Sunny (S) • Should we conclude that today the lecture will be good
Checking Interpretations • Start by figuring out what set of interpretations make our original sentences true. • Then, if G is true in all those interpretations, it must be OK to conclude it from the sentences we started out with (our knowledge base). • In a universe with only three variables, there are 8 possible interpretations in total.