Log-ish

I saw a post online this morning that recomended the transformation

f(x) = \left\{ \begin{array}{ll} \log(1+x) & \mbox{if } x > 0 \\ x & \mbox{if } x \leq 0 \end{array} \right.

I could see how this could be very handy. Often you want something like a logarithmic scale, not for the exact properties of the logarithm but because it brings big numbers closer in. And for big values of x there’s little difference between log(x) and log(1 + x).

The function above is linear near the origin, literally linear for negative values and approximately linear for small positive values.

I’ve occasionally needed something like a log scale, but one that would handle values that dip below zero. This transformation would be good for that. If data were equally far above and below zero, I’d use something like arctangent instead.

Notice that the function has a noticeable bend around 0. The next post addresses this.

2 thoughts on “Log-ish

  1. We can get a C∞ function if we use for instance log( softplus(x) ) = log( log(1 + exp(x))) instead. Looks very similar, but smoother.

  2. arcsinh can also be a useful function in similar circumstances, but it behaves logarithmically in both directions, so for large positive and large negative values.

Leave a Reply

Your email address will not be published. Required fields are marked *