-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotes.tex
More file actions
3628 lines (2983 loc) · 113 KB
/
notes.tex
File metadata and controls
3628 lines (2983 loc) · 113 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[twoside]{article}
% General document formatting
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage[nameinlink]{cleveref}
\usepackage{xcolor}
\usepackage[toc,page]{appendix}
\usepackage[]{algorithm2e}
\title{Information Theory and Coding - Prof.~Telatar}
\date{\today}
\author{Jean-Baptiste Cordonnier, Sebastien Speierer}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{claim}{Claim}[section]
\newtheorem{fact}{Fact}[section]
\newtheorem{consequence}{Consequence}[section]
\newtheorem{observation}{Observation}[section]
\newtheorem*{wikipedia}{Wikipedia}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]
\newtheorem{proposition}{Proposition}[section]
\newtheorem{notation}{Notation}
\theoremstyle{definition} % Attention side effects lololol~
\newtheorem{example}{Example}
\newcommand{\todo}[1]{\textcolor{red}{TODO: #1}}
\renewcommand{\Pr}[1]{Pr\left\{#1\right\}}
\newcommand{\Ex}[1]{\mathbb{E}\left[#1\right]}
\newcommand{\pfrac}[2]{\left( \frac{#1}{#2} \right)}
\newcommand{\overeq}[1]{\stackrel{#1}{=}}
% math bold
\def\*#1{\mathbf{#1}}
% manuscript characters
\def\D{\mathcal{D}}
\def\V{\mathcal{V}}
\def\L{\mathcal{L}}
\def\U{\mathcal{U}}
\def\N{\mathcal{N}}
\def\X{\mathcal{X}}
\def\Y{\mathcal{Y}}
\def\R{\mathbb{R}}
\def\F{\mathbb{F}}
\def\I{\mathbb{I}}
\def\C{\mathcal{C}}
\DeclareMathOperator{\E}{\mathbb{E}}% expected value
\begin{document}
\maketitle
\setcounter{tocdepth}{1}
\tableofcontents
\cleardoublepage
\section{Data compression}
\begin{definition}[Information]
Abstractly, \textbf{information} can be thought of as the resolution of uncertainty.
\end{definition}
Given an alphabet $\U$ (e.g. $\U = \{a, ..., z, A, ..., Z, ...\}$), we want to assign binary sequences to elements of $\U$, i.e.
\begin{align*}
\C: \U \rightarrow \{0, 1\}^* = \{\emptyset, 0, 1, 00, 01, ...\}
\end{align*}
For $\X$ a set
\begin{align*}
\X^n &\equiv \{ (x_0 ... x_n), x_i \in \X\} \\
\X^* &\equiv \bigcup_{n \geq 0} \X^n
\end{align*}
\begin{definition}
A code $\C$ is called \textbf{singular} if
\begin{align*}
\exists (u, v) \in \U^2, u \neq v \quad s.t. \quad \C(u) = \C(v)
\end{align*}
Non singular code is defined as opposite
\end{definition}
\begin{definition}
A code $\C$ is called \textbf{uniquely decodable} if
\begin{align*}
\forall u_1,...,u_n,v_1,...,v_n \in \U^* \quad s.t. \quad u_1,...,u_n \neq v_1,...,v_n
\end{align*}
we have
\begin{align*}
\C(u_1)...\C(u_n) \neq \C(v_1)...\C(v_n)
\end{align*}
i.e, $\C$ is non-singular
\end{definition}
\begin{definition}
Suppose $\C : \U \rightarrow \{ 0, 1\}^*$ and $\D : \V \rightarrow \{ 0, 1\}^*$ we can define
\begin{align*}
\C \times \D : \U \times \V \rightarrow \{0, 1\}^*
\quad \text{ as } \quad
(\C \times \D)(u, v) \rightarrow \C(u)\D(v)
\end{align*}
\end{definition}
\begin{definition}
Given $\C : \U \rightarrow \{ 0, 1\}^*$, define
\begin{align*}
\C^* : \U^* \rightarrow \{0, 1\}^*
\quad \text{ as } \quad
\C^*(u_1 ... u_n) = \C(u_1)...\C(u_n)
\end{align*}
\end{definition}
\begin{definition}
A code $\U \rightarrow \{0, 1\}^*$ is \textbf{prefix-free} is for no $u \neq v$ $\C(u)$ is a prefix of $\C(v)$.
\end{definition}
\begin{theorem}
If $\C$ is prefix-free then $\C$ is uniquely decodable.
\end{theorem}
\begin{definition}
$l(\C(u))$ is the length of the code word $\C(u)$ and $l(\C)$ is the expected length of the code:
\begin{align*}
l(\C) = \sum_u l(\C(u)) p(u)
\end{align*}
\end{definition}
\begin{definition}[Kraft sum]
Given $\C : \U \rightarrow \{ 0, 1\}^*$
\begin{align*}
kraftsum(\C) = \sum_u 2^{-l(\C(u))}
\end{align*}
\end{definition}
\begin{lemma}
if $\C : \U \rightarrow \{ 0, 1\}^*$ and $\D : \V \rightarrow \{ 0, 1\}^*$
then
$$kraftsum(\C \times \D) = kraftsum(\C) \times kraftsum(\D)$$
\begin{proof}
\begin{align*}
kraftsum(\C \times \D) &= \sum_{u, v} 2^{-(l(\C) * l(\D))} \\
&= \sum_u 2^{-l(\C)} \sum_v 2^{- l(\D)}
\end{align*}
\end{proof}
\end{lemma}
\begin{corollary}
$kraftsum(\C^n) = (kraftsum(\C))^n$
\end{corollary}
\begin{proposition}
if $\C$ is non-singular, then
\begin{align*}
kraftsum(\C) \leq 1 + \max_u l(\C(u))
\end{align*}
\end{proposition}
In coding theory, the \textbf{Kraft-McMillan inequality} gives a necessary and sifficient condition for the existence of a uniquely decodable code for a given set of codeword lengths.
\begin{wikipedia}
Kraft's inequality limits the lengths of codewords in a prefix code: if one takes an exponential of the length of each valid codeword, the resulting set of values must look like a probability mass function, that is, it must have total measure less than or equal to one. Kraft's inequality can be thought of in terms of a constrained budget to be spent on codewords, with shorter codewords being more expensive.
\end{wikipedia}
\begin{theorem}
if $\C$ is uniquely decodable, then $kraftsum(\C) \leq 1$
\end{theorem}
\begin{proof}
$\C$ is uniquely decodable $\equiv$ $\C^*$ is non singular
\begin{align*}
&\Rightarrow kraftsum(\C^n) \leq 1 + \max _{u_1, ..., u_n} l(\C^n) \\
&\Rightarrow kraftsum(\C)^n \leq 1 + n L, \quad L = \max l(\C(n))
\end{align*}
A growing exp cannot be bounded by a linear function
\begin{align*}
\Rightarrow kraftsum(\C) \leq 1
\end{align*}
\end{proof}
\begin{theorem}
Suppose $\C : \U \rightarrow \N$ is such that $\sum_u 2^{-l(\C(u))} \leq 1$, then, there exists a prefix-free code $\C': \U \rightarrow \{0, 1\}$ s.t. $\forall u, l(\C'(u)) = l(\C(u))$
\end{theorem}
\begin{proof}
Let $\U = \{u_1, ..., u_n\}$ and $\C(u_1) \leq \C(u_2) \leq ... \leq \C(u_k) = \C_{max}$.
Consider the complete binary tree up to depth $\C_{max}$ initially all nodes are available to be used as codewords.
For $i = 1, 2, ..., n$, place $\C(u_i)$ at an available node at level $\C(u_i)$ remove all descendant of $\C(u_i)$ from the available list.
\begin{corollary}
Suppose $\C: \U \rightarrow \{0, 1\}^*$ is uniquely decodable, then there exist an $\C': \U \rightarrow \{0, 1\}^*$ which is prefix-free and $l(\C'(n)) = l(\C(n))$
\end{corollary}
\end{proof}
\begin{example}
$\U = \{a, b, c, d\}$, $\C: \{0, 01, 011, 111\}$ and $\C': \{0, 10, 110, 111\}$\\
In this case, decoding $\C$ may require delay, while decoding $\C'$ is instanteneous.
\end{example}
% -------------------------------------------------------------
\cleardoublepage
\section{Alphabet with statistics}
Suppose we have an alphabet $\U$, and suppose we have a random variable $U$ taking values in $\U$. We denote by $p(u) = Pr(U = u), u \in \U$ with $p(u) \geq 0$ and $\sum_u p(u) = 1$.\\
Suppose we have a code $\C: \U \rightarrow \{0, 1\}^*$. We then have $\C(u)$ a random binary string and $l(\C(u))$ a random integer.
\begin{example}
$\U = \{a, b, c, d\}$\\
$p: \{0.5, 0.25, 0.125, 0.125\}$ \\
$\C: \{0, 01, 110, 111\}$ \\
then we have
\begin{align*}
l(\C(u)) =
\left\{
\begin{array}{l}
1, \quad p = 0.5 \\
2, \quad p = 0.25 \\
3, \quad p = 0.125 + 0.125 = 0.25
\end{array}
\right.
\end{align*}
\end{example}
We can measure how efficient $\C$ represents $\U$ by considering
\begin{align*}
E[l(\C(u))] = \sum_u p(u)l(\C(u)) \quad \text{with} \quad \C(u) = l(\C(u))
\end{align*}
\begin{theorem}
if $\C$ is uniquely decodable, then
\begin{align*}
E[l(\C(u))] \geq \sum_u p(u) \log \frac{1}{p(u)}
\end{align*}
\end{theorem}
\begin{proof}
let $\C(u) = l(\C(u))$, we know $\sum_u 2^{-\C(u)} \leq 1$ because $\C$ is uniquely decodable. We write $q(u)~=~2^{-\C(u)}$ and get
\begin{align*}
E[l(\C(u))] &= \sum_u p(u) \C(u) = \sum_u p(u) \log_2\frac{1}{q(u)} \\
&\equiv \sum_u p(u) \log\frac{q(u)}{p(u)} \leq 0 \\
&\equiv \sum_u p(u) \ln\frac{q(u)}{p(u)} \leq 0 \\
&\leq \sum_u p(u) \left[\frac{q(u)}{p(u)} - 1\right]
= \underbrace{\sum_u q(u)}_{\leq 1} - \underbrace{\sum_u p(u)}_{=1} \leq 0
\end{align*}
\end{proof}
\begin{theorem}
For any $\U$, there exists a prefix-free code $\C$ s.t.
\begin{align*}
E[l(\C(u))] < 1 + \sum_{u \in \U} p(u) \log\frac{1}{p(u)}
\end{align*}
\end{theorem}
\begin{proof}
Given $\U$, let
\begin{align*}
&\C(u) = \lceil \log\frac{1}{p(u)} \rceil < 1 + \log \frac{1}{p(u)} \\
&\Rightarrow \sum_u 2^{-\C(u)} \leq \sum_u p(u) = 1 \\
&\Rightarrow \sum_u p(u) \C(u) < \sum_u p(u) \log \frac{1}{p(u)} + \underbrace{1}_{\sum p(u)}
\end{align*}
\end{proof}
\begin{definition}[Entropy]
Entropy quantifies the amount of uncertainty involved in the value of a random variable or the outcome of a random process.
\end{definition}
\begin{theorem}
The entropy of a random variable $U \in \U$ is
\begin{align*}
H(U) = \sum_{u \in \U} p(u) \log \frac{1}{p(u)}
\end{align*}
with $p(u) = Pr(U = u)$
\end{theorem}
\begin{wikipedia}
The entropy is a lower bound on the optimal expected length
\begin{align*}
H(U) \leq E[l(\C(u))]
\end{align*}
In fact, one can show that there exists a uniquely decodable code such that
\begin{align*}
H(U) \leq E[l(\C(u))] < H(U) + 1
\end{align*}
\end{wikipedia}
Note that $H(U)$ is a fonction of the distribution $\C_u(.)$ of the random variable $U$, it isn't a function of $U$.
\begin{align*}
H(U) = E[f(U)] \quad \text{where} \quad f(U) = \log \frac{1}{p(u)}
\end{align*}
How to design optimal codes (in the sense of minimizing $E[l(\C(u))]$)? \\
Formally, given a random variable $U$, find $\C(u) \rightarrow \N$ s.t.
\begin{align*}
\sum_{u \in U} 2^{\C(u)} \leq 1
\quad \text{that minimizes} \quad
\sum_{u \in U} p(u)l(\C(u))
\end{align*}
Properties of optimal prefix-free codes
\begin{itemize}
\item if $p(u) < p(v)$ then $l(\C(u)) \geq l(\C(v))$
\item The two longest codewords have the same length
\item There is an optimal code such that the two least probable letters are assigned codewords that differ in the last bit.
\end{itemize}
Observe that if $\{\C(u_1), ... , \C(u_{k-1}), \C(u_k)\}$ is a prefix-free collection of the property that
\begin{align*}
\left.
\begin{array}{l l}
\C(u_{k-1}) &= \alpha 0 \\
\C(u_k) &= \alpha 1
\end{array}
\right.
\quad \text{with} \quad \alpha \in \{ 0, 1\}^*
\end{align*}
then $\{\C(u_1), ..., \C(u_{k-2}), \alpha\}$ is also a prefix-free collection.
Also
\begin{align*}
\sum_{u \in \U} p(u) l(\C(u)) &= p(u_1) l(\C(u_1)) + ... + p(u_{k-2}) l(\C(u_{k-2}))
+ [p(u_{k-1}) + p(u_k)](l(\alpha) + 1) \\
&= (p(u_{k-1}) + p(u_k)) + \sum_{v \in \V} p(v) l(\C'(v))
\end{align*}
So we have shown that with
\begin{align*}
E[l(\C(U)] = p(u_{k-1}) + p(u_k) + E[l(\C'(V))]
\end{align*}
if $\C$ is optimal for $U$, then $\C'$ is optimal for $V$
% -------------------------------------------------------------
\cleardoublepage
\section{Entropy and mutual information}
\label{sec:entropy}
\begin{definition}[Joint entropy]
Suppose $U, V$ are random variables with $p(u,v) = \Pr{U=u, V=v}$, the joint entropy is
\[
H(UV) = \sum_{u,v} p(u,v) \log \frac 1 {p(u,v)}
\]
\end{definition}
\begin{theorem}
\[
H(UV) \leq H(U) + H(V)
\]
with equality iff $U$ and $V$ are independants.
\end{theorem}
\begin{proof}
We want to show that
\begin{align*}
\sum_{u,v} p(u,v) \log \frac 1 {p(u,v)} \leq \sum_u p(u) \log \frac 1 {p(u)} + \sum_v p(v) \log \frac 1 {p(v)}
\iff \sum_{u,v} p(u,v) \log \frac {p(u)p(v)} {p(u,v)} \leq 0
\end{align*}
We use $\ln z \leq z - 1$ for all $z$ (with equality iff $z=1$):
\begin{align*}
\sum_{u,v} p(u,v) \log \frac {p(u)p(v)} {p(u,v)} \leq \sum_{u,v} p(u,v) \left[ \frac {p(u)p(v)} {p(u, v)} - 1 \right] = \sum_{u,v} p(u)p(v) - \sum_{u,v} p(u,v) = 1 - 1 = 0
\end{align*}
\end{proof}
Same definitions of entropy holds for $n$ symbols.
\begin{definition}[Joint Entropy]
Suppose $U_1, U_2, \dots, U_n$ are RVs and we are given $p(u_1 \dots u_n)$, the joint entropy is
\[
H(U_1, \dots, U_n) = \sum_{u_1 \dots u_n} p(u_1 \dots u_n) \log \frac 1 {p(u_1 \dots u_n)}
\]
\end{definition}
\begin{theorem}
\[
H(U_1 \dots U_n) \leq \sum_{i=1}^n H(U_i)
\]
with equality iff $U$s are independants
\end{theorem}
\begin{corollary}
if $U_1, \dots, U_n$ are i.i.d. then $H(U_1 \dots U_n) = nH(U_1)$
\end{corollary}
\begin{definition}[Conditional entropy]
\begin{align*}
H(U|V) &= \sum_{u,v} p(u,v) \log \frac 1 {p(u|v)}\\
&= \sum_v H(U | V = v) \Pr{V = v}
\end{align*}
\end{definition}
\begin{theorem}
\[
H(UV) = H(U) + H(V|U) = H(V) + H(U|V)
\]
\end{theorem}
\begin{theorem}
\[
H(U) + H(V) \geq H(UV) = H(V) + H(U|V)
\]
\end{theorem}
\begin{definition}[Mutual information]
Mutual information measures the amount of information that can be obtained about one random variable by observing another.
\begin{align*}
I(U;V) = I(V;U) &= H(U) - H(U|V)\\
&= H(V) - H(V|U)\\
&= H(U) + H(V) - H(UV)
\end{align*}
\end{definition}
We can apply the chain rule on the entropy as follow
\[
H(U_1 U_2 \dots U_n) = H(U_1) + H(U_2|U_1) + \dots + H(U_n|U_1 U_2 \dots U_{n-1})
= \sum_{i = 1}^n H(U_i | U^{i-1})
\]
\begin{definition}[Conditional mutual information]
\begin{align*}
I(U;V|W) &= H(U|W) - H(U|VW)\\
&= H(V|W) - H(V|UW)\\
&= \E_{u,v,w} \left[ \log \frac {p(uv|w)} {p(u|w)p(v|w)} \right]
\end{align*}
\end{definition}
\begin{theorem}
\[
I(V;U_1\dots U_n) = I(V;U_1) + I(V;U_2 | U_1) + \dots + I(V;U_n|U_1 \dots U_{n-1})
\]
\end{theorem}
We can apply the chain rule on the mutual information as follows
\[
I(U_1, U_2, ... ; V) = I(U_1; V) + I(U_2; V | U_1) + ...
\]
\begin{theorem}[Data processing inequality]
Let $X \rightarrow Y \rightarrow Z$ be a Markov chain, then
\begin{align*}
I(X ; Y) \geq I(X ; Z) \quad \text{ and } \quad I(Y ; Z) \geq I(X ; Z)
\end{align*}
We have equality iff $I(X ; Y | Z) = 0$ (i.e. $X \rightarrow Z \rightarrow Y$ form a Markov chain)
This important and useful theorem demonstrates that no processing of $Y$, deterministic or random, can increase the information that $Y$ contains about $X$.
\end{theorem}
\begin{notation}
\[
U^n \triangleq (U_1 U_2 \dots U_n)
\]
\end{notation}
\begin{theorem}
\[
I(U;V |W) \geq 0
\]
equality iff conditioned on $w$, $u$ and $v$ are independant, that is iff $U-W-V$ is a Markov chain.
\end{theorem}
\begin{proof}
\begin{align*}
I(U;V|W) &= \frac 1 {\ln 2} \sum_{u,v,w} p(uvw) \ln \frac {p(u|w)p(v|w)} {p(uv | w)}\\
&\geq \frac 1 {\ln 2} \sum_{u,v,w} p(uvw) \left[ \frac {p(u|w)p(v|w)} {p(uv | w)} - 1 \right]\\
&=\frac 1 {\ln 2} \sum_{u,v,w}(p(w)p(u|w)p(v|w) - p(uvw))\\
&= \frac 1 {\ln 2}(1 - 1) \\
&=0
\end{align*}
\end{proof}
% -----------------------------------------------------------------------
\cleardoublepage
\section{Data processing}
\begin{theorem}
$U-V-W$ is a MC $\iff I(U;W|V) = 0$
\end{theorem}
\begin{corollary}
$I(U;V) \geq I(U;W)$ and by symetry of MC $I(W;V) \geq I(U;W)$
\end{corollary}
\begin{proof}
\[
I(U;VW) = I(U;V) + I(U;W|V) = I(U;V)
\]
and
\[
I(U;VW) = I(U;W) + I(U;V|W) \geq I(U;W)
\]
\end{proof}
\begin{theorem}
Given $U$ a RV taking values in $\U$ then
\[
0 \leq H(U) \leq \log | \U |
\]
and $H(U)=0$ iff $U$ is constant, $H(U)=\log | \U |$ iff $U$ is $p(u) = 1 / |\U|$ for all $u$.
\end{theorem}
\begin{proof}
For the lower bound,
\[
H(U) = \sum_u \underbrace{p(u)}_{\geq 0} \underbrace{\log \frac 1 {p(u)}}_{\geq 0} \geq 0
\]
For the upper bound,
\begin{align*}
H(U) - \log | \U |
&= \sum_u p(u) \log \frac 1 {p(u)} - \sum_u p(u) \log |\U|\\
&= \frac 1 {\ln 2} \sum_u p(u) \ln \frac 1 {|\U | p(u)}\\
&\leq \frac 1 {\ln 2} \sum_u p(u) \left(\frac 1 {|\U | p(u)} - 1 \right)\\
&=\frac 1 {\ln 2} \left[ \sum_u \frac 1 {|\U |} - \sum_u p(u) \right]\\
&=0
\end{align*}
\end{proof}
\begin{theorem}
$I(U;V) = 0 \iff U \bot V$
\end{theorem}
\begin{definition}[Entropy rate of a stochastic process]
\[
r = \lim_{n\to \infty} \frac 1 n H(U^n) \quad \text{ if the limit exists}
\]
\end{definition}
\begin{theorem}
For stationary stochastic process $U^n$, the sequences
\[
a_n = \frac 1 n H(U^n) \text{ and } b_n = H(U_n|U^{n-1})
\]
are positive and non increasing. Then $a=\lim_{n\to \infty} a_n$ and $b=\lim_{n\to \infty} b_n$ exists and $a=b$.
\end{theorem}
\begin{proof}
\begin{align*}
b_{n+1}
&= H(U_{n+1}|U_1, U_2,\dots,U_n)\\
&\leq H(U_{n+1}|U_2,\dots,U_n)\\
&= H(U_n|U_1, U_2,\dots,U_{n-1})\\
&= b_n \text{ , because $U_1 \dots U_n \sim U_2 \dots U_{n+1}$ (Stationarity).}
\end{align*}
Hence, it is non-increasing.\\\\
For the \{$a_n$\}, observe that
\begin{align*}
a_n = \frac{1}{n} H(U^n)
&= \frac{1}{n} \bigg[ H(U_1)+H(U_2|U_1)+H(U_3|U^2) +\dots+H(U_n|U^{n-1}) \bigg]\\
&= \frac{1}{n} \bigg[ b_1+b_2+\dots+b_n\bigg]
\end{align*}
and by the "Lemma", whenever $b_n \rightarrow b$ , \space $a_n \rightarrow b$
\end{proof}
\begin{lemma}[Cesaro]
Suppose $b_n \rightarrow b$, \\\\
then,
\[
a_n = \frac{1}{n} \bigg[ b_1+b_2+\dots+b_n\bigg] \text{ also converges and to 1.}
\]
\end{lemma}
\begin{proof}
Since $b_n \rightarrow b$ , $\bigg( \equiv \forall \epsilon > 0$ , $\exists$ $n(\epsilon)$ s.t $ \forall n > n(\epsilon)$ $ |b_n-b| < \epsilon\bigg)$\\
$\exists B $ s.t. $ |b_n| < B$ for all n.\\\\
Take $n > n_1(\epsilon) \triangleq \dots $ then
\[
|a_n-b| \leq \frac{|b_1-b|+|b_2-b|+|b_3-b|+\dots+|b_n-b|}{n}
\]
\[
\text{so } |a_n-b| \leq \frac{1}{n}\bigg[ \sum_{i=1}^{n_0(\epsilon)} \underbrace{|b_i-b|}_{2B} + \sum_{i=n_0(\epsilon)+1}^{n} \underbrace{|b_i-b|}_{\leq \epsilon}\bigg] \leq \frac{n_0(\epsilon) 2B}{n} + \epsilon < 2\epsilon
\]
\[
\text{for } n>n_1(\epsilon) \triangleq \text{max, } \{ n_0(\epsilon) \frac{1}{\epsilon} n_0(\epsilon) 2B \}
\]
\end{proof}
% -------------------------------------------------------------------------
% class 9.10.2017
\begin{theorem}
Given a stationary process with entropy rate $r$:
\begin{align*}
r = \lim_{n \rightarrow \infty} \frac{1}{n} H(U^n)
\end{align*}
then
\begin{enumerate}
\item for every source coding scheme
\begin{align*}
\C_n: U^n \rightarrow \{0, 1\}^*
\end{align*}
the expected number of bits / letter is given by
\begin{align*}
\frac{1}{n} E[l(\C(U^n))] \geq r
\end{align*}
\item for any $\epsilon > 0$, there exists a source coding scheme $\C_n: U^n \rightarrow \{0, 1\}^*$ s.t.
\begin{align*}
\frac{1}{n} E[l(\C_n(U^n))] < r + \epsilon
\end{align*}
\end{enumerate}
\end{theorem}
\begin{proof}
\begin{enumerate}
\item we already know
\begin{align*}
\frac{1}{n} E[l(\C_n(U^n))] \geq \frac{1}{n} H(U^n)
\end{align*}
and the right term is decreasing
\item we also know that for each $n, \exists \C_n$ that is prefix-free s.t.
\begin{align*}
E[l(\C_n(U^n))] < \underbrace{\frac{1}{n} H(U^n)}_{r} + \underbrace{\frac{1}{n}}_{0}
\end{align*}
we can find $n$ large enough s.t. the right hand side $< r + \epsilon$
\end{enumerate}
\end{proof}
% -------------------------------------------------------------------------
% -------------------------------------------------------------------------
\cleardoublepage
\section{Typicality and typical set}
\begin{definition}[Typicality]
\label{def:typicality}
Suppose we have a sequence $U_1, U_2, ...$ of i.i.d. random variables taking values in an alphabet $\U$.
Suppose we observe $u_1,u_2..., u_n$. We will call it to be \textit{typical-$(\epsilon, p)$} if
\begin{align*}
p(u) (1 - \epsilon)
\leq \frac{\# \text{ of times $u$ appears in $u_1, ..., u_n$}}{n}
\leq p(u)(1+\epsilon)
\end{align*}
\end{definition}
\begin{theorem}
$u^n$ is $(\epsilon, p)$-typical then
\begin{align*}
2^{-n H(u)(1 + \epsilon)}
\leq Pr(U^n = u^n)
\leq 2^{-n H(u)(1 - \epsilon)}
\end{align*}
\end{theorem}
\begin{proof}
\begin{align*}
Pr(U^n = u^n) &= \prod_{i=1}^n Pr(U_i = u_i) = \prod_{i=1}^n p(u_i) = \prod_{u \in \U} p(u)^{\#_u}
\end{align*}
with $\#_u$ the number of times $u$ appears in $u_1, ..., u_n$ where
\begin{align*}
n (1-\epsilon) p(u) \leq \#_u \leq n(1+\epsilon)p(u)
\end{align*}
consequently
\begin{align*}
p(u)^{(n p(u)(1-\epsilon))} \geq p(u)^{\#_u} \geq p(u)^{n p(u)(1+\epsilon)}
\end{align*}
then
\begin{align*}
(\prod_{n} p(u)^{p(u)})^{(1-\epsilon)n}
\geq Pr(U^n = u^n)
\geq (\prod_{n} p(u)^{p(u)})^{(1+\epsilon)n}
\end{align*}
but
\begin{align*}
p(u)^{p(u)} = 2^{-p(u) \log \frac{1}{p(u)}} \Rightarrow \prod p(u)^{p(u)} = 2^{-H(u)}
\end{align*}
\end{proof}
\begin{definition}[Typical set]
\begin{align*}
T(n, \epsilon, p) = \{ u^n \in \U^n : u^n \text{ is } (\epsilon, p)\text{-typical}\}
\end{align*}
\end{definition}
\begin{wikipedia}
Typical sets provide a theoretical means for compressing data, allowing us to represent any sequence $X^n$ using $nH(X)$ bits on average, and, hence, justifying the use of entropy as a measure of information from a source.
\end{wikipedia}
\begin{theorem}
\begin{enumerate}
\item if $u^n \in T(n, \epsilon, p)$ then
\begin{align*}
p(u^n) = Pr(U^n = u^n) = 2^{-n H(u)(1 \pm \epsilon)}
\end{align*}
when $U_i$ i.i.d.
\item
\begin{align*}
\lim_{n \rightarrow \infty} Pr(U^n \in T(n, \epsilon, p)) = 1
\end{align*}
\item
\begin{align*}
|T(n, \epsilon, p)| \leq 2^{n (H(u)(1 + \epsilon))}
\end{align*}
\item
\begin{align*}
|T(n, \epsilon, p)| \geq (1-\epsilon) 2^{n H(u)(1-\epsilon)}
\end{align*}
\end{enumerate}
\end{theorem}
\begin{proof}
\begin{enumerate}
\item
Fix $u \in \U$ let $X_i = 1$ if $ U_i = u$ and $0$ otherwise
\begin{align*}
\frac{\text{\# of times } u \text{ appears in } U_1 ... U_n}{n} = \frac{1}{n} \sum_{i = 1}^n X_i
\end{align*}
observe that $\{ X_i \}$ are i.i.d.
\begin{align*}
&X_i =
\left\{
\begin{array}{l l}
1 & \text{ w.p. } p(u) \\
0 & \text{ w.p. } 1 - p(u)
\end{array}
\right. \\
&\Rightarrow \Ex{X_i} = p(u) \quad \text{ and } \quad Var[X_i] = p(u) - p(u)^2 \\
\end{align*}
\begin{align*}
\underbrace{
\Pr{|\frac{1}{n} \sum_{i=1}^n X_i - p(u)|\geq \epsilon p(u)}
}_{u^n \text{ fails the test for letter } u}
\leq
\frac{Var(\frac{1}{n} \sum X_i)}{(\epsilon p(u))^2}
= \frac{(1 - p(u))}{n\epsilon^2 p(u)}
\end{align*}
\item
\begin{align*}
\Pr{U^n \not \in T(n, \epsilon, p)} &= \Pr{\bigcup_{u \in U} \{u^n \text{ fails the test for u} \}} \\
&\leq \sum_{u \in U} \Pr{U^n \text{ fails the test for } u} \\
&\leq \frac{1}{n} \sum_{u \in U} \frac{(1 - p(u))}{p(u) \epsilon^2} \quad \text{ which goes to 0 as } n \text{ gets large}
\end{align*}
\item
\begin{align*}
1 \geq \Pr{U^n \in T(n, \epsilon, p)} &= \sum_{u^n \in T(n, \epsilon, p)} \Pr{U^n = u^n} \\
&\geq \sum_{u^n \in T(n, \epsilon, p)} 2^{-n(1 + \epsilon) H(u)} \\
&= 2^{-n (1 + \epsilon) H(u)} |T(n, \epsilon, p)|
\end{align*}
\item
\begin{align*}
1 - \epsilon \leq \Pr{U^n \in T(n, \epsilon, p)} &= \sum_{u^n \in T(n, \epsilon, p)} \Pr{U^n = u^n} \\
&\leq \sum_{u^n \in T(n, \epsilon, p)} 2^{n H(u)(1-\epsilon)} \\
&= 2^{-n H(u)(1 - \epsilon)} |T(n, \epsilon, p)|
\end{align*}
\end{enumerate}
\end{proof}
\begin{observation}
$\Pr{U^n \in T(n, \epsilon, p)} \to 1$ as $n\to \infty$
\end{observation}
\begin{definition}[Kullback Leibler divergence]
\[
D(p||q) = \sum_u p(u) \log \frac {p(u)} {q(u)} \geq 0 \text{ with equality iff } p = q
\]
\end{definition}
If we compress data in a manner that assumes $q(u)$ is the distribution underlying some data, when, in reality, $p(u)$ is the correct distribution, the Kullback-Leiber divergence is the average number of additional bits per datum necessary for compression. It is also called \textbf{relative entropy} and is a measure of how one probability distribution diverges from a second probability distribution.
% -----------------------------
% jb - lecture 2017-10-10
\begin{lemma}
if $U_1 \dots U_n$ are i.i.d. with distribution $q$ and $u_1 \dots u_n$ is $(\epsilon, p)$-tipycal, then
\[
2^{-n[H(p) + D(p||q)](1+\epsilon)}
\leq
\Pr{U^n = u^n}
\leq
2^{-n[H(p) + D(p||q)](1-\epsilon)}
\]
\end{lemma}
\begin{proof}
Follows from
\[
\left[ \prod_u q(u)^{p(u)} \right]^{n(1+\epsilon)} \leq \Pr{U^n = u^n} \leq \left[ \prod_u q(u)^{p(u)} \right]^{n(1-\epsilon)}
\]
\[
\prod_u q(u)^{p(u)} = 2^{-\sum p(u) \log \frac 1 {q(u)}}
\]
and
\[
\sum_u p(u) \log \frac 1 {q(u)} =
\underbrace{\sum_u p(u) \log \frac 1 {p(u)}}_{H(p)} +
\underbrace{\sum_u p(u) \log \frac {p(u)} {q(u)}}_{D(p||q)}
\]
\end{proof}
\begin{corollary}
if $U_1 \dots U_n$ are i.i.d. following distribution $q$, then
\[
2^{-n[(1+\epsilon)D(p||q)+2\epsilon H(p)]}
\leq
\Pr{U^n \in T(n,\epsilon,p)}
\leq
2^{-n[(1-\epsilon)D(p||q) - 2\epsilon H(p)]}
\]
\end{corollary}
\begin{proof}
\[
\Pr{U^n \in T(n,\epsilon,p)} = \sum_{u^n \in T(n, \epsilon, p)} \Pr{U^n = u^n}
\]
We have
\begin{align*}
2^{-n[H(p) + D(p||q)](1+\epsilon)}
\leq
&\Pr{U^n = u^n}
\leq
2^{-n[H(p) + D(p||q)](1-\epsilon)}\\
2^{nH(p)(1-\epsilon)}
\leq
&|T(n, \epsilon, p)|
\leq
2^{nH(p)(1+\epsilon)}
\end{align*}
\end{proof}
\begin{example}
$U \in \{0,1\}$, $p=\frac 1 2, \frac 1 2$, $q=\frac 1 2 - \delta, \frac 1 2 + \delta$
\[
D(p||q) = \frac 1 2 \log \frac 1 {1-2\delta} + \frac 1 2 \log \frac 1 {1+2\delta} = \frac 1 2 \log \frac 1 {1-4\delta^2} = - \frac 1 2 \log (1-4\delta^2) \approx \frac 1 2 4\delta^2 + o(\delta^4)
\]
So if we want $2^{-n D(p||q)}$ small, we must pick $n=\Omega(1/\delta^2)$
\end{example}
\begin{example}
Suppose we are told that $U$ is $p$ distributed and $p(u)$ are powers of 2. We design a prefix-free code $\C$ to minimize $\sum_u p(u) l(\C(u))$. We have been misinformed and $U\sim q$, then:
\begin{align*}
\Ex{l(\C(u))}
&= \sum_u q(u) \log \frac 1 {p(u)}\\
&= \underbrace{H(q)}_{\text{length for optimal code}} + \underbrace{D(q||p)}_{\text{penalty for misbelief}}
\end{align*}
\end{example}
% -------------------------------------------------------------------------
% -------------------------------------------------------------------------
\cleardoublepage
\section{Universal data compression}
Suppose we know that the distribution $p$ of $U$ is either $p_1$, $p_2$ ... $p_k$, can we design a code $\C: U \to \{0,1\}^*$
\[
\Ex{l(\C(U))} \leq H(U) + \text{small for every } p
\]
\[
\Ex{\frac 1 n l(\C(U))} \leq o(n) + \Ex{h_2 \pfrac K n}
\]
with $K = \sum_{i=1}^n u_i$
We have $\frac {\Ex{K}} n = \theta_1$ and $\Ex{h_2\pfrac K n} \leq h_2 \left(\Ex{\frac K n} \right) = h_2(\theta)$
\paragraph{Design $\C$}
Because the probability of a bit string is only dependant of the number of
1s (or 0s), it makes sense to encode two strings with the same numbers of 1
with code words of same lengths.
Given $u_1 \dots u_n \in \{0,1\}^n$, first count the number of 1, call it $k$.
\[
\C(u_1 \dots u_n) =
\underbrace{\text{describe } k}_{\lceil \log (n+1)\rceil}
\underbrace{\text{describe } u_1 \dots u_n}_{\lceil \log {n \choose k}\rceil}
\]
We now want to evaluate
\[
\frac 1 n \Ex{l(\C(U))}
\]
when $U_1 \dots U_n$ are i.i.d with $p_1 = \theta$ and $p_0 = 1 - p_1$
\begin{observation}
for any $0 \leq \alpha \leq 1$
\begin{align*}
1 = 1^n = (\alpha + (1-\alpha))^n &= \sum_{i=0}^n {n \choose i} \alpha^i (1-\alpha)^{n-i}\\
& \geq {n \choose k} \alpha^k (1-\alpha)^{n-k}
\end{align*}
Then for all $\alpha$
\[
{n \choose k} \leq \alpha^{-k}(1-\alpha)^{-(n-k)} = 2^{n(\frac k n \log \frac 1 \alpha + (1-\frac k n) \log \frac 1 {1-\alpha})}
\]
We pick $\alpha = \frac k n$, and we get
\[
{n \choose k} < 2^{n h_2 \pfrac k n}
\]
\end{observation}
Using this bound we have
\[
\frac 1 n l(\C(u_1 \dots u_n)) \leq \frac 2 n + \frac {\log (n+1)} n + h_2\pfrac k n
\]
\[
\Ex{\frac 1 n l(\C(U))} \leq o(n) + \Ex{h_2 \pfrac k n}
\]
\begin{claim}
Suppose $U_i$ are i.i.d. with $\Pr{U_1=1}=\theta$. We have $\Ex{ \frac k n} = \theta$ and $\Ex{h_2 \pfrac k n } \leq h_2(\Ex{\frac k n}) = h_2(\theta)$. So
\[
\lim_{n\to \infty} \frac 1 n \Ex{l(\C(u_1\dots u_n))} \leq h_2(\theta)
\]
consequently this scheme is asymptotically optimal.
\end{claim}
\begin{proof}
To prove the claim we need to show that if $\beta_1\dots \beta_k$ are in $[0,1]$ and $q_1 \dots q_k$ are non negative numbers that sum to 1 then
\[
\sum_{i=1}^k q_i h_2(\beta_i) \leq h_2 \left(\sum_{i=1}^k q_i \beta_i \right)
\]
Let $U$ and $V$ be random variables with $U \in \{0,1\}$ and $V \in \{1,\dots,k\}$ with
\begin{align*}
\Pr{V=i} &= q_i\\
\Pr{U=1|V=i} &= \beta_i\\
\Pr{U=0|V=i} &= 1- \beta_i\\
\end{align*}
Then,
\begin{align*}
\Pr{U=1} &= \sum_i q_i \beta_i\\
H(U) &= h_2\left(\sum_i q_i \beta_i \right)\\
H(U|V) &= \sum_i q_i h_2(\beta_i)
\end{align*}
And we already know that $H(U) \geq H(U|V)$
\end{proof}
% -------------------------------------------------------------------------
% lesson - 17.0.2017 - sebastien
Suppose we have an infinite string $u_1 u_2 ..., u_i \in \U$, and
$$u_1 u_2 ... = v_1 v_2 ... \text{ with } v_i \in \U^*, v_i \neq v_j \text{ when } i \neq j$$
for any $k$ we have
\begin{align*}
\lim_{m \to \infty} \frac{length(v_1...v_m)}{m} \geq k
\Rightarrow \lim_{m \to \infty} \frac{length(v_1 ... v_m)}{m} =
\infty
\end{align*}
\begin{definition}
Given an infinite string $u_1 u_2 ...$ and a machine $M$, let
\begin{align*}
\rho_{M}(u_1 u_2 ...) = \overline{\lim_{n \to \infty}} \frac{\text{length of the output } M \text{ after reading } u_1 u_2...}{n}
\end{align*}
also given $s > 0$, define
\begin{itemize}
\item The compressibility of $\U^*$ be s-state machines
\begin{align*}
\rho_s (u_1 u_2 ...) = \min_{M} \rho_{M}(u_1 u_2 ...)
\end{align*}
with $M$ an $s'$-state machine with $s' \leq s$
\item Compressibility of $\U^*$ by finite state machines
\begin{align*}
\rho_{FSM} (u_1 u_2 ...) = \lim_{s \to \infty} \rho_s (u_1 u_2 ...)
\end{align*}
\end{itemize}
\end{definition}