classias::classify::linear_binary< model_tmpl > Class Template Reference

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

classias::classify::linear_binary_hinge< model_tmpl > classias::classify::linear_binary_logistic< model_tmpl >

Detailed Description

template<class model_tmpl>
class classias::classify::linear_binary< model_tmpl >

A template class for linear binary classifier.

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:

The former configuration is preferable for faster training. The latter may be useful for implementing a classifier with string features.

Parameters:
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_typem_model
 The model.
value_type m_score
 The score of this instance.


Constructor & Destructor Documentation

template<class model_tmpl>
classias::classify::linear_binary< model_tmpl >::linear_binary ( const model_type model  )  [inline]

Constructs an object.

Parameters:
model The model associated with the classifier.


Member Function Documentation

template<class model_tmpl>
void classias::classify::linear_binary< model_tmpl >::clear (  )  [inline]

Resets the classification result.

Call this function before sending a next classification instance.

template<class model_tmpl>
classias::classify::linear_binary< model_tmpl >::operator bool (  )  const [inline]

Returns the binary label of the classification result.

Returns:
bool The binary label: true for positive, and false for negative.

template<class model_tmpl>
value_type classias::classify::linear_binary< model_tmpl >::score (  )  const [inline]

Returns the score of the classification result.

Returns:
value_type The score, which is equivalent to the inner product of the feature vector with the model.

template<class model_tmpl>
void classias::classify::linear_binary< model_tmpl >::scale ( const value_type scale  )  [inline]

Applies a scaling factor to the score.

Parameters:
scale The scaling factor.

template<class model_tmpl>
template<class attribute_type>
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.

Parameters:
a The attribute identifier.
value The attribute value.

template<class model_tmpl>
template<class iterator_type>
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.

Parameters:
first The iterator for the first element of attributes.
last The iterator for the element just beyond the last element of attributes.

template<class model_tmpl>
static const char* classias::classify::linear_binary< model_tmpl >::name (  )  [inline, static]

Returns the name of this classifier.

Returns:
const char* The name of the classifier.

Reimplemented in classias::classify::linear_binary_logistic< model_tmpl >, and classias::classify::linear_binary_hinge< model_tmpl >.


Copyright (c) 2002-2009 by Naoaki Okazaki
Mon Dec 28 23:41:06 2009