SNAP Library 2.3, Developer Reference
2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Community detection with AGM. Sparse AGM-fast with coordinate ascent. More...
#include <agmfast.h>
Public Member Functions | |
TAGMFast (const PUNGraph &GraphPt, const int &InitComs, const int RndSeed=0) | |
void | SetGraph (const PUNGraph &GraphPt) |
void | SetRegCoef (const double _RegCoef) |
double | GetRegCoef () |
void | RandomInit (const int InitComs) |
void | NeighborComInit (const int InitComs) |
void | SetCmtyVV (const TVec< TIntV > &CmtyVV) |
double | Likelihood (const bool DoParallel=false) |
double | LikelihoodForRow (const int UID) |
double | LikelihoodForRow (const int UID, const TIntFltH &FU) |
int | MLENewton (const double &Thres, const int &MaxIter, const TStr &PlotNm=TStr()) |
Newton method: DEPRECATED. More... | |
void | GradientForRow (const int UID, TIntFltH &GradU, const TIntSet &CIDSet) |
double | GradientForOneVar (const TFltV &AlphaKV, const int UID, const int CID, const double &Val) |
double | HessianForOneVar (const TFltV &AlphaKV, const int UID, const int CID, const double &Val) |
double | LikelihoodForOneVar (const TFltV &AlphaKV, const int UID, const int CID, const double &Val) |
void | GetCmtyVV (TVec< TIntV > &CmtyVV) |
void | GetCmtyVV (TVec< TIntV > &CmtyVV, const double Thres, const int MinSz=3) |
extract community affiliation from F_uc More... | |
int | FindComsByCV (TIntV &ComsV, const double HOFrac=0.2, const int NumThreads=20, const TStr &PlotLFNm=TStr(), const double StepAlpha=0.3, const double StepBeta=0.1) |
int | FindComsByCV (const int NumThreads, const int MaxComs, const int MinComs, const int DivComs, const TStr &OutFNm, const double StepAlpha=0.3, const double StepBeta=0.3) |
estimate number of communities using cross validation More... | |
double | LikelihoodHoldOut (const bool DoParallel=false) |
double | GetStepSizeByLineSearch (const int UID, const TIntFltH &DeltaV, const TIntFltH &GradV, const double &Alpha, const double &Beta, const int MaxIter=10) |
int | MLEGradAscent (const double &Thres, const int &MaxIter, const TStr &PlotNm, const double StepAlpha=0.3, const double StepBeta=0.1) |
int | MLEGradAscentParallel (const double &Thres, const int &MaxIter, const int ChunkNum, const int ChunkSize, const TStr &PlotNm, const double StepAlpha=0.3, const double StepBeta=0.1) |
int | MLEGradAscentParallel (const double &Thres, const int &MaxIter, const int ChunkNum, const TStr &PlotNm=TStr(), const double StepAlpha=0.3, const double StepBeta=0.1) |
void | Save (TSOut &SOut) |
void | Load (TSIn &SIn, const int &RndSeed=0) |
double | GetCom (const int &NID, const int &CID) |
void | AddCom (const int &NID, const int &CID, const double &Val) |
void | DelCom (const int &NID, const int &CID) |
double | DotProduct (const TIntFltH &UV, const TIntFltH &VV) |
double | DotProduct (const int &UID, const int &VID) |
double | Prediction (const TIntFltH &FU, const TIntFltH &FV) |
double | Prediction (const int &UID, const int &VID) |
double | Sum (const TIntFltH &UV) |
double | Norm2 (const TIntFltH &UV) |
Public Attributes | |
TVec< TIntSet > | HOVIDSV |
TFlt | MinVal |
TFlt | MaxVal |
TFlt | NegWgt |
TFlt | PNoCom |
TBool | DoParallel |
Private Attributes | |
PUNGraph | G |
TVec< TIntFltH > | F |
TRnd | Rnd |
TIntV | NIDV |
TFlt | RegCoef |
TFltV | SumFV |
TBool | NodesOk |
TInt | NumComs |
Community detection with AGM. Sparse AGM-fast with coordinate ascent.
|
inline |
Definition at line 25 of file agmfast.h.
References RandomInit(), and SetGraph().
|
inline |
Definition at line 64 of file agmfast.h.
Referenced by MLEGradAscent(), MLENewton(), NeighborComInit(), RandomInit(), and SetCmtyVV().
|
inline |
Definition at line 72 of file agmfast.h.
Referenced by MLEGradAscent(), and MLENewton().
Definition at line 78 of file agmfast.h.
References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::IsKey(), and THash< TKey, TDat, THashFunc >::Len().
Referenced by DotProduct(), GetStepSizeByLineSearch(), LikelihoodForRow(), MLENewton(), and Prediction().
|
inline |
Definition at line 95 of file agmfast.h.
References DotProduct(), and F.
int TAGMFast::FindComsByCV | ( | TIntV & | ComsV, |
const double | HOFrac = 0.2 , |
||
const int | NumThreads = 20 , |
||
const TStr & | PlotLFNm = TStr() , |
||
const double | StepAlpha = 0.3 , |
||
const double | StepBeta = 0.1 |
||
) |
Definition at line 554 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), TUNGraph::BegEI(), TStr::Empty(), TUNGraph::EndEI(), G, TVec< TVal, TSizeTy >::Gen(), TUNGraph::GetEdges(), TUNGraph::GetNIdV(), TUNGraph::GetNodes(), TRnd::GetUniDevInt(), HOVIDSV, TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::Len(), Likelihood(), LikelihoodHoldOut(), MLEGradAscent(), MLEGradAscentParallel(), TFlt::Mn, NeighborComInit(), TGnuPlot::PlotValV(), RandomInit(), Rnd, and TMath::Round().
Referenced by FindComsByCV().
int TAGMFast::FindComsByCV | ( | const int | NumThreads, |
const int | MaxComs, | ||
const int | MinComs, | ||
const int | DivComs, | ||
const TStr & | OutFNm, | ||
const double | StepAlpha = 0.3 , |
||
const double | StepBeta = 0.3 |
||
) |
estimate number of communities using cross validation
Definition at line 541 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), FindComsByCV(), TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::Len(), TMath::Log(), and TInt::Val.
Definition at line 508 of file agmfast.cpp.
References G, TUNGraph::GetEdges(), and TUNGraph::GetNodes().
extract community affiliation from F_uc
Definition at line 513 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), F, TVec< TVal, TSizeTy >::Gen(), GetCom(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::GetKey(), IAssert, TVec< TVal, TSizeTy >::Len(), NIDV, NodesOk, NumComs, THash< TKey, TDat, THashFunc >::SortByDat(), and SumFV.
|
inline |
Definition at line 57 of file agmfast.h.
References F.
Referenced by GetCmtyVV(), GetStepSizeByLineSearch(), GradientForOneVar(), GradientForRow(), LikelihoodForOneVar(), LikelihoodForRow(), MLEGradAscent(), and MLENewton().
double TAGMFast::GetStepSizeByLineSearch | ( | const int | UID, |
const TIntFltH & | DeltaV, | ||
const TIntFltH & | GradV, | ||
const double & | Alpha, | ||
const double & | Beta, | ||
const int | MaxIter = 10 |
||
) |
Definition at line 665 of file agmfast.cpp.
References DotProduct(), GetCom(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::GetKey(), THash< TKey, TDat, THashFunc >::Len(), LikelihoodForRow(), MaxVal, and MinVal.
Referenced by MLEGradAscent(), and MLEGradAscentParallel().
double TAGMFast::GradientForOneVar | ( | const TFltV & | AlphaKV, |
const int | UID, | ||
const int | CID, | ||
const double & | Val | ||
) |
Definition at line 339 of file agmfast.cpp.
References F, G, GetCom(), TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), HOVIDSV, IAssert, NegWgt, RegCoef, and SumFV.
Referenced by MLENewton().
Definition at line 250 of file agmfast.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), DoParallel, G, THash< TKey, TDat, THashFunc >::Gen(), TVec< TVal, TSizeTy >::Gen(), GetCom(), TUNGraph::TNodeI::GetDeg(), THashSet< TKey, THashFunc >::GetKey(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), HOVIDSV, IAssert, THash< TKey, TDat, THashFunc >::Len(), TVec< TVal, TSizeTy >::Len(), THashSet< TKey, THashFunc >::Len(), NegWgt, Prediction(), RegCoef, and SumFV.
Referenced by MLEGradAscent(), and MLEGradAscentParallel().
double TAGMFast::HessianForOneVar | ( | const TFltV & | AlphaKV, |
const int | UID, | ||
const int | CID, | ||
const double & | Val | ||
) |
Definition at line 394 of file agmfast.cpp.
References F, G, TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), HOVIDSV, IAssert, and RegCoef.
Referenced by MLENewton().
double TAGMFast::Likelihood | ( | const bool | DoParallel = false | ) |
Definition at line 173 of file agmfast.cpp.
References F, and LikelihoodForRow().
Referenced by FindComsByCV(), MLEGradAscent(), MLEGradAscentParallel(), and MLENewton().
double TAGMFast::LikelihoodForOneVar | ( | const TFltV & | AlphaKV, |
const int | UID, | ||
const int | CID, | ||
const double & | Val | ||
) |
Definition at line 364 of file agmfast.cpp.
References F, G, GetCom(), TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), HOVIDSV, IAssert, NegWgt, RegCoef, and SumFV.
double TAGMFast::LikelihoodForRow | ( | const int | UID | ) |
Definition at line 193 of file agmfast.cpp.
References F.
Referenced by GetStepSizeByLineSearch(), and Likelihood().
double TAGMFast::LikelihoodForRow | ( | const int | UID, |
const TIntFltH & | FU | ||
) |
Definition at line 198 of file agmfast.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), DoParallel, DotProduct(), THash< TKey, TDat, THashFunc >::EndI(), F, G, TVec< TVal, TSizeTy >::Gen(), GetCom(), TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), HOVIDSV, TVec< TVal, TSizeTy >::Len(), NegWgt, Norm2(), Prediction(), RegCoef, Sum(), and SumFV.
double TAGMFast::LikelihoodHoldOut | ( | const bool | DoParallel = false | ) |
Definition at line 647 of file agmfast.cpp.
References G, HOVIDSV, TUNGraph::IsEdge(), NegWgt, and Prediction().
Referenced by FindComsByCV().
void TAGMFast::Load | ( | TSIn & | SIn, |
const int & | RndSeed = 0 |
||
) |
Definition at line 22 of file agmfast.cpp.
References F, G, HOVIDSV, TUNGraph::Load(), TVec< TVal, TSizeTy >::Load(), TBool::Load(), TInt::Load(), TFlt::Load(), MaxVal, MinVal, NegWgt, NIDV, NodesOk, NumComs, PNoCom, TRnd::PutSeed(), RegCoef, Rnd, and SumFV.
int TAGMFast::MLEGradAscent | ( | const double & | Thres, |
const int & | MaxIter, | ||
const TStr & | PlotNm, | ||
const double | StepAlpha = 0.3 , |
||
const double | StepBeta = 0.1 |
||
) |
Definition at line 690 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), AddCom(), THash< TKey, TDat, THashFunc >::BegI(), DelCom(), TStr::Empty(), THash< TKey, TDat, THashFunc >::EndI(), F, G, GetCom(), TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), TUNGraph::GetNodes(), GetStepSizeByLineSearch(), TExeTm::GetTmStr(), GradientForRow(), HOVIDSV, IAssert, Likelihood(), TFlt::Mn, Norm2(), TGnuPlot::PlotValV(), and Rnd.
Referenced by FindComsByCV().
int TAGMFast::MLEGradAscentParallel | ( | const double & | Thres, |
const int & | MaxIter, | ||
const int | ChunkNum, | ||
const int | ChunkSize, | ||
const TStr & | PlotNm, | ||
const double | StepAlpha = 0.3 , |
||
const double | StepBeta = 0.1 |
||
) |
Definition at line 761 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::BegI(), TStr::Empty(), THashKeyDatI< TKey, TDat >::EndI, THash< TKey, TDat, THashFunc >::EndI(), F, G, TSecTm::GetAbsSecs(), TSecTm::GetCurTm(), THash< TKey, TDat, THashFunc >::GetDat(), TVec< TVal, TSizeTy >::GetDat(), TUNGraph::TNodeI::GetDeg(), THash< TKey, TDat, THashFunc >::GetKey(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), TUNGraph::GetNodes(), GetStepSizeByLineSearch(), TExeTm::GetTmStr(), GradientForRow(), HOVIDSV, IAssert, THash< TKey, TDat, THashFunc >::Len(), TVec< TVal, TSizeTy >::Len(), Likelihood(), TFlt::Mn, Norm2(), TGnuPlot::PlotValV(), TVec< TVal, TSizeTy >::PutAll(), Rnd, and SumFV.
Referenced by FindComsByCV(), and MLEGradAscentParallel().
|
inline |
Definition at line 49 of file agmfast.h.
References G, TUNGraph::GetNodes(), and MLEGradAscentParallel().
Newton method: DEPRECATED.
Definition at line 416 of file agmfast.cpp.
References TVec< TVal, TSizeTy >::Add(), AddCom(), THashSet< TKey, THashFunc >::AddKey(), THash< TKey, TDat, THashFunc >::BegI(), THashSet< TKey, THashFunc >::BegI(), DelCom(), DotProduct(), TStr::Empty(), THashSet< TKey, THashFunc >::Empty(), THash< TKey, TDat, THashFunc >::EndI(), THashSet< TKey, THashFunc >::EndI(), F, TStr::Fmt(), G, GetCom(), TUNGraph::TNodeI::GetDeg(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), TUNGraph::GetNIdV(), TUNGraph::GetNodes(), TExeTm::GetTmStr(), GradientForOneVar(), HessianForOneVar(), HOVIDSV, IAssertR, THashSet< TKey, THashFunc >::IsKey(), Likelihood(), TFlt::Mn, TGnuPlot::PlotValV(), PNoCom, Rnd, TVec< TVal, TSizeTy >::Shuffle(), and TFlt::Val.
void TAGMFast::NeighborComInit | ( | const int | InitComs | ) |
Definition at line 60 of file agmfast.cpp.
References AddCom(), F, G, TVec< TVal, TSizeTy >::Gen(), TAGMUtil::GetConductance(), TUNGraph::TNodeI::GetDeg(), TUNGraph::GetEdges(), TAGMUtil::GetNbhCom(), TUNGraph::TNodeI::GetNbrNId(), TUNGraph::GetNI(), TUNGraph::GetNodes(), TExeTm::GetTmStr(), TRnd::GetUniDev(), TRnd::GetUniDevInt(), IAssert, TVec< TVal, TSizeTy >::Len(), NumComs, Rnd, and SumFV.
Referenced by FindComsByCV().
|
inline |
Definition at line 113 of file agmfast.h.
References THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
Referenced by LikelihoodForRow(), MLEGradAscent(), and MLEGradAscentParallel().
Definition at line 98 of file agmfast.h.
References DotProduct(), TStr::Fmt(), IAssertR, and PNoCom.
Referenced by GradientForRow(), LikelihoodForRow(), LikelihoodHoldOut(), and Prediction().
|
inline |
Definition at line 103 of file agmfast.h.
References F, and Prediction().
void TAGMFast::RandomInit | ( | const int | InitComs | ) |
Definition at line 38 of file agmfast.cpp.
References AddCom(), F, G, TVec< TVal, TSizeTy >::Gen(), TUNGraph::TNodeI::GetDeg(), TUNGraph::GetNI(), TUNGraph::GetNodes(), TRnd::GetUniDev(), TRnd::GetUniDevInt(), TVec< TVal, TSizeTy >::Len(), NumComs, Rnd, and SumFV.
Referenced by FindComsByCV(), and TAGMFast().
void TAGMFast::Save | ( | TSOut & | SOut | ) |
Definition at line 7 of file agmfast.cpp.
References F, G, HOVIDSV, MaxVal, MinVal, NegWgt, NIDV, NodesOk, NumComs, PNoCom, RegCoef, TUNGraph::Save(), TVec< TVal, TSizeTy >::Save(), TBool::Save(), TInt::Save(), TFlt::Save(), and SumFV.
Definition at line 125 of file agmfast.cpp.
References AddCom(), THash< TKey, TDat, THashFunc >::AddDat(), F, G, TVec< TVal, TSizeTy >::Gen(), TVec< TVal, TSizeTy >::GetDat(), TUNGraph::GetNodes(), TUNGraph::IsNode(), TVec< TVal, TSizeTy >::Len(), NIDV, NodesOk, NumComs, and SumFV.
void TAGMFast::SetGraph | ( | const PUNGraph & | GraphPt | ) |
Definition at line 146 of file agmfast.cpp.
References TSnap::DelSelfEdges(), DoParallel, G, TUNGraph::GetNIdV(), TUNGraph::GetNodes(), TSnap::GetSubGraph(), HOVIDSV, IAssert, TUNGraph::IsNode(), TFlt::Mx, NegWgt, NIDV, NodesOk, and PNoCom.
Referenced by TAGMFast().
|
inline |
|
inline |
Definition at line 106 of file agmfast.h.
References THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
Referenced by LikelihoodForRow().
TBool TAGMFast::DoParallel |
Definition at line 23 of file agmfast.h.
Referenced by GradientForRow(), LikelihoodForRow(), and SetGraph().
Definition at line 10 of file agmfast.h.
Referenced by AddCom(), DelCom(), DotProduct(), GetCmtyVV(), GetCom(), GradientForOneVar(), HessianForOneVar(), Likelihood(), LikelihoodForOneVar(), LikelihoodForRow(), Load(), MLEGradAscent(), MLEGradAscentParallel(), MLENewton(), NeighborComInit(), Prediction(), RandomInit(), Save(), and SetCmtyVV().
|
private |
Definition at line 9 of file agmfast.h.
Referenced by FindComsByCV(), GetCmtyVV(), GradientForOneVar(), GradientForRow(), HessianForOneVar(), LikelihoodForOneVar(), LikelihoodForRow(), LikelihoodHoldOut(), Load(), MLEGradAscent(), MLEGradAscentParallel(), MLENewton(), NeighborComInit(), RandomInit(), Save(), SetCmtyVV(), and SetGraph().
Definition at line 18 of file agmfast.h.
Referenced by FindComsByCV(), GradientForOneVar(), GradientForRow(), HessianForOneVar(), LikelihoodForOneVar(), LikelihoodForRow(), LikelihoodHoldOut(), Load(), MLEGradAscent(), MLEGradAscentParallel(), MLENewton(), Save(), and SetGraph().
TFlt TAGMFast::MaxVal |
Definition at line 20 of file agmfast.h.
Referenced by GetStepSizeByLineSearch(), Load(), and Save().
TFlt TAGMFast::MinVal |
Definition at line 19 of file agmfast.h.
Referenced by GetStepSizeByLineSearch(), Load(), and Save().
TFlt TAGMFast::NegWgt |
Definition at line 21 of file agmfast.h.
Referenced by GradientForOneVar(), GradientForRow(), LikelihoodForOneVar(), LikelihoodForRow(), LikelihoodHoldOut(), Load(), Save(), and SetGraph().
|
private |
Definition at line 12 of file agmfast.h.
Referenced by GetCmtyVV(), Load(), Save(), SetCmtyVV(), and SetGraph().
|
private |
Definition at line 15 of file agmfast.h.
Referenced by GetCmtyVV(), Load(), Save(), SetCmtyVV(), and SetGraph().
|
private |
Definition at line 16 of file agmfast.h.
Referenced by GetCmtyVV(), Load(), NeighborComInit(), RandomInit(), Save(), and SetCmtyVV().
TFlt TAGMFast::PNoCom |
Definition at line 22 of file agmfast.h.
Referenced by Load(), MLENewton(), Prediction(), Save(), and SetGraph().
|
private |
Definition at line 13 of file agmfast.h.
Referenced by GetRegCoef(), GradientForOneVar(), GradientForRow(), HessianForOneVar(), LikelihoodForOneVar(), LikelihoodForRow(), Load(), Save(), and SetRegCoef().
|
private |
Definition at line 11 of file agmfast.h.
Referenced by FindComsByCV(), Load(), MLEGradAscent(), MLEGradAscentParallel(), MLENewton(), NeighborComInit(), and RandomInit().
|
private |
Definition at line 14 of file agmfast.h.
Referenced by AddCom(), DelCom(), GetCmtyVV(), GradientForOneVar(), GradientForRow(), LikelihoodForOneVar(), LikelihoodForRow(), Load(), MLEGradAscentParallel(), NeighborComInit(), RandomInit(), Save(), and SetCmtyVV().