Skip to content

ChristianKurz/LossFunctions.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LossFunctions

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
License Documentation Status Pkg Eval 0.5 Pkg Eval 0.6 Build Status Build status Coverage Status

Available Losses

Distance-based (Regression) Margin-based (Classification)
distance_losses margin_losses

Others: PeriodicLoss, PoissonLoss, ScaledLoss

Example

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.

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

Installation

This package is registered in METADATA.jl and can be installed as usual

Pkg.add("LossFunctions")

License

This code is free to use under the terms of the MIT license.

About

Julia package for loss functions in machine learning.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%