23 if (motif_lc ==
"m1") {
return M1; }
24 else if (motif_lc ==
"m2") {
return M2; }
25 else if (motif_lc ==
"m3") {
return M3; }
26 else if (motif_lc ==
"m4") {
return M4; }
27 else if (motif_lc ==
"m5") {
return M5; }
28 else if (motif_lc ==
"m6") {
return M6; }
29 else if (motif_lc ==
"m7") {
return M7; }
30 else if (motif_lc ==
"triad") {
return triad; }
31 else if (motif_lc ==
"cycle") {
return cycle; }
32 else if (motif_lc ==
"ffloop") {
return FFLoop; }
33 else if (motif_lc ==
"unide") {
return UniDE; }
34 else if (motif_lc ==
"bide") {
return BiDE; }
35 else if (motif_lc ==
"de") {
return DE; }
36 else if (motif_lc ==
"edge") {
return DE_any; }
41 if (motif_lc ==
"uedge") {
return UEdge; }
42 else if (motif_lc ==
"clique3") {
return clique3; }
43 else if (motif_lc ==
"clique4") {
return clique4; }
44 else if (motif_lc ==
"clique5") {
return clique5; }
45 else if (motif_lc ==
"clique6") {
return clique6; }
46 else if (motif_lc ==
"clique7") {
return clique7; }
47 else if (motif_lc ==
"clique8") {
return clique8; }
48 else if (motif_lc ==
"clique9") {
return clique9; }
58 case M1: printf(
"M1\n");
break;
59 case M2: printf(
"M2\n");
break;
60 case M3: printf(
"M3\n");
break;
61 case M4: printf(
"M4\n");
break;
62 case M5: printf(
"M5\n");
break;
63 case M6: printf(
"M6\n");
break;
64 case M7: printf(
"M7\n");
break;
65 case triad: printf(
"triad\n");
break;
66 case cycle: printf(
"cycle\n");
break;
67 case FFLoop: printf(
"FFLoop\n");
break;
68 case UniDE: printf(
"UniDE\n");
break;
69 case BiDE: printf(
"BiDE\n");
break;
70 case DE: printf(
"DE\n");
break;
71 case DE_any: printf(
"DE_any\n");
break;
73 case UEdge: printf(
"UEdge\n");
break;
74 case clique3: printf(
"clique3\n");
break;
75 case clique4: printf(
"clique4\n");
break;
76 case clique5: printf(
"clique5\n");
break;
77 case clique6: printf(
"clique6\n");
break;
78 case clique7: printf(
"clique7\n");
break;
79 case clique8: printf(
"clique8\n");
break;
80 case clique9: printf(
"clique9\n");
break;
148 if (level >= KSize - 1) {
153 int SrcNId = EI.GetSrcNId();
154 int DstNId = EI.GetDstNId();
155 Counts[SrcNId](DstNId)[level-1] ++;
156 Counts[DstNId](SrcNId)[level-1] ++;
160 int NodeId = NI.GetId();
161 int degHere = NI.GetOutDeg();
162 for (
int i = 0; i < level; i ++) {
163 Counts[PrevNodes[i]](NodeId)[level-1] += degHere;
164 Counts[NodeId](PrevNodes[i])[level-1] += degHere;
167 if (level == KSize - 2) {
171 PrevNodes[level] = NodeId;
173 for (
int e = 0; e < NI.GetOutDeg(); e++) {
174 int nbrID = NI.GetOutNId(e);
176 neighborsID.
Add(nbrID);
180 int numEdges = subGraph->
GetEdges();
181 for (
int i = 0; i <= level; i ++) {
182 for (
int j = i + 1; j <= level; j ++) {
183 Counts[PrevNodes[i]](PrevNodes[j])[level] += numEdges;
184 Counts[PrevNodes[j]](PrevNodes[i])[level] += numEdges;
187 countClique(subGraph, KSize, PrevNodes, level + 1);
202 int NodeId = NI.GetId();
203 for (
int e = 0; e < NI.GetOutDeg(); e++) {
204 Weights[NodeId](NI.GetOutNId(e)) = 1;
206 Weights[NodeId](NodeId) = NI.GetOutDeg();
214 int NodeId = NI.GetId();
215 for (
int e = 0; e < NI.GetOutDeg(); e++) {
216 Counts[NodeId](NI.GetOutNId(e)) =
TIntV(KSize - 2);
219 TIntV PrevNodes(KSize - 2);
226 int NodeId = NI.GetId();
228 for (
int e = 0; e < NI.GetOutDeg(); e++) {
229 int NbrId = NI.GetOutNId(e);
230 int MtfCntHere =
Counts[NodeId](NbrId)[KSize-3];
232 Weights[NodeId](NbrId) = MtfCntHere;
235 Graph_trans->DelEdge(NodeId, NbrId);
238 Weights[NodeId](NodeId) = deg_w;
248 Graph_org = TSnap::ConvertGraph<PUNGraph>(graph);
260 if (G->
IsEdge(nodeID, nbrID)) {
261 if (G->
IsEdge(nbrID, nodeID)) {
275 if (G->
IsEdge(dstNId, srcNId)) {
399 int numBasicDirMtf = 9;
402 int NodeId = NI.GetId();
403 for (
int e = 0; e < NI.GetOutDeg(); e++) {
404 Counts[NodeId](NI.GetOutNId(e)) =
TIntV(numBasicDirMtf);
408 long nodeID = NI.GetId();
410 for (
long e = 0; e < NI.GetOutDeg(); e++) {
411 long nbrID = NI.GetOutNId(e);
413 neighborsID.
Add(nbrID);
414 Counts[nodeID](nbrID)[0] ++;
415 Counts[nbrID](nodeID)[0] ++;
418 for (
long e = 0; e < NI.GetInDeg(); e++) {
419 long nbrID = NI.GetInNId(e);
421 if (graph->
IsEdge(nodeID, nbrID)) {
422 Counts[nodeID](nbrID)[0] --;
423 Counts[nbrID](nodeID)[0] --;
424 Counts[nodeID](nbrID)[1] ++;
425 Counts[nbrID](nodeID)[1] ++;
427 neighborsID.
Add(nbrID);
428 Counts[nodeID](nbrID)[0] ++;
429 Counts[nbrID](nodeID)[0] ++;
435 long srcNId = EI.GetSrcNId();
436 long dstNId = EI.GetDstNId();
438 if (srcNId > dstNId || !subGraph->
IsEdge(dstNId, srcNId)) {
441 Counts[nodeID](srcNId)[MotifNumber] ++;
442 Counts[srcNId](nodeID)[MotifNumber] ++;
443 Counts[nodeID](dstNId)[MotifNumber] ++;
444 Counts[dstNId](nodeID)[MotifNumber] ++;
445 Counts[srcNId](dstNId)[MotifNumber] ++;
446 Counts[dstNId](srcNId)[MotifNumber] ++;
460 case UniDE : {MtfInclude.
Add(0);
break;}
461 case BiDE : MtfInclude.
Add(1);
break;
462 case DE : MtfInclude.
Add(0); MtfInclude.
Add(1); MtfInclude.
Add(1);
break;
463 case DE_any : MtfInclude.
Add(0); MtfInclude.
Add(1);
break;
465 case M1 : MtfInclude.
Add(2);
break;
466 case M2 : MtfInclude.
Add(3);
break;
467 case M3 : MtfInclude.
Add(4);
break;
468 case M4 : MtfInclude.
Add(5);
break;
469 case M5 : MtfInclude.
Add(6);
break;
470 case M6 : MtfInclude.
Add(7);
break;
471 case M7 : MtfInclude.
Add(8);
break;
507 int NodeId = NI.GetId();
509 for (
int e = 0; e < NI.GetOutDeg(); e++) {
510 int NbrId = NI.GetOutNId(e);
513 for (
int i = 0; i < MtfInclude.
Len(); i ++) {
514 WeightHere += CountHere[MtfInclude[i]];
517 Weights[NodeId](NbrId) = WeightHere;
523 Weights[NodeId](NodeId) = deg_w;
533 int NodeId = NI.GetId();
534 for (
int e = 0; e < NI.GetOutDeg(); e++) {
535 int NbrId = NI.GetOutNId(e);
537 printf(
"(%d, %d): ", NodeId, NbrId);
538 for (
int i = 0; i < CountThisEdge.
Len(); i ++) {
539 int output = CountThisEdge[i];
540 printf(
"%d ", output);
549 int NodeId = NI.GetId();
550 for (
int e = 0; e < NI.GetOutDeg(); e++) {
551 int NbrId = NI.GetOutNId(e);
552 printf(
"(%d, %d): ", NodeId, NbrId);
553 if (
Weights[NodeId].IsKey(NbrId)) {
554 float weight =
Weights[NodeId](NbrId);
555 printf(
"%.2f ", weight);
557 printf(
"Not a key in Weights");
561 float d_w =
Weights[NodeId](NodeId);
562 printf(
"\td_w(%d) = %.2f.\n", NodeId, d_w);
564 printf(
"Total volume = %.2f. \n",
TotalVol);
594 if (Weights[SeedNodeId].GetDat(SeedNodeId) * eps >= 1) {
598 residual(SeedNodeId) = 1;
600 NodesWExcesRes.
Push(SeedNodeId);
602 while (!NodesWExcesRes.
Empty()) {
604 int NodeId = NodesWExcesRes.
Top();
605 NodesWExcesRes.
Pop();
607 float deg_w = Weights[NodeId].
GetDat(NodeId);
609 appr_vec(NodeId) += residual(NodeId);
611 residual(NodeId) = 0;
614 float pushVal = residual(NodeId) - deg_w * eps / 2;
615 appr_vec(NodeId) += pushVal * (1-alpha);
617 residual(NodeId) = deg_w * eps / 2;
619 pushVal *= alpha / deg_w;
621 for (
int i = 0; i < NI.
GetOutDeg(); i ++) {
623 float nbrValOld = residual(NbrId);
624 float nbrValNew = nbrValOld + pushVal * Weights[NodeId].
GetDat(NbrId);
625 residual(NbrId) = nbrValNew;
626 if (nbrValOld <= eps * Weights[NbrId].GetDat(NbrId) && nbrValNew > eps * Weights[NbrId].GetDat(NbrId)) {
627 NodesWExcesRes.
Push(NbrId);
641 int NodeId = it->Key;
642 Quotient(NodeId) = it->Dat / Weights[NodeId].
GetDat(NodeId);
646 double vol = 0, cut = 0;
652 int NodeId = it->Key;
658 vol += VolSmall * WeightsHere.
GetDat(NodeId);
659 if (VolSmall == 1 && vol >= TotalVol / 2) {
660 vol = TotalVol - vol;
663 cut += WeightsHere.
GetDat(NodeId);
664 for (
long j = 0; j < NI.
GetOutDeg(); j ++) {
666 if (IsIn.
IsKey(NbrId)) {
667 cut -= 2 * WeightsHere.
GetDat(NbrId);
700 double minCondVal = 2;
732 TExcept::Throw(
"No APPR vector has been computed! Please first do MAPPR::computeAPPR(...)!");
740 }
else if (option == -1) {
745 }
else if (option > 0) {
747 for (
int i = 0; i < option; i++) {
759 int NodeId = it->Key;
760 float VecVal = it->Dat;
761 printf(
"%d : %.7f\n", NodeId, VecVal);
763 printf(
"Number of pushes: %d\n",
NumPushs);
764 printf(
"L1-norm of APPR vector: %.7f\n",
appr_norm);
769 TExcept::Throw(
"No APPR vector has been computed! Please first do MAPPR::computeAPPR(...)!");
771 printf(
"Size\tNodeId\tConductance\n");
775 printf(
"%d\t%d\t%.7f\n", i+1, NodeId, Cond);
777 printf(
"\tGlobal minimun!!!\n");
780 printf(
"\tFirst local minimun!!!\n");
Edge iterator. Only forward iteration (operator++) is supported.
THash< TInt, TFlt > appr_vec
void computeAPPR(const ProcessedGraph &graph_p, const int SeedNodeId, float alpha, float eps)
void countClique(PUNGraph &G, int KSize, TIntV &PrevNodes, int level)
void assignWeights_undir(MotifType mt)
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
void computeProfile(const ProcessedGraph &graph_p)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
const WeightVH & getWeights() const
TVec< THash< TInt, TIntV > > CountVH
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int checkTriadMotif(PNGraph &G, long nodeID, long srcNId, long dstNId)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
MotifType ParseMotifType(const TStr &motif, const bool &IsDirected)
int GetEdges() const
Returns the number of edges in the graph.
TSizeTy Len() const
Returns the number of elements in the vector.
Node iterator. Only forward iteration (operator++) is supported.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
bool higherDeg(PUNGraph &G, TUNGraph::TNodeI &NI1, int nodeID2)
void assignWeights_dir(MotifType mt)
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
const TDat & GetDat(const TKey &Key) const
void countDirTriadMotif(PNGraph graph)
bool IsKey(const TKey &Key) const
void Pop()
Removes the first element from the queue.
bool Empty() const
Tests whether the queue is empty (contains no elements).
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Edge iterator. Only forward iteration (operator++) is supported.
static void Throw(const TStr &MsgStr)
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.
PUNGraph GetSubGraph(const PUNGraph &Graph, const TIntV &NIdV, const bool &RenumberNodes)
Returns an induced subgraph of an undirected graph Graph with NIdV nodes with an optional node renumb...
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
int AddKey(const TKey &Key)
int checkEdge(PNGraph &G, long nodeID, long nbrID)
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the graph.
TVec< THash< TInt, TFlt > > WeightVH
void sweepAPPR(int option=-1)
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
int GetId() const
Returns ID of the current node.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetOutDeg() const
Returns out-degree of the current node.
PUNGraph getTransformedGraph() const
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
void Push(const TVal &Val)
Adds an element at the end of the queue.
int getCliqueSize(const MotifType &type)
Node iterator. Only forward iteration (operator++) is supported.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
const TVal & Top() const
Returns the value of the first element in the queue, but does not remove the element.
int GetId() const
Returns ID of the current node.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
bool isLocalMin(int idx, double thresh=1.2)
float getTotalVolume() const
void printMotifType(const MotifType &type)
void SortByDat(const bool &Asc=true)