Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/empdfsort.m

raw
1 function imfcnt = empdfsort(imfcnt,imf_h,imfloor,hbin,ninv)
2 % imfcnt = empdfsort(imfcnt,imf_h,imfloor,hbin,ninv)
3 % Variablewise (but multivariate) empirical probability distribution with counts
4 % sorted into bins variablewise
5 % Note that since a particular draw (imf_h) can be below "imfloor" and above "imceiling"
6 % (=(imceiling-imfloor)*hbin), this function allows ninv+2 bins for each variable
7 %
8 % imfcnt: initial ninv+2-by-k matrix that records counts in each bin given a column in imfcnt
9 % if k==1, then only one variable is considered.
10 % imf_h: particular draw, needed not to be a 1-by-k row vector
11 % imfloor: the low value of imf but imf_h can be below "imfloor" and above "imceiling"
12 % hbin: bin size = (imceilling-imfloor)/ninv
13 % ninv: number of bins between "imfloor" and "imceiling"
14 %------------------
15 % imfcnt: updated ninv+2-by-k matrix of counts (probability)
16 %
17 % January 1999 TAZ
18 %
19 % Copyright (C) 1997-2012 Tao Zha
20 %
21 % This free software: you can redistribute it and/or modify
22 % it under the terms of the GNU General Public License as published by
23 % the Free Software Foundation, either version 3 of the License, or
24 % (at your option) any later version.
25 %
26 % It is distributed in the hope that it will be useful,
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 % GNU General Public License for more details.
30 %
31 % If you did not received a copy of the GNU General Public License
32 % with this software, see <http://www.gnu.org/licenses/>.
33 %
34
35
36 %** find the bin locations and arrange them to the order of 1, 2, ...
37 countInt = floor( (imf_h-imfloor) ./ hbin ); % imstp-by-nvar^2
38 % bin locations from <0, 0, 1,..., ninv-1, >=ninv, a total of ninv+2 bins
39 countInt = 2+countInt(:)'; % row vector, 1-by-imstp*nvar^2, see my shock (1), pp.1
40 % move everyting by 2 so as to take account of <0
41
42 countInt(find(countInt<2)) = 1; % set <0 or -infinity at 1 to start
43 countInt(find(countInt>=ninv+2)) = ninv+2; % set >=ninv+2 or +infinity at ninv+2 to end
44 countInt = countInt + (0:length(countInt)-1)*(ninv+2); % index to fill the matrix with prob. (counts)
45 % The term after "+": with every count, skip ninv+2 to keep
46 % each column in "imfcnt" with only one element (which is probability)
47 imfcnt(countInt) = imfcnt(countInt) + 1;