comparison m-toolbox/classes/@ao/qqplot.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % QQFPLOT makes quantile-quantile plot
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Make quantile-quantile plot and calculate confidence
5 % intervals on the basis of the Kolmogorov-Smirnov test.
6 %
7 % CALL: qqplot(a, pl)
8 %
9 % INPUT: a: are real valued AO
10 %
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'kstest')">Parameters Description</a>
13 %
14 % VERSION: $Id: qqplot.m,v 1.1 2011/07/08 10:28:02 luigi Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 function varargout = qqplot(varargin)
19
20 % Check if this is a call for parameters
21 if utils.helper.isinfocall(varargin{:})
22 varargout{1} = getInfo(varargin{3});
23 return
24 end
25
26 import utils.const.*
27 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
28
29 % Collect input variable names
30 in_names = cell(size(varargin));
31 for ii = 1:nargin,in_names{ii} = inputname(ii);end
32
33 % Collect all AOs and plists
34 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
35 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
36
37 % combine plists
38 if isempty(pl)
39 model = 'empirical';
40 else
41 model = lower(find(pl, 'TESTDISTRIBUTION'));
42 if isempty(model)
43 model = 'empirical';
44 pl.pset('TESTDISTRIBUTION', model);
45 end
46 end
47
48 pl = parse(pl, getDefaultPlist(model));
49
50 % get parameters
51 conf = find(pl, 'CONFLEVEL');
52 if isa(conf, 'ao')
53 conf = conf.y;
54 end
55 shapeparam = find(pl, 'SHAPEPARAM');
56 if isa(shapeparam, 'ao')
57 shapeparam = shapeparam.y;
58 end
59 ftsize = find(pl, 'FONTSIZE');
60 if isa(ftsize, 'ao')
61 ftsize = ftsize.y;
62 end
63 lwidth = find(pl, 'LINEWIDTH');
64 if isa(lwidth, 'ao')
65 lwidth = lwidth.y;
66 end
67
68 % switch among test type
69 switch lower(model)
70 case 'normal'
71 mmean = find(pl, 'MEAN');
72 if isa(mmean, 'ao')
73 mmean = mmean.y;
74 end
75 sstd = find(pl, 'STD');
76 if isa(sstd, 'ao')
77 sstd = sstd.y;
78 end
79 distparams = [mmean, sstd];
80 dist = 'normdist';
81 case 'chi2'
82 ddof = find(pl, 'DOF');
83 if isa(ddof, 'ao')
84 ddof = ddof.y;
85 end
86 distparams = [ddof];
87 dist = 'chi2dist';
88 case 'f'
89 dof1 = find(pl, 'DOF1');
90 if isa(dof1, 'ao')
91 dof1 = dof1.y;
92 end
93 dof2 = find(pl, 'DOF2');
94 if isa(dof2, 'ao')
95 dof2 = dof2.y;
96 end
97 distparams = [dof1, dof2];
98 dist = 'fdist';
99 case 'gamma'
100 shp = find(pl, 'SHAPE');
101 if isa(shp, 'ao')
102 shp = shp.y;
103 end
104 scl = find(pl, 'SCALE');
105 if isa(scl, 'ao')
106 scl = scl.y;
107 end
108 distparams = [shp, scl];
109 dist = 'gammadist';
110 otherwise
111 distparams = [];
112 end
113
114
115 % run test
116 switch lower(model)
117 case 'empirical'
118
119 % build parameters struct
120 params = struct(...
121 'conflevel',conf,...
122 'FontSize',ftsize,...
123 'LineWidth',lwidth);
124
125 y1 = as(1).y;
126 % run over input aos
127 for ii=1:numel(as)-1
128 y2 = as(ii+1).y;
129 if size(y1,1)~=size(y2,1)
130 % reshape
131 y2 = y2.';
132 end
133 utils.math.qqplot(y1, y2, params);
134
135 end
136
137 otherwise
138
139 % build parameters struct
140 params = struct(...
141 'ProbDist',dist,...
142 'ShapeParam',shapeparam,...
143 'params',distparams,...
144 'conflevel',conf,...
145 'FontSize',ftsize,...
146 'LineWidth',lwidth);
147
148 % run over input aos
149 for ii=1:numel(as)
150
151 utils.math.qqplot(as(ii).y, [], params);
152
153 end
154
155 end
156
157
158 end
159
160
161 %--------------------------------------------------------------------------
162 % Get Info Object
163 %--------------------------------------------------------------------------
164 function ii = getInfo(varargin)
165 if nargin == 1 && strcmpi(varargin{1}, 'None')
166 sets = {};
167 pl = [];
168 elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
169 sets{1} = varargin{1};
170 pl = getDefaultPlist(sets{1});
171 else
172 sets = SETS();
173 % get plists
174 pl(size(sets)) = plist;
175 for kk = 1:numel(sets)
176 pl(kk) = getDefaultPlist(sets{kk});
177 end
178 end
179 % Build info object
180 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: qqplot.m,v 1.1 2011/07/08 10:28:02 luigi Exp $', sets, pl);
181 end
182
183
184 %--------------------------------------------------------------------------
185 % Defintion of Sets
186 %--------------------------------------------------------------------------
187
188 function out = SETS()
189 out = {...
190 'empirical', ...
191 'normal', ...
192 'chi2', ...
193 'f', ...
194 'gamma' ...
195 };
196 end
197
198 %--------------------------------------------------------------------------
199 % Get Default Plist
200 %--------------------------------------------------------------------------
201 function plout = getDefaultPlist(set)
202 persistent pl;
203 persistent lastset;
204 if ~exist('pl', 'var') || isempty(pl) || ~strcmp(lastset, set)
205 pl = buildplist(set);
206 lastset = set;
207 end
208 plout = pl;
209 end
210
211 function plo = buildplist(set)
212 plo = plist();
213
214 p = param({'TESTDISTRIBUTION', ['test data are compared with the given'...
215 'test distribution. Available choices are:<ol>'...
216 '<li>EMPIRICAL test the all the input object (starting from the second) against the first object.</li>'...
217 '<li>NORMAL test all the input objects against the Normal distribution</li>'...
218 '<li>CHI2 test all the input objects against the Chi square distribution</li>'...
219 '<li>F test all the input objects against the F distribution</li>'...
220 '<li>GAMMA test all the input objects against the Gamma distribution</li></ol>']}, ...
221 {1, {'EMPIRICAL', 'NORMAL', 'CHI2', 'F', 'GAMMA'}, paramValue.SINGLE});
222 plo.append(p);
223
224 p = param({'CONFLEVEL', 'Confidence level for confidence interval calculations.'},...
225 paramValue.DOUBLE_VALUE(0.95));
226 plo.append(p);
227
228 p = param({'SHAPEPARAM', ['In the case of comparison of a data series with a'...
229 'theoretical distribution and the data series is composed of correlated'...
230 'elements. K can be adjusted with a shape parameter in order to recover'...
231 'test fairness [3]. In such a case the test is performed for K* = Phi * K.'...
232 'Phi is the corresponding Shape parameter. The shape parameter depends on'...
233 'the correlations and on the significance value. It does not depend on'...
234 'data length.']}, paramValue.DOUBLE_VALUE(1));
235 plo.append(p);
236
237 p = param({'FONTSIZE', 'Font size for axis'}, paramValue.DOUBLE_VALUE(22));
238 plo.append(p);
239
240 p = param({'LINEWIDTH', 'Line Width'}, paramValue.DOUBLE_VALUE(2));
241 plo.append(p);
242
243 switch lower(set)
244 case 'empirical'
245 % do nothing
246 case 'normal'
247 p = param({'MEAN', ['The mean of the normal distribution']}, paramValue.DOUBLE_VALUE(0));
248 plo.append(p);
249 p = param({'STD', ['The standard deviation of the normal distribution']}, paramValue.DOUBLE_VALUE(1));
250 plo.append(p);
251 case 'chi2'
252 p = param({'DOF', ['Degrees of freedom of the chi square distribution']}, paramValue.DOUBLE_VALUE(2));
253 plo.append(p);
254 case 'f'
255 p = param({'DOF1', ['First degree of freedom of the F distribution']}, paramValue.DOUBLE_VALUE(2));
256 plo.append(p);
257 p = param({'DOF2', ['Second degree of freedom of the F distribution']}, paramValue.DOUBLE_VALUE(2));
258 plo.append(p);
259 case 'gamma'
260 p = param({'SHAPE', ['Shape parameter (k) of the Gamma distribution']}, paramValue.DOUBLE_VALUE(2));
261 plo.append(p);
262 p = param({'SCALE', ['Scale parameter (theta) of the Gamma distribution']}, paramValue.DOUBLE_VALUE(2));
263 plo.append(p);
264 otherwise
265 end
266
267
268
269
270 end