Inheritance diagram for classias::classify::linear_multi< model_tmpl >:

This template class implements a multi classifier with a linear discriminant model. The types of features, feature generators, and models are customizable. Any type that yields a feature weight with operator [] is acceptable for a model. A feature generator must convert a pair of an attribute and a label into a feature identifier that is compatible with the argument type of the operator [] of the model.
An instance is designed to have multiple candidates, and the candidate that yields the highest score is chosen as a classification result. The number of candidates must be set by resize() before computing candidate scores. Call set(), inner_product(), or scale() functions to compute the score of a candidate. After computing the score of all candidates, call finalize() function to determine the candidate with the highest score.
| model_tmpl | The type of a model (container of feature weights). Any type that yields a feature weight with operator [] is usable (e.g., arrays, std::vector, std::map). |
Public Types | |
| typedef model_tmpl | model_type |
| The type of a model. | |
| typedef model_type::value_type | value_type |
| The type of a feature weight. | |
Public Member Functions | |
| linear_multi (const model_type &model) | |
| Constructs an instance. | |
| virtual | ~linear_multi () |
| Destructs an object. | |
| void | clear () |
| Resets the classification result. | |
| void | resize (int n) |
| Reserves the working space for storing n candidates. | |
| int | size () const |
| Returns the number of candidates. | |
| int | argmax () const |
| Returns the argmax index. | |
| value_type | score (int i) |
| Returns the score of a candidate. | |
| void | scale (int i, const value_type &scale) |
| Applies a scaling factor to a score. | |
| template<class feature_generator_type> | |
| void | set (int i, feature_generator_type &fgen, const typename feature_generator_type::attribute_type &a, const typename feature_generator_type::label_type &l, const value_type &value) |
| Sets an attribute for a candidate. | |
| template<class feature_generator_type, class iterator_type> | |
| void | inner_product (int i, feature_generator_type &fgen, iterator_type first, iterator_type last, const typename feature_generator_type::label_type &l) |
| Computes the inner product between an attribute vector and the model. | |
| void | finalize () |
| Finalize the classification. | |
Static Public Member Functions | |
| static const char * | name () |
| Returns the name of this classifier. | |
Protected Types | |
| typedef std::vector< value_type > | scores_type |
| The type representing an array of scores. | |
Protected Attributes | |
| const model_type & | m_model |
| The model. | |
| scores_type | m_scores |
| The scores of labels. | |
| int | m_argmax |
| The index of the label that gives the highest score. | |
| classias::classify::linear_multi< model_tmpl >::linear_multi | ( | const model_type & | model | ) | [inline] |
Constructs an instance.
| model | The model associated with the classifier. |
| void classias::classify::linear_multi< model_tmpl >::clear | ( | ) | [inline] |
Resets the classification result.
Call this function before sending a next classification instance.
Reimplemented in classias::classify::linear_multi_logistic< model_tmpl >.
| void classias::classify::linear_multi< model_tmpl >::resize | ( | int | n | ) | [inline] |
Reserves the working space for storing n candidates.
Call this function to allocate a working space for n candidates.
| n | The number of candidates. |
| int classias::classify::linear_multi< model_tmpl >::size | ( | ) | const [inline] |
Returns the number of candidates.
| int classias::classify::linear_multi< model_tmpl >::argmax | ( | ) | const [inline] |
Returns the argmax index.
| value_type classias::classify::linear_multi< model_tmpl >::score | ( | int | i | ) | [inline] |
Returns the score of a candidate.
| i | The index for the candidate. |
| void classias::classify::linear_multi< model_tmpl >::scale | ( | int | i, | |
| const value_type & | scale | |||
| ) | [inline] |
Applies a scaling factor to a score.
| i | The index for the candidate. | |
| scale | The scaling factor. |
| void classias::classify::linear_multi< model_tmpl >::set | ( | int | i, | |
| feature_generator_type & | fgen, | |||
| const typename feature_generator_type::attribute_type & | a, | |||
| const typename feature_generator_type::label_type & | l, | |||
| const value_type & | value | |||
| ) | [inline] |
Sets an attribute for a candidate.
This function calls fgen.forward(a, l, f) to translate the pairs of the attribute (a) and label (l) to the feature (f), and adds (m_model[f] * value) to the score for the candidate i.
| i | The index for the candidate. | |
| fgen | The feature generator. | |
| a | The attribute identifier. | |
| l | The label for the candidate. | |
| value | The attribute value. |
| void classias::classify::linear_multi< model_tmpl >::inner_product | ( | int | i, | |
| feature_generator_type & | fgen, | |||
| iterator_type | first, | |||
| iterator_type | last, | |||
| const typename feature_generator_type::label_type & | l | |||
| ) | [inline] |
Computes the inner product between an attribute vector and the model.
An attribute vector is represented by a range of iterators [first, last), whose element *it is compatible with std::pair. The member it->first presents an attribute identifier, and the member it->second presents the attribute value. The feature generator (fgen) is used to convert a pair of attribute (a) and label (l) into a feature identifier.
| i | The index for the candidate. | |
| fgen | The feature generator. | |
| first | The iterator for the first element of attributes. | |
| last | The iterator for the element just beyond the last element of attributes. | |
| l | The label for the candidate. |
| void classias::classify::linear_multi< model_tmpl >::finalize | ( | ) | [inline] |
Finalize the classification.
Call this function before using argmax() function.
Reimplemented in classias::classify::linear_multi_logistic< model_tmpl >.
| static const char* classias::classify::linear_multi< model_tmpl >::name | ( | ) | [inline, static] |
Returns the name of this classifier.
Reimplemented in classias::classify::linear_multi_logistic< model_tmpl >.