barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
support-bones.hpp
Go to the documentation of this file.
1 #ifndef BARRY_SUPPORT_BONES_HPP
2 #define BARRY_SUPPORT_BONES_HPP 1
3 
4 template <typename Cell_Type, typename Data_Type>
5 class BArray;
6 
7 template <typename Tdat>
8 class FreqTable;
9 
10 template <typename Array_Type, typename Data_Counter_Type>
11 class Counters;
12 
13 template <typename Array_Type, typename Data_Rule_Type>
14 class Rules;
15 
16 template<typename Array_Type, typename Data_Type>
17 class Rule;
18 
36 template <
37  typename Array_Type = BArray<bool, bool>,
38  typename Data_Counter_Type = bool,
39  typename Data_Rule_Type = bool,
40  typename Data_Rule_Dyn_Type = bool
41  >
42 class Support {
43 
44 private:
45  void calc_backend_sparse(
46  size_t pos = 0u,
47  std::vector< Array_Type > * array_bank = nullptr,
48  std::vector< double > * stats_bank = nullptr
49  );
50 
51  void calc_backend_dense(
52  size_t pos = 0u,
53  std::vector< Array_Type > * array_bank = nullptr,
54  std::vector< double > * stats_bank = nullptr
55  );
56 
60  Array_Type EmptyArray;
61  FreqTable<> data;
65 
66  size_t iter_counter = 0u;
67 
68 public:
69 
70  size_t N, M;
71  bool delete_counters = true;
72  bool delete_rules = true;
73  bool delete_rules_dyn = true;
75 
76  // Temp variables to reduce memory allocation
77  std::vector< double > current_stats;
78  std::vector< size_t > coordinates_free;
79  std::vector< size_t > coordinates_locked;
82  std::vector< double > change_stats;
83  std::vector< size_t > hashes;
84  std::vector< bool > hashes_initialized;
85  size_t n_counters;
86 
89  Support(const Array_Type & Array_) :
90  EmptyArray(Array_),
91  counters(new Counters<Array_Type,Data_Counter_Type>()),
92  rules(new Rules<Array_Type,Data_Rule_Type>()),
93  rules_dyn(new Rules<Array_Type,Data_Rule_Dyn_Type>()),
94  N(Array_.nrow()), M(Array_.ncol()), current_stats() {};
95 
98  Support(size_t N_, size_t M_) :
99  EmptyArray(N_, M_),
100  counters(new Counters<Array_Type,Data_Counter_Type>()),
101  rules(new Rules<Array_Type,Data_Rule_Type>()),
102  rules_dyn(new Rules<Array_Type,Data_Rule_Dyn_Type>()),
103  N(N_), M(M_), current_stats() {};
104 
106  EmptyArray(0u, 0u),
107  counters(new Counters<Array_Type,Data_Counter_Type>()),
108  rules(new Rules<Array_Type,Data_Rule_Type>()),
109  rules_dyn(new Rules<Array_Type,Data_Rule_Dyn_Type>()),
110  N(0u), M(0u), current_stats() {};
111 
113 
114  if (delete_counters)
115  delete counters;
116  if (delete_rules)
117  delete rules;
118  if (delete_rules_dyn)
119  delete rules_dyn;
120 
121  };
122 
123  void init_support(
124  std::vector< Array_Type > * array_bank = nullptr,
125  std::vector< double > * stats_bank = nullptr
126  );
127 
136  void reset_array();
137  void reset_array(const Array_Type & Array_);
139 
150 
163  bool eval_rules_dyn(const std::vector<double> & counts, const size_t & i, const size_t & j);
164  // bool eval_rules_dyn(const double * counts, const size_t & i, const size_t & j);
166 
180  void calc(
181  std::vector< Array_Type > * array_bank = nullptr,
182  std::vector< double > * stats_bank = nullptr,
183  size_t max_num_elements_ = 0u
184  );
185 
186  const std::vector< double > & get_counts() const;
187  std::vector< double > * get_current_stats();
188  void print() const;
189 
190  const FreqTable< double > & get_data() const;
194 
195 };
196 
197 
198 #endif
#define BARRY_MAX_NUM_ELEMENTS
Baseline class for binary arrays.
A counter function based on change statistics.
Vector of counters.
Frequency table of vectors.
Definition: freqtable.hpp:22
Rule for determining if a cell should be included in a sequence.
Definition: rules-bones.hpp:20
Vector of objects of class Rule.
Definition: rules-bones.hpp:71
Compute the support of sufficient statistics.
bool eval_rules_dyn(const std::vector< double > &counts, const size_t &i, const size_t &j)
bool delete_rules_dyn
void calc(std::vector< Array_Type > *array_bank=nullptr, std::vector< double > *stats_bank=nullptr, size_t max_num_elements_=0u)
Computes the entire support.
std::vector< double > current_stats
size_t M
Rules< Array_Type, Data_Rule_Type > * get_rules()
Vector of static rules (cells to iterate).
Support(const Array_Type &Array_)
Constructor passing a reference Array.
Support(size_t N_, size_t M_)
Constructor specifying the dimensions of the array (empty).
size_t coordiantes_n_free
size_t coordiantes_n_locked
void init_support(std::vector< Array_Type > *array_bank=nullptr, std::vector< double > *stats_bank=nullptr)
Definition: support-meat.hpp:5
Rules< Array_Type, Data_Rule_Dyn_Type > * get_rules_dyn()
Vector of dynamic rules (to include/exclude a realizaton).
size_t n_counters
std::vector< size_t > coordinates_free
void add_rule(Rule< Array_Type, Data_Rule_Type > *f_)
void print() const
std::vector< bool > hashes_initialized
void add_rule_dyn(Rule< Array_Type, Data_Rule_Dyn_Type > *f_)
std::vector< double > change_stats
bool delete_counters
void set_rules_dyn(Rules< Array_Type, Data_Rule_Dyn_Type > *rules_)
Counters< Array_Type, Data_Counter_Type > * get_counters()
Vector of couter functions.
size_t N
const std::vector< double > & get_counts() const
void add_counter(Counter< Array_Type, Data_Counter_Type > f_)
const FreqTable< double > & get_data() const
void reset_array()
std::vector< size_t > coordinates_locked
size_t max_num_elements
bool delete_rules
std::vector< size_t > hashes
void set_rules(Rules< Array_Type, Data_Rule_Type > *rules_)
void set_counters(Counters< Array_Type, Data_Counter_Type > *counters_)
std::vector< double > * get_current_stats()
List current statistics.
size_t size_t j
size_t i
Data_Type * counters_
Data_Type f_