diff --git a/barry.hpp b/barry.hpp index a2441ed7e..b344183e7 100644 --- a/barry.hpp +++ b/barry.hpp @@ -10723,25 +10723,64 @@ inline void counter_degree( // n: Net size, // s: Start of the i-th network // e: end of the i-th network +// ego_id: Ego of the cell (i, j) #define CSS_SIZE() \ - size_t n = data.indices[0u]; \ - size_t s = data.indices[1u]; \ - size_t e = data.indices[2u]; + size_t n = data.indices[0u]; \ + size_t s = data.indices[1u]; \ + size_t e = data.indices[2u]; \ + size_t ctype = data.indices[3u]; \ + size_t ego_id = data.indices[4u]; \ + if (ctype > 2) \ + throw std::range_error("Counter type should be 0, 1, or 2."); + +// Check whether ego_id is involved in the current cell +// ctype: Type of counter +// 0: All cells +// 1: Only if perceiver +// 2: Only if not perceiver +#define CSS_MATCH_TYPE() \ + if (ctype != 0u) { /* all counts */ \ + if (ctype == 1u) { /* Only if perceiver */ \ + if ((i_ != ego_id) && (j_ != ego_id)) return 0.0; \ + } else if (ctype == 2u) { /* Only if not perceiver */ \ + if ((i_ == ego_id) || (j_ == ego_id)) return 0.0; \ + } \ + }; // Variables in case that the current cell corresponds to the True #define CSS_CASE_TRUTH() if ((i < n) && (j < n)) + +// i_: i-th index of the cell +// j_: j-th index of the cell +// tji: True value of the cell (i, j) +// pij: Perceived value of the cell (i, j) +// pji: Perceived value of the cell (j, i) #define CSS_TRUE_CELLS() \ + size_t i_ = i; \ + size_t j_ = j; \ + CSS_MATCH_TYPE() \ double tji = static_cast(Array(j, i, false)); \ double pij = static_cast(Array(i + s, j + s, false)); \ double pji = static_cast(Array(j + s, i + s, false)); // Variables in case that the current cell corresponds to the Perceived #define CSS_CASE_PERCEIVED() else if (((i >= s) && (i < e)) & ((j >= s) && (j < e))) + +// i_: i-th index of the cell +// j_: j-th index of the cell +// tji: True value of the cell (i, j) +// pji: Perceived value of the cell (i, j) +// tij: True value of the cell (j, i) #define CSS_PERCEIVED_CELLS() \ + size_t i_ = i - s; \ + size_t j_ = j - s; \ + CSS_MATCH_TYPE() \ double tji = static_cast(Array(j - s, i - s, false)); \ double pji = static_cast(Array(j, i, false)); \ double tij = static_cast(Array(i - s, j - s, false)); + + // Nothing for else (for now) #define CSS_CASE_ELSE() @@ -10760,9 +10799,10 @@ inline void counter_degree( #define CSS_APPEND(name) std::string name_ = (name);\ for (size_t i = 0u; i < end_.size(); ++i) { \ - std::string tmpname = name_ + " (" + std::to_string(i) + ")";\ + std::string tmpname = name_ + " (" + std::to_string(i) + ")" + \ + ((counter_type == 1u) ? " (only perceiver)" : ((counter_type == 2u)? " (only alters)": ""));\ counters->add_counter(tmp_count, tmp_init, nullptr, \ - NetCounterData({netsize, i == 0u ? netsize : end_[i-1], end_[i]}, {}),\ + NetCounterData({netsize, i == 0u ? netsize : end_[i-1], end_[i], counter_type, i}, {}),\ tmpname);} #define CSS_NET_COUNTER_LAMBDA_INIT() NETWORK_COUNTER_LAMBDA(tmp_init) {\ @@ -10771,9 +10811,13 @@ inline void counter_degree( }; -/** @brief Counts errors of commission +/** + * @brief Counts errors of commission * @param netsize Size of the reference (true) network * @param end_ Vector indicating one past the ending index of each network. (see details) + * @param counter_type Size_t indicating the type of counter to use. Possible + * values are: 0: Count all, 1: Only count if perceiver is involved, and + * 2: Only count if perceiver is not involved. * @details * The `end_` parameter should be of length `N of networks` - 1. It is * assumed that the first network ends at `netsize`. @@ -10782,7 +10826,8 @@ template inline void counter_css_partially_false_recip_commi( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -10829,7 +10874,8 @@ template inline void counter_css_partially_false_recip_omiss( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -10873,7 +10919,8 @@ template inline void counter_css_completely_false_recip_comiss( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -10913,7 +10960,8 @@ template inline void counter_css_completely_false_recip_omiss( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -10953,7 +11001,8 @@ template inline void counter_css_mixed_recip( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -10994,7 +11043,8 @@ template inline void counter_css_census01( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) @@ -11027,8 +11077,22 @@ inline void counter_css_census01( CSS_CHECK_SIZE_INIT() double n_dbl = static_cast(data.indices[0u]); + // Discount in case of the type of counter + size_t ctype = data.indices[3u]; + + if (ctype == 1u) /* Only perceiver */ + { + + return (n_dbl - 1.0); // * (Array.D().directed ? 2.0 : 1.0); + + } else if (ctype == 2u) /* All but the perceiver */ + { + // We remove the perceiver from the eq. + n_dbl -= 1.0; + } + // At the beginning is all zero - return n_dbl * (n_dbl - 1.0)/2.0; + return n_dbl * (n_dbl - 1.0); // / (Array.D().directed ? 1.0 : 2.0); }; @@ -11044,7 +11108,8 @@ template inline void counter_css_census02( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11083,7 +11148,8 @@ template inline void counter_css_census03( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11122,7 +11188,8 @@ template inline void counter_css_census04( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11161,7 +11228,8 @@ template inline void counter_css_census05( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11200,7 +11268,8 @@ template inline void counter_css_census06( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11239,7 +11308,8 @@ template inline void counter_css_census07( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11278,7 +11348,8 @@ template inline void counter_css_census08( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11317,7 +11388,8 @@ template inline void counter_css_census09( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11356,7 +11428,8 @@ template inline void counter_css_census10( NetCounters * counters, size_t netsize, - const std::vector< size_t > & end_ + const std::vector< size_t > & end_, + size_t counter_type = 0u ) { NETWORK_COUNTER_LAMBDA(tmp_count) { @@ -11391,6 +11464,7 @@ inline void counter_css_census10( } +#undef CSS_APPEND #undef CSS_CASE_TRUTH #undef CSS_TRUE_CELLS #undef CSS_CASE_PERCEIVED @@ -11399,6 +11473,8 @@ inline void counter_css_census10( #undef CSS_CHECK_SIZE_INIT #undef CSS_CHECK_SIZE #undef CSS_NET_COUNTER_LAMBDA_INIT +#undef CSS_MATCH_TYPE +#undef CSS_SIZE #endif /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/include/barry/counters/network-css.hpp b/include/barry/counters/network-css.hpp index 3013c6e2d..cddfac58f 100644 --- a/include/barry/counters/network-css.hpp +++ b/include/barry/counters/network-css.hpp @@ -364,7 +364,7 @@ inline void counter_css_census01( if (ctype == 1u) /* Only perceiver */ { - return (n_dbl - 1.0) * (Array.D().directed ? 2.0 : 1.0); + return (n_dbl - 1.0); // * (Array.D().directed ? 2.0 : 1.0); } else if (ctype == 2u) /* All but the perceiver */ { @@ -373,7 +373,7 @@ inline void counter_css_census01( } // At the beginning is all zero - return n_dbl * (n_dbl - 1.0)/ (Array.D().directed ? 1.0 : 2.0); + return n_dbl * (n_dbl - 1.0); // / (Array.D().directed ? 1.0 : 2.0); };