LossFunctions.jl is a Julia package that provides efficient and well-tested implementations for a diverse set of loss functions that are commonly used in Machine Learning.
Package Status | Package Evaluator | Build Status |
---|---|---|
Distance-based (Regression) | Margin-based (Classification) |
---|---|
Others: PeriodicLoss
, PoissonLoss
, ScaledLoss
The following code snippets show a simple "hello world" scenario
of how a Loss
can be used to compute the element-wise values.
using LossFunctions
true_targets = [ 1, 0, -2]
pred_outputs = [0.5, 1, -1]
value(L2DistLoss(), true_targets, pred_outputs)
3-element Array{Float64,1}:
0.25
1.0
1.0
Alternatively, one can also use the loss like a function
myloss = L2DistLoss()
myloss(true_targets, pred_outputs) # same result as above
The function signatures of value
also apply to the derivatives.
deriv(L2DistLoss(), true_targets, pred_outputs)
3-element Array{Float64,1}:
-1.0
2.0
2.0
Additionally, we provide mutating versions of most functions.
buffer = zeros(3)
deriv!(buffer, L2DistLoss(), true_targets, pred_outputs)
If need be, one can also compute the mean- or sum-value efficiently, without allocating a temporary array.
# or meanvalue
sumvalue(L2DistLoss(), true_targets, pred_outputs)
0.75
Note that this only shows a small part of the functionality this package provides. For more information please have a look at the documentation.
Check out the latest documentation
Additionally, you can make use of Julia's native docsystem.
The following example shows how to get additional information
on HingeLoss
within Julia's REPL:
?HingeLoss
This package is registered in METADATA.jl
and can be installed as usual
Pkg.add("LossFunctions")
This code is free to use under the terms of the MIT license.