29 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); }
31 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); }
33 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); }
35 void Load(
TSIn& SIn,
const int& RndSeed = 0);
38 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);
44 double Likelihood(
const TFltV& NewLambdaV,
double& LEdges,
double& LNoEdges);
57 void SetPNoCom(
const double& Epsilon) {
if (BaseCID == -1 && Epsilon > 0.0) { PNoCom = Epsilon; } }
71 void RunMCMC(
const int& MaxIter,
const int& EvalLambdaIter,
const TStr& PlotFPrx =
TStr());
73 void SampleTransition(
int& NID,
int& JoinCID,
int& LeaveCID,
double& DeltaL);
77 void LeaveCom(
const int& NID,
const int& CID);
79 void JoinCom(
const int& NID,
const int& JoinCID);
83 double SeekLeave(
const int& UID,
const int& CID);
85 double SeekJoin(
const int& UID,
const int& CID);
87 double SeekSwitch(
const int& UID,
const int& CurCID,
const int& NewCID);
void Load(TSIn &SIn, const int &RndSeed=0)
void SetLambdaV(const TFltV &LambdaPt)
COMMENT.
double SeekSwitch(const int &UID, const int &CurCID, const int &NewCID)
void SetDefaultPNoCom()
Set Epsilon (the probability that two nodes sharing no communities connect) to the default value...
void SetPNoCom(const double &Epsilon)
Set Epsilon (the probability that two nodes sharing no communities connect) to the default value...
THash< TIntPr, TInt > NIDCIDPrS
pairs (for sampling MCMC moves).
double GetStepSizeByLineSearchForLambda(const TFltV &DeltaV, const TFltV &GradV, const double &Alpha, const double &Beta)
Step size search for updating P_c (which is parametarized by regularization parameter lambda)...
double Likelihood()
COMMENT.
TFltV LambdaV
Parametrization of P_c (edge probability in community c), P_c = 1 - exp(-lambda). ...
void PrintSummary()
COMMENT.
TAGMFit(const PUNGraph &GraphPt, const int InitComs, const int RndSeed=0)
COMMENT. Use to describribe parameters.
TInt BaseCID
ID of the Epsilon-community (in case we fit P_c of the epsilon community). We do not fit for the Epsi...
void GetLambdaV(TFltV &OutV)
COMMENT.
THash< TIntPr, TIntSet > EdgeComVH
Edge -> Shared Community ID Set.
Fitting the Affilialiton Graph Model (AGM).
void GetEdgeJointCom()
For each (u, v) in edges, precompute C_uv (the set of communities nodes u and v share).
void GradLogLForLambda(TFltV &GradV)
TAGMFit(const PUNGraph &GraphPt, const TVec< TIntV > &CmtyVVPt, const TRnd &RndPt)
COMMENT. Use to describribe parameters.
double CalcPNoComByCmtyVV(const int &SamplePairs=-1)
Compute the empirical edge probability between a pair of nodes who share no community (epsilon)...
void LeaveCom(const int &NID, const int &CID)
After MCMC, NID leaves community CID.
TFlt MinLambda
Minimum value of regularization parameter lambda (default = 1e-5).
void GetCmtyVV(TVec< TIntV > &CmtyVV, const double QMax=2.0)
Get communities whose p_c is higher than 1 - QMax.
int RemoveEmptyCom()
Remove all communities with no members.
int MLEGradAscentGivenCAG(const double &Thres=0.001, const int &MaxIter=10000, const TStr PlotNm=TStr())
Gradient descent for p_c while keeping the community affiliation graph (CAG) fixed.
THash< TInt, TIntSet > NIDComVH
Node ID -> Communitie IDs the node belongs to.
double SelectLambdaSum(const TIntSet &ComK)
Compute sum of lambda_c (which is log (1 - p_c)) over C_uv (ComK). The function is used to compute ed...
TFlt RegCoef
Regularization parameter when we fit for P_c (for finding # communities).
void SetRegCoef(const double Val)
void NeighborComInit(const int InitComs)
Initialize node community memberships using best neighborhood communities (see D. Gleich et al...
void GetQV(TFltV &OutV)
Returns QV, a vector of (1 - p_c) for each community c.
TAGMFit(const PUNGraph &GraphPt, const TVec< TIntV > &CmtyVVPt, const int RndSeed=0)
COMMENT. Use to describribe parameters.
double SeekJoin(const int &UID, const int &CID)
Compute the change in likelihood (Delta) if node UID joins community CID.
void RunMCMC(const int &MaxIter, const int &EvalLambdaIter, const TStr &PlotFPrx=TStr())
Main procedure for fitting the AGM to a given graph using MCMC.
void InitNodeData()
COMMENT.
double SeekLeave(const int &UID, const int &CID)
Compute the change in likelihood (Delta) if node UID leaves community CID.
void JoinCom(const int &NID, const int &JoinCID)
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)
Randomly initialize bipartite community affiliation graph.
TFlt MaxLambda
Maximum value of regularization parameter lambda (default = 10).
TVec< TIntSet > CIDNSetV
Community ID -> Member Node ID Sets.
void AddBaseCmty()
Add Epsilon community (base community which includes all nodes) into community affiliation graph...
void SetCmtyVV(const TVec< TIntV > &CmtyVV)
COMMENT.
double Likelihood(const TFltV &NewLambdaV)
TIntV ComEdgesV
The number of edges in each community.
void SampleTransition(int &NID, int &JoinCID, int &LeaveCID, double &DeltaL)
Sample MMCM transitions: Choose among (join, leave, switch), and then sample (NID, CID).
TFlt PNoCom
Probability of edge when two nodes share no community (epsilon in the paper).
void RandomInit(const int &MaxK)
COMMENT.
THash< TIntPr, TFlt > NIDCIDPrH
pairs (for sampling MCMC moves).
Vector is a sequence TVal objects representing an array that can change in size.