barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
defm-types.hpp
Go to the documentation of this file.
1 #ifndef DEFM_TYPES_HPP
2 #define DEFM_TYPES_HPP
3 class DEFMData;
4 
5 typedef barry::BArrayDense<int, DEFMData> DEFMArray;
6 
16 class DEFMData {
17 public:
18 
19  DEFMArray * array; // Pointer to the owner of this data
20  const double * covariates;
21  size_t obs_start;
22  size_t X_ncol;
23  size_t X_nrow;
24  std::vector< size_t > covar_sort;
25  std::vector< size_t > covar_used;
27 
28  DEFMData() {};
29 
38  DEFMArray * array_,
39  const double * covariates_,
40  size_t obs_start_,
41  size_t X_ncol_,
42  size_t X_nrow_,
43  bool column_major_
44  ) : array(array_), covariates(covariates_), obs_start(obs_start_),
45  X_ncol(X_ncol_), X_nrow(X_nrow_), column_major(column_major_) {};
46 
54  double operator()(size_t i, size_t j) const;
55  double at(size_t i, size_t j) const;
56  size_t ncol() const;
57  size_t nrow() const;
58  void print() const;
59 
60  ~DEFMData() {};
61 
62 };
63 
67 public:
68 
69  std::vector< size_t > indices;
70  std::vector< double > numbers;
71  std::vector< bool > logical;
72  bool is_motif;
73 
74  DEFMCounterData() : indices(0u), numbers(0u), logical(0u), is_motif(true) {};
76  const std::vector< size_t > indices_,
77  const std::vector< double > numbers_,
78  const std::vector< bool > logical_,
79  bool is_motif_ = true
80  ): indices(indices_), numbers(numbers_),
81  logical(logical_), is_motif(is_motif_) {};
82 
83  size_t idx(size_t i) const {return indices[i];};
84  double num(size_t i) const {return numbers[i];};
85  bool is_true(size_t i) const {return logical[i];};
86 
88 
89 };
90 
91 class DEFMRuleData {
92 public:
93 
94  std::vector< double > numbers;
95  std::vector< size_t > indices;
96  std::vector< bool > logical;
97 
98  bool init = false;
99 
100  double num(size_t i) const {return numbers[i];};
101  size_t idx(size_t i) const {return indices[i];};
102  bool is_true(size_t i) const {return logical[i];};
103 
105 
107  std::vector< double > numbers_,
108  std::vector< size_t > indices_,
109  std::vector< bool > logical_
110  ) : numbers(numbers_), indices(indices_), logical(logical_) {};
111 
113  std::vector< double > numbers_,
114  std::vector< size_t > indices_
115  ) : numbers(numbers_), indices(indices_), logical(numbers_.size()) {};
116 
117 };
118 
119 
120 inline double DEFMData::operator()(size_t i, size_t j) const
121 {
122 
123  if (column_major)
124  return *(covariates + (obs_start + i + X_nrow * j));
125  else
126  return *(covariates + ((obs_start + i) * X_ncol + j));
127 
128 }
129 
130 inline size_t DEFMData::ncol() const {
131  return X_ncol;
132 }
133 
134 inline size_t DEFMData::nrow() const {
135  return X_nrow;
136 }
137 
138 inline void DEFMData::print() const {
139 
140  for (size_t i = 0u; i < array->nrow(); ++i)
141  {
142 
143  printf_barry("row %li (%li): ", i, obs_start + i);
144  for (size_t j = 0u; j < X_ncol; ++j)
145  printf_barry("% 5.2f, ", operator()(i, j));
146  printf_barry("\n");
147 
148  }
149 
150 }
151 
158 
160 public:
161  const std::vector< double > * counts;
162  size_t pos;
163  size_t lb;
164  size_t ub;
165 
167  const std::vector< double > * counts_,
168  size_t pos_,
169  size_t lb_,
170  size_t ub_
171  ) : counts(counts_), pos(pos_), lb(lb_), ub(ub_) {};
172 
174 
175  const double operator()() const
176  {
177  return (*counts)[pos];
178  }
179 
180 };
181 
186 typedef barry::Counter<DEFMArray, DEFMCounterData > DEFMCounter;
187 typedef barry::Counters<DEFMArray, DEFMCounterData> DEFMCounters;
188 typedef barry::Support<DEFMArray, DEFMCounterData, DEFMRuleData,DEFMRuleDynData> DEFMSupport;
189 typedef barry::StatsCounter<DEFMArray, DEFMCounterData> DEFMStatsCounter;
190 typedef barry::Model<DEFMArray, DEFMCounterData,DEFMRuleData,DEFMRuleDynData> DEFMModel;
191 
192 
193 typedef barry::Rule<DEFMArray, DEFMRuleData> DEFMRule;
194 typedef barry::Rules<DEFMArray, DEFMRuleData> DEFMRules;
195 typedef barry::Rule<DEFMArray, DEFMRuleDynData> DEFMRuleDyn;
196 typedef barry::Rules<DEFMArray, DEFMRuleDynData> DEFMRulesDyn;
198 
199 #endif
#define printf_barry
Data class used to store arbitrary size_t or double vectors.
Definition: defm-types.hpp:66
Data class for DEFM arrays.
Definition: defm-types.hpp:16
size_t size_t j
size_t i
barry::BArrayDense< int, DEFMData > DEFMArray
Definition: defm-types.hpp:3
size_t X_ncol
Number of columns in the array of covariates.
Definition: defm-types.hpp:22
DEFMArray * array
Definition: defm-types.hpp:19
std::vector< size_t > indices
Definition: defm-types.hpp:69
barry::StatsCounter< DEFMArray, DEFMCounterData > DEFMStatsCounter
Definition: defm-types.hpp:189
std::vector< size_t > indices
Definition: defm-types.hpp:95
double num(size_t i) const
Definition: defm-types.hpp:84
std::vector< size_t > covar_sort
Definition: defm-types.hpp:24
bool is_motif
If false, then is a logit intercept.
Definition: defm-types.hpp:72
barry::Rules< DEFMArray, DEFMRuleDynData > DEFMRulesDyn
Definition: defm-types.hpp:196
std::vector< size_t > covar_used
Value where the sorting of the covariates is stored.
Definition: defm-types.hpp:25
std::vector< double > numbers
Definition: defm-types.hpp:70
double num(size_t i) const
Definition: defm-types.hpp:100
barry::Counters< DEFMArray, DEFMCounterData > DEFMCounters
Definition: defm-types.hpp:187
bool is_true(size_t i) const
Definition: defm-types.hpp:85
double operator()(size_t i, size_t j) const
Access to the row (i) colum (j) data.
Definition: defm-types.hpp:120
bool column_major
Vector indicating which covariates are included in the model.
Definition: defm-types.hpp:26
std::vector< double > numbers
Definition: defm-types.hpp:94
bool is_true(size_t i) const
Definition: defm-types.hpp:102
const std::vector< double > * counts
Definition: defm-types.hpp:161
size_t idx(size_t i) const
Definition: defm-types.hpp:83
std::vector< bool > logical
Definition: defm-types.hpp:71
std::vector< bool > logical
Definition: defm-types.hpp:96
size_t obs_start
Index of the observation in the data.
Definition: defm-types.hpp:21
DEFMRuleDynData(const std::vector< double > *counts_, size_t pos_, size_t lb_, size_t ub_)
Definition: defm-types.hpp:166
size_t nrow() const
Definition: defm-types.hpp:134
size_t ncol() const
Definition: defm-types.hpp:130
const double * covariates
Vector of covariates (complete vector)
Definition: defm-types.hpp:20
barry::Model< DEFMArray, DEFMCounterData, DEFMRuleData, DEFMRuleDynData > DEFMModel
Definition: defm-types.hpp:190
DEFMRuleData(std::vector< double > numbers_, std::vector< size_t > indices_)
Definition: defm-types.hpp:112
barry::Rule< DEFMArray, DEFMRuleDynData > DEFMRuleDyn
Definition: defm-types.hpp:195
DEFMRuleData(std::vector< double > numbers_, std::vector< size_t > indices_, std::vector< bool > logical_)
Definition: defm-types.hpp:106
barry::Rules< DEFMArray, DEFMRuleData > DEFMRules
Definition: defm-types.hpp:194
double at(size_t i, size_t j) const
const double operator()() const
Definition: defm-types.hpp:175
DEFMData(DEFMArray *array_, const double *covariates_, size_t obs_start_, size_t X_ncol_, size_t X_nrow_, bool column_major_)
Constructor.
Definition: defm-types.hpp:37
size_t idx(size_t i) const
Definition: defm-types.hpp:101
DEFMCounterData(const std::vector< size_t > indices_, const std::vector< double > numbers_, const std::vector< bool > logical_, bool is_motif_=true)
Definition: defm-types.hpp:75
size_t X_nrow
Number of rows in the array of covariates.
Definition: defm-types.hpp:23
void print() const
Definition: defm-types.hpp:138
barry::Rule< DEFMArray, DEFMRuleData > DEFMRule
Definition: defm-types.hpp:193
barry::Support< DEFMArray, DEFMCounterData, DEFMRuleData, DEFMRuleDynData > DEFMSupport
Definition: defm-types.hpp:188
barry::Counter< DEFMArray, DEFMCounterData > DEFMCounter
Definition: defm-types.hpp:186