{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/369","labels_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/369/comments","events_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/369/events","html_url":"https://github.com/JuliaStats/Distributions.jl/issues/369","id":73793776,"number":369,"title":"cdf for MixtureModel{Univariate}","user":{"login":"JockLawrie","id":11449078,"avatar_url":"https://avatars.githubusercontent.com/u/11449078?v=3","gravatar_id":"","url":"https://api.github.com/users/JockLawrie","html_url":"https://github.com/JockLawrie","followers_url":"https://api.github.com/users/JockLawrie/followers","following_url":"https://api.github.com/users/JockLawrie/following{/other_user}","gists_url":"https://api.github.com/users/JockLawrie/gists{/gist_id}","starred_url":"https://api.github.com/users/JockLawrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JockLawrie/subscriptions","organizations_url":"https://api.github.com/users/JockLawrie/orgs","repos_url":"https://api.github.com/users/JockLawrie/repos","events_url":"https://api.github.com/users/JockLawrie/events{/privacy}","received_events_url":"https://api.github.com/users/JockLawrie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-07T01:21:20Z","updated_at":"2015-05-07T10:27:40Z","closed_at":null,"body":"Hi there,\r\n\r\nI have written a cdf for univariate mixture models defined on the real line - see below.\r\nThe underlying math is valid for any other univariate mixture model, however I can't get the function working with x being a more generic type than Float64. For example, x::Int should work for mixtures of Poisson distributions. How can I get it working for say x::Real or x::Number, or just x?\r\n\r\nCheers,\r\nJock\r\n\r\n```julia\r\nimport Distributions.cdf    # Necessary to extend cdf to MixtureModel types\r\n\r\nfunction cdf(d::MixtureModel{Univariate}, x::Float64)\r\n    # cdf for UnivariateMixture\r\n    result = 0.0\r\n    comps  = components(d)\r\n    pr     = probs(d)\r\n    nc     = size(comps, 1)    # Number of componenets\r\n    for i = 1:nc\r\n        result += (pr[i] * cdf(comps[i],  x))\r\n    end\r\n    result\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/comments/99807228","html_url":"https://github.com/JuliaStats/Distributions.jl/issues/369#issuecomment-99807228","issue_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/369","id":99807228,"user":{"login":"simonbyrne","id":1692009,"avatar_url":"https://avatars.githubusercontent.com/u/1692009?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbyrne","html_url":"https://github.com/simonbyrne","followers_url":"https://api.github.com/users/simonbyrne/followers","following_url":"https://api.github.com/users/simonbyrne/following{/other_user}","gists_url":"https://api.github.com/users/simonbyrne/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbyrne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbyrne/subscriptions","organizations_url":"https://api.github.com/users/simonbyrne/orgs","repos_url":"https://api.github.com/users/simonbyrne/repos","events_url":"https://api.github.com/users/simonbyrne/events{/privacy}","received_events_url":"https://api.github.com/users/simonbyrne/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T10:27:40Z","updated_at":"2015-05-07T10:27:40Z","body":"The problem is that if you define a `cdf(d::MixtureModel{Univariate}, x::Real)` method, you get ambiguous dispatch warnings. You can try defining\r\n```julia\r\ncdf(d::MixtureModel{Univariate,Discrete},x::Int) = invoke(cdf, (MixtureModel{Univariate},Real), d, x)\r\n```\r\nfirst, then define\r\n```julia\r\nfunction cdf(d::MixtureModel{Univariate}, x::Real)\r\n    # cdf for UnivariateMixture\r\n    result = 0.0\r\n    comps  = components(d)\r\n    pr     = probs(d)\r\n    nc     = size(comps, 1)    # Number of componenets\r\n    for i = 1:nc\r\n        result += (pr[i] * cdf(comps[i],  x))\r\n    end\r\n    result\r\nend\r\n```\r\n"}}