当前位置: 首页>>代码示例>>C++>>正文


C++ TIntPrV::Last方法代码示例

本文整理汇总了C++中TIntPrV::Last方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntPrV::Last方法的具体用法?C++ TIntPrV::Last怎么用?C++ TIntPrV::Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TIntPrV的用法示例。


在下文中一共展示了TIntPrV::Last方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TakeStat

 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); }
   }
 }
开发者ID:SherlockYang,项目名称:Archive,代码行数:59,代码来源:cascades.cpp

示例2: GetAvgDepthFromRoot

 double GetAvgDepthFromRoot(const PGraph& G) {
   TMom Mom;
   TIntPrV HopCntV;
   for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
     if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) {
       TSnap::GetNodesAtHops(G, NI.GetId(), HopCntV, true);
       Mom.Add(HopCntV.Last().Val1()); }
   }
   Mom.Def();  return Mom.GetMean();
 }
开发者ID:SherlockYang,项目名称:Archive,代码行数:10,代码来源:cascades.cpp

示例3: GetNGramIdV

void TNGramBs::GetNGramIdV(
 const TStr& HtmlStr, TIntV& NGramIdV, TIntPrV& NGramBEChXPrV) const {
  // create MxNGramLen queues
  TVec<TIntQ> WIdQV(MxNGramLen);
  TVec<TIntPrQ> BEChXPrQV(MxNGramLen);
  for (int NGramLen=1; NGramLen<MxNGramLen; NGramLen++){
    WIdQV[NGramLen].Gen(100*NGramLen, NGramLen+1);
    BEChXPrQV[NGramLen].Gen(100*NGramLen, NGramLen+1);
  }
  bool AllWIdQClrP=true;
  // extract words from text-string
  PSIn HtmlSIn=TStrIn::New(HtmlStr, false);
  THtmlLx HtmlLx(HtmlSIn);
  while (HtmlLx.Sym!=hsyEof){
    if ((HtmlLx.Sym==hsyStr)||(HtmlLx.Sym==hsyNum)){
      // get word-string & word-id
      TStr WordStr=HtmlLx.UcChA;
      int WId; int SymBChX=HtmlLx.SymBChX; int SymEChX=HtmlLx.SymEChX;
      if ((SwSet.Empty())||(!SwSet->IsIn(WordStr))){
        if (!Stemmer.Empty()){
          WordStr=Stemmer->GetStem(WordStr);}
        if (IsWord(WordStr, WId)){
          if (!IsSkipWord(WId)){
            NGramIdV.Add(0+WId); // add single word
            NGramBEChXPrV.Add(TIntPr(SymBChX, SymEChX)); // add positions
            for (int NGramLen=1; NGramLen<MxNGramLen; NGramLen++){
              TIntQ& WIdQ=WIdQV[NGramLen];
              TIntPrQ& BEChXPrQ=BEChXPrQV[NGramLen];
              WIdQ.Push(WId); BEChXPrQ.Push(TIntPr(SymBChX, SymEChX));
              AllWIdQClrP=false;
              // if queue full
              if (WIdQ.Len()==NGramLen+1){
                // create sequence
                TIntV WIdV; WIdQ.GetSubValVec(0, WIdQ.Len()-1, WIdV);
                TIntPrV BEChXPrV; BEChXPrQ.GetSubValVec(0, BEChXPrQ.Len()-1, BEChXPrV);
                // add ngram-id or reset queues
                int WIdVP;
                if (WIdVToFqH.IsKey(WIdV, WIdVP)){ // if sequence is frequent
                  int NGramId=GetWords()+WIdVP; // get sequence ngram-id
                  NGramIdV.Add(NGramId); // add sequence ngram-id
                  NGramBEChXPrV.Add(TIntPr(BEChXPrV[0].Val1, BEChXPrV.Last().Val2)); // add positions
                }
              }
            }
          }
        } else {
          // break queue sequences if infrequent word occures
          if (!AllWIdQClrP){
            for (int NGramLen=1; NGramLen<MxNGramLen; NGramLen++){
              TIntQ& WIdQ=WIdQV[NGramLen];
              TIntPrQ& BEChXPrQ=BEChXPrQV[NGramLen];
              if (!WIdQ.Empty()){WIdQ.Clr(); BEChXPrQ.Clr();}
            }
            AllWIdQClrP=true;
          }
        }
      }
    }
    // get next symbol
    HtmlLx.GetSym();
  }
}
开发者ID:bergloman,项目名称:qminer,代码行数:62,代码来源:phrase.cpp


注:本文中的TIntPrV::Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。