Roadmap.jl
Roadmap.jl copied to clipboard
Syntax for `fit!(model::ModelType, data,method = :mle)`
In many models the parameters can be estimated by different methods. For instance a simple Beta(a,b) can be estimated by a method of moment or mle cf wikipedia.
It would be great to agree on a common syntax across JuliaStats for this. I am not aware of anything already in place. Optim.jl does fit!(model::ModelType, data,method = :mle)
. Thoughts?
Just to be 100% clear about my vocabulary, I take "fit!" to mean doing two things: (1) estimating the parameters of the model/distribution (2) setting the parameters of the model/distribution to be the estimated ones. Of course I am happy to hear opinions about that as well.
I think the two options are using a symbol or a type for the method
argument. The latter has the interest that the code will be specialized for the estimation method. I'm not sure this really matters in practice if fit!
is simply a wrapper which will call the corresponding fitting method. But it doesn't hurt, and it might be useful in some cases. So I think I'd vote for a type if there's no reason not to use this solution.
re: method=:mle
versus method=MleMethod
. Specialization sounds like a good argument although couldn't you specialize using a value type on a symbol or something?
An argument in favor of method=:mle
is syntax uniformity across Julia with Optim.jl and other packages. It would be good to know why other packages chose one option rather than the other when they made a decision.
re:
I think
mle
should be a variant offit
(in #20.)
mle
does only [(1) estimating the parameters] and does not [(2)setcoef!
afterwards]. For this reason I think it should not be called fit
.
I suspect "fit
" is sometimes used for (1) and sometimes used for [(1) + (2)]. This may be at the source of many confusions. I am strongly in favor of agreeing on one meaning and sticking to it.
The way I see fit!
is in the following context,
mutable struct MyStruct <: StatsBase.RegressionModel
predictors::AbstractMatrix
response::AbstractVector
parameterestimates::AbstractVector
estimationmethod::MyPkg.AbstractEstimationMethod
end
function StatsBase.fit!(obj::MyStruct)
setfield!(obj,
:ParameterEstimates,
solvingmodel(obj.predictors, obj.predictors, obj.estimationmethod))
return
end