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

📄 som_update.m

📁 this file is leverage algorithm written in matlab as m-file and tested in matlab.so anyone can ue th
💻 M
字号:
function [Wnew,param_correction] = som_update(x,W,winner,settings,act_epoch,act_obj,tot_obj);

% som_update updates kohonen weights
%
% see the HTML HELP files (help.htm) for details 
% or type "help model_kohonen" or "help model_cpann"
%
% [Wnew,param_correction] = som_update(x,W,winner,settings,act_epoch,act_obj,tot_obj)
%
% input:
%   x           sample [1 x c]
%   W           unfolded kohonen weights [size*size x c]
%   winner      winner neuron
%   settings    setting structure
%   act_epoch   number of actual epoch
%   act_obj     numbe rof actual sample
%   tot_obj     total number of samples
% 
% output:
%   Wnew       unfolded updated kohonen weights [size*size x c]
%
% see the HTML HELP files (help.htm) for details 

% calculates the number of rings of neurons to be corrected

rings = (1 + (settings.nsize - 1)/2)*(settings.epochs - act_epoch)/(settings.epochs - 1);
rings = ceil(rings) - 1;
if rings < 0; rings = 0; end;

% calculates the changing rate for each neuron in the ring
if strcmpi(settings.a_chg,'to_epo')
    L = (settings.a_max - settings.a_min)*(settings.epochs - act_epoch)/(settings.epochs - 1) + settings.a_min;
else
    ind = ((act_epoch - 1)*tot_obj + 1):act_epoch*tot_obj;
    count_ind = ind(act_obj);
    L = (settings.a_max - settings.a_min)*(settings.epochs*tot_obj - count_ind)/(settings.epochs*tot_obj - 1) + settings.a_min;
end

% applies updating in the winning neuron
Wnew = W;
Wnew(winner,~isnan(x)) = W(winner,~isnan(x)) + L*1*(x(~isnan(x)) - W(winner,~isnan(x)));

% save the settings.bound field in another format to speed up the algorithm
if strcmpi(settings.bound,'toroidal')
    bound = 1;
else
    bound = 0;
end

% applies updating in the rings
for r=1:rings
    D = 1 - r/(1 + rings);
    [list_of_neurons] = som_find_neigb(winner,r,bound,settings.nsize);
    param_correction.list_of_neurons{r} = list_of_neurons;
    ind = list_of_neurons';
    x_diff = zeros(size(ind,1),size(x,2));
    for j=1:size(x,2)
        x_diff(:,j) = x(j);
    end

    Wnew(ind,~isnan(x)) = W(ind,~isnan(x)) + L*D*(x_diff(:,~isnan(x)) - W(ind,~isnan(x)));
    
end

param_correction.rings = rings;
param_correction.L = L;

⌨️ 快捷键说明

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