Skip to content

Inconsistency with integer valued floats on binomial and multinomial distributions #2040

@mauricelanghinrichs

Description

@mauricelanghinrichs

Not a major issue, but I observed inconsistent behaviour on how the binomial and multinomial distributions behave on integer valued floats for the trial number $n$. For example, $n=10.0$ works for

julia> rand(Binomial(10.0, 0.6))
7

but will fail in the equivalent multinomial expression:

julia> rand(Multinomial(10.0, [0.6, 0.4]))
ERROR: MethodError: no method matching Multinomial(::Float64, ::Vector{Float64})
The type `Multinomial` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  Multinomial(::Integer, ::AbstractVector{T}; check_args) where T<:Real
   @ Distributions ~/.julia/packages/Distributions/xMnxM/src/multivariate/multinomial.jl:28
  Multinomial(::Integer, ::Integer; check_args)
   @ Distributions ~/.julia/packages/Distributions/xMnxM/src/multivariate/multinomial.jl:37

Stacktrace:
 [1] top-level scope
   @ REPL[37]:1

I feel they should be consistent. And, in my view, preferably, the multinomial implementation should handle these cases as the binomial version.

Maybe there are specific reasons for the current implementation however that I'm not aware of. There might be similar issues for other distributions; I don't know and did not check systematically.

EDIT:
I found the code for the binomial version on real n to be in scr/deprecates.jl:

function Binomial(n::Real, p::Real)
    Base.depwarn("Binomial(n::Real, p) is deprecated. Please use Binomial(n::Integer, p) instead.", :Binomial)
    Binomial(Int(n), p)
end

However, I didn't obtain a deprecation warning on my system (VS code) so that the implementation looked intentional to me..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions