Genetic Algorithms with gaoptim package

January 2, 2013

(This article was first published on Random Miner, and kindly contributed to R-bloggers)

Two days ago i just submitted my first R package: gaoptim. For my surprise, the next day it was already living on CRAN.

In this post i want to show you how to use gaoptim to perform a simple function maximization. This same task could be accomplished with the function optim() from the stats package, but this should serve as a simple introduction to Genetic Algorithms, which are particularly good when you have a huge search space.

The R code below defines a ‘wild’ function, with global maximum at about -15.81515. Then we setup a GAReal object and call the evolve() function, passing the number of generations to evolve as argument. Finally, we plot the results.

Some planned features for the next package version are:

  • feature selection
  • binary encoding

Enjoy it!

To leave a comment for the author, please follow the link and comment on their blog: Random Miner. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)