Ejemplo n.º 1
0
 model_filename = \
     os.path.join(output_dir, 'models',
                  '%s_%s_exp%d_bs%d_nep%d_nla%d_nno%d_'
                  % (survival_estimator_name, dataset,
                     experiment_idx, batch_size, n_epochs,
                     n_layers, n_nodes)
                  +
                  'lr%f_nd%d_cv%d.pt'
                  % (lr, num_durations, cross_val_idx))
 time_elapsed_filename = model_filename[:-3] + '_time.txt'
 if not os.path.isfile(model_filename):
     print('*** Fitting with hyperparam:', hyperparam,
           '-- cross val index:', cross_val_idx, flush=True)
     if num_durations > 0:
         surv_model.fit(fold_X_train_std,
                        fold_y_train_discrete,
                        batch_size, n_epochs, verbose=False)
     else:
         surv_model.fit(fold_X_train_std,
                        (fold_y_train[:, 0],
                         fold_y_train[:, 1]), batch_size,
                        n_epochs, verbose=False)
     elapsed = time.time() - tic
     print('Time elapsed: %f second(s)' % elapsed)
     np.savetxt(time_elapsed_filename,
                np.array(elapsed).reshape(1, -1))
     surv_model.save_net(model_filename)
 else:
     print('*** Loading ***', flush=True)
     surv_model.load_net(model_filename)
     elapsed = float(np.loadtxt(time_elapsed_filename))
Ejemplo n.º 2
0
    y_train_discrete = labtrans.fit_transform(*y_train.T)
    surv_model = NKSDiscrete(net, optimizer,
                             duration_index=labtrans.cuts)
else:
    surv_model = NKS(net, optimizer)

model_filename = \
    os.path.join(output_dir, 'models',
                 '%s_%s_exp%d_bs%d_nep%d_nla%d_nno%d_lr%f_nd%d_test.pt'
                 % (survival_estimator_name, dataset, experiment_idx,
                    batch_size, n_epochs, n_layers, n_nodes, lr, num_durations))
assert os.path.isfile(model_filename)
if not os.path.isfile(model_filename):
    print('*** Fitting with hyperparam:', hyperparam, flush=True)
    if num_durations > 0:
        surv_model.fit(X_train_std, y_train_discrete,
                       batch_size, n_epochs, verbose=True)
    else:
        surv_model.fit(X_train_std, (y_train[:, 0], y_train[:, 1]),
                       batch_size, n_epochs, verbose=True)
    surv_model.save_net(model_filename)
else:
    print('*** Loading ***', flush=True)
    surv_model.load_net(model_filename)

if num_durations > 0:
    surv_df = surv_model.interpolate(10).predict_surv_df(X_test_std)
else:
    surv_df = surv_model.predict_surv_df(X_test_std)
surv = surv_df.to_numpy().T

print()
Ejemplo n.º 3
0
                  'lr%f_nd%d_fold%d.pt'
                  % (lr, num_durations, fold_idx))
 time_elapsed_filename = model_filename[:-3] + '_time.txt'
 if not os.path.isfile(model_filename):
     if use_cross_val:
         print('*** Fitting with hyperparam:', hyperparam,
               '-- cross val index:', fold_idx, flush=True)
     else:
         print('*** Fitting with hyperparam:', hyperparam,
               flush=True)
     if num_durations > 0:
         if use_early_stopping and not use_cross_val:
             surv_model.fit(fold_X_train_std,
                            fold_y_train_discrete,
                            batch_size, n_epochs,
                            [tt.callbacks.EarlyStopping()],
                            val_data=(fold_X_val_std,
                                      fold_y_val_discrete),
                            verbose=False)
         else:
             surv_model.fit(fold_X_train_std,
                            fold_y_train_discrete,
                            batch_size, n_epochs,
                            verbose=False)
     else:
         if use_early_stopping and not use_cross_val:
             surv_model.fit(fold_X_train_std,
                            (fold_y_train[:, 0],
                             fold_y_train[:, 1]), batch_size,
                            n_epochs,
                            [tt.callbacks.EarlyStopping()],