Browse code

starting som prediction fine-tuned class-performance visualisation

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@112 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on21/01/2009 16:34:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,46 @@
1
+function Ne = som_neighbors(sM,neigh)
2
+
3
+% Ne = som_neighbors(sM,neigh)
4
+%
5
+% sM      (struct) map or data struct
6
+%         (matrix) data matrix, size n x dim
7
+% [neigh] (string) 'kNN' or 'Nk' (which is valid for a SOM only)
8
+%                  for example '6NN' or 'N1'
9
+%                  default is '10NN' for a data set and 'N1' for SOM
10
+%
11
+% Ne      (matrix) size n x n, a sparse matrix
12
+%                  indicating the neighbors of each sample by value 1 
13
+%                  (note: the unit itself also has value 0)
14
+
15
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
+
17
+if isstruct(sM), 
18
+  switch sM.type, 
19
+   case 'som_map',  M = sM.codebook; 
20
+   case 'som_data', M = sM.data; sM = []; 
21
+  end
22
+else
23
+  M = sM; 
24
+  sM = []; 
25
+end
26
+
27
+n = size(M,1);
28
+
29
+if nargin<2, 
30
+  if isempty(sM), neigh = '10NN'; else neigh = 'N1'; end
31
+end
32
+
33
+if strcmp(neigh(end-1:end),'NN'),
34
+  k  = str2num(neigh(1:end-2));
35
+  kmus = som_bmus(M,M,1:k+1);
36
+  Ne = sparse(n,n);
37
+  for i=1:n, Ne(i,kmus(i,:)) = 1; end
38
+else
39
+  if ~isstruct(sM), error('Prototypes must be in a map struct.'); end      
40
+  k  = str2num(neigh(2:end));
41
+  N1 = som_unit_neighs(sM);    
42
+  Ne = sparse(som_neighborhood(N1,k)<=k);
43
+end
44
+Ne([0:n-1]*n+[1:n]) = 0; % remove self from neighbors
45
+
46
+return;
0 47
\ No newline at end of file