def rmsprop(opfunc, x, config, state=None):
 if ((config is None) and (state is None)):
  raise ValueError('rmsprop requires a dictionary to retain state between iterations')
 state = (state if (state is not None) else config)
 lr = config.get('learningRate', 0.01)
 alpha = config.get('alpha', 0.99)
 epsilon = config.get('epsilon', 1e-08)
 wd = config.get('weightDecay', 0)
 (fx, dfdx) = opfunc(x)
 if (wd != 0):
  dfdx.add_(wd, x)
 if (not ('m' in state)):
  state['m'] = x.new().resize_as_(dfdx).zero_()
  state['tmp'] = x.new().resize_as_(dfdx)
 state['m'].mul_(alpha)
 state['m'].addcmul_((1.0 - alpha), dfdx, dfdx)
 torch.sqrt(state['m'], out=state['tmp']).add_(epsilon)
 x.addcdiv_((- lr), dfdx, state['tmp'])
 return (x, fx)

def rmsprop ( opfunc , x , config , state = None ) : if ( ( config is None ) and ( state is None ) ) : raise ValueError ( 'rmsprop requires a dictionary to retain state between iterations' ) state = ( state if ( state is not None ) else config ) lr = config . get ( 'learningRate' , 0.01 ) alpha = config . get ( 'alpha' , 0.99 ) epsilon = config . get ( 'epsilon' , 1e-08 ) wd = config . get ( 'weightDecay' , 0 ) ( fx , dfdx ) = opfunc ( x ) if ( wd != 0 ) : dfdx . add_ ( wd , x ) if ( not ( 'm' in state ) ) : state [ 'm' ] = x . new ( ) . resize_as_ ( dfdx ) . zero_ ( ) state [ 'tmp' ] = x . new ( ) . resize_as_ ( dfdx ) state [ 'm' ] . mul_ ( alpha ) state [ 'm' ] . addcmul_ ( ( 1.0 - alpha ) , dfdx , dfdx ) torch . sqrt ( state [ 'm' ] , out = state [ 'tmp' ] ) . add_ ( epsilon ) x . addcdiv_ ( ( - lr ) , dfdx , state [ 'tmp' ] ) return ( x , fx )
rmsprop updates scale learning rates by dividing with the moving average of the root mean squared gradients .