SNAP Library 6.0, Developer Reference
2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Local Spectral Clustering algorithm. More...
#include <ncp.h>
Public Member Functions | |
TLocClust (const PUNGraph &GraphPt, const double &AlphaVal) | |
int | Len () const |
Returns the support of the approximate random walk, the number of nodes with non-zero PageRank score. More... | |
int | GetRndWalkSup () const |
Returns the support of the approximate random walk, the number of nodes with non-zero PageRank score. More... | |
int | GetNId (const int &NodeN) const |
Returns the ID of the NodeN-th node in the sweep vector. More... | |
int | GetVol (const int &Nodes) const |
Returns the volume of the set of first NodeN nodes in the sweep vector. More... | |
int | GetCut (const int &Nodes) const |
Returns the size of the cut of the first Nodes nodes in the sweep vector. More... | |
double | GetPhi (const int &ValId) const |
Returns the conductance of the cut separating the first Nodes nodes in the sweep vector from the rest of the graph. More... | |
const TIntV & | GetNIdV () const |
Vector of node IDs sorted in the random walk order. More... | |
const TIntV & | GetVolV () const |
Volume (sum of the degrees) of first K-nodes in the node-id vector (GetNIdV()). More... | |
const TIntV & | GetCutV () const |
Edges cut to separate the first K-nodes in the node-id vector (GetNIdV()) from the rest of the graph. More... | |
const TFltV & | GetPhiV () const |
Conducatance of the cut separating first K-nodes in the node-id vector (GetNIdV()) from the rest of the graph. More... | |
int | BestCut () const |
Index K of the cut of the minimum conductance around the seed node. More... | |
int | BestCutNodes () const |
Number of nodes inside the 'best' (minimum conductance) cut. More... | |
int | GetCutEdges () const |
Number of edges in the 'best' (minimum conductance) cut. More... | |
int | GetCutVol () const |
Volume of the 'best' (minimum conductance) cut. More... | |
double | GetCutPhi () const |
Conductance of the 'best' (minimum conductance) cut. More... | |
int | ApproxPageRank (const int &SeedNode, const double &Eps) |
Computes Approximate PageRank from the seed node SeedNId and with tolerance Eps. More... | |
void | SupportSweep () |
After the function ApproxPageRank() has been run the SupportSweep() computes the volume, cut size, node ids, conductance vectors. More... | |
void | FindBestCut (const int &SeedNode, const int &ClustSz, const double &MinSizeFrac=0.2) |
Finds minimum conductance cut in the graph around the seed node. More... | |
void | PlotVolDistr (const TStr &OutFNm, TStr Desc=TStr()) const |
Plots the cluster volume vs. cluster size K (cluster is composed of nodes NIdV[1...K]). More... | |
void | PlotCutDistr (const TStr &OutFNm, TStr Desc=TStr()) const |
Plots the cluster cut size vs. cluster size K (cluster is composed of nodes NIdV[1...K]). More... | |
void | PlotPhiDistr (const TStr &OutFNm, TStr Desc=TStr()) const |
Plots the cluster conductance vs. cluster size K (cluster is composed of nodes NIdV[1...K]). More... | |
void | SavePajek (const TStr &OutFNm) const |
Saves the network in the Pajek format so it can be visualized. Red node represents the seed and color the cluster membership. More... | |
Static Public Member Functions | |
static void | DrawWhiskers (const PUNGraph &Graph, TStr FNmPref, const int &PlotN) |
Draws the 'whiskers' of the graph. Whiskers are small sub-graphs that are attached to the rest of the graph via a single edge. More... | |
static void | GetCutStat (const PUNGraph &Graph, const TIntV &NIdV, int &Vol, int &Cut, double &Phi, int GraphEdges=-1) |
For a given Graph and a set of nodes NIdV the function returns the Volume, CutSize and the Conductance of the cut. More... | |
static void | GetCutStat (const PUNGraph &Graph, const TIntSet &NIdSet, int &Vol, int &Cut, double &Phi, int GraphEdges=-1) |
For a given Graph and a set of nodes NIdV the function returns the Volume, CutSize and the Conductance of the cut. More... | |
static void | PlotNCP (const PUNGraph &Graph, const TStr &FNm, const TStr Desc="", const bool &BagOfWhiskers=true, const bool &RewireNet=false, const int &KMin=10, const int &KMax=Mega(100), const int &Coverage=10, const bool &SaveTxtStat=false, const bool &PlotBoltzman=false) |
Static Public Attributes | |
static bool | Verbose = true |
Private Attributes | |
PUNGraph | Graph |
int | Nodes |
int | Edges2 |
TIntFltH | ProbH |
TIntFltH | ResH |
TIntQ | NodeQ |
double | Alpha |
int | SeedNId |
TIntV | NIdV |
TIntV | VolV |
TIntV | CutV |
TFltV | PhiV |
int | BestCutIdx |
Friends | |
class | TLocClustStat |
Local Spectral Clustering algorithm.
The code implements the PageRank Nibble local clustering algorithm of Andersen, Chung and Lang. Given a single starting seed node, the algorithm will then find the clusters around that node. This is achieved by the algorithm finding the approximate personalized PageRank score of every node with respect to the Seed node. Nodes are then ordered by the PageRank score and the idea is then that by 'sweeping' the vector of PageRank scores one can find communities around the chosen seed node. The idea is to try out K = 1...N/2 and then for a set of {node_1 ... node_K} test the value of the conductance (Phi). If the conductance at certain value of K achieves a local minima, then we found a good cut in the graph. This method is also used for computing the Network Community Profile plots. See: Local Graph Partitioning using PageRank Vectors by R. Andersen, F. Chung and K. Lang URL: http://www.math.ucsd.edu/~fan/wp/localpartition.pdf
|
inline |
int TLocClust::ApproxPageRank | ( | const int & | SeedNode, |
const double & | Eps | ||
) |
Computes Approximate PageRank from the seed node SeedNId and with tolerance Eps.
The algorithm basically sets the PageRank scores of nodes with score <Eps to zero. So the lower the value of Eps the longer the algorithm will run.
Definition at line 9 of file ncp.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), Alpha, THash< TKey, TDat, THashFunc >::Clr(), TQQueue< TVal >::Clr(), TQQueue< TVal >::Empty(), THash< TKey, TDat, THashFunc >::GetDat(), TUNGraph::GetNI(), TUNGraph::GetNodes(), TUNGraph::TNodeI::GetOutDeg(), TUNGraph::TNodeI::GetOutNId(), TExeTm::GetSecs(), TExeTm::GetStr(), Graph, THash< TKey, TDat, THashFunc >::Len(), TQQueue< TVal >::Len(), Mega, NodeQ, TQQueue< TVal >::Pop(), ProbH, TQQueue< TVal >::Push(), ResH, TQQueue< TVal >::Top(), and TFlt::Val.
Referenced by FindBestCut().
|
inline |
Index K of the cut of the minimum conductance around the seed node.
This means that the set of GetNId(0)...GetNId(K) forms the best cut around the seed node.
Definition at line 73 of file ncp.h.
References BestCutIdx.
Referenced by GetCutEdges(), GetCutPhi(), GetCutVol(), and SavePajek().
|
inline |
Number of nodes inside the 'best' (minimum conductance) cut.
Definition at line 75 of file ncp.h.
Referenced by TLocClustStat::Run(), and SavePajek().
|
static |
Draws the 'whiskers' of the graph. Whiskers are small sub-graphs that are attached to the rest of the graph via a single edge.
Definition at line 172 of file ncp.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), TUNGraph::BegNI(), TStr::CStr(), TSnap::DrawGViz(), TUNGraph::EndNI(), TStr::Fmt(), TSnap::Get1CnCom(), TUNGraph::GetEdges(), TUNGraph::GetNI(), TUNGraph::GetNodes(), TSnap::GetSubGraph(), gpsLog10XY, gvlNeato, Len(), TVec< TVal, TSizeTy >::Len(), TMath::Mn(), NIdV, TGnuPlot::PlotValCntH(), and TVec< TVal, TSizeTy >::Sort().
void TLocClust::FindBestCut | ( | const int & | SeedNode, |
const int & | ClustSz, | ||
const double & | MinSizeFrac = 0.2 |
||
) |
Finds minimum conductance cut in the graph around the seed node.
Function first computes the ApproxPageRank(), initializes the SupportSweep() and then find the minimum conductance cluster. Parameter ClustSz controls the expected cluster size and is used to determine the tolerance (Eps) of the approximate PageRank calculation.
Definition at line 81 of file ncp.cpp.
References TVec< TVal, TSizeTy >::Add(), ApproxPageRank(), BestCutIdx, TVec< TVal, TSizeTy >::Clr(), THash< TKey, TDat, THashFunc >::GetKey(), TUNGraph::GetNI(), Graph, THash< TKey, TDat, THashFunc >::Len(), TVec< TVal, TSizeTy >::Len(), TFlt::Mx, NIdV, PhiV, ProbH, SeedNId, THash< TKey, TDat, THashFunc >::SortByDat(), and SupportSweep().
Referenced by TLocClustStat::Run().
|
inline |
Returns the size of the cut of the first Nodes nodes in the sweep vector.
Size of the cut is the number of edges pointing between the first Nodes nodes and the remainder of the graph.
Definition at line 55 of file ncp.h.
References Nodes.
Referenced by GetCutEdges(), and TLocClustStat::Run().
|
inline |
Number of edges in the 'best' (minimum conductance) cut.
Definition at line 77 of file ncp.h.
References BestCut(), and GetCut().
|
inline |
Conductance of the 'best' (minimum conductance) cut.
Definition at line 81 of file ncp.h.
References BestCut(), and GetPhi().
Referenced by TLocClustStat::Run().
|
static |
For a given Graph and a set of nodes NIdV the function returns the Volume, CutSize and the Conductance of the cut.
Definition at line 192 of file ncp.cpp.
References THashSet< TKey, THashFunc >::AddKey(), and TVec< TVal, TSizeTy >::Len().
Referenced by TLocClustStat::AddCut().
|
static |
For a given Graph and a set of nodes NIdV the function returns the Volume, CutSize and the Conductance of the cut.
Definition at line 198 of file ncp.cpp.
References Edges2, TUNGraph::GetEdges(), TUNGraph::GetNI(), TUNGraph::TNodeI::GetOutDeg(), TUNGraph::TNodeI::GetOutNId(), THashSet< TKey, THashFunc >::IsKey(), TUNGraph::IsNode(), and THashSet< TKey, THashFunc >::Len().
|
inline |
|
inline |
Volume of the 'best' (minimum conductance) cut.
Definition at line 79 of file ncp.h.
References BestCut(), and GetVol().
Referenced by TLocClustStat::Run().
|
inline |
|
inline |
Vector of node IDs sorted in the random walk order.
Definition at line 62 of file ncp.h.
References NIdV.
Referenced by TLocClustStat::Run().
|
inline |
Returns the conductance of the cut separating the first Nodes nodes in the sweep vector from the rest of the graph.
Conductance is the ration Cut/Volume. The lower the conductance the 'better' the cluster (higher volume, less edges cut).
Definition at line 59 of file ncp.h.
Referenced by GetCutPhi(), and TLocClustStat::Run().
|
inline |
Conducatance of the cut separating first K-nodes in the node-id vector (GetNIdV()) from the rest of the graph.
Definition at line 68 of file ncp.h.
References PhiV.
Referenced by TLocClustStat::Run().
|
inline |
Returns the support of the approximate random walk, the number of nodes with non-zero PageRank score.
Definition at line 44 of file ncp.h.
References TVec< TVal, TSizeTy >::Len().
Referenced by Len().
|
inline |
Returns the volume of the set of first NodeN nodes in the sweep vector.
Volume is defined as the sum of the degrees of the first Nodes nodes. Or in other words volume = 2* edges inside the set + the edges pointing outside the set.
Definition at line 51 of file ncp.h.
References Nodes.
Referenced by GetCutVol(), and TLocClustStat::Run().
|
inline |
|
inline |
Returns the support of the approximate random walk, the number of nodes with non-zero PageRank score.
Definition at line 42 of file ncp.h.
References GetRndWalkSup().
Referenced by DrawWhiskers(), and TLocClustStat::Run().
Plots the cluster cut size vs. cluster size K (cluster is composed of nodes NIdV[1...K]).
Definition at line 113 of file ncp.cpp.
References TVec< TVal, TSizeTy >::Add(), TGnuPlot::AddPlot(), TStr::CStr(), CutV, TStr::Empty(), TStr::Fmt(), gpwLinesPoints, TVec< TVal, TSizeTy >::Len(), TLocClustStat::MakeExpBins(), TGnuPlot::SavePng(), SeedNId, and TGnuPlot::SetXYLabel().
|
static |
Plots the Network Community Profile (NCP) of a given graph Graph. The NCP plot of a network captures the global community structure of the network. The NCP plot of a network captures the global community structure of the network. Refer to 'Community Structure in Large Networks: Natural Cluster Sizes and the Absence of Large Well-Defined Clusters by J. Leskovec, K. Lang, A. Dasgupta, M. Mahoney. Internet Mathematics 6(1) 29–123, 2009' for the explanation of how to read these plots. URL: http://arxiv.org/abs/0810.1355
Definition at line 219 of file ncp.cpp.
References TLocClustStat::AddBagOfWhiskers(), Alpha, TSnap::GenRewire(), TLocClustStat::ImposeNCP(), TLocClustStat::PlotBoltzmanCurve(), TInt::Rnd, TLocClustStat::Run(), and TLocClustStat::SaveTxtInfo().
Plots the cluster conductance vs. cluster size K (cluster is composed of nodes NIdV[1...K]).
Definition at line 126 of file ncp.cpp.
References TVec< TVal, TSizeTy >::Add(), TGnuPlot::AddPlot(), TStr::CStr(), TStr::Empty(), TStr::Fmt(), gpwLinesPoints, TVec< TVal, TSizeTy >::Len(), TLocClustStat::MakeExpBins(), PhiV, TGnuPlot::SavePng(), SeedNId, and TGnuPlot::SetXYLabel().
Plots the cluster volume vs. cluster size K (cluster is composed of nodes NIdV[1...K]).
Definition at line 100 of file ncp.cpp.
References TVec< TVal, TSizeTy >::Add(), TGnuPlot::AddPlot(), TStr::CStr(), TStr::Empty(), TStr::Fmt(), gpwLinesPoints, TVec< TVal, TSizeTy >::Len(), TLocClustStat::MakeExpBins(), TGnuPlot::SavePng(), SeedNId, TGnuPlot::SetXYLabel(), and VolV.
void TLocClust::SavePajek | ( | const TStr & | OutFNm | ) | const |
Saves the network in the Pajek format so it can be visualized. Red node represents the seed and color the cluster membership.
Definition at line 139 of file ncp.cpp.
References TUNGraph::BegNI(), BestCut(), BestCutNodes(), TStr::CStr(), TUNGraph::EndNI(), TStr::Fmt(), TUNGraph::GetEdges(), TUNGraph::GetNodes(), TVec< TStr >::GetV(), Graph, NIdV, and SeedNId.
void TLocClust::SupportSweep | ( | ) |
After the function ApproxPageRank() has been run the SupportSweep() computes the volume, cut size, node ids, conductance vectors.
Definition at line 52 of file ncp.cpp.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), CutV, Edges2, THash< TKey, TDat, THashFunc >::Empty(), THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::GetKeyId(), TUNGraph::GetNI(), TUNGraph::TNodeI::GetOutDeg(), TUNGraph::TNodeI::GetOutNId(), Graph, IAssert, THash< TKey, TDat, THashFunc >::Len(), PhiV, ProbH, and VolV.
Referenced by FindBestCut().
|
friend |
|
private |
Definition at line 32 of file ncp.h.
Referenced by ApproxPageRank(), and PlotNCP().
|
private |
Definition at line 37 of file ncp.h.
Referenced by BestCut(), and FindBestCut().
|
private |
Definition at line 35 of file ncp.h.
Referenced by GetCutV(), PlotCutDistr(), and SupportSweep().
|
private |
Definition at line 29 of file ncp.h.
Referenced by GetCutStat(), and SupportSweep().
|
private |
Definition at line 28 of file ncp.h.
Referenced by ApproxPageRank(), FindBestCut(), SavePajek(), and SupportSweep().
|
private |
Definition at line 35 of file ncp.h.
Referenced by DrawWhiskers(), FindBestCut(), GetNIdV(), and SavePajek().
|
private |
Definition at line 31 of file ncp.h.
Referenced by ApproxPageRank().
|
private |
|
private |
Definition at line 36 of file ncp.h.
Referenced by FindBestCut(), GetPhiV(), PlotPhiDistr(), and SupportSweep().
|
private |
Definition at line 30 of file ncp.h.
Referenced by ApproxPageRank(), FindBestCut(), and SupportSweep().
|
private |
Definition at line 30 of file ncp.h.
Referenced by ApproxPageRank().
|
private |
Definition at line 33 of file ncp.h.
Referenced by FindBestCut(), PlotCutDistr(), PlotPhiDistr(), PlotVolDistr(), and SavePajek().
|
static |
Definition at line 26 of file ncp.h.
Referenced by TLocClustStat::Run().
|
private |
Definition at line 35 of file ncp.h.
Referenced by GetVolV(), PlotVolDistr(), and SupportSweep().