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

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