Multiple input and multiple output | MATLAB implements PSO-BP particle swarm optimization BP neural network multiple input and multiple output

Multiple input and multiple output | MATLAB implements PSO-BP particle swarm optimization BP neural network multiple input and multiple output

Prediction effect

Insert image description here
Insert image description here

Insert image description here
Insert image description here
Insert image description here

basic introduction

Matlab implements PSO-BP particle swarm optimization BP neural network multi-input multi-output prediction
1.data is a data set with 10 input features and 3 output variables.
2.main.m is the main program file.
3. The command window outputs MBE, MAE and R2, and the data and program content can be obtained in the download area.

programming

  • How to download the complete program and data: privately message the blogger and reply to MATLAB to implement PSO-BP particle swarm optimization BP neural network multiple input and multiple output .
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  节点个数
inputnum  = size(p_train, 1);  % 输入层节点数
hiddennum = 5;                 % 隐藏层节点数
outputnum = size(t_train,1);   % 输出层节点数
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  建立网络
net = newff(p_train, t_train, hiddennum);
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  设置训练参数
net.trainParam.epochs     = 1000;      % 训练次数
net.trainParam.goal       = 1e-6;      % 目标误差
net.trainParam.lr         = 0.01;      % 学习率
net.trainParam.showWindow = 0;         % 关闭窗口
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  参数初始化
c1      = 4.494;       % 学习因子
c2      = 4.494;       % 学习因子
maxgen  =   50;        % 种群更新次数  
sizepop =    5;        % 种群规模
Vmax    =  1.0;        % 最大速度
Vmin    = -1.0;        % 最小速度
popmax  =  1.0;        % 最大边界
popmin  = -1.0;        % 最小边界
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  节点总数
numsum = inputnum * hiddennum + hiddennum + hiddennum * outputnum + outputnum;

for i = 1 : sizepop
    pop(i, :) = rands(1, numsum);  % 初始化种群
    V(i, :) = rands(1, numsum);    % 初始化速度
    fitness(i) = fun(pop(i, :), hiddennum, net, p_train, t_train);
end
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  个体极值和群体极值
[fitnesszbest, bestindex] = min(fitness);
zbest = pop(bestindex, :);     % 全局最佳
gbest = pop;                   % 个体最佳
fitnessgbest = fitness;        % 个体最佳适应度值
BestFit = fitnesszbest;        % 全局最佳适应度值
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%%  迭代寻优
for i = 1 : maxgen
    for j = 1 : sizepop
        
        % 速度更新
        V(j, :) = V(j, :) + c1 * rand * (gbest(j, :) - pop(j, :)) + c2 * rand * (zbest - pop(j, :));
        V(j, (V(j, :) > Vmax)) = Vmax;
        V(j, (V(j, :) < Vmin)) = Vmin;
        
        % 种群更新
        pop(j, :) = pop(j, :) + 0.2 * V(j, :);
        pop(j, (pop(j, :) > popmax)) = popmax;
        pop(j, (pop(j, :) < popmin)) = popmin;
      
        
        % 适应度值
        fitness(j) = fun(pop(j, :), hiddennum, net, p_train, t_train);

    end
    
    for j = 1 : sizepop

        % 个体最优更新
        if fitness(j) < fitnessgbest(j)
            gbest(j, :) = pop(j, :);
            fitnessgbest(j) = fitness(j);
        end

 

    end

    BestFit = [BestFit, fitnesszbest];    
end

%%  提取最优初始权值和阈值
w1 = zbest(1 : inputnum * hiddennum);
B1 = zbest(inputnum * hiddennum + 1 : inputnum * hiddennum + hiddennum);
w2 = zbest(inputnum * hiddennum + hiddennum + 1 : inputnum * hiddennum ...
    + hiddennum + hiddennum * outputnum);
B2 = zbest(inputnum * hiddennum + hiddennum + hiddennum * outputnum + 1 : ...
    inputnum * hiddennum + hiddennum + hiddennum * outputnum + outputnum);


Past highlights

MATLAB implements RBF radial basis neural network multi-input multi-output prediction
MATLAB implements BP neural network multi-input multi-output prediction
MATLAB implements DNN neural network multi-input multi-output prediction

References

[1] https://blog.csdn.net/kjm13182345320/article/details/116377961
[2] https://blog.csdn.net/kjm13182345320/article/details/127931217
[3] https://blog.csdn.net/kjm13182345320/article/details/127894261

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/132956776
Recommended