⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dosom.m

📁 有关聚类的一些例子
💻 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 + -