annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_sompaktrain.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [sMap, sTrain] = som_sompaktrain(sMap, D, varargin)
wolffd@0 2
wolffd@0 3 %SOM_SOMPAKTRAIN Use SOM_PAK to train the Self-Organizing Map.
wolffd@0 4 %
wolffd@0 5 % [sM,sT] = som_sompaktrain(sM, D, [[argID,] value, ...])
wolffd@0 6 %
wolffd@0 7 % sM = som_sompaktrain(sM,D);
wolffd@0 8 % sM = som_sompaktrain(sM,sD,'alpha_type','inv');
wolffd@0 9 % [M,sT] = som_sompaktrain(M,D,'bubble','trainlen',10,'inv','hexa');
wolffd@0 10 %
wolffd@0 11 % Input and output arguments ([]'s are optional):
wolffd@0 12 % sM (struct) map struct, the trained and updated map is returned
wolffd@0 13 % (matrix) codebook matrix of a self-organizing map
wolffd@0 14 % size munits x dim or msize(1) x ... x msize(k) x dim
wolffd@0 15 % The trained map codebook is returned.
wolffd@0 16 % D (struct) training data; data struct
wolffd@0 17 % (matrix) training data, size dlen x dim
wolffd@0 18 % (string) name of data file
wolffd@0 19 % [argID, (string) See below. The values which are unambiguous can
wolffd@0 20 % value] (varies) be given without the preceeding argID.
wolffd@0 21 %
wolffd@0 22 % sT (struct) learning parameters used during the training
wolffd@0 23 %
wolffd@0 24 % Here are the valid argument IDs and corresponding values. The values which
wolffd@0 25 % are unambiguous (marked with '*') can be given without the preceeding argID.
wolffd@0 26 % 'msize' (vector) map size
wolffd@0 27 % 'radius_ini' (scalar) neighborhood radius
wolffd@0 28 % 'radius' = 'radius_ini'
wolffd@0 29 % 'alpha_ini' (scalar) initial learning rate
wolffd@0 30 % 'alpha' = 'alpha_ini'
wolffd@0 31 % 'trainlen' (scalar) training length
wolffd@0 32 % 'seed' (scalar) seed for random number generator
wolffd@0 33 % 'snapfile' (string) base name for snapshot files
wolffd@0 34 % 'snapinterval' (scalar) snapshot interval
wolffd@0 35 % 'tlen_type' *(string) is the given trainlen 'samples' or 'epochs'
wolffd@0 36 % 'train' *(struct) train struct, parameters for training
wolffd@0 37 % 'sTrain','som_train' = 'train'
wolffd@0 38 % 'alpha_type' *(string) learning rate function, 'inv' or 'linear'
wolffd@0 39 % 'neigh' *(string) neighborhood function, 'gaussian' or 'bubble'
wolffd@0 40 % 'topol' *(struct) topology struct
wolffd@0 41 % 'som_topol','sTopol' = 'topol'
wolffd@0 42 % 'lattice' *(string) map lattice, 'hexa' or 'rect'
wolffd@0 43 %
wolffd@0 44 % For more help, try 'type som_sompaktrain' or check out online documentation.
wolffd@0 45 % See also SOM_MAKE, SOM_SEQTRAIN, SOM_BATCHTRAIN, SOM_TRAIN_STRUCT.
wolffd@0 46
wolffd@0 47 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 48 %
wolffd@0 49 % som_sompaktrain
wolffd@0 50 %
wolffd@0 51 % PURPOSE
wolffd@0 52 %
wolffd@0 53 % Use SOM_PAK to train the Self-Organizing Map.
wolffd@0 54 %
wolffd@0 55 % SYNTAX
wolffd@0 56 %
wolffd@0 57 % sM = som_sompaktrain(sM,D);
wolffd@0 58 % sM = som_sompaktrain(sM,sD);
wolffd@0 59 % sM = som_sompaktrain(...,'argID',value,...);
wolffd@0 60 % sM = som_sompaktrain(...,value,...);
wolffd@0 61 % [sM,sT] = som_sompaktrain(M,D,...);
wolffd@0 62 %
wolffd@0 63 % DESCRIPTION
wolffd@0 64 %
wolffd@0 65 % Trains the given SOM (sM or M above) with the given training data (sD or
wolffd@0 66 % D) using SOM_PAK. If no optional arguments (argID, value) are
wolffd@0 67 % given, a default training is done, the parameters are obtained from
wolffd@0 68 % SOM_TRAIN_STRUCT function. Using optional arguments the training
wolffd@0 69 % parameters can be specified. Returns the trained and updated SOM and a
wolffd@0 70 % train struct which contains information on the training.
wolffd@0 71 %
wolffd@0 72 % Notice that the SOM_PAK program 'vsom' must be in the search path of your
wolffd@0 73 % shell. Alternatively, you can set a variable 'SOM_PAKDIR' in the Matlab
wolffd@0 74 % workspace to tell the som_sompaktrain where to find the 'vsom' program.
wolffd@0 75 %
wolffd@0 76 % Notice also that many of the training parameters are much more limited in
wolffd@0 77 % values than when using SOM Toolbox function for training:
wolffd@0 78 % - the map shape is always 'sheet'
wolffd@0 79 % - only initial value for neighborhood radius can be given
wolffd@0 80 % - neighborhood function can only be 'bubble' or 'gaussian'
wolffd@0 81 % - only initial value for learning rate can be given
wolffd@0 82 % - learning rate can only be 'linear' or 'inv'
wolffd@0 83 % - mask cannot be used: all variables are always used in BMU search
wolffd@0 84 % Any parameters not confirming to these restrictions will be converted
wolffd@0 85 % so that they do before training. On the other hand, there are some
wolffd@0 86 % additional options that are not present in the SOM Toolbox:
wolffd@0 87 % - random seed
wolffd@0 88 % - snapshot file and interval
wolffd@0 89 %
wolffd@0 90 % REQUIRED INPUT ARGUMENTS
wolffd@0 91 %
wolffd@0 92 % sM The map to be trained.
wolffd@0 93 % (struct) map struct
wolffd@0 94 % (matrix) codebook matrix (field .data of map struct)
wolffd@0 95 % Size is either [munits dim], in which case the map grid
wolffd@0 96 % dimensions (msize) should be specified with optional arguments,
wolffd@0 97 % or [msize(1) ... msize(k) dim] in which case the map
wolffd@0 98 % grid dimensions are taken from the size of the matrix.
wolffd@0 99 % Lattice, by default, is 'rect' and shape 'sheet'.
wolffd@0 100 % D Training data.
wolffd@0 101 % (struct) data struct
wolffd@0 102 % (matrix) data matrix, size [dlen dim]
wolffd@0 103 % (string) name of data file
wolffd@0 104 %
wolffd@0 105 % OPTIONAL INPUT ARGUMENTS
wolffd@0 106 %
wolffd@0 107 % argID (string) Argument identifier string (see below).
wolffd@0 108 % value (varies) Value for the argument (see below).
wolffd@0 109 %
wolffd@0 110 % The optional arguments can be given as 'argID',value -pairs. If an
wolffd@0 111 % argument is given value multiple times, the last one is
wolffd@0 112 % used. The valid IDs and corresponding values are listed below. The values
wolffd@0 113 % which are unambiguous (marked with '*') can be given without the
wolffd@0 114 % preceeding argID.
wolffd@0 115 %
wolffd@0 116 % 'msize' (vector) map grid dimensions. Default is the one
wolffd@0 117 % in sM (field sM.topol.msize) or
wolffd@0 118 % 'si = size(sM); msize = si(1:end-1);'
wolffd@0 119 % if only a codebook matrix was given.
wolffd@0 120 % 'radius_ini' (scalar) initial neighborhood radius
wolffd@0 121 % 'radius' (scalar) = 'radius_ini'
wolffd@0 122 % 'alpha_ini' (vector) initial learning rate
wolffd@0 123 % 'alpha' (scalar) = 'alpha_ini'
wolffd@0 124 % 'trainlen' (scalar) training length (see also 'tlen_type')
wolffd@0 125 % 'seed' (scalar) seed for random number generator
wolffd@0 126 % 'snapfile' (string) base name for snapshot files
wolffd@0 127 % 'snapinterval' (scalar) snapshot interval
wolffd@0 128 % 'tlen_type' *(string) is the trainlen argument given in 'epochs' or
wolffd@0 129 % in 'samples'. Default is 'epochs'.
wolffd@0 130 % 'train' *(struct) train struct, parameters for training.
wolffd@0 131 % Default parameters, unless specified,
wolffd@0 132 % are acquired using SOM_TRAIN_STRUCT (this
wolffd@0 133 % also applies for 'trainlen', 'alpha_type',
wolffd@0 134 % 'alpha_ini', 'radius_ini' and 'radius_fin').
wolffd@0 135 % 'sTrain', 'som_topol' (struct) = 'train'
wolffd@0 136 % 'neigh' *(string) The used neighborhood function. Default is
wolffd@0 137 % the one in sM (field '.neigh') or 'gaussian'
wolffd@0 138 % if only a codebook matrix was given. The other
wolffd@0 139 % possible value is 'bubble'.
wolffd@0 140 % 'topol' *(struct) topology of the map. Default is the one
wolffd@0 141 % in sM (field '.topol').
wolffd@0 142 % 'sTopol', 'som_topol' (struct) = 'topol'
wolffd@0 143 % 'alpha_type' *(string) learning rate function, 'inv' or 'linear'
wolffd@0 144 % 'lattice' *(string) map lattice. Default is the one in sM
wolffd@0 145 % (field sM.topol.lattice) or 'rect'
wolffd@0 146 % if only a codebook matrix was given.
wolffd@0 147 %
wolffd@0 148 % OUTPUT ARGUMENTS
wolffd@0 149 %
wolffd@0 150 % sM the trained map
wolffd@0 151 % (struct) if a map struct was given as input argument, a
wolffd@0 152 % map struct is also returned. The current training
wolffd@0 153 % is added to the training history (sM.trainhist).
wolffd@0 154 % The 'neigh' and 'mask' fields of the map struct
wolffd@0 155 % are updated to match those of the training.
wolffd@0 156 % (matrix) if a matrix was given as input argument, a matrix
wolffd@0 157 % is also returned with the same size as the input
wolffd@0 158 % argument.
wolffd@0 159 % sT (struct) train struct; information of the accomplished training
wolffd@0 160 %
wolffd@0 161 % EXAMPLES
wolffd@0 162 %
wolffd@0 163 % Simplest case:
wolffd@0 164 % sM = som_sompaktrain(sM,D);
wolffd@0 165 % sM = som_sompaktrain(sM,sD);
wolffd@0 166 %
wolffd@0 167 % The change training parameters, the optional arguments 'train',
wolffd@0 168 % 'neigh','mask','trainlen','radius','radius_ini', 'alpha',
wolffd@0 169 % 'alpha_type' and 'alpha_ini' are used.
wolffd@0 170 % sM = som_sompaktrain(sM,D,'bubble','trainlen',10,'radius_ini',3);
wolffd@0 171 %
wolffd@0 172 % Another way to specify training parameters is to create a train struct:
wolffd@0 173 % sTrain = som_train_struct(sM,'dlen',size(D,1),'algorithm','seq');
wolffd@0 174 % sTrain = som_set(sTrain,'neigh','gaussian');
wolffd@0 175 % sM = som_sompaktrain(sM,D,sTrain);
wolffd@0 176 %
wolffd@0 177 % You don't necessarily have to use the map struct, but you can operate
wolffd@0 178 % directly with codebook matrices. However, in this case you have to
wolffd@0 179 % specify the topology of the map in the optional arguments. The
wolffd@0 180 % following commads are identical (M is originally a 200 x dim sized matrix):
wolffd@0 181 % M = som_sompaktrain(M,D,'msize',[20 10],'lattice','hexa');
wolffd@0 182 %
wolffd@0 183 % M = som_sompaktrain(M,D,'msize',[20 10],'hexa');
wolffd@0 184 %
wolffd@0 185 % sT= som_set('som_topol','msize',[20 10],'lattice','hexa');
wolffd@0 186 % M = som_sompaktrain(M,D,sT);
wolffd@0 187 %
wolffd@0 188 % M = reshape(M,[20 10 dim]);
wolffd@0 189 % M = som_sompaktrain(M,D,'hexa');
wolffd@0 190 %
wolffd@0 191 % The som_sompaktrain also returns a train struct with information on the
wolffd@0 192 % accomplished training. This is the same one as is added to the end of the
wolffd@0 193 % trainhist field of map struct, in case a map struct is given.
wolffd@0 194 % [M,sTrain] = som_sompaktrain(M,D,'msize',[20 10]);
wolffd@0 195 %
wolffd@0 196 % [sM,sTrain] = som_sompaktrain(sM,D); % sM.trainhist(end)==sTrain
wolffd@0 197 %
wolffd@0 198 % SEE ALSO
wolffd@0 199 %
wolffd@0 200 % som_make Initialize and train a SOM using default parameters.
wolffd@0 201 % som_seqtrain Train SOM with sequential algorithm.
wolffd@0 202 % som_batchtrain Train SOM with batch algorithm.
wolffd@0 203 % som_train_struct Determine default training parameters.
wolffd@0 204
wolffd@0 205 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
wolffd@0 206 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 207
wolffd@0 208 % Version 2.0beta juuso 151199
wolffd@0 209
wolffd@0 210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 211 %% Check arguments
wolffd@0 212
wolffd@0 213 error(nargchk(2, Inf, nargin)); % check the number of input arguments
wolffd@0 214
wolffd@0 215 % map
wolffd@0 216 struct_mode = isstruct(sMap);
wolffd@0 217 if struct_mode,
wolffd@0 218 sTopol = sMap.topol;
wolffd@0 219 else
wolffd@0 220 orig_size = size(sMap);
wolffd@0 221 if ndims(sMap) > 2,
wolffd@0 222 si = size(sMap); dim = si(end); msize = si(1:end-1);
wolffd@0 223 M = reshape(sMap,[prod(msize) dim]);
wolffd@0 224 else
wolffd@0 225 msize = [orig_size(1) 1];
wolffd@0 226 dim = orig_size(2);
wolffd@0 227 end
wolffd@0 228 sMap = som_map_struct(dim,'msize',msize);
wolffd@0 229 sTopol = sMap.topol;
wolffd@0 230 end
wolffd@0 231 [munits dim] = size(sMap.codebook);
wolffd@0 232
wolffd@0 233 % data
wolffd@0 234 givendatafile = '';
wolffd@0 235 if ischar(D),
wolffd@0 236 data_name = D;
wolffd@0 237 givendatafile = D;
wolffd@0 238 D = [];
wolffd@0 239 dlen = NaN;
wolffd@0 240 else
wolffd@0 241 if isstruct(D),
wolffd@0 242 data_name = D.name;
wolffd@0 243 D = D.data;
wolffd@0 244 else
wolffd@0 245 data_name = inputname(2);
wolffd@0 246 end
wolffd@0 247 D = D(find(sum(isnan(D),2) < dim),:); % remove empty vectors from the data
wolffd@0 248 [dlen ddim] = size(D); % check input dimension
wolffd@0 249 if ddim ~= dim, error('Map and data dimensions must agree.'); end
wolffd@0 250 end
wolffd@0 251
wolffd@0 252 % varargin
wolffd@0 253 sTrain = som_set('som_train','algorithm','seq',...
wolffd@0 254 'neigh',sMap.neigh,...
wolffd@0 255 'mask',ones(dim,1),...
wolffd@0 256 'data_name',data_name);
wolffd@0 257 tlen_type = 'epochs';
wolffd@0 258 random_seed = 0;
wolffd@0 259 snapshotname = '';
wolffd@0 260 snapshotinterval = 0;
wolffd@0 261
wolffd@0 262 i=1;
wolffd@0 263 while i<=length(varargin),
wolffd@0 264 argok = 1;
wolffd@0 265 if ischar(varargin{i}),
wolffd@0 266 switch varargin{i},
wolffd@0 267 % argument IDs
wolffd@0 268 case 'msize', i=i+1; sTopol.msize = varargin{i};
wolffd@0 269 case 'lattice', i=i+1; sTopol.lattice = varargin{i};
wolffd@0 270 case 'neigh', i=i+1; sTrain.neigh = varargin{i};
wolffd@0 271 case 'trainlen', i=i+1; sTrain.trainlen = varargin{i};
wolffd@0 272 case 'tlen_type', i=i+1; tlen_type = varargin{i};
wolffd@0 273 case 'radius_ini', i=i+1; sTrain.radius_ini = varargin{i};
wolffd@0 274 case 'radius', i=i+1; sTrain.radius_ini = varargin{i}(1);
wolffd@0 275 case 'alpha_type', i=i+1; sTrain.alpha_type = varargin{i};
wolffd@0 276 case 'alpha_ini', i=i+1; sTrain.alpha_ini = varargin{i};
wolffd@0 277 case 'alpha', i=i+1; sTrain.alpha_ini = varargin{i}(1);
wolffd@0 278 case 'seed', i=i+1; random_seed = varargin{i};
wolffd@0 279 case 'snapshotname',i=i+1; snapshotname = varargin{i};
wolffd@0 280 case 'snapshotinterval',i=i+1; snapshotinterval = varargin{i};
wolffd@0 281 case {'sTrain','train','som_train'}, i=i+1; sTrain = varargin{i};
wolffd@0 282 case {'topol','sTopol','som_topol'},
wolffd@0 283 i=i+1;
wolffd@0 284 sTopol = varargin{i};
wolffd@0 285 if prod(sTopol.msize) ~= munits,
wolffd@0 286 error('Given map grid size does not match the codebook size.');
wolffd@0 287 end
wolffd@0 288 % unambiguous values
wolffd@0 289 case {'inv','linear'}, sTrain.alpha_type = varargin{i};
wolffd@0 290 case {'hexa','rect'}, sTopol.lattice = varargin{i};
wolffd@0 291 case {'gaussian','bubble'}, sTrain.neigh = varargin{i};
wolffd@0 292 case {'epochs','samples'}, tlen_type = varargin{i};
wolffd@0 293 otherwise argok=0;
wolffd@0 294 end
wolffd@0 295 elseif isstruct(varargin{i}) & isfield(varargin{i},'type'),
wolffd@0 296 switch varargin{i}(1).type,
wolffd@0 297 case 'som_topol',
wolffd@0 298 sTopol = varargin{i};
wolffd@0 299 if prod(sTopol.msize) ~= munits,
wolffd@0 300 error('Given map grid size does not match the codebook size.');
wolffd@0 301 end
wolffd@0 302 case 'som_train', sTrain = varargin{i};
wolffd@0 303 otherwise argok=0;
wolffd@0 304 end
wolffd@0 305 else
wolffd@0 306 argok = 0;
wolffd@0 307 end
wolffd@0 308 if ~argok,
wolffd@0 309 disp(['(som_sompaktrain) Ignoring invalid argument #' num2str(i+2)]);
wolffd@0 310 end
wolffd@0 311 i = i+1;
wolffd@0 312 end
wolffd@0 313
wolffd@0 314 % check topology
wolffd@0 315 if struct_mode,
wolffd@0 316 if ~strcmp(sTopol.lattice,sMap.topol.lattice) | ...
wolffd@0 317 ~strcmp(sTopol.shape,sMap.topol.shape) | ...
wolffd@0 318 any(sTopol.msize ~= sMap.topol.msize),
wolffd@0 319 warning('Changing the original map topology.');
wolffd@0 320 end
wolffd@0 321 end
wolffd@0 322 sMap.topol = sTopol;
wolffd@0 323
wolffd@0 324 % complement the training struct
wolffd@0 325 if ~isnan(dlen),
wolffd@0 326 sTrain = som_train_struct(sTrain,sMap,'dlen',dlen);
wolffd@0 327 else
wolffd@0 328 sTrain = som_train_struct(sTrain,sMap);
wolffd@0 329 end
wolffd@0 330 if isempty(sTrain.mask), sTrain.mask = ones(dim,1); end
wolffd@0 331
wolffd@0 332 % training length
wolffd@0 333 if strcmp(tlen_type,'epochs'),
wolffd@0 334 if isnan(dlen),
wolffd@0 335 error('Training length given as epochs, but data length is not known.\n');
wolffd@0 336 else
wolffd@0 337 rlen = sTrain.trainlen*dlen;
wolffd@0 338 end
wolffd@0 339 else
wolffd@0 340 rlen = sTrain.trainlen;
wolffd@0 341 sTrain.trainlen = sTrain.trainlen/dlen;
wolffd@0 342 end
wolffd@0 343
wolffd@0 344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 345 %% check arguments
wolffd@0 346
wolffd@0 347 % mask
wolffd@0 348 if any(sTrain.mask~=1),
wolffd@0 349 sTrain.mask = ones(dim,1);
wolffd@0 350 fprintf(1,'Ignoring given mask.\n');
wolffd@0 351 end
wolffd@0 352
wolffd@0 353 % learning rate
wolffd@0 354 if strcmp(sTrain.alpha_type,'power'),
wolffd@0 355 sTrain.alpha_type = 'inv';
wolffd@0 356 fprintf(1,'Using ''inv'' learning rate type instead of ''power''\n');
wolffd@0 357 end
wolffd@0 358
wolffd@0 359 % neighborhood
wolffd@0 360 if any(strcmp(sTrain.neigh,{'cutgauss','ep'})),
wolffd@0 361 fprintf(1,'Using ''gaussian'' neighborhood function instead of %s.\n',sTrain.neigh);
wolffd@0 362 sTrain.neigh = 'gaussian';
wolffd@0 363 end
wolffd@0 364
wolffd@0 365 % map shape
wolffd@0 366 if ~strcmp(sMap.topol.shape,'sheet'),
wolffd@0 367 fprintf(1,'Using ''sheet'' map shape of %s.\n',sMap.topol.shape);
wolffd@0 368 sMap.topol.shape = 'sheet';
wolffd@0 369 end
wolffd@0 370
wolffd@0 371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 372 %% Action
wolffd@0 373
wolffd@0 374 % write files
wolffd@0 375 if ~isempty(givendatafile),
wolffd@0 376 temp_din = givendatafile;
wolffd@0 377 else
wolffd@0 378 temp_din = tempname;
wolffd@0 379 som_write_data(D, temp_din, 'x')
wolffd@0 380 end
wolffd@0 381 temp_cin = tempname;
wolffd@0 382 som_write_cod(sMap, temp_cin)
wolffd@0 383 temp_cout = tempname;
wolffd@0 384
wolffd@0 385 % check if the environment variable 'SOM_PAKDIR' has been defined
wolffd@0 386 if any(strcmp('SOM_PAKDIR', evalin('base', 'who')))
wolffd@0 387 som_pak_dir = evalin('base', 'SOM_PAKDIR');
wolffd@0 388 else
wolffd@0 389 som_pak_dir = '';
wolffd@0 390 end
wolffd@0 391 if ~isempty(som_pak_dir) & ~strncmp(som_pak_dir(end), '/', 1)
wolffd@0 392 som_pak_dir(end + 1) = '/';
wolffd@0 393 end
wolffd@0 394
wolffd@0 395 aini = sTrain.alpha_ini;
wolffd@0 396 atype = sTrain.alpha_type;
wolffd@0 397 if strcmp(atype,'inv'), atype = 'inverse_t'; end
wolffd@0 398 rad = sTrain.radius_ini;
wolffd@0 399 str = [som_pak_dir 'vsom ' ...
wolffd@0 400 sprintf('-cin %s -din %s -cout %s', temp_cin, temp_din, temp_cout) ...
wolffd@0 401 sprintf(' -rlen %d -alpha %g -alpha_type %s', rlen, aini, atype) ...
wolffd@0 402 sprintf(' -radius %g -rand %g ',rad,random_seed)];
wolffd@0 403 if ~isempty(snapshotname) & snapinterval>0,
wolffd@0 404 str = [str, sprintf(' -snapfile %s -snapinterval %d',snapshotname,snapshotinterval)];
wolffd@0 405 end
wolffd@0 406
wolffd@0 407 fprintf(1,'Execute: %s\n',str);
wolffd@0 408 if isunix,
wolffd@0 409 [status,w] = unix(str);
wolffd@0 410 if status, fprintf(1,'Execution failed.\n'); end
wolffd@0 411 if ~isempty(w), fprintf(1,'%s\n',w); end
wolffd@0 412 else
wolffd@0 413 [status,w] = dos(str);
wolffd@0 414 if status, fprintf(1,'Execution failed.\n'); end
wolffd@0 415 if ~isempty(w), fprintf(1,'%s\n',w); end
wolffd@0 416 end
wolffd@0 417
wolffd@0 418 sMap_temp = som_read_cod(temp_cout);
wolffd@0 419 M = sMap_temp.codebook;
wolffd@0 420
wolffd@0 421 if isunix
wolffd@0 422 unix(['/bin/rm -f ' temp_din ' ' temp_cin ' ' temp_cout]);
wolffd@0 423 else
wolffd@0 424 dos(['del ' temp_din ' ' temp_cin ' ' temp_cout]);
wolffd@0 425 end
wolffd@0 426
wolffd@0 427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 428 %% Build / clean up the return arguments
wolffd@0 429
wolffd@0 430 % update structures
wolffd@0 431 sTrain = som_set(sTrain,'time',datestr(now,0));
wolffd@0 432 if struct_mode,
wolffd@0 433 sMap = som_set(sMap,'codebook',M,'mask',sTrain.mask,'neigh',sTrain.neigh);
wolffd@0 434 tl = length(sMap.trainhist);
wolffd@0 435 sMap.trainhist(tl+1) = sTrain;
wolffd@0 436 else
wolffd@0 437 sMap = reshape(M,orig_size);
wolffd@0 438 end
wolffd@0 439
wolffd@0 440 return;
wolffd@0 441
wolffd@0 442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 443