Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram
- Slides: 25
Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College
Knowledge Based Agents • Representation – How is the knowledge stored by the agent? – Procedural vs. Declarative • Reasoning – How is the knowledge used… • To solve a problem? • To generate more knowledge? • Generic Functions – TELL (add a fact to the knowledge base) – ASK (get next action based on info in KB)
Hunt the Wumpus • Game is played in a Mx. N grid • One player, one wumpus, one or more pits • Goal: find gold while avoiding wumpus and pits • Percepts: – Glitter (gold is in this square) – Stench (wumpus is within 1 square N, E, S, W) – Breeze (pit is within 1 square N, E, S, W)
Wumpus Example [start] stench [Wumpus] Glitter [gold] stench, breeze [Pit] stench breeze
Examples of reasoning • If the player is in square (1, 0) and the percept is breeze, then there must be a pit in (0, 0) or a pit in (2, 0) or a pit in (1, 1). • If the player is in (0, 0) [and still alive], there is not a pit in (0, 0). • If there is no breeze in (0, 0), there is no pit in (0, 1) • If there is also no breeze in (0, 1) then there is no pit in (1, 1). • Therefore, there must be a pit in (2, 0)
Formalizing Reasoning • Information is represented in sentences, which must have correct syntax ( 1 + 2 ) * 7 = 21 vs. 2 ) + 7 = * ( 1 21 • The meaning of a sentence (semantics) defines its truth in each model (possible world) • One sentence entails another sentence if the second one follows logically from the first; i. e. every model that has the first true, also has the second true. • Inference is the process of deriving a specific sentence from a KB (where the sentence must be entailed by the KB)
Desirable properties of an inference algorithm • Soundness – Only sentences that are entailed by a KB will be derived by the inference algorithm • Completeness – Every sentence that is entailed by a KB will be derived by the inference algorithm (eventually) • If these properties are true, then every sentence derived from a true KB will be true in the world. – All reasoning can be done in a model, not the world!
Propositional Logic • Syntax: Sentence -> true, false, P, Q, R … sentence ( sentence ) ( sentence ) ( sentence ) primitive sent. not and or implies (if) if & only if (iff) • Note: propositional logic can be directly implemented in hardware using logic gates for operations
Propositional Logic Sentences • If there is a pit at [1, 1], there is a breeze at [1, 0] P 11 B 10 • There is a breeze at [2, 2], if and only if there is a pit in the neighborhood B 22 ( P 21 P 23 P 12 P 32 ) • There is no breeze at [2, 2] B 22
Propositional Logic Inference • Question: Does KB entail S? • Method 1: Truth Table Entailment – Construct a truth table whose columns are all propositions used in the sentences in KB. – If S is true everywhere all sentences in KB are true, then KB entails S (otherwise not) • Method 2: Proof – Proof by deduction – Proof by contradiction – Etc.
Truth Table Entailment A F F F B F F T C F T F A B F F F A C F F F B C F F F A^C, C does not entail B C F T T T F T F F F T T F F F T A, B, Entails A B
Truth Table Entailment is… • Sound – by definition, since it directly implements the definition of entailment • Complete – Only when the KB (and therefore the truth table) is finite • Time consuming – The truth table size is 2 number of statements , and we have to check every row!
Rules for Deductive Proofs • Modus Ponens – Given: S 1 S 2 and S 1, derive S 2 • And-elimination – Given: S 1 S 2, derive S 1 – Given: S 1 S 2, derive S 2 • De. Morgan’s Law – Given ( A B) derive A B • More on p. 210
Example Proof by Deduction • Knowledge S 1: B 22 ( P 21 P 23 P 12 P 32 ) S 2: B 22 rule observation • Inferences S 3: (B 22 (P 21 P 23 P 12 P 32 )) ((P 21 P 23 P 12 P 32 ) B 22) [S 1, bi elim] S 4: ((P 21 P 23 P 12 P 32 ) B 22) [S 3, and elim] S 5: ( B 22 ( P 21 P 23 P 12 P 32 )) [contrapos] S 6: (P 21 P 23 P 12 P 32 ) [S 2, S 6, MP] S 7: P 21 P 23 P 12 P 32 [S 6, De. Morg]
Evaluation of Deductive Inference (using p. 110 rules) • Sound – Yes, because the inference rules themselves are sound. (This can be proven using a truth table argument). • Complete – If we allow all possible inference rules, we’re searching in an infinite space, hence not complete – If we limit inference rules, we run the risk of leaving out the necessary one… • Monotonic – If we have a proof, adding information to the DB will not invalidate the proof
Resolution • Resolution allows a complete inference mechanism (search-based) using only one rule of inference • Resolution rule: – Given: P 1 P 2 P 3 … Pn, and P 1 Q 1 … Qm – Conclude: P 2 P 3 … Pn Q 1 … Qm Complementary literals P 1 and P 1 “cancel out” • Why it works: – Consider 2 cases: P 1 is true, and P 1 is false
Resolution in Wumpus World • There is a pit at 2, 1 or 2, 3 or 1, 2 or 3, 2 – P 21 P 23 P 12 P 32 • There is no pit at 2, 1 – P 21 • Therefore (by resolution) the pit must be at 2, 3 or 1, 2 or 3, 2 – P 23 P 12 P 32
Proof using Resolution • To prove a fact P, repeatedly apply resolution until either: – No new clauses can be added, (KB does not entail P) – The empty clause is derived (KB does entail P) • This is proof by contradiction: if we prove that KB P derives a contradiction (empty clause) and we know KB is true, then P must be false, so P must be true! • To apply resolution mechanically, facts need to be in Conjunctive Normal Form (CNF) • To carry out the proof, need a search mechanism that will enumerate all possible resolutions.
Conjunctive Normal Form for B 22 ( P 21 P 23 P 12 P 32 ) 1. Eliminate , replacing with two implications (B 22 ( P 21 P 23 P 12 P 32 )) ((P 21 P 23 P 12 P 32 ) B 22) • Replace implication (A B) by A B ( B 22 ( P 21 P 23 P 12 P 32 )) ( (P 21 P 23 P 12 P 32 ) B 22) 1. Move “inwards” (unnecessary parens removed) ( B 22 P 21 P 23 P 12 P 32 ) ( ( P 21 P 23 P 12 P 32 ) B 22) 4. Distributive Law ( B 22 P 21 P 23 P 12 P 32 ) ( P 21 B 22) ( P 23 B 22) ( P 12 B 22) ( P 32 B 22) (Final result has 5 clauses)
Resolution Example • Given B 22 and P 21 and P 23 and P 32 , prove P 12 • ( B 22 P 21 P 23 P 12 P 32 ) ; P 12 • ( B 22 P 21 P 23 P 32 ) ; P 21 • ( B 22 P 23 P 32 ) ; P 23 • ( B 22 P 32 ) ; P 32 • ( B 22) ; B 22 • [empty clause]
Mechanical Approach to Resolution • Use DFS in “clause space” – Initial state is Not (whatever is being proven) – Goal state is Empty clause – Next state generator finds all clauses in the KB [that include negations of one or more propositions in the current state]; next states are resolutions of those clauses with current state • Like all DFS, this is worst-case exponential (search all possible clauses)
Evaluation of Resolution • Resolution is sound – Becase the resolution rule is true in all cases • Resolution is complete – Provided a complete search method is used to find the proof, if a proof can be found it will – Note: you must know what you’re trying to prove in order to prove it! • Resolution is exponential – The number of clauses that we must search grows exponentially… – If it didn’t we could use resolution to solve 3 SAT in polynomial time!
Horn Clauses • A Horn Clause is a CNF clause with exactly one positive literal – – – The positive literal is called the head The negative literals are called the body Prolog: head: - body 1, body 2, body 3 … English: “To prove the head, prove body 1, …” Implication: If (body 1, body 2 …) then head • Horn Clauses form the basis of forward and backward chaining • The Prolog language is based on Horn Clauses • Deciding entailment with Horn Clauses is linear in the size of the knowledge base
Reasoning with Horn Clauses • Forward Chaining – For each new piece of data, generate all new facts, until the desired fact is generated – Data-directed reasoning • Backward Chaining – To prove the goal, find a clause that contains the goal as its head, and prove the body recursively – (Backtrack when you chose the wrong clause) – Goal-directed reasoning
First Order Logic (ch. 8) • Has a greater expressive power than propositional logic – We no longer need a separate rule for each square to say which other squares are breezy/pits • Allows for facts, objects, and relations – In programming terms, allows classes, functions and variables
- Cpsc 386
- Cpsc 322: introduction to artificial intelligence
- Cpsc 322 ubc
- Inference in first order logic in artificial intelligence
- Map of shannon river
- Strengths and weaknesses of evolutionary theory page 386
- The square and compasses
- Hiram na salita
- 8 emerging technologies
- Optimal decisions in games in artificial intelligence
- Dart expert system
- Total order planning in artificial intelligence
- Int 404
- Ao * algorithm
- Artificial intelligence chapter 1
- Number of fuzzy propositions
- Best for search
- Steps towards artificial intelligence
- Fundamentals of artificial intelligence
- Artificial intelligence devices
- Athena machine learning
- Knowledge manipulation in artificial intelligence
- Mobedic
- Artificial intelligence devices
- Rote learning in artificial intelligence
- Qualcomm smart audio 400 platform