All problems
Clipping Bias Estimate
Problem
Compute the expected value of a Gaussian gradient after clipping to [-clip, clip].
For g ~ N(mu, sigma ** 2), return mu * (Phi(z1) - Phi(z2)) + sigma * (phi(z2) - phi(z1)) + clip * (1 - Phi(z1) - Phi(z2)) with z1 = (clip - mu) / sigma, z2 = (-clip - mu) / sigma, and Phi, phi the standard normal CDF and PDF. For sigma <= 0, clip mu directly.
Hint
Split the expectation into the truncated body and the two clipped tails.
Test cases
case 1
in: [0,1,2]
expected: 0
case 2
in: [1,1,2]
expected: 0.9170666837293614
case 3
in: [3,1,2]
expected: 1.916684582873969
case 4
in: [0.5,2,1]
expected: 0.1896444392971461
Starter codePython
def clipping_bias_estimate(mu, sigma, clip):
# Your code here
pass4 test cases · run your code against them in the editor