run_openML_surrogate_multi_specific.py 4.9 KB

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