shark::OneVersusOneClassifier< InputType, VectorType > Class Template Reference

One-versus-one Classifier. More...

#include <shark/Models/OneVersusOneClassifier.h>

+ Inheritance diagram for shark::OneVersusOneClassifier< InputType, VectorType >:

Public Types

typedef base_type::BatchInputType BatchInputType
 
typedef base_type::BatchOutputType BatchOutputType
 
- Public Types inherited from shark::AbstractModel< InputType, unsigned int, VectorType >
enum  Feature
 
typedef InputType InputType
 Defines the input type of the model. More...
 
typedef unsigned int OutputType
 Defines the output type of the model. More...
 
typedef AbstractModel< InputType, unsigned int, VectorTypeModelBaseType
 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< VectorType >
typedef VectorType ParameterVectorType
 

Public Member Functions

 OneVersusOneClassifier ()
 Constructor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
virtual VectorType parameterVector () const
 get internal parameters of the model More...
 
virtual void setParameterVector (VectorType const &newParameters)
 set internal parameters of the model More...
 
virtual std::size_t numberOfParameters () const
 return the size of the parameter vector More...
 
unsigned int numberOfClasses () const
 return number of classes More...
 
Shape inputShape () const
 Returns the expected shape of the input. More...
 
Shape outputShape () const
 Returns the shape of the output. More...
 
binary_classifier_type const & binary (unsigned int class_one, unsigned int class_zero) const
 Obtain binary classifier. More...
 
void addClass (std::vector< binary_classifier_type *> const &binmodels)
 Add binary classifiers for one more class to the model. More...
 
boost::shared_ptr< StatecreateState () const
 Creates an internal state of the model. More...
 
void eval (BatchInputType const &patterns, BatchOutputType &output, State &state) const
 
void read (InArchive &archive)
 from ISerializable, reads a model from an archive More...
 
void write (OutArchive &archive) const
 from ISerializable, writes a model to an archive More...
 
- Public Member Functions inherited from shark::AbstractModel< InputType, unsigned int, VectorType >
 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 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 (InputType const &pattern, OutputType &output) const
 Standard interface for evaluating the response of the model to a single pattern. 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< VectorType >
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 ()
 

Protected Attributes

unsigned int m_classes
 number of classes to be distinguished More...
 
std::vector< binary_classifier_type * > m_binary
 list of binary classifiers More...
 
- Protected Attributes inherited from shark::AbstractModel< InputType, unsigned int, VectorType >
Features m_features
 

Detailed Description

template<class InputType, class VectorType = RealVector>
class shark::OneVersusOneClassifier< InputType, VectorType >

One-versus-one Classifier.

The one-versus-one classifier combines a number of binary classifiers to form a multi-class ensemble classifier. In the one-versus-one model, there exists one binary classifier for each pair of classes. The predictions of all binary machines are combined with a simple voting scheme.
The classifier can be extended to handle more classes on the fly, without a need for re-training the existing binary models.

Definition at line 62 of file OneVersusOneClassifier.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputType, class VectorType = RealVector>
typedef base_type::BatchInputType shark::OneVersusOneClassifier< InputType, VectorType >::BatchInputType

Definition at line 68 of file OneVersusOneClassifier.h.

◆ BatchOutputType

template<class InputType, class VectorType = RealVector>
typedef base_type::BatchOutputType shark::OneVersusOneClassifier< InputType, VectorType >::BatchOutputType

Definition at line 69 of file OneVersusOneClassifier.h.

Constructor & Destructor Documentation

◆ OneVersusOneClassifier()

template<class InputType, class VectorType = RealVector>
shark::OneVersusOneClassifier< InputType, VectorType >::OneVersusOneClassifier ( )
inline

Constructor.

Definition at line 72 of file OneVersusOneClassifier.h.

Member Function Documentation

◆ addClass()

template<class InputType, class VectorType = RealVector>
void shark::OneVersusOneClassifier< InputType, VectorType >::addClass ( std::vector< binary_classifier_type *> const &  binmodels)
inline

Add binary classifiers for one more class to the model.

The parameter binmodels holds a vector of n binary classifiers, where n is the current number of classes. The i-th model is this list is supposed to output a value of 1 for class n and a value of 0 for class i when faced with the binary classification problem of separating class i from class n. Afterwards the model can predict the n+1 classes {0, ..., n}.

Definition at line 147 of file OneVersusOneClassifier.h.

References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, shark::OneVersusOneClassifier< InputType, VectorType >::m_classes, and SHARK_RUNTIME_CHECK.

Referenced by main().

◆ binary()

template<class InputType, class VectorType = RealVector>
binary_classifier_type const& shark::OneVersusOneClassifier< InputType, VectorType >::binary ( unsigned int  class_one,
unsigned int  class_zero 
) const
inline

Obtain binary classifier.

The method returns the binary classifier used to distinguish class_one from class_zero. The convention class_one > class_zero is used (the inverse classifier can be constructed from this one by flipping the labels). The binary classifier outputs a value of 1 for class_one and a value of zero for class_zero.

Definition at line 132 of file OneVersusOneClassifier.h.

References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, shark::OneVersusOneClassifier< InputType, VectorType >::m_classes, and SHARK_ASSERT.

◆ createState()

template<class InputType, class VectorType = RealVector>
boost::shared_ptr<State> shark::OneVersusOneClassifier< InputType, VectorType >::createState ( ) const
inlinevirtual

Creates an internal state of the model.

The state is needed when the derivatives are to be calculated. Eval can store a state which is then reused to speed up the calculations of the derivatives. This also allows eval to be evaluated in parallel!

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

Definition at line 154 of file OneVersusOneClassifier.h.

References shark::AbstractModel< InputType, unsigned int, VectorType >::eval().

◆ eval()

template<class InputType, class VectorType = RealVector>
void shark::OneVersusOneClassifier< InputType, VectorType >::eval ( BatchInputType const &  patterns,
BatchOutputType output,
State state 
) const
inlinevirtual

One-versus-one prediction: evaluate all binary classifiers, collect their votes, and return the class with most votes.

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

Definition at line 161 of file OneVersusOneClassifier.h.

References shark::batchSize(), shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.

◆ inputShape()

template<class InputType, class VectorType = RealVector>
Shape shark::OneVersusOneClassifier< InputType, VectorType >::inputShape ( ) const
inlinevirtual

◆ name()

template<class InputType, class VectorType = RealVector>
std::string shark::OneVersusOneClassifier< InputType, VectorType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 77 of file OneVersusOneClassifier.h.

◆ numberOfClasses()

template<class InputType, class VectorType = RealVector>
unsigned int shark::OneVersusOneClassifier< InputType, VectorType >::numberOfClasses ( ) const
inline

return number of classes

Definition at line 114 of file OneVersusOneClassifier.h.

References shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.

◆ numberOfParameters()

template<class InputType, class VectorType = RealVector>
virtual std::size_t shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters ( ) const
inlinevirtual

◆ outputShape()

template<class InputType, class VectorType = RealVector>
Shape shark::OneVersusOneClassifier< InputType, VectorType >::outputShape ( ) const
inlinevirtual

Returns the shape of the output.

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

Definition at line 120 of file OneVersusOneClassifier.h.

◆ parameterVector()

template<class InputType, class VectorType = RealVector>
virtual VectorType shark::OneVersusOneClassifier< InputType, VectorType >::parameterVector ( ) const
inlinevirtual

◆ read()

template<class InputType, class VectorType = RealVector>
void shark::OneVersusOneClassifier< InputType, VectorType >::read ( InArchive archive)
inlinevirtual

◆ setParameterVector()

template<class InputType, class VectorType = RealVector>
virtual void shark::OneVersusOneClassifier< InputType, VectorType >::setParameterVector ( VectorType const &  newParameters)
inlinevirtual

◆ write()

template<class InputType, class VectorType = RealVector>
void shark::OneVersusOneClassifier< InputType, VectorType >::write ( OutArchive archive) const
inlinevirtual

Member Data Documentation

◆ m_binary

◆ m_classes


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