Skip to content

Commit 1c051a4

Browse files
0.19.0
Analytical
1 parent 612ee27 commit 1c051a4

28 files changed

Lines changed: 114 additions & 105 deletions

RELEASE_NOTES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
spotpython 0.19.0:
2+
3+
- objectivefunctions.py:
4+
- class analytical capitalized to analytical
5+
6+
- kriging.py:
7+
exp_imp() function updated. Using (y_min - y0) / s0 to ensure that the value is a scalar.
8+
19
spotpython 0.18.15:
210

311
- "numpy>=2.1.0" changed to "numpy>=2.0.0 updated in the dependencies to enable tensorflow compatibility

notebooks/00_spotPython_tests.ipynb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"source": [
7272
"import numpy as np\n",
7373
"from math import inf\n",
74-
"from spotpython.fun.objectivefunctions import analytical\n",
74+
"from spotpython.fun.objectivefunctions import Analytical\n",
7575
"from spotpython.spot import spot\n",
7676
"# number of initial points:\n",
7777
"ni = 7\n",
@@ -1204,7 +1204,7 @@
12041204
"metadata": {},
12051205
"outputs": [],
12061206
"source": [
1207-
"from spotpython.fun.objectivefunctions import analytical\n",
1207+
"from spotpython.fun.objectivefunctions import Analytical\n",
12081208
"import numpy as np\n",
12091209
"y = np.array([1, 2, 3, 4, 5])\n",
12101210
"fun = analytical(sigma=1.0, seed=123)\n",
@@ -1217,7 +1217,7 @@
12171217
"metadata": {},
12181218
"outputs": [],
12191219
"source": [
1220-
"from spotpython.fun.objectivefunctions import analytical\n",
1220+
"from spotpython.fun.objectivefunctions import Analytical\n",
12211221
"import numpy as np\n",
12221222
"print(np.array([1, 2, 3, 4, 5]))\n",
12231223
"\n"
@@ -1231,7 +1231,7 @@
12311231
"source": [
12321232
"import numpy as np\n",
12331233
"from math import inf\n",
1234-
"from spotpython.fun.objectivefunctions import analytical\n",
1234+
"from spotpython.fun.objectivefunctions import Analytical\n",
12351235
"from spotpython.spot import spot\n",
12361236
"from scipy.optimize import shgo\n",
12371237
"from scipy.optimize import direct\n",
@@ -1337,7 +1337,7 @@
13371337
"metadata": {},
13381338
"outputs": [],
13391339
"source": [
1340-
"from spotpython.fun.objectivefunctions import analytical\n",
1340+
"from spotpython.fun.objectivefunctions import Analytical\n",
13411341
"import numpy as np\n",
13421342
"X = np.array([[0, 0, 0], [0, 0, 1], [0, 0, 2]])\n",
13431343
"fun = analytical()\n",
@@ -1363,7 +1363,7 @@
13631363
"metadata": {},
13641364
"outputs": [],
13651365
"source": [
1366-
"from spotpython.fun.objectivefunctions import analytical\n",
1366+
"from spotpython.fun.objectivefunctions import Analytical\n",
13671367
"import numpy as np\n",
13681368
"pi = np.pi\n",
13691369
"X_0 = np.array([[0, 0]])\n",
@@ -1938,7 +1938,7 @@
19381938
"source": [
19391939
"import pytest\n",
19401940
"import numpy as np\n",
1941-
"from spotpython.fun.objectivefunctions import analytical\n",
1941+
"from spotpython.fun.objectivefunctions import Analytical\n",
19421942
"from spotpython.spot import spot\n",
19431943
"from spotpython.utils.init import (\n",
19441944
" fun_control_init, surrogate_control_init, design_control_init\n",
@@ -1983,7 +1983,7 @@
19831983
"source": [
19841984
"import pytest\n",
19851985
"import numpy as np\n",
1986-
"from spotpython.fun.objectivefunctions import analytical\n",
1986+
"from spotpython.fun.objectivefunctions import Analytical\n",
19871987
"from spotpython.spot import spot\n",
19881988
"from spotpython.utils.init import (\n",
19891989
" fun_control_init, surrogate_control_init, design_control_init\n",
@@ -2099,7 +2099,7 @@
20992099
"source": [
21002100
"import numpy as np\n",
21012101
"from spotpython.spot import spot\n",
2102-
"from spotpython.fun.objectivefunctions import analytical\n",
2102+
"from spotpython.fun.objectivefunctions import Analytical\n",
21032103
"from spotpython.utils.init import fun_control_init, design_control_init, surrogate_control_init\n",
21042104
"\n",
21052105
"fun = analytical().fun_branin\n",
@@ -2154,7 +2154,7 @@
21542154
"source": [
21552155
"import numpy as np\n",
21562156
"from math import inf\n",
2157-
"from spotpython.fun.objectivefunctions import analytical\n",
2157+
"from spotpython.fun.objectivefunctions import Analytical\n",
21582158
"from spotpython.spot import spot\n",
21592159
"from scipy.optimize import shgo\n",
21602160
"from scipy.optimize import direct\n",
@@ -2232,7 +2232,7 @@
22322232
"metadata": {},
22332233
"outputs": [],
22342234
"source": [
2235-
"from spotpython.fun.objectivefunctions import analytical\n",
2235+
"from spotpython.fun.objectivefunctions import Analytical\n",
22362236
"fun = analytical().fun_sphere\n",
22372237
"from spotpython.design.spacefilling import spacefilling\n",
22382238
"design = spacefilling(2)\n",
@@ -3074,7 +3074,7 @@
30743074
" design_control_init,\n",
30753075
" surrogate_control_init,\n",
30763076
" optimizer_control_init)\n",
3077-
"from spotpython.fun.objectivefunctions import analytical\n",
3077+
"from spotpython.fun.objectivefunctions import Analytical\n",
30783078
"\n",
30793079
"def test_file_save_load():\n",
30803080
" fun = analytical().fun_branin\n",
@@ -3250,7 +3250,7 @@
32503250
" design_control_init,\n",
32513251
" surrogate_control_init,\n",
32523252
" optimizer_control_init)\n",
3253-
"from spotpython.fun.objectivefunctions import analytical\n",
3253+
"from spotpython.fun.objectivefunctions import Analytical\n",
32543254
"fun = analytical().fun_branin\n",
32553255
"fun_control = fun_control_init(\n",
32563256
" PREFIX=\"branin\",\n",
@@ -3432,7 +3432,7 @@
34323432
"source": [
34333433
"from spotpython.design.spacefilling import spacefilling\n",
34343434
"from spotpython.build.kriging import Kriging\n",
3435-
"from spotpython.fun.objectivefunctions import analytical\n",
3435+
"from spotpython.fun.objectivefunctions import Analytical\n",
34363436
"import numpy as np"
34373437
]
34383438
},
@@ -3576,7 +3576,7 @@
35763576
"outputs": [],
35773577
"source": [
35783578
"import numpy as np\n",
3579-
"from spotpython.fun.objectivefunctions import analytical\n",
3579+
"from spotpython.fun.objectivefunctions import Analytical\n",
35803580
"from spotpython.spot import spot\n",
35813581
"from spotpython.utils.init import (\n",
35823582
" fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init\n",
@@ -3945,7 +3945,7 @@
39453945
"outputs": [],
39463946
"source": [
39473947
"import numpy as np\n",
3948-
"from spotpython.fun.objectivefunctions import analytical\n",
3948+
"from spotpython.fun.objectivefunctions import Analytical\n",
39493949
"from spotpython.spot import spot\n",
39503950
"from spotpython.utils.init import (\n",
39513951
" fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init\n",
@@ -4591,7 +4591,7 @@
45914591
"outputs": [],
45924592
"source": [
45934593
"import numpy as np\n",
4594-
"from spotpython.fun.objectivefunctions import analytical\n",
4594+
"from spotpython.fun.objectivefunctions import Analytical\n",
45954595
"from spotpython.spot import spot\n",
45964596
"from spotpython.utils.init import fun_control_init\n",
45974597
"fun = analytical().fun_sphere\n",
@@ -4653,7 +4653,7 @@
46534653
"outputs": [],
46544654
"source": [
46554655
"import numpy as np\n",
4656-
"from spotpython.fun.objectivefunctions import analytical\n",
4656+
"from spotpython.fun.objectivefunctions import Analytical\n",
46574657
"from spotpython.spot import spot\n",
46584658
"from spotpython.utils.init import (\n",
46594659
" fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init\n",
@@ -4688,7 +4688,7 @@
46884688
"import numpy as np\n",
46894689
"from spotpython.spot import spot\n",
46904690
"from spotpython.utils.init import design_control_init\n",
4691-
"from spotpython.fun.objectivefunctions import analytical\n",
4691+
"from spotpython.fun.objectivefunctions import Analytical\n",
46924692
"design_control = design_control_init(init_size=3)\n",
46934693
"fun_control = fun_control_init(\n",
46944694
" lower = np.array([-1, -1]),\n",
@@ -6564,7 +6564,7 @@
65646564
"outputs": [],
65656565
"source": [
65666566
"import numpy as np\n",
6567-
"from spotpython.fun.objectivefunctions import analytical\n",
6567+
"from spotpython.fun.objectivefunctions import Analytical\n",
65686568
"from spotpython.spot import spot\n",
65696569
"from spotpython.utils.init import fun_control_init, design_control_init\n",
65706570
"# 1-dimensional example\n",
@@ -6761,7 +6761,7 @@
67616761
],
67626762
"source": [
67636763
"import numpy as np\n",
6764-
"from spotpython.fun.objectivefunctions import analytical\n",
6764+
"from spotpython.fun.objectivefunctions import Analytical\n",
67656765
"from spotpython.spot import spot\n",
67666766
"from spotpython.utils.init import (\n",
67676767
" fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init\n",
@@ -7064,7 +7064,7 @@
70647064
}
70657065
],
70667066
"source": [
7067-
"from spotpython.fun.objectivefunctions import analytical\n",
7067+
"from spotpython.fun.objectivefunctions import Analytical\n",
70687068
"import numpy as np\n",
70697069
"X = np.array([[1, 2, 3], [4, 5, 6], [-1, -1, -1]])\n",
70707070
"fun = analytical()\n",
@@ -7088,7 +7088,7 @@
70887088
}
70897089
],
70907090
"source": [
7091-
"from spotpython.fun.objectivefunctions import analytical\n",
7091+
"from spotpython.fun.objectivefunctions import Analytical\n",
70927092
"import numpy as np\n",
70937093
"X = np.array([np.zeros(10), np.ones(10)])\n",
70947094
"fun = analytical()\n",

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

src/spotpython/build/kriging.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,20 @@ def exp_imp(self, y0: float, s0: float) -> float:
221221
S.exp_imp(0.0, 1.0)
222222
0.3989422804014327
223223
"""
224-
# We do not use the min y values, but the aggragated mean values
224+
# We do not use the min y values, but the aggregated mean values
225225
# y_min = min(self.nat_y)
226226
y_min = min(self.aggregated_mean_y)
227227
if s0 <= 0.0:
228228
EI = 0.0
229229
elif s0 > 0.0:
230-
EI_one = (y_min - y0) * (
231-
0.5 + 0.5 * erf((1.0 / sqrt(2.0)) * ((y_min - y0) / s0))
232-
)
233-
EI_two = (s0 * (1.0 / sqrt(2.0 * pi))) * (
234-
exp(-(1.0 / 2.0) * ((y_min - y0) ** 2.0 / s0 ** 2.0))
235-
)
230+
# Ensure (y_min - y0) / s0 is a scalar
231+
diff_scaled = (y_min - y0) / s0
232+
# Calculate expected improvement components
233+
EI_one = (y_min - y0) * (0.5 + 0.5 * erf((1.0 / sqrt(2.0)) * diff_scaled))
234+
EI_two = (s0 * (1.0 / sqrt(2.0 * pi))) * exp(-(1.0 / 2.0) * diff_scaled ** 2)
235+
236236
EI = EI_one + EI_two
237+
237238
return EI
238239

239240
def set_de_bounds(self) -> None:
@@ -1155,7 +1156,7 @@ def plot(self, show: Optional[bool] = True) -> None:
11551156
11561157
Examples:
11571158
>>> import numpy as np
1158-
from spotpython.fun.objectivefunctions import analytical
1159+
from spotpython.fun.objectivefunctions import Analytical
11591160
from spotpython.spot import spot
11601161
from spotpython.utils.init import fun_control_init, design_control_init
11611162
# 1-dimensional example

src/spotpython/fun/objectivefunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import List, Optional, Dict
55

66

7-
class analytical:
7+
class Analytical:
88
"""
99
Class for analytical test functions.
1010

0 commit comments

Comments
 (0)