nn_multi_margin_loss | R Documentation |
Creates a criterion that optimizes a multi-class classification hinge
loss (margin-based loss) between input x
(a 2D mini-batch Tensor
) and
output y
(which is a 1D tensor of target class indices,
0 \leq y \leq \mbox{x.size}(1)-1
):
nn_multi_margin_loss(p = 1, margin = 1, weight = NULL, reduction = "mean")
p |
(int, optional): Has a default value of |
margin |
(float, optional): Has a default value of |
weight |
(Tensor, optional): a manual rescaling weight given to each
class. If given, it has to be a Tensor of size |
reduction |
(string, optional): Specifies the reduction to apply to the output:
|
For each mini-batch sample, the loss in terms of the 1D input x
and scalar
output y
is:
\mbox{loss}(x, y) = \frac{\sum_i \max(0, \mbox{margin} - x[y] + x[i]))^p}{\mbox{x.size}(0)}
where x \in \left\{0, \; \cdots , \; \mbox{x.size}(0) - 1\right\}
and i \neq y
.
Optionally, you can give non-equal weighting on the classes by passing
a 1D weight
tensor into the constructor.
The loss function then becomes:
\mbox{loss}(x, y) = \frac{\sum_i \max(0, w[y] * (\mbox{margin} - x[y] + x[i]))^p)}{\mbox{x.size}(0)}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.