Documentation of 'jsat.lossfunctions.HingeLoss' Java class
HingeLoss
jsat.lossfunctions

Class HingeLoss

  • All Implemented Interfaces:
    java.io.Serializable, LossC, LossFunc, LossMC


    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 CategoricalResults classify(double score) 
      HingeLoss clone() 
      static double deriv(double pred, double y)
      Computes the first derivative of the HingeLoss loss
      void deriv(Vec processed, Vec derivs, int y)
      Computes the derivatives with respect to each output
      processed and derivs may be the same object, and will simply have all its values altered if so.
      CategoricalResults getClassification(double score)
      Given the score value of a data point, this returns the classification results.
      CategoricalResults getClassification(Vec processed)
      Given the processed predictions, returns the classification results for said predictions.
      double getConjugate(double b, double pred, double y)
      Computes the result of the conjugate function of this loss.
      double getDeriv(double pred, double y)
      Computes the first derivative of the getLoss function.
      double getDeriv2(double pred, double y)
      Computes the second derivative of the getLoss function.
      double getDeriv2Max()
      Returns an upper bound on the maximum value of the second derivative.
      double getLoss(double pred, double y)
      Computes the getLoss for a classification problem.
      double getLoss(Vec processed, int y)
      Computes the scalar loss for on the given example
      double lipschitz()
      If this loss is L-Lipschitz (1/L Lipschitz smooth), this method will return the value of L.
      static double loss(double pred, double y)
      Computes the HingeLoss loss
      void process(Vec pred, Vec processed)
      Given the vector of raw outputs for each class, transform it into a new vector.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HingeLoss

        public HingeLoss()
    • Method Detail

      • loss

        public static double loss(double pred,
                                  double y)
        Computes the HingeLoss loss
        Parameters:
        pred - the predicted value
        y - 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 value
        y - the target value
        Returns:
        the first derivative of the HingeLoss loss
      • getLoss

        public double getLoss(double pred,
                              double y)
        Description copied from interface: LossC
        Computes the getLoss for a classification problem.
        Specified by:
        getLoss in interface LossC
        Specified by:
        getLoss in interface LossFunc
        Parameters:
        pred - the predicted score in (-Infinity, Infinity)
        y - the true class label in {-1, 1}
        Returns:
        the getLoss in [0, Inf)
      • getDeriv

        public double getDeriv(double pred,
                               double y)
        Description copied from interface: LossC
        Computes the first derivative of the getLoss function.
        Specified by:
        getDeriv in interface LossC
        Specified by:
        getDeriv in interface LossFunc
        Parameters:
        pred - the predicted score in (-Infinity, Infinity)
        y - the true class label in {-1, 1}
        Returns:
        the first derivative of the getLoss
      • getDeriv2

        public double getDeriv2(double pred,
                                double y)
        Description copied from interface: LossC
        Computes the second derivative of the getLoss function.
        Specified by:
        getDeriv2 in interface LossC
        Specified by:
        getDeriv2 in interface LossFunc
        Parameters:
        pred - the predicted score in (-Infinity, Infinity)
        y - the true class label in {-1, 1}
        Returns:
        the second derivative of the getLoss function
      • getDeriv2Max

        public double getDeriv2Max()
        Description copied from interface: LossFunc
        Returns an upper bound on the maximum value of the second derivative. If the second derivative does not exist, Double.NaN is a valid result. It is also possible for 0 and Double.POSITIVE_INFINITY to be valid results, and must be checked for.
        Specified by:
        getDeriv2Max in interface LossFunc
        Returns:
        the max value of LossFunc.getDeriv2(double, double)
      • clone

        public HingeLoss clone()
        Specified by:
        clone in interface LossC
        Specified by:
        clone in interface LossFunc
        Overrides:
        clone in class java.lang.Object
      • getClassification

        public CategoricalResults getClassification(double score)
        Description copied from interface: LossC
        Given the score value of a data point, this returns the classification results.
        Specified by:
        getClassification in interface LossC
        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: LossMC
        Computes the scalar loss for on the given example
        Specified by:
        getLoss in interface LossMC
        Parameters:
        processed - the vector of raw predictions.
        y - the true class label in [0, k-1] for k classes
        Returns:
        the loss in [0, Inf)
      • process

        public void process(Vec pred,
                            Vec processed)
        Description copied from interface: LossMC
        Given the vector of raw outputs for each class, transform it into a new vector.
        processed and derivs may be the same object, and will simply have all its values altered if so.
        Specified by:
        process in interface LossMC
        Parameters:
        pred - the vector of raw predictions
        processed - the location to store the processed predictions.
      • deriv

        public void deriv(Vec processed,
                          Vec derivs,
                          int y)
        Description copied from interface: LossMC
        Computes the derivatives with respect to each output
        processed and derivs may be the same object, and will simply have all its values altered if so.
        Specified by:
        deriv in interface LossMC
        Parameters:
        processed - the processed predictions
        derivs - the vector to place the derivative of the loss to.
        y - the true class label in [0, k-1] for k classes
      • getClassification

        public CategoricalResults getClassification(Vec processed)
        Description copied from interface: LossMC
        Given the processed predictions, returns the classification results for said predictions.
        Specified by:
        getClassification in interface LossMC
        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: LossFunc
        Computes the result of the conjugate function of this loss. This function is generally optional, and should return Double.NaN if not properly implemented. Many optimization algorithms do require a working implementation though.
        Specified by:
        getConjugate in interface LossFunc
        Parameters:
        b - the primary input to the function
        pred - 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: LossFunc
        If 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.
        Specified by:
        lipschitz in interface LossFunc
        Returns:
        the L-Lipschitz constant, or 0 if this loss is not L-Lipschitz;

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.