21 static void GenPLSeq(
TIntV& SzSeq,
const int& SeqLen,
const double& Alpha,
TRnd& Rnd,
const int& Min,
const int& Max);
23 static void GenCmtyVVFromPL(
TVec<TIntV>& CmtyVV,
const PUNGraph& Graph,
const int& Nodes,
const int& Coms,
const double& ComSzAlpha,
const double& MemAlpha,
const int& MinSz,
const int& MaxSz,
const int& MinK,
const int& MaxK,
TRnd& Rnd);
24 static void GenCmtyVVFromPL(
TVec<TIntV>& CmtyVV,
const TIntV& NIDV,
const int& Nodes,
const int& Coms,
const double& ComSzAlpha,
const double& MemAlpha,
const int& MinSz,
const int& MaxSz,
const int& MinK,
const int& MaxK,
TRnd& Rnd);
25 static void GenCmtyVVFromPL(
TVec<TIntV>& CmtyVV,
const int& Nodes,
const int& Coms,
const double& ComSzAlpha,
const double& MemAlpha,
const int& MinSz,
const int& MaxSz,
const int& MinK,
const int& MaxK,
TRnd& Rnd);
57 SaveGephi(OutFNm, G, CmtyVVAtr, MaxSz, MinSz, TmpH);
61 SaveGephi(OutFNm, G, CmtyVVAtr, MaxSz, MinSz, NIDNameH, TmpH);
65 static int FindComsByAGM(
const PUNGraph& Graph,
const int InitComs,
const int MaxIter,
const int RndSeed,
const double RegGap,
const double PNoCom = 0.0,
const TStr PltFPrx =
TStr());
66 template <
class PGraph>
69 PGraph Graph = PGraph::TObj::New();
72 const int SrcNId = StrSet.
AddKey(Ss[SrcColId]);
73 const int DstNId = StrSet.
AddKey(Ss[DstColId]);
74 if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
75 if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
76 Graph->AddEdge(SrcNId, DstNId);
78 NIDNameH.
Gen(StrSet.
Len());
79 for (
int s = 0; s < StrSet.
Len(); s++) { NIDNameH.
AddDat(s, StrSet.
GetKey(s)); }
85 template <
class PGraph>
88 PGraph Graph = PGraph::TObj::New();
91 const int SrcNId = StrSet.
AddKey(Ss[SrcColId]);
92 const int DstNId = StrSet.
AddKey(Ss[DstColId]);
93 if (! Graph->IsNode(SrcNId)) { Graph->AddNode(SrcNId); }
94 if (! Graph->IsNode(DstNId)) { Graph->AddNode(DstNId); }
95 Graph->AddEdge(SrcNId, DstNId);
104 template<
class PGraph>
107 TStrV Shapes =
TStrV::GetV(
"ellipse",
"triangle",
"square",
"pentagon",
"hexagon");
114 FILE *F = fopen(GraphFNm.
CStr(),
"wt");
115 if (! Desc.Empty()) fprintf(F,
"/*****\n%s\n*****/\n\n", Desc.CStr());
116 if (IsDir) { fprintf(F,
"digraph G {\n"); }
else { fprintf(F,
"graph G {\n"); }
117 fprintf(F,
" graph [splines=false overlap=false]\n");
118 fprintf(F,
" node [width=0.3, height=0.3]\n");
120 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
121 int NID = NI.GetId();
124 TStr ShapeNm = Shapes[(CIDV.
Len()-1) % Shapes.
Len()];
125 TStr ColorNm = Colors[CIDV[0] % Colors.
Len()];
127 for(
int i=0;i<CIDV.Len();i++) {
129 NodeComLabel += TmpStr;
130 if(i<CIDV.Len()-1){NodeComLabel+=
",";}
133 fprintf(F,
" %d [style=filled, shape=\"%s\" fillcolor=\"%s\" label=\"%s\"];\n", NI.GetId(), ShapeNm.CStr(),ColorNm.
CStr(), NodeComLabel.
CStr());
137 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
138 if (NI.GetOutDeg()==0 && NI.GetInDeg()==0 ) {
139 fprintf(F,
"%d;\n", NI.GetId()); }
141 for (
int e = 0; e < NI.GetOutDeg(); e++) {
142 if (! IsDir && NI.GetId() > NI.GetOutNId(e)) {
continue; }
143 fprintf(F,
" %d %s %d;\n", NI.GetId(), IsDir?
"->":
"--", NI.GetOutNId(e));
147 if (! Desc.Empty()) {
148 fprintf(F,
" label = \"\\n%s\\n\";", Desc.CStr());
149 fprintf(F,
" fontsize=24;\n");
179 int MLEGradient(
const double& ChangeEps,
const int& MaxStep,
const TStr PlotNm);
180 int MLENewton(
const double& ChangeEps,
const int& MaxStep,
const TStr PlotNm);
215 void PrintTheta() {
for (
int t = 0; t < Theta.
Len(); t++) { printf(
"Theta[%d] = %f\n", t, Theta[t].Val); } }
void GetCfy(const TVec< TFltV > &X, TFltV &OutV)
static void GetNbhCom(const PUNGraph &Graph, const int NID, TIntSet &NBCmtyS)
void GetNewtonStep(TFltVV &HVV, const TFltV &GradV, TFltV &DeltaLV)
static int TotalMemberships(const TVec< TIntV > &CmtyVV)
total number of memberships (== sum of the sizes of communities)
static void RewireCmtyVV(const TVec< TIntV > &CmtyVVIn, TVec< TIntV > &CmtyVVOut, TRnd &Rnd)
rewire bipartite community affiliation graphs
static void GetNodeMembership(THash< TInt, TIntSet > &NIDComVH, const TVec< TIntV > &CmtyVV)
get hash table of
static void GetCfy(const TVec< TFltV > &X, TFltV &OutV, const TFltV &NewTheta)
static void GenPLSeq(TIntV &SzSeq, const int &SeqLen, const double &Alpha, TRnd &Rnd, const int &Min, const int &Max)
AGMUtil:: Utilities for AGM.
TSizeTy Len() const
Returns the number of elements in the vector.
UndefDefaultCopyAssign(TLogRegPredict)
static int Intersection(const TIntV &C1, const TIntV &C2)
void GetTheta(TFltV &_Theta)
TStr GetSubStr(const int &BChN, const int &EChN) const
const TDat & GetDat(const TKey &Key) const
static void GetIntersection(const THashSet< TInt > &A, const THashSet< TInt > &B, THashSet< TInt > &C)
static double GetConductance(const PUNGraph &Graph, const TIntSet &CmtyS, const int Edges)
static PGraph LoadEdgeListStr(const TStr &InFNm, TIntStrH &NIDNameH, const int &SrcColId=0, const int &DstColId=1, const TSsFmt SsFmt=ssfTabSep)
Affiliation Graph Model (AGM) graph generator.
void Save(TSOut &SOut) const
TSsFmt
Spread-Sheet Separator Format.
TPt< TLogRegPredict > PLogRegPredict
static void SaveGephi(const TStr &OutFNm, const PUNGraph &G, const TVec< TIntV > &CmtyVVAtr, const double MaxSz, const double MinSz)
static void ConnectCmtyVV(TVec< TIntV > &CmtyVV, const TIntPrV &CIDSzPrV, const TIntPrV &NIDMemPrV, TRnd &Rnd)
Generate bipartite community affiliation from given power law coefficients for membership distributio...
double GetCfy(const TFltV &AttrV)
void GVizDoLayout(const TStr &GraphInFNm, TStr OutFNm, const TGVizLayout &Layout)
Runs GraphViz layout engine over a graph saved in the file GraphInFNm with output saved to OutFNm...
void Gen(const int &ExpectVals)
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
static void GVizComGraph(const PGraph &Graph, const TVec< TIntV > &CmtyVV, const TStr &OutFNm, const TStr &Desc=TStr())
static PGraph LoadEdgeListStr(const TStr &InFNm, TStrHash< TInt > &NodeNameH, const int &SrcColId=0, const int &DstColId=1, const TSsFmt SsFmt=ssfTabSep)
Affiliation Graph Model (AGM) graph generator.
void Hessian(TFltVV &HVV)
PLogRegPredict CalcLogRegNewton(const TVec< TFltV > &XPt, const TFltV &yPt, const TStr &PlotNm=TStr(), const double &ChangeEps=0.01, const int &MaxStep=200, const bool InterceptPt=false)
const char * GetKey(const int &KeyId) const
static void GenCmtyVVFromPL(TVec< TIntV > &CmtyVV, const PUNGraph &Graph, const int &Nodes, const int &Coms, const double &ComSzAlpha, const double &MemAlpha, const int &MinSz, const int &MaxSz, const int &MinK, const int &MaxK, TRnd &Rnd)
Generate bipartite community affiliation from given power law coefficients for membership distributio...
TLogRegPredict(const TFltV &_bb)
static void SaveGephi(const TStr &OutFNm, const PUNGraph &G, const TVec< TIntV > &CmtyVVAtr, const double MaxSz, const double MinSz, const THash< TInt, TStr > &NIDNameH)
static void LoadCmtyVV(const TStr &InFNm, TVec< TIntV > &CmtyVV)
load bipartite community affiliation graph from text file (each row contains the member node IDs for ...
int MLEGradient(const double &ChangeEps, const int &MaxStep, const TStr PlotNm)
int AddKey(const char *Key)
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
static void SaveBipartiteGephi(const TStr &OutFNm, const TIntV &NIDV, const TVec< TIntV > &CmtyVV, const double MaxSz, const double MinSz, const TIntStrH &NIDNameH, const THash< TInt, TIntTr > &NIDColorH, const THash< TInt, TIntTr > &CIDColorH)
save bipartite community affiliation into gexf file
void Save(TSOut &SOut) const
static int FindComsByAGM(const PUNGraph &Graph, const int InitComs, const int MaxIter, const int RndSeed, const double RegGap, const double PNoCom=0.0, const TStr PltFPrx=TStr())
estimate number of communities using AGM
static TStr Fmt(const char *FmtStr,...)
double GetStepSizeByLineSearch(const TFltV &DeltaV, const TFltV &GradV, const double &Alpha, const double &Beta)
void Gradient(TFltV &GradV)
static PLogRegPredict Load(TSIn &SIn)
static void DumpCmtyVV(const TStr &OutFNm, const TVec< TIntV > &CmtyVV)
dump bipartite community affiliation into a text file
PLogRegPredict CalcLogRegGradient(const TVec< TFltV > &XPt, const TFltV &yPt, const TStr &PlotNm=TStr(), const double &ChangeEps=0.01, const int &MaxStep=200, const bool InterceptPt=false)
TLogRegPredict(TSIn &SIn)
int MLENewton(const double &ChangeEps, const int &MaxStep, const TStr PlotNm)
bool Next()
Loads next line from the input file.
static void RndConnectInsideCommunity(PUNGraph &Graph, const TIntV &CmtyV, const double &Prob, TRnd &Rnd)
Connect members of a given community by Erdos-Renyi.
static TVec< TStr, int > GetV(const TStr &Val1)
Returns a vector on element Val1.
static PUNGraph GenAGM(TVec< TIntV > &CmtyVV, const double &DensityCoef, const double &ScaleCoef, TRnd &Rnd=TInt::Rnd)
TDat & AddDat(const TKey &Key)
static void RewireCmtyNID(THash< TInt, TIntV > &CmtyVH, TRnd &Rnd)
rewire bipartite community affiliation graphs