Skip to content

Commit 63c1fb6

Browse files
v0.2.23
new: generate_config_id
1 parent b037d6e commit 63c1fb6

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotPython"
10-
version = "0.2.22"
10+
version = "0.2.23"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/fun/hypersklearn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010

1111
from spotPython.sklearn.traintest import evaluate_cv, evaluate_model_oob, evaluate_hold_out
12+
from spotPython.utils.eda import generate_config_id
1213

1314
import logging
1415
from sklearn.metrics import mean_absolute_error
@@ -80,6 +81,7 @@ def fun_sklearn(self, X, fun_control=None):
8081
self.check_X_shape(X)
8182
var_dict = assign_values(X, self.fun_control["var_name"])
8283
for config in generate_one_config_from_var_dict(var_dict, self.fun_control):
84+
config_id = generate_config_id(config)
8385
if self.fun_control["prep_model"] is not None:
8486
model = make_pipeline(self.fun_control["prep_model"], self.fun_control["core_model"](**config))
8587
else:

src/spotPython/fun/hypertorch.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
assign_values,
99
generate_one_config_from_var_dict,
1010
)
11+
from spotPython.utils.eda import generate_config_id
1112

1213

1314
logger = logging.getLogger(__name__)
@@ -64,10 +65,7 @@ def fun_torch(self, X, fun_control=None):
6465
# type information and transformations are considered in generate_one_config_from_var_dict:
6566
for config in generate_one_config_from_var_dict(var_dict, self.fun_control):
6667
print(f"\nconfig: {config}")
67-
config_id = ""
68-
for key in config:
69-
config_id += str(config[key]) + "_"
70-
config_id = config_id[:-1]
68+
config_id = generate_config_id(config)
7169
if self.fun_control["prep_model"] is not None:
7270
model = make_pipeline(self.fun_control["prep_model"], self.fun_control["core_model"](**config))
7371
else:

src/spotPython/utils/eda.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,16 @@ def compare_two_tree_models(model1, model2, headers=["Parameter", "Default", "Sp
9797
for key, value1, value2 in zip(keys, values1, values2):
9898
tbl.append([key, value1, value2])
9999
return tabulate(tbl, headers=headers, numalign="right", tablefmt="github")
100+
101+
102+
def generate_config_id(config):
103+
"""Generates a unique id for a configuration.
104+
Args:
105+
config (dict): A dictionary with the configuration.
106+
Returns:
107+
str: A unique id for the configuration.
108+
"""
109+
config_id = ""
110+
for key in config:
111+
config_id += str(config[key]) + "_"
112+
return config_id[:-1]

0 commit comments

Comments
 (0)