Spaces:
Sleeping
Sleeping
Andrea Maldonado
commited on
Commit
·
fb3f6c7
1
Parent(s):
bbd9f05
Implements manual input of grid objectives
Browse files- utils/config_fabric.py +42 -41
utils/config_fabric.py
CHANGED
@@ -88,13 +88,22 @@ 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"):
|
92 |
-
if
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
elif method=="range-from-csv":
|
100 |
tasks = ""
|
@@ -167,40 +176,33 @@ def set_generator_experiments(generator_params):
|
|
167 |
st.write(df)
|
168 |
return df.to_dict(orient='records')
|
169 |
|
170 |
-
def
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
175 |
num_values = st.number_input('How many values to define?', min_value=1, step=1)
|
|
|
|
|
|
|
176 |
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
# Generate the cartesian product of all possible combinations
|
191 |
-
cartesian_product = list(itertools.product(*feature_values_dict.values()))
|
192 |
-
|
193 |
-
# Convert each combination into a dictionary with the appropriate feature keys
|
194 |
-
experiments = [dict(zip(sel_features, values)) for values in cartesian_product]
|
195 |
-
|
196 |
-
return experiments
|
197 |
-
|
198 |
-
else:
|
199 |
-
return create_objectives_grid(generator_params['experiment'], sel_features, n_para_obj=len(sel_features), method="range-manual")
|
200 |
-
else:
|
201 |
-
experiment = {sel_feature: float(st.text_input(sel_feature, generator_params['experiment'][sel_feature])) for sel_feature in sel_features}
|
202 |
-
return [experiment]
|
203 |
-
return []
|
204 |
|
205 |
|
206 |
grid_option, csv_option = double_switch("Point-", "Grid-based", third_label="Manual", fourth_label="From CSV")
|
@@ -212,8 +214,7 @@ def set_generator_experiments(generator_params):
|
|
212 |
else:
|
213 |
experiments = []
|
214 |
else: # Manual
|
215 |
-
|
216 |
-
experiments = handle_manual_option(sel_features, grid_option)
|
217 |
|
218 |
generator_params['experiment'] = experiments
|
219 |
st.write(f"...result in {len(generator_params['experiment'])} experiment(s)")
|
|
|
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 = ""
|
|
|
176 |
st.write(df)
|
177 |
return df.to_dict(orient='records')
|
178 |
|
179 |
+
def feature_select():
|
180 |
+
return st.multiselect("Selected features", list(generator_params['experiment'].keys()))
|
181 |
+
|
182 |
+
def handle_manual_option(grid_option):
|
183 |
+
if grid_option:
|
184 |
+
combinatorial = double_switch("Range", "Combinatorial")
|
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()
|
197 |
+
return create_objectives_grid(generator_params['experiment'], sel_features, n_para_obj=len(sel_features), method="range-manual")
|
198 |
+
|
199 |
+
else: # Point
|
200 |
+
sel_features = feature_select()
|
201 |
+
#sel_features = st.multiselect("Selected features", list(generator_params['experiment'].keys()))
|
202 |
+
|
203 |
+
experiment = {sel_feature: float(st.text_input(sel_feature, generator_params['experiment'][sel_feature])) for sel_feature in sel_features}
|
204 |
+
return [experiment]
|
205 |
+
return[]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
|
208 |
grid_option, csv_option = double_switch("Point-", "Grid-based", third_label="Manual", fourth_label="From CSV")
|
|
|
214 |
else:
|
215 |
experiments = []
|
216 |
else: # Manual
|
217 |
+
experiments = handle_manual_option(grid_option)
|
|
|
218 |
|
219 |
generator_params['experiment'] = experiments
|
220 |
st.write(f"...result in {len(generator_params['experiment'])} experiment(s)")
|