Skip to content

Commit 6b478cb

Browse files
0.24.13
Kriging internals
1 parent ea9e65f commit 6b478cb

16 files changed

Lines changed: 1126 additions & 364 deletions

notebooks/00_spotPython_tests.ipynb

Lines changed: 249 additions & 55 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.24.12"
10+
version = "0.24.13"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/build/kriging.py

Lines changed: 297 additions & 253 deletions
Large diffs are not rendered by default.

src/spotpython/spot/spot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def objective_function(X, fun_control=None):
157157
min_theta=-3,
158158
max_theta=3,
159159
n_theta=2,
160-
theta_init_zero=True,
160+
theta_init_zero=False,
161161
n_p=1,
162162
optim_p=False,
163163
var_type=["num", "num"],

src/spotpython/utils/init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def surrogate_control_init(
707707
min_Lambda=1e-9,
708708
max_Lambda=1,
709709
seed=124,
710-
theta_init_zero=True,
710+
theta_init_zero=False,
711711
var_type=None,
712712
metric_factorial="canberra",
713713
) -> dict:
@@ -745,7 +745,8 @@ def surrogate_control_init(
745745
seed (int):
746746
The seed to use for the random number generator.
747747
theta_init_zero (bool):
748-
Whether to initialize theta with zero or not. Default is True.
748+
Whether to initialize theta with zero or not. If False, theta is
749+
set to n/(100 * k). Default is False.
749750
var_type (list):
750751
A list containing the type of the variables. Default is None.
751752
Note: Will be set in the Spot class.

test/test_build_Psi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_build_Psi():
8080
S.SigmaSqr = None
8181
S.Lambda = None
8282
# build_Psi() and build_U() are called in fun_likelihood
83-
S.set_de_bounds()
83+
S._set_de_bounds()
8484
if S.model_optimizer.__name__ == "dual_annealing":
8585
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
8686
elif S.model_optimizer.__name__ == "differential_evolution":

test/test_build_U.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_build_U():
7474
S.SigmaSqr = None
7575
S.Lambda = None
7676
# build_Psi() and build_U() are called in fun_likelihood
77-
S.set_de_bounds()
77+
S._set_de_bounds()
7878
if S.model_optimizer.__name__ == "dual_annealing":
7979
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
8080
elif S.model_optimizer.__name__ == "differential_evolution":

test/test_extract_from_bounds.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def test_extract_from_bounds():
22
"""
33
Test extract_from_bounds
44
"""
5-
from spotpython.build.kriging import Kriging
5+
from spotpython.build import Kriging
66
import numpy as np
77
import copy
88
from numpy import linspace, argmin
@@ -52,7 +52,7 @@ def test_extract_from_bounds():
5252
S.SigmaSqr = None
5353
S.Lambda = None
5454
# build_Psi() and build_U() are called in fun_likelihood
55-
S.set_de_bounds()
55+
S._set_de_bounds()
5656
if S.model_optimizer.__name__ == "dual_annealing":
5757
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
5858
elif S.model_optimizer.__name__ == "differential_evolution":
@@ -140,7 +140,7 @@ def test_extract_from_bounds():
140140
S.SigmaSqr = None
141141
S.Lambda = None
142142
# build_Psi() and build_U() are called in fun_likelihood
143-
S.set_de_bounds()
143+
S._set_de_bounds()
144144
if S.model_optimizer.__name__ == "dual_annealing":
145145
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
146146
elif S.model_optimizer.__name__ == "differential_evolution":
@@ -198,7 +198,7 @@ def test_extract_from_bounds():
198198
S.SigmaSqr = None
199199
S.Lambda = None
200200
# build_Psi() and build_U() are called in fun_likelihood
201-
S.set_de_bounds()
201+
S._set_de_bounds()
202202
if S.model_optimizer.__name__ == "dual_annealing":
203203
result = S.model_optimizer(func=S.fun_likelihood, bounds=S.de_bounds)
204204
elif S.model_optimizer.__name__ == "differential_evolution":

test/test_is_any.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from spotpython.build.kriging import Kriging
1+
from spotpython.build import Kriging
22
from numpy import power
33
import numpy as np
44

@@ -8,9 +8,9 @@ def test_is_any():
88
nat_y = np.array([0, 1])
99
n = 1
1010
p = 1
11-
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=False)
11+
S = Kriging(seed=124, n_theta=n, n_p=p, optim_p=True, noise=False, theta_init_zero=True)
1212
S._initialize_variables(nat_X, nat_y)
13-
S.set_variable_types()
14-
S.set_theta_values()
13+
S._set_variable_types()
14+
S._set_theta_values()
1515
assert np.equal(S.__is_any__(power(10.0, S.theta), 0), False)
1616
assert np.equal(S.__is_any__(S.theta, 0), True)

test/test_kriging.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ def test_de_bounds():
5050
Test if the bounds for the DE algorithm are set correctly.
5151
"""
5252
S = Kriging(name="kriging", seed=124)
53-
S.set_de_bounds()
53+
S._set_de_bounds()
5454
assert S.de_bounds == [[-3, 2]]
5555
n = 10
5656
S = Kriging(name="kriging", seed=124, n_theta=n)
57-
S.set_de_bounds()
57+
S._set_de_bounds()
5858
assert len(S.de_bounds) == n
5959
n = 2
6060
p = 4
6161
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True)
62-
S.set_de_bounds()
62+
S._set_de_bounds()
6363
assert len(S.de_bounds) == n + p
6464
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=False)
65-
S.set_de_bounds()
65+
S._set_de_bounds()
6666
assert len(S.de_bounds) == n
6767

6868

@@ -81,19 +81,19 @@ def test_optimize_model():
8181
p = 2
8282
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
8383
S._initialize_variables(nat_X, nat_y)
84-
S.set_variable_types()
85-
S.set_theta_values()
86-
S.initialize_matrices()
87-
S.set_de_bounds()
84+
S._set_variable_types()
85+
S._set_theta_values()
86+
S._initialize_matrices()
87+
S._set_de_bounds()
8888
new_theta_p_Lambda = S.optimize_model()
8989
assert len(new_theta_p_Lambda) == n + p + 1
9090
# no noise, so Lambda is not considered
9191
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=False)
9292
S._initialize_variables(nat_X, nat_y)
93-
S.set_variable_types()
94-
S.set_theta_values()
95-
S.initialize_matrices()
96-
S.set_de_bounds()
93+
S._set_variable_types()
94+
S._set_theta_values()
95+
S._initialize_matrices()
96+
S._set_de_bounds()
9797
new_theta_p_Lambda = S.optimize_model()
9898
assert len(new_theta_p_Lambda) == n + p
9999

@@ -105,10 +105,10 @@ def test_update_log():
105105
p = 2
106106
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
107107
S._initialize_variables(nat_X, nat_y)
108-
S.set_variable_types()
109-
S.set_theta_values()
110-
S.initialize_matrices()
111-
S.set_de_bounds()
108+
S._set_variable_types()
109+
S._set_theta_values()
110+
S._initialize_matrices()
111+
S._set_de_bounds()
112112
_ = S.optimize_model()
113113
S.update_log()
114114
assert len(S.log["negLnLike"]) == 1
@@ -150,7 +150,7 @@ def test_set_variable_types():
150150
p = 2
151151
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
152152
S._initialize_variables(nat_X, nat_y)
153-
S.set_variable_types()
153+
S._set_variable_types()
154154
assert S.var_type == ["num", "num"]
155155
assert S.var_type == ["num", "num"]
156156
assert S.num_mask.all()
@@ -163,7 +163,7 @@ def test_set_variable_types():
163163
p = 1
164164
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
165165
S._initialize_variables(nat_X, nat_y)
166-
S.set_variable_types()
166+
S._set_variable_types()
167167
S.var_type
168168
assert S.var_type == ["num", "num", "num"]
169169

@@ -175,8 +175,8 @@ def set_theta_values():
175175
p = 2
176176
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
177177
S._initialize_variables(nat_X, nat_y)
178-
S.set_variable_types()
179-
S.set_theta_values()
178+
S._set_variable_types()
179+
S._set_theta_values()
180180
assert S.theta.all() == np.array([0.0, 0.0]).all()
181181
nat_X = np.array([[1, 2], [3, 4]])
182182
nat_y = np.array([1, 2])
@@ -185,9 +185,9 @@ def set_theta_values():
185185
p = 2
186186
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
187187
S._initialize_variables(nat_X, nat_y)
188-
S.set_variable_types()
188+
S._set_variable_types()
189189
snt = S.n_theta
190-
S.set_theta_values()
190+
S._set_theta_values()
191191
# since snt == 3, it is not equal to S.n_theta, which is 2 because
192192
# of the correction in the set_theta_values method
193193
assert S.n_theta != snt
@@ -200,9 +200,9 @@ def test_initialize_matrices():
200200
p = 1
201201
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
202202
S._initialize_variables(nat_X, nat_y)
203-
S.set_variable_types()
204-
S.set_theta_values()
205-
S.initialize_matrices()
203+
S._set_variable_types()
204+
S._set_theta_values()
205+
S._initialize_matrices()
206206
# if var(self.nat_y) is > 0, then self.pen_val = self.n * log(var(self.nat_y)) + 1e4
207207
# else self.pen_val = self.n * var(self.nat_y) + 1e4
208208
assert S.pen_val == nat_X.shape[0] * log(var(S.nat_y)) + 1e4
@@ -214,9 +214,9 @@ def test_initialize_matrices():
214214
p = 1
215215
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)
216216
S._initialize_variables(nat_X, nat_y)
217-
S.set_variable_types()
218-
S.set_theta_values()
219-
S.initialize_matrices()
217+
S._set_variable_types()
218+
S._set_theta_values()
219+
S._initialize_matrices()
220220
# if var(self.nat_y) is > 0, then self.pen_val = self.n * log(var(self.nat_y)) + 1e4
221221
# else self.pen_val = self.n * var(self.nat_y) + 1e4
222222
assert S.pen_val == nat_X.shape[0] * (var(S.nat_y)) + 1e4
@@ -233,10 +233,10 @@ def test_fun_likelihood():
233233
p = 1
234234
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=False)
235235
S._initialize_variables(nat_X, nat_y)
236-
S.set_variable_types()
237-
S.set_theta_values()
238-
S.initialize_matrices()
239-
S.set_de_bounds()
236+
S._set_variable_types()
237+
S._set_theta_values()
238+
S._initialize_matrices()
239+
S._set_de_bounds()
240240
new_theta_p_Lambda = S.optimize_model()
241241
S.extract_from_bounds(new_theta_p_Lambda)
242242
S.build_Psi()
@@ -251,9 +251,9 @@ def test_likelihood():
251251
p = 1
252252
S = Kriging(name="kriging", seed=124, n_theta=n, n_p=p, optim_p=True, noise=False, theta_init_zero=True)
253253
S._initialize_variables(nat_X, nat_y)
254-
S.set_variable_types()
255-
S.set_theta_values()
256-
S.initialize_matrices()
254+
S._set_variable_types()
255+
S._set_theta_values()
256+
S._initialize_matrices()
257257
S.build_Psi()
258258
S.build_U()
259259
S.likelihood()

0 commit comments

Comments
 (0)