void TAGMFast::NeighborComInit(const int InitComs) { //initialize with best neighborhood communities (Gleich et.al. KDD'12) F.Gen(G->GetNodes()); SumFV.Gen(InitComs); NumComs = InitComs; const int Edges = G->GetEdges(); //TIntFltH NCPhiH(F.Len()); TFltIntPrV NIdPhiV(F.Len(), 0); TIntSet InvalidNIDS(F.Len()); TIntV ChosenNIDV(InitComs, 0); //FOR DEBUG TExeTm RunTm; //compute conductance of neighborhood community for (int u = 0; u < F.Len(); u++) { TIntSet NBCmty(G->GetNI(u).GetDeg() + 1); double Phi; if (G->GetNI(u).GetDeg() < 5) { //do not include nodes with too few degree Phi = 1.0; } else { TAGMUtil::GetNbhCom(G, u, NBCmty); IAssert(NBCmty.Len() == G->GetNI(u).GetDeg() + 1); Phi = TAGMUtil::GetConductance(G, NBCmty, Edges); } //NCPhiH.AddDat(u, Phi); NIdPhiV.Add(TFltIntPr(Phi, u)); } NIdPhiV.Sort(true); printf("conductance computation completed [%s]\n", RunTm.GetTmStr()); fflush(stdout); //choose nodes with local minimum in conductance int CurCID = 0; for (int ui = 0; ui < NIdPhiV.Len(); ui++) { int UID = NIdPhiV[ui].Val2; fflush(stdout); if (InvalidNIDS.IsKey(UID)) { continue; } ChosenNIDV.Add(UID); //FOR DEBUG //add the node and its neighbors to the current community AddCom(UID, CurCID, 1.0); TUNGraph::TNodeI NI = G->GetNI(UID); fflush(stdout); for (int e = 0; e < NI.GetDeg(); e++) { AddCom(NI.GetNbrNId(e), CurCID, 1.0); } //exclude its neighbors from the next considerations for (int e = 0; e < NI.GetDeg(); e++) { InvalidNIDS.AddKey(NI.GetNbrNId(e)); } CurCID++; fflush(stdout); if (CurCID >= NumComs) { break; } } if (NumComs > CurCID) { printf("%d communities needed to fill randomly\n", NumComs - CurCID); } //assign a member to zero-member community (if any) for (int c = 0; c < SumFV.Len(); c++) { if (SumFV[c] == 0.0) { int ComSz = 10; for (int u = 0; u < ComSz; u++) { int UID = Rnd.GetUniDevInt(G->GetNodes()); AddCom(UID, c, Rnd.GetUniDev()); } } } }
// Initialize node community memberships using best neighborhood communities (see D. Gleich et al. KDD'12). void TAGMFit::NeighborComInit(const int InitComs) { CIDNSetV.Gen(InitComs); const int Edges = G->GetEdges(); TFltIntPrV NIdPhiV(G->GetNodes(), 0); TIntSet InvalidNIDS(G->GetNodes()); TIntV ChosenNIDV(InitComs, 0); //FOR DEBUG TExeTm RunTm; //compute conductance of neighborhood community TIntV NIdV; G->GetNIdV(NIdV); for (int u = 0; u < NIdV.Len(); u++) { TIntSet NBCmty(G->GetNI(NIdV[u]).GetDeg() + 1); double Phi; if (G->GetNI(NIdV[u]).GetDeg() < 5) { //do not include nodes with too few degree Phi = 1.0; } else { TAGMUtil::GetNbhCom(G, NIdV[u], NBCmty); IAssert(NBCmty.Len() == G->GetNI(NIdV[u]).GetDeg() + 1); Phi = TAGMUtil::GetConductance(G, NBCmty, Edges); } NIdPhiV.Add(TFltIntPr(Phi, NIdV[u])); } NIdPhiV.Sort(true); printf("conductance computation completed [%s]\n", RunTm.GetTmStr()); fflush(stdout); //choose nodes with local minimum in conductance int CurCID = 0; for (int ui = 0; ui < NIdPhiV.Len(); ui++) { int UID = NIdPhiV[ui].Val2; fflush(stdout); if (InvalidNIDS.IsKey(UID)) { continue; } ChosenNIDV.Add(UID); //FOR DEBUG //add the node and its neighbors to the current community CIDNSetV[CurCID].AddKey(UID); TUNGraph::TNodeI NI = G->GetNI(UID); fflush(stdout); for (int e = 0; e < NI.GetDeg(); e++) { CIDNSetV[CurCID].AddKey(NI.GetNbrNId(e)); } //exclude its neighbors from the next considerations for (int e = 0; e < NI.GetDeg(); e++) { InvalidNIDS.AddKey(NI.GetNbrNId(e)); } CurCID++; fflush(stdout); if (CurCID >= InitComs) { break; } } if (InitComs > CurCID) { printf("%d communities needed to fill randomly\n", InitComs - CurCID); } //assign a member to zero-member community (if any) for (int c = 0; c < CIDNSetV.Len(); c++) { if (CIDNSetV[c].Len() == 0) { int ComSz = 10; for (int u = 0; u < ComSz; u++) { int UID = G->GetRndNI().GetId(); CIDNSetV[c].AddKey(UID); } } } InitNodeData(); SetDefaultPNoCom(); }