Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/logsum_simple.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function result = logsum(logv) |
matthiasm@8 | 2 |
matthiasm@8 | 3 len = length(logv); |
matthiasm@8 | 4 if (len<2); |
matthiasm@8 | 5 error('Subroutine logsum cannot sum less than 2 terms.'); |
matthiasm@8 | 6 end; |
matthiasm@8 | 7 |
matthiasm@8 | 8 % First two terms |
matthiasm@8 | 9 if (logv(2)<logv(1)), |
matthiasm@8 | 10 result = logv(1) + log( 1 + exp( logv(2)-logv(1) ) ); |
matthiasm@8 | 11 else, |
matthiasm@8 | 12 result = logv(2) + log( 1 + exp( logv(1)-logv(2) ) ); |
matthiasm@8 | 13 end; |
matthiasm@8 | 14 |
matthiasm@8 | 15 % Remaining terms |
matthiasm@8 | 16 for (i=3:len), |
matthiasm@8 | 17 term = logv(i); |
matthiasm@8 | 18 if (result<term), |
matthiasm@8 | 19 result = term + log( 1 + exp( result-term ) ); |
matthiasm@8 | 20 else, |
matthiasm@8 | 21 result = result + log( 1 + exp( term-result ) ); |
matthiasm@8 | 22 end; |
matthiasm@8 | 23 end |