Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMtools/em_converged.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [converged, decrease] = em_converged(loglik, previous_loglik, threshold, check_increased) | |
2 % EM_CONVERGED Has EM converged? | |
3 % [converged, decrease] = em_converged(loglik, previous_loglik, threshold) | |
4 % | |
5 % We have converged if the slope of the log-likelihood function falls below 'threshold', | |
6 % i.e., |f(t) - f(t-1)| / avg < threshold, | |
7 % where avg = (|f(t)| + |f(t-1)|)/2 and f(t) is log lik at iteration t. | |
8 % 'threshold' defaults to 1e-4. | |
9 % | |
10 % This stopping criterion is from Numerical Recipes in C p423 | |
11 % | |
12 % If we are doing MAP estimation (using priors), the likelihood can decrase, | |
13 % even though the mode of the posterior is increasing. | |
14 | |
15 if nargin < 3, threshold = 1e-4; end | |
16 if nargin < 4, check_increased = 1; end | |
17 | |
18 converged = 0; | |
19 decrease = 0; | |
20 | |
21 if check_increased | |
22 if loglik - previous_loglik < -1e-3 % allow for a little imprecision | |
23 fprintf(1, '******likelihood decreased from %6.4f to %6.4f!\n', previous_loglik, loglik); | |
24 decrease = 1; | |
25 converged = 0; | |
26 return; | |
27 end | |
28 end | |
29 | |
30 delta_loglik = abs(loglik - previous_loglik); | |
31 avg_loglik = (abs(loglik) + abs(previous_loglik) + eps)/2; | |
32 if (delta_loglik / avg_loglik) < threshold, converged = 1; end |