shark::SquaredLoss< OutputType, LabelType > Class Template Reference

squared loss for regression and classification More...

#include <shark/ObjectiveFunctions/Loss/SquaredLoss.h>

+ Inheritance diagram for shark::SquaredLoss< OutputType, LabelType >:

Public Types

typedef base_type::BatchOutputType BatchOutputType
 
typedef base_type::BatchLabelType BatchLabelType
 
- Public Types inherited from shark::AbstractLoss< LabelT, OutputT >
typedef OutputT OutputType
 
typedef LabelT LabelType
 
typedef RealMatrix MatrixType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef Batch< LabelType >::type BatchLabelType
 
typedef ConstProxyReference< LabelTypeconst >::type ConstLabelReference
 Const references to LabelType.
 
typedef ConstProxyReference< OutputTypeconst >::type ConstOutputReference
 Const references to OutputType.
 
- Public Types inherited from shark::AbstractCost< LabelT, OutputT >
enum  Feature { HAS_FIRST_DERIVATIVE = 1 , HAS_SECOND_DERIVATIVE = 2 , IS_LOSS_FUNCTION = 4 }
 list of features a cost function can have More...
 
typedef OutputT OutputType
 
typedef LabelT LabelType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef Batch< LabelType >::type BatchLabelType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Public Member Functions

 SquaredLoss ()
 Constructor.
 
std::string name () const
 From INameable: return the class name.
 
double eval (BatchLabelType const &labels, BatchOutputType const &predictions) const
 Evaluate the squared loss \( (label - prediction)^2 \).
 
double evalDerivative (BatchLabelType const &label, BatchOutputType const &prediction, BatchOutputType &gradient) const
 
virtual double eval (BatchLabelType const &target, BatchOutputType const &prediction) const=0
 evaluate the loss for a batch of targets and a prediction
 
virtual double eval (ConstLabelReference target, ConstOutputReference prediction) const
 evaluate the loss for a target and a prediction
 
double eval (Data< LabelType > const &targets, Data< OutputType > const &predictions) const
 
- Public Member Functions inherited from shark::AbstractLoss< LabelT, OutputT >
 AbstractLoss ()
 
virtual double evalDerivative (ConstLabelReference target, ConstOutputReference prediction, OutputType &gradient) const
 evaluate the loss and its derivative for a target and a prediction
 
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
 
double operator() (LabelType const &target, OutputType const &prediction) const
 evaluate the loss for a target and a prediction
 
double operator() (BatchLabelType const &target, BatchOutputType const &prediction) const
 
- Public Member Functions inherited from shark::AbstractCost< LabelT, OutputT >
virtual ~AbstractCost ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstDerivative () const
 returns true when the first parameter derivative is implemented
 
bool isLossFunction () const
 returns true when the cost function is in fact a loss function
 
double operator() (Data< LabelType > const &targets, Data< OutputType > const &predictions) const
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractCost< LabelT, OutputT >
Features m_features
 

Detailed Description

template<class OutputType = RealVector, class LabelType = OutputType>
class shark::SquaredLoss< OutputType, LabelType >

squared loss for regression and classification

The SquaredLoss computes the squared distance between target and prediction. It is defined for both vectorial as well as integral labels. In the case of integral labels, the label c is interpreted as unit-vector having the c-th component activated.

Definition at line 48 of file SquaredLoss.h.

Member Typedef Documentation

◆ BatchLabelType

template<class OutputType = RealVector, class LabelType = OutputType>
typedef base_type::BatchLabelType shark::SquaredLoss< OutputType, LabelType >::BatchLabelType

Definition at line 53 of file SquaredLoss.h.

◆ BatchOutputType

template<class OutputType = RealVector, class LabelType = OutputType>
typedef base_type::BatchOutputType shark::SquaredLoss< OutputType, LabelType >::BatchOutputType

Definition at line 52 of file SquaredLoss.h.

Constructor & Destructor Documentation

◆ SquaredLoss()

template<class OutputType = RealVector, class LabelType = OutputType>
shark::SquaredLoss< OutputType, LabelType >::SquaredLoss ( )
inline

Member Function Documentation

◆ eval() [1/4]

template<class OutputType = RealVector, class LabelType = OutputType>
double shark::SquaredLoss< OutputType, LabelType >::eval ( BatchLabelType const &  labels,
BatchOutputType const &  predictions 
) const
inlinevirtual

Evaluate the squared loss \( (label - prediction)^2 \).

Implements shark::AbstractLoss< LabelT, OutputT >.

Definition at line 69 of file SquaredLoss.h.

References SIZE_CHECK, and shark::sqr().

Referenced by shark::SquaredLoss< OutputType, LabelType >::evalDerivative(), shark::SquaredLoss< OutputType, unsigned int >::evalDerivative(), and main().

◆ eval() [2/4]

template<class OutputType = RealVector, class LabelType = OutputType>
virtual double shark::AbstractLoss< LabelT, OutputT >::eval ( BatchLabelType const &  target,
BatchOutputType const &  prediction 
) const
virtual

evaluate the loss for a batch of targets and a prediction

Parameters
targettarget values
predictionpredictions, typically made by a model

Implements shark::AbstractLoss< LabelT, OutputT >.

◆ eval() [3/4]

template<class OutputType = RealVector, class LabelType = OutputType>
virtual double shark::AbstractLoss< LabelT, OutputT >::eval ( ConstLabelReference  target,
ConstOutputReference  prediction 
) const
inlinevirtual

evaluate the loss for a target and a prediction

Parameters
targettarget value
predictionprediction, typically made by a model

Reimplemented from shark::AbstractLoss< LabelT, OutputT >.

Definition at line 92 of file AbstractLoss.h.

◆ eval() [4/4]

template<class OutputType = RealVector, class LabelType = OutputType>
double shark::AbstractLoss< LabelT, OutputT >::eval ( Data< LabelType > const &  targets,
Data< OutputType > const &  predictions 
) const
inlinevirtual

from AbstractCost

Parameters
targetstarget values
predictionspredictions, typically made by a model

Reimplemented from shark::AbstractLoss< LabelT, OutputT >.

Definition at line 149 of file AbstractLoss.h.

◆ evalDerivative()

template<class OutputType = RealVector, class LabelType = OutputType>
double shark::SquaredLoss< OutputType, LabelType >::evalDerivative ( BatchLabelType const &  label,
BatchOutputType const &  prediction,
BatchOutputType gradient 
) const
inlinevirtual

Evaluate the squared loss \( (label - prediction)^2 \) and its deriative \( \frac{\partial}{\partial prediction} 1/2 (label - prediction)^2 = prediction - label \).

Reimplemented from shark::AbstractLoss< LabelT, OutputT >.

Definition at line 79 of file SquaredLoss.h.

References shark::SquaredLoss< OutputType, LabelType >::eval().

◆ name()

template<class OutputType = RealVector, class LabelType = OutputType>
std::string shark::SquaredLoss< OutputType, LabelType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 63 of file SquaredLoss.h.


The documentation for this class was generated from the following file: