Update.
[tex.git] / inftheory.tex
1 %% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: "pdflatex.sh" -*-
2
3 %% Any copyright is dedicated to the Public Domain.
4 %% https://creativecommons.org/publicdomain/zero/1.0/
5 %% Written by Francois Fleuret <francois@fleuret.org>
6
7 \documentclass[10pt,a4paper,twoside]{article}
8 \usepackage[paperheight=18cm,paperwidth=10cm,top=5mm,bottom=20mm,right=5mm,left=5mm]{geometry}
9 %\usepackage[a4paper,top=2.5cm,bottom=2cm,left=2.5cm,right=2.5cm]{geometry}
10 \usepackage[utf8]{inputenc}
11 \usepackage{amsmath,amssymb,dsfont}
12 \usepackage[pdftex]{graphicx}
13 \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue]{hyperref}
14 \usepackage{tikz}
15 \usetikzlibrary{arrows,arrows.meta,calc}
16 \usetikzlibrary{patterns,backgrounds}
17 \usetikzlibrary{positioning,fit}
18 \usetikzlibrary{shapes.geometric,shapes.multipart}
19 \usetikzlibrary{patterns.meta,decorations.pathreplacing,calligraphy}
20 \usetikzlibrary{tikzmark}
21 \usetikzlibrary{decorations.pathmorphing}
22 \usepackage[round]{natbib}
23
24 \usepackage{mleftright}
25
26 \newcommand{\setmuskip}[2]{#1=#2\relax}
27 \setmuskip{\thinmuskip}{1.5mu} % by default it is equal to 3 mu
28 \setmuskip{\medmuskip}{2mu} % by default it is equal to 4 mu
29 \setmuskip{\thickmuskip}{3.5mu} % by default it is equal to 5 mu
30
31 \setlength{\parindent}{0cm}
32 \setlength{\parskip}{12pt}
33 %\renewcommand{\baselinestretch}{1.3}
34 %\setlength{\tabcolsep}{0pt}
35 %\renewcommand{\arraystretch}{1.0}
36
37 \def\argmax{\operatornamewithlimits{argmax}}
38 \def\argmin{\operatornamewithlimits{argmin}}
39 \def\expect{\mathds{E}}
40
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43 \begin{document}
44
45 Information Theory is awesome so here is a TL;DR about Shannon's entropy.
46
47 The field is originally about quantifying the amount of
48 ``information'' contained in a signal and how much can be transmitted
49 under certain conditions.
50
51 What makes it awesome IMO is that it is very intuitive, and like
52 thermodynamics in Physics it give exact bounds about what is possible
53 or not.
54
55 \section{Shannon's Entropy}
56
57 Shannon's entropy is the key concept from which everything is defined.
58
59 Imagine that you have a distribution of probabilities $p$ on a finite
60 set of symbols, and that you generate a stream of symbols by sampling
61 them one after another independently with that distribution.
62
63 To transmit that stream, for instance with bits over a communication
64 line, you can design a coding that takes into account that the symbols
65 are not all as probable, and decode on the other side.
66
67 For instance if $P('\!\!A')=1/2$, $P('\!\!B')=1/4$, and
68 $P('\!\!C')=1/4$ you would transmit ``0'' for a ``A'' and ``10'' for a
69 ``B'' and ``11'' for a ``C'', 1.5 bits on average.
70
71 If the symbol is always the same, you transmit nothing, if they are
72 equiprobable you need $\log_2$(nb symbols) etc.
73
74 Shannon's Entropy (in base 2) is the minimum number of bits you have
75 to emit on average per symbol to transmit that stream.
76
77 It has a simple analytical form:
78 %
79 \[
80  H(p) = - \sum_k p(k) \log_2 p(k)
81 \]
82 %
83 where by convention $0 \log_2 0 = 0$.
84
85 It is often seen as a measure of randomness since the more
86 deterministic the distribution is, the less you have to emit.
87
88 The examples above correspond to "Huffman coding", which reaches the
89 Entropy bound only for some distributions. A more sophisticated scheme
90 called "Arithmetic coding" does it always.
91
92 From this perspective, many quantities have an intuitive
93 value. Consider for instance sending pairs of symbols (X, Y).
94
95 If these two symbols are independent, you cannot do better than
96 sending one and the other separately, hence
97 %
98 \[
99 H(X, H) = H(X) + H(Y).
100 \]
101
102 However, imagine that the second symbol is a function of the first
103 Y=f(X). You just have to send X since Y can be computed from it on the
104 other side.
105
106 Hence in that case
107 %
108 \[
109 H(X, Y) = H(X).
110 \]
111
112 An associated quantity is the mutual information between two random
113 variables, defined with
114 %
115 \[
116 I(X;Y) = H(X) + H(Y) - H(X,Y),
117 \]
118 %
119 that quantifies the amount of information shared by the two variables.
120
121 \section{Conditional Entropy}
122
123 Conditional entropy is the average of the entropy of the conditional distribution:
124 %
125 \begin{align*}
126 &H(X \mid Y)\\
127  &= \sum_y p(Y=y) H(X \mid Y=y)\\
128        &= \sum_y P(Y=y) \sum_x P(X=x \mid Y=y) \log P(X=x \mid Y=y)
129 \end{align*}
130
131 Intuitively it is the [minimum average] number of bits required to describe X given that Y is known.
132
133 So in particular, if X and Y are independent, getting the value of $Y$
134 does not help at all, so you still have to send all the bits for $X$,
135 hence
136 %
137 \[
138   H(X \mid Y)=H(X)
139 \]
140
141 if X is a deterministic function of Y then
142 %
143 \[
144   H(X \mid Y)=0.
145 \]
146
147 And if you send the bits for Y and then the bits to describe X given
148 that Y, you have sent (X, Y). Hence we have the chain rule:
149 %
150 \[
151 H(X, Y) = H(Y) + H(X \mid Y).
152 \]
153
154 And then we get
155 %
156 \begin{align*}
157 I(X;Y) &= H(X) + H(Y) - H(X,Y)\\
158        &= H(X) + H(Y) - (H(Y) + H(X \mid Y))\\
159        &= H(X) - H(X \mid Y).
160 \end{align*}
161
162 \section{Kullback-Leibler divergence}
163
164 Imagine that you encode your stream thinking it comes from
165 distribution $q$ while it comes from $p$. You would emit more bits than
166 the optimal $H(p)$, and that supplement is $D_{KL}(p||q)$ the
167 Kullback-Leibler divergence between $p$ and $q$.
168
169 In particular if $p=q$
170 %
171 \[
172  D_{KL}(p\|q)=0,
173 \]
174 %
175 and if there is a symbol $x$ with $q(x)=0$ and $p(x)>0$, you cannot encode it and
176 %
177 \[
178  D_{KL}(p\|q)=+\infty.
179 \]
180
181 Its formal expression is
182 %
183 \[
184 D_{KL}(p\|q) = \sum_x p(x) \log\left(\frac{p(x)}{q(x)}\right)
185 \]
186 %
187 that can be understood as a value called the cross-entropy between $p$ and $q$
188 %
189 \[
190 H(p,q) = -\sum_x p(x) \log q(x)
191 \]
192 %
193 minus the entropy of p
194 \[
195 H(p) = -\sum_x p(x) \log p(x).
196 \]
197
198 Notation horror: if $X$ and $Y$ are random variables $H(X, Y)$ is the
199 entropy of their joint law, and if $p$ and $q$ are distributions,
200 $H(p,q)$ is the cross-entropy between them.
201
202 \end{document}