def train(hparams): # init exp and track all the parameters from the HyperOptArgumentParser exp = Experiment(name='dense_model', save_dir='/some/path', autosave=False) exp.add_argparse_meta(hparams) # define tensorflow graph x = tf.placeholder(dtype=tf.int32, name='x') y = tf.placeholder(dtype=tf.int32, name='y') out = x * y sess = tf.Session() # Run the tf op for train_step in range(0, 100): output = sess.run(out, feed_dict={x: hparams.x_val, y: hparams.y_val}) exp.add_metric_row({'fake_err': output}) # save exp when we're done exp.save()
def main_trainer(hparams): print_params(hparams) exp = Experiment(name=hparams.tt_name, debug=hparams.debug, autosave=False, description=hparams.tt_description, save_dir=hparams.tt_save_path) exp.add_argparse_meta(hparams) # fit model val_scores = [] best_score = 0 for trial_nb in range(hparams.nb_trials): data = dataset_loader.IndividualSequencesData( hparams.data_path, y_labels=hparams.y_labels.split(',')) X, Y, lengths = flatten_data(data.train_x_y) # fit model = hmm.GaussianHMM(n_components=hparams.nb_components, n_iter=hparams.nb_hmm_iters) model.fit(X, lengths) val_X, val_Y, lengths = flatten_data(data.val_x_y) Y_hat = model.predict(val_X, lengths) val_score = np.equal(Y_hat, val_Y).sum() / float(len(Y_hat)) # save model if val_score > best_score: best_score = val_score save_model(model, hparams, exp, trial_nb) val_scores.append(val_score) exp.add_metric_row({'val_acc': val_score, 'trail_nb': trial_nb}) mean_val_acc = np.mean(val_scores) exp.add_metric_row({'final_val_acc': mean_val_acc}) exp.save()
def main_trainer(hparams): print_params(hparams) exp = Experiment(name=hparams.tt_name, debug=hparams.debug, autosave=False, description=hparams.tt_description, save_dir=hparams.tt_save_path) exp.add_argparse_meta(hparams) # init data loader # fit model val_scores, train_scores = [], [] best_score = 0 for trial_nb in range(hparams.nb_trials): data = SequentialReadingsData(window_size=hparams.time_steps, data_path=hparams.data_path, flatten_x=True) clf = RandomForestClassifier(n_estimators=hparams.nb_estimators) clf.fit(data.train_x, data.train_y) train_score = clf.score(data.train_x, data.train_y) val_score = clf.score(data.val_x, data.val_y) # save model when we have a better one if val_score > best_score: best_score = val_score save_model(clf, hparams, exp, trial_nb) train_scores.append(train_score) val_scores.append(val_score) exp.add_metric_row({'val_acc': val_score, 'train_acc': train_score, 'trail_nb': trial_nb}) mean_val_acc = np.mean(val_scores) mean_train_acc = np.mean(train_scores) exp.add_metric_row({'final_val_acc': mean_val_acc, 'final_train_acc': mean_train_acc}) exp.save()
def main_trainer(hparams): print_params(hparams) full_exp = Experiment(name=hparams.tt_name + '_overall', debug=hparams.debug, autosave=False, description=hparams.tt_description, save_dir=hparams.tt_save_path) full_exp.add_argparse_meta(hparams) # fit model val_scores, train_scores = [], [] best_acc = 0 best_loss = 0 best_trial_nb = 0 for trial_nb in range(hparams.nb_trials): exp = Experiment(name=hparams.tt_name, debug=hparams.debug, autosave=False, description=hparams.tt_description, save_dir=hparams.tt_save_path) exp.add_argparse_meta(hparams) data = SequentialReadingsData(window_size=hparams.time_steps, data_path=hparams.data_path) val_loss, val_acc, history = fit_feedforward(hparams, exp, trial_nb, data) log_history(history.history, exp) exp.add_metric_row({ 'final_val_acc': val_acc, 'final_train_acc': val_loss }) exp.save() full_exp.add_metric_row({ 'val_acc': val_acc, 'val_loss': val_loss, 'trial_nb': trial_nb }) # save model when we have a better one if val_acc > best_acc: best_acc = val_acc best_loss = val_loss best_trial_nb = trial_nb val_scores.append(val_acc) mean_val_acc = np.mean(val_scores) full_exp.add_metric_row({ 'final_val_acc': mean_val_acc, 'best_val_loss': best_loss, 'best_val_acc': best_acc, 'best_trial_nb': best_trial_nb }) full_exp.save()
parser.add_opt_argument_range( "--noise_factor", default=1, type=float, start=0, end=1, nb_samples=5 ) hparams = parser.parse_args() env = gym.make("Pendulum-v0") state_size = int(np.prod(env.observation_space.shape)) action_size = int(np.prod(env.action_space.shape)) S, A = state_size, action_size H = hparams.hidden_size exp.add_metric_row({"S": state_size, "A": action_size, "H": hparams.hidden_size}) class Critic(nn.Module): def __init__(self): super().__init__() self.fc1 = Linear(S + A, H) self.fc2 = Linear(H, H) self.out = Linear(H, 1) def forward(self, s, a): q = torch.cat((s, a), dim=1) q = relu(self.fc1(q)) q = relu(self.fc2(q)) q = self.out(q) return q