0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % KSTEST perform KS test on input AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: Kolmogorov - Smirnov test is typically used to assess if a
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % sample comes from a specific distribution or if two data samples came
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % from the same distribution. The test statistics is d_K = max|S(x) - K(x)|
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % where S(x) and K(x) are cumulative distribution functions of the two
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % inputs respectively.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % In the case of the test on a single data series:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % - null hypothesis is that the data are a realizations of a random variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % which is distributed according to the given probability distribution
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % In the case of the test on two data series:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % - null hypothesis is that the two data series are realizations of the same random variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % CALL: b = kstest(a1, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % b = kstest(a1, a2, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % b = kstest(a1, a2, a3, pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % INPUT: ai: are real valued AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % OUTPUT: b: are cdata AOs containing the results of the test:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 % true if the null hypothesis is rejected
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % at the given significance level.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % false if the null hypothesis is not rejected
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % at the given significance level.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % The procinfo of b contain further information as:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % - KSstatistic, the value of d_K = max|S(x) - K(x)|.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % - criticalValue, it is the value of the test statistics
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % corresponding to the significance level. CRITICAL VALUE
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % is depending on K, where K is the data length of Y1 if Y2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % is a theoretical distribution, otherwise if Y1 and Y2 are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % two data samples K = n1*n2/(n1 + n2) where n1 and n2 are
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % data length of Y1 and Y2 respectively. In the case of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % comparison of a data series with a theoretical
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % distribution and the data series is composed of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % correlated elements. K can be adjusted with a shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % parameter in order to recover test fairness. In such a
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % case the test is performed for K' = Phi * K. If
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % KSstatistic > criticalValue the null hypothesis is
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 % rejected.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % - pValue, it is the probability value associated to the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 % test statistic.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'kstest')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % VERSION: $Id: kstest.m,v 1.5 2011/07/14 07:09:06 mauro Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 function varargout = kstest(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Collect input variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 for ii = 1:nargin,in_names{ii} = inputname(ii);end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % Collect all AOs and plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 if nargout == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 error('### KSTEST cannot be used as a modifier. Please give an output variable.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % Collect input histories
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 inhists = [as.hist];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % combine plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 if isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 model = 'empirical';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 model = lower(find(pl, 'TESTDISTRIBUTION'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 if isempty(model)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 model = 'empirical';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 pl.pset('TESTDISTRIBUTION', model);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 pl = parse(pl, getDefaultPlist(model));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % get parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 alpha = find(pl, 'ALPHA');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 if isa(alpha, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 alpha = alpha.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 shapeparam = find(pl, 'SHAPEPARAM');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 if isa(shapeparam, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 shapeparam = shapeparam.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 criticalvalue = find(pl, 'CRITICALVALUE');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 if isa(criticalvalue, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 criticalvalue = criticalvalue.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % switch among test type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 switch lower(model)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 case 'normal'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 mmean = find(pl, 'MEAN');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 if isa(mmean, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 mmean = mmean.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 sstd = find(pl, 'STD');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 if isa(sstd, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 sstd = sstd.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 distparams = [mmean, sstd];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 dist = 'normdist';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 case 'chi2'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 ddof = find(pl, 'DOF');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 if isa(ddof, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 ddof = ddof.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 distparams = [ddof];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 dist = 'chi2dist';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 case 'f'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 dof1 = find(pl, 'DOF1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 if isa(dof1, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 dof1 = dof1.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 dof2 = find(pl, 'DOF2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 if isa(dof2, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 dof2 = dof2.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 distparams = [dof1, dof2];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 dist = 'fdist';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 case 'gamma'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 shp = find(pl, 'SHAPE');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 if isa(shp, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 shp = shp.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 scl = find(pl, 'SCALE');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 if isa(scl, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 scl = scl.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 distparams = [shp, scl];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 dist = 'gammadist';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 distparams = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % run test
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 switch lower(model)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 case 'empirical'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 y1 = as(1).y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 bs = ao.initObjectWithSize(1, numel(as)-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 % run over input aos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 for ii = 1:numel(bs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 y2 = as(ii+1).y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 if size(y1, 1) ~= size(y2, 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 % reshape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 y2 = y2.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 [H, KSstatistic, criticalValue, pValue] =...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 utils.math.kstest(y1, y2, alpha, distparams, shapeparam, criticalvalue);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 bs(ii) = ao(H);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 bs(ii).setName(sprintf('KStest(%s,%s)', as(1).name, as(ii+1).name));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 plproc = plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 'KSstatistic', KSstatistic,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 'criticalValue', criticalValue,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 'pValue', pValue);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 bs(ii).setProcinfo(plproc);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 bs(ii).addHistory(getInfo('None'), pl, [ao_invars(1) ao_invars(ii+1)], [inhists(1) inhists(ii+1)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 bs = ao.initObjectWithSize(1, numel(as));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 % run over input aos
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 for ii = 1:numel(bs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 [H, KSstatistic, criticalValue, pValue] =...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 utils.math.kstest(as(ii).y, dist, alpha, distparams, shapeparam, criticalvalue);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 bs(ii) = ao(H);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 bs(ii).setName(sprintf('KStest(%s,%s)', as(ii).name,model));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 plproc = plist(...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 'KSstatistic',KSstatistic,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 'criticalValue',criticalValue,...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 'pValue',pValue);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 bs(ii).setProcinfo(plproc);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 bs(ii).addHistory(getInfo('None'), pl, ao_invars(ii), inhists(ii));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 % Set output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 varargout = utils.helper.setoutputs(nargout, bs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 % Get Info Object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 sets{1} = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 pl = getDefaultPlist(sets{1});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 sets = SETS();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 % get plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 pl(size(sets)) = plist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 for kk = 1:numel(sets)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 pl(kk) = getDefaultPlist(sets{kk});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: kstest.m,v 1.5 2011/07/14 07:09:06 mauro Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 % Defintion of Sets
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 function out = SETS()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 out = {...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 'empirical', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 'normal', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 'chi2', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 'f', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 'gamma' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 };
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 % Get Default Plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 function plout = getDefaultPlist(set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 persistent pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 persistent lastset;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 if ~exist('pl', 'var') || isempty(pl) || ~strcmp(lastset, set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 pl = buildplist(set);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 lastset = set;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 plout = pl;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 function plo = buildplist(set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 plo = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 p = param({'TESTDISTRIBUTION', ['test data are compared with the given '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 'test distribution. Available choices are:<ol>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 '<li>EMPIRICAL test all the input objects (starting from the second) against the first object.</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 '<li>NORMAL test all the input objects against the Normal distribution, '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 'with mean specified by the ''MEAN'' parameter, and sigma specified by the ''STD'' parameter</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 '<li>CHI2 test all the input objects against the Chi square distribution, ' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 'with degrees of freedom specified by the ''DOF'' parameter</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 '<li>F test all the input objects against the F distribution, '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 'with first degree of freedom specified by the ''DOF1'' parameter, and '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 'second degree of freedom specified by the ''DOF2'' parameter</li>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 '<li>GAMMA test all the input objects against the Gamma distribution, '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 'with shape parameter (k) specified by the ''SHAPE'' parameter, '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 'and scale parameter (theta) specified by the ''SCALE'' parameter</li></ol>']}, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 {1, {'EMPIRICAL', 'NORMAL', 'CHI2', 'F', 'GAMMA'}, paramValue.SINGLE});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 p = param({'ALPHA', ['ALPHA is the desired significance level. It represents '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 'the probability of rejecting the null hypothesis when it is true.'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 'Rejecting the null hypothesis, H0, when it is true is called a Type I '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 'Error. Therefore, if the null hypothesis is true , the level of the test, '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 'is the probability of a type I error.']}, paramValue.DOUBLE_VALUE(0.05));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 p = param({'SHAPEPARAM', ['In the case of comparison of a data series with a '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 'theoretical distribution and the data series is composed of correlated '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 'elements. K can be adjusted with a shape parameter in order to recover '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 'test fairness [3]. In such a case the test is performed for K* = Phi * K.<br>'...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 'Phi is the corresponding Shape parameter. The shape parameter depends on '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 'the correlations and on the significance value. It does not depend on '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 'data length.']}, paramValue.DOUBLE_VALUE(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 p = param({'CRITICALVALUE', ['In case the critical value for the test is available from '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 'external calculations, e.g. Monte Carlo simulation, the vale can be input '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 'as a parameter.']}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 switch lower(set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 case 'empirical'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 % do nothing
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 case 'normal'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 p = param({'MEAN', ['The mean of the normal distribution']}, paramValue.DOUBLE_VALUE(0));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 p = param({'STD', ['The standard deviation of the normal distribution']}, paramValue.DOUBLE_VALUE(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 case 'chi2'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 p = param({'DOF', ['Degrees of freedom of the Chi square distribution']}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 case 'f'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 p = param({'DOF1', ['First degree of freedom of the F distribution']}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 p = param({'DOF2', ['Second degree of freedom of the F distribution']}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 case 'gamma'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 p = param({'SHAPE', ['Shape parameter (k) of the Gamma distribution']}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 p = param({'SCALE', ['Scale parameter (theta) of the Gamma distribution']}, paramValue.DOUBLE_VALUE(2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 plo.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 end
|