cs231n / cs231n.github.io

Public facing notes page
MIT License
10.12k stars 4.06k forks source link

what is meaning of f = lambda W: net.loss(X, y, reg=0.05)[0] #230

Closed luckydog1996 closed 4 years ago

luckydog1996 commented 4 years ago

This is from Assignment_1, two_layer_net jupyter notebook. And I not sure how function net.loss actually act on W? It seems there is no relationship?

brentyi commented 4 years ago

Ah, this is an understandable thing to be confused about --

Assuming you're referring to this bit:

    f = lambda W: net.loss(X, y, reg=0.05)[0]
    param_grad_num = eval_numerical_gradient(f, net.params[param_name], verbose=False)

The W passed into the lambda function is ignored, but eval_numerical_gradient directly mutates its second parameter (net.params[param_name]), which is then used when the loss is computed.

luckydog1996 commented 4 years ago

Thanks do much for your help!