How to deal with $e^{-x}$ when $x$ is too big ($x \gg 0$) and therefore $e^{-x}$ gives us a "prohibitive" value (computer context)?

62 Views Asked by At

I don't know how to formulate my question correctly but I'm going to try:

Suppose the following:

$\textbf{a} = e^{-101}$

$\textbf{b} = e^{-98}$

$\textbf{c} = e^{-97}$

$\textbf{W} = (\textbf{w}_0,\textbf{w}_1,\textbf{w}_2)$

$\textbf{w}_0 = \frac{\textbf{a}}{\textbf{a}+\textbf{b}+\textbf{c}}\quad$ $\textbf{w}_1 = \frac{\textbf{b}}{\textbf{a}+\textbf{b}+\textbf{c}}\quad$ $\textbf{w}_2 = \frac{\textbf{c}}{\textbf{a}+\textbf{b}+\textbf{c}}$

So:

$\textbf{W} \approx (0.01321289, 0.26538793, 0.72139918)$

$\textbf{W}$ is a probability density function: $\sum_i\textbf{W}_i = 1$

Now, suppose I am using a computer that cannot calculate with precision values under $e^{-70}$. For example:

$e^{-70} \approx 3.975449735908647\times 10^{-31}$ (good)

$e^{-70.1} = 0.0$ (bad)

$e^{-80} = 0.0$ (bad)

So, my computer, cannot calculate correctly $\textbf{W}$, because:

$\textbf{a} = e^{-101} = 0$

$\textbf{b} = e^{-98} = 0$

$\textbf{c} = e^{-97} = 0$

Therefore:

$\textbf{w}_0 = \frac{\textbf{a}}{\textbf{a}+\textbf{b}+\textbf{c}} = \infty$

$\textbf{w}_1 = \frac{\textbf{b}}{\textbf{a}+\textbf{b}+\textbf{c}} = \infty$

$\textbf{w}_2 = \frac{\textbf{c}}{\textbf{a}+\textbf{b}+\textbf{c}} = \infty$

I wonder how can I solve this issue. How to get correctly $\textbf{w}$ if I have that restriction ? (in real life the limit is bigger, not $e^{-70}$ but something like $e^{-745}$)

2

There are 2 best solutions below

0
On BEST ANSWER

If you just know that your numbers are very small but of the same order, you can simplify the fraction by writing $$ \frac{a}{a+b+c} = \frac{1}{1+\frac{b}{a}+\frac{c}{a}} $$ For instance $$ \frac{e^{-101}}{e^{-101}+e^{-97}+e^{-98}} = \frac{1}{1+e^{4}+e^3} $$

1
On

The functions you care about are independent of scaling the variables. So just multiply all of your values by $e^{101}.$