Skip to content

ocba

OCBA: Optimal Computing Budget Allocation

get_ocba(means, vars, delta)

Optimal Computer Budget Allocation (OCBA)

References

Chun-Hung Chen and Loo Hay Lee: Stochastic Simulation Optimization: An Optimal Computer Budget Allocation, pp. 49 and pp. 215

C.S.M Currie and T. Monks: How to choose the best setup for a system. A tutorial for the Simulation Workshop 2021, see: https://colab.research.google.com/github/TomMonks/sim-tools/blob/master/examples/sw21_tutorial.ipynb and https://github.com/TomMonks/sim-tools

Examples:

From the Chen et al. book (p. 49): mean_y = np.array([1,2,3,4,5]) var_y = np.array([1,1,9,9,4]) get_ocba(mean_y, var_y, 50)

[11 9 19 9 2]

Args: means (numpy.array): means vars (numpy.array): variances delta (int): incremental budget

Returns: (numpy.array): budget recommendations. (n,) numpy.array

Source code in spotPython/budget/ocba.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def get_ocba(means, vars, delta):
    """
    Optimal Computer Budget Allocation (OCBA)

    References:
        Chun-Hung Chen and Loo Hay Lee:
        Stochastic Simulation Optimization: An Optimal Computer Budget Allocation,
        pp. 49 and pp. 215

        C.S.M Currie and T. Monks:
        How to choose the best setup for a system. A tutorial for the Simulation Workshop 2021,
        see:
        https://colab.research.google.com/github/TomMonks/sim-tools/blob/master/examples/sw21_tutorial.ipynb
        and
        https://github.com/TomMonks/sim-tools

    Examples:

        From the Chen et al. book (p. 49):
        mean_y = np.array([1,2,3,4,5])
        var_y = np.array([1,1,9,9,4])
        get_ocba(mean_y, var_y, 50)

        [11  9 19  9  2]

        Args:
        means (numpy.array):
            means
        vars (numpy.array):
            variances
        delta (int):
            incremental budget

        Returns:
        (numpy.array):
            budget recommendations. `(n,)` numpy.array
    """
    n_designs = means.shape[0]
    allocations = zeros(n_designs, int32)
    ratios = zeros(n_designs, float64)
    budget = delta
    ranks = get_ranks(means)
    best, second_best = argpartition(ranks, 2)[:2]
    ratios[second_best] = 1.0
    select = [i for i in range(n_designs) if i not in [best, second_best]]
    temp = (means[best] - means[second_best]) / (means[best] - means[select])
    ratios[select] = square(temp) * (vars[select] / vars[second_best])
    select = [i for i in range(n_designs) if i not in [best]]
    temp = (square(ratios[select]) / vars[select]).sum()
    ratios[best] = sqrt(vars[best] * temp)
    more_runs = full(n_designs, True, dtype=bool)
    add_budget = zeros(n_designs, dtype=float)
    more_alloc = True
    while more_alloc:
        more_alloc = False
        ratio_s = (more_runs * ratios).sum()
        add_budget[more_runs] = (budget / ratio_s) * ratios[more_runs]
        add_budget = around(add_budget).astype(int)
        mask = add_budget < allocations
        add_budget[mask] = allocations[mask]
        more_runs[mask] = 0
        if mask.sum() > 0:
            more_alloc = True
        if more_alloc:
            budget = allocations.sum() + delta
            budget -= (add_budget * ~more_runs).sum()
    t_budget = add_budget.sum()
    add_budget[best] += allocations.sum() + delta - t_budget
    return add_budget - allocations