-
Notifications
You must be signed in to change notification settings - Fork 422
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
Generic support for uni gmm #615
Generic support for uni gmm #615
Conversation
These are now parametric types, you'll have to modify the constructors to account for the type parameter. The 0.5-compatible syntax is function (::Type{UnivariateGMM{T}}){T}(...)
...
end (Much nicer syntax for this is available in 0.6 but unfortunately it isn't compatible with 0.5.) |
Thank you for pointing this. I will make the change soon. I have a problem which I don't know if I can ask here - actually I failed to run the tests for Pkg.test("Distributions")
INFO: Computing test dependencies for Distributions...
ERROR: unsatisfiable package requirements detected: no feasible version could be found for package: ColorVectorSpace Do you know why this happens? |
I've seen that error once before with a different package. If |
Hi Alex, I fix the constructor now. I stoped working on this PR because I also meet some dependent problems - a group of functions used by uni gmm seems didn't support |
src/mixtures/unigmm.jl
Outdated
prior::Categorical | ||
|
||
function UnivariateGMM(ms::Vector{Float64}, ss::Vector{Float64}, pri::Categorical) | ||
(::Type{UnivariateGMM{T}}){T}(ms::Vector{T}, ss::Vector{T}, pri::Categorical) = begin |
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.
Why change from the long-form function
definition? That's generally preferable to begin
blocks for style.
src/mixtures/unigmm.jl
Outdated
end | ||
end | ||
|
||
UnivariateGMM{T<:Real}(ms::Vector{T}, ss::Vector{T}, pri::Categorical) = UnivariateGMM{T}(K, ms, ss, pri) |
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.
K
isn't defined here
Thx Alex. I found that I messed up 3 Distributions.jl forks on my local so I actually run tests on another commit. I will give another try to fix it. |
Ok, I think I meet the problem I see before: a lot of functions in
julia test/mixture.jl
testing UnivariateMixture
Test Failed
Expression: logpdf(g,X[i]) ≈ mix_lp0[i]
Evaluated: -Inf isapprox -2.0463780454938103
ERROR: LoadError: There was an error during testing
in record(::Base.Test.FallbackTestSet, ::Base.Test.Fail) at test.jl:397
in do_test(::Base.Test.Returned, ::Expr) at test.jl:281
in test_mixture(::Distributions.MixtureModel{Distributions.Univariate,Distributions.Continuous,Distributions.Normal}, ::Int64, ::Int64) at mixture.jl:56
in include_from_node1(::String) at loading.jl:488
in include_from_node1(::String) at sys.dylib:?
in process_options(::Base.JLOptions) at client.jl:265
in _start() at client.jl:321
in _start() at sys.dylib:?
while loading /Users/kai/projects/Turing/exps/Distributions.jl/test/mixture.jl, in expression starting on line 212 Can you give me some help and some general suggestions how to make things in |
Hi @xukai92 what's the status on this? Maybe you can keep going on this PR on Julia 1.0 and the latest Distributions master branch |
ping @xukai92 to move on this :) |
@matbesancon Thanks for pinging me! I'm on it now :) |
I disabled the tests for generic support of GMM for julia> d = Normal(Dual(0), Dual(1))
Normal{Dual{Nothing,Int64,0}}(μ=Dual{Nothing}(0), σ=Dual{Nothing}(1))
julia> rand(d, 10)
ERROR: MethodError: no method matching Float64(::Dual{Nothing,Float64,0})
Closest candidates are:
Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:194
Float64(::T<:Number) where T<:Number at boot.jl:741
Float64(::Int8) at float.jl:60
...
Stacktrace:
[1] convert(::Type{Float64}, ::Dual{Nothing,Float64,0}) at ./number.jl:7
[2] setindex!(::Array{Float64,1}, ::Dual{Nothing,Float64,0}, ::Int64) at ./array.jl:767
[3] rand! at /Users/kai/projects/Distributions.jl/src/univariates.jl:167 [inlined]
[4] rand at /Users/kai/projects/Distributions.jl/src/univariates.jl:160 [inlined]
[5] rand(::Normal{Dual{Nothing,Int64,0}}, ::Int64) at /Users/kai/projects/Distributions.jl/src/genericrand.jl:24
[6] top-level scope at none:0 |
@matbesancon Not sure why some tests for |
yes sadly we need #836 merged for this first |
not sure if we should do it here or in a following PR, but it would be good to replace |
Do yo mean making everything typed by |
yes exactly |
Also what was done in #837 for multivariate gaussians |
ping @xukai92 all good on this? |
src/mixtures/mixturemodel.jl
Outdated
@@ -135,13 +135,13 @@ function MixtureModel(components::Vector{C}, prior::Categorical) where C<:Distri | |||
MixtureModel{VF,VS,C}(components, prior) | |||
end | |||
|
|||
MixtureModel(components::Vector{C}, p::Vector{Float64}) where {C<:Distribution} = | |||
MixtureModel(components::Vector{C}, p::Vector{T}) where {C<:Distribution,T<:Real} = |
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.
Should we allow for any <:AbstractVector{<:Real}
?
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.
Is this the only place we need to change? Or we actually need make AT<: AbstractVector
part of the parameter of type MixtureModel
?
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.
yes exactly
@matbesancon suggestions fixed! Please take another review. |
Approved, merged in 12 hours if no objection |
Thanks for the help @matbesancon ! |
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.
No objection.
woops, 12 hours became 2 days, merged. Thanks for the contribution @xukai92 |
Add generic support for uni-gmm