1 | #ifndef _theplu_yat_classifier_sampler_ |
---|
2 | #define _theplu_yat_classifier_sampler_ |
---|
3 | |
---|
4 | // $Id: Sampler.h 680 2006-10-11 17:49:03Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006 Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 2 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
24 | 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | #include "Target.h" |
---|
28 | |
---|
29 | #include <vector> |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace classifier { |
---|
34 | |
---|
35 | /// |
---|
36 | /// Interface for dividing samples into training and validation. |
---|
37 | /// |
---|
38 | |
---|
39 | class Sampler |
---|
40 | { |
---|
41 | |
---|
42 | public: |
---|
43 | /// |
---|
44 | /// @brief Constructor |
---|
45 | /// |
---|
46 | /// @param target used to balance partitions |
---|
47 | /// |
---|
48 | Sampler(const Target& target); |
---|
49 | |
---|
50 | /// |
---|
51 | /// Destructor (pure virtual destructor) |
---|
52 | /// |
---|
53 | virtual ~Sampler() =0; |
---|
54 | |
---|
55 | /// |
---|
56 | /// @return number of partitions |
---|
57 | /// |
---|
58 | inline u_long size(void) const { return training_index_.size(); } |
---|
59 | |
---|
60 | /// |
---|
61 | /// @return the targets for the total set |
---|
62 | /// |
---|
63 | inline const Target& target(void) const { return target_; } |
---|
64 | |
---|
65 | /// |
---|
66 | /// @return training indices |
---|
67 | /// |
---|
68 | inline const std::vector<size_t>& |
---|
69 | training_index(std::vector<size_t>::size_type i) const |
---|
70 | { return training_index_[i]; } |
---|
71 | |
---|
72 | /// |
---|
73 | /// @return training target |
---|
74 | /// |
---|
75 | /// @note if state is invalid the result is undefined |
---|
76 | /// |
---|
77 | inline const Target& |
---|
78 | training_target(std::vector<Target>::size_type i) const |
---|
79 | { return training_target_[i]; } |
---|
80 | |
---|
81 | /// |
---|
82 | /// @return validation index |
---|
83 | /// |
---|
84 | /// @note if state is invalid the result is undefined |
---|
85 | /// |
---|
86 | inline const std::vector<size_t>& |
---|
87 | validation_index(std::vector<size_t>::size_type i) const |
---|
88 | { return validation_index_[i]; } |
---|
89 | |
---|
90 | /// |
---|
91 | /// @return validation target |
---|
92 | /// |
---|
93 | /// @note if state is invalid the result is undefined |
---|
94 | /// |
---|
95 | inline const Target& |
---|
96 | validation_target(std::vector<Target>::size_type i) const |
---|
97 | { return validation_target_[i]; } |
---|
98 | |
---|
99 | |
---|
100 | protected: |
---|
101 | /// Target used to balance partitions |
---|
102 | Target target_; |
---|
103 | /// index of training sets for the partitions |
---|
104 | std::vector<std::vector<size_t> > training_index_; |
---|
105 | /// Targets for training sets for the partitions |
---|
106 | std::vector<Target> training_target_; |
---|
107 | /// index of validation sets for the partitions |
---|
108 | std::vector<std::vector<size_t> > validation_index_; |
---|
109 | /// Targets for validation sets for the partitions |
---|
110 | std::vector<Target> validation_target_; |
---|
111 | |
---|
112 | }; |
---|
113 | |
---|
114 | }}} // of namespace classifier, yat, and theplu |
---|
115 | |
---|
116 | #endif |
---|
117 | |
---|