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

proposal for mixture models #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

proposal for mixture models #53

wants to merge 2 commits into from

Conversation

bob-carpenter
Copy link
Collaborator

The feature proposal is in the file 0034-mixtures.md

@SteveBronder
Copy link
Collaborator

Rendered version

https://github.com/stan-dev/design-docs/blob/0034-mixtures/designs/0034-mixtures.md

@bob-carpenter
Copy link
Collaborator Author

Thanks, @SteveBronder. Does it render automatically or did you have to do something to turn it on?

@jsocolar
Copy link

Do you intend to support mixtures of distributions with different support (e.g. a mixture of a normal and a lognormal)?

@bob-carpenter
Copy link
Collaborator Author

Do you intend to support mixtures of distributions with different support (e.g. a mixture of a normal and a lognormal)?

Yes. There's an example of zero-inflated Poisson that mix a distribution with support at a single point with a mixture with support over all natural numbers.

Are there problems that arise in that setting we should consider? Even if there is, support isn't something that's known statically, so it'd have to be some kind of run-time check.

@jsocolar
Copy link

jsocolar commented Feb 15, 2024

Are there problems that arise in that setting we should consider?

If you pass a negative value to a lognormal_lpdf, I don't think you get back -Inf, but rather something like: Exception: lognormal_lpdf: Random variable is -1, but must be nonnegative!

So I think you'd either need to wrap the input lognormal inside a function that conditionally branches depending on whether you satisfy a support check (returning -Inf otherwise), or... ?

Edit: I think the example with the delta function on zero is an example of a function with support everywhere over the integers, and a return of -Inf everywhere except zero. Or am I misapprehending the way this all works?

Edit2: Maybe the exception is exactly the sort of runtime check you have in mind, and the solution is to force the user to define their own lpdf that implements the support check and branching logic.

@bob-carpenter
Copy link
Collaborator Author

Good point about returning exceptions. So we'll have to warn people about that.

Edit 1: Yes, that's right. We were torn when first building Stan between throwing exceptions and returning -inf for out of support args and went with the latter to make it easier for people to debug.

Edit 2: No, I just hadn't thought this through. But that is what it will force the user to do.

@WardBrian
Copy link
Member

the mixture_lpdf function could catch std::invalid_argument and return -infinity? That seems a bit too magical though, and definitely harder to debug

@jsocolar
Copy link

the mixture_lpdf function could catch std::invalid_argument and return -infinity? That seems a bit too magical though, and definitely harder to debug

Do arguments arguments of invalid type result in std::invalid_argument, or something else? If the former then I think this is a no-go.

@WardBrian
Copy link
Member

Depends on what you mean by “type”. It would also be thrown for example if you give a matrix that isn’t a cholesky factor to wishart_cholesky_lpdf

@jsocolar
Copy link

I mean would catching exceptions in this way allow people to end up passing integers to _lpdfs or reals to _lpmfs without seeing an exception raised?

@WardBrian
Copy link
Member

That kind of thing would be stopped by the compiler still. Invalid_argument is only used for runtime properties like bounds or requiring a matrix to be square

@bob-carpenter
Copy link
Collaborator Author

@jsocolar noted in an offline discussion that we need to include truncation contributions to the densities, too.

@bob-carpenter
Copy link
Collaborator Author

We also need a note about mixing pdfs and pmfs being illegal. You could wrap a pmf in a user-defined pdf, but Stan's not going to be able to handle sampling parameters that mix discrete and continuous distributions.

@bob-carpenter
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants