【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码
2021/7/4 22:22:22
本文主要是介绍【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、核极限学习机
本文将介绍一种新的SLFN的算法,极限学习机,该算法将随机产生输入层和隐含层间的连接权值和隐含层神经元的阈值,且在训练过程中无需调整,只需要设置隐含层的神经元的个数,便可以获得唯一最优解,与传统的训练方法相比,该方法具有学习速率快、泛化性能好等优点。
典型的单隐层前馈神经网络如上图所示,输入层与隐含层,隐含层与输出层之间是全连接的。输入层的神经元的个数是根据样本的而特征数的多少来确定的,输出层的神经元的个数是根据样本的种类数来确定的
设隐含层神经元的阈值 b为:
当隐层神经元的个数和样本数相同时(10)式有唯一的解,也就是说零误差的逼近训练样本。通常的学习算法中,W和b需要不断进行调整,但研究结果告诉我们,他们事实上是不需要进行不断调整的,甚至可以随意指定。调整他们不仅费时,而且并没有太多的好处。(此处有疑虑,可能是断章取义,这个结论有可能是基于某个前提下的)。
二、狮群算法
三、代码介绍
function [TrainingTime, TestingTime, TrainingAccuracy, TestingAccuracy] = elm_kernel(TrainingData, TestingData, Elm_Type, Regularization_coefficient, Kernel_type, Kernel_para) % Usage: elm(TrainingData_File, TestingData_File, Elm_Type, NumberofHiddenNeurons, ActivationFunction) % OR: [TrainingTime, TestingTime, TrainingAccuracy, TestingAccuracy] = elm(TrainingData_File, TestingData_File, Elm_Type, NumberofHiddenNeurons, ActivationFunction) % % Input: % TrainingData_File - Filename of training data set tic; Omega_test = kernel_matrix(P',Kernel_type, Kernel_para,TV.P'); TY=(Omega_test' * OutputWeight)'; % TY: the actual output of the testing data TestingTime=toc %%%%%%%%%% Calculate training & testing classification accuracy if Elm_Type == REGRESSION %%%%%%%%%% Calculate training & testing accuracy (RMSE) for regression case TrainingAccuracy=sqrt(mse(T - Y)) TestingAccuracy=sqrt(mse(TV.T - TY)) end if Elm_Type == CLASSIFIER %%%%%%%%%% Calculate training & testing classification accuracy MissClassificationRate_Training=0; MissClassificationRate_Testing=0; for i = 1 : size(T, 2) [x, label_index_expected]=max(T(:,i)); [x, label_index_actual]=max(Y(:,i)); if label_index_actual~=label_index_expected MissClassificationRate_Training=MissClassificationRate_Training+1; end end TrainingAccuracy=1-MissClassificationRate_Training/size(T,2) for i = 1 : size(TV.T, 2) [x, label_index_expected]=max(TV.T(:,i)); [x, label_index_actual]=max(TY(:,i)); if label_index_actual~=label_index_expected MissClassificationRate_Testing=MissClassificationRate_Testing+1; end end TestingAccuracy=(1-MissClassificationRate_Testing/size(TV.T,2))*100 end %%%%%%%%%%%%%%%%%% Kernel Matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function omega = kernel_matrix(Xtrain,kernel_type, kernel_pars,Xt) nb_data = size(Xtrain,1); if strcmp(kernel_type,'RBF_kernel'), if nargin<4, XXh = sum(Xtrain.^2,2)*ones(1,nb_data); omega = XXh+XXh'-2*(Xtrain*Xtrain'); omega = exp(-omega./kernel_pars(1)); else XXh1 = sum(Xtrain.^2,2)*ones(1,size(Xt,1)); XXh2 = sum(Xt.^2,2)*ones(1,nb_data); omega = XXh1+XXh2' - 2*Xtrain*Xt'; omega = exp(-omega./kernel_pars(1)); end elseif strcmp(kernel_type,'lin_kernel') if nargin<4, omega = Xtrain*Xtrain'; else omega = Xtrain*Xt'; end elseif strcmp(kernel_type,'poly_kernel') if nargin<4, omega = (Xtrain*Xtrain'+kernel_pars(1)).^kernel_pars(2); else omega = (Xtrain*Xt'+kernel_pars(1)).^kernel_pars(2); end elseif strcmp(kernel_type,'wav_kernel') if nargin<4, XXh = sum(Xtrain.^2,2)*ones(1,nb_data); omega = XXh+XXh'-2*(Xtrain*Xtrain'); XXh1 = sum(Xtrain,2)*ones(1,nb_data); omega1 = XXh1-XXh1'; omega = cos(kernel_pars(3)*omega1./kernel_pars(2)).*exp(-omega./kernel_pars(1)); else XXh1 = sum(Xtrain.^2,2)*ones(1,size(Xt,1)); XXh2 = sum(Xt.^2,2)*ones(1,nb_data); omega = XXh1+XXh2' - 2*(Xtrain*Xt'); XXh11 = sum(Xtrain,2)*ones(1,size(Xt,1)); XXh22 = sum(Xt,2)*ones(1,nb_data); omega1 = XXh11-XXh22'; omega = cos(kernel_pars(3)*omega1./kernel_pars(2)).*exp(-omega./kernel_pars(1)); end end
测试集结果如下图所示:
四、参考文献
完整代码下载https://www.cnblogs.com/ttmatlab/p/14882966.html
这篇关于【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-10百万架构师第十三课:源码分析:Spring 源码分析:Spring核心IOC容器及依赖注入原理|JavaGuide
- 2025-01-10便捷好用的电商API工具合集
- 2025-01-09必试!帮 J 人团队解决物流错发漏发的软件神器!
- 2025-01-09不容小觑!助力 J 人物流客服安抚情绪的软件!
- 2025-01-09为什么医疗团队协作离不开智能文档工具?
- 2025-01-09惊叹:J 人团队用啥软件让物流服务快又准?
- 2025-01-09如何利用数据分析工具优化项目资源分配?4种工具推荐
- 2025-01-09多学科协作难?这款文档工具可以帮你省心省力
- 2025-01-09团队中的技术项目经理TPM:工作内容与资源优化策略
- 2025-01-09JIT生产管理法:优化流程,提升竞争力的秘诀