C++ main module for mmsd Package  1.0
MMSD_DataSet.h
Go to the documentation of this file.
1 #ifndef MMSD_DataSet_H
2 #define MMSD_DataSet_H
3 
4 
5 #include "MMSD_Object.h"
6 
7 #include "CORE_Array.h"
9 #include "MMSD_IntegerVector.h"
10 #include "CORE_Integer.h"
11 
26 class MMSD_DataSet : public virtual MMSD_Object {
27  SP_OBJECT(MMSD_DataSet);
28  // ATTRIBUTES
29 
30 private:
31 
32 
33  static const tFlag STRING_TYPE;
34  static const tFlag REAL_TYPE;
35 
36  int mSamplesNumber;
37 
38  // ASSOCIATIONS
39  // poperties name
40  CORE_StringArray mPropertiesName;
41 
42  // property index of the property in the property values list
43  CORE_IntArray mPropertiesIndex;
44 
45  // type of the property at index
46  CORE_FlagArray mPropertiesType;
47 
48  // values of double properties
49  SP::MMSD_DoubleFullMatrix mProperties;
50 
51  // value of string properties
52  SV::CORE_StringArray mStringProperties;
53 
54 
55 
56 
57 
58 
59 protected:
60  // METHODS
61 
62  // CONSTRUCTORS
63 
65  MMSD_DataSet(void);
66 
67 
68 
69  // DESTRUCTORS
70 
71 
74  virtual ~MMSD_DataSet(void);
75 
76 
77 
78 public:
79  //----------------
80  // NEW constructors
81  // ---------------
82  inline static SP::MMSD_DataSet New() {
83  SP::MMSD_DataSet p(new MMSD_DataSet(),
85  p->setThis(p);
86  return p;
87  };
88 
89 
90  // -----------------
91  // SET & GET Methods
92  // -----------------
93 
94 
97  inline int getTotalPropertiesNumber() const {
98  return mPropertiesName.getSize();
99  };
100 
103  inline int getPropertiesNumber() const {
104  return mProperties->getColumnsNumber();
105  };
109  return mSamplesNumber;
110  };
111 
114  inline int getPropertyIndex(const tString& name) const {
115 
116  int i,n=mPropertiesName.getSize();
117  for (i=0;i<n;i++) {
118  if (mPropertiesName[i].compare(name)==0) return i;
119  }
120  return -1;
121  };
124  inline tString getStringProperty(const tString& name,const int& sampleIndex) const {
125  ASSERT_IN(sampleIndex<mSamplesNumber);
126  int propIndex=getPropertyIndex(name);
127  if (propIndex==-1) return "";
128  if (mPropertiesType[propIndex]!=STRING_TYPE) return "";
129  return mStringProperties(mPropertiesIndex[propIndex])[sampleIndex];
130  };
133  inline tString getStringProperty(const int& index,const int& sampleIndex) const {
134  ASSERT_IN(sampleIndex<mSamplesNumber);
136  return mStringProperties(mPropertiesIndex[index])[sampleIndex];
137  };
138 
141  inline double getProperty(const tString& name,const int& sampleIndex) const {
142  ASSERT_IN(sampleIndex<mSamplesNumber);
143  int propIndex=getPropertyIndex(name);
144  if (propIndex==-1) return 0;
145  if (mPropertiesType[propIndex]!=REAL_TYPE) return 0;
146  return (*mProperties.get())(sampleIndex,mPropertiesIndex[propIndex]);
147  };
150  inline double getProperty(const int& index,const int& sampleIndex) const {
151  ASSERT_IN(sampleIndex<mSamplesNumber);
153  return (*mProperties.get())(sampleIndex,mPropertiesIndex[index]);
154  };
155 
158  inline const MMSD_DoubleFullMatrix& getProperties() const {
159  return *mProperties.get();
160  };
163  inline void getProperties(SPC::MMSD_DoubleFullMatrix& y) const {
164  y=mProperties;
165  };
166 
167 
171  inline void setProperties(const int& n,const int& p,const double* values) {
172  mSamplesNumber=n;
173  mProperties->setValues(n,p,values);
174  mPropertiesName.setSize(p);
175  mPropertiesIndex.setSize(p);
176  mPropertiesType.setSize(p);
177  for (int i=0;i<p;i++) {
178  mPropertiesName[i]="";
179  mPropertiesIndex[i]=i;
180  mPropertiesType[i]=REAL_TYPE;
181  }
182  };
183 
189  void scale();
190 
191 
192  // ---------------------------
193  // LOADER & SAVER FILE METHODS
194  // ----------------------------
195 
199  inline tBoolean load(const tString& file) {
200  vector<tString> names;
201  return load(file,names);
202  }
203 
204 
211  tBoolean load(const tString& file,const vector<tString>& names);
212 
213 
220  inline tBoolean load(const tString& file,const vector<int>& indices) {
221  vector<tString> names;
222  int n=indices.size();
223  for (int i=0;i<n;i++) names.push_back(CORE_String::toString(indices[i]));
224  return load(file,names);
225  }
226 
227 
228 private:
241  int loadCSVFile(const tString& file,const vector<tString>& names);
242 
252  int loadTXTFile(const tString& file,const vector<tString>& names);
253 
254 
255 private:
259  tBoolean saveTXTFile(const tString& file,const int& ndigits) const;
263  tBoolean saveCSVFile(const tString& file,const int& ndigits) const;
264 
265 public:
269  tBoolean save(const tString& file,const int& ndigits) const;
273  inline tBoolean save(const tString& file) const {
274  return save(file,12);
275  }
276 
277  // ------------------------------
278  // SAVER & LOADER for UI class
279  // ------------------------------
282  virtual void saveToUIClass(UI_Class& mclass) const;
283 
286  virtual void loadFromUIClass(const UI_Class& mclass);
287 
288  // ----------------------
289  // String representation
290  // ----------------------
291 
294  virtual tString toString() const {
295  tString ret="";
296  ret+="Properties:";
297  if (mProperties.get()!=null) ret+=mProperties->toString()+"\n";
298  else ret+="null\n";
299  return ret;
300  }
301 
302 
303 };
304 
305 #endif
tBoolean save(const tString &file, const int &ndigits) const
load the data set from txt file
Definition: MMSD_DataSet.cpp:540
int getPropertyIndex(const tString &name) const
get the property index of property with name
Definition: MMSD_DataSet.h:114
void setProperties(const int &n, const int &p, const double *values)
set the properties values is an array of size n x p
Definition: MMSD_DataSet.h:171
double get(const tLVectorIndex &i, const tLVectorIndex &j) const
get the value taking into account the view
Definition: LAP_DoubleMatrix.h:172
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
int getPropertiesNumber() const
get the properties number of real properties
Definition: MMSD_DataSet.h:103
virtual tString toString() const
turn the class into string
Definition: MMSD_DataSet.h:294
int getTotalPropertiesNumber() const
get the properties number of real + string properties
Definition: MMSD_DataSet.h:97
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: MMSD_DataSet.cpp:52
This class describes the FullMatrix class.
Definition: MMSD_DoubleFullMatrix.h:17
const MMSD_DoubleFullMatrix & getProperties() const
get real properties
Definition: MMSD_DataSet.h:158
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
#define tBoolean
Definition: types.h:48
CORE_Array< tString > CORE_StringArray
Definition: CORE_Array.h:619
DEFINE_SPTR(MMSD_DataSet)
tBoolean load(const tString &file)
load a data set from txt file
Definition: MMSD_DataSet.h:199
#define null
Definition: types.h:13
This class describes a data set.
Definition: MMSD_DataSet.h:26
virtual ~MMSD_DataSet(void)
destroy an object.
Definition: MMSD_DataSet.cpp:20
static SP::MMSD_DataSet New()
Definition: MMSD_DataSet.h:82
double getProperty(const int &index, const int &sampleIndex) const
get the real value of index - property at index sampleIndex
Definition: MMSD_DataSet.h:150
tBoolean save(const tString &file) const
load the data set from txt file
Definition: MMSD_DataSet.h:273
tString getStringProperty(const int &index, const int &sampleIndex) const
get the string value of index - property at index sampleIndex
Definition: MMSD_DataSet.h:133
tString getStringProperty(const tString &name, const int &sampleIndex) const
get the string property of name at index sampleIndex
Definition: MMSD_DataSet.h:124
void setSize(const tArrayIndex &n)
set the size of the array
Definition: CORE_Array.hpp:149
tLVectorIndex getSamplesNumber() const
get the samples number
Definition: MMSD_DataSet.h:108
#define tLVectorIndex
Definition: lapack_types.h:13
MMSD_DataSet(void)
create an object
Definition: MMSD_DataSet.cpp:13
#define tString
Definition: types.h:49
double getProperty(const tString &name, const int &sampleIndex) const
get the real property of name at index sampleIndex
Definition: MMSD_DataSet.h:141
void scale()
scale the data set
Definition: MMSD_DataSet.cpp:24
const tArrayIndex & getSize() const
return the size of the array
Definition: CORE_Array.h:223
tBoolean load(const tString &file, const vector< int > &indices)
load a data set from csv file and select only the properties whose name is in names list ...
Definition: MMSD_DataSet.h:220
void getProperties(SPC::MMSD_DoubleFullMatrix &y) const
get real properties
Definition: MMSD_DataSet.h:163
#define ASSERT_IN(a)
Definition: types.h:96
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: MMSD_DataSet.cpp:40
This class is the base class of all Mixture of Multiple Scaled Distribution package.
Definition: MMSD_Object.h:20
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14