def main_standard(dataset, subject, model, params, exp, eval_set, ph):
    printd(dataset, subject, model, params, exp, eval_set, ph)

    # retrieve model's parameters
    params = locate_params(params)
    model_class = locate_model(model)

    # scale variables in minutes to the benchmark sampling frequency
    ph_f = ph // cs.freq
    hist_f = params["hist"] // cs.freq
    day_len_f = cs.day_len // cs.freq
    """ PREPROCESSING """
    train, valid, test, scalers = preprocessing(dataset, subject, ph_f, hist_f,
                                                day_len_f)
    """ MODEL TRAINING """
    raw_results = make_predictions_pclstm(subject,
                                          model_class,
                                          params,
                                          ph_f,
                                          train,
                                          valid,
                                          test,
                                          scalers,
                                          mode=eval_set)
    """ POST-PROCESSING """
    raw_results = postprocessing(raw_results, scalers, dataset)
    """ EVALUATION """
    ResultsSubject(model,
                   exp,
                   ph,
                   dataset,
                   subject,
                   params=params,
                   results=raw_results).save_raw_results()
示例#2
0
def study(dataset, model, params, mode, ph, all_feat, patients, combs):
    # retrieve model's parameters
    params = locate_params(params)
    model_class = locate_model(model)

    # scale variables in minutes to the benchmark sampling frequency
    ph_f = ph // cs.freq
    hist_f = params["hist"] // cs.freq
    day_len_f = cs.day_len // cs.freq

    # full processing
    for i in patients:
        dir = os.path.join(cs.path, "study", dataset, model, mode,
                           "patient " + str(i))
        """ PREPROCESSING ALL FEATURES"""
        printd("Preprocessing patient " + str(i))
        data = preprocessing_full(dataset, str(i), ph_f, hist_f, day_len_f,
                                  all_feat)

        for ele in combs:
            printd("Preprocessing patient", str(i),
                   "with features glucose " + " + ".join(ele))
            train, valid, test, scalers = preprocessing_select(
                data, dataset, day_len_f, all_feat, ele)

            for j in range(5):
                torch.manual_seed(j)
                """ MODEL TRAINING & TUNING """
                if not ele:
                    file = os.path.join(dir, "reference", "seed " + str(j),
                                        "weights", "weights")
                else:
                    file = os.path.join(dir, " + ".join(ele), "seed " + str(j),
                                        "weights", "weights")
                raw_results = make_predictions(str(i),
                                               model_class,
                                               params,
                                               ph_f,
                                               train,
                                               valid,
                                               test,
                                               mode=mode,
                                               save_model_file=file)
                """ POST-PROCESSING """
                raw_results = postprocessing(raw_results, scalers, dataset)
                """ EVALUATION """
                if not ele:
                    file_save = os.path.join("reference", "seed " + str(j))
                else:
                    file_save = os.path.join(" + ".join(ele), "seed " + str(j))
                results = ResultsSubject(model,
                                         file_save,
                                         ph,
                                         dataset,
                                         str(i),
                                         params=params,
                                         results=raw_results,
                                         study=True,
                                         mode=mode)
                printd(results.compute_mean_std_results())
示例#3
0
文件: main.py 项目: dotXem/GLYFE
def main(dataset, subject, model, params, exp, mode, log, ph, plot):
    printd(dataset, subject, model, params, exp, mode, log, ph, plot)

    # retrieve model's parameters
    search = locate_search(params)
    params = locate_params(params)
    model_class = locate_model(model)

    # scale variables in minutes to the benchmark sampling frequency
    ph_f = ph // cs.freq
    hist_f = params["hist"] // cs.freq
    day_len_f = cs.day_len // cs.freq

    """ PREPROCESSING """
    train, valid, test, scalers = preprocessing(dataset, subject, ph_f, hist_f, day_len_f)
    """ MODEL TRAINING & TUNING """
    if search:
        params = find_best_hyperparameters(subject, model_class, params, search, ph_f, train, valid, test)

    raw_results = make_predictions(subject, model_class, params, ph_f, train, valid, test, mode=mode)
    """ POST-PROCESSING """
    raw_results = postprocessing(raw_results, scalers, dataset)

    """ EVALUATION """
    results = ResultsSubject(model, exp, ph, dataset, subject, params=params, results=raw_results)
    printd(results.compute_results())
    if plot:
        results.plot(0)
def main_cgega_iterative_training(dataset,
                                  subject,
                                  model,
                                  params1,
                                  params2,
                                  exp,
                                  eval_set,
                                  ph,
                                  save_iter=False):
    printd(dataset, subject, model, params1, params2, exp, eval_set, ph)

    # retrieve model's parameters
    params1 = locate_params(params1)
    params2 = locate_params(params2)
    model_class = locate_model(model)

    # scale variables in minutes to the benchmark sampling frequency
    ph_f = ph // cs.freq
    hist_f = params1["hist"] // cs.freq
    day_len_f = cs.day_len // cs.freq
    freq_ds = misc.datasets.datasets[dataset]["glucose_freq"]
    """ PREPROCESSING """
    train, valid, test, scalers = preprocessing(dataset, subject, ph_f, hist_f,
                                                day_len_f)
    """ MODEL TRAINING """
    dir = join(cs.path, "processing", "models", "weights", "cg_ega")
    file = join(dir, exp, model_class.__name__ + "_" + dataset + subject)

    results_test, results_valid_iter = progressive_improvement_clinical_acceptability(
        subject, model_class, params1, params2, ph, freq_ds, train, valid,
        test, scalers, file, eval_set)

    results_test = postprocessing(results_test, scalers, dataset)
    results_valid_iter = postprocessing_all_iter(results_valid_iter, scalers,
                                                 dataset)

    ResultsSubject(model,
                   exp,
                   ph,
                   dataset,
                   subject,
                   params=[params1, params2],
                   results=results_test).save_raw_results()
    if save_iter:
        ResultsSubjectPICA(model,
                           exp,
                           ph,
                           dataset,
                           subject,
                           params=[params1, params2],
                           results=results_valid_iter).save_raw_results()
示例#5
0
def evaluation(raw_results, scalers, source_dataset, target_dataset, target_subject, model, params, exp, plot, tl_mode):
    raw_results = postprocessing(raw_results, scalers, target_dataset)

    exp += "_" + tl_mode.split("_")[1]
    exp = os.path.join(source_dataset + "_2_" + target_dataset, exp)
    results = ResultsSubject(model.__name__, exp, ph, target_dataset, target_subject, params=params,
                             results=raw_results)

    res_mean = results.compute_mean_std_results()
    printd(res_mean)
    if plot:
        results.plot(0)

    return res_mean
示例#6
0
def main(dataset,
         subject,
         model,
         params,
         exp,
         mode,
         log,
         ph,
         plot,
         save=False):
    printd(dataset, subject, model, params, exp, mode, log, ph, plot)

    # retrieve model's parameters
    search = locate_search(params)
    params = locate_params(params)
    model_class = locate_model(model)

    # scale variables in minutes to the benchmark sampling frequency
    ph_f = ph // cs.freq
    hist_f = params["hist"] // cs.freq
    day_len_f = cs.day_len // cs.freq
    """ PREPROCESSING """
    train, valid, test, scalers = preprocessing(dataset, subject, ph_f, hist_f,
                                                day_len_f)
    start = time.time()
    """ MODEL TRAINING & TUNING """
    if search:
        params = find_best_hyperparameters(subject, model_class, params,
                                           search, ph_f, train, valid, test)

    if save:
        dir = os.path.join(cs.path, "processing", "models", "weights",
                           model_class.__name__, exp)
        file = os.path.join(dir,
                            model_class.__name__ + "_" + dataset + subject)
    else:
        file = None

    raw_results = make_predictions(subject,
                                   model_class,
                                   params,
                                   ph_f,
                                   train,
                                   valid,
                                   test,
                                   mode=mode,
                                   save_model_file=file)
    """ POST-PROCESSING """
    raw_results = postprocessing(raw_results, scalers, dataset)
    """ EVALUATION """
    results = ResultsSubject(model,
                             exp,
                             ph,
                             dataset,
                             subject,
                             params=params,
                             results=raw_results)
    printd(results.compute_mean_std_results())
    end = time.time()
    printd("Time elapsed : " + str(end - start) + " seconds")
    if plot:
        results.plot(0)
示例#7
0
文件: main.py 项目: Owaisaaa/pcLSTM
def main(dataset,
         subject,
         Model,
         params,
         ph,
         eval="valid",
         print=True,
         plot=False,
         save=True,
         excel_file=None):
    printd(dataset, subject, Model.__name__)

    file = os.path.join("data", "dynavolt", dataset,
                        dataset + "_subject" + subject + ".csv")
    """ PREPROCESSING """
    train_sets, valid_sets, test_sets, norm_min, norm_max = preprocessing(
        file, misc.hist, ph, misc.freq, misc.cv)

    # TODO REMOVE - one split testing
    # split_number = 7
    # train_sets, valid_sets, test_sets = [train_sets[split_number]], [valid_sets[split_number]], [
    #     test_sets[split_number]]
    # norm_min, norm_max = [norm_min[split_number]],[norm_max[split_number]]
    """ CROSS-VALIDATION """
    results = []
    for i, [train, valid,
            test] in enumerate(zip(train_sets, valid_sets, test_sets)):
        train_x, train_y = train.iloc[:, :-2], train.iloc[:, -2:]
        valid_x, valid_y = valid.iloc[:, :-2], valid.iloc[:, -2:]
        test_x, test_y = test.iloc[:, :-2], test.iloc[:, -2:]

        model = Model(params)
        if Model.__name__ in misc.nn_models:
            model.fit(x_train=train_x,
                      y_train=train_y,
                      x_valid=valid_x,
                      y_valid=valid_y)
        else:
            model.fit(x=train_x, y=train_y)

        if eval == "valid":
            y_true, y_pred = model.predict(x=valid_x, y=valid_y)
        elif eval == "test":
            y_true, y_pred = model.predict(x=test_x, y=test_y)
        results.append(np.c_[y_true, y_pred])
    """ POST-PROCESSING """
    results = postprocessing(results.copy(),
                             hist=misc.hist,
                             ph=misc.ph,
                             freq=misc.freq,
                             min=norm_min,
                             max=norm_max)
    """ EVALUATION """
    res = Results(Model.__name__,
                  misc.ph,
                  dataset,
                  subject,
                  misc.freq,
                  results=np.array(results))
    metrics = res.get_results()
    if print: printd(metrics)
    if save: res.save()
    if plot: res.plot()
    if excel_file is not None:
        res.to_excel(params, len(res.results), file_name=excel_file)