From 2a9da9e90db59d487878eaca1bdfecf4bdb0b57d Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 14 Nov 2024 16:23:45 -0500 Subject: [PATCH 1/3] Fix log_mix signature --- .../real-valued_basic_functions.qmd | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/functions-reference/real-valued_basic_functions.qmd b/src/functions-reference/real-valued_basic_functions.qmd index 5eab3cc22..1b5b83cc1 100644 --- a/src/functions-reference/real-valued_basic_functions.qmd +++ b/src/functions-reference/real-valued_basic_functions.qmd @@ -1601,7 +1601,7 @@ The logarithm of one minus the natural exponentiation of x Return the natural logarithm of the difference of the natural exponentiation of x and the natural exponentiation of y. \begin{equation*} \mathrm{log\_diff\_exp}(x,y) = \begin{cases} \log(\exp(x)-\exp(y)) & -\text{if } +\infty > x \ge y \\[6pt] +\text{if } +\infty > x \ge y \\[6pt] \textrm{NaN} & \text{otherwise} \end{cases} \end{equation*} @@ -1628,11 +1628,16 @@ proportion theta, defined by \begin{eqnarray*} \lambda_1, \ \log(1 - \theta) + \lambda_2\right). \end{eqnarray*} {{< since 2.6 >}} - -\index{{\tt \bfseries log\_mix }!{\tt (T1 theta, T2 lp1, T3 lp2): real}|hyperpage} + +\index{{\tt \bfseries log\_mix }!{\tt (T1 thetas, T2 lps): real}|hyperpage} + +`R` **`log_mix`**`(T1 thetas, T2 lps)`
\newline + +Extension of the two-mixture case above to more densities. +Return the log mixture of the log densities stored in `lps`, +where each log density has the mixing proportion given by +the same index in `thetas`. -`R` **`log_mix`**`(T1 theta, T2 lp1, T3 lp2)`
\newline -Vectorized implementation of the `log_mix` function {{< since 2.26 >}} From 48d6b882272cb640ef3cf980b88cd4870248e325 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 14 Nov 2024 16:26:34 -0500 Subject: [PATCH 2/3] Example --- src/functions-reference/real-valued_basic_functions.qmd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions-reference/real-valued_basic_functions.qmd b/src/functions-reference/real-valued_basic_functions.qmd index 1b5b83cc1..43dcd886b 100644 --- a/src/functions-reference/real-valued_basic_functions.qmd +++ b/src/functions-reference/real-valued_basic_functions.qmd @@ -1638,6 +1638,9 @@ Return the log mixture of the log densities stored in `lps`, where each log density has the mixing proportion given by the same index in `thetas`. +In other words, `log_mix(a,b,c)` could be equivalent written +to use this signature by writing `log_mix({a, 1-a}, {b, c})`. + {{< since 2.26 >}} From dbf2884cc22cb42b658170bfa8e1ac53cb9eb110 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 15 Nov 2024 10:03:40 -0500 Subject: [PATCH 3/3] Update prose for log_mix --- .gitattributes | 1 + src/functions-reference/functions_index.qmd | 17 ++++++++++++++- .../real-valued_basic_functions.qmd | 21 ++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..9a47cffcd --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +src/functions-reference/functions_index.qmd linguist-generated=true diff --git a/src/functions-reference/functions_index.qmd b/src/functions-reference/functions_index.qmd index 369ee9e6a..0d999b019 100644 --- a/src/functions-reference/functions_index.qmd +++ b/src/functions-reference/functions_index.qmd @@ -289,6 +289,21 @@ pagetitle: Alphabetical Index -
[`(reals theta | reals alpha, reals beta) : real`](continuous_distributions_on_0_1.qmd#index-entry-340181b236cc79820c87cfca7dc7e8d9ef5bdf6e) (continuous_distributions_on_0_1.html)
+**beta_neg_binomial**: + + -
[distribution statement](unbounded_discrete_distributions.qmd#index-entry-0c7465aa1beceb6e7e303af36b60e2b847fc562a) (unbounded_discrete_distributions.html)
+ + +**beta_neg_binomial_lpmf**: + + -
[`(ints n | reals r, reals alpha, reals beta) : real`](unbounded_discrete_distributions.qmd#index-entry-9d835cd7ed67218478d70e1db49912bf2d710a1e) (unbounded_discrete_distributions.html)
+ + +**beta_neg_binomial_lupmf**: + + -
[`(ints n | reals r, reals alpha, reals beta) : real`](unbounded_discrete_distributions.qmd#index-entry-1bd0b7fec4d1f3e315d4328c1844d15641058615) (unbounded_discrete_distributions.html)
+ + **beta_proportion**: -
[distribution statement](continuous_distributions_on_0_1.qmd#index-entry-9e3ba228a8bb07d871e13efa26340614b125cd7f) (continuous_distributions_on_0_1.html)
@@ -1694,7 +1709,7 @@ pagetitle: Alphabetical Index **log_mix**: -
[`(real theta, real lp1, real lp2) : real`](real-valued_basic_functions.qmd#index-entry-569bcea73548d03bb5791681fcc60ee056c259b3) (real-valued_basic_functions.html)
- -
[`(T1 theta, T2 lp1, T3 lp2) : R`](real-valued_basic_functions.qmd#index-entry-2a36a682590acfceeb277b003f5f529fa3ccd882) (real-valued_basic_functions.html)
+ -
[`(T1 thetas, T2 lps) : R`](real-valued_basic_functions.qmd#index-entry-83690ccdb1ecc891d26739b85cb08f317eece075) (real-valued_basic_functions.html)
**log_modified_bessel_first_kind**: diff --git a/src/functions-reference/real-valued_basic_functions.qmd b/src/functions-reference/real-valued_basic_functions.qmd index 43dcd886b..e3848c507 100644 --- a/src/functions-reference/real-valued_basic_functions.qmd +++ b/src/functions-reference/real-valued_basic_functions.qmd @@ -1633,13 +1633,20 @@ proportion theta, defined by \begin{eqnarray*} `R` **`log_mix`**`(T1 thetas, T2 lps)`
\newline -Extension of the two-mixture case above to more densities. -Return the log mixture of the log densities stored in `lps`, -where each log density has the mixing proportion given by -the same index in `thetas`. - -In other words, `log_mix(a,b,c)` could be equivalent written -to use this signature by writing `log_mix({a, 1-a}, {b, c})`. +Calculates the log mixture density given `thetas`, +mixing proportions which should be between 0 and 1 and sum to 1, +and `lps`, log densities. +These two containers must have the same length. + +\begin{eqnarray*} +\mathrm{log\_mix}(\theta, \lambda) +& = & \log \!\left( \sum_{n=1}^N \theta_n * \exp(\lambda_n) \right) \\[3pt] +& = & \mathrm{log\_sum\_exp}\!\left(\log(\theta) + \lambda\right). +\end{eqnarray*} + +This is a generalization of the above signature of three arguments to +more than two densities. +For example, `log_mix(lambda, lp1, lp2) == log_mix({lambda, 1 - lambda}, {lp1, lp2})`. {{< since 2.26 >}}