Skip to content

Commit

Permalink
CSS counters can be split
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 18, 2023
1 parent 061e0e7 commit fab9734
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 24 deletions.
120 changes: 98 additions & 22 deletions barry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(Array(j, i, false)); \
double pij = static_cast<double>(Array(i + s, j + s, false)); \
double pji = static_cast<double>(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<double>(Array(j - s, i - s, false)); \
double pji = static_cast<double>(Array(j, i, false)); \
double tij = static_cast<double>(Array(i - s, j - s, false));



// Nothing for else (for now)
#define CSS_CASE_ELSE()

Expand All @@ -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) {\
Expand All @@ -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`.
Expand All @@ -10782,7 +10826,8 @@ template<typename Tnet = Network>
inline void counter_css_partially_false_recip_commi(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -10829,7 +10874,8 @@ template<typename Tnet = Network>
inline void counter_css_partially_false_recip_omiss(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -10873,7 +10919,8 @@ template<typename Tnet = Network>
inline void counter_css_completely_false_recip_comiss(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -10913,7 +10960,8 @@ template<typename Tnet = Network>
inline void counter_css_completely_false_recip_omiss(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -10953,7 +11001,8 @@ template<typename Tnet = Network>
inline void counter_css_mixed_recip(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -10994,7 +11043,8 @@ template<typename Tnet = Network>
inline void counter_css_census01(
NetCounters<Tnet> * 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)
Expand Down Expand Up @@ -11027,8 +11077,22 @@ inline void counter_css_census01(
CSS_CHECK_SIZE_INIT()
double n_dbl = static_cast<double>(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);

};

Expand All @@ -11044,7 +11108,8 @@ template<typename Tnet = Network>
inline void counter_css_census02(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11083,7 +11148,8 @@ template<typename Tnet = Network>
inline void counter_css_census03(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11122,7 +11188,8 @@ template<typename Tnet = Network>
inline void counter_css_census04(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11161,7 +11228,8 @@ template<typename Tnet = Network>
inline void counter_css_census05(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11200,7 +11268,8 @@ template<typename Tnet = Network>
inline void counter_css_census06(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11239,7 +11308,8 @@ template<typename Tnet = Network>
inline void counter_css_census07(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11278,7 +11348,8 @@ template<typename Tnet = Network>
inline void counter_css_census08(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11317,7 +11388,8 @@ template<typename Tnet = Network>
inline void counter_css_census09(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11356,7 +11428,8 @@ template<typename Tnet = Network>
inline void counter_css_census10(
NetCounters<Tnet> * 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) {
Expand Down Expand Up @@ -11391,6 +11464,7 @@ inline void counter_css_census10(

}

#undef CSS_APPEND
#undef CSS_CASE_TRUTH
#undef CSS_TRUE_CELLS
#undef CSS_CASE_PERCEIVED
Expand All @@ -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
/*//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions include/barry/counters/network-css.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
{
Expand All @@ -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);

};

Expand Down

0 comments on commit fab9734

Please sign in to comment.