I'm trying to compute the log of the mean of some very small values. For the current data set, the extreme points are
log_a=-1.6430e+03;
log_b=-3.8278e+03;
So in effect I want to compute (a+b) / 2
, or log((a+b)/2)
since I know (a+b)/2
is too small to store as a double.
I considered trying to pad everything by a constant, so that instead of storing log_a
I'd store log_a+c
, but it seems that a
and b
are far enough apart that in order to pad log_b
enough to make exp(log_b+c)
computable, I'd end up making exp(log_a+c)
too large.
Am I missing some obvious way to go about this computation? As far as I know MATLAB won't let me use anything but double precision, so I'm stumped as to how I can do this simple computation.
EDIT: To clarify: I can compute the exact answer for these specific values. For other runs of the algorithm, the values will be different and might be closer together. So far there have been some good suggestions for approximations; if an exact solution isn't practical, are there any other approximations for more general numbers/magnitudes of values?
(exp(log_a) + exp(log_b)) / 2
just be the average ofa
andb
? The log of the mean of the original values would be more likelog((a+b)/2)
(although to get the mean of the values, you can't just take the extrema and average them).a
andb
, but I know that botha
andb
are too small to represent as doubles, so I am in effect looking forlog((a+b)/2)
rather than(a+b)/2
.a
andb
are so different, adding them together won't actually affect the value ofa
for several hundred decimal places (well outside double precision), solog((a+b)/2)
degrades tolog(a/2)
orlog_a-log(2)
.