wolffd@0: function [hits,ninvalid] = hits(bmus, mmax, values) wolffd@0: wolffd@0: %HITS Calculate number of occurances of each value. wolffd@0: % wolffd@0: % hits = hits(bmus,[mmax],[values]) wolffd@0: % wolffd@0: % h = hits(bmus); wolffd@0: % h = hits(bmus,length(sM.codebook)); wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % bmus (vector) BMU indeces (or other similar) wolffd@0: % [mmax] (scalar) maximum index, default value max(bmus) wolffd@0: % (struct) map or topology struct from where the maximum wolffd@0: % index is acquired wolffd@0: % [values] (vector) values associated with the data (default = 1) wolffd@0: % wolffd@0: % hits (vector) the number of occurances of each index wolffd@0: % (or if values are given, their sum for each index) wolffd@0: % ninvalid (scalar) number of invalid indeces (NaN, Inf or wolffd@0: % <=0 or > mmax) wolffd@0: % wolffd@0: % See also SOM_HITS, SOM_BMUS. wolffd@0: wolffd@0: % Copyright (c) 2002 by the SOM toolbox programming team. wolffd@0: % Contributed to SOM Toolbox by Juha Vesanto, April 24th, 2002 wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta juuso 240402 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: if nargin<2 | isempty(mmax), wolffd@0: mmax = max(bmus); wolffd@0: elseif isstruct(mmax), wolffd@0: switch mmax.type, wolffd@0: case 'som_map', mmax = prod(mmax.topol.msize); wolffd@0: case 'som_topol', mmax = prod(mmax.msize); wolffd@0: otherwise, wolffd@0: error('Illegal struct for 2nd argument.') wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if nargin<3, values = 1; end wolffd@0: wolffd@0: valid_bmus = find(isfinite(bmus) & bmus>0 & bmus<=mmax); wolffd@0: ninvalid = length(bmus)-length(valid_bmus); wolffd@0: wolffd@0: bmus = bmus(valid_bmus); wolffd@0: if length(values)>length(bmus), values = values(valid_bmus); end wolffd@0: hits = full(sum(sparse(bmus,1:length(bmus),values,mmax,length(bmus)),2)); wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: