All problems
Z-Channel Optimal Input
Problem
For a Z-channel where a transmitted 1 is flipped to 0 with probability q and a 0 is never flipped, the capacity-achieving output distribution satisfies py1 = 1 / (1 + 2^(H(q) / (1 - q))) with H the binary entropy in bits. Return the corresponding input P(X = 1) = py1 / (1 - q). Return 1.0 for q <= 0 and 0.0 for q >= 1.
Hint
Optimize I(X;Y) = H(py1) - px1 * H(q) over px1 and solve the derivative condition.
Test cases
case 1
in: [0.5]
expected: 0.4
case 2
in: [0.25]
expected: 0.42782559679176746
case 3
in: [0.1]
expected: 0.45629812363536315
case 4
in: [0.9]
expected: 0.3729708346843838
Starter codePython
import math
def z_channel_optimal_input(q):
# Your code here
pass4 test cases · run your code against them in the editor