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

📄 som_net.m

📁 MOLMAP multiway toolbox是一个matlab集成工具箱
💻 M
字号:
function net = som_net(X,settings,class);

% som_net calculates the Kohonen map (Self Organizing Map) weights
%
% net = som_model(X,settings,class)
%
% input:
%   X           data [n x p]
%   settings    setting structure
%
% optional input, only for CPANNs:
%   class       class vector [n x 1]
% 
% output:
%   net         structure containing all the map information (used settings 
%               and calculated weights [size x size x p]
%
% see the HTML HELP files (help.htm) for extensive explanations, details and examples
%
% The toolbox is freeware and may be used (but not modified) 
% if proper reference is given to the authors. Preferably refer to:
% D. Ballabio, V. Consonni, R. Todeschini
% Classification of multiway analytical data based on MOLMAP approach
% Analytica Chimica Acta, in press
% 
% version 1.0 - november 2007
% Davide Ballabio
% Milano Chemometrics and QSAR Research Group
% www.disat.unimib.it/chm


nsize  = settings.nsize;
enter  = settings.enter;
nobj   = size(X,1);
nvar   = size(X,2);
display_mod = 10;  % display epochs every display_mod
start_epoch = 1;
end_epoch = settings.epochs;
if nargin == 3
    net_type = 'cpann';
else
    net_type = 'kohonen';
end

% initializes kohonen weights inbetween 0.1 and 0.9
W = rand(nsize, nsize, size(X,2)).*0.8 + 0.1;
W = reshape(permute(W,[2 1 3]),[nsize*nsize nvar]);

if strcmpi(net_type,'cpann')
    in_out = zeros(size(class,1),max(class));
    for i=1:size(class,1); in_out(i,class(i)) = 1; end;
    W_out = ones(nsize, nsize, size(in_out,2)).*(1/max(class));
    W_out = reshape(permute(W_out,[2 1 3]),[nsize*nsize size(in_out,2)]);
end

disp(['training net (size: ' num2str(settings.nsize) 'x' num2str(settings.nsize) ' - epochs: ' num2str(settings.epochs) ')'])
in_order = 1:nobj;
for e = start_epoch:end_epoch
    if mod(e,display_mod) == 0
        disp(['training epochs: ' num2str(e) ' of ' num2str(end_epoch)])
    end
    if strcmpi(enter,'random')
        in_order = randperm(nobj);
    end
    for i = 1:nobj
        x_in = X(in_order(i),:);
        % calculates winning neuron
        winner = som_winner(x_in,W);
        % applies corrections
        [Wnew,param_correction] = som_update(x_in,W,winner,settings,e,i,nobj);
        W = Wnew;        
    end
end
disp('training finished')
    
% readapts W from reshaping
for k=1:nsize
    for j=1:nsize
        ind = som_which_col(k,j,size(W,1));
        W_final(k,j,:) = W(ind,:);
    end
end

% saves results
net.W = W_final;
net.settings = settings;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -