您现在的位置:首页 >> 智能优化 >> 内容

基于PSO三维极点搜索matlab仿真

时间:2023/1/13 20:20:39 点击:

  核心提示:a223,包括程序操作录像...

1.完整项目描述和程序获取

>面包多安全交易平台:https://mbd.pub/o/bread/Y56VlZlr

>如果链接失效,可以直接打开本站店铺搜索相关店铺:

点击店铺

>如果链接失效,程序调试报错或者项目合作可以加微信或者QQ联系。

2.部分仿真图预览




3.算法概述

       在PSO中,群中的每个粒子表示为向量。在投资组合优化的背景下,这是一个权重向量,表示每个资产的分配资本。矢量转换为多维搜索空间中的位置。每个粒子也会记住它最好的历史位置。对于PSO的每次迭代,找到全局最优位置。这是群体中最好的最优位置。一旦找到全局最优位置,每个粒子都会更接近其局部最优位置和全局最优位置。当在多次迭代中执行时,该过程产生一个解决该问题的良好解决方案,因为粒子会聚在近似最优解上。

4.部分源码

...........................................................

pbest = zeros(pop_size,part_size+1);      %   pbest the best result, last column contain the parameter as well

w_max = 0.9;                            %   w_max maximum of weight

w_min = 0.4;                            %   w_min minumum of weitht

v_max = 2;             %      ** maximum of velocity 

c1 = 2;                   %   learning parameter 1

c2 = 2;                   %   learning parameter 2

best_record = zeros(1,max_gen);     %   best_record remember the best particle's parameters

.............................................................

for i=1:max_gen

    grid on;

    ezmesh(z,[-1,1,-1,1]),hold on,grid on,plot3(arr_present(:,1),arr_present(:,2),arr_present(:,3),'*'),hold off;

    drawnow

    F(i)=getframe;

    pause(0.01);

    %     m(:,i) = getframe;        %

    w = w_max-(w_max-w_min)*i/max_gen;

    reset = 0;          %   reset = 1

    if reset==1

        bit = 1;

        for k=1:part_size

            bit = bit&(range(arr_present(:,k))<0.1);

        end

        if bit==1       %   bit=1, reset position and velocity

            arr_present = ini_pos(pop_size,part_size);   %   present position

            v = ini_v(pop_size,part_size);           %   velocity initialization

            for k=1:pop_size                                    %   re-calculate affinity

                arr_present(k,end) = fitness(arr_present(k,1:part_size));

            end

            warning('Reset particle because they already converged……');    

            display(i);

        end

    end

    for j=1:pop_size

        v(j,:) = w.*v(j,:)+c1.*rand.*(pbest(j,1:part_size)-arr_present(j,1:part_size))...

            +c2.*rand.*(gbest(1:part_size)-arr_present(j,1:part_size));                        %  renew velocity (a)

        %   The abs(velocity) must <5————————————————————————————

        c = find(abs(v)>6);                                                                 

        v(c) = sign(v(c))*6;   %if v>3.14则,v=3.14

        arr_present(j,1:part_size) = arr_present(j,1:part_size)+v(j,1:part_size);              %  renew position (b)

        arr_present(j,end) = fitness(arr_present(j,1:part_size));

        if (arr_present(j,end)>pbest(j,end))&(Region_in(arr_present(j,:),region))     %   renew pbest

            pbest(j,:) = arr_present(j,:);

        end

    end

end

figure

plot(best_record)

a223

作者:我爱C编程 来源:我爱C编程
本站最新成功开发工程项目案例
相关文章
相关评论
发表我的评论
  • 大名:
  • 内容:
本类固顶
  • 没有
  • FPGA/MATLAB商业/科研类项目合作(www.store718.com) © 2025 版权所有 All Rights Reserved.
  • Email:1480526168@qq.com 站长QQ: 1480526168