FreeLing  3.0
adaboost.h
Go to the documentation of this file.
00001 
00002 //
00003 //    Omlet - Open Machine Learning Enhanced Toolkit
00004 //
00005 //    Copyright (C) 2006   TALP Research Center
00006 //                         Universitat Politecnica de Catalunya
00007 //
00008 //    This file is part of the Omlet library
00009 //
00010 //    The Omlet library is free software; you can redistribute it 
00011 //    and/or modify it under the terms of the GNU General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 3 of the License, or (at your option) any later version.
00014 //
00015 //    This library is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110-1301 USA
00023 //
00024 //    contact: Lluis Padro (padro@lsi.upc.es)
00025 //             TALP Research Center
00026 //             despatx Omega.S112 - Campus Nord UPC
00027 //             08034 Barcelona.  SPAIN
00028 //
00030 
00031 //
00032 // Author: Xavier Carreras
00033 //
00034 
00035 #ifndef _ADABOOST
00036 #define _ADABOOST
00037 
00038 #include "freeling/omlet/weakrule.h"
00039 #include "freeling/omlet/dataset.h"
00040 #include "freeling/omlet/classifier.h"
00041 
00042 #include <iostream>
00043 #include <string>
00044 #include <list>
00045 #include <vector>
00046 
00047 
00052 
00053 class adaboost : public std::list<weak_rule*>, public classifier {
00054  private:
00056   bool option_initialize_weights;
00057 
00059   std::wstring wr_type;
00060 
00061   adaboost::const_iterator pcl_pointer; // partial classification pointer
00062   int nrules;
00063 
00065   std::wostream *out;
00066 
00068   void initialize_weights(dataset &ds);
00069   void update_weights(weak_rule *wr, double Z, dataset &ds);
00070   void add_weak_rule(weak_rule *wr);
00071 
00073   adaboost(const adaboost &old_bab); 
00074 
00075  public:
00077   adaboost(int nl, std::wstring t);
00078   adaboost(const std::wstring &file, const std::wstring &codes);
00079   int n_rules();
00080 
00084   void classify(const example &i,  double pred[]) const;
00086   std::vector<double> classify(const example &i);
00087 
00089   void pcl_ini_pointer();
00090   int  pcl_advance_pointer(int steps);
00093   void pcl_classify(const example &i, double *pred, int nrules);
00094 
00096   void learn(dataset &ds, int nrounds, bool init, wr_params *p);
00097   void learn(dataset &ds, int nrounds, bool init, wr_params *p, const std::wstring &outf);
00098 
00100   void set_output(std::wostream *os);
00101   void read_from_stream(std::wistream *in);
00102   void read_from_file(const std::wstring &f);
00103 
00104   void set_initialize_weights(bool b);
00105 };
00106 
00107 
00108 
00109 #endif