Daniel@0: function sD = som_denormalize(sD,varargin) Daniel@0: Daniel@0: %SOM_DENORMALIZE Denormalize data. Daniel@0: % Daniel@0: % sS = som_denormalize(sS, [argID, value, ...]) Daniel@0: % Daniel@0: % sS = som_denormalize(sS) Daniel@0: % sS = som_denormalize(sS,[1:3 10],'remove') Daniel@0: % D = som_denormalize(D,sM.comp_norm) Daniel@0: % D = som_denormalize(D,sM,[1:3 10]) Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % sS The data to which the denormalization is applied. Daniel@0: % The modified and updated data is returned. Daniel@0: % (struct) data or map struct Daniel@0: % (matrix) data matrix (a matrix is also returned) Daniel@0: % [argID, (string) See below. The values which are unambiguous can Daniel@0: % value] (varies) be given without the preceeding argID. Daniel@0: % Daniel@0: % Here are the valid argument IDs and corresponding values. The values which Daniel@0: % are unambiguous (marked with '*') can be given without the preceeding argID. Daniel@0: % 'norm' *(struct) Normalization struct, or an array of such. Daniel@0: % Alternatively, a map/data struct can be given Daniel@0: % in which case its '.comp_norm' field is used Daniel@0: % (see below). Daniel@0: % *(cell array) Of normalization structs. Typically, the Daniel@0: % '.comp_norm' field of a map/data struct. The Daniel@0: % length of the array must be equal to data dimension. Daniel@0: % 'remove' *(string) If 'remove' tag is specified, the Daniel@0: % normalization operations are not only undone, Daniel@0: % they are also removed from the struct. Daniel@0: % 'comps' *(vector) the components to which the denormalization is Daniel@0: % applied, default is [1:dim] ie. all components Daniel@0: % Daniel@0: % For more help, try 'type som_denormalize' or check out online documentation. Daniel@0: % See also SOM_NORMALIZE, SOM_NORM_VARIABLE, SOM_INFO. Daniel@0: Daniel@0: %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Daniel@0: % som_denormalize Daniel@0: % Daniel@0: % PURPOSE Daniel@0: % Daniel@0: % Undo normalizations of data structs/sets. Daniel@0: % Daniel@0: % SYNTAX Daniel@0: % Daniel@0: % sS = som_denormalize(sS) Daniel@0: % sS = som_denormalize(...,'argID',value,...); Daniel@0: % sS = som_denormalize(...,value,...); Daniel@0: % D = som_denormalize(D,sNorm) Daniel@0: % Daniel@0: % DESCRIPTION Daniel@0: % Daniel@0: % This function is used to undo normalizations of data structs/sets. If a Daniel@0: % data/map struct is given, all normalizations in the '.comp_norm' field are Daniel@0: % undone and, thus, the values in the original data context are returned. If Daniel@0: % a matrix is given, the normalizations to undo must be given as the second Daniel@0: % argument. SOM_DENORMALIZE actually uses function SOM_NORM_VARIABLE to Daniel@0: % handle the normalization operations, and only handles the data struct/set Daniel@0: % specific stuff itself. Daniel@0: % Daniel@0: % Normalizations are always one-variable operations. In the data and map Daniel@0: % structs the normalization information for each component is saved in the Daniel@0: % '.comp_norm' field, which is a cell array of length dim. Each cell Daniel@0: % contains normalizations for one vector component in a Daniel@0: % struct array of normalization structs. Each component may have different Daniel@0: % amounts of different kinds of normalizations. Typically, all Daniel@0: % normalizations are either 'undone' or 'done', but in special situations Daniel@0: % this may not be the case. The easiest way to check out the status of the Daniel@0: % normalizations is to use function SOM_INFO, e.g. som_info(sS,3) Daniel@0: % Daniel@0: % REQUIRED INPUT ARGUMENTS Daniel@0: % Daniel@0: % sS The data to which the denormalization is applied. Daniel@0: % (struct) Data or map struct. The normalizations in the Daniel@0: % '.comp_norm' field are undone for the specified Daniel@0: % components. Daniel@0: % (matrix) Data matrix. The normalization to undo must be Daniel@0: % given in the second argument. Daniel@0: % Daniel@0: % OPTIONAL INPUT ARGUMENTS Daniel@0: % Daniel@0: % argID (string) Argument identifier string (see below). Daniel@0: % value (varies) Value for the argument (see below). Daniel@0: % Daniel@0: % The optional arguments can be given as 'argID',value -pairs. If an Daniel@0: % argument is given value multiple times, the last one is used. The Daniel@0: % valid IDs and corresponding values are listed below. The values Daniel@0: % which are unambiguous (marked with '*') can be given without the Daniel@0: % preceeding argID. Daniel@0: % Daniel@0: % sNorm *(struct) Normalization struct, or an array of structs, which Daniel@0: % is undone for all specified components. If the Daniel@0: % '.status' field of the struct(s) is 'uninit', Daniel@0: % the undoing operation is interrupted - it cannot be Daniel@0: % done. Alternatively, the struct may be map or Daniel@0: % data struct in which case its '.comp_norm' field Daniel@0: % is used (see the cell array option below). Daniel@0: % *(cell array) In practice, the '.comp_norm' field of Daniel@0: % a data/map struct. The length of the array Daniel@0: % must be equal to the dimension of the given Daniel@0: % data set (sS). Each cell contains the Daniel@0: % normalization(s) for one component. Only the Daniel@0: % normalizations listed in comps argument are Daniel@0: % undone though. Daniel@0: % Daniel@0: % 'remove' *(string) If 'remove' tag is specified, the Daniel@0: % normalization operations are not only undone, Daniel@0: % they are also removed from the struct. Daniel@0: % Daniel@0: % 'comps' *(vector) The components which are denormalized. Daniel@0: % Default is to undo all components. Daniel@0: % *(string) 'all' Daniel@0: % Daniel@0: % OUTPUT ARGUMENTS Daniel@0: % Daniel@0: % sS Modified and/or updated data. Daniel@0: % (struct) If a struct was given as input argument, the Daniel@0: % same struct is returned with denormalized data and Daniel@0: % updated '.comp_norm' fields. Daniel@0: % (matrix) If a matrix was given as input argument, the Daniel@0: % denormalized data matrix is returned. Daniel@0: % Daniel@0: % EXAMPLES Daniel@0: % Daniel@0: % To undo normalization of a data/map struct: Daniel@0: % Daniel@0: % sD = som_denormalize(sD); Daniel@0: % sM = som_denormalize(sM); Daniel@0: % Daniel@0: % To completely remove the normalizations, use the 'remove' tag: Daniel@0: % Daniel@0: % sD = som_denormalize(sD,'remove'); Daniel@0: % Daniel@0: % To undo only a few selected components, use the comps argument: Daniel@0: % Daniel@0: % sD = som_denormalize(sD,[1 3:5]); Daniel@0: % Daniel@0: % To denormalize a set of values from a data set D (which must be Daniel@0: % of equal dimension as the data in sD): Daniel@0: % Daniel@0: % D = som_denormalize(D,sD); Daniel@0: % or Daniel@0: % D = som_denormalize(D,sD.comp_norm); Daniel@0: % only denormalize a few components Daniel@0: % D = som_denormalize(D,sD,[1 3:5]); Daniel@0: % Daniel@0: % Assuming you have a few values of a certain vector component (i) Daniel@0: % in a vector (x) which you want to denormalize: Daniel@0: % Daniel@0: % xorig = som_denormalize(x,sD.comp_norm{i}); Daniel@0: % or using SOM_NORM_VARIABLE Daniel@0: % xorig = som_norm_variable(x,sD.comp_norm{i},'undo'); Daniel@0: % Daniel@0: % To check out the status of normalization in a struct use SOM_INFO: Daniel@0: % Daniel@0: % som_info(sM,3) Daniel@0: % som_info(sD,3) Daniel@0: % Daniel@0: % SEE ALSO Daniel@0: % Daniel@0: % som_normalize Add/apply/redo normalizations of a data struct/set. Daniel@0: % som_norm_variable Normalization operations for a set of scalar values. Daniel@0: % som_info User-friendly information of SOM Toolbox structs. Daniel@0: Daniel@0: % Copyright (c) 1998-2000 by the SOM toolbox programming team. Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 151199 150300 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% check arguments Daniel@0: Daniel@0: error(nargchk(1, 3, nargin)); % check no. of input arguments is correct Daniel@0: Daniel@0: % sD Daniel@0: struct_mode = isstruct(sD); Daniel@0: if struct_mode, Daniel@0: switch sD.type Daniel@0: case 'som_map', D = sD.codebook; Daniel@0: case 'som_data', D = sD.data; Daniel@0: otherwise, error('Illegal struct.') Daniel@0: end Daniel@0: else Daniel@0: D = sD; Daniel@0: end Daniel@0: [dlen dim] = size(D); Daniel@0: Daniel@0: % varargin Daniel@0: comps = [1:dim]; Daniel@0: remove_tag = 0; Daniel@0: if struct_mode, sNorm = sD.comp_norm; else sNorm = []; end Daniel@0: i=1; Daniel@0: while i<=length(varargin), Daniel@0: argok = 1; Daniel@0: if ischar(varargin{i}), Daniel@0: switch varargin{i}, Daniel@0: % argument IDs Daniel@0: case 'comps', i=i+1; comps = varargin{i}; Daniel@0: case {'norm','sNorm','som_norm'}, i=i+1; sNorm = varargin{i}; Daniel@0: % unambiguous values Daniel@0: case 'remove', remove_tag = 1; Daniel@0: otherwise argok=0; Daniel@0: end Daniel@0: elseif isnumeric(varargin{i}), Daniel@0: comps = varargin{i}; Daniel@0: elseif isstruct(varargin{i}), Daniel@0: sNorm = varargin{i}; Daniel@0: elseif iscell(varargin{i}), Daniel@0: sNorm = varargin{i}; Daniel@0: else Daniel@0: argok = 0; Daniel@0: end Daniel@0: if ~argok, Daniel@0: disp(['(som_denormalize) Ignoring invalid argument #' num2str(i+1)]); Daniel@0: end Daniel@0: i = i+1; Daniel@0: end Daniel@0: Daniel@0: % check comps Daniel@0: if ischar(comps), comps = [1:dim]; end Daniel@0: if isempty(comps), return; end Daniel@0: if size(comps,1)>1, comps = comps'; end % make it a row vector Daniel@0: Daniel@0: % sNorm Daniel@0: % check out the given normalization Daniel@0: % (and if necessary, copy it for each specified component) Daniel@0: if isstruct(sNorm), Daniel@0: switch sNorm(1).type, Daniel@0: case {'som_map','som_data'}, csNorm = sNorm(1).comp_norm; Daniel@0: case {'som_norm'}, for i=comps, csNorm{i} = sNorm; end Daniel@0: otherwise, Daniel@0: error('Invalid struct for sNorm.') Daniel@0: end Daniel@0: elseif iscell(sNorm), Daniel@0: csNorm = sNorm; Daniel@0: else Daniel@0: error('Illegal value for sNorm.') Daniel@0: end Daniel@0: Daniel@0: % check that csNorm and comps possibly agree Daniel@0: if max(comps) > length(csNorm), Daniel@0: error('Given normalizations does not match the components.') Daniel@0: end Daniel@0: if length(csNorm) ~= dim, Daniel@0: error('Given normalizations does not match data dimension.') Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% action Daniel@0: Daniel@0: % undo the normalizations Daniel@0: for i = comps, Daniel@0: len = length(csNorm{i}); Daniel@0: for j=len:-1:1, Daniel@0: sN = csNorm{i}(j); Daniel@0: if struct_mode, Daniel@0: if strcmp(sN.status,'done'), Daniel@0: [x,sN] = som_norm_variable(D(:,i), sN, 'undo'); Daniel@0: D(:,i) = x; Daniel@0: csNorm{i}(j) = sN; Daniel@0: end Daniel@0: else Daniel@0: D(:,i) = som_norm_variable(D(:,i), sN, 'undo'); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % remove normalizations Daniel@0: if struct_mode & remove_tag, Daniel@0: for i = comps, csNorm{i} = []; end Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% output Daniel@0: Daniel@0: Daniel@0: if struct_mode, Daniel@0: switch sD.type Daniel@0: case 'som_map', sD.codebook = D; Daniel@0: case 'som_data', sD.data = D; Daniel@0: otherwise, error('Illegal struct.') Daniel@0: end Daniel@0: sD.comp_norm = csNorm; Daniel@0: else Daniel@0: sD = D; Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: Daniel@0: