1 #ifndef BARRY_CSS_COUNTERS
2 #define BARRY_CSS_COUNTERS
9 size_t n = data.indices[0u]; \
10 size_t s = data.indices[1u]; \
11 size_t e = data.indices[2u]; \
12 size_t ctype = data.indices[3u]; \
13 size_t ego_id = data.indices[4u]; \
15 throw std::range_error("Counter type should be 0, 1, or 2.");
22 #define CSS_MATCH_TYPE() \
25 if ((i_ != ego_id) && (j_ != ego_id)) return 0.0; \
26 } else if (ctype == 2u) { \
27 if ((i_ == ego_id) || (j_ == ego_id)) return 0.0; \
32 #define CSS_CASE_TRUTH() if ((i < n) && (j < n))
39 #define CSS_TRUE_CELLS() \
43 double tji = static_cast<double>(Array(j, i, false)); \
44 double pij = static_cast<double>(Array(i + s, j + s, false)); \
45 double pji = static_cast<double>(Array(j + s, i + s, false));
48 #define CSS_CASE_PERCEIVED() else if (((i >= s) && (i < e)) & ((j >= s) && (j < e)))
55 #define CSS_PERCEIVED_CELLS() \
59 double tji = static_cast<double>(Array(j - s, i - s, false)); \
60 double pji = static_cast<double>(Array(j, i, false)); \
61 double tij = static_cast<double>(Array(i - s, j - s, false));
66 #define CSS_CASE_ELSE()
70 #define CSS_CHECK_SIZE_INIT() \
72 if ((data.indices.at(0) > Array.ncol()) \
73 | (data.indices.at(2) > Array.ncol())) \
74 throw std::range_error("The network does not match the prescribed size.");
76 #define CSS_CHECK_SIZE() for (size_t i = 0u; i < end_.size(); ++i) {\
77 if (i == 0u) continue; \
78 else if (end_[i] < end_[i-1u]) \
79 throw std::logic_error("Endpoints should be specified in order.");}
81 #define CSS_APPEND(name) std::string name_ = (name);\
82 for (size_t i = 0u; i < end_.size(); ++i) { \
83 std::string tmpname = name_ + " (" + std::to_string(i) + ")" + \
84 ((counter_type == 1u) ? " (only perceiver)" : ((counter_type == 2u)? " (only alters)": ""));\
85 counters->add_counter(tmp_count, tmp_init, nullptr, \
86 NetCounterData({netsize, i == 0u ? netsize : end_[i-1], end_[i], counter_type, i}, {}),\
89 #define CSS_NET_COUNTER_LAMBDA_INIT() NETWORK_COUNTER_LAMBDA(tmp_init) {\
90 CSS_CHECK_SIZE_INIT() \
106 template<
typename Tnet = Network>
110 const std::vector< size_t > & end_,
111 size_t counter_type = 0u
126 return pij * pji * (1.0 - 2.0 * tji) - (1.0 - tji)*(
127 pij * (1.0 - pji) + (1.0 - pij) * pji
134 return pji * (tij * (1.0 - tji) + (1.0 - tij) * tji) +
135 (1.0 - tij) * (1.0 - tji) * (1 - 2.0 * pji)
147 CSS_APPEND(
"Partially false recip (comission)")
154 template<
typename Tnet = Network>
158 const std::vector< size_t > & end_,
159 size_t counter_type = 0u
172 return tji * ((1.0 - pij) * pji + pij * (1.0 - pji)) +
173 (1.0 - 2.0 * tji) * (1.0 - pij) * (1.0 - pji)
179 return tji * tij * (1.0 - 2.0 * pji) -
180 (1.0 - pji) * ((1.0 - tij) * tji + tij * (1.0 - tji))
192 CSS_APPEND(
"Partially false recip (omission)")
199 template<
typename Tnet = Network>
203 const std::vector< size_t > & end_,
204 size_t counter_type = 0u
217 return -(1.0 - tji) * pij * pji;
222 return (1.0 - tij) * (1.0 - tji) * pji;
233 CSS_APPEND(
"Completely false recip (comission)")
240 template<
typename Tnet = Network>
244 const std::vector< size_t > & end_,
245 size_t counter_type = 0u
258 return tji * (1.0 - pij) * (1.0 - pji);
263 return - tij * tji * (1.0 - pji);
274 CSS_APPEND(
"Completely false recip (omission)")
281 template<
typename Tnet = Network>
285 const std::vector< size_t > & end_,
286 size_t counter_type = 0u
299 return (1.0 - tji) * (1.0 - pij) * pji - tji * pij * (1.0 - pji);
304 return (1.0 - tij) * tji * (1.0 - pji) - tij * (1.0 - tij) * pji;
323 template<
typename Tnet = Network>
327 const std::vector< size_t > & end_,
328 size_t counter_type = 0u
342 return -(1.0 - pij) * (1.0 - pji) * (1.0 - tji);
347 return -(1.0 - tij) * (1.0 - tji) * (1.0 - pji);
359 double n_dbl =
static_cast<double>(
data.indices[0u]);
362 size_t ctype =
data.indices[3u];
367 return (n_dbl - 1.0);
369 }
else if (ctype == 2u)
376 return n_dbl * (n_dbl - 1.0) / 2.0;
388 template<
typename Tnet = Network>
392 const std::vector< size_t > & end_,
393 size_t counter_type = 0u
406 return -(1.0 - tji) * ((1.0 - pij) * pji + pij * (1.0 - pji));
411 return (1.0 - tij) * (1.0 - tji) * (1 - 2.0 * pji);
422 CSS_APPEND(
"(02) Partial false positive (null)")
428 template<
typename Tnet = Network>
432 const std::vector< size_t > & end_,
433 size_t counter_type = 0u
446 return -(1.0 - tji) * pij * pji;
451 return (1.0 - tij) * (1.0 - tji) *pji;
462 CSS_APPEND(
"(03) Complete false positive (null)")
468 template<
typename Tnet = Network>
472 const std::vector< size_t > & end_,
473 size_t counter_type = 0u
486 return (1.0 - pij) * (1.0 - pji) * (1.0 - 2.0 * tji);
491 return -(1.0 - pji) * ((1.0 - tij) * tji + tij * (1.0 - tji));
502 CSS_APPEND(
"(04) Partial false negative (assym)")
508 template<
typename Tnet = Network>
512 const std::vector< size_t > & end_,
513 size_t counter_type = 0u
526 return pij * (1.0 - tji) * (1.0 - pji) - (1.0 - pij) * tji * pji;
531 return tij * (1.0 - tji) * (1.0 - pji) - (1.0 - tij) * tji * pji;
548 template<
typename Tnet = Network>
552 const std::vector< size_t > & end_,
553 size_t counter_type = 0u
566 return (1.0 - pij) * (1.0 - tji) * pji - pij * tji * (1.0 - pji);
571 return (1.0 - tij) * tji * (1.0 - pji) - tij * (1.0 - tji) * pji;
588 template<
typename Tnet = Network>
592 const std::vector< size_t > & end_,
593 size_t counter_type = 0u
606 return pij * pji * (1.0 - 2.0 * tji);
611 return pji * (tij * (1.0 - tji) + (1.0 - tij) * tji);
622 CSS_APPEND(
"(07) Partial false positive (assym)")
628 template<
typename Tnet = Network>
632 const std::vector< size_t > & end_,
633 size_t counter_type = 0u
646 return tji * (1.0 - pij) * (1.0 - pji);
651 return - tij * tji * (1.0 - pji);
662 CSS_APPEND(
"(08) Complete false negative (full)")
668 template<
typename Tnet = Network>
672 const std::vector< size_t > & end_,
673 size_t counter_type = 0u
686 return tji * (pij * (1.0 - pji) + (1.0 - pij) * pji);
691 return tij * tji * (1.0 - 2.0 * pji);
702 CSS_APPEND(
"(09) Partial false negative (full)")
708 template<
typename Tnet = Network>
712 const std::vector< size_t > & end_,
713 size_t counter_type = 0u
726 return tji * pij * pji;
731 return tij * tji * pji;
749 #undef CSS_CASE_TRUTH
750 #undef CSS_TRUE_CELLS
751 #undef CSS_CASE_PERCEIVED
752 #undef CSS_PERCEIVED_CELLS
754 #undef CSS_CHECK_SIZE_INIT
755 #undef CSS_CHECK_SIZE
756 #undef CSS_NET_COUNTER_LAMBDA_INIT
757 #undef CSS_MATCH_TYPE
Data_Type &&counter_ data(std::move(counter_.data))
void counter_css_census06(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_completely_false_recip_omiss(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
Counts completely false reciprocity (omission)
void counter_css_census04(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_census10(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
#define CSS_CHECK_SIZE_INIT()
void counter_css_census03(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_census02(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_census08(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_mixed_recip(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
Counts mixed reciprocity errors.
void counter_css_census01(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_partially_false_recip_commi(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
Counts errors of commission.
void counter_css_census05(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
#define CSS_PERCEIVED_CELLS()
#define CSS_NET_COUNTER_LAMBDA_INIT()
void counter_css_census09(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_completely_false_recip_comiss(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
Counts completely false reciprocity (comission)
#define CSS_CASE_PERCEIVED()
void counter_css_census07(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
void counter_css_partially_false_recip_omiss(NetCounters< Tnet > *counters, size_t netsize, const std::vector< size_t > &end_, size_t counter_type=0u)
Counts errors of omission.
#define NETWORK_COUNTER_LAMBDA(a)