1 #ifndef BARRY_SUPPORT_MEAT
2 #define BARRY_SUPPORT_MEAT_HPP 1
4 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
6 std::vector< Array_Type > * array_bank,
7 std::vector< double > * stats_bank
11 this->iter_counter = 0u;
14 coordinates_free.clear();
15 coordinates_locked.clear();
16 rules->get_seq(
EmptyArray, &coordinates_free, &coordinates_locked);
18 coordiantes_n_free = coordinates_free.size() / 2u;
19 coordiantes_n_locked = coordinates_locked.size() / 2u;
22 hashes.resize(coordiantes_n_free, 0u);
23 hashes_initialized.resize(coordiantes_n_free,
false);
29 for (
size_t i = 0u;
i < coordiantes_n_free; ++
i)
31 coordinates_free[
i * 2u],
32 coordinates_free[
i * 2u + 1u],
40 for (
size_t i = 0u;
i < coordiantes_n_locked; ++
i)
44 coordinates_locked[
i * 2u], coordinates_locked[
i * 2u + 1u]
48 coordinates_locked[
i * 2u],
49 coordinates_locked[
i * 2u + 1u],
57 throw std::logic_error(
"No counters added: Cannot compute the support without knowning what to count!");
60 if (coordiantes_n_locked)
74 for (
size_t n = 0u; n < n_counters; ++n)
89 pow(2.0,
static_cast<double>(coordiantes_n_free)),
94 bool include_it = rules_dyn->operator()(
EmptyArray, 0u, 0u);
98 change_stats.resize(coordiantes_n_free * n_counters, 0.0);
100 if (include_it && (array_bank !=
nullptr))
103 if (include_it && (stats_bank !=
nullptr))
110 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
117 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
127 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
130 std::vector< Array_Type > * array_bank,
131 std::vector< double > * stats_bank
134 #ifdef BARRY_USER_INTERRUPT
135 if (++iter_counter % 1000u == 0u)
142 if (pos >= coordiantes_n_free)
146 calc_backend_sparse(pos + 1u, array_bank, stats_bank);
150 const size_t & coord_i = coordinates_free[pos * 2u];
151 const size_t & coord_j = coordinates_free[pos * 2u + 1u];
164 size_t change_stats_different = hashes_initialized[pos] ? 0u : 1u;
165 for (
size_t n = 0u; n < n_counters; ++n)
168 tmp_chng =
counters->operator[](n).count(
174 if ((tmp_chng < DBL_MIN) & (tmp_chng > -DBL_MIN))
177 change_stats[pos * n_counters + n] = 0.0;
183 change_stats_different++;
185 change_stats[pos * n_counters + n] = tmp_chng;
193 if (rules_dyn->size() > 0u)
196 if (rules_dyn->operator()(
203 if (change_stats_different > 0u)
209 if (array_bank !=
nullptr)
212 if (stats_bank !=
nullptr)
220 if (change_stats_different > 0u)
226 if (array_bank !=
nullptr)
229 if (stats_bank !=
nullptr)
236 calc_backend_sparse(pos + 1u, array_bank, stats_bank);
245 if (change_stats_different > 0u)
247 #if defined(__OPENMP) || defined(_OPENMP)
250 for (
size_t n = 0u; n < n_counters; ++n)
259 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
262 std::vector< Array_Type > * array_bank,
263 std::vector< double > * stats_bank
266 #ifdef BARRY_USER_INTERRUPT
267 if (++iter_counter % 1000u == 0u)
274 if (pos >= coordiantes_n_free)
278 calc_backend_dense(pos + 1u, array_bank, stats_bank);
282 const size_t & coord_i = coordinates_free[pos * 2u];
283 const size_t & coord_j = coordinates_free[pos * 2u + 1u];
286 EmptyArray.insert_cell(coord_i, coord_j, 1,
false,
false);
291 size_t change_stats_different = hashes_initialized[pos] ? 0u : 1u;
292 for (
size_t n = 0u; n < n_counters; ++n)
295 tmp_chng =
counters->operator[](n).count(
301 if ((tmp_chng < DBL_MIN) & (tmp_chng > -DBL_MIN))
304 change_stats[pos * n_counters + n] = 0.0;
309 if (std::isnan(tmp_chng))
310 throw std::domain_error(
"Undefined number.");
312 change_stats_different++;
314 change_stats[pos * n_counters + n] = tmp_chng;
322 if (rules_dyn->size() > 0u)
325 if (rules_dyn->operator()(
EmptyArray, coord_i, coord_j))
328 if (change_stats_different > 0u)
334 if (array_bank !=
nullptr)
337 if (stats_bank !=
nullptr)
347 if (change_stats_different > 0u)
353 if (array_bank !=
nullptr)
356 if (stats_bank !=
nullptr)
363 calc_backend_dense(pos + 1u, array_bank, stats_bank);
366 EmptyArray.rm_cell(coord_i, coord_j,
false,
false);
368 if (change_stats_different > 0u)
370 #if defined(__OPENMP) || defined(_OPENMP)
373 for (
size_t n = 0u; n < n_counters; ++n)
381 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
384 std::vector< Array_Type > * array_bank,
385 std::vector< double > * stats_bank,
386 size_t max_num_elements_
389 if (max_num_elements_ != 0u)
390 this->max_num_elements = max_num_elements_;
393 this->init_support(array_bank, stats_bank);
397 calc_backend_dense(0u, array_bank, stats_bank);
399 calc_backend_sparse(0u, array_bank, stats_bank);
401 change_stats.clear();
403 if (max_num_elements_ != 0u)
406 if (this->
data.size() == 0u)
408 throw std::logic_error(
"The array has support of size 0 (i.e., empty support). This could be a problem in the rules (constraints).\n");
416 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
426 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
434 delete_counters =
false;
443 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
453 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
463 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
471 delete_rules =
false;
478 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
483 rules_dyn->add_rule(
f_);
488 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
493 rules_dyn->add_rule(
f_);
498 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
504 if (delete_rules_dyn)
506 delete_rules_dyn =
false;
513 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
515 const std::vector< double > & counts,
520 if (rules_dyn->size() == 0u)
527 bool rule_res = rules_dyn->operator()(
EmptyArray,
i,
j);
556 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
559 return data.get_data();
570 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
575 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
580 for (
size_t i = 0u;
i < n_counters; ++
i) {
587 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
592 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
597 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
602 template <
typename Array_Type,
typename Data_Counter_Type,
typename Data_Rule_Type,
typename Data_Rule_Dyn_Type>
604 return this->rules_dyn;
#define BARRY_MAX_NUM_ELEMENTS
#define BARRY_CHECK_SUPPORT(x, maxs)
A counter function based on change statistics.
Frequency table of vectors.
Rule for determining if a cell should be included in a sequence.
Vector of objects of class Rule.
Count stats for a single Array.
void set_counters(Counters< Array_Type, Data_Type > *counters_)
std::vector< double > count_all()
Compute the support of sufficient statistics.
bool eval_rules_dyn(const std::vector< double > &counts, const size_t &i, const size_t &j)
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.
Rules< Array_Type, Data_Rule_Type > * get_rules()
Vector of static rules (cells to iterate).
void init_support(std::vector< Array_Type > *array_bank=nullptr, std::vector< double > *stats_bank=nullptr)
Rules< Array_Type, Data_Rule_Dyn_Type > * get_rules_dyn()
Vector of dynamic rules (to include/exclude a realizaton).
void add_rule(Rule< Array_Type, Data_Rule_Type > *f_)
void add_rule_dyn(Rule< Array_Type, Data_Rule_Dyn_Type > *f_)
void set_rules_dyn(Rules< Array_Type, Data_Rule_Dyn_Type > *rules_)
Counters< Array_Type, Data_Counter_Type > * get_counters()
Vector of couter functions.
const std::vector< double > & get_counts() const
void add_counter(Counter< Array_Type, Data_Counter_Type > f_)
const FreqTable< double > & get_data() const
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.
Data_Type &&counter_ data(std::move(counter_.data))