Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-262

Prequential Code Length

Problem

Return the prequential (sequential) code length in bits for a sequence of conditional probabilities:

L = sum_i -log2(p_i)

Each p_i is the probability the model assigned to the i-th outcome given the past.

Hint

Summing predictive log losses yields a valid code length for the whole sequence.

Test cases

case 1
in: [[0.5,0.5]]
expected: 2
case 2
in: [[1,1]]
expected: 0
case 3
in: [[0.5,0.25]]
expected: 3
case 4
in: [[0.1]]
expected: 3.321928094887362
Starter codePython
import math
def prequential_code_length(conditional_probs):
    # Your code here
    pass

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