@@ -0,0 +1,2067 @@
+# Copyright 2015 Leon Sixt%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#    http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%0Afrom keras.optimizers import Optimizer%0Aimport theano.tensor as T%0Aimport keras.backend as K%0Aimport numpy as np%0A%0A%0Aclass RProp(Optimizer):%0A    def __init__(self,%0A                 init_step=0.01,%0A                 increase=1.10,%0A                 decrease=0.8,%0A                 min_step=1e-7,%0A                 max_step=10,%0A                 **kwargs):%0A        self.init_step = init_step%0A        self.increase = K.variable(increase)%0A        self.decrease = K.variable(decrease)%0A        self.min_step = K.variable(min_step)%0A        self.max_step = K.variable(max_step)%0A        super(RProp, self).__init__(**kwargs)%0A%0A    def get_updates(self, params, constraints, loss):%0A        grads = self.get_gradients(loss, params)%0A        for param, grad, c in zip(params, grads, constraints):%0A            grad_tm1 = K.variable(np.zeros(K.get_value(param).shape))%0A            step_tm1 = K.variable(%0A                self.init_step*np.ones(K.get_value(param).shape))%0A            test = grad * grad_tm1%0A            diff = T.lt(test, 0)%0A            steps = step_tm1 * (T.eq(test, 0) +%0A                                T.gt(test, 0) * self.increase +%0A                                diff * self.decrease)%0A            step = T.minimum(self.max_step, T.maximum(self.min_step, steps))%0A            grad = grad - diff * grad%0A            self.updates.append((param, c(param - T.sgn(grad) * step)))%0A            self.updates.append((grad_tm1, grad))%0A            self.updates.append((step_tm1, step))%0A        return self.updates%0A

add RProp Optimizer