SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
00001 00002 // Graph Statistics 00003 // statistics of a single snapshot of a graph 00004 class TGStat; 00005 typedef TPt<TGStat> PGStat; 00006 typedef TVec<PGStat> TGStatV; 00007 00008 // statistics of a sequence of graph snapshots 00009 class TGStatVec; 00010 typedef TPt<TGStatVec> PGStatVec; 00011 00013 // Statistics of a Sigle Graph 00014 // Scalar statistics of the graph 00015 typedef enum { 00016 gsvNone, gsvIndex, gsvTime, gsvNodes, gsvZeroNodes, gsvNonZNodes, gsvSrcNodes, gsvDstNodes, 00017 gsvEdges, gsvUniqEdges, gsvBiDirEdges, 00018 gsvWccNodes, gsvWccSrcNodes, gsvWccDstNodes, gsvWccEdges, gsvWccUniqEdges, gsvWccBiDirEdges, 00019 gsvSccNodes, gsvSccEdges,gsvBccNodes, gsvBccEdges, 00020 gsvFullDiam, gsvEffDiam, gsvEffWccDiam, gsvFullWccDiam, 00021 gsvFullDiamDev, gsvEffDiamDev, gsvEffWccDiamDev, gsvFullWccDiamDev, // diameter+variance 00022 gsvClustCf, gsvOpenTriads, gsvClosedTriads, gsvWccSize, gsvSccSize, gsvBccSize, 00023 gsvMx 00024 } TGStatVal; 00025 00026 // Distribution statistics of the graph 00027 typedef enum { 00028 gsdUndef=100, gsdInDeg, gsdOutDeg, gsdWcc, gsdScc, 00029 gsdHops, gsdWccHops, gsdSngVal, gsdSngVec, gsdClustCf, 00030 gsdTriadPart, // triad participation 00031 gsdMx, 00032 } TGStatDistr; 00033 00036 class TGStat { 00037 public: 00038 static int NDiamRuns; 00039 static int TakeSngVals; 00040 typedef TQuad<TStr, TStr, TStr, TGpScaleTy> TPlotInfo; // file prefix, x label, y label, scale 00041 public: 00042 class TCmpByVal { 00043 private: 00044 TGStatVal ValCmp; 00045 bool SortAsc; 00046 public: 00047 TCmpByVal(TGStatVal SortBy, bool Asc) : ValCmp(SortBy), SortAsc(Asc) { } 00048 bool operator () (const TGStat& GS1, const TGStat& GS2) const; 00049 bool operator () (const PGStat& GS1, const PGStat& GS2) const; 00050 }; 00051 private: 00052 const static TFltPrV EmptyV; 00053 TCRef CRef; 00054 public: 00055 TSecTm Time; 00056 TStr GraphNm; 00057 TIntFltH ValStatH; // scalar statistics 00058 THash<TInt, TFltPrV> DistrStatH; // distribution statistics 00059 public: 00060 TGStat(const TSecTm& GraphTm = TSecTm(), const TStr& GraphName=TStr()); 00061 TGStat(const PNGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), const TStr& GraphName=TStr()); 00062 TGStat(const PUNGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), const TStr& GraphName=TStr()); 00063 TGStat(const PNEGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), const TStr& GraphName=TStr()); 00064 template <class PGraph> TGStat(const PGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), const TStr& GraphName=TStr()) { 00065 TakeStat(Graph, Time, StatFSet, GraphName); } 00066 TGStat(const TGStat& GStat); 00067 TGStat(TSIn& SIn); 00068 void Save(TSOut& SOut) const; 00069 static PGStat New(const TSecTm& Time=TSecTm(), const TStr& GraphName=TStr()) { 00070 return new TGStat(Time, GraphName); } 00071 static PGStat New(const PNGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), 00072 const TStr& GraphNm=TStr()) { return new TGStat(Graph, Time, StatFSet, GraphNm); } 00073 static PGStat New(const PUNGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), 00074 const TStr& GraphNm=TStr()) { return new TGStat(Graph, Time, StatFSet, GraphNm); } 00075 static PGStat New(const PNEGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), 00076 const TStr& GraphNm=TStr()) { return new TGStat(Graph, Time, StatFSet, GraphNm); } 00077 template <class PGraph> PGStat New(const PGraph& Graph, const TSecTm& Time, TFSet StatFSet=TFSet(), 00078 const TStr& GraphNm=TStr()) { return new TGStat(Graph, Time, StatFSet, GraphNm); } 00079 static PGStat Load(TSIn& SIn) { return new TGStat(SIn); } 00080 PGStat Clone() const { return new TGStat(*this); } 00081 TGStat& operator = (const TGStat& GStat); 00082 bool operator == (const TGStat& GStat) const; 00083 bool operator < (const TGStat& GStat) const; 00084 00085 int GetYear() const { return Time.GetYearN(); } 00086 int GetMonth() const { return Time.GetMonthN(); } 00087 int GetDay() const { return Time.GetDayN(); } 00088 int GetHour() const { return Time.GetHourN(); } 00089 int GetMin() const { return Time.GetMinN(); } 00090 int GetSec() const { return Time.GetSecN(); } 00091 TStr GetTmStr() const { return Time.GetStr(); } 00092 void SetTm(const TSecTm& GraphTm) { Time = GraphTm; } 00093 TStr GetNm() const { return GraphNm; } 00094 void SetNm(const TStr& GraphName) { GraphNm=GraphName; } 00095 int GetTime(const TTmUnit& TimeUnit) const { return Time.GetInUnits(TimeUnit); } 00096 00097 int GetVals() const { return ValStatH.Len(); } 00098 bool HasVal(const TGStatVal& StatVal) const; 00099 double GetVal(const TGStatVal& StatVal) const; 00100 void SetVal(const TGStatVal& StatVal, const double& Val); 00101 int GetDistrs() const { return DistrStatH.Len(); } 00102 bool HasDistr(const TGStatDistr& Distr) const { return DistrStatH.IsKey(Distr); } 00103 const TFltPrV& GetDistr(const TGStatDistr& Distr) const; 00104 void GetDistr(const TGStatDistr& Distr, TFltPrV& FltPrV) const; 00105 void SetDistr(const TGStatDistr& Distr, const TFltPrV& FltPrV); 00106 00107 int GetNodes() const { return (int) GetVal(gsvNodes); } 00108 int GetEdges() const { return (int) GetVal(gsvEdges); } 00109 00110 void TakeStat(const PNGraph& Graph, const TSecTm& Time, TFSet StatFSet, const TStr& GraphName); 00111 void TakeStat(const PUNGraph& Graph, const TSecTm& Time, TFSet StatFSet, const TStr& GraphName); 00112 template <class PGraph> void TakeStat(const PGraph& Graph, const TSecTm& Time, TFSet StatFSet, const TStr& GraphName); 00113 template <class PGraph> void TakeBasicStat(const PGraph& Graph, const bool& IsMxWcc=false); 00114 template <class PGraph> void TakeBasicStat(const PGraph& Graph, TFSet FSet, const bool& IsMxWcc=false); 00115 template <class PGraph> void TakeSccStat(const PGraph& Graph, TFSet StatFSet); 00116 template <class PGraph> void TakeBccStat(const PGraph& Graph, TFSet StatFSet); 00117 template <class PGraph> void TakeDegDistr(const PGraph& Graph); 00118 template <class PGraph> void TakeDegDistr(const PGraph& Graph, TFSet StatFSet); 00119 template <class PGraph> void TakeDiam(const PGraph& Graph, const bool& IsMxWcc=false); 00120 template <class PGraph> void TakeDiam(const PGraph& Graph, TFSet StatFSet, const bool& IsMxWcc=false); 00121 template <class PGraph> void TakeConnComp(const PGraph& Graph); 00122 template <class PGraph> void TakeConnComp(const PGraph& Graph, TFSet StatFSet); 00123 template <class PGraph> void TakeClustCf(const PGraph& Graph, const int& SampleNodes=-1); 00124 template <class PGraph> void TakeTriadPart(const PGraph& Graph); 00125 void TakeSpectral(const PNGraph& Graph, const int _TakeSngVals = -1); 00126 void TakeSpectral(const PNGraph& Graph, TFSet StatFSet, int _TakeSngVals = -1); 00127 00128 void Plot(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc=TStr(), bool PowerFit=false) const; 00129 void Plot(const TFSet& FSet, const TStr& FNmPref, TStr Desc=TStr(), bool PowerFit=false) const; 00130 void PlotAll(const TStr& FNmPref, TStr Desc=TStr(), bool PowerFit=false) const; 00131 void DumpValStat(); 00132 00133 void AvgGStat(const PGStatVec& GStatVec, const bool& ClipAt1=false); 00134 void AvgGStat(const TGStatV& GStatV, const bool& ClipAt1=false); 00135 00136 // take graph statistics (see TTakeGStat) 00137 static TStr GetDistrStr(const TGStatDistr& Distr); 00138 static TStr GetValStr(const TGStatVal& Val); 00139 static TPlotInfo GetPlotInfo(const TGStatVal& Val); 00140 static TPlotInfo GetPlotInfo(const TGStatDistr& Distr); 00141 static TFSet NoStat(); 00142 static TFSet BasicStat(); 00143 static TFSet DegDStat(); 00144 static TFSet NoDiamStat(); 00145 static TFSet NoDistrStat(); 00146 static TFSet NoSvdStat(); 00147 static TFSet AllStat(); 00148 00149 friend class TCmpByVal; 00150 friend class TPt<TGStat>; 00151 }; 00152 00153 //#////////////////////////////////////////////// 00155 class TGStatVec { 00156 public: 00157 static uint MinNodesEdges; 00158 private: 00159 TCRef CRef; 00160 TTmUnit TmUnit; 00161 TFSet StatFSet; 00162 TGStatV GStatV; // each snapshot (TVec<PGStat>) 00163 public: 00164 TGStatVec(const TTmUnit& _TmUnit=tmu1Sec); 00165 TGStatVec(const TTmUnit& _TmUnit, const TFSet& TakeGrowthStat); 00166 TGStatVec(const TGStatVec& GStat); 00167 static PGStatVec New(const TTmUnit& _TmUnit=tmu1Sec); 00168 static PGStatVec New(const TTmUnit& _TmUnit, const TFSet& TakeGrowthStat); 00169 static PGStatVec Load(TSIn& SIn) { return new TGStatVec(SIn); } 00170 TGStatVec(TSIn& SIn); 00171 void Save(TSOut& SOut) const; 00172 TGStatVec& operator = (const TGStatVec& GStat); 00173 00174 PGStat Add(); 00175 PGStat Add(const TSecTm& Time, TStr GraphNm=TStr()); 00176 void Add(const PGStat& Growth) { GStatV.Add(Growth); } 00177 void Add(const PNGraph& Graph, const TSecTm& Time, const TStr& GraphNm=TStr()); 00178 void Add(const PUNGraph& Graph, const TSecTm& Time, const TStr& GraphNm=TStr()); 00179 void Add(const PNEGraph& Graph, const TSecTm& Time, const TStr& GraphNm=TStr()); 00180 void Clr() { GStatV.Clr(); } 00181 void Sort(const TGStatVal& SortBy=gsvNodes, const bool& Asc=true); 00182 00183 int Len() const { return GStatV.Len(); } 00184 bool Empty() const { return GStatV.Empty(); } 00185 PGStat operator[](const int& ValN) const { return GStatV[ValN]; } 00186 PGStat At(const int& ValN) const { return GStatV[ValN]; } 00187 PGStat Last() const { return GStatV.Last(); } 00188 const TGStatV& GetGStatV() const { return GStatV; } 00189 int GetTime(const int& ValN) const { return At(ValN)->GetTime(TmUnit); } 00190 00191 void Del(const int& ValN) { GStatV.Del(ValN); } 00192 void DelLast() { GStatV.DelLast(); } 00193 void DelBefore(const TSecTm& Tm); 00194 void DelAfter(const TSecTm& Tm); 00195 void DelSmallNodes(const int& MinNodes); 00196 00197 void SetTmUnit(const TTmUnit& TimeUnit) { TmUnit = TimeUnit; } 00198 TTmUnit GetTmUnit() const { return TmUnit; } 00199 void SetTakeStat(const TFSet& TakeStatSet) { StatFSet = TakeStatSet; } 00200 bool HasVal(const TGStatVal& Stat) const { return StatFSet.In(Stat); } 00201 bool HasDistr(const TGStatDistr& Stat) const { return StatFSet.In(Stat); } 00202 00203 void GetValV(const TGStatVal& XVal, const TGStatVal& YVal, TFltPrV& ValV) const; 00204 PGStat GetAvgGStat(const bool& ClipAt1=false); 00205 00206 void Plot(const TGStatVal& XVal, const TGStatVal& YVal, const TStr& OutFNm, TStr& Desc, 00207 const TGpScaleTy& Scale=gpsAuto, const bool& PowerFit=false) const; 00208 void PlotAllVsX(const TGStatVal& XVal, const TStr& OutFNm, TStr Desc=TStr(), const TGpScaleTy& Scale=gpsAuto, const bool& PowerFit=false) const; 00209 void ImposeDistr(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc=TStr(), const bool& ExpBin=false, 00210 const bool& PowerFit=false, const TGpSeriesTy& PlotWith=gpwLinesPoints, const TStr& Style="") const; 00211 00212 void SaveTxt(const TStr& FNmPref, const TStr& Desc) const; 00213 friend class TPt<TGStatVec>; 00214 }; 00215 00217 // Implementation 00218 template <class PGraph> 00219 void TGStat::TakeStat(const PGraph& Graph, const TSecTm& _Time, TFSet StatFSet, const TStr& GraphName) { 00220 printf("**TakeStat: G(%u, %u)\n", Graph->GetNodes(), Graph->GetEdges()); 00221 TExeTm ExeTm, FullTm; 00222 Time = _Time; 00223 GraphNm = GraphName; 00224 if (StatFSet.In(gsvNone)) { return; } 00225 TakeBasicStat(Graph, false); 00226 TakeSccStat(Graph, StatFSet); 00227 TakeBccStat(Graph, StatFSet); 00228 if (StatFSet.In(gsdWcc)) { 00229 PGraph WccG = TSnap::GetMxWcc(Graph); 00230 TakeBasicStat(WccG, true); 00231 SetVal(gsvWccSize, WccG->GetNodes()/double(Graph->GetNodes())); 00232 } 00233 // degrees 00234 TakeDegDistr(Graph, StatFSet); 00235 if (StatFSet.In(gsvFullDiam) || StatFSet.In(gsvEffDiam) || StatFSet.In(gsdHops) || 00236 StatFSet.In(gsvEffWccDiam) || StatFSet.In(gsdWccHops) || StatFSet.In(gsdWcc) || StatFSet.In(gsdScc) || 00237 StatFSet.In(gsdClustCf) || StatFSet.In(gsvClustCf) || StatFSet.In(gsdTriadPart)) { 00238 PNGraph NGraph = TSnap::ConvertGraph<PNGraph>(Graph, true); 00239 // diameter 00240 TakeDiam(NGraph, StatFSet, false); 00241 // components 00242 TakeConnComp(NGraph, StatFSet); 00243 // spectral 00244 TakeSpectral(NGraph, StatFSet, -1); 00245 // clustering coeffient 00246 if (StatFSet.In(gsdClustCf) || StatFSet.In(gsvClustCf)) { 00247 TakeClustCf(NGraph); } 00248 if (StatFSet.In(gsdTriadPart)) { 00249 TakeTriadPart(NGraph); } 00250 if (StatFSet.In(gsvFullDiam) || StatFSet.In(gsvEffWccDiam)) { 00251 TakeDiam(TSnap::GetMxWcc(NGraph), StatFSet, true); } 00252 printf("**[%s]\n", FullTm.GetTmStr()); 00253 } 00254 } 00255 00256 template <class PGraph> 00257 void TGStat::TakeBasicStat(const PGraph& Graph, const bool& IsMxWcc) { 00258 TakeBasicStat(Graph, TFSet() | gsvBiDirEdges | gsvWccBiDirEdges, IsMxWcc); 00259 } 00260 00261 template <class PGraph> 00262 void TGStat::TakeBasicStat(const PGraph& Graph, TFSet FSet, const bool& IsMxWcc) { 00263 TExeTm ExeTm; 00264 if (! IsMxWcc) { 00265 // gsvNodes, gsvZeroNodes, gsvNonZNodes, gsvSrcNodes, gsvDstNodes, 00266 // gsvEdges, gsvUniqEdges, gsvBiDirEdges 00267 printf("basic..."); 00268 const int Nodes = Graph->GetNodes(); 00269 SetVal(gsvNodes, Nodes); 00270 SetVal(gsvZeroNodes, TSnap::CntDegNodes(Graph, 0)); 00271 SetVal(gsvNonZNodes, Nodes - GetVal(gsvZeroNodes)); 00272 SetVal(gsvSrcNodes, Nodes - TSnap::CntOutDegNodes(Graph, 0)); 00273 SetVal(gsvDstNodes, Nodes - TSnap::CntInDegNodes(Graph, 0)); 00274 SetVal(gsvEdges, Graph->GetEdges()); 00275 if (! Graph->HasFlag(gfMultiGraph)) { SetVal(gsvUniqEdges, Graph->GetEdges()); } 00276 else { SetVal(gsvUniqEdges, TSnap::CntUniqDirEdges(Graph)); } 00277 if (FSet.In(gsvBiDirEdges)) { 00278 if (Graph->HasFlag(gfDirected)) { SetVal(gsvBiDirEdges, TSnap::CntUniqBiDirEdges(Graph)); } 00279 else { SetVal(gsvUniqEdges, GetVal(gsvEdges)); } 00280 } 00281 printf("[%s] ", ExeTm.GetTmStr()); 00282 } else { 00283 // gsvWccNodes, gsvWccSrcNodes, gsvWccDstNodes, gsvWccEdges, gsvWccUniqEdges, gsvWccBiDirEdges 00284 printf("basic wcc..."); 00285 const int Nodes = Graph->GetNodes(); 00286 SetVal(gsvWccNodes, Nodes); 00287 SetVal(gsvWccSrcNodes, Nodes - TSnap::CntOutDegNodes(Graph, 0)); 00288 SetVal(gsvWccDstNodes, Nodes - TSnap::CntInDegNodes(Graph, 0)); 00289 SetVal(gsvWccEdges, Graph->GetEdges()); 00290 if (! Graph->HasFlag(gfMultiGraph)) { SetVal(gsvWccUniqEdges, Graph->GetEdges()); } 00291 else { SetVal(gsvWccUniqEdges, TSnap::CntUniqDirEdges(Graph)); } 00292 if (FSet.In(gsvBiDirEdges)) { 00293 if (Graph->HasFlag(gfDirected)) { SetVal(gsvWccBiDirEdges, TSnap::CntUniqBiDirEdges(Graph)); } 00294 else { SetVal(gsvUniqEdges, GetVal(gsvEdges)); } 00295 } 00296 printf("[%s] ", ExeTm.GetTmStr()); 00297 } 00298 } 00299 00300 template <class PGraph> 00301 void TGStat::TakeDegDistr(const PGraph& Graph) { 00302 TakeDegDistr(Graph, TFSet() | gsdInDeg | gsdOutDeg); 00303 } 00304 00305 template <class PGraph> 00306 void TGStat::TakeDegDistr(const PGraph& Graph, TFSet StatFSet) { 00307 TExeTm ExeTm; 00308 // degree distribution 00309 if (StatFSet.In(gsdOutDeg) || StatFSet.In(gsdOutDeg)) { 00310 printf("deg:"); } 00311 if (StatFSet.In(gsdInDeg)) { 00312 printf("-in"); 00313 TFltPrV& InDegV = DistrStatH.AddDat(gsdInDeg); 00314 TSnap::GetInDegCnt(Graph, InDegV); 00315 } 00316 if (StatFSet.In(gsdOutDeg)) { 00317 printf("-out"); 00318 TFltPrV& OutDegV = DistrStatH.AddDat(gsdOutDeg); 00319 TSnap::GetOutDegCnt(Graph, OutDegV); 00320 } 00321 if (StatFSet.In(gsdOutDeg) || StatFSet.In(gsdOutDeg)) { 00322 printf("[%s] ", ExeTm.GetTmStr()); } 00323 } 00324 00325 template <class PGraph> 00326 void TGStat::TakeDiam(const PGraph& Graph, const bool& IsMxWcc) { 00327 TakeDiam(Graph, TFSet() | gsvFullDiam | gsvEffDiam | gsdHops | 00328 gsvEffWccDiam| gsdWccHops, IsMxWcc); 00329 } 00330 00331 template <class PGraph> 00332 void TGStat::TakeDiam(const PGraph& Graph, TFSet StatFSet, const bool& IsMxWcc) { 00333 TExeTm ExeTm; 00334 if (! IsMxWcc) { 00335 if (StatFSet.In(gsvFullDiam) || StatFSet.In(gsvEffDiam) || StatFSet.In(gsdHops)) { 00336 printf("anf:%druns...", NDiamRuns); } 00337 //bool Line=false; 00338 if (StatFSet.In(gsvEffDiam) || StatFSet.In(gsdHops)) { 00339 TMom DiamMom; ExeTm.Tick(); 00340 TIntFltKdV DistNbrsV; 00341 for (int r = 0; r < NDiamRuns; r++) { 00342 TSnap::GetAnf(Graph, DistNbrsV, -1, false, 32); 00343 DiamMom.Add(TSnap::TSnapDetail::CalcEffDiam(DistNbrsV, 0.9)); 00344 printf("."); 00345 } 00346 DiamMom.Def(); 00347 SetVal(gsvEffDiam, DiamMom.GetMean()); 00348 SetVal(gsvEffDiamDev, DiamMom.GetSDev()); 00349 TFltPrV& HopsV = DistrStatH.AddDat(gsdHops); 00350 HopsV.Gen(DistNbrsV.Len(), 0); 00351 for (int i = 0; i < DistNbrsV.Len(); i++) { 00352 HopsV.Add(TFltPr(DistNbrsV[i].Key(), DistNbrsV[i].Dat)); } 00353 printf(" anf-eff %.1f[%s]", DiamMom.GetMean(), ExeTm.GetTmStr()); 00354 //Line=true; 00355 } 00356 } else { 00357 if (StatFSet.In(gsvEffWccDiam) || StatFSet.In(gsdWccHops)) { printf("wcc diam..."); } 00358 //bool Line=false; 00359 if (StatFSet.In(gsvFullDiam)) { 00360 TMom DiamMom; ExeTm.Tick(); 00361 for (int r = 0; r < NDiamRuns; r++) { 00362 DiamMom.Add(TSnap::GetBfsFullDiam(Graph, 1, false)); 00363 printf("."); } 00364 DiamMom.Def(); 00365 SetVal(gsvFullDiam, DiamMom.GetMean()); 00366 SetVal(gsvFullDiamDev, DiamMom.GetSDev()); 00367 printf(" bfs-full %g[%s]", DiamMom.GetMean(), ExeTm.GetTmStr()); 00368 //Line=true; 00369 } 00370 if (StatFSet.In(gsvEffWccDiam) || StatFSet.In(gsdWccHops)) { 00371 TMom DiamMom; ExeTm.Tick(); 00372 TIntFltKdV DistNbrsV; 00373 for (int r = 0; r < NDiamRuns; r++) { 00374 TSnap::GetAnf(Graph, DistNbrsV, -1, false, 32); 00375 DiamMom.Add(TSnap::TSnapDetail::CalcEffDiam(DistNbrsV, 0.9)); 00376 printf("."); 00377 } 00378 DiamMom.Def(); 00379 SetVal(gsvEffWccDiam, DiamMom.GetMean()); 00380 SetVal(gsvEffWccDiamDev, DiamMom.GetSDev()); 00381 TFltPrV& WccHopsV = DistrStatH.AddDat(gsdWccHops); 00382 WccHopsV.Gen(DistNbrsV.Len(), 0); 00383 for (int i = 0; i < DistNbrsV.Len(); i++) { 00384 WccHopsV.Add(TFltPr(DistNbrsV[i].Key(), DistNbrsV[i].Dat)); } 00385 printf(" anf-wcceff %.1f[%s]", DiamMom.GetMean(), ExeTm.GetTmStr()); 00386 //Line=true; 00387 } 00388 } 00389 } 00390 00391 template <class PGraph> 00392 void TGStat::TakeConnComp(const PGraph& Graph) { 00393 TakeConnComp(Graph, TFSet() | gsdWcc | gsdScc); 00394 } 00395 00396 template <class PGraph> 00397 void TGStat::TakeConnComp(const PGraph& Graph, TFSet StatFSet) { 00398 TExeTm ExeTm; 00399 if (StatFSet.In(gsdWcc)) { 00400 printf("wcc..."); 00401 TIntPrV WccSzCntV1; 00402 TSnap::GetWccSzCnt(Graph, WccSzCntV1); 00403 TFltPrV& WccSzCntV = DistrStatH.AddDat(gsdWcc); 00404 WccSzCntV.Gen(WccSzCntV1.Len(), 0); 00405 for (int i = 0; i < WccSzCntV1.Len(); i++) 00406 WccSzCntV.Add(TFltPr(WccSzCntV1[i].Val1(), WccSzCntV1[i].Val2())); 00407 } 00408 if (StatFSet.In(gsdScc)) { 00409 printf("scc..."); 00410 TIntPrV SccSzCntV1; 00411 TSnap::GetSccSzCnt(Graph, SccSzCntV1); 00412 TFltPrV& SccSzCntV = DistrStatH.AddDat(gsdScc); 00413 SccSzCntV.Gen(SccSzCntV1.Len(), 0); 00414 for (int i = 0; i < SccSzCntV1.Len(); i++) 00415 SccSzCntV.Add(TFltPr(SccSzCntV1[i].Val1(), SccSzCntV1[i].Val2())); 00416 } 00417 if (StatFSet.In(gsdWcc) || StatFSet.In(gsdScc)) { printf("[%s] ", ExeTm.GetTmStr()); } 00418 } 00419 00420 template <class PGraph> 00421 void TGStat::TakeSccStat(const PGraph& Graph, TFSet StatFSet) { 00422 TExeTm ExeTm; 00423 if (StatFSet.In(gsvSccNodes) || StatFSet.In(gsvSccEdges) || StatFSet.In(gsvSccSize)) { 00424 printf("scc..."); 00425 PGraph SccG = TSnap::GetMxScc(Graph); 00426 SetVal(gsvSccNodes, SccG->GetNodes()); 00427 SetVal(gsvSccEdges, SccG->GetEdges()); 00428 SetVal(gsvSccSize, SccG->GetNodes()/double(Graph->GetNodes())); 00429 printf("[%s] ", ExeTm.GetTmStr()); 00430 } 00431 } 00432 00433 template <class PGraph> 00434 void TGStat::TakeBccStat(const PGraph& Graph, TFSet StatFSet) { 00435 TExeTm ExeTm; 00436 if (StatFSet.In(gsvBccNodes) || StatFSet.In(gsvBccEdges) || StatFSet.In(gsvBccSize)) { 00437 printf("bcc..."); 00438 PGraph BccG = TSnap::GetMxBiCon(Graph); 00439 SetVal(gsvBccNodes, BccG->GetNodes()); 00440 SetVal(gsvBccEdges, BccG->GetEdges()); 00441 SetVal(gsvBccSize, BccG->GetNodes()/double(Graph->GetNodes())); 00442 printf("[%s] ", ExeTm.GetTmStr()); 00443 } 00444 } 00445 00446 template <class PGraph> 00447 void TGStat::TakeClustCf(const PGraph& Graph, const int& SampleNodes) { 00448 TExeTm ExeTm; 00449 printf("clustcf..."); 00450 TFltPrV& ClustCfV = DistrStatH.AddDat(gsdClustCf); 00451 int64 Open, Close; 00452 const double ClustCf = TSnap::GetClustCf(Graph, ClustCfV, Close, Open, SampleNodes); 00453 SetVal(gsvClustCf, ClustCf); 00454 SetVal(gsvOpenTriads, Open); 00455 SetVal(gsvClosedTriads, Close); 00456 printf("[%s] ", ExeTm.GetTmStr()); 00457 } 00458 00459 template <class PGraph> 00460 void TGStat::TakeTriadPart(const PGraph& Graph) { 00461 TExeTm ExeTm; 00462 printf("triadparticip..."); 00463 TFltPrV& TriadCntV = DistrStatH.AddDat(gsdTriadPart); 00464 TIntPrV CntV; 00465 TSnap::GetTriadParticip(Graph, CntV); 00466 TriadCntV.Gen(CntV.Len(), 0); 00467 for (int i = 0; i < CntV.Len(); i++) { 00468 TriadCntV.Add(TFltPr(CntV[i].Val1(), CntV[i].Val2())); 00469 } 00470 printf("[%s] ", ExeTm.GetTmStr()); 00471 }