How do you get fval with iterations out of ga and particleswarm (genetic algorithms and particle swarm)

조회 수: 2 (최근 30일)
Currently I have:
[s_best,fval_best] = ga(fhandleformatlab,d_fun,[],[],[],[],lb_fun, ub_fun,[],[],options);
[s_best,fval_best,~,~] = particleswarm(fhandleformatlab,d_fun,lb_fun, ub_fun,options);
But I want to save the result of fval at each iteration/generation to an array, so I can analyse how fast the algorithm converges to optimum. I cannot see how to get this output into an array in the matlab workspace.
Note - I do not merely want to display the output, which I can do. I cannot figure out how to output it to an array in the workspace so I can plot it, analyse it etc.

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 1일
You would initialize an array and you would have the output function append to the array each time it was called. I recommend using nested functions for this purpose so that you avoid the temptation of global variables.
  댓글 수: 2
JMP Phillips
JMP Phillips 2015년 9월 4일
Hi Walter, I just use the evalin function to append it to a variable in the calling function or workspace each iteration.
Mark Brandon
Mark Brandon 2019년 9월 14일
Several years have gone by, but I would be interested in this solution you found. Can provide more detail?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by