| 116 | |
| 117 | |
| 118 | class RMSprop(Update): |
| 119 | |
| 120 | def __init__(self, lr=0.001, rho=0.9, epsilon=1e-6, *args, **kwargs): |
| 121 | Update.__init__(self, *args, **kwargs) |
| 122 | self.__dict__.update(locals()) |
| 123 | |
| 124 | def __call__(self, params, cost): |
| 125 | updates = [] |
| 126 | grads = T.grad(cost, params) |
| 127 | grads = clip_norms(grads, self.clipnorm) |
| 128 | for p,g in zip(params,grads): |
| 129 | g = self.regularizer.gradient_regularize(p, g) |
| 130 | acc = theano.shared(p.get_value() * 0.) |
| 131 | acc_new = self.rho * acc + (1 - self.rho) * g ** 2 |
| 132 | updates.append((acc, acc_new)) |
| 133 | |
| 134 | updated_p = p - self.lr * (g / T.sqrt(acc_new + self.epsilon)) |
| 135 | updated_p = self.regularizer.weight_regularize(updated_p) |
| 136 | updates.append((p, updated_p)) |
| 137 | return updates |
| 138 | |
| 139 | |
| 140 | class Adam(Update): |
nothing calls this directly
no outgoing calls
no test coverage detected