annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_map_struct.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 = som_map_struct(dim, varargin)
Daniel@0 2
Daniel@0 3 %SOM_MAP_STRUCT Create map struct.
Daniel@0 4 %
Daniel@0 5 % sMap = som_map_struct(dim, [[argID,] value, ...])
Daniel@0 6 %
Daniel@0 7 % sMap = som_map_struct(4);
Daniel@0 8 % sMap = som_map_struct(4,'msize',[3 4],'hexa','sheet');
Daniel@0 9 % sMap = som_map_struct(4,'msize',[3 4 5],'rect','name','a 3D-SOM');
Daniel@0 10 % sMap = som_map_struct(4,'msize',[3 4],'bubble','mask',[1 1 1 0]);
Daniel@0 11 %
Daniel@0 12 % Input and output arguments ([]'s are optional):
Daniel@0 13 % dim (scalar) input space dimension
Daniel@0 14 % [argID, (string) See below. The values which are unambiguous can
Daniel@0 15 % value] (varies) be given without the preceeding argID.
Daniel@0 16 %
Daniel@0 17 % sMap (struct) self-organizing map struct
Daniel@0 18 %
Daniel@0 19 % Here are the valid argument IDs and corresponding values. The values
Daniel@0 20 % which are unambiguous (marked with '*') can be given without the
Daniel@0 21 % preceeding argID.
Daniel@0 22 % 'mask' (vector) BMU search mask, size dim x 1
Daniel@0 23 % 'msize' (vector) map grid size, default is [0]
Daniel@0 24 % 'labels' (string array / cellstr) labels for each map unit,
Daniel@0 25 % length=prod(msize)
Daniel@0 26 % 'name' (string) map name
Daniel@0 27 % 'comp_names' (string array / cellstr) component names, size dim x 1
Daniel@0 28 % 'comp_norm' (cell array) normalization operations for each
Daniel@0 29 % component, size dim x 1. Each cell is either empty,
Daniel@0 30 % or a cell array of normalization structs.
Daniel@0 31 % 'topol' *(struct) topology struct
Daniel@0 32 % 'som_topol','sTopol' = 'topol'
Daniel@0 33 % 'lattice' *(string) map lattice, 'hexa' or 'rect'
Daniel@0 34 % 'shape' *(string) map shape, 'sheet', 'cyl' or 'toroid'
Daniel@0 35 % 'neigh' *(string) neighborhood function, 'gaussian', 'cutgauss',
Daniel@0 36 % 'ep' or 'bubble'
Daniel@0 37 %
Daniel@0 38 % For more help, try 'type som_map_struct' or check out online documentation.
Daniel@0 39 % See also SOM_SET, SOM_INFO, SOM_DATA_STRUCT, SOM_TOPOL_STRUCT, SOM_MAKE.
Daniel@0 40
Daniel@0 41 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 42 %
Daniel@0 43 % som_map_struct
Daniel@0 44 %
Daniel@0 45 % PURPOSE
Daniel@0 46 %
Daniel@0 47 % Creates a self-organizing map structure.
Daniel@0 48 %
Daniel@0 49 % SYNTAX
Daniel@0 50 %
Daniel@0 51 % sM = som_map_struct(dim)
Daniel@0 52 % sM = som_map_struct(...,'argID',value,...);
Daniel@0 53 % sM = som_map_struct(...,value,...);
Daniel@0 54 %
Daniel@0 55 % DESCRIPTION
Daniel@0 56 %
Daniel@0 57 % Creates a self-organizing map struct. The struct contains the map
Daniel@0 58 % codebook, labels, topology, information on normalization and training,
Daniel@0 59 % as well as component names and a name for the map. The obligatory
Daniel@0 60 % parameter is the map dimension. Most of the other fields can be
Daniel@0 61 % given values using optional arguments. If they are left unspecified,
Daniel@0 62 % default values are used.
Daniel@0 63 %
Daniel@0 64 % Field Type Size / default value (munits = prod(msize))
Daniel@0 65 % ------------------------------------------------------------------------
Daniel@0 66 % .type (string) 'som_map'
Daniel@0 67 % .name (string) 'SOM date'
Daniel@0 68 % .codebook (matrix) rand(munits, dim)
Daniel@0 69 % .topol (struct) topology struct, with the following fields
Daniel@0 70 % .type (string) 'som_topol'
Daniel@0 71 % .msize (vector) size k x 1, [0]
Daniel@0 72 % .lattice (string) 'hexa'
Daniel@0 73 % .shape (string) 'sheet'
Daniel@0 74 % .labels (cellstr) size munits x m, {''; ''; ... ''}
Daniel@0 75 % .neigh (string) 'gaussian'
Daniel@0 76 % .mask (vector) size dim x 1, [1; 1; ...; 1]
Daniel@0 77 % .trainhist (cell array) size tl x 1, []
Daniel@0 78 % .comp_names (cellstr) size dim x 1, {'Variable1', 'Variable2', ...}
Daniel@0 79 % .comp_norm (cell array) size dim x 1, {[], [], ... []}
Daniel@0 80 %
Daniel@0 81 % '.type' field is the struct identifier. Do not change it.
Daniel@0 82 % '.name' field is the identifier for the whole map struct
Daniel@0 83 % '.codebook' field is the codebook matrix, each row corresponds to one unit
Daniel@0 84 % '.topol' field is the topology of the map. This struct has three fields:
Daniel@0 85 % '.msize' field is the dimensions of the map grid. Note that the
Daniel@0 86 % matrix notation of indeces is used.
Daniel@0 87 % '.lattice' field is the map grid lattice
Daniel@0 88 % '.shape' field is the map grid shape
Daniel@0 89 % '.labels' field contains the labels for each of the vectors. The ith row
Daniel@0 90 % of '.labels' contains the labels for ith map unit. Note that
Daniel@0 91 % if some vectors have more labels than others, the others are
Daniel@0 92 % are given empty labels ('') to pad the '.labels' array up.
Daniel@0 93 % '.neigh' field is the neighborhood function.
Daniel@0 94 % '.mask' field is the BMU search mask.
Daniel@0 95 % '.trainhist' field contains information on the training. It is a cell
Daniel@0 96 % array of training structs. The first training struct contains
Daniel@0 97 % information on initialization, the others on actual trainings.
Daniel@0 98 % If the map has not been initialized, '.trainhist' is empty ([]).
Daniel@0 99 % '.comp_names' field contains the names of the vector components
Daniel@0 100 % '.comp_norm' field contains normalization information for each
Daniel@0 101 % component. Each cell of '.comp_norm' is itself a cell array of
Daniel@0 102 % normalization structs. If no normalizations are performed for
Daniel@0 103 % the particular component, the cell is empty ([]).
Daniel@0 104 %
Daniel@0 105 % REQUIRED INPUT ARGUMENTS
Daniel@0 106 %
Daniel@0 107 % dim (scalar) Input space dimension.
Daniel@0 108 %
Daniel@0 109 % OPTIONAL INPUT ARGUMENTS
Daniel@0 110 %
Daniel@0 111 % argID (string) Argument identifier string (see below).
Daniel@0 112 % value (varies) Value for the argument (see below).
Daniel@0 113 %
Daniel@0 114 % The optional arguments are given as 'argID',value -pairs. If the
Daniel@0 115 % value is unambiguous (marked below with '*'), it can be given
Daniel@0 116 % without the preceeding argID. If an argument is given value
Daniel@0 117 % multiple times, the last one is used.
Daniel@0 118 %
Daniel@0 119 % 'mask' (vector) BMU search mask, size dim x 1
Daniel@0 120 % 'msize' (vector) map grid size, default is [0]
Daniel@0 121 % 'labels' (string array / cellstr) labels for each map unit,
Daniel@0 122 % length=prod(msize)
Daniel@0 123 % 'name' (string) map name
Daniel@0 124 % 'comp_names' (string array / cellstr) component names, size dim x 1
Daniel@0 125 % 'comp_norm' (cell array) normalization operations for each
Daniel@0 126 % component, size dim x 1. Each cell is either empty,
Daniel@0 127 % or a cell array of normalization structs.
Daniel@0 128 % 'lattice' *(string) map lattice, 'hexa' or 'rect'
Daniel@0 129 % 'shape' *(string) map shape, 'sheet', 'cyl' or 'toroid'
Daniel@0 130 % 'topol' *(struct) topology struct, sets msize, lattice and shape
Daniel@0 131 % 'som_topol','sTopol' = 'topol'
Daniel@0 132 % 'neigh' *(string) neighborhood function, 'gaussian', 'cutgauss',
Daniel@0 133 % 'ep' or 'bubble'
Daniel@0 134 %
Daniel@0 135 % OUTPUT ARGUMENTS
Daniel@0 136 %
Daniel@0 137 % sMap (struct) the map struct
Daniel@0 138 %
Daniel@0 139 % EXAMPLES
Daniel@0 140 %
Daniel@0 141 % Simplest case:
Daniel@0 142 % sMap = som_map_struct(3);
Daniel@0 143 %
Daniel@0 144 % With optional arguments, the other fields can be given values:
Daniel@0 145 % sTo = som_set('som_topol','msize',[10 5]);
Daniel@0 146 % labs = cell(50, 1); labs{1, 1} = 'first_unit';
Daniel@0 147 % cnames = {'first'; 'second'; 'third'};
Daniel@0 148 % sN = som_set('som_norm');
Daniel@0 149 % csN = {sN; sN; sN};
Daniel@0 150 %
Daniel@0 151 % sMap = som_map_struct(3,'msize',[10 5],'rect');
Daniel@0 152 % sMap = som_map_struct(3,'msize',[10 5],'lattice','rect');
Daniel@0 153 % sMap = som_map_struct(3,sTo,'bubble','labels',labs);
Daniel@0 154 % sMap = som_map_struct(3,sTo,'comp_names',cnames);
Daniel@0 155 % sMap = som_map_struct(3,sTo,'name','a data struct');
Daniel@0 156 % sMap = som_map_struct(3,sTo,'comp_norm',csN,'mask',[1 0 0.5]);
Daniel@0 157 %
Daniel@0 158 % SEE ALSO
Daniel@0 159 %
Daniel@0 160 % som_set Set values and create SOM Toolbox structs.
Daniel@0 161 % som_data_struct Create a data struct.
Daniel@0 162 % som_make Initialize and train self-organizing map.
Daniel@0 163 % som_topol_struct Default values for map topology.
Daniel@0 164
Daniel@0 165 % Copyright (c) 1997-2000 by the SOM toolbox programming team.
Daniel@0 166 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 167
Daniel@0 168 % Version 1.0beta ecco 100997
Daniel@0 169 % Version 2.0beta juuso 101199 130300
Daniel@0 170
Daniel@0 171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 172
Daniel@0 173 % default values
Daniel@0 174 sTopol = som_set('som_topol','lattice','hexa','shape','sheet');
Daniel@0 175 neigh = 'gaussian';
Daniel@0 176 mask = ones(dim,1);
Daniel@0 177 name = sprintf('SOM %s', datestr(now, 1));
Daniel@0 178 labels = cell(prod(sTopol.msize),1);
Daniel@0 179 for i=1:length(labels), labels{i} = ''; end
Daniel@0 180 comp_names = cell(dim,1);
Daniel@0 181 for i = 1:dim, comp_names{i} = sprintf('Variable%d', i); end
Daniel@0 182 comp_norm = cell(dim,1);
Daniel@0 183
Daniel@0 184 % varargin
Daniel@0 185 i=1;
Daniel@0 186 while i<=length(varargin),
Daniel@0 187 argok = 1;
Daniel@0 188 if ischar(varargin{i}),
Daniel@0 189 switch varargin{i},
Daniel@0 190 % argument IDs
Daniel@0 191 case 'mask', i=i+1; mask = varargin{i};
Daniel@0 192 case 'msize', i=i+1; sTopol.msize = varargin{i};
Daniel@0 193 case 'labels', i=i+1; labels = varargin{i};
Daniel@0 194 case 'name', i=i+1; name = varargin{i};
Daniel@0 195 case 'comp_names', i=i+1; comp_names = varargin{i};
Daniel@0 196 case 'comp_norm', i=i+1; comp_norm = varargin{i};
Daniel@0 197 case 'lattice', i=i+1; sTopol.lattice = varargin{i};
Daniel@0 198 case 'shape', i=i+1; sTopol.shape = varargin{i};
Daniel@0 199 case {'topol','som_topol','sTopol'}, i=i+1; sTopol = varargin{i};
Daniel@0 200 case 'neigh', i=i+1; neigh = varargin{i};
Daniel@0 201 % unambiguous values
Daniel@0 202 case {'hexa','rect'}, sTopol.lattice = varargin{i};
Daniel@0 203 case {'sheet','cyl','toroid'}, sTopol.shape = varargin{i};
Daniel@0 204 case {'gaussian','cutgauss','ep','bubble'}, neigh = varargin{i};
Daniel@0 205 otherwise argok=0;
Daniel@0 206 end
Daniel@0 207 elseif isstruct(varargin{i}) & isfield(varargin{i},'type'),
Daniel@0 208 switch varargin{i}(1).type,
Daniel@0 209 case 'som_topol', sTopol = varargin{i};
Daniel@0 210 otherwise argok=0;
Daniel@0 211 end
Daniel@0 212 else
Daniel@0 213 argok = 0;
Daniel@0 214 end
Daniel@0 215 if ~argok,
Daniel@0 216 disp(['(som_map_struct) Ignoring invalid argument #' num2str(i+1)]);
Daniel@0 217 end
Daniel@0 218 i = i+1;
Daniel@0 219 end
Daniel@0 220
Daniel@0 221 % create the SOM
Daniel@0 222 codebook = rand(prod(sTopol.msize),dim);
Daniel@0 223 sTrain = som_set('som_train','time',datestr(now,0),'mask',mask);
Daniel@0 224 sMap = som_set('som_map','codebook',codebook,'topol',sTopol,...
Daniel@0 225 'neigh',neigh,'labels',labels,'mask',mask,...
Daniel@0 226 'comp_names',comp_names,'name',name,...
Daniel@0 227 'comp_norm',comp_norm,'trainhist',sTrain);
Daniel@0 228
Daniel@0 229
Daniel@0 230
Daniel@0 231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%