SNAP Library , Developer Reference
2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
00001 namespace TSnap { 00002 00004 // Spectral graph properties 00005 void PlotEigValRank(const PUNGraph& Graph, const int& EigVals, const TStr& FNmPref, TStr DescStr) { 00006 TFltV EigValV; 00007 TSnap::GetEigVals(Graph, EigVals, EigValV); 00008 EigValV.Sort(false); 00009 if (DescStr.Empty()) { DescStr = FNmPref; } 00010 TGnuPlot::PlotValV(EigValV, "eigVal."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f", 00011 DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges(), EigValV[0].Val), "Rank", "Eigen value", gpsLog10XY, false, gpwLinesPoints); 00012 } 00013 00014 void PlotEigValDistr(const PUNGraph& Graph, const int& EigVals, const TStr& FNmPref, TStr DescStr) { 00015 const int NBuckets = 50; 00016 TFltV EigValV; 00017 for (int f = 1; EigValV.Empty() && f < 4; f++) { 00018 TSnap::GetEigVals(Graph, f*EigVals, EigValV); 00019 } 00020 EigValV.Sort(true); 00021 THash<TFlt, TFlt> BucketCntH; 00022 double Step = (EigValV.Last()-EigValV[0]) / double(NBuckets-1); 00023 for (int i = 0; i < NBuckets; i++) { 00024 BucketCntH.AddDat(EigValV[0]+Step*(i+0.5), 0); 00025 } 00026 for (int i = 0; i < EigValV.Len(); i++) { 00027 const int Bucket = (int) floor((EigValV[i]-EigValV[0]) / Step); 00028 BucketCntH[Bucket] += 1; 00029 } 00030 TFltPrV EigCntV; 00031 BucketCntH.GetKeyDatPrV(EigCntV); 00032 if (DescStr.Empty()) { DescStr = FNmPref; } 00033 TGnuPlot::PlotValV(EigCntV, "eigDistr."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f", DescStr.CStr(), 00034 Graph->GetNodes(), Graph->GetEdges(), EigValV.Last().Val), "Eigen value", "Count", gpsAuto, false, gpwLinesPoints); 00035 } 00036 00037 // Inverse participation ratio: normalize EigVec to have L2=1 and then I=sum_k EigVec[i]^4 00038 // see Spectra of "real-world" graphs: Beyond the semicircle law by Farkas, Derenyi, Barabasi and Vicsek 00039 void PlotInvParticipRat(const PUNGraph& Graph, const int& MaxEigVecs, const int& TimeLimit, const TStr& FNmPref, TStr DescStr) { 00040 TFltPrV EigIprV; 00041 GetInvParticipRat(Graph, MaxEigVecs, TimeLimit, EigIprV); 00042 if (DescStr.Empty()) { DescStr = FNmPref; } 00043 if (EigIprV.Empty()) { DescStr+=". FAIL"; EigIprV.Add(TFltPr(-1,-1)); return; } 00044 TGnuPlot::PlotValV(EigIprV, "eigIPR."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f (%d values)", 00045 DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges(), EigIprV.Last().Val1(), EigIprV.Len()), 00046 "Eigenvalue", "Inverse Participation Ratio of corresponding Eigenvector", gpsLog10Y, false, gpwPoints); 00047 } 00048 00049 void PlotSngValRank(const PNGraph& Graph, const int& SngVals, const TStr& FNmPref, TStr DescStr) { 00050 TFltV SngValV; 00051 TSnap::GetSngVals(Graph, SngVals, SngValV); 00052 SngValV.Sort(false); 00053 if (DescStr.Empty()) { DescStr = FNmPref; } 00054 TGnuPlot::PlotValV(SngValV, "sngVal."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f", 00055 DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges(), SngValV[0].Val), "Rank", "Singular value", gpsLog10XY, false, gpwLinesPoints); 00056 } 00057 00058 void PlotSngValDistr(const PNGraph& Graph, const int& SngVals, const TStr& FNmPref, TStr DescStr) { 00059 const int NBuckets = 50; 00060 TFltV SngValV; 00061 for (int f = 1; SngValV.Empty() && f < 4; f++) { 00062 TSnap::GetSngVals(Graph, f*SngVals, SngValV); 00063 } 00064 SngValV.Sort(true); 00065 THash<TFlt, TFlt> BucketCntH; 00066 double Step = (SngValV.Last()-SngValV[0]) / double(NBuckets-1); 00067 for (int i = 0; i < NBuckets; i++) { 00068 BucketCntH.AddDat(SngValV[0]+Step*(i+0.5), 0); 00069 } 00070 for (int i = 0; i < SngValV.Len(); i++) { 00071 const int Bucket = (int) floor((SngValV[i]-SngValV[0]) / Step); 00072 BucketCntH[Bucket] += 1; 00073 } 00074 TFltPrV EigCntV; 00075 BucketCntH.GetKeyDatPrV(EigCntV); 00076 if (DescStr.Empty()) { DescStr = FNmPref; } 00077 TGnuPlot::PlotValV(EigCntV, "sngDistr."+FNmPref, TStr::Fmt("%s. G(%d, %d). Largest eig val = %f", DescStr.CStr(), 00078 Graph->GetNodes(), Graph->GetEdges(), SngValV.Last().Val), "Singular value", "Count", gpsAuto, false, gpwLinesPoints); 00079 } 00080 00081 void PlotSngVec(const PNGraph& Graph, const TStr& FNmPref, TStr DescStr) { 00082 TFltV LeftSV, RightSV; 00083 TSnap::GetSngVec(Graph, LeftSV, RightSV); 00084 LeftSV.Sort(false); 00085 RightSV.Sort(false); 00086 TFltV BinV; 00087 if (DescStr.Empty()) { DescStr = FNmPref; } 00088 TGUtil::MakeExpBins(LeftSV, BinV, 1.01); 00089 TGnuPlot::PlotValV(BinV, "sngVecL."+FNmPref, TStr::Fmt("%s. G(%d, %d). Left signular vector", 00090 DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges()), "Rank", "Component of left singular vector", gpsLog10XY, false, gpwLinesPoints); 00091 TGnuPlot::PlotValV(BinV, "sngVecL."+FNmPref, TStr::Fmt("%s. G(%d, %d). Right signular vector", 00092 DescStr.CStr(), Graph->GetNodes(), Graph->GetEdges()), "Rank", "Component of right singular vector", gpsLog10XY, false, gpwLinesPoints); 00093 } 00094 00095 } // namespace TSnap