All problems
Pathwise Derivative Estimate
Problem
The pathwise (reparameterization) estimator of the gradient of E[f(mu + sigma * eps)] with respect to mu is the sample average of f'(mu + sigma * eps_i).
For f(x) = sum(coeffs[i] * x^i) and a list of standard normal samples epsilons, return that average.
Hint
Unlike the score-function estimator, the pathwise estimator differentiates the sample directly.
Test cases
case 1
in: [[0,0,1],1,0.5,[-1,0,1]]
expected: 2
case 2
in: [[0,0,0,1],0,1,[0,0]]
expected: 0
case 3
in: [[0,0,1],2,0,[5]]
expected: 4
case 4
in: [[0,1],0,3,[1,-1,2]]
expected: 1
Starter codePython
def pathwise_derivative(coeffs, mu, sigma, epsilons):
# Your code here
pass4 test cases · run your code against them in the editor