contrib/mul/clsfy/clsfy_adaboost_trainer.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_adaboost_trainer.h
00002 #ifndef clsfy_adaboost_trainer_h_
00003 #define clsfy_adaboost_trainer_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Functions to train classifiers using AdaBoost algorithm
00010 // \author dac
00011 // \date   Fri Mar  1 23:49:39 2002
00012 //  Functions to train classifiers using AdaBoost algorithm
00013 //  AdaBoost combines a set of (usually simple, weak) classifiers into
00014 //  a more powerful single classifier.  Essentially it selects the
00015 //  classifiers one at a time, choosing the best at each step.
00016 //  The classifiers are trained to distinguish the examples mis-classified
00017 //  by the currently selected classifiers.
00018 
00019 #include <vsl/vsl_binary_io.h>
00020 #include <clsfy/clsfy_simple_adaboost.h>
00021 #include <clsfy/clsfy_builder_1d.h>
00022 #include <mbl/mbl_data_wrapper.h>
00023 #include <vcl_string.h>
00024 #include <vcl_iosfwd.h>
00025 
00026 //=======================================================================
00027 
00028 //: A class for some purpose.
00029 // The purpose of this class is to prove that 1+1=3.
00030 class clsfy_adaboost_trainer
00031 {
00032  public:
00033 
00034   //: Dflt ctor
00035   clsfy_adaboost_trainer();
00036 
00037   //: Destructor
00038   virtual ~clsfy_adaboost_trainer();
00039 
00040   //: Build classifier composed of 1d classifiers working on individual vector elements
00041   //  Builds an n-component classifier, each component of which is a 1D classifier
00042   //  working on a single element of the input vector.
00043   void build_strong_classifier(clsfy_simple_adaboost& strong_classifier,
00044                                int max_n_clfrs,
00045                                clsfy_builder_1d& builder,
00046                                mbl_data_wrapper<vnl_vector<double> >& egs0,
00047                                mbl_data_wrapper<vnl_vector<double> >& egs1);
00048 
00049   //: Correctly classified examples have weights scaled by beta
00050   void clsfy_update_weights_weak(vnl_vector<double> &wts,
00051                                  const vnl_vector<double>& data,
00052                                  clsfy_classifier_1d& classifier,
00053                                  int class_number,
00054                                  double beta);
00055 
00056   //: Extracts the j-th element of each vector in data and puts into v
00057   void clsfy_get_elements(vnl_vector<double>& v,
00058                           mbl_data_wrapper<vnl_vector<double> >& data, int j);
00059 
00060   //: Version number for I/O
00061   short version_no() const;
00062 
00063   //: Name of the class
00064   vcl_string is_a() const;
00065 
00066   //: Name of the class
00067   virtual bool is_class(vcl_string const& s) const;
00068 
00069   //: Print class to os
00070   void print_summary(vcl_ostream& os) const;
00071 
00072   //: Save class to binary file stream.
00073   void b_write(vsl_b_ostream& bfs) const;
00074 
00075   //: Load class from binary file stream
00076   void b_read(vsl_b_istream& bfs);
00077 
00078  protected:
00079 #if 0
00080   // This is required if there are any references to objects
00081   // created on the heap. A deep copy should be made of anything
00082   // referred to by pointer during construction by copy. The copy
00083   // constructor is protected to stop its use for class
00084   // instantiation. It should be implemented in terms of the
00085   // assignment operator.
00086 
00087   //: Copy constructor
00088   clsfy_adaboost_trainer( const clsfy_adaboost_trainer& b );
00089 
00090   //: Assignment operator
00091   clsfy_adaboost_trainer& operator=( const clsfy_adaboost_trainer& b );
00092 #endif
00093 };
00094 
00095 //=======================================================================
00096 
00097 //: Binary file stream output operator for class reference
00098 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_adaboost_trainer& b);
00099 
00100 //: Binary file stream input operator for class reference
00101 void vsl_b_read(vsl_b_istream& bfs, clsfy_adaboost_trainer& b);
00102 
00103 //: Stream output operator for class reference
00104 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_adaboost_trainer& b);
00105 
00106 //: Stream output operator for class reference
00107 void vsl_print_summary(vcl_ostream& os,const clsfy_adaboost_trainer& b);
00108 
00109 #endif // clsfy_adaboost_trainer_h_