def prepare_adagrad_test(dataset_type='arange', model_type='random'):
 cost = SumOfCosts([SumOfOneHalfParamsSquared(), (0.0, DummyCost())])
 model = DummyModel(shapes, lr_scalers=scales, init_type=model_type)
 if (dataset_type == 'arange'):
  dataset = ArangeDataset(1)
 elif (dataset_type == 'zeros'):
  X = np.zeros((1, 1))
  X[:, 0] = np.arange(1)
  dataset = DenseDesignMatrix(X)
 else:
  raise ValueError('Unknown value for dataset_type: %s', dataset_type)
 sgd = SGD(cost=cost, learning_rate=learning_rate, learning_rule=AdaGrad(), batch_size=1)
 sgd.setup(model=model, dataset=dataset)
 state = {}
 for param in model.get_params():
  param_shape = param.get_value().shape
  state[param] = {}
  state[param]['sg2'] = np.zeros(param_shape)
 return (cost, model, dataset, sgd, state)

def prepare_adagrad_test ( dataset_type = 'arange' , model_type = 'random' ) : cost = SumOfCosts ( [ SumOfOneHalfParamsSquared ( ) , ( 0.0 , DummyCost ( ) ) ] ) model = DummyModel ( shapes , lr_scalers = scales , init_type = model_type ) if ( dataset_type == 'arange' ) : dataset = ArangeDataset ( 1 ) elif ( dataset_type == 'zeros' ) : X = np . zeros ( ( 1 , 1 ) ) X [ : , 0 ] = np . arange ( 1 ) dataset = DenseDesignMatrix ( X ) else : raise ValueError ( 'Unknown value for dataset_type: %s' , dataset_type ) sgd = SGD ( cost = cost , learning_rate = learning_rate , learning_rule = AdaGrad ( ) , batch_size = 1 ) sgd . setup ( model = model , dataset = dataset ) state = { } for param in model . get_params ( ) : param_shape = param . get_value ( ) . shape state [ param ] = { } state [ param ] [ 'sg2' ] = np . zeros ( param_shape ) return ( cost , model , dataset , sgd , state )
factor out common code for adagrad tests .