I am trying to use the rbga.bin genetic function in R.
I have a dataframe with 40 observations (rows) and 189 metrics (columns). In the evaluation function, I have to run a Principal Component Analysis on both the original dataset and the "chromosome dataset" (i.e., the dataframe with some of the metrics columns - the ones that have 1s in the chromosome) in order to produce the fitness score.
For example, a possible solution (chromosome) is the following:
(1,1,1,0,0,...,0)
The solution dataset that I would want to run a PCA on, would just have only the first 3 columns of the original dataset.
How can I refer to that "reduced" dataset inside the evaluation function?
It seems that the variable you provide to the evaluation function is the chromosome, i.e. the binary vector. You can get the reduced dataset the following way.
Assume chromosome
is the binary vector, original is the starting dataframe and reduced is the resulting dataframe with only the columns that are 1 in the chromosome.
reduced = !!chromosome
reduced = original[reduced]