source: trunk/lib/classifier/Target.h @ 507

Last change on this file since 507 was 507, checked in by Jari Häkkinen, 16 years ago

Reverting these files to revision 505; these were changed by mistake.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: Target.h 507 2006-02-17 00:02:57Z jari $
2
3#ifndef _theplu_classifier_target_
4#define _theplu_classifier_target_
5
6#include <c++_tools/utility/Exception.h>
7
8#include <algorithm>
9#include <map>
10#include <vector>
11
12
13namespace theplu {
14namespace classifier { 
15
16  ///
17  /// Class for targets
18  ///
19
20  class Target
21  {
22 
23  public:
24    ///
25    /// Default constructor
26    ///
27    inline Target(const size_t n=0,const int init_value=0) 
28      : vector_(std::vector<int>(n,init_value)) {init_classes();} 
29
30    ///
31    /// Constructor
32    ///
33    Target(const std::vector<int>&);
34
35    ///
36    /// The istream constructor.
37    ///
38    Target(std::istream&, char sep='\0') 
39      throw (utility::IO_error,std::exception);
40
41    ///
42    /// Copy Constructor
43    ///
44    inline Target(const Target& other) 
45    { vector_=other.vector_; classes_=other.classes_; }
46
47    ///
48    /// Constructor taking the index vector as input.
49    ///
50    Target(const Target&, const std::vector<size_t>&);
51
52    ///
53    /// Destructor
54    ///
55    ~Target();
56
57    ///
58    /// @return number of classes
59    ///
60    inline size_t classes(void) const { return classes_.size(); }
61   
62    ///
63    /// @return the class of a target value
64    ///
65    u_int classes(int target) const; 
66   
67   
68    ///
69    /// @return size
70    ///
71    inline size_t size(void) const { return vector_.size(); }
72
73    ///
74    /// @brief sort
75    ///
76    inline void sort(void) { std::sort(vector_.begin(), vector_.end()); }
77
78    inline const int& operator()(const size_t i) const { return vector_[i]; }
79
80    inline int& operator()(const size_t i)  { return vector_[i]; }
81
82    const Target& operator*=(const int d);
83
84    const Target& operator=(const Target& other);
85
86  private:
87    std::vector<int> vector_;
88    std::map<int,u_int> classes_;       
89   
90    void init_classes(void);
91
92  }; 
93 
94  ///
95  /// The output operator for the Target class.
96  ///
97  std::ostream& operator<<(std::ostream&, const Target& );
98
99}} // of namespace classifier and namespace theplu
100
101#endif
Note: See TracBrowser for help on using the repository browser.