3.14 Composed Functions
The functions in this section are equivalent in theory to combinations of other functions. In practice, they are implemented to be more efficient and more numerically stable than defining them directly using more basic Stan functions.
R
expm1
(T x)
natural exponential of x minus 1
real
fma
(real x, real y, real z)
Return z plus the result of x multiplied by y. \[ \text{fma}(x,y,z) =
(x \times y) + z \]
real
multiply_log
(real x, real y)
Warning: This function is deprecated and should be replaced with
lmultiply
. Return the product of x and the natural logarithm of y.
\[ \mathrm{multiply\_log}(x,y) = \begin{cases} 0 & \text{if } x = y =
0 \\ x \log y & \text{if } x, y \neq 0 \\ \text{NaN} &
\text{otherwise} \end{cases} \]
R
multiply_log
(T1 x, T2 y)
Vectorized implementation of the multiply_log
function
real
lmultiply
(real x, real y)
Return the product of x and the natural logarithm of y. \[
\text{lmultiply}(x,y) = \begin{cases} 0 & \text{if } x = y = 0 \\ x
\log y & \text{if } x, y \neq 0 \\ \text{NaN} & \text{otherwise}
\end{cases} \]
R
lmultiply
(T1 x, T2 y)
Vectorized implementation of the lmultiply
function
R
log1p
(T x)
natural logarithm of 1 plus x
R
log1m
(T x)
natural logarithm of 1 minus x
R
log1p_exp
(T x)
natural logarithm of one plus the natural exponentiation of x
R
log1m_exp
(T x)
logarithm of one minus the natural exponentiation of x
real
log_diff_exp
(real x, real y)
Return the natural logarithm of the difference of the natural
exponentiation of x and the natural exponentiation of y. \[
\mathrm{log\_diff\_exp}(x,y) = \begin{cases} \log(\exp(x)-\exp(y)) &
\text{if } x > y \\[6pt] \textrm{NaN} & \text{otherwise} \end{cases}
\]
R
log_diff_exp
(T1 x, T2 y)
Vectorized implementation of the log_diff_exp
function
real
log_mix
(real theta, real lp1, real lp2)
Return the log mixture of the log densities lp1 and lp2 with mixing
proportion theta, defined by \[\begin{eqnarray*}
\mathrm{log\_mix}(\theta, \lambda_1, \lambda_2) & = & \log \!\left(
\theta \exp(\lambda_1) + \left( 1 - \theta \right) \exp(\lambda_2)
\right) \\[3pt] & = & \mathrm{log\_sum\_exp}\!\left(\log(\theta) +
\lambda_1, \ \log(1 - \theta) + \lambda_2\right). \end{eqnarray*}\]
real
log_sum_exp
(real x, real y)
Return the natural logarithm of the sum of the natural exponentiation
of x and the natural exponentiation of y. \[
\mathrm{log\_sum\_exp}(x,y) = \log(\exp(x)+\exp(y)) \]
R
log_inv_logit
(T x)
natural logarithm of the inverse logit function of x
R
log1m_inv_logit
(T x)
natural logarithm of 1 minus the inverse logit function of x