MultiClass_ECOC Class Reference

Multiclass classification using error-correcting output code. More...

#include <multiclass_ecoc.h>

Inheritance diagram for MultiClass_ECOC:

Inheritance graph
[legend]
Collaboration diagram for MultiClass_ECOC:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MultiClass_ECOC ()
 MultiClass_ECOC (std::istream &is)
virtual const id_tid () const
virtual MultiClass_ECOCcreate () const
 Create a new object using the default constructor.
virtual MultiClass_ECOCclone () const
 Create a new object by replicating itself.
REAL model_weight (UINT n) const
const ECOC_TABLEECOC_table () const
void set_ECOC_table (const ECOC_TABLE &)
void set_ECOC_table (ECOC_TYPE)
void set_ECOC_table (UINT, const ECOC_VECTOR &)
UINT n_class () const
virtual bool support_weighted_data () const
 Whether the learning model/algorithm supports unequally weighted data.
virtual REAL c_error (const Output &out, const Output &y) const
 Error measure for classification problems.
virtual void set_train_data (const pDataSet &, const pDataWgt &=0)
 Set the data set and sample weight to be used in training.
virtual void train ()
 Train with preset data set and sample weight.
virtual void reset ()
virtual Output operator() (const Input &) const
virtual Output get_output (UINT idx) const
 Get the output of the hypothesis on the idx-th input.
virtual REAL margin (UINT) const
 Report the (unnormalized) margin of the example i.
virtual REAL margin_of (const Input &, const Output &) const
 Report the (unnormalized) margin of an example (x, y).
REAL cost () const
 The in-sample exponential cost defined in my paper.

Protected Member Functions

virtual REAL ECOC_distance (const Output &, const ECOC_VECTOR &) const
virtual REAL ECOC_distance (REAL, int, REAL, REAL=0) const
const std::vector< REAL > & distances (const Input &) const
const std::vector< REAL > & distances (UINT) const
bool is_full_partition (const ECOC_VECTOR &) const
 Does the partition only consist of -1 and +1?
virtual void setup_aux ()
 Prepare auxiliary variables for current n_in_agg.
virtual bool ECOC_partition (UINT, ECOC_VECTOR &) const
virtual pLearnModel train_with_partition (ECOC_VECTOR &) const
virtual REAL assign_weight (const ECOC_VECTOR &, const LearnModel &) const
virtual void update_aux (const ECOC_VECTOR &)
 Update those auxiliary variables after this round of learning.
virtual bool serialize (std::ostream &, ver_list &) const
virtual bool unserialize (std::istream &, ver_list &, const id_t &=NIL_ID)

Protected Attributes

std::vector< REALlm_wgt
 hypothesis weight
ECOC_TABLE ecoc
ECOC_TYPE ecoc_type
UINT nclass
 number of classes
std::vector< REALlabels
 class labels
std::vector< UINTex_class
 class number of examples
std::vector< REALlocal_d

Detailed Description

Multiclass classification using error-correcting output code.

Definition at line 30 of file multiclass_ecoc.h.


Constructor & Destructor Documentation

MultiClass_ECOC  )  [inline]
 

Definition at line 44 of file multiclass_ecoc.h.

References LearnModel::set_dimensions().

Referenced by MultiClass_ECOC::clone(), and MultiClass_ECOC::create().

MultiClass_ECOC std::istream &  is  )  [inline, explicit]
 

Definition at line 46 of file multiclass_ecoc.h.


Member Function Documentation

virtual REAL assign_weight const ECOC_VECTOR ,
const LearnModel
const [inline, protected, virtual]
 

Reimplemented in AdaBoost_ECOC.

Definition at line 121 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::train().

REAL c_error const Output out,
const Output y
const [virtual]
 

Error measure for classification problems.

Parameters:
out is the output from the learned hypothesis.
y is the real output.
Returns:
Classification error between out and y. The error measure is not necessary symmetric. A commonly used measure is out != y.

Reimplemented from LearnModel.

Definition at line 124 of file multiclass_ecoc.cpp.

References LABEL_EQUAL, and LearnModel::n_output().

virtual MultiClass_ECOC* clone  )  const [inline, virtual]
 

Create a new object by replicating itself.

Returns:
A pointer to the new copy.
The code for a derived class Derived is always
 return new Derived(*this); 
Though seemingly redundant, it helps to copy an object without knowing the real type of the object.
See also:
C++ FAQ Lite 20.6

Implements Aggregating.

Reimplemented in AdaBoost_ECOC, and AdaBoost_ERP.

Definition at line 51 of file multiclass_ecoc.h.

References MultiClass_ECOC::MultiClass_ECOC().

REAL cost  )  const
 

The in-sample exponential cost defined in my paper.

Definition at line 399 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::distances(), MultiClass_ECOC::ex_class, LearnModel::ptd, and LearnModel::ptw.

virtual MultiClass_ECOC* create  )  const [inline, virtual]
 

Create a new object using the default constructor.

The code for a derived class Derived is always

 return new Derived(); 

Implements Aggregating.

Reimplemented in AdaBoost_ECOC, and AdaBoost_ERP.

Definition at line 50 of file multiclass_ecoc.h.

References MultiClass_ECOC::MultiClass_ECOC().

const std::vector< REAL > & distances UINT   )  const [protected]
 

Definition at line 263 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, MultiClass_ECOC::ECOC_distance(), MultiClass_ECOC::get_output(), Aggregating::lm, MultiClass_ECOC::lm_wgt, and Aggregating::n_in_agg.

const std::vector< REAL > & distances const Input  )  const [protected]
 

Note:
It might be unsafe to use a reference to a local variable as the return value

Definition at line 243 of file multiclass_ecoc.cpp.

References Aggregating::lm, MultiClass_ECOC::lm_wgt, Aggregating::n_in_agg, and LearnModel::n_output().

Referenced by MultiClass_ECOC::cost(), MultiClass_ECOC::get_output(), MultiClass_ECOC::margin(), MultiClass_ECOC::margin_of(), MultiClass_ECOC::operator()(), and AdaBoost_ECOC::setup_aux().

REAL ECOC_distance REAL  ,
int  ,
REAL  ,
REAL  = 0
const [protected, virtual]
 

Definition at line 348 of file multiclass_ecoc.cpp.

REAL ECOC_distance const Output ,
const ECOC_VECTOR
const [protected, virtual]
 

Definition at line 337 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::lm_wgt.

Referenced by MultiClass_ECOC::distances().

bool ECOC_partition UINT  ,
ECOC_VECTOR
const [protected, virtual]
 

Reimplemented in AdaBoost_ECOC, and AdaBoost_ERP.

Definition at line 360 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, and Aggregating::size().

Referenced by AdaBoost_ERP::ECOC_partition(), AdaBoost_ECOC::ECOC_partition(), and MultiClass_ECOC::train().

const ECOC_TABLE& ECOC_table  )  const [inline]
 

Definition at line 55 of file multiclass_ecoc.h.

References MultiClass_ECOC::ecoc.

Output get_output UINT  idx  )  const [virtual]
 

Get the output of the hypothesis on the idx-th input.

Note:
It is possible to cache results to save computational effort.

Reimplemented from LearnModel.

Definition at line 307 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::distances(), MultiClass_ECOC::ecoc, GET_BEST_CLASS, MultiClass_ECOC::labels, and LearnModel::ptw.

Referenced by MultiClass_ECOC::distances().

virtual const id_t& id  )  const [virtual]
 

Returns:
Class ID string (class name)

Implements Object.

Reimplemented in AdaBoost_ECOC, and AdaBoost_ERP.

Referenced by MultiClass_ECOC::train().

bool is_full_partition const ECOC_VECTOR  )  const [protected]
 

Does the partition only consist of -1 and +1?

Definition at line 353 of file multiclass_ecoc.cpp.

Referenced by AdaBoost_ECOC::smpwgt_with_partition(), AdaBoost_ERP::train_with_partition(), AdaBoost_ECOC::train_with_partition(), and AdaBoost_ECOC::update_aux().

REAL margin UINT  idx  )  const [virtual]
 

Report the (unnormalized) margin of the example i.

Note:
It is possible to cache results to save computational effort.

Reimplemented from LearnModel.

Definition at line 328 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::distances(), MultiClass_ECOC::ex_class, GET_MARGIN, and LearnModel::ptw.

REAL margin_of const Input ,
const Output
const [virtual]
 

Report the (unnormalized) margin of an example (x, y).

Reimplemented from LearnModel.

Definition at line 320 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::distances(), GET_MARGIN, LABEL2INDEX, LABEL_EQUAL, and MultiClass_ECOC::labels.

REAL model_weight UINT  n  )  const [inline]
 

Definition at line 54 of file multiclass_ecoc.h.

References MultiClass_ECOC::lm_wgt.

UINT n_class  )  const [inline]
 

Definition at line 59 of file multiclass_ecoc.h.

References MultiClass_ECOC::nclass.

Referenced by AdaBoost_ECOC::ECOC_partition(), AdaBoost_ECOC::setup_aux(), and AdaBoost_ECOC::smpwgt_with_partition().

Output operator() const Input  )  const [virtual]
 

Implements LearnModel.

Definition at line 301 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::distances(), GET_BEST_CLASS, and MultiClass_ECOC::labels.

void reset  )  [virtual]
 

Todo:
Keep the initial ECOC settings

Reimplemented from Aggregating.

Definition at line 129 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, MultiClass_ECOC::ecoc_type, MultiClass_ECOC::lm_wgt, lemga::NO_TYPE, and Aggregating::reset().

bool serialize std::ostream &  ,
ver_list
const [protected, virtual]
 

Reimplemented from Aggregating.

Definition at line 20 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, Aggregating::lm, MultiClass_ECOC::lm_wgt, SERIALIZE_PARENT, and Aggregating::size().

void set_ECOC_table UINT  ,
const ECOC_VECTOR
 

Definition at line 79 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, and Aggregating::size().

void set_ECOC_table ECOC_TYPE   ) 
 

Definition at line 89 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc_type, lemga::NO_TYPE, lemga::ONE_VS_ALL, and lemga::ONE_VS_ONE.

void set_ECOC_table const ECOC_TABLE  ) 
 

Definition at line 72 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, Aggregating::max_n_model, Aggregating::set_max_models(), and Aggregating::size().

Referenced by MultiClass_ECOC::train().

void set_train_data const pDataSet pd,
const pDataWgt pw = 0
[virtual]
 

Set the data set and sample weight to be used in training.

If the learning model/algorithm can only do training using uniform sample weight, i.e., support_weighted_data() returns false, a ``boostrapped'' copy of the original data set will be generated and used in the following training. The boostrapping is done by randomly pick samples (with replacement) w.r.t. the given weight pw.

In order to make the life easier, when support_weighted_data() returns true, a null pw will be replaced by a uniformly distributed probability vector. So we have the following invariant

Invariant:
support_weighted_data() == (ptw != 0)
Parameters:
pd gives the data set.
pw gives the sample weight, whose default value is 0.
See also:
support_weighted_data(), train()

Reimplemented from Aggregating.

Definition at line 139 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc_type, LABEL_EQUAL, MultiClass_ECOC::labels, LearnModel::n_samples, lemga::NO_TYPE, LearnModel::ptd, and Aggregating::set_train_data().

virtual void setup_aux  )  [inline, protected, virtual]
 

Prepare auxiliary variables for current n_in_agg.

Reimplemented in AdaBoost_ECOC.

Definition at line 118 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::train().

virtual bool support_weighted_data  )  const [inline, virtual]
 

Whether the learning model/algorithm supports unequally weighted data.

Returns:
true if supporting; false otherwise. The default is false, just for safety.
See also:
set_train_data()

Reimplemented from LearnModel.

Definition at line 61 of file multiclass_ecoc.h.

void train  )  [virtual]
 

Train with preset data set and sample weight.

Implements LearnModel.

Definition at line 194 of file multiclass_ecoc.cpp.

References LearnModel::_n_out, MultiClass_ECOC::assign_weight(), MultiClass_ECOC::ecoc, MultiClass_ECOC::ECOC_partition(), MultiClass_ECOC::id(), MultiClass_ECOC::labels, Aggregating::lm, Aggregating::lm_base, MultiClass_ECOC::lm_wgt, Aggregating::max_n_model, Aggregating::n_in_agg, LearnModel::ptd, LearnModel::ptw, LearnModel::set_dimensions(), MultiClass_ECOC::set_ECOC_table(), MultiClass_ECOC::setup_aux(), MultiClass_ECOC::train_with_partition(), and MultiClass_ECOC::update_aux().

pLearnModel train_with_partition ECOC_VECTOR  )  const [protected, virtual]
 

Reimplemented in AdaBoost_ECOC, and AdaBoost_ERP.

Definition at line 370 of file multiclass_ecoc.cpp.

References dataset::append(), MultiClass_ECOC::ex_class, Aggregating::lm_base, LearnModel::ptd, and LearnModel::ptw.

Referenced by MultiClass_ECOC::train().

bool unserialize std::istream &  ,
ver_list ,
const id_t = NIL_ID
[protected, virtual]
 

Reimplemented from Aggregating.

Definition at line 46 of file multiclass_ecoc.cpp.

References MultiClass_ECOC::ecoc, Aggregating::lm, MultiClass_ECOC::lm_wgt, Object::NIL_ID, and UNSERIALIZE_PARENT.

virtual void update_aux const ECOC_VECTOR  )  [inline, protected, virtual]
 

Update those auxiliary variables after this round of learning.

Reimplemented in AdaBoost_ECOC.

Definition at line 124 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::train().


Member Data Documentation

ECOC_TABLE ecoc [protected]
 

the ECC table

Definition at line 33 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::distances(), MultiClass_ECOC::ECOC_partition(), MultiClass_ECOC::ECOC_table(), MultiClass_ECOC::get_output(), MultiClass_ECOC::reset(), MultiClass_ECOC::serialize(), MultiClass_ECOC::set_ECOC_table(), MultiClass_ECOC::train(), and MultiClass_ECOC::unserialize().

ECOC_TYPE ecoc_type [protected]
 

The type of the ECOC table, if there is some fixed type.

Note:
It is not serialized, at least for now.

Definition at line 36 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::reset(), MultiClass_ECOC::set_ECOC_table(), and MultiClass_ECOC::set_train_data().

std::vector<UINT> ex_class [protected]
 

class number of examples

Definition at line 41 of file multiclass_ecoc.h.

Referenced by AdaBoost_ECOC::confusion_matrix(), MultiClass_ECOC::cost(), MultiClass_ECOC::margin(), AdaBoost_ECOC::setup_aux(), AdaBoost_ECOC::smpwgt_with_partition(), AdaBoost_ECOC::train_with_full_partition(), AdaBoost_ERP::train_with_partial_partition(), MultiClass_ECOC::train_with_partition(), AdaBoost_ERP::train_with_partition(), AdaBoost_ECOC::train_with_partition(), and AdaBoost_ECOC::update_aux().

std::vector<REAL> labels [protected]
 

class labels

Definition at line 40 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::get_output(), MultiClass_ECOC::margin_of(), MultiClass_ECOC::operator()(), MultiClass_ECOC::set_train_data(), and MultiClass_ECOC::train().

std::vector<REAL> lm_wgt [protected]
 

hypothesis weight

Definition at line 32 of file multiclass_ecoc.h.

Referenced by MultiClass_ECOC::distances(), MultiClass_ECOC::ECOC_distance(), MultiClass_ECOC::model_weight(), MultiClass_ECOC::reset(), MultiClass_ECOC::serialize(), MultiClass_ECOC::train(), MultiClass_ECOC::unserialize(), and AdaBoost_ECOC::update_aux().

std::vector<REAL> local_d [mutable, protected]
 

Definition at line 108 of file multiclass_ecoc.h.

UINT nclass [protected]
 

number of classes

Definition at line 39 of file multiclass_ecoc.h.

Referenced by AdaBoost_ECOC::confusion_matrix(), MultiClass_ECOC::n_class(), AdaBoost_ECOC::setup_aux(), AdaBoost_ERP::train_with_partial_partition(), and AdaBoost_ERP::train_with_partition().


The documentation for this class was generated from the following files:
Generated on Wed Nov 8 08:17:05 2006 for LEMGA by  doxygen 1.4.6