SNAP Library 2.1, User Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TGraphAttributes Class Reference

#include <circles.h>

List of all members.

Public Member Functions

 TGraphAttributes (PUNGraph G, const char *nodeFeaturePath, const char *groundtruthPath)
 ~TGraphAttributes ()

Public Attributes

PUNGraph G
TInt NFeatures
THash< TInt, TIntIntHNodeFeatures
THash< TIntPr, TIntIntHEdgeFeatures
TVec< TIntNodeIDs
TCRef CRef
TVec< TIntSetGroundTruth

Detailed Description

Definition at line 5 of file circles.h.


Constructor & Destructor Documentation

TGraphAttributes::TGraphAttributes ( PUNGraph  G,
const char *  nodeFeaturePath,
const char *  groundtruthPath 
)
Parameters:
Gthe graph on which to run community detection
nodeFeaturePaththe path of the file containing node attributes

Definition at line 194 of file circles.h.

                                                                :
  G(G) {
  // Read node Features for the graph
  FILE* f = fopen(NodeFeaturePath, "r");
  int NNodes;
  int nF;
  fscanf(f, "%d %d", &NNodes, &nF);
  NFeatures = nF;

  for (int i = 0; i < NNodes; i++) {
    int nid;
    fscanf(f, "%d", &nid);

    if (not G->IsNode(nid)) {
      printf("Warning: %d is not a node in G.\n", nid);
    }
    TInt kv = NodeFeatures.AddKey(nid);
    for (int x = 0; x < nF; x++) {
      int z = 0;
      fscanf(f, "%d", &z);
      if (z) {
        NodeFeatures[kv].AddDat(x) = z;
      }
    }
    if (G->IsNode(nid)) {
      NodeIDs.Add(nid);
    }
  }
  fclose(f);
  
  f = fopen(GroundTruthPath, "r");
  if (f == NULL) {
    printf("Groundtruth file %s not found.\n", GroundTruthPath);
  }
  else {
    char* CircleName = new char [1000];
    while (fscanf(f, "%s", CircleName) == 1)
    {
      TIntSet Circle;
      while (true) {
        int nid;
        fscanf(f, "%d", &nid);
        Circle.AddKey(nid);
        char c;
        while (true) {          
          c = fgetc(f);
          if (c == '\n') break;
          if (c >= '0' and c <= '9') {
            fseek(f, -1, SEEK_CUR);
            break;
          }
        }
        if (c == '\n') break;
      }
      GroundTruth.Add(Circle);
    }
    delete [] CircleName;
  }
  fclose(f);

  // Construct the Features encoding the difference between node attributes.
  for (int i = 0; i < NodeIDs.Len(); i++) {
    TInt ni = NodeIDs[i];
    for (int j = i + 1; j < NodeIDs.Len(); j++) {
      TInt nj = NodeIDs[j];
      TInt kv = EdgeFeatures.AddKey(TIntPr(ni, nj));
      for (THashKeyDatI<TInt, TInt> it = NodeFeatures.GetDat(ni).BegI();
           not it.IsEnd(); it++) {
        TInt k = it.GetKey();
        TInt diff = 0;
        if (NodeFeatures.GetDat(nj).IsKey(k)) {
          diff = abs(it.GetDat() - NodeFeatures.GetDat(nj).GetDat(k));
        } else {
          diff = abs(it.GetDat());
        }
        if (diff) {
          EdgeFeatures[kv].AddDat(k) = diff;
        }
      }
      for (THashKeyDatI<TInt, TInt> it = NodeFeatures.GetDat(nj).BegI();
           not it.IsEnd(); it++) {
        TInt k = it.GetKey();
        TInt diff = 0;
        if (NodeFeatures.GetDat(ni).IsKey(k)) {
          diff = abs(it.GetDat() - NodeFeatures.GetDat(ni).GetDat(k));
        } else {
          diff = abs(it.GetDat());
        }
        if (diff) {
          EdgeFeatures[kv].AddDat(k) = diff;
        }
      }
    }
  }
}

Definition at line 12 of file circles.h.

                      {
  }

Member Data Documentation

Definition at line 21 of file circles.h.

Definition at line 15 of file circles.h.

Definition at line 23 of file circles.h.

Definition at line 16 of file circles.h.

Definition at line 20 of file circles.h.


The documentation for this class was generated from the following file: