A one-bit code is z∼Bernoulli(π), and
f(z)=(z−0.3)2. Find the true derivative of E[f(z)] with respect to
π. Write the draw as z=1[u<π] with u uniform on
(0,1), and find what differentiating through it returns. Then find the
score-function estimate at π=0.5, its mean and its variance.
Hint
E[f(z)]=πf(1)+(1−π)f(0). The function 1[u<π] is a step
in π.
Solution
The truth.f(1)=0.49 and f(0)=0.09, so the derivative is
f(1)−f(0)=0.4.
Through the draw. For fixed u, 1[u<π] is constant in
π except at π=u, where it jumps. Its derivative is zero with
probability one, so backpropagating through the draw returns 0. The
claim broken is that writing a draw as a function of noise always gives a
usable pathwise gradient: the function must be differentiable, and a step
is not.
Score function.logq(z)=zlogπ+(1−z)log(1−π), so its
derivative is z/π−(1−z)/(1−π). At π=0.5 the estimate is
f(1)/0.5=0.98 when z=1 and −f(0)/0.5=−0.18 when z=0. Its mean is
21(0.98−0.18)=0.4, correct, and its variance is
21(0.98−0.4)2+21(−0.18−0.4)2=0.3364.
The standard deviation 0.58 exceeds the gradient itself, which is
typical of the score function. Relaxations such as the Gumbel-softmax
replace the step by a smooth function of the noise, accepting bias for a
pathwise gradient.