0

i have no idea, Is this plot appropriate because the fitness function I created is like that? output plot

here is the code:

library(GA)
frame_uji <-  data.matrix(data_uji)
sum_fu <- matrix(0, nrow = 350, ncol = 1)
sum_fu <- c(rowSums(frame_uji))

setup <- function(x)
{   

    output_fitness <- numeric()
    for (i in 1:350) {
        output_fitness <- c(output_fitness, 1 / (1 + sum_fu[i])) 
    }
    
    output_fitness
}

gann <- ga(type = "real-valued", population = , fitness = setup, lower = 1, upper = 5, 
           selection = gareal_rwSelection, crossover = gareal_spCrossover, 
           mutation = gareal_rsMutation, popSize = 350, maxiter = 350, 
           pcrossover = 0.6 , pmutation = 0.1, run = 30)
summary(gann)
plot(gann)

note: whereas the code I want to display is like this (https://rpubs.com/Argaadya/550805), fitness_function from web rpubs. and this is a mathematical equation that I applied fitness_math_equation;

if i separate the setup function in another chunk, it looks like this'output_fitness'

frame_uji;data_uji

Noval
  • 1
  • 4
  • just do `output_fitness <- 1/sum(sum_fu)` – Onyambu Nov 24 '21 at 18:14
  • 1
    We cannot replicate this problem without the dataset. Please provide a reproducible dataset as an example (or a link to or subset of object data_uji). That said, this error sounds like you are trying to overwrite an existing object of a different size. I ran your code using `data(mtcars)` and did not get any errors. – Jessica Burnett Nov 24 '21 at 18:17
  • Note that the function does not even use the passed argument. What the purpose of `x` if its note used?. – Onyambu Nov 24 '21 at 18:25
  • okie dokie then, thanks @Onyambu – Noval Nov 26 '21 at 08:47
  • @JessicaBurnett when you execute the code the plot looks the same as this? https://i.stack.imgur.com/m3XUf.png – Noval Nov 26 '21 at 09:22
  • Yes, but fitness is constant at 0.0030 – Jessica Burnett Nov 26 '21 at 18:37
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 29 '21 at 09:41

0 Answers0