SiGraph: sulcal graphs


dbLearnable.h
Go to the documentation of this file.
1
2
3#ifndef SI_LEARNABLE_DBLEARNABLE_H
4#define SI_LEARNABLE_DBLEARNABLE_H
5
7#include <vector>
8#include <string>
9#include <string.h>
10#include <map>
11#include <iostream> //FIXME : todel
12
13namespace sigraph
14{
15
18
19class DBLearnable : public Learnable
20{
21 public:
22 DBLearnable() : _X(NULL), _Y(NULL), _INF(NULL), _size(0),
23 _cols_numbers(std::vector<int>(3, 0)), _owned_data(false) {};
24
31 DBLearnable(double *X, double *Y, char *INF, std::vector<int> &dims,
32 bool owned_data);
33
34 virtual ~DBLearnable();
35
36 inline DBLearnable(const DBLearnable & db)
37 : Learnable(db)
38 {
39 *this = db;
40 }
41
42
44 {
45 if (this == &db) return *this;
46 _size = db._size;
48 if (_owned_data == false)
49 {
50 _X = db._X;
51 _Y = db._Y;
52 _INF = db._INF;
53 } else {
54 _X = new double[_cols_numbers[0] * _size];
55 _Y = new double[_cols_numbers[1] * _size];
56 _INF = new char[_cols_numbers[2] * 32 * _size];
57 memcpy(_X, db._X, _cols_numbers[0] * _size);
58 memcpy(_Y, db._Y, _cols_numbers[1] * _size);
59 //FIXME : vrai pour siDBLearnable uniquement
60 memcpy(_INF, db._INF, _cols_numbers[2] * 32 * _size);
61 }
62 return( *this );
63 }
64
65
66
68
69 public:
70 inline double *getX() const { return _X; };
71 inline double *getY() const { return _Y; };
72 inline char *getINF() const { return _INF; };
73 inline int size() const { return _size; };
74 inline const std::vector<int> &getColsNumber() const {
75 return _cols_numbers; }
76 inline int getXcolsNumber() const { return _cols_numbers[0]; };
77 inline int getYcolsNumber() const { return _cols_numbers[1]; };
78 inline int getINFcolsNumber() const { return _cols_numbers[2]; };
79 inline unsigned int getIndiceFromLabel(std::string &label) const {
80 if (_labels_to_indices.find(label) == _labels_to_indices.end())
81 throw;
82 return (*_labels_to_indices.find(label)).second;
83
84 };
85 // New allocated VectorLearnable from database slice
86 DBVectorLearnable *operator[](unsigned int ind) const;
88
89 void clear();
90
91 public:
92 void setLabels(std::vector<std::string> &labels) {
93 std::vector<std::string>::const_iterator il, el;
94 unsigned int ind = 0;
95
96 for (il = labels.begin(), el = labels.end();
97 il != el; ++il, ++ind)
98 _labels_to_indices[*il] = ind;
99 }
100
101 protected:
103 double *_X;
105 double *_Y;
107 char *_INF;
109 int _size;
111 std::vector<int> _cols_numbers;
115 std::map<std::string, unsigned int> _labels_to_indices;
116};
117
118
120{
121 public:
123 SiDBLearnable(double *X, double *Y, char *INF,
124 std::vector<int> &dims, bool owned_data) :
125 DBLearnable(X, Y, INF, dims, owned_data), _cycles(0) {};
126
127 virtual ~SiDBLearnable() {};
128
130
131 public:
132 inline void setSplit(int split) { _split = split; };
133 inline void setCycles(int cycles) { _cycles = cycles; };
134 inline int getSplit() const { return _split; };
135 inline int getCycles() const { return _cycles; };
136 // New allocated SiVectorLearnable from database slice
137 SiVectorLearnable *operator[](unsigned int ind) const;
139
140 private:
141 // split value between train and test vectors
142 int _split;
143 // number of train cycles.
144 int _cycles;
145};
146
147}
148
149#endif
double * _Y
Y data matrix.
DBLearnable(const DBLearnable &db)
Definition dbLearnable.h:36
const std::vector< int > & getColsNumber() const
Definition dbLearnable.h:74
void setLabels(std::vector< std::string > &labels)
Definition dbLearnable.h:92
DBLearnable(double *X, double *Y, char *INF, std::vector< int > &dims, bool owned_data)
Create DBLearnable from arrays and dims.
unsigned int getIndiceFromLabel(std::string &label) const
Definition dbLearnable.h:79
int getINFcolsNumber() const
Definition dbLearnable.h:78
char * getINF() const
Definition dbLearnable.h:72
double * getX() const
Accessors :
Definition dbLearnable.h:70
int getYcolsNumber() const
Definition dbLearnable.h:77
int _size
number of vectors
DBLearnable & operator=(const DBLearnable &db)
Definition dbLearnable.h:43
double * getY() const
Definition dbLearnable.h:71
int getXcolsNumber() const
Definition dbLearnable.h:76
char * _INF
meta information data matrix
std::map< std::string, unsigned int > _labels_to_indices
info labels -> indices
DBVectorLearnable * operator[](unsigned int ind) const
double * _X
X data matrix.
bool _owned_data
data are owned by database
std::vector< int > _cols_numbers
number of columns (X, Y, INF)
void setSplit(int split)
Accessors.
SiVectorLearnable * operator[](unsigned int ind) const
void setCycles(int cycles)
SiDBLearnable(double *X, double *Y, char *INF, std::vector< int > &dims, bool owned_data)
Specialization for sigraph : Y as only one dim.
STL namespace.