Larry Holder School of EECS Washington State University
1 Artificial Intelligence
Larry Holder School of EECS Washington State University Artificial - - PowerPoint PPT Presentation
Larry Holder School of EECS Washington State University Artificial Intelligence 1 } Knowledge base T ELL agent about the environment } Knowledge representation First-order logic Many others } Reasoning via inference A SK agent
Larry Holder School of EECS Washington State University
1 Artificial Intelligence
} Knowledge base
} Knowledge representation
} Reasoning via inference
knowledge
Artificial Intelligence 2
Artificial Intelligence 3
function KB-AGENT (percept) returns an action persistent: KB, a knowledge base t, a counter, initially 0, indicating time TELL (KB, MAKE-PERCEPT-SENTENCE (percept, t)) action ← ASK (KB, MAKE-ACTION-QUERY (t)) TELL (KB, MAKE-ACTION-SENTENCE (action, t)) t ← t + 1 return action
} Goals
unvisited locations, then move to [1,1] and Climb
Artificial Intelligence 4
Artificial Intelligence 5
2 3 3 1 2 4 1 4
Artificial Intelligence 6
2 3 3 1 2 4 1 4
Artificial Intelligence 7
2 3 3 1 2 4 1 4
} Percept1 = [None,None,None,None,None]
} Action = GoForward } Percept2 = [None,Breeze,None,None,None] } Either [2,2] or [3,1] or both has a pit } Execute TurnLeft, TurnLeft, GoForward, TurnRight, GoForward
Artificial Intelligence 8
}
Percept7 = [Stench,None,None,None,None]
}
Could Shoot, but <TurnRight,GoForward> to [2,2]
}
Percept9 = [None,None,None,None,None]
}
<TurnLeft,GoForward> to [2,3]
}
Percept11 = [Stench,Breeze,Glitter,None,None]
}
Grab gold, head home, and Climb (score: 1000 – 17 = 983)
Artificial Intelligence 9
OK OK
} A knowledge base (KB) consists of
} Syntax specifies a well-formed sentence } Semantics specifies the meaning of a
} Example
Artificial Intelligence 10
} Logical inference is the process of inferring
} Inference should be sound or truth-
} Inference should be complete
Artificial Intelligence 11
} Pro
Propositional logic assumes world consists of facts that are either true, false or unknown
} Fi
First-or
logic ic assumes world consists of facts, objects and relations that are either true, false or unknown
} Tem
Temporal logic = FOL where facts hold at particular times
} Hi
Higher-or
logic ic assumes world includes first-order relations as objects
} Pro
Probabilistic logic = propositional logic with a degree of belief for each fact
Artificial Intelligence 12
} Or, First-Order Predicate Calculus (FOPC) } Borrowing from elements of natural language
Properties: adjectives (e.g., smelly) Functions: map input to single output (e.g., location(wumpus))
Artificial Intelligence 13
Artificial Intelligence 14
Sentence → AtomicSentence | ComplexSentence AtomicSentence → Predicate | Predicate (Term,...) | Term = Term ComplexSentence → (Sentence) | [Sentence] | ¬ Sentence | Sentence ∧ Sentence | Sentence ∨ Sentence | Sentence ⇒ Sentence | Sentence ⇔ Sentence | Quantifier Variable,... Sentence Term → Function (Term,...) | Constant | Variable Quantifier → " | $ Constant → A | B | Wumpus | 1 | 2 | ... Variable → a | x | s | ... Predicate → True | False | Adjacent | At | Alive | ... Function → Location | RightOf | ... Operator Precedence: ¬, =, ∧, ∨, ⇒, ⇔
} Not (¬) is a negation } Literal is either an atomic sentence (positive
literal) or a negated atomic sentence (negative literal)
} And (∧) is a conjunction; its parts are conjuncts } Or (∨) is a disjunction; its parts are disjuncts } Implies (⇒) is an implication
} If and only if (⇔) is a biconditional
Artificial Intelligence 15
} How to determine the truth value (true or
} True is always true } False is always false } Truth values of every other sentence must be
Artificial Intelligence 16
} Semantics for complex sentences
Artificial Intelligence 17
P Q ¬P P ∧ Q P ∨ Q P ⇒ Q P ⇔ Q false false true false false true true false true true false true true false true false false false true false false true true false true true true true Truth Table
} Constant symbols stand for objects } Predicate symbols stand for relations } Function symbols stand for functions } R&N convention: Above symbols begin with
} Arity is the number of arguments to a
Artificial Intelligence 18
} Terms represent objects with constants,
} Note: Functions do not return an object, but
t) ∧ At(Agent, loc, t) ⇒ At(Agent, RightOf(loc), t+1)
} R&N convention: variables begin with
Artificial Intelligence 19
} Express properties of collections of objects } Universal quantification (")
quantified variables
} "x P(x) ≡ P(A) ∧ P(B) ∧ P(Wumpus) ∧ ...
Artificial Intelligence 20
} Existential quantification ($)
by quantified variables, for which a statement is true
} $x P(x) ≡ P(A) ∨ P(B) ∨ P(Wumpus) ∨ ...
Artificial Intelligence 21
} Nested quantifiers } "x "y same as "y "x same as "x,y } $x $y same as $y $x same as $x,y } $x "y same as "y $x ?
Artificial Intelligence 22
} Negation and quantifiers } $x P(x) ≡ ¬"x ¬P(x)
} "x P(x) ≡ ¬$x ¬P(x)
is false.”
} "x ¬P(x) ≡ ¬$x P(x)
is true.”
} ¬"x P(x) ≡ $x ¬P(x)
which P is false.”
Artificial Intelligence 23
} Equality symbol (Term1 = Term1) means
} Useful for constraining two terms to be
} E.g., Sibling
¬(x = y)
Artificial Intelligence 24
} Closed-world assumption
assumed false
} Unique-names assumption
} Domain closure
exist
Artificial Intelligence 25
} TELL (KB, α)
} ASK (KB, β)
} ASKVARS (KB, α)
Artificial Intelligence 26
} Percepts
} Actions
} AskVars (∃a BestAction(a,5)) à {a/Grab}
Artificial Intelligence 27
} “Perception”
} Reflex agent
Artificial Intelligence 28
} Location list term [x,y] (e.g., [1,2])
} Definition of Breezy(s), where s is a location
} Definition of Adjacent
y=b+1)) ∨ (y=b ∧ (x=a-1 ∨ x=a+1))
Artificial Intelligence 29
} Movement } Wumpus never moves
} Nothing can be in two places at once
} Successor-state axioms for each action
¬Action(Shoot,t))
Action(Grab,t)))
Artificial Intelligence 30
} How do we express that there is only one
= x) ∨ ¬(z=y))))
} Only one arrow? } Only one gold? } At least one pit?
Artificial Intelligence 31
Artificial Intelligence 32
Artificial Intelligence 33
} Now that we have FOL, how can we perform
} Approaches
} State of the art
Artificial Intelligence 34
} Carefully…
Artificial Intelligence 35
Monty Python and the Holy Grail (1975)
} Notation } Modus Ponens
Artificial Intelligence 36
} Substitution (binding) θ = {x/y}
α θ = At(Wumpus,[1,3],5)
} Generalized Modus Ponens
} Find θ via unification
Artificial Intelligence 37
} Example } ∀s,r Pit(s) ∧ Adjacent(s,r) ⇒ Breeze(r) } Pit([3,1]), Adjacent([3,1],[2,1]) } p1 = Pit(s), p2 = Adjacent(s,r), q = Breeze(r) } p1’ = Pit([3,1]), p2’ = Adjacent([3,1],[2,1]) } θ = {s/[3,1], r/[2,1]} } SUBST(θ,q) = Breeze([2,1])
Artificial Intelligence 38
} Unification determines if two sentences
} UNIFY(p,q) = q where SUBST(q,p) = SUBST(q,q) } Examples
{s/[1,3], t/5}
{s/AgentLoc(t), t/5} = {s/AgentLoc(5), t/5}
Artificial Intelligence 39
} Standarize variables apart
{x17/Wumpus, x21/[1,3], t/5}
Artificial Intelligence 40
} Occur check
Artificial Intelligence 41
Term 1 Term 2 Substitution (or fail) Glitter(x,y) Glitter(3,3) Adjacent(x,2,2,y) Adjacent(2,y,x,3) At(w,x,y) At(Wumpus,u,3) At(Agent,x,Row(Wumpus)) At(z,3,Row(w)) At(w,Column(w),y) At(Agent,Column(Wumpus),3)
Artificial Intelligence 42
} Start with atomic sentences in KB } Apply Modus Ponens where possible to infer
} Continue until goal is proven or no new
} Assume first-order definite clauses for now
literal
∀x,y A(x) ∧ B(y) ⇒ C(x,y)
Artificial Intelligence 43
} The law says that it is a crime for an
} The country Nono, an enemy of America, has
} Prove that Col. West is a criminal
Artificial Intelligence 44
} “… it is a crime for an American to sell
Hostile(z) ⇒ Criminal(x)
} “… Nono, an enemy of America, …”
} “… Nono … has some missiles”
Artificial Intelligence 45
} “… all of its missiles were sold to it by
Sells(West,x,Nono)
} “… Colonel West, who is American.”
} A few more rules…
Artificial Intelligence 46
Artificial Intelligence 47
American(West) Missile(M1) Owns(Nono,M1) Enemy(Nono,America) Hostile(Nono) Weapon(M1) Sells(West,M1,Nono) Criminal(West) R1: {x4/West, y1/M1, z1/Nono} R7: {x1/M1} R8: {x3/Nono} R5: {x2/M1} R6 R4 R3 R2
} Sound? } Complete? } Efficient?
Conjunct ordering R5: ∀x Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Every new fact inferred on iteration t must be derived from at least one new fact inferred on iteration t-1 Incremental forward chaining
Artificial Intelligence 48
} Work backwards from the goal } For rules concluding goal, add premises as
} Continue until all open goals supported by
} Again, assume first-order definite clauses for
Artificial Intelligence 49
Artificial Intelligence 50
Criminal(West) American(West) Weapon(y) Sells(West,M1,z) Hostile(Nono) Missile(y) Missile(M1) Owns(Nono, M1) Enemy(Nono,America) R6 R1: {x1/West} {y/M1} R5: {z/Nono} R4 Missile(M1) R7: {x2/y} R4 R3 R2 R8
} Sound? } Complete? } Efficient?
More constraints R5: ∀x Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Yes, but only those whose consequent unifies with an
Excluded
} Logic programming in Prolog
Artificial Intelligence 51
} l's and m's are literals } A clause is a disjunction of literals } Resolution takes two clauses and infers a new
Artificial Intelligence 52
} Resolution using refutation (proof by
If result ever empty clause, then proven
} Convert FOL to clausal form (CNF) } Efficient? Resolution strategies
Artificial Intelligence 53
} Conjunctive Normal Form (CNF)
} Example
Hostile(z) ⇒ Criminal(x)
¬Hostile(x) ∨ Criminal(x)
Artificial Intelligence 54
} Step 1: Eliminate implications ⇒
} Step 2: Move ¬ inwards
} Step 3: Standardize variables
Artificial Intelligence 55
} Step 4: Skolemize (Skolemization)
with a new constant or function
universally quantified variables in whose scope the existential quantifier appears
Artificial Intelligence 56
Thoralf Skolem (1887-1963) Norwegian mathematician
} Step 5: Drop universal quantifiers
} Step 6: Distribute ∨ over ∧
Artificial Intelligence 57
} What is a brick?
brick as well
same thing as a brick.
Artificial Intelligence 58
} Step 1: Eliminate implications
Artificial Intelligence 59
} Step 2: Move ¬ inwards
Artificial Intelligence 60
} Step 3: Standardize variables
Artificial Intelligence 61
} Step 4: Skolemization } Step 5: Drop universal quantifiers
Artificial Intelligence 62
} Step 6: Distribute ∨ over ∧
Artificial Intelligence 63
} CNF
∨ Criminal(x)
} Prove: Criminal(West)
Artificial Intelligence 64
Artificial Intelligence 65
} Prove: ∃c Criminal(c)
} Generated clauses
¬Hostile(z)
Artificial Intelligence 66
} Add clause with negated goal and answer
} Search for clause containing only answer
} Prove: ∃x,y,z Goal(x,y,z) } Add (¬Goal(x,y,z) ∨ Answer(x,y,z)) to KB } Final clause Answer(x,y,z) will have variables
Artificial Intelligence 67
} Prove: ∃c Criminal(c) and retrieve c
} Generated clauses
Answer(c)
Answer(West)
Answer(West)
Artificial Intelligence 68
} Willy is a wumpus. Swiper is not a wumpus,
} Prove that Swiper jumps over Willy.
Artificial Intelligence 69
Artificial Intelligence 70
Artificial Intelligence 71
} Vampire (vprover.github.io) } iProver (www.cs.man.ac.uk/~korovink/iprover) } Conference on Automated Deduction (CADE)
} Applications
Artificial Intelligence 72
} Knowledge-based (logical) agent } First-order logic } Inference
Artificial Intelligence 73