This is a static copy of a profile reportHome
ml_estpdf (4 calls, 0.030 sec)
Generated 05-Nov-2014 07:52:30 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/3D/vesicles/ml_estpdf.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
134 | [f.mu,f.sigma] = normfit(x); | 3 | 0.020 s | 66.7% |  |
145 | param = ml_initparam(param, st... | 1 | 0.010 s | 33.3% |  |
195 | f2 = f; | 4 | 0 s | 0% |  |
171 | end | 1 | 0 s | 0% |  |
170 | end | 1 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 0.030 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
65 | RMFIELD output must be assigned back to the structure. |
90 | The variable 'fs' appears to change size on every loop iteration. Consider preallocating for speed. |
100 | The variable 'y' appears to change size on every loop iteration. Consider preallocating for speed. |
101 | The variable 'lks' appears to change size on every loop iteration. Consider preallocating for speed. |
112 | The value assigned here to 'maxlk' appears to be unused. Consider replacing it by ~. |
126 | The variable 'y' appears to change size on every loop iteration. Consider preallocating for speed. |
133 | Use && instead of & as the AND operator in (scalar) conditional statements. |
149 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
163 | Use && instead of & as the AND operator in (scalar) conditional statements. |
179 | The value assigned here to 'occ1' appears to be unused. Consider replacing it by ~. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 195 |
Non-code lines (comments, blank lines) | 65 |
Code lines (lines that can run) | 130 |
Code lines that did run | 27 |
Code lines that did not run | 103 |
Coverage (did run/can run) | 20.77 % |
Function listing
time calls line
1 function f2 = ml_estpdf(x,f,param)
2 %ML_ESTPDF Estimate the distribution from data.
3 % F2 = ML_ESTPDF(X,F) returns a [pdf], which is the estimation of the
4 % [partial pdf] F on data X. If it is a univariate distribution, X must
5 % be a column vector. If it is a multivariate distribution, X must be a
6 % [feature matrix].
7 % Notice: Although F.transform is usually a [general function], there is
8 % one exception. F.transform will do PCA transformation when the name is
9 % '_pca'. The number of PCA components can be specified by the field
10 % 'ncomp' in F.transform.param.
11 %
12 % F2 = ML_ESTPDF(X,F,PARAM) specifies how to estimate the distribution.
13 % PARAM is a structure. Currently it is only available for the 'mvn' pdf.
14 % If F.name is 'mvn', then PARAM has the following field:
15 % 'weights' - weights of the samples. It should have same number of
16 % rows as that of X.
17 % 'tz_estcov' - the parameter for ML_ESTCOV, which is used to
18 % estimate the covariance matrix. This is only useful when the
19 % [pdf] F has unknown covariance matrix. But the 'weights'
20 % field in 'tz_estcov' has no effect.
21 %
22 % See also ML_PDF ML_RND
23
24 % 03-Aug-2006 Initial write T. Zhao
25 % Copyright (c) 2006 Murphy Lab
26 % Carnegie Mellon University
27 %
28 % This program is free software; you can redistribute it and/or modify
29 % it under the terms of the GNU General Public License as published
30 % by the Free Software Foundation; either version 2 of the License,
31 % or (at your option) any later version.
32 %
33 % This program is distributed in the hope that it will be useful, but
34 % WITHOUT ANY WARRANTY; without even the implied warranty of
35 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 % General Public License for more details.
37 %
38 % You should have received a copy of the GNU General Public License
39 % along with this program; if not, write to the Free Software
40 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
41 % 02110-1301, USA.
42 %
43 % For additional information visit http://murphylab.web.cmu.edu or
44 % send email to murphy@cmu.edu
45
46
4 47 if nargin < 2
48 error('At least 2 arguments are required');
49 end
50
4 51 if ~exist('param','var')
4 52 param = struct([]);
4 53 end
54
4 55 ml_estpdf_checkvar(size(x,2),f.name);
56
4 57 if isfield(f,'transform')
58 if strcmp(f.transform.funname,'_pca')
59 f.transform.funname = 'ml_pcatrans';
60 f.transform.param.basevec = princomp(x);
61 if isfield(f.transform,'param')
62 if isfield(f.transform.param,'ncomp')
63 f.transform.param.basevec = ...
64 f.transform.param.basevec(:,1:f.transform.param.ncomp);
65 rmfield(f.transform.param,'ncomp');
66 end
67 end
68 f.transform.param.offset = mean(x,1);
69 f.mu = zeros(1,size(f.transform.param.basevec,2));
70 end
71 x = ml_evalfun(x,f.transform);
72 end
73
4 74 switch f.name
4 75 case 'trunc' %truncated function
76 f = ml_initparam(f,struct('a1',min(x),'a2',max(x)));
77 param = ml_initparam(param,struct('iter',100,'isshow',0));
78 if f.a1>f.a2
79 error(['The left bound should ' ...
80 'not be greater than the right round']);
81 end
82
83 y = x;
84 f2 = f;
85 fs = {};
86 lks = [];
87 for k=1:param.iter
88 comppdf = ml_estpdf(y,f.comppdf);
89 f2.comppdf = comppdf; %intermediate results
90 fs{k} = f2;
91
92 cdf1 = ml_cdf(f.a2,comppdf) - ml_cdf(f.a1,comppdf);
93 n = round(length(x)/cdf1);
94 y = ml_rnd(comppdf,n);
95
96 y(y>f.a1 & y<f.a2) = [];
97 if isempty(y) %no new data points
98 break;
99 end
100 y = [y;x];
101 lks = [lks ml_loglk(x,f2)];
102
103 if param.isshow==1
104 subplot(1,2,1)
105 ml_histpdfplot(x,f2);
106 subplot(1,2,2)
107 plot(lks)
108 drawnow
109 end
110 end
111 if ~isempty(lks)
112 [maxlk,idx] = max(lks);
113 f = fs{idx(1)};
114 else
115 f = fs{1};
116 end
4 117 case 'tnorm' %truncated normal distribution
118 y = x;
119 a1 = min(x);
120 for k=1:50
121 f = ml_estpdf(y,struct('name','norm'));
122 cdf1 = normcdf(a1,f.mu,f.sigma);
123 n = round(length(x)/(1-cdf1));
124 y = ml_rnd(f,struct('n',n));
125 y(y>a1) = [];
126 y = [y;x];
127 ml_histpdfplot(y,f);
128 drawnow;
129 end
130 f.name = 'tnorm';
131 f.a1 = a1;
4 132 case 'norm' %normal distribution
3 133 if ~isfield(f,'mu') & ~isfield(f,'sigma')
0.02 3 134 [f.mu,f.sigma] = normfit(x);
135 else
136 if ~isfield(f,'mu')
137 f.mu = mean(x);
138 end
139
140 if ~isfield(f,'sigma')
141 f.sigma = sqrt(sum((x-f.mu).^2)/(length(x)-1));
142 end
143 end
1 144 case 'mvn' %multivariate norml distribution
0.01 1 145 param = ml_initparam(param, struct('tz_estcov', ...
146 struct('method','mle'),'weights',[]));
147
1 148 if isfield(param.tz_estcov,'weights')
149 warning(['The field ''weight'' in param.tz_estcov has no ' ...
150 'effect']);
151 param.tz_estcov.weights = param.weights;
152 end
153
1 154 if ~isfield(f,'mu')
1 155 if isempty(param.weights)
1 156 f.mu = mean(x,1);
157 else
158 f.mu = weights'*x/sum(weights);
159 end
160
1 161 end
162
1 163 if ~isfield(f,'mu') & ~isfield(f,'sigma')
164 f.sigma = ml_estcov(x,param.tz_estcov);
1 165 else
1 166 if ~isfield(f,'sigma')
1 167 param.tz_estcov.mu = f.mu;
1 168 f.sigma = ml_estcov(x,param.tz_estcov);
169 %f.sigma = ml_cov(x,0,[],f.mu);
1 170 end
1 171 end
172 case 'gamma'
173 parmhat = gamfit(x);
174 f.alpha = parmhat(1);
175 f.beta = parmhat(2);
176 case 'exp'
177 f.beta = expfit(x);
178 case 'hist'
179 [f.hist,occ1,occ2] = unique(x,'rows');
180 f.hist(:,end+1) = ml_countnum(occ2)'/size(x,1);
181 case 'mix'
182 switch param.mixname
183 case 'gmm' %gaussian mixture
184 f = ml_gmmfit(x,param);
185 otherwise
186 error('Unrecognized mixture model name');
187 end
188 case 'bicond'
189 f.pdf1 = ml_estpdf(x(:,1),f.pdf1);
190 f.pdf2 = ml_estpdf(ml_evalfun({x(:,2),x(:,1)},f.relation),f.pdf2);
191 otherwise
192 error(['Unrecognized pdf:' f.name]);
193 end
194
4 195 f2 = f;
Other subfunctions in this file are not included in this listing.