FreeLing
4.0
|
00001 00002 // 00003 // Omlet - Open Machine Learning Enhanced Toolkit 00004 // 00005 // Copyright (C) 2014 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 Affero 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 // Affero General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Affero 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 namespace freeling { 00048 00053 00054 class adaboost : public std::list<weak_rule*>, public classifier { 00055 private: 00057 bool option_initialize_weights; 00058 00060 std::wstring wr_type; 00061 00062 adaboost::const_iterator pcl_pointer; // partial classification pointer 00063 int nrules; 00064 00066 std::wostream *out; 00067 00069 void initialize_weights(dataset &ds); 00070 void update_weights(weak_rule *wr, double Z, dataset &ds); 00071 void add_weak_rule(weak_rule *wr); 00072 00074 adaboost(const adaboost &old_bab); 00075 00076 public: 00078 adaboost(int nl, std::wstring t); 00079 adaboost(const std::wstring &file, const std::wstring &codes); 00080 int n_rules() const; 00081 00085 void classify(const example &i, double pred[]) const; 00087 std::vector<double> classify(const example &i) const; 00088 00090 void pcl_ini_pointer(); 00091 int pcl_advance_pointer(int steps); 00094 void pcl_classify(const example &i, double *pred, int nrules); 00095 00097 void learn(dataset &ds, int nrounds, bool init, wr_params *p); 00098 void learn(dataset &ds, int nrounds, bool init, wr_params *p, const std::wstring &outf); 00099 00101 void set_output(std::wostream *os); 00102 void read_from_stream(std::wistream *in); 00103 void read_from_file(const std::wstring &f); 00104 00105 void set_initialize_weights(bool b); 00106 }; 00107 00108 } // namespace 00109 00110 #endif