回归预测

您所在的位置:网站首页 matlab多输入单输出 回归预测

回归预测

2023-01-24 02:40| 来源: 网络整理| 查看: 265

%% 参数设置pop=5; % 种群数M=20; % 最大迭代次数dim=4;%一共有4个参数需要优化lb=[1 1 1 0.001];%分别对两个lstm隐含层节点 训练次数与学习率寻优ub=[100 100 50 0.01];%这个分别代表4个参数的上下界,比如第一个参数的范围就是1-100

P_percent = 0.2; %producers 在全部种群的占比pNum = round( pop * P_percent ); % producers的数量

for t = 1 : M

[ ~, sortIndex ] = sort( pFit );% Sort.从小到大 [fmax,B]=max( pFit ); worse= x(B,:); r2=rand(1); %%%%%%%%%%%%%5%%%%%%这一部位为发现者(探索者)的位置更新%%%%%%%%%%%%%%%%%%%%%%%%% if(r2(pop/2))%这个代表这部分麻雀处于十分饥饿的状态(因为它们的能量很低,也是是适应度值很差),需要到其它地方觅食 x( sortIndex(i ), : )=randn(1,dim).*exp((worse-pX( sortIndex( i ), : ))/(i)^2); else%这一部分追随者是围绕最好的发现者周围进行觅食,其间也有可能发生食物的争夺,使其自己变成生产者 x( sortIndex( i ), : )=bestXX+(abs(( pX( sortIndex( i ), : )-bestXX)))*(A'*(A*A')^(-1))*ones(1,dim); end x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );%判断边界是否超出 fit( sortIndex( i ) )=fitness(x(sortIndex( i ),:),P_train,T_train,P_test,T_test); end %%%%%%%%%%%%%5%%%%%%这一部位为意识到危险(注意这里只是意识到了危险,不代表出现了真正的捕食者)的麻雀的位置更新%%%%%%%%%%%%%%%%%%%%%%%%% c=randperm(numel(sortIndex));%%%%%%%%%这个的作用是在种群中随机产生其位置(也就是这部分的麻雀位置一开始是随机的,意识到危险了要进行位置移动, %处于种群外围的麻雀向安全区域靠拢,处在种群中心的麻雀则随机行走以靠近别的麻雀) b=sortIndex(c(1:3)); for j = 1 : length(b) % Equation (5) if( pFit( sortIndex( b(j) ) )>(fMin) ) %处于种群外围的麻雀的位置改变 x( sortIndex( b(j) ), : )=bestX+(randn(1,dim)).*(abs(( pX( sortIndex( b(j) ), : ) -bestX))); else %处于种群中心的麻雀的位置改变 x( sortIndex( b(j) ), : ) =pX( sortIndex( b(j) ), : )+(2*rand(1)-1)*(abs(pX( sortIndex( b(j) ), : )-worse))/ ( pFit( sortIndex( b(j) ) )-fmax+1e-50); end x( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub ); fit( sortIndex( b(j) ) )=fitness(x(sortIndex( b(j) ),:),P_train,T_train,P_test,T_test);

end



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3