jsat.lossfunctions
Class SquaredLoss
- java.lang.Object
-
- jsat.lossfunctions.SquaredLoss
-
public class SquaredLoss extends java.lang.Object implements LossR
The SquaredLoss loss function for regression L(x, y) = (x-y)2.
This function is twice differentiable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SquaredLoss()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description SquaredLossclone()static doublederiv(double pred, double y)Computes the first derivative of the squared lossstatic doublederiv2(double pred, double y)Computes the second derivative of the squared loss, which is always1doublegetConjugate(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)Computes the SquaredLoss lossstatic doubleregress(double score)
-
-
-
Method Detail
-
loss
public static double loss(double pred, double y)Computes the SquaredLoss loss- Parameters:
pred- the predicted valuey- the true value- Returns:
- the squared loss
-
deriv
public static double deriv(double pred, double y)Computes the first derivative of the squared loss- Parameters:
pred- the predicted valuey- the true value- Returns:
- the first derivative of the squared loss
-
deriv2
public static double deriv2(double pred, double y)Computes the second derivative of the squared loss, which is always1- Parameters:
pred- the predicted valuey- the true value- Returns:
- the second derivative of the squared 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 SquaredLoss 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