Approximate $\log(1-e^x)$ where $x<0$

2.7k Views Asked by At

The title is pretty self-explanatory,

I need to calculate the logit function ($x=\log(p)$): $$x-\log(1-e^x)$$ Where $x<0$,

And my problem is to approximate $$\log(1-e^x)$$

I was thinking of using the Taylor expansion: $$\log(1-t) = - \sum^{\infty}_{n=1} \frac{t^n}n\quad\text{ for } |t| < 1$$ Where $t=e^x$

But I doesn't seem to be too helpful

2

There are 2 best solutions below

0
On BEST ANSWER

'my problem is to approximate' - this strongly depends on what exactly you want to do, e.g. approximate around which value. For $t \approx 0 \ \log(1-t) \sim -t +\frac{t^2}{2}$ if $t$ is positive. BTW in the expansion you gave $t=-1$ works too.

0
On

Assuming you have access to the IEEE recommended function $\mathrm{log1p}$ or sometimes $\mathrm{logp1}$ or $\mathrm{ln1p}$ defined by $\mathrm{log1p}(p)=\log(1+p),\,$ I can give a numerical stable evaluation of the usual function $$\mathrm{logit}(p)=\log \frac{p}{1-p}$$ The instable/inaccurate region is near $p=1/2$. You can safely use the definition for $p<1/3$ or $p > 2/3$ otherwise compute $$\mathrm{logit}(p)=\log \frac{p}{1-p}=\log \frac{1-p+2p-1}{1-p} =\log \left( 1 +\frac{2p-1}{1-p}\right)=\mathrm{log1p}\left(\frac{2p-1}{1-p}\right)$$

BTW: The $\mathrm{log1p}$ is availabe for many progamming languages, it is accuarate even at arguments near zero.