rbga                 package:genalg                 R Documentation

_R _B_a_s_e_d _G_e_n_e_t_i_c _A_l_g_o_r_i_t_h_m (_f_l_o_a_t_i_n_g _p_o_i_n_t _c_h_r_o_m_o_s_o_m_e)

_D_e_s_c_r_i_p_t_i_o_n:

     A R based genetic algorithm that optimizes, using a user set
     evaluation function, a set of floats. It takes as input minimum
     and maximum values for the floats to optimizes. The optimum is the
     chromosome for which the  evaluation value is minimal.

     It requires a 'evalFunc' method to be supplied that takes as
     argument the chromosome, a vector of floats. Additionally, the GA
     optimization can be monitored by setting a  'monitorFunc' that
     takes a 'rbga' object as argument.

     Results can be visualized with 'plot.rbga' and summarized with
     'summary.rbga'.

_U_s_a_g_e:

     rbga(stringMin=c(), stringMax=c(),
          suggestions=NULL,
          popSize=200, iters=100,
          mutationChance=NA,
          elitism=NA,
          monitorFunc=NULL, evalFunc=NULL,
          showSettings=FALSE, verbose=FALSE)

_A_r_g_u_m_e_n_t_s:

stringMin: vector with minimum values for each gene.

stringMax: vector with maximum values for each gene.

suggestions: optional list of suggested chromosomes

 popSize: the population size.

   iters: the number of iterations.

mutationChance: the chance that a gene in the chromosome mutates. By
          default 1/(size+1). It affects the convergence rate and the
          probing of search space: a low chance results in quicker
          convergence, while a high chance increases the span of the
          search space.

 elitism: the number of chromosomes that are kept into the next
          generation. By default is about 20% of the population size.

monitorFunc: Method run after each generation to allow monitoring of
          the optimization

evalFunc: User supplied method to calculate the evaluation function for
          the given chromosome

showSettings: if true the settings will be printed to screen. By
          default False.

 verbose: if true the algorithm will be more verbose. By default False.

_R_e_f_e_r_e_n_c_e_s:

     C.B. Lucasius and G. Kateman (1993). Understanding and using
     genetic algorithms - Part 1. Concepts, properties and context.
     _Chemometrics and Intelligent Laboratory Systems 19:1-33_.

     C.B. Lucasius and G. Kateman (1994). Understanding and using
     genetic algorithms - Part 2. Representation, configuration and
     hybridization. _Chemometrics and Intelligent Laboratory Systems
     25:99-145_.

_S_e_e _A_l_s_o:

     'rbga.bin'

_E_x_a_m_p_l_e_s:

     # optimize two values to match pi and sqrt(50)
     evaluate <- function(string=c()) {
         returnVal = NA;
         if (length(string) == 2) {
             returnVal = abs(string[1]-pi) + abs(string[2]-sqrt(50));
         } else {
             stop("Expecting a chromosome of length 2!");
         }
         returnVal
     }

     monitor <- function(obj) {
         # plot the population
         xlim = c(obj$stringMin[1], obj$stringMax[1]);
         ylim = c(obj$stringMin[2], obj$stringMax[2]);
         plot(obj$population, xlim=xlim, ylim=ylim, xlab="pi", ylab="sqrt(50)");
     }

     rbga.results = rbga(c(1, 1), c(5, 10), monitorFunc=monitor, 
         evalFunc=evaluate, verbose=TRUE, mutationChance=0.01)

     plot(rbga.results)
     plot(rbga.results, type="hist")
     plot(rbga.results, type="vars")

