shark::Classifier< Model > Class Template Reference

Conversion of real-valued or vector valued outputs to class labels. More...

#include <shark/Models/Classifier.h>

+ Inheritance diagram for shark::Classifier< Model >:

Public Types

typedef Model::InputType InputType
 
typedef unsigned int OutputType
 
typedef Batch< InputType >::type BatchInputType
 
typedef Batch< unsigned int >::type BatchOutputType
 
- Public Types inherited from shark::AbstractModel< Model::InputType, unsigned int >
enum  Feature
 
typedef Model::InputType InputType
 Defines the input type of the model. More...
 
typedef unsigned int OutputType
 Defines the output type of the model. More...
 
typedef AbstractModel< Model::InputType, unsigned int, RealVector > ModelBaseType
 Defines the BaseType used by the model (this type). Useful for creating derived models. More...
 
typedef Batch< InputType >::type BatchInputType
 defines the batch type of the input type. More...
 
typedef Batch< OutputType >::type BatchOutputType
 defines the batch type of the output type More...
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable< RealVector >
typedef RealVector ParameterVectorType
 

Public Member Functions

 Classifier ()
 
 Classifier (Model const &decisionFunction)
 
std::string name () const
 returns the name of the object More...
 
RealVector parameterVector () const
 Return the parameter vector. More...
 
void setParameterVector (RealVector const &newParameters)
 Set the parameter vector. More...
 
std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
Shape inputShape () const
 Returns the expected shape of the input. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
RealVector const & bias () const
 
RealVector & bias ()
 
Model const & decisionFunction () const
 Return the decision function. More...
 
Model & decisionFunction ()
 Return the decision function. More...
 
void eval (BatchInputType const &input, BatchOutputType &output) const
 
void eval (BatchInputType const &input, BatchOutputType &output, State &state) const
 
void eval (InputType const &pattern, OutputType &output) const
 Standard interface for evaluating the response of the model to a single pattern. More...
 
void read (InArchive &archive)
 From ISerializable. More...
 
void write (OutArchive &archive) const
 From ISerializable. More...
 
- Public Member Functions inherited from shark::AbstractModel< Model::InputType, unsigned int >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasFirstParameterDerivative () const
 Returns true when the first parameter derivative is implemented. More...
 
bool hasFirstInputDerivative () const
 Returns true when the first input derivative is implemented. More...
 
virtual boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
virtual void eval (BatchInputType const &patterns, BatchOutputType &outputs) const
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
virtual void eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const=0
 Standard interface for evaluating the response of the model to a batch of patterns. More...
 
Data< OutputTypeoperator() (Data< InputType > const &patterns) const
 Model evaluation as an operator for a whole dataset. This is a convenience function. More...
 
OutputType operator() (InputType const &pattern) const
 Model evaluation as an operator for a single pattern. This is a convenience function. More...
 
BatchOutputType operator() (BatchInputType const &patterns) const
 Model evaluation as an operator for a single pattern. This is a convenience function. More...
 
virtual void weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const
 calculates the weighted sum of derivatives w.r.t the parameters. More...
 
virtual void weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const
 calculates the weighted sum of derivatives w.r.t the inputs More...
 
virtual void weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, RealVector &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time More...
 
- Public Member Functions inherited from shark::IParameterizable< RealVector >
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractModel< Model::InputType, unsigned int >
Features m_features
 

Detailed Description

template<class Model>
class shark::Classifier< Model >

Conversion of real-valued or vector valued outputs to class labels.

The Classifier is a model converting the real-valued vector output of an underlying decision function to a class label 0, ..., d-1 by means of an arg-max operation. The class returns the argument of the maximal input component as its output. This convertson is adjusted to interpret the output of a linear model, a neural network or a support vector machine for multi-category classification.

In the special case that d is 1, it is assumed that the model can be represented as a 2 d vector with both components having the same value but opposite sign. In consequence, a positive output of the model is interpreted as class 1, a negative as class 0.

The underlying decision function is an arbitrary model. It should be default constructable and it can be accessed using decisionFunction(). The parameters of the Classifier are the ones of the decision function.

Optionally the model allows to set bias values which are added on the predicted values of the decision function. Thus adding positive weights on a class makes it more likely to be predicted. In the binary case with a single output, a positive weight makes class one more likely and a negative weight class 0.

Definition at line 64 of file Classifier.h.

Member Typedef Documentation

◆ BatchInputType

template<class Model>
typedef Batch<InputType>::type shark::Classifier< Model >::BatchInputType

Definition at line 71 of file Classifier.h.

◆ BatchOutputType

template<class Model>
typedef Batch<unsigned int>::type shark::Classifier< Model >::BatchOutputType

Definition at line 72 of file Classifier.h.

◆ InputType

template<class Model>
typedef Model::InputType shark::Classifier< Model >::InputType

Definition at line 69 of file Classifier.h.

◆ OutputType

template<class Model>
typedef unsigned int shark::Classifier< Model >::OutputType

Definition at line 70 of file Classifier.h.

Constructor & Destructor Documentation

◆ Classifier() [1/2]

template<class Model>
shark::Classifier< Model >::Classifier ( )
inline

Definition at line 74 of file Classifier.h.

◆ Classifier() [2/2]

template<class Model>
shark::Classifier< Model >::Classifier ( Model const &  decisionFunction)
inline

Definition at line 75 of file Classifier.h.

Member Function Documentation

◆ bias() [1/2]

template<class Model>
RealVector const& shark::Classifier< Model >::bias ( ) const
inline

◆ bias() [2/2]

template<class Model>
RealVector& shark::Classifier< Model >::bias ( )
inline

Definition at line 107 of file Classifier.h.

◆ decisionFunction() [1/2]

template<class Model>
Model const& shark::Classifier< Model >::decisionFunction ( ) const
inline

◆ decisionFunction() [2/2]

template<class Model>
Model& shark::Classifier< Model >::decisionFunction ( )
inline

Return the decision function.

Definition at line 117 of file Classifier.h.

◆ eval() [1/3]

template<class Model>
void shark::Classifier< Model >::eval ( BatchInputType const &  input,
BatchOutputType output 
) const
inline

◆ eval() [2/3]

template<class Model>
void shark::Classifier< Model >::eval ( BatchInputType const &  input,
BatchOutputType output,
State state 
) const
inline

Definition at line 142 of file Classifier.h.

◆ eval() [3/3]

template<class Model>
void shark::Classifier< Model >::eval ( InputType const &  pattern,
OutputType output 
) const
inlinevirtual

Standard interface for evaluating the response of the model to a single pattern.

Parameters
patternthe input of the model
outputthe prediction or response of the model to the pattern

Reimplemented from shark::AbstractModel< Model::InputType, unsigned int >.

Definition at line 146 of file Classifier.h.

◆ inputShape()

template<class Model>
Shape shark::Classifier< Model >::inputShape ( ) const
inlinevirtual

Returns the expected shape of the input.

Implements shark::AbstractModel< Model::InputType, unsigned int >.

Definition at line 94 of file Classifier.h.

◆ name()

template<class Model>
std::string shark::Classifier< Model >::name ( ) const
inlinevirtual

returns the name of the object

Reimplemented from shark::INameable.

Definition at line 78 of file Classifier.h.

◆ numberOfParameters()

template<class Model>
std::size_t shark::Classifier< Model >::numberOfParameters ( ) const
inlinevirtual

Return the number of parameters.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 89 of file Classifier.h.

◆ outputShape()

template<class Model>
Shape shark::Classifier< Model >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

For the classifier, Shape is 0 as the output is a scalar

Implements shark::AbstractModel< Model::InputType, unsigned int >.

Definition at line 100 of file Classifier.h.

◆ parameterVector()

template<class Model>
RealVector shark::Classifier< Model >::parameterVector ( ) const
inlinevirtual

Return the parameter vector.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 81 of file Classifier.h.

◆ read()

template<class Model>
void shark::Classifier< Model >::read ( InArchive archive)
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractModel< Model::InputType, unsigned int >.

Definition at line 165 of file Classifier.h.

◆ setParameterVector()

template<class Model>
void shark::Classifier< Model >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

Set the parameter vector.

Reimplemented from shark::IParameterizable< RealVector >.

Definition at line 85 of file Classifier.h.

◆ write()

template<class Model>
void shark::Classifier< Model >::write ( OutArchive archive) const
inlinevirtual

From ISerializable.

Reimplemented from shark::AbstractModel< Model::InputType, unsigned int >.

Definition at line 170 of file Classifier.h.


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