HO05-MetodeDictionary

7

Click here to load reader

Transcript of HO05-MetodeDictionary

Page 1: HO05-MetodeDictionary

1

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

METODE DICTIONARYMETODE DICTIONARYKOMPRESI DATAKOMPRESI DATA

TP4113TP4113

RestyanditoRestyandito, S.Kom, MSIS, S.Kom, MSISMetode Dictionary Kompresi Data Restyandito - 2

DictionaryDictionary--Based CompressionBased CompressionAlgoritma ini menggunakan suatu tabel referensi Algoritma ini menggunakan suatu tabel referensi untuk menyimpan simbol yang akan dikodekan.untuk menyimpan simbol yang akan dikodekan.Contoh:Contoh: menggunakanmenggunakan Random House Random House Dictionary of the English Language, 2nd Ed, Dictionary of the English Language, 2nd Ed, Unabridged.Unabridged.

no halaman

‘Contoh yg baik suatu dictionary based compression….’

1/1 822/3 674/4 1343/60 928/75 550/32 173/46 421/2

no item dalam suatu halaman

Metode Dictionary Kompresi Data Restyandito - 3

PengkodeanPengkodean static dictionary static dictionary ::A=A={a,b,c,d,r{a,b,c,d,r}}

code entry000 a001 b010 c011 d100 r101 ab110 ac111 ad

Untuk mengkodekanabracadabra.

String output yg dihasilkan101100110111101100000.

Dictionary Based CompressionDictionary Based Compression

Metode Dictionary Kompresi Data Restyandito - 4

DictionaryDictionary--Based CompressionBased CompressionBeberapa teknik DictionaryBeberapa teknik Dictionary--basedbased compression compression yg saat ini banyak digunakan dalam kompresi yg saat ini banyak digunakan dalam kompresi data yang bersifat lossles yaitu:data yang bersifat lossles yaitu:

WinzipWinzipWinarjWinarj

Metode Dictionary Kompresi Data Restyandito - 5

LempelLempel--Ziv CodingZiv CodingAlgoritma ini tidakAlgoritma ini tidak mengkodekan sebuah simbol mengkodekan sebuah simbol sebagai bit streams, ttpsebagai bit streams, ttp mengkodekan beberapa mengkodekan beberapa variabel sebagai sebuah token.variabel sebagai sebuah token.

MasingMasing--masing token disimpan dalam sebuah masing token disimpan dalam sebuah tabel yang dimiliki oleh tabel yang dimiliki oleh encoderencoder maupun maupun decoderdecoder

Metode Dictionary Kompresi Data Restyandito - 6

LempelLempel--Ziv CodingZiv CodingDlm kamus terdapat sekitar 31.500 kata, dan Dlm kamus terdapat sekitar 31.500 kata, dan menurut formula menurut formula information content information content Shannon, Shannon, sebuah kata dapat dikodekan dengan 18 buah sebuah kata dapat dikodekan dengan 18 buah bits.bits.Dengan menggunakan LZ compression, berapa Dengan menggunakan LZ compression, berapa digit diperlukan untuk mengkodekan seluruh digit diperlukan untuk mengkodekan seluruh kata dalam kamus?kata dalam kamus?Berapa rasio kompresi jika akan dikodekan kata Berapa rasio kompresi jika akan dikodekan kata MULTIMEDIAMULTIMEDIA ??

Page 2: HO05-MetodeDictionary

2

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 7

LempelLempel--Ziv CodingZiv CodingLATIHANLATIHAN

Suatu file teks akan dikompres. Jika rataSuatu file teks akan dikompres. Jika rata--rata rata jumlah karakter per kata adalah 6, dan jumlah karakter per kata adalah 6, dan dictionarydictionary yang digunakan berisi 4096 buah kata, yang digunakan berisi 4096 buah kata, berapakah rasio kompresi yang diperoleh jika berapakah rasio kompresi yang diperoleh jika digunakan algoritma LZ.digunakan algoritma LZ.

Metode Dictionary Kompresi Data Restyandito - 8

Static vs. AdaptiveStatic vs. Adaptive DictionaryDictionary

Pendekatan StaticPendekatan StaticKamus dibuat sebelum pengkodean.Kamus dibuat sebelum pengkodean.Dibutuhkan pengetahuan yang memadai Dibutuhkan pengetahuan yang memadai mengenai sourcemengenai source

Pendekatan AdaptivePendekatan AdaptiveKamus dibuat pada saat proses pengkodean.Kamus dibuat pada saat proses pengkodean.

Metode Dictionary Kompresi Data Restyandito - 9

LempelLempel--ZivZiv--Welsh CodingWelsh CodingAlgoritma LZW mengkodekan suatu teks secara Algoritma LZW mengkodekan suatu teks secara dinamis.dinamis.Sebagai inisialisasi, Sebagai inisialisasi, dictionarydictionary berisi set karakter berisi set karakter yang digunakan untuk membuat suatu teks (mis yang digunakan untuk membuat suatu teks (mis ASCII)ASCII)Selanjutnya Selanjutnya dictionarydictionary diisi secara dinamis diisi secara dinamis berdasarkan kataberdasarkan kata--kata yang ada dalam teks.kata yang ada dalam teks.

Metode Dictionary Kompresi Data Restyandito - 10

Contoh: Contoh: ((dictionary index = dictionary index = 8 bit)8 bit)teknik kompresi LZW itu gampangteknik kompresi LZW itu gampang

::

gampanggampang

ituitu

LZWLZW

kompresikompresi

teknikteknik

DELDEL

::

SOHSOH

NULNUL

255255

132132

131131

130130

129129

128128

127127

::

11

00

LempelLempel--ZivZiv--Welsh CodingWelsh Coding

Metode Dictionary Kompresi Data Restyandito - 11

LZ77LZ77““ A Universal Algorithm for Sequential Data A Universal Algorithm for Sequential Data Compression,Compression,”” diterbitkan dalam diterbitkan dalam IEEE IEEE Transactions on Information TheoryTransactions on Information Theory , 1977, 1977Sliding Windows CompressionSliding Windows CompressionStruktur data berupa Struktur data berupa text windowstext windows yang dibagi yang dibagi menjadi 2 bagian, terdiri dari teks yang sudah menjadi 2 bagian, terdiri dari teks yang sudah dikodekan, dan bagian dari teks yang akan dikodekan, dan bagian dari teks yang akan dikodekan dikodekan (look ahead buffer)(look ahead buffer)

Metode Dictionary Kompresi Data Restyandito - 12

LZ77LZ77

Frasa dalam teks inputan diganti dengan sebuah Frasa dalam teks inputan diganti dengan sebuah pointer yang ada pada pointer yang ada pada dicitionarydicitionaryUkuran normal text window : Beberapa ribu chr Ukuran normal text window : Beberapa ribu chr Ukuran normal lookUkuran normal look--ahead buffer : 10 ~100 chrahead buffer : 10 ~100 chr

A;^for(i=0;^i<MAX-1;^i++)\r^for(j=i+1;^j <MAX^;^j++

Text window 40 chars

Look-ahead buffer10 chars

Page 3: HO05-MetodeDictionary

3

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 13

LZ77LZ77 A;^for(i=0;^i<MAX-1;^i++)\r^for(j=i+1;^j <MAX^;^j++

Token :Token :an an offsetoffset to a phrase in the text window to a phrase in the text window the the lengthlength of the phrase ; andof the phrase ; andthe the first symbolfirst symbol in the lookin the look--ahead buffer that follows ahead buffer that follows the phrase.the phrase.

““<MAX^<MAX^”” dikodekan sebagai ( 14, 4,dikodekan sebagai ( 14, 4,””^””))((The Data Compression BookThe Data Compression Book -- Mark Nelson Mark Nelson ))

Metode Dictionary Kompresi Data Restyandito - 14

A;^for(i=0;^i<MAX-1;^i++)\r^for(j=i+1;^j <MAX^;^j++

r(i=0;^i<MAX-1;^i++)\r^for(j=i+1;^j<MAX^ ;^j++)\r^a[i]

LZ77LZ77

Geser token ke dalam Geser token ke dalam text windows text windows (5 karakter)(5 karakter)Masukkan 5 simbol baru ke dalam Masukkan 5 simbol baru ke dalam looklook--ahead ahead bufferbufferToken berikutnya adalah (33, 3, +)Token berikutnya adalah (33, 3, +)Jika dalam Jika dalam text windows text windows tidak ada yang match, tidak ada yang match, maka token = maka token = (0,0,karakter)(0,0,karakter)

Metode Dictionary Kompresi Data Restyandito - 15

LZ77LZ77Untuk menUntuk men--decode hasil kompresi cukup decode hasil kompresi cukup sederhana:sederhana:

1.1. reads in a token reads in a token 2.2. outputs the indicated phrase outputs the indicated phrase 3.3. shifts shifts 4.4. repeatsrepeats

Metode Dictionary Kompresi Data Restyandito - 16

r ( i = 0 ; ^ i < M A X - 1 ; ^ i + + ) \ r ^ f o r ( j = i + 1 ; ^ j < M A X ; ^ j +

LZ77LZ77MenMen--decode token ( 14, 4,decode token ( 14, 4,””^””))

Text window

A;^for(i=0;^i<MAX-1;^i++)\r^for(j=i+1;^j <MAX^

14

MenMen--decode token ( 33, 3,decode token ( 33, 3,””++””))

33

Metode Dictionary Kompresi Data Restyandito - 17

LZ77LZ77

Token :Token :an an offsetoffset to a phrase in the text window to a phrase in the text window (dari kanan (dari kanan ke kiri)ke kiri)the the lengthlength of the phrase; andof the phrase; andthe the first symbolfirst symbol in the lookin the look--ahead buffer that follows ahead buffer that follows the phrase.the phrase.

((Data Compression: The Complete Reference Data Compression: The Complete Reference –– David SalomonDavid Salomon))

Metode Dictionary Kompresi Data Restyandito - 18

LZ77LZ77

Contoh: CODINGContoh: CODINGkukukuku--kuku kaki kakak kakekku kakukuku kaki kakak kakekku kaku--kaku kok.kaku kok.

k u k u – k u k u ^ k a k i ^ k a k a k ^ k a k e k k u ^ k a (11, 3,”e”)

– k u k u ^ k a k i ^ k a k a k ^ k a k e k k u ^ k a k u – k (20, 1,”k”)

u k u ^ k a k i ^ k a k a k ^ k a k e k k u ^ k a k u – k a k (19, 5,”u”)

k i ^ k a k a k ^ k a k e k k u ^ k a k u – k a k u ^ k o k . ( 0, 0,”k”)

LatihanLatihanKodekan kalimat di atas menggunakan LZ77 (Salomon) Kodekan kalimat di atas menggunakan LZ77 (Salomon) dimulai dengan huruf pertama!dimulai dengan huruf pertama!

Page 4: HO05-MetodeDictionary

4

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 19

LZ77LZ77

Contoh: DECODE Contoh: DECODE

k u k u – k u k u ^ k a k i ^ k a k a k ^ (11, 3,”e”)

– k u k u ^ k a k i ^ k a k a k ^ k a k e(20, 1,”k”)

u k u ^ k a k i ^ k a k a k ^ k a k e k k(19, 5,”u”)

k i ^ k a k a k ^ k a k e k k u ^ k a k u( 0, 0,”k”)

Algoritma ini cocok untuk kasusAlgoritma ini cocok untuk kasus--kasus dimana kasus dimana suatu file dikompres sekali tetapi disuatu file dikompres sekali tetapi di--dekompres dekompres berkaliberkali--kalikali

Metode Dictionary Kompresi Data Restyandito - 20

Circular QueueCircular Queuestruktur data dasarstruktur data dasarLarik berisi karakter yg ditambahkan diakhirLarik berisi karakter yg ditambahkan diakhirJika larik penuh, karakter pertama dihapusJika larik penuh, karakter pertama dihapusContoh: (CQ 16 bytes)Contoh: (CQ 16 bytes)

k u k u – k u

k u k u – k u k u ^ k a k i ^ k

a u k u – k u k u ^ k a k i ^ k

k a k a k k u k u ^ k a k i ^ k

LZ77LZ77

Metode Dictionary Kompresi Data Restyandito - 21

LZSSLZSSDikembangkan oleh Storer dan SzymanskiDikembangkan oleh Storer dan SzymanskiMemperbaiki LZ77 dalam hal:Memperbaiki LZ77 dalam hal:

menyimpan menyimpan looklook--aheadahead--bufferbuffer dalam suatu dalam suatu circular circular queuequeuemenyimpan menyimpan search buffer (dictionary)search buffer (dictionary) dalam dalam binary binary search treesearch treemembuat token dnegan dua buah field saja membuat token dnegan dua buah field saja

Metode Dictionary Kompresi Data Restyandito - 22

aku

cincin

energi

gula

harimau

indah

kamar

mandi

pakaian

rahasia

LZSSLZSSContoh binary treeContoh binary tree

gula

cincin kamar

aku energi indah mandi

harimau pakaian

Metode Dictionary Kompresi Data Restyandito - 23

LZSSLZSSContoh: Contoh: search buffer (16B), looksearch buffer (16B), look--aheadahead--buffer (5B)buffer (5B)

a k u ^ m e m a k a i ^ p a k a i a n ^ d i ^ k a m a r ^ m a n d i

encoder membuat tree yang terdiri dari 5 karakterencoder membuat tree yang terdiri dari 5 karaktera k u ^ m offset 16k u ^ m e 15u ^ m e m 14^ m e m a 13m e m a k 12e m a k a i 11m a k a i 10a k a i ^ 9k a i ^ p 8a i ^ p a k 7i ^ p a k a 6^ p a k a 5

i a n ^ d

(6, 1)

Metode Dictionary Kompresi Data Restyandito - 24

LZSSLZSSContoh: Contoh: search buffer (16B), looksearch buffer (16B), look--aheadahead--buffer (5B)buffer (5B)

a k u ^ m e m a k a i ^ p a k a i a n ^ d i ^ k a m a r ^ m a n d i

k u ^ m e m a k a i ^ p a k a i a n ^ d i ^ k a m a r ^ m a n d i

Pohon diupdate dengan menghapus 1 string Pohon diupdate dengan menghapus 1 string

dan menambah 1 string barudan menambah 1 string barua k u ^ m offset 16

p a k a i 5

Page 5: HO05-MetodeDictionary

5

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 25

LZSSLZSSContoh:Contoh: LZSS is better than LZ77LZSS is better than LZ77

"LZSS"

"^is^b" "ZSSi"

"SSis"

"S is "

"is be"

"s bet"

"^bett"

"bette"

"etter"

"tter "

"ter t"

"er th" "r^tha"

"^than"

"than ""han L""an LZ"

"n^LZ7"

"^LZ77"

Isi dari setiap simpul adalah pointer ke text

window

isi dari text window

Metode Dictionary Kompresi Data Restyandito - 26

LZSSLZSSLZSS uses a single bit as a prefix to every output LZSS uses a single bit as a prefix to every output token to indicate whether it is an offset/ length token to indicate whether it is an offset/ length pair or a single symbol for output.pair or a single symbol for output.

Matched phrase (0,position, length, character)Matched phrase (0,position, length, character)NonNon--matched phrase (1,character)matched phrase (1,character)

If the text window size is 4096 characters, lookIf the text window size is 4096 characters, look--ahead buffer size is 16 characters,ahead buffer size is 16 characters,

Matched token needs 1+12+4+8=25 bitsMatched token needs 1+12+4+8=25 bitsNonNon--matched token needs 1+8=9 bitsmatched token needs 1+8=9 bits

Metode Dictionary Kompresi Data Restyandito - 27

LZSSLZSSGreedy vs. Optimal Greedy vs. Optimal Baik LZ77 maupun LZSS disebut algoritma Baik LZ77 maupun LZSS disebut algoritma ““greedygreedy”” :Keduanya tidak menganalisa :Keduanya tidak menganalisa input input stream stream untuk mencari kombinasi terbaik dari untuk mencari kombinasi terbaik dari indeks dan karakter.indeks dan karakter.

Contoh: Contoh: dictionary dictionary frasa yang dikodekanfrasa yang dikodekanGo^TGo^T Go To StatementGo To Statemento^So^Stattat^Stat^Stat

Aturan:Aturan: 25 bits utk index/offset pair25 bits utk index/offset pair9 bits utk sebuah character9 bits utk sebuah character

Metode Dictionary Kompresi Data Restyandito - 28

LZSSLZSS

〝Go^T〞 :25

〝o^S〞 :25

〝 tat〞 :25

:75

〝Go〞 :25

〝T〞 : 9

“o” 〝Stat〞

: 0

:25

:68

first longest possible as greedy

best match as optimized

Metode Dictionary Kompresi Data Restyandito - 29

• In the world of data compression, a few good heuristics are often more respected than a provably superior algorithm.

• The greedy heuristics in this case is definitely the choice of most compression programmers.

LZSSLZSS

Metode Dictionary Kompresi Data Restyandito - 30

DISKUSIDISKUSIApakah besar Apakah besar texttext--windowswindows dan dan looklook--upup--table table ada pengaruhnya terhadap hasil ada pengaruhnya terhadap hasil kompresi?kompresi?

Contoh:Contoh:sir_sid_eastman_easily_teases_sea_sick_sealssir_sid_eastman_easily_teases_sea_sick_seals

Page 6: HO05-MetodeDictionary

6

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 31

LZ78LZ78Kelemahan algoritma LZ77Kelemahan algoritma LZ77

Keterbatasan Keterbatasan text windows text windows mengakibatkan banyak mengakibatkan banyak frasa yang terbuang.frasa yang terbuang.Ukuran frasa yang cocok terbatas sesuai dengan Ukuran frasa yang cocok terbatas sesuai dengan looklook--ahead buffer ahead buffer yang digunakan.yang digunakan.

LZ88 tidak menggunakan konsep LZ88 tidak menggunakan konsep text windowstext windowsLZ77: dictionary ditentukan oleh LZ77: dictionary ditentukan oleh text windowstext windows dari dari teks yang dibaca/dikodekan sebelumnya.teks yang dibaca/dikodekan sebelumnya.LZ78: dictionary berupa daftar yg tak terbatas dari LZ78: dictionary berupa daftar yg tak terbatas dari frasa yang dilihat sebelumnyafrasa yang dilihat sebelumnya

suatu code yg memilih suatu frasa yg diberikansuatu code yg memilih suatu frasa yg diberikanSebuah karakter yg mengikuti frasa tersebutSebuah karakter yg mengikuti frasa tersebut

Metode Dictionary Kompresi Data Restyandito - 32

LZ78LZ78Token berisikan:Token berisikan:

suatu code yg memilih suatu frasa yang suatu code yg memilih suatu frasa yang diberikandiberikansebuah karakter yg mengikuti frasa tersebutsebuah karakter yg mengikuti frasa tersebut

LangkahLangkah--langkahlangkahMulai dengan sebuah null string pada posisi nolMulai dengan sebuah null string pada posisi nolSimbol yg dikodekan dimasukkan ke dalam tabel Simbol yg dikodekan dimasukkan ke dalam tabel secara urutsecara urutJika tabel telah berisi, dicari simbol yang sama, Jika tabel telah berisi, dicari simbol yang sama, jika ditemukan masukkan offset dan simbol.jika ditemukan masukkan offset dan simbol.

Metode Dictionary Kompresi Data Restyandito - 33

LZ78LZ78Contoh:Contoh: sir_sid_eastman_easily_teases_sea_sick_sealssir_sid_eastman_easily_teases_sea_sick_seals

Metode Dictionary Kompresi Data Restyandito - 34

LZ78LZ78Contoh:Contoh: sir_sid_eastman_easily_teases_sea_sick_sealssir_sid_eastman_easily_teases_sea_sick_seals

Metode Dictionary Kompresi Data Restyandito - 35

LZ78LZ78Latihan:Latihan: kukukuku--kuku kaki kakakku kakukuku kaki kakakku kaku--kaku kaku

Metode Dictionary Kompresi Data Restyandito - 36

LZPLZPCharles Bloom: Prinsip prediksi konteksCharles Bloom: Prinsip prediksi konteksS = String S = String : simbol yg akan dikodekan: simbol yg akan dikodekanC = ContextC = Context : string yg biasanya mengikuti S: string yg biasanya mengikuti SNN : panjang C: panjang C

Page 7: HO05-MetodeDictionary

7

TP4113 – Kompresi Data

Restyandito, S.Kom,MSIS

5-Metode Dictionary Kompresi Data

Metode Dictionary Kompresi Data Restyandito - 37

LZPLZPAlgoritmaAlgoritma

1. 1. It saves P and replace it in the index table with a It saves P and replace it in the index table with a fresh pointer Q pointing to S in the lookfresh pointer Q pointing to S in the look--ahead ahead buffer. L is set to zero.buffer. L is set to zero.

2.2. If P is not a null pointer, it compares the string If P is not a null pointer, it compares the string pointed by P to S, set L to the match length.pointed by P to S, set L to the match length.

3.3. If L = 0, the buffer is slid to the right one position If L = 0, the buffer is slid to the right one position and the first symbol of string S is written to the and the first symbol of string S is written to the compressed stream as a raw ASCII codecompressed stream as a raw ASCII code

4.4. If L > 0, the buffer is slid to the rigth L positions If L > 0, the buffer is slid to the rigth L positions and the value of L is written on the compressed and the value of L is written on the compressed streams.streams.

Metode Dictionary Kompresi Data Restyandito - 38

LZPLZP

Metode Dictionary Kompresi Data Restyandito - 39

LZYLZY

Metode Dictionary Kompresi Data Restyandito - 40

BUKU ACUANBUKU ACUAN

Hallsal, F, 2001, Hallsal, F, 2001, Multimedia Communications Multimedia Communications ––Applications, Networks, Protocols and StandardsApplications, Networks, Protocols and Standards, , AddisonAddison--Wesley (p. 136Wesley (p. 136--140)140)

Salomon, D, 2000, Salomon, D, 2000, Data Compression, The Complete Data Compression, The Complete Reference, 2Reference, 2ndnd editionedition, , Springer (p. 165Springer (p. 165--245)245)

TERIMAKASIHTERIMAKASIH