Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.generators.geometric.geographical_threshold_graph

geographical_threshold_graph(n, theta, dim=2, pos=None, weight=None, metric=None, p_dist=None, seed=None)[source]

Returns a geographical threshold graph.

The geographical threshold graph model places \(n\) nodes uniformly at random in a rectangular domain. Each node \(u\) is assigned a weight \(w_u\). Two nodes \(u\) and \(v\) are joined by an edge if

\[(w_u + w_v)h(r) \ge \theta\]

where r is the distance between u and v, h(r) is a probability of connection as a function of r, and \(\theta\) as the threshold parameter. h(r) corresponds to the p_dist parameter.

Parameters:
  • n (int or iterable) – Number of nodes or iterable of nodes

  • theta (float) – Threshold value

  • dim (int, optional) – Dimension of graph

  • pos (dict) – Node positions as a dictionary of tuples keyed by node.

  • weight (dict) – Node weights as a dictionary of numbers keyed by node.

  • metric (function) – A metric on vectors of numbers (represented as lists or tuples). This must be a function that accepts two lists (or tuples) as input and yields a number as output. The function must also satisfy the four requirements of a metric. Specifically, if \(d\) is the function and \(x\), \(y\), and \(z\) are vectors in the graph, then \(d\) must satisfy

    1. \(d(x, y) \ge 0\),
    2. \(d(x, y) = 0\) if and only if \(x = y\),
    3. \(d(x, y) = d(y, x)\),
    4. \(d(x, z) \le d(x, y) + d(y, z)\).

    If this argument is not specified, the Euclidean distance metric is used.

  • p_dist (function, optional) – A probability density function computing the probability of connecting two nodes that are of distance, r, computed by metric. The probability density function, p_dist, must be any function that takes the metric value as input and outputs a single probability value between 0-1. The scipy.stats package has many probability distribution functions implemented and tools for custom probability distribution definitions [2], and passing the .pdf method of scipy.stats distributions can be used here. If the probability function, p_dist, is not supplied, the default exponential function :math: r^{-2} is used.

  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.

Returns:

A random geographic threshold graph, undirected and without self-loops.

Each node has a node attribute pos that stores the position of that node in Euclidean space as provided by the pos keyword argument or, if pos was not provided, as generated by this function. Similarly, each node has a node attribute weight that stores the weight of that node as provided or as generated.

Return type:

Graph

Examples

Specify an alternate distance metric using the metric keyword argument. For example, to use the taxicab metric instead of the default Euclidean metric:

>>> dist = lambda x, y: sum(abs(a - b) for a, b in zip(x, y))
>>> G = nx.geographical_threshold_graph(10, 0.1, metric=dist)

Notes

If weights are not specified they are assigned to nodes by drawing randomly from the exponential distribution with rate parameter \(\lambda=1\). To specify weights from a different distribution, use the weight keyword argument:

>>> import random
>>> n = 20
>>> w = {i: random.expovariate(5.0) for i in range(n)}
>>> G = nx.geographical_threshold_graph(20, 50, weight=w)

If node positions are not specified they are randomly assigned from the uniform distribution.

Starting in NetworkX 2.1 the parameter alpha is deprecated and replaced with the customizable p_dist function parameter, which defaults to r^-2 if p_dist is not supplied. To reproduce networks of earlier NetworkX versions, a custom function needs to be defined and passed as the p_dist parameter. For example, if the parameter alpha = 2 was used in NetworkX 2.0, the custom function def custom_dist(r): r**-2 can be passed in versions >=2.1 as the parameter p_dist = custom_dist to produce an equivalent network. Note the change in sign from +2 to -2 in this parameter change.

References

[1]Masuda, N., Miwa, H., Konno, N.: Geographical threshold graphs with small-world and scale-free properties. Physical Review E 71, 036108 (2005)
[2]Milan Bradonjić, Aric Hagberg and Allon G. Percus, Giant component and connectivity in geographical threshold graphs, in Algorithms and Models for the Web-Graph (WAW 2007), Antony Bonato and Fan Chung (Eds), pp. 209–216, 2007