geometric_graph#
- graph_tool.generation.geometric_graph(points, radius, ranges=None, p=2)[git][source]#
Generate a geometric network from a set of N-dimensional points.
- Parameters:
- pointslist or
numpy.ndarray List of points. This must be a two-dimensional array, where the rows are coordinates in an N-dimensional space.
- radiusfloat
Pairs of points with a distance lower than or equal to this parameter will be connected.
- rangeslist or
numpy.ndarray(optional, default:None) If provided, periodic boundary conditions will be assumed, and the values of this parameter will be used as the ranges in all dimensions. It must be a two-dimensional array, where each row will contain the lower and upper bound of each dimension.
- p
float(optional, default:2) Exponent \(p \ge 1\) of the Minkowski distance \((\sum_i|x_i-y_i|^p)^{1/p}\), with
p=numpy.inffor the maximum norm \(\max_i|x_i-y_i|\). The default value corresponds to the euclidean distance.
- pointslist or
- Returns:
- geometric_graph
Graph The generated graph.
- pos
VertexPropertyMap A vertex property map with the position of each vertex.
- geometric_graph
See also
triangulation2D or 3D triangulation
random_graphRandom graph generation
latticeN-dimensional square lattice
Notes
A geometric graph [geometric-graph] is generated by connecting points embedded in an N-dimensional space which are at a distance equal to or smaller than a given radius, according to the Minkowski distance with exponent \(p\) (euclidean by default). The algorithm runs in time \(O(3^D N\langle n\rangle)\) for \(D\) dimensions, where \(\langle n\rangle\) is the average number of points in a cube of side \(2r\).
References
[geometric-graph]Jesper Dall and Michael Christensen, “Random geometric graphs”, Phys. Rev. E 66, 016121 (2002), DOI: 10.1103/PhysRevE.66.016121 [sci-hub, @tor]
Examples
>>> points = random((500, 2)) * 4 >>> g, pos = gt.geometric_graph(points, 0.3) >>> gt.graph_draw(g, pos=pos, output="geometric.pdf") <...>
>>> g, pos = gt.geometric_graph(points, 0.3, [(0,4), (0,4)]) >>> pos = gt.graph_draw(g, output="geometric_periodic.pdf")
With the maximum norm, the neighborhoods are squares instead of disks, which yields more edges for the same radius:
>>> g, pos = gt.geometric_graph(points, 0.3, p=np.inf) >>> print(g.num_edges()) 2613
Left: Geometric network with random points. Right: Same network, but with periodic boundary conditions.