Skip to content

Commit 8cc5ce0

Browse files
0.17.0
design
1 parent 8603f4f commit 8cc5ce0

48 files changed

Lines changed: 197 additions & 325 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

RELEASE_NOTES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
spotpython-0.17.0
2+
3+
- designs.py and spacefilling.py:
4+
Naming Conventions: The class names have been capitalized to follow the PEP 8 convention for class naming:
5+
1. `designs` -> `Designs`
6+
2. `spacefilling` -> `SpaceFilling`
7+
8+
- The dimension of the design, k (int), must be specified by the user. There is not default dimension "2" anymore.
9+
10+
111
spotpython-0.16.19:
212

313
- kriging.py update completed

pyproject.toml

Lines changed: 2 additions & 2 deletions
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.16.19"
10+
version = "0.17.0"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]
@@ -71,7 +71,7 @@ namespaces = true
7171
where = ["src"]
7272

7373
[tool.black]
74-
line-length = 120
74+
line-length = 200
7575
target-version = ["py312"]
7676

7777
[tool.pytest.ini_options]

src/spotpython/build/kriging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from scipy.optimize import differential_evolution
1616
from scipy.linalg import cholesky as scipy_cholesky
1717
import pylab
18-
from spotpython.design.spacefilling import spacefilling
18+
from spotpython.design.spacefilling import SpaceFilling
1919
from spotpython.build.surrogates import surrogates
2020
from scipy.spatial.distance import squareform
2121
from scipy.spatial.distance import pdist
@@ -725,7 +725,7 @@ def initialize_matrices(self) -> None:
725725
The `pen_val` attribute is initialized as the natural logarithm of the
726726
variance of `nat_y`, multiplied by `n`, plus 1e4.
727727
The `negLnLike`, `LnDetPsi`, `mu`, `U`, `SigmaSqr`, and `Lambda` attributes are all set to None.
728-
The `gen` attribute is initialized using the `spacefilling` function with arguments `k` and `seed`.
728+
The `gen` attribute is initialized using the `SpaceFilling` function with arguments `k` and `seed`.
729729
The `Psi` attribute is initialized as a zero matrix with shape `(n, n)` and dtype `float64`.
730730
The `psi` attribute is initialized as a zero matrix with shape `(n, 1)`.
731731
The `one` attribute is initialized as a list of ones with length `n`.
@@ -780,7 +780,7 @@ def initialize_matrices(self) -> None:
780780
self.Lambda = None
781781

782782
# Initialize generator
783-
self.gen = spacefilling(k=self.k, seed=self.seed)
783+
self.gen = SpaceFilling(k=self.k, seed=self.seed)
784784
logger.debug("In initialize_matrices(): self.gen: %s", self.gen)
785785

786786
# Initialize matrix Psi and vector psi

src/spotpython/data/base.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ def __repr__(self):
240240
l_len = max(map(len, self._repr_content.keys()))
241241
r_len = max(map(len, self._repr_content.values()))
242242

243-
out = f"{self.desc}\n\n" + "\n".join(
244-
k.rjust(l_len) + " " + v.ljust(r_len) for k, v in self._repr_content.items()
245-
)
243+
out = f"{self.desc}\n\n" + "\n".join(k.rjust(l_len) + " " + v.ljust(r_len) for k, v in self._repr_content.items())
246244

247245
if "Parameters\n ----------" in self.__doc__:
248246
params = re.split(
@@ -361,11 +359,7 @@ def _get_params(self) -> typing.Dict[str, typing.Any]:
361359
'n_outputs': 1,
362360
'sparse': False}
363361
"""
364-
return {
365-
name: getattr(self, name)
366-
for name, param in inspect.signature(self.__init__).parameters.items() # type: ignore
367-
if param.kind != param.VAR_KEYWORD
368-
}
362+
return {name: getattr(self, name) for name, param in inspect.signature(self.__init__).parameters.items() if param.kind != param.VAR_KEYWORD} # type: ignore
369363

370364

371365
class FileConfig(Config):

src/spotpython/data/california_housing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ class CaliforniaHousing(Dataset):
5757
print(f"Targets: {targets}")
5858
"""
5959

60-
def __init__(
61-
self, feature_type: torch.dtype = torch.float, target_type: torch.dtype = torch.float, train: bool = True
62-
) -> None:
60+
def __init__(self, feature_type: torch.dtype = torch.float, target_type: torch.dtype = torch.float, train: bool = True) -> None:
6361
super().__init__()
6462
self.feature_type = feature_type
6563
self.target_type = target_type

src/spotpython/data/csvdataset.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,15 @@ def _load_data(self) -> tuple:
6969
# Apply OrdinalEncoder to non-numerical feature columns
7070
if non_numerical_columns:
7171
if self.oe is None:
72-
raise ValueError(
73-
f"\n!!! non_numerical_columns in data: {non_numerical_columns}"
74-
"\nOrdinalEncoder object oe must be provided for encoding non-numerical columns"
75-
)
72+
raise ValueError(f"\n!!! non_numerical_columns in data: {non_numerical_columns}" "\nOrdinalEncoder object oe must be provided for encoding non-numerical columns")
7673
feature_df[non_numerical_columns] = self.oe.fit_transform(feature_df[non_numerical_columns])
7774

7875
target_df = df[self.target_column]
7976

8077
# Check if the target column is non-numerical using dtype
8178
if not pd.api.types.is_numeric_dtype(target_df):
8279
if self.le is None:
83-
raise ValueError(
84-
f"\n!!! The target column '{self.target_column}' is non-numerical"
85-
"\nLabelEncoder object le must be provided for encoding non-numerical target"
86-
)
80+
raise ValueError(f"\n!!! The target column '{self.target_column}' is non-numerical" "\nLabelEncoder object le must be provided for encoding non-numerical target")
8781
target_df = self.le.fit_transform(target_df)
8882

8983
# Convert DataFrames to NumPy arrays and then to PyTorch tensors

src/spotpython/data/diabetes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ class Diabetes(Dataset):
5252
print(f"Targets: {targets}")
5353
"""
5454

55-
def __init__(
56-
self, feature_type: torch.dtype = torch.float, target_type: torch.dtype = torch.float, train: bool = True
57-
) -> None:
55+
def __init__(self, feature_type: torch.dtype = torch.float, target_type: torch.dtype = torch.float, train: bool = True) -> None:
5856
super().__init__()
5957
self.feature_type = feature_type
6058
self.target_type = target_type

src/spotpython/data/lightcrossvalidationdatamodule.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def setup(self, stage: Optional[str] = None) -> None:
9696
self.data_train = [(self.scaler.transform(data), target) for data, target in self.data_train]
9797
data_tensors_train = [data.clone().detach() for data, target in self.data_train]
9898
target_tensors_train = [target.clone().detach() for data, target in self.data_train]
99-
self.data_train = TensorDataset(
100-
torch.stack(data_tensors_train).squeeze(1), torch.stack(target_tensors_train)
101-
)
99+
self.data_train = TensorDataset(torch.stack(data_tensors_train).squeeze(1), torch.stack(target_tensors_train))
102100
self.data_val = [(self.scaler.transform(data), target) for data, target in self.data_val]
103101
data_tensors_val = [data.clone().detach() for data, target in self.data_val]
104102
target_tensors_val = [target.clone().detach() for data, target in self.data_val]

src/spotpython/data/lightdatamodule.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def setup(self, stage: Optional[str] = None) -> None:
160160
if self.verbosity > 0:
161161
print(f"train_size: {train_size}, val_size: {val_size} used for train & val data.")
162162
generator_fit = torch.Generator().manual_seed(self.test_seed)
163-
self.data_train, self.data_val, _ = random_split(
164-
self.data_full, [train_size, val_size, test_size], generator=generator_fit
165-
)
163+
self.data_train, self.data_val, _ = random_split(self.data_full, [train_size, val_size, test_size], generator=generator_fit)
166164
if self.scaler is not None:
167165
# Fit the scaler on training data
168166
scaler_train_data = torch.stack([self.data_train[i][0] for i in range(len(self.data_train))]).squeeze(1)
@@ -189,9 +187,7 @@ def setup(self, stage: Optional[str] = None) -> None:
189187
if self.verbosity > 0:
190188
print(f"test_size: {test_size} used for predict dataset.")
191189
generator_predict = torch.Generator().manual_seed(self.test_seed)
192-
self.data_predict, _ = random_split(
193-
self.data_full, [test_size, full_train_size], generator=generator_predict
194-
)
190+
self.data_predict, _ = random_split(self.data_full, [test_size, full_train_size], generator=generator_predict)
195191
if self.scaler is not None:
196192
# Transform the predict data
197193
self.data_predict = self.transform_dataset(self.data_predict)

src/spotpython/design/designs.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,41 @@
22
from typing import List
33

44

5-
class designs:
5+
class Designs:
66
"""
7-
Super class for all design classes (factorial and spacefilling).
7+
Super class for all design classes (factorial and space-filling).
88
99
Attributes:
10-
designs (List):
11-
A list of designs.
12-
k (int):
13-
The dimension of the design.
14-
seed (int):
15-
The seed for the random number generator.
16-
rng (Generator):
17-
A random number generator instance.
10+
designs (List): A list of design instances.
11+
k (int): The dimension of the design.
12+
seed (int): The seed for the random number generator.
13+
rng (Generator): A random number generator instance.
1814
"""
1915

20-
def __init__(self, k: int = 2, seed: int = 123) -> None:
16+
def __init__(self, k: int, seed: int = 123) -> None:
2117
"""
2218
Initializes a Designs object with the given dimension and seed.
2319
2420
Args:
25-
k (int):
26-
The dimension of the design. Defaults to 2.
27-
seed (int):
28-
The seed for the random number generator. Defaults to 123.
21+
k (int): The dimension of the design.
22+
seed (int): The seed for the random number generator. Defaults to 123.
23+
24+
Raises:
25+
ValueError: If 'k' is not an integer.
26+
2927
Examples:
30-
>>> designs = designs(k=2, seed=123)
28+
>>> from spotpython.design.designs import Designs
29+
>>> designs = Designs(k=2, seed=123)
3130
>>> designs.get_dim()
3231
2
33-
3432
"""
35-
self.designs: List = []
33+
if not isinstance(k, int):
34+
raise ValueError("The dimension of the design must be an integer.")
35+
3636
self.k: int = k
3737
self.seed: int = seed
3838
self.rng = default_rng(self.seed)
39+
self.designs: List = []
3940

4041
def get_dim(self) -> int:
4142
"""

0 commit comments

Comments
 (0)