回归预测 | Matlab实现DE-BP差分算法优化BP神经网络多变量回归预测

回归预测 | Matlab实现DE-BP差分算法优化BP神经网络多变量回归预测

目录

效果一览



基本介绍

1.Matlab实现DE-BP差分算法优化BP神经网络多变量回归预测(完整源码和数据)

2.运行环境为Matlab2018b;

3.excel数据集,输入多个特征,输出单个变量,多变量回归预测预测,DE_BP.m为主程序,运行即可,所有文件放在一个文件夹;

4.输出优化前后对比图,误差对比图;

代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。

程序设计

clike 复制代码
%%  清空环境变量
%选连样本输入输出数据归一化
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
%构建网络
net=newff(inputn,outputn,hiddennum);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%优化前的BP
net.trainParam.epochs=100;
net.trainParam.lr=0.1;
net.trainParam.goal=0.00001;
[net,~]=train(net,inputn,outputn);
inputn_test=mapminmax('apply',input_test,inputps);
an=sim(net,inputn_test);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 利用差分进化算法选择最佳的BP参数
D=inputnum*hiddennum+hiddennum+hiddennum*outputnum+outputnum;%变量个数%变量的维数
NP=5;                                %个体数目                               
G=30;                                %最大进化代数

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xs=1*ones(D,1);                                 %上限
Xx=-1*ones(D,1);                                %下限
%%%%%%%%%%%%%%%%%%%%%%%%%赋初值%%%%%%%%%%%%%%%%%%%%%%%%   
xx=zeros(D,NP);                        %初始种群
v=zeros(D,NP);                        %变异种群
u=zeros(D,NP);                        %选择种群
xchu=rand(D,NP);
for i=1:NP
xx(:,i)=xchu(:,i).*(Xs-Xx)+Xx;              %赋初始种群初值
end
%%%%%%%%%%%%%%%%%%%%计算目标函数%%%%%%%%%%%%%%%%%%%%%%%

trace(1)=min(Ob);
gbest=100;
%%%%%%%%%%%%%%%%%%%%%%%差分进化循环%%%%%%%%%%%%%%%%%%%%%
for gen=1:G
    %%%%%%%%%%%%%%%%%%%%%%变异操作%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%r1,r2,r3和m互不相同%%%%%%%%%%%%%%%
    for m=1:NP
        r1=randi([1,NP],1,1);
        while (r1==m)
            r1=randi([1,NP],1,1);
        end
        r2=randi([1,NP],1,1);
        while (r2==m)||(r2==r1)
            r2=randi([1,NP],1,1);
        end
        r3=randi([1,NP],1,1);
        while (r3==m)||(r3==r1)||(r3==r2)
            r3=randi([1,NP],1,1);
        end
        v(:,m)=xx(:,r1)+F*(xx(:,r2)-xx(:,r3));
    end
    %%%%%%%%%%%%%%%%%%%%%%交叉操作%%%%%%%%%%%%%%%%%%%%%%%
    r=randi([1,D],1,1);
    for n=1:D
        cr=rand(1);
        if (cr<=CR)||(n==r)
            u(n,:)=v(n,:);
        else
            u(n,:)=xx(n,:);
        end
    end
    %%%%%%%%%%%%%%%%%%%边界条件的处理%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%边界吸收%%%%%%%%%%%%%%%%%%%%%%%%%
    for n=1:D
        for m=1:NP
            if u(n,m)<Xx(n)
                u(n,m)=Xx(n);
            end
            if u(n,m)>Xs(n)
                u(n,m)=Xs(n);
            end
        end
    end
    %%%%%%%%%%%%%%%%%%%%%%选择操作%%%%%%%%%%%%%%%%%%%%%%%
    for m=1:NP
        Ob1(m)=fitness(u(:,m));
    end
    for m=1:NP
        if Ob1(m)<Ob(m)
            xx(:,m)=u(:,m);
        end
    end
    for m=1:NP
        Ob(m)=fitness(xx(:,m));
    end
    fbest=min(Ob);

    if(fbest<gbest)        
        gbest=fbest;
        histor(gen)=fbest;
    else
        histor(gen)=gbest;
    end


end

参考资料

[1] https://blog.csdn.net/kjm13182345320/article/details/129215161

[2] https://blog.csdn.net/kjm13182345320/article/details/128105718

相关推荐
机器学习之心1 个月前
一区北方苍鹰算法优化+创新改进Transformer!NGO-Transformer-LSTM多变量回归预测
算法·lstm·transformer·北方苍鹰算法优化·多变量回归预测·ngo-transformer
不想当个技术宅3 个月前
【图像压缩与重构】基于BP神经网络
图像处理·matlab·bp神经网络·图像压缩
不想当个技术宅3 个月前
【图像压缩与重构】基于标准+改进BP神经网络
matlab·bp神经网络·gui·图像压缩
机器学习之心3 个月前
顶刊算法 | 鹈鹕算法POA-Transformer-LSTM多变量回归预测
算法·lstm·transformer·多变量回归预测·poa
机器学习之心4 个月前
回归预测 | Matlab实现GWO-BP-Adaboost灰狼算法优化BP神经网络集成学习多输入单输出回归预测
算法·matlab·回归·bp神经网络·灰狼算法优化·gwo-bp-adaboost
机器学习之心5 个月前
机器学习之心一区级 | Matlab实现SMA-Transformer-LSTM多变量回归预测(黏菌算法优化)
matlab·lstm·transformer·多变量回归预测·sma·黏菌算法优化
机器学习之心5 个月前
JCR一区级 | Matlab实现TTAO-Transformer-LSTM多变量回归预测
matlab·lstm·transformer·多变量回归预测·ttao
机器学习之心5 个月前
JCR一区级 | Matlab实现GA-Transformer-LSTM多变量回归预测
matlab·lstm·transformer·遗传算法·多变量回归预测
机器学习之心5 个月前
JCR一区级 | Matlab实现PSO-Transformer-LSTM多变量回归预测
matlab·lstm·transformer·多变量回归预测
机器学习之心6 个月前
区间预测 | Matlab实现BP-ABKDE的BP神经网络自适应带宽核密度估计多变量回归区间预测
bp神经网络·自适应带宽核密度估计·多变量回归区间预测·bp-abkde