yat  0.21pre
Target.h
1 #ifndef _theplu_yat_classifier_target_
2 #define _theplu_yat_classifier_target_
3 
4 // $Id: Target.h 4245 2022-09-21 05:41:41Z 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, 2019, 2021 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 
78  Target(const Target& org, const utility::Index& vec);
79 
83  const std::map<std::string,size_t>& classes(void) const;
84 
95  size_t nof_classes(void) const;
96 
105  bool binary(size_t i) const;
106 
114  const std::vector<std::string>& labels(void) const;
115 
121  void set_binary(size_t i, bool b);
122 
129  void random_shuffle(void);
130 
134  size_t size(void) const;
135 
139  size_t size(const std::string& label) const;
140 
144  size_t size(size_t cl) const;
145 
146 
150  size_t operator()(size_t sample) const;
151 
158  size_t operator[](size_t sample) const YAT_DEPRECATE;
159 
160  private:
162  // using compiler generated constructor
163  //Target(const Target& other);
164 
165  // binary target for class i
166  std::vector<char> binary_; // avoid using vector<bool>
167  std::vector<size_t> classes_; // class of sample i
168  // map between class label and class index (inverse of labels_)
169  std::map<std::string,size_t> class_map_;
170  std::vector<std::string> labels_; // label of class i
171 
172  void init(const std::vector<std::string>&);
173 
174  };
175 
181  std::ostream& operator<<(std::ostream&, const Target& );
182 
183 }}} // of namespace classifier, yat, and theplu
184 
185 #endif
Class for containing sample labels.
Definition: Target.h:47
The Department of Theoretical Physics namespace as we define it.
size_t nof_classes(void) const
bool binary(size_t i) const
Default binary is set to false for all classes except class 0.
Class for storing indices of, e.g., a MatrixLookup.
Definition: Index.h:41
const std::vector< std::string > & labels(void) const
void set_binary(size_t i, bool b)
Target(void)
default constructor
void random_shuffle(void)
randomize labels
const std::map< std::string, size_t > & classes(void) const
size_t operator[](size_t sample) const
size_t operator()(size_t sample) const

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14