1 %% -*- mode: latex; mode: reftex; mode: flyspell; coding: utf-8; tex-command: "pdflatex.sh" -*-
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>
7 \documentclass[11pt,a4paper,oneside]{article}
8 \usepackage[paperheight=15cm,paperwidth=8cm,top=2mm,bottom=15mm,right=2mm,left=2mm]{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}
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 \usepackage[osf]{libertine}
24 \usepackage{microtype}
26 \usepackage{mleftright}
28 \newcommand{\setmuskip}[2]{#1=#2\relax}
29 \setmuskip{\thinmuskip}{1.5mu} % by default it is equal to 3 mu
30 \setmuskip{\medmuskip}{2mu} % by default it is equal to 4 mu
31 \setmuskip{\thickmuskip}{3.5mu} % by default it is equal to 5 mu
33 \setlength{\parindent}{0cm}
34 \setlength{\parskip}{1ex}
35 %\renewcommand{\baselinestretch}{1.3}
36 %\setlength{\tabcolsep}{0pt}
37 %\renewcommand{\arraystretch}{1.0}
39 \def\argmax{\operatornamewithlimits{argmax}}
40 \def\argmin{\operatornamewithlimits{argmin}}
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 \def\given{\,\middle\vert\,}
45 \def\proba{\operatorname{P}}
46 \newcommand{\seq}{{S}}
47 \newcommand{\expect}{\mathds{E}}
48 \newcommand{\variance}{\mathds{V}}
49 \newcommand{\empexpect}{\hat{\mathds{E}}}
50 \newcommand{\mutinf}{\mathds{I}}
51 \newcommand{\empmutinf}{\hat{\mathds{I}}}
52 \newcommand{\entropy}{\mathds{H}}
53 \newcommand{\empentropy}{\hat{\mathds{H}}}
54 \newcommand{\ganG}{\mathbf{G}}
55 \newcommand{\ganD}{\mathbf{D}}
56 \newcommand{\ganF}{\mathbf{F}}
58 \newcommand{\dkl}{\mathds{D}_{\mathsf{KL}}}
59 \newcommand{\djs}{\mathds{D}_{\mathsf{JS}}}
61 \newcommand*{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
62 \newcommand*{\horzbar}{\rule[.5ex]{2.5ex}{0.5pt}}
64 \def\positionalencoding{\operatorname{pos-enc}}
65 \def\concat{\operatorname{concat}}
66 \def\crossentropy{\LL_{\operatorname{ce}}}
73 {\Large Some bits of Information Theory}
83 Information Theory is awesome so here is a TL;DR about Shannon's entropy.
85 The field is originally about quantifying the amount of
86 ``information'' contained in a signal and how much can be transmitted
87 under certain conditions.
89 What makes it awesome is that it is very intuitive, and like
90 thermodynamics in Physics, it gives exact bounds about what is
93 \section{Shannon's Entropy}
95 Shannon's entropy is the key concept from which everything is defined.
97 Imagine that you have a distribution of probabilities $p$ on a finite
98 set of symbols, and that you generate a stream of symbols by sampling
99 them one after another independently with that distribution.
101 To transmit that stream, for instance with bits over a communication
102 line, you can design a coding that takes into account that the symbols
103 are not all as probable, and decode on the other side.
105 For instance if $\proba('\!\!A')=1/2$, $\proba('\!\!B')=1/4$, and
106 $\proba('\!\!C')=1/4$ you would transmit ``$0$'' for a ``A'' and ``$10$'' for a
107 ``B'' and ``$11$'' for a ``C'', 1.5 bits on average.
109 If the symbol is always the same, you transmit nothing, if they are
110 equiprobable you need $\log_2$(nb symbols) etc.
112 Shannon's Entropy (in base 2) is the minimum number of bits you have
113 to emit on average per symbol to transmit that stream.
115 It has a simple analytical form:
118 \entropy(p) = - \sum_k p(k) \log_2 p(k)
121 where by convention $0 \log_2 0 = 0$.
123 It is often seen as a measure of randomness since the more
124 deterministic the distribution is, the less you have to emit.
126 The examples above correspond to "Huffman coding", which reaches the
127 Entropy bound only for some distributions. A more sophisticated scheme
128 called "Arithmetic coding" does it always.
130 From this perspective, many quantities have an intuitive
131 value. Consider for instance sending pairs of symbols $(X, Y)$.
133 If these two symbols are independent, you cannot do better than
134 sending one and the other separately, hence
137 \entropy(X, Y) = \entropy(X) + \entropy(Y).
140 However, imagine that the second symbol is a function of the first
141 Y=f(X). You just have to send $X$ since $Y$ can be computed from it on the
147 \entropy(X, Y) = \entropy(X).
150 An associated quantity is the mutual information between two random
151 variables, defined with
154 \mutinf(X;Y) = \entropy(X) + \entropy(Y) - \entropy(X,Y),
157 that quantifies the amount of information shared by the two variables.
159 \section{Conditional Entropy}
161 Conditional entropy is the average of the entropy of the conditional distribution:
164 \entropy(X \mid Y) = \sum_y \proba(Y=y) \entropy(X \mid Y=y)
170 \entropy(X \mid Y=y) \hspace*{13.5em} \\
171 = \sum_x \proba(X=x \mid Y=y) \log \proba(X=x \mid Y=y)
174 Intuitively it is the [minimum average] number of bits required to describe $X$ given that $Y$ is known.
176 So in particular, if $X$ and $Y$ are independent, getting the value of $Y$
177 does not help at all, so you still have to send all the bits for $X$,
181 \entropy(X \mid Y)=\entropy(X),
184 and if $X$ is a deterministic function of $Y$ then
187 \entropy(X \mid Y)=0.
190 And if you send the bits for $Y$ and then the bits to describe $X$
191 given that $Y$, you have sent $(X, Y)$, hence the chain rule:
194 \entropy(X, Y) = \entropy(Y) + \entropy(X \mid Y).
200 I(X;Y) &= \entropy(X) + \entropy(Y) - \entropy(X,Y)\\
201 &= \entropy(X) + \entropy(Y) - (\entropy(Y) + \entropy(X \mid Y))\\
202 &= \entropy(X) - \entropy(X \mid Y).
205 \section{Kullback-Leibler divergence}
207 Imagine that you encode your stream thinking it comes from
208 distribution $q$ while it comes from $p$. You would emit more bits
209 than the optimal $\entropy(p)$, and that excess of bits is
210 $\dkl(p||q)$ the Kullback-Leibler divergence between $p$ and $q$.
212 In particular if $p=q$
218 and if there is a symbol $x$ with $q(x)=0$ and $p(x)>0$, you cannot encode it and
224 Its formal expression is
227 \dkl(p\|q) = \sum_x p(x) \log\left(\frac{p(x)}{q(x)}\right)
230 that can be understood as a value called the cross-entropy between $p$ and $q$
233 \entropy(p,q) = -\sum_x p(x) \log q(x)
236 minus the entropy of p
238 \entropy(p) = -\sum_x p(x) \log p(x).
241 Notation horror: if $X$ and $Y$ are random variables $\entropy(X, Y)$ is the
242 entropy of their joint law, and if $p$ and $q$ are distributions,
243 $\entropy(p,q)$ is the cross-entropy between them.