# HTW Berlin - Angewandte Informatik - Advanced Topics - Exercise - Entropy

## Table of Contents

## Introduction

In this notebook you will calculate the entropy of a probability mass function (pmf).

In order to detect errors in your own code, execute the notebook cells containing `assert`

or `assert_almost_equal`

. These statements raise exceptions, as long as the calculated result is not yet correct.

## Requirements

### Knowledge

To complete this exercise notebook you should possess knowledge about the following topics.

- Proability mass function (pmf)
- Proability density function (pdf)
- Entropy
- Expected value

The following literature can help you to acquire this knowledge:

- Read Chapter 3 "Probability and Information Theory" of the Deep Learning Book
- Read Chapter 2.4 to 2.6 in David MacKays Book http://www.inference.org.uk/itprnn/book.html

### Python Modules

```
# External Modules
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as ss
from numpy.testing import assert_almost_equal
%matplotlib inline
```

## Exercise

At a party you are offered a free drink $x$ by playing a special roulette game. With probability 40% you receive 1 of 3 possible kinds of beer. 30% for 1 of 5 possible kinds of wine, 20% for 1 of 10 different kinds of schnapps and with a probability of 10% you receive vinegar. The different kinds in each of those categories (beer, wine, ...) are uniformly distributed.

**Task:**

Estimate the entropy $X$ of your drink in bits.

**Reminder**:

or

```
# Complete this cell
# (...)
hX =
```

```
# Executing this cell must not throw an Exception
# The solution is obfuscated so you can solve the exercise without unintendedly spoiling yourself
obfuscated_solution = 126361276584.6638/32894689023
assert_almost_equal(hX, obfuscated_solution)
```

## Literature

## Licenses

### Notebook License (CC-BY-SA 4.0)

*The following license applies to the complete notebook, including code cells. It does however not apply to any referenced external media (e.g., images).*

HTW Berlin - Angewandte Informatik - Advanced Topics - Exercise - Entropy

by Christian Herta, Klaus Strohmenger

is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Based on a work at https://gitlab.com/deep.TEACHING.

### Code License (MIT)

*The following license only applies to code cells of the notebook.*

Copyright 2018 Christian Herta, Klaus Strohmenger

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.