comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_trajectory.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 som_trajectory(bmus,varargin)
2
3 %SOM_TRAJECTORY Launch a "comet" trajectory visualization GUI.
4 %
5 % som_show(sM,'umat','all')
6 % bmus = som_bmus(sM,sD);
7 % som_trajectory(bmus)
8 % som_trajectory(bmus, 'data1', sD, 'trajsize', [12 6 3 1]')
9 % som_trajectory(bmus, 'data1', sD.data(:,[1 2 3]), 'name1', {'fii' 'faa' 'foo'})
10 %
11 % Input arguments ([]'s are optional):
12 % bmus (matrix) size Nx1, vector of BMUS
13 % ['argID', (string) Other arguments can be given as 'argID', value
14 % value] (varies) pairs. See list below for valid values.
15 %
16 % NOTE: the GUI only works on a figure which has been made with SOM_SHOW.
17 %
18 % Here are the valid argument IDs (case insensitive) and associated values:
19 % 'color' string 'xor' or ColorSpec, default: 'xor'.
20 % (default: according to lattice as in som_cplane)
21 % 'TrajSize' vector of size Nx1 to define the length of comet
22 % (N) and size of the comet dots in points.
23 % default: [16 12 10 8 6 4]'
24 % 'Data1' SOM Toolbox data struct or matrix. The size of
25 % data matrix (in data struct the field .data) is
26 % Nxd, where N must be the same as the amount of
27 % BMUS given in the first input argument 'bmus'
28 % This data is shown in a new window in d subplots.
29 % Default: BMU indices (first input argument)
30 % 'Name1' cell array of d strings which contains names
31 % for the components in 'Data1'. If 'Data1' is a SOM
32 % Toolbox data struct, the existing component names
33 % are overdone.
34 % 'Figure' scalar that must be a handle to an existing figure
35 % which has been made using SOM_SHOW function.
36 % Default: current active figure (gcf).
37 %
38 % The following tools can be found in the 'Tools' -menu.
39 %
40 % Remove Trajectory: removes trajectory from the map.
41 % Dye Nodes : opens GUI for selecting color for the nodes
42 % and points selected.
43 % Clear Markers : removes markers from map and data figure.
44 % Save : saves the current situation as a struct.
45 % Load : loads the struct from workspace and draws markers.
46 %
47 % Mouse operation
48 %
49 % In data window: Left button is used to drag the operation point ruler
50 % if left button is on blank area, it starts
51 % In map window : Left button starts a polygon; right button
52 % finishes; middle button toggles a unit.
53 %
54 % SOM_TRAJECTORY is an application for observing trajectory behavior.
55 %
56 % Using mouse the line in data figure can be dragged and the
57 % trajectory moves in the SOM SHOW figure. It is also possible to move
58 % trajectory by pressing keys '>' and '<' when mouse pointer is above
59 % data figure.
60 %
61 % Regions can be chosen from the data and the points in that region
62 % are mapped to the component planes. Regions can be chosen also in
63 % the map. In this situation data points and map nodes are also
64 % marked (Left mouse button adds point to the polygon indicating the
65 % region and right button finals the polygon). By clicking a node (the
66 % middle button) that node is either added or removed from selection.
67 %
68 % It should be noticed that choosing intervals from data may cause
69 % situations that seem to be bugs. If there exisist marks of different
70 % color, removing them by clicking the map may left some marks in the
71 % data, because more than one point in the data is mapped to the same
72 % node in the map and the removing operation depends on the color of
73 % the marks. However, all the marks can be removed by using the 'Clear
74 % Markers' -operation.
75 %
76 % FEATURES
77 %
78 % The first input argument 'bmus' may also be a munits x N matrix
79 % In this case each column defines a "fuzzy response". That is,
80 % each column defines a hit histogram function). The element
81 % bmus(i,t) sets the size of marker on unit i at time t.
82 % NOTE: - in this case no regions can be selcted on the map!
83 % - only > and < keys can be used to move the operation point
84 % line: it can't be dragged
85 % - "fuzzy response is always black (hope this will be fixed)
86 %
87 % It is possible to open a second data window showing different data:
88 % use indetifiers 'Data2' (and 'Name2'). The argument syntax is
89 % identical to 'Data1' (and 'Name1').
90 %
91 % See also SOM_SHOW, SOM_SHOW_ADD, SOM_BMUS.
92
93 % Contributed to SOM Toolbox 2.0, February 11th, 2000 by Johan
94 % Himberg and Juha Parhankangas
95 % Copyright (c) 2000 by the Johan Himberg and Juha Parhankangas
96 % http://www.cis.hut.fi/projects/somtoolbox/
97
98 % Check arguments
99
100 error(nargchk(1,Inf,nargin)); % Check no. of input arguments
101
102 %% Init input argument struct (see subfunction)
103 Traj=iniTraj(bmus);
104
105 % Check tentative BMU input validity
106
107 if ~vis_valuetype(bmus,{'nxm'}),
108 error(['First input should be a vector of BMU indices or' ...
109 ' a "response matrix"']);
110 end
111
112 %% Check optional arguments
113 for i=1:2:length(varargin)
114 identifier=lower(varargin{i});
115 value=varargin{i+1};
116
117 % Trajectory color
118 switch identifier
119 case 'color'
120 if isempty(value)
121 value='xor';
122 end
123 if vis_valuetype(value,{'colorstyle','xor'})
124 Traj.color=value;
125 else
126 error('''Color'' has to be ColorSpec or string ''xor''.');
127 end
128
129 % 1st data
130 case 'data1'
131 if isempty(value),
132 value=[];
133 elseif vis_valuetype(value,{'nxm'})
134 Traj.primary_data=value;
135 elseif isstruct(value) & isfield(value,'type') & ...
136 ischar(value.type) & strcmp(value.type,'som_data'),
137 Traj.primary_data=value.data;
138 if isempty(Traj.primary_names),
139 Traj.primary_names=value.comp_names;
140 end
141 end
142
143 % 2nd data
144 case 'data2'
145 if isempty(value),
146 value=[];
147 elseif vis_valuetype(value,{'nxm'})
148 Traj.secondary_data=value;
149 elseif isstruct(value) & isfield(value,'type') & ...
150 ischar(value.type) & strcmp(value.type,'som_data'),
151 Traj.secondary_data=value.data;
152 if isempty(Traj.secondary_names),
153 Traj.secondary_names=value.comp_names;
154 end
155 end
156
157 % Trajectory length & size
158 case 'trajsize'
159 if isempty(value),
160 Traj.size=[16 12 10 8 6 4]';
161 end
162 if vis_valuetype(value,{'nx1'})
163 Traj.size=value
164 else
165 error('''TrajSize'' has to be a nx1 vector.');
166 end
167
168 % Names for first data variables
169 case 'name1'
170 if isempty(value),
171 Traj.primary_names=[];
172 elseif ~vis_valuetype(value,{'cellcolumn_of_char'}),
173 error('''Name1'': variable names must be in a cell column array.')
174 else
175 Traj.primary_names = value;
176 end
177 % Names for 2nd data variables
178 case 'name2'
179 if isempty(value),
180 Traj.secondary_names=[];
181 elseif ~vis_valuetype(value,{'cellcolumn_of_char'}),
182 error('''Name2'': variable names must be in a cell column array.')
183 else
184 Traj.secondary_names = value;
185 end
186
187 % Figure number
188 case 'figure'
189 if isempty(value)
190 Traj.figure='gcf';
191 end
192 if vis_valuetype(value,{'1x1'})
193 Traj.figure=value;
194 else
195 error('''Figure'' should be number of an existing figure.')
196 end
197 end
198 end
199
200 %% Get SOM data from figure
201 [h,msg,lattice,msize,dim]=vis_som_show_data('all',Traj.figure);
202
203 %% Not a SOM_SHOW figure?
204 if ~isempty(msg);
205 error('Figure is invalid: use SOM_SHOW to draw the figure.');
206 end
207
208 % Get map size from figure data
209 Traj.lattice=lattice;
210 Traj.msize=msize;
211 if length(msize)>2,
212 error(['This function works only with 2D maps: figure contains' ...
213 ' something else.']);
214 end
215 munits=prod(msize);
216
217 % Check BMU (or response) and map match
218
219 if vis_valuetype(bmus,{'nx1'});
220 if max(bmus)>prod(msize) | min(bmus) <1
221 error('BMU indexes out of range.')
222 elseif any(round(bmus)~=bmus)
223 error('BMU indexes must be integer.');
224 elseif isempty(Traj.primary_data),
225 Traj.primary_data=bmus;
226 end
227 elseif size(bmus,1) ~= munits
228 error(['Response matrix column number must match with the number of' ...
229 ' map units.']);
230 else
231 bmus=bmus';
232 if isempty(Traj.primary_data),
233 Traj.primary_data=[1:size(bmus,1)]';
234 Traj.primary_names={'BMU Index'};
235 end
236 end
237
238 size1=size(Traj.primary_data);
239 size2=size(Traj.secondary_data);
240
241 % Data2 must not be defined alone
242
243 if isempty(Traj.primary_data)&~isempty(Traj.secondary_data),
244 error('If ''Data2'' is specified ''Data1'' must be specified, too.');
245 elseif ~isempty(Traj.secondary_data) ...
246 & size1~= size2
247 % If data1 and data2 exist both, check data1 and data2 match
248 error('''Data1'' and ''Data2'' have different amount of data vectors.')
249 end
250
251 % Check BMU and data1 match (data2 matches with 1 anyway)
252
253 if ~isempty(Traj.primary_data) & size(bmus,1) ~= size1,
254 error(['The number of data vectors in ''data1'' must match with' ...
255 ' the number of rows in the first input argument (bmus).']);
256 end
257
258 % Check that number of names and data dimension is consistent
259
260 if ~isempty(Traj.primary_names) & (size1(2)~=length(Traj.primary_names)),
261 error('Number of component names and ''Data1'' dimension mismatch.');
262 end
263 if ~isempty(Traj.secondary_names) & ...
264 (size2(2)~=length(Traj.secondary_names)),
265 error('Number of component names and ''Data2'' dimension mismatch.');
266 end
267
268 %% Call the function that does the job
269 vis_trajgui(Traj);
270
271 %%% Subfunctions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
273 function Traj=iniTraj(bmus)
274
275 Traj.figure=gcf;
276 Traj.primary_data=[];
277 Traj.secondary_data=[];
278 Traj.primary_names = [];
279 Traj.secondary_names = [];
280 Traj.size=[16 12 10 8 6 4]';
281 Traj.bmus=bmus;
282 Traj.color='xor';
283 Traj.msize=[];
284 Traj.lattice=[];
285