Download presentation
Presentation is loading. Please wait.
1
Introduction to Artificial Intelligence – Unit 4 Logical Agents and First Order Logic Course 67842
The Hebrew University of Jerusalem School of Engineering and Computer Science Academic Year: 2008/2009 Instructor: Jeff Rosenschein (Chapters 7 and 8, “Artificial Intelligence: A Modern Approach”)
2
Outline – Logical Agents
Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem proving forward chaining backward chaining resolution
3
Knowledge bases Knowledge base = set of sentences in a formal language
Declarative approach to building an agent (or other system): Tell it what it needs to know Then it can Ask itself what to do – answers should follow from the KB Agents can be viewed at the knowledge level i.e., what they know, regardless of how implemented Or at the implementation level i.e., data structures in KB and algorithms that manipulate them
4
A simple knowledge-based agent
The agent must be able to: Represent states, actions, etc. Incorporate new percepts Update internal representations of the world Deduce hidden properties of the world Deduce appropriate actions
5
Wumpus World PEAS description
Performance measure gold +1000, death -1000 -1 per step, -10 for using the arrow Environment Squares adjacent to wumpus are smelly Squares adjacent to pit are breezy Glitter iff gold is in the same square Shooting kills wumpus if you are facing it Shooting uses up the only arrow Grabbing picks up gold if in same square Releasing drops the gold in same square Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot Sensors: Stench, Breeze, Glitter, Bump, Scream
6
Wumpus world characterization
Fully 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 essentially a natural feature
7
Exploring a wumpus world
8
Exploring a wumpus world
9
Exploring a wumpus world
10
Exploring a wumpus world
11
Exploring a wumpus world
12
Exploring a wumpus world
13
Exploring a wumpus world
14
Exploring a wumpus world
15
Other Tight Spots
16
Logic in general Logics are formal languages for representing information such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the “meaning” of sentences; i.e., define truth of a sentence in a world E.g., the language of arithmetic x+2 ≥ y is a sentence; x2+y > is not a sentence x+2 ≥ y is true iff the number x+2 is no less than the number y x+2 ≥ y is true in a world where x = 7, y = 1 x+2 ≥ y is false in a world where x = 0, y = 6
17
Entailment Entailment means that one thing follows from another:
KB ╞ α Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true E.g., the KB containing “the Giants won” and “the Reds won” entails “Either the Giants won or the Reds won” E.g., x+y = 4 entails 4 = x+y Entailment is a relationship between sentences (i.e., syntax) that is based on semantics Note: brains process syntax (of some sort)
18
Models Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated We say m is a model of a sentence α if α is true in m M(α) is the set of all models of α Then KB ╞ α iff M(KB) M(α) E.g., KB = Giants won and Reds won α = Giants won
19
Entailment in the wumpus world
Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for KB assuming only pits 3 Boolean choices 8 possible models
20
Wumpus models
21
Wumpus models KB = wumpus-world rules + observations
22
Wumpus models KB = wumpus-world rules + observations
α1 = “[1,2] is safe”, KB ╞ α1, proved by model checking
23
Wumpus models KB = wumpus-world rules + observations
24
Wumpus models KB = wumpus-world rules + observations
α2 = “[2,2] is safe”, KB ╞ α2
25
Inference KB ├i α = sentence α can be derived from KB by procedure i
Consequences of KB are a haystack; α is a needle Entailment = needle in haystack; inference = finding it Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α
26
Inference Sentences Sentence Aspects of the real world
Entails Sentence Representation Semantics Semantics World Aspects of the real world Aspects of the real world Follows
27
Inference Preview: we will eventually define a logic (first-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure That is, the procedure will answer any question whose answer follows from what is known by the KB But first, Propositional Logic…
28
Propositional logic: Syntax
Propositional logic is the simplest logic – illustrates basic ideas The proposition symbols P1, P2, etc. are sentences If S is a sentence, S is a sentence (negation) If S1 and S2 are sentences, S1 S2 is a sentence (conjunction) If S1 and S2 are sentences, S1 S2 is a sentence (disjunction) If S1 and S2 are sentences, S1 S2 is a sentence (implication) If S1 and S2 are sentences, S1 S2 is a sentence (biconditional)
29
Propositional logic: Semantics
Each model specifies true/false for each proposition symbol E.g. P1,2 P2,2 P3,1 false false true With these symbols, 8 possible models, can be enumerated automatically. Rules for evaluating truth with respect to a model m: S is true iff S is false S1 S2 is true iff S1 is true and S2 is true S1 S2 is true iff S1is true or S2 is true S1 S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true and S2 is false S1 S2 is true iff S1S2 is true and S2S1 is true Simple recursive process evaluates an arbitrary sentence, e.g., P1,2 (P2,2 P3,1) = true (false true) = true true = true
30
Truth tables for connectives
31
Wumpus world sentences
Let Pi,j be true if there is a pit in [i, j]. Let Bi,j be true if there is a breeze in [i, j]. There is no pit in [1, 1]: R1 : P1,1 “Pits cause breezes in adjacent squares” “A square is breezy if and only if there is an adjacent pit” R2 : B1,1 (P1,2 P2,1) R3 : B2,1 (P1,1 P2,2 P3,1) “There was no breeze in B1,1, there was a breeze in B2,1” R4 : B1,1 R5 : B2,1
32
Truth tables for inference
128 rows (27); KB is conjunction of R1 through R5, and is true in 3 of the rows; in all 3 of those rows, P1,2 is false; so there is no pit in [1,2]; we don’t know whether there is a pit in [2,2]
33
Inference by enumeration
Depth-first enumeration of all models is sound and complete; there are finitely many models to examine For n symbols, time complexity is O(2n), space complexity is O(n) [depth-first search]; problem is co-NP-complete
34
Knights and Knaves Island inhabited by Knights (always tell the truth) and Knaves (always lie) There are two inhabitants of the Island, A and B A says, "At least one of us is a knave." What are A and B?
35
0's are Knaves, 1's are Knights
A says "At least one of us is a Knave." A B 1 x x possible x
36
Knights and Knaves Three island inhabitants, A, B, and C, are standing in a garden. A stranger asks A, "How many knights are among you?" A answers unclearly. The stranger asks B, "What did A say?" B replies, "A said there is one knight among us." Then C says, "Don't believe B; he is lying!" What are B and C?
37
0's are Knaves, 1's are Knights
B C 1 After B's statement After C's statement x possible Stranger asks A, "How many knights are among you?" A answers unclearly. The stranger asks B, "What did A say?" B replies, "A said there is one knight among us." Then C says, "Don't believe B; he is lying!" Solution by model enumeration; B is a Knave, C is a Knight
38
Final One Three people, A, B, and C, each of whom is a Knight or a Knave. A says, "All of us are knaves." B says, "Exactly one of us is a knight." What are A, B, and C?
39
0's are Knaves, 1's are Knights
B C 1 After B's statement After C's statement x possible A says, "All of us are knaves." B says, "Exactly one of us is a knight." Solution by model enumeration; B is a Knight, C is a Knave
40
Logical equivalence Two sentences are logically equivalent iff true in same models: α ≡ β iff α╞ β and β╞ α
41
Validity and satisfiability
A sentence is valid if it is true in all models, e.g., True, A A, A A, (A (A B)) B Validity is connected to inference via the Deduction Theorem: KB ╞ α if and only if (KB α) is valid A sentence is satisfiable if it is true in some model e.g., A B, C A sentence is unsatisfiable if it is true in no models e.g., AA Satisfiability is connected to inference via the following: KB ╞ α if and only if (KB α) is unsatisfiable i.e., prove α by reductio ad absurdum
42
Proof methods Proof methods divide into (roughly) two kinds:
Application of inference rules Legitimate (sound) generation of new sentences from old Proof = a sequence of inference rule applications Can use inference rules as operators in a standard search algorithm Typically require transformation of sentences into a normal form Model checking truth table enumeration (always exponential in n) improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL) heuristic search in model space (sound but incomplete) e.g., min-conflicts-like hill-climbing algorithms
43
Forward and backward chaining
Horn Form (restricted) KB = conjunction of Horn clauses Horn clause = proposition symbol; or (conjunction of symbols) symbol E.g., C (B A) (C D B) Modus Ponens (for Horn Form): complete for Horn KBs α1,…, αn α1 … αn β β Can be used with forward chaining or backward chaining These algorithms are very natural and run in linear time
44
Forward chaining Idea: fire any rule whose premises are satisfied in the KB, add its conclusion to the KB, until query is found
45
Forward chaining algorithm
Forward chaining is sound and complete for Horn KB
46
Forward chaining example
47
Forward chaining example
48
Forward chaining example
49
Forward chaining example
50
Forward chaining example
51
Forward chaining example
52
Forward chaining example
53
Forward chaining example
54
Proof of completeness FC derives every atomic sentence that is entailed by KB FC reaches a fixed point where no new atomic sentences are derived Consider the final state as a model m, assigning true/false to symbols Every clause in the original KB is true in m Proof: Suppose a clause a1 … ak b is false in m Then a1 … ak is true in m and b is false in m Therefore the algorithm has not reached a fixed point! Hence m is a model of KB If KB╞ q, q is true in every model of KB, including m General Idea: construct any model of KB by sound inference, check α
55
Backward chaining Idea: work backwards from the query q:
to prove q by BC, check if q is known already, or prove by BC all premises of some rule concluding q Avoid loops: check if new subgoal is already on the goal stack Avoid repeated work: check if new subgoal has already been proved true, or has already failed
56
Backward chaining example
57
Backward chaining example
58
Backward chaining example
59
Backward chaining example
60
Backward chaining example
61
Backward chaining example
62
Backward chaining example
63
Backward chaining example
64
Backward chaining example
65
Backward chaining example
66
Forward vs. backward chaining
FC is data-driven, automatic, unconscious processing, e.g., object recognition, routine decisions May do lots of work that is irrelevant to the goal BC is goal-driven, appropriate for problem-solving, e.g., Where are my keys? How do I get into a PhD program? Complexity of BC can be much less than linear in size of KB
67
l1 … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn
Resolution Conjunctive Normal Form (CNF) conjunction of disjunctions of literals clauses E.g., (A B) (B C D) Resolution inference rule (for CNF): l1 … lk m1 … mn l1 … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn where li and mj are complementary literals. E.g., P1,3 P2,2, P2,2 P1,3 Resolution is sound and complete for propositional logic
68
Resolution Soundness of resolution inference rule:
(l1 … li-1 li+1 … lk) li mj (m1 … mj-1 mj+1 ... mn) (l1 … li-1 li+1 … lk) (m1 … mj-1 mj+1 ... mn) If li is true, mj must be false, so (m1 … mj-1 mj+1 ... mn) must be true; If li is false, then (l1 … li-1 li+1 … lk) must be true; Since li is either true or false, one or the other of these conclusions must be true, which is what the rule says
69
Resolution “Canada is in North America, or Canada is in the EU”
“Canada is not in North America, or Canada is in the British Commonwealth” From this we can conclude: “Canada is in the EU, or Canada is in the British Commonwealth”
70
Conversion to CNF B1,1 (P1,2 P2,1)
Eliminate , replacing α β with (α β)(β α) (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) 2. Eliminate , replacing α β with α β (B1,1 P1,2 P2,1) ((P1,2 P2,1) B1,1) 3. Move inwards using de Morgan’s rules and double-negation: (B1,1 P1,2 P2,1) ((P1,2 P2,1) B1,1) 4. Apply distributivity law ( over ) and flatten: (B1,1 P1,2 P2,1) (P1,2 B1,1) (P2,1 B1,1)
71
Resolution algorithm Proof by contradiction, i.e., show KBα unsatisfiable
72
Resolution example KB = (B1,1 (P1,2 P2,1)) B1, α = P1,2
73
Efficient propositional inference
Two families of efficient algorithms for propositional inference: Complete backtracking search algorithms DPLL algorithm (Davis, Putnam, Logemann, Loveland) Incomplete local search algorithms WalkSAT algorithm
74
The DPLL algorithm Determine if an input propositional logic sentence (in CNF) is satisfiable. Improvements over truth table enumeration: Early termination (before a model is complete) A clause is true if any literal is true A sentence is false if any clause is false Pure symbol heuristic Pure symbol: always appears with the same “sign” in all clauses e.g., In the three clauses (A B), (B C), (C A), A and B are pure, C is impure Make a pure symbol literal true Unit clause heuristic Unit clause: when there is only one literal in the clause Here, all literals but one are already assigned false by the model The only literal in a unit clause (or “remaining” literal) must be true
75
The DPLL algorithm
76
The WalkSAT algorithm Incomplete, local search algorithm
Evaluation function: The min-conflict heuristic of minimizing the number of unsatisfied clauses (i.e., maximizes satisfied clauses) Balance between greediness and randomness
77
The WalkSAT algorithm Every iteration, pick an unsatisfied clause; pick a symbol to flip in one of two ways: 1) “random walk” that picks symbol randomly; 2) “min-conflicts” that maximizes number of satisfied clauses If sentence is satisfiable, and max-flips big enough, will eventually find it; if sentence is unsatisfiable, cannot inform us of the fact
78
Hard satisfiability problems
Consider random 3-CNF sentences (randomly selected 3 distinct symbols, each negated with 50% probability), e.g., (D B C) (B A C) (C B E) (E D B) (B E C) m = number of clauses n = number of symbols (overall, in the KB) Hard problems seem to cluster near m/n = 4.3 (critical point) Lower ratio is less constrained, higher ratio is more constrained
79
Hard satisfiability problems
Graph showing probability that a random 3-CNF sentence with n=50 symbols is satisfiable, as a function of the clause/symbol ratio m/n
80
Hard satisfiability problems
Median runtime for 100 satisfiable random 3-CNF sentences, n = 50 Problems near the critical point are much more difficult than random problems DPLL is effective: a few thousand steps as compared to 250 (approx. 1015) for truth-table enumeration WalkSAT is faster than DPLL throughout the range
81
Inference-based agents in the wumpus world
A wumpus-world agent using propositional logic: P1,1 W1,1 Bx,y (Px,y+1 Px,y-1 Px+1,y Px-1,y) Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y) W1,1 W1,2 … W4,4 W1,1 W1,2 W1,1 W1,3 … 64 distinct proposition symbols, 155 sentences
83
Expressiveness limitation of propositional logic
KB contains “physics” sentences for every single square For every time t and every location [x,y], Lx,y FacingRightt Forwardt Lx+1,y Rapid proliferation of clauses t t+1
84
Circuit-Based Agents A kind of reflex agent
Percepts are inputs to a sequential circuit --- a network of gates (each implementing a logical connective), and registers (each storing the truth value of a single proposition) The outputs of the circuit are registers corresponding to actions
85
Circuit-Based Agent Part of a circuit-based agent in the wumpus world, showing inputs, outputs, circuit for grabbing gold, and circuit for determining whether wumpus is alive Registers are rectangles, triangles are one-step delays
86
Circuit-Based Agent Circuits are evaluated in dataflow fashion
inputs are set at each time step, and signals propagate through the circuit When a gate has all its inputs, it produces an output The internal state of the agent is maintained by connecting the output of a register back into the circuit through a delay line
87
Circuit-Based Agent The circuit for determining whether the agent is at [1,1] Every location and orientation register has a similar circuit attached
88
Comparison of Inference-Based and Circuit-Based Agents
Conciseness: the circuit-based agent need not have separate copies of its knowledge for every time step Computational efficiency: worst case, inference takes time exponential in the number of symbols, while evaluating a circuit takes time linear in the size of the circuit (or linear in the depth of the circuit, if it is a physical device); in practice, however, required inferences can be fast, e.g., DPLL
89
Comparison of Inference-Based and Circuit-Based Agents
Completeness: circuit-based agents may be incomplete due to the acyclicity restriction (requirement that every path connecting a register’s output back to its input have an intervening delay element) – Breezes implied by Pits, and vice versa; can be overcome, but adds to complexity of circuit Also, in some environments, a complete circuit must be exponentially larger than the inference-based agent’s KB Also, since (only) individual propositions are remembered, conclusions derived from disjuncts won’t be…B1,1 implies P1,2 P2,1; and P1,2 P2,1 implies B2,2…an inference agent could derive B2,2 from B1,1, a circuit-based agent couldn’t Ease of construction: somewhat in the eye of the beholder…
90
Summary Logical agents apply inference to a knowledge base to derive new information and make decisions Basic concepts of logic: syntax: formal structure of sentences semantics: truth of sentences wrt models entailment: necessary truth of one sentence given another inference: deriving sentences from other sentences soundness: derivations produce only entailed sentences completeness: derivations can produce all entailed sentences Wumpus world requires the ability to represent partial and negated information, reason by cases, etc. Forward, backward chaining are linear-time, complete for Horn clauses Resolution is complete for propositional logic Propositional logic lacks expressive power
91
First-Order Logic Chapter 8
92
Outline Why FOL? Syntax and semantics of FOL
Using FOL – fun with sentences Wumpus world in FOL Knowledge engineering in FOL
93
Pros and cons of propositional logic
Propositional logic is declarative: pieces of syntax correspond to facts Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases) Propositional logic is compositional: meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2 Meaning in propositional logic is context-independent (unlike natural language, where meaning depends on context) Propositional logic has very limited expressive power (unlike natural language) E.g., cannot say “pits cause breezes in adjacent squares” except by writing one sentence for each square
94
First-order logic Whereas propositional logic assumes the world contains facts, first-order logic (like natural language) assumes the world contains Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries, … Relations: red, round, prime, multistoried, brother of, bigger than, inside, part of, has color, occurred after, owns, comes between, … Functions: father of, best friend, third inning of, one more than, plus, end of, …
95
Logics in General
96
Syntax of FOL: Basic elements
Constants KingJohn, 2, HU, ... Predicates Brother, >, ... Functions Sqrt, LeftLegOf, ... Variables x, y, a, b, ... Connectives , , , , Equality = Quantifiers ,
97
Atomic sentences Atomic sentence = predicate (term1,...,termn) or term1 = term2 Term = function (term1,...,termn) or constant or variable E.g., Brother(KingJohn, RichardTheLionheart) > (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))
98
Complex sentences Complex sentences are made from atomic sentences using connectives S, S1 S2, S1 S2, S1 S2, S1 S2 E.g., Sibling(KingJohn,Richard) Sibling(Richard,KingJohn) >(1,2) ≤ (1,2) >(1,2) >(1,2)
99
Truth in first-order logic
Sentences are true with respect to a model and an interpretation Model contains objects (domain elements) and relations among them Interpretation specifies referents for constant symbols → objects predicate symbols → relations function symbols → functional relations An atomic sentence predicate(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relation referred to by predicate
100
Semantics What do sentences mean? Descriptive Semantics:
symbols and sentences
104
Models for FOL: Example
105
Truth Example Consider the interpretation in which Richard -> Richard the Lionhearted John -> the evil King John Brother -> the brotherhood relation Under this interpretation, Brother(Richard,John) is true just in case Richard the Lionhearted and the evil King John are in the brotherhood relation in the model
106
Models for FOL: Lots! Entailment in propositional logic can be computed by enumerating models We can enumerate the FOL models for a given KB vocabulary: For each number of domain elements n from 1 to ∞ For each k-ary predicate Pk in the vocabulary For each possible k-ary relation on n objects For each constant symbol C in the vocabulary For each choice of referent for C from n objects . . . Computing entailment by enumerating FOL models is not easy!
107
Universal quantification
<variables> <sentence> Everyone at HU is smart: x At(x, HU) Smart(x) x P is true in a model m iff P is true with x being each possible object in the model Roughly speaking, equivalent to the conjunction of instantiations of P At(KingJohn, HU) Smart(KingJohn) At(Richard, HU) Smart(Richard) At(HU, HU) Smart(HU) ...
108
A common mistake to avoid
Typically, is the main connective with Common mistake: using as the main connective with : x At(x, HU) Smart(x) means “Everyone is at HU and everyone is smart”
109
Existential quantification
<variables> <sentence> Someone at TAU is smart: x At(x, TAU) Smart(x) x P is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P At(KingJohn, TAU) Smart(KingJohn) At(Richard, TAU) Smart(Richard) At(TAU, TAU) Smart(TAU) ...
110
Another common mistake to avoid
Typically, is the main connective with Common mistake: using as the main connective with : x At(x, TAU) Smart(x) is true if there is anyone who is not at TAU!
111
Properties of quantifiers
x y is the same as y x (why?) x y is the same as y x (why?) x y is not the same as y x x y Loves(x,y) “There is a person who loves everyone in the world” y x Loves(x,y) “Everyone in the world is loved by at least one person” Quantifier duality: each can be expressed using the other x Likes(x, IceCream) x Likes(x, IceCream) x Likes(x, Broccoli) x Likes(x, Broccoli)
112
First-Order vs. Second-Order Logics
A first-order language is one in which variables refer to objects in the universe of discourse, not functions or relations A second-order language allows function and relation variables: P (P(Confucius)) AI typically only uses first-order (not second-order) predicate calculus (though circumscription can be described this way)
113
Fun with sentences Brothers are siblings x y Brother(x, y) Sibling(x, y) “Sibling” is symmetric x y Sibling(x, y) Sibling(y, x) One’s mother is one’s female parent x y Mother(x, y) (Female(x) Parent(x, y)) A first cousin is a child of a parent’s sibling x y FirstCousin(x, y) p ps Parent(p, x) Sibling(ps, p) Parent(ps, y)
114
Equality term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object E.g., definition of (full) Sibling in terms of Parent: x,y Sibling(x,y) [(x = y) m,f (m = f) Parent(m,x) Parent(f,x) Parent(m,y) Parent(f,y)]
115
Using FOL The kinship domain: Brothers are siblings
x,y Brother(x,y) Sibling(x,y) One’s mother is one’s female parent m,c Mother(c) = m (Female(m) Parent(m,c)) “Sibling” is symmetric x,y Sibling(x,y) Sibling(y,x)
116
Using FOL The set domain:
s Set(s) (s = {} ) (x,s2 Set(s2) s = {x|s2}) x,s {x|s} = {} x,s x s s = {x|s} x,s x s [ y,s2} (s = {y|s2} (x = y x s2))] s1,s2 s1 s2 (x x s1 x s2) s1,s2 (s1 = s2) (s1 s2 s2 s1) x,s1,s2 x (s1 s2) (x s1 x s2) x,s1,s2 x (s1 s2) (x s1 x s2)
117
Interacting with FOL KBs
Suppose a wumpus-world agent is using an FOL KB and perceives a smell and a breeze (but no glitter) at t=5: Tell(KB,Percept([Smell,Breeze,None],5)) Ask(KB,a BestAction(a,5)) I.e., does the KB entail some best action at t=5? Answer: Yes, {a/Shoot} ← substitution (binding list) Given a sentence S and a substitution σ, Sσ denotes the result of plugging σ into S; e.g., S = Smarter(x,y) σ = {x/Hillary,y/Bill} Sσ = Smarter(Hillary,Bill) Ask(KB,S) returns some/all σ such that KB╞ σ
118
Knowledge base for the wumpus world
Perception t,s,b Percept([s,b,Glitter],t) AtGold(t) Reflex t AtGold(t) Action(Grab, t) Reflex with internal state: do we have the gold already? t AtGold(t) Holding(Gold, t) Action(Grab, t) Holding(Gold, t) cannot be observed, so keeping track of change is essential (and tricky)
119
Deducing hidden properties
x,y,a,b Adjacent([x,y],[a,b]) [a,b] {[x+1,y], [x-1,y],[x,y+1],[x,y-1]} Properties of squares: s,t At(Agent,s,t) Breeze(t) Breezy(s) Squares are breezy near a pit: Diagnostic rule---infer cause from effect s Breezy(s) r Adjacent(r,s) Pit(r) Causal rule---infer effect from cause r Pit(r) [ s Adjacent(r,s) Breezy(s) ] Neither of these is complete --- e.g., the causal rule doesn’t say whether squares far away from pits can be breezy Overall definition for the Breezy predicate: s Breezy(s) r Adjacent(r, s) Pit(r)
120
Keeping Track of Change
Facts hold in situations, rather than eternally E.g., Holding(Gold, Now) rather than just Holding(Gold) Situation calculus is one way to represent change in FOL: Adds a situation argument to each non-eternal predicate E.g., Now in Holding(Gold, Now) denotes a situation Situations are connected by the Result function; Result(a, s) is the situation that results from doing a in s
121
Describing Actions I “Effect” axiom—describe changes due to action s AtGold(s) Holding(Gold, Result(Grab, s)) “Frame” axiom—describe non-changes due to action s HaveArrow(s) HaveArrow(Result(Grab, s)) Frame problem: find an elegant way to handle non-change (a) representation – avoid frame axioms (b) inference – avoid repeated “copy-overs” to keep track of state Qualification problem: true descriptions of real actions require endless caveats – what if gold is slippery or nailed down or … Ramification problem: real actions have many secondary consequences – what about the dust on the gold, wear and tear on gloves, …
122
Describing Actions II Successor-state axioms solve the representational frame problem Each axiom is “about” a predicate (not an action per se): P true afterwards [an action made P true P true already and no action made P false] For holding the gold: a, s Holding(Gold, Result(a, s)) [(a = Grab AtGold(s)) (Holding(Gold, s) a != Release)]
123
Making Plans Initial condition in KB: At(Agent, [1, 1], S0) At(Gold, [1, 2], S0) Query: Ask(KB, s Holding(Gold, s)) i.e., in what situation will I be holding the gold? Answer: {s/Result(Grab, Result(Forward, S0))} i.e., go forward and then grab the gold This assumes that the agent is interested in plans starting at S0 and that S0 is the only situation described in the KB
124
Green’s Method (Another explanation)
Add state variables to the predicates, and use a function Result that maps actions and states into new states Result: A x S S Ex: Result(Unstack(x, y), S) is a new state A B
125
Example in Blocks World
So to characterize the action UNSTACK we could write: [ Clear(x, s) On(x, y, s) ] [Holding(x, Result(Unstack(x,y),s)) Clear(y, Result(Unstack(x,y),s))] We can prove that if S0 is On(A,B,S0) Ontable(B,S0) Clear(A, S0) then Holding(A,Result(Unstack(A,B),S0)) Clear(B, Result(Unstack(A,B),S0)) S1 A S1 B
126
Example in Blocks World
The proof could proceed further; if we characterize Putdown: Holding(x, s) Ontable(x, Result(Putdown(x), s)) then we can prove: Ontable(A, Result(Putdown(A), Result(Unstack(A,B), S0))) The nested actions in this constructive proof give you the plan: 1. Unstack(A,B); 2. Putdown(A) S1 S2 A B
127
Frame Problem (again) So if we have in our KB: On(A,B,S0) Ontable(B, S0) Clear(A,S0) and our query is s (Ontable(A, s)) we could use theorem proving to find the plan But could I prove: Ontable(B, Result(Putdown(A), Result(Unstack(A,B), S0))) A B No, not without additional frame axioms S1 S2
128
The Frame Problem How do you determine what changes and what doesn’t change when an action is performed? One solution: “Frame axioms” that specify how predicates can remain unchanged after an action
129
Frame Axioms Ontable(z, s) Ontable(z, Result(Unstack(x,y), s))
[On(m, n, s) m != x] On(m, n, Result(Unstack(x,y), s)) Problem: Unless we go to a higher-order logic, Green’s method forces us to write many axioms: Color(x, c, s) Color(x, c, Result(Unstack(y, z), s)) We want to avoid this.
130
Making Plans: A better way
Represent plans as action sequences [a1, a2, … , an] PlanResult(p, s) is the result of executing p in s Then the query Ask(KB, p Holding(Gold, PlanResult(p, S0))) has the solution {p/[Forward, Grab]} Definition of PlanResult in terms of Result: s PlanResult([ ], s) = s a, p, s PlanResult([a|p], s) = PlanResult(p, Result(a, s)) Planning systems are special-purpose reasoners designed to do this type of inference more efficiently than a general-purpose reasoner
131
Knowledge engineering in FOL
Identify the task Assemble the relevant knowledge Decide on a vocabulary of predicates, functions, and constants Encode general knowledge about the domain Encode a description of the specific problem instance Pose queries to the inference procedure and get answers Debug the knowledge base
132
The electronic circuits domain
One-bit full adder
133
The electronic circuits domain
Identify the task Does the circuit actually add properly? (circuit verification) Assemble the relevant knowledge Composed of wires and gates; Types of gates (AND, OR, XOR, NOT) Irrelevant: size, shape, color, cost of gates Decide on a vocabulary Alternatives: Type(X1) = XOR Type(X1, XOR) XOR(X1)
134
The electronic circuits domain
Encode general knowledge of the domain t1,t2 Connected(t1, t2) Signal(t1) = Signal(t2) t Signal(t) = 1 Signal(t) = 0 1 ≠ 0 t1,t2 Connected(t1, t2) Connected(t2, t1) g Type(g) = OR Signal(Out(1,g)) = 1 n Signal(In(n,g)) = 1 g Type(g) = AND Signal(Out(1,g)) = 0 n Signal(In(n,g)) = 0 g Type(g) = XOR Signal(Out(1,g)) = 1 Signal(In(1,g)) ≠ Signal(In(2,g)) g Type(g) = NOT Signal(Out(1,g)) ≠ Signal(In(1,g))
135
The electronic circuits domain
Encode the specific problem instance: Type(X1) = XOR Type(X2) = XOR Type(A1) = AND Type(A2) = AND Type(O1) = OR Connected(Out(1,X1),In(1,X2)) Connected(In(1,C1),In(1,X1)) Connected(Out(1,X1),In(2,A2)) Connected(In(1,C1),In(1,A1)) Connected(Out(1,A2),In(1,O1)) Connected(In(2,C1),In(2,X1)) Connected(Out(1,A1),In(2,O1)) Connected(In(2,C1),In(2,A1)) Connected(Out(1,X2),Out(1,C1)) Connected(In(3,C1),In(2,X2)) Connected(Out(1,O1),Out(2,C1)) Connected(In(3,C1),In(1,A2))
136
The electronic circuits domain
Pose queries to the inference procedure What are the possible sets of values of all the terminals for the adder circuit? i1,i2,i3,o1,o2 Signal(In(1,C_1)) = i1 Signal(In(2,C1)) = i2 Signal(In(3,C1)) = i3 Signal(Out(1,C1)) = o1 Signal(Out(2,C1)) = o2 Debug the knowledge base May have omitted assertions like 1 ≠ 0
137
Summary First-order logic:
objects and relations are semantic primitives syntax: constants, functions, predicates, equality, quantifiers Increased expressive power: sufficient to define wumpus world Situation calculus: conventions for describing actions and change in FOL can formulate planning as inference on a situation calculus KB
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.