Perform some checks that the trainig config is correct.

  Args:
    train_config: train config as produced by merge_metadata()

  Raises:
    ValueError: if columns look wrong.
542001
def validate_metadata(train_config):
  

  # Make sure we have a default for every column
  if len(train_config['csv_header']) != len(train_config['csv_defaults']):
    raise ValueError('Unequal number of columns in input features file and '
                     'schema file.')

  # Check there are no missing columns. sorted_colums has two copies of the
  # target column because the target column is also listed in
  # categorical_columns or numerical_columns.
  sorted_columns = sorted(train_config['csv_header'] +
                          [train_config['target_column']])

  sorted_columns2 = sorted(train_config['categorical_columns'] +
                           train_config['numerical_columns'] +
                           [train_config['key_column']] +
                           [train_config['target_column']])
  if sorted_columns2 != sorted_columns:
    raise ValueError('Each csv header must be a numerical/categorical type, a '
                     ' key, or a target.')
537748
def fix_config(self, options):
        
        opt = "setup"
        if opt not in options:
            options[opt] = datagen.DataGenerator(classname="weka.datagenerators.classifiers.classification.Agrawal")
        if opt not in self.help:
            self.help[opt] = "The data generator to use (DataGenerator)."

        opt = "incremental"
        if opt not in options:
            options[opt] = False
        if opt not in self.help:
            self.help[opt] = "Whether to output the data incrementally, in case the generator supports that (bool)."

        return super(DataGenerator, self).fix_config(options)
770810
def get_traindata(self) -> np.ndarray:
        
        traindata = None
        for key, value in self.data.items():
            if key not in ['__header__', '__version__', '__globals__']:
                if traindata is None:
                    traindata = value[np.where(value[:, 4] != 0)]
                else:
                    traindata = np.concatenate((traindata, value[np.where(value[:, 4] != 0)]))
        return traindata
1139724
def train(self, data, **kwargs):
        
        self.data = data
        for i in xrange(0,data.shape[1]):
            column_mean = np.mean(data.icol(i))
            column_stdev = np.std(data.icol(i))

            #Have to do += or "list" type will fail (ie with append)
            self.column_means += [column_mean]
            self.column_stdevs += [column_stdev]

        self.data = self.predict(data)
896869
def fix_config(self, options):
        
        options = super(Train, self).fix_config(options)

        opt = "setup"
        if opt not in options:
            options[opt] = Classifier(classname="weka.classifiers.rules.ZeroR")
        if opt not in self.help:
            self.help[opt] = "The classifier/clusterer/associator to train (Classifier/Clusterer/Associator)."

        return options
730415
def validate_config(raise_=True):
    
    ELIBConfig.check()
    known_paths = set()
    duplicate_values = set()
    missing_values = set()
    for config_value in ConfigValue.config_values:
        if config_value.path not in known_paths:
            known_paths.add(config_value.path)
        else:
            duplicate_values.add(config_value.name)
        try:
            config_value()
        except MissingValueError:
            missing_values.add(config_value.name)

    if raise_ and duplicate_values:
        raise DuplicateConfigValueError(str(duplicate_values))
    if raise_ and missing_values:
        raise MissingValueError(str(missing_values), 'missing config value(s)')
    return duplicate_values, missing_values
1011106
def update(self, new_data, *args, **kwargs):
        '''
        '''
        self.train_set += new_data
        self.train_features = [(self.extract_features(d), c)
                               for d, c in self.train_set]
        try:
            self.classifier = self.nltk_class.train(self.train_features,
                                                    *args, **kwargs)
        except AttributeError:  # Descendant has not defined nltk_class
            raise ValueError("NLTKClassifier must have a nltk_class"
                             " variable that is not None.")
        return True
302276
def _train_model(self, train_set, train_labels,
                     validation_set, validation_labels):
        
        shuff = list(zip(train_set, train_labels))

        pbar = tqdm(range(self.num_epochs))
        for i in pbar:

            np.random.shuffle(list(shuff))
            batches = [_ for _ in utilities.gen_batches(
                shuff, self.batch_size)]

            for batch in batches:
                x_batch, y_batch = zip(*batch)
                self.tf_session.run(
                    self.train_step,
                    feed_dict={self.input_data: x_batch,
                               self.input_labels: y_batch,
                               self.keep_prob: self.dropout})

            if validation_set is not None:
                feed = {self.input_data: validation_set,
                        self.input_labels: validation_labels,
                        self.keep_prob: 1}
                acc = tf_utils.run_summaries(
                    self.tf_session, self.tf_merged_summaries,
                    self.tf_summary_writer, i, feed, self.accuracy)
                pbar.set_description("Accuracy: %s" % (acc))
955762
def _check_train_time(self) -> None:
        
        if self._minutes is not None and (datetime.now() - self._training_start).total_seconds()/60 > self._minutes:
                raise TrainingTerminated('Training terminated after more than {} minutes'.format(self._minutes))
1192916
def train(X_train, X_test, y_train, y_test, **kwargs):
    '''
    
    '''
    crf = Trainer()
    crf.set_params({
        'c1': 1.0,
        'c2': 0.001,
        'max_iterations': 200,
    })

    for xseq, yseq in zip(X_train, y_train):
        crf.append(xseq, yseq)
    crf.train(model_name)
    return crf
1199514
def _valid_config(config, required):
    '''
    
    '''
    re_template = r"\s*{config}\s*=.*".format(config=config)
    found = re.search(re_template, configs.exhaleDoxygenStdin)
    if required:
        return found is not None
    else:
        return found is None
326697
protected boolean trainCorpus(List<List<Acronym>> corpus, List<Map<String, String>> trueLabels){
		boolean converge = false;
		
		// Unsupervised
		trueLabels = null;

		initModelParamsAndCounters();

		int n = corpus.size();

		int c = 1;
		Double change; 

		LOG.debug("Training abbreviations...");
		while(!converge){

			for (int i = 0; i < n; i++) {
				List<Acronym> docAcronyms = corpus.get(i);
				Map<String, String> docTrueLabels = null;
				if(trueLabels != null)
					docTrueLabels = trueLabels.get(i);
				int m = docAcronyms.size();
				for (int j = 0; j < m; j++) {
					Acronym currAcronym = docAcronyms.get(j);
					if(trueLabels != null)
						expectationStep(currAcronym, docTrueLabels.get(currAcronym._shortForm));
					else
						expectationStep(currAcronym, null);
				}
			}

			change = maximizationStep();
			LOG.debug("step {}...",c);

			c++;
			if(c > MAX_ITERATIONS){
				System.out.println("\n\tTraining stopped after "+(c-1)+" iterations with final change: "+change);
				converge = true;
			}
			if(change.compareTo(CHANGE_THRESHOLD) < 0){
				LOG.debug("Training converged in "+(c-1)+" iterations.");
				converge = true;
			}
		}
		saveModelParams();
		return true;
	}
754592
def set_config_value(self, name, value):
        
        if value is True:
            value = "True"
        elif value is False:
            if name in self.config_dict:
                del self.config_dict[name]
                self.config_changed = True
            return
        if name not in self.config_dict or self.config_dict[name] != value:
            self.config_changed = True
            self.config_dict[name] = value
1049135
def check(cls):
        
        attribs = [
            'app_version',
            'app_name',
            'config_file_path',
            'config_sep_str',
        ]
        for attrib in attribs:
            if getattr(cls, attrib) == 'not_set':
                raise IncompleteSetupError(f'elib_config setup is incomplete; missing: {attrib}')
243945
def validate_config_file(cls, config_filepath):
        
        is_file = os.path.isfile(config_filepath)
        if not is_file and os.path.isabs(config_filepath):
            raise IOError('File path %s is not a valid yml, ini or cfg file or does not exist' % config_filepath)

        elif is_file:
            if os.path.getsize(config_filepath) == 0:
                raise IOError('File %s is empty' % config_filepath)

        with open(config_filepath, 'r') as f:
            if yaml.load(f) is None:
                raise IOError('No YAML config was found in file %s' % config_filepath)
655989
def check_config(config):
    
    for section, expected_section_keys in SECTION_KEYS.items():
        section_content = config.get(section)
        if not section_content:
            raise ConfigurationError("Config file badly formed! Section {} is missing."
                                     .format(section))
        elif not _section_is_healthy(section_content, expected_section_keys):
            raise ConfigurationError("The {} section of the configuration file is badly formed!"
                                     .format(section))
476813
def ensure_value(
        config: dict,
        name: Union[str, Tuple[str, ...]],
        mutable_config_list: List[str]):
    
    if not isinstance(name, tuple):
        path: Tuple[str, ...] = (name,)
    else:
        path = name
    for element in path[:-1]:
        config = config[element]

    value = config[path[-1]]
    if path[-1] in mutable_config_list:
        value = value['value']
    return value