Lesson 1 of 15
Self-Information
Self-Information
Self-information (also called surprisal) quantifies how much information is gained when you learn that an event with probability has occurred.
Intuition
- A certain event () carries 0 bits of information — you already knew it would happen.
- A coin flip () carries 1 bit — you need one yes/no question to resolve it.
- A rare event () carries 3 bits — it takes three yes/no questions to pin down.
Log Base Choice
Using gives information in bits. Using gives nats. This course uses bits throughout.
Example
import math
def self_information(p):
return -math.log2(p)
print(self_information(0.5)) # 1.0 bit
print(self_information(0.25)) # 2.0 bits
Your Task
Implement three equivalent functions:
self_information(p)— returnsinformation_content(p)— same formulasurprise(p)— same formula (different name used in some literature)
All three should return results in bits.
Python runtime loading...
Loading...
Click "Run" to execute your code.