【BP分类】基于鸟群算法优化BP神经网络实现数据分类附matlab代码

1 简介

​BSA 算法优化 BP 神经网络的基本思想是: 利 用 BSA 算法的全局搜索能力, 优化 BP 神经网络初始的权值和阈值, 也就是决策变量, 其中每一组决策变量均包含在鸟群个体所处的空间位置中. 然后, 通过适应度函数来衡量个体所处空间位置的优劣度, 并利用鸟群觅食过程中的觅食行为、警戒行为和飞行行为等策略不断更新个体空间位置, 直至获取最佳的个体空间位置, 即获得待优化问题的最佳决策变量

BSA-BP 算法预测 PMV 指标主要包括以下几个部分: 确定训练样本数据、设计 BP 神经网络结构、利用 BSA 算法优化 BP 神经网络初始的权值和阈值、训练优化后的网络. 具体实现步骤如下:

步骤 1. 确定训练样本数据. 确定所需输入变量的取值范围; 然后, 根据 PMV 指标的数学模型, 利用MATLAB 软件编辑 PMV 指标的计算程序, 获取相当数量的样本数据; 最后, 经过预处理, 作为 BP 神经网络的训练样本和测试样本数据.

步骤 2. 设计 BP 神经网络结构. 依据标准 BP 神经网络模型以及 PMV 指标的数学模型, 确定 BP 神经网络的层数、每层的神经元数, 以及其他参数.

步骤 3. 确定 BSA 算法中各参数. 包括初始化种群规模 N、搜索空间维数 D、最大迭代次数 T、飞行间隔 FQ、觅食概率 P、常量 C、S、a1、a2、FL 以及随机初始化鸟群个体空间位置 xti.

步骤 4. 计算 BSA 算法的适应度函数值, 将样本的均方误差作为适应度函数, 找到最小的适应度值, 并保留当前最好个体空间位置. 判断算法终止条件是否满足, 若满足则转至步骤 6, 否则执行步骤

5.步骤 5. BSA 算法优化 BP 神经网络初始的权值和阈值. 依据 BSA 算法的步骤, 不断迭代进行寻优, 直到迭代停止, 输出全局最优值, 也就是最优网络初始的权值和阈值, 并将其赋给 BP 神经网络.

步骤 6. 训练 BSA 算法优化后的 BP 神经网络. 网络经训练结束后, 将得到最佳的 PMV 指标预测模型.上面所述的实现步骤可见图 3

2 部分代码

% ------------------------------------------------------------------------% Bird Swarm Algorithm (BSA) (demo)% This is a simple demo version only implemented the basic idea of BSA for% solving the unconstrained problem, namely Sphere function.%% The details about BSA are illustratred in the following paper.% Xian-Bing Meng, et al (2015): A new bio-inspXred optimisation algorithm:% Bird Swarm Algorithm, Journal of Experimental & Theoretical% Artificial Intelligence, DOI: 10.1080/0952813X.2015.1042530%% The parameters in BSA are presented as follows.% FitFunc    % The objective function% M          % Maxmimal generations (iterations)% pop        % Population size% dim        % Dimension% FQ         % The frequency of birds' flight behaviours% c1         % Cognitive accelerated coefficient% c2         % Social accelerated coefficient% a1, a2     % Two paramters which are related to the indirect and direct%              effect on the birds' vigilance bahaviors.%% Using the default value, BSA can be executed using the following code.% [ bestX, fMin ] = BSA% ------------------------------------------------------------------------% Main programsfunction [ bestX, fMin ,yy] = BSA( FitFunc, M, pop, dim, FQ, c1, c2, a1, a2 )% Display helphelp BSA.m%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set the default parameters% set the parameterslb= -100*ones( 1,dim );   % Lower boundsub= 100*ones( 1,dim );    % Upper bounds%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Initializationfor i = 1 : pop    x( i, : ) = lb + (ub - lb) .* rand( 1, dim );    fit( i ) = FitFunc( x( i, : ) );endpFit = fit; % The individual's best fitness valuepX = x;     % The individual's best position corresponding to the pFit[ fMin, bestIndex ] = min( fit );  % fMin denotes the global optimum% bestX denotes the position corresponding to fMinbestX = x( bestIndex, : );%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Start the iteration.for iteration = 1 : M        prob = rand( pop, 1 ) .* 0.2 + 0.8;%The probability of foraging for food        if( mod( iteration, FQ ) ~= 0 )        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        % Birds forage for food or keep vigilance        sumPfit = sum( pFit );        meanP = mean( pX );        for i = 1 : pop            if rand < prob(i)                x( i, : ) = x( i, : ) + c1 * rand.*(bestX - x( i, : ))+ ...                    c2 * rand.*( pX(i,:) - x( i, : ) );            else                person = randiTabu( 1, pop, i, 1 );                                x( i, : ) = x( i, : ) + rand.*(meanP - x( i, : )) * a1 * ...                    exp( -pFit(i)/( sumPfit + realmin) * pop ) + a2 * ...                    ( rand*2 - 1) .* ( pX(person,:) - x( i, : ) ) * exp( ...                    -(pFit(person) - pFit(i))/(abs( pFit(person)-pFit(i) )...                    + realmin) * pFit(person)/(sumPfit + realmin) * pop );            end                        x( i, : ) = Bounds( x( i, : ), lb, ub );            fit( i ) = FitFunc( x( i, : ) );        end        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%            else        FL = rand( pop, 1 ) .* 0.4 + 0.5;    %The followed coefficient                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        % Divide the bird swarm into two parts: producers and scroungers.        [ans, minIndex ] = min( pFit );        [ans, maxIndex ] = max( pFit );        choose = 0;        if ( minIndex < 0.5*pop && maxIndex < 0.5*pop )            choose = 1;        end        if ( minIndex > 0.5*pop && maxIndex < 0.5*pop )            choose = 2;        end        if ( minIndex < 0.5*pop && maxIndex > 0.5*pop )            choose = 3;        end        if ( minIndex > 0.5*pop && maxIndex > 0.5*pop )            choose = 4;        end        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        if choose < 3            for i = (pop/2+1) : pop                x( i, : ) = x( i, : ) * ( 1 + randn );                x( i, : ) = Bounds( x( i, : ), lb, ub );                fit( i ) = FitFunc( x( i, : ) );            end            if choose == 1                x( minIndex,: ) = x( minIndex,: ) * ( 1 + randn );                x( minIndex, : ) = Bounds( x( minIndex, : ), lb, ub );                fit( minIndex ) = FitFunc( x( minIndex, : ) );            end            for i = 1 : 0.5*pop                if choose == 2 || minIndex ~= i                    person = randi( [(0.5*pop+1), pop ], 1 );                    x( i, : ) = x( i, : ) + (pX(person, :) - x( i, : )) * FL( i );                    x( i, : ) = Bounds( x( i, : ), lb, ub );    end% End of the main program%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The following functions are associated with the main program%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This function is the objective function

3 仿真结果

4 参考文献

[1]郭彤颖, 陈露. 基于鸟群算法优化BP神经网络的热舒适度预测[J]. 计算机系统应用, 2018, 27(4):5.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值