comparison toolboxes/FullBNT-1.0.7/KPMtools/logsum_simple.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 result = logsum(logv)
2
3 len = length(logv);
4 if (len<2);
5 error('Subroutine logsum cannot sum less than 2 terms.');
6 end;
7
8 % First two terms
9 if (logv(2)<logv(1)),
10 result = logv(1) + log( 1 + exp( logv(2)-logv(1) ) );
11 else,
12 result = logv(2) + log( 1 + exp( logv(1)-logv(2) ) );
13 end;
14
15 % Remaining terms
16 for (i=3:len),
17 term = logv(i);
18 if (result<term),
19 result = term + log( 1 + exp( result-term ) );
20 else,
21 result = result + log( 1 + exp( term-result ) );
22 end;
23 end