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

Last change on this file since 704 was 704, checked in by Markus Ringnér, 15 years ago

Fixes #104. Also fixed inline bug in Averager.h

  • 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 704 2006-12-18 16:01:41Z markus $
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 number of subsets
73    ///
74    inline u_long size(void) const { return sampler_.size(); }
75
76    ///
77    /// @return the target for the total set
78    ///
79    inline const Target& target(void) const { return sampler_.target(); }
80
81
82    ///
83    /// @return the sampler for the total set
84    ///
85    //    inline const Sampler& sampler(void) const { return sampler_; }
86
87
88    ///
89    /// @return training data
90    ///
91    inline const DataLookup2D& training_data(std::vector<DataLookup2D*>::
92                                             size_type i) const 
93    { return *(training_data_[i]); } 
94
95    ///
96    /// @return training features
97    ///
98    inline const std::vector<size_t>& training_features(std::vector<size_t>::
99                                                        size_type i) const
100    { return f_selector_ ? features_[i] : features_[0]; }
101
102
103    ///
104    /// @return training index
105    ///
106    inline const std::vector<size_t>& training_index(std::vector<size_t>::
107                                                     size_type i) const
108    { return sampler_.training_index(i); }
109
110    ///
111    /// @return training target
112    ///
113    inline const Target& training_target(std::vector<Target>::
114                                         size_type i) const 
115    { return training_target_[i]; }
116
117    ///
118    /// @return validation data
119    ///
120    inline const DataLookup2D& validation_data(std::vector<DataLookup2D*>::
121                                               size_type i) const
122    { return *(validation_data_[i]); }
123
124    ///
125    /// @return validation index
126    ///
127    inline const std::vector<size_t>& validation_index(std::vector<size_t>::
128                                                       size_type i) const
129    { return sampler_.validation_index(i); }
130
131    ///
132    /// @return validation target
133    ///
134    inline const Target& validation_target(std::vector<Target>::
135                                           size_type i) const 
136    { return validation_target_[i]; }
137
138    ///
139    /// @return true if weighted
140    /// @todo remove this function
141    //inline bool weighted(void) const { return weighted_; }
142
143  private:
144    SubsetGenerator(const SubsetGenerator&);
145    const SubsetGenerator& operator=(const SubsetGenerator&) const;
146
147    FeatureSelector* f_selector_;
148    std::vector<std::vector<size_t> > features_;
149    const Sampler& sampler_;
150    std::vector<const DataLookup2D*> training_data_;
151    std::vector<Target> training_target_;
152    std::vector<const DataLookup2D*> validation_data_;
153    std::vector<Target> validation_target_;
154    const bool weighted_;
155
156  };
157
158}}} // of namespace classifier, yat, and theplu
159
160#endif
161
Note: See TracBrowser for help on using the repository browser.