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

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

References #83. Changing project name to yat. Compilation will fail in this revision.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1#ifndef _theplu_classifier_subset_generator_
2#define _theplu_classifier_subset_generator_
3
4// $Id: SubsetGenerator.h 675 2006-10-10 12:08:45Z jari $
5
6/*
7  Copyright (C) 2006 Markus Ringnér, 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 "yat/classifier/Target.h"
28#include "yat/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.