💥💥💥💞💞💞歡迎來到本部落格❤️❤️❤️💥💥💥
🏆部落客優勢:🌞🌞🌞部落格内容盡量做到思維缜密,邏輯清晰,為了友善讀者。
⛳️座右銘:行百裡者,半于九十。
目錄
💥1 概述
1.1 RBF神經網絡模型
1.2 K-均值聚類算法
📚2 運作結果
🎉3 參考文獻
🌈4 Matlab代碼實作
💥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