Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums...

51
Praktikum KI Teil V: Logik

Transcript of Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums...

Page 1: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI

Teil V: Logik

Page 2: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Überblick

Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer „intelligenten“ Lösung Problemlösung mit Heuristiken Logik Planung & Robotik Expertensysteme Lernen

Page 3: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

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

Page 4: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

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 – Wumpus is essentially a natural feature

Page 5: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 6: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 7: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 8: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 9: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 10: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 11: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 12: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Exploring a wumpus world

Page 13: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik – Grundlagen Aussagenlogik

Aussagenlogik kennt nur Fakten (und die Verknüpfungen , , v, , ) B21 (breeze in Feld (2,1)) B41 B42 P31 B43 B34 P33 v P44

Implikationen () lassen sich umschreiben: (A B) ist äqivalent zu (A v B) Beweis: Wahrheitstabelle:

A B A B A v B

True True True True

True False False False

False True True True

False False True True

Page 14: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik – Knowledge Base

Fakten werden in Knowledge Base (KB) gespeichert Einträge der KB sind mit UND verknüpft Aus bestehenden Einträgen können neue generiert

werden KB: {A, A B} Daraus generiert (“geschlussfolgert”) B Neue KB: {A, A B, B}

Oder: KB: {A, A B C } Daraus generiert (“geschlussfolgert”) C Neue KB: {A, A B C, C}

Page 15: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik - Interferenz

An die Knowledge Base können Anfragen gestellt werden KB: {A, A B C } Mögliche Anfragen (α): A, C, C, D, …

Eine Anfrage ist true, wenn gilt (KB α) Zur positiven Beantwortung einer Anfrage zeige also,

dass für jede Belegung der Symbole mit true / false (=Modell), die für KB true ergibt, auch α true ist

Alternativ zeige, dass (KB α) false ist Die Suche nach einem solchen Modell wird als

Interferenz bezeichnet

Page 16: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik - Inference by enumeration One sentence entails another (A B) if B is true in all worlds where A is true An Inference Method is

sound if it derives only sentences which are entailed in the KB complete if it derives all sentences which are entailed in the KB

Depth-first enumeration of all models is sound and complete

For n symbols, time complexity is O(2n), space complexity is O(n)

Page 17: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik – Kojunktive Normalform Konjunktive Normalform (CNF): Konjunktion () von

Disjunktionen (v) von Literalen, z.B.(A B) (B C D)

Jede Aussage kann in CNF gebracht werden A B ist äquivalent (≡) zu (A B) (B A) (A B) ≡ (A v B) de Morgan ((AvB) ≡ A B, …) Distributivität von und v

Zur Interferenz werden stets zwei Disjunktionen herangezogen, die das gleiche Literal einmal mit und einmal ohne Negation () enthalten (A B) (B C D)

Page 18: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Resolution Resolution inference rule (for CNF):

Let li and mj be complementary literals (i.e. li ≡ mj). Then it holds

l1 … lk, m1 … mn

l1 … li-1 li+1 … lk m1 … mj-1 mj+1 ... mn

E.g.,

P1,3 P2,2, P2,2

P1,3

Resolution is sound and complete for propositional logic

Page 19: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik – Beweis durch Resolution

Führt die Interferenz durch Resolution auf die leere Aussage {}, so ist die ursprüngliche CNF falsch {} entsteht ausschließlich durch

A, A

{} Wenn A und A in Konjunktion () auftreten, so ist die Aussage

stets False

Um KB ╞ α zu zeigen, versuche daher (KB α) via Resolution zum Widerspruch, d.h. zu {}, zu bringen.

Page 20: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Resolution algorithm Proof by contradiction, i.e., show KBα unsatisfiable

Page 21: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Resolution example KB = (B1,1 (P1,2 P2,1)) B1,1

α = P1,2

Page 22: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Logik – Horn Clauses

Horn Clauses sind spezielle Form der CNF Jede Disjunktion enthält genau ein positives Literal Bsp: (A B) (B C D) Es gilt: (A B C … N ) ≡ (B C … N A)

Damit kann die “Modus Ponens”-Regel angewandt werden:

A B C, A B C D

D

Bei einer KB aus Horn Clauses können Forward- und Backward-Chaining angewandt werden

Page 23: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining Idea: fire any rule whose premises are satisfied in the KB,

add its conclusion to the KB, until query is found

Page 24: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 25: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 26: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 27: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 28: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 29: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 30: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Forward chaining example

Page 31: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chainingIdea: work backwards from the query q:

to prove q by BC,check if q is known already, orprove by BC all premises of some rule concluding q

Avoid loops: check if new subgoal is already on the goal stack

Avoid repeated work: check if new subgoal1. has already been proved true, or2. has already failed

3.

Page 32: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 33: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 34: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 35: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 36: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 37: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 38: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 39: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 40: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 41: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Backward chaining example

Page 42: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

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

Page 43: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Efficient propositional inferenceTwo families of efficient algorithms for propositional inference:

Complete backtracking search algorithms DPLL algorithm (Davis, Putnam, Logemann, Loveland) Incomplete local search algorithms

WalkSAT algorithm

Page 44: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

The DPLL algorithmDetermine if an input propositional logic sentence (in CNF) is satisfiable.

Improvements over truth table enumeration:1. Early termination

A clause is true if any literal is true.A sentence is false if any clause is false.

2. Pure symbol heuristicPure symbol: always appears with the same "sign" in all clauses. e.g., In the three clauses (A B), (B C), (C A), A and B are pure, C is impure. Make a pure symbol literal true.

3. Unit clause heuristicUnit clause: only one literal in the clauseThe only literal in a unit clause must be true.

Page 45: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

The DPLL algorithm

Page 46: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

The WalkSAT algorithm Incomplete, local search algorithm Evaluation function: The min-conflict heuristic of minimizing the number of

unsatisfied clauses Balance between greediness and randomness

Page 47: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

The WalkSAT algorithm

Page 48: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

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

Page 49: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

Inference-based agents in the wumpus world

Page 50: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

KB contains "physics" sentences for every single square

For every time t and every location [x,y],

Lx,y FacingRightt Forwardt Lx+1,y

Rapid proliferation of clauses

Expressiveness limitation of propositional logic

t+1t

Page 51: Praktikum KI Teil V: Logik. Praktikum KI SoSe 2005 Überblick Organisation des Praktikums Einführung in die Künstliche Intelligenz Suche nach einer intelligenten.

Praktikum KI SoSe 2005

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 logicForward, backward chaining are linear-time, complete for Horn clauses

Propositional logic lacks expressive power