Skip to contents

Formula:

loss <- maximum(neg - pos + 1, 0)

where neg=maximum((1-y_true)*y_pred) and pos=sum(y_true*y_pred)

Usage

loss_categorical_hinge(
  y_true,
  y_pred,
  ...,
  reduction = "sum_over_batch_size",
  name = "categorical_hinge"
)

Arguments

y_true

The ground truth values. y_true values are expected to be either {-1, +1} or {0, 1} (i.e. a one-hot-encoded tensor) with shape <- [batch_size, d0, .. dN].

y_pred

The predicted values with shape = [batch_size, d0, .. dN].

...

For forward/backward compatability.

reduction

Type of reduction to apply to the loss. In almost all cases this should be "sum_over_batch_size". Supported options are "sum", "sum_over_batch_size" or NULL.

name

Optional name for the loss instance.

Value

Categorical hinge loss values with shape = [batch_size, d0, .. dN-1].

Examples

y_true <- rbind(c(0, 1), c(0, 0))
y_pred <- rbind(c(0.6, 0.4), c(0.4, 0.6))
loss <- loss_categorical_hinge(y_true, y_pred)