Md. Asif Uddin
    I.13.X08

    A discrete code has no pathwise derivative

    counterexample▲▲△

    A one-bit code is z∼Bernoulli⁡(π)z\sim\operatorname{Bernoulli}(\pi), and f(z)=(z−0.3)2f(z)=(z-0.3)^2. Find the true derivative of E[f(z)]\E[f(z)] with respect to π\pi. Write the draw as z=1[u<π]z=\mathbf 1[u<\pi] with uu uniform on (0,1)(0,1), and find what differentiating through it returns. Then find the score-function estimate at π=0.5\pi=0.5, its mean and its variance.

    Hint

    E[f(z)]=πf(1)+(1−π)f(0)\E[f(z)]=\pi f(1)+(1-\pi)f(0). The function 1[u<π]\mathbf 1[u<\pi] is a step in π\pi.

    Solution

    The truth. f(1)=0.49f(1)=0.49 and f(0)=0.09f(0)=0.09, so the derivative is f(1)−f(0)=0.4f(1)-f(0)=0.4.

    Through the draw. For fixed uu, 1[u<π]\mathbf 1[u<\pi] is constant in π\pi except at π=u\pi=u, where it jumps. Its derivative is zero with probability one, so backpropagating through the draw returns 00. 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. log⁡q(z)=zlog⁡π+(1−z)log⁡(1−π)\log q(z)=z\log\pi+(1-z)\log(1-\pi), so its derivative is z/π−(1−z)/(1−π)z/\pi-(1-z)/(1-\pi). At π=0.5\pi=0.5 the estimate is f(1)/0.5=0.98f(1)/0.5=0.98 when z=1z=1 and −f(0)/0.5=−0.18-f(0)/0.5=-0.18 when z=0z=0. Its mean is 12(0.98−0.18)=0.4\tfrac12(0.98-0.18)=0.4, correct, and its variance is

    12(0.98−0.4)2    +12(−0.18−0.4)2=0.3364.\begin{aligned} &\tfrac12(0.98-0.4)^2\\ &\;\;+\tfrac12(-0.18-0.4)^2=0.3364. \end{aligned}

    The standard deviation 0.580.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.

    Draws on