Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-314

MDL Penalty in Nats

Problem

Return the MDL / BIC-style complexity penalty in nats for a model with k parameters fitted to n samples, which is 0.5 * k * ln(n). Natural logarithms make the penalty add directly to a negative log-likelihood measured in nats. Assume n >= 1 and k >= 0.

Hint

Each parameter is charged half a natural log of the sample count.

Test cases

case 1
in: [2,100]
expected: 4.605170185988092
case 2
in: [0,100]
expected: 0
case 3
in: [5,10]
expected: 5.756462732485115
case 4
in: [3,1]
expected: 0
Starter codePython
import math
def mdl_penalty_nats(k, n):
    # Your code here
    pass

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