One-versus-one Classifier. More...
#include <shark/Models/OneVersusOneClassifier.h>
 Inheritance diagram for shark::OneVersusOneClassifier< InputType, VectorType >:
 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< InputTypeT, OutputTypeT, ParameterVectorType > | |
| enum | Feature { HAS_FIRST_PARAMETER_DERIVATIVE = 1 , HAS_FIRST_INPUT_DERIVATIVE = 4 } | 
| typedef InputTypeT | InputType | 
| Defines the input type of the model. | |
| typedef OutputTypeT | OutputType | 
| Defines the output type of the model. | |
| typedef AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType > | ModelBaseType | 
| Defines the BaseType used by the model (this type). Useful for creating derived models. | |
| typedef Batch< InputType >::type | BatchInputType | 
| defines the batch type of the input type. | |
| typedef Batch< OutputType >::type | BatchOutputType | 
| defines the batch type of the output type | |
| typedef TypedFlags< Feature > | Features | 
| typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException | 
|  Public Types inherited from shark::IParameterizable< VectorType > | |
| typedef VectorType | ParameterVectorType | 
| Public Member Functions | |
| OneVersusOneClassifier () | |
| Constructor. | |
| std::string | name () const | 
| From INameable: return the class name. | |
| virtual VectorType | parameterVector () const | 
| get internal parameters of the model | |
| virtual void | setParameterVector (VectorType const &newParameters) | 
| set internal parameters of the model | |
| virtual std::size_t | numberOfParameters () const | 
| return the size of the parameter vector | |
| unsigned int | numberOfClasses () const | 
| return number of classes | |
| Shape | inputShape () const | 
| Returns the expected shape of the input. | |
| Shape | outputShape () const | 
| Returns the shape of the output. | |
| binary_classifier_type const & | binary (unsigned int class_one, unsigned int class_zero) const | 
| Obtain binary classifier. | |
| void | addClass (std::vector< binary_classifier_type * > const &binmodels) | 
| Add binary classifiers for one more class to the model. | |
| boost::shared_ptr< State > | createState () const | 
| Creates an internal state of the model. | |
| void | eval (BatchInputType const &patterns, BatchOutputType &output, State &state) const | 
| void | read (InArchive &archive) | 
| from ISerializable, reads a model from an archive | |
| void | write (OutArchive &archive) const | 
| from ISerializable, writes a model to an archive | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const | 
| Standard interface for evaluating the response of the model to a batch of patterns. | |
| 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. | |
| virtual void | eval (InputType const &pattern, OutputType &output) const | 
| Standard interface for evaluating the response of the model to a single pattern. | |
|  Public Member Functions inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType > | |
| AbstractModel () | |
| virtual | ~AbstractModel () | 
| const Features & | features () const | 
| virtual void | updateFeatures () | 
| bool | hasFirstParameterDerivative () const | 
| Returns true when the first parameter derivative is implemented. | |
| bool | hasFirstInputDerivative () const | 
| Returns true when the first input derivative is implemented. | |
| Data< OutputType > | operator() (Data< InputType > const &patterns) const | 
| Model evaluation as an operator for a whole dataset. This is a convenience function. | |
| OutputType | operator() (InputType const &pattern) const | 
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| BatchOutputType | operator() (BatchInputType const &patterns) const | 
| Model evaluation as an operator for a single pattern. This is a convenience function. | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType &derivative) const | 
| calculates the weighted sum of derivatives w.r.t the parameters. | |
| 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 | |
| virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &outputs, BatchOutputType const &coefficients, State const &state, ParameterVectorType ¶meterDerivative, BatchInputType &inputDerivative) const | 
| calculates weighted input and parameter derivative at the same time | |
|  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. | |
| void | load (InArchive &archive, unsigned int version) | 
| Versioned loading of components, calls read(...). | |
| void | save (OutArchive &archive, unsigned int version) const | 
| Versioned storing of components, calls write(...). | |
| BOOST_SERIALIZATION_SPLIT_MEMBER () | |
| Protected Attributes | |
| unsigned int | m_classes | 
| number of classes to be distinguished | |
| std::vector< binary_classifier_type * > | m_binary | 
| list of binary classifiers | |
|  Protected Attributes inherited from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType > | |
| Features | m_features | 
One-versus-one Classifier.
Definition at line 63 of file OneVersusOneClassifier.h.
| typedef base_type::BatchInputType shark::OneVersusOneClassifier< InputType, VectorType >::BatchInputType | 
Definition at line 69 of file OneVersusOneClassifier.h.
| typedef base_type::BatchOutputType shark::OneVersusOneClassifier< InputType, VectorType >::BatchOutputType | 
Definition at line 70 of file OneVersusOneClassifier.h.
| 
 | inline | 
Constructor.
Definition at line 73 of file OneVersusOneClassifier.h.
| 
 | 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 148 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, shark::OneVersusOneClassifier< InputType, VectorType >::m_classes, and SHARK_RUNTIME_CHECK.
Referenced by main().
| 
 | inline | 
Obtain binary classifier.
Definition at line 133 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, shark::OneVersusOneClassifier< InputType, VectorType >::m_classes, and SHARK_ASSERT.
| 
 | 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< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 155 of file OneVersusOneClassifier.h.
| 
 | inlinevirtual | 
One-versus-one prediction: evaluate all binary classifiers, collect their votes, and return the class with most votes.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 162 of file OneVersusOneClassifier.h.
References shark::batchSize(), shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.
| 
 | inlinevirtual | 
Standard interface for evaluating the response of the model to a batch of patterns.
| patterns | the inputs of the model | 
| outputs | the predictions or response of the model to every pattern | 
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 163 of file AbstractModel.h.
| 
 | virtual | 
Standard interface for evaluating the response of the model to a batch of patterns.
| patterns | the inputs of the model | 
| outputs | the predictions or response of the model to every pattern | 
| state | intermediate results stored by eval which can be reused for derivative computation. | 
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
| 
 | inlinevirtual | 
Standard interface for evaluating the response of the model to a single pattern.
| pattern | the input of the model | 
| output | the prediction or response of the model to the pattern | 
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 179 of file AbstractModel.h.
| 
 | inlinevirtual | 
Returns the expected shape of the input.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 118 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary.
| 
 | inlinevirtual | 
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 78 of file OneVersusOneClassifier.h.
| 
 | inline | 
return number of classes
Definition at line 115 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.
| 
 | inlinevirtual | 
return the size of the parameter vector
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 107 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters().
Referenced by shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters(), shark::OneVersusOneClassifier< InputType, VectorType >::parameterVector(), and shark::OneVersusOneClassifier< InputType, VectorType >::setParameterVector().
| 
 | inlinevirtual | 
Returns the shape of the output.
Implements shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 121 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.
| 
 | inlinevirtual | 
get internal parameters of the model
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 83 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters().
| 
 | inlinevirtual | 
from ISerializable, reads a model from an archive
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 201 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.
| 
 | inlinevirtual | 
set internal parameters of the model
Reimplemented from shark::IParameterizable< VectorType >.
Definition at line 96 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters(), and SHARK_RUNTIME_CHECK.
| 
 | inlinevirtual | 
from ISerializable, writes a model to an archive
Reimplemented from shark::AbstractModel< InputTypeT, OutputTypeT, ParameterVectorType >.
Definition at line 208 of file OneVersusOneClassifier.h.
References shark::OneVersusOneClassifier< InputType, VectorType >::m_binary, and shark::OneVersusOneClassifier< InputType, VectorType >::m_classes.
| 
 | protected | 
list of binary classifiers
Definition at line 217 of file OneVersusOneClassifier.h.
Referenced by shark::OneVersusOneClassifier< InputType, VectorType >::addClass(), shark::OneVersusOneClassifier< InputType, VectorType >::binary(), shark::OneVersusOneClassifier< InputType, VectorType >::eval(), shark::OneVersusOneClassifier< InputType, VectorType >::inputShape(), shark::OneVersusOneClassifier< InputType, VectorType >::numberOfParameters(), shark::OneVersusOneClassifier< InputType, VectorType >::parameterVector(), shark::OneVersusOneClassifier< InputType, VectorType >::read(), shark::OneVersusOneClassifier< InputType, VectorType >::setParameterVector(), and shark::OneVersusOneClassifier< InputType, VectorType >::write().
| 
 | protected | 
number of classes to be distinguished
Definition at line 216 of file OneVersusOneClassifier.h.
Referenced by shark::OneVersusOneClassifier< InputType, VectorType >::addClass(), shark::OneVersusOneClassifier< InputType, VectorType >::binary(), shark::OneVersusOneClassifier< InputType, VectorType >::eval(), shark::OneVersusOneClassifier< InputType, VectorType >::numberOfClasses(), shark::OneVersusOneClassifier< InputType, VectorType >::outputShape(), shark::OneVersusOneClassifier< InputType, VectorType >::read(), and shark::OneVersusOneClassifier< InputType, VectorType >::write().