Download - systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

Transcript
Page 1: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

1

Logical agents

(Logické agenty)

Lubica Benuskova

Reading: AIMA 2nd ed., Chapter 7.1 – 7.5

1

Intro 2 Artificial Intelligence: Lecture 02

Logic

• Logic (from the Ancient Greek: λογική, logike) consists of the systematic study of the forms of arguments.

• A valid argument is one where there is a logical support between

the assumptions of the argument and its conclusion.

• Logic has traditionally included the classification of arguments, the systematic exposition of the 'logical form' common to all valid

arguments, the study of inference, and the study of semantics.

• Logic has been studied in philosophy (Aristotle, 384-322 BC) and mathematics (since the mid-1800s), and recently logic has been

studied in computer science, linguistics, psychology, and other fields.

2

Logical form

• The logical form of a an argument is the form obtained by abstracting from the subject matter of its content.

• Original argument

• All humans are mortal.

• Socrates is human.

• Therefore, Socrates is mortal.

• All w e have done in the Argument form is to put 'H' for 'human' and

'humans', 'M' for 'mortal', and 'S' for 'Socrates'; w hat results is the logical form of the original argument.

• The concept of logical form is central to logic. The validity of an

argument is determined by its logical form, not by its content.

• Argument logical form

• All H are M.

• S is H.

• Therefore, S is M.

3

Subdivisions of logic

• Informal logic is the study of natural language arguments.

• Formal logic is the study of inference with purely formal content . No formal logic captures all of the nuances of natural language.

– Propositional logic (Výroková logika)

– Predicate logic (Predikátová logika)

– And others (e.g. Fuzzy logic)

• Inference possesses a purely formal content if it can be expressed as a

particular application of an abstract rule, that is, a rule that is not about any particular (concrete) thing or property.

• Inference is the act or process of deriving logical conclusions from premises known or assumed to be true, i.e. from the observed facts holding

in the world. 4

Znalostný agent: knowledge-based agent

Čo obsahuje znalostný agent?

1. Databázu poznatkov o svete : knowledge base (KB).

2. Mechanizmus usudzovania: the (empty) inference mechanism (IM).

KB, which is

the model of

the world

IM

5

Working of the knowledge-based agent

Dodá do KB

aktuálny

vnem

Opýta sa KB

na možnú

akciu

Záznam

vybranej akcie

The function KB-AGENT(percept)

1) Tells KB, which fact/s is/are true through the function TELL.

2) Asks KB, which action to choose through the function ASK.

6

Page 2: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

2

Knowledge-Based Agents

• KB = know ledge base

– A set of facts (e.g. A, B, C) and – A set of statements in a logic language, e.g.: If A then (B OR C)

• IM = Inference module

– uses a set of logical statements to infer new ones

• Example of a simple model of reasoning:

– Agent is told or perceives new evidence • E.g., A is true and C is false

– Agent then infers new facts to be added to the KB

• E.g., KB = {if A then (B OR C) }, then given A and not C w e can infer that B is true

• B is now added to the KB even though it w as not explicitly observed, i.e., the agent inferred B is true.

7

The Wumpus World: PEAS

• Performance measures:

• +1000 for picking up gold

• -1000 got falling into pit

• -1 for each move

• -10 for using arrow

• Environment

– Cave of 4×4 rooms

• Wumpus: A deadly beast who kills anyone entering his room.

• Pits: Bottomless pits that will

trap you forever.

• Gold

8

„Wumpus world“ charakteristiky

• Plne pozorovateľné? Nie – vnem je len lokálny

• Deterministické? Áno

• Epizodické? Nie

• Statické Áno – obluda a priepasti sa nehýbu, sú to

charakteristiky prostredia, nie agenti

• Diskrétne? Áno

• Jednoagentové? Áno, obluda nie je agent, ale črta

prostredia

9

The Wumpus World: PEAS

• Agents Sensors:

– Stench next to Wumpus – Breeze next to pit

– Glitter in square w ith gold – Bump w hen agent moves into

a w all – Scream from w umpus when

killed

• Agents actions – Agent can move forw ard, turn

left or turn right – Shoot, one shot

10

• The goal is to explore environment, make inferences (reasoning) to try to find the gold.

Exploring the Wumpus World

The KB initially contains the rules of the environment; i.e. rooms next to the pit are breezy, the rooms next to the wumpus are smelly. There is only one wumpus, agent has only 1 arrow, etc.

The first percept is [1,1] = [stench=0; breeze=0, glitter=0; bump=0; scream=0],

THUS it is safe to move to cell [2,1] = OK or [1,2]=OK. Let’s try [2,1].

Exploring the Wumpus World

[2,1] = [stench=0; breeze=1, glitter=0; bump=0; scream=0],

Percept indicates that there is a pit in [2,2] = P? or [3,1] = P?,

Action: return to [1,1] to try the next safe cell [1,2]

Page 3: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

3

Exploring the Wumpus World

[1,2] Stench in the cell, which means that wumpus is either in [1,3] or [2,2] AND not in [2,2] = OK, because there was no stench in [2,1]

THUS Wumpus is not in [2,2] or stench would have been detected in [2,1] (this is relatively sophisticated reasoning!)

Action: move to cell [2,2] = OK

Exploring the Wumpus World

Percept [2,2] = [stench=0; breeze=0, glitter=0; bump=0; scream=0],

Thus it is safe to move either to [2,3] or [3,2]. Let’s move to [2,3]

Percept [2,3] = [stench=1; breeze=1, glitter=1; bump=0; scream=0],

THUS gold in [2,3] and pit in [3,3] or [2,4] and Wumpus in [1,3]

Exploring the Wumpus World

Percept [2,3] = [stench=1; breeze=1, glitter=1; bump=0; scream=0], THUS gold in [2,3] and pit in [3,3] or [2,4] and Wumpus in [1,3]

Action: pick up gold in [2,3] and then move to [1,3] to kill the Wumpus Percept [1,3] (after killing Wumpus) = [0,0,0,0,0]

THUS it is safe to move to [1,4] and from there continue to explore the

cave to find more gold, while avoiding the pits…

What the Wumpus example has shown us

• Logical agent can represent general know ledge about the environment by a set of rules and facts.

• Logical agent can gather evidence and then infer new facts by

combining evidence w ith the rules.

• The conclusions are guaranteed to be correct if

– The evidence and rules are correct and

– The inference procedure is correct (thanks to logic)

• The inference may be quite complex

– E.g., evidence at different times, combined w ith different rules, etc.

16

Logical language

• The rules in the KB are expressed as propositions (sentences) according to the syntax of the representation language.

– SYNTAX specifies all the propositions that are w ell formed.

• in arithmetic: “x+y=4” is w ell formed w hile “+x4y=“ not

• A logic must also define the semantics of the language. Loosely speaking, SEMANTICS means the “meaning” of propositions.

• In logic, the definition is more precise. The TRUTH semantics of the language defines the truth of each sentence w ith respect to each possible world.

– For example, the usual semantics adopted for arithmetic specifies that the sentence “x + y =4” is true in a w orld w here x=2 and y=2, but false in a w orld w here x=1 and y=1.

17

Possible worlds – models

• Ludw ig Wittgenstein (1922, Tractatus):

– The w orld is everything that is the case:

• The w orld is the complete collection of facts, not things.

• The w orld is determined by the facts, and by being the complete collection of facts.

• To be precise, w e w ill use the term model in place of “possible w orld.”

• Models are mathematical abstractions, each of which fixes the truth or falsehood of every relevant proposition/sentence.

– In standard logics, every sentence/proposition must be either true or false in each possible w orld—there is no “in betw een.

– In fuzzy logic, degrees of truth are allow ed.

18

Page 4: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

4

Propositional logic: Syntax

• Atomic sentences

– Are single proposition symbols, e.g., P, Q, R, and so on

– Plus tw o special symbols with fixed meaning: T = true, F = false • Complex sentences: If S, S1 and S2 are sentences, then

– S is a sentence negation

– S1 S2 is a sentence conjunction (its parts are called conjuncts)

– S1 S2 is a sentence disjunction (its parts are called disjuncts)

– S1 S2 is a sentence implication (also known as if-then statement) – S1 is a premise/antecedent; S2 is called conclusion / consequent

– S1 S2 is a sentence biconditional

19

Backus-Naur Form (BNF)

• A BNF (Backus–Naur Form) of sentences in propositional logic.

• The syntax must be completely unambiguous (jednoznačná).

• Hence w e use the order of precedence (priority): , , , ,

• If not enough then use parentheses to disambiguate. 20

Propositional logic: Semantics

• The semantics defines the rules for determining the truth of a sentence w ith respect to a particular model (possible w orld).

• First, w e fix the truth value for every symbol (atomic sentence), e.g. P

= T, Q = F and R = T (there are 23=8 possible w orlds for 3 symbols).

• Next, the semantics for propositional logic must specify how to compute the truth value of any sentence, given a model.

• All sentences are constructed from atomic sentences and the five

connectives; therefore, w e need to specify how to compute the truth of sentences formed w ith each of the five connectives.

21

Truth tables for connectives

• Implication is alw ays true w hen the premise is false. Why also w hen P is false and Q is true?

• Consider an example: “It rains, therefore I am a w oman.”

• Propositional logic does not require any relation of causation or relevance betw een P and Q. Thus, if I am a w oman (Q=T), then

(P => Q) = T, too. • There is an additional connective called “exclusive or” (“xor”

for short) that yields true only w hen a single disjunct is true. 22

An example of a simple knowledge base

• A simple KB for the cave that contains only pits. For each [i, j]:

– Let P[i, j ] = T if there is a pit in [i, j ]

– Let B[i,j ] = T if there is a breeze in [i, j]

• The initial KB includes the sentences (R1 R2 R3) :

– R1 : P[1, 1] // There is no pit in [1,1]

– R2 : B[1, 1] ( P[1, 2] P[2, 1] )

– R3 : B[2, 1] ( P[1, 1] P[2, 2] P[3, 1] )

• IMPORTANT: After the agent moves to [2,1], the KB expands to include additional sentences (KB = R1R2 R3 R4 R5) , where

– R4 : B[1, 1] // There is no breeze in [1,1]

– R5 : B[2, 1] // There is a breeze in [2,1]

• After each agent action, the KB expands to include new sentences!

23

Inference: logické vyvodzovanie (entailment)

• Logical inference involves the relation of logical entailment between sentences—the idea that a sentence follows logically from another sentence. In mathematical notation, we write as

– a ╞ b

– To mean that sentence a entails the sentence b.

• The formal definition of entailment is this:

– a ╞ b if and only if, in every model, in which the sentence a is true, the sentence b is also true.

• Another way to say this is that if a is true then b must also be true, or the truth of b is “contained” in the truth of a.

• If an inference algorithm I can derive a from KB, we write: KB - Ia, which reads “ a is derived from KB by I”.

24

Page 5: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

5

Logical inference – example: cave with pits

• Consider the situation the agent has detected nothing in [1,1] and a

breeze in [2,1], and the KB = R1R2 R3 R4 R5.

• The agent w ants to infer w hether there is a pit in [1,2], [2,2] and [3,1]

• First, w e generate all the possible w orlds, i.e. models.

• There are 23 = 8 possible models.

25

Model checking: 1st part

• The KB is false in those models that contradict w hat the agent knows, e.g. the KB is false in any model in w hich [1,2] contains a pit, because

there is no breeze in [1,1].

• Thus out of total 8 possible models, the KB is true only in 3 of them.

26

Logical inference from KB

• Let’s consider the first conclusion, i.e. that α1 = "[1,2] is safe"

• We can see, in every model, in which KB is true, a1 is also true.

• Thus KB ╞ α1, i.e. a1 is derived from the KB. KB entails a1.

[1,2]

27

Logical inference from KB

[2,2]

• Let’s consider the 2nd conclusion, i.e. that α2 = "[2,2] is safe"

• We can see, in some models, in which KB is true, a2 is false.

• Thus KB ╞ α1, i.e. a2 is not derived from the KB.

28

Logical inference by model checking

• The definition of entailment can be applied to derive conclusions

from the KB, i.e. by entailment w e carry out the logical inference.

• The w hole procedure is called model checking:

– First w e generate all possible models and check, in w hich of them

the KB is true.

– Next, for each conclusion a, w e check w hether a is true in all

models, in w hich the KB is true.

• In deriving the conclusions, w e have watch out for logical

equivalence, validity and satisfiability of derived sentences

(ekvivalencia, platnosť a splniteľnosť).

29

Equivalence: standard logical equivalencies

• Logical equivalence: tw o sentences a and b are logically equivalent if

they are true in the same set of models: a b.

• Alternative definition: a b, if and only if a ╞ b and b╞ a.

30

Page 6: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

6

Validity (platnosť) and tautology

• A sentence (proposition) is logically valid if it is true in all models.

• We call sentences / propositions that are valid, TAUTOLOGIES.

• The concept of validity is crucial for the deduction theorem:

For any sentences a and b; a entails b, i.e. a ╞ b , if and only if the implication (a b) is valid.

• Thus, w e can think of the model checking inference as checking the validity of KB a, i.e KB entails a.

• In turn, every valid implication describes a legitimate inference.

31

Tautológia: formula pravdivá v ľubovoľnej interpretácii

Príklad:

PQP

P Q PQP PQ

True

True

True

True

True

True

True

True

True

True

True

False

False False

False

False

Tautology: an example

32

Satisfiability (splniteľnosť)

• A sentence is satisfiable if it is true in some model.

– For example, the KB given earlier, (R1 R2 R3 R4 R5), is satisfiable because there are 3 models, in w hich it is true.

• If a sentence a is true in a model m, then w e say that m satisfies a, or

that m is a model of a.

• Satisfiability can be checked by enumerating the possible models until one is found that satisfies the sentence.

• Validity and satisfiability are related:

– a is valid if a is unsatisfiable

– a is satisfiable if a is not valid 33

Proof by contradiction (refutation): dôkaz sporom

• Theorem:

– a ╞ b if and only if the sentence (a b) is unsatisfiable.

• Proving b from a by checking the unsatisfiability of (a b) corresponds to the standard mathematical proof technique of

reductio ad absurdum (i.e. reduction to an absurd thing).

• This kind of proof is also called refutation or proof by contradiction.

• One assumes a proposition b to be false and show s that this leads to a contradiction w ith the know n axiom(s) a. This contradiction is exactly

w hat is meant by saying that (a b) is unsatisfiable.

34

Rules of logical inference (logical reasoning)

• At last, w e w ill cover patterns of inference that the inference mechanism (IM) applies to derive conclusions that lead to the desired goal.

• These patterns of inference are called INFERENCE RULES.

• An IM that derives only sentences entailed by the KB is called sound or

truth-preserving (korektný algoritmus).

• An IM is complete (kompletný algoritmus) if it can derive any sentence that is entailed by the KB.

Ak je KB pravdivá v reálnom svete, potom každá veta

odvodená z KB korektnou vyvodzovacou procedúrou je tiež

pravdivá v reálnom svete. 35

Modus Ponens

• This means that w henever a sentence of the form a and a b are

given, then the sentence b can be inferred.

• For example if Wumpus and Wumpus Shoot are given, then Shoot

can be inferred.

b

baa ,

Shoot

ShootWumpusWumpus ,

36

Page 7: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

7

Modus Tollens

• This means that w henever a sentence of the form b and a b are

given, then the sentence a can be inferred.

• For example if Glitter = False and Gold Glitter are given, then

Gold = F can be inferred.

a

bab

,

FGold

GoldGlitterFGlitter

,

37

And-Elimination

• Simplifikácia (pravidlo odstránenia konjunkcie): Z konjunkcie sa dá odvodiť ľubovoľný z jej konjunktov. Ak celá konjunkcia je pravdivá,

všetky konjunkty musia byť pravdivé, i.e.

• Pravidlo odstránenia dvojitej negácie: Keď nejaký výrok dvakrát znegujeme, dostaneme ten samý výrok, i.e.

i

n

a

aaa ...21

a

a

38

• Pravidlo vovedenia konjunkcie: Umožní z viacerých formúl odvodiť ich konjunkciu. Ak sú pravdivé, aj ich

konjunkcia je pravdivá.

• Adícia (pravidlo vovedenia dizjunkcie): Z jednej formuly odvodí jej dizjunkciu s hocijakými formulami. Ak je formula

pravdivá, jej dizjunkcia s čímkoľvek je pravdivá.

n

n

aaa

aaa

...

,....,,

21

21

ni

i

aaaaa

a

.....321

naaa ,....,, 21

Vovedenie konjunkcie a dizjunkcie

39

Example of inference in the cave with pits

• The preceding derivation—a sequence of applications of inference rules—is called a PROOF.

40

Vyvodzovanie vo výrokovej logike – iný príklad

4

3

2

1

predpokladTS

predpokladSR

predpokladPR

predpokladQP

T

S

R

Q

P

1

2

3 4

5

6

7 8

9

simplifikácia predpokladu 1

simplifikácia predpokladu 1

medzivýsledok 5 a modus tollens na predpoklad 2

medzivýsledok 7 a modus ponens na predpoklad 3

medzivýsledok 8 a modus ponens na predpoklad 4

41

Resolution (rezolvencia)

• RESOLUTION is a single inference rule, that yields a complete inference algorithm w hen coupled w ith any complete search

algorithm.

• REZOLVENCIA je špeciálny prípad modus ponens:

• In order to generalize, let’s introduce this notation:

42

b

baa

b

baa

,,

mlwherel

llm

l

llm

1

2

21

2

21 ,,

Page 8: systematic study of the forms of arguments. …dai.fmph.uniba.sk/courses/intro-ai/lectures/L02-logic...1 systematic study of the forms of arguments. Logical agents (Logické agenty)

8

kii

k

llll

lllm

- ......

....,

111

21

njjkii

kn

mmmmllll

lllmm

-- ............

....,...

111111

211

Resolution inference rule

• Unit resolution (jednotková rezolvencia), li = m

• Full resolution (plná rezolvencia ), li = mj

43

• Resolution for 3 propositions: takes tw o clauses and produces a new clause containing all the literals of the tw o original clauses except the

tw o complementary literals, i.e.:

• Note: a literal is the atomic proposition and clause (klauzula) is a disjunction of literals.

• What about conjunctions? Every sentence of propositional logic is

logically equivalent to a conjunction of disjunctions of literals.

• A sentence expressed as a conjunction of disjunctions of literals is said to be in conjunctive normal form or CNF.

31

3221 ,

ll

llll

Conjunctive normal form (CNF)

44

vstup : formula A , výstup CNF A

algoritmus:

1. Podformule nahradiť

2. nahradiť

3. Urobiť úpravy negácií:

Algoritmus CNF

YX XYYX

YX YX

YX

YX

X

YX

YX

X

45

4. Uplatniť distributivitu voči :

5. Odstrániť redundancie napr. nahradiť X.

ZYX

ZYX

ZYZX

ZXYX

)(

XX

A resolution algorithm

• Inference by resolution w orks by using the proof by contradiction.

• That is, to show that KB a, i.e KB entails a, w e show that (KB a) is not satisfiable (i.e. not true in any model).

• First, (KB a) is converted into CNF.

• Then the resolution is applied to the resulting clauses.

• Each pair that contains complementary literals is resolved to produce a

new clause, w hich is added to the set if it is not already present. The process continues until one of tw o things happens:

– there are no new clauses that can be added

– resolution derives an empty clause, i.e. a disjunction of no disjuncts.

46

A resolution algorithm

47

Conclusion

• In propositional logic, any complete search algorithm, applying only the resolution rule, can derive any conclusion entailed by any KB.

• Vo výrokovej logike, ktorýkoľvek kompletný algoritmus prehľadávania,

ktorý používa len rezolvenčné pravidlo, dokáže odvodiť ktorúkoľvek

vetu vyplývajúcu z ktorejkoľvek bázy znalostí.

• Logical reasoning thus ensures that the new clauses represent aspects of the w orld that actually follow from the aspects that the old clauses

represent.

48