Package: graph-measures
Topological Graph FeaturesTopological feature calculators infrastructure.Calculating FeaturesThis package helps one to calculate features for a given graph. All features are implemented in python codes,
and some features have also an accelerated version written in C++. Among the accelerated features, one can find
a code for calculating 3- and 4-motifs using VDMC, a distributed algorithm to calculate 3- and 4-motifs in a
GPU-parallelized way.VersionsLast version: 0.1.55 (most recommended)What Features Can Be Calculated Here?The set of all vertex features implemented in graph-measures is the following:FeatureFeature's name in codeIs available in gpu?Output size for directed graphOutput size for undirected graphAverage neighbor degreeaverage_neighbor_degreeNON x 1N x 1Degree^degreeNON x 2N x 1In degreein_degreeNON x 1- - - - - - -Out degreeout_degreeNON x 1- - - - - - -Louvain^^louvainNO- - - - - - -N x 1Hierarchy energyhierarchy_energyNOMotifs3motif3YESN x 13N x 2Motifs4motif4YESN x 199N x 6K corek_coreYESN x 1N x 1Attraction basinattractor_basinYESN x 1- - - - - - -Page Rankpage_rankYESN x 1N x 1Fiedler vectorfiedler_vectorNO- - - - - - -N x 1Closeness centralitycloseness_centralityNON x 1N x 1EccentricityeccentricityNON x 1N x 1Load centralityload_centralityNON x 1N x 1BFS momentsbfs_momentsNON x 2N x 2FlowflowYESN x 1- - - - - - -Betweenness centralitybetweenness_centralityNON x 1N x 1Communicability betweenness centralitycommunicability_betweenness_centralityNO- - - - - - -N x ?Eigenvector centralityeigenvector_centralityNON x 1N x 1Clustering coefficientclustering_coefficientNON x 1N x 1Square clustering coefficientsquare_clustering_coefficientNON x 1N x 1Generalized degreegeneralized_degreeNO- - - - - - -N x 16All pairs shortest path lengthall_pairs_shortest_path_lengthNON x NN x N^ Degree - In the undirected case return the sum of the in degree and the out degree.^^Louvain - Implement Louvain community detection method, then associate to each vertex the number of vertices in its community.Aside from those, there are some otheredge features.
Some more information regarding the features can be found in the files offeatures_meta.Dependenciessetuptools
networkx==2.6.3
pandas
numpy
matplotlib
scipy
scikit-learn
python-louvain
bitstring
future
torchHow To Use The Accelerated Version (CPU/GPU)?Both versions currently are not supported with the pip installation.To use the accelerated version, one must useLinuxoperation systemandAnacondadistribution, with the follow the next steps:Go to thepackage's GitHub websiteand manually download:The directorygraphMeasures.The python filerunMakefileACC.py.You might need to download a zip of the repository and extract the necessary files.Place both the file and the directory inside your project, and runrunMakefileACC.py.Move to theboost environment:conda activate boost(The environment was created in step 2).Use the package as explained in the sectionHow To Use?Installation Through pipThe full functionality of the package is currently available on a Linux machine, with a Conda environment.Linux + Conda1. Go to base environment2. If pip is not installed on your env, install it. Then, use pip to install the packageOtherwise, pip must be installed.pip install graph-measuresNote:On Linux+Conda the installation might take longer (about 5-10 minuets) due to the compilation of the c++ files.How To Use?Even though one has installed the package asgraph-measures, The package should be imported from the code asgraphMesaures. Hence, use:fromgraphMeasuresimportFeatureCalculatorCalculating FeaturesThere are two main methods to calculate features:UsingFeatureCalculator(recommended):A class for calculating any requested features on a given graph.The graph is input to this class as a text-like file of edges, with a comma delimiter, or a networkxGraphobject.
For example, the graphexample_graph.txtis the following file:0,1
0,2
1,3
3,2Now, an implementation of feature calculations on this graph looks like this:importosfromgraphMeasuresimportFeatureCalculator# set of features to be calculatedfeats=["motif3","louvain"]# path to the graph's edgelist or nx.Graph objectgraph=os.path.join("measure_tests","example_graph.txt")# The path in which one would like to save the pickled features calculated in the process.dir_path=""# More options are shown here. For information about them, refer to the file.ftr_calc=FeatureCalculator(path,feats,dir_path=dir_path,acc=True,directed=False,gpu=True,device=0,verbose=True)# Calculates the features. If one do not want the features to be saved,# one should set the parameter 'should_dump' to False (set to True by default).# If the features was already saved, you can set force_build to be True.ftr_calc.calculate_features(force_build=True)features=ftr_calc.get_features()# return pandas Dataframe with the featuresNote:If one setacc=Truewithout using a Linux+Conda machine, an exception will be thrown.Note:If one setgpu=Truewithout using a Linux+Conda machine that has cuda available on it, an exception will be thrown.2. Using graphMeasurewithout FeatureCalculator(**less recommended**).Edges motifs:For now, you can calculate only motifs for edges. Unfortunately, you will have to do it separately from the nodes features.
There are two options for motif calculation - python version, and accelerated version (in CPP).
The python version is always available, but the accelerated version available only on linux machine
(the makefile targets linux, but the code should work for any os). Anyway, if you have a suitable machine,
the accelerated version is more recommended.To run the accelerated version you should do:Copy the graphMeasures directory to your project (available in this branch).Open terminal ingraphMeasures/edges_features/acc_features/acc/Run the commandmake. If the makefile ends normally, a so file should be in a dir named bin.Execution example:importnetworkxasnxfromgraphMeasures.edges_features.feature_calculatorimportFeatureCalculatorpath="./data/graph.txt"gnx=nx.read_edgelist(path,delimiter=",",create_using=nx.DiGraph)# acc signs if we will use the accelerated version.calculator=FeatureCalculator(["motif3","motif4"],gnx,acc=True)calculator.build()# The result will be a pandas Dataframe named calculator.df.print(calculator.df)Contact usThis package was written byYolo lab'steam from Bar-Ilan University.For questions, comments or suggestions you can contactlouzouy@math.biu.ac.il.