We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
'float' object has no attribute 'get_value' problem.
When I was trying to print the configuration of a model by "model.get_config()" or trying to save my model as a 'json' file:

json_str = autoEncoder.to_json()
open('temp_model.json','w').write(json_str)
autoEncoder.save_weights('temp_model_weights.h5')

It raise the exception "float object has no attribute 'get_value' " in file 'optimizer.py', in class SGD(because I was using SGD as the optimizer), the definition of get_config() is:

 def get_config(self):
        return {"name": self.**class**.**name**,
                "lr": float(self.lr.get_value()),
                "momentum": float(self.momentum.get_value()),
                "decay": float(self.decay.get_value()),
                "nesterov": self.nesterov}

while the **init** of class SGD does not contain decay and nesterov

```
def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, *args, **kwargs):
    super(SGD, self).__init__(**kwargs)
    self.__dict__.update(locals())
    self.iterations = shared_scalar(0)
    self.lr = shared_scalar(lr)
    self.momentum = shared_scalar(momentum)
```

Is it a bug? Can I fix the problem by adding 'self.decay = shared_scalar(decay)' or something like this?

Thank you very much!


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `keras/optimizers.py`
Content:
```
1 from __future__ import absolute_import
2 import theano
3 import theano.tensor as T
4 
5 from .utils.theano_utils import shared_zeros, shared_scalar, floatX
6 from .utils.generic_utils import get_from_module
7 from six.moves import zip
8 
9 
10 def clip_norm(g, c, n):
11     if c > 0:
12         g = T.switch(T.ge(n, c), g * c / n, g)
13     return g
14 
15 
16 def kl_divergence(p, p_hat):
17     return p_hat - p + p * T.log(p / p_hat)
18 
19 
20 class Optimizer(object):
21     def __init__(self, **kwargs):
22         self.__dict__.update(kwargs)
23         self.updates = []
24 
25     def get_state(self):
26         return [u[0].get_value() for u in self.updates]
27 
28     def set_state(self, value_list):
29         assert len(self.updates) == len(value_list)
30         for u, v in zip(self.updates, value_list):
31             u[0].set_value(floatX(v))
32 
33     def get_updates(self, params, constraints, loss):
34         raise NotImplementedError
35 
36     def get_gradients(self, loss, params):
37 
38         grads = T.grad(loss, params)
39 
40         if hasattr(self, 'clipnorm') and self.clipnorm > 0:
41             norm = T.sqrt(sum([T.sum(g ** 2) for g in grads]))
42             grads = [clip_norm(g, self.clipnorm, norm) for g in grads]
43 
44         if hasattr(self, 'clipvalue') and self.clipvalue > 0:
45             grads = [T.clip(g, -self.clipvalue, self.clipvalue) for g in grads]
46 
47         return grads
48 
49     def get_config(self):
50         return {"name": self.__class__.__name__}
51 
52 
53 class SGD(Optimizer):
54 
55     def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, *args, **kwargs):
56         super(SGD, self).__init__(**kwargs)
57         self.__dict__.update(locals())
58         self.iterations = shared_scalar(0)
59         self.lr = shared_scalar(lr)
60         self.momentum = shared_scalar(momentum)
61         self.decay = shared_scalar(decay)
62 
63     def get_updates(self, params, constraints, loss):
64         grads = self.get_gradients(loss, params)
65         lr = self.lr * (1.0 / (1.0 + self.decay * self.iterations))
66         self.updates = [(self.iterations, self.iterations + 1.)]
67 
68         for p, g, c in zip(params, grads, constraints):
69             m = shared_zeros(p.get_value().shape)  # momentum
70             v = self.momentum * m - lr * g  # velocity
71             self.updates.append((m, v))
72 
73             if self.nesterov:
74                 new_p = p + self.momentum * v - lr * g
75             else:
76                 new_p = p + v
77 
78             self.updates.append((p, c(new_p)))  # apply constraints
79         return self.updates
80 
81     def get_config(self):
82         return {"name": self.__class__.__name__,
83                 "lr": float(self.lr.get_value()),
84                 "momentum": float(self.momentum.get_value()),
85                 "decay": float(self.decay.get_value()),
86                 "nesterov": self.nesterov}
87 
88 
89 class RMSprop(Optimizer):
90     def __init__(self, lr=0.001, rho=0.9, epsilon=1e-6, *args, **kwargs):
91         super(RMSprop, self).__init__(**kwargs)
92         self.__dict__.update(locals())
93         self.lr = shared_scalar(lr)
94         self.rho = shared_scalar(rho)
95 
96     def get_updates(self, params, constraints, loss):
97         grads = self.get_gradients(loss, params)
98         accumulators = [shared_zeros(p.get_value().shape) for p in params]
99         self.updates = []
100 
101         for p, g, a, c in zip(params, grads, accumulators, constraints):
102             new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator
103             self.updates.append((a, new_a))
104 
105             new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)
106             self.updates.append((p, c(new_p)))  # apply constraints
107         return self.updates
108 
109     def get_config(self):
110         return {"name": self.__class__.__name__,
111                 "lr": float(self.lr.get_value()),
112                 "rho": float(self.rho.get_value()),
113                 "epsilon": self.epsilon}
114 
115 
116 class Adagrad(Optimizer):
117     def __init__(self, lr=0.01, epsilon=1e-6, *args, **kwargs):
118         super(Adagrad, self).__init__(**kwargs)
119         self.__dict__.update(locals())
120         self.lr = shared_scalar(lr)
121 
122     def get_updates(self, params, constraints, loss):
123         grads = self.get_gradients(loss, params)
124         accumulators = [shared_zeros(p.get_value().shape) for p in params]
125         self.updates = []
126 
127         for p, g, a, c in zip(params, grads, accumulators, constraints):
128             new_a = a + g ** 2  # update accumulator
129             self.updates.append((a, new_a))
130             new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)
131             self.updates.append((p, c(new_p)))  # apply constraints
132         return self.updates
133 
134     def get_config(self):
135         return {"name": self.__class__.__name__,
136                 "lr": float(self.lr.get_value()),
137                 "epsilon": self.epsilon}
138 
139 
140 class Adadelta(Optimizer):
141     '''
142         Reference: http://arxiv.org/abs/1212.5701
143     '''
144     def __init__(self, lr=1.0, rho=0.95, epsilon=1e-6, *args, **kwargs):
145         super(Adadelta, self).__init__(**kwargs)
146         self.__dict__.update(locals())
147         self.lr = shared_scalar(lr)
148 
149     def get_updates(self, params, constraints, loss):
150         grads = self.get_gradients(loss, params)
151         accumulators = [shared_zeros(p.get_value().shape) for p in params]
152         delta_accumulators = [shared_zeros(p.get_value().shape) for p in params]
153         self.updates = []
154 
155         for p, g, a, d_a, c in zip(params, grads, accumulators,
156                                    delta_accumulators, constraints):
157             new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator
158             self.updates.append((a, new_a))
159 
160             # use the new accumulator and the *old* delta_accumulator
161             update = g * T.sqrt(d_a + self.epsilon) / T.sqrt(new_a +
162                                                              self.epsilon)
163 
164             new_p = p - self.lr * update
165             self.updates.append((p, c(new_p)))  # apply constraints
166 
167             # update delta_accumulator
168             new_d_a = self.rho * d_a + (1 - self.rho) * update ** 2
169             self.updates.append((d_a, new_d_a))
170         return self.updates
171 
172     def get_config(self):
173         return {"name": self.__class__.__name__,
174                 "lr": float(self.lr.get_value()),
175                 "rho": self.rho,
176                 "epsilon": self.epsilon}
177 
178 
179 class Adam(Optimizer):
180     '''
181         Reference: http://arxiv.org/abs/1412.6980v8
182 
183         Default parameters follow those provided in the original paper.
184     '''
185     def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-8, *args, **kwargs):
186         super(Adam, self).__init__(**kwargs)
187         self.__dict__.update(locals())
188         self.iterations = shared_scalar(0)
189         self.lr = shared_scalar(lr)
190 
191     def get_updates(self, params, constraints, loss):
192         grads = self.get_gradients(loss, params)
193         self.updates = [(self.iterations, self.iterations+1.)]
194 
195         t = self.iterations + 1
196         lr_t = self.lr * T.sqrt(1-self.beta_2**t)/(1-self.beta_1**t)
197 
198         for p, g, c in zip(params, grads, constraints):
199             m = theano.shared(p.get_value() * 0.)  # zero init of moment
200             v = theano.shared(p.get_value() * 0.)  # zero init of velocity
201 
202             m_t = (self.beta_1 * m) + (1 - self.beta_1) * g
203             v_t = (self.beta_2 * v) + (1 - self.beta_2) * (g**2)
204             p_t = p - lr_t * m_t / (T.sqrt(v_t) + self.epsilon)
205 
206             self.updates.append((m, m_t))
207             self.updates.append((v, v_t))
208             self.updates.append((p, c(p_t)))  # apply constraints
209         return self.updates
210 
211     def get_config(self):
212         return {"name": self.__class__.__name__,
213                 "lr": float(self.lr.get_value()),
214                 "beta_1": self.beta_1,
215                 "beta_2": self.beta_2,
216                 "epsilon": self.epsilon}
217 
218 # aliases
219 sgd = SGD
220 rmsprop = RMSprop
221 adagrad = Adagrad
222 adadelta = Adadelta
223 adam = Adam
224 
225 
226 def get(identifier, kwargs=None):
227     return get_from_module(identifier, globals(), 'optimizer', instantiate=True,
228                            kwargs=kwargs)
229
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/keras/optimizers.py b/keras/optimizers.py
--- a/keras/optimizers.py
+++ b/keras/optimizers.py
@@ -82,7 +82,7 @@
         return {"name": self.__class__.__name__,
                 "lr": float(self.lr.get_value()),
                 "momentum": float(self.momentum.get_value()),
-                "decay": float(self.decay.get_value()),
+                "decay": float(self.decay),
                 "nesterov": self.nesterov}

{"golden_diff": "diff --git a/keras/optimizers.py b/keras/optimizers.py\n--- a/keras/optimizers.py\n+++ b/keras/optimizers.py\n@@ -82,7 +82,7 @@\n         return {\"name\": self.__class__.__name__,\n                 \"lr\": float(self.lr.get_value()),\n                 \"momentum\": float(self.momentum.get_value()),\n-                \"decay\": float(self.decay.get_value()),\n+                \"decay\": float(self.decay),\n                 \"nesterov\": self.nesterov}\n", "issue": "'float' object has no attribute 'get_value' problem.\nWhen I was trying to print the configuration of a model by \"model.get_config()\" or trying to save my model as a 'json' file:\n\njson_str = autoEncoder.to_json()\nopen('temp_model.json','w').write(json_str)\nautoEncoder.save_weights('temp_model_weights.h5')\n\nIt raise the exception \"float object has no attribute 'get_value' \" in file 'optimizer.py', in class SGD(because I was using SGD as the optimizer), the definition of get_config() is:\n\n def get_config(self):\n        return {\"name\": self.**class**.**name**,\n                \"lr\": float(self.lr.get_value()),\n                \"momentum\": float(self.momentum.get_value()),\n                \"decay\": float(self.decay.get_value()),\n                \"nesterov\": self.nesterov}\n\nwhile the **init** of class SGD does not contain decay and nesterov\n\n```\ndef __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, *args, **kwargs):\n    super(SGD, self).__init__(**kwargs)\n    self.__dict__.update(locals())\n    self.iterations = shared_scalar(0)\n    self.lr = shared_scalar(lr)\n    self.momentum = shared_scalar(momentum)\n```\n\nIs it a bug? Can I fix the problem by adding 'self.decay = shared_scalar(decay)' or something like this?\n\nThank you very much!\n\n", "before_files": [{"content": "from __future__ import absolute_import\nimport theano\nimport theano.tensor as T\n\nfrom .utils.theano_utils import shared_zeros, shared_scalar, floatX\nfrom .utils.generic_utils import get_from_module\nfrom six.moves import zip\n\n\ndef clip_norm(g, c, n):\n    if c > 0:\n        g = T.switch(T.ge(n, c), g * c / n, g)\n    return g\n\n\ndef kl_divergence(p, p_hat):\n    return p_hat - p + p * T.log(p / p_hat)\n\n\nclass Optimizer(object):\n    def __init__(self, **kwargs):\n        self.__dict__.update(kwargs)\n        self.updates = []\n\n    def get_state(self):\n        return [u[0].get_value() for u in self.updates]\n\n    def set_state(self, value_list):\n        assert len(self.updates) == len(value_list)\n        for u, v in zip(self.updates, value_list):\n            u[0].set_value(floatX(v))\n\n    def get_updates(self, params, constraints, loss):\n        raise NotImplementedError\n\n    def get_gradients(self, loss, params):\n\n        grads = T.grad(loss, params)\n\n        if hasattr(self, 'clipnorm') and self.clipnorm > 0:\n            norm = T.sqrt(sum([T.sum(g ** 2) for g in grads]))\n            grads = [clip_norm(g, self.clipnorm, norm) for g in grads]\n\n        if hasattr(self, 'clipvalue') and self.clipvalue > 0:\n            grads = [T.clip(g, -self.clipvalue, self.clipvalue) for g in grads]\n\n        return grads\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__}\n\n\nclass SGD(Optimizer):\n\n    def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, *args, **kwargs):\n        super(SGD, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.iterations = shared_scalar(0)\n        self.lr = shared_scalar(lr)\n        self.momentum = shared_scalar(momentum)\n        self.decay = shared_scalar(decay)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        lr = self.lr * (1.0 / (1.0 + self.decay * self.iterations))\n        self.updates = [(self.iterations, self.iterations + 1.)]\n\n        for p, g, c in zip(params, grads, constraints):\n            m = shared_zeros(p.get_value().shape)  # momentum\n            v = self.momentum * m - lr * g  # velocity\n            self.updates.append((m, v))\n\n            if self.nesterov:\n                new_p = p + self.momentum * v - lr * g\n            else:\n                new_p = p + v\n\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"momentum\": float(self.momentum.get_value()),\n                \"decay\": float(self.decay.get_value()),\n                \"nesterov\": self.nesterov}\n\n\nclass RMSprop(Optimizer):\n    def __init__(self, lr=0.001, rho=0.9, epsilon=1e-6, *args, **kwargs):\n        super(RMSprop, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n        self.rho = shared_scalar(rho)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, c in zip(params, grads, accumulators, constraints):\n            new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n\n            new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"rho\": float(self.rho.get_value()),\n                \"epsilon\": self.epsilon}\n\n\nclass Adagrad(Optimizer):\n    def __init__(self, lr=0.01, epsilon=1e-6, *args, **kwargs):\n        super(Adagrad, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, c in zip(params, grads, accumulators, constraints):\n            new_a = a + g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n            new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"epsilon\": self.epsilon}\n\n\nclass Adadelta(Optimizer):\n    '''\n        Reference: http://arxiv.org/abs/1212.5701\n    '''\n    def __init__(self, lr=1.0, rho=0.95, epsilon=1e-6, *args, **kwargs):\n        super(Adadelta, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        delta_accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, d_a, c in zip(params, grads, accumulators,\n                                   delta_accumulators, constraints):\n            new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n\n            # use the new accumulator and the *old* delta_accumulator\n            update = g * T.sqrt(d_a + self.epsilon) / T.sqrt(new_a +\n                                                             self.epsilon)\n\n            new_p = p - self.lr * update\n            self.updates.append((p, c(new_p)))  # apply constraints\n\n            # update delta_accumulator\n            new_d_a = self.rho * d_a + (1 - self.rho) * update ** 2\n            self.updates.append((d_a, new_d_a))\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"rho\": self.rho,\n                \"epsilon\": self.epsilon}\n\n\nclass Adam(Optimizer):\n    '''\n        Reference: http://arxiv.org/abs/1412.6980v8\n\n        Default parameters follow those provided in the original paper.\n    '''\n    def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-8, *args, **kwargs):\n        super(Adam, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.iterations = shared_scalar(0)\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        self.updates = [(self.iterations, self.iterations+1.)]\n\n        t = self.iterations + 1\n        lr_t = self.lr * T.sqrt(1-self.beta_2**t)/(1-self.beta_1**t)\n\n        for p, g, c in zip(params, grads, constraints):\n            m = theano.shared(p.get_value() * 0.)  # zero init of moment\n            v = theano.shared(p.get_value() * 0.)  # zero init of velocity\n\n            m_t = (self.beta_1 * m) + (1 - self.beta_1) * g\n            v_t = (self.beta_2 * v) + (1 - self.beta_2) * (g**2)\n            p_t = p - lr_t * m_t / (T.sqrt(v_t) + self.epsilon)\n\n            self.updates.append((m, m_t))\n            self.updates.append((v, v_t))\n            self.updates.append((p, c(p_t)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"beta_1\": self.beta_1,\n                \"beta_2\": self.beta_2,\n                \"epsilon\": self.epsilon}\n\n# aliases\nsgd = SGD\nrmsprop = RMSprop\nadagrad = Adagrad\nadadelta = Adadelta\nadam = Adam\n\n\ndef get(identifier, kwargs=None):\n    return get_from_module(identifier, globals(), 'optimizer', instantiate=True,\n                           kwargs=kwargs)\n", "path": "keras/optimizers.py"}], "after_files": [{"content": "from __future__ import absolute_import\nimport theano\nimport theano.tensor as T\n\nfrom .utils.theano_utils import shared_zeros, shared_scalar, floatX\nfrom .utils.generic_utils import get_from_module\nfrom six.moves import zip\n\n\ndef clip_norm(g, c, n):\n    if c > 0:\n        g = T.switch(T.ge(n, c), g * c / n, g)\n    return g\n\n\ndef kl_divergence(p, p_hat):\n    return p_hat - p + p * T.log(p / p_hat)\n\n\nclass Optimizer(object):\n    def __init__(self, **kwargs):\n        self.__dict__.update(kwargs)\n        self.updates = []\n\n    def get_state(self):\n        return [u[0].get_value() for u in self.updates]\n\n    def set_state(self, value_list):\n        assert len(self.updates) == len(value_list)\n        for u, v in zip(self.updates, value_list):\n            u[0].set_value(floatX(v))\n\n    def get_updates(self, params, constraints, loss):\n        raise NotImplementedError\n\n    def get_gradients(self, loss, params):\n\n        grads = T.grad(loss, params)\n\n        if hasattr(self, 'clipnorm') and self.clipnorm > 0:\n            norm = T.sqrt(sum([T.sum(g ** 2) for g in grads]))\n            grads = [clip_norm(g, self.clipnorm, norm) for g in grads]\n\n        if hasattr(self, 'clipvalue') and self.clipvalue > 0:\n            grads = [T.clip(g, -self.clipvalue, self.clipvalue) for g in grads]\n\n        return grads\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__}\n\n\nclass SGD(Optimizer):\n\n    def __init__(self, lr=0.01, momentum=0., decay=0., nesterov=False, *args, **kwargs):\n        super(SGD, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.iterations = shared_scalar(0)\n        self.lr = shared_scalar(lr)\n        self.momentum = shared_scalar(momentum)\n        self.decay = shared_scalar(decay)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        lr = self.lr * (1.0 / (1.0 + self.decay * self.iterations))\n        self.updates = [(self.iterations, self.iterations + 1.)]\n\n        for p, g, c in zip(params, grads, constraints):\n            m = shared_zeros(p.get_value().shape)  # momentum\n            v = self.momentum * m - lr * g  # velocity\n            self.updates.append((m, v))\n\n            if self.nesterov:\n                new_p = p + self.momentum * v - lr * g\n            else:\n                new_p = p + v\n\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"momentum\": float(self.momentum.get_value()),\n                \"decay\": float(self.decay),\n                \"nesterov\": self.nesterov}\n\n\nclass RMSprop(Optimizer):\n    def __init__(self, lr=0.001, rho=0.9, epsilon=1e-6, *args, **kwargs):\n        super(RMSprop, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n        self.rho = shared_scalar(rho)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, c in zip(params, grads, accumulators, constraints):\n            new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n\n            new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"rho\": float(self.rho.get_value()),\n                \"epsilon\": self.epsilon}\n\n\nclass Adagrad(Optimizer):\n    def __init__(self, lr=0.01, epsilon=1e-6, *args, **kwargs):\n        super(Adagrad, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, c in zip(params, grads, accumulators, constraints):\n            new_a = a + g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n            new_p = p - self.lr * g / T.sqrt(new_a + self.epsilon)\n            self.updates.append((p, c(new_p)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"epsilon\": self.epsilon}\n\n\nclass Adadelta(Optimizer):\n    '''\n        Reference: http://arxiv.org/abs/1212.5701\n    '''\n    def __init__(self, lr=1.0, rho=0.95, epsilon=1e-6, *args, **kwargs):\n        super(Adadelta, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        delta_accumulators = [shared_zeros(p.get_value().shape) for p in params]\n        self.updates = []\n\n        for p, g, a, d_a, c in zip(params, grads, accumulators,\n                                   delta_accumulators, constraints):\n            new_a = self.rho * a + (1 - self.rho) * g ** 2  # update accumulator\n            self.updates.append((a, new_a))\n\n            # use the new accumulator and the *old* delta_accumulator\n            update = g * T.sqrt(d_a + self.epsilon) / T.sqrt(new_a +\n                                                             self.epsilon)\n\n            new_p = p - self.lr * update\n            self.updates.append((p, c(new_p)))  # apply constraints\n\n            # update delta_accumulator\n            new_d_a = self.rho * d_a + (1 - self.rho) * update ** 2\n            self.updates.append((d_a, new_d_a))\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"rho\": self.rho,\n                \"epsilon\": self.epsilon}\n\n\nclass Adam(Optimizer):\n    '''\n        Reference: http://arxiv.org/abs/1412.6980v8\n\n        Default parameters follow those provided in the original paper.\n    '''\n    def __init__(self, lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-8, *args, **kwargs):\n        super(Adam, self).__init__(**kwargs)\n        self.__dict__.update(locals())\n        self.iterations = shared_scalar(0)\n        self.lr = shared_scalar(lr)\n\n    def get_updates(self, params, constraints, loss):\n        grads = self.get_gradients(loss, params)\n        self.updates = [(self.iterations, self.iterations+1.)]\n\n        t = self.iterations + 1\n        lr_t = self.lr * T.sqrt(1-self.beta_2**t)/(1-self.beta_1**t)\n\n        for p, g, c in zip(params, grads, constraints):\n            m = theano.shared(p.get_value() * 0.)  # zero init of moment\n            v = theano.shared(p.get_value() * 0.)  # zero init of velocity\n\n            m_t = (self.beta_1 * m) + (1 - self.beta_1) * g\n            v_t = (self.beta_2 * v) + (1 - self.beta_2) * (g**2)\n            p_t = p - lr_t * m_t / (T.sqrt(v_t) + self.epsilon)\n\n            self.updates.append((m, m_t))\n            self.updates.append((v, v_t))\n            self.updates.append((p, c(p_t)))  # apply constraints\n        return self.updates\n\n    def get_config(self):\n        return {\"name\": self.__class__.__name__,\n                \"lr\": float(self.lr.get_value()),\n                \"beta_1\": self.beta_1,\n                \"beta_2\": self.beta_2,\n                \"epsilon\": self.epsilon}\n\n# aliases\nsgd = SGD\nrmsprop = RMSprop\nadagrad = Adagrad\nadadelta = Adadelta\nadam = Adam\n\n\ndef get(identifier, kwargs=None):\n    return get_from_module(identifier, globals(), 'optimizer', instantiate=True,\n                           kwargs=kwargs)\n", "path": "keras/optimizers.py"}]}