comparison m-toolbox/classes/@pest/computePdf.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 % computes Probability Density Function from a pest object
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: computes Probability Density Function from a pest object.
5 %
6 % CALL: p = computePdf(p,pl)
7 % p.computePdf(pl)
8 %
9 % INPUTS: p - pest object
10 % pl - parameter list (BurnIn,nbins)
11 %
12 % OUTPUTs: p - pest object with the computed normilized pdf
13 %
14 % <a href="matlab:utils.helper.displayMethodInfo('pest', 'computePdf')">Parameters Description</a>
15 %
16 % VERSION: $Id: computePdf.m,v 1.2 2011/06/06 14:02:12 nikos Exp $
17 %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 function varargout = computePdf(varargin)
21
22 %%% Check if this is a call for parameters
23 if utils.helper.isinfocall(varargin{:})
24 varargout{1} = getInfo(varargin{3});
25 return
26 end
27
28 import utils.const.*
29 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
30
31 % Collect input variable names
32 in_names = cell(size(varargin));
33 for ii = 1:nargin,in_names{ii} = inputname(ii);end
34
35 % Collect all AOs and plists
36 [pests, pest_invars] = utils.helper.collect_objects(varargin(:), 'pest', in_names);
37 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
38
39 % Decide on a deep copy or a modify
40 p = copy(pests, nargout);
41
42 % combine plists
43 pl = parse(pl, getDefaultPlist());
44 BurnIn = find(pl, 'BurnIn');
45 nbins = find(pl, 'nbins');
46
47 if ~all(isa(pests, 'pest'))
48 error('### computePdf must be only applied to pest objects.');
49 end
50
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53 N = numel(p);
54
55 for ii=1:N
56 a=p(ii).chain;
57 D=size(a);
58 [n(1,:),xout(1,:)]=hist(a(BurnIn:D(1),1),nbins);
59 sumbins = sum(n(1,:));
60 PDF = [xout(1,:) ; n(1,:)/sumbins]';
61
62 for jj=2:D(2)
63 % creating histograms
64 [n(jj,:),xout(jj,:)]=hist(a(BurnIn:D(1),jj),nbins);
65 sumbins = sum(n(jj,:));
66 PDF = [PDF xout(jj,:)' (n(jj,:)')/sumbins];
67 end
68 PDFn(:,:,ii)= PDF;
69 end
70
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
73 % Output pest/pdf
74 if nargout == 1
75 for ii=1:N
76 p(ii).setPdf(PDFn(:,:,ii));
77 end
78 out = p;
79 elseif nargout == 0
80 for ii=1:N
81 p(ii).setPdf(PDFn(:,:,ii));
82 end
83 out = p;
84 out.addHistory(getInfo('None'), pl, pest_invars(:), [pests(:).hist]);
85 else
86 error('### The number of output arguments must be a one or zero');
87 end
88
89 name = p(1).name;
90 if N>1
91 for ii=2:N
92 name = [name ',' p(ii).name];
93 end
94 end
95
96 % Set outputs
97 if nargout > 0
98 varargout{1} = out;
99 end
100
101 end
102
103
104 %--------------------------------------------------------------------------
105 % Get Info Object
106 %--------------------------------------------------------------------------
107 function ii = getInfo(varargin)
108 if nargin == 1 && strcmpi(varargin{1}, 'None')
109 sets = {};
110 pl = [];
111 else
112 sets = {'Default'};
113 pl = getDefaultPlist;
114 end
115 % Build info object
116 ii = minfo(mfilename, 'pest', 'ltpda', utils.const.categories.helper, '$Id: computePdf.m,v 1.2 2011/06/06 14:02:12 nikos Exp $', sets, pl);
117 end
118
119
120 %--------------------------------------------------------------------------
121 % Get Default Plist
122 %--------------------------------------------------------------------------
123 function plout = getDefaultPlist()
124 persistent pl;
125 if exist('pl', 'var')==0 || isempty(pl)
126 pl = buildplist();
127 end
128 plout = pl;
129 end
130
131 function pl = buildplist()
132 pl = plist();
133
134 p = param({'BurnIn','Number of samples (of the chains) to be discarded'}, paramValue.DOUBLE_VALUE(1));
135 pl.append(p);
136
137 p = param({'nbins','Number of bins of the pdf histogram computed for every parameter'}, paramValue.DOUBLE_VALUE(10));
138 pl.append(p);
139
140 end
141