kunal18
kunal18

Reputation: 1926

delta value while calculating logarithm

I am using a formula to calculate a parameter, the formula involves taking logarithm of a value which can be zero at times. To handle such case, I read in literature the technique to put some delta value as follows:

ln(delta + A)

Here, the paramter A is a real number ranging from [0, 1].

What value I should assign to delta? Shall I assign delta = 1, so that ln(delta + A) will return 0 whenever A is 0?

Further, is there any rule of choice for using natural logarithm or base10 or base2 logarithm?

Following is the formula I am using:

Lw = exp[ 1 / N( sum[ log( delta + Lw( x, y ) ) ] ) ]

Please refer to this link for explanation: Log average luminance

Upvotes: 1

Views: 1638

Answers (1)

Phil H
Phil H

Reputation: 20141

Without knowing what the range of A is, it is hard to answer.

If A is generally an integer, but happens to sometimes be 0, then returning log(A + 1) will do what you want, but return 0 when A is 0. The question is what impact it will have on the use of the answer if you use log(A + 1) instead of log(A), since they are mathematically different.

-- Edit --

For A as a real value in the range [0,1], the value of log(A) would be negative anyway. The sensible answer for log(0) in that circumstance is -Infinity. Most programming languages use the IEEE 754 standard for representing floating point values, and that standard includes a value for -Infinity as one of the special values. Using -Infinity here would preserve monotonicity, i.e. log(a) < log(b) if a < b, even if a == 0.

The code would depend on the implementation of log in use; unless it is certain that log(0) would return -Infinity, the obvious thing to do is just check:

if(A == 0)
   result = -INFINITY; // macro in math.h
else
   result = log(A); 

as a (GNU) C example.

Upvotes: 1

Related Questions