Skip to content

Commit 7d123f5

Browse files
0.14.28
New hyperparameter handling: set_int_hyperparameter_values, set_float_hyperparameter_values, set_boolean_hyperparamerer_values, and set_factor_hyperparameter_values
1 parent 7f94561 commit 7d123f5

4 files changed

Lines changed: 111 additions & 6 deletions

File tree

notebooks/00_spotPython_tests.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3908,7 +3908,7 @@
39083908
},
39093909
{
39103910
"cell_type": "code",
3911-
"execution_count": 3,
3911+
"execution_count": 1,
39123912
"metadata": {},
39133913
"outputs": [
39143914
{

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.14.27"
10+
version = "0.14.28"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/data/california_housing.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ class CaliforniaHousing(Dataset):
1919
- Latitude block group latitude
2020
- Longitude block group longitude
2121
* Missing Attribute Values: None
22-
* Target: The target variable is the median house value for California districts, expressed in hundreds of thousands of dollars ($100,000).
23-
This dataset was obtained from the StatLib repository. https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html
24-
This dataset was derived from the 1990 U.S. census, using one row per census block group. A block group is the smallest geographical unit for which the U.S. Census Bureau publishes sample data (a block group typically has a population of 600 to 3,000 people).
25-
A household is a group of people residing within a home. Since the average number of rooms and bedrooms in this dataset are provided per household, these columns may take surprisingly large values for block groups with few households and many empty houses, such as vacation resorts.
22+
* Target: The target variable is the median house value for California districts,
23+
expressed in hundreds of thousands of dollars ($100,000).
24+
This dataset was obtained from the StatLib repository:
25+
https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html
26+
This dataset was derived from the 1990 U.S. census, using one row per census block group.
27+
A block group is the smallest geographical unit for which the U.S. Census Bureau publishes
28+
sample data (a block group typically has a population of 600 to 3,000 people).
29+
A household is a group of people residing within a home. Since the average number of rooms
30+
and bedrooms in this dataset are provided per household, these columns may take surprisingly
31+
large values for block groups with few households and many empty houses, such as vacation resorts.
2632
2733
Args:
2834
feature_type (torch.dtype): The data type of the features. Defaults to torch.float.

src/spotPython/hyperparameters/values.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,105 @@ def update_fun_control_with_hyper_num_cat_dicts(fun_control, num_dict, cat_dict,
14661466
fun_control["core_model_hyper_dict"][key].update({"upper": len(fle) - 1})
14671467

14681468

1469+
def set_int_hyperparameter_values(fun_control, key, lower, upper):
1470+
"""
1471+
Set the integer hyperparameter values in the fun_control dictionary.
1472+
1473+
Args:
1474+
fun_control (dict):
1475+
The fun_control dictionary.
1476+
key (str):
1477+
The key of the hyperparameter.
1478+
lower (int):
1479+
The lower bound of the hyperparameter.
1480+
upper (int):
1481+
The upper bound of the hyperparameter.
1482+
"""
1483+
set_control_hyperparameter_value(
1484+
fun_control,
1485+
key,
1486+
[
1487+
lower,
1488+
upper,
1489+
],
1490+
)
1491+
1492+
1493+
def set_float_hyperparameter_values(fun_control, key, lower, upper):
1494+
"""
1495+
Set the float hyperparameter values in the fun_control dictionary.
1496+
1497+
Args:
1498+
fun_control (dict):
1499+
The fun_control dictionary.
1500+
key (str):
1501+
The key of the hyperparameter.
1502+
lower (float):
1503+
The lower bound of the hyperparameter.
1504+
upper (float):
1505+
The upper bound of the hyperparameter.
1506+
"""
1507+
set_control_hyperparameter_value(
1508+
fun_control,
1509+
key,
1510+
[
1511+
lower,
1512+
upper,
1513+
],
1514+
)
1515+
1516+
1517+
def set_boolean_hyperparameter_values(fun_control, key, lower, upper):
1518+
"""
1519+
Set the boolean hyperparameter values in the fun_control dictionary.
1520+
1521+
Args:
1522+
fun_control (dict):
1523+
The fun_control dictionary.
1524+
key (str):
1525+
The key of the hyperparameter.
1526+
lower (bool):
1527+
The lower bound of the hyperparameter.
1528+
upper (bool):
1529+
The upper bound of the hyperparameter.
1530+
"""
1531+
set_control_hyperparameter_value(
1532+
fun_control,
1533+
key,
1534+
[
1535+
lower,
1536+
upper,
1537+
],
1538+
)
1539+
1540+
1541+
def set_factor_hyperparameter_values(fun_control, key, levels):
1542+
"""
1543+
Set the factor hyperparameter values in the fun_control dictionary.
1544+
1545+
Args:
1546+
fun_control (dict):
1547+
The fun_control dictionary.
1548+
key (str):
1549+
The key of the hyperparameter.
1550+
levels (list):
1551+
The levels of the hyperparameter.
1552+
"""
1553+
# check if levels is a list of strings. If not, convert it to a list
1554+
if not isinstance(levels, list):
1555+
levels = [levels]
1556+
# check if levels is a list of strings. Othewise, issue a warning and return None
1557+
if not all(isinstance(x, str) for x in levels):
1558+
print("!!! Warning: levels should be a list of strings.")
1559+
return None
1560+
# check if key "core_model_hyper_dict" exists in fun_control:
1561+
if "core_model_hyper_dict" not in fun_control.keys():
1562+
return None
1563+
else:
1564+
fun_control["core_model_hyper_dict"][key].update({"levels": levels})
1565+
fun_control["core_model_hyper_dict"][key].update({"upper": len(levels) - 1})
1566+
1567+
14691568
def get_core_model_from_name(core_model_name) -> object:
14701569
"""
14711570
Returns the river core model name and instance from a core model name.

0 commit comments

Comments
 (0)