Skip to content

Function in Genetic Algorithms

1 message · Daniel Patón

#
Dear colleagues:

I'm trying to fit a model by Genetic Algorithms. In the GAFIT package the expression I use for fitting is:

fitness <- expression((Z - (X^a + Y^b))^2)

Y a and b are coefficients of the variables X and Y. Z is the output variable.

When I try to use another package (rgenoud, GA, etc...) I must put the syntax in function form. I use this:

fitness <- function(X,Y,Z) { 
Z <- trees$BIOMASS
X <- trees$DIAMETER
Y <- trees$HEIGHT
observed <- (X + X^2 + Y + Y^2 + X*Y)
expected <- Z
error <- (observed-expected)^2
return(error)
}

I don't know what I'm doing wrong. 

I'd appreciate a little help.
Thank you