comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_demo3.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
2 %SOM_DEMO3 Self-organizing map visualization.
3
4 % Contributed to SOM Toolbox 2.0, February 11th, 2000 by Juha Vesanto
5 % http://www.cis.hut.fi/projects/somtoolbox/
6
7 % Version 1.0beta juuso 071197
8 % Version 2.0beta juuso 080200 070600
9
10 clf reset;
11 figure(gcf)
12 echo on
13
14
15
16
17 clc
18 % ==========================================================
19 % SOM_DEMO3 - VISUALIZATION
20 % ==========================================================
21
22 % som_show - Visualize map.
23 % som_grid - Visualization with free coordinates.
24 %
25 % som_show_add - Add markers on som_show visualization.
26 % som_show_clear - Remove markers from som_show visualization.
27 % som_recolorbar - Refresh and rescale colorbars in som_show
28 % visualization.
29 %
30 % som_cplane - Visualize component/color/U-matrix plane.
31 % som_pieplane - Visualize prototype vectors as pie charts.
32 % som_barplane - Visualize prototype vectors as bar charts.
33 % som_plotplane - Visualize prototype vectors as line graphs.
34 %
35 % pcaproj - Projection to principal component space.
36 % cca - Projection with Curvilinear Component Analysis.
37 % sammon - Projection with Sammon's mapping.
38 % som_umat - Calculate U-matrix.
39 % som_colorcode - Color coding for the map.
40 % som_normcolor - RGB values of indexed colors.
41 % som_hits - Hit histograms for the map.
42
43 % The basic functions for SOM visualization are SOM_SHOW and
44 % SOM_GRID. The SOM_SHOW has three auxiliary functions:
45 % SOM_SHOW_ADD, SOM_SHOW_CLEAR and SOM_RECOLORBAR which are used
46 % to add and remove markers and to control the colorbars.
47 % SOM_SHOW actually uses SOM_CPLANE to make the visualizations.
48 % Also SOM_{PIE,BAR,PLOT}PLANE can be used to visualize SOMs.
49
50 % The other functions listed above do not themselves visualize
51 % anything, but their results are used in the visualizations.
52
53 % There's an important limitation that visualization functions have:
54 % while the SOM Toolbox otherwise supports N-dimensional map grids,
55 % visualization only works for 1- and 2-dimensional map grids!!!
56
57 pause % Strike any key to create demo data and map...
58
59
60
61
62
63 clc
64 % DEMO DATA AND MAP
65 % =================
66
67 % The data set contructed for this demo consists of random vectors
68 % in three gaussian kernels the centers of which are at [0, 0, 0],
69 % [3 3 3] and [9 0 0]. The map is trained using default parameters.
70
71 D1 = randn(100,3);
72 D2 = randn(100,3) + 3;
73 D3 = randn(100,3); D3(:,1) = D3(:,1) + 9;
74
75 sD = som_data_struct([D1; D2; D3],'name','Demo3 data',...
76 'comp_names',{'X-coord','Y-coord','Z-coord'});
77 sM = som_make(sD);
78
79 % Since the data (and thus the prototypes of the map) are
80 % 3-dimensional, they can be directly plotted using PLOT3.
81 % Below, the data is plotted using red 'o's and the map
82 % prototype vectors with black '+'s.
83
84 plot3(sD.data(:,1),sD.data(:,2),sD.data(:,3),'ro',...
85 sM.codebook(:,1),sM.codebook(:,2),sM.codebook(:,3),'k+')
86 rotate3d on
87
88 % From the visualization it is pretty easy to see what the data is
89 % like, and how the prototypes have been positioned. One can see
90 % that there are three clusters, and that there are some prototype
91 % vectors between the clusters, although there is actually no
92 % data there. The map units corresponding to these prototypes
93 % are called 'dead' or 'interpolative' map units.
94
95 pause % Strike any key to continue...
96
97
98
99 clc
100 % VISUALIZATION OF MULTIDIMENSIONAL DATA
101 % ======================================
102
103 % Usually visualization of data sets is not this straightforward,
104 % since the dimensionality is much higher than three. In principle,
105 % one can embed additional information to the visualization by
106 % using properties other than position, for example color, size or
107 % shape.
108
109 % Here the data set and map prototypes are plotted again, but
110 % information of the cluster is shown using color: red for the
111 % first cluster, green for the second and blue for the last.
112
113 plot3(sD.data(1:100,1),sD.data(1:100,2),sD.data(1:100,3),'ro',...
114 sD.data(101:200,1),sD.data(101:200,2),sD.data(101:200,3),'go',...
115 sD.data(201:300,1),sD.data(201:300,2),sD.data(201:300,3),'bo',...
116 sM.codebook(:,1),sM.codebook(:,2),sM.codebook(:,3),'k+')
117 rotate3d on
118
119 % However, this works only for relatively small dimensionality, say
120 % less than 10. When the information is added this way, the
121 % visualization becomes harder and harder to understand. Also, not
122 % all properties are equal: the human visual system perceives
123 % colors differently from position, not to mention the complex
124 % rules governing perception of shape.
125
126 pause % Strike any key to learn about linking...
127
128
129
130
131
132 clc
133 % LINKING MULTIPLE VISUALIZATIONS
134 % ===============================
135
136 % The other option is to use *multiple visualizations*, so called
137 % small multiples, instead of only one. The problem is then how to
138 % link these visualizations together: one should be able to idetify
139 % the same object from the different visualizations.
140
141 % This could be done using, for example, color: each object has
142 % the same color in each visualization. Another option is to use
143 % similar position: each object has the same position in each
144 % small multiple.
145
146 % For example, here are four subplots, one for each component and
147 % one for cluster information, where color denotes the value and
148 % position is used for linking. The 2D-position is derived by
149 % projecting the data into the space spanned by its two greatest
150 % eigenvectors.
151
152 [Pd,V,me] = pcaproj(sD.data,2); % project the data
153 Pm = pcaproj(sM.codebook,V,me); % project the prototypes
154 colormap(hot); % colormap used for values
155
156 echo off
157 for c=1:3,
158 subplot(2,2,c), cla, hold on
159 som_grid('rect',[300 1],'coord',Pd,'Line','none',...
160 'MarkerColor',som_normcolor(sD.data(:,c)));
161 som_grid(sM,'Coord',Pm,'Line','none','marker','+');
162 hold off, title(sD.comp_names{c}), xlabel('PC 1'), ylabel('PC 2');
163 end
164
165 subplot(2,2,4), cla
166 plot(Pd(1:100,1),Pd(1:100,2),'ro',...
167 Pd(101:200,1),Pd(101:200,2),'go',...
168 Pd(201:300,1),Pd(201:300,2),'bo',...
169 Pm(:,1),Pm(:,2),'k+')
170 title('Cluster')
171 echo on
172
173 pause % Strike any key to use color for linking...
174
175 % Here is another example, where color is used for linking. On the
176 % top right triangle are the scatter plots of each variable without
177 % color coding, and on the bottom left triangle with the color
178 % coding. In the colored figures, each data sample can be
179 % identified by a unique color. Well, almost identified: there are
180 % quite a lot of samples with almost the same color. Color is not as
181 % precise linking method as position.
182
183 echo off
184 Col = som_normcolor([1:300]',jet(300));
185 k=1;
186 for i=1:3,
187 for j=1:3,
188 if i<j, i1=i; i2=j; else i1=j; i2=i; end
189 if i<j,
190 subplot(3,3,k); cla
191 plot(sD.data(:,i1),sD.data(:,i2),'ko')
192 xlabel(sD.comp_names{i1}), ylabel(sD.comp_names{i2})
193 elseif i>j,
194 subplot(3,3,k); cla
195 som_grid('rect',[300 1],'coord',sD.data(:,[i1 i2]),...
196 'Line','none','MarkerColor',Col);
197 xlabel(sD.comp_names{i1}), ylabel(sD.comp_names{i2})
198 end
199 k=k+1;
200 end
201 end
202 echo on
203
204 pause % Strike any key to learn about data visualization using SOM...
205
206
207 clc
208 % DATA VISUALIZATION USING SOM
209 % ============================
210
211 % The basic visualization functions and their usage have already
212 % been introduced in SOM_DEMO2. In this demo, a more structured
213 % presentation is given.
214
215 % Data visualization techniques using the SOM can be divided to
216 % three categories based on their goal:
217
218 % 1. visualization of clusters and shape of the data:
219 % projections, U-matrices and other distance matrices
220 %
221 % 2. visualization of components / variables:
222 % component planes, scatter plots
223 %
224 % 3. visualization of data projections:
225 % hit histograms, response surfaces
226
227 pause % Strike any key to visualize clusters with distance matrices...
228
229
230
231 clf
232 clc
233 % 1. VISUALIZATION OF CLUSTERS: DISTANCE MATRICES
234 % ===============================================
235
236 % Distance matrices are typically used to show the cluster
237 % structure of the SOM. They show distances between neighboring
238 % units, and are thus closely related to single linkage clustering
239 % techniques. The most widely used distance matrix technique is
240 % the U-matrix.
241
242 % Here, the U-matrix of the map is shown (using all three
243 % components in the distance calculation):
244
245 colormap(1-gray)
246 som_show(sM,'umat','all');
247
248 pause % Strike any key to see more examples of distance matrices...
249
250 % The function SOM_UMAT can be used to calculate U-matrix. The
251 % resulting matrix holds distances between neighboring map units,
252 % as well as the median distance from each map unit to its
253 % neighbors. These median distances corresponding to each map unit
254 % can be easily extracted. The result is a distance matrix using
255 % median distance.
256
257 U = som_umat(sM);
258 Um = U(1:2:size(U,1),1:2:size(U,2));
259
260 % A related technique is to assign colors to the map units such
261 % that similar map units get similar colors.
262
263 % Here, four clustering figures are shown:
264 % - U-matrix
265 % - median distance matrix (with grayscale)
266 % - median distance matrix (with map unit size)
267 % - similarity coloring, made by spreading a colormap
268 % on top of the principal component projection of the
269 % prototype vectors
270
271 subplot(2,2,1)
272 h=som_cplane([sM.topol.lattice,'U'],sM.topol.msize, U(:));
273 set(h,'Edgecolor','none'); title('U-matrix')
274
275 subplot(2,2,2)
276 h=som_cplane(sM, Um(:));
277 set(h,'Edgecolor','none'); title('D-matrix (grayscale)')
278
279 subplot(2,2,3)
280 som_cplane(sM,'none',1-Um(:)/max(Um(:)))
281 title('D-matrix (marker size)')
282
283 subplot(2,2,4)
284 C = som_colorcode(Pm); % Pm is the PC-projection calculated earlier
285 som_cplane(sM,C)
286 title('Similarity coloring')
287
288 pause % Strike any key to visualize shape and clusters with projections...
289
290
291
292 clf
293 clc
294 % 1. VISUALIZATION OF CLUSTERS AND SHAPE: PROJECTIONS
295 % ===================================================
296
297 % In vector projection, a set of high-dimensional data samples is
298 % projected to a lower dimensional such that the distances between
299 % data sample pairs are preserved as well as possible. Depending
300 % on the technique, the projection may be either linear or
301 % non-linear, and it may place special emphasis on preserving
302 % local distances.
303
304 % For example SOM is a projection technique, since the prototypes
305 % have well-defined positions on the 2-dimensional map grid. SOM as
306 % a projection is however a very crude one. Other projection
307 % techniques include the principal component projection used
308 % earlier, Sammon's mapping and Curvilinear Component Analysis
309 % (to name a few). These have been implemented in functions
310 % PCAPROJ, SAMMON and CCA.
311
312 % Projecting the map prototype vectors and joining neighboring map
313 % units with lines gives the SOM its characteristic net-like look.
314 % The projection figures can be linked to the map planes using
315 % color coding.
316
317 % Here is the distance matrix, color coding, a projection without
318 % coloring and a projection with one. In the last projection,
319 % the size of interpolating map units has been set to zero.
320
321 subplot(2,2,1)
322 som_cplane(sM,Um(:));
323 title('Distance matrix')
324
325 subplot(2,2,2)
326 C = som_colorcode(sM,'rgb4');
327 som_cplane(sM,C);
328 title('Color code')
329
330 subplot(2,2,3)
331 som_grid(sM,'Coord',Pm,'Linecolor','k');
332 title('PC-projection')
333
334 subplot(2,2,4)
335 h = som_hits(sM,sD); s=6*(h>0);
336 som_grid(sM,'Coord',Pm,'MarkerColor',C,'Linecolor','k','MarkerSize',s);
337 title('Colored PC-projection')
338
339 pause % Strike any key to visualize component planes...
340
341
342 clf
343 clc
344 % 2. VISUALIZATION OF COMPONENTS: COMPONENT PLANES
345 % ================================================
346
347 % The component planes visualizations shows what kind of values the
348 % prototype vectors of the map units have for different vector
349 % components.
350
351 % Here is the U-matrix and the three component planes of the map.
352
353 som_show(sM)
354
355 pause % Strike any key to continue...
356
357 % Besides SOM_SHOW and SOM_CPLANE, there are three other
358 % functions specifically designed for showing the values of the
359 % component planes: SOM_PIEPLANE, SOM_BARPLANE, SOM_PLOTPLANE.
360
361 % SOM_PIEPLANE shows a single pie chart for each map unit. Each
362 % pie shows the relative proportion of each component of the sum of
363 % all components in that map unit. The component values must be
364 % positive.
365
366 % SOM_BARPLANE shows a barchart in each map unit. The scaling of
367 % bars can be made unit-wise or variable-wise. By default it is
368 % determined variable-wise.
369
370 % SOM_PLOTPLANE shows a linegraph in each map unit.
371
372 M = som_normalize(sM.codebook,'range');
373
374 subplot(1,3,1)
375 som_pieplane(sM, M);
376 title('som\_pieplane')
377
378 subplot(1,3,2)
379 som_barplane(sM, M, '', 'unitwise');
380 title('som\_barplane')
381
382 subplot(1,3,3)
383 som_plotplane(sM, M, 'b');
384 title('som\_plotplane')
385
386 pause % Strike any key to visualize cluster properties...
387
388
389
390 clf
391 clc
392 % 2. VISUALIZATION OF COMPONENTS: CLUSTERS
393 % ========================================
394
395 % An interesting question is of course how do the values of the
396 % variables relate to the clusters: what are the values of the
397 % components in the clusters, and which components are the ones
398 % which *make* the clusters.
399
400 som_show(sM)
401
402 % From the U-matrix and component planes, one can easily see
403 % what the typical values are in each cluster.
404
405 pause % Strike any key to continue...
406
407 % The significance of the components with respect to the clustering
408 % is harder to visualize. One indication of importance is that on
409 % the borders of the clusters, values of important variables change
410 % very rabidly.
411
412 % Here, the distance matrix is calculated with respect to each
413 % variable.
414
415 u1 = som_umat(sM,'mask',[1 0 0]'); u1=u1(1:2:size(u1,1),1:2:size(u1,2));
416 u2 = som_umat(sM,'mask',[0 1 0]'); u2=u2(1:2:size(u2,1),1:2:size(u2,2));
417 u3 = som_umat(sM,'mask',[0 0 1]'); u3=u3(1:2:size(u3,1),1:2:size(u3,2));
418
419 % Here, the distance matrices are shown, as well as a piechart
420 % indicating the relative importance of each variable in each
421 % map unit. The size of piecharts has been scaled by the
422 % distance matrix calculated from all components.
423
424 subplot(2,2,1)
425 som_cplane(sM,u1(:));
426 title(sM.comp_names{1})
427
428 subplot(2,2,2)
429 som_cplane(sM,u2(:));
430 title(sM.comp_names{2})
431
432 subplot(2,2,3)
433 som_cplane(sM,u3(:));
434 title(sM.comp_names{3})
435
436 subplot(2,2,4)
437 som_pieplane(sM, [u1(:), u2(:), u3(:)], hsv(3), Um(:)/max(Um(:)));
438 title('Relative importance')
439
440 % From the last subplot, one can see that in the area where the
441 % bigger cluster border is, the 'X-coord' component (red color)
442 % has biggest effect, and thus is the main factor in separating
443 % that cluster from the rest.
444
445 pause % Strike any key to learn about correlation hunting...
446
447
448 clf
449 clc
450 % 2. VISUALIZATION OF COMPONENTS: CORRELATION HUNTING
451 % ===================================================
452
453 % Finally, the component planes are often used for correlation
454 % hunting. When the number of variables is high, the component
455 % plane visualization offers a convenient way to visualize all
456 % components at once and hunt for correlations (as opposed to
457 % N*(N-1)/2 scatterplots).
458
459 % Hunting correlations this way is not very accurate. However, it
460 % is easy to select interesting combinations for further
461 % investigation.
462
463 % Here, the first and third components are shown with scatter
464 % plot. As with projections, a color coding is used to link the
465 % visualization to the map plane. In the color coding, size shows
466 % the distance matrix information.
467
468 C = som_colorcode(sM);
469 subplot(1,2,1)
470 som_cplane(sM,C,1-Um(:)/max(Um(:)));
471 title('Color coding + distance matrix')
472
473 subplot(1,2,2)
474 som_grid(sM,'Coord',sM.codebook(:,[1 3]),'MarkerColor',C);
475 title('Scatter plot'); xlabel(sM.comp_names{1}); ylabel(sM.comp_names{3})
476 axis equal
477
478 pause % Strike any key to visualize data responses...
479
480
481 clf
482 clc
483 % 3. DATA ON MAP
484 % ==============
485
486 % The SOM is a map of the data manifold. An interesting question
487 % then is where on the map a specific data sample is located, and
488 % how accurate is that localization? One is interested in the
489 % response of the map to the data sample.
490
491 % The simplest answer is to find the BMU of the data sample.
492 % However, this gives no indication of the accuracy of the
493 % match. Is the data sample close to the BMU, or is it actually
494 % equally close to the neighboring map units (or even approximately
495 % as close to all map units)? Sometimes accuracy doesn't really
496 % matter, but if it does, it should be visualized somehow.
497
498 % Here are different kinds of response visualizations for two
499 % vectors: [0 0 0] and [99 99 99].
500 % - BMUs indicated with labels
501 % - BMUs indicated with markers, relative quantization errors
502 % (in this case, proportion between distances to BMU and
503 % Worst-MU) with vertical lines
504 % - quantization error between the samples and all map units
505 % - fuzzy response (a non-linear function of quantization
506 % error) of all map units
507
508 echo off
509 [bm,qe] = som_bmus(sM,[0 0 0; 99 99 99],'all'); % distance to all map units
510 [dummy,ind] = sort(bm(1,:)); d0 = qe(1,ind)';
511 [dummy,ind] = sort(bm(2,:)); d9 = qe(2,ind)';
512 bmu0 = bm(1,1); bmu9 = bm(2,1); % bmus
513
514 h0 = zeros(prod(sM.topol.msize),1); h0(bmu0) = 1; % crisp hits
515 h9 = zeros(prod(sM.topol.msize),1); h9(bmu9) = 1;
516
517 lab = cell(prod(sM.topol.msize),1);
518 lab{bmu0} = '[0,0,0]'; lab{bmu9} = '[99,99,99]';
519
520 hf0 = som_hits(sM,[0 0 0],'fuzzy'); % fuzzy response
521 hf9 = som_hits(sM,[99 99 99],'fuzzy');
522
523 som_show(sM,'umat',{'all','BMU'},...
524 'color',{d0,'Qerror 0'},'color',{hf0,'Fuzzy response 0'},...
525 'empty','BMU+qerror',...
526 'color',{d9,'Qerror 99'},'color',{hf9,'Fuzzy response 99'});
527 som_show_add('label',lab,'Subplot',1,'Textcolor','r');
528 som_show_add('hit',[h0, h9],'Subplot',4,'MarkerColor','r');
529 hold on
530 Co = som_vis_coords(sM.topol.lattice,sM.topol.msize);
531 plot3(Co(bmu0,[1 1]),Co(bmu0,[2 2]),[0 10*qe(1,1)/qe(1,end)],'r-')
532 plot3(Co(bmu9,[1 1]),Co(bmu9,[2 2]),[0 10*qe(2,1)/qe(2,end)],'r-')
533 view(3), axis equal
534 echo on
535
536 % Here are the distances to BMU, 2-BMU and WMU:
537
538 qe(1,[1,2,end]) % [0 0 0]
539 qe(2,[1,2,end]) % [99 99 99]
540
541 % One can see that for [0 0 0] the accuracy is pretty good as the
542 % quantization error of the BMU is much lower than that of the
543 % WMU. On the other hand [99 99 99] is very far from the map:
544 % distance to BMU is almost equal to distance to WMU.
545
546 pause % Strike any key to visualize responses of multiple samples...
547
548
549
550 clc
551 clf
552 % 3. DATA ON MAP: HIT HISTOGRAMS
553 % ==============================
554
555 % One can also investigate whole data sets using the map. When the
556 % BMUs of multiple data samples are aggregated, a hit histogram
557 % results. Instead of BMUs, one can also aggregate for example
558 % fuzzy responses.
559
560 % The hit histograms (or aggregated responses) can then be compared
561 % with each other.
562
563 % Here are hit histograms of three data sets: one with 50 first
564 % vectors of the data set, one with 150 samples from the data
565 % set, and one with 50 randomly selected samples. In the last
566 % subplot, the fuzzy response of the first data set.
567
568 dlen = size(sD.data,1);
569 Dsample1 = sD.data(1:50,:); h1 = som_hits(sM,Dsample1);
570 Dsample2 = sD.data(1:150,:); h2 = som_hits(sM,Dsample2);
571 Dsample3 = sD.data(ceil(rand(50,1)*dlen),:); h3 = som_hits(sM,Dsample3);
572 hf = som_hits(sM,Dsample1,'fuzzy');
573
574 som_show(sM,'umat','all','umat','all','umat','all','color',{hf,'Fuzzy'})
575 som_show_add('hit',h1,'Subplot',1,'Markercolor','r')
576 som_show_add('hit',h2,'Subplot',2,'Markercolor','r')
577 som_show_add('hit',h3,'Subplot',3,'Markercolor','r')
578
579 pause % Strike any key to visualize trajectories...
580
581
582
583 clc
584 clf
585 % 3. DATA ON MAP: TRAJECTORIES
586 % ============================
587
588 % A special data mapping technique is trajectory. If the samples
589 % are ordered, forming a time-series for example, their response on
590 % the map can be tracked. The function SOM_SHOW_ADD can be used to
591 % show the trajectories in two different modes: 'traj' and 'comet'.
592
593 % Here, a series of data points is formed which go from [8,0,0]
594 % to [2,2,2]. The trajectory is plotted using the two modes.
595
596 Dtraj = [linspace(9,2,20); linspace(0,2,20); linspace(0,2,20)]';
597 T = som_bmus(sM,Dtraj);
598
599 som_show(sM,'comp',[1 1]);
600 som_show_add('traj',T,'Markercolor','r','TrajColor','r','subplot',1);
601 som_show_add('comet',T,'MarkerColor','r','subplot',2);
602
603 % There's also a function SOM_TRAJECTORY which lauches a GUI
604 % specifically designed for displaying trajectories (in 'comet'
605 % mode).
606
607 pause % Strike any key to learn about color handling...
608
609
610
611
612 clc
613 clf
614 % COLOR HANDLING
615 % ==============
616
617 % Matlab offers flexibility in the colormaps. Using the COLORMAP
618 % function, the colormap may be changed. There are several useful
619 % colormaps readily available, for example 'hot' and 'jet'. The
620 % default number of colors in the colormaps is 64. However, it is
621 % often advantageous to use less colors in the colormap. This way
622 % the components planes visualization become easier to interpret.
623
624 % Here the three component planes are visualized using the 'hot'
625 % colormap and only three colors.
626
627 som_show(sM,'comp',[1 2 3])
628 colormap(hot(3));
629 som_recolorbar
630
631 pause % Press any key to change the colorbar labels...
632
633 % The function SOM_RECOLORBAR can be used to reconfigure
634 % the labels beside the colorbar.
635
636 % Here the colorbar of the first subplot is labeled using labels
637 % 'small', 'medium' and 'big' at values 0, 1 and 2. For the
638 % colorbar of the second subplot, values are calculated for the
639 % borders between colors.
640
641 som_recolorbar(1,{[0 4 9]},'',{{'small','medium','big'}});
642 som_recolorbar(2,'border','');
643
644 pause % Press any key to learn about SOM_NORMCOLOR...
645
646 % Some SOM Toolbox functions do not use indexed colors if the
647 % underlying Matlab function (e.g. PLOT) do not use indexed
648 % colors. SOM_NORMCOLOR is a convenient function to simulate
649 % indexed colors: it calculates fixed RGB colors that
650 % are similar to indexed colors with the specified colormap.
651
652 % Here, two SOM_GRID visualizations are created. One uses the
653 % 'surf' mode to show the component colors in indexed color
654 % mode, and the other uses SOM_NORMALIZE to do the same.
655
656 clf
657 colormap(jet(64))
658 subplot(1,2,1)
659 som_grid(sM,'Surf',sM.codebook(:,3));
660 title('Surf mode')
661
662 subplot(1,2,2)
663 som_grid(sM,'Markercolor',som_normcolor(sM.codebook(:,3)));
664 title('som\_normcolor')
665
666 pause % Press any key to visualize different map shapes...
667
668
669
670 clc
671 clf
672 % DIFFERENT MAP SHAPES
673 % ====================
674
675 % There's no direct way to visualize cylinder or toroid maps. When
676 % visualized, they are treated exactly as if they were sheet
677 % shaped. However, if function SOM_UNIT_COORDS is used to provide
678 % unit coordinates, then SOM_GRID can be used to visualize these
679 % alternative map shapes.
680
681 % Here the grids of the three possible map shapes (sheet, cylinder
682 % and toroid) are visualized. The last subplot shows a component
683 % plane visualization of the toroid map.
684
685 Cor = som_unit_coords(sM.topol.msize,'hexa','sheet');
686 Coc = som_unit_coords(sM.topol.msize,'hexa','cyl');
687 Cot = som_unit_coords(sM.topol.msize,'hexa','toroid');
688
689 subplot(2,2,1)
690 som_grid(sM,'Coord',Cor,'Markersize',3,'Linecolor','k');
691 title('sheet'), view(0,-90), axis tight, axis equal
692
693 subplot(2,2,2)
694 som_grid(sM,'Coord',Coc,'Markersize',3,'Linecolor','k');
695 title('cylinder'), view(5,1), axis tight, axis equal
696
697 subplot(2,2,3)
698 som_grid(sM,'Coord',Cot,'Markersize',3,'Linecolor','k');
699 title('toroid'), view(-100,0), axis tight, axis equal
700
701 subplot(2,2,4)
702 som_grid(sM,'Coord',Cot,'Surf',sM.codebook(:,3));
703 colormap(jet), colorbar
704 title('toroid'), view(-100,0), axis tight, axis equal
705
706 echo off