Generate GA Plot after the algorithm has finnished

조회 수: 10 (최근 30일)
Marcus Heßeling
Marcus Heßeling 2021년 1월 8일
댓글: Star Strider 2021년 1월 11일
Hey Guys,
i have a very complex function to optimize with GA, its already need about 5 hours without a plot activated, so i want to generate a plot with the results after the algorithm is finished. So far, i always saved the command window information with "diary", so the savings kinda looks like this and repeat :
....
x: 30.80606 105.0739 5 0.8621733 0.3187652 0.1 0.1 0.3426245 3.578397 obj: 3.2365
x: 96.6515 60.2254 91.6727 5.78384 5.89348 5.14982 6.43606 2.48569 4.53104 obj: 1.78
x: 79.81447 78.14723 129.7414 1.610127 8.481399 6.818627 6.844434 4.471865 3.497146 obj: 2.0136
x: 73.6651 98.8845 83.1789 1.94892 0.758555 3.55138 8.41613 3.0194 8.43609 obj: 3.0492
x: 64.6236 65.0341 94.9168 3.92559 1.34072 0.766707 0.114988 3.19566 7.77677 obj: 3.0613
x: 136.7348 21.8462 117.6277 7.317458 9.027388 0.8396103 2.702008 0.551372 7.5124 obj: 1.8702
x: 131.5978 44.16512 132.7881 2.824445 9.458292 5.58881 3.89878 8.731667 7.22164 obj: 2.3449
x: 33.4331 144.1815 21.22591 9.646141 7.317277 6.503243 1.924164 1.892613 1.564883 obj: 1.1898
x: 78.5224 79.2316 97.9015 1.87417 0.963924 0.498753 8.43496 8.31711 0.845001 obj: 3.0582
Warning: Reference to non-existent field 'xx'.
> In Simulink/SimulationOutput/get
In Simulink/SimulationOutput/subsref
In Simulink/SimulationOutput/numArgumentsFromSubscript
.....
so far my main code looks like this :
options = optimoptions('ga','Display','iter','OutputFcn', @myoutputFunc,'UseParallel', true,'ConstraintTolerance',1e-5,'PopulationSize',1000,'TimeLimit',60*60*60);
[xopt,fval,exitflag,output,population,scores] = ga(@objective,9,[],[],[],[],lb,ub,@constraint,options);
Is it possible to generate a plot out of these information or do i need to change something ?
Thank you

채택된 답변

Star Strider
Star Strider 2021년 1월 8일
I am not certain what you want to do.
If you want to save the interim results to plot later (or to save them in the event that MATLAB crashes for some reason), see: How to save data from Genetic Algorithm in case MATLAB crashes? It offers a way to save the ‘fittest’ individual to a .mat file at each iteration.
.
  댓글 수: 6
Marcus Heßeling
Marcus Heßeling 2021년 1월 11일
Hey Star Strider,
sorry to bother again but i still have problems implementing your code: Where do i have to implement/call your SaveOut function to make it work in the GA
Thanks
Star Strider
Star Strider 2021년 1월 11일
No worries!
It is an output function (formally: 'OutputFcn'), so it needs to be included in the optimoptions ‘opts’ structure. (I could not find the code I originally used to test it — unusual for me — so I had to reconstruct some example code that I am attaching here. I apologise for the resulting delay.)
The optimoptions call to include it is:
opts = optimoptions('ga', 'PopulationSize',PopSz, 'InitialPopulationMatrix',randi(1E+4,PopSz,Parms)*1E-3, 'MaxGenerations',2E3, 'PlotFcn',@gaplotbestf, 'PlotInterval',1, 'OutputFcn',@SaveOut);
↑ ← HERE
The attached code includes the ‘SaveOut’ function and all the necessary coding infrastructure required to use it. (I tested this code to be certain that it works and does what I intend it to do.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by