Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-276

Adaptive Arithmetic Update

Problem

An adaptive arithmetic coder keeps running symbol counts and updates them after every symbol. Given the current count list and the index of the observed symbol, increment that count and return the new normalized probability list. Assume the symbol index is valid and the counts are non-negative.

Hint

The increment happens before the probabilities are normalized.

Test cases

case 1
in: [[1,1],0]
expected: [0.6666666666666666,0.3333333333333333]
case 2
in: [[0,3,1],1]
expected: [0,0.8,0.2]
case 3
in: [[0,0],1]
expected: [0,1]
case 4
in: [[2,0,0,0],3]
expected: [0.6666666666666666,0,0,0.3333333333333333]
Starter codePython
def adaptive_arithmetic_update(counts, symbol):
    # Your code here
    pass

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