Skip to content

Commit be0c457

Browse files
v0.0.8 Handling Errors
1 parent 1f54196 commit be0c457

6 files changed

Lines changed: 130 additions & 151 deletions

File tree

dist/spotPython-0.0.7.tar.gz

-3.79 MB
Binary file not shown.

dist/spotPython-0.0.8.tar.gz

3.69 MB
Binary file not shown.

notebooks/00_spot_doc.ipynb

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

src/spotPython/fun/objectivefunctions.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
from numpy.random import default_rng
3+
from random import random
34

45

56
class analytical:
@@ -561,3 +562,34 @@ def fun_rosen(self, X, fun_control=None):
561562
return self.add_noise(y)
562563
else:
563564
return y
565+
566+
def fun_random_error(self, X, fun_control=None):
567+
"""Return errors for testing spot stability.
568+
569+
Args:
570+
X (array): input
571+
572+
Returns:
573+
(float): objective function value.
574+
"""
575+
if fun_control is not None:
576+
self.fun_control = fun_control
577+
try:
578+
X.shape[1]
579+
except ValueError as err:
580+
print("error message:", err)
581+
X = np.array(X)
582+
if len(X.shape) < 2:
583+
X = np.array([X])
584+
y = np.array([], dtype=float)
585+
for i in range(X.shape[0]):
586+
# provoke error:
587+
if random() < 0.1:
588+
y = np.append(y, np.nan)
589+
else:
590+
y = np.append(y, np.sum(X[i]))
591+
if self.fun_control["sigma"] > 0:
592+
return self.add_noise(y)
593+
else:
594+
print(y)
595+
return y

0 commit comments

Comments
 (0)