Java教程

【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码

本文主要是介绍【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、核极限学习机

本文将介绍一种新的SLFN的算法,极限学习机,该算法将随机产生输入层和隐含层间的连接权值和隐含层神经元的阈值,且在训练过程中无需调整,只需要设置隐含层的神经元的个数,便可以获得唯一最优解,与传统的训练方法相比,该方法具有学习速率快、泛化性能好等优点。

6bfe375e9892be0abf61e73c35878cc6.png

 

aebaeed27d655064c50c534314a67986.jpeg

典型的单隐层前馈神经网络如上图所示,输入层与隐含层,隐含层与输出层之间是全连接的。输入层的神经元的个数是根据样本的而特征数的多少来确定的,输出层的神经元的个数是根据样本的种类数来确定的

ee545312a27139338194b69c176c93d3.png

bb24614b1bebe213868990590464cb64.png

设隐含层神经元的阈值 b为:


fd4ce9c2b288047e7fc066651077cf0e.png

460453f1234f35811aa44418cd1d5696.png

934c4757dac7d919dd2a5f29c516516f.png

adc278528266b6a695fdd259a0396583.png

8bcb5e88f64228d40d3bcea4b9e3483a.png

8e839ff7e20296ad45fb5a85cd075da6.png

bba2fea477466eccd82b4af330a523a9.png

当隐层神经元的个数和样本数相同时(10)式有唯一的解,也就是说零误差的逼近训练样本。通常的学习算法中,W和b需要不断进行调整,但研究结果告诉我们,他们事实上是不需要进行不断调整的,甚至可以随意指定。调整他们不仅费时,而且并没有太多的好处。(此处有疑虑,可能是断章取义,这个结论有可能是基于某个前提下的)。

 

 

0de6928c273afe763186217029c4fe62.png

 

二、狮群算法

3e82ecaa6e258fe1afbd2c22e628ff30.png

4cb3d5ad86e315630fbc8b3e0b4290ff.png

48a2185fa50bcc64fd4b25d056b72a17.png

2f7b690da43d3ee1c91fb81901d76f75.png

169836c3483cc7423dd67d327453d0a6.png

三、代码介绍

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

61e388925e6162f557923fa646d6b4ee.png

测试集结果如下图所示:
b52791a879128da9ebc239d6384ced57.png

四、参考文献

完整代码下载https://www.cnblogs.com/ttmatlab/p/14882966.html

这篇关于【预测模型】基于狮群算法改进核极限学习机(KELM)分类算法 matlab源码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!