Learn R Programming

mcga (version 1.0)

mcga: mcga

Description

mcga package uses machine coded chromosomes for the real value optimization problems. Chromosomes are not encoded/decoded, the byte representation of the double values are used for crossing-over and mutation operations. This makes mcga extremely fast even the number of parameters is high. Values of the parameters are bounded with the machine double type.

mcga function is a wrapper for the C++ library.

Usage

mcga(popsize, chsize, elitism = 1, minval, maxval, maxiter = 10, evalFunc)

Arguments

popsize
Length of the population (The number of chromosomes in the population).
chsize
Length of the chromosomes (How many variables does a chromosome holds).
elitism
Best 'elitism' chromosomes will be copeid into next population.
minval
Lower bound for the variables. This bound is only used when the chromosomes are randomized at the beginning of the algorithm.
maxval
Lower bound for the variables. This bound is only used when the chromosomes are randomized at the beginning of the algorithm.
maxiter
Number of generations.
evalFunc
User defined R function subject to minimize. In the case of maximization type optimizations, this function may return -1 * cost.

Value

  • Returnes the sorted population of the last iteration.

Examples

Run this code
#Examples

#Evolution of PI
f<-function(x){
        return(abs(x-pi));
}

m<-mcga(500,1,1,-1000000,1000000,100,evalFunc=f);

print(m[1,]);



#Calculation LMS (Least median of squares) estimates
f<-function(candidates){
        res<-y-candidates[1]-candidates[2]*x
        return(median(res^2));
}

n<-100;
x<-rnorm(n);
e<-rnorm(n);
y<-5+5*x+e;

m<-mcga(popsize=500, chsize=2, minval=-9999999, maxval=9999999, evalFunc=f, maxiter=50)

print("Best solution for LMS:")
print(m[1,])
print("Cost is:")
print(f(m[1,]))

Run the code above in your browser using DataLab