I’m attempting to construct an array of probability distributions of a single type based on arrays of parameters, then combine it with one or more distributions of a different type, then use this to construct a MixtureModel, but I’m having trouble getting the types right. Any help would be greatly appreciated.
Here is a MWE:
D = Vector{Distribution{Univariate, Continuous}}[]
μs = [0., 1.]
σs = [1., 2.]
for k=1:length(μs)
push!(D,Normal(μs[k],σs[k]))
end
push!(D,Gamma(2,3))
X = MixtureModel(D,[0.5, 0.2, 0.3])
MethodError: Cannot `convert` an object of type Normal{Float64} to an object of type Vector{Distribution{Univariate, Continuous}}
Closest candidates are:
convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N}
@ StaticArrays C:\Users\Monali\.julia\packages\StaticArrays\xEhFV\src\SizedArray.jl:88
convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, M, TData} where {M, TData<:AbstractArray{T, M}}) where {T, S, N}
@ StaticArrays C:\Users\Monali\.julia\packages\StaticArrays\xEhFV\src\SizedArray.jl:82
convert(::Type{T}, ::T) where T
@ Base Base.jl:84
...
Stacktrace:
[1] push!(a::Vector{Vector{Distribution{Univariate, Continuous}}}, item::Normal{Float64})
@ Base .\array.jl:1118
[2] top-level scope
@ .\In[101]:5
It also seems unintuitive to me that the following would be false:
a = [Normal(2,2), Gamma(2,2)]
b = typeof(a)[]
typeof(b)==typeof(a)