M3 Pengenalan Logical Agents

  Logical Agents Chastine Fatichah Teknik Informatika

  Institut Teknologi Sepuluh Nopember November 2012 Kecerdasan Buatan (KI092301)

Pokok Bahasan

  • Knowledge-based agents
  • Contoh: Wumpus world
  • Logic
  • Propositional logic
  • Equivalence, validity, satisfiability
  • Inference rules dan metode pembuktian
  • forward chaining
  • backward chaining
  • resolution

  

Outline

  • Knowledge-based agents
  • Contoh: Wumpus world
  • Logic
  • Propositional logic
  • Equivalence, validity, satisfiability
  • Inference rules dan metode pembuktian
  • forward chaining
  • backward chaining
  • resolution

  

Knowledge bases

  • Knowledge base (pengetahuan) = sekumpulan kalimat pada sebuah bahasa formal
  • Pendekatan deklaratif membangun agent :
  • Beritahu informasi yg relevan, simpan dalam KB  (Tell)

  

Agen dapat ditanya (bertanya pd diri sendiri) apa yang sebaiknya

dilakukan berdasarkan KB  (Ask)

  • Agen dapat ditunjukkan level pengetahuan

  Contoh: apa yg mereka ketahui, bagaimana implementasinya Atau level implementasi

  • Contoh: struktur data pada KB dan algoritma-algoritma yang memanipulasi

  

Knowledge-based Agent

  • Agen harus dapat:
  • Merepresentasikan state, action, dll.
  • Menerima informasi baru
  • Mengupdate representasi
  • Menyimpulkan pengetahuan lain yang tidak eksplisit ( hidden property)
  • Menyimpulkan action apa yang perlu diambil

  

Outline

  • Knowledge-based agents
  • Contoh: Wumpus world
  • Logic
  • Propositional logic
  • Equivalence, validity, satisfiability
  • Inference rules dan metode pembuktian
  • forward chaining
  • backward chaining
  • resolution

  

Wumpus World

Performance measure emas +1000, mati -1000 gerak -1 , panah -10

  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 local persepsi

  

Karakteristik Wumpus world

  • – hanya
    • Fully Observable No

  • – keluaran yg bisa dispesifikasikan secara tepat
    • Deterministic Yes

  • – sequential pada level aksi
    • Episodic No

  • – Wumpus dan Pits tidak bergerak
    • Static Yes
    • Discrete Yes

  • – Wumpus mmepunyai fitur alami
    • Single-agent? Yes

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Exploring a wumpus world

  

Logic

  • Logic adalah bahasa formal untuk merepresentasikan

  

informasi sedemikian hingga kesimpulan dapat dibuat

  • Syntax mendefinisikan kalimat-kalimat pada bahasa
  • Semantics mendefinisikan arti kalimat;

  misal , mendefinisikan kebenaran sebuah kalimat

  • Contoh, bahasa aritmatika
  • 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 y
  • x+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

  

Entailment

  • Entailment artinya bahwa sesuatu mengikuti dari

  yang lain KB ╞

  Knowledge base KB entails kalimat α jika dan hanya jika α adalah true pada semua dunia dimana KB bernilai true

  • Misal, KB “the Giants won” dan “the Reds won”

    entails “Either the Giants won or the Reds won”

  • Misal, x+y = 4 entails 4 = x+y
  • Entailment adalah sebuah hubungan antar kalimat (

  syntax ) yang didasarkan pada semantics

  

Models

  sebuah kalimat α jika α bernilai true pada m

  • m adalah sebuah model pada
  • M(α) adalah kumpulan semua model pada α

  KB ╞ α iff M(KB) M(α)

  • Misal:
  • KB = Giants won and Reds

  won

  • α = Giants won

  

Entailment pada wumpus world

Situasi setelah deteksi nothing in [1,1], moving right, breeze in [2,1] Kemungkinan semua model pada KB yang mengasumsikan hanya ada pits  8

  3 Boolean terpilih possible models

  

Wumpus models

  

Wumpus models

  • KB = wumpus-world rules + observations

  

Wumpus models

  • KB = wumpus-world rules + observations

  ╞ α

  1

  1

  • = "[1,2] is safe", KB , proved by model checking α

  

Wumpus models

  • KB = wumpus-world rules + observations

  

Wumpus models

  • KB = wumpus-world rules + observations

  ╞ α

  2

  2

  • = "[2,2] is safe", KB α

  

Inference

  ├ i

  α = kalimat α dapat diderivasi dari KB dengan prosedur I

  • KB

  ├ i

  α, bernilai juga benar pada KB ╞ α

  • Soundness : i adalah sound jika KB

  ╞ α, bernilai juga benar pada KB ├ i

  • Completeness : i adalah complete jika KB

  α

  

Propositional logic: Syntax

  • – Propositional logic adalah logika paling sederhana menggambarkan ide dasar

  1

  2

  • Simbol proposisi P , P dll adalah sebuah kalimat
    • S is a sentence (

  • If S is a sentence, negation )

  If S and S are sentences, S  S is a sentence ( conjunction )

  1

  2

  

1

  2

  1

  2

  

1

  2

  If S and S are sentences, S is a sentence ( disjunction )  S

  1

  2

  

1

  2

  If S and S are sentences, S is a sentence ( implication )  S

  1

  2

  

1

  2

If S and S are sentences, S is a sentence ( biconditional )  S

  • S is true iff S is false S

  

S

  1

  is true and S

  2

  is false S

  1

   S

  2

  is true iff S

  1

  2

  2

  is true and S

  2

  S

  1

  is true Proses recursif sederhana mengevaluasi sebuah kalimat, misal

  1,2

   (P

  2,2

   P

  3,1

  is true i.e., is false iff S

  is false or S

  ) = true (true false) = true true = true

  1

  

Logika Propositional: Semantics

Tiap model menspesifikasikan true/false untuk setiap simbol proposisi

  Misal:P 1,2 P 2,2 P 3,1 false true false Dengan simbol ini, 8 possible models, dapat digenerate secara otomatis Rule untuk mengevaluasi nilai kebenaran dengan model m:

  1

   S

  2

  is true iff S

  1

  is true and S

  2

  is true S

   S

  1

  2

  is true iff S

  1

  is true or S

  2

  is true S

  1

   S

  2

  is true iff S

  • P

  

Tabel kebenaran untuk

konektifitas

  

Kalimat pada Wumpus world

Let P be true if there is a pit in [i, j]. i,j Let B be true if there is a breeze in [i, j]. i,j

  • P

  1,1

  • B

  1,1 B

  2,1

  • "Pits cause breezes in adjacent squares”

  B  (P  P ) 1,1 1,2 2,1

   (P  P  P B )

  2,1 1,1 2,2 3,1

  

Tabel Kebenararan untuk

inference

  

Inference dengan enumeration

  Untuk n symbol, waktu kompleksitas adalah O(2 ), space kompleksitas adalah O(n)

  • n

  

Logical equivalence

  • Dua kalimat adalah logically equivalent iff bernilai true

    pada model yang sama: α ≡ ß iff α╞ β and β╞ α

  

Validity dan satisfiability

Sebuah kalimat adalah valid jika bernilai true pada semua model,

  Misal, True, A A, A  A, (A  (A  B))  B Validity dihubungkan ke inference melalui Deduction Theorem :

  KB ╞ α if and only if (KB  α) is valid

  Sebuah kalimat adalah satisfiable jika bernilai true pada beberapa model Misal: A  B, C

  

Sebuah kalimat adalah unsatisfiable jika bernilai salah pada semua model

Misal: A A

  Satisfiability dihubungkan ke inference melalui : KB

  ╞ α if and only if (KB α) is unsatisfiable

  

Resolution

Conjunctive Normal Form (CNF) conjunction of disjunctions of literals clauses

  E.g., (A  B)  (B  C  D)

  • Resolution inference rule (for CNF):
  • l , m

    …  l  …  m

  i k 1 n l l   m  m ...  m

   …  l  …  l  …  m i i-1 i+1 k 1 j-1 j+1 n dimana l dan m adalah complementary literals. i j

  Misal: P ,  PP 1,3 2,2 2,2

  P 1,3

  

Resolution

Soundness of resolution inference rule: l

  • (l   l )  …  l  …  l

  i i-1 i+1 k i

  • m  (m  m ...  m )  …  m

  j 1 j-1 j+1 n l

  • (l   (m  m ...  m )

  )  …  l  …  l  …  m i i-1 i+1 k 1 j-1 j+1 n

  1,1 )

  )  B 1,1

  3. Move

  ( B 1,1

   P 1,2

   P 2,1

  )  ((P 1,2

   P 2,1

  )

  )  B 1,1

  4. Apply distributivity law (  over ) and flatten: (

  1,1  P

  1,2  P

  2,1 )  (P

  1,2  B

  1,1 )  (P

  2,1  B

  )

   P 2,1

  

Konversi ke CNF

B

   P 2,1

  1,1  (P

  1,2  P

  2,1 ) β

  1. Eliminate , replacing α  β with (α  β)(β  α).

  (B 1,1

   (P 1,2

  ))  ((P 1,2

  )  ((P 1,2

   P 2,1

  )  B 1,1

  )

  2. Eliminate , replacing α  β with α β.

  ( B 1,1

   P 1,2

   P 2,1

  • inwards using de Morgan's rules and double- negation:
  • B

  

Algortima Resolution

  

Resolution example

  α = P 1,1 1,2 2,1 1,1 1,2

  • KB = (B  (P  P ))  B

  

Forward and backward chaining

  • Horn Form (restricted)

  KB = conjunction of Horn clauses

  • Horn clause =
  • proposition symbol; or
  • (conjunction of symbols)  symbol
  • E.g., C  (B  A)  (C  D  B)

  Modus Ponens (for Horn Form): complete for Horn KBs

  • ,

    α , … ,α α  …  α  β

  1 n 1 n

β

  • Can be used with forward chaining or backward chaining .
  • These algorithms are very natural and run in linear time

  

Forward chaining

  • Ide: sembarang rule yang memiliki premise yang satisfy dalam KB,
  • Tambahkan kesimpulan ke KB, sampai query ditemukan

  

Algortima Forward chaining

  

Contoh Forward chaining

  

Contoh Forward chaining

  

Contoh Forward chaining

  

Contoh Forward chaining

  

Forward chaining example

  

Contoh Forward chaining

  

Contoh Forward chaining

  

Contoh Forward chaining

  

Backward chaining

Ide: bekerja backwards dari query q: membuktikan q dengan BC,

  , atau cek jika q sudah diketahui buktikan dengan BC semua premise pada beberapa rule concluding q

Avoid loops: chek jika subgoal baru sudah siap pada stack

tujuan Avoid repeated work: check if new subgoal telah terbukti benar, atau telah gagal

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining

  

Contoh Backward chaining Sumber :