JuliaStats / Roadmap.jl

A centralized location for planning the direction of JuliaStats
35 stars 3 forks source link

Syntax for `fit!(model::ModelType, data,method = :mle)` #21

Open BenConnault opened 8 years ago

BenConnault commented 8 years ago

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.

nalimilan commented 8 years ago

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.

BenConnault commented 8 years ago

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.

BenConnault commented 8 years ago

re:

I think mle should be a variant of fit

(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.

Nosferican commented 6 years ago

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