def loadTrainParameters(self): params_file = os.path.join(self.RESULTS_PATH, self.analysis_name, "trnparams.jbl") if (os.path.exists(params_file)): self.trn_params = TrainParameters.SAENoveltyDetectionTrnParams() self.trn_params.load(params_file) # Choose how many fold to be used in Cross Validation self.CVO = TrainParameters.NoveltyDetectionFolds( folder=self.RESULTS_PATH, n_folds=self.n_folds, trgt=self.all_trgt, dev=self.development_flag, verbose=True) else: self.setTrainParameters()
# Load train parameters analysis_str = 'StackedAutoEncoder' model_prefix_str = 'RawData' trn_params_folder = '%s/%s/%s_trnparams.jbl' % (results_path, analysis_str, analysis_name) # if os.path.exists(trn_params_folder): # os.remove(trn_params_folder) if not os.path.exists(trn_params_folder): trn_params = trnparams.NeuralClassificationTrnParams( n_inits=1, hidden_activation='tanh', # others tanh, relu, sigmoid, linear output_activation='linear', n_epochs=300, #500 patience=30, #30 batch_size=256, #128 verbose=False, optmizerAlgorithm='Adam', metrics=['accuracy'], loss='mean_squared_error') trn_params.save(trn_params_folder) else: trn_params = trnparams.NeuralClassificationTrnParams() trn_params.load(trn_params_folder) # Choose how many fold to be used in Cross Validation n_folds = 10 CVO = trnparams.NoveltyDetectionFolds(folder=results_path, n_folds=n_folds, trgt=all_trgt,
def setTrainParameters(self, n_inits=1, hidden_activation='tanh', output_activation='linear', classifier_output_activation='softmax', n_epochs=300, n_folds=10, patience=30, batch_size=256, verbose=False, optmizerAlgorithm='Adam', metrics=['accuracy'], loss='mean_squared_error', norm='mapstd', train_verbose=False, learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, learning_decay=1e-6, momentum=0.3, nesterov=True): self.trn_params = TrainParameters.SAENoveltyDetectionTrnParams( n_inits=n_inits, folds=n_folds, hidden_activation= hidden_activation, # others tanh, relu, sigmoid, linear output_activation=output_activation, classifier_output_activation=classifier_output_activation, n_epochs=n_epochs, patience=patience, batch_size=batch_size, verbose=verbose, optmizerAlgorithm=optmizerAlgorithm, metrics=metrics, #mean_squared_error loss=loss, #kullback_leibler_divergence norm=norm, train_verbose=train_verbose, learning_rate=learning_rate, beta_1=beta_1, beta_2=beta_2, epsilon=epsilon, learning_decay=learning_decay, momentum=momentum, nesterov=nesterov) self.modelPath = self.trn_params.getModelPath() self.baseResultsPath = self.getBaseResultsPath() self.trn_params_file = os.path.join(self.baseResultsPath, "trnparams.jbl") if not os.path.exists(self.trn_params_file): self.trn_params.save(self.trn_params_file) self.trn_params.save( os.path.join(self.RESULTS_PATH, self.analysis_name, "trnparams.jbl")) # Choose how many fold to be used in Cross Validation self.CVO = TrainParameters.NoveltyDetectionFolds( folder=self.RESULTS_PATH, n_folds=n_folds, trgt=self.all_trgt, dev=self.development_flag, verbose=True)
# turn targets in sparse mode from keras.utils import np_utils trgt_sparse = np_utils.to_categorical(all_trgt.astype(int)) # Load train parameters analysis_str = 'StackedAutoEncoder' model_prefix_str = 'RawData' trn_params_folder = '%s/%s/%s_trnparams.jbl' % (results_path, analysis_str, analysis_name) os.remove(trn_params_folder) if not os.path.exists(trn_params_folder): trn_params = trnparams.NeuralClassificationTrnParams( n_inits=1, hidden_activation='tanh', # others tanh, relu, sigmoid, linear output_activation='linear', n_epochs=50, #500 patience=10, #30 batch_size=4, #256 verbose=False) trn_params.save(trn_params_folder) else: trn_params = trnparams.NeuralClassificationTrnParams() trn_params.load(trn_params_folder) # Choose how many fold to be used in Cross Validation n_folds = 2 CVO = trnparams.ClassificationFolds(folder=results_path, n_folds=2, trgt=all_trgt, dev=development_flag, verbose=True)