示例#1
0
def features_gsa(write_dir, model_dir, fl_loader_file, N):
    problem = {
        'num_vars': 4,
        'names': ['', '', '', ''],
        'bounds': [[0, 1], [0, 1], [200, 2000], [0, 1]],
    }
    param_values = saltelli.sample(problem, N, calc_second_order=True)

    param_values = param_values[param_values[:, 0] + param_values[:, 1] <= 1]

    features_c = param_values[:, :-1]
    onehot = param_values[:, -1]
    onehot_store = []
    for single in onehot:
        if single <= 1 / 3:
            onehot_store.append([1, 0, 0])
        elif single <= 2 / 3:
            onehot_store.append([0, 1, 0])
        else:
            onehot_store.append([0, 0, 1])
    features = np.concatenate((features_c, np.array(onehot_store)), axis=1)

    fl = load_data_to_fl(fl_loader_file,
                         norm_mask=[0, 1, 3, 4, 5],
                         normalise_labels=False,
                         label_type='cutoff')
    features_input_norm = fl.apply_scaling(features)

    model_store = load_model_ensemble(model_dir)
    outputs = model_ensemble_prediction(model_store, features_input_norm)

    si_output = sobol.analyze(problem,
                              outputs,
                              calc_second_order=True,
                              print_to_console=True)

    print('pass')
示例#2
0
def run_skf_with_te(inputs_store, loader_excel, smote_numel, mode, name, learningrate=0.001, eval_model_dir=None):
    write_dir = create_results_directory('./results/{}'.format(name),
                                         folders=['plots', 'models', 'learning rate plots'],
                                         excels=['skf_results', 'te.xlsx'])
    data_store = []
    loss = 'mse'
    if eval_model_dir:
        inputs_store = load_model_ensemble(eval_model_dir)

    for inputs in inputs_store:
        fl = load_data_to_fl(loader_excel,
                             label_type='cutoff',
                             normalise_labels=False,
                             norm_mask=[0, 1, 3, 4, 5])

        test_excel_dir = './excel/ett_30testset_cut.xlsx'
        ett_store = ['./excel/ett_30testset_cut Invariant 1.xlsx',
                     './excel/ett_30testset_cut Invariant 1 - 2.xlsx',
                     './excel/ett_30testset_cut Invariant 1 - 3.xlsx',
                     './excel/ett_30testset_cut Invariant 5.xlsx',
                     './excel/ett_30testset_cut Invariant 5 - 2.xlsx',
                     './excel/ett_30testset_cut Invariant 5 - 3.xlsx',
                     './excel/ett_30testset_cut Invariant 10.xlsx',
                     './excel/ett_30testset_cut Invariant 10 - 2.xlsx',
                     './excel/ett_30testset_cut Invariant 10 - 3.xlsx',
                     './excel/ett_30testset_cut Invariant 30.xlsx',
                     './excel/ett_30testset_cut Invariant 30 - 2.xlsx',
                     './excel/ett_30testset_cut Invariant 30 - 3.xlsx',
                     './excel/ett_30testset_cut Invariant 50.xlsx',
                     './excel/ett_30testset_cut Invariant 50 - 2.xlsx',
                     './excel/ett_30testset_cut Invariant 50 - 3.xlsx',
                     './excel/ett_125trainset_cut.xlsx',
                     './excel/ett_125trainset_cut Invariant 1.xlsx',
                     './excel/ett_125trainset_cut Invariant 5.xlsx',
                     './excel/ett_125trainset_cut Invariant 10.xlsx']

        test_fl = load_testset_to_fl(test_excel_dir, scaler=fl.scaler, norm_mask=[0, 1, 3, 4, 5])
        ett_fl_store = [load_testset_to_fl(x, scaler=fl.scaler, norm_mask=[0, 1, 3, 4, 5]) for x in ett_store]

        if smote_numel:
            fl_store = fl.fold_smote_kf_augment(k_folds=10, shuffle=True, numel=smote_numel)
        else:
            fl_store = fl.create_kf(k_folds=10, shuffle=True)

        if eval_model_dir:
            val_score, train_score, data = run_eval_model_on_train_val_test_error(fl=fl,
                                                                                  fl_store=fl_store, test_fl=test_fl,
                                                                                  ett_fl_store=ett_fl_store,
                                                                                  model_name='hparams_opt_makeup',
                                                                                  model=inputs, )
        else:
            pre, epochs = inputs
            hparams = create_hparams(shared_layers=[30, 30], ts_layers=[5, 5], cs_layers=[5, 5],
                                     learning_rate=learningrate,
                                     shared=0, end=0, pre=pre, filters=0, epochs=epochs,
                                     reg_l1=0.0005, reg_l2=0, loss=loss,
                                     max_depth=pre, num_est=epochs,
                                     epsilon=0.0001, c=0.001,
                                     activation='relu', batch_size=16, verbose=0)

            if mode == 'ann':
                model_mode = 'ann3'
                loss_mode = 'ann'
            elif mode == 'dtr':
                model_mode = 'dtr'
                loss_mode = 'dtr'

            val_score, train_score, data = run_skf_train_val_test_error(model_mode=model_mode, loss_mode=loss_mode,
                                                                        fl=fl,
                                                                        fl_store=fl_store, test_fl=test_fl,
                                                                        ett_fl_store=ett_fl_store,
                                                                        model_name='{}_{}_{}_{}'.format(write_dir,
                                                                                                        model_mode, pre,
                                                                                                        epochs),
                                                                        hparams=hparams,
                                                                        k_folds=10, scoring='mse',
                                                                        save_model_name='/{}_{}_{}'.format(mode, pre,
                                                                                                           epochs),
                                                                        save_model=True,
                                                                        save_model_dir=write_dir + '/models',
                                                                        plot_name='{}/{}'.format(write_dir,
                                                                                                 str(inputs)))
        ett_names = ['I01-1', 'I01-2', 'I01-3',
                     'I05-1', 'I05-2', 'I05-3',
                     'I10-1', 'I10-2', 'I10-3',
                     'I30-1', 'I30-2', 'I30-3',
                     'I50-1', 'I50-2', 'I50-3',
                     '125Test', '125Test I01', '125Test I05', '125Test I10']
        if eval_model_dir:
            data.append([1, 1])
        else:
            data.append([pre, epochs])
        data_store.append(data)
        with open('{}/data_store.pkl'.format(write_dir), "wb") as file:
            pickle.dump(data_store, file)
    read_hparam_data(data_store=data_store, write_dir=write_dir, ett_names=ett_names, print_s_df=False,
                     trainset_ett_idx=-4)
示例#3
0
def eval_models(model_directory_store, results_dir):
    model_store = []
    for model_directory in model_directory_store:
        model_store.extend(load_model_ensemble(model_directory))

    test_excel_dir = './excel/ett_30testset_cut.xlsx'
    ett_names = [
        'I01-1', 'I01-2', 'I01-3', 'I05-1', 'I05-2', 'I05-3', 'I10-1', 'I10-2',
        'I10-3', 'I30-1', 'I30-2', 'I30-3', 'I50-1', 'I50-2', 'I50-3',
        '125Test', '125Test I01', '125Test I05', '125Test I10'
    ]
    ett_store = [
        './excel/ett_30testset_cut Invariant 1.xlsx',
        './excel/ett_30testset_cut Invariant 1 - 2.xlsx',
        './excel/ett_30testset_cut Invariant 1 - 3.xlsx',
        './excel/ett_30testset_cut Invariant 5.xlsx',
        './excel/ett_30testset_cut Invariant 5 - 2.xlsx',
        './excel/ett_30testset_cut Invariant 5 - 3.xlsx',
        './excel/ett_30testset_cut Invariant 10.xlsx',
        './excel/ett_30testset_cut Invariant 10 - 2.xlsx',
        './excel/ett_30testset_cut Invariant 10 - 3.xlsx',
        './excel/ett_30testset_cut Invariant 30.xlsx',
        './excel/ett_30testset_cut Invariant 30 - 2.xlsx',
        './excel/ett_30testset_cut Invariant 30 - 3.xlsx',
        './excel/ett_30testset_cut Invariant 50.xlsx',
        './excel/ett_30testset_cut Invariant 50 - 2.xlsx',
        './excel/ett_30testset_cut Invariant 50 - 3.xlsx',
        './excel/ett_125trainset_cut.xlsx',
        './excel/ett_125trainset_cut Invariant 1.xlsx',
        './excel/ett_125trainset_cut Invariant 5.xlsx',
        './excel/ett_125trainset_cut Invariant 10.xlsx'
    ]

    fl = load_data_to_fl(
        './excel/Data_loader_spline_full_onehot_R13_cut_CM3.xlsx',
        label_type='cutoff',
        normalise_labels=False,
        norm_mask=[0, 1, 3, 4, 5])
    test_fl = load_testset_to_fl(test_excel_dir,
                                 scaler=fl.scaler,
                                 norm_mask=[0, 1, 3, 4, 5])
    ett_fl_store = [
        load_testset_to_fl(x, scaler=fl.scaler, norm_mask=[0, 1, 3, 4, 5])
        for x in ett_store
    ]

    ytt = test_fl.labels
    yett_store = [ett_fl.labels for ett_fl in ett_fl_store]

    stt_p_y_store = []
    stt_df_store = []
    stt_mse_store = []
    stt_mre_store = []

    sett_p_y_store = []
    sett_df_store = []
    sett_mse_store = []
    sett_mre_store = []

    for model in model_store:
        stt_p_y, stt_df, stt_mse, stt_mre = eval_model_on_fl(model,
                                                             test_fl,
                                                             return_df=True)
        stt_p_y_store.append(stt_p_y)
        stt_df_store.append(stt_df)
        stt_mse_store.append(stt_mse)
        stt_mre_store.append(stt_mre)

        p_y_store = []
        df_store = []
        mse_store = []
        mre_store = []

        for ett_fl in ett_fl_store:
            p_y, df, mse, mre = eval_model_on_fl(model, ett_fl, return_df=True)
            p_y_store.append(p_y)
            df_store.append(df)
            mse_store.append(mse)
            mre_store.append(mre)

        sett_p_y_store.append(p_y_store)
        sett_df_store.append(df_store)
        sett_mse_store.append(mse_store)
        sett_mre_store.append(mre_store)

    p_ytt_selected_mean = np.mean(np.array(stt_p_y_store), axis=0)
    p_yett_store_selected_mean = [
        np.mean(np.array(p_yett), axis=0)
        for p_yett in [list(x) for x in zip(*sett_p_y_store)]
    ]

    def get_mse_re(y, p_y):
        return np.mean((y - p_y)**2), np.mean(np.abs(y - p_y).T / y[:, -1].T)

    mse_tt, re_tt = get_mse_re(ytt, p_ytt_selected_mean)
    mse_re_ett_store = [
        get_mse_re(yett, p_yett)
        for yett, p_yett in zip(yett_store, p_yett_store_selected_mean)
    ]

    var_ett = []
    idx_store = [
        1, 1, 1, 5, 5, 5, 10, 10, 10, 30, 30, 30, 50, 50, 50, 0, 1, 5, 10
    ]

    for idx, (invariant,
              p_y) in enumerate(zip(idx_store, p_yett_store_selected_mean)):
        if invariant == 0:
            var_ett.append(0)
        else:
            if idx < 15:
                base_numel = 30
            else:
                base_numel = 125
            var_ett.append(
                np.mean([
                    np.std(np.concatenate(
                        (p_y[i:i + 1, :],
                         p_y[base_numel + invariant * i:base_numel +
                             invariant * i + invariant, :]),
                        axis=0),
                           axis=0) for i in range(base_numel)
                ]))

    # Printing to excel
    excel_name = results_dir + '/results.xlsx'
    wb = openpyxl.Workbook()
    wb.create_sheet('main')

    def print_results(name, y, p_y, mse, re):
        nonlocal wb
        wb.create_sheet(name)
        ws = wb[name]
        df = pd.DataFrame(np.concatenate((y, p_y), axis=1),
                          columns=['y1', 'y2', 'y3', 'P_y1', 'P_y2', 'P_y3'])
        print_df_to_excel(df=df, ws=ws)
        start_col = len(df.columns) + 3
        ws.cell(1, start_col).value = 'MSE'
        ws.cell(2, start_col).value = 'HE'
        ws.cell(1, start_col + 1).value = mse
        ws.cell(2, start_col + 1).value = re

    print_results('Test', ytt, p_ytt_selected_mean, mse_tt, re_tt)
    [
        print_results(name, yett_store[idx], p_yett_store_selected_mean[idx],
                      mse_re[0], mse_re[1]) for name, idx, mse_re in zip(
                          ett_names, range(len(yett_store)), mse_re_ett_store)
    ]

    df = pd.DataFrame(data=[[mse_tt] + [x[0] for x in mse_re_ett_store],
                            [re_tt] + [x[1] for x in mse_re_ett_store],
                            [0] + var_ett],
                      columns=['Test'] + ett_names,
                      index=['MSE', 'HE', 'Var'])

    print_df_to_excel(df=df, ws=wb['main'], start_row=5)
    wb.save(excel_name)
示例#4
0
def inverse_design(targets, loss_func, bounds, int_idx, init_guess,
                   model_directory_store, svm_directory, loader_file,
                   write_dir, opt_mode):
    model_store = []
    for model_directory in model_directory_store:
        model_store.extend(load_model_ensemble(model_directory))
    svm_store = load_svm_ensemble(svm_directory)
    fl = load_data_to_fl(loader_file,
                         norm_mask=[0, 1, 3, 4, 5],
                         normalise_labels=False,
                         label_type='cutoff')

    data_store = []
    if opt_mode == 'psoga':

        def fitness(params):
            nonlocal data_store
            features = np.array(params)
            x = features[0]
            y = features[1]
            if x + y > 1:
                u = -y + 1
                v = -x + 1
                features[0:2] = np.array([u, v])

            # SVM Check
            p_class, distance = svm_ensemble_prediction(
                svm_store, features[0:2])

            if distance.item() < 0:
                # Distance should be negative value when SVM assigns class 0. Hence a_score will be negative.
                # The more negative the a_score is, the further the composition is from the hyperplane,
                # hence, the less likely the optimizer will select examples with class 0.
                mse = 10e5 * distance.item()
                prediction_mean = [-1] * fl.labels_dim
                prediction_std = [-1] * fl.labels_dim
                disagreement = -1
            elif features[0] + features[1] > 1:
                # Distance should be negative value when SVM assigns class 0. Hence a_score will be negative.
                # The more negative the a_score is, the further the composition is from the hyperplane,
                # hence, the less likely the optimizer will select examples with class 0.
                mse = 10e5 * (1 - (features[0] + features[1]))
                prediction_mean = [-1] * fl.labels_dim
                prediction_std = [-1] * fl.labels_dim
                disagreement = -1
            else:
                features_c = features[:-1]
                onehot = features[-1].item()
                if onehot == 0:
                    features_in = np.concatenate(
                        (features_c, np.array([1, 0, 0])))
                elif onehot == 1:
                    features_in = np.concatenate(
                        (features_c, np.array([0, 1, 0])))
                elif onehot == 2:
                    features_in = np.concatenate(
                        (features_c, np.array([0, 0, 1])))
                features_input_norm = fl.apply_scaling(features_in)
                prediction_mean, prediction_std = model_ensemble_prediction(
                    model_store, features_input_norm)
                mse = -loss_func(targets, prediction_mean)
                disagreement = np.mean(prediction_std)
                prediction_mean = prediction_mean.tolist()
                prediction_std = prediction_std.tolist()

            data = list(features) + [-mse, disagreement
                                     ] + prediction_mean + prediction_std
            data_store.append(data)
            return (-mse, )

        pmin = [x[0] for x in bounds]
        pmax = [x[1] for x in bounds]

        smin = [abs(x - y) * 0.001 for x, y in zip(pmin, pmax)]
        smax = [abs(x - y) * 0.5 for x, y in zip(pmin, pmax)]

        pso_params = {
            'c1': 1.5,
            'c2': 1.5,
            'wmin': 0.4,
            'wmax': 0.9,
            'ga_iter_min': 2,
            'ga_iter_max': 10,
            'iter_gamma': 10,
            'ga_num_min': 5,
            'ga_num_max': 20,
            'num_beta': 15,
            'tourn_size': 3,
            'cxpd': 0.9,
            'mutpd': 0.05,
            'indpd': 0.5,
            'eta': 0.5,
            'pso_iter': 10,
            'swarm_size': 300
        }

        pso_ga(func=fitness,
               pmin=pmin,
               pmax=pmax,
               smin=smin,
               smax=smax,
               int_idx=[3],
               params=pso_params,
               ga=True,
               initial_guess=init_guess)

    elif opt_mode == 'forest' or opt_mode == 'dummy':
        space = [
            Real(low=bounds[0][0], high=bounds[0][1], name='CNT'),
            Real(low=bounds[1][0], high=bounds[1][1], name='PVA'),
            Real(low=bounds[2][0], high=bounds[2][1], name='Thickness'),
            Categorical(categories=[0, 1, 2], name='Dimension')
        ]

        iter_count = 0
        start = time.time()
        end = 0

        @use_named_args(space)
        def fitness(**params):
            nonlocal data_store, iter_count, start, end
            iter_count += 1
            features = np.array([x for x in params.values()])
            x = features[0]
            y = features[1]
            if x + y > 1:
                u = -y + 1
                v = -x + 1
                features[0:2] = np.array([u, v])
            # SVM Check
            p_class, distance = svm_ensemble_prediction(
                svm_store, features[0:2])
            if distance.item() < 0:
                # Distance should be negative value when SVM assigns class 0. Hence a_score will be negative.
                # The more negative the a_score is, the further the composition is from the hyperplane,
                # hence, the less likely the optimizer will select examples with class 0.
                mse = 10e5 * distance.item()
                prediction_mean = [-1] * fl.labels_dim
                prediction_std = [-1] * fl.labels_dim
                disagreement = -1
            elif features[0] + features[1] > 1:
                # Sum of composition needs to be less than 1
                mse = 10e5 * (1 - (features[0] + features[1]))
                prediction_mean = [-1] * fl.labels_dim
                prediction_std = [-1] * fl.labels_dim
                disagreement = -1
            else:
                features_c = features[:-1]
                onehot = features[-1].item()
                if onehot == 0:
                    features_in = np.concatenate(
                        (features_c, np.array([1, 0, 0])))
                elif onehot == 1:
                    features_in = np.concatenate(
                        (features_c, np.array([0, 1, 0])))
                elif onehot == 2:
                    features_in = np.concatenate(
                        (features_c, np.array([0, 0, 1])))
                features_input_norm = fl.apply_scaling(features_in)
                prediction_mean, prediction_std = model_ensemble_prediction(
                    model_store, features_input_norm)
                mse = -loss_func(targets,
                                 prediction_mean)  # Some negative number
                disagreement = np.mean(prediction_std)
                prediction_mean = prediction_mean.tolist()
                prediction_std = prediction_std.tolist()

            data = list(features) + [-mse, disagreement
                                     ] + prediction_mean + prediction_std
            data_store.append(data)
            if iter_count % 10 == 0:
                end = time.time()
                print(
                    'Current Iteration {}. Time taken for past 10 evals: {}. '.
                    format(iter_count, end - start))
                start = time.time()
            return -mse  # Make negative become positive, and minimizing score towards 0.

        if opt_mode == 'forest':
            forest_minimize(
                func=fitness,
                dimensions=space,
                acq_func='EI',  # Expected Improvement.
                n_calls=1000,
                verbose=False)
        else:
            dummy_minimize(func=fitness,
                           dimensions=space,
                           n_calls=5000,
                           verbose=False)

    p_mean_name = np.array(
        ['Pmean_' + str(x) for x in list(map(str, np.arange(1, 4)))])
    p_std_name = np.array(
        ['Pstd_' + str(x) for x in list(map(str, np.arange(1, 4)))])

    columns = np.concatenate(
        (np.array(fl.features_c_names[:-2]), np.array(['mse']),
         np.array(['Disagreement']), p_mean_name, p_std_name))

    iter_df = pd.DataFrame(data=data_store, columns=columns)

    iter_df = iter_df.sort_values(by=['mse'], ascending=True)

    excel_dir = create_excel_file('{}/inverse_design_{}_{}.xlsx'.format(
        write_dir, opt_mode, targets))
    wb = openpyxl.load_workbook(excel_dir)
    ws = wb[wb.sheetnames[
        -1]]  # Taking the ws name from the back ensures that if SNN1 is the new ws, it works
    ws.cell(1, 1).value = 'Target'
    print_array_to_excel(array=targets, first_cell=(1, 2), axis=1, ws=ws)
    print_df_to_excel(df=iter_df, ws=ws, start_row=3)

    wb.save(excel_dir)
    wb.close()
示例#5
0
def final_prediction_results(write_excel, model_dir_store,
                             combined_excel_store, rounds,
                             excel_loader_dir_store, fn, numel):
    wb = openpyxl.load_workbook(write_excel)
    results_col = fn + 1 + 1 + 2 * numel + 3
    mse_store = []
    mre_store = []
    mare_store = []
    final_excel_loader_dir = excel_loader_dir_store[-1]
    final_features = pd.read_excel(final_excel_loader_dir,
                                   sheet_name='features',
                                   index_col=0).sort_index().values
    final_df = pd.read_excel(final_excel_loader_dir,
                             sheet_name='cutoff',
                             index_col=0).sort_index()
    for idx, (model_dir, combined_excel, loader_excel, round) in enumerate(
            zip(model_dir_store, combined_excel_store, excel_loader_dir_store,
                rounds)):
        wb.create_sheet('Round {}'.format(round))
        ws = wb[wb.sheetnames[-1]]

        combined_df = pd.read_excel(combined_excel,
                                    sheet_name='Results',
                                    index_col=0).sort_index()
        numel_expt = combined_df.shape[0]
        total_expt = final_df.shape[0]

        y_store = combined_df.iloc[:, fn + 1:fn + 1 + numel].values
        p_y_store = combined_df.iloc[:,
                                     fn + 1 + numel:fn + 1 + 2 * numel].values

        if total_expt > numel_expt:
            model_store = load_model_ensemble(model_dir)
            fl = load_data_to_fl(data_loader_excel_file=loader_excel,
                                 norm_mask=[0, 1, 3, 4, 5],
                                 normalise_labels=True,
                                 label_type='cutoff')

            p_y, _ = model_ensemble_prediction(
                model_store, fl.apply_scaling(final_features[numel_expt:, :]))

            y_store = np.concatenate(
                (y_store, final_df.values[numel_expt:, :]), axis=0)
            p_y_store = np.concatenate((p_y_store, p_y), axis=0)

        se_store = (y_store - p_y_store)**2
        re_store = np.abs(y_store - p_y_store) / y_store
        are_store = np.arctan(re_store)

        column_headers = final_df.columns.values.tolist()

        df = pd.DataFrame(data=np.concatenate(
            (y_store, p_y_store, se_store, re_store, are_store), axis=1),
                          index=list(final_df.index),
                          columns=column_headers +
                          ['P_{}'.format(col) for col in column_headers] +
                          ['SE_{}'.format(col) for col in column_headers] +
                          ['RE_{}'.format(col) for col in column_headers] +
                          ['ARE_{}'.format(col) for col in column_headers])
        print_df_to_excel(df=df, ws=ws)

        col = fn + 1 + 1 + 2 * numel + 3
        mse_store.append(np.mean(se_store))
        mre_store.append(np.mean(re_store))
        mare_store.append(np.mean(are_store))
        ws.cell(1, col).value = 'MSE'
        ws.cell(1, col + 1).value = mse_store[-1]
        ws.cell(2, col).value = 'MRE'
        ws.cell(2, col + 1).value = mre_store[-1]
        ws.cell(3, col).value = 'ARE'
        ws.cell(3, col + 1).value = mare_store[-1]

    wb.create_sheet('Final_results')
    ws = wb[wb.sheetnames[-1]]
    df = pd.DataFrame(data=np.array([mse_store, mre_store, mare_store]),
                      index=['mse', 're', 'are'],
                      columns=rounds)
    print_df_to_excel(df=df, ws=ws)
    wb.save(write_excel)
示例#6
0
def test(selector, number=None):
    if selector == 1:
        write_dir = './results/svm gamma130 with proba'
        svm_store = load_svm_ensemble('{}/models'.format(write_dir))
        x, y = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100))
        composition = np.concatenate((x.reshape(-1, 1), y.reshape(-1, 1)),
                                     axis=1)
        prediction, distance, probability = svm_ensemble_prediction(
            svm_store, composition, probability=True)
        plt.scatter(composition[:, 0], composition[:, 1], c=distance)
        plt.colorbar()
        plt.savefig('./results/svm gamma130 with proba/distance map.png',
                    bbox_inches='tight')
        plt.close()
        plt.scatter(composition[:, 0], composition[:, 1], c=prediction)
        plt.colorbar()
        plt.savefig('./results/svm gamma130 with proba/prediction map.png',
                    bbox_inches='tight')
        plt.close()
        plt.scatter(composition[:, 0], composition[:, 1], c=probability)
        plt.colorbar()
        plt.savefig('./results/svm gamma130 with proba/probability map.png',
                    bbox_inches='tight')
        plt.close()
        with open('results/grid full/grid_data', 'rb') as handle:
            fl = pickle.load(handle)
        plt.scatter(fl.features[:, 0], fl.features[:, 1], c=fl.labels)
        plt.colorbar()
        plt.savefig('./results/svm gamma130 with proba/actual map.png',
                    bbox_inches='tight')
        plt.close()

        wb = openpyxl.Workbook()
        wb.create_sheet('data')
        x_name = 'CNT'
        y_name = 'PVA'
        print_df_to_excel(df=pd.DataFrame(
            np.array([
                composition[:, 0], composition[:, 1], prediction, distance,
                probability
            ]).T,
            columns=[x_name, y_name, 'prediction', 'distance', 'probability']),
                          ws=wb['data'])
        wb.save('{}/svm prediction distance prob.xlsx'.format(write_dir))

        model = SVMmodel(fl=fl, gamma=130)
        model.train_model(fl=fl)
        prediction, distance = svm_ensemble_prediction([model], composition)
        plt.scatter(composition[:, 0], composition[:, 1], c=distance)
        plt.colorbar()
        plt.savefig('{}/distance map2.png'.format(write_dir),
                    bbox_inches='tight')
        plt.close()
        plt.scatter(composition[:, 0], composition[:, 1], c=prediction)
        plt.colorbar()
        plt.savefig('{}/prediction map2.png'.format(write_dir),
                    bbox_inches='tight')
        plt.close()

    elif selector == 2:
        with open('results/grid full/grid_data', 'rb') as handle:
            fl = pickle.load(handle)

        grid_hparam_opt(fl, 300)
    elif selector == 3:
        composition = np.array([0.175763935003216, 0.195036471863385])
        svm_store = load_svm_ensemble('./results/svm gamma130/models')
        prediction, distance = svm_ensemble_prediction(svm_store, composition)
        print('prediction: {}\ndistance: {}'.format(prediction, distance))
    elif selector == 4:
        write_dir = './results/skf3'
        plot_arcsinh_predicted_splines(
            plot_dir='{}/plots'.format(write_dir),
            results_excel_dir='{}/skf_results.xlsx'.format(write_dir),
            end_excel_dir='./results/combine Round 6/end 6.xlsx',
            transformation='arcsinh',
            sheets=['ann3'],
            fn=6,
            numel=99)
    elif selector == 5:
        combine_excel_results(
            results_excel_dir=
            './results/Optimal Combinations/testset_combi/combinations.xlsx',
            end_excel_dir='./results/combine Round 6/end 6.xlsx',
            plot_dir='./results/combine Round 6/plots',
            sheets=[
                'ann3_115_0', 'ann3_190_0 sqrt', 'conv1_40_0',
                'conv1_158_0 sqrt'
            ],
            fn=6)
    elif selector == 6:
        cutoff_combine_excel_results(
            dir_store=[
                './results/hparams_opt Round {} SVR'.format(number),
                './results/hparams_opt Round {} DTR'.format(number),
                './results/hparams_opt Round {} ANN3'.format(number)
            ],
            sheets=['svr', 'dtr', 'ann3'],
            results_excel_dir='./results/combination {}/combination CM R{}.xlsx'
            .format(number, number),
            plot_dir='./results/combination {}/plots'.format(number),
            plot_mode=False,
            fn=6,
            numel=3)
    elif selector == 6.1:
        cutoff_combine_excel_results(
            dir_store=[
                './results/hparams_opt Round {} DTR'.format(number),
                './results/hparams_opt Round {} ANN3 - 2'.format(number)
            ],
            sheets=['dtr', 'ann3'],
            results_excel_dir='./results/combination {}/combination CM R{}.xlsx'
            .format(number, number),
            plot_dir='./results/combination {}/plots'.format(number),
            plot_mode=False,
            fn=6,
            numel=3)
    elif selector == 6.2:
        cutoff_combine_excel_results_with_excel(
            results_excel_dir=
            './results/combination_13s_R13_predictions/testset_prediction.xlsx',
            plot_dir='./results/combination_13s_R13_predictions/plots',
            plot_mode=False,
            fn=-1,
            numel=3)

    elif selector == 7:
        model_store = load_model_ensemble('./results/skf13/models')
        mean, std = model_ensemble_prediction(
            model_store, np.array([[0.5, 0.5, 0.5, 0, 1, 0]]))
        print(mean, std)

    elif selector == 8:
        mse_tracker(excel_store=[
            './results/combination {}/combination CM R{}.xlsx'.format(1, 1),
            './results/combination {}/combination CM R{}.xlsx'.format(2, 2),
            './results/combination {}/combination CM R{}.xlsx'.format(3, 3),
            './results/combination {}/combination CM R{}.xlsx'.format(4, 4),
            './results/combination {}/combination CM R{}.xlsx'.format(5, 5),
            './results/combination {}/combination CM R{}.xlsx'.format(6, 6),
            './results/combination {}/combination CM R{}.xlsx'.format(
                '6e', '6e'),
            './results/combination {}/combination CM R{}.xlsx'.format(7, 7),
            './results/combination {}/combination CM R{}.xlsx'.format(8, 8),
            './results/combination {}/combination CM R{}.xlsx'.format(9, 9),
            './results/combination {}/combination CM R{}.xlsx'.format(10, 10),
            './results/combination {}/combination CM R{}.xlsx'.format(11, 11),
            './results/combination {}/combination CM R{}.xlsx'.format(12, 12),
            './results/combination {}/combination CM R{}.xlsx'.format(13, 13)
        ],
                    write_excel='./MSE tracker.xlsx',
                    rounds=[1, 2, 3, 4, 5, 6, '6e', 7, 8, 9, 10, 11, 12, 13],
                    headers=['SVR', 'DTR', 'ANN3', 'Combined'],
                    fn=6,
                    numel=3)
    elif selector == 9:
        write_dir = create_results_directory(
            results_directory='./results/final_prediction',
            excels=['final_prediction'])
        final_prediction_results(
            write_excel='{}/final_prediction.xlsx'.format(write_dir),
            model_dir_store=[
                './results/combination {}/models'.format(1),
                './results/combination {}/models'.format(2),
                './results/combination {}/models'.format(3),
                './results/combination {}/models'.format(4),
                './results/combination {}/models'.format(5),
                './results/combination {}/models'.format(6),
                './results/combination {}/models'.format('6e'),
                './results/combination {}/models'.format(7),
                './results/combination {}/models'.format(8),
                './results/combination {}/models'.format(9),
                './results/combination {}/models'.format(10),
                './results/combination {}/models'.format(11),
                './results/combination {}/models'.format(12),
                './results/combination {}/models'.format(13)
            ],
            combined_excel_store=[
                './results/combination {}/combination CM R{}.xlsx'.format(
                    1, 1),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    2, 2),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    3, 3),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    4, 4),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    5, 5),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    6, 6),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    '6e', '6e'),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    7, 7),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    8, 8),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    9, 9),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    10, 10),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    11, 11),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    12, 12),
                './results/combination {}/combination CM R{}.xlsx'.format(
                    13, 13)
            ],
            excel_loader_dir_store=[
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(1, 1),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(2, 2),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(3, 3),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(4, 4),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(5, 5),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(6, 6),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format('6e', '6e'),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(7, 7),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(8, 8),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(9, 9),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(10, 10),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(11, 11),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(12, 12),
                './excel/Data_loader_spline_full_onehot_R{}_cut_CM3.xlsx'.
                format(13, 13)
            ],
            rounds=[1, 2, 3, 4, 5, 6, '6e', 7, 8, 9, 10, 11, 12, 13],
            fn=6,
            numel=3)