Entropy is not the easiest thing to understand.
It is rumored to describe something about information and disorder, but it is not clear why. What do logarithms and sums have to do with the notion of information?
š” Let me explain! š”
I have randomly selected an integer between 0 and 31. Can you guess which one? You can ask as many questions as you want. What is the minimum number of questions you have to ask to be 100% sure?
You can start guessing the numbers one by one, sure. But there is a better way!
If you ask "is the number larger or equal than 16?", you immediately eliminate half the search space! Continuing with this tactic, you can find the number for sure in 5 questions. In other words, we need to take the base two logarithm of 32 to get the number of questions required.
This logic applies to all numbers! If I pick a number between 0 and , you need questions to find it for sure, by cutting the possibilities in half with each.
Because the questions are yes-or-no questions, we can encode each answer with a or .
If we write down the answers in a row, we effectively encode the numbers in n bits!
š: 00000
š: 00001
š: 00010
...
šš: 11111
This is simply the number in base 2!
No matter which number I pick, five questions are needed to find it. So, the average number of bits required is also five. However, we are using a critical assumption here: I pick each number with an equal probability. What if that is not the case? š¤
Suppose that I am picking between 0, 1, and 2, but I am picking 0 at 50% of the time, while 1 and 2 only 25% of the time. We should put this into mathematical form now! Let's denote the number I pick with . This is what is called a random variable. The probability distribution is given by
How many bits do we need now? We can be more bit-efficient than before! Consider this.
1st question: did you pick 0? If the answer is yes, the 2nd question is not needed. If no, we proceed!
2nd question: did you pick 1? No matter what the answer is, we know the solution! Yes implies 1, no implies 2.
Thus, the average number of bits are
(This is just the expected value of the number of bits. If you didn't understand this step, check out my explanation about the expected value!)
Now we are almost there! Let's see the general case. Suppose that I pick between and I pick with probability . Similarly, as before, the number of questions needed to find is !
The entropy of a probability distribution is simply the average bits of information needed to guess its elements successfully. You should feel proud now! We have tamed entropy.
A few additional comments!
You might wonder what happens when the logarithm of the probability is not an integer. Not all questions provide 100% new information. In some cases, the answer gives you information that is partially contained in other bits. Hence, the "amount of new information" is not always an integer.
Does the base of the logarithm matter? In general, we can easily swap the base of the logarithms:
Thus, swapping bases in the entropy formula is just multiplication with a constant.
So, entropy is simpler than you thought! (And probably also simpler than what you were taught.)