Unsupervised Learning: Information Theory Recap
Tags: machinelearning, unsupervisedlearning
Published: 2019-02-23 13:45:41

---
title: "Unsupervised Learning: Information Theory Recap"
published: true
description: A small detour to catch up on the basics of Information Theory we'll need
tags: Machine Learning, Unsupervised Learning
---

*This is the 13th in a series of class notes as I go through the [Georgia Tech/Udacity Machine Learning course](https://www.udacity.com/course/machine-learning--ud262). The class textbook is [Machine Learning by Tom Mitchell](https://www.cs.ubbcluj.ro/~gabis/ml/ml-books/McGrawHill%20-%20Machine%20Learning%20-Tom%20Mitchell.pdf).*

> ⚠️This is a more theoretical chapter, feel free to skip if not directly interested.

## The Central Question

In a machine learning problem, we want to be able to ask questions like "how is X1 or X2 related to Y", or "are X1 and X2 related" (mutual information). In general these machine learning problems can be modeled as a probability density function. So **information theory is a mathematical framework which allows us to compare these density functions.**

## Information Theory History

[Claude Shannon](https://en.wikipedia.org/wiki/Claude_Shannon). End of story 😅

## Entropy and the Measurement of information

We measure information in terms of the minimum number of bits we need to encode messages. 10 Coin Flips = 10 bits.

![http://lisathorne.files.wordpress.com/2009/10/tree-diagram.png?w=300&h=115](http://lisathorne.files.wordpress.com/2009/10/tree-diagram.png?w=300&h=115)

Another way of looking at amount of information is the number of granular questions you have to ask in order to determine what the message is. The number of bits per symbol is also know as "entropy".

## Variable Length Encoding

*[Wikipedia reading](https://en.wikipedia.org/wiki/Variable-length_code)*

However encoding doesnt have to be strictly based on uniform distribution and even trees - we can change our encoding around based on the probability of more frequent bits of information to save on the *average* bits per message (aka expected size).

![http://computationstructures.org/lectures/info/slides/Slide18.png](http://computationstructures.org/lectures/info/slides/Slide18.png)

## Joint and Conditional Entropy

Some variables have covariance with others. For example, the probability that it is raining (X) and the probability that there will be thunder (Y). This can also be expressed as Joint vs Conditional Entropy:

![https://slideplayer.com/slide/6013317/20/images/18/Joint+and+conditional+entropy.jpg](https://slideplayer.com/slide/6013317/20/images/18/Joint+and+conditional+entropy.jpg)

If X and Y are independent, then the conditional entropy is just the same as the individual entropies, and the joint entropy is the SUM of the individual entropies.

## Mutual Information

Although Joint and Conditional entropy give us some insight of independence, they aren't direct measures of *de*pendence. For example, if `H(Y|X)` is small, we don't know if that's because `X` gives a lot of information about `Y`, or if `H(Y)` is just small to begin with.

A better measure normalizes this: 

```
I(X,Y) = H(Y) - H(X|Y)
```

and we call it **Mutual information.**

See [further notes on derivation of the Mutual Information formula](http://www.robotvisions.org/4641/downloads/InfoTheory.fm.pdf).


## Example

Given this system of equations you can verify that, for 2 independent coins:

- Individual entropy is 1
- Conditional entropy is 1
- Joint entropy is 2 (additive)
- Mutual Information is 0 (no shared information)

{% youtube LQJ4PQBhDd4 %}

Which are intuitive. [Vice versa for the fully dependent case](https://www.youtube.com/watch?v=P5GpR-9XVWQ).

## Kullback-Leibler (KL) Divergence

Mutual Information is just a special case of KL Divergence - it is a measure of distance or divergence between any two distributions.

![https://wikimedia.org/api/rest_v1/media/math/render/svg/726edcd02293461b82768ea2fd299c3a3ef16112](https://wikimedia.org/api/rest_v1/media/math/render/svg/726edcd02293461b82768ea2fd299c3a3ef16112)

Note it is always non-negative and equals zero only when `p = q` for all x.

In Machine Learning we can use KL Divergence as an alternative to least-squares fitting of our dataset. (to be explained in later chaptesr)

## Next in our series

Further notes on this topic:

- [Maxwell's demon](https://en.wikipedia.org/wiki/Maxwell%27s_demon) - an early thought experiment that tried to contradict the second law of thermodynamics, and therefore reverse entropy.
- [Wikpedia on KL Divergence](https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence)
- [An Introduction to Information Theory and Entropy](https://github.com/pushkar/4641/raw/master/downloads/gentle_intro_to_information_theory.pdf) - [with a clearer 8-page summary here](https://github.com/pushkar/4641/raw/master/downloads/InfoTheory.fm.pdf)

Hopefully that was a good introduction to Information Theory. I am planning more primers and would love your feedback and questions on:

- [Overview](https://dev.to/swyx/machine-learning-an-overview-216n)
- Supervised Learning
    - [Decision Trees](https://dev.to/swyx/machine-learning-classification-learning--decision-trees-1mbh)
    - [Regression](https://dev.to/swyx/supervised-learning-regression-4d17)
    - [Neural Networks](https://dev.to/swyx/supervised-learning-neural-networks-mpo)
    - [Instance Based Learning (K Nearest Neighbors)](https://dev.to/swyx/supervised-learning-instance-based-learning-and-k-nearest-neighbors-kge)
    - [Ensemble Learning (AdaBoost)](https://dev.to/swyx/supervised-learning-ensemble-learning-lim)
    - [Kernel Methods & SVMs](https://dev.to/swyx/supervised-learning-support-vector-machines-3mgk)
    - [Computational Learning Theory](https://dev.to/swyx/supervised-learning-computational-learning-theory-160h)
    - [VC Dimensions](https://dev.to/swyx/supervised-learning-vc-dimensions-10b)
    - [Bayesian Learning](https://dev.to/swyx/supervised-learning-bayesian-learning-403l)
    - [Bayesian Inference](https://dev.to/swyx/supervised-learning-bayesian-inference-4l72)
- Unsupervised Learning
    - [Randomized Optimization](https://dev.to/swyx/unsupervised-learning-randomized-optimization-4c1i)
    - [Information Theory](https://dev.to/swyx/unsupervised-learning-information-theory-recap-4iem)
    - [Clustering](https://dev.to/swyx/unsupervised-learning-clustering-42mi)
    - Feature Selection - week of Mar 4
    - Feature Transformation - week of Mar 11
- Reinforcement Learning
    - Markov Decision Processes - week of Mar 25
    - "True" RL - week of Apr 1
    - Game Theory - week of Apr 15