Skip to content

Commit 9360842

Browse files
0.16.0
condNet
1 parent c07b592 commit 9360842

20 files changed

Lines changed: 888 additions & 154 deletions

notebooks/00_spotPython_tests.ipynb

Lines changed: 734 additions & 143 deletions
Large diffs are not rendered by default.

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

src/spotpython/hyperdict/light_hyper_dict.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,115 @@
11
{
2+
"NNCondNetRegressor": {
3+
"l1": {
4+
"type": "int",
5+
"default": 3,
6+
"transform": "transform_power_2_int",
7+
"lower": 3,
8+
"upper": 8
9+
},
10+
"epochs": {
11+
"type": "int",
12+
"default": 4,
13+
"transform": "transform_power_2_int",
14+
"lower": 4,
15+
"upper": 9
16+
},
17+
"batch_size": {
18+
"type": "int",
19+
"default": 4,
20+
"transform": "transform_power_2_int",
21+
"lower": 1,
22+
"upper": 4
23+
},
24+
"act_fn": {
25+
"levels": [
26+
"Sigmoid",
27+
"Tanh",
28+
"ReLU",
29+
"LeakyReLU",
30+
"ELU",
31+
"Swish"
32+
],
33+
"type": "factor",
34+
"default": "ReLU",
35+
"transform": "None",
36+
"class_name": "spotpython.torch.activation",
37+
"core_model_parameter_type": "instance()",
38+
"lower": 0,
39+
"upper": 5
40+
},
41+
"optimizer": {
42+
"levels": [
43+
"Adadelta",
44+
"Adagrad",
45+
"Adam",
46+
"AdamW",
47+
"SparseAdam",
48+
"Adamax",
49+
"ASGD",
50+
"NAdam",
51+
"RAdam",
52+
"RMSprop",
53+
"Rprop",
54+
"SGD"
55+
],
56+
"type": "factor",
57+
"default": "SGD",
58+
"transform": "None",
59+
"class_name": "torch.optim",
60+
"core_model_parameter_type": "str",
61+
"lower": 0,
62+
"upper": 11
63+
},
64+
"dropout_prob": {
65+
"type": "float",
66+
"default": 0.01,
67+
"transform": "None",
68+
"lower": 0.0,
69+
"upper": 0.25
70+
},
71+
"lr_mult": {
72+
"type": "float",
73+
"default": 1.0,
74+
"transform": "None",
75+
"lower": 0.1,
76+
"upper": 10.0
77+
},
78+
"patience": {
79+
"type": "int",
80+
"default": 2,
81+
"transform": "transform_power_2_int",
82+
"lower": 2,
83+
"upper": 6
84+
},
85+
"batch_norm": {
86+
"levels": [
87+
0,
88+
1
89+
],
90+
"type": "factor",
91+
"default": 0,
92+
"transform": "None",
93+
"core_model_parameter_type": "bool",
94+
"lower": 0,
95+
"upper": 1
96+
},
97+
"initialization": {
98+
"levels": [
99+
"Default",
100+
"kaiming_uniform",
101+
"kaiming_normal",
102+
"xavier_uniform",
103+
"xavier_normal"
104+
],
105+
"type": "factor",
106+
"default": "Default",
107+
"transform": "None",
108+
"core_model_parameter_type": "str",
109+
"lower": 0,
110+
"upper": 4
111+
}
112+
},
2113
"TransformerLightRegression": {
3114
"d_mult": {
4115
"type": "int",

src/spotpython/light/classification/netlightbasemapk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def __init__(
7373
patience: int,
7474
_L_in: int,
7575
_L_out: int,
76+
*args,
77+
**kwargs,
7678
):
7779
"""
7880
Initializes the NetLightBase object.

src/spotpython/light/cvmodel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def cv_model(config: dict, fun_control: dict) -> float:
2626
>>> fun_control = {
2727
... "_L_in": 10,
2828
... "_L_out": 1,
29+
... "_L_cond": 0,
2930
... "enable_progress_bar": True,
3031
... "core_model": MyModel,
3132
... "num_workers": 4,
@@ -38,6 +39,7 @@ def cv_model(config: dict, fun_control: dict) -> float:
3839
"""
3940
_L_in = fun_control["_L_in"]
4041
_L_out = fun_control["_L_out"]
42+
_L_cond = fun_control["_L_cond"]
4143
_torchmetric = fun_control["_torchmetric"]
4244
if fun_control["enable_progress_bar"] is None:
4345
enable_progress_bar = False
@@ -52,7 +54,9 @@ def cv_model(config: dict, fun_control: dict) -> float:
5254
for k in range(num_folds):
5355
print("k:", k)
5456

55-
model = fun_control["core_model"](**config, _L_in=_L_in, _L_out=_L_out, _torchmetric=_torchmetric)
57+
model = fun_control["core_model"](
58+
**config, _L_in=_L_in, _L_out=_L_out, _L_cond=_L_cond, _torchmetric=_torchmetric
59+
)
5660

5761
dm = LightCrossValidationDataModule(
5862
k=k,

src/spotpython/light/litmodel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __init__(
4747
learning_rate: float = 2e-4,
4848
_L_in: int = 28 * 28,
4949
_L_out: int = 10,
50+
*args,
51+
**kwargs,
5052
):
5153
"""
5254
Initializes the LitModel object.

src/spotpython/light/loadmodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def load_light_from_checkpoint(config: dict, fun_control: dict, postfix: str = "
5151
default_root_dir,
5252
_L_in=fun_control["_L_in"],
5353
_L_out=fun_control["_L_out"],
54+
_L_cond=fun_control["_L_cond"],
5455
_torchmetric=fun_control["_torchmetric"],
5556
)
5657
# disable randomness, dropout, etc...

src/spotpython/light/predictmodel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def predict_model(config: dict, fun_control: dict) -> Tuple[float, float]:
5353
"""
5454
_L_in = fun_control["_L_in"]
5555
_L_out = fun_control["_L_out"]
56+
_L_cond = fun_control["_L_cond"]
5657
_torchmetric = fun_control["_torchmetric"]
5758
if fun_control["enable_progress_bar"] is None:
5859
enable_progress_bar = False
@@ -74,7 +75,7 @@ def predict_model(config: dict, fun_control: dict) -> Tuple[float, float]:
7475
# TODO: Check if this is necessary:
7576
# dm.setup(stage="train")
7677
# Init model from datamodule's attributes
77-
model = fun_control["core_model"](**config, _L_in=_L_in, _L_out=_L_out, _torchmetric=_torchmetric)
78+
model = fun_control["core_model"](**config, _L_in=_L_in, _L_out=_L_out, _L_cond=_L_cond, _torchmetric=_torchmetric)
7879

7980
trainer = L.Trainer(
8081
# Where to save models

src/spotpython/light/regression/netlightregression.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def __init__(
107107
_L_in: int,
108108
_L_out: int,
109109
_torchmetric: str,
110+
*args,
111+
**kwargs,
110112
):
111113
"""
112114
Initializes the NetLightRegression object.

src/spotpython/light/regression/nn_condnet_regressor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def __init__(
146146
_L_in: int,
147147
_L_out: int,
148148
_torchmetric: str,
149+
*args,
150+
**kwargs,
149151
):
150152
"""
151153
Initializes the NNLinearRegressor object.
@@ -212,12 +214,12 @@ def __init__(
212214
hidden_sizes = self._get_hidden_sizes()
213215

214216
# Conditional Layer
215-
self.cond_layer = ConditionalLayer(self._L_in, self._L_cond, self._L_in)
216-
217+
self.cond_layer = ConditionalLayer(self._L_in, self._L_cond, self.hparams.l1)
218+
217219
if batch_norm:
218220
# Add batch normalization layers
219221
layers = []
220-
layer_sizes = [self._L_in] + hidden_sizes
222+
layer_sizes = [self.hparams.l1] + hidden_sizes
221223
for i in range(len(layer_sizes) - 1):
222224
current_layer_size = layer_sizes[i]
223225
next_layer_size = layer_sizes[i + 1]
@@ -230,7 +232,7 @@ def __init__(
230232
layers += [nn.Linear(layer_sizes[-1], self._L_out)]
231233
else:
232234
layers = []
233-
layer_sizes = [self._L_in] + hidden_sizes
235+
layer_sizes = [self.hparams.l1] + hidden_sizes
234236
for i in range(len(layer_sizes) - 1):
235237
current_layer_size = layer_sizes[i]
236238
next_layer_size = layer_sizes[i + 1]
@@ -244,8 +246,6 @@ def __init__(
244246
# Wrap the layers into a sequential container
245247
self.layers = nn.Sequential(*layers)
246248

247-
248-
249249
# Initialization (Xavier, Kaiming, or Default)
250250
self.apply(self._init_weights)
251251

0 commit comments

Comments
 (0)