skidjoe
skidjoe

Reputation: 649

Accumulating a variable while updating dict values? (Trying to implement SGD + momentum)

So I have the following dictionary implemented for vanilla SGD:

        update_weights = dict(zip(weight_keys,
                                [grad_weight[key] -
                                 lr * convert_to_tensor(dx[key])]) for key in weight_keys)

I am trying to implement something similar with momentum, however, I am not sure how I would be able to accumulate the velocity term so that I can update it all at once in list comprehension terms:

v_(i) = mu * v_(i-1) - lr * convert_to_tensor(dx[key])
grad_weight[key] += v_i

does anyone have any idea how I might do this using list comprehension (using Tensorflow preferably)?

for key in weight_keys:
     v = mu * v - lr * convert_to_tensor(dx[key])
     update_weights[key] = grad_weight[key] + v

Upvotes: 0

Views: 57

Answers (0)

Related Questions