Rastrigin Function

Abstract

In this page, we describe the Rastrigin function which is often used as an example in global optimization. We describe its main features and present several plots obtained with Scilab.

Introduction

Rastrigin functions is a class of functions which are used in global optimization because it has the property to have many local minima but only one global minimum [1,2,3].

In this page, we consider the Rastrigin function defined for $$x\in[-1,1]^2$$ by $$y = x_1^2+x_2^2-cos(12x_1)-cos(18x_2)$$ This function has several local minima, but only one global minimum, that is $$x^\star=0$$ associated with the value $$f(x^\star)=-2$$.

Scilab scripts

In this section, we detail the Scilab scripts which enables to define the Rastrigin function and draw contour and 3D plots.

In the following Scilab script, one defines the Rastrigin function.

function y = rastriginV ( x1 , x2 )
    // Vectorized function for contouring.
    y = x1.^2 + x2.^2-cos(12*x1)-cos(18*x2)
endfunction
function y = rastrigin ( x )
    // Non-vectorized function for optimization.
    y = rastriginV ( x(1) , x(2) )
endfunction

The following Scilab commands generates a contour plot and a 3D plot of the Rastrigin function.

//
// Contour plot
//
x1 = linspace(-1,1,100); 
x2 = linspace(-1,1,100); 
[XX1,XX2]=meshgrid(x1,x2);
Z = rastriginV ( XX1 , XX2  );
scf();
xset("fpf"," ");
contour ( x1 , x2 , Z' , 5 );
xtitle('Ratrigin Function - Contour Plot','x1','x2');

//
// 3D plot
//
scf();
plot3d(x1,x2,Z');
xtitle('Ratrigin Function - 3D Plot','x1','x2');

Rastrigin plots

The following is a Scilab plot of the contours of the Rastrigin function.

rastriginFunctionContour.png

The following is a Scilab 3D plot of the contours of the Rastrigin function.

rastriginFunction3D.png

References

[1] Rastrigin Function, http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/TestGO_files/Page2607.htm

[2] The Generalized Rastrigin Function, http://tracer.lcc.uma.es/problems/rastrigin/rastrigin.html

[3] Global optimization, Aimo Törn, Antanas Žilinskas, Berlin, New York : Springer-Verlag, 1989

public: Rastrigin function (last edited 2011-12-08 11:21:13 by favignana)