| 94 | |
| 95 | |
| 96 | class NAG(Update): |
| 97 | |
| 98 | def __init__(self, lr=0.01, momentum=0.9, *args, **kwargs): |
| 99 | Update.__init__(self, *args, **kwargs) |
| 100 | self.__dict__.update(locals()) |
| 101 | |
| 102 | def __call__(self, params, cost): |
| 103 | updates = [] |
| 104 | grads = T.grad(cost, params) |
| 105 | grads = clip_norms(grads, self.clipnorm) |
| 106 | for p, g in zip(params, grads): |
| 107 | g = self.regularizer.gradient_regularize(p, g) |
| 108 | m = theano.shared(p.get_value() * 0.) |
| 109 | v = (self.momentum * m) - (self.lr * g) |
| 110 | |
| 111 | updated_p = p + self.momentum * v - self.lr * g |
| 112 | updated_p = self.regularizer.weight_regularize(updated_p) |
| 113 | updates.append((m,v)) |
| 114 | updates.append((p, updated_p)) |
| 115 | return updates |
| 116 | |
| 117 | |
| 118 | class RMSprop(Update): |
nothing calls this directly
no outgoing calls
no test coverage detected