Distributions fit_mle of distribution type vs distributions with parameters

dmetivie
Wed, 26 Jan 2022 13:05:33 +0000
General Usage

I try the following, but it does not work.

using Distributions
p = 0.2
x = rand(Bernoulli(0.2),50)
fit_mle(Bernoulli(p), x)
 MethodError: no method matching fit_mle(::Bernoulli{Float64}, ::Vector{Bool})

I know that

fit_mle(Bernoulli, x)

works.
Adding the following seems to do what I want

function fit_mle(g::Distribution{Univariate,Discrete}, args...)
    fit_mle(typeof(g), args...)
end

function fit_mle(g::Distribution{Univariate,Continuous}, args...)
    fit_mle(typeof(g), args...)
end

However, I don’t understand why fit_mle(Bernoulli(p), x) is not authorized (or coded this way)?
Sure, the parameter p does not matter for the usual function where the MLE is explicit.
In my applications, I write extensions of fit_mle to other distributions where the actual parameter p is useful. It can be an initialization for an optimization algorithm.
Or when the distributions are Products or Mixture, the type is not enough and the whole distribution structure is needed.

7 posts - 3 participants