SNAP Library 2.2, Developer Reference
2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
00001 #ifndef snap_agmfit_h 00002 #define snap_agmfit_h 00003 00004 #include "Snap.h" 00005 00008 class TAGMFit { 00009 private: 00010 PUNGraph G; 00011 TVec<TIntSet> CIDNSetV; 00012 THash<TIntPr,TIntSet> EdgeComVH; 00013 THash<TInt, TIntSet> NIDComVH; 00014 TIntV ComEdgesV; 00015 TFlt PNoCom; 00016 TFltV LambdaV; 00017 TRnd Rnd; 00018 THash<TIntPr,TFlt> NIDCIDPrH; 00019 THash<TIntPr,TInt> NIDCIDPrS; 00020 TFlt MinLambda; 00021 TFlt MaxLambda; 00022 TFlt RegCoef; 00023 TInt BaseCID; 00024 00025 public: 00026 TAGMFit() { } 00027 ~TAGMFit() { } 00029 TAGMFit(const PUNGraph& GraphPt, const TVec<TIntV>& CmtyVVPt, const int RndSeed = 0): G(GraphPt), PNoCom(0.0), Rnd(RndSeed), MinLambda(0.00001), MaxLambda(10.0), RegCoef(0), BaseCID(-1) { SetCmtyVV(CmtyVVPt); } 00031 TAGMFit(const PUNGraph& GraphPt, const int InitComs, const int RndSeed = 0): G(GraphPt), PNoCom(0.0), Rnd(RndSeed), MinLambda(0.00001), MaxLambda(10.0), RegCoef(0), BaseCID(-1) { NeighborComInit(InitComs); }//RandomInitCmtyVV(InitComs); } 00033 TAGMFit(const PUNGraph& GraphPt, const TVec<TIntV>& CmtyVVPt, const TRnd& RndPt): G(GraphPt), PNoCom(0.0), Rnd(RndPt), MinLambda(0.00001), MaxLambda(10.0), RegCoef(0), BaseCID(-1) { SetCmtyVV(CmtyVVPt); } 00034 void Save(TSOut& SOut); 00035 void Load(TSIn& SIn, const int& RndSeed = 0); 00036 00038 void RandomInitCmtyVV(const int InitComs, const double ComSzAlpha = 1.3, const double MemAlpha = 1.8, const int MinComSz = 8, const int MaxComSz = 200, const int MinMem = 1, const int MaxMem = 10); 00040 void AddBaseCmty(); 00042 double Likelihood(); 00043 double Likelihood(const TFltV& NewLambdaV) { double Tmp1, Tmp2; return Likelihood(NewLambdaV, Tmp1, Tmp2); } 00044 double Likelihood(const TFltV& NewLambdaV, double& LEdges, double& LNoEdges); 00045 void SetRegCoef(const double Val) { RegCoef = Val; } 00047 void GetEdgeJointCom(); 00049 void NeighborComInit(const int InitComs); 00050 // Gradient of likelihood for \c P_c. 00051 void GradLogLForLambda(TFltV& GradV); 00053 int MLEGradAscentGivenCAG(const double& Thres=0.001, const int& MaxIter=10000, const TStr PlotNm = TStr()); 00055 void SetDefaultPNoCom(); 00057 void SetPNoCom(const double& Epsilon) { if (BaseCID == -1 && Epsilon > 0.0) { PNoCom = Epsilon; } } 00058 double GetPNoCom() { return PNoCom; } 00060 double CalcPNoComByCmtyVV(const int& SamplePairs = -1); 00061 void GetNewtonStep(TFltVV& HVV, TFltV& GradV, TFltV& DeltaLV); 00063 double SelectLambdaSum(const TIntSet& ComK); 00065 double SelectLambdaSum(const TFltV& NewLambdaV, const TIntSet& ComK); 00066 00068 void RandomInit(const int& MaxK); 00070 void RunMCMC(const int& MaxIter, const int& EvalLambdaIter, const TStr& PlotFPrx = TStr()); 00072 void SampleTransition(int& NID, int& JoinCID, int& LeaveCID, double& DeltaL); 00074 void InitNodeData(); 00076 void LeaveCom(const int& NID, const int& CID); 00077 // After MCMC, \c NID joins community \c CID. 00078 void JoinCom(const int& NID, const int& JoinCID); 00080 int RemoveEmptyCom(); 00082 double SeekLeave(const int& UID, const int& CID); 00084 double SeekJoin(const int& UID, const int& CID); 00085 // Compute the change in likelihood (Delta) if node \c UID switches from \c CurCID to \c NewCID. 00086 double SeekSwitch(const int& UID, const int& CurCID, const int& NewCID); 00087 00089 double GetStepSizeByLineSearchForLambda(const TFltV& DeltaV, const TFltV& GradV, const double& Alpha, const double& Beta); 00091 void SetLambdaV(const TFltV& LambdaPt) {LambdaV = LambdaPt;} 00093 void GetLambdaV(TFltV& OutV) {OutV = LambdaV;} 00095 void GetQV(TFltV& OutV); 00097 void GetCmtyVV(TVec<TIntV>& CmtyVV, const double QMax = 2.0); 00099 void GetCmtyVV(TVec<TIntV>& CmtyVV, TFltV& QV, const double QMax = 2.0); 00101 void SetCmtyVV(const TVec<TIntV>& CmtyVV); 00103 void PrintSummary(); 00104 }; 00105 00106 #endif