👨🎓个人主页:研学社的博客
💥💥💞💞欢迎来到本博客❤️❤️💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
📋📋📋本文目录如下:🎁🎁🎁
目录
💥1 概述
心电信号具有低频低幅微弱的特点,心电信号的最大幅值一般不超5mv,心电信号的频率一般在0.01-100Hz之间,且心电信号在采集过程中极易受到干扰[15]。在采集心电信号时,皮肤与电极之间的接触阻抗、人体组织产生的各种其他的生理信号以及所处的电磁环境不稳定都会对心
电信号造成干扰[16]。
这些不可避免出现的噪音会对心电信号产生干扰,甚至把重要的信号信息给掩盖掉,影响心电信号的特征提取,进而降低模型的分类性能17l。所以一般在对心电信号进行特征提取之前,要对心电信号进行降噪处理,保留有用的信号,降低噪音干扰对分类模型产生的影响,为后续的心电图分类打好基础。
📚2 运行结果
部分代码:
function [predict_label,bestc,bestg,Convergence_curve]=IGWO_KELM(train_wine,train_wine_labels,test_wine,test_wine_labels,DIST)
% %% 利用灰狼算法选择最佳的SVM参数c和g
% SearchAgents_no=10; % 狼群数量,Number of search agents
% Max_iteration=100; % 最大迭代次数,Maximum numbef of iterations
% dim=2; % 此例需要优化两个参数c和g,number of your variables
% lb=[0.1,0.001]; % 参数取值下界
% ub=[10,1]; % 参数取值上界
% % v = 5; % SVM Cross Validation参数,默认为5
lb=0.01;ub=10;
dim=2;
N = 20;
Max_iteration=50;
lu = [lb* ones(1, dim); ub* ones(1, dim)];
% initialize alpha, beta, and delta_pos
Alpha_pos=zeros(1,dim); % 初始化Alpha狼的位置
Alpha_score=inf; % 初始化Alpha狼的目标函数值,change this to -inf for maximization problems
Beta_pos=zeros(1,dim); % 初始化Beta狼的位置
Beta_score=inf; % 初始化Beta狼的目标函数值,change this to -inf for maximization problems
Delta_pos=zeros(1,dim); % 初始化Delta狼的位置
Delta_score=inf; % 初始化Delta狼的目标函数值,change this to -inf for maximization problems
% Initialize the positions of wolves
Positions=initialization(N,dim,ub,lb);
Positions = boundConstraint (Positions, Positions, lu);
% Calculate objective function for each wolf
for i=1:size(Positions,1)
model = elm_kernel_train([train_wine_labels train_wine],Positions(i,1),DIST,Positions(i,2));
Output2 = elm_kernel_test([train_wine_labels train_wine], model);
predict_trainlabel=Output2.PredictLabel;
Fit(i)=1-sum(predict_trainlabel==train_wine_labels)/length(predict_trainlabel);
end
% Personal best fitness and position obtained by each wolf
pBestScore = Fit;
pBest = Positions;
neighbor = zeros(N,N);
Convergence_curve=zeros(1,Max_iteration);
l=0; % Loop counter循环计数器
% Main loop主循环
while l<Max_iteration % 对迭代次数循环
for i=1:size(Positions,1) % 遍历每个狼
fitness = Fit(i);
% Update Alpha, Beta, and Delta
if fitness<Alpha_score % 如果目标函数值小于Alpha狼的目标函数值
Alpha_score=fitness; % 则将Alpha狼的目标函数值更新为最优目标函数值,Update alpha
Alpha_pos=Positions(i,:); % 同时将Alpha狼的位置更新为最优位置
end
if fitness>Alpha_score && fitness<Beta_score % 如果目标函数值介于于Alpha狼和Beta狼的目标函数值之间
Beta_score=fitness; % 则将Beta狼的目标函数值更新为最优目标函数值,Update beta
Beta_pos=Positions(i,:); % 同时更新Beta狼的位置
end
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score % 如果目标函数值介于于Beta狼和Delta狼的目标函数值之间
Delta_score=fitness; % 则将Delta狼的目标函数值更新为最优目标函数值,Update delta
Delta_pos=Positions(i,:); % 同时更新Delta狼的位置
end
end
a=2-l*((2)/Max_iteration); % 对每一次迭代,计算相应的a值,a decreases linearly fron 2 to 0
% Update the Position of search agents including omegas
for i=1:size(Positions,1) % 遍历每个狼
for j=1:size(Positions,2) % 遍历每个维度
% 包围猎物,位置更新
r1=rand(); % r1 is a random number in [0,1]
r2=rand(); % r2 is a random number in [0,1]
A1=2*a*r1-a; % 计算系数A,Equation (3.3)
C1=2*r2; % 计算系数C,Equation (3.4)
% Alpha狼位置更新
D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j)); % Equation (3.5)-part 1
X1=Alpha_pos(j)-A1*D_alpha; % Equation (3.6)-part 1
r1=rand();
r2=rand();
A2=2*a*r1-a; % 计算系数A,Equation (3.3)
C2=2*r2; % 计算系数C,Equation (3.4)
% Beta狼位置更新
D_beta=abs(C2*Beta_pos(j)-Positions(i,j)); % Equation (3.5)-part 2
X2=Beta_pos(j)-A2*D_beta; % Equation (3.6)-part 2
r1=rand();
r2=rand();
A3=2*a*r1-a; % 计算系数A,Equation (3.3)
C3=2*r2; % 计算系数C,Equation (3.4)
% Delta狼位置更新
D_delta=abs(C3*Delta_pos(j)-Positions(i,j)); % Equation (3.5)-part 3
X3=Delta_pos(j)-A3*D_delta; % Equation (3.5)-part 3
% 位置更新
X_GWO(i,j)=(X1+X2+X3)/3; % Equation (3.7) Positions(i,j)=(X1+X2+X3)/3;% Equation (3.7)
end
X_GWO(i,:) = boundConstraint(X_GWO(i,:), Positions(i,:), lu);
% 计算适应度函数值
model = elm_kernel_train([train_wine_labels train_wine],X_GWO(i,1),DIST,X_GWO(i,2));
Output2 = elm_kernel_test([train_wine_labels train_wine], model);
predict_trainlabel=Output2.PredictLabel;
Fit_GWO(i)=1-sum(predict_trainlabel==train_wine_labels)/length(predict_trainlabel);
end
%% Calculate the candiadate position Xi-DLH
radius = pdist2(Positions, X_GWO, 'euclidean'); % Equation (10)
dist_Position = squareform(pdist(Positions));
r1 = randperm(N,N);
for t=1:N
neighbor(t,:) = (dist_Position(t,:)<=radius(t,t));
[~,Idx] = find(neighbor(t,:)==1); % Equation (11)
random_Idx_neighbor = randi(size(Idx,2),1,dim);
for d=1:dim
X_DLH(t,d) = Positions(t,d) + rand .*(Positions(Idx(random_Idx_neighbor(d)),d)...
- Positions(r1(t),d)); % Equation (12)
end
X_DLH(t,:) = boundConstraint(X_DLH(t,:), Positions(t,:), lu);
% 计算适应度函数值
model = elm_kernel_train([train_wine_labels train_wine],X_GWO(i,1),DIST,X_GWO(i,2));
Output2 = elm_kernel_test([train_wine_labels train_wine], model);
predict_trainlabel=Output2.PredictLabel;
Fit_DLH(t) =1-sum(predict_trainlabel==train_wine_labels)/length(predict_trainlabel);
end
%% Selection
tmp = Fit_GWO < Fit_DLH; % Equation (13)
tmp_rep = repmat(tmp',1,dim);
tmpFit = tmp .* Fit_GWO + (1-tmp) .* Fit_DLH;
tmpPositions = tmp_rep .* X_GWO + (1-tmp_rep) .* X_DLH;
%% Updating
tmp = pBestScore <= tmpFit; % Equation (13)
tmp_rep = repmat(tmp',1,dim);
pBestScore = tmp .* pBestScore + (1-tmp) .* tmpFit;
pBest = tmp_rep .* pBest + (1-tmp_rep) .* tmpPositions;
Fit = pBestScore;
Positions = pBest;
%%
l=l+1;
neighbor = zeros(N,N);
Convergence_curve(l)=Alpha_score;
end
bestc=Alpha_pos(1,1);
bestg=Alpha_pos(1,2);
% bestGWOaccuarcy=Alpha_score;
% %% 打印参数选择结果
% disp('打印选择结果');
% str=sprintf('Best Cross Validation Accuracy = %g%%,Best c = %g,Best g = %g',bestGWOaccuarcy*100,bestc,bestg);
% disp(str)
%% 利用最佳的参数进行SVM网络训练
modelbest = elm_kernel_train([train_wine_labels train_wine],bestc,DIST,bestg);
Output2best = elm_kernel_test([test_wine_labels test_wine], modelbest);
predict_label=Output2best.PredictLabel;
% cmd_gwosvm = ['-c ',num2str(bestc),' -g ',num2str(bestg)];
% model_gwosvm = svmtrain(train_wine_labels,train_wine,cmd_gwosvm);
% %% SVM网络预测
% [predict_label,accuracy,preb] = svmpredict(test_wine_labels,test_wine,model_gwosvm);
🎉3 参考文献
部分理论来源于网络,如有侵权请联系删除。
[1]TAO ZHANG (2023). WST based BW(2D)2PCA and KELM for classify EEGs and ECGs.
[2]赵运祥. 基于特征融合与深度神经网络的心电图分类方法研究[D].齐鲁工业大学,2021.DOI:10.27278/d.cnki.gsdqc.2021.000008.
[3]张雄伟.脑电图周期波的分类及临床意义[J].国外医学.神经病学神经外科学分册,1982(06):300-302.DOI:10.16636/j.cnki.jinn.1982.06.007.