11   int CNodes = CmtyV.
Len(), CEdges;
 
   15     CEdges = (int) (Prob * CNodes * (CNodes - 1) / 2);
 
   18   for (
int edge = 0; edge < CEdges; ) {
 
   21     if (SrcNId > DstNId) { 
Swap(SrcNId,DstNId); }
 
   22     if (SrcNId != DstNId && ! NewEdgeSet.
IsKey(
TIntPr(SrcNId, DstNId))) { 
 
   33   const double ScaleCoef = (double) TargetEdges / (
double) TryG->
GetEdges();
 
   34   return TAGM::GenAGM(CmtyVV, DensityCoef, ScaleCoef, Rnd);
 
   40   for (
int i = 0; i < CmtyVV.
Len(); i++) {
 
   41     Prob = ScaleCoef*pow( 
double( CmtyVV[i].Len()), - DensityCoef);
 
   42     if (Prob > 1.0) { Prob = 1; }
 
   51   printf(
"AGM begins\n");
 
   52   for (
int i = 0; i < CmtyVV.
Len(); i++) {
 
   53     TIntV& CmtyV = CmtyVV[i];
 
   54     for (
int u = 0; u < CmtyV.
Len(); u++) {
 
   55       if ( G->
IsNode(CmtyV[u])) { 
continue; }
 
   58     double Prob = CProbV[i];
 
   63     for (
int c = 0; c < CmtyVV.
Len(); c++) {
 
   64       for (
int u = 0; u < CmtyVV[c].
Len(); u++) {
 
   83   while (SzSeq.
Len() < SeqLen) {
 
   85     if (Sz >= Min && Sz <= Max) {
 
   92 void TAGMUtil::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){
 
   94   for (
int i = 0; i < Nodes; i++) {
 
   97   GenCmtyVVFromPL(CmtyVV, NIDV, Nodes, Coms, ComSzAlpha, MemAlpha, MinSz, MaxSz, MinK, MaxK, Rnd);
 
  101 void TAGMUtil::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){
 
  102   if (Coms == 0 || Nodes == 0) {
 
  108   GenCmtyVVFromPL(CmtyVV, NIDV, Nodes, Coms, ComSzAlpha, MemAlpha, MinSz, MaxSz, MinK, MaxK, Rnd);
 
  112 void TAGMUtil::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){
 
  113   if (Coms == 0 || Nodes == 0) {
 
  117   TIntV ComSzSeq, MemSeq;
 
  121   for (
int i = 0; i < ComSzSeq.
Len(); i++) {
 
  124   for (
int i = 0; i < MemSeq.
Len(); i++) {
 
  125     NIDMemPrV.
Add(
TIntPr(NIDV[i], MemSeq[i]));
 
  132   const int Nodes = NIDMemPrV.
Len(), Coms = CIDSzPrV.
Len();
 
  137   for (
int i = 0;i < CIDSzPrV.
Len(); i++) {
 
  138     for (
int j = 0; j < CIDSzPrV[i].Val2; j++) {
 
  139       CDegV.
Add(CIDSzPrV[i].Val1);
 
  142   for (
int i = 0; i < NIDMemPrV.
Len(); i++) {
 
  143     for (
int j = 0; j < NIDMemPrV[i].Val2; j++) {
 
  144       NDegV.
Add(NIDMemPrV[i].Val1);
 
  147   while (CDegV.
Len() < (int) (1.2 * Nodes)) {
 
  150   while (NDegV.
Len() < CDegV.
Len()) {
 
  153   printf(
"Total Mem: %d, Total Sz: %d\n",NDegV.
Len(), CDegV.
Len());
 
  155   while (c++ < 15 && CDegV.
Len() > 1) {
 
  156     for (
int i = 0; i < CDegV.
Len(); i++) {
 
  159       if (CNIDSet.
IsKey(
TIntPr(CDegV[u], NDegV[v]))) { 
continue; }
 
  161       HitNodes.
AddKey(NDegV[v]);
 
  162       if (u == CDegV.
Len() - 1) { CDegV.
DelLast(); }
 
  164         CDegV[u] = CDegV.
Last(); 
 
  167       if (v == NDegV.
Len() - 1) { NDegV.
DelLast(); }
 
  169         NDegV[v] = NDegV.
Last();
 
  175   for (
int i = 0; i < Nodes; i++) {
 
  176     int NID = NIDMemPrV[i].Val1;
 
  177     if (! HitNodes.
IsKey(NID)) {
 
  183   for (
int i = 0; i < CNIDSet.
Len(); i++) {
 
  184     TIntPr CNIDPr = CNIDSet[i];
 
  194   for (
int i = 0; i < CmtyVVIn.
Len(); i++) {
 
  195     CmtyVH.
AddDat(i, CmtyVVIn[i]);
 
  206   for (
int i = 0; i < CmtyVH.
Len(); i++) {
 
  207     int CID = CmtyVH.
GetKey(i);
 
  208     for (
int j = 0; j < CmtyVH[i].
Len(); j++) {
 
  209       int NID = CmtyVH[i][j];
 
  216   while (c++ < 15 && CDegV.
Len() > 1){
 
  217     for (
int i = 0; i < CDegV.
Len(); i++) {
 
  220       if (CNIDSet.IsKey(
TIntPr(CDegV[u], NDegV[v]))) { 
continue; }
 
  221       CNIDSet.AddKey(
TIntPr(CDegV[u], NDegV[v]));
 
  222       if (u == CDegV.
Len() - 1) { 
 
  225         CDegV[u] = CDegV.
Last();
 
  228       if ( v == NDegV.
Len() - 1) {
 
  231         NDegV[v] = NDegV.Last();
 
  236   for (
int i = 0; i < CNIDSet.Len(); i++) {
 
  237     TIntPr CNIDPr = CNIDSet[i];
 
  239     NewCmtyVH.AddDat(CNIDPr.
Val1);
 
  240     NewCmtyVH.GetDat(CNIDPr.
Val1).Add(CNIDPr.
Val2);
 
  252       for (
int i = 0; i < Ss.
GetFlds(); i++) {
 
  261   printf(
"community loading completed (%d communities)\n",CmtyVV.
Len());
 
  272       for (
int i = BeginCol; i < Ss.
GetFlds(); i++) {
 
  277       if (CmtyV.
Len() < MinSz) { 
continue; }
 
  282   printf(
"community loading completed (%d communities)\n",CmtyVV.
Len());
 
  287   FILE* F = fopen(OutFNm.
CStr(),
"wt");
 
  288   for (
int i = 0; i < CmtyVV.
Len(); i++) {
 
  289     for (
int j = 0; j < CmtyVV[i].
Len(); j++) {
 
  290       fprintf(F,
"%d\t", (
int) CmtyVV[i][j]);
 
  299   FILE* F = fopen(OutFNm.
CStr(), 
"wt");
 
  300   for (
int c = 0; c < CmtyVV.
Len(); c++) {
 
  301     for (
int u = 0; u < CmtyVV[c].
Len(); u++) {
 
  302       if (NIDNmH.
IsKey(CmtyVV[c][u])){
 
  303         fprintf(F, 
"%s\t", NIDNmH.
GetDat(CmtyVV[c][u]).
CStr());
 
  306         fprintf(F, 
"%d\t", (
int) CmtyVV[c][u]);
 
  317   for (
int i = 0; i < CmtyVV.
Len(); i++) {
 
  318     M += CmtyVV[i].
Len();
 
  327     for (
int j = 0;j < HI.GetDat().Len(); j++) {
 
  328       int NID = HI.GetDat()[j];
 
  337   for (
int i = 0; i < CmtyVV.
Len(); i++){
 
  339     for (
int j = 0; j < CmtyVV[i].
Len(); j++) {
 
  340       int NID = CmtyVV[i][j];
 
  349   for (
int u = 0; u < NIDV.
Len(); u++) {
 
  352   for (
int i = 0; i < CmtyVV.
Len(); i++){
 
  354     for (
int j = 0; j < CmtyVV[i].
Len(); j++) {
 
  355       int NID = CmtyVV[i][j];
 
  363   for (
int i = 0; i < CmtyVV.
Len(); i++){
 
  366       int NID = SI.GetKey();
 
  373     int CID = HI.GetKey();
 
  374     for (
int j = 0; j < HI.GetDat().Len(); j++) {
 
  375       int NID = HI.GetDat()[j];
 
  382   for (
int i = 0; i < CmtyVH.
Len(); i++){
 
  383     int CID = CmtyVH.
GetKey(i);
 
  384     for (
int j = 0; j < CmtyVH[i].
Len(); j++) {
 
  385       int NID = CmtyVH[i][j];
 
  393   for (
int i = 0; i < CmtyVV.
Len(); i++) {
 
  394     CmtyVH.
AddDat(i, CmtyVV[i]);
 
  419       if (B.
IsKey(it.GetKey())) n++;
 
  422       if (A.
IsKey(it.GetKey())) n++;
 
  432   FILE* F = fopen(OutFNm.
CStr(), 
"wt");
 
  433   fprintf(F, 
"<?xml version='1.0' encoding='UTF-8'?>\n");
 
  434   fprintf(F, 
"<gexf xmlns='http://www.gexf.net/1.2draft' xmlns:viz='http://www.gexf.net/1.1draft/viz' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version='1.2'>\n");
 
  435   fprintf(F, 
"\t<graph mode='static' defaultedgetype='undirected'>\n");
 
  436   if (CmtyVVAtr.
Len() > 0) {
 
  437     fprintf(F, 
"\t<attributes class='node'>\n");
 
  438     for (
int c = 0; c < CmtyVVAtr.
Len(); c++) {
 
  439       fprintf(F, 
"\t\t<attribute id='%d' title='c%d' type='boolean'>", c, c);
 
  440       fprintf(F, 
"\t\t<default>false</default>\n");
 
  441       fprintf(F, 
"\t\t</attribute>\n");
 
  443     fprintf(F, 
"\t</attributes>\n");
 
  445   fprintf(F, 
"\t\t<nodes>\n");
 
  447     int NID = NI.GetId();
 
  452     double SizeStep = (MaxSz - MinSz) / (
double) CmtyVVAtr.
Len();
 
  453     if (NIDComVHAtr.
IsKey(NID)) {
 
  454       Size = MinSz +  SizeStep *  (double) NIDComVHAtr.
GetDat(NID).
Len();
 
  457     fprintf(F, 
"\t\t\t<node id='%d' label='%s'>\n", NID, Label.
CStr());
 
  458     fprintf(F, 
"\t\t\t\t<viz:color r='%d' g='%d' b='%d' a='%.1f'/>\n", Color.
Val1.Val, Color.
Val2.Val, Color.
Val3.Val, Alpha);
 
  459     fprintf(F, 
"\t\t\t\t<viz:size value='%.3f'/>\n", Size);
 
  461     if (NIDComVHAtr.
IsKey(NID)) {
 
  462       fprintf(F, 
"\t\t\t\t<attvalues>\n");
 
  463       for (
int c = 0; c < NIDComVHAtr.
GetDat(NID).
Len(); c++) {
 
  464         int CID = NIDComVHAtr.
GetDat(NID)[c];
 
  465         fprintf(F, 
"\t\t\t\t\t<attvalue for='%d' value='true'/>\n", CID);
 
  467       fprintf(F, 
"\t\t\t\t</attvalues>\n");
 
  470     fprintf(F, 
"\t\t\t</node>\n");
 
  472   fprintf(F, 
"\t\t</nodes>\n");
 
  475   fprintf(F, 
"\t\t<edges>\n");
 
  477     fprintf(F, 
"\t\t\t<edge id='%d' source='%d' target='%d'/>\n", EID++, EI.GetSrcNId(), EI.GetDstNId());
 
  479   fprintf(F, 
"\t\t</edges>\n");
 
  480   fprintf(F, 
"\t</graph>\n");
 
  481   fprintf(F, 
"</gexf>\n");
 
  488   if (CmtyVV.
Len() == 0) { 
return; }
 
  489   double NXMin = 0.1, YMin = 0.1, NXMax = 250.00, YMax = 30.0;
 
  490   double CXMin = 0.3 * NXMax, CXMax = 0.7 * NXMax;
 
  491   double CStep = (CXMax - CXMin) / (
double) CmtyVV.
Len(), NStep = (NXMax - NXMin) / (
double) NIDV.
Len();
 
  495   FILE* F = fopen(OutFNm.
CStr(), 
"wt");
 
  496   fprintf(F, 
"<?xml version='1.0' encoding='UTF-8'?>\n");
 
  497   fprintf(F, 
"<gexf xmlns='http://www.gexf.net/1.2draft' xmlns:viz='http://www.gexf.net/1.1draft/viz' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version='1.2'>\n");
 
  498   fprintf(F, 
"\t<graph mode='static' defaultedgetype='directed'>\n");
 
  499   fprintf(F, 
"\t\t<nodes>\n");
 
  500   for (
int c = 0; c < CmtyVV.
Len(); c++) {
 
  502     double XPos = c * CStep + CXMin;
 
  504     fprintf(F, 
"\t\t\t<node id='C%d' label='C%d'>\n", CID, CID);
 
  505     fprintf(F, 
"\t\t\t\t<viz:color r='%d' g='%d' b='%d'/>\n", Color.
Val1.Val, Color.
Val2.Val, Color.
Val3.Val);
 
  506     fprintf(F, 
"\t\t\t\t<viz:size value='%.3f'/>\n", MaxSz);
 
  507     fprintf(F, 
"\t\t\t\t<viz:shape value='square'/>\n");
 
  508     fprintf(F, 
"\t\t\t\t<viz:position x='%f' y='%f' z='0.0'/>\n", XPos, YMax); 
 
  509     fprintf(F, 
"\t\t\t</node>\n");
 
  512   for (
int u = 0;u < NIDV.
Len(); u++) {
 
  516     double XPos = NXMin + u * NStep;
 
  519     fprintf(F, 
"\t\t\t<node id='%d' label='%s'>\n", NID, Label.
CStr());
 
  520     fprintf(F, 
"\t\t\t\t<viz:color r='%d' g='%d' b='%d' a='%.1f'/>\n", Color.
Val1.Val, Color.
Val2.Val, Color.
Val3.Val, Alpha);
 
  521     fprintf(F, 
"\t\t\t\t<viz:size value='%.3f'/>\n", Size);
 
  522     fprintf(F, 
"\t\t\t\t<viz:shape value='square'/>\n");
 
  523     fprintf(F, 
"\t\t\t\t<viz:position x='%f' y='%f' z='0.0'/>\n", XPos, YMin); 
 
  524     fprintf(F, 
"\t\t\t</node>\n");
 
  526   fprintf(F, 
"\t\t</nodes>\n");
 
  527   fprintf(F, 
"\t\t<edges>\n");
 
  529   for (
int u = 0;u < NIDV.
Len(); u++) {
 
  531     if (NIDComVH.
IsKey(NID)) {
 
  532       for (
int c = 0; c < NIDComVH.
GetDat(NID).
Len(); c++) {
 
  533         int CID = NIDComVH.
GetDat(NID)[c];
 
  534         fprintf(F, 
"\t\t\t<edge id='%d' source='C%d' target='%d'/>\n", EID++, CID, NID);
 
  538   fprintf(F, 
"\t\t</edges>\n");
 
  539   fprintf(F, 
"\t</graph>\n");
 
  540   fprintf(F, 
"</gexf>\n");
 
  546   int LambdaIter = 100;
 
  547   if (Graph->
GetNodes() < 200) { LambdaIter = 1; } 
 
  548   if (Graph->
GetNodes() < 200 && Graph->
GetEdges() > 2000) { LambdaIter = 100; } 
 
  551   TAGMFit AGMFitM(Graph, InitComs, RndSeed);
 
  552   if (PNoCom > 0.0) { AGMFitM.
SetPNoCom(PNoCom); }
 
  553   AGMFitM.
RunMCMC(MaxIter, LambdaIter, 
"");
 
  558   for (
int r = 0; r < 25; r++) {
 
  559     RegV.
Add(RegV.
Last() * RegGap);
 
  561   TFltPrV RegComsV, RegLV, RegBICV;
 
  564   for (
int r = 0; r < RegV.
Len(); r++) {
 
  565     double RegCoef = RegV[r];
 
  572     int NumLowQ = EstCmtyVV.
Len();
 
  573     RegComsV.
Add(
TFltPr(RegCoef, (
double) NumLowQ));
 
  575     if (EstCmtyVV.
Len() > 0) {
 
  576       TAGMFit AFTemp(Graph, EstCmtyVV, Rnd);
 
  580       BICV.
Add(-2.0 * CurL + (
double) EstCmtyVV.
Len() * log((
double) Graph->
GetNodes() * (Graph->
GetNodes() - 1) / 2.0));
 
  587   if (LV.
Len() == 0) { 
return 2; }
 
  588   else if (LV[0] == LV.
Last()) { 
return (
int) TMath::Mx<TFlt>(2.0, RegComsV[LV.
Len() - 1].Val2); }
 
  597     for (
int l = 0; l < ValueV.
Len(); l++) {
 
  598       if (ValueV[l] < MinValue) { MinValue = ValueV[l]; }
 
  599       if (ValueV[l] > MaxValue) { MaxValue = ValueV[l]; }
 
  601     while (ValueV.
Len() < RegV.
Len()) { ValueV.
Add(MinValue); }
 
  602     double RangeVal = MaxValue - MinValue;
 
  603     for (
int l = 0; l < ValueV.
Len(); l++) {
 
  604       RegValueV.
Add(
TFltPr(RegV[l], 
double(MaxL) * (ValueV[l] - MinValue) / RangeVal));
 
  609     TFltV& ValueV = BICV;
 
  612     for (
int l = 0; l < ValueV.
Len(); l++) {
 
  613       if (ValueV[l] < MinValue) { MinValue = ValueV[l]; }
 
  614       if (ValueV[l] > MaxValue) { MaxValue = ValueV[l]; }
 
  616     while (ValueV.
Len() < RegV.
Len()) { ValueV.
Add(MaxValue); }
 
  617     double RangeVal = MaxValue - MinValue;
 
  618     for (
int l = 0; l < ValueV.
Len(); l++) {
 
  619       RegValueV.
Add(
TFltPr(RegV[l], 
double(MaxL) * (ValueV[l] - MinValue) / RangeVal));
 
  626   for (
int l = 0; l < RegLV.
Len(); l++) {
 
  628     YV[l] = RegLV[l].Val2 / (double) MaxL;
 
  633   for (
int l = 0; l < RegLV.
Len(); l++) {
 
  634     LRV.
Add(
TFltPr(RegV[l], LRMd->GetCfy(XV[l])));
 
  639   int NumComs = 0, IdxRegDrop = 0;
 
  640   double LRThres = 1.1, RegDrop; 
 
  641   double LeftReg = 0.0, RightReg = 0.0;
 
  643   LRMd->GetTheta(Theta);
 
  644   RegDrop = (- Theta[1] - LRThres) / Theta[0];
 
  645   if (RegDrop <= XV[0][0]) { NumComs = (int) RegComsV[0].Val2; }
 
  646   else if (RegDrop >= XV.Last()[0]) { NumComs = (int) RegComsV.
Last().
Val2; }
 
  648     for (
int i = 0; i < XV.Len(); i++) {
 
  649       if (XV[i][0] > RegDrop) { IdxRegDrop = i; 
break; }
 
  652     if (IdxRegDrop == 0) {
 
  653       printf(
"Error!! RegDrop:%f, Theta[0]:%f, Theta[1]:%f\n", RegDrop, Theta[0].Val, Theta[1].Val);
 
  654       for (
int l = 0; l < RegLV.
Len(); l++) {
 
  655         printf(
"X[%d]:%f, Y[%d]:%f\n", l, XV[l][0].Val, l, YV[l].Val);
 
  659     LeftReg = RegDrop - XV[IdxRegDrop - 1][0];
 
  660     RightReg = XV[IdxRegDrop][0] - RegDrop;
 
  661     NumComs = (int) 
TMath::Round( (RightReg * RegComsV[IdxRegDrop - 1].Val2 + LeftReg * RegComsV[IdxRegDrop].Val2) / (LeftReg + RightReg));
 
  665   printf(
"Num Coms:%d\n", NumComs);
 
  666   if (NumComs < 2) { NumComs = 2; }
 
  668   if (PltFPrx.
Len() > 0) {
 
  676     GPC.SetTitle(PlotTitle);
 
  677     GPC.SavePng(PltFPrx + 
".l.png");
 
  684   const int Edges2 = Edges >= 0 ? 2*Edges : Graph->
GetEdges();
 
  685   int Vol = 0,  Cut = 0; 
 
  687   for (
int i = 0; i < CmtyS.
Len(); i++) {
 
  688     if (! Graph->
IsNode(CmtyS[i])) { 
continue; }
 
  690     for (
int e = 0; e < NI.
GetOutDeg(); e++) {
 
  697     if (2 * Vol > Edges2) { Phi = Cut / double (Edges2 - Vol); }
 
  698     else if (Vol == 0) { Phi = 0.0; }
 
  699     else { Phi = Cut / double(Vol); }
 
  701     if (Vol == Edges2) { Phi = 1.0; }
 
  710   for (
int e = 0; e < NI.
GetDeg(); e++) {
 
  719   bool HSingular = 
false;
 
  720   for (
int i = 0; i < HVV.
GetXDim(); i++) {
 
  721     if (HVV(i,i) == 0.0) {
 
  725     DeltaLV[i] = GradV[i] / HVV(i, i);
 
  729       for (
int r = 0; r < 
Theta.
Len(); r++) {
 
  730         for (
int c = 0; c < 
Theta.
Len(); c++) {
 
  731           HVV(r, c) = - HVV(r, c);
 
  738       for (
int i = 0; i < DeltaLV.
Len(); i++) {
 
  739         DeltaLV[i] = - DeltaLV[i];
 
  750   for (
int i = 0; i < 
X.Len(); i++) {
 
  751     for (
int r = 0; r < 
Theta.
Len(); r++) {
 
  752       HVV.
At(r, r) += - (
X[i][r] * OutV[i] * (1 - OutV[i]) * 
X[i][r]);
 
  753       for (
int c = r + 1; c < 
Theta.
Len(); c++) {
 
  754         HVV.
At(r, c) += - (
X[i][r] * OutV[i] * (1 - OutV[i]) * 
X[i][c]);
 
  755         HVV.
At(c, r) += - (
X[i][r] * OutV[i] * (1 - OutV[i]) * 
X[i][c]);
 
  775   double MinVal = -1e10, MaxVal = 1e10;
 
  776   for(iter = 0; iter < MaxStep; iter++) {
 
  781     if (Increment <= ChangeEps) {
break;}
 
  783     for(
int i = 0; i < 
Theta.
Len(); i++) {
 
  784       double Change = LearnRate * DeltaLV[i];
 
  790   if (! PlotNm.
Empty()) {
 
  791     printf(
"MLE with Newton method completed with %d iterations(%s)\n",iter,ExeTm.
GetTmStr());
 
  802   double MinVal = -1e10, MaxVal = 1e10;
 
  803   double GradCutOff = 100000;
 
  804   for(iter = 0; iter < MaxStep; iter++) {
 
  806     for(
int i = 0; i < 
Theta.
Len(); i++) {
 
  807       if (GradV[i] < -GradCutOff) { GradV[i] = -GradCutOff; }
 
  808       if (GradV[i] > GradCutOff) { GradV[i] = GradCutOff; }
 
  809       if (
Theta[i] <= MinVal && GradV[i] < 0) { GradV[i] = 0.0; }
 
  810       if (
Theta[i] >= MaxVal && GradV[i] > 0) { GradV[i] = 0.0; }
 
  812     double Alpha = 0.15, Beta = 0.9;
 
  816     for(
int i = 0; i < 
Theta.
Len(); i++) {
 
  817       double Change = LearnRate * GradV[i];
 
  822     if (! PlotNm.
Empty()) {
 
  829   if (! PlotNm.
Empty()) {
 
  832     printf(
"MLE for Lambda completed with %d iterations(%s)\n",iter,ExeTm.
GetTmStr());
 
  838   double StepSize = 1.0;
 
  842   double MinVal = -1e10, MaxVal = 1e10;
 
  843   for(
int iter = 0; ; iter++) {
 
  844     for (
int i = 0; i < 
Theta.
Len(); i++){
 
  845       NewThetaV[i] = 
Theta[i] + StepSize * DeltaV[i];
 
  846       if (NewThetaV[i] < MinVal) { NewThetaV[i] = MinVal;  }
 
  847       if (NewThetaV[i] > MaxVal) { NewThetaV[i] = MaxVal; }
 
  862   for (
int r = 0; r < OutV.
Len(); r++) {
 
  863     L += 
Y[r] * log(OutV[r]);
 
  864     L += (1 - 
Y[r]) * log(1 - OutV[r]);
 
  873   for (
int r = 0; r < 
X.Len(); r++) {
 
  875     for (
int m = 0; m < 
M; m++) {
 
  876       GradV[m] += (
Y[r] - OutV[r]) * 
X[r][m];
 
  887   if (Intercept == 
false) { 
 
  888     for (
int r = 0; r < 
X.Len(); r++) {  
X[r].Add(1); }
 
  891   for (
int r = 0; r < 
X.Len(); r++) {  
IAssert(
X[r].Len() == 
M); }
 
  892   for (
int r = 0; r < 
Y.
Len(); r++) {  
 
  893     if (
Y[r] >= 0.99999) { 
Y[r] = 0.99999; }
 
  894     if (
Y[r] <= 0.00001) { 
Y[r] = 0.00001; }
 
  905   if (Intercept == 
false) { 
 
  906     for (
int r = 0; r < 
X.Len(); r++) {  
X[r].Add(1); }
 
  909   for (
int r = 0; r < 
X.Len(); r++) {  
IAssert(
X[r].Len() == 
M); }
 
  910   for (
int r = 0; r < 
Y.
Len(); r++) {  
 
  911     if (
Y[r] >= 0.99999) { 
Y[r] = 0.99999; }
 
  912     if (
Y[r] <= 0.00001) { 
Y[r] = 0.00001; }
 
  923     int len = AttrV.
Len();
 
  925     if (len < NewTheta.
Len()) { res = NewTheta.
Last(); } 
 
  926     for (
int i = 0; i < len; i++) {
 
  927       if (i < NewTheta.
Len()) { res += AttrV[i] * NewTheta[i]; }
 
  929     double mu = 1 / (1 + exp(-res));
 
  935   for (
int r = 0; r < X.
Len(); r++) {
 
  936     OutV[r] = 
GetCfy(X[r], NewTheta);
 
Edge iterator. Only forward iteration (operator++) is supported. 
 
TPair< TInt, TInt > TIntPr
 
static void GetNbhCom(const PUNGraph &Graph, const int NID, TIntSet &NBCmtyS)
 
TIter EndI() const 
Returns an iterator referring to the past-the-end element in the vector. 
 
void GetNewtonStep(TFltVV &HVV, const TFltV &GradV, TFltV &DeltaLV)
 
static double Norm(const TFltV &x)
 
static int TotalMemberships(const TVec< TIntV > &CmtyVV)
total number of memberships (== sum of the sizes of communities) 
 
void GetDatV(TVec< TDat > &DatV) const 
 
TEdgeI EndEI() const 
Returns an iterator referring to the past-the-end edge in the graph. 
 
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)
 
void SetPNoCom(const double &Epsilon)
Set Epsilon (the probability that two nodes sharing no communities connect) to the default value...
 
void GetNIdV(TIntV &NIdV) const 
Gets a vector IDs of all nodes in the graph. 
 
int AddNode(int NId=-1)
Adds a node of ID NId to the graph. 
 
double Likelihood()
COMMENT. 
 
static void GenPLSeq(TIntV &SzSeq, const int &SeqLen, const double &Alpha, TRnd &Rnd, const int &Min, const int &Max)
AGMUtil:: Utilities for AGM. 
 
int GetEdges() const 
Returns the number of edges in the graph. 
 
TSizeTy Len() const 
Returns the number of elements in the vector. 
 
Node iterator. Only forward iteration (operator++) is supported. 
 
static int Intersection(const TIntV &C1, const TIntV &C2)
 
void GetKeyV(TVec< TKey > &KeyV) const 
 
void Gen(const int &ExpectVals)
 
bool GetInt(const int &FldN, int &Val) const 
If the field FldN is an integer its value is returned in Val and the function returns true...
 
const TDat & GetDat(const TKey &Key) const 
 
static void GetIntersection(const THashSet< TInt > &A, const THashSet< TInt > &B, THashSet< TInt > &C)
 
Fitting the Affilialiton Graph Model (AGM). 
 
static double GetConductance(const PUNGraph &Graph, const TIntSet &CmtyS, const int Edges)
 
int GetFlds() const 
Returns the number of fields in the current line. 
 
bool IsKey(const TKey &Key) const 
 
int GetNodes() const 
Returns the number of nodes in the graph. 
 
const char * GetFld(const int &FldN) const 
Returns the contents of the field at index FldN. 
 
TSsFmt
Spread-Sheet Separator Format. 
 
TPair< TInt, TFlt > TIntFltPr
 
int GetDeg() const 
Returns degree of the current node. 
 
const char * GetTmStr() const 
 
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...
 
int GetOutDeg() const 
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
 
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector. 
 
void GetCmtyVV(TVec< TIntV > &CmtyVV, const double QMax=2.0)
Get communities whose  p_c is higher than 1 - QMax. 
 
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. 
 
bool IsKey(const char *Key) const 
 
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)
 
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...
 
static double Round(const double &Val)
 
Whitespace (space or tab) separated. 
 
TNodeI GetNI(const int &NId) const 
Returns an iterator referring to the node of ID NId in the graph. 
 
void SetRegCoef(const double Val)
 
TEdgeI BegEI() const 
Returns an iterator referring to the first edge in the graph. 
 
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New(). 
 
int AddKey(const TKey &Key)
 
const TVal & Last() const 
Returns a reference to the last element of the vector. 
 
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 ...
 
static void SolveSymetricSystem(TFltVV &A, const TFltV &b, TFltV &x)
 
void Gen(const int &_XDim, const int &_YDim)
 
TPair< TFlt, TFlt > TFltPr
 
int MLEGradient(const double &ChangeEps, const int &MaxStep, const TStr PlotNm)
 
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph. 
 
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 
 
double GetBinomialDev(const double &Prb, const int &Trials)
 
int GetOutNId(const int &NodeN) const 
Returns ID of NodeN-th out-node (the node the current node points to). 
 
void RunMCMC(const int &MaxIter, const int &EvalLambdaIter, const TStr &PlotFPrx=TStr())
Main procedure for fitting the AGM to a given graph using MCMC. 
 
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 void PlotValV(const TVec< TPair< TVal1, TVal2 > > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
 
static TStr Fmt(const char *FmtStr,...)
 
void Pack()
The vector reduces its capacity (frees memory) to match its size. 
 
double GetStepSizeByLineSearch(const TFltV &DeltaV, const TFltV &GradV, const double &Alpha, const double &Beta)
 
void Gradient(TFltV &GradV)
 
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph. 
 
TNodeI EndNI() const 
Returns an iterator referring to the past-the-end node in the graph. 
 
static void DumpCmtyVV(const TStr &OutFNm, const TVec< TIntV > &CmtyVV)
dump bipartite community affiliation into a text file 
 
int GetNbrNId(const int &NodeN) const 
Returns ID of NodeN-th neighboring node. 
 
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
 
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)
 
int MLENewton(const double &ChangeEps, const int &MaxStep, const TStr PlotNm)
 
bool IsNode(const int &NId) const 
Tests whether ID NId is a node. 
 
bool Next()
Loads next line from the input file. 
 
static double DotProduct(const TFltV &x, const TFltV &y)
 
static void RndConnectInsideCommunity(PUNGraph &Graph, const TIntV &CmtyV, const double &Prob, TRnd &Rnd)
Connect members of a given community by Erdos-Renyi. 
 
TTriple< TInt, TInt, TInt > TIntTr
 
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements. 
 
int GetUniDevInt(const int &Range=0)
 
static TVec< TVal, TSizeTy > GetV(const TVal &Val1)
Returns a vector on element Val1. 
 
bool IsKey(const TKey &Key) const 
 
bool IsInt(const int &FldN) const 
Checks whether fields FldN is an integer. 
 
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element. 
 
TNodeI BegNI() const 
Returns an iterator referring to the first node in the graph. 
 
void DelLast()
Removes the last element of the vector. 
 
static PUNGraph GenAGM(TVec< TIntV > &CmtyVV, const double &DensityCoef, const double &ScaleCoef, TRnd &Rnd=TInt::Rnd)
 
TDat & AddDat(const TKey &Key)
 
const TVal & At(const int &X, const int &Y) const 
 
const TKey & GetKey(const int &KeyId) const 
 
double GetPowerDev(const double &AlphaSlope)
 
int GetKeyId(const char *Key) const 
 
static void RewireCmtyNID(THash< TInt, TIntV > &CmtyVH, TRnd &Rnd)
rewire bipartite community affiliation graphs 
 
void Swap(TRec &Rec1, TRec &Rec2)