Have a question? Connect with the community at the TensorFlow Forum

# Hinge

public class Hinge

Computes the hinge loss between labels and predictions.

``` loss = maximum(1 - labels * predictions, 0) ``` .

``` labels ``` values are expected to be -1 or 1. If binary (0 or 1) labels are provided, they will be converted to -1 or 1.

Standalone usage:

```    Operand<TFloat32> labels =
tf.constant(new float[][] { {0.f, 1.f}, {0.f, 0.f} });
Operand<TFloat32> predictions =
tf.constant(new float[][] { {0.6f, 0.4f}, {0.4f, 0.6f} });
Hinge hingeLoss = new Hinge(tf);
Operand<TFloat32> result = hingeLoss.call(labels, predictions);
// produces 1.3f
```

Calling with sample weight:

```    Operand<TFloat32> sampleWeight = tf.constant(new float[] {1.f, 0.f});
Operand<TFloat32> result = hingeLoss.call(labels, predictions, sampleWeight);
// produces 0.55f
```

Using ``` SUM ``` reduction type:

```    Hinge hingeLoss = new Hinge(tf, Reduction.SUM);
Operand<TFloat32> result = hingeLoss.call(labels, predictions);
// produces 2.6f
```

Using ``` NONE ``` reduction type:

```    Hinge hingeLoss = new Hinge(tf, Reduction.NONE);
Operand<TFloat32> result = hingeLoss.call(labels, predictions);
// produces [1.1f, 1.5f]
```

### Public Constructors

 (Ops tf) Creates a Hinge Loss using ``` getSimpleName() ``` as the loss name and a Loss Reduction of ``` REDUCTION_DEFAULT ``` (Ops tf, Reduction reduction) Creates a Hinge Loss using ``` getSimpleName() ``` as the loss name (Ops tf, String name, Reduction reduction) Creates a Hinge

### Public Methods

 Operand ( Operand labels, Operand predictions, Operand sampleWeights) Generates an Operand that calculates the loss.

## Public Constructors

#### public Hinge (Ops tf)

Creates a Hinge Loss using ``` getSimpleName() ``` as the loss name and a Loss Reduction of ``` REDUCTION_DEFAULT ```

##### Parameters
 tf the TensorFlow Ops

#### public Hinge (Ops tf, Reduction reduction)

Creates a Hinge Loss using ``` getSimpleName() ``` as the loss name

##### Parameters
 tf the TensorFlow Ops Type of Reduction to apply to the loss.

#### public Hinge (Ops tf, String name, Reduction reduction)

Creates a Hinge

##### Parameters
 tf the TensorFlow Ops the name of the loss Type of Reduction to apply to the loss.

## Public Methods

#### public Operand <T> call ( Operand <? extends TNumber > labels, Operand <T> predictions, Operand <T> sampleWeights)

Generates an Operand that calculates the loss.

If run in Graph mode, the computation will throw ``` TFInvalidArgumentException ``` if the label values are not in the set [-1., 0., 1.]. In Eager Mode, this call will throw ``` IllegalArgumentException ``` , if the label values are not in the set [-1., 0., 1.].

##### Parameters
 labels the truth values or labels, must be either -1, 0, or 1. Values are expected to be -1 or 1. If binary (0 or 1) labels are provided they will be converted to -1 or 1. the predictions, values must be in the range [0. to 1.] inclusive. Optional sampleWeights acts as a coefficient for the loss. If a scalar is provided, then the loss is simply scaled by the given value. If sampleWeights is a tensor of size [batch_size], then the total loss for each sample of the batch is rescaled by the corresponding element in the SampleWeights vector. If the shape of SampleWeights is [batch_size, d0, .. dN-1] (or can be broadcast to this shape), then each loss element of predictions is scaled by the corresponding value of SampleWeights. (Note on dN-1: all loss functions reduce by 1 dimension, usually axis=-1.)
• the loss
##### Throws
 IllegalArgumentException if the predictions are outside the range [0.-1.].
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]