Learn R Programming

smint (version 0.4.0)

ShepFun1: Test functions for/from SHEPPACK

Description

Test functions for/from SHEPPACK

Usage

ShepFun1(x)

Arguments

x
A numeric vector with arbitrary length.

Value

  • Function's value.

Details

These functions are described in the article cited in the references section. $$f_1(\mathbf{x}) = 1 + \frac{2}{d} \, \left| d/2 - \sum_i x_i \right|$$ $$f_2(\mathbf{x}) = 1 - \frac{2}{d}\, \sum_i \left|x_i - 0.5 \right|$$ $$f_3(\mathbf{x}) = 1 - 2 \, \max_{i} \left|x_i - 0.5 \right|$$ $$f_4(\mathbf{x}) = \prod_i \left[ 1 - 2 \left| x_i - 0.5 \right| \right]$$ $$f_5(\mathbf{x}) = 1 - c_5 \, \left[ \sum_i \left|x_i - 0.5 \right| + \prod_i \left| x_i - 0.5 \right| \right]$$ where $c_5 = d/2 + (0.5)^d$, and all sums or products are for $i=1$ to $d$. All these functions are defined on $[0,\,1]^d$ and take values in $[0,1]$. The four functions $f_i$ for $i > 1$ have an unique maximum located at $\mathbf{x}^\star$ with all coordinates $x_j^\star = 0.5$ and $f_i(\mathbf{x}^\star) =1$.

References

W.I. Thacker, J. Zhang, L.T. Watson, J.B. Birch, M.A. Iyer and M.W. Berry (2010). Algorithm 905: SHEPPACK: Modified Shepard Algorithm for Interpolation of Scattered Multivariate Data ACM Trans. on Math. Software (TOMS) Vol. 37, n. 3. http://dl.acm.org/citation.cfm?id=1824812{link}

Examples

Run this code
## interpolate 'Shepfun3' for d = 4
d <- 4
GDd <- Grid(nlevels = rep(8, d))
fGrid <- apply_Grid(GDd, ShepFun3)
Xoutd <- matrix(runif(200 * d), ncol = d)
GI <- interp_Grid(X = GDd, Y = fGrid, Xout = Xoutd)
F <- apply(Xoutd, 1, ShepFun3)
max(abs(F - GI))

## 3D plot
require(lattice)
X <- as.data.frame(Grid(nlevels = c("x1" = 30, "x2" = 30)))
df <- data.frame(x1 = numeric(0), x2 = numeric(0),
                 f = numeric(0), i = numeric(0))
for (i in 1:5) {
   f <- apply(X, 1, ShepFuns[[i]])
   df <- rbind(df, data.frame(x1 = X$x1, x2 = X$x2, f = f, i = i))
}
pl <- wireframe(f ~ x1 * x2 | i, data = df,
                outer = TRUE, shade = FALSE, zlab = "",
                screen = list(z = 20, x = -30),
                strip = strip.custom(strip.names = c(TRUE),
                                     strip.levels = c(TRUE)),
                main = "", horizontal = TRUE, col = "SpringGreen4")
pl

Run the code above in your browser using DataLab