source: trunk/c++_tools/classifier/SubsetGenerator.h @ 648

Last change on this file since 648 was 648, checked in by Peter, 15 years ago

fixes #133 removed all errors reported from Doxygen. Only one error left which says Index is not documented but I don't want it to be documented actually we use the Doxygens preprocessor to skip documenting that class, yet Doxygen complains that class is not documented huh. Only solution would be to move that class to its own file and not keep it together with SVM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1#ifndef _theplu_classifier_subset_generator_
2#define _theplu_classifier_subset_generator_
3
4// $Id: SubsetGenerator.h 648 2006-09-14 03:04:17Z peter $
5
6/*
7  Copyright (C) 2006 Markus Ringnér, Peter Johansson
8
9  This file is part of the thep c++ tools library,
10                                http://lev.thep.lu.se/trac/c++_tools
11
12  The c++ tools library is free software; you can redistribute it
13  and/or modify it under the terms of the GNU General Public License
14  as published by the Free Software Foundation; either version 2 of
15  the License, or (at your option) any later version.
16
17  The c++ tools library is distributed in the hope that it will be
18  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19  of 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#include <c++_tools/classifier/Target.h>
28#include <c++_tools/classifier/Sampler.h>
29
30#include <vector>
31
32namespace theplu {
33namespace classifier { 
34  class DataLookup2D;
35  class FeatureSelector;
36  class MatrixLookup;
37
38  ///
39  /// Class splitting a set into training set and validation set using
40  /// a Sampler method.
41  ///   
42  class SubsetGenerator
43  {
44 
45  public:
46    ///
47    /// @brief Constructor
48    /// 
49    /// @param sampler sampler
50    /// @param data data to split up in validation and training.
51    ///
52    SubsetGenerator(const Sampler& sampler, const DataLookup2D& data);
53
54
55    ///
56    /// @brief Constructor
57    /// 
58    /// @param sampler taking care of partioning dataset
59    /// @param data data to be split up in validation and training.
60    /// @param fs Object selecting features for each subset
61    ///
62    SubsetGenerator(const Sampler& sampler, const DataLookup2D& data, 
63                    FeatureSelector& fs);
64
65    ///
66    /// Destructor
67    ///
68    ~SubsetGenerator();
69
70    ///
71    /// @return true if in a valid state
72    ///
73    inline bool more(void) const { return state_<size(); } 
74
75    ///
76    /// Function turning the object to the next state.
77    ///
78    inline void next(void) { state_++; }
79
80    ///
81    /// rewind object to initial state
82    ///
83    inline void reset(void) { state_=0; }
84 
85    ///
86    /// @return number of subsets
87    ///
88    inline u_long size(void) const { return sampler_.size(); }
89
90    ///
91    /// @return the target for the total set
92    ///
93    inline const Target& target(void) const { return sampler_.target(); }
94
95
96    ///
97    /// @return the sampler for the total set
98    ///
99    //    inline const Sampler& sampler(void) const { return sampler_; }
100
101
102    ///
103    /// @return training data
104    ///
105    inline const DataLookup2D& training_data(void) const 
106    { return *(training_data_[state_]); } 
107
108    ///
109    /// @return training features
110    ///
111    inline const std::vector<size_t>& training_features(void) const
112    { return f_selector_ ? features_[state_] : features_[0]; }
113
114
115    ///
116    /// @return training index
117    ///
118    inline const std::vector<size_t>& training_index(void) const
119    { return sampler_.training_index(state_); }
120
121    ///
122    /// @return training target
123    ///
124    inline const Target& training_target(void) const 
125    { return training_target_[state_]; }
126
127    ///
128    /// @return validation data
129    ///
130    inline const DataLookup2D& validation_data(void) const
131    { return *(validation_data_[state_]); }
132
133    ///
134    /// @return validation index
135    ///
136    inline const std::vector<size_t>& validation_index(void) const
137    { return sampler_.validation_index(state_); }
138
139    ///
140    /// @return validation target
141    ///
142    inline const Target& validation_target(void) const 
143    { return validation_target_[state_]; }
144
145    ///
146    /// @return true if weighted
147    /// @todo remove this function
148    //inline bool weighted(void) const { return weighted_; }
149
150  private:
151    SubsetGenerator(const SubsetGenerator&);
152    const SubsetGenerator& operator=(const SubsetGenerator&) const;
153
154    FeatureSelector* f_selector_;
155    std::vector<std::vector<size_t> > features_;
156    const Sampler& sampler_;
157    size_t state_;
158    std::vector<const DataLookup2D*> training_data_;
159    std::vector<Target> training_target_;
160    std::vector<const DataLookup2D*> validation_data_;
161    std::vector<Target> validation_target_;
162    const bool weighted_;
163
164  };
165
166}} // of namespace classifier and namespace theplu
167
168#endif
169
Note: See TracBrowser for help on using the repository browser.