pablo14/genetic-algorithm-feature-selection

custom fitness function not working

Opened this issue · 1 comments

I tried to run this algorithm. It started fine with data loading, x and y variables.
I had problems while executing the GA

Executing the GA

ga_GA_1 = ga(fitness = function(vars) custom_fitness(vars = vars,
data_x = data_x,
data_y = data_y,
p_sampling = 0.7), # custom fitness function
type = "binary", # optimization data type
crossover=gabin_uCrossover, # cross-over method
elitism = 3, # number of best ind. to pass to next iteration
pmutation = 0.03, # mutation rate prob
popSize = 50, # the number of indivduals/solutions
nBits = param_nBits, # total number of variables
names=col_names, # variable name
run=5, # max iter without improvement (stopping criteria)
maxiter = 50, # total runs or generations
monitor=plot, # plot the result at each iteration
keepBest = TRUE, # keep the best solution at the end
parallel = T, # allow parallel procesing
seed=84211 # for reproducibility purposes
)

I got the following:

Error in { : task 1 failed - "could not find function "custom_fitness""

How to solve this problem?

Pass the library as a relative path. For example
source("C:/Users/JhoanBorges/Downloads/genetic-algorithm-feature-selection-master/genetic-algorithm-feature-selection-master/lib_ga.R")