knowledge representation

Post on 19-Jan-2015

263 Views

Category:

Education

7 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Rushdi Shams, Dept of CSE, KUET, Bangladesh 1

Knowledge Representation IIKnowledge Representation IILogicsLogics

Artificial IntelligenceArtificial IntelligenceVersion 1.0Version 1.0

There are 10 types of people in this world- who understand binary There are 10 types of people in this world- who understand binary and who do not understand binaryand who do not understand binary

Rushdi Shams, Dept of CSE, KUET, Bangladesh 2

Propositional LogicPropositional Logic

Rushdi Shams, Dept of CSE, KUET, Bangladesh 3

IntroductionNeed formal notation to represent

knowledge, allowing automated inference and problem solving.

One popular choice is use of logic.Propositional logic is the simplest.

Symbols represent facts: P, Q, etc..These are joined by logical connectives (and,

or, implication) e.g., P Λ Q; Q RGiven some statements in the logic we can

deduce new facts (e.g., from above deduce R)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 4

Syntactic Properties of Propositional Logic

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 (bi-conditional)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 5

Semantic Properties of Propositional Logic

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

Rushdi Shams, Dept of CSE, KUET, Bangladesh 6

Truth Table for Connectives

Rushdi Shams, Dept of CSE, KUET, Bangladesh 7

Model of a FormulaIf the value of the formula X holds 1 for the

assignment A, then the assignment A is called model for formula X.

That means, all assignments for which the formula X is true are models of it.

Rushdi Shams, Dept of CSE, KUET, Bangladesh 8

Model of a Formula

Rushdi Shams, Dept of CSE, KUET, Bangladesh 9

Model of a Formula: Can you do it?

Rushdi Shams, Dept of CSE, KUET, Bangladesh 10

Satisfiable FormulasIf there exist at least one model of a formula

then the formula is called satisfiable.The value of the formula is true for at least

one assignment. It plays no rule how many models the formula has.

Rushdi Shams, Dept of CSE, KUET, Bangladesh 11

Satisfiable Formulas

Rushdi Shams, Dept of CSE, KUET, Bangladesh 12

Valid FormulasA formula is called valid (or tautology) if all

assignments are models of this formula.The value of the formula is true for all

assignments. If a tautology is part of a more complex formula then you could replace it by the value 1.

Rushdi Shams, Dept of CSE, KUET, Bangladesh 13

Valid Formulas

Rushdi Shams, Dept of CSE, KUET, Bangladesh 14

Unsatisfiable FormulasA formula is unsatisfiable if none of its

assignment is true in no models

Rushdi Shams, Dept of CSE, KUET, Bangladesh 15

Logical equivalenceTwo sentences are logically equivalent iff true in same

models: α ≡ ß iff α╞ β and β╞ α

Rushdi Shams, Dept of CSE, KUET, Bangladesh 16

Deduction: Rule of Inference

1.Either cat fur was found at the scene of the crime, or dog fur was found at the scene of the crime. (Premise)

C v D

Rushdi Shams, Dept of CSE, KUET, Bangladesh 17

Deduction: Rule of Inference

2.If dog fur was found at the scene of the crime, then officer Thompson had an allergy attack. (Premise)

D → A

Rushdi Shams, Dept of CSE, KUET, Bangladesh 18

Deduction: Rule of Inference

3.If cat fur was found at the scene of the crime, then Macavity is responsible for the crime. (Premise)

C → M

Rushdi Shams, Dept of CSE, KUET, Bangladesh 19

Deduction: Rule of Inference

4.Officer Thompson did not have an allergy attack. (Premise)

¬ A

Rushdi Shams, Dept of CSE, KUET, Bangladesh 20

Deduction: Rule of Inference

5.Dog fur was not found at the scene of the crime. (Follows from 2 D → A and 4. ¬ A). When is ¬ A true? When A is false- right? Now, take a look at the implication truth table. Find what is the value of D when A is false and D → A is true

¬ D

Rushdi Shams, Dept of CSE, KUET, Bangladesh 21

Rules for Inference: Modus TollensIf given α → β

and we know ¬β       Then ¬α

Rushdi Shams, Dept of CSE, KUET, Bangladesh 22

Deduction: Rule of Inference

6.Cat fur was found at the scene of the crime. (Follows from 1 C v D and 5 ¬ D). When is ¬ D true? When D is false- right? Now, take a look at the OR truth table. Find what is the value of C when D is false and C V D is true

C

Rushdi Shams, Dept of CSE, KUET, Bangladesh 23

Rules for Inference: Disjunctive SyllogismIf given α v β

and we know ¬α       then β

If given α v βand we know ¬β       then α

Rushdi Shams, Dept of CSE, KUET, Bangladesh 24

Deduction: Rule of Inference

7.Macavity is responsible for the crime. (Conclusion. Follows from 3 C → M and 6 C). When is C → M true given that C is true? Take a look at the Implication truth table.

M

Rushdi Shams, Dept of CSE, KUET, Bangladesh 25

Rules for Inference: Modus PonensIf given α → β

and we know α         Then β

Rushdi Shams, Dept of CSE, KUET, Bangladesh 26

Conjunctive Normal Form (CNF)A formula is in conjunctive normal form

(CNF) if it is a conjunction (AND) of clauses, where a clause is a disjunction (OR) of literals or a single literal.

It is similar to the canonical product of sums form used in circuit theory

All of the following formulas are in CNF:

Rushdi Shams, Dept of CSE, KUET, Bangladesh 27

Conjunctive Normal Form (CNF)The following formulae are not in CNF:

The above three formulas are respectively equivalent to the following three formulas that are in conjunctive normal form:

Rushdi Shams, Dept of CSE, KUET, Bangladesh 28

Conjunctive Normal Form (CNF)Eliminate implication with its equivalence.

This will turn P → Q into ¬ P V QUse de Morgan's law to move the  ¬  symbol

onto atoms (not sentences), replace:

Perform the following operation:

Rushdi Shams, Dept of CSE, KUET, Bangladesh 29

CNF

(p ^ ~q) V (r V s) ^ (r V t)(p V r V s ) ^ (p V r V t) ^ (~q V r V s)^(~q V r V t)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 30

Horn Clause A Horn clause is a clause with at most one positive

literal. Any Horn clause therefore belongs to one of four

categories: 1. A rule: 1 positive literal, at least 1 negative literal.

A rule has the form "~P1 V ~P2 V ... V ~Pk V Q". 

2. A fact or unit: 1 positive literal, 0 negative literals.  3. A negated goal : 0 positive literals, at least 1

negative literal. 4. The null clause: 0 positive and 0 negative literals.

Appears only as the end of a resolution proof.

Rushdi Shams, Dept of CSE, KUET, Bangladesh 31

First Order Logic orFirst Order Logic orFirst Order Predicate Logic orFirst Order Predicate Logic or

Predicate LogicPredicate Logic

Rushdi Shams, Dept of CSE, KUET, Bangladesh 32

IntroductionPropositional logic is declarativePropositional logic allows partial/disjunctive/negated

information(unlike most data structures and databases)

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 “if any student sits an exam they either pass or fail”.

Propositional logic is compositional(meaning of B ^ P is derived from meaning of B and of P)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 33

Introduction You see that we can convert the sentences

into propositional logic but it is difficultThus, we will use the foundation of

propositional logic and build a more expressive logic

Rushdi Shams, Dept of CSE, KUET, Bangladesh 34

IntroductionWhereas propositional logic assumes the

world contains facts,first-order logic (like natural language)

assumes the world containsObjects: people, houses, numbers, colors,

baseball games, wars, …Relations: red, round, prime, brother of, bigger

than, part of, comes between, …Functions: father of, best friend, one more

than, plus, …

Rushdi Shams, Dept of CSE, KUET, Bangladesh 35

Syntax of FOL: Basic ElementsConstants KingJohn, 2, NUS,... Predicates Brother, >,...Functions Sqrt, LeftLegOf,...Variables x, y, a, b,...Connectives , , , , Equality = Quantifiers ,

Rushdi Shams, Dept of CSE, KUET, Bangladesh 36

ExamplesKing John and Richard the Lion heart are

brothersBrother(KingJohn,RichardTheLionheart)

The length of left leg of Richard is greater than the length of left leg of King John> (Length(LeftLegOf(Richard)),Length(LeftLegOf(KingJohn)))

Rushdi Shams, Dept of CSE, KUET, Bangladesh 37

Atomic Sentences

Rushdi Shams, Dept of CSE, KUET, Bangladesh 38

Atomic Sentences

Rushdi Shams, Dept of CSE, KUET, Bangladesh 39

Complex SentencesComplex sentences are made from atomic sentences

using connectives:S, S1 S2, S1 S2, S1 S2, S1 S2,

Example

Sibling(KingJohn,Richard) Sibling(Richard,KingJohn)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 40

Complex Sentences

Rushdi Shams, Dept of CSE, KUET, Bangladesh 41

FOL illustrated Five objects-1. Richard the Lionheart2. Evil King John3. Left leg of Richard4. Left leg of John5. The crown

Rushdi Shams, Dept of CSE, KUET, Bangladesh 42

FOL illustrated Objects are related with

Relations For example, King John

and Richard are related with Brother relationship

This relationship can be denoted by(Richard,John),(John,Richard)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 43

FOL illustrated Again, the crown and

King John are related with OnHead Relationship-OnHead (Crown,John)

Brother and OnHead are binary relations as they relate couple of objects.

Rushdi Shams, Dept of CSE, KUET, Bangladesh 44

FOL illustrated Properties are relations

that are unary. In this case, Person can

be such property acting upon both Richard and JohnPerson (Richard)Person (John)

Again, king can be acted only upon JohnKing (John)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 45

FOL illustrated Certain relationships

are best performed when expressed as functions.

Means one object is related with exactly one object.Richard -> Richard’s left legJohn -> John’s left leg

Rushdi Shams, Dept of CSE, KUET, Bangladesh 46

Universal quantification<variables> <sentence>

Everyone studies at KUET is smart:

x Studies (x,KUET) 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

Rushdi Shams, Dept of CSE, KUET, Bangladesh 47

Universal quantification Remember, we had five

objects, let us replace them with a variable x-

1. x ―›Richard the Lionheart

2. x ―› Evil King John3. x ―› Left leg of Richard4. x ―› Left leg of John5. x ―› The crown

Rushdi Shams, Dept of CSE, KUET, Bangladesh 48

Universal quantification Now, for the quantified

sentencex King (x) Person (x)

Richard is king Richard is Person

John is king John is personRichard’s left leg is king

Richard’s left leg is personJohn’s left leg is king John’s

left leg is personThe crown is king the crown is

person

Rushdi Shams, Dept of CSE, KUET, Bangladesh 49

Universal quantificationRichard is king Richard is

PersonJohn is king John is personRichard’s left leg is king

Richard’s left leg is person

John’s left leg is king John’s left leg is person

The crown is king the crown is person

Only the second sentence is correct, the rest is incorrect

Rushdi Shams, Dept of CSE, KUET, Bangladesh 50

A common mistake to avoidTypically, is the main connective with

Common mistake: using as the main connective with :

x Studies (x,KUET) Smart (x)

means “Everyone Studies at KUET and everyone is smart”

Rushdi Shams, Dept of CSE, KUET, Bangladesh 51

Existential Quantification<variables> <sentence>

Someone studies at KUET is smart:x Studies (x,KUET) 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

Rushdi Shams, Dept of CSE, KUET, Bangladesh 52

Another common mistake to avoidTypically, is the main connective with

Common mistake: using as the main connective with :

x Studies (x,KUET) Smart (x)

means some guys, if they study in KUET, then they are smart

Rushdi Shams, Dept of CSE, KUET, Bangladesh 53

Properties of quantifiers

x y is the same as y x

x y is the same as y x

x y is not the same as y x

Rushdi Shams, Dept of CSE, KUET, Bangladesh 54

Properties of quantifiersx 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”

Rushdi Shams, Dept of CSE, KUET, Bangladesh 55

Properties of quantifiersQuantifier duality: each can be expressed using

the other

x Likes(x,IceCream) is equivalent to x Likes(x,IceCream)

x Likes(x,Broccoli) is equivalent tox Likes(x,Broccoli)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 56

Properties of quantifiers Equivalences-1. x P is equivalent to x P2. x P is equivalent to x P3. x P is equivalent to x P4. x P is equivalent to x P

Rushdi Shams, Dept of CSE, KUET, Bangladesh 57

Equalityterm1 = term2 is true under a given interpretation if

and only if term1 and term2 refer to the same object

E.g., definition of 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)]

Rushdi Shams, Dept of CSE, KUET, Bangladesh 58

Example knowledge baseThe law says that it is a crime for an

American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.

Prove that Col. West is a criminal

Rushdi Shams, Dept of CSE, KUET, Bangladesh 59

Example knowledge base... it is a crime for an American to sell weapons to hostile nations:

American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)Nono … has some missiles,

Owns(Nono,x)Missile(x)

… all of its missiles were sold to it by Colonel WestMissile(x) Owns(Nono,x) Sells(West,x,Nono)

Missiles are weapons:Missile(x) Weapon(x)

An enemy of America counts as "hostile“:Enemy(x,America) Hostile(x)

West, who is American …American(West)

The country Nono, an enemy of America …Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 60

Forward ChainingAmerican(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(x,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 61

Forward ChainingAmerican(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(x,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 62

Forward ChainingAmerican(West) Weapon(y) Sells(x,y,z)

Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(x,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 63

Forward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(x,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 64

Forward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(x,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 65

Forward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(x)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 66

Forward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(z) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 67

Forward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 68

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 69

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 70

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 71

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 72

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,z)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 73

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,Nono)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 74

Backward ChainingAmerican(West) Weapon(y) Sells(West,y,Nono)

Hostile(Nono) Criminal(x)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 75

…& the InferenceAmerican(West) Weapon(y) Sells(West,y,Nono)

Hostile(Nono) Criminal(West)

Owns(Nono,x)Missile(x)Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missile(x) Weapon(x)Enemy(Nono,America) Hostile(Nono)American(West)Enemy(Nono,America)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 76

Probability: Logic for Probability: Logic for UncertaintyUncertainty

Rushdi Shams, Dept of CSE, KUET, Bangladesh 77

Conditional ProbabilityDefinition of conditional probability:

P(a | b) = P(a b) / P(b) if P(b) > 0Product rule gives an alternative formulation:

P(a b) = P(a | b) P(b) = P(b | a) P(a)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 78

Inference with Probability

Rushdi Shams, Dept of CSE, KUET, Bangladesh 79

Inference in ProbabilityP(toothache) =

0.108 + 0.012 + 0.016 + 0.064 = 0.2

Rushdi Shams, Dept of CSE, KUET, Bangladesh 80

Inference in ProbabilityP(cavity V toothache) =

0.108 + 0.012 + 0.072 + .008 + 0.016 + 0.064 = 0.28

Rushdi Shams, Dept of CSE, KUET, Bangladesh 81

Inference in ProbabilityCan also compute conditional probabilities:

Rushdi Shams, Dept of CSE, KUET, Bangladesh 82

Inference in ProbabilityCan also compute conditional probabilities:

Rushdi Shams, Dept of CSE, KUET, Bangladesh 83

Baye’s RuleProduct rule gives an alternative formulation:

P(a b) = P(a | b) P(b) = P(b | a) P(a)

Joining them together, we can find-P(a | b) = P(b | a) P(a)

P(b)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 84

Application of Bayes’ RuleA doctor knows that the disease meningitis causes the patient to have a stiff neck is 50%Means probability of stiff neck given the probability of having meningitis P(s | m) = 0.5He also knows that in every 50000 patients, 1 may have meningitisMeans probability that a patient has meningitisP (m) = 1/50000He also knows that in every 20 patients, 1 may have stiff neckMeans probability that a patient has meningitisP (m) = 1/20Then, from Bayes’ ruleP(m | s) = P(s | m) P(m)

P(s)

Rushdi Shams, Dept of CSE, KUET, Bangladesh 85

Application of Bayes’ RuleP(m | s) = P(s | m) P(m)

P(s)= 0.5 X (1/50000)

1/20= 0.0002

Means he can expect only 1 in 5000 patients with a stiff neck

to have meningitis

Rushdi Shams, Dept of CSE, KUET, Bangladesh 86

ReferencesArtificial Intelligence: A Modern Approach

(2nd Edition)by Russell and NorvigChapter 7, 8, 9, 13

http://www.iep.utm.edu/p/prop-log.htm#H5 http://www.cs.yale.edu/homes/cc392/node5.h

tml

http://www.cs.nyu.edu/courses/spring03/G22.2560-001/horn.html

Rushdi Shams, Dept of CSE, KUET, Bangladesh 87

Acknowledgement Dr. Adel Elsayed

Research Leader, M3C Lab, University of Bolton, UK

Weiqiang WeiPhD Student, University of Bolton, UK

top related