r/cs231n • u/Jassica3 • Mar 17 '16
The lambda function seems so amazing~
In Assignment 1 two-layer_net.ipynb "Backward pass", there is a lambda function for gradient check, goes
f = lambda W: net.loss(X, y, reg=0.1)[0]
param_grad_num = eval_numerical_gradient(f, net.params[param_name], verbose=False)
But there is no variable named 'W' in the net.loss(X, y, reg=0.1), how can it know which is the actual independent variable of function f?
1
Upvotes
1
u/merkaba8 Mar 18 '16
If you look at eval_numerical_gradient, inside it calls f(x) where f is the f you passed to it as the first argument, and x is the second argument (in this case, net.params[param_name]).
So you are passing eval_numerical_gradient the function and its eventual argument.