shark::SquaredLoss< Sequence, Sequence > Class Template Reference

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

+ Inheritance diagram for shark::SquaredLoss< Sequence, Sequence >:

Public Member Functions

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

Additional Inherited Members

- Public Types inherited from shark::AbstractLoss< Sequence, Sequence >
typedef Sequence OutputType
 
typedef Sequence LabelType
 
typedef RealMatrix MatrixType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef Batch< LabelType >::type BatchLabelType
 
typedef ConstProxyReference< LabelType const >::type ConstLabelReference
 Const references to LabelType. More...
 
typedef ConstProxyReference< OutputType const >::type ConstOutputReference
 Const references to OutputType. More...
 
- Public Types inherited from shark::AbstractCost< Sequence, Sequence >
enum  Feature
 list of features a cost function can have More...
 
typedef Sequence OutputType
 
typedef Sequence LabelType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef Batch< LabelType >::type BatchLabelType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Protected Attributes inherited from shark::AbstractCost< Sequence, Sequence >
Features m_features
 

Detailed Description

template<>
class shark::SquaredLoss< Sequence, Sequence >

Definition at line 140 of file SquaredLoss.h.

Constructor & Destructor Documentation

◆ SquaredLoss()

shark::SquaredLoss< Sequence, Sequence >::SquaredLoss ( std::size_t  ignore = 0)
inline

Constructor.

Parameters
ignoreSpecifies how many elements of the sequence are to be ignored during evaluation must be strictly smaller than the smalles sequnce to evaluate.

Definition at line 147 of file SquaredLoss.h.

References shark::AbstractCost< LabelType, OutputType >::HAS_FIRST_DERIVATIVE, and shark::AbstractCost< LabelType, OutputType >::m_features.

Member Function Documentation

◆ eval()

double shark::SquaredLoss< Sequence, Sequence >::eval ( BatchLabelType const &  labels,
BatchOutputType const &  predictions 
) const
inlinevirtual

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

For Sequences this is:

\[ sum_{i=i_0} (label_i-prediction_i)^2\]

where \( i_0 \) is the first element to be evaluated. By default it is 0

Implements shark::AbstractLoss< Sequence, Sequence >.

Definition at line 164 of file SquaredLoss.h.

References SHARK_RUNTIME_CHECK, and SIZE_CHECK.

◆ evalDerivative()

double shark::SquaredLoss< Sequence, Sequence >::evalDerivative ( BatchLabelType const &  labels,
BatchOutputType const &  predictions,
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< Sequence, Sequence >.

Definition at line 181 of file SquaredLoss.h.

References SHARK_RUNTIME_CHECK, and SIZE_CHECK.

◆ name()

std::string shark::SquaredLoss< Sequence, Sequence >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 154 of file SquaredLoss.h.

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


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