visibility_graph#
- graph_tool.generation.visibility_graph(series)[git][source]#
Return the natural visibility graph of a time series.
- Parameters:
- seriesiterable of
float Values \(y_i\) of the time series.
- seriesiterable of
- Returns:
- g
Graph The undirected visibility graph, where vertex \(i\) corresponds to the value \(y_i\).
- g
See also
interval_graphIntersection graph of intervals
geometric_graphGeometric graph of points within a given distance
Notes
In the natural visibility graph of Lacasa et al. [lacasa-time-2008], two values \(y_i\) and \(y_j\) (\(i < j\)) are connected if every intermediate value lies strictly below the straight line between them, i.e. \(y_k < y_i + (y_j - y_i)(k - i)/(j - i)\) for all \(i < k < j\). For fixed \(i\), this holds if and only if the slope from \(i\) to \(j\) exceeds the slopes to all intermediate values, which are swept once, in time \(O(N^2)\) overall.
References
[lacasa-time-2008]Lucas Lacasa, Bartolo Luque, Fernando Ballesteros, Jordi Luque and Juan Carlos Nuño, “From time series to complex networks: The visibility graph”, Proceedings of the National Academy of Sciences 105, 4972-4975 (2008), DOI: 10.1073/pnas.0709247105 [sci-hub, @tor], arXiv: 0810.0920
Examples
>>> g = gt.visibility_graph([3, 1, 2, 1, 4]) >>> print(sorted(tuple(sorted(e)) for e in g.get_edges().tolist())) [(0, 1), (0, 2), (0, 4), (1, 2), (2, 3), (2, 4), (3, 4)]
The visibility graph of a random series is drawn as follows, with every vertex \(i\) at the position \((i, y_i)\):
>>> y = np.random.random(30) >>> g = gt.visibility_graph(y) >>> pos = g.new_vp("vector<double>", vals=np.array([np.arange(30) / 3, ... -8 * y]).T) >>> gt.graph_draw(g, pos=pos, ... output="visibility_graph-random.pdf") <...>
Natural visibility graph of a series of 30 values \(y_i\) drawn uniformly from \([0, 1]\), with the vertex \(i\) at the position \((i, y_i)\) (up to a scaling of the axes).#