Skip to content

Commit 97f108f

Browse files
0.14.31
1 parent 4f6fec7 commit 97f108f

49 files changed

Lines changed: 760 additions & 873 deletions

Some content is hidden

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

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.30"
10+
version = "0.14.31"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import pytest
21
from spotPython.light.regression.netlightregression import NetLightRegression
32
from spotPython.utils.init import fun_control_init
43
from spotPython.hyperdict.light_hyper_dict import LightHyperDict
54
from spotPython.hyperparameters.values import add_core_model_to_fun_control
65

6+
77
def test_add_core_model_to_fun_control():
88
fun_control = fun_control_init()
9-
add_core_model_to_fun_control(core_model=NetLightRegression,
10-
fun_control=fun_control,
11-
hyper_dict=LightHyperDict)
9+
add_core_model_to_fun_control(core_model=NetLightRegression, fun_control=fun_control, hyper_dict=LightHyperDict)
1210
assert fun_control["core_model"].__name__ == "NetLightRegression"
1311
assert isinstance(fun_control["core_model_hyper_dict"], dict)
14-
15-
16-
if __name__ == "__main__":
17-
pytest.main(["-v", __file__])

test/test_aggregate_mean_var.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ def test_aggregate_mean_var_var():
1919
"""
2020
import numpy as np
2121
from spotPython.utils.aggregate import aggregate_mean_var
22-
X_1 = np.ones((2,3))
22+
23+
X_1 = np.ones((2, 3))
2324
y_1 = np.sum(X_1, axis=1)
2425
y_2 = 2 * y_1
25-
X_2 = np.append(X_1, 2*X_1, axis=0)
26+
X_2 = np.append(X_1, 2 * X_1, axis=0)
2627
X = np.append(X_2, X_1, axis=0)
2728
y = np.append(y_1, y_2, axis=0)
2829
y = np.append(y, y_2, axis=0)
29-
Z = aggregate_mean_var(X,y)
30-
assert (Z[0] == np.array([[1., 1., 1.],[2., 2., 2.]])).all()
31-
assert (Z[1] == np.array([4.5, 6. ])).all()
32-
assert (Z[2] == np.array([3., 0.])).all()
30+
Z = aggregate_mean_var(X, y)
31+
assert (Z[0] == np.array([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]])).all()
32+
assert (Z[1] == np.array([4.5, 6.0])).all()
33+
assert (Z[2] == np.array([3.0, 0.0])).all()

test/test_branin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ def test_branin():
44
"""
55
from spotPython.fun.objectivefunctions import analytical
66
import numpy as np
7+
78
pi = np.pi
89
# some value, e.g. at 0,0:
910
X_0 = np.array([[0, 0]])
1011
# there are 3 min values: disregarding rounding errors, they
1112
# should be the same for the following three points:
1213
X_1 = np.array([[-pi, 12.275], [pi, 2.275], [9.42478, 2.475]])
13-
# first of the three points should be identical to X_0, the
14+
# first of the three points should be identical to X_0, the
1415
# other two should be shifted by 10 in y-direction (plus and minus)
15-
X_2 = np.array([[0,0,0], [0,0,1], [0,0,2]])
16+
X_2 = np.array([[0, 0, 0], [0, 0, 1], [0, 0, 2]])
1617
fun = analytical()
1718
y_0 = fun.fun_branin(X_0)
1819
y_1 = fun.fun_branin(X_1)
1920
y_2 = fun.fun_branin_factor(X_2)
2021

21-
assert round(y_1[0], 2) == round(y_1[1],2)
22-
assert round(y_1[0], 2) == round(y_1[2],2)
22+
assert round(y_1[0], 2) == round(y_1[1], 2)
23+
assert round(y_1[0], 2) == round(y_1[2], 2)
2324

2425
assert (y_2[0] == y_0)[0]
2526
assert (y_2[1] == y_0 + 10)[0]
2627
assert (y_2[2] == y_0 - 10)[0]
27-

test/test_build_Psi.py

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,49 @@ def test_build_Psi():
55
from spotPython.build.kriging import Kriging
66
import numpy as np
77
import copy
8-
import matplotlib.pyplot as plt
9-
from numpy import append, ndarray, multiply, isinf, linspace, meshgrid, ravel, argmin
10-
from numpy import ones, zeros, arange, log, var, float64
11-
from numpy import spacing, empty_like
8+
from numpy import argmin
9+
from numpy import ones, zeros, log, var, float64
10+
from numpy import empty_like
1211
from numpy import array
1312
from spotPython.design.spacefilling import spacefilling
14-
import spotPython
1513
from spotPython.fun.objectivefunctions import analytical
1614
from spotPython.spot import spot
1715
from spotPython.utils.repair import repair_non_numeric
18-
from spotPython.utils.init import fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init
16+
from spotPython.utils.init import (
17+
fun_control_init,
18+
surrogate_control_init,
19+
design_control_init,
20+
)
1921

2022
# number of points:
2123
ni = 7
2224

2325
fun = analytical().fun_sphere
2426
fun_control = fun_control_init(
25-
lower = np.array([-1,-1]),
26-
upper = np.array([1,1]),
27-
fun_evals = 25,
28-
noise = False,
29-
log_level = 50)
30-
design_control= design_control_init(init_size=ni)
27+
lower=np.array([-1, -1]), upper=np.array([1, 1]), fun_evals=25, noise=False, log_level=50
28+
)
29+
design_control = design_control_init(init_size=ni)
3130
surrogate_control = surrogate_control_init()
3231

3332
# Spot: to generate initial design
34-
S_spot = spot.Spot(fun=fun,
35-
fun_control=fun_control,
36-
design_control=design_control,
37-
surrogate_control=surrogate_control)
33+
S_spot = spot.Spot(
34+
fun=fun, fun_control=fun_control, design_control=design_control, surrogate_control=surrogate_control
35+
)
3836

39-
X = S_spot.generate_design(size=S_spot.design_control["init_size"],
40-
repeats=S_spot.design_control["repeats"],
41-
lower=S_spot.lower,
42-
upper=S_spot.upper)
37+
X = S_spot.generate_design(
38+
size=S_spot.design_control["init_size"],
39+
repeats=S_spot.design_control["repeats"],
40+
lower=S_spot.lower,
41+
upper=S_spot.upper,
42+
)
4343
X = repair_non_numeric(X, S_spot.var_type)
4444
# (S-3): Eval initial design:
4545
y = fun(X)
4646
S_spot.min_y = min(y)
4747
S_spot.min_X = X[argmin(y)]
4848
# Kriging:
4949

50-
51-
S = Kriging(name='kriging',
52-
seed=124,
53-
n_theta=2,
54-
noise=True,
55-
cod_type="norm")
50+
S = Kriging(name="kriging", seed=124, n_theta=2, noise=True, cod_type="norm")
5651
S.nat_X = copy.deepcopy(X)
5752
S.nat_y = copy.deepcopy(y)
5853
S.n = S.nat_X.shape[0]
@@ -62,7 +57,7 @@ def test_build_Psi():
6257
# assume all variable types are "num" if "num" is
6358
# specified once:
6459
if len(S.var_type) == 1:
65-
S.var_type = S.var_type * S.k
60+
S.var_type = S.var_type * S.k
6661
S.num_mask = array(list(map(lambda x: x == "num", S.var_type)))
6762
S.factor_mask = array(list(map(lambda x: x == "factor", S.var_type)))
6863
S.int_mask = array(list(map(lambda x: x == "int", S.var_type)))
@@ -86,25 +81,21 @@ def test_build_Psi():
8681
S.Lambda = None
8782
# build_Psi() and build_U() are called in fun_likelihood
8883
S.set_de_bounds()
89-
if S.model_optimizer.__name__ == 'dual_annealing':
90-
result = S.model_optimizer(func=S.fun_likelihood,
91-
bounds=S.de_bounds)
92-
elif S.model_optimizer.__name__ == 'differential_evolution':
93-
result = S.model_optimizer(func=S.fun_likelihood,
94-
bounds=S.de_bounds,
95-
maxiter=S.model_fun_evals,
96-
seed=S.seed)
97-
elif S.model_optimizer.__name__ == 'direct':
98-
result = S.model_optimizer(func=S.fun_likelihood,
99-
bounds=S.de_bounds,
100-
# maxfun=S.model_fun_evals,
101-
eps=1e-2)
102-
elif S.model_optimizer.__name__ == 'shgo':
103-
result = S.model_optimizer(func=S.fun_likelihood,
104-
bounds=S.de_bounds)
105-
elif S.model_optimizer.__name__ == 'basinhopping':
106-
result = S.model_optimizer(func=S.fun_likelihood,
107-
x0=S.min_X)
84+
if S.model_optimizer.__name__ == "dual_annealing":
85+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
86+
elif S.model_optimizer.__name__ == "differential_evolution":
87+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds, maxiter=S.model_fun_evals, seed=S.seed)
88+
elif S.model_optimizer.__name__ == "direct":
89+
result = S.model_optimizer(
90+
func=S.fun_likelihood,
91+
bounds=S.de_bounds,
92+
# maxfun=S.model_fun_evals,
93+
eps=1e-2,
94+
)
95+
elif S.model_optimizer.__name__ == "shgo":
96+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
97+
elif S.model_optimizer.__name__ == "basinhopping":
98+
result = S.model_optimizer(func=S.fun_likelihood, x0=S.min_X)
10899
else:
109100
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
110101
# Finally, set new theta and p values and update the surrogate again
@@ -115,4 +106,3 @@ def test_build_Psi():
115106
assert S.Psi.shape[0] == ni
116107
assert S.Psi.shape[1] == ni
117108
assert (S.Psi == S.Psi.T).all()
118-

test/test_build_U.py

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,43 @@ def test_build_U():
55
from spotPython.build.kriging import Kriging
66
import numpy as np
77
import copy
8-
import matplotlib.pyplot as plt
9-
from numpy import append, ndarray, multiply, isinf, linspace, meshgrid, ravel, argmin
10-
from numpy import ones, zeros, arange, log, var, float64
11-
from numpy import spacing, empty_like
8+
from numpy import argmin
9+
from numpy import ones, zeros, log, var, float64
10+
from numpy import empty_like
1211
from numpy import array
1312
from spotPython.design.spacefilling import spacefilling
14-
import spotPython
1513
from spotPython.fun.objectivefunctions import analytical
1614
from spotPython.spot import spot
1715
from spotPython.utils.repair import repair_non_numeric
18-
from spotPython.utils.init import fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init
16+
from spotPython.utils.init import (
17+
fun_control_init,
18+
design_control_init,
19+
)
1920

2021
# number of points:
2122
ni = 7
2223

2324
fun = analytical().fun_sphere
2425
fun_control = fun_control_init(
25-
lower = np.array([-1,-1]),
26-
upper = np.array([1,1]),
27-
fun_evals = 25,
28-
noise = False,
29-
log_level = 50)
30-
design_control= design_control_init(init_size=ni)
26+
lower=np.array([-1, -1]), upper=np.array([1, 1]), fun_evals=25, noise=False, log_level=50
27+
)
28+
design_control = design_control_init(init_size=ni)
3129
# Spot: to generate initial design
32-
S_spot = spot.Spot(fun=fun,
33-
fun_control=fun_control,
34-
design_control=design_control)
30+
S_spot = spot.Spot(fun=fun, fun_control=fun_control, design_control=design_control)
3531

36-
X = S_spot.generate_design(size=S_spot.design_control["init_size"],
37-
repeats=S_spot.design_control["repeats"],
38-
lower=S_spot.lower,
39-
upper=S_spot.upper)
32+
X = S_spot.generate_design(
33+
size=S_spot.design_control["init_size"],
34+
repeats=S_spot.design_control["repeats"],
35+
lower=S_spot.lower,
36+
upper=S_spot.upper,
37+
)
4038
X = repair_non_numeric(X, S_spot.var_type)
4139
# (S-3): Eval initial design:
4240
y = fun(X)
4341
S_spot.min_y = min(y)
4442
S_spot.min_X = X[argmin(y)]
4543
# Kriging:
46-
S = Kriging(name='kriging',
47-
seed=124,
48-
n_theta=2,
49-
noise=True,
50-
cod_type="norm")
44+
S = Kriging(name="kriging", seed=124, n_theta=2, noise=True, cod_type="norm")
5145
S.nat_X = copy.deepcopy(X)
5246
S.nat_y = copy.deepcopy(y)
5347
S.n = S.nat_X.shape[0]
@@ -57,7 +51,7 @@ def test_build_U():
5751
# assume all variable types are "num" if "num" is
5852
# specified once:
5953
if len(S.var_type) == 1:
60-
S.var_type = S.var_type * S.k
54+
S.var_type = S.var_type * S.k
6155
S.num_mask = array(list(map(lambda x: x == "num", S.var_type)))
6256
S.factor_mask = array(list(map(lambda x: x == "factor", S.var_type)))
6357
S.int_mask = array(list(map(lambda x: x == "int", S.var_type)))
@@ -81,25 +75,21 @@ def test_build_U():
8175
S.Lambda = None
8276
# build_Psi() and build_U() are called in fun_likelihood
8377
S.set_de_bounds()
84-
if S.model_optimizer.__name__ == 'dual_annealing':
85-
result = S.model_optimizer(func=S.fun_likelihood,
86-
bounds=S.de_bounds)
87-
elif S.model_optimizer.__name__ == 'differential_evolution':
88-
result = S.model_optimizer(func=S.fun_likelihood,
89-
bounds=S.de_bounds,
90-
maxiter=S.model_fun_evals,
91-
seed=S.seed)
92-
elif S.model_optimizer.__name__ == 'direct':
93-
result = S.model_optimizer(func=S.fun_likelihood,
94-
bounds=S.de_bounds,
95-
# maxfun=S.model_fun_evals,
96-
eps=1e-2)
97-
elif S.model_optimizer.__name__ == 'shgo':
98-
result = S.model_optimizer(func=S.fun_likelihood,
99-
bounds=S.de_bounds)
100-
elif S.model_optimizer.__name__ == 'basinhopping':
101-
result = S.model_optimizer(func=S.fun_likelihood,
102-
x0=S.min_X)
78+
if S.model_optimizer.__name__ == "dual_annealing":
79+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
80+
elif S.model_optimizer.__name__ == "differential_evolution":
81+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds, maxiter=S.model_fun_evals, seed=S.seed)
82+
elif S.model_optimizer.__name__ == "direct":
83+
result = S.model_optimizer(
84+
func=S.fun_likelihood,
85+
bounds=S.de_bounds,
86+
# maxfun=S.model_fun_evals,
87+
eps=1e-2,
88+
)
89+
elif S.model_optimizer.__name__ == "shgo":
90+
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
91+
elif S.model_optimizer.__name__ == "basinhopping":
92+
result = S.model_optimizer(func=S.fun_likelihood, x0=S.min_X)
10393
else:
10494
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
10595
# Finally, set new theta and p values and update the surrogate again
@@ -109,4 +99,4 @@ def test_build_U():
10999
S.build_Psi()
110100
S.build_U()
111101
assert S.U.shape[0] == ni
112-
assert S.U.shape[1] == ni
102+
assert S.U.shape[1] == ni

test/test_build_psi_vec.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ def test_build_psi_vec():
55
import numpy as np
66
from spotPython.build.kriging import Kriging
77

8-
X_train = np.array([[1., 2.],
9-
[2., 4.],
10-
[3., 6.]])
11-
y_train = np.array([1., 2., 3.])
8+
X_train = np.array([[1.0, 2.0], [2.0, 4.0], [3.0, 6.0]])
9+
y_train = np.array([1.0, 2.0, 3.0])
1210

13-
S = Kriging(name='kriging',
14-
seed=123,
15-
log_level=50,
16-
n_theta=1,
17-
noise=False,
18-
cod_type="norm")
11+
S = Kriging(name="kriging", seed=123, log_level=50, n_theta=1, noise=False, cod_type="norm")
1912
S.fit(X_train, y_train)
2013

2114
# force theta to simple values:
2215
S.theta = np.array([0.0])
23-
cod_x = np.array([1., 0.])
16+
cod_x = np.array([1.0, 0.0])
2417
S.psi = np.zeros((S.n, 1))
2518
S.build_psi_vec(cod_x)
26-
res = np.array([[np.exp(-4)],
27-
[np.exp(-17)],
28-
[np.exp(-40)]])
19+
res = np.array([[np.exp(-4)], [np.exp(-17)], [np.exp(-40)]])
2920

3021
assert np.array_equal(S.psi, res)

test/test_california_housing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ def test_california_housing():
66
dataset = CaliforniaHousing()
77

88
# Expected outputs
9-
expected_names = [
10-
'MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population',
11-
'AveOccup', 'Latitude', 'Longitude'
12-
]
9+
expected_names = ["MedInc", "HouseAge", "AveRooms", "AveBedrms", "Population", "AveOccup", "Latitude", "Longitude"]
1310
expected_length = 20640
1411

1512
# Assert if get_names() returns the correct feature names
1613
assert dataset.get_names() == expected_names, "The feature names do not match the expected values."
1714

1815
# Assert if the length of the dataset is correct
19-
assert len(dataset) == expected_length, "The length of the dataset does not match the expected value."
16+
assert len(dataset) == expected_length, "The length of the dataset does not match the expected value."

0 commit comments

Comments
 (0)