This module includes centrality-related algorithms.
| pagerank (g[, damping, prop, epslon, ...]) | Calculate the PageRank of each vertex. |
| betweenness (g[, vprop, eprop, weight, ...]) | Calculate the betweenness centrality for each vertex and edge. |
| central_point_dominance (g, betweenness) | Calculate the central point dominance of the graph, given the betweenness centrality of each vertex. |
| eigentrust (g, trust_map[, vprop, norm, epslon, ...]) | Calculate the eigentrust centrality of each vertex in the graph. |
| absolute_trust (g, trust_map, source[, target, vprop]) | Calculate the absolute trust centrality of each vertex in the graph, from a given source. |
Calculate the PageRank of each vertex.
| Parameters: | g : Graph
damping : float, optional (default: 0.8)
prop : PropertyMap, optional (default: None)
epslon : float, optional (default: 1e-6)
max_iter : int, optional (default: None)
ret_iter : bool, optional (default: False)
|
|---|---|
| Returns: | pagerank : PropertyMap
|
See also
Notes
The value of PageRank [pagerank-wikipedia] of vertex v PR(v) is given interactively by the relation:
where \Gamma^{-}(v) are the in-neighbours of v, d^{+}(w) is the out-degree of w, and d is a damping factor.
The implemented algorithm progressively iterates the above condition, until it no longer changes, according to the parameter epslon. It has a topology-dependent running time.
If enabled during compilation, this algorithm runs in parallel.
References
| [pagerank-wikipedia] | http://en.wikipedia.org/wiki/Pagerank |
| [lawrence-pagerank-1998] | P. Lawrence, B. Sergey, M. Rajeev, W. Terry, “The pagerank citation ranking: Bringing order to the web”, Technical report, Stanford University, 1998 |
Examples
>>> from numpy.random import poisson, seed
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> pr = gt.pagerank(g)
>>> print pr.a
[ 0.63876901 1.13528868 0.31465963 0.55855277 0.2 0.75605741
0.42628689 0.53066254 0.55004112 0.91717076 0.71164749 0.32015438
0.67275227 1.08207389 1.14412231 0.9049167 1.32002 1.4692142
0.76549771 0.71510277 0.23732927 0.40844911 0.2 0.27912876
0.71309781 0.32015438 1.3376236 0.31352887 0.59346569 0.33381039
0.67300081 0.73318264 0.65812653 0.73409673 0.93051993 0.83241145
1.59816568 0.43979363 0.2512247 1.15663357 0.2 0.35977148
0.72182022 1.01267711 0.76304859 0.49247376 0.49384283 1.8436647
0.64312224 1.00778243 0.62287633 1.15215387 0.56176895 0.7166227
0.56506109 0.67104337 0.95570565 0.27996953 0.79975983 0.33631497
1.09471419 0.33631497 0.2512247 2.09126732 0.68157485 0.2
0.37140185 0.65619459 1.27370737 0.48383225 1.36125161 0.2
0.78300573 1.03427279 0.56904755 1.66077917 1.73302035 0.28749261
0.83143045 1.04969728 0.70090048 0.55991433 0.68440994 0.2
0.34018009 0.45485484 0.28 1.2015438 2.11850885 1.24990775
0.59914308 0.59989185 0.73535564 0.78168417 0.55390281 0.38627667
1.42274704 0.51105348 0.92550979 1.27968065]
Calculate the betweenness centrality for each vertex and edge.
| Parameters: | g : Graph
vprop : PropertyMap, optional (default: None)
eprop : PropertyMap, optional (default: None)
weight : PropertyMap, optional (default: None)
norm : bool, optional (default: True)
|
|---|---|
| Returns: | vertex_betweenness : A vertex property map with the vertex betweenness
edge_betweenness : An edge property map with the edge betweenness
|
See also
Notes
Betweenness centrality of a vertex C_B(v) is defined as,
where \sigma_{st} is the number of shortest geodesic paths from s to t, and \sigma_{st}(v) is the number of shortest geodesic paths from s to t that pass through a vertex v. This may be normalised by dividing through the number of pairs of vertices not including v, which is (n-1)(n-2)/2.
The algorithm used here is defined in [brandes-faster-2001], and has a complexity of O(VE) for unweighted graphs and O(VE + V(V+E) \log V) for weighted graphs. The space complexity is O(VE).
If enabled during compilation, this algorithm runs in parallel.
References
| [betweenness-wikipedia] | http://en.wikipedia.org/wiki/Centrality#Betweenness_centrality |
| [brandes-faster-2001] | U. Brandes, “A faster algorithm for betweenness centrality”, Journal of Mathematical Sociology, 2001 |
Examples
>>> from numpy.random import poisson, seed
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g)
>>> print vb.a
[ 0.03395047 0.07911989 0.00702948 0.02337119 0. 0.02930099
0.01684377 0.02558675 0.03440095 0.02886187 0.03124262 0.00975953
0.01307953 0.03938858 0.07266505 0.01313647 0. 0.06450598
0.0575418 0.00525468 0.00466089 0.01803829 0. 0.00050161
0.0085034 0.02362432 0.05620574 0.00097157 0.04006816 0.01301474
0.02154916 0. 0.06009194 0.02780363 0.08963522 0.04049657
0.06993559 0.02082698 0.00288318 0.03264322 0. 0.03641759
0.01083859 0.03750864 0.04079359 0.02092599 0. 0.02153655
0. 0.05674631 0.03861911 0.05473282 0.00904367 0.03249097
0.00894043 0.0192741 0.03379204 0.02125998 0.0018321 0.0013495
0.0336502 0.0210088 0.00125318 0.0489189 0.05254974 0.
0.00432189 0.04866168 0.06444727 0.02508525 0.02533085 0.
0.05308703 0.02539854 0.02270809 0.044889 0.04766016 0.0086368
0.01501699 0. 0.03107868 0.0054221 0. 0.
0.00596081 0.01183977 0.00159761 0.11435876 0.03988501 0.05128991
0.04558135 0.02303469 0.05092032 0.04700221 0.00927644 0.00841903
0. 0.03243633 0.04514374 0.05170213]
Calculate the central point dominance of the graph, given the betweenness centrality of each vertex.
| Parameters: | g : Graph
betweenness : PropertyMap
|
|---|---|
| Returns: | cp : float
|
See also
Notes
Let v^* be the vertex with the largest relative betweenness centrality; then, the central point dominance [freeman-set-1977] is defined as:
where C_B(v) is the normalized betweenness centrality of vertex v. The value of C_B lies in the range [0,1].
The algorithm has a complexity of O(V).
References
| [freeman-set-1977] | Linton C. Freeman, “A Set of Measures of Centrality Based on Betweenness”, Sociometry, Vol. 40, No. 1, pp. 35-41 (1977) |
Examples
>>> from numpy.random import poisson, seed
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g)
>>> print gt.central_point_dominance(g, vb)
0.0884414811909
Calculate the eigentrust centrality of each vertex in the graph.
| Parameters: | g : Graph
trust_map : PropertyMap
vprop : PropertyMap, optional (default: None)
norm : bool, optional (default: false)
epslon : float, optional (default: 1e-6)
max_iter : int, optional (default: None)
ret_iter : bool, optional (default: False)
|
|---|---|
| Returns: | eigentrust : A vertex property map containing the eigentrust values. |
See also
Notes
The eigentrust [kamvar-eigentrust-2003] values t_i correspond the following limit
where c_i = 1/|V| and the elements of the matrix C are the normalized trust values:
The algorithm has a topology-dependent complexity.
If enabled during compilation, this algorithm runs in parallel.
References
| [kamvar-eigentrust-2003] | S. D. Kamvar, M. T. Schlosser, H. Garcia-Molina “The eigentrust algorithm for reputation management in p2p networks”, Proceedings of the 12th international conference on World Wide Web, Pages: 640 - 651, 2003 |
Examples
>>> from numpy.random import poisson, random, seed
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> trust = g.new_edge_property("double")
>>> trust.get_array()[:] = random(g.num_edges())*42
>>> t = gt.eigentrust(g, trust, norm=True)
>>> print t.get_array()
[ 5.51422638e-03 1.12397965e-02 2.34959294e-04 6.32738574e-03
0.00000000e+00 6.34804836e-03 2.67885424e-03 4.02497751e-03
1.67943467e-02 6.46196106e-03 1.92402451e-02 9.04032352e-04
9.70843104e-03 1.40319816e-02 1.04995777e-02 2.86712231e-02
2.47285894e-02 2.38394469e-02 7.06936059e-03 9.45794717e-03
2.09970054e-05 1.64768298e-03 0.00000000e+00 1.19346706e-03
6.88434371e-03 5.36337333e-03 2.08428677e-02 2.85813783e-03
1.10564670e-02 3.16345060e-04 5.25737238e-03 5.43761445e-03
7.98048389e-03 7.95939648e-03 2.23891858e-02 5.68630666e-03
2.09300588e-02 4.28902068e-03 1.70833078e-03 2.37814042e-02
0.00000000e+00 1.20805010e-03 1.29713483e-02 5.73021992e-03
8.71093674e-03 7.77661067e-03 8.76489806e-04 2.38519385e-02
3.53225723e-03 8.46948906e-03 5.09874234e-03 2.44547150e-02
1.32342629e-02 1.80085559e-03 4.37189381e-03 1.18195253e-02
1.62748861e-02 1.83200678e-04 1.09745025e-02 1.47544090e-03
3.34512926e-02 1.58885132e-03 1.13128910e-03 3.04944830e-02
4.22684975e-03 0.00000000e+00 9.89654274e-04 4.25927156e-03
2.34516214e-02 4.91370905e-03 2.29366664e-02 0.00000000e+00
6.83407601e-03 1.60508753e-02 1.62762068e-03 3.94324856e-02
2.84109571e-02 8.81167727e-04 2.16999908e-02 1.28688125e-02
1.10825963e-02 2.64915564e-03 2.88711928e-03 0.00000000e+00
4.24392252e-03 9.38398819e-03 0.00000000e+00 1.74508371e-02
3.26594153e-02 4.07188867e-02 3.20678152e-03 6.35046287e-03
8.07061556e-03 5.08505374e-03 3.27300367e-03 3.30989070e-03
2.30651195e-02 4.20338525e-03 5.04332662e-03 3.58731532e-02]
Calculate the absolute trust centrality of each vertex in the graph, from a given source.
| Parameters: | g : Graph
trust_map : PropertyMap
source : Vertex
target : Vertex (optional, default: None)
vprop : PropertyMap (optional, default: None)
|
|---|---|
| Returns: | absolute_trust : PropertyMap or float
|
See also
Notes
The absolute trust between vertices i and j is defined as
where A_{ij} is the adjacency matrix, c_{ij} is the direct trust from i to j, and w_G(i\to j) is the weight of the path with maximum weight from i to j, computed as
The algorithm measures the absolute trust by finding the paths with maximum weight, using Dijkstra’s algorithm, to all in-neighbours of a given target. This search needs to be performed repeatedly for every target, since it needs to be removed from the graph first. The resulting complexity is therefore O(N^2\log N) for all targets, and O(N\log N) for a single target.
If enabled during compilation, this algorithm runs in parallel.
Examples
>>> from numpy.random import poisson, random, seed
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> trust = g.new_edge_property("double")
>>> trust.a = random(g.num_edges())
>>> t = gt.absolute_trust(g, trust, source=g.vertex(0))
>>> print t.a
[ 0.16260667 0.04129912 0.13735376 0.19146125 0. 0.09147461
0.10371912 0.12465511 0.24631221 0.0603916 0.2375385 0.06637879
0.08897662 0.0800988 0.05250601 0.66759022 0.09368793 0.08275437
0.13674709 0.15553915 0.01376162 0.417068 0. 0.06096886
0.08746817 0.39380693 0.09215297 0.09575144 0.15594162 0.04008874
0.05483972 0.05691086 0.13571077 0.32376012 0.22477937 0.06347962
0.10445085 0.19447845 0.38007043 0.13810585 0. 0.08451096
0.06648153 0.18479174 0.13003649 0.14850631 0.00320603 0.1074644
0.12088162 0.06792678 0.08472666 0.2002143 0.25963204 0.37838425
0.03089371 0.18389694 0.39420339 0.03348093 0.11483196 0.0656204
0.14206403 0.07066434 0.25168986 0.07040126 0.04870569 0.
0.09861349 0.03882069 0.1105267 0.07951823 0.08748441 0.
0.08393443 0.11121719 0.21903223 0.25529628 0.0414386 0.03695558
0.17664854 0.05143033 0.11735779 0.06525968 0.19600919 0. 0.1220922
0.33330041 0. 0.28595961 0.14526678 0.12514885 0.089524
0.40738962 0.03719195 0.54409979 0.06247424 0.10660136 0.11674385
0.13218144 0.02214988 0.23215937]