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