Loss function interface. More...
#include <shark/ObjectiveFunctions/Loss/AbstractLoss.h>
Public Types | |
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< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Member Functions | |
AbstractLoss () | |
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 | |
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 | |
virtual double | evalDerivative (BatchLabelType const &target, BatchOutputType const &prediction, BatchOutputType &gradient) const |
evaluate the loss and the derivative w.r.t. the prediction | |
double | eval (Data< LabelType > const &targets, Data< OutputType > const &predictions) const |
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 Features & | features () 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 () |
virtual std::string | name () const |
returns the name of the object | |
Additional Inherited Members | |
Protected Attributes inherited from shark::AbstractCost< LabelT, OutputT > | |
Features | m_features |
Loss function interface.
Definition at line 62 of file AbstractLoss.h.
typedef Batch<LabelType>::type shark::AbstractLoss< LabelT, OutputT >::BatchLabelType |
Definition at line 71 of file AbstractLoss.h.
typedef Batch<OutputType>::type shark::AbstractLoss< LabelT, OutputT >::BatchOutputType |
Definition at line 70 of file AbstractLoss.h.
typedef ConstProxyReference<LabelTypeconst>::type shark::AbstractLoss< LabelT, OutputT >::ConstLabelReference |
Const references to LabelType.
Definition at line 74 of file AbstractLoss.h.
typedef ConstProxyReference<OutputTypeconst>::type shark::AbstractLoss< LabelT, OutputT >::ConstOutputReference |
Const references to OutputType.
Definition at line 76 of file AbstractLoss.h.
typedef LabelT shark::AbstractLoss< LabelT, OutputT >::LabelType |
Definition at line 67 of file AbstractLoss.h.
typedef RealMatrix shark::AbstractLoss< LabelT, OutputT >::MatrixType |
Definition at line 68 of file AbstractLoss.h.
typedef OutputT shark::AbstractLoss< LabelT, OutputT >::OutputType |
Definition at line 66 of file AbstractLoss.h.
|
inline |
Definition at line 78 of file AbstractLoss.h.
References shark::AbstractCost< LabelT, OutputT >::IS_LOSS_FUNCTION, and shark::AbstractCost< LabelT, OutputT >::m_features.
|
pure virtual |
evaluate the loss for a batch of targets and a prediction
target | target values |
prediction | predictions, typically made by a model |
Implemented in shark::AbsoluteLoss< VectorType >, shark::EpsilonHingeLoss, shark::HingeLoss, shark::HuberLoss, shark::SquaredEpsilonHingeLoss, shark::SquaredHingeLoss, shark::SquaredLoss< OutputType, LabelType >, shark::SquaredLoss< OutputType, unsigned int >, shark::SquaredLoss< Sequence, Sequence >, shark::ZeroOneLoss< LabelType, OutputType >, shark::ZeroOneLoss< unsigned int, blas::vector< Float > >, shark::DiscreteLoss, shark::AbsoluteLoss< VectorType >, shark::CrossEntropy< blas::vector< T, Device >, blas::vector< T, Device > >, shark::SquaredLoss< OutputType, LabelType >, and shark::ZeroOneLoss< LabelType, OutputType >.
Referenced by shark::LooError< ModelTypeT, LabelType >::eval(), shark::AbstractLoss< LabelT, OutputT >::eval(), shark::AbstractLoss< LabelT, OutputT >::eval(), shark::AbstractLoss< LabelT, OutputT >::operator()(), and shark::AbstractLoss< LabelT, OutputT >::operator()().
|
inlinevirtual |
evaluate the loss for a target and a prediction
target | target value |
prediction | prediction, typically made by a model |
Reimplemented in shark::AbsoluteLoss< VectorType >, shark::CrossEntropy< unsigned int, OutputType >, shark::CrossEntropy< blas::vector< T, Device >, blas::vector< T, Device > >, shark::SquaredLoss< OutputType, LabelType >, and shark::ZeroOneLoss< LabelType, OutputType >.
Definition at line 92 of file AbstractLoss.h.
References shark::AbstractLoss< LabelT, OutputT >::eval(), and shark::getBatchElement().
|
inlinevirtual |
from AbstractCost
targets | target values |
predictions | predictions, typically made by a model |
Implements shark::AbstractCost< LabelT, OutputT >.
Reimplemented in shark::SquaredLoss< OutputType, LabelType >, and shark::ZeroOneLoss< LabelType, OutputType >.
Definition at line 149 of file AbstractLoss.h.
References shark::Data< Type >::batch(), shark::AbstractLoss< LabelT, OutputT >::eval(), shark::Data< Type >::numberOfBatches(), shark::Data< Type >::numberOfElements(), SHARK_CRITICAL_REGION, SHARK_PARALLEL_FOR, and SIZE_CHECK.
|
inlinevirtual |
evaluate the loss and the derivative w.r.t. the prediction
target | target value |
prediction | prediction, typically made by a model |
gradient | the gradient of the loss function with respect to the prediction |
Reimplemented in shark::SquaredLoss< OutputType, LabelType >, shark::EpsilonHingeLoss, shark::HingeLoss, shark::HuberLoss, shark::SquaredEpsilonHingeLoss, shark::SquaredHingeLoss, shark::SquaredLoss< OutputType, unsigned int >, and shark::SquaredLoss< Sequence, Sequence >.
Definition at line 139 of file AbstractLoss.h.
References shark::AbstractCost< LabelT, OutputT >::HAS_FIRST_DERIVATIVE, and SHARK_FEATURE_EXCEPTION_DERIVED.
|
inlinevirtual |
evaluate the loss and its derivative for a target and a prediction
target | target value |
prediction | prediction, typically made by a model |
gradient | the gradient of the loss function with respect to the prediction |
Reimplemented in shark::CrossEntropy< unsigned int, OutputType >.
Definition at line 105 of file AbstractLoss.h.
References shark::AbstractLoss< LabelT, OutputT >::evalDerivative(), and shark::getBatchElement().
Referenced by shark::AbstractLoss< LabelT, OutputT >::evalDerivative(), shark::VariationalAutoencoderError< SearchPointType >::evalDerivative(), and shark::KernelSGDTrainer< InputType, CacheType >::train().
|
inlinevirtual |
evaluate the loss and its first and second derivative for a target and a prediction
target | target value |
prediction | prediction, typically made by a model |
gradient | the gradient of the loss function with respect to the prediction |
hessian | the hessian of the loss function with respect to the prediction |
Definition at line 122 of file AbstractLoss.h.
References shark::AbstractCost< LabelT, OutputT >::HAS_SECOND_DERIVATIVE, and SHARK_FEATURE_EXCEPTION_DERIVED.
|
inline |
Definition at line 173 of file AbstractLoss.h.
References shark::AbstractLoss< LabelT, OutputT >::eval().
|
inline |
evaluate the loss for a target and a prediction
target | target value |
prediction | prediction, typically made by a model |
Definition at line 170 of file AbstractLoss.h.
References shark::AbstractLoss< LabelT, OutputT >::eval().