Beispiel #1
0
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
  const int ExpClosedTr = 3;  // Expected closed triads
  const int ExpOpenTr = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  TFltPrV DegToCCfV;
  int64 ClosedTr = 0;
  int64 OpenTr = 0;

  TSnap::GetClustCf(GraphTUN, DegToCCfV, ClosedTr, OpenTr);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();
  DegToCCfV.Clr();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetClustCf(GraphTN, DegToCCfV, ClosedTr, OpenTr);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  DegToCCfV.Clr();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetClustCf(GraphTNE, DegToCCfV, ClosedTr, OpenTr);
  for (TFltPr *Pair = DegToCCfV.BegI(); Pair < DegToCCfV.EndI(); Pair++) {
    double Diff = Pair->Val2 - 5.0/9.0;   // Used for case 4
    Diff = (Diff < 0) ? -1.0*Diff : Diff; // Used for case 4
    switch ((int) Pair->Val1) {
      case 2:
        EXPECT_EQ(1.0, Pair->Val2);
        break;
      case 4:
        EXPECT_GT(0.00001, Diff); // Due to floats being imprecise
        break;
      case 7:
        EXPECT_EQ(2.0/3.0, Pair->Val2);
        break;
      case 15:
        EXPECT_EQ(0.3, Pair->Val2);
        break;
      default:
        ASSERT_FALSE(true); // Shouldn't have degrees other than listed
        break;
    }
  }
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);
}
Beispiel #2
0
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
  const int expected_closed = 3;  // Expected closed triads
  const int expected_open = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph Graph_TUNGraph = TriadGetTestTUNGraph();
  TFltPrV DegToCCfV;
  int64 closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TUNGraph, DegToCCfV, closed, open);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph Graph_TNGraph = TriadGetTestTNGraph();
  DegToCCfV.Clr();
  closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TNGraph, DegToCCfV, closed, open);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph Graph_TNEGraph = TriadGetTestTNEGraph();
  DegToCCfV.Clr();
  closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TNEGraph, DegToCCfV, closed, open);
  for (TFltPr *pair = DegToCCfV.BegI(); pair < DegToCCfV.EndI(); pair++) {
    double diff = pair->Val2 - 5.0/9.0;   // Used for case 4
    diff = (diff < 0) ? -1.0*diff : diff; // Used for case 4
    switch ((int) pair->Val1) {
      case 2:
        EXPECT_EQ(1.0, pair->Val2);
        break;
      case 4:
        EXPECT_GT(0.00001, diff); // Due to floats being imprecise
        break;
      case 7:
        EXPECT_EQ(2.0/3.0, pair->Val2);
        break;
      case 15:
        EXPECT_EQ(0.3, pair->Val2);
        break;
      default:
        ASSERT_FALSE(true); // Shouldn't have degrees other than listed
        break;
    }
  }
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);
}
Beispiel #3
0
void GetInvParticipRat(const PUNGraph& Graph, int MaxEigVecs, int TimeLimit, TFltPrV& EigValIprV) {
  TUNGraphMtx GraphMtx(Graph);
  TFltVV EigVecVV;
  TFltV EigValV;
  TExeTm ExeTm;
  if (MaxEigVecs<=1) { MaxEigVecs=1000; }
  int EigVecs = TMath::Mn(Graph->GetNodes(), MaxEigVecs);
  printf("start %d vecs...", EigVecs);
  try {
    TSparseSVD::Lanczos2(GraphMtx, EigVecs, TimeLimit, ssotFull, EigValV, EigVecVV, false);
  } catch(...) {
    printf("\n  ***EXCEPTION:  TRIED %d GOT %d values** \n", EigVecs, EigValV.Len()); }
  printf("  ***TRIED %d GOT %d values in %s\n", EigVecs, EigValV.Len(), ExeTm.GetStr());
  TFltV EigVec;
  EigValIprV.Clr();
  if (EigValV.Empty()) { return; }
  for (int v = 0; v < EigVecVV.GetCols(); v++) {
    EigVecVV.GetCol(v, EigVec);
    EigValIprV.Add(TFltPr(EigValV[v], GetInvParticipRat(EigVec)));
  }
  EigValIprV.Sort();
}