Spaces:
Running
Running
Andrea Maldonado
commited on
Commit
Β·
1539c36
1
Parent(s):
5c9620d
Adds range option for gridbase, csv config files
Browse files- setup.py +1 -0
- utils/config_fabric.py +57 -57
- merge_csvs.py β utils/merge_csvs.py +0 -0
- merge_jsons.py β utils/merge_jsons.py +0 -0
setup.py
CHANGED
@@ -32,6 +32,7 @@ setup(
|
|
32 |
'seaborn==0.13.2',
|
33 |
'smac==2.0.2',
|
34 |
'tqdm==4.65.0',
|
|
|
35 |
],
|
36 |
packages = ['gedi'],
|
37 |
classifiers=[
|
|
|
32 |
'seaborn==0.13.2',
|
33 |
'smac==2.0.2',
|
34 |
'tqdm==4.65.0',
|
35 |
+
'streamlit-toggle-switch>=1.0.2'
|
36 |
],
|
37 |
packages = ['gedi'],
|
38 |
classifiers=[
|
utils/config_fabric.py
CHANGED
@@ -46,36 +46,30 @@ def get_ranges(stats, tuple_values):
|
|
46 |
result = ", ".join(result)
|
47 |
return result
|
48 |
|
49 |
-
def create_objectives_grid(df, objectives, n_para_obj=2):
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
experiments = [{key: value[idx] for idx, key in enumerate(sel_features)} for value in cartesian_product]
|
57 |
return experiments
|
58 |
-
else:
|
59 |
-
if n_para_obj==1:
|
60 |
-
experiments = [[exp] for exp in objectives]
|
61 |
-
else:
|
62 |
-
experiments = eval(f"[exp for exp in list(itertools.product({(parameters_o*n_para_obj)[:-2]})) if exp[0]!=exp[1]]")
|
63 |
-
experiments = list(set([tuple(sorted(exp)) for exp in experiments]))
|
64 |
-
parameters = "np.around(np.arange(0.0, 1.5,0.5),2), "
|
65 |
-
tasks = eval(f"list(itertools.product({(parameters*n_para_obj)[:-2]}))")
|
66 |
-
print("TASKS", tasks, type(parameters), type(n_para_obj), parameters*n_para_obj)
|
67 |
-
#print(len(experiments), experiments)
|
68 |
-
|
69 |
-
print(len(tasks))
|
70 |
-
|
71 |
-
for exp in experiments:
|
72 |
-
df = pd.DataFrame(data=tasks, columns=["task", *exp])
|
73 |
-
#experiment_path = os.path.join('..','data', f'grid_{n_para_obj}obj')
|
74 |
-
#os.makedirs(experiment_path, exist_ok=True)
|
75 |
-
#experiment_path = os.path.join(experiment_path, f"grid_{len(df.columns)-1}objectives_{abbrev_obj_keys(exp)}.csv")
|
76 |
-
#df.to_csv(experiment_path, index=False)
|
77 |
-
#print(f"Saved experiment in {experiment_path}")
|
78 |
-
#write_generator_experiment(experiment_path, objectives=exp)
|
79 |
|
80 |
def set_up(generator_params):
|
81 |
create_button = False
|
@@ -90,38 +84,44 @@ def set_up(generator_params):
|
|
90 |
if uploaded_file is not None:
|
91 |
df = pd.read_csv(uploaded_file)
|
92 |
sel_features = st.multiselect("Selected features", list(df.columns))
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
else:
|
117 |
-
|
118 |
-
|
119 |
-
view(df)
|
120 |
-
experiments = df.to_dict(orient='records')
|
121 |
else:
|
122 |
sel_features = st.multiselect("Selected features", list(generator_params['experiment'].keys()))
|
123 |
-
|
124 |
-
|
|
|
125 |
generator_params['experiment'] = experiments
|
126 |
st.write(f"...result in {len(generator_params['experiment'])} experiments")
|
127 |
|
|
|
46 |
result = ", ".join(result)
|
47 |
return result
|
48 |
|
49 |
+
def create_objectives_grid(df, objectives, n_para_obj=2, method="combinatorial"):
|
50 |
+
if method=="combinatorial":
|
51 |
+
#if n_para_obj==len(objectives):
|
52 |
+
sel_features = df.index.to_list()
|
53 |
+
parameters_o = "objectives, "
|
54 |
+
parameters = get_ranges(df, sorted(objectives))
|
55 |
+
tasks = f"list(itertools.product({parameters}))[0]"
|
56 |
+
|
57 |
+
else:
|
58 |
+
sel_features = objectives
|
59 |
+
tasks = ""
|
60 |
+
for objective in objectives:
|
61 |
+
min_col, max_col, step_col = st.columns(3)
|
62 |
+
with min_col:
|
63 |
+
selcted_min = st.slider(objective+': min', min_value=float(df[objective].min()), max_value=float(df[objective].max()), value=df[objective].quantile(0.1), step=0.1, key=objective+"min")
|
64 |
+
with max_col:
|
65 |
+
selcted_max = st.slider('max', min_value=selcted_min, max_value=float(df[objective].max()), value=df[objective].quantile(0.9), step=0.1, key=objective+"max")
|
66 |
+
with step_col:
|
67 |
+
step_value = st.slider('step', min_value=float(df[objective].min()), max_value=float(df[objective].quantile(0.9)), value=df[objective].median()/df[objective].min(), step=0.01, key=objective+"step")
|
68 |
+
tasks += f"np.around(np.arange({selcted_min}, {selcted_max}+{step_value}, {step_value}),2), "
|
69 |
+
|
70 |
+
cartesian_product = list(product(*eval(tasks)))
|
71 |
experiments = [{key: value[idx] for idx, key in enumerate(sel_features)} for value in cartesian_product]
|
72 |
return experiments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
def set_up(generator_params):
|
75 |
create_button = False
|
|
|
84 |
if uploaded_file is not None:
|
85 |
df = pd.read_csv(uploaded_file)
|
86 |
sel_features = st.multiselect("Selected features", list(df.columns))
|
87 |
+
if sel_features:
|
88 |
+
df = df[sel_features]
|
89 |
+
if grid_option:
|
90 |
+
combinatorial = double_switch("Range", "Combinatorial")
|
91 |
+
if combinatorial:
|
92 |
+
add_quantile = st.slider('Add %-quantile', min_value=0.0, max_value=100.0, value=50.0, step=5.0)
|
93 |
+
stats = df.describe().transpose()
|
94 |
+
stats[str(int(add_quantile))+"%"] = df.quantile(q=add_quantile/100)
|
95 |
+
view(stats)
|
96 |
+
tuple_values = st.multiselect("Tuples including", list(stats.columns)[3:], default=['min', 'max'])
|
97 |
+
triangular_option = double_switch("Square", "Triangular")
|
98 |
+
if triangular_option:
|
99 |
+
elements = sel_features
|
100 |
+
# List to store all combinations
|
101 |
+
all_combinations = []
|
102 |
+
|
103 |
+
# Generate combinations of length 1, 2, and 3
|
104 |
+
for r in range(1, len(elements) + 1):
|
105 |
+
# Generate combinations of length r
|
106 |
+
combinations_r = list(combinations(elements, r))
|
107 |
+
# Extend the list of all combinations
|
108 |
+
all_combinations.extend(combinations_r)
|
109 |
+
# Print or use the result as needed
|
110 |
+
for comb in all_combinations:
|
111 |
+
sel_stats = stats.loc[list(comb)]
|
112 |
+
experiments += create_objectives_grid(sel_stats, tuple_values, n_para_obj=len(tuple_values))
|
113 |
+
else:
|
114 |
+
experiments = create_objectives_grid(stats, tuple_values, n_para_obj=len(tuple_values))
|
115 |
+
else:
|
116 |
+
experiments = create_objectives_grid(df, sel_features, n_para_obj=len(sel_features), method="range")
|
117 |
else:
|
118 |
+
view(df)
|
119 |
+
experiments = df.to_dict(orient='records')
|
|
|
|
|
120 |
else:
|
121 |
sel_features = st.multiselect("Selected features", list(generator_params['experiment'].keys()))
|
122 |
+
if sel_features != None:
|
123 |
+
for sel_feature in sel_features:
|
124 |
+
generator_params['experiment'][sel_feature] = float(st.text_input(sel_feature, generator_params['experiment'][sel_feature]))
|
125 |
generator_params['experiment'] = experiments
|
126 |
st.write(f"...result in {len(generator_params['experiment'])} experiments")
|
127 |
|
merge_csvs.py β utils/merge_csvs.py
RENAMED
File without changes
|
merge_jsons.py β utils/merge_jsons.py
RENAMED
File without changes
|