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