Download Inference and resolution for problem solving

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Boolean satisfiability problem wikipedia , lookup

Propositional calculus wikipedia , lookup

Resolution of singularities wikipedia , lookup

Transcript
Inference and Resolution
for Problem Solving
Fall 2016
Comp3710 Artificial Intelligence
Computing Science
Thompson Rivers University
Course Outline


Part I – Introduction to Artificial Intelligence
Part II – Classical Artificial Intelligence



Knowledge Representation
Searching
Knowledge Represenation and Automated Reasoning





Propositinoal and Predicate Logic
Inference and Resolution for Problem Solving
Rules and Expert Systems
Part III – Machine Learning
Part IV – Advanced Topics
TRU-COMP3710
Inference and Resolution
2
Chapter Objectives





How to convert BNF to CNF
Use of the resolution rule for some problems
How to construct Horn clauses from given rules and facts
Use of forward chaining
Use of backward chaining
TRU-COMP3710
Inference and Resolution
3
Chapter Outline
1.
2.
3.
4.
Introduction
Resolution in propositional logic
An application of resolution – graph coloring
Inference methods – forward and backward chaining
1.
2.
3.
Horn clauses
Forward chaining
Backward chaining
TRU-COMP3710
Inference and Resolution
4
1. Introduction

Topics
Problem solving using propositional calculus:

Based on rules, knowledge, and facts,
Decide if a given query is valid.

Example


Rules and facts (or observations)





Question:




TRU-COMP3710
If it is raining, Jenny does not go camping.
It is raining.
It is a hot day.
It is afternoon.
Does Jenny go fishing?
Can you convert them to a logical form, i.e., wff (or sentence)?
(Raining  ~Camping)  Raining  HotDay  Afternoon  ~Fishing ???
We need to see the above sentence is contradictory to answer “Is Jenny
coming?”.
Inference and Resolution
5
2. Resolution in Propositional Logic
1.
2.
3.
4.
5.
6.
CNF(Conjunctive Normal Form)
How to convert propositions to CNFs
Clauses instead of CNFs for convenience
The Resolution rule
Resolution refutation
Proof by refutation
TRU-COMP3710
Inference and Resolution
6
Conjunctive Normal Forms (CNF)


BNF (Backus-Naur Form) is not convenient to use.
A wff is in Conjunctive Normal Form (CNF) if it is a conjunction of
disjunctions:






2.
conjunction of disjunctions of literals
clauses
E.g., (A  B)  (B  C  D)
E.g., A  (B  C)  (¬A  ¬B  ¬C  D)
Every sentence of propositional logic is logically equivalent to a
conjunction of disjunctions of literals.
[Q] Really? How to convert?
[Q] Why do we need to use CNF?
Similarly, a wff is in Disjunctive Normal Form (DNF) if it is a
disjunction of conjunctions.

E.g., A  (B  C)  (¬A  ¬B  ¬C  D)
TRU-COMP3710
Inference and Resolution
7
Converting to CNF

Any wff can be converted to CNF by using the following
equivalences:
1.
2.
3.
4.
5.
6.


A ↔ B  (A → B)  (B → A)
A → B  ¬A  B
¬(A  B)  ¬A  ¬B
¬(A  B)  ¬A  ¬B
¬¬AA
A  (B  C)  (A  B)  (A  C)
biconditional elimination
implication elimination
de Morgan’s law
de Morgan’s law
double-negation elimination
distributivity
Importantly, this can be converted into an algorithm – this will be
useful when we come to automating resolution.
Examples – convert the following propositions to CNFs.


(¬A → B) → ¬C
A  (B  C)
TRU-COMP3710
Inference and Resolution
8
2.

Examples – convert the following propositions to CNFs.



(~A  B)  ~C
~(~A  B)  ~C
(~~A  B)  ~C
(A  B  ~C)
A  (B  C)
(A  B)  (B  A)
(~A  B)  (~B  A)
(A → B) → C
TRU-COMP3710
Inference and Resolution
9
Clauses


2.
Having converted a wff to CNF, it is usual to write it as a set of
clauses.
E.g.:
(A → B) → C

In CNF is:
(A  C)  (¬B  C)

[Q] How?
In clause form, we write:
{(A, C), (~B, C)}
Disjunction
TRU-COMP3710
Conjunction
Inference and Resolution
10
The Resolution Rule

2.
The resolution rule is written as follows:
A  B, ¬B  C
AC
A  B, ¬B
A
(A  B)  (¬B  C) ╞ (A  C)
(A  B)  ¬B ╞ A
If the upper part is valid, then the lower part should be valid.

This tells us that if we have two clauses that have a literal and its
negation, we can combine them by removing that literal.

[Q] Can you prove it using the truth table?

E.g.: if we have {(A, C), (~A, D)}, we would apply resolution to get
{(C, D)}
TRU-COMP3710
Inference and Resolution
11
Resolution Refutation


2.
Let us resolve: {(~A, B), (~A, ~B, C), A, ~C}
[Q] We begin by resolving the first clause with the second clause, thus
eliminating B and ~B:
{(~A, B), (~A, ~B, C), A, ~C}
=> {(~A, C), A, ~C}
=> {C, ~C}
=> falsum
Why falsum? Because the initial assumption, ~C, is not valid. Therefore C
is valid.

Now we can resolve both remaining literals, which gives falsum:
^


If we reach falsum, we have proved that our initial set of clauses were
inconsistent.
This can be written as:
{(~A, B), (~A, ~B, C), A, ~C} ╞ ^
TRU-COMP3710
Inference and Resolution
12
Proof by Refutation



If we want to prove that a logical argument is valid, we negate its
conclusion, convert it to clause form, and then try to derive falsum
using resolution.
If we derive falsum, then our clauses were inconsistent, meaning the
original argument was valid, since we negated its conclusion.
Proof by refutation is also called proof by contradiction.
TRU-COMP3710
Inference and Resolution
13

[Q] Is the following argument valid?
(A ˄ ¬B) → C
A ˄ ¬B
C

Start with the negation of the conclusion and convert to clauses:
{(~A, B, C), A, ~B, ~C}

Let’s resolve:
{(~A, B, C), A, ~B, ~C}
=> {(B, C), ~B, ~C}
=> {C, ~C}
=> ^



[Q] How?
How?
How?
We have reached falsum.
[Q] Why?
Because of the assumption of ~C. Therefore C. Hence, our original
argument is valid.
TRU-COMP3710
Inference and Resolution
14
Another example:
AB
BC
CD
DEF
AF
Is this argument valid?
~(A  F) 
~(~A  F)  A  ~F
Clause form?
{(~A, B), (~B, C), (~C, D), (~D, E, F), A, ~F }
Resolution?
TRU-COMP3710
Inference and Resolution
15
2.

It is often sensible to represent a refutation proof in tree form:
Topics
How to
automate the
resolution?

In this case, the
proof has failed, as we
are left with E instead of falsum.
TRU-COMP3710
Inference and Resolution
16
3. Applications of Resolution



Resolution refutation can be used to determine if a solution exists for a
particular combinatorial problem.
For example, for graph coloring, we represent the assignment of
colors to the nodes and the constraints regarding edges as propositions,
and attempt to prove that the complete set of clauses is satisfiable (i.e.,
to be deduced to non-false sum).
This does not tell us how to color the graph, simply that it is possible.
TRU-COMP3710
Inference and Resolution
17
Topics






3-coloring problem: Available colors are r (red), g (green) and b (blue).
Ar means that node A has been coloured red.
Each node must have exactly one color:
Ar  Ag  Ab
¬Ar  ¬Ag
( ¬(Ar  Ag))
¬Ag  ¬Ab
¬Ab  ¬Ar
If (A, B) is an edge, then:
¬Ar  ¬Br
( ¬(Ar  Br))
¬Ab  ¬Bb
¬Ag  ¬Bg
(B, C), (A, C), (C, D) and (A, D) are also edges.
Now we construct the complete set of clauses for our graph, and try to
see if they are satisfiable, using the resolution rule.
TRU-COMP3710
Inference and Resolution
18
4. Forward and backward chaining
1.
2.
3.
Horn clauses – a simpler form
Forward chaining
Backward chaining
TRU-COMP3710
Inference and Resolution
19
Horn Clauses

Horn Form (a more restricted version of propositional language) –
conjunction of Horn clauses

Horn clause =



E.g., C  (B  A)  (C  D  B)




proposition symbol; or
(conjunction of symbols)  symbol
Fact: C
Rules: if B then A; if C and D then B
Modus Ponens (for Horn Form): complete for Horn KBs
α1[, … ,αn],
α1 [ …  αn]  β
β
Meaning: Facts and the rule with the facts  then  is a fact.
E.g., Rule: if red light, then stop; Fact: red light; then ???
Can be used with forward chaining or backward chaining. These
algorithms are very natural and run in linear time.
TRU-COMP3710
Inference and Resolution
20
How to model Horn clauses?




Example:
Rules

IF P THEN Q

IF L and M THEN P

IF B and L THEN M

IF A and P THEN L

IF A and B THEN L
Facts

A

B
[Q] Horn clauses?
TRU-COMP3710
Inference and Resolution
and-or graph
21



Example:
Rules

If X croaks and X eats flies, then X is a frog.

If X chirps and X sings, then X is a canary.

If X is a frog, then X is green.

If X is a canary, then X is yellow.
Facts



Question



Fritz croaks.
Fritz eats flies.
The color of Fritz.
How to solve?
Can you convert the problem to Horn clauses?
TRU-COMP3710
Inference and Resolution
22

Another more complex example – ZooKeeper:












If X has hair, then X is a mammal.
If X gives milk, then X is a mammal.
If X has feathers, then X is a bird.
If X flies and lays eggs, then X is a bird
If X is a mammal and X eats meat, then X is a carnivore.
If X is a mammal and X has pointed teeth and X has claws and X has forward
pointing eyes, then X is a carnivore.
If X is a mammal and X has hoofs, then X is an ungulate.
If X is a mammal and X chews cud, then X is an ungulate.
If X is a carnivore and X has tawny color and X has dark spots, then X is a cheetah.
If X is a carnivore and X has tawny color and X has black strips, then X is a tiger.
If X is an ungulate and X has long legs and X has a long neck and X has tawny color
and X has dark spots, then X is a giraffe.
If X is an ungulate and X has white color and X has black strips, then X is a zebra.
TRU-COMP3710
Inference and Resolution
23
4.




Facts/observations







Stretch has hair.
Stretch chew cud.
Stretch has long legs.
Stretch has a long neck.
Stretch has tawny color.
Stretch has dark spots.
Question


If X is a bird and X does not fly and X has long neck and X has long legs and X is
black and white, then X is an ostrich.
If X is a bird and X does not fly and X swims and X is black and white, then X is a
penguin.
If X is a bird and X is a good flier, then X is an albatross.
What animal is Stretch?
How to solve?
TRU-COMP3710
Inference and Resolution
24
Forward chaining

[Q] The query Q is valid?
Knowledge base
Facts
Query = Q
TRU-COMP3710
Inference and Resolution
25

Idea:

Start with facts, and fire any rule whose premises are
satisfied in the KB; Keep adding its conclusion to the KB, until
query is found.
Knowledge base
OR
AND
Facts
Query = Q
TRU-COMP3710
AND-OR graph
Inference and Resolution
26
Query
Facts
Rules
triggered
Rule fired
A, B
OR
# of premises
AND
Not inferred
TRU-COMP3710
Inference and Resolution
27
Facts
Rules
triggered
Rule fired
A, B
Reduced by 1
Set true
TRU-COMP3710
Inference and Resolution
28
Facts
A, B
Rules
triggered
5
Rule fired
5
OR
AND
TRU-COMP3710
Inference and Resolution
29
Facts
A, B
A, B, L
TRU-COMP3710
Inference and Resolution
Rules
triggered
5
3
Rule fired
5
30
Facts
A, B
A, B, L
A, B, L, M
TRU-COMP3710
Inference and Resolution
Rules
triggered
5
3
2
Rule fired
5
3
31
Facts
A, B
A, B, L
A, B, L, M
A, B, L, M, P
TRU-COMP3710
Inference and Resolution
Rules
triggered
5
3
2
4, 1
Rule fired
5
3
2
32
Facts
A, B
A, B, L
A, B, L, M
A, B, L, M, P
TRU-COMP3710
Inference and Resolution
Rules
triggered
5
3
2
4, 1
Rule fired
5
3
2
4
33
Facts
A, B
A, B, L
A, B, L, M
A, B, L, M, P
A, B, L, M, P, Q
TRU-COMP3710
Inference and Resolution
Rules
triggered
5
3
2
4, 1
1
STOP
Rule fired
5
3
2
4
1
34
4.



Example – Fritz:
Rules
1.
Croak  EatFly  Frog
2.
Chirp  Sing  Canary
3.
Frog  Green
4.
Canary  Yellow


Croak
EatFly
Frog
Canary
Facts
Croak, EatFly
Question

Yellow
Croak
Facts

Green
EatFly
Chirp
Rules triggered
Sing
Rule fired
The color of Fritz.
TRU-COMP3710
Inference and Resolution
35
Backward chaining


[Q] Problem of forward chaining (FC)?
FC starts with all the asserted symbols, i.e., facts -> longer execution
time
(We do not have to use all the facts to conclude the given query.)
Idea of backward chaining (BC): work backwards from the query q:
to prove q by BC,
check if q is known already, or
prove by BC – only the premises of some rules concluding q

Avoid loops: check if new subgoal is already on the goal stack

Avoid repeated work: check if new subgoal
1.
has already been proved true, or
2.
has already failed
TRU-COMP3710
Inference and Resolution
36
Unknown
Facts
A, B
Goals
Q
Matching rules
?
TRUE
TRU-COMP3710
Inference and Resolution
37
Unknown
Facts
(subgoal)
A, B
A, B
TRU-COMP3710
Inference and Resolution
Goals
Q
P
Matching rules
1
?
38
Facts
A, B
A, B
A, B
TRU-COMP3710
Inference and Resolution
Goals
Q
P
L, M
Matching rules
1
2
L: ?
39
Already in the stack of subgoals
Facts
A, B
A, B
A, B
Goals
Q
P
L, M
Matching rules
1
2
L: 4, 5
Not fired
TRU-COMP3710
Inference and Resolution
40
Facts
A, B
A, B
A, B
TRU-COMP3710
Inference and Resolution
Goals
Q
P
L, M
Matching rules
1
2
L: 4, 5
41
Facts
A, B
A, B
A, B
A, B, L
Goals
Q
P
L, M
M
Matching rules
1
2
L: 4, 5
?
Became TRUE
TRU-COMP3710
Inference and Resolution
42
Facts
A, B
A, B
A, B
A, B, L
TRU-COMP3710
Inference and Resolution
Goals
Q
P
L, M
M
Matching rules
1
2
L: 4, 5
3
43
Facts
A, B
A, B
A, B
A, B, L
A, B, L, M
TRU-COMP3710
Inference and Resolution
Goals
Q
P
L, M
M

STOP
Matching rules
1
2
L: 4, 5
3
44
TRU-COMP3710
Inference and Resolution
45
TRU-COMP3710
Inference and Resolution
46



Example – Fritz:
Rules
1.
Croak  EatFly  Frog
2.
Chirp  Sing  Canary
3.
Frog  Green
4.
Canary  Yellow


Croak
EatFly
Question

The color of Fritz.
TRU-COMP3710
Yellow
Frog
Canary
Croak
Facts

Green
EatFly
Chirp
Facts
Croak, EatFly
Croak, EatFly
Croak, EatFly
Goals
Yellow
Canary
Chirp, Sing
Croak, EatFly
Green
Inference and Resolution
Sing
Matching rules
4
2

Failure
47

How to use BC to solve ZooKeeper?




Animals – Cheetah, Tiger, Giraffe, Zebra, Ostrich, Penguin, Albatross
For each of the above animals,
Run BC to see if the animal can be deduced.
Can you implement BC for ZooKeeper?
Recursion with the next representation of rules and facts.
var rule = {};
rule['Carnivore'] = [
[Mammal, EatMeat],
[Mammal, PointedTooth, Claw, ForwardPointingEye]
]; // (Mammal  EatMeat) 
// (Mammal  PointedTooth  Claw  ForwardPointingEye)
...
var fact = [];
fact[1] = 'Hair';
...
TRU-COMP3710
Inference and Resolution
48
Forward vs. backward chaining

FC is data-driven, automatic, unconscious processing,

May do lots of work that is irrelevant to the goal

BC is goal-driven, appropriate for problem-solving,



Topics
E.g., object recognition, routine decisions


4.
E.g., Where are my keys?
E.g., How do I get into a PhD program?
E.g., My car won’t start. What is the problem?
Complexity of BC can be much less than linear in size of KB
TRU-COMP3710
Inference and Resolution
49
Summary
TRU-COMP3710
Inference and Resolution
50