Скачать презентацию Artificial Intelligence 6 Representing Knowledge in Predicate Logic Скачать презентацию Artificial Intelligence 6 Representing Knowledge in Predicate Logic

4b3623d9fcf697a7aaa72c12c10d78c7.ppt

  • Количество слайдов: 35

Artificial Intelligence 6. Representing Knowledge in Predicate Logic Course V 231 Department of Computing Artificial Intelligence 6. Representing Knowledge in Predicate Logic Course V 231 Department of Computing Imperial College, London Jeremy Gow

The Case of the Silk Gloves “It was elementary my dear Watson. The killer The Case of the Silk Gloves “It was elementary my dear Watson. The killer always left a silk glove at the scene of the murder. That was his calling card. Our investigations showed that only three people have purchased such gloves in the past year. Of these, Professor Doolally and Reverend Fisheye have iron-clad alibis, so the murderer must have been Sergeant Heavyset. When he tried to murder us with that umbrella, we knew we had our man. ”

Not So Elementary “The killer always left a silk glove at the scene of Not So Elementary “The killer always left a silk glove at the scene of the murder. ” (This is inductive reasoning - guessing at a hypothesis) “That was his calling card. ” (This is abductive reasoning - choosing an explanation) “…only three people have purchased such gloves in the past year. ” (This is model generation - constructing examples) “Professor Doolally and Reverend Fisheye have iron-clad alibis. ” (This is constraint-based reasoning - ruling out possibilities) “…so the murderer must have been Sergeant Heavyset. ” (This is deductive reasoning - inferring new information from ‘known’ facts)

Bring on the Lawyers l The murderer always confesses in some way l So, Bring on the Lawyers l The murderer always confesses in some way l So, Holmes never has to defend his reasoning l This is a good job, as it’s mostly unsound l A good lawyer might point out that all the victims were coincidentally - members of the silk glove appreciation society. Where’s your case now, Mr. Holmes?

Automated Reasoning l l Very important area of AI research “Reasoning” usually means deductive Automated Reasoning l l Very important area of AI research “Reasoning” usually means deductive reasoning – l Inductive reasoning (later in course) – l New facts are deduced logically from old ones Guessing facts from old ones and from evidence Two main aspects of deductive reasoning – – – Logical representations (thousands of them) Rules of deduction (how to deduce new things) Lecture 6 and Lecture 7

Applications of Automated Reasoning l Automated theorem proving – – – Automated mathematics Axioms(A) Applications of Automated Reasoning l Automated theorem proving – – – Automated mathematics Axioms(A) are given, theorem statement(T) is given Reasoning agent searches from A to T (or from T to A) l l Using rules of deduction to move around the search space Automated verification – Hardware and Software verification l – That they perform as specified Remember the Intel chip fiasco? l Intel now have lots of people working on automated verification

First Order Predicate Logic Very important way of representing knowledge re re 6 ctu First Order Predicate Logic Very important way of representing knowledge re re 6 ctu Le FOPL Prolog Deduction Expert Systems Theorem Proving 7 Le ctu l

Syntax and Semantics l l Keep thinking of predicate logic as a language We Syntax and Semantics l l Keep thinking of predicate logic as a language We need to communicate (share knowledge) with AI agent – – l Using logic as the knowledge representation scheme Need to both inform and understand Syntax – Symbols used and how sentences are put together l l Predicates, connectives, constants, functions, variables, quantifiers Semantics – – – How we interpret sentences How we translate between the two languages How we tell the truth of a sentence

Predicates l Predicates are statements that – – l l Example: father(bob, bill) Father Predicates l Predicates are statements that – – l l Example: father(bob, bill) Father is the predicate name – – l Certain things are related in specific ways Predicate name identifies the relationship Arguments are things being related Arity is the number of things being related Relationship is (nearly) obvious: bob is bill’s father Bob and bill are the arguments (arity here is 2) Predicates can relate – Constants, functions and variables

Connectives: And, Or l “And” represented by: (i) & (ii) ∧ (iii) , – Connectives: And, Or l “And” represented by: (i) & (ii) ∧ (iii) , – l If predicates p 1 and p 2 are true then (p 1 ∧ p 2) is true “Or” represented by: (i) ∨ (ii) | (iii) ; – If either predicate p 1 or predicate p 2 is true (or both) l l Then (p 1 ∨ p 2) is true Also note the use of brackets – Indicate where to stop and work out truth values

Connectives: Not, Implies, Equivalence l “Not” represented by: (i) ┓(ii) ∼ (iii) + – Connectives: Not, Implies, Equivalence l “Not” represented by: (i) ┓(ii) ∼ (iii) + – l “Implies” represented by: → or ← – l Changes predicate truth (true to false, or false to true) If one statement is true, then another is also true “is equivalent to” represented by: ↔ – You’ll also hear: l “if and only if” & “necessary and sufficient condition”

Examples of Connectives in Use l “Simon lectures AI and bioinformatics” lectures_ai(simon) ∧ lectures_bioinformatics(simon) Examples of Connectives in Use l “Simon lectures AI and bioinformatics” lectures_ai(simon) ∧ lectures_bioinformatics(simon) Better: lectures(simon, ai) ∧ lectures(simon, bioinfo) l “If Simon isn’t lecturing AI, Bob must be” ┓lectures(simon, ai) → lectures(bob, ai) l “George and Tony will win or Saddam will lose” (will_win(george) ∧ will_win(tony)) ∨ ┓will_win(saddam)

Constants l Stand for actual things – l Such as england or barbara_woodhouse Also Constants l Stand for actual things – l Such as england or barbara_woodhouse Also use constants for specific words like blue – – But blue has different shades… In this case you should have: l l – l Made blue a predicate name, then you could have had: shade_of_blue(aqua_marine), shade_of_blue(navy), etc. Choosing predicates and constants is important Convention: use lower case letters for constants

Functions l Special predicates – – Where we think of them having inputs and Functions l Special predicates – – Where we think of them having inputs and an output If arity n, then the first n-1 arguments are inputs l l Important – l And the final argument is thought of the output Only a function if a set of inputs has a unique output Use the equals sign to make I/O clear – And to make it clear this is a function

Example of a Function l l “The cost of an omelette at the Red Example of a Function l l “The cost of an omelette at the Red Lion is £ 5” Normally: – l But cost_of is a function – – l cost_of(omelette, red_lion, five_pounds) Input: the name of a meal and the name of a pub Output: the cost of the meal So, we can write this as: – cost_of(omelette, red_lion) = five_pounds

Using Functions for Abbreviation l We want to minimise misunderstanding – l If we Using Functions for Abbreviation l We want to minimise misunderstanding – l If we want to, we can abbreviate: – – – l So, if we can, we should make sentences succinct If we are talking about the output of a function We can replace it with the predicate part i. e. , replace the RHS of equality with the LHS Example: – “Omelettes at the Red Lion cost less than pancakes at House of Pancakes” less_than(cost_of(omelette, red_lion), cost_of(pancake, pancake_house))

Variables l Want to be more expressive now – l cost_of(meal, red_lion) = 3 Variables l Want to be more expressive now – l cost_of(meal, red_lion) = 3 – – l But meal is a constant, like omelette or pancake Doesn’t express what we wanted it to We’re really talking about some general meal – – l “There’s a meal at the Red Lion which costs £ 3” Not a meal in particular Call this meal X (a variable) cost_of(X, red_lion) = 3 – Not quite right yet

Variables Continued l l Need to further express our beliefs about X We say Variables Continued l l Need to further express our beliefs about X We say that: – – l “There is such a meal X” “There exists such a meal X” We need a symbol for “there exists” – – – This is represented as: ∃ ∃ X (cost_of(X, red_lion) = 3) Still not quite right (see later)

Quantifiers l The exists sign is known as a quantifier – l l l Quantifiers l The exists sign is known as a quantifier – l l l A sentence is known as “existentially quantified” Using quantifiers is known as quantification One other quantifier: ∀ (“forall sign”) Example: “all students enjoy AI lectures” ∀ X (student(X) → enjoys(X, ai_lectures)) l This is “universally quantified” – l Forall says that each predicate involving the quantified variable is true for every possible choice of that variable Terminology: – – Constants are ‘ground variable’, and we ‘instantiate’ a variable “All meals cost £ 3” becomes “Spaghetti costs £ 3”

Be careful with quantifiers!! “There is a meal at the Red Lion which costs Be careful with quantifiers!! “There is a meal at the Red Lion which costs three pounds” ∃ X (meal(X) ∧ cost_of(red_lion, X) = 3) What about: “All the meals at the Red Lion cost three pounds” Replace exists by forall: ∀ X (meal(X) ∧ cost_of(red_lion, X) = 3) ∀ X (meal(X) → cost_of(red_lion, X) = 3) ∀ X (meal(X) & serves(red_lion, X) → cost_of(red_lion, X) =3)

More Translation Pitfalls to Avoid l l Getting ∧ and ∨ mixed up Example More Translation Pitfalls to Avoid l l Getting ∧ and ∨ mixed up Example from lecture 4 “Every Monday and Wednesday I go to John’s house for dinner” ∀ X (day(X, mon) ∨ day(X, weds) → go(me, house(john)) ∧ eat(me, dinner))

Even More Pitfalls l l l Getting confused with quantifiers Translate: “All things in Even More Pitfalls l l l Getting confused with quantifiers Translate: “All things in the bag are red” Which of these translations is correct? 1. ∃ X (in_bag(X) → red(X)) 2. ∀ X (red(X) → in_bag(X)) 3. ∀ X (∀ Y (bag(X) ∧ in_bag(Y, X) → red(Y)))

Translating Logic to English Take explicit sentence, make it more succinct l Example: ∃ Translating Logic to English Take explicit sentence, make it more succinct l Example: ∃ X (meal(X) ∧ cost_of(red_lion, X) = 3) 1. “There is something called X, where X is a meal and X costs three pounds at the Red Lion” 2. “There is a meal, X, which costs three pounds at the Red Lion” 3. “There is a meal which costs £ 3 at the Red Lion” l

The Prolog Programming Language l Declarative rather than procedural – l Ask a friend The Prolog Programming Language l Declarative rather than procedural – l Ask a friend to buy you some groceries… For declarative languages (Kowalski) – – Algorithm = Logic + Control That is, two most important aspects are: l l l The underlying logical representation chosen The search techniques underpinning the language We look at the logic and search in Prolog

From FOPL to Logic Programs l l Restrict representation to only implications Restrict implications From FOPL to Logic Programs l l Restrict representation to only implications Restrict implications to have the format ∀ Xi (P 1 ∧ P 2 ∧ … ∧ Pn → H) l l These are called Horn clauses P 1 ∧ P 2 ∧ … ∧ Pn is called the body H is called the head A collection of Horn clauses is called – A Logic Program

From Logic Programs to Prolog 1. Drop the universal quantification – This is assumed From Logic Programs to Prolog 1. Drop the universal quantification – This is assumed in Prolog 2. Write the other way around – – So that P 1 ∧ P 2 ∧ … ∧ Pn → H Becomes: H ← P 1 ∧ P 2 ∧ … ∧ Pn 3. Write ← as : – Gives us: H : - P 1 ∧ P 2 ∧ … ∧ Pn 4. Write ∧ as commas and put a full stop on the end: – l Gives us: H : - P 1 , P 2 , … , Pn. It’s now in Prolog format

Example Translation l “In every lecture, if the lecturer is good, or the subject Example Translation l “In every lecture, if the lecturer is good, or the subject matter interesting, then the students are bright and attentive” ∀ X (has_good_lecturer(X) ⌵ subject_is_interesting_in(X)) → students_bright_in(X) ∧ students_attentive_in(X)) l Written as a Prolog Logic Program: students_bright_in(X) : students_attentive_in(X) has_good_lecturer(X) subject_is_interesting(X) : - has_good_lecturer(X) : - subject_is_interesting(X)

Search in Prolog l Prolog programs consist of – l A database of many Search in Prolog l Prolog programs consist of – l A database of many Horn clauses Given a query: ? - query_predicate(X). l Prolog searches the database – – From top to bottom To match the head and arity of the query predicate l To a Horn clause already in the database

Search in Prolog Continued l l Once it has found a match for the Search in Prolog Continued l l Once it has found a match for the head It checks to see whether it can also match – – The variables in the body Does this using unification (see later lecture) l l Variables can be instantiated to constants Variables can be matched If it gets a match, we say it has proved the query Prolog has a closed world assumption – If it cannot prove a query, then the query is false

Search Example president(X) : - first_name(X, georgedubya), second_name(X, bush). prime_minister(X) : - first_name(X, maggie), Search Example president(X) : - first_name(X, georgedubya), second_name(X, bush). prime_minister(X) : - first_name(X, maggie), second_name(X, thatcher). prime_minister(X) : - first_name(X, tony), second_name(X, blair). first_name(tonyblair, tony). first_name(georgebush, georgedubya). second_name(tonyblair, blair). second_name(georgebush, bush). ? - prime_minister(P). P = tonyblair ? - + president(tonyblair) Yes

Prolog Details l Check out the notes (and Russell & Norvig) – – How Prolog Details l Check out the notes (and Russell & Norvig) – – How arithmetic is carried out How performance is measured l – Logical inferences per second (LIPS) How performance is greatly improved l l By compiling the code Either to something like C Or an intermediate language like the WAM LIPS are now in millions

OR-Parallelism of Prolog l When trying to find a match to query – l OR-Parallelism of Prolog l When trying to find a match to query – l ? - prime_minister(X) One processor takes this clause prime_minister(X) : - first_name(X, tony), second_name(X, blair). l And another processor takes this: prime_minister(X) : - first_name(X, maggie), second_name(X, thatcher).

AND-Parallelism of Prolog l When trying to find a match to query – ? AND-Parallelism of Prolog l When trying to find a match to query – ? - prime_minister(X) And looking in the database at: – prime_minister(X) : - first_name(X, tony), second_name(X, blair). – l One processor tries to match this: first_name(X, tony) l And another processor tries to match this: second_name(X, thatcher) l More tricky than OR-parallelism (variables have to match)

Expert Systems l Speak to experts in the field – – – l Determine Expert Systems l Speak to experts in the field – – – l Determine a set of important rules for the task they do Encode them in a knowledge base, e. g. , a Prolog program Use the program to try to do the expert’s task Major success in AI – In particular medical/agricultural diagnosis systems "A leading expert on lymph-node pathology describes a fiendishly difficult case to the expert system, and examines the system's diagnosis. He scoffs at the system's response. Only slightly worried, the creators of the system suggest he ask the computer for an explanation of the diagnosis. The machine points out the major factors influencing its decision and explains the subtle interaction of several of the symptoms in this case. The experts admits his error, eventually. “ l From Russell and Norvig

Example of a Prolog Expert System l Card game from last lecture – – Example of a Prolog Expert System l Card game from last lecture – – Overkill to use minimax to solve it As we can express what each player should do l l Examples (rules for player one, first move) – If there are three or four even numbered cards l – Then player one should choose the biggest even number If there are three or four odd numbered cards l l Using rules about which card to choose in which situation Then player one should choose the biggest odd number See notes for Prolog implementation of this