def apply_momentum(updates, params=None, momentum=0.9):
 if (params is None):
  params = updates.keys()
 updates = OrderedDict(updates)
 for param in params:
  value = param.get_value(borrow=True)
  velocity = theano.shared(np.zeros(value.shape, dtype=value.dtype), broadcastable=param.broadcastable)
  x = ((momentum * velocity) + updates[param])
  updates[velocity] = (x - param)
  updates[param] = x
 return updates

def apply_momentum ( updates , params = None , momentum = 0.9 ) : if ( params is None ) : params = updates . keys ( ) updates = OrderedDict ( updates ) for param in params : value = param . get_value ( borrow = True ) velocity = theano . shared ( np . zeros ( value . shape , dtype = value . dtype ) , broadcastable = param . broadcastable ) x = ( ( momentum * velocity ) + updates [ param ] ) updates [ velocity ] = ( x - param ) updates [ param ] = x return updates
returns a modified update dictionary including momentum generates update expressions of the form: * velocity := momentum * velocity + updates[param] - param * param := param + velocity parameters updates : ordereddict a dictionary mapping parameters to update expressions params : iterable of shared variables .