yat  0.8.3pre
Target.h
00001 #ifndef _theplu_yat_classifier_target_ 
00002 #define _theplu_yat_classifier_target_ 
00003 
00004 // $Id: Target.h 2119 2009-12-12 23:11:43Z peter $
00005 
00006 /*
00007   Copyright (C) 2005 Peter Johansson
00008   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
00009   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
00010   Copyright (C) 2009 Peter Johansson
00011 
00012   This file is part of the yat library, http://dev.thep.lu.se/yat
00013 
00014   The yat library is free software; you can redistribute it and/or
00015   modify it under the terms of the GNU General Public License as
00016   published by the Free Software Foundation; either version 3 of the
00017   License, or (at your option) any later version.
00018 
00019   The yat library is distributed in the hope that it will be useful,
00020   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00022   General Public License for more details.
00023 
00024   You should have received a copy of the GNU General Public License
00025   along with yat. If not, see <http://www.gnu.org/licenses/>.
00026 */
00027 
00028 #include "yat/utility/deprecate.h"
00029 #include "yat/utility/Exception.h"
00030 
00031 #include <iosfwd>
00032 #include <map>
00033 #include <stdexcept>
00034 #include <string>
00035 #include <vector>
00036 
00037 namespace theplu {
00038 namespace yat {
00039   namespace utility {
00040     class Index;
00041   }
00042 namespace classifier {  
00043 
00047   class Target
00048   {
00049   
00050   public:
00054     Target(void);
00055 
00059     explicit Target(const std::vector<std::string>& labels);
00060 
00064     Target(const std::vector<std::string>& labels, const Target&);
00065 
00069     Target(std::istream&, char sep='\0') 
00070       throw (utility::IO_error,std::exception);
00071 
00079     Target(const Target& org, const utility::Index& vec);
00080 
00084     ~Target();
00085 
00089     const std::map<std::string,size_t>& classes(void) const;
00090     
00101     size_t nof_classes(void) const;
00102 
00111     bool binary(size_t i) const;
00112     
00120     const std::vector<std::string>& labels(void);
00121 
00127     void set_binary(size_t i, bool b);
00128 
00135     void random_shuffle(void);
00136 
00140     size_t size(void) const;
00141 
00145     size_t size(const std::string& label) const;
00146 
00150     size_t size(size_t cl) const;
00151 
00152 
00156     size_t operator()(size_t sample) const;
00157     
00164     size_t operator[](size_t sample) const YAT_DEPRECATE;
00165 
00169     const Target& operator=(const Target&);
00170 
00171   private:
00173     // using compiler generated constructor
00174     //Target(const Target& other); 
00175 
00176     // binary target for class i
00177     std::vector<char> binary_; // avoid using vector<bool>
00178     std::vector<size_t> classes_; // class of sample i
00179     // map between class label and class index (inverse of labels_)
00180     std::map<std::string,size_t> class_map_;  
00181     std::vector<std::string> labels_; // label of class i
00182     
00183     void init(const std::vector<std::string>&);
00184 
00185   };  
00186   
00192   std::ostream& operator<<(std::ostream&, const Target& );
00193 
00194 }}} // of namespace classifier, yat, and theplu
00195 
00196 #endif

Generated on Thu Dec 20 2012 03:12:57 for yat by  doxygen 1.8.0-20120409