yat  0.14.5pre
Target.h
1 #ifndef _theplu_yat_classifier_target_
2 #define _theplu_yat_classifier_target_
3 
4 // $Id: Target.h 2119 2009-12-12 23:11:43Z peter $
5 
6 /*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2009 Peter Johansson
11 
12  This file is part of the yat library, http://dev.thep.lu.se/yat
13 
14  The yat library is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License as
16  published by the Free Software Foundation; either version 3 of the
17  License, or (at your option) any later version.
18 
19  The yat library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with yat. If not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #include "yat/utility/deprecate.h"
29 #include "yat/utility/Exception.h"
30 
31 #include <iosfwd>
32 #include <map>
33 #include <stdexcept>
34 #include <string>
35 #include <vector>
36 
37 namespace theplu {
38 namespace yat {
39  namespace utility {
40  class Index;
41  }
42 namespace classifier {
43 
47  class Target
48  {
49 
50  public:
54  Target(void);
55 
59  explicit Target(const std::vector<std::string>& labels);
60 
64  Target(const std::vector<std::string>& labels, const Target&);
65 
69  Target(std::istream&, char sep='\0')
70  throw (utility::IO_error,std::exception);
71 
79  Target(const Target& org, const utility::Index& vec);
80 
84  ~Target();
85 
89  const std::map<std::string,size_t>& classes(void) const;
90 
101  size_t nof_classes(void) const;
102 
111  bool binary(size_t i) const;
112 
120  const std::vector<std::string>& labels(void);
121 
127  void set_binary(size_t i, bool b);
128 
135  void random_shuffle(void);
136 
140  size_t size(void) const;
141 
145  size_t size(const std::string& label) const;
146 
150  size_t size(size_t cl) const;
151 
152 
156  size_t operator()(size_t sample) const;
157 
164  size_t operator[](size_t sample) const YAT_DEPRECATE;
165 
169  const Target& operator=(const Target&);
170 
171  private:
173  // using compiler generated constructor
174  //Target(const Target& other);
175 
176  // binary target for class i
177  std::vector<char> binary_; // avoid using vector<bool>
178  std::vector<size_t> classes_; // class of sample i
179  // map between class label and class index (inverse of labels_)
180  std::map<std::string,size_t> class_map_;
181  std::vector<std::string> labels_; // label of class i
182 
183  void init(const std::vector<std::string>&);
184 
185  };
186 
192  std::ostream& operator<<(std::ostream&, const Target& );
193 
194 }}} // of namespace classifier, yat, and theplu
195 
196 #endif
const std::vector< std::string > & labels(void)
Class for containing sample labels.
Definition: Target.h:47
size_t operator[](size_t sample) const
size_t operator()(size_t sample) const
Class for storing indices of, e.g., a MatrixLookup.
Definition: Index.h:41
bool binary(size_t i) const
Default binary is set to false for all classes except class 0.
const Target & operator=(const Target &)
assignment operator
Class to report errors associated with IO operations.
Definition: Exception.h:109
void set_binary(size_t i, bool b)
Target(void)
default constructor
void random_shuffle(void)
randomize labels
size_t nof_classes(void) const
const std::map< std::string, size_t > & classes(void) const

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5