Loss Functions
-
Computes the (element-wise) binary cross entropy loss on the given and expected probabilities and uses the mean as a reduction. expected and predicted are assumed to be in the interval (0, 1).
The binary cross entropy loss is defined as
-expected * log(predicted) - (1 - expected) * log(1 - predicted)Declaration
Swift
public func binaryCrossEntropy<Element, Device>(expected: Tensor<Element, Device>, actual: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
expectedExpected values
actualPredicted values
ignoreIndexValue in expected, which is ignored.
Return Value
Loss, scalar value
-
Computes the categorical cross entropy loss on the given expected probabilities and the expected labels and uses the mean as a reduction. predicted values are assumed to be in the interval (0, 1)
The categorical cross entropy loss is defined as
-log(predicted[expected])Declaration
Swift
public func categoricalCrossEntropy<Element, Device>(expected: Tensor<Int32, Device>, actual: Tensor<Element, Device>, ignoreIndex: Int32 = -1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
expectedExpected labels
actualPredicted values
ignoreIndexValue in expected, which is ignored.
Return Value
Loss, scalar value
-
Computes the categorical negative log likelihood (NLL) loss on the given expected probabilities and the expected labels and uses the mean as a reduction. Predicted values are assumed to be in the interval (-infinity, 0).
NLL loss should be used in conjunction with logSoftmax.
The categorical NLL loss is defined as
-predicted[expected]Declaration
Swift
public func categoricalNegativeLogLikelihood<Element, Device>(expected: Tensor<Int32, Device>, actual: Tensor<Element, Device>, ignoreIndex: Int32 = -1) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
expectedExpected labels
actualPredicted values
Return Value
Loss, scalar value
-
Computes the element-wise mean squared error between the given predicted and expected values
Declaration
Swift
public func meanSquaredError<Element, Device>(expected: Tensor<Element, Device>, actual: Tensor<Element, Device>) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
expectedExpected values
actualPredicted values
-
Computes the L1 loss of the given tensor.
Declaration
Swift
public func l1loss<Element, Device>(_ vector: Tensor<Element, Device>, loss: Element) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
vectorTensor to apply weight decay on
lossWeight decay importance scaling factor
-
Computes the L2 loss of the given tensor.
Declaration
Swift
public func l2loss<Element, Device>(_ vector: Tensor<Element, Device>, loss: Element) -> Tensor<Element, Device> where Element : NumericType, Device : DeviceTypeParameters
vectorTensor to apply weight decay on
lossWeight decay importance scaling factor
View on GitHub
Loss Functions Reference