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

Type signature of HeterogeneousMixture #500

Closed
mirkoklukas opened this issue Feb 15, 2023 · 1 comment · Fixed by #501
Closed

Type signature of HeterogeneousMixture #500

mirkoklukas opened this issue Feb 15, 2023 · 1 comment · Fixed by #501

Comments

@mirkoklukas
Copy link
Contributor

Gen's HeterogeneousMixture expects Vector{Distribution{T}} and doesn't know what to do with
Vector{D} where D "inherits" from Distribution{T}. Note that feeding [uniform, normal] is fine since it is converted to the common "supertype" and is treated as Vector{Distribution{T}}. However [D(),D()] is treated as Vector{D}.

This is an issue when you use GenDistributions.jl's DistributionsBacked or my PushForward type for instance.

The signature should be changed as follows:

# Current signature
HeterogeneousMixture(distributions::Vector{Distribution{T}}) where {T}
# Better signature, solving the issue.
HeterogeneousMixture(distributions::Vector{D}) where {T, D <: Distribution{T}}
@mirkoklukas
Copy link
Contributor Author

Example.
Code below throws MethodError: no method matching HeterogeneousMixture(::Vector{DistributionsBacked}).

using .GenDistributions
using Distributions
using Gen

const dirichlet = DistributionsBacked(alpha -> Dirichlet(alpha), (true,), true, Vector{Float64})
const flip      = DistributionsBacked(p -> Bernoulli(p), (true,), false, Bool) 

mix = HeterogeneousMixture([dirichlet,flip])

alex-lew added a commit that referenced this issue Mar 15, 2023
Type signature of HeterogeneousMixture, Closes #500
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 a pull request may close this issue.

1 participant