def get_updates(self, params, gparams): self._ms_ = [] self._vs_ = [] for param in params: self._ms_ += [K.shared(np.zeros_like(param.get_value()))] self._vs_ += [K.shared(np.zeros_like(param.get_value()))] updates = [] t = self._iter_ + 1 alpha_t = self._alpha_ * (K.sqrt(1. - K.power(self._beta2_, t)) / (1. - K.power(self._beta1_, t))) for p, g, m, v in zip(params, gparams, self._ms_, self._vs_): m_new = self._beta1_ * m + (1. - self._beta1_) * g updates.append((m, m_new)) v_new = self._beta2_ * v + (1. - self._beta2_) * K.sqr(g) updates.append((v, v_new)) p_new = p - alpha_t * m_new / (K.sqrt(v_new) + self._eps_) updates.append((p, p_new)) updates.append((self._iter_, self._iter_ + 1)) return updates
def get_updates(self, params, gparams): self._accumulators_ = [] self._delta_accumulators_ = [] for param in params: self._accumulators_ += [K.shared(np.zeros_like(param.get_value()))] self._delta_accumulators_ += [K.shared(np.zeros_like(param.get_value()))] updates = [] for p, g, a, d_a in zip(params, gparams, self._accumulators_, self._delta_accumulators_): a_new = self._rou_ * a + (1. - self._rou_) * K.sqr(g) updates.append((a, a_new)) p_delta = - g * K.sqrt(d_a + self._eps_) / K.sqrt(a_new + self._eps_) p_new = p + p_delta updates.append((p, p_new)) d_a_new = self._rou_ * d_a + (1. - self._rou_) * K.sqr(p_delta) updates.append((d_a, d_a_new)) return updates
def get_updates(self, params, gparams): self._accumulators_ = [] for param in params: self._accumulators_.append(K.shared(np.zeros_like(K.get_value(param)))) updates = [] for p, g, a in zip(params, gparams, self._accumulators_): a_new = a + K.sqr(g) p_new = p - self._lr_ * g / (K.sqrt(a_new) + self._eps_) updates.append((a, a_new)) updates.append((p, p_new)) return updates
def get_reg(self, params): reg = self._l1_ * K.sum( [ K.sum( K.abs( param ) ) for param in params ] ) + \ self._l2_ * K.sum( [ K.sum( K.sqr( param ) ) for param in params ] ) return reg
def get_reg(self, params): return self._l2_ * K.sum([K.sum(K.sqr(param)) for param in params])
def mse(y_pred, y_gt): return K.mean(K.sqr(y_pred - y_gt))
def get_reg( self, params ): reg = self._l1_ * K.sum( [ K.sum( K.abs( param ) ) for param in params ] ) + \ self._l2_ * K.sum( [ K.sum( K.sqr( param ) ) for param in params ] ) return reg
def get_reg( self, params ): return self._l2_ * K.sum( [ K.sum( K.sqr( param ) ) for param in params ] )
def mse( y_pred, y_gt ): return K.mean( K.sum( K.sqr( y_pred - y_gt ), axis=-1 ) )