Logical Agents Chapter 7 part 2 Modified by
Logical Agents ﻋﺎﻣﻠﻬﺎﻱ ﻣﻨﻄﻘﻲ Chapter 7 (part 2) Modified by Vali Derhami 1/46
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 2/46
( ﺗﺤﻠﻴﻞ )ﺍﺩﺍﻣﻪ we can now derive the absence of pits in [2, 2] and [1, 3], ([1, 1] is already known) Respect to R 11 and R 12: Known : from past: Respect to R 15 and Rr 13: Respect to R 10 (R 10 : P 11), and R 16: 5/46
( ﺗﺤﻠﻴﻞ )ﺍﺩﺍﻣﻪ Conjunctive Normal Form (CNF)( )ﻓﺮﻡ ﻧﺮﻣﺎﻝ ﻋﻄﻔﻲ conjunction of disjunctions of literals (clauses). ﺷﺪﻩ ﺍﻧﺪ OR ﺍﺯ ﻟﻴﺘﺮﺍﻝ ﻛﻪ ﺑﺎ ﻫﻢ AND ﺗﺮﻛﻴﺐ Literal: a atomic sentence. Ex; P , Q , or , A Clause: a disjunction of literals. E. g. , (A B) (B C D) • Unit resolution inference rule: Where li and m are complementary literals 6/46
( ﺗﺤﻠﻴﻞ )ﺍﺩﺍﻣﻪ • Full Resolution inference rule (for CNF): l 1 … lk, m 1 … mn l 1 … li-1 li+1 … lk m 1 … mj-1 mj+1 . . . mn where li and mj are complementary literals. E. g. , P 1, 3 P 2, 2, P 2, 2 P 1, 3 • Using any complete search, • Resolution is sound and complete for propositional logic ﺗﺤﻠﻴﻞ ﻫﻤﻴﺸﻪ ﻣﻲ ﺗﻮﺍﻧﺪ ﺑﺮﺍﻱ ﺍﺛﺒﺎﺕ ، ﺗﻮﺟﻪ ﻳﺎﺗﻜﺬﻳﺐ ﻳﻚ ﺟﻤﻠﻪ ﺍﺳﺘﻔﺎﺩﻩ ﺷﻮﺩ 7/46
Conversion to CNF ﺗﺒﺪﻳﻞ ﺑﻪ ﻓﺮﻡ ﻧﺮﻣﺎﻝ ﻋﻄﻔﻲ B 1, 1 (P 1, 2 P 2, 1) 1. Eliminate , replacing α β with (α β) (β α). (B 1, 1 (P 1, 2 P 2, 1)) ((P 1, 2 P 2, 1) B 1, 1) 2. Eliminate , replacing α β with α β. ( B 1, 1 (P 1, 2 P 2, 1)) ( (P 1, 2 P 2, 1) B 1, 1) 3. Move inwards using de Morgan's rules and doublenegation: ( B 1, 1 P 1, 2 P 2, 1) (( P 1, 2 P 2, 1) B 1, 1) 4. Apply distributivity law ( over ) and flatten: ( B 1, 1 P 1, 2 P 2, 1) ( P 1, 2 B 1, 1) ( P 2, 1 B 1, 1) 8/46
Resolution algorithm • Proof by contradiction, i. e. , to Prove KB a, show KB α unsatisfiable 9/46
Steps in Resolution algorithm • (KB a) is converted into CNF. • The resolution rule is applied to the resulting clauses. Each pair that contains complementary literals is resolved to produce a new clause, which is added to the set if it is not already present. • The process continues until one of two things happens: 1 - two clauses resolve to yield the empty clause, in which case KB entails a. 2 - there are no new clauses that can be added, in which case KB does not entail a. 10/46
Resolution example • KB = (B 1, 1 (P 1, 2 P 2, 1)) B 1, 1 , α = P 1, 2 11/46
Forward and backward chaining A Horn clause with no positive literals can be written as an implication whose conclusion is the literal False. Ex: —wumpus cannot be in both [1, 1] and [1, 2]—is equivalent to. Such sentences are called integrity ( ) کﺎﻣﻞ constraints in the database world, 15/46
Forward chaining • Idea: fire any rule whose premises are satisfied in the KB, – add its conclusion to the KB, until query is found 16/46
Forward chaining algorithm • Forward chaining is sound and complete for Horn KB 17/46
Forward chaining example 18/46
Forward chaining example 19/46
Forward chaining example 20/46
Forward chaining example 21/46
Forward chaining example 22/46
Forward chaining example 23/46
Forward chaining example 24/46
Forward chaining example 25/46
Proof of completeness • FC derives every atomic sentence that is entailed by KB 1. FC reaches a fixed point where no new atomic sentences are derived 2. Consider the final state as a model m, assigning true/false to symbols 3. Every clause in the original KB is true in m a 1 … ak b 4. Hence m is a model of KB 5. If KB╞ q, q is true in every model of KB, including m 26/46
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 27/46
Backward chaining example 28/46
Backward chaining example 29/46
Backward chaining example 30/46
Backward chaining example 31/46
Backward chaining example 32/46
Backward chaining example 33/46
Backward chaining example 34/46
Backward chaining example 35/46
Backward chaining example 36/46
Backward chaining example 37/46
Forward vs. backward chaining • FC is data-driven, automatic, unconscious processing ( )پﺮﻭﺳﺲ ﺑﻲ ﻫﺪﻑ , appropritate for Design, Control. – 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, Diagnosis, – e. g. , Where are my keys? How do I get into a Ph. D program? • Complexity of BC can be much less than linear in size of KB 38/46
Efficient propositional inference Two families of efficient algorithms for propositional inference on Model checking: § Complete backtracking search algorithms – DPLL algorithm (Davis, Putnam, Logemann, Loveland) § Incomplete local search algorithms – Walk. SAT algorithm 39/46
The DPLL algorithm Determine if an input propositional logic sentence (in CNF) is satisfiable. . ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺭﻭﺵ ﻋﻤﻖ ﺍﻭﻝ ﺑﺮﺍﻱ ﻳﺎﻓﺘﻦ ﻣﺪﻝ Improvements over truth table enumeration: 1. Early termination A clause is true if any literal is true. A sentence is false if any clause is false. 2. 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. آگﺮ ﺟﻤﻠﻪ ﻣﺪﻟﻲ ﺩﺍﺷﺘﻪ ﺑﺎﺷﺪ ﻟﺬﺍ ﻣﻘﺪﺍﺭ ﺳﻤﺒﻞ ﻫﺎﻱ ﺧﺎﻟﺺ ﻣﻲ ﺗﻮﺍﻧﺪ ﺑﻪ گﻮﻧﻪ ﺍﻱ ﻣﻘﺪﺍﺭ ﺩﻫی ﺷﻮﺩﻧﺪ ﻛﻪ ﺑﻨﺪ ﻣﺮﺑﻮﻃﻪ ﺍﺷﺎﻥ ﺭﺍ . ﺻﺤﻴﺢ ﻛﻨﺪ 3. Unit clause heuristic Unit clause: only one literal in the clause The only literal in a unit clause must be true. ﺩﺭ ﻭﺍﻗﻊ ﻣﻘﺪﺍﺭ ﺩﻫی ﺗﻤﺎﻡ ﺑﻨﺪﻫﺎی ﻭﺍﺣﺪ ﻗﺒﻞ ﺍﺯ ﺍﻧﺸﻌﺎﺏ ﺩﺭﺧﺖ 40/46
The DPLL algorithm 41/46
The Walk. SAT algorithm • Incomplete, local search algorithm ﺗﺎﺑﻊ ﺍﺭﺯﻳﺎﺑﻲ ﻛﻪ ﺗﻌﺪﺍﺩ. • ﻫﺪﻑ ﻳﺎﻓﺘﻦ ﺍﻧﺘﺴﺎﺑﻲ ﺍﺳﺖ ﻛﻪ ﺗﻤﺎﻡ ﺑﻨﺪﻫﺎ ﺭﺍ ﺍﺭﺿﺎ ﻛﻨﺪ . ﺑﻨﺪﻫﺎﻱ ﺍﺭﺿﺎ ﻧﺸﺪﻩ ﺭﺍ ﺑﺸﻤﺎﺭﺩ ﺍﺯ ﻋﻬﺪﻩ ﺍﻳﻦ ﻛﺎﺭ ﺑﺮ ﻣﻲ آﻴﺪ • On every iteration, the algorithm picks an unsatisfied clause and picks a symbol in the clause to flip. It chooses randomly between two ways to pick which symbol to flip: A) a "min-conflicts" step that minimizes the number of unsatisfied clauses in the new state, and B) a random walk" step that picks the symbol randomly. • Evaluation function: The min-conflict heuristic of minimizing the number of unsatisfied clauses • Balance between greediness and randomness 42/46
The Walk. SAT algorithm 43/46
Hard satisfiability problems • Consider random 3 -CNF sentences. 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 – Hard problems seem to cluster near m/n = 4. 3 (critical point) 44/46
Hard satisfiability problems 45/46
Hard satisfiability problems • Median runtime for 100 satisfiable random 3 CNF sentences, n = 50 46/46
- Slides: 46