Clauset-Newman-Moore community detection method. At every step two communities that contribute maximum positive value to global modularity are merged. See: Finding community structure in very large networks, A. Clauset, M.E.J. Newman, C. Moore, 2004
Definition at line 1326 of file cmty.cpp.
static double TSnap::TSnapDetail::TCNMQMatrix::CmtyCMN |
( |
const PUNGraph & |
Graph, |
|
|
TCnComV & |
CmtyV |
|
) |
| |
|
inlinestatic |
Definition at line 1430 of file cmty.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), TUNGraph::BegNI(), CmtyIdUF, TUNGraph::EndNI(), TUnionFind::Find(), TVec< TVal, TSizeTy >::Gen(), THash< TKey, TDat, THashFunc >::Len(), MergeBestQ(), Q, and TVec< TVal, TSizeTy >::Swap().
Referenced by TSnap::CommunityCNM().
1433 while (QMatrix.MergeBestQ()) {}
1437 IdCmtyH.
AddDat(QMatrix.CmtyIdUF.Find(NI.GetId())).
Add(NI.GetId());
1439 CmtyV.
Gen(IdCmtyH.
Len());
1440 for (
int j = 0; j < IdCmtyH.
Len(); j++) {
1441 CmtyV[j].NIdV.
Swap(IdCmtyH[j]);
TCNMQMatrix(const PUNGraph &Graph)
Node iterator. Only forward iteration (operator++) is supported.
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TDat & AddDat(const TKey &Key)
void TSnap::TSnapDetail::TCNMQMatrix::Init |
( |
const PUNGraph & |
Graph | ) |
|
|
inline |
Definition at line 1362 of file cmty.cpp.
References TUnionFind::Add(), THeap< TVal, TCmp >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::AddQ(), TUNGraph::BegNI(), TUNGraph::EndNI(), TUNGraph::GetEdges(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::GetMxQ(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::GetMxQNId(), TUNGraph::GetNI(), TUNGraph::TNodeI::GetOutDeg(), THeap< TVal, TCmp >::MakeHeap(), and TMath::Sqr().
Referenced by TCNMQMatrix().
1363 const double M = 0.5 / Graph->GetEdges();
1367 const int OutDeg = NI.GetOutDeg();
1368 if (OutDeg == 0) {
continue; }
1369 TCmtyDat& Dat =
CmtyQH.AddDat(NI.GetId(), TCmtyDat(M * OutDeg, OutDeg));
1370 for (
int e = 0; e < NI.GetOutDeg(); e++) {
1371 const int DstNId = NI.GetOutNId(e);
1372 const double DstMod = 2 * M * (1.0 - OutDeg * Graph->GetNI(DstNId).GetOutDeg() * M);
1373 Dat.AddQ(DstNId, DstMod);
1376 if (NI.GetId() < Dat.GetMxQNId()) {
int Add(const int &Key)
Adds an element Key to the structure.
Node iterator. Only forward iteration (operator++) is supported.
static double Sqr(const double &x)
THeap< TFltIntIntTr > MxQHeap
TTriple< TFlt, TInt, TInt > TFltIntIntTr
THash< TInt, TCmtyDat > CmtyQH
bool TSnap::TSnapDetail::TCNMQMatrix::MergeBestQ |
( |
| ) |
|
|
inline |
Definition at line 1393 of file cmty.cpp.
References TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::AddQ(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::DegFrac, THash< TKey, TDat, THashFunc >::DelKey(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::DelLink(), THash< TKey, TDat, THashFunc >::Empty(), FindMxQEdge(), THash< TKey, TDat, THashFunc >::FNextKeyId(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::IsKey(), TMath::Mn(), TMath::Mx(), TSnap::TSnapDetail::TCNMQMatrix::TCmtyDat::NIdQH, THeap< TVal, TCmp >::PushHeap(), TUnionFind::Union(), TTriple< TVal1, TVal2, TVal3 >::Val1, TTriple< TVal1, TVal2, TVal3 >::Val2, and TTriple< TVal1, TVal2, TVal3 >::Val3.
Referenced by CmtyCMN().
1395 if (TopQ.
Val1 <= 0.0) {
return false; }
1397 const int I = TopQ.
Val3;
1398 const int J = TopQ.
Val2;
1401 TCmtyDat& DatJ =
CmtyQH.GetDat(J);
1402 { TCmtyDat& DatI =
CmtyQH.GetDat(I);
1403 DatI.DelLink(J); DatJ.DelLink(I);
1404 for (
int i = -1; DatJ.NIdQH.FNextKeyId(i); ) {
1405 const int K = DatJ.NIdQH.GetKey(i);
1406 TCmtyDat& DatK =
CmtyQH.GetDat(K);
1407 double NewQ = DatJ.NIdQH[i];
1408 if (DatI.NIdQH.IsKey(K)) { NewQ = NewQ + DatI.NIdQH.GetDat(K); DatK.DelLink(I); }
1409 else { NewQ = NewQ - 2 * DatI.DegFrac*DatK.DegFrac; }
1414 for (
int i = -1; DatI.NIdQH.FNextKeyId(i); ) {
1415 const int K = DatI.NIdQH.GetKey(i);
1416 if (!DatJ.NIdQH.IsKey(K)) {
1417 TCmtyDat& DatK =
CmtyQH.GetDat(K);
1418 const double NewQ = DatI.NIdQH[i] - 2 * DatJ.DegFrac*DatK.DegFrac;
1425 DatJ.DegFrac += DatI.DegFrac; }
1426 if (DatJ.NIdQH.Empty()) {
CmtyQH.DelKey(J); }
static const T & Mn(const T &LVal, const T &RVal)
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)
THeap< TFltIntIntTr > MxQHeap
TTriple< TFlt, TInt, TInt > TFltIntIntTr
THash< TInt, TCmtyDat > CmtyQH