jsat.lossfunctions
Class HuberLoss
- java.lang.Object
-
- jsat.lossfunctions.HuberLoss
-
public class HuberLoss extends java.lang.Object implements LossR
The HuberLoss loss function for regression. The HuberLoss loss switches betweenSquaredLossandAbsoluteLossloss based on a threshold value.
This function is only partially twice differentiable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description HuberLoss()Creates a new HuberLoss loss thresholded at 1HuberLoss(double c)Creates a new HuberLoss loss
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description HuberLossclone()static doublederiv(double pred, double y, double c)Computes the first derivative of the HuberLoss lossstatic doublederiv2(double pred, double y, double c)Computes the second derivative of the HuberLoss loss, which only exists for values <cdoublegetConjugate(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 regression problem.doublegetRegression(double score)Given the score value of a data point, this returns the correct numeric result.doublelipschitz()If this loss is L-Lipschitz (1/L Lipschitz smooth), this method will return the value of L.static doubleloss(double pred, double y, double c)Computes the HuberLoss lossstatic doubleregress(double score)
-
-
-
Constructor Detail
-
HuberLoss
public HuberLoss(double c)
Creates a new HuberLoss loss- Parameters:
c- the threshold to switch between the squared and logistic loss at
-
HuberLoss
public HuberLoss()
Creates a new HuberLoss loss thresholded at 1
-
-
Method Detail
-
loss
public static double loss(double pred, double y, double c)Computes the HuberLoss loss- Parameters:
pred- the predicted valuey- the true valuec- the threshold value- Returns:
- the HuberLoss loss
-
deriv
public static double deriv(double pred, double y, double c)Computes the first derivative of the HuberLoss loss- Parameters:
pred- the predicted valuey- the true valuec- the threshold value- Returns:
- the first derivative of the HuberLoss loss
-
deriv2
public static double deriv2(double pred, double y, double c)Computes the second derivative of the HuberLoss loss, which only exists for values <c- Parameters:
pred- the predicted valuey- the target valuec- the threshold value- Returns:
- the second derivative of the HuberLoss loss
-
regress
public static double regress(double score)
-
getLoss
public double getLoss(double pred, double y)Description copied from interface:LossRComputes the getLoss for a regression problem.
-
getDeriv
public double getDeriv(double pred, double y)Description copied from interface:LossRComputes the first derivative of the getLoss function.
-
getDeriv2
public double getDeriv2(double pred, double y)Description copied from interface:LossRComputes the second derivative of the getLoss function.
-
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
-
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 HuberLoss clone()
-
getRegression
public double getRegression(double score)
Description copied from interface:LossRGiven the score value of a data point, this returns the correct numeric result. For most regression problems this simply returns the score value.- Specified by:
getRegressionin interfaceLossR- Parameters:
score- the score for a data point- Returns:
- the correct numeric regression value for this loss function
-
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