1 Introduction
The basic idea of Optimizing BP neural network with BSA algorithm is to use the global search ability of BSA algorithm to optimize the initial weights and thresholds of BP neural network, that is, decision variables, in which each group of decision variables is contained in the spatial position of individual birds Then, the fitness function is used to measure the pros and cons of the individual's spatial position, and the strategies of foraging behavior, vigilance behavior and flight behavior in the process of bird flock foraging are used to continuously update the individual's spatial position until the best individual spatial position is obtained, that is, the best decision variable of the problem to be optimized is obtained
The prediction of PMV index by BSA-BP algorithm mainly includes the following parts: determining the training sample data, designing the structure of BP neural network, using BSA algorithm to optimize the initial weight and threshold of BP neural network, and training the optimized network The specific implementation steps are as follows:
Step 1 Determine the training sample data Determine the value range of the required input variables; Then, according to the mathematical model of PMV index, the calculation program of PMV index is edited by MATLAB software to obtain a considerable number of sample data; Finally, after preprocessing, it is used as the training sample and test sample data of BP neural network
Step 2 The structure of BP neural network is designed According to the standard BP neural network model and the mathematical model of PMV index, the number of layers, the number of neurons in each layer and other parameters of BP neural network are determined
Step 3 Determine the parameters of BSA algorithm It includes initial population size N, search space dimension D, maximum iteration times T, flight interval FQ, foraging probability P, constants C, S, a1, a2, FL, and individual spatial position xti of random initial bird population
Step 4 Calculate the fitness function value of BSA algorithm, take the sample mean square error as the fitness function, find the minimum fitness value, and keep the current best individual space position Judge whether the algorithm termination conditions are met. If yes, go to step 6. Otherwise, execute step
5. step 5 BSA algorithm optimizes the initial weights and thresholds of BP neural network According to the steps of the BSA algorithm, the optimization is carried out by iteration until the iteration stops. The global optimal value, that is, the initial weight and threshold of the optimal network, is output and assigned to the BP neural network
Step 6 The BP neural network optimized by BSA algorithm is trained After training, the network will get the best PMV index prediction model The implementation steps described above can be seen in Figure 3
2 part code
% ------------------------------------------------------------------------% 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 simulation results
4 references
[1] Guotongying, Chen Lu Thermal comfort prediction based on BP neural network optimized by bird swarm algorithm [J] Computer system application, 2018, 27 (4): 5
About the blogger: he is good at matlab simulation in many fields, such as intelligent optimization algorithm, neural network prediction, signal processing, cellular automata, image processing, path planning, UAV, etc. relevant matlab code problems can be exchanged through private letters.
Some theories cite online literature. If there is infringement, contact the blogger to delete it.