losses

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrossEntropy

func CrossEntropy(g *ag.Graph, x ag.Node, c int) ag.Node

CrossEntropy implements a cross-entropy loss function. x is the raw scores for each class (logits). c is the index of the gold class.

func CrossEntropySeq

func CrossEntropySeq(g *ag.Graph, predicted []ag.Node, target []int, reduceMean bool) ag.Node

CrossEntropySeq calculates the CrossEntropy loss on the given sequence.

func Distance

func Distance(g *ag.Graph, x ag.Node, target mat.Float) ag.Node

Distance is a loss function that calculates the distance between target and x.

func FocalLoss added in v0.6.0

func FocalLoss(g *ag.Graph, x ag.Node, c int, gamma mat.Float) ag.Node

FocalLoss implements a variant of the CrossEntropy loss that reduces the loss contribution from "easy" examples and increases the importance of correcting misclassified examples. x is the raw scores for each class (logits). c is the index of the gold class. gamma is the focusing parameter (gamma ≥ 0).

func MAE

func MAE(g *ag.Graph, x ag.Node, y ag.Node, reduceMean bool) ag.Node

MAE measures the mean absolute error (a.k.a. L1 Loss) between each element in the input x and target y.

func MAESeq

func MAESeq(g *ag.Graph, predicted []ag.Node, target []ag.Node, reduceMean bool) ag.Node

MAESeq calculates the MAE loss on the given sequence.

func MSE

func MSE(g *ag.Graph, x ag.Node, y ag.Node, reduceMean bool) ag.Node

MSE measures the mean squared error (squared L2 norm) between each element in the input x and target y.

func MSESeq

func MSESeq(g *ag.Graph, predicted []ag.Node, target []ag.Node, reduceMean bool) ag.Node

MSESeq calculates the MSE loss on the given sequence.

func NLL

func NLL(g *ag.Graph, x ag.Node, y ag.Node) ag.Node

NLL returns the loss of the input x respect to the target y. The target is expected to be a one-hot vector.

func Norm2Quantization

func Norm2Quantization(g *ag.Graph, x ag.Node) ag.Node

Norm2Quantization is a loss function that is minimized when norm2(x) = 1.

func OneHotQuantization

func OneHotQuantization(g *ag.Graph, x ag.Node, q mat.Float) ag.Node

OneHotQuantization is a loss function that pushes towards the x vector to be 1-hot. q is the quantization regularizer weight (suggested 0.00001).

func Perplexity

func Perplexity(g *ag.Graph, x ag.Node, c int) ag.Node

Perplexity computes the perplexity, implemented as exp over the cross-entropy.

func SPG

func SPG(g *ag.Graph, logPropActions []ag.Node, logProbTargets []ag.Node) ag.Node

SPG (Softmax Policy Gradient) is a Gradient Policy used in Reinforcement Learning. logPropActions are the log-probability of the chosen action by the Agent at each time; logProbTargets are results of the reward function i.e. the predicted log-likelihood of the ground truth at each time;

func WeightedCrossEntropy added in v0.6.0

func WeightedCrossEntropy(weights []mat.Float) func(g *ag.Graph, x ag.Node, c int) ag.Node

WeightedCrossEntropy implements a weighted cross-entropy loss function. x is the raw scores for each class (logits). c is the index of the gold class. This function is scaled by a weighting factor weights[class] ∈ [0,1]

func WeightedFocalLoss added in v0.6.0

func WeightedFocalLoss(weights []mat.Float) func(g *ag.Graph, x ag.Node, c int, gamma mat.Float) ag.Node

WeightedFocalLoss implements a variant of the CrossEntropy loss that reduces the loss contribution from "easy" examples and increases the importance of correcting misclassified examples. x is the raw scores for each class (logits). c is the index of the gold class. gamma is the focusing parameter (gamma ≥ 0). This function is scaled by a weighting factor weights[class] ∈ [0,1].

func ZeroOneQuantization

func ZeroOneQuantization(g *ag.Graph, x ag.Node) ag.Node

ZeroOneQuantization is a loss function that is minimized when each component of x satisfies x(i) ≡ [x]i ∈ {0, 1}.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL