forked from ilarinieminen/SOM-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
som_bmucolor.m
93 lines (74 loc) · 2.19 KB
/
som_bmucolor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function bmu_colors=som_bmucolor(bmus, m, colors)
% SOM_BMUCOLOR Returns the colors of the bmus according to a map colorcode
%
% bmu_colors=som_bmucolor(bmus, msize, colors);
%
% INPUT ARGUMENTS ([]'s are optional)
%
% bmus (matrix) Nx1 vector of BMU indexes
% msize (map struct, topol struct or 1x2 vector)
% gives the map grid size
% colors (matrix) colormap(s): munits x 3 x d matrix of RGB vectors
%
% OUTPUT ARGUMENTS
%
% bmu_colors (Nx3xd matrix) color of the data point according to its BMU's
% color(s).
%
% Idea is to get a color for each data point that links it to its BMU.
%
% EXAMPLE
%
% We want to show how an time series is projected to a map. Instead of
% a trajectory, we use 'color linking'
%
% map=som_make(multi_dim_signal);
% bmus=som_bmu(map,multi_dim_signal);
% Colors=som_bmucolor(bmus, map, som_colorcode(map,'rgb1'));
% colorsignal(Colors, multi_dim_signal);
%
% See also SOM_COLORCODE.
% Copyright (c) 1999-2000 by the SOM toolbox programming team.
% http://www.cis.hut.fi/projects/somtoolbox/
% Version 2.0alpha Johan 170699
%% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
error(nargchk(3, 3, nargin)) % check no. of input args is correct
% Check map grid size
if vis_valuetype(m,{'1x2'}),
msize=m;
else
[tmp,ok,tmp]=som_set(m);
if isstruct(m) && all(ok) % check m type
switch m.type
case 'som_topol'
msize=m.msize;
lattice=m.lattice;
case 'som_map'
msize=m.topol.msize;
lattice=m.topol.lattice;
otherwise
error('Invalid map or topol struct.');
end
end
end
if length(msize)>2
error('Only 2D maps allowed!');
end
n=prod(msize)
% Check colorcode size
if ~vis_valuetype(colors,{'nx3xdimrgb','nx3rgb'})
error('Colorcode matrix not valid!');
end
% Check bmu vector
if ~vis_valuetype(bmus,{'nx1'}),
error('Need a column vector of BMU indexes!');
else
bmus=round(bmus);
if max(bmus) > n || min(bmus) < 1
error('BMU indexes exeed the map size!')
end
end
%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bmu_c=colors(bmus,:,:);
%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bmu_colors=squeeze(bmu_c);