| lambertW | R Documentation |
Solves W(x) e^{W(x)} = x for the principal branch W_0.
lambertW(x)
x |
vector of evaluation points, |
This implementation allows for automatic differentiation with RTMB.
The value is obtained by Halley iteration, which converges to machine
precision in a handful of steps over the whole domain. For AD, the function
is registered as an atomic operation via ADjoint with
the analytic derivative
W'(x) = \frac{1}{e^{W(x)} (1 + W(x))},
expressed through the returned value rather than through x. Written
this way the derivative is itself an AD-able expression, so derivatives of
every order are available; in particular the third-order derivatives that
the gradient of a Laplace approximation requires.
The principal branch is defined for x \ge -1/e, with
W_0(-1/e) = -1 and W_0(x) \ge -1 throughout. Values below
-1/e return NaN with a warning. The derivative is infinite at
the branch point x = -1/e.
The principal branch of the Lambert W function evaluated at x.
lambertW(exp(1)) # 1
lambertW(0) # 0
x <- c(0.5, 1, 10, 1000)
lambertW(x) * exp(lambertW(x)) - x # ~ 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.