Squared Hinge-loss for large margin classification. More...
#include <shark/ObjectiveFunctions/Loss/SquaredHingeLoss.h>
Public Member Functions | |
SquaredHingeLoss () | |
constructor More... | |
std::string | name () const |
Returns class name "HingeLoss". More... | |
double | eval (BatchLabelType const &labels, BatchOutputType const &predictions) const |
calculates the sum of all More... | |
double | evalDerivative (BatchLabelType const &labels, BatchOutputType const &predictions, BatchOutputType &gradient) const |
evaluate the loss and the derivative w.r.t. the prediction More... | |
Public Member Functions inherited from shark::AbstractLoss< unsigned int, RealVector > | |
AbstractLoss () | |
virtual double | eval (ConstLabelReference target, ConstOutputReference prediction) const |
evaluate the loss for a target and a prediction More... | |
double | eval (Data< LabelType > const &targets, Data< OutputType > const &predictions) const |
virtual double | evalDerivative (ConstLabelReference target, ConstOutputReference prediction, OutputType &gradient) const |
evaluate the loss and its derivative for a target and a prediction More... | |
virtual double | evalDerivative (ConstLabelReference target, ConstOutputReference prediction, OutputType &gradient, MatrixType &hessian) const |
evaluate the loss and its first and second derivative for a target and a prediction More... | |
double | operator() (LabelType const &target, OutputType const &prediction) const |
evaluate the loss for a target and a prediction More... | |
double | operator() (BatchLabelType const &target, BatchOutputType const &prediction) const |
Public Member Functions inherited from shark::AbstractCost< unsigned int, RealVector > | |
virtual | ~AbstractCost () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstDerivative () const |
returns true when the first parameter derivative is implemented More... | |
bool | isLossFunction () const |
returns true when the cost function is in fact a loss function More... | |
double | operator() (Data< LabelType > const &targets, Data< OutputType > const &predictions) const |
Public Member Functions inherited from shark::INameable | |
virtual | ~INameable () |
Squared Hinge-loss for large margin classification.
The squared hinge loss for two class problems is defined as \( L_i = 1/2\max \{ 0 , (1- y_i f(x_i))^2 \} \) where \( y_i \in \{-1,1} \) is the label and \( f(x_i) \) is the prediction of the model for the ith input. The loss introduces the concept of a margin, that is, the point should not only be correctly classified but also not too close to the decision boundary. Therefore even correctly classified points are getting punished.
for multi class problems the concept of sums of the relative margin is used: \( L_i = 1/2 \sum_{c \neq y_i} \max \{ 0 , 1- 1/2 (f_{y_i}(x_i)- f_c(x_i) \} \). This loss requires that there is a margin between the different class outputs and the functions needs as many outputs as classes. the pre-factor 1/2 ensures that in the 2 class 2 output case with a linear function the value of loss is the same as in the single output version.
The loss is implemented for class labels 0,1,...,n, even in the binary cases.
The difference to the normal hinge loss is, that the squared hinge-loss is always differentiable. However compared to the hinge loss, small margin violations are not as much punished - but big deviations are punished much stronger.
Definition at line 57 of file SquaredHingeLoss.h.
|
inline |
constructor
Definition at line 61 of file SquaredHingeLoss.h.
References shark::AbstractCost< unsigned int, RealVector >::m_features.
|
inlinevirtual |
calculates the sum of all
Implements shark::AbstractLoss< unsigned int, RealVector >.
Definition at line 71 of file SquaredHingeLoss.h.
References SIZE_CHECK, and shark::sqr().
|
inlinevirtual |
evaluate the loss and the derivative w.r.t. the prediction
target | target value |
prediction | prediction, typically made by a model |
gradient | the gradient of the loss function with respect to the prediction |
Reimplemented from shark::AbstractLoss< unsigned int, RealVector >.
Definition at line 99 of file SquaredHingeLoss.h.
References SIZE_CHECK.
|
inlinevirtual |
Returns class name "HingeLoss".
Reimplemented from shark::INameable.
Definition at line 66 of file SquaredHingeLoss.h.