forked from ilarinieminen/SOM-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsom_projections_plot.m
More file actions
76 lines (69 loc) · 2.52 KB
/
som_projections_plot.m
File metadata and controls
76 lines (69 loc) · 2.52 KB
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
function som_projections_plot(pmode,varargin)
% SOM_PROJECTIONS_PLOT Projection visualizations.
%
% som_projections_plot(pmode,varargin)
%
% [cPCAarg, Pdata, Pproto] = som_projections(D,sM);
% som_projections_plot('scatter',Pdata(:,1:3))
% som_projections_plot('scatter',Pproto(:,1:3),Pproto(:,5:7),5,sM)
% som_projections_plot('residuals',Pdata(:,1:4))
% som_projections_plot('scree',cPCAarg{3})
%
% The other arguments depend on the pmode:
%
% pmode = 'scatter'
%
% arg1: Co (matrix) coordinates
% arg2: color (matrix) color vectors
% (string) colorstring ('k' by default)
% arg3: psize (scalar) point size
% arg4: sT (struct) topology struct, if map grid is drawn
%
% pmode = 'residuals'
%
% arg1: Co (matrix) coordinates (2 first columns) + residuals (the rest)
% arg2: color (string) colorstring ('k' by default)
%
% pmode = 'scree'
%
% arg1: eigval (vector) vector of eigenvalues
%
% See also SOM_PROJECTIONS.
switch pmode,
case 'scatter',
Co = varargin{1};
if length(varargin)>1, color = varargin{2}; else color = 'k'; end
if length(varargin)>2, psize = varargin{3}; else psize = 5; end
if length(varargin)>3, sT = varargin{4}; else sT = []; end
if isstruct(sT) && strcmp(sT.type,'som_map'), sT = sT.topol; end
if isempty(sT),
som_grid({'rect',[size(Co,1) 1]},'Coord',Co,'Markercolor',color,'line','none','markersize',psize);
else
if ischar(color), lcolor = color; else lcolor = 'k'; end
som_grid(sT,'Coord',Co,'Markercolor',color,'markersize',psize,'linecolor',lcolor);
end
case 'residuals',
CoRes = varargin{1};
n = size(CoRes,1);
if length(varargin)>1, color = varargin{2}; else color = 'k'; end
Co = CoRes(:,1:2); Co(end+1,:) = NaN;
res = sqrt(sum(CoRes(:,3:end).*CoRes(:,3:end),2));
h=plot(Co(:,1),Co(:,2),'k.'); set(h,'color',color);
Co(end+1,:) = NaN;
res = [res; 0; NaN];
i = [1:n; 1:n; (n+1)+zeros(1,n)]; i = i(:);
j = [(n+1)+zeros(1,n); 1:n; (n+2)+zeros(1,n)]; j = j(:);
h = line(Co(i,1),Co(i,2),res(j)); set(h,'color',color);
axis tight, axis equal, view(3)
case 'scree',
eigval = varargin{1};
if size(eigval,1)>1, eigval = eigval'; end
eigval = eigval / sum(eigval);
cumeig = cumsum(eigval);
bar(cumeig,0.1)
i = find(cumeig>=0.75); i75 = i(1);
hold on
plot([0 2],cumeig([2 2]),'r-',[0 i75],cumeig([i75 i75]),'r-');
set(gca,'YTick',unique([0:0.1:1 cumeig(2) cumeig(i75)]));
axis tight, grid on
end