?? neuralnetwork_rbf_classification.m
字號:
% RBF 神經網絡用于模式分類
% 使用平臺 - Matlab6.5
% 作者:陸振波,海軍工程大學
% 歡迎同行來信交流與合作,更多文章與程序下載請訪問我的個人主頁
% 電子郵件:luzhenbo@yahoo.com.cn
% 個人主頁:http://luzhenbo.88uu.com.cn
clc
clear
close all
%---------------------------------------------------
% 產生訓練樣本與測試樣本,每一列為一個樣本
n1 = [rand(3,5),rand(3,5)+1,rand(3,5)+2];
x1 = [repmat([1;0;0],1,5),repmat([0;1;0],1,5),repmat([0;0;1],1,5)];
n2 = [rand(3,5),rand(3,5)+1,rand(3,5)+2];
x2 = [repmat([1;0;0],1,5),repmat([0;1;0],1,5),repmat([0;0;1],1,5)]
xn_train = n1; % 訓練樣本
dn_train = x1; % 訓練目標
xn_test = n2; % 測試樣本
dn_test = x2; % 測試目標
%---------------------------------------------------
% 訓練與測試
switch 3
case 1
% 神經元數是訓練樣本個數
P = xn_train;
T = dn_train;
spread = 40; % 此值越大,覆蓋的函數值就大(默認為1)
net = newrbe(P,T,spread);
case 2
% 神經元數逐步增加,最多就是訓練樣本個數
P = xn_train;
T = dn_train;
goal = 1e-8; % 訓練誤差的平方和(默認為0)
spread = 40; % 此值越大,需要的神經元就越少(默認為1)
MN = size(xn_train,2); % 最大神經元數(默認為訓練樣本個數)
DF = 1; % 顯示間隔(默認為25)
net = newrb(P,T,goal,spread,MN,DF);
case 3
P = xn_train;
T = dn_train;
spread = 0.5; % 此值越大,需要的神經元就越少(默認為1)
net = newgrnn(P,T,spread);
end
X = sim(net,xn_test); % 測試 - 輸出為預測值
X = full(compet(X)) % 競爭輸出
%---------------------------------------------------
% 結果統計
Result = ~sum(abs(X-x2)) % 正確分類顯示為1
Percent = sum(Result)/length(Result) % 正確分類率
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -