-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor clarifications.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thetas
is presumably required to be a simplex, so that should be mentioned.thetas
andlps
have to be the same length, so that should be mentioned.- 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 opaquelog_sum_exp(log(thetas) + lps)
(it'd be OK to include both if you think just one would be confusing).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 inthetas
.
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.
Yes, this should definitely be checked. I created an issue: |
I guess we shouldn't say it's checking, just that the first argument must be non-negative values that sum to 1. |
Thanks @WardBrian for fixing this, I have been annoyed by this for a long time and was constantly looking up what this does. In fact, I have a similar issue with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates.
Hi is there a place where we can look up types allowed for this function? This example here allowed theta as a vector (size K), and the ps the densities component as an array size N* K, basically using the same weight. I am curious if this function allows theta to be same N*K array so we can apply different weights to the densities of each data point. https://github.com/stan-dev/example-models/blob/master/basic_estimators/normal_mixture_k.stan |
That's what the doc update is addressing.
This is not supported according to the documentation Brian wrote above. It's just |
Thank you Bob! The doc update" meaning the user guide or the math library? I was hoping for some like R functions arguments specification in any R packages, but it is just nice to have you available to clarify. |
Yes, that's what I meant because that's what the doc said. I just tried that example and it compiled just fine. It also works with an array of different @WardBrian---the doc should mention that this can be vectorized in both arguments. It's not clear from the types, variable names, or example as rendered above. Yes, I meant we're updating the functions reference doc to reflect what's really going on. I just misunderstood the existing signatures. I'm not sure what you mean by "like R functions". |
I do not believe it can be. It appears the second argument ( So We don't really have any other functions quite like this, so how to describe it exactly might require some new convention |
Ah, I forgot to change my variable in my program. So these both compile: log_mix(vector, vector);
log_mix(vector, array[] vector); But these two don't: log_mix(array[] vector, vector);
log_mix(array[] vector, array[] vector); I think we should just describe it right in the doc for this function rather than trying to come up with an indirect convention. |
If I use below: log_mix(lambda, poisson_lpmf(y | pe),poisson_lpmf(y| pc)) is this desired { lambda[1]*f(y[1]|pe[1])+(1- lambda[1])f(y[1]|pc[1])} .... { lambda[n]*f(y[n]|pe[n])+(1- lambda[n])*f(y[n]|pc[n])} |
For Stan, |
Thank you Bob! |
@pmahling: We have a very active forum which is a better place to ask Stan questions than closed pull requests: https://discourse.mc-stan.org I think those would be equivalent, but I'm not 100% sure, so I'd try both to make sure they yield the same answer. Note: you can use |
Submission Checklist
<<{ since VERSION }>>
Summary
Closes #831. I'm happy to take further suggestions on the wording here.
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):
Simons Foundation
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: