?? dosom.m
字號:
% doSom: Supervised classification using Self-Organizing Map (SOM is
% actually an unsupervised clustering technique. )
%
% [C] = doSom(data, proto, protoClass)
%
% Input and output arguments ([]'s are optional):
% data (matrix) of size NxD. N is the number of data (classifiee)
% vectors, and D is the dimension of each vector.
% proto (matrix) of size PxD. P is the number of prototype vectors,
% and D is the dimension of each vector.
% protoClass (vector) of size Px1 that contains integer class labels of
% prototypes. protoClass(j) is the class of jth prototype.
% [UNIT] (scalar) # of SOM units. UNIT == # of class will avoid
% the risk to be classified as unknown anyway.
% C (vector) of size Nx1: integers indicating the class
% decision for data items. C(i) is the classification for
% data item i.
%
% Requirement: somtoolbox
%
% Author : Naotoshi Seo
% Date : April, 2005
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function C = doSom(data, proto, protoClass, UNIT)
% addpath('somtoolbox');
if nargin < 4
classLabel = unique(protoClass);
nClass = length(classLabel);
UNIT = nClass; % # of SOM units
end
if size(data,2) ~= size(proto,2)
error('Dimension of data vectors and prototype vectors do not match.');
end
if size(proto,1) ~= size(protoClass,1)
error('Row # of prototypes and prototype class vector do not match.');
end
%%%% Training
%sMap = som_randinit(proto); % init randomly
%sMap = som_seqtrain(sMap, proto); % sequential train
sMap = som_make(proto, 'munits', UNIT); % equals to randinit and seqtrain
% labeling proto class to SOM units (make SOM supervised)
protoSom = som_data_struct(proto,'labels',num2str(protoClass));
sMap = som_autolabel(sMap, protoSom);
% plot SOM space
%som_grid(sMap, 'Label', sMap.labels, 'LabelSize', 30);
%%%%% Testing
[Bmus, Qerrors] = som_bmus(sMap, data); % find best matching units
% labeling
%sMap.labels
dataClassified = sMap.labels(Bmus);
for i=1:length(dataClassified)
if isempty(dataClassified{i}), dataClassified{i} = '0', end;
end
C = cellfun(@str2num, dataClassified);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -