degate  0.1.2
Public Member Functions | Static Public Member Functions
Classifier< T > Class Template Reference

#include <adaboost.hpp>

Inheritance diagram for Classifier< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual int recognize (T &)=0
virtual string get_name () const =0

Static Public Member Functions

static vector< float > adaboost (vector< Classifier< T > * > clsfrs, vector< T * > data, vector< int > label, const int maxround=80)

Detailed Description

template<class T>
class Classifier< T >

Definition at line 20 of file adaboost.hpp.


Member Function Documentation

template<class T>
static vector<float> Classifier< T >::adaboost ( vector< Classifier< T > * >  clsfrs,
vector< T * >  data,
vector< int >  label,
const int  maxround = 80 
) [inline, static]

Definition at line 35 of file adaboost.hpp.

        {
                vector<float> alpha;
                vector<float> d;
                
                if (data.size()!=label.size() || clsfrs.size()==0 || label.size()==0)
                        return alpha;
                
                d.resize(label.size());
                alpha.resize(clsfrs.size());


                for (unsigned int i=0;i<label.size();i++)
                        d[i]=float(1.0)/float(label.size());
                vector< vector<int> > rec;
                rec.resize(clsfrs.size());

                // run the weak classifiers on all the trainning data first
                for (unsigned int j=0;j<clsfrs.size();j++)
                {
                        rec[j].resize(label.size());
                        for (unsigned int i=0;i<label.size();i++)
                                rec[j][i]=clsfrs[j]->recognize(*data[i]);
                }

                //run maxround times of iteration
                
                for (int round=0;round<maxround;round++)
                {
                        float minerr=(float)label.size();
                        int best = 0;
                        for (unsigned int j=0;j<clsfrs.size();j++) 
                        {
                                float err=0;
                                for (unsigned int i=0;i<label.size();i++)
                                {
                                        if (rec[j][i]!=label[i])
                                        err += d[i];
                                }
                                if (err<minerr)
                                {
                                        minerr = err;
                                        best = j;
                                }
                        }
                        if (minerr >= 0.5) break;

                        float a= log((1.0f-minerr)/minerr)/2;
                        alpha[best]+=a;
                        vector<float> d1=d;
                        float z = 0;
                        for (unsigned int i=0;i<label.size();i++)
                        {
                                d1[i]=d[i]*exp(-a*label[i]*rec[best][i]);
                                z+=d1[i];
                        }
                        for (unsigned int i=0;i<label.size();i++)
                        {
                                d[i]=d1[i]/z;
                        }
                }
                return alpha;
        }
template<class T>
virtual string Classifier< T >::get_name ( ) const [pure virtual]
template<class T>
virtual int Classifier< T >::recognize ( T &  ) [pure virtual]

Implemented in MultiClassifier< T >.

Referenced by testClassifier().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: