|
| 1 | +#!/usr/bin/env python |
| 2 | +# ------------------------------------------------------------------------------------------------------% |
| 3 | +# Created by "Thieu Nguyen" at 00:51, 29/03/2020 % |
| 4 | +# % |
| 5 | +# Email: nguyenthieu2102@gmail.com % |
| 6 | +# Homepage: https://www.researchgate.net/profile/Thieu_Nguyen6 % |
| 7 | +# Github: https://github.com/thieunguyen5991 % |
| 8 | +# -------------------------------------------------------------------------------------------------------% |
| 9 | + |
| 10 | +from os.path import splitext, basename, realpath |
1 | 11 | from sklearn.model_selection import ParameterGrid |
2 | 12 | from model.main.hybrid_elm import ABfoLSElm |
3 | | -from utils.IOUtil import read_dataset_file |
4 | 13 | from utils.SettingPaper import abfols_elm_paras_final as param_grid |
5 | | -from utils.SettingPaper import traffic_eu, traffic_uk, worldcup |
| 14 | +from utils.SettingPaper import * |
| 15 | +from utils.IOUtil import load_dataset |
6 | 16 |
|
7 | | -rv_data = [traffic_eu, traffic_uk, worldcup] |
8 | | -data_file = ["it_eu_5m", "it_uk_5m", "worldcup98_5m"] |
9 | | -test_type = "stability" ### normal: for normal test, stability: for n_times test |
10 | | -run_times = None |
| 17 | +if SP_RUN_TIMES == 1: |
| 18 | + all_model_file_name = SP_LOG_FILENAME |
| 19 | +else: # If runs with more than 1, like stability test --> name of the models ==> such as: rnn1hl.csv |
| 20 | + all_model_file_name = str(splitext(basename(realpath(__file__)))[0]) |
11 | 21 |
|
12 | | -if test_type == "normal": ### For normal test |
13 | | - run_times = 1 |
14 | | - pathsave = "paper/results/final/" |
15 | | - all_model_file_name = "elm_log_models" |
16 | | -elif test_type == "stability": ### For stability test (n times run with the same parameters) |
17 | | - run_times = 15 |
18 | | - pathsave = "paper/results/stability/" |
19 | | - all_model_file_name = "stability_abfols_elm" |
20 | | -else: |
21 | | - pass |
22 | 22 |
|
23 | 23 | def train_model(item): |
24 | 24 | root_base_paras = { |
25 | 25 | "dataset": dataset, |
26 | 26 | "feature_size": feature_size, |
27 | | - "data_idx": (0.7, 0.15, 0.15), |
| 27 | + "data_idx": SP_DATA_SPLIT_INDEX_2, |
28 | 28 | "sliding": item["sliding"], |
29 | | - "multi_output": requirement_variables[2], |
30 | | - "output_idx": requirement_variables[3], |
31 | | - "method_statistic": 0, # 0: sliding window, 1: mean, 2: min-mean-max, 3: min-median-max |
| 29 | + "multi_output": multi_output, |
| 30 | + "output_idx": output_index, |
| 31 | + "method_statistic": SP_PREPROCESSING_METHOD, |
32 | 32 | "log_filename": all_model_file_name, |
33 | | - "path_save_result": pathsave + requirement_variables[4], |
34 | | - "test_type": test_type, |
35 | | - "draw": True, |
36 | | - "print_train": 0 # 0: nothing, 1 : full detail, 2: short version |
| 33 | + "n_runs": SP_RUN_TIMES, # 1 or others |
| 34 | + "path_save_result": SP_PATH_SAVE_BASE + SP_DATA_FILENAME[loop] + "/", |
| 35 | + "draw": SP_DRAW, |
| 36 | + "print_train": SP_PRINT_TRAIN, # 0: nothing, 1 : full detail, 2: short version |
37 | 37 | } |
| 38 | + paras_name = "hs_{}-ep_{}-act_{}-Ci_{}-Ped_{}-Ns_{}-N_minmax_{}".format(item["hidden_size"], item["epoch"], item["activation"], |
| 39 | + item["Ci"], item["Ped"], item["Ns"], item["N_minmax"]) |
38 | 40 | root_hybrid_paras = { |
39 | | - "hidden_size": item["hidden_size"], "activation": item["activation"], "epoch": item["epoch"], |
40 | | - "train_valid_rate": item["train_valid_rate"], "domain_range": item["domain_range"] |
| 41 | + "hidden_size": item["hidden_size"], "activation": item["activation"], "epoch": item["epoch"], "domain_range": item["domain_range"], |
| 42 | + "paras_name": paras_name |
41 | 43 | } |
42 | 44 | abfols_paras = { |
43 | | - "epoch": item["epoch"], "pop_size": item["pop_size"], "Ci": item["Ci"], "Ped": item["Ped"], "Ns": item["Ns"], |
44 | | - "N_minmax": item["N_minmax"] |
| 45 | + "epoch": item["epoch"], "pop_size": item["pop_size"], "Ci": item["Ci"], "Ped": item["Ped"], "Ns": item["Ns"], "N_minmax": item["N_minmax"] |
45 | 46 | } |
46 | 47 | md = ABfoLSElm(root_base_paras=root_base_paras, root_hybrid_paras=root_hybrid_paras, abfols_paras=abfols_paras) |
47 | 48 | md._running__() |
48 | 49 |
|
49 | | -for _ in range(run_times): |
50 | | - for loop in range(len(rv_data)): |
51 | | - requirement_variables = rv_data[loop] |
52 | | - filename = requirement_variables[0] + data_file[loop] + ".csv" |
53 | | - dataset = read_dataset_file(filename, requirement_variables[1]) |
54 | | - feature_size = len(requirement_variables[1]) |
| 50 | + |
| 51 | +for _ in range(SP_RUN_TIMES): |
| 52 | + for loop in range(len(SP_DATA_FILENAME)): |
| 53 | + filename = SP_LOAD_DATA_FROM + SP_DATA_FILENAME[loop] |
| 54 | + dataset = load_dataset(filename, cols=SP_DATA_COLS[loop]) |
| 55 | + feature_size = len(SP_DATA_COLS[loop]) |
| 56 | + multi_output = SP_DATA_MULTI_OUTPUT[loop] |
| 57 | + output_index = SP_OUTPUT_INDEX[loop] |
55 | 58 | # Create combination of params. |
56 | 59 | for item in list(ParameterGrid(param_grid)): |
57 | 60 | train_model(item) |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
0 commit comments