weierstrass: Weierstrass Function for Benchmarking Optimization Algorithms

View source: R/weierstrass.R

weierstrassR Documentation

Weierstrass Function for Benchmarking Optimization Algorithms

Description

The Weierstrass function is a continuous but non-differentiable function commonly used for testing optimization algorithms. It is highly multimodal, with numerous local minima, making it challenging for optimization algorithms to locate the global minimum.

Usage

weierstrass(x,
            a = 0.5,
            b = 3,
            kmax = 20)

Arguments

x

A numeric vector representing the input variables. The length of x determines the dimensionality of the problem.

a

A numeric value representing the scaling factor. Typically, a = 0.5.

b

A numeric value representing the frequency factor. Typically, b = 3.

kmax

An integer specifying the maximum number of terms in the summation. Typically, kmax = 20.

Value

Returns a numeric value representing the evaluation of the Weierstrass function at the given input vector x.

References

Weierstrass, K. (1872). On Continuous Non-Differentiable Functions. In Mathematische Werke, 2(1), 71–74.

Examples


# Evaluation 1: Global minimum point in a four-dimensional space
x <- rep(0, 4)
weierstrass(x)

# Evaluation 2: A point in a six-dimensional space
x <- c(0, 0.24, 11, -1, -0.7, pi)
weierstrass(x)

# Contour Plot: Visualizing the Weierstrass Function
x1 <- seq(-10, 10, length.out = 100)
x2 <- seq(-10, 10, length.out = 100)
z <- outer(x1, x2, FUN = Vectorize(function(x, y) weierstrass(c(x, y))))
contour(x1, x2, z, nlevels = 20, main = "Contour of the Weierstrass Function")

# EDA.mnorm() example
res = EDA.mnorm(fun = weierstrass, lower = c(-10,-10), upper = c(10,10), n = 30, 
                k = 2, tolerance = 0.01, maxiter = 200)
res$sol

# Contour plot: Visualizing solution with EDA.mnorm()
x1 <- seq(-10, 10, length.out = 100)
x2 <- seq(-10, 10, length.out = 100)
z <- outer(x1, x2, FUN = Vectorize(function(x, y) weierstrass(c(x, y))))
contour(x1, x2, z, nlevels = 20, cex.axis = 0.8, 
        main = "Contour plot of the Weierstrass Function with EDA.mnorm solution")
points(res$sol[1], res$sol[2], col = "red", pch = 19)

EEEA documentation built on June 10, 2025, 9:13 a.m.

Related to weierstrass in EEEA...