source: trunk/yat/classifier/SubsetGenerator.h @ 680

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

Addresses #153. Introduced yat namespace. Removed alignment namespace. Clean up of code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1#ifndef _theplu_yat_classifier_subset_generator_
2#define _theplu_yat_classifier_subset_generator_
3
4// $Id: SubsetGenerator.h 680 2006-10-11 17:49:03Z 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 "Target.h"
28#include "Sampler.h"
29
30#include <vector>
31
32namespace theplu {
33namespace yat {
34namespace classifier { 
35  class DataLookup2D;
36  class FeatureSelector;
37  class MatrixLookup;
38
39  ///
40  /// Class splitting a set into training set and validation set using
41  /// a Sampler method.
42  ///   
43  class SubsetGenerator
44  {
45 
46  public:
47    ///
48    /// @brief Constructor
49    /// 
50    /// @param sampler sampler
51    /// @param data data to split up in validation and training.
52    ///
53    SubsetGenerator(const Sampler& sampler, const DataLookup2D& data);
54
55
56    ///
57    /// @brief Constructor
58    /// 
59    /// @param sampler taking care of partioning dataset
60    /// @param data data to be split up in validation and training.
61    /// @param fs Object selecting features for each subset
62    ///
63    SubsetGenerator(const Sampler& sampler, const DataLookup2D& data, 
64                    FeatureSelector& fs);
65
66    ///
67    /// Destructor
68    ///
69    ~SubsetGenerator();
70
71    ///
72    /// @return true if in a valid state
73    ///
74    inline bool more(void) const { return state_<size(); } 
75
76    ///
77    /// Function turning the object to the next state.
78    ///
79    inline void next(void) { state_++; }
80
81    ///
82    /// rewind object to initial state
83    ///
84    inline void reset(void) { state_=0; }
85 
86    ///
87    /// @return number of subsets
88    ///
89    inline u_long size(void) const { return sampler_.size(); }
90
91    ///
92    /// @return the target for the total set
93    ///
94    inline const Target& target(void) const { return sampler_.target(); }
95
96
97    ///
98    /// @return the sampler for the total set
99    ///
100    //    inline const Sampler& sampler(void) const { return sampler_; }
101
102
103    ///
104    /// @return training data
105    ///
106    inline const DataLookup2D& training_data(void) const 
107    { return *(training_data_[state_]); } 
108
109    ///
110    /// @return training features
111    ///
112    inline const std::vector<size_t>& training_features(void) const
113    { return f_selector_ ? features_[state_] : features_[0]; }
114
115
116    ///
117    /// @return training index
118    ///
119    inline const std::vector<size_t>& training_index(void) const
120    { return sampler_.training_index(state_); }
121
122    ///
123    /// @return training target
124    ///
125    inline const Target& training_target(void) const 
126    { return training_target_[state_]; }
127
128    ///
129    /// @return validation data
130    ///
131    inline const DataLookup2D& validation_data(void) const
132    { return *(validation_data_[state_]); }
133
134    ///
135    /// @return validation index
136    ///
137    inline const std::vector<size_t>& validation_index(void) const
138    { return sampler_.validation_index(state_); }
139
140    ///
141    /// @return validation target
142    ///
143    inline const Target& validation_target(void) const 
144    { return validation_target_[state_]; }
145
146    ///
147    /// @return true if weighted
148    /// @todo remove this function
149    //inline bool weighted(void) const { return weighted_; }
150
151  private:
152    SubsetGenerator(const SubsetGenerator&);
153    const SubsetGenerator& operator=(const SubsetGenerator&) const;
154
155    FeatureSelector* f_selector_;
156    std::vector<std::vector<size_t> > features_;
157    const Sampler& sampler_;
158    size_t state_;
159    std::vector<const DataLookup2D*> training_data_;
160    std::vector<Target> training_target_;
161    std::vector<const DataLookup2D*> validation_data_;
162    std::vector<Target> validation_target_;
163    const bool weighted_;
164
165  };
166
167}}} // of namespace classifier, yat, and theplu
168
169#endif
170
Note: See TracBrowser for help on using the repository browser.