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 _EXAMPLE 00036 #define _EXAMPLE 00037 00038 #include <map> 00039 #include <vector> 00040 00041 namespace freeling { 00042 00047 00048 class category { 00049 friend class example; 00050 protected: 00052 bool belongs; 00054 double weight; 00056 double prediction; 00057 00058 public: 00060 category(bool, double, double); 00062 category(const category &); 00063 }; 00064 00071 00072 class example : public std::map<int,double> { 00073 00074 private: 00076 int dimension; 00078 std::vector<category> labels; 00079 int nlabels; 00080 00081 public: 00083 example(int nl); 00085 example(const example &e); 00086 00088 example(double f1, const example& i1, double f2, const example& i2); 00089 00091 double norm() const; 00092 00094 void add_feature(int l, double v = 1.0); 00095 00097 int get_nlabels() const; 00098 double get_feature_value(int label) const; 00099 int get_dimension() const; 00100 00102 double inner_product(const example &i2) const; 00104 void add_vector(double f, const example &i2); 00105 00107 void set_label(int l, bool b, double w, double pr); 00108 void set_belongs(int l, bool b); 00109 bool belongs(int l) const; 00110 int sign(int l) const; 00111 void set_weight(int l, double w); 00112 double get_weight(int l) const; 00113 void set_prediction(int l, double pr); 00114 double get_prediction(int l) const; 00115 }; 00116 00117 } // namespace 00118 00119 #endif