source: trunk/c++_tools/classifier/Sampler.h @ 610

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

ref #60 Sampler and inherited CrossValidationSampler?.

File size: 3.1 KB
Line 
1#ifndef _theplu_classifier_sampler_
2#define _theplu_classifier_sampler_
3
4// $Id$
5
6/*
7  Copyright (C) 2006 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
28#include <c++_tools/classifier/Target.h>
29
30#include <cassert>
31#include <vector>
32
33namespace theplu {
34namespace classifier { 
35  class DataLookup2D;
36  class FeatureSelector;
37
38  ///
39  /// Interface for dividing samples into training and validation.
40  ///   
41
42  class Sampler
43  {
44 
45  public:
46    ///
47    /// @brief Constructor
48    /// 
49    /// @parameter Target targets
50    ///
51    Sampler(const Target& target);
52
53    ///
54    /// Destructor
55    ///
56    virtual ~Sampler();
57
58    ///
59    /// @return true if in a valid state
60    ///
61    inline bool more(void) const { return state_<size(); }
62
63    ///
64    /// Function turning the object to the next state.
65    ///
66    inline void next(void) { state_++; }
67
68    ///
69    /// rewind the sampler to initial state
70    ///
71    inline void reset(void) { state_=0; }
72
73
74    ///
75    /// @return number of partitions
76    ///
77    inline u_long size(void) const { return training_index_.size(); }
78
79    ///
80    /// @return the target for the total set
81    ///
82    inline const Target& target(void) const { return target_; }
83
84
85    /// @return training index
86    ///
87    /// @note if state is invalid the result is undefined
88    ///
89    inline const std::vector<size_t>& training_index(void) const
90    { assert(more()); return training_index_[state_]; }
91
92    ///
93    /// @return training target
94    ///
95    /// @note if state is invalid the result is undefined
96    ///
97    inline const Target& training_target(void) const 
98    { assert(more()); return training_target_[state_]; }
99
100    ///
101    /// @return validation index
102    ///
103    /// @note if state is invalid the result is undefined
104    ///
105    inline const std::vector<size_t>& validation_index(void) const
106    { assert(more()); return validation_index_[state_]; }
107
108    ///
109    /// @return validation target
110    ///
111    /// @note if state is invalid the result is undefined
112    ///
113    inline const Target& validation_target(void) const 
114    { assert(more()); return validation_target_[state_]; }
115
116
117  protected:
118    Target target_;
119    std::vector<std::vector<size_t> > training_index_;
120    std::vector<Target> training_target_;
121    std::vector<std::vector<size_t> > validation_index_;
122    std::vector<Target> validation_target_;
123
124  private:
125    u_long state_;
126
127  };
128
129}} // of namespace classifier and namespace theplu
130
131#endif
132
Note: See TracBrowser for help on using the repository browser.