Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log_mix signature #832

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/functions-reference/real-valued_basic_functions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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*}

Expand All @@ -1628,11 +1628,19 @@ proportion theta, defined by \begin{eqnarray*}
\lambda_1, \ \log(1 - \theta) + \lambda_2\right). \end{eqnarray*}
{{< since 2.6 >}}

<!-- R; log_mix; (T1 theta, T2 lp1, T3 lp2); -->
\index{{\tt \bfseries log\_mix }!{\tt (T1 theta, T2 lp1, T3 lp2): real}|hyperpage}
<!-- R; log_mix; (T1 thetas, T2 lps); -->
\index{{\tt \bfseries log\_mix }!{\tt (T1 thetas, T2 lps): real}|hyperpage}

`R` **`log_mix`**`(T1 thetas, T2 lps)`<br>\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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. thetas is presumably required to be a simplex, so that should be mentioned.
  2. thetas and lps have to be the same length, so that should be mentioned.
  3. The result should be given explicitly in math, e.g., log(SUM_n thetas[n] * exp(lps[n])) or the more efficient but also more opaque log_sum_exp(log(thetas) + lps) (it'd be OK to include both if you think just one would be confusing).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly enough, it doesn't seem that the math library is checking that thetas is a simplex, just that it is bounded between 0 and 1. Possibly worthy of a math issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

I would prefer this to say something about how this is intended to be looped across each density observation but is generalized to more than two densities. This connects the warning in the mixture modeling section about why we need to loop.


In other words, `log_mix(a,b,c)` could be equivalent written
WardBrian marked this conversation as resolved.
Show resolved Hide resolved
to use this signature by writing `log_mix({a, 1-a}, {b, c})`.

`R` **`log_mix`**`(T1 theta, T2 lp1, T3 lp2)`<br>\newline
Vectorized implementation of the `log_mix` function
{{< since 2.26 >}}

<!-- R; log_sum_exp; (T1 x, T2 y); -->
Expand Down