SNAP Library 6.0, Developer Reference
2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include "Snap.h"
Go to the source code of this file.
Typedefs | |
typedef TVec< TFlt > | TFtr |
Feature of a node. More... | |
typedef THash< TInt, TFtr > | TIntFtrH |
The node-feature mapping: <node ID, feature>. More... | |
Functions | |
void | PrintFeatures (const TIntFtrH &Features) |
Prints all nodes' feature. More... | |
TIntFtrH | CreateEmptyFeatures (const PUNGraph Graph) |
Creates an empty node-feature mapping of all nodes in the given graph. More... | |
TIntFtrH | CreateEmptyFeatures (const TIntFtrH &Features) |
Creates an empty node-feature mapping of all nodes from an existing mapping. More... | |
int | GetNumFeatures (const TIntFtrH &Features) |
Gets number of features from the node-feature mapping. More... | |
TFtr | GetNthFeature (const TIntFtrH &Features, const int N) |
Gets the n-th feature of all nodes. More... | |
TIntFtrH | ExtractFeatures (const PUNGraph Graph) |
Performs feature extraction, the first step of RolX. More... | |
void | AddNeighborhoodFeatures (const PUNGraph Graph, TIntFtrH &Features) |
Adds neighborhood features (local + egonet) to the node-feature mapping. More... | |
void | AddRecursiveFeatures (const PUNGraph Graph, TIntFtrH &Features) |
Adds recursive features to the node-feature mapping. More... | |
void | AddLocalFeatures (const PUNGraph Graph, TIntFtrH &Features) |
Adds local features to the node-feature mapping. More... | |
void | AddEgonetFeatures (const PUNGraph Graph, TIntFtrH &Features) |
Adds egonet features to the node-feature mapping. More... | |
TIntFtrH | GenerateRecursiveFeatures (const PUNGraph Graph, const TIntFtrH &CurrFeatures) |
Generates recursive features out of current features. More... | |
TIntFtrH | PruneRecursiveFeatures (const PUNGraph Graph, const TIntFtrH &Features, const TIntFtrH &NewFeatures, const int SimilarityThreshold) |
Prunes recursive features. More... | |
void | AppendFeatures (TIntFtrH &DstFeatures, const TIntFtrH &SrcFeatures, const int ColIdx=-1) |
Appends all src features to dst features. More... | |
TIntFtrH | CalcVerticalLogBinning (const TIntFtrH &Features, const float BinFraction) |
Calculates vertical logarithmic binning features from the given features. More... | |
PUNGraph | BuildFeatureGraph (const TIntFtrH &LogFeatures, const int SimilarityThreshold) |
Builds s-friend graph given similarity threshold. More... | |
TIntFtrH | SummarizeConnectedComponents (const PUNGraph FeatureGraph, const TIntFtrH &Features, const TIntFtrH &NewFeatures) |
Summarizes s-friend graph and return retained features. More... | |
TVec< TInt > | GetNIdSorted (const TIntFtrH &Feature, const int Idx) |
Sorts the Idx-th feature, return the list of corresponding node ID. More... | |
void | AssignBinValue (const TVec< TInt > &SortedNId, const float BinFraction, TIntFtrH &LogBinFeatures) |
Assigns logarithmic binning value to features. More... | |
bool | IsSimilarFeature (const TFtr &F1, const TFtr &F2, const int SimilarityThreshold) |
Whether the two features are similar, given similarity threshold. More... | |
TFltVV | ConvertFeatureToMatrix (const TIntFtrH &Features, const TIntIntH &NodeIdMtxIdxH) |
Converts node-feature mapping to matrix. (i, j): i-th node, j-th feature. More... | |
void | PrintMatrix (const TFltVV &Matrix) |
Prints feature matrix to stdout. More... | |
TFltVV | CreateRandMatrix (const int XDim, const int YDim) |
Creates a random matrix with specified dimension. More... | |
bool | FltIsZero (const TFlt Number) |
Whether the float is zero. More... | |
void | CalcNonNegativeFactorization (const TFltVV &V, const int NumRoles, TFltVV &W, TFltVV &H, const double Threshold) |
Performs non-negative factorization V = WH. 2nd dim of W == number of roles. More... | |
TFlt | CalcDescriptionLength (const TFltVV &V, const TFltVV &G, const TFltVV &F) |
Calculates the description length L = M + E. More... | |
TIntIntH | CreateNodeIdMtxIdxHash (const TIntFtrH &Features) |
Creates the mapping of <node ID, matrix index>. More... | |
int | GetMtxIdx (const TInt NodeId, const TIntIntH &NodeIdMtxIdxH) |
Gets matrix index of the node ID. More... | |
TIntIntH | FindRoles (const TFltVV &G, const TIntIntH &NodeIdMtxIdxH) |
Gets matrix index of the node ID. More... | |
void | PlotRoles (const PUNGraph Graph, const TIntIntH &Roles) |
Plots found roles on a picture (.png). More... | |
void | PrintRoles (const TIntIntH &Roles) |
Prints found roles on stdout. More... | |
void | FPrintMatrix (const TFltVV &Matrix, const TStr &Path) |
Prints feature matrix to file. More... | |
void | FPrintNodeMappings (const TIntIntH &NodeIdMtxIdxH, const TStr &Path) |
Prints node mappings to file, feature line -> node ID. More... | |
void | FPrintRoles (const TIntIntH &Roles, const TStr &Path) |
Prints found roles to file. More... | |
Adds egonet features to the node-feature mapping.
Definition at line 87 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::GetDat(), and TSnap::GetEgonet().
Referenced by AddNeighborhoodFeatures().
Adds local features to the node-feature mapping.
Definition at line 81 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::GetDat().
Referenced by AddNeighborhoodFeatures().
Adds neighborhood features (local + egonet) to the node-feature mapping.
Definition at line 57 of file rolx.cpp.
References AddEgonetFeatures(), and AddLocalFeatures().
Referenced by ExtractFeatures().
Adds recursive features to the node-feature mapping.
Definition at line 64 of file rolx.cpp.
References AppendFeatures(), GenerateRecursiveFeatures(), GetNumFeatures(), and PruneRecursiveFeatures().
Referenced by ExtractFeatures().
Appends all src features to dst features.
Definition at line 131 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetDat(), TVec< TVal, TSizeTy >::GetDat(), and TVec< TVal, TSizeTy >::Len().
Referenced by AddRecursiveFeatures(), PruneRecursiveFeatures(), and SummarizeConnectedComponents().
void AssignBinValue | ( | const TVec< TInt > & | SortedNId, |
const float | BinFraction, | ||
TIntFtrH & | LogBinFeatures | ||
) |
Assigns logarithmic binning value to features.
Definition at line 212 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::GetDat(), and THash< TKey, TDat, THashFunc >::Len().
Referenced by CalcVerticalLogBinning().
Builds s-friend graph given similarity threshold.
Definition at line 158 of file rolx.cpp.
References GetNthFeature(), GetNumFeatures(), IsSimilarFeature(), and TPt< TRec >::New().
Referenced by PruneRecursiveFeatures().
Calculates the description length L = M + E.
Definition at line 352 of file rolx.cpp.
References FltIsZero(), TVVec< TVal, TSizeTy >::GetXDim(), TVVec< TVal, TSizeTy >::GetYDim(), TMath::Log(), and TLinAlg::Multiply().
void CalcNonNegativeFactorization | ( | const TFltVV & | V, |
const int | NumRoles, | ||
TFltVV & | W, | ||
TFltVV & | H, | ||
const double | Threshold | ||
) |
Performs non-negative factorization V = WH. 2nd dim of W == number of roles.
Definition at line 286 of file rolx.cpp.
References TFlt::Abs(), TVVec< TVal, TSizeTy >::At(), CreateRandMatrix(), FltIsZero(), TVVec< TVal, TSizeTy >::GetXDim(), TVVec< TVal, TSizeTy >::GetYDim(), TMath::Log(), and TLinAlg::Multiply().
Calculates vertical logarithmic binning features from the given features.
Definition at line 147 of file rolx.cpp.
References AssignBinValue(), CreateEmptyFeatures(), GetNIdSorted(), and GetNumFeatures().
Referenced by PruneRecursiveFeatures().
Converts node-feature mapping to matrix. (i, j): i-th node, j-th feature.
Definition at line 239 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), GetMtxIdx(), GetNumFeatures(), and THash< TKey, TDat, THashFunc >::Len().
Creates an empty node-feature mapping of all nodes in the given graph.
Definition at line 19 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::AddDat().
Referenced by CalcVerticalLogBinning(), ExtractFeatures(), GenerateRecursiveFeatures(), PruneRecursiveFeatures(), and SummarizeConnectedComponents().
Creates an empty node-feature mapping of all nodes from an existing mapping.
Definition at line 27 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
Creates the mapping of <node ID, matrix index>.
Definition at line 373 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
TFltVV CreateRandMatrix | ( | const int | XDim, |
const int | YDim | ||
) |
Creates a random matrix with specified dimension.
Definition at line 270 of file rolx.cpp.
Referenced by CalcNonNegativeFactorization().
Performs feature extraction, the first step of RolX.
Definition at line 48 of file rolx.cpp.
References AddNeighborhoodFeatures(), AddRecursiveFeatures(), and CreateEmptyFeatures().
Gets matrix index of the node ID.
Definition at line 398 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), GetNodeId(), TVVec< TVal, TSizeTy >::GetXDim(), TVVec< TVal, TSizeTy >::GetYDim(), and TFlt::Mn.
bool FltIsZero | ( | const TFlt | Number | ) |
Whether the float is zero.
Definition at line 282 of file rolx.cpp.
References TFlt::Abs(), and TFlt::Eps.
Referenced by CalcDescriptionLength(), and CalcNonNegativeFactorization().
Prints feature matrix to file.
Definition at line 434 of file rolx.cpp.
References TStr::CStr(), TVVec< TVal, TSizeTy >::GetXDim(), and TVVec< TVal, TSizeTy >::GetYDim().
Prints node mappings to file, feature line -> node ID.
Definition at line 451 of file rolx.cpp.
References TStr::CStr(), GetNodeId(), and THash< TKey, TDat, THashFunc >::Len().
Prints found roles to file.
Definition at line 462 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), TStr::CStr(), and THash< TKey, TDat, THashFunc >::EndI().
Generates recursive features out of current features.
Definition at line 97 of file rolx.cpp.
References CreateEmptyFeatures(), THash< TKey, TDat, THashFunc >::GetDat(), and GetNumFeatures().
Referenced by AddRecursiveFeatures().
Gets matrix index of the node ID.
Definition at line 383 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::GetDat().
Referenced by ConvertFeatureToMatrix().
Sorts the Idx-th feature, return the list of corresponding node ID.
Definition at line 199 of file rolx.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), and THash< TKey, TDat, THashFunc >::SortByDat().
Referenced by CalcVerticalLogBinning().
Gets the n-th feature of all nodes.
Definition at line 39 of file rolx.cpp.
References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), GetNumFeatures(), and IAssert.
Referenced by BuildFeatureGraph().
int GetNumFeatures | ( | const TIntFtrH & | Features | ) |
Gets number of features from the node-feature mapping.
Definition at line 35 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), and THashKeyDatI< TKey, TDat >::GetDat().
Referenced by AddRecursiveFeatures(), BuildFeatureGraph(), CalcVerticalLogBinning(), ConvertFeatureToMatrix(), GenerateRecursiveFeatures(), GetNthFeature(), and SummarizeConnectedComponents().
Whether the two features are similar, given similarity threshold.
Definition at line 228 of file rolx.cpp.
References TFlt::Abs(), IAssert, and TVec< TVal, TSizeTy >::Len().
Referenced by BuildFeatureGraph().
Plots found roles on a picture (.png).
Definition at line 415 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), TStr::CStr(), TSnap::DrawGViz(), THash< TKey, TDat, THashFunc >::EndI(), and gvlDot.
void PrintFeatures | ( | const TIntFtrH & | Features | ) |
Prints all nodes' feature.
Definition at line 5 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), TVec< TVal, TSizeTy >::GetDat(), and TVec< TVal, TSizeTy >::Len().
void PrintMatrix | ( | const TFltVV & | Matrix | ) |
Prints feature matrix to stdout.
Definition at line 253 of file rolx.cpp.
References TVVec< TVal, TSizeTy >::GetXDim(), and TVVec< TVal, TSizeTy >::GetYDim().
void PrintRoles | ( | const TIntIntH & | Roles | ) |
Prints found roles on stdout.
Definition at line 425 of file rolx.cpp.
References THash< TKey, TDat, THashFunc >::BegI(), and THash< TKey, TDat, THashFunc >::EndI().
TIntFtrH PruneRecursiveFeatures | ( | const PUNGraph | Graph, |
const TIntFtrH & | Features, | ||
const TIntFtrH & | NewFeatures, | ||
const int | SimilarityThreshold | ||
) |
Prunes recursive features.
Definition at line 119 of file rolx.cpp.
References AppendFeatures(), BuildFeatureGraph(), CalcVerticalLogBinning(), CreateEmptyFeatures(), and SummarizeConnectedComponents().
Referenced by AddRecursiveFeatures().
TIntFtrH SummarizeConnectedComponents | ( | const PUNGraph | FeatureGraph, |
const TIntFtrH & | Features, | ||
const TIntFtrH & | NewFeatures | ||
) |
Summarizes s-friend graph and return retained features.
Definition at line 178 of file rolx.cpp.
References TVec< TVal, TSizeTy >::Add(), AppendFeatures(), CreateEmptyFeatures(), GetNumFeatures(), TSnap::GetWccs(), TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().
Referenced by PruneRecursiveFeatures().