Você está na página 1de 48

Unit -3 Knowledge

Representation and Reasoning


Knowledge in AI
• To solve complex problems we need:
1. Large amount of knowledge
2. Mechanism for representation and manipulation
of existing knowledge to create new solution.
• Knowledge in AI studies can be represented
using logic, structure, semantics, ES rules etc.
• The language of logic can be used for the
representations of facts.
Knowledge Representation
• Knowledge Representation
– Facts: Things we want to represent. Truth in
some relevant world.
– Representation of facts.
Good Knowledge representation should
exhibit
1. Representational Adequacy: Ability to represent all
kinds of knowledge that are needed in the domain.
2. Inferential Adequacy: Ability to manipulate
representational structures such that new
knowledge can be derived/inferred from the old.
3. Inferential efficiency: Ability to incorporate additional
information into an existing knowledge base that
can be used to focus the attention of inference
mechanisms in the most promising direction.
4. Adequistional efficiency: Ability to easily acquire
new information.
Approaches to KR
1. Simple relational knowledge:
• Provides very weak inferential capabilities.
• May serve as the input to powerful inference engines.
Player Height Weight handed
Peter 6-0 180 right
Ajay 5-10 170 left
John 6-2 215 left
Vickey 6-3 205 right

Fails to infer “which right handed player can best face a


particular bowler” .

10
Approaches to KR
2. Inheritable knowledge:
• Objects are organized into classes and classes are
organized in a generalization hierarchy.
• Inheritance is a powerful form of inference, but not
adequate.
• Ex. Property inheritance inference mechanism.

isa handed
Adult male Person Right

instance

Peter Tata Consultancy 11


Works_at
Approaches to KR

3. Inferential knowledge:
• Facts represented in a logical form, which facilitates
reasoning.
• An inference engine is required.

ex. 1. “Marcus is a man”


2. “All men are mortal”
Implies:
3. “Marcus is mortal” 12
Approaches to KR

4. Procedural knowledge:
• Representation of “how to make it” rather than “what
it is”.
• May have inferential efficiency, but no inferential
adequacy and acquisitional efficiency.
• Ex. Writing LISP programs

8
Logic
• Logic is an “algebra” for manipulating only two values:
true (T) and false (F)
• Nevertheless, logic can be quite challenging
his talk will cover:
– Propositional logic--the simplest kind
– Predicate logic (predicate calculus)--an extension of
propositional logic
– Resolution theory--a general way of doing proofs in predicate
logic
– Possibly: Conversion to clause form
– Possibly: Other logics (just to make you aware that they exist)
Propositional logic
 Propositional logic consists of:
 The logical values true and false (Tand F)
 Propositions: “Sentences,” which
 Are atomic (that is, they must be treated as indivisible units, with no
internal structure), and
 Have a single logical value, either true or false
 Operators, both unary and binary; when applied to logical
values, yield logical values
 The usual operators are and, or, not, and implies
Truth tables

• Logic, like arithmetic, has operators, which apply to one, two,
or more values (operands)

• A truth table lists the results for each possible
arrangement of operands

• Order is important: x op y may or may not give the same
result as y op x

The rows in a truth table list all possible sequences of truth
values for n operands, and specify a result for each sequence

 Hence, there are 2n rows in a truth table for n operands

1
Propositional logic
• Statements used in mathematics.
• Proposition :is a declarative sentence whose value is
either true or false.
• We can easily represent real world facts as logical propositions
written as well-formed formulas (wff’s).
Examples:
• “The sky is blue.” [Atomic Proposition]
• “The sky is blue and the plants are green.”
[Molecular/Complex Proposition]
• “Today is a rainy day” [Atomic Proposition]
• “Today is Sunday” [Atomic Proposition]
• “ 2*2=4” [Atomic Proposition]
12
World
 A world is a collection of prepositions and logical
expressions relating those prepositions
 Example:
 Propositions: JohnLovesMary, MaryIsFemale, MaryIsRich
 Expressions:
MaryIsFemale  MaryIsRich  JohnLovesMary
 A proposition “says something” about the world, but
since it is atomic (you can’t look inside it to see
component parts), propositions tend to be very
specialized and inflexible
13
Model
A model is an assignment of a truth value to each proposition, for
example:
 JohnLovesMary: T, MaryIsFemale: T, MaryIsRich: F
 An expression is satisfiable if there is a model for which the
expression is true
 For example, the above model satisfies the expression
MaryIsFemale  MaryIsRich  JohnLovesMary
 An expression is valid if it is satisfied by every model
 This expression is not valid:

MaryIsFemale  MaryIsRich  JohnLovesMary


But this expression is valid:
MaryIsFemale  MaryIsFemale JohnLovesMary

14
Terminologies in propositional algebra
• Statement: sentence that can be true/false.
• Properties:
Satisfiability: a sentence is satisfy able if there is an
interpretation for which it is true.
Eg.”we wear woolen cloths”

Contradiction: if there is no interpretation for which


sentence is true.
Eg. “Japan is capital of India”

Validity: a sentence is valid if it is true for every interpretation.


Eg. “Delhi is the capital of India”
Inference Rules:
Implication elimination
 A particularly important rule allows you to get rid of the
implication operator,  :
 X  Y  X  Y
 We will use this later on as a necessary tool for
simplifying logical expressions

The symbol  means “is logically equivalent to”
Conjunction elimination
 Another important rule for simplifying logical
expressions allows you to get rid of the conjunction
(and) operator,  :
 This rule simply says that if you have an and operator at
the top level of a fact (logical expression), you can
break the expression up into two separate facts:
 MaryIsFemale  MaryIsRich

 becomes:

 MaryIsFemale

 MaryIsRich
Inference by computer
 To do inference (reasoning) by computer is basically a search
process, taking logical expressions and applying inference
rules to them
 Which logical expressions to use?
 Which inference rules to apply?
 Usually you are trying to “prove” some particular statement
 Example:
 it_is_raining  it_is_sunny
 it_is_sunny  I_stay_dry
 it_is_rainy  I_take_umbrella
 I_take_umbrella  I_stay_dry
 To prove: I_stay_dry
Forward and backward
reasoning
 Situation: You have a collection of logical expressions
(premises), and you are trying to prove some additional
logical expression (the conclusion)
 You can:
 Do forward reasoning: Start applying inference rules to the
logical expressions you have, and stop if one of your results is
the conclusion you want
 Do backward reasoning: Start from the conclusion you want,
and try to choose inference rules that will get you back to the
logical expressions you have
 With the tools we have discussed so far, neither is
feasible
Example
 Given:
 it_is_raining  it_is_sunny
 it_is_sunny  I_stay_dry
 it_is_raining  I_take_umbrella
 I_take_umbrella  I_stay_dry
 You can conclude:
 it_is_sunny  it_is_raining
 I_take_umbrella  it_is_sunny
 I_take_umbrella I_stay_dry
 Etc., etc. ... there are just too many things you can conclude!
BASICS for Predicate Logic
• Logical expressions are built out of components
– Objects (Constants)
– Variables
– Functions
• The above three are called Terms
– Predicates
– Connectives
– Quantifiers
Objects
• Symbols that denote specific things or
individuals
– JOHN
– MARY
– BASKETBALL
– TRIANGLE
Variables
• Unspecific references to objects: x, y, z
• Functions
– An argument to a function is either an object or a
variable
– Starting with a lowercase letter
– The value of a function is either an object or a variable
– exp(0) = 1
– next-day(THURSDAY) = FRIDAY
– brother(JOHN) = JIM
Predicates
(or functions returning True or False)
• Functions which denote attributes of objects
or relationships between individuals
• - Starting with a uppercase letter
– Loves(JOHN, MARY)
– Man(SOCRATES)
– Sunny(THURDAY)
Connectives
• Logical operators which computes truth values
• ^ AND
•  OR
• ¬ NOT
•  IMPLIES
• Quantifiers
– Logical operators which assert the scope of a
predicate
–  For All (universal quantifier)
–  There Exists (existential quantifier)
Examples for Conversionfrom Natural
Language Sentences to Predicate Logic

• Marcus was a man


– man(Marcus)
• Marcus was a Pompeian
– pompeian(Marcus)
• All Pompeians were Romans
–  x: [Pompeian(x)  Roman(x)]
• Caesar was a ruler
– ruler(Caesar)
• All Romans were either loyal to Caesar or
hated him
–  x :Roman(x) loyalto(x,Caesar) 
Hate(x,Caesar)
• Everyone is loyal to someone
– x: y loyalto(x,y)
• People only try to assassinate rulers they
aren't loyal to
– x: y: person(x) ^ ruler(y) ^ tryassassinate(x,y)
¬loyalto(x,y)
• Marcus tried to assassinate Caesar
– tryassassinate(Marcus, Caesar)
• Was Marcus loyal to Caesar?
¬loyalto(Marcus,Caesar)
Inference
• Infer means " to derive as a conclusion from facts or
premises".
• There are 2 common rules for deriving new facts from
rules and known facts. These are Modus Ponens and
Modus Tollens.
• Modus Ponens: most common inference strategy
simple , reasoning based on it is easily understood.
• The rule states that when A is known to be true and if a
rule states " If A then B "
it is valid to conclude that B is true.
• e.g. from “If John loves Mary, Mary is happy” and
“John loves Mary,” “Mary is happy” is inferred.
Resolution
• Resolution produces proofs by refutation
(action of proving).
• That is to prove statement, resolution
attempts to show, that the negation of that
statement contrasts.
• Clause Normal Form (CNF) is the form used by
resolution inference rule.
CNF
• Clause Normal Form (CNF) is a sub-language
of 1st order logic.
• There are satisfiability preserving
transformations from 1st order logic to CNF.
• i.e., if a set of (1st order) formulae are
satisfiable, then their CNF is satisfiable.
• Conversely is also true.
Transforming to CNF (Algorithm Steps):
1. Eliminate ->
2. Reduce the scope of each ¬ to a single term
3. Standardize variables so that each quantifiers binds a
unique variable.
4. Move all the quantifies to the left of the formula without
changing their relative order.
5. Eliminate existential quantifier.
6. Drop the prefix.
7. Convert the matrix into a conjunctions of disjunctions.
8. Create separate clause corresponding to each conjunct.
9. Standardize apart the variables in the set of clauses
generated in step 8.
Transforming to CNF.
• The first operation is to simplify the formulae
so that they contain only
the ∀, ∃, &, | and ~ connectives.
Simplify
Formula Rewrites to
(P | Q) &
P <~> Q
(~P | ~Q)
(P => Q) &
P <=> Q
(Q => P)
P => Q ~P | Q
• The second operation is to move negations
in so that they apply to only atoms.
• This is done by using known logical identities
(including De Morgan's laws), which are easily
verified as above.
Move negations in
Formula Rewrites to
~∀X P ∃X ~P
~∃X P ∀X ~P
~(P & Q) (~P | ~Q)
~(P | Q) (~P & ~Q)
~~P P
• The third operation is to move quantifiers
out so that each formula is in the scope of all
the quantifiers in that formula.
Move quantifiers out
Formula Rewrites to
∀X P & Q ∀X (P & Q)
∃X P & Q ∃X (P & Q)
Q & ∀X P ∀X (Q & P)
Q & ∃X P ∃X (Q & P)
∀X P | Q ∀X (P | Q)
∃X P | Q ∃X (P | Q)
Q | ∀X P ∀X (Q | P)
Q | ∃XP ∃X (Q | P)
• The fourth operation is to Skolemize to
remove existential quantifiers.
• This step replaces existentially quantified
variables by Solemn functions and removes all
quantifiers.
Skolemize
Formula Rewrites to
Initially Set γ = {}
∀X P P
and set γ = γ ∪ {X}
∃X P P[X/x(γ)]
where x is a new
Skolem functor
• The fifth operation is to distribute
disjunctions so that the formulae are
conjunctions of disjunctions.
• After distributing disjunctions the formulae
are in conjunctive normal form.

Distribute disjunctions
Formula Rewrites to
(P | Q) &
P | (Q & R)
(P | R)
(Q | P) &
(Q & R) | P
(R | P)
Example
Example
1st order formula
∀Y (∀X (taller(Y,X) | wise(X)) => wise(Y))
Simplify
∀Y (~∀X (taller(Y,X) | wise(X)) | wise(Y))
Move negations in
∀Y (∃X (~taller(Y,X) & ~wise(X)) | wise(Y))
Move quantifiers out
∀Y (∃X ((~taller(Y,X) & ~wise(X)) | wise(Y)))
Skolemize
∃X ((~taller(Y,X) & ~wise(X)) | wise(Y)) γ = {Y}
(~taller(Y,x(Y)) & ~wise(x(Y))) | wise(Y)
Distribute disjunctions
(~taller(Y,x(Y)) | wise(Y)) & (~wise(x(Y)) | wise(Y))
Convert to CNF
{ ~taller(Y,x(Y)) | wise(Y),
~wise(x(Y)) | wise(Y) }
Non-monotonic Reasoning
• In real world some problems are uncertain
and fuzzy.
• The different approaches to handle these are:
– Non-monotonical reasoning: In which the facts
and the rules of inference are extended to make it
possible to reason with incomplete information.
– Statistical Reasoning: In which the representation
is extended to allow some kind of numeric
measure of certainty to be associated with each
statement.
Key issues in non-monotonic reasoning
• How can the knowledge base be extended to
allow inferences to be made on the basis of lack
of knowledge as well as on the presence of it?
• How can the knowledge base be updated
properly when a new fact added to the system? –
To keep proofs called justification.
• How can knowledge be used to help resolve
conflicts when there are several inconsistent non-
monotonic inferences that can be drawn?
Default Reasoning (Non monotonic
reasoning)
• Draw conclusions based on what is most likely
to be true.
• Two common kinds of non-monotonic
reasoning:
– Abduction
– Inheritance
Abduction
 Abduction is the qaulitative,everyday reasoning.
 Deduction shows that something must be,
induction shows that something exists, and
abduction shows that something mabye.
 Abduction is that starting point of all research.

• More Precisely: “Given two wff’s (A->B) and (B),


for any expressions A and B if it is consistent to
assume A, do so.
Inheritance
• An object inherits attribute values from all the
classes of which it is a member unless doing
so leads to contradiction, in which case a
value from a more restricted class has
precedence over value from broader class.
Probabilistic Reasoning
• An important goal of many problem solving
systems is to collect evidence as the system
goes along and to modify its behavior on the
basis if the evidence.
• To model this behavior, need statistical theory
of evidence.
Bayes Theorem
• P(H i|E) = the probability that hypothesis Hi is true given
evidence E

• P(E|Hi) = the probability that we will observe evidence E given


that hypothesis Hi is true

• P(Hi)= the a priori probability that hypothesis Hi


is true in the absence of any specific evidence. These
probabilities are called prior probabilities or prios

• k = the number of possible hypotheses


Example
• S:patient has spots
• M:patient has measles
• F:patient has high fever

• Spots & Fever are not independent events and hence


we cannot just sum their effects.
• There is a need to represent explicitly the conditional
probability that arises from their conjunction
• In general, given a prior body of evidence e and some
new observation E, we need to compute
P(H|E,e) = P(H|E). P(e|E,H)
P(e|E)
Bayes' theorem is intractable for several
reasons:
– The knowledge acquisition problem is
insurmountable (too great to overcome)

– The space that would be required to store all the


probabilities is too large

– The time required to compute the probabilities is


too large

Você também pode gostar