01.08.2013 Views

Information Theory, Inference, and Learning ... - MAELabs UCSD

Information Theory, Inference, and Learning ... - MAELabs UCSD

Information Theory, Inference, and Learning ... - MAELabs UCSD

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Copyright Cambridge University Press 2003. On-screen viewing permitted. Printing not permitted. http://www.cambridge.org/0521642981<br />

You can buy this book for 30 pounds or $50. See http://www.inference.phy.cam.ac.uk/mackay/itila/ for links.<br />

106 5 — Symbol Codes<br />

encoded with the longer codeword that was c’s, <strong>and</strong> c, which is more probable<br />

than a, gets the shorter codeword. Clearly this reduces the expected length<br />

of the code. The change in expected length is (pa − pc)(lc − la). Thus we have<br />

contradicted the assumption that the rival code is optimal. Therefore it is<br />

valid to give the two symbols with smallest probability equal encoded lengths.<br />

Huffman coding produces optimal symbol codes. ✷<br />

Solution to exercise 5.21 (p.102). A Huffman code for X 2 where AX = {0, 1}<br />

<strong>and</strong> PX = {0.9, 0.1} is {00, 01, 10, 11} → {1, 01, 000, 001}. This code has<br />

L(C, X 2 ) = 1.29, whereas the entropy H(X 2 ) is 0.938.<br />

A Huffman code for X 3 is<br />

{000, 100, 010, 001, 101, 011, 110, 111} →<br />

{1, 011, 010, 001, 00000, 00001, 00010, 00011}.<br />

This has expected length L(C, X 3 ) = 1.598 whereas the entropy H(X 3 ) is<br />

1.4069.<br />

A Huffman code for X 4 maps the sixteen source strings to the following<br />

codelengths:<br />

{0000, 1000, 0100, 0010, 0001, 1100, 0110, 0011, 0101, 1010, 1001, 1110, 1101,<br />

1011, 0111, 1111} → {1, 3, 3, 3, 4, 6, 7, 7, 7, 7, 7, 9, 9, 9, 10, 10}.<br />

This has expected length L(C, X 4 ) = 1.9702 whereas the entropy H(X 4 ) is<br />

1.876.<br />

When PX = {0.6, 0.4}, the Huffman code for X 2 has lengths {2, 2, 2, 2};<br />

the expected length is 2 bits, <strong>and</strong> the entropy is 1.94 bits. A Huffman code for<br />

X 4 is shown in table 5.10. The expected length is 3.92 bits, <strong>and</strong> the entropy<br />

is 3.88 bits.<br />

Solution to exercise 5.22 (p.102). The set of probabilities {p1, p2, p3, p4} =<br />

{ 1/6, 1/6, 1/3, 1/3} gives rise to two different optimal sets of codelengths, because<br />

at the second step of the Huffman coding algorithm we can choose any of the<br />

three possible pairings. We may either put them in a constant length code<br />

{00, 01, 10, 11} or the code {000, 001, 01, 1}. Both codes have expected length<br />

2.<br />

Another solution is {p1, p2, p3, p4} = { 1/5, 1/5, 1/5, 2/5}.<br />

And a third is {p1, p2, p3, p4} = { 1/3, 1/3, 1/3, 0}.<br />

Solution to exercise 5.26 (p.103). Let pmax be the largest probability in<br />

p1, p2, . . . , pI. The difference between the expected length L <strong>and</strong> the entropy<br />

H can be no bigger than max(pmax, 0.086) (Gallager, 1978).<br />

See exercises 5.27–5.28 to underst<strong>and</strong> where the curious 0.086 comes from.<br />

Solution to exercise 5.27 (p.103). Length − entropy = 0.086.<br />

Solution to exercise 5.31 (p.104). There are two ways to answer this problem<br />

correctly, <strong>and</strong> one popular way to answer it incorrectly. Let’s give the incorrect<br />

answer first:<br />

Erroneous answer. “We can pick a r<strong>and</strong>om bit by first picking a r<strong>and</strong>om<br />

source symbol xi with probability pi, then picking a r<strong>and</strong>om bit from<br />

c(xi). If we define fi to be the fraction of the bits of c(xi) that are 1s,<br />

we find C3:<br />

P (bit is 1) = <br />

(5.34)<br />

i<br />

pifi<br />

= 1/2 × 0 + 1/4 × 1/2 + 1/8 × 2/3 + 1/8 × 1 = 1/3.” (5.35)<br />

ai pi li c(ai)<br />

0000 0.1296 3 000<br />

0001 0.0864 4 0100<br />

0010 0.0864 4 0110<br />

0100 0.0864 4 0111<br />

1000 0.0864 3 100<br />

1100 0.0576 4 1010<br />

1010 0.0576 4 1100<br />

1001 0.0576 4 1101<br />

0110 0.0576 4 1110<br />

0101 0.0576 4 1111<br />

0011 0.0576 4 0010<br />

1110 0.0384 5 00110<br />

1101 0.0384 5 01010<br />

1011 0.0384 5 01011<br />

0111 0.0384 4 1011<br />

1111 0.0256 5 00111<br />

Table 5.10. Huffman code for X 4<br />

when p0 = 0.6. Column 3 shows<br />

the assigned codelengths <strong>and</strong><br />

column 4 the codewords. Some<br />

strings whose probabilities are<br />

identical, e.g., the fourth <strong>and</strong><br />

fifth, receive different codelengths.<br />

ai c(ai) pi li<br />

a 0 1/2 1<br />

b 10 1/4 2<br />

c 110 1/8 3<br />

d 111 1/8 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!