Mathematical Definition

\[f(\textbf{x}) = f(x_1, ..., x_n) = 1 + \sum_{i=1}^{n} \frac{x_i^{2}}{4000} - \prod_{i=1}^{n}cos(\frac{x_i}{\sqrt{i}})\]

Plots

Griewank Function

Griewank Function

Griewank Function

Griewank Function

The contour of the function: Griewank Function Contour

Griewank Function Contour

Description and Features

  • The function is continuous.
  • The function is not convex.
  • The function can be defined on n-dimensional space.
  • The function is unimodal.

Input Domain

The function can be defined on any input domain but it is usually evaluated on $x_i \in [-600, 600]$ for $i = 1, …, n$.

Global Minima

$f(\textbf{x}^{\ast}) = 0$ at $\textbf{x}^{\ast} = (0, …, 0)$

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 griewank

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

MATLAB

An implementation of the Griewank Function with MATLAB is provided below.

% Computes the value of the Griewank benchmark function.
% SCORES = GRIEWANKFCN(X) computes the value of the Griewank's
% function at point X. GRIEWANKFCN accepts a matrix of size M-by-N 
% and returns a vetor SCORES of size M-by-1 in which each row contains the 
% function value for the corresponding row of X.
% 
% 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 = griewankfcn(x)
    
    n = size(x, 2);
    
    sumcomp = 0;
    prodcomp = 1;
    
    for i = 1:n
        sumcomp = sumcomp + (x(:, i) .^ 2);
        prodcomp = prodcomp .* (cos(x(:, i) / sqrt(i)));
    end
    
    scores = (sumcomp / 4000) - prodcomp + 1;
end

The function can be represented in Latex as follows:

f(\textbf{x}) = f(x_1, ..., x_n) = 1 + \sum_{i=1}^{n} \frac{x_i^{2}}{4000} - \prod_{i=1}^{n}cos(\frac{x_i}{\sqrt{i}})

Acknowledgement

Prof Ender Özcan kindly contributed to the correctness of this document.

References:

  • http://www.sfu.ca/~ssurjano