Code covered by the BSD License  

Highlights from
LABELNET

image thumbnail

LABELNET

by

 

26 Feb 2002 (Updated )

Plots neurons and inputs of a self-organizing network on a 2D weight map.

labelnet(net,varargin)
function labelnet(net,varargin)
% LABELNET(NET)
%   Plots and label the network architecture for a self organizing 
%   neural network NET.
% 
% LABBELNET(NET,M)
%   Plots the net with the markersize determined by M.
%   If you want to specify a markersize and need to use 
%   the options below, use [] (the default value of
%   20 will then be used.
%
% LABELNET(NET,M,P)
%   Plots the neural network and the inputs. Only the neural
%   gets labeled.
% 
% LABELNET(NET,M,P,1)
%   Plots and label both the neural network and the inputs.
%   
% LABELNET(NET,M,P,0)
%   Colorcodes the Neurons and Inputs that they fire to. Only 
%   the neurons get labeled (to labe input, call LABELNET again
%   with the HOLD ON function and the LABELNET(NET,P,1) syntax.
%     
%   
% EXAMPLE:
%   
%   net = newsom([0 2; 0 1] , [2 3]); %create net and inputs
%   P = [.1 .3 1.2 1.1 1.8 1.7 .1 .3 1.2 1.1 1.8 1.7;...
%   0.2 0.1 0.3 0.1 0.3 0.2 1.8 1.8 1.9 1.9 1.7 1.8];
%
%   net.trainParam.epochs = 100; %train and plot @100 epochs
%   net = train(net,P);
%   labelnet(net,[],P,1);
%
%   net.trainParam.epochs = 300; %train and plot @100 more epochs
%   net = train(net,P);
%   figure; labelnet(net,[],P,0);

   

inputs=length(varargin);
M=20;
try,if ~isempty(varargin{1,1}),M=varargin{1,1};end,catch,end;

%Plot just the neurons

plotsom(net.iw{1,1},net.layers{1}.distances)
neurons=net.iw{1,1};
hold on;

for i=1:length(neurons),
        
    eval(['str=[''Neuron '',''',num2str(i),'''];'])
    text(neurons(i,1),neurons(i,2),str);
      
end

%Plot neurons and Input

if inputs >=2,
    
    P=varargin{1,2};
    plot(P(1,:),P(2,:),'.g','markersize',M)
    hold on

%Plot Neurons/Input and Label the Inputs

    if inputs ==3,
    
        if varargin{1,3}==1,
            
           for i=1:length(P),
        
               eval(['str=[''Input '',''',num2str(i),'''];'])
               text(P(1,i),P(2,i),str);
        
           end
           
%Color cluster Inputs and Neurons        
        elseif varargin{1,3}==0,
            
               marker={'.y','.m','.c','.r','.g','.b','.k'};
               colors={};
               j=1;
               for i=1:length(neurons),
                   if j>length(marker),
                       j=1;
                   end
                   colors{end+1}=marker(j);
                   j=j+1;
               end
                   
               A=sim(net,P);
               data=vec2ind(A);
               
               for i=1:length(neurons),
               
               str = colors{i};
               str = [str{:}];
               plot(neurons(i,1),neurons(i,2),str,'markersize',M);
               hold on;
               
               ind = find(data(:)==i);
               select= P(:,ind);
               plot(select(1,:),select(2,:),str,'markersize',M)
            
               end
        end
    end
end




    

Contact us