FreeLing  3.0
example.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 _EXAMPLE
00036 #define _EXAMPLE
00037 
00038 #include <map>
00039 #include <vector>
00040 
00045 
00046 class category {
00047   friend class example;
00048  protected:
00050   bool belongs;
00052   double weight;
00054   double prediction;   
00055 
00056  public:
00058   category(bool, double, double);
00060   category(const category &);
00061 };
00062 
00069 
00070 class example : public std::map<int,double> {
00071 
00072  private:
00074   int dimension;
00076   std::vector<category> labels;
00077   int nlabels;
00078 
00079  public:  
00081   example(int nl);
00083   example(const example &e);
00084 
00086   example(double f1, const example& i1, double f2, const example& i2);
00087 
00089   double norm();
00090 
00092   void add_feature(int l, double v = 1.0);
00093 
00095   int get_nlabels() const;
00096   double get_feature_value(int label) const;
00097   int get_dimension() const;
00098 
00100   double inner_product(const example &i2) const;
00102   void add_vector(double f, const example &i2);
00103 
00105   void set_label(int l, bool b, double w, double pr);
00106   void set_belongs(int l, bool b);
00107   bool belongs(int l) const;
00108   int sign(int l) const;
00109   void set_weight(int l, double w);
00110   double get_weight(int l) const;
00111   void set_prediction(int l, double pr);
00112   double get_prediction(int l);
00113 };
00114 
00115 
00116 #endif