| 1 |
function [log_sum, log_max] = fn_logsum(log_sum, log_max, log_new) |
| 2 |
% [log_sum, log_max] = fn_logsum(log_sum, log_max, log_new) |
| 3 |
% |
| 4 |
%Outputs: |
| 5 |
% log_sum: updated log(sum of x_1, ..., x_{N+1}) |
| 6 |
% log_max: updated max of log(x_1), ..., log(x_{N+1}). |
| 7 |
%-------------- |
| 8 |
%Inputs: |
| 9 |
% log_sum: log(sum of x_1, ..., x_N) |
| 10 |
% log_max: max of log(x_1), ..., log(x_N). |
| 11 |
% log_new: log(x_{N+1}). |
| 12 |
% |
| 13 |
%Written by T. Zha; 12:20PM 06/28/2005 |
| 14 |
% |
| 15 |
% Copyright (C) 1997-2012 Tao Zha |
| 16 |
% |
| 17 |
% This free software: you can redistribute it and/or modify |
| 18 |
% it under the terms of the GNU General Public License as published by |
| 19 |
% the Free Software Foundation, either version 3 of the License, or |
| 20 |
% (at your option) any later version. |
| 21 |
% |
| 22 |
% It is distributed in the hope that it will be useful, |
| 23 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
% GNU General Public License for more details. |
| 26 |
% |
| 27 |
% If you did not received a copy of the GNU General Public License |
| 28 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 29 |
% |
| 30 |
|
| 31 |
|
| 32 |
%=== Updates log_sumpdf with an additional pdf value. See TVBVAR Notes p.81a. |
| 33 |
if (log_max>=log_new) |
| 34 |
log_sum = log( exp(log_sum-log_max) + exp(log_new-log_max) ) + log_max; |
| 35 |
else |
| 36 |
log_sum = log( exp(log_sum-log_new) + 1.0 ) + log_new; |
| 37 |
log_max = log_new; |
| 38 |
end |