SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <agm.h>
Static Public Member Functions | |
static void | RndConnectInsideCommunity (PUNGraph &Graph, const TIntV &CmtyV, const double &Prob, TRnd &Rnd) |
Connect members of a given community by Erdos-Renyi. | |
static PUNGraph | GenAGM (const TIntV &NIdV, THash< TInt, TIntV > &CmtyVH, const TStr &AGMNm, const double &PiCoef, const double &ProbBase, TRnd &Rnd=TInt::Rnd) |
static PUNGraph | GenAGM (TVec< TIntV > &CmtyVV, const double &DensityCoef, const double &ScaleCoef, TRnd &Rnd=TInt::Rnd) |
static PUNGraph | GenAGM (TVec< TIntV > &CmtyVV, const double &DensityCoef, const int TargetEdges, TRnd &Rnd) |
static PUNGraph | GenAGM (TVec< TIntV > &CmtyVV, const TFltV &CProbV, TRnd &Rnd, const double PNoCom=-1.0) |
Generate graph using the AGM model. CProbV = vector of Pc. |
static PUNGraph TAGM::GenAGM | ( | const TIntV & | NIdV, |
THash< TInt, TIntV > & | CmtyVH, | ||
const TStr & | AGMNm, | ||
const double & | PiCoef, | ||
const double & | ProbBase, | ||
TRnd & | Rnd = TInt::Rnd |
||
) | [static] |
PUNGraph TAGM::GenAGM | ( | TVec< TIntV > & | CmtyVV, |
const double & | DensityCoef, | ||
const int | TargetEdges, | ||
TRnd & | Rnd | ||
) | [static] |
Definition at line 31 of file agm.cpp.
{ PUNGraph TryG = TAGM::GenAGM(CmtyVV, DensityCoef, 1.0, Rnd); const double ScaleCoef = (double) TargetEdges / (double) TryG->GetEdges(); return TAGM::GenAGM(CmtyVV, DensityCoef, ScaleCoef, Rnd); }
PUNGraph TAGM::GenAGM | ( | TVec< TIntV > & | CmtyVV, |
const TFltV & | CProbV, | ||
TRnd & | Rnd, | ||
const double | PNoCom = -1.0 |
||
) | [static] |
Generate graph using the AGM model. CProbV = vector of Pc.
Definition at line 49 of file agm.cpp.
{ PUNGraph G = TUNGraph::New(100 * CmtyVV.Len(), -1); printf("AGM begins\n"); for (int i = 0; i < CmtyVV.Len(); i++) { TIntV& CmtyV = CmtyVV[i]; for (int u = 0; u < CmtyV.Len(); u++) { if ( G->IsNode(CmtyV[u])) { continue; } G->AddNode(CmtyV[u]); } double Prob = CProbV[i]; RndConnectInsideCommunity(G, CmtyV, Prob, Rnd); } if (PNoCom > 0.0) { //if we want to connect nodes that do not share any community TIntSet NIDS; for (int c = 0; c < CmtyVV.Len(); c++) { for (int u = 0; u < CmtyVV[c].Len(); u++) { NIDS.AddKey(CmtyVV[c][u]); } } TIntV NIDV; NIDS.GetKeyV(NIDV); RndConnectInsideCommunity(G,NIDV,PNoCom,Rnd); } printf("AGM completed (%d nodes %d edges)\n",G->GetNodes(),G->GetEdges()); G->Defrag(); return G; }
void TAGM::RndConnectInsideCommunity | ( | PUNGraph & | Graph, |
const TIntV & | CmtyV, | ||
const double & | Prob, | ||
TRnd & | Rnd | ||
) | [static] |
Connect members of a given community by Erdos-Renyi.
Definition at line 10 of file agm.cpp.
{ int CNodes = CmtyV.Len(), CEdges; if (CNodes < 20) { CEdges = (int) Rnd.GetBinomialDev(Prob, CNodes * (CNodes-1) / 2); } else { CEdges = (int) (Prob * CNodes * (CNodes - 1) / 2); } THashSet<TIntPr> NewEdgeSet(CEdges); for (int edge = 0; edge < CEdges; ) { int SrcNId = CmtyV[Rnd.GetUniDevInt(CNodes)]; int DstNId = CmtyV[Rnd.GetUniDevInt(CNodes)]; if (SrcNId > DstNId) { Swap(SrcNId,DstNId); } if (SrcNId != DstNId && ! NewEdgeSet.IsKey(TIntPr(SrcNId, DstNId))) { // is new edge NewEdgeSet.AddKey(TIntPr(SrcNId, DstNId)); Graph->AddEdge(SrcNId, DstNId); edge++; } } }