libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
loss.hpp File Reference

Contains some general purpose loss objectives. More...

#include "../tensor/math.hpp"
Include dependency graph for loss.hpp:

Go to the source code of this file.

Functions

TensorPtr dl::loss::mse (TensorPtr x, TensorPtr y) noexcept
 Mean Square Error.
 
TensorPtr dl::loss::bce (TensorPtr x, TensorPtr y) noexcept
 Binary Cross Entropy Loss.
 

Detailed Description

Contains some general purpose loss objectives.

Definition in file loss.hpp.

Function Documentation

◆ bce()

TensorPtr dl::loss::bce ( TensorPtr  x,
TensorPtr  y 
)
noexcept

Binary Cross Entropy Loss.

Implements the binary cross entropy loss function. Let \(\vec{x}=\begin{pmatrix}x_1 & \dots & x_n\end{pmatrix}\) be the model's outputs and \(\vec{y}=\begin{pmatrix}y_1 & \dots & y_n\end{pmatrix}\) the targets, the binary cross entropy loss is defined as

\[\text{BCE}(\vec{x}, \vec{y}) := -\frac{1}{n}\sum_{i=1}^n (y_i\log x_i + (1-y_i)\log(1-x_i)).\]

Parameters
xthe model outputs
ythe targets (desired outputs)
Returns
the binary cross entropy

Definition at line 37 of file loss.hpp.

37 {
38 return -dl::mean(y * dl::log(x) + (1.0f - y) * dl::log(1.0f - x));
39 }
TensorPtr log(TensorPtr x) noexcept
Natural logarithm, .
TensorPtr mean(TensorPtr x) noexcept
Mean.

◆ mse()

TensorPtr dl::loss::mse ( TensorPtr  x,
TensorPtr  y 
)
noexcept

Mean Square Error.

Implements the mean square error loss function. Let \(\vec{x}=\begin{pmatrix}x_1 & \dots & x_n\end{pmatrix}\) be the model's outputs and \(\vec{y}=\begin{pmatrix}y_1 & \dots & y_n\end{pmatrix}\) the targets, the margin square error is defined as

\[\text{MSE}(\vec{x}, \vec{y}) := \frac{1}{n}\sum_{i=1}^n (x_i - y_i)^2.\]

Parameters
xthe model outputs
ythe targets (desired outputs)
Returns
the mean square error

Definition at line 23 of file loss.hpp.

23{ return dl::mean(dl::pow(x - y, 2.0f)); }
TensorPtr pow(TensorPtr base, float exponent) noexcept
Computes the exponent -th power of each element in base and returns the resulting tensor.