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


C++ TFltV::BegI方法代码示例

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


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

示例1: GetGiniCoefficient

// Computes GINI coefficient of egonet as a subset of the parent graph (edges into and out of the egonet ARE considered)
double TSnap::GetGiniCoefficient(const TIntFltH DegH, const TIntV NIdV) {
  typename TIntV::TIter VI;
  typename TFltV::TIter DI;
  TFltV DegV;
  const int n = NIdV.Len();
  // DegV.Gen(n); // NOTE: don't use Gen() and Sort() on the same object (!)
  for (VI = NIdV.BegI(); VI < NIdV.EndI(); VI++) {
    DegV.Add(DegH.GetDat(VI->Val)); // might need to change this (in / out / undirected)
  }
  DegV.Sort();
  int i = 0;
  double numerator = 0.0, denominator = 0.0;
  for (DI = DegV.BegI(); DI < DegV.EndI(); DI++, i++) {
    numerator += (i + 1)*DegV[i];
    denominator += DegV[i];
  }
  return(double(2*numerator) / double(n*denominator) - double(n + 1) / double(n));
}
开发者ID:huisaddison,项目名称:snap,代码行数:19,代码来源:wstats.cpp

示例2: main

int main(int argc, char* argv[]) {
  
  setbuf(stdout, NULL); // disables the buffer so that print statements are not buffered and display immediately (?)
   
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs(TStr::Fmt("Vespignani backbone method. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
  
  TExeTm ExeTm;
  
  Try
  
  const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "input network");
  const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "output prefix (alpha value and filename extensions added)");
  double alpha = Env.GetIfArgPrefixFlt("-a:", 0.01, "alpha significance level threshold");
  const TStr AlphaVFNm = Env.GetIfArgPrefixStr("--alphav:", "", "vector of alpha significance level threshold (overrides -a)");
  const bool verbose = Env.GetIfArgPrefixBool("--verbose:", true, "verbose output for each step of the Vespignani method");

  const bool bootstrap = Env.GetIfArgPrefixBool("--bootstrap:", false, "bootstrap Vespignani method to retain --ratio of total weight W");
  const double ratio = Env.GetIfArgPrefixFlt("--ratio:", 0.50, "bootstrap target ratio of total weight W");
  const double lowerBound = Env.GetIfArgPrefixFlt("--lowerbound:", 0.0, "lower bound for alpha (binary search)");
  const double upperBound = Env.GetIfArgPrefixFlt("--upperbound:", 1.0, "upper bound for alpha (binary search)");
  const double tol = Env.GetIfArgPrefixFlt("--tolerance:", 5.0e-3, "tolerance for alpha (binary search)");
  const double spread = Env.GetIfArgPrefixFlt("--spread:", 2.0, "spread for bootstrapped alpha benchmark (binary search)");

  // Load graph and create directed and undirected graphs (pointer to the same memory)
  printf("\nLoading %s...", InFNm.CStr());
  const PFltWNGraph WGraph = TSnap::LoadFltWEdgeList<TWNGraph>(InFNm);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  
  TSnap::printFltWGraphSummary(WGraph, true, "\nWGraph\n------");
  
  // Variables
  
  PFltWNGraph WGraphCopy;
  TFltV AlphaV;
  TFltV::TIter VI;
  
  if (!AlphaVFNm.Empty()) {
    AlphaV = TSnap::LoadTxtFltV(AlphaVFNm);
  } else {
    if (bootstrap) {
      printf("\n");
      alpha = TSnap::FindVespignaniThreshold<TFlt, TWNGraph>(WGraph, ratio, tol, lowerBound, upperBound);
      AlphaV.Add(alpha / spread);
      AlphaV.Add(alpha);
      AlphaV.Add(alpha * spread);
    } else {
      AlphaV.Add(alpha);
    }
  }

  // VESPIGNANI METHOD

  Progress progress(ExeTm, AlphaV.Len(), 5, "Computing Vespignani method", !verbose);
  progress.start();
  if (verbose) {
    printf("\n");
  }
  int i = 0;
  for (VI = AlphaV.BegI(); VI < AlphaV.EndI(); VI++) {
    const double& alpha = VI->Val;
    
    // Compute method and save filtered

    printf("Computing Vespignani method (alpha: %e)\n\n", alpha);
    
    WGraphCopy = TSnap::FilterEdgesVespignani<TFlt, TWNGraph>(WGraph, alpha);
    TSnap::RemoveIsolated(WGraphCopy);
    TSnap::SaveFltWEdgeList(WGraphCopy, TStr::Fmt("%s-%9e.snap", OutFNm.CStr(), alpha), TStr::Fmt("Vespignani backbone with alpha: %e", alpha));

    // Save bootstrapped
    
    if (bootstrap && i == 1) {
      TSnap::SaveFltWEdgeList(WGraphCopy, TStr::Fmt("%s-bootstrapped.snap", OutFNm.CStr()), TStr::Fmt("Vespignani backbone with alpha: %e", alpha));
    }
    
    // Verbose summary

    if (verbose) {
      TSnap::printFltWGraphSummary(WGraphCopy, true, TStr::Fmt("WGraphCopy (alpha: %e)\n------", alpha));
      printf("\n");
    }

    i++;
    progress++;
  }

  Catch
  
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
  
}
开发者ID:jsw883,项目名称:snap,代码行数:93,代码来源:vespignani.cpp

示例3: main

int main(int argc, char* argv[]) {
  
  setbuf(stdout, NULL); // disables the buffer so that print statements are not buffered and display immediately (?)
   
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs(TStr::Fmt("Node centrality. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
  
  TExeTm ExeTm;
  
  Try
  
  const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "", "input network");
  const TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "output prefix (filename extensions added)");
  const TStr BseFNm = OutFNm.RightOfLast('/');
  const int k = Env.GetIfArgPrefixInt("-k:", 1, "depth of weighted degree distributions (1 / 2 / ...)");
  const bool c = Env.GetIfArgPrefixBool("-c:", false, "collate centralities into matrix (T / F)");
  
  // Load graph and create directed and undirected graphs (pointer to the same memory)
  printf("\nLoading %s...", InFNm.CStr());
  PFltWNGraph WGraph = TSnap::LoadFltWEdgeList<TWNGraph>(InFNm);
  printf(" DONE\n");
  printf("  nodes: %d\n", WGraph->GetNodes());
  printf("  edges: %d\n", WGraph->GetEdges());
  printf("  time elapsed: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  
  // Declare variables
  TIntFltVH FirstWDegVH;
  TIntFltVH kWInDegVH, kWOutDegVH, kWDegVH;
  TIntFltVH WDegCentrVH, WEigCentrVH;
  TFltV WEigDiffV;
  TIntFltH WPgRH;
  double WPgRDiff;
  TFltWNGraph::TNodeI NI;
  TFltV::TIter VI;
  
  // CENTRALITY (computations)
  
  // Weighted first degree distributions
  
  printf("\nComputing weighted degree distributions...");
  TSnap::GetWDegVH(WGraph, FirstWDegVH);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  
  // 1:k degree distributions
  
  printf("Computing egonet degrees for k = 1 to %d (in / out / undirected)\n", k);
  TSnap::TFixedMemorykWDeg<TFlt, TWNGraph> FixedMemorykWDeg(WGraph, k);
  printf("  ...");
  FixedMemorykWDeg.GetkWInDegSeqH(kWInDegVH);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  printf("  ...");
  FixedMemorykWDeg.GetkWOutDegSeqH(kWOutDegVH);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  printf("  ...");
  FixedMemorykWDeg.GetkWDegSeqH(kWDegVH);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  
  // Centrality measures
  
  printf("Computing weighted degree centrality...");
  TSnap::GetWDegreeCentrVH(WGraph, WDegCentrVH, 0.5);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  
  printf("Computing weighted eigenvector centrality...");
  WEigDiffV = TSnap::GetWEigenVectorCentrVH<TFlt>(WGraph, WEigCentrVH, 1e-4, 1000);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  printf("  convergence differences (in / out / undirected)\n");
  printf("    %f\n", double(WEigDiffV[0]));
  printf("    %f\n", double(WEigDiffV[1]));
  printf("    %f\n", double(WEigDiffV[2]));
  
  printf("Computing weighted PageRank centrality...");
  WPgRDiff = TSnap::GetWPageRank<TFlt>(WGraph, WPgRH, 0.85, 1e-4, 1000);
  printf(" DONE (time elapsed: %s (%s))\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  printf("  convergence difference: %f\n", double(WPgRDiff));
  
  // OUTPUTTING (mostly verbose printing statements, don't get scared)
  
  if (c) {
    
    printf("\nSaving %s.wcentr...", BseFNm.CStr());
    const TStr AggFNm = TStr::Fmt("%s.wcentr", OutFNm.CStr());
    FILE *F = fopen(AggFNm.CStr(), "wt");
    fprintf(F,"# Node centrality distributions on the directed / undirected graph (as applicable)\n");
    fprintf(F,"# Nodes: %d\tEdges: %d\n", WGraph->GetNodes(), WGraph->GetEdges());
    fprintf(F,"# NodeId\tWInDegCentr\tWOutDegCentr\tWDegCentr\tWInEigCentr\tWOutEigCentr\tWEigCentr\tWPgRCentr\n");
    for (NI = WGraph->BegNI(); NI < WGraph->EndNI(); NI++) {
      const int NId = NI.GetId(); fprintf(F, "%d", NId);
      const TFltV WDegCentrV = WDegCentrVH.GetDat(NId);
      for (VI = WDegCentrV.BegI(); VI < WDegCentrV.EndI(); VI++) { fprintf(F, "\t%f", VI->Val); }
      const TFltV WEigCentrV = WEigCentrVH.GetDat(NId);
      for (VI = WEigCentrV.BegI(); VI < WEigCentrV.EndI(); VI++) { fprintf(F, "\t%f", VI->Val); }
      const double WPgRCentr = WPgRH.GetDat(NId); fprintf(F, "\t%f", WPgRCentr);
      fprintf(F, "\n");
    }
    printf(" DONE\n");
    
  } else {
    
    printf("\nSaving %s.wdeg.centr...", BseFNm.CStr());
//.........这里部分代码省略.........
开发者ID:bpark738,项目名称:snap,代码行数:101,代码来源:wcentrality.cpp


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