wolffd@0
|
1 function sMap=sompak_train(sMap,ft,cout,ct,din,dt,rlen,alpha,radius)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOMPAK_TRAIN Call SOM_PAK training program from Matlab.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % sMap=sompak_train(sMap,ft,cout,ct,din,dt,rlen,alpha,radius)
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % ARGUMENTS ([]'s are optional and can be given as empty: [] or '')
|
wolffd@0
|
8 % sMap (struct) map struct
|
wolffd@0
|
9 % (string) filename
|
wolffd@0
|
10 % [ft] (string) 'pak' or 'box'. Argument must be defined, if input file
|
wolffd@0
|
11 % is used.
|
wolffd@0
|
12 % [cout] (string) filename for output SOM, if argument is not defined
|
wolffd@0
|
13 % (i.e. argument is '[]') temporary file '__abcdef' is
|
wolffd@0
|
14 % used in operations and *it_is_removed* after
|
wolffd@0
|
15 % operations!!!
|
wolffd@0
|
16 % [ct] (string) 'pak' or 'box'. Argument must be defined, if output
|
wolffd@0
|
17 % file is used.
|
wolffd@0
|
18 % din (struct) data struct to be used in teaching
|
wolffd@0
|
19 % (matrix) data matrix
|
wolffd@0
|
20 % (string) filename
|
wolffd@0
|
21 % If argument is not a filename or file is .mat -file,
|
wolffd@0
|
22 % temporary file '__din' is used in operations
|
wolffd@0
|
23 % and *it_is_removed* after operations!!!
|
wolffd@0
|
24 % [dt] (string) 'pak' or 'box'. Argument must be defined, if input file
|
wolffd@0
|
25 % is used.
|
wolffd@0
|
26 % rlen (scalar) running length of teaching
|
wolffd@0
|
27 % alpha (float) initial alpha value
|
wolffd@0
|
28 % radius (float) initial radius of neighborhood
|
wolffd@0
|
29 %
|
wolffd@0
|
30 % RETURNS
|
wolffd@0
|
31 % sMap (struct) map struct
|
wolffd@0
|
32 %
|
wolffd@0
|
33 % Calls SOM_PAK training program (vsom) from Matlab. Notice that to
|
wolffd@0
|
34 % use this function, the SOM_PAK programs must be in your search path,
|
wolffd@0
|
35 % or the variable 'SOM_PAKDIR' which is a string containing the
|
wolffd@0
|
36 % program path, must be defined in the workspace. SOM_PAK programs can
|
wolffd@0
|
37 % be found from: http://www.cis.hut.fi/research/som_lvq_pak.shtml
|
wolffd@0
|
38 %
|
wolffd@0
|
39 % See also SOMPAK_TRAIN, SOMPAK_SAMMON, SOMPAK_TRAIN_GUI,
|
wolffd@0
|
40 % SOMPAK_GUI, SOM_SEQTRAIN.
|
wolffd@0
|
41
|
wolffd@0
|
42 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas
|
wolffd@0
|
43 % Copyright (c) by Juha Parhankangas
|
wolffd@0
|
44 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
45
|
wolffd@0
|
46 % Juha Parhankangas 050100
|
wolffd@0
|
47
|
wolffd@0
|
48
|
wolffd@0
|
49 nargchk(9,9,nargin);
|
wolffd@0
|
50
|
wolffd@0
|
51 NO_FILE=0;
|
wolffd@0
|
52 DIN_FILE = 0;
|
wolffd@0
|
53
|
wolffd@0
|
54 if ~isstruct(sMap) & ~isstr(sMap)
|
wolffd@0
|
55 error('Argument ''sMap'' must be a struct or string.');
|
wolffd@0
|
56 end
|
wolffd@0
|
57
|
wolffd@0
|
58 if isstr(sMap)
|
wolffd@0
|
59 if isempty(ft)
|
wolffd@0
|
60 error('Argument ''ft'' must be defined.');
|
wolffd@0
|
61 end
|
wolffd@0
|
62 if strcmp(ft,'pak')
|
wolffd@0
|
63 sMap=som_read_cod(sMap);
|
wolffd@0
|
64 elseif strcmp(ft,'box')
|
wolffd@0
|
65 new_var=diff_varname;
|
wolffd@0
|
66 varnames=evalin('base','who');
|
wolffd@0
|
67 loadname=eval(cat(2,'who(''-file'',''',sMap,''')'));
|
wolffd@0
|
68 if any(strcmp(loadname{1},evalin('base','who')))
|
wolffd@0
|
69 assignin('base',new_var,evalin('base',loadname{1}));
|
wolffd@0
|
70 evalin('base',cat(2,'load(''',sMap,''');'));
|
wolffd@0
|
71 new_var2=diff_varname;
|
wolffd@0
|
72
|
wolffd@0
|
73 assignin('base',new_var2,evalin('base',loadname{1}));
|
wolffd@0
|
74 assignin('base',loadname{1},evalin('base',new_var));
|
wolffd@0
|
75 evalin('base',cat(2,'clear ',new_var));
|
wolffd@0
|
76 sMap=evalin('base',new_var2);
|
wolffd@0
|
77 evalin('base',cat(2,'clear ',new_var2));
|
wolffd@0
|
78 else
|
wolffd@0
|
79 evalin('base',cat(2,'load(''',sMap,''');'));
|
wolffd@0
|
80 sMap=evalin('base',loadname{1});
|
wolffd@0
|
81 evalin('base',cat(2,'clear ',loadname{1}));
|
wolffd@0
|
82 end
|
wolffd@0
|
83
|
wolffd@0
|
84 end
|
wolffd@0
|
85 end
|
wolffd@0
|
86 if ~isstr(cout) & isempty(cout)
|
wolffd@0
|
87 cout = '__abcdef';
|
wolffd@0
|
88 NO_FILE = 1;
|
wolffd@0
|
89 elseif ~isstr(cout) | (isstr(cout) & isempty(cout))
|
wolffd@0
|
90 error('Argument ''cout'' must be a string or ''[]''.');
|
wolffd@0
|
91 end
|
wolffd@0
|
92
|
wolffd@0
|
93 if ~NO_FILE & (isempty(ct) | ~(~isempty(ct) & ...
|
wolffd@0
|
94 (strcmp(ct,'pak') | strcmp(ct,'box'))))
|
wolffd@0
|
95 error('Argument ''ct'' must be string ''pak'' or ''box''.');
|
wolffd@0
|
96 end
|
wolffd@0
|
97
|
wolffd@0
|
98 map_name=sMap.name;
|
wolffd@0
|
99 som_write_cod(sMap,cout);
|
wolffd@0
|
100
|
wolffd@0
|
101 if ~isempty(din)
|
wolffd@0
|
102 som_write_data(din, '__din');
|
wolffd@0
|
103 DIN_FILE = 1;
|
wolffd@0
|
104 din = '__din';
|
wolffd@0
|
105 else
|
wolffd@0
|
106 DIN_FILE=0;
|
wolffd@0
|
107 end
|
wolffd@0
|
108
|
wolffd@0
|
109 if ~DIN_FILE
|
wolffd@0
|
110 if isempty(dt) | ~isstr(dt) | ~(strcmp(dt,'box') | strcmp(dt,'pak'))
|
wolffd@0
|
111 error('Argument ''dt'' must be string ''pak'' or ''box''.');
|
wolffd@0
|
112 end
|
wolffd@0
|
113 if strcmp(dt,'box');
|
wolffd@0
|
114 DIN_FILE = 1;
|
wolffd@0
|
115 din_var=diff_varname;
|
wolffd@0
|
116 varnames=evalin('base','who');
|
wolffd@0
|
117 loadname=eval(cat(2,'who(''-file'',''',din,''')'));
|
wolffd@0
|
118 if any(strcmp(loadname{1},evalin('base','who')))
|
wolffd@0
|
119 assignin('base',din_var,evalin('base',loadname{1}));
|
wolffd@0
|
120 evalin('base',cat(2,'load(''',din,''');'));
|
wolffd@0
|
121 din_var2=diff_varname;
|
wolffd@0
|
122
|
wolffd@0
|
123 assignin('base',new_var2,evalin('base',loadname{1}));
|
wolffd@0
|
124 assignin('base',loadname{1},evalin('base',din_var));
|
wolffd@0
|
125 evalin('base',cat(2,'clear ',din_var));
|
wolffd@0
|
126 din=evalin('base',din_var2);
|
wolffd@0
|
127 else
|
wolffd@0
|
128 evalin('base',cat(2,'load(''',din,''')'));
|
wolffd@0
|
129 din=evalin('base',loadname{1});
|
wolffd@0
|
130 evalin('base',cat(2,'clear ',loadname{1}));
|
wolffd@0
|
131 end
|
wolffd@0
|
132 som_write_data(din,'__din');
|
wolffd@0
|
133 din = '__din';
|
wolffd@0
|
134 end
|
wolffd@0
|
135 end
|
wolffd@0
|
136 if ~is_positive_integer(rlen)
|
wolffd@0
|
137 error('Argument ''rlen'' must be positive integer.');
|
wolffd@0
|
138 end
|
wolffd@0
|
139
|
wolffd@0
|
140 if ~(isreal(alpha) & all(size(alpha)==1))
|
wolffd@0
|
141 error('Argument ''alpha'' must be a floating point number.');
|
wolffd@0
|
142 end
|
wolffd@0
|
143
|
wolffd@0
|
144 if ~(isreal(radius) & all(size(radius)==1) & radius > 0)
|
wolffd@0
|
145 error('Argument ''radius'' must be a positive floating point number.');
|
wolffd@0
|
146 end
|
wolffd@0
|
147
|
wolffd@0
|
148 if any(strcmp('SOM_PAKDIR',evalin('base','who')))
|
wolffd@0
|
149 traincommand=cat(2,evalin('base','SOM_PAKDIR'),'vsom ');
|
wolffd@0
|
150 else
|
wolffd@0
|
151 traincommand='vsom ';
|
wolffd@0
|
152 end
|
wolffd@0
|
153
|
wolffd@0
|
154 str=cat(2,traincommand,sprintf('-cin %s -din %s -cout %s ',cout,din,cout),...
|
wolffd@0
|
155 sprintf(' -rlen %d -alpha %f -radius %f',rlen,alpha,radius));
|
wolffd@0
|
156 if isunix
|
wolffd@0
|
157 unix(str);
|
wolffd@0
|
158 else
|
wolffd@0
|
159 dos(str);
|
wolffd@0
|
160 end
|
wolffd@0
|
161
|
wolffd@0
|
162 sMap=som_read_cod(cout);
|
wolffd@0
|
163 sMap.name=map_name;
|
wolffd@0
|
164
|
wolffd@0
|
165 if ~NO_FILE
|
wolffd@0
|
166 if isunix
|
wolffd@0
|
167 unix(cat(2,'/bin/rm ',cout));
|
wolffd@0
|
168 else
|
wolffd@0
|
169 dos(cat(2,'del ',cout));
|
wolffd@0
|
170 end
|
wolffd@0
|
171 if isempty(ct) | ~isstr(ct) | ~(strcmp(ct,'pak') | strcmp(ct,'box'))
|
wolffd@0
|
172 error('Argument ''ct'' must be string ''pak'' or ''box''.');
|
wolffd@0
|
173 elseif strcmp(ct,'box');
|
wolffd@0
|
174 eval(cat(2,'save ',cout,' sMap'));
|
wolffd@0
|
175 disp(cat(2,'Output written to the file ',sprintf('''%s.mat''.',cout)));
|
wolffd@0
|
176 else
|
wolffd@0
|
177 som_write_cod(sMap,cout);
|
wolffd@0
|
178 end
|
wolffd@0
|
179 else
|
wolffd@0
|
180 if isunix
|
wolffd@0
|
181 unix('/bin/rm __abcdef');
|
wolffd@0
|
182 else
|
wolffd@0
|
183 dos('del __abcdef');
|
wolffd@0
|
184 end
|
wolffd@0
|
185 end
|
wolffd@0
|
186
|
wolffd@0
|
187 if DIN_FILE
|
wolffd@0
|
188 if isunix
|
wolffd@0
|
189 unix('/bin/rm __din');
|
wolffd@0
|
190 else
|
wolffd@0
|
191 dos('del __abcdef');
|
wolffd@0
|
192 end
|
wolffd@0
|
193 end
|
wolffd@0
|
194
|
wolffd@0
|
195
|
wolffd@0
|
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
197
|
wolffd@0
|
198 function bool = is_positive_integer(x)
|
wolffd@0
|
199
|
wolffd@0
|
200 bool = ~isempty(x) & isreal(x) & all(size(x) == 1) & x > 0;
|
wolffd@0
|
201 if ~isempty(bool)
|
wolffd@0
|
202 if bool & x~=round(x)
|
wolffd@0
|
203 bool = 0;
|
wolffd@0
|
204 end
|
wolffd@0
|
205 else
|
wolffd@0
|
206 bool = 0;
|
wolffd@0
|
207 end
|
wolffd@0
|
208
|
wolffd@0
|
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
210
|
wolffd@0
|
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
212
|
wolffd@0
|
213 function str = diff_varname();
|
wolffd@0
|
214
|
wolffd@0
|
215 array=evalin('base','who');
|
wolffd@0
|
216
|
wolffd@0
|
217 if isempty(array)
|
wolffd@0
|
218 str='a';
|
wolffd@0
|
219 return;
|
wolffd@0
|
220 end
|
wolffd@0
|
221
|
wolffd@0
|
222 for i=1:length(array)
|
wolffd@0
|
223 lens(i)=length(array{i});
|
wolffd@0
|
224 end
|
wolffd@0
|
225
|
wolffd@0
|
226
|
wolffd@0
|
227 ind=max(lens);
|
wolffd@0
|
228
|
wolffd@0
|
229 str(1:ind+1)='a';
|
wolffd@0
|
230
|
wolffd@0
|
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
232
|
wolffd@0
|
233
|
wolffd@0
|
234
|
wolffd@0
|
235
|
wolffd@0
|
236
|
wolffd@0
|
237
|
wolffd@0
|
238
|
wolffd@0
|
239
|
wolffd@0
|
240
|
wolffd@0
|
241
|
wolffd@0
|
242
|
wolffd@0
|
243
|