SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <circles.h>
Public Member Functions | |
TGraphAttributes (PUNGraph G, const char *nodeFeaturePath, const char *groundtruthPath) | |
~TGraphAttributes () | |
Public Attributes | |
PUNGraph | G |
TInt | NFeatures |
THash< TInt, TIntIntH > | NodeFeatures |
THash< TIntPr, TIntIntH > | EdgeFeatures |
TVec< TInt > | NodeIDs |
TCRef | CRef |
TVec< TIntSet > | GroundTruth |
TGraphAttributes::TGraphAttributes | ( | PUNGraph | G, |
const char * | nodeFeaturePath, | ||
const char * | groundtruthPath | ||
) |
G | the graph on which to run community detection |
nodeFeaturePath | the path of the file containing node attributes |
Definition at line 194 of file circles.h.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::AddKey(), THashSet< TKey, THashFunc >::AddKey(), THash< TKey, TDat, THashFunc >::BegI(), EdgeFeatures, THash< TKey, TDat, THashFunc >::GetDat(), GroundTruth, THashKeyDatI< TKey, TDat >::IsEnd(), THash< TKey, TDat, THashFunc >::IsKey(), TUNGraph::IsNode(), TVec< TVal, TSizeTy >::Len(), NFeatures, NodeFeatures, NodeIDs, and SEEK_CUR.
: 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; } } } } }
TGraphAttributes::~TGraphAttributes | ( | ) | [inline] |
Definition at line 19 of file circles.h.
Referenced by TCluster::Gradient(), TCluster::LogLikelihood(), TCluster::MCMC(), and TGraphAttributes().
Definition at line 15 of file circles.h.
Referenced by TCluster::Gradient(), TCluster::LogLikelihood(), and TCluster::MCMC().
Definition at line 23 of file circles.h.
Referenced by TGraphAttributes().
Definition at line 16 of file circles.h.
Referenced by TCluster::Gradient(), TCluster::LogLikelihood(), TCluster::MCMC(), TCluster::TCluster(), TGraphAttributes(), and TCluster::Train().
Definition at line 18 of file circles.h.
Referenced by TGraphAttributes().
Definition at line 20 of file circles.h.
Referenced by TCluster::MCMC(), TGraphAttributes(), and TCluster::Train().