[Lssvm prediction] Improved least squares support vector machine lssvm prediction based on matlab moth extinguishing algorithm [with Matlab source code 142]

1. Introduction

Features of LSSVM
  1) The same is to solve the original dual problem, but by solving a linear equation set (caused by the linear constraints in the optimization objective) instead of the QP problem in the SVM (simplifying the solution process), for the high-dimensional input space The same applies to classification and regression tasks;
  2) Essentially the process of solving linear matrix equations, combined with the core version of Gaussian processes, regularization networks and Fisher discriminant analysis ;
  3) Use sparse approximation (to overcome the drawbacks of using this algorithm) and robust regression (robust statistics);
  4) Use Bayesian inference;
  5) Can be extended to unsupervised learning: kernel Principal component analysis (kernel PCA) or density clustering;
  6) Can be extended to recurrent neural networks.

LSSVM is used for classification tasks
  1)
  Insert picture description here
Insert picture description here
Insert picture description here
The disadvantages of optimization target LSSVM
  noticed when solving classification tasks, in the process of solving optimization, α i = γ ei \alpha_{i}=\gamma{e_{i}}αi​=γei , Since the Lagrange multiplier α i ≠ 0 \alpha_{i}\neq{0}αi​̸​=0 corresponding to the equality constraint in the Lagrange multiplier method, all training samples will be taken as Looking at the support vector, this will cause it to lose the original sparse nature of the SVM, but the training set can also be pruning based on support to achieve the purpose of sparseness. This step can also be seen Doing is a sparse approximate operation.
Moth-flame optimization (MFO), proposed by Seyedali Mirjalili in 2015, provides a new heuristic search paradigm for the optimization field: spiral search.
Moths have a special way of navigating at night: horizontal orientation. That is, it will fly at a certain angle with the moon (light source), so as to maintain a straight flight path. However, this method is only effective when the light source is far away from the moth. When there is an artificial light source, the moth will be deceived by the artificial light and keep flying at the same angle as the artificial light. Because it is too close to the light source, its flight path is not a straight line, but a spiral path. .
Insert picture description here
Inspired by this natural phenomenon, Seyedali Mirjalili abstracted the process of moths flying spirally around the light source as an optimal process. The entire space in which the moths fly is the solution space for the problem, and a moth is one of the problems. The flame (light source) is a better solution to the problem. Each moth corresponds to a light source, which prevents the algorithm from falling into the local optimum; when there are enough moths and flames, the moth’s flight can search for the solution. In the process of optimization, the number of flames decreases as the number of iterations increases, so that moths can fully search for more optimal neighborhood spaces, which ensures Algorithm utilization ability.

Based on the above characteristics, MFO has found a balance between exploration and utilization, so that the algorithm has a better effect in optimization problems.

In general, MFO is also a population-based random heuristic search algorithm. The biggest difference between it and PSO, GSA and other algorithms is that its particle search path is spiral, and the particles surround a better solution in a spiral manner. Move instead of moving in a straight line.

The process of MFO is as follows:
1. Initialize the moth population
2. Perform fitness evaluation on the moth population
3. Repeat the following process until the stopping criterion is reached:
3.1 Adaptively update the number of flames n, when the number of iterations is 1, the number of moths The number is the number of flames.
3.2 The population fitness of the moths is sorted, and n moths with better fitness are selected as
the search parameters of the flame 3.3 update moths.
3.4 Update the position of the moth according to the flame and flight parameters corresponding to each moth
4. Output the optimal solution (flame)

See the paper for the specific moth position update formula: Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm

Second, the source code

%=====================================================================
%初始化
clc
close all
clear
format long
tic
%==============================================================
%%导入数据
data=xlsread('1.xlsx');
[row,col]=size(data);
x=data(:,1:col-1);
y=data(:,col);
set=1; %设置测量样本数
row1=row-set;%
train_x=x(1:row1,:);
train_y=y(1:row1,:);
test_x=x(row1+1:row,:);%预测输入
test_y=y(row1+1:row,:);%预测输出
train_x=train_x';
train_y=train_y';
test_x=test_x';
test_y=test_y';
 
%%数据归一化
[train_x,minx,maxx, train_yy,miny,maxy] =premnmx(train_x,train_y);
test_x=tramnmx(test_x,minx,maxx);
train_x=train_x';
train_yy=train_yy';
train_y=train_y';
test_x=test_x';
test_y=test_y';
%% 参数初始化
eps = 10^(-6);
%%定义lssvm相关参数
type='f';
kernel = 'RBF_kernel';
 
N=20; % Number of search agents
Max_iteration=100; % Maximum numbef of iterations
Leader_pos=zeros(1,dim);
Leader_score=inf; %change this to -inf for maximization problems
%Initialize the positions of search agents
% for i=1:SearchAgents_no
%     Positions(i,1)=ceil(rand(1)*(ub(1)-lb(1))+lb(1));
%     Positions(i,2)=ceil(rand(1)*(ub(2)-lb(2))+lb(2));
%     
end
 
%% 结果分析
plot( Convergence_curve,'LineWidth',2);
title(['飞蛾扑火优化算法适应度曲线','(参数c1=',num2str(Best_flame_pos(1)),',c2=',num2str(Best_flame_pos(2)),',终止代数=',num2str(Max_iteration),')'],'FontSize',13);
xlabel('进化代数');ylabel('误差适应度');
 
bestc = Best_flame_pos(1);
bestg = Best_flame_pos(2);
 
gam=bestc;
sig2=bestg;
model=initlssvm(train_x,train_yy,type,gam,sig2,kernel,proprecess);%原来是显示
model=trainlssvm(model);%原来是显示
%求出训练集和测试集的预测值
[train_predict_y,zt,model]=simlssvm(model,train_x);
[test_predict_y,zt,model]=simlssvm(model,test_x);
 
%预测数据反归一化
train_predict=postmnmx(train_predict_y,miny,maxy);%预测输出
test_predict=postmnmx(test_predict_y,miny,maxy);
%计算均方差
trainmse=sum((train_predict-train_y).^2)/length(train_y);
%testmse=sum((test_predict-test_y).^2)/length(test_y)
 
for i=1:set
    RD(i)=(test_predict(i)-test_y(i))/test_y(i)*100;
end
for i=1:set
    D(i)=test_predict(i)-test_y(i);
end
RD=RD'
disp(['飞蛾扑火优化算法优化svm预测误差=',num2str(D)])
figure
plot(train_predict,':og')
hold on
plot(train_y,'- *')
legend('预测输出','期望输出')
title('飞蛾扑火优化svm网络预测输出','fontsize',12)
ylabel('函数输出','fontsize',12)
xlabel('样本','fontsize',12)
 
toc   %计算时间
 

Three, running results

Insert picture description here
Insert picture description here

Four, remarks

Complete code or writing add QQ2449341593 past review
>>>>>>
[prediction model] lssvm prediction based on matlab particle swarm [including Matlab source code 103]
[lSSVM prediction] lSSVM data prediction based on matlab whale optimization algorithm [including Matlab Source code 104]
[lstm prediction] Improved lstm prediction based on matlab whale optimization algorithm [including Matlab source code 105]
[SVM prediction] Improved SVM prediction based on matlab bat algorithm (1) [Containing Matlab source code 106]
[ SVM prediction 】Based on matlab gray wolf algorithm to optimize svm support vector machine prediction [including Matlab source code 107]
[Prediction model] based on matlab BP neural network prediction [including Matlab source code 108]
[lssvm prediction model] based on bat algorithm improved least squares Support vector machine lssvm prediction [Matlab 109 issue]
[lssvm prediction] Least squares support vector machine lssvm prediction based on the improvement of moth fire fighting algorithm [Matlab 110]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/113027995