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