local_scan#
- graph_tool.clustering.local_scan(g, k=1, weight=None, mode='all', prop=None)[git][source]#
Compute the local scan statistics of every vertex.
- Parameters:
- g
Graph Graph to be used.
- k
int(optional, default:1) Radius of the neighborhoods.
- weight
EdgePropertyMap(optional, default:None) Edge weights. If given, the total weight of the edges is computed, instead of their number.
- mode
str(optional, default:"all") For directed graphs, the edges that define the neighborhoods:
"out","in", or"all"(both). It has no effect for undirected graphs.- prop
VertexPropertyMap(optional, default:None) Vertex property map of type
doublewhere the values will be stored. If not given, a new one is created.
- g
- Returns:
- scan
VertexPropertyMap The local scan statistic of every vertex.
- scan
See also
local_clusteringLocal clustering coefficient
graph_tool.structure.ego_graphNeighborhood subgraph of a vertex
Notes
The local scan statistic [priebe-scan-2005] of a vertex \(v\) with radius \(k\ge 1\) is the number of edges (or their total weight) of the subgraph induced by the vertices at distance at most \(k\) from \(v\) (including \(v\) itself), where the distances follow the edges chosen by
mode; all edges between these vertices are counted, regardless of their direction. For \(k=0\), it is the degree (or the weighted degree) of \(v\), according tomode. The maximum over the vertices is the scan statistic of Priebe et al., used for anomaly detection in time series of graphs. For \(k=1\) in undirected graphs, it is the degree plus the number of triangles of \(v\).The algorithm runs in time \(O(\sum_v E_k(v))\), where \(E_k(v)\) is the number of edges incident on the vertices at distance at most \(k\) from \(v\).
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
References
[priebe-scan-2005]Carey E. Priebe, John M. Conroy, David J. Marchette and Youngser Park, “Scan statistics on Enron graphs”, Computational and Mathematical Organization Theory 11, 229-247 (2005), DOI: 10.1007/s10588-005-5378-z [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> s = gt.local_scan(g) >>> print(s.a[:10]) [34. 21. 21. 16. 5. 7. 7. 10. 10. 2.] >>> print(gt.local_scan(g, k=2).a.max()) 76.0
The values can be visualized by drawing the network with vertex colors and sizes given by them:
>>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=s, vcmap=cmap, ... vertex_size=gt.prop_to_size(s, mi=5, ma=15), ... output="local_scan-karate.pdf") <...>
Local scan statistics with radius one of the vertices of Zachary’s karate club network. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#