Skip to content

Commit fc2a840

Browse files
v0.5.21
documentation
1 parent e002486 commit fc2a840

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

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

src/spotPython/budget/ocba.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
from numpy import zeros, square, sqrt, full, around
99

1010

11-
def get_ocba(means, vars, delta):
11+
def get_ocba(means, vars, delta) -> int32:
1212
"""
1313
Optimal Computer Budget Allocation (OCBA)
1414
15+
This function calculates the budget recommendations for a given set of means,
16+
variances, and incremental budget using the OCBA algorithm.
17+
1518
References:
1619
Chun-Hung Chen and Loo Hay Lee:
1720
Stochastic Simulation Optimization: An Optimal Computer Budget Allocation,
@@ -24,6 +27,17 @@ def get_ocba(means, vars, delta):
2427
and
2528
https://github.com/TomMonks/sim-tools
2629
30+
Args:
31+
means (numpy.array): An array of means.
32+
vars (numpy.array): An array of variances.
33+
delta (int): The incremental budget.
34+
35+
Returns:
36+
numpy.array: An array of budget recommendations.
37+
38+
Note:
39+
The implementation is based on the pseudo-code in the Chen et al. book (p. 49).
40+
2741
Examples:
2842
2943
From the Chen et al. book (p. 49):
@@ -32,18 +46,6 @@ def get_ocba(means, vars, delta):
3246
get_ocba(mean_y, var_y, 50)
3347
3448
[11 9 19 9 2]
35-
36-
Args:
37-
means (numpy.array):
38-
means
39-
vars (numpy.array):
40-
variances
41-
delta (int):
42-
incremental budget
43-
44-
Returns:
45-
(numpy.array):
46-
budget recommendations. `(n,)` numpy.array
4749
"""
4850
n_designs = means.shape[0]
4951
allocations = zeros(n_designs, int32)
@@ -79,6 +81,19 @@ def get_ocba(means, vars, delta):
7981
return add_budget - allocations
8082

8183

82-
def get_ocba_X(X, means, vars, delta):
84+
def get_ocba_X(X, means, vars, delta) -> float64:
85+
"""
86+
This function calculates the OCBA allocation and repeats the input array X along the specified axis.
87+
88+
Args:
89+
X (numpy.ndarray): Input array to be repeated.
90+
means (list): List of means for each alternative.
91+
vars (list): List of variances for each alternative.
92+
delta (float): Indifference zone parameter.
93+
94+
Returns:
95+
numpy.ndarray: Repeated array of X along the specified axis based on the OCBA allocation.
96+
97+
"""
8398
o = get_ocba(means=means, vars=vars, delta=delta)
8499
return repeat(X, o, axis=0)

src/spotPython/build/kriging.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,20 @@ def __init__(
215215
logger.setLevel(self.log_level)
216216
logger.info(f"Starting the logger at level {self.log_level} for module {__name__}:")
217217

218-
def exp_imp(self, y0, s0):
218+
def exp_imp(self, y0: float, s0: float) -> float:
219219
"""
220-
Returns the expected improvement for y0 and error s0 (in coded units).
220+
Calculates the expected improvement for a given function value and error in coded units.
221+
221222
Args:
222-
y0 (float):
223-
function value (in coded units)
224-
s0 (float):
225-
error
223+
y0 (float): The function value in coded units.
224+
s0 (float): The error value.
225+
226226
Returns:
227-
(float):
228-
The expected improvement value.
227+
float: The expected improvement value.
228+
229+
Example:
230+
>>> exp_imp(1.0, 2.0)
231+
0.1977966
229232
"""
230233
# y_min = min(self.cod_y)
231234
y_min = min(self.mean_cod_y)

0 commit comments

Comments
 (0)