Inheritance diagram for classias::classify::linear_binary< model_tmpl >:
This template class implements a binary classifier with a linear discriminant model. The types of features and models are customizable. Any type that yields a feature weight with operator [] is acceptable for a model. The type of features must be compatible with the argument type of the operator
[] of the model. The typical configurations are:
std::vector<double>
, and features are integers (indices to the model array).std::map<std::string, double>
, and features are strings.The former configuration is preferable for faster training. The latter may be useful for implementing a classifier with string features.
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_binary (const model_type &model) | |
Constructs an object. | |
virtual | ~linear_binary () |
Destructs an object. | |
void | clear () |
Resets the classification result. | |
operator bool () const | |
Returns the binary label of the classification result. | |
value_type | score () const |
Returns the score of the classification result. | |
void | scale (const value_type &scale) |
Applies a scaling factor to the score. | |
template<class attribute_type> | |
void | set (const attribute_type &a, const value_type &value) |
Sets an attribute and value for the classification. | |
template<class iterator_type> | |
void | inner_product (iterator_type first, iterator_type last) |
Computes the inner product between a feature vector and the model. | |
Static Public Member Functions | |
static const char * | name () |
Returns the name of this classifier. | |
Protected Attributes | |
const model_type & | m_model |
The model. | |
value_type | m_score |
The score of this instance. |
classias::classify::linear_binary< model_tmpl >::linear_binary | ( | const model_type & | model | ) | [inline] |
Constructs an object.
model | The model associated with the classifier. |
void classias::classify::linear_binary< model_tmpl >::clear | ( | ) | [inline] |
Resets the classification result.
Call this function before sending a next classification instance.
classias::classify::linear_binary< model_tmpl >::operator bool | ( | ) | const [inline] |
Returns the binary label of the classification result.
true
for positive, and false
for negative. value_type classias::classify::linear_binary< model_tmpl >::score | ( | ) | const [inline] |
Returns the score of the classification result.
void classias::classify::linear_binary< model_tmpl >::scale | ( | const value_type & | scale | ) | [inline] |
Applies a scaling factor to the score.
scale | The scaling factor. |
void classias::classify::linear_binary< model_tmpl >::set | ( | const attribute_type & | a, | |
const value_type & | value | |||
) | [inline] |
Sets an attribute and value for the classification.
This function adds (model[a] * value) to the score.
a | The attribute identifier. | |
value | The attribute value. |
void classias::classify::linear_binary< model_tmpl >::inner_product | ( | iterator_type | first, | |
iterator_type | last | |||
) | [inline] |
Computes the inner product between a feature vector and the model.
A feature vector is represented by a range of iterators [first, last), whose element *it
is compatible with std::pair
. The member it->first
presents a feature identifier, and the member it->second
presents the feature value.
first | The iterator for the first element of attributes. | |
last | The iterator for the element just beyond the last element of attributes. |
static const char* classias::classify::linear_binary< model_tmpl >::name | ( | ) | [inline, static] |
Returns the name of this classifier.
Reimplemented in classias::classify::linear_binary_logistic< model_tmpl >, and classias::classify::linear_binary_hinge< model_tmpl >.