X-Boost  2.3.8
DataSet.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _DATA_SET_H
22 #define _DATA_SET_H
23 
27 #include <vector>
28 #include "Types.h"
29 #include "Pattern/Aggregator.h"
30 
31 // fwd
32 template<class Aggregator>
33 struct DataSet;
34 
49 template<class Aggregator >
50 struct DataSetHandle: public Aggregator::ParamType {
51 
52 public:
55 
58 
59  // additional Typedef
60  DECLARE_AGGREGATOR
61 
63  typedef typename std::vector<PatternType> ListType;
64 
65 public:
66 
70  unsigned int n_patternP, n_patternN;
71 
73  ListType templates;
74 
75 public:
76 
77  DataSetHandle() : n_patternP(0), n_patternN(0) { }
78 
81  template<class SrcAggregator>
82  explicit DataSetHandle( const DataSetHandle<SrcAggregator> & src) :n_patternP(src.n_patternP), n_patternN(src.n_patternN)
83  {
84  static_cast<ParamType&>(*this) = static_cast<const ParamType&>(src);
85  templates.reserve(src.templates.size() );
86  for(typename DataSetHandle<SrcAggregator>::ListType::const_iterator i = src.templates.begin(); i!=src.templates.end(); ++i)
87  templates.push_back( PatternType ( *i ) ); // convert
88  }
89 
90  // do nothing
91  ~DataSetHandle() { }
92 
94  void Clear()
95  {
96  n_patternP = n_patternN = 0;
97  templates.clear();
98  }
99 
101  inline unsigned int Size() const {
102  return templates.size();
103  }
104 
107  void SetParams(const ParamType & src) {
108  static_cast<ParamType &>(*this) = src;
109  }
110 
112  const ParamType & GetParams() const {
113  return static_cast<const ParamType &>(*this);
114  }
115 
117  void Insert(const PatternType & p)
118  {
119  if(p.category == 1)
120  n_patternP++;
121  else
122  n_patternN++;
123  templates.push_back(p);
124  }
125 
127  void Release()
128  {
129  // release pattern data memory
130  for(typename ListType::iterator i = templates.begin(); i!=templates.end(); ++i)
131  i->release();
132  }
133 
136  template<class SrcAggregator>
138  static_cast<ParamType&>(*this) = static_cast<const ParamType&>(src);
140  n_patternN=src.n_patternN;
141  templates.clear();
142  templates.reserve(src.templates.size() );
143  for( typename DataSetHandle<SrcAggregator>::ListType::const_iterator i = src.templates.begin(); i!=src.templates.end(); ++i)
144  templates.push_back( PatternType ( *i ) ); // convert
145  }
146 
149  void Import(const DataType & data, int category);
150 
151 };
152 
157 template<class Aggregator>
158 struct DataSet: public DataSetHandle<Aggregator> {
159 public:
160 
161  typedef DataSetHandle<Aggregator> ViewType;
162  typedef DataSet<Aggregator> StoreType;
163 
164 private:
165 
166  // uncopiable
167  DataSet(const DataSet & src) { }
168 
169 public:
170 
171  DataSet() { }
172 
173  ~DataSet()
174  {
175  // on destruction, memory is released:
176  this->Release();
177  }
178 
179 };
180 
181 
183 
184 template<class Aggregator >
185 void DataSetHandle<Aggregator>::Import(const DataType & data, int category)
186 {
187  // update stats:
188  if(category == 1)
189  n_patternP++;
190  else
191  n_patternN++;
192 
193  // add the data to the set
194  templates.push_back(PatternType(data, category));
195 }
196 
197 
198 #endif
199 
void Insert(const PatternType &p)
add a new pattern to the list
Definition: DataSet.h:117
unsigned int n_patternP
Definition: DataSet.h:70
void Release()
Force, manually, to release memory in data.
Definition: DataSet.h:127
Types involved in boosting.
DataSetHandle< Aggregator > ViewType
a soft copy of the set
Definition: DataSet.h:54
Definition: DataSet.h:33
Definition: DataSet.h:50
unsigned int Size() const
Return number of allocated samples (complete size of DataSet)
Definition: DataSet.h:101
void operator=(const DataSetHandle< SrcAggregator > &src)
Definition: DataSet.h:137
ListType templates
a collection of Pattern used in this dataset
Definition: DataSet.h:73
void Clear()
Reset (but not release memory)
Definition: DataSet.h:94
DataSetHandle(const DataSetHandle< SrcAggregator > &src)
Definition: DataSet.h:82
macro used to declare a PatternAggregator
void SetParams(const ParamType &src)
Definition: DataSet.h:107
DataSet< Aggregator > StoreType
an hard copy of the set
Definition: DataSet.h:57
void Import(const DataType &data, int category)
Definition: DataSet.h:185