9 template <
class PGraph> 
void PlotInDegDistr(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr=
TStr(), 
const bool& PlotCCdf=
false, 
const bool& PowerFit=
false);
 
   13 template <
class PGraph> 
void PlotOutDegDistr(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr=
TStr(), 
const bool& PlotCCdf=
false, 
const bool& PowerFit=
false);
 
   22 template <
class PGraph> 
void PlotHops(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr=
TStr(), 
const bool& IsDir=
false, 
const int& NApprox=32);
 
   46 template <
class PGraph>
 
   47 void PlotInDegDistr(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr, 
const bool& PlotCCdf, 
const bool& PowerFit) {
 
   50   const double AvgDeg = 2*Graph->GetEdges()/double(Graph->GetNodes());
 
   51   int AboveAvg=0, Above2Avg=0;
 
   52   for (
int i = 0; i < DegCntV.
Len(); i++) {
 
   53     if (DegCntV[i].Val1 > AvgDeg) { AboveAvg += DegCntV[i].Val2; }
 
   54     if (DegCntV[i].Val1 > 2*AvgDeg) { Above2Avg += DegCntV[i].Val2; }
 
   58   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
   60     TStr::Fmt(
"%s. G(%d, %d). %d (%.4f) nodes with in-deg > avg deg (%.1f), %d (%.4f) with >2*avg.deg", DescStr.
CStr(),
 
   61       Graph->GetNodes(), Graph->GetEdges(), AboveAvg, AboveAvg/double(Graph->GetNodes()), AvgDeg, Above2Avg, Above2Avg/
double(Graph->GetNodes())),
 
   65 template <
class PGraph>
 
   66 void PlotOutDegDistr(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr, 
const bool& PlotCCdf, 
const bool& PowerFit) {
 
   69   const double AvgDeg = 2*Graph->GetEdges()/double(Graph->GetNodes());
 
   70   int AboveAvg=0, Above2Avg=0;
 
   71   for (
int i = 0; i < DegCntV.
Len(); i++) {
 
   72     if (DegCntV[i].Val1 > AvgDeg) { AboveAvg += DegCntV[i].Val2; }
 
   73     if (DegCntV[i].Val1 > 2*AvgDeg) { Above2Avg += DegCntV[i].Val2; }
 
   77   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
   79     TStr::Fmt(
"%s. G(%d, %d). %d (%.4f) nodes with out-deg > avg deg (%.1f), %d (%.4f) with >2*avg.deg", DescStr.
CStr(),
 
   80       Graph->GetNodes(), Graph->GetEdges(), AboveAvg, AboveAvg/double(Graph->GetNodes()), AvgDeg, Above2Avg, Above2Avg/
double(Graph->GetNodes())),
 
   84 template <
class PGraph>
 
   88   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
   89   TGnuPlot GnuPlot(
"wcc."+FNmPref, 
TStr::Fmt(
"%s. G(%d, %d). Largest component has %f nodes",
 
   90     DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges(), WccSzCnt.
Last().
Val1/double(Graph->GetNodes())));
 
   92   GnuPlot.SetXYLabel(
"Size of weakly connected component", 
"Number of components");
 
   97 template <
class PGraph>
 
  101   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  102   TGnuPlot GnuPlot(
"scc."+FNmPref, 
TStr::Fmt(
"%s. G(%d, %d). Largest component has %f nodes",
 
  103     DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges(), SccSzCnt.
Last().
Val1/double(Graph->GetNodes())));
 
  105   GnuPlot.SetXYLabel(
"Size of strongly connected component", 
"Number of components");
 
  110 template <
class PGraph>
 
  113   int64 ClosedTriads, OpenTriads;
 
  114   const double CCF = 
GetClustCf(Graph, DegToCCfV, ClosedTriads, OpenTriads);
 
  115   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  117     TStr::Fmt(
"%s. G(%d, %d). Average clustering: %.4f  OpenTriads: %d (%.4f)  ClosedTriads: %d (%.4f)", DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges(),
 
  118     CCF, OpenTriads, OpenTriads/double(OpenTriads+ClosedTriads), ClosedTriads, ClosedTriads/double(OpenTriads+ClosedTriads)));
 
  120   GnuPlot.
SetXYLabel(
"Node degree", 
"Average clustering coefficient");
 
  125 template <
class PGraph>
 
  126 void PlotHops(
const PGraph& Graph, 
const TStr& FNmPref, 
TStr DescStr, 
const bool& IsDir, 
const int& NApprox) {
 
  130   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  131   TGnuPlot GnuPlot(
"hop."+FNmPref, 
TStr::Fmt(
"%s. Hop plot. EffDiam: %g, G(%d, %d)",
 
  132     DescStr.
CStr(), EffDiam, Graph->GetNodes(), Graph->GetEdges()));
 
  133   GnuPlot.
SetXYLabel(
"Number of hops", 
"Number of pairs of nodes");
 
  139 template <
class PGraph>
 
  146   for (
int tries = 0; tries < 
TMath::Mn(TestNodes, Graph->GetNodes()); tries++) {
 
  147     const int NId = NodeIdV[tries];
 
  154   for (
int i = 0; i < DistToCntH.
Len(); i++) {
 
  159   const int FullDiam = (int) DistNbrsPdfV.
Last().Val1;
 
  160   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  162     TStr::Fmt(
"%s. G(%d, %d). Diam: avg:%.2f  eff:%.2f  max:%d", DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges(),
 
  166 template <
class PGraph>
 
  170   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  171   TGnuPlot::PlotValV(CoreNodesV, 
"coreNodes."+FNmPref, 
TStr::Fmt(
"%s. G(%d, %d).", DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges()), 
"k-Core", 
"Number of nodes in the k-Core", 
gpsLog10Y, 
false, 
gpwLinesPoints);
 
  174 template <
class PGraph>
 
  178   if (DescStr.
Empty()) { DescStr = FNmPref; }
 
  179   TGnuPlot::PlotValV(CoreEdgesV, 
"coreEdges."+FNmPref, 
TStr::Fmt(
"%s. G(%d, %d).", DescStr.
CStr(), Graph->GetNodes(), Graph->GetEdges()), 
"k-Core", 
"Number of edges in the k-Core", 
gpsLog10Y, 
false, 
gpwLinesPoints);
 
void PlotSccDistr(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr())
Plots the distribution of sizes of strongly connected components of a Graph. 
 
static const T & Mn(const T &LVal, const T &RVal)
 
Main namespace for all the Snap global entities. 
 
int GetKCoreNodes(const PGraph &Graph, TIntPrV &CoreIdSzV)
Returns the number of nodes in each core of order K (where K=0, 1, ...) 
 
void PlotKCoreNodes(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr())
Plots the k-Core node-size distribution: Core k vs. number of nodes in k-core. 
 
void GetOutDegCnt(const PGraph &Graph, TIntPrV &DegToCntV)
Returns an out-degree histogram: a set of pairs (out-degree, number of nodes of such out-degree) ...
 
void SavePng(const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr())
 
void PlotOutDegDistr(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr(), const bool &PlotCCdf=false, const bool &PowerFit=false)
 
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...
 
TSizeTy Len() const 
Returns the number of elements in the vector. 
 
void GetAnf(const PGraph &Graph, const int &SrcNId, TIntFltKdV &DistNbrsV, const int &MxDist, const bool &IsDir, const int &NApprox=32)
 
void SetXYLabel(const TStr &XLabel, const TStr &YLabel)
 
void PlotSngValRank(const PNGraph &Graph, const int &SngVals, const TStr &FNmPref, TStr DescStr)
Plots the rank distribution of singular values of the Graph adjacency matrix. Plots first SngVals val...
 
void PlotEigValRank(const PUNGraph &Graph, const int &EigVals, const TStr &FNmPref, TStr DescStr)
Plots the eigen-value rank distribution of the Graph adjacency matrix. Plots first EigVals eigenvalue...
 
void PlotEigValDistr(const PUNGraph &Graph, const int &EigVals, const TStr &FNmPref, TStr DescStr)
Plots the distribution of components of the leading eigen-vector of the Graph adjacency matrix...
 
void PlotInvParticipRat(const PUNGraph &Graph, const int &MaxEigVecs, const int &TimeLimit, const TStr &FNmPref, TStr DescStr)
 
void GetSccSzCnt(const PGraph &Graph, TIntPrV &SccSzCnt)
Returns a distribution of strongly connected component sizes. 
 
void GetInDegCnt(const PGraph &Graph, TIntPrV &DegToCntV)
Returns an in-degree histogram: a set of pairs (in-degree, number of nodes of such in-degree) ...
 
void PlotWccDistr(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr())
Plots the distribution of sizes of weakly connected components of a Graph. 
 
double CalcEffDiamPdf(const TIntFltKdV &DistNbrsPdfV, const double &Percentile)
Helper function for computing a given Percentile of a (unnormalized) probability distribution functio...
 
int GetKCoreEdges(const PGraph &Graph, TIntPrV &CoreIdSzV)
Returns the number of edges in each core of order K (where K=0, 1, ...) 
 
const TVal & Last() const 
Returns a reference to the last element of the vector. 
 
void PlotSngValDistr(const PNGraph &Graph, const int &SngVals, const TStr &FNmPref, TStr DescStr)
Plots the rank distribution of singular values of the Graph adjacency matrix. Plots first SngVals val...
 
TPair< TFlt, TFlt > TFltPr
 
void PlotKCoreEdges(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr())
Plots the k-Core edge-size distribution: Core k vs. number of edges in k-core. 
 
void PlotHops(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr(), const bool &IsDir=false, const int &NApprox=32)
 
void PlotSngVec(const PNGraph &Graph, const TStr &FNmPref, TStr DescStr)
Plots the distribution of the values of the leading left singular vector of the Graph adjacency matri...
 
void SortByKey(const bool &Asc=true)
 
static void GetCCdf(const TIntPrV &PdfV, TIntPrV &CCdfV)
 
double CalcAvgDiamPdf(const TIntFltKdV &DistNbrsPdfV)
Helper function for computing the mean of a (unnormalized) probability distribution function...
 
double CalcEffDiam(const TIntFltKdV &DistNbrsCdfV, const double &Percentile)
Helper function for computing a given Percentile of a (unnormalized) cumulative distribution function...
 
void SetScale(const TGpScaleTy &GpScaleTy)
 
static TStr Fmt(const char *FmtStr,...)
 
void PlotShortPathDistr(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr(), int TestNodes=TInt::Mx)
Plots the distribution of the shortest path lengths of a Graph. Implementation is based on BFS...
 
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector. 
 
void PlotClustCf(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr())
Plots the distribution of clustering coefficient of a Graph. 
 
double GetClustCf(const PGraph &Graph, int SampleNodes=-1)
Computes the average clustering coefficient as defined in Watts and Strogatz, Collective dynamics of ...
 
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element. 
 
TDat & AddDat(const TKey &Key)
 
void GetWccSzCnt(const PGraph &Graph, TIntPrV &WccSzCnt)
Returns a distribution of weakly connected component sizes. 
 
static void PlotValV(const TVec< TVal1 > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
 
void PlotInDegDistr(const PGraph &Graph, const TStr &FNmPref, TStr DescStr=TStr(), const bool &PlotCCdf=false, const bool &PowerFit=false)
 
const TKey & GetKey(const int &KeyId) const