Ackley function

The Ackley function is defined as: $f(x) = -a*exp(-b\sqrt{\frac{1}{d}\sum_{i=1}^d x_i^2}) - exp(\frac{1}{d} \sum_{i=1}^d cos(cx_i)) + a + exp(1)$ Usually the recommended values are: $a = 20$, $b = 0.2$ and $c = 2\pi$

Let's see the 1D case.

using Surrogates
using Plots
default()

Now, let's define the Ackley function:

function ackley(x)
    a, b, c = 20.0, -0.2, 2.0*π
    len_recip = inv(length(x))
    sum_sqrs = zero(eltype(x))
    sum_cos = sum_sqrs
    for i in x
        sum_cos += cos(c*i)
        sum_sqrs += i^2
    end
    return (-a * exp(b * sqrt(len_recip*sum_sqrs)) -
            exp(len_recip*sum_cos) + a + 2.71)
end
ackley (generic function with 1 method)
n = 100
lb = -32.768
ub = 32.768
x = sample(n, lb, ub, SobolSample())
y = ackley.(x)
xs = lb:0.001:ub
scatter(x, y, label="Sampled points", xlims=(lb, ub), ylims=(0,30), legend=:top)
plot!(xs, ackley.(xs), label="True function", legend=:top)