2
$\begingroup$

What is the conversion of the following equation into log space?

$bf2 = 1 + (p * (bf1 - 1))$

Given log.bf1 (log Bayes factor), how do I get to log.bf2 without having to compute bf1, but instead using log.bf1?

Context: Numerical issues are arising because bf1 is often very large or very small. Hence, the computations are performed in log space to avoid numerical over/underflow.

$\endgroup$
4
  • $\begingroup$ Please explain what "numerical issues" are arising and (if possible) tell us why they happen. For instance, would it be because $\text{bf}_1$ is very large, very close to $0,$ very close to $1,$ or something else? $\endgroup$
    – whuber
    Jan 9, 2019 at 16:28
  • $\begingroup$ Thanks. I have added a clarification to the question. $\endgroup$ Jan 9, 2019 at 16:41
  • 1
    $\begingroup$ Have a look at how other people have defined functions such as log1p_exp, that should help. $\endgroup$
    – Björn
    Jan 9, 2019 at 16:44
  • $\begingroup$ Thank you, I'm currently using numerical work arounds like that. The aim of my question was check if there really aren't any mathematical tricks I could use instead. $\endgroup$ Jan 9, 2019 at 17:59

1 Answer 1

3
$\begingroup$

To simplify the notation, write $x$ for $\text{bf}_1$ and $x^\prime$ for $\text{bf}_2.$ By subtracting $1$ from each side, write their relation as

$$y^\prime = x^\prime - 1 = p(x - 1) = py.$$

Let $s = \operatorname{signum}(y)$ be the sign of $y$ (equal to $1$ when $y\gt 0,$ $-1$ when $y \lt 0,$ and $0$ when $y=0$). Multiplying by $s$ to make both sides nonnegative (assuming $p\ge 0$) allows us to take logarithms, giving

$$\log(s y^\prime) = \log(s y) + \log(p).$$

Thus,

By representing the information in terms of $s = \operatorname{signum}(x-1)$ together with $\eta = \log|x - 1|,$ the update step merely adds $\log(p)$ to $\eta.$ After a sequence of updates you can recover the final value of $x$ from the final value of $\eta$ as $$x = s \exp(\eta) + 1.$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.