遗传算法ga如何导出每代的最佳适应度和平均适应度函数值?
显示 更早的评论
用的2021a版本,help给的函数样例为[x,fval,exitflag,output,population,scores] = ga(___)
输出参数没有每代的过程变量。
每代的最佳适应度和平均适应度函数值会给出一张图,但我想知道确切的值。

回答(1 个)
打开ga函数,从后往前找,大概400行左右,根据你的优化问题类型找到对应的求解函数,比如我之前用线性规划的时候就打开galincon这个函数,在galincon的第95行代码:state.Best(generation) = fval;后边添加以下两行代码:
output.fitever(generation) = fval;%######
output.bestpopulationever(generation,:) = state.Population(best,:);%#######
这样在调用ga函数的时候输出变量output这个结构体里就保存了历史最优适应度fitever和历史最优种群bestpopulationever。
更具体的可以参考以下两个链接:
类别
在 帮助中心 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!