📄 model_kohonen.m
字号:
function model = model_kohonen(X,settings);
% Kohonen maps
% model_kohonen builds Kohonen maps (self organising maps, SOM)
%
% model = model_kohonen(X,settings);
%
% input:
% X data [n x p], n samples, p variables
% settings setting structure
%
% output:
% model is a structure, with the following fields
% model.net.W kohonen weights [size x size x p]
% model.scal structure containing scaling parameters
% model.res.top_map sample position in the kohonen map [n x 2]
%
% important:
% - to define the settings structure type 'help som_settings'
% - data are always range scaled (inbetween 0 and 1) in order to
% make them comparable with net weights
%
% see the HTML HELP files (help.htm) for details and examples
%
% version 1.0 - may 2007
% Davide Ballabio
% Milano Chemometrics and QSAR Research Group
% www.disat.unimib.it/chm
% checks
errortype = kohonen_check(X,settings,[],'model');
if ~strcmp(errortype,'none')
disp(errortype)
return
end
% data scaling
[Xsca,scal] = som_scaling(X,settings);
% calculates the map
net = som_net(Xsca,settings);
% projects the samples on the topmap
W_reshape = reshape(permute(net.W,[2 1 3]),[settings.nsize*settings.nsize size(Xsca,2)]);
for i = 1:size(Xsca,1)
x_in = Xsca(i,:);
winner = som_winner(x_in,W_reshape);
[pos(i,1),pos(i,2)] = som_which_neuron(winner,size(W_reshape,1));
end
% saves results
model.type = 'kohonen_map';
model.net = net;
model.scal = scal;
model.res.top_map = pos;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -