💥💥💥💞💞💞欢迎来到本博客❤️❤️❤️💥💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
目录
💥1 概述
1.1 RBF神经网络模型
RBF神经网络是一种常见的三层结构神经网络,主要包括输入层、隐含层及输出层,如图1所示。RBF神经网络的作用原理,是将径向基函数(RBF)作为网络第二层隐含层的节点函数,以此构成隐含层空间。当数据被输入网络后,输入层会把数据传递给隐含层。经过隐含层节点函数计算之后,再将数据传递给输出层。通常而言,隐含层节点的计算函数是非线性的。当隐含层的节点数增加时,处理数据的次数也随之增加,使RBF网络得到的结果也就更加精确。但是,过多的节点数会减低网络的执行效率。第三层输出层的节点函数通常是线性的,其作用通常是对隐含层函数计算所得结果进行加权处理,将数据处理成方便输出,容易读懂的形式。
在 RBF神经网络中,设输入层节点个数为Ⅰ,隐含层节点数为M,输出层节点数为N,输入量为x.当x经输入到模型后,会经过Ⅰ次传递。因此定义x为Ⅰ维输入量。设输出量为y,同理y会经过N次输出,称y为N维输出量。一般来说,采用高斯激活函数作为隐含层节点的作用函数,该函数在RBF网络隐含层第i个节点输出为:
1.2 K-均值聚类算法
K均值聚类算法是目前应用最为广泛的划分聚类算法。其算法具有原理简单、模型清晰、操作方便、计算快速等特点,可以大规模同时对多种类型的数据进行聚类,快速挖掘出数据中隐含的关系和结构。
K均值聚类算法是判断基于数据到中心点的距离来区分数据的所属类别。其把N个对象划分)成k个簇,用簇中对象的均值表示每个簇的中心点(质心),利用合适的距离计算公式,计算出数据与聚类中心的距离,将其划分到合适的聚类中。当所有数据聚类结束后,检查聚类中心是否已收敛,如果收敛则终止,否则将继续迭代。
📚2 运行结果
部分代码:
function [C]=K_Means(X,M,D)
%% Function for Finding K-Means in the X data
% X is the Data Matrix
% M is the Number of Means Required (K)
temp=randperm(size(X,1)); % Random Permutation of Random index to pick data point
C=X(temp(1:M),:); % Initial Guess for Centers is the random data point
J=[]; % Cost Function to be minimized
k=1; % Iteration number
while(1)
J(k)=0;
S=zeros(M,size(X,2)); % Sum of values fall in K Centers
indeX=[]; % Index of the closest Center to the test data point
for i=1:size(X,1)
temp=0; % temporary Variable for storing distance to centers
for j =1:M
temp(j)=(norm((X(i,:)-C(j,:))).^2);
end
[tmp,ind]=min(temp); % Finding the closest Center for ith data point
indeX=[indeX ind]; % Index of the closest Center to the test data point
S(ind,:)=S(ind,:)+X(i,:); % Sum of values fall in K Centers
J(k)=J(k)+sum(temp); % Cost Function
end
for j=1:M
N(j)=length(find(indeX==j)); % Number of Values closest to jth Center
end
Ctemp=[]; % Temporary Values for Center that will be updated only if different
for l=1:size(X,2)
Ctemp=[Ctemp S(:,l)./N'];
end
%% Check for update and stoping condition
% Temporary Values for Center that will be updated only if different
if(sum(sum(~(C==Ctemp)))~=0)
C=Ctemp;
else
break
end
%% Optional Animated Graph for Data only work if number of argument to function > 2
% START
if (nargin>2)
scatter(X(:,1),X(:,2))
hold on
scatter(C(:,1),C(:,2),'filled')
hold off
pause(0.25)
end
% END
k=k+1;
end
%% Optional Graph for Cost only work if number of argument to function > 2
% START
if (nargin>2)
figure,plot(J)
xlabel('Iterations');
ylabel('Cost');
title('Cost Function');
end
% END
🎉3 参考文献
[1]张天逸,孙毅然,刘凡琪,梁悦祺,林永杰,马明辉.基于K均值聚类算法与RBF神经网络的交通流预测方法[J].智能计算机与应用,2020,10(08):148-151.