SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TGraphAttributes Class Reference

#include <circles.h>

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.

195  :
196  G(G) {
197  // Read node Features for the graph
198  FILE* f = fopen(NodeFeaturePath, "r");
199  int NNodes;
200  int nF;
201  fscanf(f, "%d %d", &NNodes, &nF);
202  NFeatures = nF;
203 
204  for (int i = 0; i < NNodes; i++) {
205  int nid;
206  fscanf(f, "%d", &nid);
207 
208  if (!G->IsNode(nid)) {
209  printf("Warning: %d is not a node in G.\n", nid);
210  }
211  TInt kv = NodeFeatures.AddKey(nid);
212  for (int x = 0; x < nF; x++) {
213  int z = 0;
214  fscanf(f, "%d", &z);
215  if (z) {
216  NodeFeatures[kv].AddDat(x) = z;
217  }
218  }
219  if (G->IsNode(nid)) {
220  NodeIDs.Add(nid);
221  }
222  }
223  fclose(f);
224 
225  f = fopen(GroundTruthPath, "r");
226  if (f == NULL) {
227  printf("Groundtruth file %s not found.\n", GroundTruthPath);
228  }
229  else {
230  char* CircleName = new char [1000];
231  while (fscanf(f, "%s", CircleName) == 1)
232  {
233  TIntSet Circle;
234  while (true) {
235  int nid;
236  fscanf(f, "%d", &nid);
237  Circle.AddKey(nid);
238  char c;
239  while (true) {
240  c = fgetc(f);
241  if (c == '\n') break;
242  if (c >= '0' && c <= '9') {
243  fseek(f, -1, SEEK_CUR);
244  break;
245  }
246  }
247  if (c == '\n') break;
248  }
249  GroundTruth.Add(Circle);
250  }
251  delete [] CircleName;
252  }
253  fclose(f);
254 
255  // Construct the Features encoding the difference between node attributes.
256  for (int i = 0; i < NodeIDs.Len(); i++) {
257  TInt ni = NodeIDs[i];
258  for (int j = i + 1; j < NodeIDs.Len(); j++) {
259  TInt nj = NodeIDs[j];
260  TInt kv = EdgeFeatures.AddKey(TIntPr(ni, nj));
261  for (THashKeyDatI<TInt, TInt> it = NodeFeatures.GetDat(ni).BegI();
262  !it.IsEnd(); it++) {
263  TInt k = it.GetKey();
264  TInt diff = 0;
265  if (NodeFeatures.GetDat(nj).IsKey(k)) {
266  diff = abs(it.GetDat() - NodeFeatures.GetDat(nj).GetDat(k));
267  } else {
268  diff = abs(it.GetDat());
269  }
270  if (diff) {
271  EdgeFeatures[kv].AddDat(k) = diff;
272  }
273  }
274  for (THashKeyDatI<TInt, TInt> it = NodeFeatures.GetDat(nj).BegI();
275  !it.IsEnd(); it++) {
276  TInt k = it.GetKey();
277  TInt diff = 0;
278  if (NodeFeatures.GetDat(ni).IsKey(k)) {
279  diff = abs(it.GetDat() - NodeFeatures.GetDat(ni).GetDat(k));
280  } else {
281  diff = abs(it.GetDat());
282  }
283  if (diff) {
284  EdgeFeatures[kv].AddDat(k) = diff;
285  }
286  }
287  }
288  }
289 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
#define SEEK_CUR
Definition: fl.cpp:968
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
THash< TInt, TIntIntH > NodeFeatures
Definition: circles.h:18
THash< TIntPr, TIntIntH > EdgeFeatures
Definition: circles.h:19
int AddKey(const TKey &Key)
Definition: shash.h:1254
TVec< TIntSet > GroundTruth
Definition: circles.h:23
Definition: dt.h:1137
TInt NFeatures
Definition: circles.h:16
PUNGraph G
Definition: circles.h:15
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TVec< TInt > NodeIDs
Definition: circles.h:20
TGraphAttributes::~TGraphAttributes ( )
inline

Definition at line 12 of file circles.h.

12  {
13  }

Member Data Documentation

TCRef TGraphAttributes::CRef

Definition at line 21 of file circles.h.

THash<TIntPr, TIntIntH> TGraphAttributes::EdgeFeatures

Definition at line 19 of file circles.h.

PUNGraph TGraphAttributes::G

Definition at line 15 of file circles.h.

TVec<TIntSet> TGraphAttributes::GroundTruth

Definition at line 23 of file circles.h.

TInt TGraphAttributes::NFeatures

Definition at line 16 of file circles.h.

THash<TInt, TIntIntH> TGraphAttributes::NodeFeatures

Definition at line 18 of file circles.h.

TVec<TInt> TGraphAttributes::NodeIDs

Definition at line 20 of file circles.h.


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