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,269 @@
1
+function flag=vis_valuetype(value, valid, str);
2
+
3
+% VIS_VALUETYPE Used for type checks in SOM Toolbox visualization routines
4
+%
5
+%  flag = vis_valuetype(value, valid, str)
6
+%
7
+%  Input and output arguments:
8
+%   value  (varies) variable to be checked
9
+%   valid  (cell array) size 1xN, cells are strings or vectors (see below)
10
+%   str    (string) 'all' or 'any' (default), determines whether
11
+%                   all or just any of the types listed in argument 'valid' 
12
+%                   should be true for 'value'
13
+%
14
+%   flag   (scalar) 1 or 0 (true or false) 
15
+%
16
+% This is an internal function of SOM Toolbox visualization.  It makes
17
+% various type checks. For example:
18
+%
19
+%  % Return 1 if X is a numeric scalar otherwise 0:
20
+%  f=vis_valuetype(X,{'1x1'});
21
+%
22
+%  % Return 1 if X is a ColorSpec, that is, a 1x3 vector presenting an RGB
23
+%  % value or any of strings 'red','blue','green','yellow','magenta','cyan',
24
+%  % 'white' or 'black' or their shortenings  'r','g','b','y','m','c','w','k': 
25
+%  f=vis_valueype(X,{'1x3rgb','colorstyle'})
26
+%
27
+%  % Return 1 if X is _both_ 10x3 size numeric matrix and has RGB values as rows
28
+%  f=vis_valuetype(X,{'nx3rgb',[10 3]},'all')
29
+%
30
+% Strings that may be used in argument valid: 
31
+%  id             is true if value is 
32
+% 
33
+%  [n1 n2 ... nn] any n1 x n2 x ... x nn sized numeric matrix
34
+%  '1x1'          scalar (numeric)
35
+%  '1x2'          1x2 vector (numeric)
36
+%  'nx1'          any nx1 numeric vector
37
+%  'nx2'              nx2
38
+%  'nx3'              nx3
39
+%  'nxn'          any numeric square matrix
40
+%  'nxn[0,1]'     numeric square matrix with values in interval [0,1]
41
+%  'nxm'          any numeric matrix
42
+%  '1xn'          any 1xn numeric vector
43
+%  '1x3rgb'       1x3 vector v for which all(v>=0 & v<=1), e.g., a RGB code
44
+%  'nx3rgb'       nx3 numeric matrix that contains n RGB values as rows
45
+%  'nx3dimrgb'    nx3xdim numeric matrix that contains RGB values
46
+%  'nxnx3rgb'     nxnx3 numeric matrix of nxn RGB triples
47
+%  'none'         string 'none'
48
+%  'xor'          string 'xor'
49
+%  'indexed'      string 'indexed'
50
+%  'colorstyle'   strings 'red','blue','green','yellow','magenta','cyan','white' 
51
+%                 or 'black', or 'r','g','b','y','m','c','w','k'                 
52
+%  'markerstyle'  any of Matlab's marker chars '.','o','x','+','*','s','d','v',
53
+%                 '^','<','>','p'or 'h'
54
+%  'linestyle'    any or Matlab's line style strings '-',':','--', or '-.'
55
+%  'cellcolumn'   a nx1 cell array
56
+%  'topol_cell'   {lattice, msize, shape} 
57
+%  'topol_cell_no_shape' {lattice, msize}
58
+%  'string'       any string (1xn array of char)  
59
+%  'chararray'    any MxN char array
60
+
61
+% Copyright (c) 1999-2000 by the SOM toolbox programming team.
62
+% http://www.cis.hut.fi/projects/somtoolbox/             
63
+
64
+% Version 2.0beta Johan 201099 juuso 280800
65
+
66
+if nargin == 2
67
+  str='any';
68
+end
69
+
70
+flag=0;  
71
+sz=size(value);
72
+dims=ndims(value);
73
+
74
+% isnumeric
75
+numeric=isnumeric(value);
76
+character=ischar(value);
77
+
78
+% main loop: go through all types in arg. 'valid'
79
+for i=1:length(valid),
80
+  if isnumeric(valid{i}), % numeric size for double matrix
81
+    if numeric & length(valid{i}) == dims,
82
+      flag(i)=all(sz == valid{i});
83
+    else
84
+      flag(i)=0; % not numeric or wrong dimension
85
+    end
86
+  else
87
+    msg=''; % for a error message inside try 
88
+    try 
89
+      switch valid{i}
90
+	
91
+	% scalar
92
+       case '1x1'
93
+	flag(i)=numeric & dims == 2 & sz(1)==1 & sz(2) ==1;
94
+	
95
+	% 1x2 numeric vector
96
+       case '1x2'
97
+	flag(i)=numeric & dims == 2 & sz(1)==1 & sz(2) == 2;
98
+	
99
+	% 1xn numeric vector
100
+       case '1xn'
101
+	flag(i)=numeric & dims == 2 & sz(1) == 1;
102
+	
103
+	% any numeric matrix
104
+       case 'nxm' 
105
+	flag(i)=numeric & dims == 2;
106
+	
107
+	% nx3 numeric matrix 
108
+       case 'nx3'
109
+	flag(i)=numeric & dims == 2 & sz(2) == 3;
110
+	
111
+	% nx2 numeric matrix 
112
+       case 'nx2'
113
+	flag(i)=numeric & dims == 2 & sz(2) == 2;
114
+	
115
+	% nx1 numeric vector
116
+       case 'nx1'
117
+	flag(i)=numeric & dims == 2 & sz(2) == 1;
118
+       
119
+	% nx1xm numric matrix
120
+       case 'nx1xm'
121
+	flag(i)=numeric & dims == 3 & sz(2) == 1;
122
+	
123
+	% nx3 matrix of RGB triples
124
+       case 'nx3rgb'  
125
+	flag(i)=numeric & dims == 2 & sz(2) == 3 & in0_1(value);
126
+	
127
+	% RGB triple (ColorSpec vector)
128
+       case '1x3rgb'
129
+	flag(i) = numeric & dims == 2 & sz(1)==1 & sz(2) == 3 & in0_1(value);
130
+	
131
+	% any square matrix
132
+       case 'nxn'
133
+	flag(i)=numeric & dims == 2 & sz(1) == sz(2);
134
+	
135
+	% nx3xdim array of nxdim RGB triples
136
+       case 'nx3xdimrgb'
137
+	flag(i)=numeric & dims == 3 & sz(2) == 3 & in0_1(value);
138
+	
139
+	% nxnx3 array of nxn RGB triples
140
+       case 'nxnx3rgb'
141
+	flag(i)= numeric & dims == 3 & sz(1) == sz(2) & sz(3) == 3 ...
142
+		 & in0_1(value);
143
+	
144
+	% nxn matrix of values between [0,1]
145
+       case 'nxn[0,1]' 
146
+	
147
+	flag(i)=numeric & dims == 2 & sz(1) == sz(2) & in0_1(value);
148
+	
149
+	% string 'indexed'
150
+       case 'indexed'
151
+	flag(i) = ischar(value) & strcmp(value,'indexed');
152
+	
153
+	% string 'none'
154
+       case 'none'
155
+	flag(i) = character & strcmp(value,'none');
156
+      
157
+	% string 'xor'
158
+       case 'xor'
159
+	flag(i) = character & strcmp(value,'xor');
160
+	
161
+	% any string (1xn char array)
162
+       case 'string'
163
+	flag(i) = character & dims == 2 & sz(1)<=1;
164
+	
165
+	% any char array
166
+       case 'chararray'
167
+	flag(i) = character & dims == 2 & sz(1)>0;
168
+	
169
+	% ColorSpec string
170
+       case 'colorstyle'
171
+	flag(i)=(character &  sz(1) == 1 & sz(2) == 1 & ...
172
+		 any(ismember('ymcrgbwk',value))) | ...
173
+	(ischar(value) & any(strcmp(value,{'none','yellow','magenta',...
174
+		    'cyan','red','green','blue','white','black'})));
175
+	
176
+	% any valid Matlab's Marker
177
+       case 'markerstyle'
178
+	flag(i)=character &  sz(1) == 1 & sz(2) == 1 & ...
179
+		any(ismember('.ox+*sdv^<>ph',value));
180
+	
181
+	% any valid Matlab's LineStyle
182
+       case 'linestyle'
183
+	str=strrep(strrep(strrep(value,'z','1'),'--','z'),'-.','z');
184
+	flag(i)=character & any(ismember(str,'z-:')) & sz(1)==1 & (sz(2)==1 | sz(2)==2);
185
+	
186
+	% any struct
187
+       case 'struct'
188
+	flag(i)=isstruct(value);
189
+	
190
+	% nx1 cell array of strings
191
+       case 'cellcolumn_of_char'
192
+	flag(i)=iscell(value) & dims == 2 & sz(2)==1;  
193
+	try, char(value); catch, flag(i)=0; end
194
+	
195
+	% mxn cell array of strings
196
+       case '2Dcellarray_of_char'  
197
+	flag(i)=iscell(value) & dims == 2; 
198
+	try, char(cat(2,value{:})); catch, flag(i)=0; end
199
+	
200
+	% valid {lattice, msize} 
201
+       case 'topol_cell_no_shape'
202
+	flag(i)=1;
203
+	if ~iscell(value) | length(size(value)) ~= 2 | size(value,2)~=2
204
+	  flag(i)=0;
205
+	else
206
+	  if vis_valuetype(value{1},{'string'}),
207
+	    switch value{1}
208
+	     case { 'hexa','rect'}
209
+	      ;
210
+	     otherwise
211
+	      flag(i)=0;
212
+	    end
213
+	  end
214
+	  if ~vis_valuetype(value{2},{'1xn'}),
215
+	    flag(i)=0;
216
+	  end
217
+	end
218
+	
219
+	% valid {lattice, msize, shape} 
220
+       case 'topol_cell'
221
+	flag(i)=1;
222
+	if ~iscell(value) | length(size(value)) ~= 2 | size(value,2) ~= 3,
223
+	  flag(i)=0;
224
+	else
225
+	  if vis_valuetype(value{1},{'string'}),
226
+	    switch value{1}
227
+	     case { 'hexa','rect'}
228
+	      ;
229
+	     otherwise
230
+	      flag(i)=0;
231
+	    end
232
+	  end
233
+	  if ~vis_valuetype(value{2},{'1xn'})
234
+	    flag(i)=0;
235
+	  end
236
+	  if ~vis_valuetype(value{3},{'string'})
237
+	    flag(i)=0;
238
+	  else
239
+	    switch value{3}
240
+	     case { 'sheet','cyl', 'toroid'}
241
+	      ;
242
+	     otherwise
243
+	      flag(i)=0;
244
+	    end
245
+	  end
246
+	end
247
+       otherwise
248
+	msg='Unknown valuetype!';
249
+      end
250
+    catch 
251
+      % error during type check is due to wrong type of value: 
252
+      % lets set flag(i) to 0
253
+      flag(i)=0; 
254
+    end
255
+    % Unknown indetifier?
256
+    error(msg);
257
+  end
258
+  % set flag according to 3rd parameter (all ~ AND, any ~ OR) 
259
+  if strcmp(str,'all');
260
+    flag=all(flag);
261
+  else
262
+    flag=any(flag);
263
+  end
264
+end
265
+
266
+
267
+function f=in0_1(value)
268
+
269
+f=all(value(:) >= 0 & value(:)<=1);
0 270
\ No newline at end of file