-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_openML_surrogate_multi_specific.py
104 lines (76 loc) · 4.86 KB
/
run_openML_surrogate_multi_specific.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os, argparse
import shutil
open_ml_problems_folder = 'OpenML_datasets'
surrogate_data_path = 'data/surrogate/data/'
# fixed test params as first part
k_params = [30, 50, 100] # 100, 150, 200
k_random = [0] # 0, 1
k_reinit = [0] # 0, 1
every_ls = 5
n_times = 5
def main():
parser = argparse.ArgumentParser(description="Find best features for each OpenML problems")
parser.add_argument('--ils', type=int, help='number of total iteration for ils algorithm', required=True)
parser.add_argument('--ls', type=int, help='number of iteration for Local Search algorithm', required=True)
args = parser.parse_args()
p_ils = args.ils
p_ls = args.ls
open_ml_problems = sorted(os.listdir(open_ml_problems_folder))
for ml_problem in open_ml_problems:
# for each problem prepare specific pre-computed real solution file
ml_problem_name = ml_problem.replace('.csv', '')
ml_problem_path = os.path.join(open_ml_problems_folder, ml_problem)
# ml_surrogate_command = f"python find_best_attributes_surrogate_openML_multi_specific.py " \
# f"--data {ml_problem_path} " \
# f"--ils {p_ils} " \
# f"--ls {p_ls} " \
# f"--output {ml_problem_name} " \
# f"--generate_only 1"
# print(f'Running extraction real evaluations data for {ml_problem_name}')
# os.system(ml_surrogate_command)
# real_evaluation_data_file_path = os.path.join(surrogate_data_path, ml_problem_name)
# for each multi param:
# - copy precomputed real_evaluation_data_file
# - run new instance using specific data
for k in k_params:
for k_r in k_random:
for k_init in k_reinit:
# if not use of k_reinit and use of random, then run multiple times this instance to do mean later
if k_init == 0 and k_r == 1:
for i in range(n_times):
str_index = str(i)
while len(str_index) < 3:
str_index = "0" + str_index
output_problem_name = f'{ml_problem_name}_everyLS_{every_ls}_k{k}_random{k_r}_reinit{k_init}_{str_index}'
# copy pre-computed real evaluation data for this instance
# current_output_real_eval_path = os.path.join(surrogate_data_path, output_problem_name)
# shutil.copy2(real_evaluation_data_file_path, current_output_real_eval_path)
ml_surrogate_multi_command = f"python find_best_attributes_surrogate_openML_multi_specific.py " \
f"--data {ml_problem_path} " \
f"--ils {p_ils} " \
f"--ls {p_ls} " \
f"--every_ls {every_ls} " \
f"--k_division {k} " \
f"--k_random {k_r} " \
f"--k_dynamic {k_init} " \
f"--output {output_problem_name}"
print(f'Running extraction data for {ml_problem_name} with [ils: {p_ils}, ls: {p_ls}, k: {k}, k_r: {k_r}, i: {i}]')
os.system(ml_surrogate_multi_command)
else:
output_problem_name = f'{ml_problem_name}_everyLS_{every_ls}_k{k}_random{k_r}_reinit{k_init}'
# copy pre-computed real evaluation data for this instance
# current_output_real_eval_path = os.path.join(surrogate_data_path, output_problem_name)
# shutil.copy2(real_evaluation_data_file_path, current_output_real_eval_path)
ml_surrogate_multi_command = f"python find_best_attributes_surrogate_openML_multi_specific.py " \
f"--data {ml_problem_path} " \
f"--ils {p_ils} " \
f"--ls {p_ls} " \
f"--every_ls {every_ls} " \
f"--k_division {k} " \
f"--k_random {k_r} " \
f"--k_dynamic {k_init} " \
f"--output {output_problem_name}"
print(f'Running extraction data for {ml_problem_name} with [ils: {p_ils}, ls: {p_ls}, k: {k}, k_r: {k_r}]')
os.system(ml_surrogate_multi_command)
if __name__ == "__main__":
main()