All problems
Z-Channel Capacity
Problem
Return the capacity in bits of a Z-channel with crossover q, where a transmitted 1 is flipped to 0 with probability q and a 0 is never flipped:
C = log2(1 + (1 - q) * q^(q / (1 - q)))
Return 1.0 for q <= 0 and 0.0 for q >= 1.
Hint
The optimal input distribution for a Z-channel is not uniform.
Test cases
case 1
in: [0]
expected: 1
case 2
in: [0.5]
expected: 0.32192809488736235
case 3
in: [0.1]
expected: 0.7628482520105094
case 4
in: [0.25]
expected: 0.5582386267373455
case 5
in: [0.9]
expected: 0.05483743386065755
Starter codePython
import math
def z_channel_capacity(q):
# Your code here
pass5 test cases · run your code against them in the editor