Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College.

Slides:



Advertisements
Similar presentations
Russell and Norvig Chapter 7
Advertisements

Inference Rules Universal Instantiation Existential Generalization
UIUC CS 497: Section EA Lecture #2 Reasoning in Artificial Intelligence Professor: Eyal Amir Spring Semester 2004.
Methods of Proof Chapter 7, second half.. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound)
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
Agents That Reason Logically Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2004.
Methods of Proof Chapter 7, Part II. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound) generation.
Propositional Logic Reading: C , C Logic: Outline Propositional Logic Inference in Propositional Logic First-order logic.
Logic.
Proof methods Proof methods divide into (roughly) two kinds: –Application of inference rules Legitimate (sound) generation of new sentences from old Proof.
Logic in general Logics are formal languages for representing information such that conclusions can be drawn Syntax defines the sentences in the language.
Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Fall 2005.
Knowledge Representation & Reasoning.  Introduction How can we formalize our knowledge about the world so that:  We can reason about it?  We can do.
ITCS 3153 Artificial Intelligence Lecture 11 Logical Agents Chapter 7 Lecture 11 Logical Agents Chapter 7.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Lecture 9 Jim Martin.
Logical Agents Chapter 7. Why Do We Need Logic? Problem-solving agents were very inflexible: hard code every possible state. Search is almost always exponential.
Knowledge Representation & Reasoning (Part 1) Propositional Logic chapter 6 Dr Souham Meshoul CAP492.
Logical Agents Chapter 7. Why Do We Need Logic? Problem-solving agents were very inflexible: hard code every possible state. Search is almost always exponential.
Knowledge in intelligent systems So far, we’ve used relatively specialized, naïve agents. How can we build agents that incorporate knowledge and a memory?
Logical Agents Chapter 7.
Methods of Proof Chapter 7, second half.
Knoweldge Representation & Reasoning
Knowledge Representation & Reasoning (Part 1) Propositional Logic chapter 5 Dr Souham Meshoul CAP492.
Logical Agents Chapter 7 Feb 26, Knowledge and Reasoning Knowledge of action outcome enables problem solving –a reflex agent can only find way from.
Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2005.
Logical Agents Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2008.
Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip )
Propositional Logic Reasoning correctly computationally Chapter 7 or 8.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
Inference is a process of building a proof of a sentence, or put it differently inference is an implementation of the entailment relation between sentences.
Logical Agents Chapter 7 (based on slides from Stuart Russell and Hwee Tou Ng)
February 20, 2006AI: Chapter 7: Logical Agents1 Artificial Intelligence Chapter 7: Logical Agents Michael Scherger Department of Computer Science Kent.
1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.
CS 4100 Artificial Intelligence Prof. C. Hafner Class Notes Jan 19, 2012.
Knowledge Representation Use of logic. Artificial agents need Knowledge and reasoning power Can combine GK with current percepts Build up KB incrementally.
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
Logical Agents Logic Propositional Logic Summary
1 Knowledge Representation. 2 Definitions Knowledge Base Knowledge Base A set of representations of facts about the world. A set of representations of.
Dr. Shazzad Hosain Department of EECS North South Universtiy Lecture 04 – Part A Knowledge Representation and Reasoning.
Logical Agents Chapter 7. Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence,
Logical Agents Chapter 7. Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence,
Class Project Due at end of finals week Essentially anything you want, so long as its AI related and I approve Any programming language you want In pairs.
An Introduction to Artificial Intelligence – CE Chapter 7- Logical Agents Ramin Halavati
S P Vimal, Department of CSIS, BITS, Pilani
Logical Agents Chapter 7. Knowledge bases Knowledge base (KB): set of sentences in a formal language Inference: deriving new sentences from the KB. E.g.:
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
1 Logical Agents Chapter 7. 2 A simple knowledge-based agent The agent must be able to: –Represent states, actions, etc. –Incorporate new percepts –Update.
LDK R Logics for Data and Knowledge Representation Propositional Logic: Reasoning First version by Alessandro Agostini and Fausto Giunchiglia Second version.
Logical Agents Chapter 7. Outline Knowledge-based agents Logic in general Propositional (Boolean) logic Equivalence, validity, satisfiability.
1 Logical Inference Algorithms CS 171/271 (Chapter 7, continued) Some text and images in these slides were drawn from Russel & Norvig’s published material.
1 The Wumpus Game StenchBreeze Stench Gold Breeze StenchBreeze Start  Breeze.
© Copyright 2008 STI INNSBRUCK Intelligent Systems Propositional Logic.
Dr. Shazzad Hosain Department of EECS North South Universtiy Lecture 04 – Part B Propositional Logic.
1 Propositional Logic Limits The expressive power of propositional logic is limited. The assumption is that everything can be expressed by simple facts.
Logical Agents Chapter 7. Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence,
Logical Agents Chapter 7. Outline Knowledge-based agents Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem.
Logical Agents Chapter 7. Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence,
Logical Agents Chapter 7. Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence,
Logical Agents Chapter 7 Part I. 2 Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic.
Proof Methods for Propositional Logic CIS 391 – Intro to Artificial Intelligence.
Logical Agents. Inference : Example 1 How many variables? 3 variables A,B,C How many models? 2 3 = 8 models.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
ECE457 Applied Artificial Intelligence Fall 2007 Lecture #6
EA C461 Artificial Intelligence
EA C461 – Artificial Intelligence Logical Agent
Logical Agents Chapter 7 Selected and slightly modified slides from
Artificial Intelligence
Artificial Intelligence: Agents and Propositional Logic.
CS 416 Artificial Intelligence
Methods of Proof Chapter 7, second half.
Presentation transcript:

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 MxN 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 stench[Wumpus]stench Glitter [gold] stench, breeze [start]breeze[Pit]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 ( ) * 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 …primitive sent.  sentencenot ( sentence  sentence )and ( sentence  sentence )or ( sentence  sentence )implies (if) ( sentence  sentence )if & only if (iff) ( sentence ) 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 ABC A  BA  CB  C FFFFFF FFTFFF FTFFFF FTTFFT TFFFFF TFTFTF TTFTFF TTTTTT A,B, Entails A  B A^C, C does not entail B  C

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: S1  S2 and S1, derive S2 And-elimination –Given: S1  S2, derive S1 –Given: S1  S2, derive S2 DeMorgan’s Law –Given  ( A  B) derive  A   B –Given  ( A  B) derive  A   B More on p. 210

Example Proof by Deduction Knowledge S1: B 22  ( P 21  P 23  P 12  P 32 )rule S2:  B 22 observation Inferences S3: (B 22  (P 21  P 23  P 12  P 32 ))  ((P 21  P 23  P 12  P 32 )  B 22 ) [S1,bi elim] S4: ((P 21  P 23  P 12  P 32 )  B 22 ) [S3, and elim] S5: (  B 22   ( P 21  P 23  P 12  P 32 )) [contrapos] S6:  (P 21  P 23  P 12  P 32 ) [S2,S6, MP] S7:  P 21   P 23   P 12   P 32 [S6, DeMorg]

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 …  P n, and  P 1  Q 1 …  Q m –Conclude: P 2  P 3 …  P n  Q 1 …  Q m 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 ) 2. 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 ) 3. 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 3SAT 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:- body1, body2, body3 … –English: “To prove the head, prove body1, …” –Implication: If (body1, body2 …) 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