genmodel 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ //
2
+ // BitVector.h
3
+ //
4
+ //
5
+ // Created by Mathieu Bouchard on 2014-03-03.
6
+ //
7
+ //
8
+
9
+ #ifndef _BitVector_h
10
+ #define _BitVector_h
11
+
12
+ #include <stdint.h>
13
+ #include <math.h>
14
+
15
+ #include <string>
16
+ #include <vector>
17
+ #include <map>
18
+
19
+
20
+ using namespace std;
21
+
22
+ class BitVector
23
+ {
24
+ public:
25
+ BitVector(const BitVector& bit_vector);
26
+ BitVector() : bits(NULL), n(0), m(0), extra(0) { }
27
+ BitVector(size_t _size);
28
+ ~BitVector();
29
+
30
+ bool operator[](size_t index) const;
31
+ BitVector operator&(const BitVector& bit_vector) const;
32
+ BitVector operator|(const BitVector& bit_vector) const;
33
+ BitVector operator^(const BitVector& bit_vector) const;
34
+ BitVector operator~() const;
35
+ BitVector& operator&=(const BitVector& bit_vector);
36
+ BitVector& operator|=(const BitVector& bit_vector);
37
+ BitVector& operator^=(const BitVector& bit_vector);
38
+ BitVector _and(const BitVector& bit_vector) const;
39
+ BitVector _or(const BitVector& bit_vector) const;
40
+ BitVector _xor(const BitVector& bit_vector) const;
41
+ BitVector _not() const;
42
+ BitVector& s_and(const BitVector& bit_vector) ;
43
+ BitVector& s_or(const BitVector& bit_vector);
44
+ BitVector& s_xor(const BitVector& bit_vector);
45
+ BitVector& s_not();
46
+ BitVector& operator=(const BitVector& bit_vector);
47
+ BitVector kronecker(const BitVector& bit_vector) const;
48
+
49
+ bool is_zero() const;
50
+ bool is_one() const;
51
+ size_t sum() const;
52
+ //BitVector operator<<();
53
+ //BitVector operator>>();
54
+
55
+ string to_s() const;
56
+ bool get(size_t index) const;
57
+ void set(size_t index, bool value);
58
+ void set(string val);
59
+ void random_fill();
60
+ void init(size_t _size);
61
+ size_t size() const;
62
+ void* Ptr();
63
+
64
+ private:
65
+ inline void set_extra();
66
+ uint64_t* bits;
67
+ size_t n;
68
+ size_t m;
69
+ uint64_t extra;
70
+ };
71
+
72
+ class BitIndex
73
+ {
74
+ public:
75
+ BitIndex(const BitVector& bit_vector);
76
+ ~BitIndex();
77
+ bool operator[](size_t _index) const;
78
+ //private:
79
+ size_t* index;
80
+ size_t n;
81
+ };
82
+
83
+ class BitMatrix
84
+ {
85
+ public:
86
+ BitMatrix();
87
+ BitMatrix(size_t _m, size_t _n);
88
+ ~BitMatrix();
89
+
90
+ void set_size(size_t _m, size_t _n);
91
+ void reset();
92
+ void seta(size_t index_i, size_t index_j, double val);
93
+ double geta(size_t index_i, size_t index_j) const;
94
+ void setrow(size_t index, const string& bit_str);
95
+ void setcol(size_t index, const string& bit_str);
96
+ double sum(const BitVector& col, const BitVector& row) const;
97
+ double sum_row(size_t i) const;
98
+ double sum_col(size_t i) const;
99
+ BitMatrix& operator+=(const BitMatrix& bit_matrix);
100
+ BitMatrix operator+(const BitMatrix& bit_matrix) const;
101
+ BitMatrix& operator-=(const BitMatrix& bit_matrix);
102
+ BitMatrix operator-(const BitMatrix& bit_matrix) const;
103
+ BitMatrix& operator=(const BitMatrix& bit_matrix);
104
+ BitMatrix copy() const;
105
+ BitMatrix operator*=(double m) const;
106
+ BitMatrix& operator*(double m);
107
+ BitMatrix add_m(const BitMatrix& bit_matrix, double m1) const; // C = A+m2*B
108
+ BitMatrix& s_add_m(const BitMatrix& bit_matrix, double m1); // A = A+m2*B
109
+
110
+ void ComputeMaximalCliqueCoverage();
111
+
112
+ size_t n; //nb_col
113
+ size_t m; //nb_row
114
+ BitVector* rows;
115
+ BitVector* cols;
116
+
117
+ private:
118
+ double** a_c;
119
+ double** a_r;
120
+ };
121
+
122
+ class BitHash
123
+ {
124
+ public:
125
+ BitHash() {name = "BitHash";}
126
+ BitHash(char* _name) {name = string(_name);}
127
+ ~BitHash() { }
128
+
129
+ size_t id_for_oid(size_t _oid);
130
+ size_t oid_for_id(size_t _id);
131
+
132
+ string name;
133
+ map<size_t,size_t> oid2id;
134
+ vector<size_t> id2oid;
135
+ };
136
+
137
+ class BitSet
138
+ {
139
+ public:
140
+ BitSet( ) {name = "BitSet";}
141
+ BitSet(char* _name) {name = string(_name);}
142
+ ~BitSet() { }
143
+
144
+ void set(char* feature, char* item, bool value);
145
+ bool get(char* feature, char* item);
146
+ void set(size_t feature_id, size_t item_id, bool value);
147
+ bool get(size_t feature_id, size_t item_id);
148
+ void add_feature(char* _name, size_t _size);
149
+
150
+ string name;
151
+ map<string, size_t> id_for_feature;
152
+ vector<map<string,size_t> > id_for_feature_item;
153
+ vector<BitVector> features;
154
+ vector<string> feature_names;
155
+ };
156
+
157
+ class BitModel
158
+ {
159
+ public:
160
+ BitModel() {name = "BitModel";}
161
+ BitModel(char* _name) {name = string(_name);}
162
+
163
+ void add_set(char* _name);
164
+ BitSet& get_set(char* _name);
165
+ BitSet& get_set(size_t set_id);
166
+
167
+ string name;
168
+ vector<BitSet> sets;
169
+ map<string, size_t> set_for_set_name;
170
+ };
171
+
172
+ #endif