Debian Codegraph @

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

raw
1 function imfcnt = fn_empdfsort(imfcnt,imf_h,imfloor,hbin,ninv)
2 % imfcnt = fn_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: k-element vector of particular draws. Need not be a 1-by-k row vector.
11 % imfloor: k-element vector of low values of imf but imf_h can be below "imfloor" and above "imceiling"
12 % hbin: k-element vector of bin lengths = (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 TZ; Revised, August 2000.
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 imf_h=imf_h(:); imfloor=imfloor(:); hbin=hbin(:);
38 countInt = floor( (imf_h-imfloor) ./ hbin ); % k-by-1
39 % bin locations from <0, 0, 1,..., ninv-1, >=ninv, a total of ninv+2 bins
40 countInt = 2+countInt'; % 1-by-k row vector, see my shock (1), pp.1
41 % move everyting by 2 so as to take account of <0
42
43 countInt(find(countInt<2)) = 1; % set <0 or -infinity at 1 to start
44 countInt(find(countInt>=ninv+2)) = ninv+2; % set >=ninv+2 or +infinity at ninv+2 to end
45 countInt = countInt + (0:length(countInt)-1)*(ninv+2);
46 % 1-by-k*(ninv+2) index vector to fill the matrix with prob. (counts)
47 % The term after "+" implies that with every count, we skip ninv+2 to keep
48 % each column in "imfcnt" with only one element (which is probability)
49 imfcnt(countInt) = imfcnt(countInt) + 1;