이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
resuming and starting from new line in genetic algorithm after specific generations
조회 수: 2 (최근 30일)
이전 댓글 표시
Hamid
2014년 11월 5일
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
Geoff Hayes
2014년 11월 7일
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
2014년 11월 7일
Deae Geoff.
I want to use genetic algorithm from 0-100 generations for my project then from 101-200 generations for my project with a little change in it and so on until generations 800.
In fact I want these simulations will be continuos and connencted.
My m file commands some input at the first, These changes after specific generations comes to one of them and I don't how to this.
I attached my project and the changes will happen in f-matrix in GAmodule (GAmodule is main function).
Thank you Geoff.
Geoff Hayes
2014년 11월 8일
Hamid - rather than attaching an unknown zip file, consider attaching the m files instead.
Geoff Hayes
2014년 11월 9일
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
2014년 11월 9일
편집: Hamid
2014년 11월 9일
I want to change f-matrix every 100 generations and I'm partly sure that a solution better happen at the end of generation 700, beside I don't have another choice and I have to inject all these 7 conditions.
for example : nn=20 nb=4 nl=6
case 1 (0-100 generations) : f(13)=800 f(14)=0 f(15)=-1000 and so on
case 2 (101-200 generations) : f(13)=0 f(14)=700 f(15)=-500 and so on
also I used 5 for an experiment and the right one is 700 generations.
Thank you very much Geoff for helping me.
Hamid
2014년 11월 9일
Dear Geoff - my final goal is to reaching to best solution under all 7 conditions together, these conditions only difference in f-matrix.
What do you recommend?????
I'm so confused and I'm gonna be crazy.
답변 (1개)
Geoff Hayes
2014년 11월 10일
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
Hamid
2014년 11월 10일
Dear Geoff
[x,fval,exitflag,output,population]=ga(@(x)penalty2(x,...,options);
Time=toc;
% 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,...,options);
I write these in my m file but It gets an error :
??? Error using ==> bin2dec at 36
Binary string must be 52 bits or less.
I think I don't get that you thought me and this is bad writing.
please write the whole script that I must change including loop to me Geoff.
Thank you very very much.
Geoff Hayes
2014년 11월 10일
Hamid - please post/attach your updated code with comments indicating what changes you have made.
Hamid
2014년 11월 10일
Geoff - I only add these lines to my file (line 168-171)
% 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,...,options);
rest of the file is remained unchanged.
Thanks.
Geoff Hayes
2014년 11월 10일
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
2014년 11월 11일
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
2014년 11월 11일
Dear Geoff - you were right and popSize and Initpop are the same size.
I know what you saying but I can't fulfill it correctly.
these are my codes with new changes :
[x,fval,exitflag,output,popSize] = ga(@(x) penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),Nvars,options);
Time=toc;
% re-use the population as the initial population for the next 100 generations
options = gaoptimset('InitialPopulation', popSize);
f=zeros(3*nn,1);
for i=nb+1:nb+nl
f(3*i-2)=input(['For load node ',num2str(i-nb),' please specify the X-resultant of the load! (N) ']);
f(3*i-1)=input(['For load node ',num2str(i-nb),' please specify the Y-resultant of the load! (N) ']);
f(3*i)=input(['For load node ',num2str(i-nb),' please specify the Z-resultant of the load! (N) ']);
end
% run the algorithm
[x,fval,exitflag,output,popSize] = ga(@(x) penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),Nvars,options);
but I kept this error again :
??? Error using ==> bin2dec at 36
Binary string must be 52 bits or less.
please write the codes for me.
You are the best Geoff, thanks a lot.
Geoff Hayes
2014년 11월 11일
편집: Geoff Hayes
2014년 11월 11일
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
2014년 11월 12일
??? Error using ==> bin2dec at 36
Binary string must be 52 bits or less.
Error in ==> bintranslate at 137
if ceil(bin2dec(num2str(chromosome4(i-(numbitEp-1):i))))>na
Error in ==> penalty2 at 38
[Coord,Edof2,Ep2]=bintranslate(available,chromosome,Dof,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,xspan,yspan,zspan);
Error in ==>
GAmodule>@(x)penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan)
at 177
[x,fval,exitflag,output,popSize] = ga(@(x)
penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),Nva
Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 135
fitness = @(x) fitness(x,FitnessFcnArgs{:});
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> stepGA at 45
nextScore = fcnvectorizer(nextPopulation,FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 85
[score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in ==> ga at 279
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in ==> GAmodule at 177
[x,fval,exitflag,output,popSize] = ga(@(x)
penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),Nva
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Geoff Hayes
2014년 11월 12일
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
2014년 11월 12일
Dear Geoff - I attached chromosome4 value as a jpeg file.
numbitEp is number of bits required in the different segments of the bit string and calculated:
numbitEp=ceil(log2(na));
na is always 256, then numbitEp is 8.
binary string because I need the obtained nodes coordinates.
No this is not matter and this does NOT make sense.
Thanks Geoff for helping me out.
Geoff Hayes
2014년 11월 13일
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
2014년 11월 13일
Geoff - with the same f I still have that error and this is not because of f matrix change.
When i is maximum for example i=80 ;
num2str(chromosome4(i-(numbitEp-1):i))= 1 1 0 0 1 0 1 1
It is less than 52 but I keep that error, What's wrong?
Thanks Geoff.
Geoff Hayes
2014년 11월 14일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)