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

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