CS 8520: Artificial Intelligence

Download Report

Transcript CS 8520: Artificial Intelligence

CS 8520: Artificial Intelligence
Logical Agents and First
Order Logic
Paula Matuszek
Fall, 2005
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
1
Outline
•
•
•
•
•
•
Knowledge-based agents
Wumpus world
Logic in general - models and entailment
Propositional (Boolean) logic
Equivalence, validity, satisfiability
Inference rules and theorem proving
– forward chaining
– backward chaining
– resolution
–
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
2
Knowledge bases
• Knowledge base = set of sentences in a formal languageDeclarative
approach to building an agent (or other system):
– Tell it what it needs to know
• Then it can Ask itself what to do - answers should follow from the KB
• Agents can be viewed at the knowledge level
i.e., what they know, regardless of how implemented
• Or at the implementation level
– i.e., data structures in KB and algorithms that manipulate them
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
3
A simple knowledge-based agent
• This agent tells the KB what it sees, asks the KB what to do, tells the
KB what it has done (or is about to do).
• The agent must be able to:
–
–
–
–
–
Represent states, actions, etc.
Incorporate new percepts
Update internal representations of the world
Deduce hidden properties of the world
Deduce appropriate actions
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
4
Wumpus World PEAS Description
• Performance measure
– gold +1000, death -1000
– -1 per step, -10 for using the arrow
• Environment
–
–
–
–
–
–
–
Squares adjacent to wumpus are smelly
Squares adjacent to pit are breezy
Glitter iff gold is in the same square
Shooting kills wumpus if you are facing it
Shooting uses up the only arrow
Grabbing picks up gold if in same square
Releasing drops the gold in same square
• Sensors: Stench, Breeze, Glitter, Bump, Scream
• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
5
Wumpus world characterization
•
•
•
•
•
•
Fully Observable No – only local perception
Deterministic Yes – outcomes exactly specified
Episodic No – sequential at the level of actions
Static Yes – Wumpus and Pits do not move
Discrete Yes
Single-agent? Yes – The wumpus itself is
essentially a natural feature, not another agent
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
6
Exploring a wumpus world
Directly observed:
S: stench
B: breeze
G: glitter
A: agent
V: visited
Inferred (mostly):
OK: safe square
1,1
2,1
3,1
4,1
P: pit
W: wumpus
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
7
Exploring a wumpus world
In 1,1 we don’t get B
or S, so we know 1,2
and 2,1 are safe.
Move to 1,2.
In 1,2 we feel a
breeze.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
8
Exploring a wumpus world
In 1,2 we feel a
breeze. So we know
there is a pit in 1,3 or
2,2.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
9
Exploring a wumpus world
So go back to
1,1, then to 1,2,
where we smell a
stench.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
10
Exploring a wumpus world
We don't feel a breeze
in 2,1, so 2,2 can't be
a pit, so 1,3 must be a
pit.
We don't smell a
stench in 1,2, so 2,2
can't be the wumpus,
so 1,3 must be the
wumpus.
2,2 has neither pit nor
wumpus and is
therefore okay.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
11
Exploring a wumpus world
We move to 2,2. We
don’t get any sensory
input.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
12
Exploring a wumpus world
So we know
that 2,3 and 3,2
are ok.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
13
Exploring a wumpus world
Move to 3,2,
where we
observe stench,
breeze and
glitter!
At this point we
could infer the
existence of
another pit
(where?), but
since we have
found the gold
we don't bother.
We have won.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
14
Logic in general
• Logics are formal languages for representing information
such that conclusions can be drawn
• Syntax defines the sentences in the language
• Semantics define the "meaning" of sentences;
– i.e., define truth of a sentence in a world
• E.g., the language of arithmetic
• x+2 ≥ y is a sentence; x2+y > {} is not a sentence
– x+2 ≥ y is true iff the number x+2 is no less than the number yx+2
≥ y is true in a world where x = 7, y = 1
– x+2 ≥ y is false in a world where x = 0, y = 6
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
15
Entailment
• Entailment means that one thing follows from
another:
• Knowledge base KB entails sentence S if and only
if S is true in all worlds where KB is true
– E.g., the KB containing “the Giants won” and “the
Reds won” entails “Either the Giants won or the Reds
won”
– E.g., x+y = 4 entails 4 = x+y
– Entailment is a relationship between sentences (i.e.,
syntax) that is based on semantics
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
16
Entailment in the wumpus world
Situation after detecting
nothing in [1,1], moving
right, breeze in [2,1]
Consider possible models for
KB assuming only pits:
there are 3 Boolean choices
 8 possible models
(ignoring sensory data)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
17
Wumpus models for pits
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
18
Wumpus models
• KB = wumpus-world rules + observations. Only
the three models in red are consistent with KB.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
19
Wumpus Models
KB plus hypothesis S1 that pit is not in 1.2.
KB is solid red boundary. S1 is dotted yellow
boundary. KB is contained within S1, so KB
entails S; in every model in which KB is true, so
is S. We can conclude that the pit is not in1.2.
KB plus hypothesis S2 that pit is not in 2.2 .
KB is solid red boundary. S2 is dotted brown
boundary. KB is not within S1, so KB does not
entail S2; nor does S2 entail KB. So we can't
conclude anything about the truth of S2 given
KB.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
20
Inference
• KB entailsi S = sentence S can be derived from KB by procedure i
• Soundness: i is sound if it derives only sentences S that are entailed by
KB
• Completeness: i is complete if it derives all sentences S that are
entailed by KB.
• First-order logic:
– Has a sound and complete inference procedure
– Which will answer any question whose answer follows from what is
known by the KB.
– And is richly expressive
• We must also be aware of the issue of grounding: the connection
between our KB and the real world.
–
–
–
–
Straightforward for Wumpus or our adventure games
Much more difficult if we are reasoning about real situations
Real problems seldom perfectly grounded, because we ignore details.
Is the connection good enough to get useful answers?
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
21
Propositional logic: Syntax
• Propositional logic is the simplest logic – illustrates basic
ideas
• The proposition symbols P1, P2 etc 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)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
22
Wumpus world sentences
Let Pi,j be true if there is a pit in [i, j].
Let Bi,j be true if there is a breeze in [i, j].
 P1,1
B1,1
B2,1
• "Pits cause breezes in adjacent squares"
B1,1 
B2,1 
(P1,2  P2,1)
(P1,1  P2,2  P3,1)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
23
Inference by enumeration
• Depth-first enumeration of all models is sound and complete
• For n symbols, time complexity is O(2n), space complexity is O(n)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
24
Inference-based agents in the wumpus world
A wumpus-world agent using propositional logic:
P1,1
W1,1
Bx,y  (Px,y+1  Px,y-1  Px+1,y  Px-1,y)
Sx,y  (Wx,y+1  Wx,y-1  Wx+1,y  Wx-1,y)
W1,1  W1,2  …  W4,4
W1,1  W1,2
W1,1  W1,3
…
 64 distinct proposition symbols, 155 sentences
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
25
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
26
Expressiveness limitation of
propositional logic
• Rapid proliferation of clauses.
– For instance, Wumpus KB contains "physics" sentences for every
single square
• Very bushy inference, especially if forward chaining.
• Not trivial to express complex relationships; people don't
naturally think in logical terms.
• Monotonic: if something is true it stays true
• Binary: something is either true or false, never maybe or
unknown
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
27
Pros and cons of propositional logic
 Propositional logic is declarative
 Propositional logic allows
partial/disjunctive/negated information (unlike
most data structures and databases)
 Propositional logic is compositional:
– meaning of B1,1  P1,2 is derived from meaning of B1,1 and of P1,2
 Meaning in propositional logic is contextindependent (unlike natural language, where meaning
depends on context)
 Propositional logic has very limited expressive
power (unlike natural language)
– E.g., cannot say "pits cause breezes in adjacent squares“
• except by writing one sentence for each square
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
28
Summary
• Logical agents apply inference to a knowledge base to derive new
information and make decisions
• Basic concepts of logic:
–
–
–
–
–
–
syntax: formal structure of sentences
semantics: truth of sentences wrt models
entailment: necessary truth of one sentence given another
inference: deriving sentences from other sentences
soundness: derivations produce only entailed sentences
completeness: derivations can produce all entailed sentences
• Wumpus world requires the ability to represent partial and negated
information, reason by cases, etc.
• Resolution is complete for propositional logic
Forward, backward chaining are linear-time, complete for Horn
clauses
• Propositional logic lacks expressive power
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
29
First-order logic
• Whereas propositional logic assumes the
world contains facts,
• first-order logic (like natural language)
assumes the world contains
– Objects: 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, …
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
30
Syntax of FOL: Basic elements
•
•
•
•
•
•
•
Constants
Predicates
Functions
Variables
Connectives
Equality
Quantifiers
KingJohn, 2, Villanova,...
Brother, >,...
Sqrt, LeftLegOf,...
x, y, a, b,...
, , , , 
=
, 
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
31
Terms and Atomic sentences
• A term is a logical expression that refers to an
object.
– Book(Eric). Eric's book.
– Textbook(8520). Textbook for 8520.
• An atomic sentence states a fact.
– Student(Eric).
– Student(Eric, Paula).
– Student(Eric, AI).
Note that the interpretation of these is different; it depends
on how we consider them to be grounded.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
32
Complex sentences
• Complex sentences are made from atomic
sentences using connectives
S, S1  S2, S1  S2, S1  S2, S1  S2,
E.g. Sibling(KingJohn,Richard) 
Sibling(Richard,KingJohn)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
33
Truth in first-order logic
• Sentences are true with respect to a model and an
interpretation
• Model contains objects (domain elements) and
relations among them
• Interpretation specifies referents for
constant symbols →
predicate symbols →
function symbols →
objects
relations
functional relations
• An atomic sentence predicate(term1,...,termn) is
true iff the objects referred to by term1,...,termn
are in the relation referred to by predicate
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
34
Knowledge base for the wumpus world
• Perception
– t,s,b Percept([s,b,Glitter],t)  Glitter(t)
• Reflex
– t Glitter(t)  BestAction(Grab,t)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
35
Deducing hidden properties
• x,y,a,b Adjacent([x,y],[a,b]) 
[a,b]  {[x+1,y], [x-1,y],[x,y+1],[x,y-1]}
Properties of squares:
• s,t At(Agent,s,t)  Breeze(t)  Breezy(s)
Squares are breezy near a pit:
Diagnostic rule---infer cause from effect
s Breezy(s)   r Adjacent(r,s)  Pit(r)
Causal rule---infer effect from cause
r Pit(r)  [s Adjacent(r,s)  Breezy(s)]
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
36
Knowledge engineering in FOL
1. Identify the task
2. Assemble the relevant knowledge
3. Decide on a vocabulary of predicates, functions,
and constants
4. Encode general knowledge about the domain
5. Encode a description of the specific problem
instance
6. Pose queries to the inference procedure and get
answers
7. Debug the knowledge base
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
37
Summary
• First-order logic:
– objects and relations are semantic primitives
– syntax: constants, functions, predicates,
equality, quantifiers
• Increased expressive power: sufficient to
define wumpus world
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
38
Example knowledge base
• The 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
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
39
Inference
• We need to DO SOMETHING with our
knowledge.
– Forward chaining
– Backward chaining
– Resolution
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
40
Example knowledge base contd.
... 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, i.e., x Owns(Nono,x)  Missile(x):
Owns(Nono,M1) and Missile(M1)
… all of its missiles were sold to it by Colonel West
Missile(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)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
41
Forward chaining algorithm
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
42
Forward chaining proof
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
43
Forward chaining proof
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
44
Forward chaining proof
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
45
Properties of forward chaining
• Sound and complete for first-order definite clauses
• Datalog = first-order definite clauses + no functions
• FC terminates for Datalog in finite number of iterations
• May not terminate in general if α is not entailed
• This is unavoidable: entailment with definite clauses is
semidecidable
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
46
Efficiency of forward chaining
Incremental forward chaining: no need to match a rule on
iteration k if a premise wasn't added on iteration k-1
 match each rule whose premise contains a newly added positive
literal
Matching itself can be expensive:
Database indexing allows O(1) retrieval of known facts
– e.g., query Missile(x) retrieves Missile(M1)
Forward chaining is widely used in deductive databases
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
47
Backward chaining algorithm
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
48
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
49
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
50
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
51
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
52
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
53
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
54
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
55
Backward chaining example
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
56
Properties of backward chaining
• Depth-first recursive proof search: space is linear
in size of proof
• Incomplete due to infinite loops
–  fix by checking current goal against every goal on
stack
• Inefficient due to repeated subgoals (both success
and failure)
–  fix using caching of previous results (extra space)
• Widely used for logic programming
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
57
Forward vs. backward chaining
• FC is data-driven, automatic, unconscious processing,
– e.g., object recognition, routine decisions
• May do lots of work that is irrelevant to the goal
• BC is goal-driven, appropriate for problem-solving,
– e.g., Where are my keys? How do I get into a PhD program?
• Complexity of BC can be much less than linear in size of
KB
• Choice may depend on whether you are likely to have
many goals or lots of data.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
58
Other Knowledge Representations
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
59
Decision Trees: Example
• Is your animal a mammal?
– Yes: Is your animal a pet
• Yes: Your animal is a cat
• No: Your animal is a lion.
– No: Is your animal bigger than a
breadbox?
• Yes: Your animal is a bear
• No: Your animal is a mouse.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
60
Decision Trees: Advantages
• Easy to implement. We know a lot about trees in
computer science.
• Explanations and the inference process are very
clearcut and easy to explain
• Easy to get started. Don’t require excessive
knowledge
• For simple problems, may reflect well the problem
domain.
• Fast to do inference: it’s just a tree walker
• Obvious way to do automated extension
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
61
Decision Trees: Disadvantages
• Decision trees reflect a semi-procedural view of expertise
which is often not a good match to a domain
– Difficult to modify
– Difficult to maintain “tree” shape, even if you allow multiple
inheritance
• Intermediate state of a problem is only captured implicitly.
• Often very difficult to elicit from expert
• Don’t scale well. Large decision trees are very hard to
maintain and debug.
• Gives an illusion of structure which doesn’t actually reflect
the domain
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
62
Production Rules
• frequently used to formulate the knowledge in
expert systems
• a formal variation is Backus-Naur form (BNF)
– metalanguage for the definition of language syntax
– a grammar is a complete, unambiguous set of
production rules for a specific language
– a parse tree is a graphic representation of a sentence in
that language
– provides only a syntactic description of the language
• not all sentences make sense
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
63
Example 1 Production Rules
• for a subset of the English language
<sentence> -> <subject> <verb> <object> <modifier>
>subject> -> <noun>
<object> -> <noun>
<noun> -> man | woman
<verb> -> loves | hates | marries | divorces
<modifier> -> a little | a lot | forever | sometimes
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
64
Chaining Rules
• Specialization of production rules
• Typical pattern is
– LHS: Left Hand Side: Some kind of condition
– RHS: Right Hand Side: Some kind of action
• The left hand side might test the existence
of some fact, the result of some test, the
relationship of two values
• The right hand side might assert a fact, elicit
additional data, quit, reach a decision.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
65
Forward Chaining Rules
• Typically used in domains which are data-driven.
• Left hand side generally tests the existence or
value of specific data, or identifies situation which
requires new data.
• Right hand side typically asserts some additional
condition or state to be true, or acquires new data.
• Appropriate when there are many possible
conclusions, data is readily available
• Example: automotive diagnostic systems
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
66
Backward Chaining Rules
• Typically used in domains which are goal-driven
• Left hand side is typically a condition which we
would like to reach, or suspect we are in
• Right hand side is typically the facts or conditions
which will be true if the left hand side is true.
• More appropriate when you have relatively few
goals or data is relatively expensive to acquire
• Example: system for diagnosing cancer
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
67
Advantages of Production Rules
•
•
•
•
•
Simple and easy to understand
Basic inference is straightforward
Formal foundations for some variants
Get started quickly
The pattern-matching view of knowledge
which they reflect is often a close match to
the expert’s thought processes.
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
68
Disadvantages of Production Rules
• Simple implementations are very inefficient
if there is a large branching factor.
• Some types of knowledge are not easily
expressed in such rules
• Large sets of rules become difficult to
understand and maintain
• Good at capturing existing knowledge, but
no capability for reasoning about new
problems
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
69
Scripts
• Describe typical events or sequences
• Components are
–
–
–
–
script variables (players, props)
entry conditions
transactions
exit conditions
• Create instance by filling in variables
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
70
Restaurant Script Example
• generic template for restaurants
– different types
– default values
• script for a typical sequence of activities at
a restaurant
• Often has a frame behind it; script is
essentially instantiating the frame
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
[Rogers 1999]
71
Restaurant Script
EAT-AT-RESTAURANT Script
Props:
(Restaurant, Money, Food, Menu, Tables, Chairs)
Roles:
(Hungry-Persons, Wait-Persons, Chef-Persons)
Point-of-View:
Hungry-Persons
Time-of-Occurrence: (Times-of-Operation of Restaurant)
Place-of-Occurrence: (Location of Restaurant)
Event-Sequence:
first:
Enter-Restaurant Script
then:
if (Wait-To-Be-Seated-Sign or Reservations)
then Get-Maitre-d's-Attention Script
then:
Please-Be-Seated Script
then:
Order-Food-Script
then:
Eat-Food-Script unless (Long-Wait) when Exit-Restaurant-Angry
Script
then:
if (Food-Quality was better than Palatable)
then Compliments-To-The-Chef Script
then:
Pay-For-It-Script
finally:
Leave-Restaurant Script
[Rogers 1999]
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
72
Ontologies
• An ontology is a formal description of the
concepts and relationships in a domain
• Concept originates in philosophy; a model
of a theory of nature or existence.
• An ontology describes the things we want to
talk about, including both objects and
relationships
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
73
Ontological Engineering
• OE is the process of capturing the relevant
knowledge in a formal representation
• Ultimate goal may be represent everything
in the world!! -- Result is an upper ontology
Anything/Root
AbstractObjects
Sets
Numbers
Categories
RepresentationalObjects
Sentences
Times
Measurements
Weights
GeneralizedEvents
Interval
Places
Moments
PhyscialObjects
Things
Animals
Processes
Stuff
Agents Solid
Liquid Gas
Humans
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
74
Special- and General-purpose Ontologies
• Special-purpose ontology:
– Designed to represent a specific domain of
knowledge;
• genetics (GO)
• mathematics (Tom Gruber)
• General-purpose ontology:
– Should be applicable in any special-purpose domain
– Unifies different domains of knowledge
• Upper ontology provides highest level
framework - all other concepts follow
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
75
Cyc Upper Ontology
• Cycorp released 3,000 upper-level concepts
into public domain
• Cyc Upper Ontology satisfies two important
criteria;
– It is universal: Every concept can be linked to it
– It is articulate: Distinctions are necessary and
sufficient for most purposes
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
76
Some Interesting Issues in KR
• The Frame Problem -- how do we represent
all the things in the world that stay the
same?
• Temporal and Spatial modeling and
reasoning
• Default reasoning
• Uncertainty
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
77
KR Languages and Programming Languages
• How is a knowledge representation language
different from a programming language (e.g. Java,
C++)?
– programming languages can be used to express facts
and states
– what about "there is a pit in [2,2] or [3,1] (but we don't
know for sure)" or "there is a wumpus in some square"
• programming languages are not expressive enough
for situations with incomplete information
– we only know some possibilities which exist
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
[Rogers 1999]
78
KR Languages and Natural Language
• How is a knowledge representation language different from
natural language
– e.g. English, Spanish, German, …
• Natural languages are expressive, but have evolved to meet
the needs of communication, rather than representation
• The meaning of a sentence depends on the sentence itself
and on the context in which the sentence was spoken
– e.g. “Look!”
• Sharing of knowledge is done without explicit
representation of the knowledge itself
• Ambiguous (e.g. small dogs and cats)
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
[Rogers 1999]
79
Good Knowledge Representations
• combine the best of natural and formal languages:
–
–
–
–
expressive
concise
unambiguous
independent of context
• what you say today will still be interpretable tomorrow
– efficient
• the knowledge can be represented in a format that is suitable for
computers
• practical inference procedures exist for the chosen format
– effective
• there is an inference procedure which can act on it to make new
sentences
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
[Rogers 1999]
80
Summary: Knowledge Representation
• Knowledge representation is essential component
if AI applications
• Popular knowledge representation schemes are
– rules, semantic nets, frames, scripts, logic, ontologies
• The selected knowledge representation scheme
should have appropriate inference methods to
allow reasoning
• A balance must be found between
– effective representation, efficiency, understandability
CSC 8520 Fall, 2005. Paula Matuszek. Slides in part from aima.eecs.berkeley.edu/slides-ppt, chs 7-9
81