Learn R Programming

smint (version 0.4.2)

branin: Branin-Hoo 2-dimensional test function

Description

Branin-Hoo 2-dimensional test function.

Usage

branin(x)

Arguments

x
Numeric vector with length 2.

Value

The Branin-Hoo function's value.

Details

The Branin-Hoo function is defined here over $[0, 1] x [0, 1]$, instead of $[-5, 0] x [10, 15]$ as usual. It has 3 global minima at (nearly) : $x1 = c(0.96, 0.15)$, $x2 = c(0.12, 0.82)$ and $x3 = c(0.54, 0.15)$.

Examples

Run this code
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)))
## Not run: 
# ## for the users of the "rgl" package only...
# library(rgl)
# persp3d(x = x, y = y, z = f, aspect = c(1, 1, 0.5), col = "lightblue", alpha = 0.8)
# spheres3d(Xout2[ , 1], Xout2[ , 2], GIS, col = "orangered",
#           radius = 2)
# ## End(Not run)

Run the code above in your browser using DataLab