Example #1
0
 void TakeStat(const PGraph& InfG, const PGraph& NetG, const TIntH& NIdInfTmH, const double& P, const bool& DivByM=true) {
   const double M = DivByM ? InfG->GetNodes() : 1;  IAssert(M>=1);
   PGraph CcInf, CcNet; // largest connected component
   // connected components and sizes
   { TCnComV CnComV;  TSnap::GetWccs(InfG, CnComV);
   NCascInf.AddDat(P).Add(CnComV.Len()/M);
   MxSzInf.AddDat(P).Add(CnComV[0].Len()/M);
   { int a=0; for (int i=0; i<CnComV.Len(); i++) { a+=CnComV[i].Len(); }
   AvgSzInf.AddDat(P).Add(a/double(CnComV.Len()*M)); }
   CcInf = TSnap::GetSubGraph(InfG, CnComV[0].NIdV);
   TSnap::GetWccs(NetG, CnComV);
   NCascNet.AddDat(P).Add(CnComV.Len()/M);
   MxSzNet.AddDat(P).Add(CnComV[0].Len()/M);
   { int a=0; for (int i=0; i<CnComV.Len(); i++) { a+=CnComV[i].Len(); }
   AvgSzNet.AddDat(P).Add(a/double(CnComV.Len()*M)); }
   CcNet = TSnap::GetSubGraph(NetG, CnComV[0].NIdV); }
   // count isolated nodes and leaves; average in- and out-degree (skip leaves)
   { int i1=0, i2=0,l1=0,l2=0,r1=0,r2=0,ENet=0,EInf=0; double ci1=0,ci2=0,co1=0,co2=0;
   for (typename PGraph::TObj::TNodeI NI = InfG->BegNI(); NI < InfG->EndNI(); NI++) {
     if (NI.GetOutDeg()==0 && NI.GetInDeg()>0) { l1++; }
     if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) { r1++; }
     if (NI.GetDeg()==0) { i1++; }  if (NI.GetInDeg()>0) { ci1+=1; }
     if (NI.GetOutDeg()>0) { co1+=1; }  EInf+=NI.GetOutDeg(); }
   for (typename PGraph::TObj::TNodeI NI = NetG->BegNI(); NI < NetG->EndNI(); NI++) {
     if (NI.GetOutDeg()==0 && NI.GetInDeg()>0) { l2++; }
     if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) { r2++; }
     if (NI.GetDeg()==0) { i2++; }  if (NI.GetInDeg()>0) { ci2+=1; }
     if (NI.GetOutDeg()>0) { co2+=1; }  ENet+=NI.GetOutDeg(); }
   if(ci1>0)InDegInf.AddDat(P).Add(EInf/ci1);  if(ci2>0)InDegNet.AddDat(P).Add(ENet/ci2);
   if(co1>0)OutDegInf.AddDat(P).Add(EInf/co1); if(co2>0)OutDegNet.AddDat(P).Add(ENet/co2);
   NLfInf.AddDat(P).Add(l1/M);  NLfNet.AddDat(P).Add(l2/M);
   NRtInf.AddDat(P).Add(r1/M);  NRtNet.AddDat(P).Add(r2/M);
   NIsoInf.AddDat(P).Add(i1/M); NIsoNet.AddDat(P).Add(i2/M); }
   // cascade depth
   { const double M1 = DivByM ? CcNet->GetNodes() : 1;  IAssert(M1>=1);
   int Root=FindCascadeRoot(CcInf, NIdInfTmH);  TIntPrV HopCntV;
   TSnap::GetNodesAtHops(CcInf, Root, HopCntV, true);
   int MxN=0, Lev=0, IncL=0;
   for (int i = 0; i < HopCntV.Len(); i++) {
     if (MxN<HopCntV[i].Val2) { MxN=HopCntV[i].Val2; Lev=HopCntV[i].Val1; }
     if (i > 0 && HopCntV[i-1].Val2<=HopCntV[i].Val2) { IncL++; } }
   double D=0; int c=0; TIntH DistH;
   D = HopCntV.Last().Val1; c=1; // maximum depth
   if (c!=0 && D!=0) { D = D/c;
     DepthInf.AddDat(P).Add(D/M1); MxWidInf.AddDat(P).Add(MxN/M1);
     MxLevInf.AddDat(P).Add(Lev/D); IncLevInf.AddDat(P).Add(IncL/D);
   }
   Root=FindCascadeRoot(CcNet, NIdInfTmH);
   TSnap::GetNodesAtHops(CcNet, Root, HopCntV, true);
   MxN=0; Lev=0; IncL=0; D=0; c=0;
   for (int i = 0; i < HopCntV.Len(); i++) {
     if (MxN<HopCntV[i].Val2) { MxN=HopCntV[i].Val2; Lev=HopCntV[i].Val1; }
     if (i > 0 && HopCntV[i-1].Val2<=HopCntV[i].Val2) { IncL++; } }
   D = HopCntV.Last().Val1; c=1; // maximum depth
   if (c!=0 && D!=0) { D = D/c;
     DepthNet.AddDat(P).Add(D/M1); MxWidNet.AddDat(P).Add(MxN/M1);
     MxLevNet.AddDat(P).Add(Lev/D); IncLevNet.AddDat(P).Add(IncL/D); }
   }
 }
Example #2
0
int MxDegree(const PGraph& Graph) {
  
  int MaxDeg = 0;
  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    if (NI.GetDeg() > MaxDeg) {
      MaxDeg = NI.GetDeg();
    }
  }
  
  return MaxDeg;
}
Example #3
0
double PercentDegree(const PGraph& Graph, const int Threshold=0) {

    int Cnt = 0;
  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)
  {
    if (NI.GetDeg() >= Threshold) Cnt++;
  }

  return (double)Cnt / (double) Graph->GetNodes();
}
Example #4
0
int NodesGTEDegree(const PGraph& Graph, const int Threshold=0) {
  
  int Cnt = 0;
  for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI();
       NI++)
  {
    if (NI.GetDeg() >= Threshold) Cnt++;
  }
  
  return Cnt;
}