Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-073

Binary Source RD Point

Problem

Return the rate-distortion function in bits for a Bernoulli(p) source at distortion d:

R(d) = H(p) - H(d)

where H is the binary entropy function in bits with H(0) = 0. Assume 0 <= d <= min(p, 1 - p).

Hint

At zero distortion the rate equals the source entropy.

Test cases

case 1
in: [0.5,0.25]
expected: 0.18872187554086717
case 2
in: [0.5,0]
expected: 1
case 3
in: [0.25,0.1]
expected: 0.3422825308698516
case 4
in: [0.5,0.1]
expected: 0.5310044064107188
Starter codePython
import math
def binary_rd(p, d):
    # Your code here
    pass

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