mygrad.nnet.losses.multiclass_hinge#

mygrad.nnet.losses.multiclass_hinge(x: ArrayLike, y_true: ArrayLike, hinge: float = 1.0, *, constant: bool | None = None) Tensor[source]#

Computes the average multiclass hinge loss.

Parameters:
xArrayLike, shape=(N, K)

The K class scores for each of the N pieces of data.

y_trueArrayLike, shape=(N,)

The correct class-indices, in [0, K), for each datum.

hingefloat

The size of the “hinge” outside of which a nonzero loss is incurred.

constantbool, optional(default=False)

If True, the returned tensor is a constant (it does not back-propagate a gradient)

Returns:
Tensor, shape-() (scalar)

The average multiclass hinge loss

Raises:
TypeError

y_true must be an integer-type array-like object

ValueError

x must be a 2-dimensional array-like object y_true must be a shape-(N,) array-like object