resuming and starting from new line in genetic algorithm after specific generations
Show older comments
Hi,
I want to resume and start from new line in genetic algorithm after specific generations.
Has anyone know How is impossible??
Any suggestion may help a lot.
Thank you guys.
7 Comments
Geoff Hayes
on 7 Nov 2014
Hamid - please clarify what you mean by wanting to start from new line in genetic algorithm after specific generations. What is a new line?
Hamid
on 7 Nov 2014
Geoff Hayes
on 8 Nov 2014
Hamid - rather than attaching an unknown zip file, consider attaching the m files instead.
Hamid
on 8 Nov 2014
Geoff Hayes
on 9 Nov 2014
Hamid - what type of change do you want to inject into the population at the start of generation 101? It may be that the population has converged to a solution prior to generation 100, so continuing the genetic algorithm for another 700 iterations may not lead to a better solution. (I noticed that currently you use 5 generations only...)
Hamid
on 9 Nov 2014
Answers (1)
Geoff Hayes
on 10 Nov 2014
Hamid - I don't think that I can give a valid recommendation because I don't know enough of what you are trying to do. f seems to be a matrix used in the fitness function, but I can't guess as to its impact or that of changing a handful of its values. But if you want to try and re-use the population after 100 iterations with a slight change to the f matrix, then you could change your return from the ga function of
[x,fval]=ga(@(x) penalty2(x,available,bc,Dof,E...),Nvars,options);
to
[x,fval,exitflag,output,population] = ga(@(x)penalty2(x,available,bc,Dof, E...),Nvars,options);
The population output parameter will be the final population for (say) 100 iterations of the algorithm. You then update the f matrix, and re-call
% re-use the population as the initial population for the next 100 generations
options = gaoptimset('InitialPopulation', population);
% run the algorithm
[x,fval,exitflag,output,population] = ga(@(x)penalty2(x,available,bc,Dof, E...),Nvars,options);
for 100 more generations. Then change f to whatever you want. You can put this in a loop that iterates from 1 through to 7, and you would change f on each iteration.
However, this method may not work as expected especially if the GA has converged to a premature solution before generation 100. If all members of the population are identical (or near-identical) then there will not be enough genetic diversity in the next round of 100 generations to produce any new members even though you have changed the f matrix.
19 Comments
Hamid
on 10 Nov 2014
Geoff Hayes
on 10 Nov 2014
Hamid - please post/attach your updated code with comments indicating what changes you have made.
Hamid
on 10 Nov 2014
Geoff Hayes
on 10 Nov 2014
Hamid - compare the matrix population with Initpop with respect to their sizes. Do they both have the same number of rows and columns?
I noticed that you didn't try to change the f matrix when running the second set of generations. Why not?
Geoff Hayes
on 11 Nov 2014
population, which is one of the return values from the updated call to ga should be a matrix. I'm not referring to your local variable of Population which is the number of organisms in your population (you should name this variable popSize or something similar). So please verify again what this output from the ga function is.
Unfortunately, I don't have the Global Optimization Toolbox so I can't run your code. Since you want to change the f matrix at after each batch of 100 generations then it seems to me that you need to do the following:
- Run the GA for the first 100 generations.
- Change the f matrix.
- Run the GA for the next 100 generations.
- Repeat steps 2 to 3 until the f matrix has been updated the required number of times.
Hamid
on 11 Nov 2014
Hamid
on 11 Nov 2014
Geoff Hayes
on 11 Nov 2014
Edited: Geoff Hayes
on 11 Nov 2014
Hamid - where is the bin2dec being called from? There must be more to the error than that which you are showing. Please copy and paste all of the red text that corresponds to this error into a comment.
Hamid
on 12 Nov 2014
Geoff Hayes
on 12 Nov 2014
Before running your code, type the following in the Command Window
dbstop if error
Now re-run your code. When the error is encountered, the debugger will pause at the line that is generating the error. So that should be at line
if ceil(bin2dec(num2str(chromosome4(i-(numbitEp-1):i))))>na
Look at
chromosome4(i-(numbitEp-1):i)
What is the value of this chromosome? What is i? What is numbitEp? Why is it a binary string? Once converted to a string, it must have more than 52 bits. Does this make sense for the problem that you are trying to solve?
Hamid
on 12 Nov 2014
Hamid
on 13 Nov 2014
Geoff Hayes
on 13 Nov 2014
Hamid - you are going to have step through the code and determine why you are observing invalid values. Determine when the error occurs, i.e. which iteration/generation of the second batch. Is it because the f matrix has changed? What happens if you use the same f matrix from the previous 100 generations - do you still observe an error? Use breakpoints and the debugger to help.
Hamid
on 13 Nov 2014
Geoff Hayes
on 13 Nov 2014
How does i become 80?
Hamid
on 13 Nov 2014
Geoff Hayes
on 14 Nov 2014
Hamid - you will have to work backwards from the above in order to determine what the problem is. Consider how nevt and neft are initialized and/or updated.
Hamid
on 14 Nov 2014
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!