Hello,
I am using the EO-Lib in my project and now I have a problem with the eoEasyEA.
My individual has a length of 34 and if I use exactly the same code described in lesson 3 (for initialisation, selection and replacement, variation operators, termination condition etc. ) I got the following exception.
invalid vector<T> subscript in eoEasyEA.
The only thing I changed is the fitness-function.
Any ideas?
Thanks a lot.
Carsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay... I solved this problem by myself. I'm not an expert in genetic algorithm, but maybe there is a little bug in the EOLib. I try to explain it.
By using the eoUniformGenerator<double> uGen(0.0, 1.0) I generate individuals with random numbers between 0.0 and 1.0.
I use the random numbers to choose between several parameters I stored in a std::vector<double>. With the random number I calculate the position of the parameter I want to choose. For example I have a vector with size 6 in which I stored my parameters, I calculate the position of the parameter I choose by using one of the genes.
int positionOfParameter = (int)(gene * vectorsize-1)+0.5; //+0.5 round
double parameter = getParameter(positionOfParameter); //get the parameter at position
If I use exactly the same initialisation, selection and replacement, variation operators, termination condition etc. used in lesson3, I suddenly get some random numbers in my individual that are greater than 1.0 or smaller than 0.0 like 1.26..., 1.67...,-0.01...
If I calculate the position of my parameter with numbers out of bounds [0.0,1.0] I get the exception described above.
Now my question. Is this a bug, or a feature? Maybe it's volitional that the operators of the GA generate numbers out of bounds?
Nevertheless, thank you for this great Lib.
Carsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
as Maarten already pointed out this is difficult to decide without any code. Can you please post a minimal example [1] that shows the problem, so we can reproduce it?
Greetings,
Jochen
[1] A "minimal example" is a complete C++ program consisting of a few lines of code that still shows the problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
int positionOfParameter = (int)(gene * vectorsize-1)+0.5; //+0.5 round
doesn't really round, you need:
int positionOfParameter = (int)floor(gene * vectorsize);
What you currently get, I think, is that the last position in the vector will never be chosen.
But I don't think that that is your issue. What seems to be the case is that your mutation operators are unguarded, i.e., there is no mechanism in place that keeps the values in your genotype between 0 and 1. There is support for that, but you have to get into Lesson 4 for that. They are called internally eoRealBounds and are used to implement constraints on the boundaries of the objective variables.
Hope this helps,
-Maarten-
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to (hopefully) make myself completely clear: mutation is an operation that takes an existing value (possibly generated by your uGen), and changes it a tiny bit. If that operator doesn't know about any bounds, it will happily suggest a value larger than 1 or smaller than 0.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Maarten,
thank you for your quick response and yes... it helps!
To be honest, I didn't make the Lesson 4 yet, so I didn't know something about guarded and unguarded mutation operators. I think I have to get into it.
Thank you very much for your support.
Carsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am using the EO-Lib in my project and now I have a problem with the eoEasyEA.
My individual has a length of 34 and if I use exactly the same code described in lesson 3 (for initialisation, selection and replacement, variation operators, termination condition etc. ) I got the following exception.
invalid vector<T> subscript in eoEasyEA.
The only thing I changed is the fitness-function.
Any ideas?
Thanks a lot.
Carsten
I honestly haven't got a clue. Can you attach the fitness function you're using?
-Maarten-
Okay... I solved this problem by myself. I'm not an expert in genetic algorithm, but maybe there is a little bug in the EOLib. I try to explain it.
By using the eoUniformGenerator<double> uGen(0.0, 1.0) I generate individuals with random numbers between 0.0 and 1.0.
I use the random numbers to choose between several parameters I stored in a std::vector<double>. With the random number I calculate the position of the parameter I want to choose. For example I have a vector with size 6 in which I stored my parameters, I calculate the position of the parameter I choose by using one of the genes.
int positionOfParameter = (int)(gene * vectorsize-1)+0.5; //+0.5 round
double parameter = getParameter(positionOfParameter); //get the parameter at position
If I use exactly the same initialisation, selection and replacement, variation operators, termination condition etc. used in lesson3, I suddenly get some random numbers in my individual that are greater than 1.0 or smaller than 0.0 like 1.26..., 1.67...,-0.01...
If I calculate the position of my parameter with numbers out of bounds [0.0,1.0] I get the exception described above.
Now my question. Is this a bug, or a feature? Maybe it's volitional that the operators of the GA generate numbers out of bounds?
Nevertheless, thank you for this great Lib.
Carsten
Dear Carsten,
as Maarten already pointed out this is difficult to decide without any code. Can you please post a minimal example [1] that shows the problem, so we can reproduce it?
Greetings,
Jochen
[1] A "minimal example" is a complete C++ program consisting of a few lines of code that still shows the problem.
Hi Carsten, hope you get this message,
First of:
int positionOfParameter = (int)(gene * vectorsize-1)+0.5; //+0.5 round
doesn't really round, you need:
int positionOfParameter = (int)floor(gene * vectorsize);
What you currently get, I think, is that the last position in the vector will never be chosen.
But I don't think that that is your issue. What seems to be the case is that your mutation operators are unguarded, i.e., there is no mechanism in place that keeps the values in your genotype between 0 and 1. There is support for that, but you have to get into Lesson 4 for that. They are called internally eoRealBounds and are used to implement constraints on the boundaries of the objective variables.
Hope this helps,
-Maarten-
Just to (hopefully) make myself completely clear: mutation is an operation that takes an existing value (possibly generated by your uGen), and changes it a tiny bit. If that operator doesn't know about any bounds, it will happily suggest a value larger than 1 or smaller than 0.
Hi Maarten,
thank you for your quick response and yes... it helps!
To be honest, I didn't make the Lesson 4 yet, so I didn't know something about guarded and unguarded mutation operators. I think I have to get into it.
Thank you very much for your support.
Carsten