Closed swaheera closed 3 years ago
The issue is that you try to adapt R code for a one-dimensional and two-dimensional problems to your case, which is a 7-dimensional problem. Simply you can't do that and when you try R will give errors. For instance, when you use
curve(fitness, from = lbound, to = ubound, n = 1000)
you are trying to plot the one-dimensional function fitness
from lbound
to ubound
on a regular grid of n
points. But fitness
has 7 input arguments. How you can do that?
I am working with R. I am following this tutorial (https://cran.r-project.org/web/packages/GA/vignettes/GA.html) and am learning how to optimize functions using the "genetic algorithm".
The entire process is illustrated in the code below:
Part 1: Generate some sample data ("train_data")
Part 2: Define the "fitness function" : the objective of my problem is to generate 7 random numbers :
"split_3" (between 0 and 1 )
and use these numbers to perform a series of data manipulation procedures on the train data. At the end of these data manipulation procedures, a "total" mean variable is calculated.
Part 3: The purpose of the "genetic algorithm" is to find the set of these 7 numbers that produce the largest value of the "total".
Below, I illustrate this entire process :
Part 1
Part 2
Part 3
The above code (Part 1, Part 2, Part 3) all work fine.
Problem: Now, I am trying to produce some the of the visual plots from the tutorial:
First Plot - This Works:
plot(GA)
But I can't seem to produce the other plots from the tutorial:
Second Plot: Does Not Work
Third Plot : Does Not Work
Fourth Plot: Does Not Work
Can someone please show me how to fix these errors?
Thanks