jsat.lossfunctions
Class HingeLoss
- java.lang.Object
-
- jsat.lossfunctions.HingeLoss
-
public class HingeLoss extends java.lang.Object implements LossMC
The HingeLoss loss function for classification L(x, y) = max(0, 1-y*x) . This also includes the multi-class version of the hinge loss.
This function is only once differentiable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description HingeLoss()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static CategoricalResultsclassify(double score)HingeLossclone()static doublederiv(double pred, double y)Computes the first derivative of the HingeLoss lossvoidderiv(Vec processed, Vec derivs, int y)Computes the derivatives with respect to each output
processedandderivsmay be the same object, and will simply have all its values altered if so.CategoricalResultsgetClassification(double score)Given the score value of a data point, this returns the classification results.CategoricalResultsgetClassification(Vec processed)Given theprocessedpredictions, returns the classification results for said predictions.doublegetConjugate(double b, double pred, double y)Computes the result of the conjugate function of this loss.doublegetDeriv(double pred, double y)Computes the first derivative of the getLoss function.doublegetDeriv2(double pred, double y)Computes the second derivative of the getLoss function.doublegetDeriv2Max()Returns an upper bound on the maximum value of the second derivative.doublegetLoss(double pred, double y)Computes the getLoss for a classification problem.doublegetLoss(Vec processed, int y)Computes the scalar loss for on the given exampledoublelipschitz()If this loss is L-Lipschitz (1/L Lipschitz smooth), this method will return the value of L.static doubleloss(double pred, double y)Computes the HingeLoss lossvoidprocess(Vec pred, Vec processed)Given the vector of raw outputs for each class, transform it into a new vector.
-
-
-
Method Detail
-
loss
public static double loss(double pred, double y)Computes the HingeLoss loss- Parameters:
pred- the predicted valuey- the target value- Returns:
- the HingeLoss loss
-
deriv
public static double deriv(double pred, double y)Computes the first derivative of the HingeLoss loss- Parameters:
pred- the predicted valuey- the target value- Returns:
- the first derivative of the HingeLoss loss
-
classify
public static CategoricalResults classify(double score)
-
getLoss
public double getLoss(double pred, double y)Description copied from interface:LossCComputes the getLoss for a classification problem.
-
getDeriv
public double getDeriv(double pred, double y)Description copied from interface:LossCComputes the first derivative of the getLoss function.
-
getDeriv2
public double getDeriv2(double pred, double y)Description copied from interface:LossCComputes the second derivative of the getLoss function.
-
getDeriv2Max
public double getDeriv2Max()
Description copied from interface:LossFuncReturns an upper bound on the maximum value of the second derivative. If the second derivative does not exist,Double.NaNis a valid result. It is also possible for0andDouble.POSITIVE_INFINITYto be valid results, and must be checked for.- Specified by:
getDeriv2Maxin interfaceLossFunc- Returns:
- the max value of
LossFunc.getDeriv2(double, double)
-
clone
public HingeLoss clone()
-
getClassification
public CategoricalResults getClassification(double score)
Description copied from interface:LossCGiven the score value of a data point, this returns the classification results.- Specified by:
getClassificationin interfaceLossC- Parameters:
score- the score for a data point- Returns:
- the categorical results with the correct probability values for this loss function.
-
getLoss
public double getLoss(Vec processed, int y)
Description copied from interface:LossMCComputes the scalar loss for on the given example
-
process
public void process(Vec pred, Vec processed)
Description copied from interface:LossMCGiven the vector of raw outputs for each class, transform it into a new vector.
processedandderivsmay be the same object, and will simply have all its values altered if so.
-
deriv
public void deriv(Vec processed, Vec derivs, int y)
Description copied from interface:LossMCComputes the derivatives with respect to each output
processedandderivsmay be the same object, and will simply have all its values altered if so.
-
getClassification
public CategoricalResults getClassification(Vec processed)
Description copied from interface:LossMCGiven theprocessedpredictions, returns the classification results for said predictions.- Specified by:
getClassificationin interfaceLossMC- Parameters:
processed- the processed score/prediction vector- Returns:
- the classification results
-
getConjugate
public double getConjugate(double b, double pred, double y)Description copied from interface:LossFuncComputes the result of the conjugate function of this loss. This function is generally optional, and should returnDouble.NaNif not properly implemented. Many optimization algorithms do require a working implementation though.- Specified by:
getConjugatein interfaceLossFunc- Parameters:
b- the primary input to the functionpred- the predicted score in (-Infinity, Infinity)y- the true class label in {-1, 1}- Returns:
- the result of the conjugate function of this loss
-
lipschitz
public double lipschitz()
Description copied from interface:LossFuncIf this loss is L-Lipschitz (1/L Lipschitz smooth), this method will return the value of L. If it is not L-Lipschitz, a value of 0 will be returned.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG