Skip to content

Commit f9a246f

Browse files
v0.6.8
docs
1 parent 2304c5c commit f9a246f

12 files changed

Lines changed: 176 additions & 147 deletions

File tree

mkdocs.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
site_name: spotPython
2+
site_description: spotPython - Sequential Parameter Optimization Toolbox in Python
23
site_url: https://github.com/sequential-parameter-optimization/spotPython
34
repo_url: https://github.com/sequential-parameter-optimization/spotPython/tree/main
5+
6+
# Copyright
7+
copyright: Copyright © 2004 - 2023
8+
49
nav:
510
- Home: index.md
11+
- Code Reference: reference/
612
- Documentation: hyperparameter-tuning-cookbook.md
713
- Download: download.md
814
- Examples: examples.md
9-
- Code Reference: reference/
1015
- About: about.md
16+
1117
theme:
1218
name: material
1319
locale: en
1420
highlightjs: true
1521
favicon: images/favicon.png
1622
logo: images/spotlogo.png
23+
1724
palette:
1825
# Palette toggle for light mode
1926
- media: "(prefers-color-scheme: light)"
2027
scheme: default
2128
primary: grey
29+
accent: orange
2230
toggle:
2331
icon: material/brightness-7
2432
name: Switch to dark mode
@@ -27,9 +35,19 @@ theme:
2735
- media: "(prefers-color-scheme: dark)"
2836
scheme: slate
2937
primary: blue grey
38+
accent: orange
3039
toggle:
3140
icon: material/brightness-4
3241
name: Switch to light mode
42+
font:
43+
text: Roboto
44+
code: Fira Code
45+
features:
46+
- content.code.copy
47+
- navigation.tabs
48+
- navigation.instant
49+
- navigation.indexes
50+
3351
plugins:
3452
- search:
3553
- exclude:

pyproject.toml

Lines changed: 1 addition & 4 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.6.7"
10+
version = "0.6.8"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]
@@ -61,9 +61,6 @@ where = ["src"]
6161
line-length = 120
6262
target-version = ["py310"]
6363

64-
[tool.setuptools_scm]
65-
write_to = "src/spotPython/_version.py"
66-
6764
[tool.pytest.ini_options]
6865
addopts = [
6966
"--import-mode=importlib",

src/spotPython/budget/ocba.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,28 @@ def get_ocba(means, vars, delta) -> int32:
1616
variances, and incremental budget using the OCBA algorithm.
1717
1818
References:
19-
Chun-Hung Chen and Loo Hay Lee:
20-
Stochastic Simulation Optimization: An Optimal Computer Budget Allocation,
21-
pp. 49 and pp. 215
22-
23-
C.S.M Currie and T. Monks:
24-
How to choose the best setup for a system. A tutorial for the Simulation Workshop 2021,
25-
see:
26-
https://colab.research.google.com/github/TomMonks/sim-tools/blob/master/examples/sw21_tutorial.ipynb
27-
and
28-
https://github.com/TomMonks/sim-tools
19+
[1]: Chun-Hung Chen and Loo Hay Lee: Stochastic Simulation Optimization: An Optimal Computer Budget Allocation, pp. 49 and pp. 215
20+
[2]: C.S.M Currie and T. Monks: How to choose the best setup for a system. A tutorial for the Simulation Workshop 2021, see:
21+
[sw21_tutorial.ipynb](https://colab.research.google.com/github/TomMonks/sim-tools/blob/master/examples/sw21_tutorial.ipynb) and
22+
[sim-tools](https://github.com/TomMonks/sim-tools)
2923
3024
Args:
3125
means (numpy.array): An array of means.
3226
vars (numpy.array): An array of variances.
3327
delta (int): The incremental budget.
3428
3529
Returns:
36-
numpy.array: An array of budget recommendations.
30+
(numpy.array): An array of budget recommendations.
3731
3832
Note:
39-
The implementation is based on the pseudo-code in the Chen et al. book (p. 49).
33+
The implementation is based on the pseudo-code in the Chen et al. (p. 49), see [1].
4034
4135
Examples:
42-
4336
From the Chen et al. book (p. 49):
44-
mean_y = np.array([1,2,3,4,5])
45-
var_y = np.array([1,1,9,9,4])
46-
get_ocba(mean_y, var_y, 50)
47-
48-
[11 9 19 9 2]
37+
>>> mean_y = np.array([1,2,3,4,5])
38+
var_y = np.array([1,1,9,9,4])
39+
get_ocba(mean_y, var_y, 50)
40+
[11 9 19 9 2]
4941
"""
5042
n_designs = means.shape[0]
5143
allocations = zeros(n_designs, int32)
@@ -92,7 +84,20 @@ def get_ocba_X(X, means, vars, delta) -> float64:
9284
delta (float): Indifference zone parameter.
9385
9486
Returns:
95-
numpy.ndarray: Repeated array of X along the specified axis based on the OCBA allocation.
87+
(numpy.ndarray): Repeated array of X along the specified axis based on the OCBA allocation.
88+
89+
Examples:
90+
>>> X = np.array([[1,2,3],[4,5,6]])
91+
means = [1,2,3]
92+
vars = [1,1,1]
93+
delta = 50
94+
get_ocba_X(X, means, vars, delta)
95+
array([[1, 2, 3],
96+
[1, 2, 3],
97+
[1, 2, 3],
98+
[4, 5, 6],
99+
[4, 5, 6],
100+
[4, 5, 6]])
96101
97102
"""
98103
o = get_ocba(means=means, vars=vars, delta=delta)

src/spotPython/build/kriging.py

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
from __future__ import annotations
2-
3-
# google-style docstring documentation, type information, an example, and return values: 2023, July, 15th
4-
# tests: None
5-
61
import copy
72
from math import erf
83
import matplotlib.pyplot as plt
@@ -47,6 +42,45 @@
4742

4843

4944
class Kriging(surrogates):
45+
"""Kriging surrogate.
46+
47+
Attributes:
48+
nat_range_X (list):
49+
List of X natural ranges.
50+
nat_range_y (list):
51+
List of y nat ranges.
52+
noise (bool):
53+
noisy objective function. Default: False. If `True`, regression kriging will be used.
54+
var_type (str):
55+
variable type. Can be either `"num`" (numerical) of `"factor"` (factor).
56+
num_mask (array):
57+
array of bool variables. `True` represent numerical (float) variables.
58+
factor_mask (array):
59+
array of factor variables. `True` represents factor (unordered) variables.
60+
int_mask (array):
61+
array of integer variables. `True` represents integers (ordered) variables.
62+
ordered_mask (array):
63+
array of ordered variables. `True` represents integers or float (ordered) variables.
64+
Set of veriables which an order relation, i.e., they are either num (float) or int.
65+
name (str):
66+
Surrogate name
67+
seed (int):
68+
Random seed.
69+
use_cod_y (bool):
70+
Use coded y values.
71+
sigma (float):
72+
Kriging sigma.
73+
gen (method):
74+
Design generator, e.g., spotPython.design.spacefilling.spacefilling.
75+
min_theta (float):
76+
min log10 theta value. Defaults: -6.
77+
max_theta (float):
78+
max log10 theta value. Defaults: 3.
79+
min_p (float):
80+
min p value. Default: 1.
81+
max_p (float):
82+
max p value. Default: 2.
83+
"""
5084
def __init__(
5185
self: object,
5286
noise: bool = False,
@@ -68,7 +102,7 @@ def __init__(
68102
**kwargs
69103
):
70104
"""
71-
Kriging surrogate.
105+
Initialize the Kriging surrogate.
72106
73107
Args:
74108
noise (bool): Use regression instead of interpolation kriging. Defaults to False.
@@ -92,73 +126,39 @@ def __init__(
92126
spot_writer : Spot writer.
93127
counter : Counter.
94128
95-
Attributes:
96-
nat_range_X (list):
97-
List of X natural ranges.
98-
nat_range_y (list):
99-
List of y nat ranges.
100-
noise (bool):
101-
noisy objective function. Default: False. If `True`, regression kriging will be used.
102-
var_type (str):
103-
variable type. Can be either `"num`" (numerical) of `"factor"` (factor).
104-
num_mask (array):
105-
array of bool variables. `True` represent numerical (float) variables.
106-
factor_mask (array):
107-
array of factor variables. `True` represents factor (unordered) variables.
108-
int_mask (array):
109-
array of integer variables. `True` represents integers (ordered) variables.
110-
ordered_mask (array):
111-
array of ordered variables. `True` represents integers or float (ordered) variables.
112-
Set of veriables which an order relation, i.e., they are either num (float) or int.
113-
name (str):
114-
Surrogate name
115-
seed (int):
116-
Random seed.
117-
use_cod_y (bool):
118-
Use coded y values.
119-
sigma (float):
120-
Kriging sigma.
121-
gen (method):
122-
Design generator, e.g., spotPython.design.spacefilling.spacefilling.
123-
min_theta (float):
124-
min log10 theta value. Defaults: -6.
125-
max_theta (float):
126-
max log10 theta value. Defaults: 3.
127-
min_p (float):
128-
min p value. Default: 1.
129-
max_p (float):
130-
max p value. Default: 2.
131-
132129
Examples:
133-
Surrogate of the x*sin(x) function.
134-
See:
135-
[scikit-learn](https://scikit-learn.org/stable/auto_examples/gaussian_process/plot_gpr_noisy_targets.html)
130+
Surrogate of the x*sin(x) function, see [1].
136131
137132
>>> from spotPython.build.kriging import Kriging
138-
>>> import numpy as np
139-
>>> import matplotlib.pyplot as plt
140-
>>> rng = np.random.RandomState(1)
141-
>>> X = linspace(start=0, stop=10, num=1_000).reshape(-1, 1)
142-
>>> y = np.squeeze(X * np.sin(X))
143-
>>> training_indices = rng.choice(arange(y.size), size=6, replace=False)
144-
>>> X_train, y_train = X[training_indices], y[training_indices]
145-
>>> S = Kriging(name='kriging', seed=124)
146-
>>> S.fit(X_train, y_train)
147-
>>> mean_prediction, std_prediction = S.predict(X)
148-
>>> plt.plot(X, y, label=r"$f(x)$", linestyle="dotted")
149-
>>> plt.scatter(X_train, y_train, label="Observations")
150-
>>> plt.plot(X, mean_prediction, label="Mean prediction")
151-
>>> plt.fill_between(
152-
X.ravel(),
153-
mean_prediction - 1.96 * std_prediction,
154-
mean_prediction + 1.96 * std_prediction,
155-
alpha=0.5,
156-
label=r"95% confidence interval",
157-
)
158-
>>> plt.legend()
159-
>>> plt.xlabel("$x$")
160-
>>> plt.ylabel("$f(x)$")
161-
>>> _ = plt.title("Gaussian process regression on noise-free dataset")
133+
import numpy as np
134+
import matplotlib.pyplot as plt
135+
rng = np.random.RandomState(1)
136+
X = linspace(start=0, stop=10, num=1_000).reshape(-1, 1)
137+
y = np.squeeze(X * np.sin(X))
138+
training_indices = rng.choice(arange(y.size), size=6, replace=False)
139+
X_train, y_train = X[training_indices], y[training_indices]
140+
S = Kriging(name='kriging', seed=124)
141+
S.fit(X_train, y_train)
142+
mean_prediction, std_prediction = S.predict(X)
143+
plt.plot(X, y, label=r"$f(x)$", linestyle="dotted")
144+
plt.scatter(X_train, y_train, label="Observations")
145+
plt.plot(X, mean_prediction, label="Mean prediction")
146+
plt.fill_between(
147+
X.ravel(),
148+
mean_prediction - 1.96 * std_prediction,
149+
mean_prediction + 1.96 * std_prediction,
150+
alpha=0.5,
151+
label=r"95% confidence interval",
152+
)
153+
plt.legend()
154+
plt.xlabel("$x$")
155+
plt.ylabel("$f(x)$")
156+
_ = plt.title("Gaussian process regression on noise-free dataset")
157+
plt.show()
158+
159+
References:
160+
161+
[[1](https://scikit-learn.org/stable/auto_examples/gaussian_process/plot_gpr_noisy_targets.html)] scikit-learn: Gaussian Processes regression: basic introductory example
162162
163163
"""
164164
super().__init__(name, seed, log_level)

src/spotPython/design/factorial.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def full_factorial(self, p: int) -> "np.ndarray":
3232
Returns:
3333
numpy.ndarray: A 2D array representing the full factorial design.
3434
35-
Example:
36-
>>> factorial_design = factorial(k=2)
37-
>>> factorial_design.full_factorial(p=2)
38-
array([[0., 0.],
39-
[0., 1.],
40-
[1., 0.],
41-
[1., 1.]])
35+
Examples:
36+
>>> from spotPython.design.factorial import factorial
37+
factorial_design = factorial(k=2)
38+
factorial_design.full_factorial(p=2)
39+
array([[0., 0.],
40+
[0., 1.],
41+
[1., 0.],
42+
[1., 1.]])
4243
"""
4344
i = (slice(0, 1, p * 1j),) * self.k
4445
return mgrid[i].reshape(self.k, p**self.k).T

src/spotPython/design/spacefilling.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ def scipy_lhd(
3939
Returns:
4040
(ndarray): Latin hypercube design.
4141
42-
Example:
42+
Examples:
4343
>>> from spotPython.design.spacefilling import spacefilling
44-
>>> import numpy as np
45-
>>> lhd = spacefilling(k=2, seed=123)
46-
>>> lhd.scipy_lhd(n=5, repeats=2, lower=np.array([0,0]), upper=np.array([1,1]))
47-
array([[0.66352963, 0.5892358 ],
48-
[0.66352963, 0.5892358 ],
49-
[0.55592803, 0.96312564],
50-
[0.55592803, 0.96312564],
51-
[0.16481882, 0.0375811 ],
52-
[0.16481882, 0.0375811 ],
53-
[0.215331 , 0.34468512],
54-
[0.215331 , 0.34468512],
55-
[0.83604909, 0.62202146],
56-
[0.83604909, 0.62202146]])
44+
import numpy as np
45+
lhd = spacefilling(k=2, seed=123)
46+
lhd.scipy_lhd(n=5, repeats=2, lower=np.array([0,0]), upper=np.array([1,1]))
47+
array([[0.66352963, 0.5892358 ],
48+
[0.66352963, 0.5892358 ],
49+
[0.55592803, 0.96312564],
50+
[0.55592803, 0.96312564],
51+
[0.16481882, 0.0375811 ],
52+
[0.16481882, 0.0375811 ],
53+
[0.215331 , 0.34468512],
54+
[0.215331 , 0.34468512],
55+
[0.83604909, 0.62202146],
56+
[0.83604909, 0.62202146]])
5757
"""
5858
if lower is None:
5959
lower = zeros(self.k)

src/spotPython/fun/hyperlight.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def fun(self, X: np.ndarray, fun_control: dict = None) -> np.ndarray:
103103
104104
Examples:
105105
>>> hyper_light = HyperLight(seed=126, log_level=50)
106-
>>> X = np.array([[1, 2], [3, 4]])
107-
>>> fun_control = {"weights": np.array([1, 0, 0])}
108-
>>> hyper_light.fun(X, fun_control)
109-
array([nan, nan])
106+
X = np.array([[1, 2], [3, 4]])
107+
fun_control = {"weights": np.array([1, 0, 0])}
108+
hyper_light.fun(X, fun_control)
109+
array([nan, nan])
110110
"""
111111
z_res = np.array([], dtype=float)
112112
if fun_control is not None:

0 commit comments

Comments
 (0)