annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/hits.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [hits,ninvalid] = hits(bmus, mmax, values)
wolffd@0 2
wolffd@0 3 %HITS Calculate number of occurances of each value.
wolffd@0 4 %
wolffd@0 5 % hits = hits(bmus,[mmax],[values])
wolffd@0 6 %
wolffd@0 7 % h = hits(bmus);
wolffd@0 8 % h = hits(bmus,length(sM.codebook));
wolffd@0 9 %
wolffd@0 10 % Input and output arguments ([]'s are optional):
wolffd@0 11 % bmus (vector) BMU indeces (or other similar)
wolffd@0 12 % [mmax] (scalar) maximum index, default value max(bmus)
wolffd@0 13 % (struct) map or topology struct from where the maximum
wolffd@0 14 % index is acquired
wolffd@0 15 % [values] (vector) values associated with the data (default = 1)
wolffd@0 16 %
wolffd@0 17 % hits (vector) the number of occurances of each index
wolffd@0 18 % (or if values are given, their sum for each index)
wolffd@0 19 % ninvalid (scalar) number of invalid indeces (NaN, Inf or
wolffd@0 20 % <=0 or > mmax)
wolffd@0 21 %
wolffd@0 22 % See also SOM_HITS, SOM_BMUS.
wolffd@0 23
wolffd@0 24 % Copyright (c) 2002 by the SOM toolbox programming team.
wolffd@0 25 % Contributed to SOM Toolbox by Juha Vesanto, April 24th, 2002
wolffd@0 26 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 27
wolffd@0 28 % Version 2.0beta juuso 240402
wolffd@0 29
wolffd@0 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 31
wolffd@0 32 if nargin<2 | isempty(mmax),
wolffd@0 33 mmax = max(bmus);
wolffd@0 34 elseif isstruct(mmax),
wolffd@0 35 switch mmax.type,
wolffd@0 36 case 'som_map', mmax = prod(mmax.topol.msize);
wolffd@0 37 case 'som_topol', mmax = prod(mmax.msize);
wolffd@0 38 otherwise,
wolffd@0 39 error('Illegal struct for 2nd argument.')
wolffd@0 40 end
wolffd@0 41 end
wolffd@0 42
wolffd@0 43 if nargin<3, values = 1; end
wolffd@0 44
wolffd@0 45 valid_bmus = find(isfinite(bmus) & bmus>0 & bmus<=mmax);
wolffd@0 46 ninvalid = length(bmus)-length(valid_bmus);
wolffd@0 47
wolffd@0 48 bmus = bmus(valid_bmus);
wolffd@0 49 if length(values)>length(bmus), values = values(valid_bmus); end
wolffd@0 50 hits = full(sum(sparse(bmus,1:length(bmus),values,mmax,length(bmus)),2));
wolffd@0 51
wolffd@0 52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 53