# Branin Function

The Branin Function is commonly used as a test function for metamodelling in computer experiments, especially in the context of optimization.

The expression of the Branin Function is given as: $f(x) = (x_2 - \frac{5.1}{4\pi^2}x_1^{2} + \frac{5}{\pi}x_1 - 6)^2 + 10(1-\frac{1}{8\pi})\cos(x_1) + 10$

where $x = (x_1, x_2)$ with $-5\leq x_1 \leq 10, 0 \leq x_2 \leq 15$

First of all we will import these two packages Surrogates and Plots.

using Surrogates
using Plots
default()

Now, let's define our objective function:

function branin(x)
x1 = x[1]
x2 = x[2]
b = 5.1 / (4*pi^2);
c = 5/pi;
r = 6;
a = 1;
s = 10;
t = 1 / (8*pi);
term1 = a * (x2 - b*x1^2 + c*x1 - r)^2;
term2 = s*(1-t)*cos(x1);
y = term1 + term2 + s;
end
branin (generic function with 1 method)

Now, let's plot it:

n_samples = 80
lower_bound = [-5, 0]
upper_bound = [10,15]
xys = sample(n_samples, lower_bound, upper_bound, SobolSample())
zs = branin.(xys);

Now it's time to fitting different surrogates and then we will plot them. We will have a look on Kriging Surrogate:

kriging_surrogate = Kriging(xys, zs, lower_bound, upper_bound, p=[1.9, 1.9])
(::Kriging{Array{Tuple{Float64,Float64},1},Array{Float64,1},Array{Int64,1},Array{Int64,1},Array{Float64,1},Array{Float64,1},Float64,Array{Float64,2},Float64,Array{Float64,2}}) (generic function with 2 methods)

Now, we will have a look on Inverse Distance Surrogate:

InverseDistance = InverseDistanceSurrogate(xys, zs,  lower_bound, upper_bound)
(::InverseDistanceSurrogate{Array{Tuple{Float64,Float64},1},Array{Float64,1},Array{Int64,1},Array{Int64,1},Float64}) (generic function with 1 method)

Now, let's talk about Lobachesky Surrogate:

Lobachesky = LobacheskySurrogate(xys, zs,  lower_bound, upper_bound, alpha = [2.8,2.8], n=8)
(::LobacheskySurrogate{Array{Tuple{Float64,Float64},1},Array{Float64,1},Array{Float64,1},Int64,Array{Int64,1},Array{Int64,1},Array{Float64,1},Bool}) (generic function with 2 methods)