搜索 问答 Rules & Tips
1. 遵守中国大陆相关法律法规
2. 在虫部落的提问准则
3. 禁止发布代下载类求助信息
4. 特别提倡抛砖引玉的问题
5. 扩展阅读:提问的智慧

matlab 代码复现问题

查看: 822|回复: 4
1
周鱼佬 发表于 2023-11-4 17:57:14
未解决20Bit
情况是这样的,我下载了一篇文献的代码,是动态多目标问题的,连接放这里,有兴趣的老哥可以看看

第一个,基于历史的,问题是他给的代码是函数,如何在platemo平台上跑呢,我试着处理了一下,报错,原来代码是这样的

  1. function [PopX,Pareto,POF_iter,POS_iter]=NSGAII22( Problem,popSize,MaxIt,t,T_parameter,group,Mp,hisPareto,Mm,ni,bi,ci,numi,init_pop)

  2.     %% Generate random population
  3. %     Population = Global.Initialization();
  4. CostFunction=Problem.FObj;  % Cost Function
  5. nVar=size(Problem.XLow,1);             % Number of Decision Variables
  6. VarSize=[nVar 1];   % Decision Variables Matrix Size
  7. detect_py=0;
  8. VarMin=Problem.XLow;
  9. VarMax=Problem.XUpp;
  10. T=size(hisPareto,2)+1;
  11.    
  12. nObj=Problem.NObj;
  13. nPop=popSize;    % Population Size (Number of Sub-Problems)
  14. nArchive=100;
  15. Lower = repmat(VarMin,1,nPop);
  16. Upper = repmat(VarMax,1,nPop);
  17. crossover_params.gamma=0.5;
  18. crossover_params.VarMin=VarMin;
  19. crossover_params.VarMax=VarMax;
  20. empty_individual.Position=[];
  21. empty_individual.Cost=[];
  22. pop=repmat(empty_individual,nPop,1);
  23. Off=repmat(empty_individual,nPop,1);
  24. Offspring=repmat(empty_individual,nPop,1);
  25. gailv=0.5;
  26. gailv2=0.1;
  27. zhixing1=1;
  28. zhixing2=1;
  29. traindata=[];
  30. testdata=[];
  31. if nargin == 6
  32.     MaxIt=50;
  33. %     MaxIt=1000;
  34.     for i=1:nPop
  35.         pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
  36.         pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
  37.     end
复制代码


然后在 platemo 上是这样的:

  1. classdef NSGAII_HEL < ALGORITHM
  2. % <multi> <real/integer/label/binary/permutation> <constrained/none><dynamic>
  3. % Nondominated sorting genetic algorithm II

  4. %------------------------------- Reference --------------------------------
  5. % K. Deb, A. Pratap, S. Agarwal, and T. Meyarivan, A fast and elitist
  6. % multiobjective genetic algorithm: NSGA-II, IEEE Transactions on
  7. % Evolutionary Computation, 2002, 6(2): 182-197.
  8. %------------------------------- Copyright --------------------------------
  9. % Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
  10. % research purposes. All publications which use this platform or any code
  11. % in the platform should acknowledge the use of "PlatEMO" and reference "Ye
  12. % Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
  13. % for evolutionary multi-objective optimization [educational forum], IEEE
  14. % Computational Intelligence Magazine, 2017, 12(4): 73-87".
  15. %--------------------------------------------------------------------------

  16.     methods
  17.         function main(Algorithm,Problem)
  18.             %% Generate random population
  19. %     Population = Global.Initialization();
  20. CostFunction=Problem.FObj;  % Cost Function
  21. nVar=size(Problem.XLow,1);             % Number of Decision Variables
  22. VarSize=[nVar 1];   % Decision Variables Matrix Size
  23. detect_py=0;
  24. VarMin=Problem.XLow;
  25. VarMax=Problem.XUpp;
  26. T=size(hisPareto,2)+1;
  27.    
  28. nObj=Problem.NObj;
  29. nPop=popSize;    % Population Size (Number of Sub-Problems)
  30. nArchive=100;
  31. Lower = repmat(VarMin,1,nPop);
  32. Upper = repmat(VarMax,1,nPop);
  33. crossover_params.gamma=0.5;
  34. crossover_params.VarMin=VarMin;
  35. crossover_params.VarMax=VarMax;
  36. empty_individual.Position=[];
  37. empty_individual.Cost=[];
  38. pop=repmat(empty_individual,nPop,1);
  39. Off=repmat(empty_individual,nPop,1);
  40. Offspring=repmat(empty_individual,nPop,1);
  41. gailv=0.5;
  42. gailv2=0.1;
  43. zhixing1=1;
  44. zhixing2=1;
  45. traindata=[];
  46. testdata=[];
  47. if nargin == 6
  48.     MaxIt=50;
  49. %     MaxIt=1000;
  50.     for i=1:nPop
  51.         pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
  52.         pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
  53.     end
  54. elseif nargin > 6
  55.     if size(init_pop,1)< popSize
  56.         newpop = addNoise(init_pop, popSize, size(init_pop,2));
  57.         init_pop = [init_pop' newpop'];
  58.     else
  59.         init_pop = init_pop';
  60.     end
  61.     init_pop  = max(min(init_pop,Upper),Lower);
  62.     for i=1:size(init_pop,2)
  63.         pop(i).Position=init_pop(:,i);
  64.         pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
  65.     end
  66. end
复制代码
这可咋办

补充内容 (2023-11-4 17:58):
报错图片没出来,这里补上
未识别类 'FDA1' 的方法、属性或字段 'FObj'。

出错 NSGAII_HEL/main (第 22 行)
CostFunction=Problem.FObj;  % Cost Function

出错 ALGORITHM/Sol...
windyer 发表于 2023-11-4 18:14:01
写成函数,老老实实按参数调用不就好了
 楼主| 周鱼佬 发表于 2023-11-4 18:44:04
windyer 发表于 2023-11-4 18:14
写成函数,老老实实按参数调用不就好了

不是啊,platemo要写成类
windyer 发表于 2023-11-4 22:52:58
周鱼佬 发表于 2023-11-4 18:44
不是啊,platemo要写成类

这就不是matlab问题,而是platemo这个包的问题,你应该去该项目的github问问,或者对应群。
 楼主| 周鱼佬 发表于 2023-11-5 11:14:52
windyer 发表于 2023-11-4 22:52
这就不是matlab问题,而是platemo这个包的问题,你应该去该项目的github问问,或者对应群。 ...

对 我不会用platemo框架
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

虫部落 陕ICP备14001577号-1川公网安备 51019002003015号联系我们FAQ关于虫部落免责声明虫部落生存法则蛙先知 - AI 玩家社区 🚧

Build with for "make search easier" Copyright © 2013-2024. Powered by Discuz! GMT+8, 2024-5-11 13:52

快速回复 返回顶部 返回列表