VectorGA: A Vectorized Implementation of a Genetic Algorithm in Matlab

VectorGA is a vectorized implementation of a genetic algorithm in the Matlab programming language.

Matlab is optimized for performing operations on arrays. Loops, especially nested loops, tend to run slowly in Matlab. It is possible to significantly improve the performance of Matlab programs by converting loops into array operations. This process is called vectorization. Matlab provides a rich set of functions and many expressive indexing schemes that make it possible to vectorize code. Such code not only runs faster, it is also shorter, and simpler to understand and change (provided that you know a little about Matlab of course).

Genetic Algorithms that are implemented in C/C++ or Java typically have multiple nested loops. Therefore direct ports of such implementations to Matlab will run very slowly. Many of the nested loops found in a typical GA implementation have been eliminated from VectorGA. The resulting code is short, fast and simple. It is a neat coincidence when the constructs of a programming language match a programming task so well that a program can be written this succintly.

VectorGA is proof that Matlab is a useful language for the rapid prototyping of Genetic Algorithms. This, in addition to Matlab’s extensive data visualization capabilities, make Matlab an extremely useful platform for the experimental analysis of GAs.

VectorGA has been created and tested under Matlab 7 (R14). Out of the box it evolves a population against the one-max fitness function. The royal-roads fitness function has also been included but is not currently being called. If you find vectorGA useful or find any bugs please let me know.

Enjoy!

Original vectorGA release site

The latst version of VectorGA is SpeedyGA

Advertisement

6 Comments

  1. Sayeh said,

    May 19, 2007 at 10:08 am

    That was very usefull for me :)

  2. D.Jeya Mala said,

    May 24, 2007 at 4:46 am

    It will be useful for me in my research

  3. Masaya said,

    October 1, 2007 at 3:28 am

    It is very useful.
    I found a small bug.Please check it.

    line 43
    %%%%%%%%%%%%%%%%%%%%%%%%
    if size(nargin==1)
    rand(‘state’,varargin{:});
    else
    rand(‘state’,sum(100*clock));
    end
    %%%%%%%%%%%%%%%%%%%%%%%%

                    ↓

    %%%%%%%%%%%%%%%%%%%%%%%%
    if size(varargin)==1
    rand(‘state’,varargin{:});
    else
    rand(‘state’,sum(100*clock));
    end
    %%%%%%%%%%%%%%%%%%%%%%%%

  4. Keki said,

    November 19, 2007 at 11:59 pm

    You’re right. That is a bug. Thanks!

  5. Panos said,

    May 9, 2008 at 3:55 pm

    Interesting and useful.
    Any plans to port it to SCILAB (http://www.scilab.org)?
    Regards

  6. Durai said,

    May 21, 2008 at 3:34 am

    I think it may be useful for my project


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.