X-Boost  2.3.8
MultiClassDataSet.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 _MULTICLASS_DATA_SET_H
22 #define _MULTICLASS_DATA_SET_H
23 
27 #include <vector>
28 #include <_stdint.h>
29 #include <fstream>
30 #include <iostream>
31 #include <map> // multimap
32 #include <cmath>
33 #include <stdlib.h> // rand
34 
35 #include "bitset.h"
36 
37 // fwd
38 template<class PatternType>
40 
48 template<class _PatternType, class DataParams>
49 struct MultiClassDataSetHandle: public DataParams {
50 
51 public:
52 
54  typedef typename _PatternType::DataType DataType;
55 
57  typedef _PatternType PatternType;
62 
63 public:
66  unsigned int width, height;
67 
70  std::vector<unsigned int> n_pattern;
71 
73  std::vector<PatternType> templates;
74 
75 public:
76 
77  MultiClassDataSetHandle(int n_classes) : width(0), height(0), n_pattern(n_classes) { }
78 
80  template<class R>
81  explicit MultiClassDataSetHandle( const MultiClassDataSetHandle<R> & src) : width(src.width), height(src.height), n_pattern(src.n_pattern), templates(src.templates) { }
82 
83  // do nothing
85 
87  void Clear()
88  {
89  width = height = 0;
90  for(int i =0;i<n_pattern.size();++i)
91  n_pattern[i] = 0;
92  templates.clear();
93  }
94 
96  inline unsigned int Width() const {
97  return width;
98  }
100  inline unsigned int Height() const {
101  return height;
102  }
103 
105  inline unsigned int Size() const {
106  return templates.size();
107  }
108 
111  void SetGeometry(unsigned int width, unsigned int height) {
112  this->width = width;
113  this->height = height;
114  }
115 
117  void Insert(const PatternType & p)
118  {
119  // NOTE: not boundary check
120  n_pattern[p.category] ++;
121  templates.push_back(p);
122  }
123 
125  void Release()
126  {
127  // release pattern data memory
128  for(typename std::vector<PatternType>::iterator i = templates.begin(); i!=templates.end(); ++i)
129  i->release();
130  }
131 
133  template<class R>
134  void operator=( const DataSetHandle<R> & src) {
135  width=src.width;
136  height=src.height;
137  n_pattern=src.n_pattern;
138  templates.clear();
139  templates.reserve(src.templates.size() );
140  for(typename std::vector<R>::const_iterator i = src.templates.begin(); i!=src.templates.end(); ++i)
141  templates.push_back( *i );
142  }
143 
146  void Import(const DataType & data, int category);
147 
148 };
149 
151 template<class PatternType>
152 struct MultiClassDataSet: public MultiClassDataSetHandle<PatternType> {
153 public:
154 
155  typedef MultiClassDataSetHandle<PatternType> ViewType;
156  typedef MultiClassDataSet<PatternType> StoreType;
157 
158 public:
160  {
161  this->Release();
162  }
163 
164 };
165 
166 
168 
169 template<class PatternType>
171 {
172  Insert( PatternType(data,sign) );
173 }
174 
175 
176 #endif
177 
void Import(const DataType &data, int category)
DataSetHandle< PatternType > ViewType
a soft copy
Definition: MultiClassDataSet.h:59
MultiClassDataSetHandle(const MultiClassDataSetHandle< R > &src)
DataSet conversion.
Definition: MultiClassDataSet.h:81
unsigned int Size() const
Return number of allocated samples (complete size of DataSet)
Definition: MultiClassDataSet.h:105
void Clear()
Reset (but not release memory)
Definition: MultiClassDataSet.h:87
Definition: MultiClassDataSet.h:39
_PatternType PatternType
the pattern type
Definition: MultiClassDataSet.h:57
void Release()
Force, manually, to release memory in data.
Definition: MultiClassDataSet.h:125
DataSet< PatternType > StoreType
an hard copy
Definition: MultiClassDataSet.h:61
unsigned int Width() const
training pattern geometry: width
Definition: MultiClassDataSet.h:96
Definition: DataSet.h:33
Definition: DataSet.h:50
_PatternType::DataType DataType
Inner DataType.
Definition: MultiClassDataSet.h:54
Definition: MultiClassDataSet.h:49
ListType templates
a collection of Pattern used in this dataset
Definition: DataSet.h:73
unsigned int width
Definition: MultiClassDataSet.h:66
additional typedef, for portability under win32
std::vector< unsigned int > n_pattern
Definition: MultiClassDataSet.h:70
std::vector< PatternType > templates
a collection of Pattern used in this dataset
Definition: MultiClassDataSet.h:73
void SetGeometry(unsigned int width, unsigned int height)
Definition: MultiClassDataSet.h:111
void Insert(const PatternType &p)
add a new pattern to the list
Definition: MultiClassDataSet.h:117
some usefull bit operator function
unsigned int Height() const
training pattern geometry: height
Definition: MultiClassDataSet.h:100
void operator=(const DataSetHandle< R > &src)
copy operator (do not release old memory)
Definition: MultiClassDataSet.h:134