22 TInt src_idx = data_ptr->GetColIdx(
"source");
23 TInt dst_idx = data_ptr->GetColIdx(
"destination");
24 TInt tim_idx = data_ptr->GetColIdx(
"time");
25 for (
TRowIterator RI = data_ptr->BegRI(); RI < data_ptr->EndRI(); RI++) {
26 TInt row_idx = RI.GetRowIdx();
27 int src = data_ptr->GetIntValAtRowIdx(src_idx, row_idx).Val;
28 int dst = data_ptr->GetIntValAtRowIdx(dst_idx, row_idx).Val;
29 int tim = data_ptr->GetIntValAtRowIdx(tim_idx, row_idx).Val;
38 nodes.
Add(it.GetId());
50 for (
int i = 0; i < NI.
GetInDeg(); i++) {
68 #pragma omp parallel for schedule(dynamic)
69 for (
int node_id = 0; node_id < nodes.
Len(); node_id++) {
70 int src = nodes[node_id];
77 #pragma omp parallel for schedule(dynamic)
78 for (
int i = 0; i < order.
Len(); i++) {
79 order[degrees[i].Dat] = i;
84 #pragma omp parallel for schedule(dynamic)
85 for (
int node_id = 0; node_id < nodes.
Len(); node_id++) {
86 int src = nodes[node_id];
87 int src_pos = order[src];
92 TIntV neighbors_higher;
93 for (
int i = 0; i < nbrs.
Len(); i++) {
95 if (order[nbr] > src_pos) { neighbors_higher.
Add(nbr); }
98 for (
int ind1 = 0; ind1 < neighbors_higher.
Len(); ind1++) {
99 for (
int ind2 = ind1 + 1; ind2 < neighbors_higher.
Len(); ind2++) {
100 int dst1 = neighbors_higher[ind1];
101 int dst2 = neighbors_higher[ind2];
125 counts(4, 0) = edge_counts(0, 0);
126 counts(4, 1) = edge_counts(0, 1);
127 counts(5, 0) = edge_counts(1, 0);
128 counts(5, 1) = edge_counts(1, 1);
130 Counter3D pre_counts, pos_counts, mid_counts;
132 counts(0, 0) = mid_counts(1, 1, 1);
133 counts(0, 1) = mid_counts(1, 1, 0);
134 counts(0, 4) = pos_counts(1, 1, 0);
135 counts(0, 5) = pos_counts(1, 1, 1);
136 counts(1, 0) = mid_counts(1, 0, 1);
137 counts(1, 1) = mid_counts(1, 0, 0);
138 counts(1, 4) = pos_counts(1, 0, 0);
139 counts(1, 5) = pos_counts(1, 0, 1);
140 counts(2, 0) = mid_counts(0, 0, 1);
141 counts(2, 1) = mid_counts(0, 1, 1);
142 counts(2, 2) = pos_counts(0, 1, 0);
143 counts(2, 3) = pos_counts(0, 1, 1);
144 counts(3, 0) = mid_counts(0, 0, 0);
145 counts(3, 1) = mid_counts(0, 0, 1);
146 counts(3, 2) = pos_counts(0, 0, 0);
147 counts(3, 3) = pos_counts(0, 0, 1);
148 counts(4, 2) = pre_counts(0, 1, 0);
149 counts(4, 3) = pre_counts(0, 1, 1);
150 counts(4, 4) = pre_counts(1, 0, 0);
151 counts(4, 5) = pre_counts(1, 0, 1);
152 counts(5, 2) = pre_counts(0, 0, 0);
153 counts(5, 3) = pre_counts(0, 0, 1);
154 counts(5, 4) = pre_counts(1, 1, 0);
155 counts(5, 5) = pre_counts(1, 1, 1);
159 counts(0, 2) = triad_counts(0, 0, 0);
160 counts(0, 3) = triad_counts(0, 0, 1);
161 counts(1, 2) = triad_counts(0, 1, 0);
162 counts(1, 3) = triad_counts(0, 1, 1);
163 counts(2, 4) = triad_counts(1, 0, 0);
164 counts(2, 5) = triad_counts(1, 0, 1);
165 counts(3, 4) = triad_counts(1, 1, 0);
166 counts(3, 5) = triad_counts(1, 1, 1);
175 int src = it.GetSrcNId();
176 int dst = it.GetDstNId();
178 if (src < dst || (dst < src && !static_graph_->IsEdge(dst, src))) {
183 #pragma omp parallel for schedule(dynamic)
184 for (
int i = 0; i < undir_edges.
Len(); i++) {
190 counts(0, 0) += local(0, 1, 0) + local(1, 0, 1);
191 counts(0, 1) += local(1, 0, 0) + local(0, 1, 1);
192 counts(1, 0) += local(0, 0, 0) + local(1, 1, 1);
193 counts(1, 1) += local(0, 0, 1) + local(1, 1, 0);
210 for (
int k = 0; k < combined.
Len(); k++) {
211 in_out[k] = combined[k].Dat;
212 timestamps[k] = combined[k].Key;
214 counter.
Count(in_out, timestamps, delta, counts);
223 for (
int i = 0; i < timestamps.
Len(); i++) {
238 #pragma omp parallel for schedule(dynamic)
239 for (
int c = 0; c < centers.
Len(); c++) {
241 int center = centers[c];
244 for (
int i = 0; i < nbrs.
Len(); i++) {
245 for (
int j = i + 1; j < nbrs.
Len(); j++) {
257 for (
int k = 0; k < combined.
Len(); k++) {
258 edge_id[k] = combined[k].Dat;
259 timestamps[k] = combined[k].Key;
262 counter.
Count(edge_id, timestamps, delta, local);
266 for (
int dir1 = 0; dir1 < 2; ++dir1) {
267 for (
int dir2 = 0; dir2 < 2; ++dir2) {
268 for (
int dir3 = 0; dir3 < 2; ++dir3) {
269 pre_counts(dir1, dir2, dir3) +=
270 local(dir1, dir2, dir3 + 2) + local(dir1 + 2, dir2 + 2, dir3);
271 pos_counts(dir1, dir2, dir3) +=
272 local(dir1, dir2 + 2, dir3 + 2) + local(dir1 + 2, dir2, dir3);
273 mid_counts(dir1, dir2, dir3) +=
274 local(dir1, dir2 + 2, dir3) + local(dir1 + 2, dir2, dir3 + 2);
286 int& index,
int u,
int v,
int nbr,
int key) {
289 for (
int j = 0; j < ts_vec.
Len(); ++j) {
306 #pragma omp parallel for schedule(dynamic)
307 for (
int c = 0; c < centers.
Len(); c++) {
309 int center = centers[c];
317 for (
int i = 0; i < nbrs.
Len(); i++) {
326 for (
int j = 0; j < ts_indices.
Len(); j++) {
327 timestamps.
Add(ts_indices[j].Key);
328 ordered_events.
Add(events[ts_indices[j].Dat]);
333 tesc.
Count(ordered_events, timestamps, delta);
336 for (
int dir1 = 0; dir1 < 2; ++dir1) {
337 for (
int dir2 = 0; dir2 < 2; ++dir2) {
338 for (
int dir3 = 0; dir3 < 2; ++dir3) {
339 pre_counts(dir1, dir2, dir3) += tesc.
PreCount(dir1, dir2, dir3);
340 pos_counts(dir1, dir2, dir3) += tesc.
PosCount(dir1, dir2, dir3);
341 mid_counts(dir1, dir2, dir3) += tesc.
MidCount(dir1, dir2, dir3);
348 for (
int nbr_id = 0; nbr_id < nbrs.
Len(); nbr_id++) {
349 int nbr = nbrs[nbr_id];
354 for (
int dir1 = 0; dir1 < 2; ++dir1) {
355 for (
int dir2 = 0; dir2 < 2; ++dir2) {
356 for (
int dir3 = 0; dir3 < 2; ++dir3) {
357 pre_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
358 pos_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
359 mid_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
374 #pragma omp parallel for schedule(dynamic)
375 for (
int i = 0; i < Us.
Len(); i++) {
380 int uv = 0, vu = 1, uw = 2, wu = 3, vw = 4, wv = 5;
393 for (
int k = 0; k < combined.
Len(); k++) {
394 edge_id[k] = combined[k].Dat;
395 timestamps[k] = combined[k].Key;
398 counter.
Count(edge_id, timestamps, delta, local);
404 counts(0, 0, 0) += local(uv, wv, uw) + local(vu, wu, vw) + local(uw, vw, uv)
405 + local(wu, vu, wv) + local(vw, uw, vu) + local(wv, uv, wu);
407 counts(0, 0, 1) += local(uv, wv, wu) + local(vu, wu, wv) + local(uw, vw, vu)
408 + local(wu, vu, vw) + local(vw, uw, uv) + local(wv, uv, uw);
410 counts(0, 1, 0) += local(uv, vw, uw) + local(vu, uw, vw) + local(uw, wv, uv)
411 + local(wu, uv, wv) + local(vw, wu, vu) + local(wv, vu, wu);
413 counts(0, 1, 1) += local(uv, vw, wu) + local(vu, uw, wv) + local(uw, wv, vu)
414 + local(wu, uv, vw) + local(vw, wu, uv) + local(wv, vu, uw);
416 counts(1, 0, 0) += local(uv, wu, vw) + local(vu, wv, uw) + local(uw, vu, wv)
417 + local(wu, vw, uv) + local(vw, uv, wu) + local(wv, uw, vu);
419 counts(1, 0, 1) += local(uv, wu, wv) + local(vu, wv, wu) + local(uw, vu, vw)
420 + local(wu, vw, vu) + local(vw, uv, uw) + local(wv, uw, uv);
422 counts(1, 1, 0) += local(uv, uw, vw) + local(vu, vw, uw) + local(uw, uv, wv)
423 + local(wu, wv, uv) + local(vw, vu, wu) + local(wv, wu, vu);
425 counts(1, 1, 1) += local(uv, uw, wv) + local(vu, vw, wu) + local(uw, uv, vw)
426 + local(wu, wv, vu) + local(vw, vu, uw) + local(wv, wu, uv);
433 int& index,
int u,
int v,
int nbr,
434 int key1,
int key2) {
437 for (
int i = 0; i < timestamps.
Len(); i++) {
453 int src = it.GetSrcNId();
454 int dst = it.GetDstNId();
455 int min_node =
MIN(src, dst);
456 int max_node =
MAX(src, dst);
458 assignments[min_node](max_node) =
TIntV();
464 #pragma omp parallel for schedule(dynamic)
465 for (
int i = 0; i < Us.
Len(); i++) {
469 int counts_uv = edge_counts[
MIN(u, v)].
GetDat(
MAX(u, v));
470 int counts_uw = edge_counts[
MIN(u, w)].GetDat(
MAX(u, w));
471 int counts_vw = edge_counts[
MIN(v, w)].GetDat(
MAX(v, w));
472 if (counts_uv >=
MAX(counts_uw, counts_vw)) {
478 }
else if (counts_uw >=
MAX(counts_uv, counts_vw)) {
484 }
else if (counts_vw >=
MAX(counts_uv, counts_uw)) {
496 for (
int node_id = 0; node_id < all_nodes.
Len(); node_id++) {
497 int u = all_nodes[node_id];
500 for (
int nbr_id = 0; nbr_id < nbrs.
Len(); nbr_id++) {
501 int v = nbrs[nbr_id];
502 if (assignments[u].IsKey(v) && assignments[u].GetDat(v).Len() > 0) {
509 #pragma omp parallel for schedule(dynamic)
510 for (
int edge_id = 0; edge_id < all_edges.
Len(); edge_id++) {
515 if (!assignments[u].IsKey(v)) {
continue; }
518 if (uv_assignment.
Len() == 0) {
continue; }
530 for (
int w_id = 0; w_id < uv_assignment.
Len(); w_id++) {
531 int w = uv_assignment[w_id];
542 for (
int i = 0; i < ts_indices.
Len(); i++) {
543 timestamps[i] = ts_indices[i].Key;
544 sorted_events[i] = events[ts_indices[i].Dat];
549 tetc.
Count(sorted_events, timestamps, delta);
552 for (
int dir1 = 0; dir1 < 2; dir1++) {
553 for (
int dir2 = 0; dir2 < 2; dir2++) {
554 for (
int dir3 = 0; dir3 < 2; dir3++) {
555 counts(dir1, dir2, dir3) += tetc.
Counts(dir1, dir2, dir3);
571 if (event_string.
Len() != timestamps.
Len()) {
572 TExcept::Throw(
"Number of events must equal number of timestamps");
575 for (
int end = 0; end < event_string.
Len(); end++) {
576 while (
double(timestamps[start]) + delta < double(timestamps[end])) {
586 for (
int i = 0; i <
size_; i++) {
587 for (
int j = 0; j <
size_; j++) {
602 template <
typename EdgeData>
604 const TIntV& timestamps,
double delta) {
605 InitializeCounters();
606 if (events.
Len() != timestamps.
Len()) {
607 TExcept::Throw(
"Number of events must match number of timestamps.");
611 int L = timestamps.
Len();
612 for (
int j = 0; j < L; j++) {
613 double tj = double(timestamps[j]);
615 while (start < L &&
double(timestamps[start]) < tj - delta) {
616 PopPre(events[start]);
620 while (end < L &&
double(timestamps[end]) <= tj + delta) {
621 PushPos(events[end]);
626 ProcessCurrent(events[j]);
678 for (
int i = 0; i < 2; i++) {
679 for (
int j = 0; j < 2; j++) {
703 int u_or_v =
event.u_or_v;
706 for (
int i = 0; i < 2; i++) {
715 int u_or_v =
event.u_or_v;
718 for (
int i = 0; i < 2; i++) {
727 int u_or_v =
event.u_or_v;
729 for (
int i = 0; i < 2; i++) {
739 int u_or_v =
event.u_or_v;
741 for (
int i = 0; i < 2; i++) {
751 int u_or_v =
event.u_or_v;
754 for (
int i = 0; i < 2; i++) {
763 if (((nbr ==
node_u_) && dir == 0) || ((nbr ==
node_v_) && dir == 1)) {
bool HasEdges(int u, int v)
void Count(const TVec< EdgeData > &events, const TIntV ×tamps, double delta)
void GetAllNodes(TIntV &nodes)
TempMotifCounter(const TStr &filename)
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
int PreCount(int dir1, int dir2, int dir3)
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
TKeyDat< TInt, TInt > TIntPair
void Count(const TIntV &event_string, const TIntV ×tamps, double delta, Counter3D &counts)
TSizeTy Len() const
Returns the number of elements in the vector.
void Count3TEdgeTriadsNaive(double delta, Counter3D &counts)
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
void ProcessCurrent(const StarEdgeData &event)
void Count3TEdge23Node(double delta, Counter2D &counts)
void PopPre(const StarEdgeData &event)
void PopPre(const TriadEdgeData &event)
void PopPos(const StarEdgeData &event)
int PosCount(int dir1, int dir2, int dir3)
void PopPos(const TriadEdgeData &event)
void GetAllStaticTriangles(TIntV &Us, TIntV &Vs, TIntV &Ws)
Iterator class for TTable rows.
void InitializeCounters()
void AddStarEdgeData(TVec< TIntPair > &ts_indices, TVec< StarEdgeData > &events, int &index, int u, int v, int nbr, int key)
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
void ProcessCurrent(const TriadEdgeData &event)
Edge iterator. Only forward iteration (operator++) is supported.
static void Throw(const TStr &MsgStr)
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the graph.
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
void IncrementCounts(int event)
void Count3TEdge3NodeStars(double delta, Counter3D &pre_counts, Counter3D &pos_counts, Counter3D &mid_counts)
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
void InitializeCounters()
void GetAllNeighbors(int node, TIntV &nbrs)
int Counts(int dir1, int dir2, int dir3)
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
void PushPos(const StarEdgeData &event)
void AddTriadEdgeData(TVec< TriadEdgeData > &events, TVec< TIntPair > &ts_indices, int &index, int u, int v, int nbr, int key1, int key2)
void DecrementCounts(int event)
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
static PTable LoadSS(const Schema &S, const TStr &InFNm, TTableContext *Context, const char &Separator= '\t', TBool HasTitleLine=false)
Loads table from spread sheet (TSV, CSV, etc). Note: HasTitleLine = true is not supported. Please comment title lines instead.
int GetOutDeg() const
Returns out-degree of the current node.
void Count3TEdge2Node(double delta, Counter2D &counts)
Node iterator. Only forward iteration (operator++) is supported.
void PushPre(const StarEdgeData &event)
void Count3TEdgeTriads(double delta, Counter3D &counts)
void PushPre(const TriadEdgeData &event)
void AddStarEdges(TVec< TIntPair > &combined, int u, int v, int key)
int GetInDeg() const
Returns in-degree of the current node.
int MidCount(int dir1, int dir2, int dir3)
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TVec< THash< TInt, TIntV > > temporal_data_
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
void PushPos(const TriadEdgeData &event)
void Count3TEdge3NodeStarsNaive(double delta, Counter3D &pre_counts, Counter3D &pos_counts, Counter3D &mid_counts)
Vector is a sequence TVal objects representing an array that can change in size.