Mathematical Definition

\[f(x) = \frac{sin(10\pi x)}{2x} + (x-1)^4\]

Plots

Gramacy & Lee Function

Description and Features

  • The function is continuous.
  • The function is not convex.
  • The function is defined on 1-dimensional space.
  • The function is unimodal.

Input Domain

The function can be defined on any input domain but it is usually evaluated on $x \in [-0.5, 2.5]$.

Global Minima

The function has one local minimum at: $f(x^*)=-0.869011134989500$ at $\textbf{x}^{\ast} = 0.548563444114526$.

Implementation

Python

For Python, the function is implemented in the benchmarkfcns package, which can be installed from command line with pip install benchmarkfcns.

from benchmarkfcns import gramacylee

print(gramacylee([[0, 0],
              [1, 1]]))

MATLAB

An implementation of the Gramacy & Lee Function with MATLAB is provided below.

% Computes the value of the Gramacy & Lee benchmark function.
% SCORES = GRAMACYLEEFCN(X) computes the value of the Gramacy & Lee 
% function at point X. GRAMACYLEEFCN accepts a matrix of size M-by-2 and 
% returns a vetor SCORES of size M-by-1 in which each row contains the 
% function value for the corresponding row of X.
% For more information please visit: 
% https://en.wikipedia.org/wiki/Test_functions_for_optimization
% 
% Author: Mazhar Ansari Ardeh
% Please forward any comments or bug reports to mazhar.ansari.ardeh at
% Google's e-mail service or feel free to kindly modify the repository.
function scores = gramacyleefcn(x)
    n = size(x, 2);
    assert(n == 1, 'Gramacy & Lee function is only defined on a 1-D space.')

    scores = (sin(10 .* pi .* x) ./ (2 * x) ) + ((x - 1) .^ 4);
end

The function can be represented in Latex as follows:

f(x) = \frac{sin(10\pi x)}{2x} + (x-1)^4

References: