Andrea Maldonado commited on
Commit
1405a67
·
1 Parent(s): fb3f6c7

Triangular option for manual grids.

Browse files
Files changed (1) hide show
  1. utils/config_fabric.py +33 -28
utils/config_fabric.py CHANGED
@@ -88,22 +88,13 @@ def get_ranges_from_stats(stats, tuple_values):
88
  result = ", ".join(result)
89
  return result
90
 
91
- def create_objectives_grid(df, objectives, n_para_obj=2, method="combinatorial", n_values=None):
92
  if "combinatorial" in method:
93
- if method=="combinatorial-manual":
94
- values_indexes = ["value "+str(i+1) for i in range(n_values)]
95
- values_defaults = ['*(1+2*0.'+str(i)+')' for i in range(n_values)]
96
- cross_labels = [feature[0]+': '+feature[1] for feature in list(cproduct(objectives,values_indexes))]
97
- cross_values = [round(eval(str(combination[0])+combination[1]), 2) for combination in list(cproduct(list(df.values()), values_defaults))]
98
- parameters = split_list(list(input_multicolumn(cross_labels, cross_values, n_cols=n_values)), len(objectives))
99
- tasks = f"list({parameters})"
100
-
101
- else: #combinatorial from csv
102
- sel_features = df.index.to_list()
103
- parameters_o = "objectives, "
104
- parameters = get_ranges_from_stats(df, sorted(objectives))
105
- objectives = sorted(sel_features)
106
- tasks = f"list(cproduct({parameters}))[0]"
107
 
108
  elif method=="range-from-csv":
109
  tasks = ""
@@ -127,10 +118,16 @@ def create_objectives_grid(df, objectives, n_para_obj=2, method="combinatorial",
127
  selcted_min, selcted_max, step_value = range_value
128
  tasks += f"np.around(np.arange({selcted_min}, {selcted_max}+{step_value}, {step_value}),2), "
129
 
130
- #import pdb; pdb.set_trace()
131
- cartesian_product = list(cproduct(*eval(tasks)))
132
- experiments = [{key: value[idx] for idx, key in enumerate(objectives)} for value in cartesian_product]
133
- return experiments
 
 
 
 
 
 
134
 
135
  def set_generator_experiments(generator_params):
136
  def handle_csv_file(grid_option):
@@ -156,11 +153,11 @@ def set_generator_experiments(generator_params):
156
  for comb in all_combinations:
157
  sel_stats = stats.loc[sorted(list(comb))]
158
  experiments += create_objectives_grid(sel_stats, tuple_values, n_para_obj=len(tuple_values), method="combinatorial")
159
- else:
160
- experiments = create_objectives_grid(stats, tuple_values, n_para_obj=len(tuple_values))
161
  return experiments
162
 
163
- def handle_grid_option(grid_option, df, sel_features):
164
  if grid_option:
165
  combinatorial = double_switch("Range", "Combinatorial")
166
  if combinatorial:
@@ -185,12 +182,20 @@ def set_generator_experiments(generator_params):
185
  if combinatorial:
186
  col1, col2 = st.columns([1,4])
187
  with col1:
188
- num_values = st.number_input('How many values to define?', min_value=1, step=1)
189
  with col2:
190
- #sel_features = st.multiselect("Selected features", list(generator_params['experiment'].keys()))
191
  sel_features = feature_select()
192
 
193
- return create_objectives_grid(generator_params['experiment'], sel_features, n_para_obj=len(sel_features), method="combinatorial-manual", n_values=num_values)
 
 
 
 
 
 
 
 
 
194
 
195
  else: # Range
196
  sel_features = feature_select()
@@ -210,7 +215,7 @@ def set_generator_experiments(generator_params):
210
  if csv_option:
211
  df, sel_features = handle_csv_file(grid_option)
212
  if df is not None and sel_features is not None:
213
- experiments = handle_grid_option(grid_option, df, sel_features)
214
  else:
215
  experiments = []
216
  else: # Manual
@@ -236,7 +241,7 @@ if __name__ == '__main__':
236
  pipeline_steps = st.multiselect(
237
  "Choose pipeline step",
238
  step_candidates,
239
- []
240
  )
241
  step_configs = []
242
  set_col, view_col = st.columns([3, 2])
@@ -265,7 +270,7 @@ if __name__ == '__main__':
265
  save_labels = ["Save configuration file"]
266
  #create_button, create_run_button = multi_button(save_labels)
267
  create_button = multi_button(save_labels)
268
- # ToDo: Bug: automatically updates the experiment_config.json file even without pressing the save button
269
  if create_button: # or create_run_button:
270
  with open(output_path, "w") as f:
271
  f.write(config_file)
 
88
  result = ", ".join(result)
89
  return result
90
 
91
+ def create_objectives_grid(df, objectives, n_para_obj=2, method="combinatorial"):
92
  if "combinatorial" in method:
93
+ sel_features = df.index.to_list()
94
+ parameters_o = "objectives, "
95
+ parameters = get_ranges_from_stats(df, sorted(objectives))
96
+ objectives = sorted(sel_features)
97
+ tasks = f"list(cproduct({parameters}))[0]"
 
 
 
 
 
 
 
 
 
98
 
99
  elif method=="range-from-csv":
100
  tasks = ""
 
118
  selcted_min, selcted_max, step_value = range_value
119
  tasks += f"np.around(np.arange({selcted_min}, {selcted_max}+{step_value}, {step_value}),2), "
120
 
121
+ try:
122
+ cartesian_product = list(cproduct(*eval(tasks)))
123
+ experiments = [{key: value[idx] for idx, key in enumerate(objectives)} for value in cartesian_product]
124
+ return experiments
125
+ except SyntaxError as e:
126
+ st.write("Please select valid features above.")
127
+ sys.exit(1)
128
+ except TypeError as e:
129
+ st.write("Please select at least 2 values to define.")
130
+ sys.exit(1)
131
 
132
  def set_generator_experiments(generator_params):
133
  def handle_csv_file(grid_option):
 
153
  for comb in all_combinations:
154
  sel_stats = stats.loc[sorted(list(comb))]
155
  experiments += create_objectives_grid(sel_stats, tuple_values, n_para_obj=len(tuple_values), method="combinatorial")
156
+ else: # Square
157
+ experiments = create_objectives_grid(stats, tuple_values, n_para_obj=len(tuple_values), method="combinatorial")
158
  return experiments
159
 
160
+ def handle_csv_option(grid_option, df, sel_features):
161
  if grid_option:
162
  combinatorial = double_switch("Range", "Combinatorial")
163
  if combinatorial:
 
182
  if combinatorial:
183
  col1, col2 = st.columns([1,4])
184
  with col1:
185
+ num_values = st.number_input('How many values to define?', min_value=2, step=1)
186
  with col2:
 
187
  sel_features = feature_select()
188
 
189
+ values_indexes = ["value "+str(i+1) for i in range(num_values)]
190
+ values_defaults = ['*(1+2*0.'+str(i)+')' for i in range(num_values)]
191
+ cross_labels = [feature[0]+': '+feature[1] for feature in list(cproduct(sel_features,values_indexes))]
192
+ cross_values = [round(eval(str(combination[0])+combination[1]), 2) for combination in list(cproduct(list(generator_params['experiment'].values()), values_defaults))]
193
+ parameters = split_list(list(input_multicolumn(cross_labels, cross_values, n_cols=num_values)), len(sel_features))
194
+ tasks = f"list({parameters})"
195
+
196
+ tasks_df = pd.DataFrame(eval(tasks), index=sel_features, columns=values_indexes)
197
+ tasks_df = tasks_df.astype(float)
198
+ return handle_combinatorial(sel_features, tasks_df, values_indexes)
199
 
200
  else: # Range
201
  sel_features = feature_select()
 
215
  if csv_option:
216
  df, sel_features = handle_csv_file(grid_option)
217
  if df is not None and sel_features is not None:
218
+ experiments = handle_csv_option(grid_option, df, sel_features)
219
  else:
220
  experiments = []
221
  else: # Manual
 
241
  pipeline_steps = st.multiselect(
242
  "Choose pipeline step",
243
  step_candidates,
244
+ ["event_logs_generation"]
245
  )
246
  step_configs = []
247
  set_col, view_col = st.columns([3, 2])
 
270
  save_labels = ["Save configuration file"]
271
  #create_button, create_run_button = multi_button(save_labels)
272
  create_button = multi_button(save_labels)
273
+ # FIXME: Bug: automatically updates the experiment_config.json file even without pressing the save button
274
  if create_button: # or create_run_button:
275
  with open(output_path, "w") as f:
276
  f.write(config_file)