Mathematical Definition

In the above definition, is a real-valued parameter. For the value of , the contour of the function resembles a smiling cat, leading to the naming of the function.


For the value of , the function looks as:

Happy Cat Function

Happy Cat Function

Happy Cat Function

Happy Cat Function

A contour of the function is presented below:

Happy Cat Function

Description and Features

  • The function is not convex.
  • The function is defined on n-dimensional space.
  • The function is non-separable.
  • The function is differentiable.

Input Domain

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

Global Minima

The function has one global minimum at $f(\textbf{x}^{\ast}) = 0$ located at $\mathbf{x^\ast}=(-1, …, -1)$.


An implementation of the Happy Cat Function with MATLAB is provided below.

% Computes the value of the Happy Cat benchmark function.
% SCORES = HAPPYCATFCN(X) computes the value of the Happy Cat function at 
% point X. HAPPYCATFCN 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. 
% SCORES = HAPPYCAT(X, ALPHA) specifies power of the sphere component of 
% the function.
% For more information please visit: 
% 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 = happycatfcn(x, alpha)

    if nargin < 2 
        alpha = 0.5;
    n = size(x, 2);
    x2 = sum(x .* x, 2);
    scores = ((x2 - n).^2).^(alpha) + (0.5*x2 + sum(x,2))/n + 0.5;

The function can be represented in Latex as follows:

f(\textbf{x})=\left[\left(||\textbf{x}||^2 - n\right)^2\right]^\alpha + \frac{1}{n}\left(\frac{1}{2}||\textbf{x}||^2+\sum_{i=1}^{n}x_i\right)+\frac{1}{2}



  • Hans-Georg Beyer and Steffen Finck, HappyCat – A Simple Function Class Where Well-Known Direct Search Algorithms Do Fail, Parallel Problem Solving from Nature - PPSN XII, pp. 367–376 (2012),