6 namespace TSnapDetail {
18 Cmty1.
Clr(
false); Cmty2.
Clr(
false);
22 if (BtwEH.
Empty()) {
return; }
27 if (BFS.
GetHops(NId1, NId2) == -1) {
40 for (
int c = 0; c < CnComV.
Len(); c++) {
41 const TIntV& NIdV = CnComV[c]();
42 double EIn = 0, EEIn = 0;
43 for (
int i = 0; i < NIdV.
Len(); i++) {
46 EEIn += OutDegH.
GetDat(NIdV[i]);
48 Mod += (EIn-EEIn*EEIn / (2.0*OrigEdges));
50 if (Mod == 0) {
return 0; }
51 else {
return Mod / (2.0*OrigEdges); }
55 float InModule = 0.0, OutModule = 0.0, Val;
56 int Mds[2] = { a, b };
57 for (
int i = 0; i<2; i++) {
58 InModule = 0.0, OutModule = 0.0;
59 if (Qi.
IsKey(Mds[i])) {
60 int CentralModule = Mds[i];
66 if (Module.
GetDat(NI.GetId()) == CentralModule)
70 for (
int j = 0; j<newM.
Len(); j++) {
74 for (
int k = 0; k<Graph->
GetNI(newM[j]).
GetDeg(); k++) {
79 int ms = Module.
GetDat(ids);
80 int md = Module.
GetDat(idd);
92 if (InModule >1) InModule = InModule / 2;
97 if (InModule + OutModule > 0) {
98 Val = OutModule / (InModule + OutModule);
110 double SumPAlpha = 1.0, SumQi = 0.0, SumQiLogQi = 0.0;
111 double SumQiSumPAlphaLogQiSumPAlpha = 0.0, logqi = 0.0, qi = 0.0;
112 for (
int i = 0; i<Qi.
Len(); i++) {
120 SumQiLogQi += Qi[i] * logqi;
121 SumQiSumPAlphaLogQiSumPAlpha += (Qi[i] + SumPAlpha)*log(Qi[i] + SumPAlpha);
123 return (SumQi*log(SumQi) - 2 * SumQiLogQi - SumPAlphaLogPAlpha +
124 SumQiSumPAlphaLogQiSumPAlpha);
128 for (
int i = 0; i<a.
Len(); i++) {
129 for (
int j = 0; j<b.
Len(); j++) {
130 if (graph->
IsEdge(a[i], b[j]))
140 for (
int i = 0; i<a.
Len(); i++) {
141 for (
int j = 0; j<b.
Len(); j++) {
161 if (inCompCount.
IsKey(
id)) {
162 inComp = inCompCount.
GetDat(
id);
164 if (inCompCount.
IsKey(neigh)) {
165 inCompN = inCompCount.
GetDat(neigh);
168 if (inCompN < neighDeg && inComp < deg && (!g1->
IsNode(neigh) || Graph->
GetNI(neigh).
GetDeg() - neighDeg == 0)) {
169 inCompCount.
AddDat(neigh, ++inCompN);
170 inCompCount.
AddDat(
id, ++inComp);
180 for (
int i = 0; i < a.
Len(); i++) {
182 for (
int j = 0; j < b.
Len(); j++) {
198 for (
int i = 0; i < a.
Len(); i++) {
211 return (after && before);
236 double oldAlphaN1 = 0.0;
237 double oldAlphaN2 = 0.0;
240 oldAlphaN1 = PAlpha.
GetDat(n1);
243 oldAlphaN2 = PAlpha.
GetDat(n2);
247 int nodeDeg = node.
GetDeg();
248 float d = ((float)nodeDeg / (
float)(2 * e));
252 SumPAlphaLogPAlpha = SumPAlphaLogPAlpha - oldAlphaN1 + d*log(d);
261 node = Graph->
GetNI(n2);
263 d = ((float)nodeDeg / (
float)(2 * e));
267 SumPAlphaLogPAlpha = SumPAlphaLogPAlpha - oldAlphaN2 + d*log(d);
279 double PrevIterationCodeLength = 0.0;
282 PrevIterationCodeLength = MinCodeLength;
283 int id[2] = { n1, n2 };
284 for (
int k = 0; k<2; k++) {
285 for (
int i = 0; i<Graph->
GetNI(
id[k]).
GetDeg(); i++) {
287 int OldModule = Module.
GetDat(
id[k]);
290 Module.
AddDat(
id[k], NewModule);
294 if (NewCodeLength<MinCodeLength) {
295 MinCodeLength = NewCodeLength;
296 OldModule = NewModule;
299 Module.
AddDat(
id[k], OldModule);
303 }
while (MinCodeLength<PrevIterationCodeLength);
305 return MinCodeLength;
314 const int NEdges = Graph->GetEdges();
316 OutDegH.
AddDat(NI.GetId(), NI.GetOutDeg());
328 CmtyV.
Swap(CurCmtyV);
330 if (Cmty1.
Len() == 0 || Cmty2.
Len() == 0) {
break; }
343 double SumPAlphaLogPAlpha = 0.0;
345 const int e = Graph->GetEdges();
349 int nodeId = NI.GetId();
350 int nodeDeg = NI.GetDeg();
351 float d = ((float)nodeDeg / (
float)(2 * e));
353 SumPAlphaLogPAlpha += d*log(d);
354 Module.
AddDat(nodeId, Br);
360 double NewCodeLength, PrevIterationCodeLength = 0.0;
361 int OldModule, NewModule;
365 nodes.
Add(NI.GetId());
368 PrevIterationCodeLength = MinCodeLength;
372 for (
int ndcounter = 0; ndcounter<nodes.
Len(); ndcounter++) {
374 int nodeId = nodes[ndcounter];
376 for (
int i = 0; i<NI.
GetDeg(); i++) {
378 OldModule = Module.
GetDat(nodeId);
381 if (OldModule != NewModule){
383 Module.
AddDat(nodeId, NewModule);
387 if (NewCodeLength<MinCodeLength) {
388 MinCodeLength = NewCodeLength;
389 OldModule = NewModule;
392 Module.
AddDat(nodeId, OldModule);
397 }
while (MinCodeLength<PrevIterationCodeLength);
402 for (
int i = 0; i<Module.
Len(); i++) {
407 if (Module.
GetDat(NI.GetId()) == Mod)
414 return MinCodeLength;
424 for (
int i = 0; i<Module.
Len(); i++) {
429 if (Module.
GetDat(NI.GetId()) == Mod)
436 return MinCodeLength;
445 for (
int i = 0; i < cCont.
Len(); i++){
447 if (!uniqueId.
IsIn(it.GetKey()))
448 uniqueId.
Add(it.GetKey());
452 for (
int j = 0; j<uniqueId.
Len(); j++)
455 for (
int i = 0; i<cCont.
Len(); i++)
457 if (cCont[i].IsKey(uniqueId[j]))
462 cContV.
AddDat(uniqueId[j], cV);
466 for (
int i = 0; i < sizesCont.
Len(); i++){
468 if (!uniqueC.
IsIn(it.GetKey()))
469 uniqueC.
Add(it.GetKey());
473 for (
int j = 0; j<uniqueC.
Len(); j++)
476 for (
int i = 0; i<sizesCont.
Len(); i++)
478 if (sizesCont[i].IsKey(uniqueC[j]))
483 sizesContV.
AddDat(uniqueC[j], cV);
514 if (Marker.
GetCh(0) ==
'#'){
527 if (!Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
528 if (!Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
529 Graph->AddEdge(SrcNId, DstNId);
533 }
while (Marker.
GetCh(0) !=
'#' && !Ss.
Eof());
536 if (Graph->GetNodes()>0) {
544 CmtyAlgStr =
"Girvan-Newman";
547 else if (CmtyAlg == 2) {
548 CmtyAlgStr =
"Clauset-Newman-Moore";
551 else if (CmtyAlg == 3) {
552 CmtyAlgStr =
"Infomap";
562 for (
int c = 0; c < CmtyV.
Len(); c++) {
563 for (
int i = 0; i < CmtyV[c].
Len(); i++){
564 prev.
AddDat(CmtyV[c][i].Val, c);
567 prev_sizes.
AddDat(c, CmtyV[c].Len());
579 int first_new_c_id = -1;
583 if (it.GetKey() > first_new_c_id)
584 first_new_c_id = it.
GetKey();
585 if (CmtyV.
Len() - 1>first_new_c_id)
586 first_new_c_id = CmtyV.
Len() - 1;
589 for (
int c = 0; c < CmtyV.
Len(); c++) {
597 dist.
AddDat(it.GetKey(), 0);
601 for (
int i = 0; i < CmtyV[c].
Len(); i++) {
602 int id = CmtyV[c][i].Val;
605 prev_comm = prev.
GetDat(CmtyV[c][i].Val);
607 int pre_val = dist.
GetDat(prev_comm);
608 dist.
AddDat(prev_comm, pre_val + 1);
617 if (prev_sizes.
IsKey(it.GetKey())){
619 double stat1_ = (double)d / (
double)prev_sizes.
GetDat(k);
622 double stat2_ = (double)d / (
double)CmtyV[c].
Len();
638 if (sumstat2 > 0.98)
break;
641 int n_of_c_greater_than_half = 0;
642 int id_of_c_greater_than_half = -1;
643 TIntV ids_of_c_greater_than_half;
646 if (it.GetDat()>alpha){
647 id_of_c_greater_than_half = it.GetKey();
648 ids_of_c_greater_than_half.
Add(it.GetKey());
649 n_of_c_greater_than_half++;
654 if (n_of_c_greater_than_half == 1){
655 map.
AddDat(c, id_of_c_greater_than_half);
659 for (
int i = 0; i<ids_of_c_greater_than_half.
Len(); i++){
660 double H2 = statH2.
GetDat(ids_of_c_greater_than_half[i]);
662 h2part_id = ids_of_c_greater_than_half[i];
668 map.
AddDat(c, first_new_c_id);
683 for (
int c = 0; c < CmtyV.
Len(); c++){
684 for (
int i = 0; i < CmtyV[c].
Len(); i++){
695 int b = it.GetDat()[1];
696 int v = it.GetDat()[2];
697 int d = it.GetDat()[3];
698 int e = it.GetDat()[4];
712 sizesCont.
AddDat(br, prev_sizes);
729 Json.
InsStr(Json.
Len(),
"{\n\"edges\":[\n");
736 TInt n1 = it.GetDat()[1];
738 TInt n2 = it.GetDat()[0];
740 TInt w = it.GetDat()[2];
742 TInt t0 = it.GetDat()[3];
744 TInt t1 = it.GetDat()[4];
760 Json.
InsStr(Json.
Len(),
"],\n\"communities\":[\n");
764 for (
int i = 0; i < sizesContV[0].
Len(); i++)
769 TInt id = it.GetKey();
771 TInt size = it.GetDat()[i];
780 TInt size = it.GetDat()[i];
849 int first = 429496729;
857 if (it.GetDat()<first)
859 if (it.GetDat()>last)
866 if (it.GetDat() - (e / 2) >= first)
867 timePoints.
Add(it.GetDat() - (e / 2) );
868 timePoints.
Add(it.GetDat());
869 if (it.GetDat() + (e / 2) <= last)
870 timePoints.
Add(it.GetDat() + (e / 2) );
875 for (
int i = 0; i<timePoints.
Len(); i++) {
877 int focusTimePoint = timePoints[i];
883 if ((it.GetDat() <= focusTimePoint + (e / 2)) && (it.GetDat() >= focusTimePoint - (e / 2)))
884 fnodes.
Add(it.GetKey());
889 for (
int i = 0; i<fnodes.
Len(); i++) {
890 if (!g1->
IsNode(fnodes[i]))
895 if (t.
GetDat(NeighId)<focusTimePoint - (e / 2)) {
901 g1->
AddEdge(NeighId, fnodes[i]);
907 if (t.
GetDat(NeighId)>focusTimePoint + (e / 2)) {
913 g1->
AddEdge(fnodes[i], NeighId);
921 TIntV communitiesAtT;
922 for (
int cc = 0; cc < CnComV.
Len(); cc++) {
923 components.
AddDat(newId, CnComV[cc].NIdV);
924 communitiesAtT.
Add(newId);
927 if (CnComV.
Len() > 0)
928 ct.
AddDat(focusTimePoint, communitiesAtT);
935 while (it < prelast) {
940 focusTimePoint = it.
GetKey();
943 focusTimePoint1 = it.
GetKey();
945 if (cms0.
Len()>0 && cms1.
Len() > 0) {
946 for (
int i = 0; i < cms0.
Len(); i++) {
947 for (
int j = 0; j < cms1.
Len(); j++) {
951 if (!gFinal->
IsNode(cms0[i])) {
953 tFinal.
AddDat(cms0[i], focusTimePoint);
955 if (!gFinal->
IsNode(cms1[j])) {
957 tFinal.
AddDat(cms1[j], focusTimePoint1);
959 gFinal->
AddEdge(cms0[i], cms1[j]);
969 if (NI.GetInDeg() == 1 && NI.GetOutDeg() == 1)
970 if (gFinal->
GetNI(NI.GetInNId(0)).GetOutDeg() == 1 && gFinal->
GetNI(NI.GetOutNId(0)).GetInDeg() == 1)
972 gFinal->
AddEdge(NI.GetInNId(0), NI.GetOutNId(0));
973 gFinal->
DelEdge(NI.GetInNId(0), NI.GetId());
974 tFinal.
DelKey(NI.GetId());
989 int first = 429496729;
997 if (it.GetDat() < first)
999 if (it.GetDat() > last)
1006 if (it.GetDat() - (e / 2) >= first)
1007 timePoints.
Add(it.GetDat() - (e / 2) );
1008 timePoints.
Add(it.GetDat());
1009 if (it.GetDat() + (e / 2) <= last)
1010 timePoints.
Add(it.GetDat() + (e / 2) );
1013 TIntV timePointsUnique;
1016 for (
int i = 0; i < timePoints.
Len(); i++){
1017 if (timePoints[i] > prevtp)
1018 timePointsUnique.
Add(timePoints[i]);
1019 prevtp = timePoints[i];
1023 timePoints = timePointsUnique;
1026 for (
int i = 0; i < timePoints.
Len(); i++) {
1028 int focusTimePoint = timePoints[i];
1034 if ((it.GetDat() <= focusTimePoint + (e / 2)) && (it.GetDat() >= focusTimePoint - (e / 2)))
1035 fnodes.
Add(it.GetKey());
1040 for (
int i = 0; i < fnodes.
Len(); i++) {
1041 if (!g1->
IsNode(fnodes[i]))
1044 for (
int j = 0; j < Graph->
GetNI(fnodes[i]).
GetInDeg(); j++) {
1046 if (t.
GetDat(NeighId) < focusTimePoint - (e / 2)) {
1050 if (!g1->
IsNode(NeighId))
1052 g1->
AddEdge(NeighId, fnodes[i]);
1058 if (t.
GetDat(NeighId) > focusTimePoint + (e / 2)) {
1062 if (!g1->
IsNode(NeighId))
1064 g1->
AddEdge(fnodes[i], NeighId);
1075 int FTP = focusTimePoint;
1081 int FTPNode = NI.GetId();
1083 int FI, FO, RI, RO, I, O;
1086 RO = NI.GetOutDeg();
1091 if (focusTimePoint + (e / 2) == t.
GetDat(NI.GetId())) {
1094 if (focusTimePoint - (e / 2) == t.
GetDat(NI.GetId())) {
1103 if (TEdges.
IsKey(FTP))
1104 temp = TEdges.
GetDat(FTP);
1105 TEdges.
AddDat(FTP, O + temp);
1110 if (I > 1 && O > 1) {
1118 for (
int i = 0; i < I; i++) {
1122 for (
int i = 0; i < O; i++) {
1126 for (
int j = 0; j < nn; j++) {
1128 comps.
AddDat(compBr, nds);
1134 else if (I == 1 && O > 1) {
1135 for (
int i = 0; i < O; i++) {
1140 comps.
AddDat(compBr, nds);
1146 else if (I > 1 && O == 1) {
1147 for (
int i = 0; i < I; i++) {
1152 comps.
AddDat(compBr, nds);
1158 else if (I == 0 && O > 1) {
1159 for (
int i = 0; i < O; i++) {
1163 comps.
AddDat(compBr, nds);
1169 else if (I > 1 && O == 0) {
1170 for (
int i = 0; i < I; i++) {
1174 comps.
AddDat(compBr, nds);
1180 else if (I == 1 && O == 1) {
1185 comps.
AddDat(compBr, nds);
1190 else if (I == 0 && O == 1) {
1194 comps.
AddDat(compBr, nds);
1199 else if (I == 1 && O == 0) {
1203 comps.
AddDat(compBr, nds);
1215 for (
int cc0 = 0; cc0 < comps.
Len(); cc0++) {
1216 for (
int cc1 = cc0; cc1 < comps.
Len(); cc1++) {
1217 int smaller = comps[cc0].
Len();
1218 int smaller_id = cc0;
1220 if (comps[cc1].Len() < smaller) {
1221 smaller = comps[cc1].
Len();
1225 if (vi == smaller && !nn_nodes.
IsKey(smaller_id)){
1226 banned.
AddDat(smaller_id);
1248 for (
int cc0 = 0; cc0 < comps.
Len(); cc0++) {
1249 if (!banned.
IsKey(cc0) )
1250 elements.
AddDat(cc0, comps[cc0]);
1254 TIntV communitiesAtT;
1255 for (
int cc = 0; cc < elements.
Len(); cc++) {
1256 components.
AddDat(newId, elements[cc]);
1257 communitiesAtT.
Add(newId);
1260 if (elements.
Len() > 0)
1261 ct.
AddDat(focusTimePoint, communitiesAtT);
1269 while (it < prelast) {
1273 int focusTimePoint1;
1274 focusTimePoint = it.
GetKey();
1277 focusTimePoint1 = it.
GetKey();
1279 if (cms0.
Len() > 0 && cms1.
Len() > 0) {
1280 for (
int i = 0; i < cms0.
Len(); i++) {
1281 for (
int j = 0; j < cms1.
Len(); j++) {
1284 int smaller = ids0.
Len();
1285 if (ids1.
Len() < smaller)
1286 smaller = ids1.
Len();
1289 if (!gFinal->
IsNode(cms0[i])) {
1291 tFinal.
AddDat(cms0[i], focusTimePoint);
1293 if (!gFinal->
IsNode(cms1[j])) {
1295 tFinal.
AddDat(cms1[j], focusTimePoint1);
1297 gFinal->
AddEdge(cms0[i], cms1[j]);
1307 if (NI.GetInDeg() == 1 && NI.GetOutDeg() == 1)
1308 if (gFinal->
GetNI(NI.GetInNId(0)).GetOutDeg() == 1 && gFinal->
GetNI(NI.GetOutNId(0)).GetInDeg() == 1)
1310 gFinal->
AddEdge(NI.GetInNId(0), NI.GetOutNId(0));
1311 gFinal->
DelEdge(NI.GetInNId(0), NI.GetId());
1312 tFinal.
DelKey(NI.GetId());
1320 namespace TSnapDetail {
1331 TCmtyDat(
const double& NodeDegFrac,
const int& OutDeg) :
1333 void AddQ(
const int& NId,
const double&
Q) {
1361 const double M = 0.5 / Graph->
GetEdges();
1365 const int OutDeg = NI.GetOutDeg();
1366 if (OutDeg == 0) {
continue; }
1368 for (
int e = 0; e < NI.GetOutDeg(); e++) {
1369 const int DstNId = NI.GetOutNId(e);
1370 const double DstMod = 2 * M * (1.0 - OutDeg * Graph->
GetNI(DstNId).
GetOutDeg() * M);
1371 Dat.
AddQ(DstNId, DstMod);
1382 if (
MxQHeap.Empty()) {
break; }
1393 if (TopQ.
Val1 <= 0.0) {
return false; }
1395 const int I = TopQ.
Val3;
1396 const int J = TopQ.
Val2;
1405 double NewQ = DatJ.
NIdQH[i];
1437 CmtyV.
Gen(IdCmtyH.
Len());
1438 for (
int j = 0; j < IdCmtyH.
Len(); j++) {
1439 CmtyV[j].NIdV.
Swap(IdCmtyH[j]);
double CommunityGirvanNewman(PUNGraph &Graph, TCnComV &CmtyV)
static const T & Mn(const T &LVal, const T &RVal)
int Add(const int &Key)
Adds an element Key to the structure.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
void Add(const int &NodeId)
int GetHops(const int &SrcNId, const int &DstNId) const
void Union(const int &Key1, const int &Key2)
Merges sets with elements Key1 and Key2.
TFltIntIntTr FindMxQEdge()
static const T & Mx(const T &LVal, const T &RVal)
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
void GetNodeWcc(const PGraph &Graph, const int &NId, TIntV &CnCom)
Returns (via output parameter CnCom) all nodes that are in the same connected component as node NId...
TCNMQMatrix(const PUNGraph &Graph)
int DoBfs(const int &StartNode, const bool &FollowOut, const bool &FollowIn, const int &TargetNId=-1, const int &MxDist=TInt::Mx)
Performs BFS from node id StartNode for at maps MxDist steps by only following in-links (parameter Fo...
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int GetEdges() const
Returns the number of edges in the graph.
TSizeTy Len() const
Returns the number of elements in the vector.
double InfomapOnline(PUNGraph &Graph, int n1, int n2, TIntFltH &PAlpha, double &SumPAlphaLogPAlpha, TIntFltH &Qi, TIntH &Module, int &Br, TCnComV &CmtyV)
void ReebSimplify(PNGraph &Graph, TIntH &t, int e, PNGraph &gFinal, TIntH &tFinal, bool collapse)
Node iterator. Only forward iteration (operator++) is supported.
void GetBetweennessCentr(const PGraph &Graph, TIntFltH &NIdBtwH, const double &NodeFrac=1.0, const bool &IsDir=false)
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
TChA GetLnStr() const
Returns the current line.
const TDat & GetDat(const TKey &Key) const
static double Sqr(const double &x)
const TKey & GetKey() const
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
int GetDeg() const
Returns degree of the current node.
void DelKey(const TKey &Key)
bool Eof() const
Checks for end of file.
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.
int Find(const int &Key)
Returns the set that contains element Key.
const TDat & GetDat() const
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
void CmtyEvolutionFileBatch(TStr InFNm, TIntIntHH &sizesCont, TIntIntHH &cCont, TIntIntVH &edges, double alpha, double beta, int CmtyAlg)
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the graph.
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.
bool inComp(PNGraph &g1, PNGraph &Graph, TIntH &inCompCount, int id, int neigh)
Simple heap data structure.
Whitespace (space or tab) separated.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
bool FNextKeyId(int &KeyId) const
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
bool chekIfCrossing(TIntV &a, TIntH &t, int f, int l, int TP)
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New().
void CmtyEvolutionFileBatchV(TStr InFNm, TIntIntVH &sizesContV, TIntIntVH &cContV, TIntIntVH &edges, double alpha, double beta, int CmtyAlg)
TStr CmtyTest(TStr InFNm, int CmtyAlg)
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the graph.
TSizeTy IntrsLen(const TVec< TVal, TSizeTy > &ValV) const
Returns the size of the intersection of vectors this and ValV. Assumes the vectors are sorted! ...
char GetCh(const int &ChN) const
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
THeap< TFltIntIntTr > MxQHeap
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
void DelLink(const int &K)
int GetKeyId(const TKey &Key) const
void CmtyEvolutionJson(TStr &Json, TIntIntVH &sizesContV, TIntIntVH &cContV, TIntIntVH &edges)
void MapEquationNew2Modules(PUNGraph &Graph, TIntH &Module, TIntFltH &Qi, int a, int b)
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
double InfomapOnlineIncrement(PUNGraph &Graph, int n1, int n2, TIntFltH &PAlpha, double &SumPAlphaLogPAlpha, TIntFltH &Qi, TIntH &Module, int &Br)
void AddQ(const int &NId, const double &Q)
int GetOutDeg() const
Returns out-degree of the current node.
void transitiveTransform(TIntV &a, TIntV &b)
double CommunityCNM(const PUNGraph &Graph, TCnComV &CmtyV)
void ReebRefine(PNGraph &Graph, TIntH &t, int e, PNGraph &gFinal, TIntH &tFinal, bool collapse)
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Node iterator. Only forward iteration (operator++) is supported.
void Init(const PUNGraph &Graph)
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
int vectorIntersect(TIntV &a, TIntV &b)
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
bool Next()
Loads next line from the input file.
bool edgeIntersect(PNGraph &graph, TIntV &a, TIntV &b)
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
int GetInDeg() const
Returns in-degree of the current node.
int GetId() const
Returns ID of the current node.
bool IsKey(const TKey &Key) const
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
TCmtyDat(const double &NodeDegFrac, const int &OutDeg)
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.
void DelSelfEdges(const PGraph &Graph)
Removes all the self-edges from the graph.
double Equation(TIntFltH &PAlpha, double &SumPAlphaLogPAlpha, TIntFltH &Qi)
void InsStr(const int &BChN, const TStr &Str)
double Infomap(PUNGraph &Graph, TCnComV &CmtyV)
TDat & AddDat(const TKey &Key)
static double CmtyCMN(const PUNGraph &Graph, TCnComV &CmtyV)
void GetWccs(const PGraph &Graph, TCnComV &CnComV)
Returns all weakly connected components in a Graph.
Union Find class (Disjoint-set data structure).
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
const TKey & GetKey(const int &KeyId) const
TTriple< TFlt, TInt, TInt > TFltIntIntTr
double _GirvanNewmanGetModularity(const PUNGraph &G, const TIntH &OutDegH, const int &OrigEdges, TCnComV &CnComV)
Vector is a sequence TVal objects representing an array that can change in size.
THash< TInt, TCmtyDat > CmtyQH
void CmtyGirvanNewmanStep(PUNGraph &Graph, TIntV &Cmty1, TIntV &Cmty2)
A single step of Girvan-Newman clustering procedure.
void SortByDat(const bool &Asc=true)