JuliaML / LossFunctions.jl

Julia package of loss functions for machine learning.
https://juliaml.github.io/LossFunctions.jl/stable
Other
148 stars 34 forks source link

Introduce uniform interface for accessing loss function parameters #147

Open ablaom opened 2 years ago

ablaom commented 2 years ago

Perhaps I'm missing something, but this does not appear to exist at present. For most losses with a parameter, you access using property, as in

loss = HuberLoss(0.5)

julia> loss.d
0.5

But for an LPDistLoss there no field for p, only a type parameter:

julia> loss=LPDistLoss(2.5)
LPDistLoss{2.5}()

julia> propertynames(loss)
()

One suggestion would be overload Base.getproperty/Base.propertynames for cases of the second kind (I think these are just LPDistLoss, L1DistLoss, L2DistLoss, but I haven't checked lately), or to implement StatsBase.params or both.

I ran into this issue when wrapping the losses for use in MLJ and was obliged to write my own interface, which is not robust to extensions of LossFunctions.jl

juliohm commented 2 years ago

Yes, instead of fixing things with glue code downstream, it would be much better to have it fixed here. The situation described is not ideal, and we appreciate if you can try to improve the interface here instead of wrapping a new one in MLJ.jl next time 🙏🏽