annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_denormalize.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 sD = som_denormalize(sD,varargin)
Daniel@0 2
Daniel@0 3 %SOM_DENORMALIZE Denormalize data.
Daniel@0 4 %
Daniel@0 5 % sS = som_denormalize(sS, [argID, value, ...])
Daniel@0 6 %
Daniel@0 7 % sS = som_denormalize(sS)
Daniel@0 8 % sS = som_denormalize(sS,[1:3 10],'remove')
Daniel@0 9 % D = som_denormalize(D,sM.comp_norm)
Daniel@0 10 % D = som_denormalize(D,sM,[1:3 10])
Daniel@0 11 %
Daniel@0 12 % Input and output arguments ([]'s are optional):
Daniel@0 13 % sS The data to which the denormalization is applied.
Daniel@0 14 % The modified and updated data is returned.
Daniel@0 15 % (struct) data or map struct
Daniel@0 16 % (matrix) data matrix (a matrix is also returned)
Daniel@0 17 % [argID, (string) See below. The values which are unambiguous can
Daniel@0 18 % value] (varies) be given without the preceeding argID.
Daniel@0 19 %
Daniel@0 20 % Here are the valid argument IDs and corresponding values. The values which
Daniel@0 21 % are unambiguous (marked with '*') can be given without the preceeding argID.
Daniel@0 22 % 'norm' *(struct) Normalization struct, or an array of such.
Daniel@0 23 % Alternatively, a map/data struct can be given
Daniel@0 24 % in which case its '.comp_norm' field is used
Daniel@0 25 % (see below).
Daniel@0 26 % *(cell array) Of normalization structs. Typically, the
Daniel@0 27 % '.comp_norm' field of a map/data struct. The
Daniel@0 28 % length of the array must be equal to data dimension.
Daniel@0 29 % 'remove' *(string) If 'remove' tag is specified, the
Daniel@0 30 % normalization operations are not only undone,
Daniel@0 31 % they are also removed from the struct.
Daniel@0 32 % 'comps' *(vector) the components to which the denormalization is
Daniel@0 33 % applied, default is [1:dim] ie. all components
Daniel@0 34 %
Daniel@0 35 % For more help, try 'type som_denormalize' or check out online documentation.
Daniel@0 36 % See also SOM_NORMALIZE, SOM_NORM_VARIABLE, SOM_INFO.
Daniel@0 37
Daniel@0 38 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 39 %
Daniel@0 40 % som_denormalize
Daniel@0 41 %
Daniel@0 42 % PURPOSE
Daniel@0 43 %
Daniel@0 44 % Undo normalizations of data structs/sets.
Daniel@0 45 %
Daniel@0 46 % SYNTAX
Daniel@0 47 %
Daniel@0 48 % sS = som_denormalize(sS)
Daniel@0 49 % sS = som_denormalize(...,'argID',value,...);
Daniel@0 50 % sS = som_denormalize(...,value,...);
Daniel@0 51 % D = som_denormalize(D,sNorm)
Daniel@0 52 %
Daniel@0 53 % DESCRIPTION
Daniel@0 54 %
Daniel@0 55 % This function is used to undo normalizations of data structs/sets. If a
Daniel@0 56 % data/map struct is given, all normalizations in the '.comp_norm' field are
Daniel@0 57 % undone and, thus, the values in the original data context are returned. If
Daniel@0 58 % a matrix is given, the normalizations to undo must be given as the second
Daniel@0 59 % argument. SOM_DENORMALIZE actually uses function SOM_NORM_VARIABLE to
Daniel@0 60 % handle the normalization operations, and only handles the data struct/set
Daniel@0 61 % specific stuff itself.
Daniel@0 62 %
Daniel@0 63 % Normalizations are always one-variable operations. In the data and map
Daniel@0 64 % structs the normalization information for each component is saved in the
Daniel@0 65 % '.comp_norm' field, which is a cell array of length dim. Each cell
Daniel@0 66 % contains normalizations for one vector component in a
Daniel@0 67 % struct array of normalization structs. Each component may have different
Daniel@0 68 % amounts of different kinds of normalizations. Typically, all
Daniel@0 69 % normalizations are either 'undone' or 'done', but in special situations
Daniel@0 70 % this may not be the case. The easiest way to check out the status of the
Daniel@0 71 % normalizations is to use function SOM_INFO, e.g. som_info(sS,3)
Daniel@0 72 %
Daniel@0 73 % REQUIRED INPUT ARGUMENTS
Daniel@0 74 %
Daniel@0 75 % sS The data to which the denormalization is applied.
Daniel@0 76 % (struct) Data or map struct. The normalizations in the
Daniel@0 77 % '.comp_norm' field are undone for the specified
Daniel@0 78 % components.
Daniel@0 79 % (matrix) Data matrix. The normalization to undo must be
Daniel@0 80 % given in the second argument.
Daniel@0 81 %
Daniel@0 82 % OPTIONAL INPUT ARGUMENTS
Daniel@0 83 %
Daniel@0 84 % argID (string) Argument identifier string (see below).
Daniel@0 85 % value (varies) Value for the argument (see below).
Daniel@0 86 %
Daniel@0 87 % The optional arguments can be given as 'argID',value -pairs. If an
Daniel@0 88 % argument is given value multiple times, the last one is used. The
Daniel@0 89 % valid IDs and corresponding values are listed below. The values
Daniel@0 90 % which are unambiguous (marked with '*') can be given without the
Daniel@0 91 % preceeding argID.
Daniel@0 92 %
Daniel@0 93 % sNorm *(struct) Normalization struct, or an array of structs, which
Daniel@0 94 % is undone for all specified components. If the
Daniel@0 95 % '.status' field of the struct(s) is 'uninit',
Daniel@0 96 % the undoing operation is interrupted - it cannot be
Daniel@0 97 % done. Alternatively, the struct may be map or
Daniel@0 98 % data struct in which case its '.comp_norm' field
Daniel@0 99 % is used (see the cell array option below).
Daniel@0 100 % *(cell array) In practice, the '.comp_norm' field of
Daniel@0 101 % a data/map struct. The length of the array
Daniel@0 102 % must be equal to the dimension of the given
Daniel@0 103 % data set (sS). Each cell contains the
Daniel@0 104 % normalization(s) for one component. Only the
Daniel@0 105 % normalizations listed in comps argument are
Daniel@0 106 % undone though.
Daniel@0 107 %
Daniel@0 108 % 'remove' *(string) If 'remove' tag is specified, the
Daniel@0 109 % normalization operations are not only undone,
Daniel@0 110 % they are also removed from the struct.
Daniel@0 111 %
Daniel@0 112 % 'comps' *(vector) The components which are denormalized.
Daniel@0 113 % Default is to undo all components.
Daniel@0 114 % *(string) 'all'
Daniel@0 115 %
Daniel@0 116 % OUTPUT ARGUMENTS
Daniel@0 117 %
Daniel@0 118 % sS Modified and/or updated data.
Daniel@0 119 % (struct) If a struct was given as input argument, the
Daniel@0 120 % same struct is returned with denormalized data and
Daniel@0 121 % updated '.comp_norm' fields.
Daniel@0 122 % (matrix) If a matrix was given as input argument, the
Daniel@0 123 % denormalized data matrix is returned.
Daniel@0 124 %
Daniel@0 125 % EXAMPLES
Daniel@0 126 %
Daniel@0 127 % To undo normalization of a data/map struct:
Daniel@0 128 %
Daniel@0 129 % sD = som_denormalize(sD);
Daniel@0 130 % sM = som_denormalize(sM);
Daniel@0 131 %
Daniel@0 132 % To completely remove the normalizations, use the 'remove' tag:
Daniel@0 133 %
Daniel@0 134 % sD = som_denormalize(sD,'remove');
Daniel@0 135 %
Daniel@0 136 % To undo only a few selected components, use the comps argument:
Daniel@0 137 %
Daniel@0 138 % sD = som_denormalize(sD,[1 3:5]);
Daniel@0 139 %
Daniel@0 140 % To denormalize a set of values from a data set D (which must be
Daniel@0 141 % of equal dimension as the data in sD):
Daniel@0 142 %
Daniel@0 143 % D = som_denormalize(D,sD);
Daniel@0 144 % or
Daniel@0 145 % D = som_denormalize(D,sD.comp_norm);
Daniel@0 146 % only denormalize a few components
Daniel@0 147 % D = som_denormalize(D,sD,[1 3:5]);
Daniel@0 148 %
Daniel@0 149 % Assuming you have a few values of a certain vector component (i)
Daniel@0 150 % in a vector (x) which you want to denormalize:
Daniel@0 151 %
Daniel@0 152 % xorig = som_denormalize(x,sD.comp_norm{i});
Daniel@0 153 % or using SOM_NORM_VARIABLE
Daniel@0 154 % xorig = som_norm_variable(x,sD.comp_norm{i},'undo');
Daniel@0 155 %
Daniel@0 156 % To check out the status of normalization in a struct use SOM_INFO:
Daniel@0 157 %
Daniel@0 158 % som_info(sM,3)
Daniel@0 159 % som_info(sD,3)
Daniel@0 160 %
Daniel@0 161 % SEE ALSO
Daniel@0 162 %
Daniel@0 163 % som_normalize Add/apply/redo normalizations of a data struct/set.
Daniel@0 164 % som_norm_variable Normalization operations for a set of scalar values.
Daniel@0 165 % som_info User-friendly information of SOM Toolbox structs.
Daniel@0 166
Daniel@0 167 % Copyright (c) 1998-2000 by the SOM toolbox programming team.
Daniel@0 168 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 169
Daniel@0 170 % Version 2.0beta juuso 151199 150300
Daniel@0 171
Daniel@0 172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 173 %% check arguments
Daniel@0 174
Daniel@0 175 error(nargchk(1, 3, nargin)); % check no. of input arguments is correct
Daniel@0 176
Daniel@0 177 % sD
Daniel@0 178 struct_mode = isstruct(sD);
Daniel@0 179 if struct_mode,
Daniel@0 180 switch sD.type
Daniel@0 181 case 'som_map', D = sD.codebook;
Daniel@0 182 case 'som_data', D = sD.data;
Daniel@0 183 otherwise, error('Illegal struct.')
Daniel@0 184 end
Daniel@0 185 else
Daniel@0 186 D = sD;
Daniel@0 187 end
Daniel@0 188 [dlen dim] = size(D);
Daniel@0 189
Daniel@0 190 % varargin
Daniel@0 191 comps = [1:dim];
Daniel@0 192 remove_tag = 0;
Daniel@0 193 if struct_mode, sNorm = sD.comp_norm; else sNorm = []; end
Daniel@0 194 i=1;
Daniel@0 195 while i<=length(varargin),
Daniel@0 196 argok = 1;
Daniel@0 197 if ischar(varargin{i}),
Daniel@0 198 switch varargin{i},
Daniel@0 199 % argument IDs
Daniel@0 200 case 'comps', i=i+1; comps = varargin{i};
Daniel@0 201 case {'norm','sNorm','som_norm'}, i=i+1; sNorm = varargin{i};
Daniel@0 202 % unambiguous values
Daniel@0 203 case 'remove', remove_tag = 1;
Daniel@0 204 otherwise argok=0;
Daniel@0 205 end
Daniel@0 206 elseif isnumeric(varargin{i}),
Daniel@0 207 comps = varargin{i};
Daniel@0 208 elseif isstruct(varargin{i}),
Daniel@0 209 sNorm = varargin{i};
Daniel@0 210 elseif iscell(varargin{i}),
Daniel@0 211 sNorm = varargin{i};
Daniel@0 212 else
Daniel@0 213 argok = 0;
Daniel@0 214 end
Daniel@0 215 if ~argok,
Daniel@0 216 disp(['(som_denormalize) 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 % check comps
Daniel@0 222 if ischar(comps), comps = [1:dim]; end
Daniel@0 223 if isempty(comps), return; end
Daniel@0 224 if size(comps,1)>1, comps = comps'; end % make it a row vector
Daniel@0 225
Daniel@0 226 % sNorm
Daniel@0 227 % check out the given normalization
Daniel@0 228 % (and if necessary, copy it for each specified component)
Daniel@0 229 if isstruct(sNorm),
Daniel@0 230 switch sNorm(1).type,
Daniel@0 231 case {'som_map','som_data'}, csNorm = sNorm(1).comp_norm;
Daniel@0 232 case {'som_norm'}, for i=comps, csNorm{i} = sNorm; end
Daniel@0 233 otherwise,
Daniel@0 234 error('Invalid struct for sNorm.')
Daniel@0 235 end
Daniel@0 236 elseif iscell(sNorm),
Daniel@0 237 csNorm = sNorm;
Daniel@0 238 else
Daniel@0 239 error('Illegal value for sNorm.')
Daniel@0 240 end
Daniel@0 241
Daniel@0 242 % check that csNorm and comps possibly agree
Daniel@0 243 if max(comps) > length(csNorm),
Daniel@0 244 error('Given normalizations does not match the components.')
Daniel@0 245 end
Daniel@0 246 if length(csNorm) ~= dim,
Daniel@0 247 error('Given normalizations does not match data dimension.')
Daniel@0 248 end
Daniel@0 249
Daniel@0 250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 251 %% action
Daniel@0 252
Daniel@0 253 % undo the normalizations
Daniel@0 254 for i = comps,
Daniel@0 255 len = length(csNorm{i});
Daniel@0 256 for j=len:-1:1,
Daniel@0 257 sN = csNorm{i}(j);
Daniel@0 258 if struct_mode,
Daniel@0 259 if strcmp(sN.status,'done'),
Daniel@0 260 [x,sN] = som_norm_variable(D(:,i), sN, 'undo');
Daniel@0 261 D(:,i) = x;
Daniel@0 262 csNorm{i}(j) = sN;
Daniel@0 263 end
Daniel@0 264 else
Daniel@0 265 D(:,i) = som_norm_variable(D(:,i), sN, 'undo');
Daniel@0 266 end
Daniel@0 267 end
Daniel@0 268 end
Daniel@0 269
Daniel@0 270 % remove normalizations
Daniel@0 271 if struct_mode & remove_tag,
Daniel@0 272 for i = comps, csNorm{i} = []; end
Daniel@0 273 end
Daniel@0 274
Daniel@0 275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 276 %% output
Daniel@0 277
Daniel@0 278
Daniel@0 279 if struct_mode,
Daniel@0 280 switch sD.type
Daniel@0 281 case 'som_map', sD.codebook = D;
Daniel@0 282 case 'som_data', sD.data = D;
Daniel@0 283 otherwise, error('Illegal struct.')
Daniel@0 284 end
Daniel@0 285 sD.comp_norm = csNorm;
Daniel@0 286 else
Daniel@0 287 sD = D;
Daniel@0 288 end
Daniel@0 289
Daniel@0 290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 291
Daniel@0 292
Daniel@0 293