Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
DataManagerWithSurrogates.hxx
1 /*
2  * DataManagerWithSurrogates.hxx
3  *
4  * Created by: Marcel Luethi and Remi Blanc
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 INTERRUPTION) 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 __DataManagerWithSurrogates_hxx
39 #define __DataManagerWithSurrogates_hxx
40 
41 #include "DataManagerWithSurrogates.h"
42 
43 #include <iostream>
44 
45 #include "HDF5Utils.h"
46 
47 namespace statismo {
48 
49 
51 // Data manager With Surrogates
53 
54 
55 template <typename T>
56 DataManagerWithSurrogates<T>::DataManagerWithSurrogates(const RepresenterType* representer, const std::string& filename)
57  : DataManager<T>(representer) {
58  LoadSurrogateTypes(filename);
59 }
60 
61 
62 template <typename T>
63 void
65  VectorType tmpVector;
66  tmpVector = Utils::ReadVectorFromTxtFile(filename.c_str());
67  m_typeInfo.typeFilename = filename;
68  m_typeInfo.types.clear();
69  for (unsigned i=0 ; i<tmpVector.size() ; i++) {
70  if (tmpVector(i)==0) m_typeInfo.types.push_back(DataItemWithSurrogatesType::Categorical);
71  else m_typeInfo.types.push_back(DataItemWithSurrogatesType::Continuous);
72  }
73 }
74 
75 
76 
77 template <typename T>
78 void
80  const std::string& datasetURI,
81  const std::string& surrogateFilename) {
82 
83 
84  //assert(this->m_representer != 0);
85  //assert(this->m_surrogateTypes.size() > 0);
86  assert(this->m_representer != 0);
87 
88  const VectorType& surrogateVector = Utils::ReadVectorFromTxtFile(surrogateFilename.c_str());
89 
90  if (static_cast<unsigned>(surrogateVector.size()) != m_typeInfo.types.size() ) throw StatisticalModelException("Trying to loading a dataset with unexpected number of surrogates");
91 
92  DatasetPointerType sample;
93  sample = this->m_representer->CloneDataset(ds);
94 
95  this->m_DataItemList.push_back(DataItemWithSurrogatesType::Create(this->m_representer,
96  datasetURI,
97  this->m_representer->SampleToSampleVector(sample),
98  surrogateFilename,
99  surrogateVector));
100  this->m_representer->DeleteDataset(sample);
101 }
102 
103 
104 } // Namespace statismo
105 
106 #endif
void LoadSurrogateTypes(const std::string &filename)
Definition: DataManagerWithSurrogates.hxx:64
A trivial representer, that does no representation at all, but works directly with vectorial data...
Definition: TrivialVectorialRepresenter.h:83
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
void AddDatasetWithSurrogates(DatasetConstPointerType ds, const std::string &datasetURI, const std::string &surrogateFilename)
Definition: DataManagerWithSurrogates.hxx:79