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;
40 nodes.
Add(it.GetId());
52 for (
int i = 0; i < NI.
GetInDeg(); i++) {
70 #pragma omp parallel for schedule(dynamic)
71 for (
int node_id = 0; node_id < nodes.
Len(); node_id++) {
72 int src = nodes[node_id];
79 #pragma omp parallel for schedule(dynamic)
80 for (
int i = 0; i < order.
Len(); i++) {
81 order[degrees[i].Dat] = i;
86 #pragma omp parallel for schedule(dynamic)
87 for (
int node_id = 0; node_id < nodes.
Len(); node_id++) {
88 int src = nodes[node_id];
89 int src_pos = order[src];
94 TIntV neighbors_higher;
95 for (
int i = 0; i < nbrs.
Len(); i++) {
97 if (order[nbr] > src_pos) { neighbors_higher.
Add(nbr); }
100 for (
int ind1 = 0; ind1 < neighbors_higher.
Len(); ind1++) {
101 for (
int ind2 = ind1 + 1; ind2 < neighbors_higher.
Len(); ind2++) {
102 int dst1 = neighbors_higher[ind1];
103 int dst2 = neighbors_higher[ind2];
127 counts(4, 0) = edge_counts(0, 0);
128 counts(4, 1) = edge_counts(0, 1);
129 counts(5, 0) = edge_counts(1, 0);
130 counts(5, 1) = edge_counts(1, 1);
132 Counter3D pre_counts, pos_counts, mid_counts;
134 counts(0, 0) = mid_counts(1, 1, 1);
135 counts(0, 1) = mid_counts(1, 1, 0);
136 counts(0, 4) = pos_counts(1, 1, 0);
137 counts(0, 5) = pos_counts(1, 1, 1);
138 counts(1, 0) = mid_counts(1, 0, 1);
139 counts(1, 1) = mid_counts(1, 0, 0);
140 counts(1, 4) = pos_counts(1, 0, 0);
141 counts(1, 5) = pos_counts(1, 0, 1);
142 counts(2, 0) = mid_counts(0, 1, 0);
143 counts(2, 1) = mid_counts(0, 1, 1);
144 counts(2, 2) = pos_counts(0, 1, 0);
145 counts(2, 3) = pos_counts(0, 1, 1);
146 counts(3, 0) = mid_counts(0, 0, 0);
147 counts(3, 1) = mid_counts(0, 0, 1);
148 counts(3, 2) = pos_counts(0, 0, 0);
149 counts(3, 3) = pos_counts(0, 0, 1);
150 counts(4, 2) = pre_counts(0, 1, 0);
151 counts(4, 3) = pre_counts(0, 1, 1);
152 counts(4, 4) = pre_counts(1, 0, 0);
153 counts(4, 5) = pre_counts(1, 0, 1);
154 counts(5, 2) = pre_counts(0, 0, 0);
155 counts(5, 3) = pre_counts(0, 0, 1);
156 counts(5, 4) = pre_counts(1, 1, 0);
157 counts(5, 5) = pre_counts(1, 1, 1);
161 counts(0, 2) = triad_counts(0, 0, 0);
162 counts(0, 3) = triad_counts(0, 0, 1);
163 counts(1, 2) = triad_counts(0, 1, 0);
164 counts(1, 3) = triad_counts(0, 1, 1);
165 counts(2, 4) = triad_counts(1, 0, 0);
166 counts(2, 5) = triad_counts(1, 0, 1);
167 counts(3, 4) = triad_counts(1, 1, 0);
168 counts(3, 5) = triad_counts(1, 1, 1);
177 int src = it.GetSrcNId();
178 int dst = it.GetDstNId();
180 if (src < dst || (dst < src && !static_graph_->IsEdge(dst, src))) {
185 #pragma omp parallel for schedule(dynamic)
186 for (
int i = 0; i < undir_edges.
Len(); i++) {
192 counts(0, 0) += local(0, 1, 0) + local(1, 0, 1);
193 counts(0, 1) += local(1, 0, 0) + local(0, 1, 1);
194 counts(1, 0) += local(0, 0, 0) + local(1, 1, 1);
195 counts(1, 1) += local(0, 0, 1) + local(1, 1, 0);
212 for (
int k = 0; k < combined.
Len(); k++) {
213 in_out[k] = combined[k].Dat;
214 timestamps[k] = combined[k].Key;
216 counter.
Count(in_out, timestamps, delta, counts);
225 for (
int i = 0; i < timestamps.
Len(); i++) {
240 #pragma omp parallel for schedule(dynamic)
241 for (
int c = 0; c < centers.
Len(); c++) {
243 int center = centers[c];
246 for (
int i = 0; i < nbrs.
Len(); i++) {
247 for (
int j = i + 1; j < nbrs.
Len(); j++) {
259 for (
int k = 0; k < combined.
Len(); k++) {
260 edge_id[k] = combined[k].Dat;
261 timestamps[k] = combined[k].Key;
264 counter.
Count(edge_id, timestamps, delta, local);
268 for (
int dir1 = 0; dir1 < 2; ++dir1) {
269 for (
int dir2 = 0; dir2 < 2; ++dir2) {
270 for (
int dir3 = 0; dir3 < 2; ++dir3) {
271 pre_counts(dir1, dir2, dir3) +=
272 local(dir1, dir2, dir3 + 2) + local(dir1 + 2, dir2 + 2, dir3);
273 pos_counts(dir1, dir2, dir3) +=
274 local(dir1, dir2 + 2, dir3 + 2) + local(dir1 + 2, dir2, dir3);
275 mid_counts(dir1, dir2, dir3) +=
276 local(dir1, dir2 + 2, dir3) + local(dir1 + 2, dir2, dir3 + 2);
288 int& index,
int u,
int v,
int nbr,
int key) {
291 for (
int j = 0; j < ts_vec.
Len(); ++j) {
308 #pragma omp parallel for schedule(dynamic)
309 for (
int c = 0; c < centers.
Len(); c++) {
311 int center = centers[c];
319 for (
int i = 0; i < nbrs.
Len(); i++) {
328 for (
int j = 0; j < ts_indices.
Len(); j++) {
329 timestamps.
Add(ts_indices[j].Key);
330 ordered_events.
Add(events[ts_indices[j].Dat]);
335 tesc.
Count(ordered_events, timestamps, delta);
338 for (
int dir1 = 0; dir1 < 2; ++dir1) {
339 for (
int dir2 = 0; dir2 < 2; ++dir2) {
340 for (
int dir3 = 0; dir3 < 2; ++dir3) {
341 pre_counts(dir1, dir2, dir3) += tesc.
PreCount(dir1, dir2, dir3);
342 pos_counts(dir1, dir2, dir3) += tesc.
PosCount(dir1, dir2, dir3);
343 mid_counts(dir1, dir2, dir3) += tesc.
MidCount(dir1, dir2, dir3);
350 for (
int nbr_id = 0; nbr_id < nbrs.
Len(); nbr_id++) {
351 int nbr = nbrs[nbr_id];
356 for (
int dir1 = 0; dir1 < 2; ++dir1) {
357 for (
int dir2 = 0; dir2 < 2; ++dir2) {
358 for (
int dir3 = 0; dir3 < 2; ++dir3) {
359 pre_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
360 pos_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
361 mid_counts(dir1, dir2, dir3) -= edge_counts(dir1, dir2, dir3);
376 #pragma omp parallel for schedule(dynamic)
377 for (
int i = 0; i < Us.
Len(); i++) {
382 int uv = 0, vu = 1, uw = 2, wu = 3, vw = 4, wv = 5;
395 for (
int k = 0; k < combined.
Len(); k++) {
396 edge_id[k] = combined[k].Dat;
397 timestamps[k] = combined[k].Key;
400 counter.
Count(edge_id, timestamps, delta, local);
406 counts(0, 0, 0) += local(uv, wv, uw) + local(vu, wu, vw) + local(uw, vw, uv)
407 + local(wu, vu, wv) + local(vw, uw, vu) + local(wv, uv, wu);
409 counts(0, 0, 1) += local(uv, wv, wu) + local(vu, wu, wv) + local(uw, vw, vu)
410 + local(wu, vu, vw) + local(vw, uw, uv) + local(wv, uv, uw);
412 counts(0, 1, 0) += local(uv, vw, uw) + local(vu, uw, vw) + local(uw, wv, uv)
413 + local(wu, uv, wv) + local(vw, wu, vu) + local(wv, vu, wu);
415 counts(0, 1, 1) += local(uv, vw, wu) + local(vu, uw, wv) + local(uw, wv, vu)
416 + local(wu, uv, vw) + local(vw, wu, uv) + local(wv, vu, uw);
418 counts(1, 0, 0) += local(uv, wu, vw) + local(vu, wv, uw) + local(uw, vu, wv)
419 + local(wu, vw, uv) + local(vw, uv, wu) + local(wv, uw, vu);
421 counts(1, 0, 1) += local(uv, wu, wv) + local(vu, wv, wu) + local(uw, vu, vw)
422 + local(wu, vw, vu) + local(vw, uv, uw) + local(wv, uw, uv);
424 counts(1, 1, 0) += local(uv, uw, vw) + local(vu, vw, uw) + local(uw, uv, wv)
425 + local(wu, wv, uv) + local(vw, vu, wu) + local(wv, wu, vu);
427 counts(1, 1, 1) += local(uv, uw, wv) + local(vu, vw, wu) + local(uw, uv, vw)
428 + local(wu, wv, vu) + local(vw, vu, uw) + local(wv, wu, uv);
435 int& index,
int u,
int v,
int nbr,
436 int key1,
int key2) {
439 for (
int i = 0; i < timestamps.
Len(); i++) {
455 int src = it.GetSrcNId();
456 int dst = it.GetDstNId();
457 int min_node =
MIN(src, dst);
458 int max_node =
MAX(src, dst);
460 assignments[min_node](max_node) =
TIntV();
466 #pragma omp parallel for schedule(dynamic)
467 for (
int i = 0; i < Us.
Len(); i++) {
471 int counts_uv = edge_counts[
MIN(u, v)].
GetDat(
MAX(u, v));
472 int counts_uw = edge_counts[
MIN(u, w)].GetDat(
MAX(u, w));
473 int counts_vw = edge_counts[
MIN(v, w)].GetDat(
MAX(v, w));
474 if (counts_uv >=
MAX(counts_uw, counts_vw)) {
480 }
else if (counts_uw >=
MAX(counts_uv, counts_vw)) {
486 }
else if (counts_vw >=
MAX(counts_uv, counts_uw)) {
498 for (
int node_id = 0; node_id < all_nodes.
Len(); node_id++) {
499 int u = all_nodes[node_id];
502 for (
int nbr_id = 0; nbr_id < nbrs.
Len(); nbr_id++) {
503 int v = nbrs[nbr_id];
504 if (assignments[u].IsKey(v) && assignments[u].GetDat(v).Len() > 0) {
511 #pragma omp parallel for schedule(dynamic)
512 for (
int edge_id = 0; edge_id < all_edges.
Len(); edge_id++) {
517 if (!assignments[u].IsKey(v)) {
continue; }
520 if (uv_assignment.
Len() == 0) {
continue; }
532 for (
int w_id = 0; w_id < uv_assignment.
Len(); w_id++) {
533 int w = uv_assignment[w_id];
544 for (
int i = 0; i < ts_indices.
Len(); i++) {
545 timestamps[i] = ts_indices[i].Key;
546 sorted_events[i] = events[ts_indices[i].Dat];
551 tetc.
Count(sorted_events, timestamps, delta);
554 for (
int dir1 = 0; dir1 < 2; dir1++) {
555 for (
int dir2 = 0; dir2 < 2; dir2++) {
556 for (
int dir3 = 0; dir3 < 2; dir3++) {
557 counts(dir1, dir2, dir3) += tetc.
Counts(dir1, dir2, dir3);
573 if (event_string.
Len() != timestamps.
Len()) {
574 TExcept::Throw(
"Number of events must equal number of timestamps");
577 for (
int end = 0; end < event_string.
Len(); end++) {
578 while (
double(timestamps[start]) + delta < double(timestamps[end])) {
588 for (
int i = 0; i <
size_; i++) {
589 for (
int j = 0; j <
size_; j++) {
604 template <
typename EdgeData>
606 const TIntV& timestamps,
double delta) {
607 InitializeCounters();
608 if (events.
Len() != timestamps.
Len()) {
609 TExcept::Throw(
"Number of events must match number of timestamps.");
613 int L = timestamps.
Len();
614 for (
int j = 0; j < L; j++) {
615 double tj = double(timestamps[j]);
617 while (start < L &&
double(timestamps[start]) < tj - delta) {
618 PopPre(events[start]);
622 while (end < L &&
double(timestamps[end]) <= tj + delta) {
623 PushPos(events[end]);
628 ProcessCurrent(events[j]);
680 for (
int i = 0; i < 2; i++) {
681 for (
int j = 0; j < 2; j++) {
705 int u_or_v =
event.u_or_v;
708 for (
int i = 0; i < 2; i++) {
717 int u_or_v =
event.u_or_v;
720 for (
int i = 0; i < 2; i++) {
729 int u_or_v =
event.u_or_v;
731 for (
int i = 0; i < 2; i++) {
741 int u_or_v =
event.u_or_v;
743 for (
int i = 0; i < 2; i++) {
753 int u_or_v =
event.u_or_v;
756 for (
int i = 0; i < 2; i++) {
765 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.