Returns a method that can be used in argument parsing to check that the argument is a valid learning rate schedule
    string.

    :return: A method that can be used as a type in argparse.
325998
def learning_schedule() -> Callable:
    

    def parse(schedule_str):
        try:
            schedule = LearningRateSchedulerFixedStep.parse_schedule_str(schedule_str)
        except ValueError:
            raise argparse.ArgumentTypeError(
                "Learning rate schedule string should have form rate1:num_updates1[,rate2:num_updates2,...]")
        return schedule

    return parse
955367
def stringmethod(func):
    
    method_name = func()

    @wraps(func)
    def factory():
        def validator(v):
            if not isinstance(v, six.string_types):
                raise Invalid(_(u'Not a string'), get_type_name(six.text_type), get_type_name(type(v)))
            return getattr(v, method_name)()
        return validator
    return factory
77607
def argval(self):
        
        if self.arg is None or any(x is None for x in self.arg):
            return None

        for x in self.arg:
            if not isinstance(x, int):
                raise InvalidArgError(self.arg)

        return self.arg
169390
def method_missing(method_name, *arguments)
      klass = REGISTRY.fetch(method_name) { super }

      Evaluator.new(klass, arguments).rules.each do |rule|
        add(rule)
      end

      self
    end
759384
def get_learning_rate(self, iter):
        '''
        
        '''

        return self.init_lr * (self.gamma ** (iter // self.iter_interval))
173463
def timespan_type(arg):
	""""""
	try:
		arg = parse_timespan(arg)
	except ValueError:
		raise argparse.ArgumentTypeError("{0} is not a valid time span".format(repr(arg)))
	return arg
767974
def is_str(arg):
    '''
     
    '''
    return (isinstance(arg, six.string_types) or
            is_npscalar(arg, 'string') or
            is_npvalue(arg, 'string'))
1167394
def _validate_arguments(self):
        
        # dtype
        if self.dtype not in ['numerical', 'categorical']:
            raise ValueError("dtype must be in ['numerical','categorical'], "\
                             "but found dtype = {}".format(self.dtype))

        # fit_linear XOR fit_splines
        if self.fit_linear == self.fit_splines:
            raise ValueError('term must have fit_linear XOR fit_splines, but found: '
                             'fit_linear= {}, fit_splines={}'.format(self.fit_linear, self.fit_splines))

        # penalties
        if not isiterable(self.penalties):
            self.penalties = [self.penalties]

        for i, p in enumerate(self.penalties):
            if not (hasattr(p, '__call__') or
                    (p in PENALTIES) or
                    (p is None)):
                raise ValueError("penalties must be callable or in "\
                                 "{}, but found {} for {}th penalty"\
                                 .format(list(PENALTIES.keys()), p, i))

        # check lams and distribute to penalites
        if not isiterable(self.lam):
            self.lam = [self.lam]

        for lam in self.lam:
            check_param(lam, param_name='lam', dtype='float', constraint='>= 0')

        if len(self.lam) == 1:
            self.lam = self.lam * len(self.penalties)

        if len(self.lam) != len(self.penalties):
            raise ValueError('expected 1 lam per penalty, but found '\
                             'lam = {}, penalties = {}'.format(self.lam, self.penalties))

        # constraints
        if not isiterable(self.constraints):
            self.constraints = [self.constraints]

        for i, c in enumerate(self.constraints):
            if not (hasattr(c, '__call__') or
                    (c in CONSTRAINTS) or
                    (c is None)):
                raise ValueError("constraints must be callable or in "\
                                 "{}, but found {} for {}th constraint"\
                                 .format(list(CONSTRAINTS.keys()), c, i))

        return self
921900
def _sanity_check_args(args):
    
    if "scheduler" in args and "queue" in args:
        if args.scheduler and not args.queue:
            if args.scheduler != "sge":
                return "IPython parallel scheduler (-s) specified. This also requires a queue (-q)."
        elif args.queue and not args.scheduler:
            return "IPython parallel queue (-q) supplied. This also requires a scheduler (-s)."
        elif args.paralleltype == "ipython" and (not args.queue or not args.scheduler):
            return "IPython parallel requires queue (-q) and scheduler (-s) arguments."
1196123
def _decodeRelativeValidityPeriod(tpVp):
    
    if tpVp <= 143:
        return timedelta(minutes=((tpVp + 1) * 5))
    elif 144 <= tpVp <= 167:
        return timedelta(hours=12, minutes=((tpVp - 143) * 30))
    elif 168 <= tpVp <= 196:
        return timedelta(days=(tpVp - 166))
    elif 197 <= tpVp <= 255:
        return timedelta(weeks=(tpVp - 192))
    else:
        raise ValueError('tpVp must be in range [0, 255]')
617828
def parse_schedule_str(schedule_str: str) -> List[Tuple[float, int]]:
        
        schedule = list()
        for step in schedule_str.split(","):
            rate, num_updates = step.split(":")
            schedule.append((float(rate), int(num_updates)))
        return schedule
971379
def _validate_teaching(cls, belief, teaching, *args, **kwargs):
        
        if teaching.__hash__ is None:
            raise DictionaryDogmaException(''''The belief '%s' does not have a hashable teaching '%s' ''' % (belief, teaching ))

        return teaching
1283092
def format (self, *args, **kwargs):
        
        return self.__class__ (str (self).format (*args, **kwargs))
108926
def learn(self, input_dir: str) -> float:
        
        if self.is_default:
            LOGGER.error("Cannot learn using default model")
            raise GuesslangError('Cannot learn using default "readonly" model')

        languages = self.languages

        LOGGER.info("Extract training data")
        extensions = [ext for exts in languages.values() for ext in exts]
        files = search_files(input_dir, extensions)
        nb_files = len(files)
        chunk_size = min(int(CHUNK_PROPORTION * nb_files), CHUNK_SIZE)

        LOGGER.debug("Evaluation files count: %d", chunk_size)
        LOGGER.debug("Training files count: %d", nb_files - chunk_size)
        batches = _pop_many(files, chunk_size)

        LOGGER.debug("Prepare evaluation data")
        evaluation_data = extract_from_files(next(batches), languages)
        LOGGER.debug("Evaluation data count: %d", len(evaluation_data[0]))

        accuracy = 0
        total = ceil(nb_files / chunk_size) - 1
        LOGGER.info("Start learning")
        for pos, training_files in enumerate(batches, 1):
            LOGGER.info("Step %.2f%%", 100 * pos / total)

            LOGGER.debug("Training data extraction")
            training_data = extract_from_files(training_files, languages)
            LOGGER.debug("Training data count: %d", len(training_data[0]))

            steps = int(FITTING_FACTOR * len(training_data[0]) / 100)
            LOGGER.debug("Fitting, steps count: %d", steps)
            self._classifier.fit(input_fn=_to_func(training_data), steps=steps)

            LOGGER.debug("Evaluation")
            accuracy = self._classifier.evaluate(
                input_fn=_to_func(evaluation_data), steps=1)['accuracy']
            _comment(accuracy)

        return accuracy
160428
def _learning_rate_warmup(warmup_steps, warmup_schedule="exp", hparams=None):
  """"""
  if not warmup_steps:
    return tf.constant(1.)

  tf.logging.info("Applying %s learning rate warmup for %d steps",
                  warmup_schedule, warmup_steps)

  warmup_steps = tf.to_float(warmup_steps)
  global_step = _global_step(hparams)

  if warmup_schedule == "exp":
    return tf.exp(tf.log(0.01) / warmup_steps)**(warmup_steps - global_step)
  else:
    assert warmup_schedule == "linear"
    start = tf.constant(0.35)
    return ((tf.constant(1.) - start) / warmup_steps) * global_step + start
602932
def _prepare(self, **kwargs):
        '''
        '''
        self.learning_rate = util.as_float(kwargs.pop('learning_rate', 1e-4))
        self.momentum = kwargs.pop('momentum', 0)
        self.nesterov = kwargs.pop('nesterov', False)
        self.patience = kwargs.get('patience', 5)
        self.validate_every = kwargs.pop('validate_every', 10)
        self.min_improvement = kwargs.pop('min_improvement', 0)
        self.max_gradient_norm = kwargs.pop('max_gradient_norm', 0)
        self.max_gradient_elem = kwargs.pop('max_gradient_elem', 0)

        util.log_param('patience', self.patience)
        util.log_param('validate_every', self.validate_every)
        util.log_param('min_improvement', self.min_improvement)
        util.log_param('max_gradient_norm', self.max_gradient_norm)
        util.log_param('max_gradient_elem', self.max_gradient_elem)
        util.log_param('learning_rate', self.learning_rate)
        util.log_param('momentum', self.momentum)
        util.log_param('nesterov', self.nesterov)
561595
def gradient_compression_params(args: argparse.Namespace) -> Optional[Dict[str, Any]]:
    
    if args.gradient_compression_type is None:
        return None
    else:
        return {'type': args.gradient_compression_type, 'threshold': args.gradient_compression_threshold}