Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
DataManager.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS addINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef __DATAMANAGER_H_
39 #define __DATAMANAGER_H_
40 
41 #include <list>
42 
43 #include "Config.h"
44 #include "CommonTypes.h"
45 #include "DataItem.h"
46 #include "Exceptions.h"
47 #include "HDF5Utils.h"
48 #include "ModelInfo.h"
49 #include "Representer.h"
50 #include "StatismoUtils.h"
51 
52 namespace statismo {
53 
57 template<typename T>
59  public:
60  typedef DataItem<T> DataItemType;
61  typedef std::list<const DataItemType*> DataItemListType;
62 
63  /***
64  * Create an empty fold
65  */
67  }
68  ;
69 
73  CrossValidationFold(const DataItemListType& trainingData,
74  const DataItemListType& testingData) :
75  m_trainingData(trainingData), m_testingData(testingData) {
76  }
77 
81  DataItemListType GetTrainingData() const {
82  return m_trainingData;
83  }
84 
88  DataItemListType GetTestingData() const {
89  return m_testingData;
90  }
91 
92  private:
93  DataItemListType m_trainingData;
94  DataItemListType m_testingData;
95 };
96 
113 template<typename T>
114 class DataManager {
115 
116  public:
117 
118  typedef Representer<T> RepresenterType;
119  typedef typename RepresenterType::DatasetPointerType DatasetPointerType;
120  typedef typename RepresenterType::DatasetConstPointerType DatasetConstPointerType;
121 
122  typedef DataItem<T> DataItemType;
123  typedef DataItemWithSurrogates<T> DataItemWithSurrogatesType;
124  typedef std::list<const DataItemType*> DataItemListType;
126  typedef std::list<CrossValidationFoldType> CrossValidationFoldListType;
127 
132  static DataManager<T>* Create(const RepresenterType* representer) {
133  return new DataManager<T>(representer);
134  }
135 
139  static DataManager<T>* Load(Representer<T>* representer,
140  const std::string& filename);
141 
142 
148  void Delete() {
149  delete this;
150  }
151 
155  virtual ~DataManager();
156 
166  virtual void AddDataset(DatasetConstPointerType dataset,
167  const std::string& URI);
168 
173  virtual void Save(const std::string& filename) const;
174 
179  DataItemListType GetData() const;
180 
184  unsigned GetNumberOfSamples() const {
185  return m_DataItemList.size();
186  }
187 
195  CrossValidationFoldListType GetCrossValidationFolds(unsigned nFolds,
196  bool randomize = true) const;
197 
201  CrossValidationFoldListType GetLeaveOneOutCrossValidationFolds() const;
202 
203  protected:
204  DataManager(const RepresenterType* representer);
205 
206  DataManager(const DataManager<T>& orig);
207  DataManager& operator=(const DataManager<T>& rhs);
208 
209  RepresenterType* m_representer;
210 
211  // members
212  DataItemListType m_DataItemList;
213 };
214 
215 }
216 
217 #include "DataManager.hxx"
218 
219 #endif /* __DATAMANAGER_H_ */
CrossValidationFoldListType GetLeaveOneOutCrossValidationFolds() const
Definition: DataManager.hxx:278
unsigned GetNumberOfSamples() const
Definition: DataManager.h:184
Manages Training and Test Data for building Statistical Models and provides functionality for Crossva...
Definition: DataManager.h:114
CrossValidationFold(const DataItemListType &trainingData, const DataItemListType &testingData)
Definition: DataManager.h:73
A trivial representer, that does no representation at all, but works directly with vectorial data...
Definition: TrivialVectorialRepresenter.h:83
static DataManager< T > * Load(Representer< T > *representer, const std::string &filename)
Definition: DataManager.hxx:75
CrossValidationFoldListType GetCrossValidationFolds(unsigned nFolds, bool randomize=true) const
Definition: DataManager.hxx:232
static DataManager< T > * Create(const RepresenterType *representer)
Definition: DataManager.h:132
DataItemListType GetTrainingData() const
Definition: DataManager.h:81
DataItemListType GetData() const
Definition: DataManager.hxx:227
virtual void AddDataset(DatasetConstPointerType dataset, const std::string &URI)
Definition: DataManager.hxx:214
DataItemListType GetTestingData() const
Definition: DataManager.h:88
virtual ~DataManager()
Definition: DataManager.hxx:58
Holds training and test data used for Crossvalidation.
Definition: DataManager.h:58
void Delete()
Definition: DataManager.h:148
virtual void Save(const std::string &filename) const
Definition: DataManager.hxx:156