function [hits] = som_hits(sMap, sData)
%SOM_HITS Calculate the number of hits from the data to each map unit.
%
% hits = som_hits(sMap, sData)
%
% ARGUMENTS
%
% Input and output arguments ([]'s are optional):
% sMap (struct) map struct
% (matrix) codebook matrix, size munits x dim
% sData (struct) data struct
% (matrix) data matrix, size dlen x dim
%
% hits (vector) the number of hits in each map unit, length = munits
%
% For more help, try 'type som_hits' or check out the helpdesk.
% See also SOM_AUTOLABEL, SOM_BMUS.
%%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% som_hits
%
% PURPOSE
%
% Calculate the number of hits from the data to each map unit.
%
% SYNTAX
%
% hits = som_hits(sMap, sData)
%
% DESCRIPTION
%
% Returns a vector indicating how many "hits" each map unit got
% from the data. In other words, how many times each map unit
% was the BMU.
%
% INPUT ARGUMENTS
%
% sMap The vectors from among which the BMUs are searched
% for. These must not have any unknown components (NaNs).
% (struct) map struct
% (matrix) codebook matrix, size munits x dim
%
% sData The data vector(s) for which the BMUs are searched.
% (struct) data struct
% (matrix) data matrix, size dlen x dim
%
% OUTPUT ARGUMENTS
%
% hits (vector) The number of hits in each map unit.
%
% EXAMPLES
%
% hits = som_hits(sM,D);
%
% SEE ALSO
%
% som_bmus Find BMUs and quantization errors for a given data set.
% Copyright (c) 1997-1999 by the SOM toolbox programming team.
% http://www.cis.hut.fi/projects/somtoolbox/
% Version 1.0beta juuso 220997
% Version 2.0beta juuso 151199
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% check arguments
error(nargchk(2, 2, nargin)); % check no. of input args is correct
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% action
% calculate BMUs
bmus = som_bmus(sMap,sData,1);
% for each unit, check how many hits it got
if isstruct(sMap), munits = prod(sMap.topol.msize);
else munits = size(sMap,1);
end
hits = zeros(munits,1);
for i=1:munits, hits(i) = sum(bmus == i); end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%