shark::DiscreteLoss Class Reference

flexible loss for classification More...

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

+ Inheritance diagram for shark::DiscreteLoss:

Public Member Functions

SHARK_EXPORT_SYMBOL DiscreteLoss (RealMatrix const &cost)
 
std::string name () const
 From INameable: return the class name. More...
 
SHARK_EXPORT_SYMBOL double eval (BatchLabelType const &target, BatchOutputType const &prediction) const
 inherited from AbstractLoss, evaluation of the loss function More...
 
SHARK_EXPORT_SYMBOL void defineCostMatrix (RealMatrix const &cost)
 
SHARK_EXPORT_SYMBOL void defineBalancedCost (UnlabeledData< unsigned int > const &labels)
 
- Public Member Functions inherited from shark::AbstractLoss< unsigned int, unsigned int >
 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...
 
virtual double evalDerivative (BatchLabelType const &target, BatchOutputType const &prediction, BatchOutputType &gradient) const
 evaluate the loss and the derivative w.r.t. the 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< unsigned int, unsigned int >
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 ()
 

Protected Attributes

RealMatrix m_cost
 cost matrix More...
 
- Protected Attributes inherited from shark::AbstractCost< unsigned int, unsigned int >
Features m_features
 

Additional Inherited Members

- Public Types inherited from shark::AbstractLoss< unsigned int, unsigned int >
typedef unsigned int OutputType
 
typedef unsigned int 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< unsigned int, unsigned int >
enum  Feature
 list of features a cost function can have More...
 
typedef unsigned int OutputType
 
typedef unsigned int LabelType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef Batch< LabelType >::type BatchLabelType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Detailed Description

flexible loss for classification

The DiscreteLoss class allows for the definition of a cost matrix applied to a finite number of classes. The cost of correct classification must be zero, all other costs must be non-negative.
Note: As a special case, this loss can be used to provide a balanced error signal for unbalanced data sets.

Definition at line 57 of file DiscreteLoss.h.

Constructor & Destructor Documentation

◆ DiscreteLoss()

SHARK_EXPORT_SYMBOL shark::DiscreteLoss::DiscreteLoss ( RealMatrix const &  cost)

Constructor

Parameters
costcost matrix in the format (target, prediction).

Member Function Documentation

◆ defineBalancedCost()

SHARK_EXPORT_SYMBOL void shark::DiscreteLoss::defineBalancedCost ( UnlabeledData< unsigned int > const &  labels)

Define a new cost structure so that the cost of misclassifying a pattern is anti-proportional to the frequency of its class. This amounts to balancing the class-wise cost in unbalanced data sets (i.e., where one class is far more frequent than another).

Parameters
labelslabel set to which the balanced loss should be adapted

Referenced by name().

◆ defineCostMatrix()

SHARK_EXPORT_SYMBOL void shark::DiscreteLoss::defineCostMatrix ( RealMatrix const &  cost)

Define a new cost structure given by an explicit cost matrix.

Parameters
costcost matrix in the format (target, prediction).

Referenced by name().

◆ eval()

SHARK_EXPORT_SYMBOL double shark::DiscreteLoss::eval ( BatchLabelType const &  target,
BatchOutputType const &  prediction 
) const
virtual

inherited from AbstractLoss, evaluation of the loss function

Implements shark::AbstractLoss< unsigned int, unsigned int >.

Referenced by name().

◆ name()

std::string shark::DiscreteLoss::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 67 of file DiscreteLoss.h.

References defineBalancedCost(), defineCostMatrix(), eval(), and SHARK_EXPORT_SYMBOL.

Member Data Documentation

◆ m_cost

RealMatrix shark::DiscreteLoss::m_cost
protected

cost matrix

Definition at line 88 of file DiscreteLoss.h.


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