天天看点

【预测模型-ELM预测】基于松鼠算法优化极限学习机预测附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。​

⛄ 内容介绍

极限学习机(Extreme Learning Machine,ELM)是一种新型的前馈神经网络,该网络由广义逆直接求出输出层权重,使得其具有误差小,速度快的优点.但针对具体问题,ELM不能自动寻找到最佳的网络结构,从而造成该算法模型针对复杂,无规律性的数据精度及稳定性较差.为了提高极限学习机的泛化能力和预测精度,提出利用松鼠优化极限学习机算法对不同数据进行预测.使用松鼠算法选择最优的隐含层偏差和输入权值矩阵,计算出输出权值矩阵,从而提高ELM的精度及稳定性

⛄ 部分代码

% Differential Squirrel Search Algorithm (DSSA) source Code Version 1.0

%

% Developed in MATLAB R2018b

%

% Programmers:

% Bibekananda Jena and Dr Manoj Kumar Naik

% _____________________________________________________________________________________________________

% Please cite to the main paper:

% ******************************

% B. Jena, M. K. Naik, A. Wunnava, and R. Panda,

% 揂 Differential Squirrel Search Algorithm,?

% S. Das and M. N. Mohanty, Eds. Singapore: Springer Singapore, 2021, pp. 143?52.

% https://doi.org/10.1007/978-981-16-0695-3_15

%_____________________________________________________________________________________________________

%%

function [Destination_fitness,bestPositions,Convergence_curve]=SSA(NP,Max_iter,lb,ub,npar,fobj)

% Constant initialization and memory initialization

Gc=1.9; % Gliding constant

Cr=0.5; % crossover rate

dg=0.8; %Random gliding distance

Pdp=0.1; %predator presence probability

Convergence_curve=zeros(1,Max_iter);

Fitness=ones(1,NP)*inf;

% Initialization of the Squirrel初始化

Pos=initialization(NP,npar,ub,lb);

% Fitness eval(i)=fobj(Pos(i,:));

end

% Segregating the Squirrel into hickory, acorn and normal tree

%将松鼠分为山核桃树、橡子树和普通树

[Sorted_fitness,Sort_index]=sort(Fitness);

Pos_hickory=Pos(Sort_index(1),:); % best solution (hickory tree)

Pos_acorn=Pos(Sort_index(2:4),:); % acorn tree

Pos_normal=Pos(Sort_index(5:end),:); % normal tree

L=size(Pos_normal,1);

L1=randperm(L);

% Squirrels in normal tree splitted into two sets randomly

%正常树上的松鼠随机分成两组

Pnormal_1=Pos_normal(L1(1:end-10),:);

Pnormal_2=Pos_normal(L1(end-10+1:end),:);

G=Sorted_fitness(1); % best fitness

Convergence_curve(1)=Sorted_fitness(1);

for itr=2:Max_iter

    Pos_avg=mean(Pos,1); % average of all squirrels position in the current population所有松鼠在当前种群中的平均位置

    %Temporary new location of squirrels in acorn and normal trees松鼠在橡树和正常的树临时的新位置

    Pacorn_tree=[];

    Pnormal_1_tree=[];

    Pnormal_2_tree=[];

    %New locations of squirrels present in the acorn trees松鼠出现在橡子树上的新位置

    for i=1:3

        if rand>Pdp

            Pacorn_tree(i,:)=Pos_acorn(i,:)+dg*Gc*(Pos_hickory-Pos_acorn(i,:)-Pos_avg);  %Eq(1)

        else

            Xrand=initialization(1,npar,ub,lb);

            Pacorn_tree(i,:)=Xrand-rand(1,npar).*abs(Xrand-2*rand*Pos_acorn(i,:));

        end

    end

    %New locations of some of the squirrels present in the normal trees一些松鼠的新位置出现在正常的树上

    for i=1:size(Pnormal_1,1)

        if rand>Pdp

            k=randi(3,1);

            Pnormal_1_tree(i,:)=Pnormal_1(i,:)+dg*Gc*(Pos_acorn(k,:)-Pnormal_1(i,:));   %Eq(3)

        else

            Xrand=initialization(1,npar,ub,lb);

            Pnormal_1_tree(i,:)=Xrand-rand(1,npar).*abs(Xrand-2*rand*Pnormal_1(i,:));

        end

    end

    %New locations of remaining squirrels present in the normal trees现存松鼠的新位置出现在正常的树上

    for i=1:size(Pnormal_2,1)

        if rand>Pdp

            Pnormal_2_tree(i,:)=Pnormal_2(i,:)+dg*Gc*(Pos_hickory-Pnormal_2(i,:));   %Eq(4)

        else

            Xrand=initialization(1,npar,ub,lb);

            Pnormal_2_tree(i,:)=Xrand-rand*abs(Xrand-2*rand*Pnormal_2(i,:));

        end

    end

    Pnt=[Pnormal_1_tree; Pnormal_2_tree];

    Ph1=Pos_hickory+dg*Gc*(Pos_hickory-mean(Pos_acorn,1));   %Eq(6)

    if fobj(Ph1)<fobj(Pos_hickory)

        Pos_hickory=Ph1;

    end

    Pnew=[Pos_hickory; Pacorn_tree; Pnt];

    FTnew=[];

    % Updating the population

    for i=1:NP

        FTnew(i)=fobj(Pnew(i,:));

        if FTnew(i)<Fitness(i)

            Fitness(i)=FTnew(i);

            Pos(i,:)=Pnew(i);

        else

            Pos(i,:)=Pos(i,:);

            Fitness(i)=Fitness(i);

        end

    end

    [Sorted_fitness,Sort_index]=sort(Fitness);

    % Update Best squirrel positions in hickory tree更新山核桃树上最好的松鼠位置

    if Sorted_fitness(1)<G(itr-1)

        Pos_hickory=sort(Pos(Sort_index(1),:),2);

        G(itr)=Sorted_fitness(1);

    else

        G(itr)=G(itr-1);

    end

    %Updated locations of squirrels in acorn trees更新了橡子树上松鼠的位置

    Pos_acorn=Pos(Sort_index(2:4),:);

    %Updated locations of squirrels in normal trees更新松鼠在正常树上的位置

    Pos_normal=Pos(Sort_index(5:end),:);

    L=size(Pos_normal,1);

    L1=randperm(L);

    Pnormal_1=Pos_normal(L1(1:end-10),:);

    Pnormal_2=Pos_normal(L1(end-10+1:end),:);

    % Keeping all iteration best fitness value保持所有迭代的最佳适应度值

    Convergence_curve(itr)=G(itr);

end

Destination_fitness=Convergence_curve(end);

bestPositions=Pos_hickory;

end

⛄ 运行结果

【预测模型-ELM预测】基于松鼠算法优化极限学习机预测附matlab代码
【预测模型-ELM预测】基于松鼠算法优化极限学习机预测附matlab代码

⛄ 参考文献

❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除

继续阅读