branin: Branin-Hoo 2-dimensional test function

braninR Documentation

Branin-Hoo 2-dimensional test function

Description

Branin-Hoo 2-dimensional test function.

Usage

branin(x)

Arguments

x

Numeric vector with length 2.

Details

The Branin-Hoo function is defined here over [0,\,1] \times [0,\,1], instead of [-5,\,0] \times [10,\,15] as usual. It has 3 global minima at (nearly) : \mathbf{x}_1 = [0.96, \,0.15]^\top, \mathbf{x}_2 = [0.12, \,0.82]^\top and \mathbf{x}_3 = [0.54,\,0.15]^\top.

Value

The Branin-Hoo function's value.

Author(s)

David Ginsbourger

Examples

GD <- Grid(nlevels = c("x" = 20, "y" = 20))
x <- levels(GD)[[1]]; y <- levels(GD)[[2]]
f  <- apply_Grid(GD, branin)
dim(f) <- nlevels(GD)
contour(x = x, y = y, z = f, nlevels = 40)
nOut <- 100; Xout2 <- array(runif(nOut * 2), dim = c(nOut, 2))
colnames(Xout2) <- c("x", "y")

## interpolate using default method (Lagrange) 
GIL <- interp_Grid(X = GD, Y = f, Xout = Xout2)

## interpolate using a natural spline
GIS <- interp_Grid(X = GD, Y = f, Xout = Xout2,
                 cardinalBasis1d = function(x, xout) {
                     cardinalBasis_natSpline(x = x, xout = xout)$CB
                  })
F <- apply(Xout2, 1, branin)
mat <- cbind(Xout2, fTrue = F, fIntL = GIL, errorLag = F - GIL,
             fIntS = GIS, errorSpline = F - GIS)
apply(mat[ , c("errorLag", "errorSpline")], 2, function(x) mean(abs(x)))
## for the users of the "rgl" package only...
if (requireNamespace("rgl")) { 
 rgl::persp3d(x = x, y = y, z = f, aspect = c(1, 1, 0.5), col = "lightblue", alpha = 0.8)
 rgl::spheres3d(Xout2[ , 1], Xout2[ , 2], GIS, col = "orangered",
          radius = 2)
}

IRSN/smint documentation built on Dec. 9, 2023, 9:53 p.m.