def test_adagrad():
 (cost, model, dataset, sgd, state) = prepare_adagrad_test()
 def adagrad_manual(model, state):
  rval = []
  for (scale, param) in izip(scales, model.get_params()):
   pstate = state[param]
   param_val = param.get_value()
   pstate['sg2'] += (param_val ** 2)
   dx_t = (- (((scale * learning_rate) / np.sqrt(pstate['sg2'])) * param_val))
   rval += [(param_val + dx_t)]
  return rval
 manual = adagrad_manual(model, state)
 sgd.train(dataset=dataset)
 assert all((np.allclose(manual_param, sgd_param.get_value()) for (manual_param, sgd_param) in izip(manual, model.get_params())))
 manual = adagrad_manual(model, state)
 sgd.train(dataset=dataset)
 assert all((np.allclose(manual_param, sgd_param.get_value()) for (manual_param, sgd_param) in izip(manual, model.get_params())))

def test_adagrad ( ) : ( cost , model , dataset , sgd , state ) = prepare_adagrad_test ( ) def adagrad_manual ( model , state ) : rval = [ ] for ( scale , param ) in izip ( scales , model . get_params ( ) ) : pstate = state [ param ] param_val = param . get_value ( ) pstate [ 'sg2' ] += ( param_val ** 2 ) dx_t = ( - ( ( ( scale * learning_rate ) / np . sqrt ( pstate [ 'sg2' ] ) ) * param_val ) ) rval += [ ( param_val + dx_t ) ] return rval manual = adagrad_manual ( model , state ) sgd . train ( dataset = dataset ) assert all ( ( np . allclose ( manual_param , sgd_param . get_value ( ) ) for ( manual_param , sgd_param ) in izip ( manual , model . get_params ( ) ) ) ) manual = adagrad_manual ( model , state ) sgd . train ( dataset = dataset ) assert all ( ( np . allclose ( manual_param , sgd_param . get_value ( ) ) for ( manual_param , sgd_param ) in izip ( manual , model . get_params ( ) ) ) )
make sure that learning_rule .