Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-001

Self-Information

Problem

Compute the self-information (surprisal) of an event with probability p:

I(p) = -ln(p)

Use the natural logarithm. Assume 0 < p <= 1.

Hint

Rare events carry more information; a certain event carries none.

Test cases

case 1
in: [1]
expected: 0
case 2
in: [0.5]
expected: 0.6931471805599453
case 3
in: [0.25]
expected: 1.3862943611198906
case 4
in: [0.1]
expected: 2.3025850929940455
Starter codePython
import math
def self_information(p):
    # Your code here
    pass

4 test cases · run your code against them in the editor