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

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

Sampler and SubsetGenerator? in progress. Fixes #103

File size: 2.8 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
36  ///
37  /// Interface for dividing samples into training and validation.
38  ///   
39
40  class Sampler
41  {
42 
43  public:
44    ///
45    /// @brief Constructor
46    /// 
47    /// @parameter Target targets
48    ///
49    Sampler(const Target& target);
50
51    ///
52    /// Destructor (pure virtual destructor)
53    ///
54    virtual ~Sampler() =0;
55
56    ///
57    /// @return number of partitions
58    ///
59    inline u_long size(void) const { return training_index_.size(); }
60
61    ///
62    /// @return the targets for the total set
63    ///
64    inline const Target& target(void) const { return target_; }
65
66    ///
67    /// @return training indices
68    ///
69    inline const std::vector<size_t>& 
70    training_index(std::vector<size_t>::size_type i) const
71    { assert(i<size()); return training_index_[i]; }
72
73    ///
74    /// @return training target
75    ///
76    /// @note if state is invalid the result is undefined
77    ///
78    inline const Target& 
79    training_target(std::vector<Target>::size_type i) const 
80    { assert(i<size()); return training_target_[i]; }
81
82    ///
83    /// @return validation index
84    ///
85    /// @note if state is invalid the result is undefined
86    ///
87    inline const std::vector<size_t>& 
88    validation_index(std::vector<size_t>::size_type i) const
89    { assert(i<size()); return validation_index_[i]; }
90
91    ///
92    /// @return validation target
93    ///
94    /// @note if state is invalid the result is undefined
95    ///
96    inline const Target& 
97    validation_target(std::vector<Target>::size_type i) const 
98    { assert(i<size()); return validation_target_[i]; }
99
100
101  protected:
102    Target target_;
103    std::vector<std::vector<size_t> > training_index_;
104    std::vector<Target> training_target_;
105    std::vector<std::vector<size_t> > validation_index_;
106    std::vector<Target> validation_target_;
107
108  };
109
110}} // of namespace classifier and namespace theplu
111
112#endif
113
Note: See TracBrowser for help on using the repository browser.