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

Convolution between Gaussian mixture model and normal distribution #1921

Open
Alexander-Barth opened this issue Dec 5, 2024 · 0 comments
Open

Comments

@Alexander-Barth
Copy link

It would be nice to allow the convolution between Gaussian mixture model and normal distribution, for example:

using Distributions # v0.25.113

d1 = MixtureModel(Normal, [(-2.0, 1.0), (2.0, 1.0)],[0.5,0.5])
d2 = Normal(0,1)

convolve(d1,d2)

Currently, this fails with:

ERROR: MethodError: no method matching convolve(::MixtureModel{Univariate, Continuous, Normal, Categorical{Float64, Vector{Float64}}}, ::Normal{Float64})

Support for this would be quite easy to add:

import Distributions: convolve, MixtureModel
# special case: https://mathoverflow.net/questions/370982/convolution-of-two-gaussian-mixture-model
Distributions.convolve(d1::MixtureModel,d2::Normal) =
    MixtureModel([convolve(c,d2) for c in d1.components],d1.prior)
Distributions.convolve(d1::Normal,d2::MixtureModel) = convolve(d2,d1)

d3 = convolve(d1,d2)

using Test

@test var(d3.components[1])  2
@test var(d3.components[2])  2
@test mean(d3.components[1])  -2
@test mean(d3.components[2])  2
@test convolve(d1,d2) == convolve(d2,d1)

I can easily made a PR with the test case.

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

No branches or pull requests

1 participant