Chapter 4 - AI - Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Chapter – 4

Knowledge and Reasoning


1. Introduction
Knowledge includes facts about the real world entities and the relationship between them

• Characteristics of Knowledge:
– It is large in nature and requires proper structuring.
– It may be incomplete and vague.
– It may keep on changing (dynamic).

2. Knowledge: What and Why?


• We are living in complex environment where there are:

– Many actors, presume, strong competitors, and high turnover

• It enables to:

– Automate reasoning , Discover new facts, Deduce new facts that follow from the
KB, and Answer users queries

– Make quality decisions - select courses of actions, etc.

– Hence, there is a need to represent knowledge to ease the development of an


intelligent system.

Motivation of Knowledge-Based (KB)

• Knowledge-Based Systems (KBSs) are useless without the ability to represent


knowledge. Agents can be seen as knowing about their world, and reasoning about their
possible courses of action. One can also design an autonomousagent that learns from
experience and construct knowledge without human interventions

• Intelligent system require:

– Knowledge(current state) of the world

• formally represented using knowledge representation language

– Inference mechanisms: Inference is deriving new sentences from old.

– Goal: what it wants to achieve

– Effect of its action: what its own action do in various circumstances


Components of a Knowledge-based Agent (KBA)

The agent is composed of:

 Knowledge base
– It operates by storing a set of sentences (facts and relationship between facts)
about the world in its KB.

(KB update)
 Inference mechanism :
– With the help of inference mechanism deduce new sentences and use them to

Learning
decide what action to take

 Learning mechanism:
– Adapt to changes in the environment by updating the relevant knowledge

(actions
Output

Knowledge
Inference

Base
Engine
environment
Input from

Knowledge Base (KB)

• Contains set of facts about the domain expressed in a suitable representation language

– Each individual representation are called sentences


– Sentences are expressed in a (formal) knowledge representation (KR) language
• A KBA is designed such that there is a way to:-

– TELL it (i.e. to add new sentences to the KB) and ASK it (i.e. to query the KBA)
– When one ASKs a question, the answer should follow from what has been
TELLed to the KB previously
– Inference mechanism determines what follows from what has been TELLed to
the KB
Inference Engine (IE)

• The Inference engine derives new sentences from the input and KB
• The agent operates as follows:
1. It receives percepts from environment
2. It computes what action it should perform (by IE and KB)
3. It performs the chosen action.

KB can be viewed at different levels

• Knowledge Level.

– The most abstract level -- describe agent by saying what it knows.


– Example: An automated taxi might be said to know that the Abay Bridge links
Kebele10 and Kebele11

• Logical Level.

– The level at which the knowledge is encoded into sentences.


– For e.g. the taxi might be described as having the logical sentences.
Links (AB,K10,K11) in our knowledge base.
• Implementation Level.

– The physical representation of the sentences in the logical level - how will it be
represented in the computer?

3. Knowledge Representation, Reasoning and Logic

• Knowledge Representation (KR): express knowledge clearly in a computer-tractable


way such that the agent can reason out.

• Reasoning: is the process of constructing new sentences from existing facts in the KB.

– Proper reasoning ensures that the new configuration represent facts that actually
follow from the facts in the KB.

Parts of KR language:

Syntax of a language: describes the possible configuration to form sentences.

E.g.: if x & y denote numbers, then x > y is a sentence about numbers

Semantics: determines the facts in the world to which the sentences refer.

E.g.: Y > X is false when X is greater than Y


Proof theory (inference rules and proof procedures)

Why KR is important ?

• It enables to:
– Automate reasoning
– Discover new facts.
– Deduce new facts that follow from the KB
– Answer users queries
– Make decisions - select courses of actions
– etc.
How is Knowledge represented?

• Knowledge is basically represented as “symbol structures” (essentially, complex data


structures) representing bits of knowledge (objects, concepts, facts, rules, strategies...)

Example: “red” represents color red.

“mycar” represents my car.

red(mycar) represents the fact that my car is red.

• Intelligent behavior can be achieved through manipulation of symbol structures

• Build KB following declarative approach

– Rather than procedural language (like C++/Java data structures), use declarative
languages (like prolog).

Logic as KR

• A Logic is a formal language in which knowledge can be represented such that


conclusions can be drawn.

– It is a declarative language to assert sentences and deduce from sentences.

• Components of a formal logic include: syntax, semantics, reasoning and inference


mechanism.

– Syntax: what expressions/structures are allowed in the language. Describes how


to make sentences

E.g. red(mycar) is ok, but mycar(grey or green) is not.

– Semantics: express what sentences mean, in terms of a mapping to real world.


• E.g. red(mycar) means that my car is red.

– Proof Theory: how we can draw new conclusions from existing statements in the
logic.

4. Why formal languages (Logic) ?

• An obvious way of expressing or representing facts and thoughts is by writing them in a


natural language such as English. However,

– The meaning of a sentence depends on the sentence itself and on the context on
which the sentence was spoken

– Natural languages exhibit ambiguity. E.g. small dogs and cats.

• Ambiguity makes reasoning difficult and incomplete.

– Hence we need formal languages to express facts and concepts in an unambiguous


and well-defined way.

Natural languages:

– Natural languages are certainly expressive,


– they help us for communication, not for representation.
– A good way for a speaker to get a listener to come to know something
– Natural language also suffers from ambiguity.
• Small dogs and cats
• Dangerous men and locations
Logics

• Logic is the science or art of reasoning


– Concerned with what is true and how we know whether something is true.
• Two kinds of Logic

– Propositional logic or Boolean Logic


– First-order Logic

5. Propositional logic

A simple language useful for showing key ideas and definitions


Syntax: PLallows facts about the world to be represented as sentences formed from:
i. Logical constants: True, False
ii. Proposition symbols (P, Q, R, …) are used to represent facts about the
world: e.g.: P = "It is hot“, Q = "It is humid“, R = "It is raining“
iii. Logical connectives: not (), and (),or (), implies (), is equivalent, if
and only if ().

1. Precedence order from highest to lowest is:


, ,,, 
e.g. The sentence P v Q R  S is equivalent to
[(P) v (Q R)]  S

2. Parenthesis ( ): Used for grouping sentences and to specify order


of precedence

Propositional logic (PL) sentences

• A sentence is made by linking prepositional symbols together using logical connectives.

– There are atomic and complex sentences.

– Atomic sentences consist of propositional symbol (e.g. P, Q, TRUE, FALSE)

– Complex sentences are combined by using connectives or parenthesis:

– while S and T are atomic sentences, S  T, (S  T), (S  T), (S  T), and (S 


T) are complex sentences.

Examples: Given the following sentences about the “weather problem” convert them into PL
sentences:

• “It is humid.”:Q

• “If it is humid, then it is hot” : Q  P

• “If it is hot and humid, then it is raining”:(P  Q)  R

A BNF(Backus-Naur form) grammar of sentences in propositional logic:

S :=<Sentence> ;

<Sentence> := <AtomicSentence> | <ComplexSentence> ;

<AtomicSentence> := "TRUE" | "FALSE" | "P" | "Q" | "S" ;

<ComplexSentence> := "(" <Sentence> ")" | <Sentence><Connective><Sentence> |"NOT"


<Sentence> ;

<Connective> := "NOT" | "AND" | "OR" | "IMPLIES" | "EQUIVALENT" ;

Exercise: 1
Convert the following English sentences to Propositional logic. Let:

A = Sara is absolutely beautiful

R = her personality is perfect

P = dawit will in love with Sara

• Sara is not absolutely beautiful:A

• Sara is absolutely beautiful andher personality is perfect:A  R

• either Sara is absolutely beautiful orher personality is perfect : A V R

• ifSara is absolutely beautiful, thenher personality is not perfect : A  R

• Sara is absolutely beautifulif and only ifher personality is perfect: A  R

• if Sara is absolutely beautiful, then if her personality is not perfect, Dawit will not in
love with Sara :A  (R P )

Exercise: 2

Examples: Convert from English to Propositional sentence

Let A= Lectures are active , R = Text is readable, P = Kebede will pass the exam,

then represent the following:

• the lectures are not active:A

• the lectures are active and the text is readable:A  R

• either the lectures are active or the text is readable: A V R

• if the lectures are active, then the text is not readable: A  R

• the lectures are active if and only if the text is readable: A  R

• if the lectures are active, then if the text is not readable, Kebede will not pass the exam:A
 (R P )

Propositional logic: Syntax

• Propositional logic is the simplest logic – illustrates basic ideas


The proposition symbols P1, P2etc are sentences

– 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 (biconditional)

Terminology

o Valid sentence: A sentence is valid sentence or tautology if and only if it is True under
all possible interpretations in all possible worlds.
Example: “It’s raining or it’s not raining.” (RR).

o Satisfiable: A sentence is satisfiable if and only if there is some interpretations in some


world for which the sentence is True.
Example: “It is raining or it is humid”. R v Q

o Unsatisfiable: A sentence is unsatisfiable (inconsistent sentence or self- contradiction) if


and only if it is not satisfiable, i.e. a sentence that is False under all interpretations.
The world is never like what it describes.

Example: “It’s raining and it's not raining.” R R

Logical equivalence

PΛT≡P Identity Laws


PVF≡P
PVT≡P Domination Values
PΛF≡P
PVP≡P Idempotent Laws
PΛP≡P

( ( p) ≡ p Double Negation elimination

pνq≡qνp Commutativity of disjunction

pΛq≡qΛp Commutativity of conjunction

(p Λ q) Λ r ≡ p Λ (q Λ r) Associativity of conjunction
(p ν q) ν r ≡ p ν (q ν r) Associativity of disjunction

p Λ (q ν r) ≡ (p Λ q) ν (p Λ r) Distributive of Λ over ν

p ν (q Λ r) ≡ (p ν q) Λ (p ν r) Distributive of ν over Λ
p  q ≡  q  p Contraposition

pq≡pνq implication elimination

 (p ν q) ≡ (p Λ q) De-Morgan

 (p Λ q) ≡ (p νq) De-Morgan

(p  q) ≡ (p q) Λ (q  p) Biconditional elimination

Inference Rules

RULE PREMISE CONCLUSION

Modus Ponens A, A  B B

Modus Tolens B, A  B A

And Elimination AB A

And Introduction A, B AB

Or Introduction A A1 A2…  An

Double Negation Elimination A A

Unit Resolution A  B, B A

Resolution A  B, B  C AC

Hypothetical Syllogism PQ, QR PR

Validity and satisfiability

A sentence is valid if it is true in all models,

e.g., True, A A, A A, (A  (A  B))  B

A sentence is satisfiable if it is true in some model


e.g., A B, C

A sentence is unsatisfiable if it is true in no models

e.g., AA

Example

• Example 1: Given the following facts and rules that relates facts; what can we say about
the weather condition?

• It is humid:
• If it is humid, then it is hot :
• If it is hot and humid, then it is raining:

– Q Premise

– QP Premise

– (P  Q)  R Premise

– P using Modes Ponens (1 & 2)

– P Q using AND introduction (1 & 4)

– R using Modes Ponens (3 & 5)

Propositional logic is a weak language

• Example: Prove that “my dog Fido is Nice, given that “all dogs are Nice.”

– This requires to get at the structure and meanings of statements (where FOL is
useful).

6. First Order Logic

• First-Order Logic (FOL) is expressive enough to concisely represent any kind of situation
that are expressed in natural language.

– FOL represents objects and relations between objects, variables, and quantifiers in
addition to propositions

Every elephant is gray:

x (elephant(x) → gray(x))

There is a white alligator:


x (alligator(X) ^ white(X))

Syntax of FOL

• Constants symbol

– names (like Jonas, Kebede, …), numbers (like 1, 2, … n), ...

• Predicates:

– Predicates used to relate one object with another. E.g. brother, >,...

• Functions: Returns value (mother-of,...)

• Variables: x, y, a, b,...

– Important to increase generalization capability of KB

• Connectives:

– retains connectives used in PL (, , , , )

• Quantifiers:

– Quantifiers specify whether all or some objects satisfy properties or relations


between objects

– Two standard quantifiers: Universal (" for all, for every) and Existential ($ there
exists, some)

1. Universal quantification

• Universal Quantifiers: makes statements about every object


<variables><sentence>
– Everyone at WKU is smart:
x At(x,WKU)  Smart(x)
– All cats are mammals:
x cat(x)  mammal(x)
x sentence P is true iffP is true with x being each possible object in the given universe

– The above statement is equivalent to the conjunction


At(Jonas, WKU)  Smart(Jonas)
At(Rawad, WKU)  Smart(Rawad)
...
• A common mistake to avoid
– Typically,  is the main connective with 
– Common mistake: the use of  as the main connective with :
x At(x,WKU)  Smart(x) is true if “Everyone is at Wku& everyone is smart”
2. Existential quantification

• Makes statements about some objects in the universe


<variables><sentence>
– Someone at WKU is smart:
x At(x,WKU)  Smart(x)
– Spot has a sister who is a cat:
x sister(spot,x)  cat(x)
x sentence P is true iffP is true with x being some possible objects

– The above statement is equivalent to the disjunction


At(Jonas, WKU)  Smart(Jonas)
At(Alemu, WKU)  Smart(Alemu)
…..
• Common mistake to avoid
– Typically,  is the main connective with 
– Common mistake: using  as the main connective with :
x At(x,WKU)  Smart(x) is true if there is anyone who is not at WKU

3. Nested quantifiers

• x,y parent(x,y)  child(y,x)


– for all x and y, if x is the parent of y then y is the child of x.
• xy Loves(x,y)
– There is a person who loves everyone in the given world
• yx Loves(x,y)
– Everyone in the given universe is loved by at least one person

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

 Quantifier duality: each can be expressed using the other, using negation ()

x Likes(x,icecream) xLikes(x,icecream)
– Everyone likes ice cream means that there is nobody who dislikes ice cream

x Likes(x,cake) xLikes(x,cake)

– There is someone who likes cake means that there is no one who dislikes cake

Sentence structure

In FOL the basic unit is a predicate (argument/terms) structure called sentence to represent facts.

• A predicate is the one that says something about the subject. E.g., There is a red book

• Subject: color of the book, represented as: x book(x)red(x)

– Predicate also refers to a particular relation between objects

• Example: likes(X, richard)

friends(motherof(jonas), motherof(semu))

– A predicate statement takes the value true or false

Sentences

Atomic sentences: formed from a predicate symbol followed by a parenthesized list of terms

Atomic sentence = predicate (term1,...,termn)

Example:Brother(John, Richard)

• Atomic sentences can have arguments that are complex terms (e.g. term = function
(term1,...,termn) )

Example:married(fatherof(Richard),motherof(John))

Complex sentences: complex sentences are made by combining atomic sentences using
connectives:

S, S1S2, S1 S2, S1S2, S1S2,

Ex. likes(john, mary) tall(mary)

tall(john) handsome(john)

Sibling(John, Richard)  Sibling(Richard, John)

• Sentences can also be formed using quantifiers to indicate how to treat variables:
– Universal quantifier: x lovely(x) - Everything is lovely.

– Existential quantifier: x lovely(x) - Something is lovely.

Exercise - 1

• Can have several quantifiers, e.g.,

xy loves(x, y)

x handsome(x) y loves(y, x)

Represent the following in FOL:

• Everything in the garden is lovely x in(x, garden)  lovely(x)

• Everyone likes ice cream x likes(x, icecream)

• Peter has some friends y friends(y, Peter)

• John plays the piano or the violinplays(john, piano) v plays(john, violin)

• Some people like snakes x(person(x) Λ likes(x, snakes))

• Winston did not write Hamlet write( winston, hamlet)

• Nobody wrote Hamlet x write(x, hamlet)

Exercise - 2

Bob is a buffalo. Pat is a pig. Buffaloes outrun pigs


Conclude: Bob outruns Pat

1. Buffalo(Bob)
2. Pig(Pat)
3. x,y Buffalo(x) ^ Pig(y)→ outrun(x,y)
4. Buffalo(Bob) ^ Pig(Pat) And Introduction (1, 2)
5. Buffalo(Bob) ^ Pig(Pat) → outrun (Bob, Pat)
6. outrun(Bob,Pat)

7. Inference Mechanisms

• Inference is a means of interpretation of knowledge in the KB to reason and give advise


to users query.
• There are two inference strategies to control and organize the steps taken to solve
problems:
– Forward chaining: also called data-driven chaining
• It starts with facts and rules in the KB and try to draw conclusions from
the data
– Backward chaining: also called goal-driven chaining
• It starts with possible solutions/goals and tries to gather information that
verifies the solution

Conclude by Chaining: Forward chaining


– Proofs start with the given axioms/premises in KB, deriving new sentences until
the goal/query sentence is derived.
– This defines a forward chaining inference procedure because it moves "forward"
from the KB to the goal.
• Example: All cats like fish, cats eat everything they like, and Ziggy is a cat. Goal query:
Does Ziggy eat fish?
1. "x cat(x) Þ likes(x, Fish)
2. "x,y (cat(x) ^ likes(x,y)) Þ eats(x,y)
3. cat(Ziggy)
– Proof: 4. likes(Ziggy, Fish) Using rule with (1) and (3) & subst{x/Ziggy}
5. eats(Ziggy, Fish) Using rule with (3), (4) and (2) So, Yes, Ziggy eats fish.

Conclude by Chaining: Backward chaining


– Proofs start with the goal query, find implications that would allow you to prove
it, continuing to work "backwards" until we get to the axioms, which we know are
true.
– To prove eats(Ziggy, Fish), first see if this is known from one of the axioms
directly. Otherwise, see if there is a Horn clause that has the consequent (i.e.,
right-hand side (RHS)) of the implication matching the goal. Here,
• Goal matches RHS of (2), so prove new sub-goals
cat(Ziggy) and likes(Ziggy, Fish) that correspond to the LHS of (2)
• cat(Ziggy) matches axiom (3), so we've "solved" that sub-goal
• likes(Ziggy, Fish) matches the RHS of (1), so prove cat(Ziggy)
• cat(Ziggy) matches (3), so we've solved this sub-goal
• There are no unsolved sub-goals,
So we conclude. Yes, Ziggy eats fish

Properties of Good KB
• A KB should be clear, correct, expressive, concise, context-insensitive and effective.
• Separate the KB from inference procedure.
• This allows the KE (creator of the KB) to focus on the content of the KB
• Define a generally applicable KB.
• Every KB has two potential consumers: human readers and inference procedure
• E.g. consider the sentence:
BearOfVerySmallBrain(Lilly).
Do you think the Inference engine be able to infer from this sentence facts such as:
Lilly is a bear or Lilly has a very small brain; that it has a brain at all

Most general KB design


• In a good KB, BearOfVerySmallBrain(Lilly) would be replaced by the following
– Lilly is a bear; bears are animals; animals are physical things, animal have a brain
• Bear(Lilly)
• "x bear(x) Þ animal(x)
• "y animal(y) Þ physicalThing(y)
– All animals have a brain, which is a part of the animal
• "z animal(z) Û brain(z)
• "x partOf(brainOf(x),x)
– Lilly has a very small brain
relativeSize(BrainOf(Lilly), BrainOf(typicalBear)) = very(small)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy