comparison m-toolbox/classes/@matrix/matrix.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children a71a40911c27
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MATRIX constructor for matrix class.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MATRIX constructor for matrix class.
5 %
6 % CONSTRUCTOR:
7 %
8 % fb = matrix() - creates an empty matrix object
9 % fb = matrix(objs) - construct from an array of objects
10 % fb = matrix(pl) - create a matrix object from a parameter list
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'matrix')">Parameters Description</a>
13 %
14 % VERSION: $Id: matrix.m,v 1.49 2011/08/23 13:50:46 hewitson Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 classdef matrix < ltpda_uoh
19
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 % Property definition %
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24 %---------- Public (read/write) Properties ----------
25 properties
26 objs = []; % objects in matrix
27 end
28
29 %---------- Protected read-only Properties ----------
30 properties (SetAccess = protected)
31 end
32
33 %---------- Private Properties ----------
34 properties (GetAccess = protected, SetAccess = protected)
35 end
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 % Check property setting %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 methods
42
43 end
44
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 % Constructor %
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49 methods
50 function obj = matrix(varargin)
51
52 callerIsMethod = utils.helper.callerIsMethod;
53
54 import utils.const.*
55 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
56
57 % Collect all matrix objects
58 [mats, invars, rest] = utils.helper.collect_objects(varargin(:), 'matrix');
59
60 if isempty(rest) && ~isempty(mats)
61 % Do copy constructor and return
62 utils.helper.msg(msg.OPROC1, 'copy constructor');
63 obj = copy(mats, 1);
64 for kk=1:numel(obj)
65 obj(kk).addHistory(matrix.getInfo('matrix', 'None'), [], [], obj(kk).hist);
66 end
67 return
68 end
69
70 switch nargin
71 case 0
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%% no input %%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 utils.helper.msg(msg.OPROC1, 'empty constructor');
76 obj.addHistory(matrix.getInfo('matrix', 'None'), plist(), [], []);
77
78 case 1
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 if ischar(varargin{1})
84 %%%%%%%%%% pzm = matrix('foo.mat') %%%%%%%%%%
85 %%%%%%%%%% pzm = matrix('foo.xml') %%%%%%%%%%
86 utils.helper.msg(msg.OPROC1, 'constructing from file %s', varargin{1});
87 obj = fromFile(obj, varargin{1});
88
89 elseif isstruct(varargin{1})
90 %%%%%%%%%% r = matrix(struct) %%%%%%%%%%
91 utils.helper.msg(msg.OPROC1, 'constructing from struct');
92 obj = fromStruct(obj, varargin{1});
93
94 elseif isa(varargin{1}, 'ltpda_uoh')
95 %%%%%%%%%% r = matrix(<ltpda_uoh-objects>) %%%%%%%%%%
96 obj = obj.fromInput(plist('objs', varargin), callerIsMethod);
97
98 elseif isnumeric(varargin{1})
99 %%%%%%%%%% r = matrix(doubleArray) %%%%%%%%%%
100 obj = obj.fromValues(plist('values', varargin{1}), callerIsMethod);
101
102 elseif isa(varargin{1}, 'plist')
103 %%%%%%%%%% r = matrix(plist) %%%%%%%%%%
104 pl = varargin{1};
105
106 if pl.isparam('filename')
107 utils.helper.msg(msg.PROC2, 'constructing from file %s', pl.find('filename'));
108 obj = obj.fromFile(pl);
109
110 elseif pl.isparam('hostname') || pl.isparam('conn')
111 utils.helper.msg(msg.PROC2, 'constructing from repository %s', pl.find('hostname'));
112 obj = obj.fromRepository(pl);
113
114 elseif pl.isparam('objs')
115 obj = obj.fromInput(pl, callerIsMethod);
116
117 elseif pl.isparam('plist')
118 obj = matrix(pl.find('plist'));
119
120 elseif pl.isparam('built-in')
121 utils.helper.msg(msg.OPROC1, 'constructing from built-in model');
122 obj = fromModel(obj, pl);
123
124 elseif pl.isparam('csd')
125 utils.helper.msg(msg.PROC2, 'constructing from csd %s', char(pl.find('csd')));
126 obj = obj.fromCSD(pl);
127
128 elseif pl.isparam('model')
129 utils.helper.msg(msg.PROC2, 'constructing Multichannel Zero Mean Gaussian Noise %s', char(pl.find('model')));
130 obj = obj.MultiChannelNoise(pl);
131
132 elseif pl.isparam('values')
133 obj = obj.fromValues(pl, callerIsMethod);
134
135 else
136 obj.setProperties(pl);
137 obj.addHistory(matrix.getInfo('matrix', 'None'), pl, [], []);
138 end
139
140 else
141 error('### Unknown single argument constructor.');
142 end
143
144 case 2
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 %%%%%%%%%%%%%%%%%%%%%%%%%%% two inputs %%%%%%%%%%%%%%%%%%%%%%%%%%
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 if isa(varargin{1}, 'ltpda_uoh') && isa(varargin{2}, 'ltpda_uoh')
150 %%%%%%%%%% f = matrix(a1, a2) %%%%%%%%%%
151 utils.helper.msg(msg.OPROC1, 'retrieve from repository');
152 obj = obj.fromInput(plist('objs', varargin), callerIsMethod);
153
154 elseif (isa(varargin{1}, 'database') || isa(varargin{1}, 'mpipeline.repository.RepositoryConnection')) ...
155 && isnumeric(varargin{2})
156 %%%%%%%%%% f = matrix(<database-object>, [IDs]) %%%%%%%%%%
157 utils.helper.msg(msg.OPROC1, 'retrieve from repository');
158 obj = obj.fromRepository(plist('conn', varargin{1}, 'id', varargin{2}));
159
160 elseif isa(varargin{1}, 'matrix') && isa(varargin{2}, 'plist') && isempty(varargin{2}.params)
161 %%%%%%%%%% f = matrix(matrix-object, <empty plist>) %%%%%%%%%%
162 obj = matrix(varargin{1});
163
164 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
165 isa(varargin{2}, 'history')
166 %%%%%%%%%% obj = matrix(DOM node, history-objects) %%%%%%%%%%
167 obj = fromDom(obj, varargin{1}, varargin{2});
168
169 elseif isnumeric(varargin{1}) && iscell(varargin{2})
170 %%%%%%%%%% r = matrix(doubleArray, cellArray) %%%%%%%%%%
171 obj = matrix(plist('values', varargin{1}, 'yunits', varargin{2}));
172
173 elseif isa(varargin{1}, 'ltpda_uoh') && isa(varargin{2}, 'plist')
174 %%%%%%%%%%% matrix(<ltpda_uoh>-object, plist-object) %%%%%%%%%%
175 % always recreate from plist if it contains 'objs' key
176
177
178 % If we are trying to load from file, and the file exists, do
179 % that. Otherwise, copy the input object.
180 if varargin{2}.isparam('filename')
181 if exist(fullfile('.', find(varargin{2}, 'filename')), 'file')==2
182 obj = matrix(varargin{2});
183 else
184 obj = matrix(varargin{1});
185 end
186 else
187 if isparam(varargin{2}, 'objs')
188 obj = matrix(varargin{2});
189 else
190 obj = obj.fromInput(combine(plist('objs', varargin{1}), varargin{2}), callerIsMethod);
191 end
192 end
193 else
194 error('### Unknown 2 argument constructor.');
195 end
196
197 otherwise
198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 %%%%%%%%%%%%%%%%%%%%%%%%%%% any input %%%%%%%%%%%%%%%%%%%%%%%%%%%
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 [pls, mat_invars, rest] = utils.helper.collect_objects(varargin, 'plist');
202 pl = combine(plist('objs', rest), pls);
203
204 obj = obj.fromInput(pl, callerIsMethod);
205 end
206
207 end % End constructor
208
209 end
210
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % Methods (static) %
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 methods (Static)
215
216 function mdls = getBuiltInModels(varargin)
217 mdls = ltpda_uo.getBuiltInModels('matrix');
218 end
219
220 function out = VEROUT()
221 out = '$Id: matrix.m,v 1.49 2011/08/23 13:50:46 hewitson Exp $';
222 end
223
224 function ii = getInfo(varargin)
225 ii = utils.helper.generic_getInfo(varargin{:}, 'matrix');
226 end
227
228 function out = SETS()
229 out = [SETS@ltpda_uoh, ...
230 {'From Input'}, ...
231 {'MultiChannel Noise'}, ...
232 {'From CSD'}, ...
233 {'From Values'}];
234 end
235
236 function plout = getDefaultPlist(set)
237 persistent pl;
238 persistent lastset;
239 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
240 pl = matrix.buildplist(set);
241 lastset = set;
242 end
243 plout = pl;
244 end
245
246 function out = buildplist(set)
247
248 if ~utils.helper.ismember(lower(matrix.SETS), lower(set))
249 error('### Unknown set [%s]', set);
250 end
251
252 out = plist();
253 out = matrix.addGlobalKeys(out);
254 out = buildplist@ltpda_uoh(out, set);
255
256 switch lower(set)
257 case 'default'
258 p = param({'shape', 'Specify the shape of the resulting matrix.'}, paramValue.EMPTY_DOUBLE);
259 out.append(p);
260
261 p = param({'objs', 'Matrix of user objects.'}, paramValue.EMPTY_DOUBLE);
262 out.append(p);
263 case 'from input'
264 p = param({'shape', 'Specify the shape of the resulting matrix.'}, paramValue.EMPTY_DOUBLE);
265 out.append(p);
266
267 p = param({'objs', 'Matrix of user objects.'}, paramValue.EMPTY_DOUBLE);
268 out.append(p);
269
270 case 'from csd'
271
272 % CSD
273 p = param({'csd','A matrix of fsdata AOs containing the cross spectral density matrix elements.'}, paramValue.EMPTY_DOUBLE);
274 out.append(p);
275
276 % Target Objects
277 p = param({'targetobj', ['Choose the type of output objects:<ul>',...
278 '<li>''miir'' output a matrix containing filterbanks of parallel miir filters</li>',...
279 '<li>''parfrac'' output a matrix containing parafracs objects</li>']}, ...
280 {1, {'miir','parfrac'}, paramValue.OPTIONAL});
281 out.append(p);
282
283 % Fs
284 p = param({'fs', 'The sampling frequency of the discrete filters.'}, {1, {1}, paramValue.OPTIONAL});
285 out.append(p);
286
287 % Max Iter
288 p = param({'MaxIter', 'Maximum number of fit iterations.'}, {1, {50}, paramValue.OPTIONAL});
289 out.append(p);
290
291 % Pole type
292 p = param({'PoleType',['Choose the pole type for fitting initialization:<ul>',...
293 '<li>1 == use real starting poles</li>',...
294 '<li>2 == generates complex conjugate poles of the type <tt>a.*exp(theta*pi*j)</tt> with <tt>theta = linspace(0,pi,N/2+1)</tt></li>',...
295 '<li>3 == generates complex conjugate poles of the type <tt>a.*exp(theta*pi*j)</tt> with <tt>theta = linspace(0,pi,N/2+2)</tt></li></ul>']}, ...
296 {1, {1, 2, 3}, paramValue.SINGLE});
297 out.append(p);
298
299 % Min order
300 p = param({'MinOrder','Minimum order to fit with.'}, {1, {7}, paramValue.OPTIONAL});
301 out.append(p);
302
303 % Max Order
304 p = param({'MaxOrder','Maximum order to fit with.'}, {1, {35}, paramValue.OPTIONAL});
305 out.append(p);
306
307 % Weights
308 p = param({'Weights',['Choose weighting for the fit:<ul>',...
309 '<li> 1 == equal weights for each point</li>',...
310 '<li> 2 == weight with <tt>1/abs(model)</tt></li>',...
311 '<li> 3 == weight with <tt>1/abs(model).^2</tt></li>',...
312 '<li> 4 == weight with inverse of the square mean spread of the model</li></ul>']}, {2, {1 2 3 4}, paramValue.SINGLE});
313 out.append(p);
314
315 % Plot
316 p = param({'Plot', 'Plot results of each fitting step.'}, paramValue.TRUE_FALSE);
317 p.val.setValIndex(2);
318 out.append(p);
319
320 % MSE Vartol
321 p = param({'MSEVARTOL', ['Mean Squared Error Variation - Check if the realtive variation of the mean squared error is<br>',...
322 'smaller than the value specified. This option is useful for finding the minimum of Chi squared.']}, ...
323 {1, {1e-2}, paramValue.OPTIONAL});
324 out.append(p);
325
326 % FIT TOL
327 p = param({'FITTOL',['Mean Squared Error Value - Check if the mean squared error value <br>',...
328 ' is lower than the value specified.']}, {1, {1e-2}, paramValue.OPTIONAL});
329 out.append(p);
330
331 % UseSym
332 p = param({'UseSym', ['Use symbolic calculation in eigen-decomposition.<ul>'...
333 '<li>''on'' - uses symbolic math toolbox calculation<br>'...
334 'for poles stabilization</li>'...
335 '<li>''off'' - perform double-precision calculation<br>'...
336 'for poles stabilization</li>']}, {1, {'on','off'}, paramValue.SINGLE});
337 out.append(p);
338
339 % Iunits
340 p = param({'iunits', 'The unit to set as input unit for the output filters'}, paramValue.EMPTY_STRING);
341 out.append(p);
342
343 % Ounits
344 p = param({'ounits', 'The unit to set as output unit for the output filters'}, paramValue.EMPTY_STRING);
345 out.append(p);
346
347 case 'multichannel noise'
348
349 % Model
350 p = param({'model','A matrix of filterbanks or parfarcs objects, modeling multichannel system response.'}, paramValue.EMPTY_DOUBLE);
351 out.append(p);
352
353 % Nsecs
354 p = param({'nsecs', 'Number of seconds in the desired noise data series.'}, {1, {1}, paramValue.OPTIONAL});
355 out.append(p);
356
357 % Fs
358 p = param({'fs', 'The sampling frequency of the noise data series.'}, {1, {1}, paramValue.OPTIONAL});
359 out.append(p);
360
361 % Yunits
362 p = param({'yunits','Unit on Y axis.'}, paramValue.STRING_VALUE('m'));
363 out.append(p);
364
365 case 'from values'
366
367 % Values
368 p = param({'values', 'Each value will create a single AO.'}, paramValue.EMPTY_DOUBLE);
369 out.append(p);
370
371 % Yunits
372 p = param({'yunits', 'Y-unit for the AOs which are built from the values'}, paramValue.EMPTY_CELL);
373 out.append(p);
374
375 % Names
376 p = param({'names', 'Names for the AOs which are built from the values'}, paramValue.EMPTY_CELL);
377 out.append(p);
378
379 end
380 end % function out = getDefaultPlist(varargin)
381
382 function obj = initObjectWithSize(n,m)
383 obj = matrix.newarray([n m]);
384 end
385
386 end % End static methods
387
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 % Methods (static, private) %
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391
392 methods (Static, Access=private)
393 varargout = elementOp(varargin)
394 end % End static, private methods
395
396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 % Methods (static, hidden) %
398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399
400 methods (Static = true, Hidden = true)
401 varargout = loadobj(varargin)
402 varargout = update_struct(varargin);
403 end
404
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 % Methods (public) %
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 methods
409
410 varargout = char(varargin)
411 varargout = display(varargin)
412 varargout = copy(varargin)
413 out = det(varargin)
414 out = inv(varargin)
415 varargout = minus(varargin)
416 varargout = plus(varargin)
417 varargout = rdivide(varargin)
418 varargout = times(varargin)
419 varargout = mtimes(varargin)
420 varargout = transpose(varargin)
421 varargout = ctranspose(varargin)
422 varargout = filter(varargin)
423 varargout = conj(varargin)
424 varargout = nrows(varargin)
425 varargout = ncols(varargin)
426 varargout = osize(varargin)
427 varargout = setObjs(varargin)
428 varargout = getObjectAtIndex(varargin)
429 end
430
431 methods (Hidden = true)
432 varargout = attachToDom(varargin)
433 end
434
435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 % Methods (protected) %
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 methods (Access = protected)
439 varargout = fromInput(varargin)
440 varargout = fromStruct(varargin)
441 varargout = fromDom(varargin)
442 end
443
444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445 % Methods (private) %
446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
447 methods (Access = private)
448 % Constructors
449 varargout = wrapper(varargin)
450 a = fromCSD(a, pli)
451 a = MultiChannelNoise(a, pli)
452 end
453
454 end % End classdef
455