A list,

Particle swarm Optimization (PSO) is an evolutionary computation technology. It comes from the study of predation behavior in flocks of birds. The basic idea of particle swarm optimization algorithm is to find the optimal solution through the cooperation and information sharing among individuals in the group. The advantage of PSO is that it is simple and easy to implement without many parameters adjustment. It has been widely used in function optimization, neural network training, fuzzy system control and other applications of genetic algorithms.

2. Analysis of particle swarm optimization

2.1 Basic Ideas

Particle swarm optimization (PSO) simulates a bird in a flock by designing a massless particle that has only two properties: speed and position. Speed represents how fast the bird moves, and position represents the direction of the bird. Each particle separately searches for the optimal solution in the search space, and records it as the current individual extreme value, and shares the individual extreme value with other particles in the whole particle swarm, and finds the optimal individual extreme value as the current global optimal solution of the whole particle swarm. All particles in a swarm adjust their speed and position based on the current individual extremum they find and the current global optimal solution shared by the whole swarm. The following GIF vividly shows the process of the PSO algorithm:



2 Update Rules

PSO initializes as a group of random particles (random solutions). Then find the optimal solution through iteration. At each iteration, the particle updates itself by tracking two “extreme values” (PBest, GBest). After finding these two optimal values, the particle updates its velocity and position by using the formula below.



The first part of formula (1) is called [memory term], which represents the influence of the magnitude and direction of the last speed. The second part of Formula (1) is called [self cognition term], which is a vector pointing from the current point to the particle’s own best point, indicating that the particle’s action comes from its own experience. The third part of Formula (1) is called [group cognition term], which is a vector from the current point to the best point of the population, reflecting the cooperation and knowledge sharing among particles. The particle is determined by its own experience and the best experience of its companions. Based on the above two formulas, the standard form of PSO is formed.



Formula (2) and Formula (3) are regarded as standard PSO algorithms.

3. Process and pseudocode of PSO algorithm

Ii. Source code

% This program has been run in MATLAB2014a via function varargout = GUI (varargin) % GUI MATLAB codefor gui.fig
%      GUI, by itself, creates a new GUI or raises the existing
%      singleton*.
%
%      H = GUI returns the handle to a new GUI or the handle to
%      the existing singleton*.
%
%      GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI.M with the given input arguments.
%
%      GUI('Property'.'Value',...). creates anew GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui

% Last Modified by GUIDE v2. 5 13-Sep- 2015. 19:51:50

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_OutputFcn, ...
                   'gui_LayoutFcn', [],...'gui_Callback'[]);if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui is made visible.
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gui (see VARARGIN)

% Choose default command line output for gui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = gui_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double

input = get(handles.edit1,'String'); 
input = str2num(input);

% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0.'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor'.'white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a doubl
% --- Executes during object creation, after setting all properties.
input = get(handles.edit2,'String'); 
input = str2num(input);


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0.'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor'.'white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
input = get(handles.edit3,'String'); 
input = str2num(input);

function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0.'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor'.'white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
C = 30;
theta = 2; %C is the regularization parameter of the least squares support vector machine, theta is the kernel function parameter of the Gaussian radial basis, and the two need to be optimized for selection and debugging NumOfPre =1; % Forecast days, where the last seven days of the quarter are forecast Time =24;
Data = xlsread('a23.xls'); [M N] = size(Data); [M N] = size(Data); % calculates the rows and columns M rows and N columns of the data read infor i = 1:3maxData = max(Data(:,i)); minData = min(Data(:,i)); Data1(:,i) = (Data(:,i) - minData)/(maxData-minData); % To normalize the temperature endfor i = 4:5
    Data1(:,i) = Data(:,i);
end
for i = 6:N
    Data1(:,i) = log10(Data(:,i)) ; End Dim = M - End Dim = M - End Dim = M -2- NumOfPre; % Training samples % Training samples Input = Zeros (M2 -.12,Time); % Input vector space y = zeros(Dim,Time);for i = 3:M 
    for j = 1:Time %% Select the temperature of the previous day, the load at the same Time, the load of the previous two days, and the temperature of the current day as the input characteristics x = [Data1(I- 1.1:5), Data1(i- 1,j+5), Data1(i2 -,j+5),Data1(i,1:5)];
        Input(i2 -,:,j) = x;
        y(i2 -,j) = Data1(i,j+5); end end Dist = zeros(Dim,Dim,Time); % preallocates distance spacefor i=1:Time
    for j=1:Dim
        for k=1:Dim
            Dist(j,k,i) = (Input(j,:,i) - Input(k,:,i))*(Input(j,:,i) - Input(k,:,i))'; end end end Dist1 = exp(-Dist/(2*theta)); %RBF for i=1:Time H = Dist1(:,:,i) + eye(Dim)/C; H matrix f = -y(1:Dim, I); Aeq = ones(Dim,1)';
    beq = [0];
    option.MaxIter=1000; [a,fval]=quadprog(H,f,[],[],Aeq,beq); %,[],[],[],option); b =0;
    for j = 1:Dim
        b(j) = y(j,i) - a(j)/C - a'* Dist1(:,j,i); End b = sum(b)/Dim; % find the average b, eliminate the errorfor j = Dim + 1:M2 -
        for k = 1:Dim
            K(k) = exp(-(Input(j,:,i) - Input(k,:,i))*(Input(j,:,i) - Input(k,:,i))'/(2*theta)); End Pre(j-dim, I) = sum(a'*K') + b; End End Len = M - (Dim + 13) + 1; % The number of forecast days is the last Len days of the quarter Pre =10.^Pre;
for i = 1:Len
    %figure 
    axes(handles.axes1);
    plot(1:Time,Data(i+Dim+2.6:N),'-or'.1:Time,Pre(i,:),'-vk'); Draw the predicted and true values for each dayhold on
    scatter(1:Time,Data(i+Dim+2.6:N),'o')
    scatter(1:Time,Pre(i,:),'v')
    legend('Actual value'.'Predicted value'.'location'.'southeast')
    hold off
end
Acu = (Pre - Data(Dim+3:M,6:N))./Data(Dim+3:M,6:N); % relative error save Acu. Mat Acu s=0;
for i=1:Time
    s=abs(Acu(1,i))+s;
end
acu=s/Time;
save acu.mat acu;
Result=[C,theta,acu];
disp(Result);
Copy the code

3. Operation results

Fourth, note

Version: 2014 a