Distributions.Multinomial seems to accept a vector of probabilities that doesn’t sum to one, even if in the code reported in the documentation it should have ckeck_args true by default. Why is that ?
Looks like it changed in the the latest release (v0.21.6), at this commit. I’m not sure why the default for check_args isn’t being used here, but it does throw the expected error for check_args = true:
julia> using Distributions
julia> p_v = [0.1,0.4,0.3,0.8]
4-element Array{Float64,1}:
0.1
0.4
0.3
0.8
julia> isprobvec(p_v)
false
julia> Multinomial(10, p_v)
Multinomial{Float64,Array{Float64,1}}(n=10, p=[0.1, 0.4, 0.3, 0.8])
julia> Multinomial(10, p_v; check_args = true)
ERROR: ArgumentError: p = [0.1, 0.4, 0.3, 0.8] is not a probability vector.
Stacktrace:
[1] #Multinomial#114(::Bool, ::Type{Multinomial}, ::Int64, ::Array{Float64,1}) at /home/jkbest/.julia/packages/Distributions/ehx56/src/multivariate/multinomial.jl:32
[2] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:check_args,),Tuple{Bool}}, ::Type{Multinomial}, ::Int64, ::Array{Float64,1}) at ./none:0
[3] top-level scope at REPL[25]:1
Thanks for reporting this, this is due to the default constructors in parameterized structures, it has already bitten me off in Distributions. I’m running the test and pushing a patch now. https://github.com/JuliaStats/Distributions.jl/pull/1012