Home   >   User Resources   >   Online Help   >   apaGraph.Edges.Random
 

 

Function index Version 3.0.0

apaGraph.Edges.Random(NumberOfNodes, [GraphType], [Parameter], [DistanceType], [Seed])

Excel=apaGraph.Edges.Random(NumberOfNodes, [GraphType], [Parameter], [DistanceType], [Seed])

Result

Generates a random graph and returns it as an m x 3 edge list: node i, node j (1-based, i < j, sorted by i and then j) and the distance between the two nodes. The edge list can be used directly as input of the apaGraph.Layout functions, apaGraph.MinimumSpanningTree.FromEdges and the other apaGraph functions that take an edge list.

Syntax

NumberOfNodes: number of nodes n, from 2 to 5000

GraphType: optional; 0 complete graph, 1 minimum spanning tree of the complete graph, 2 uniform random tree, 3 preferential-attachment tree, 4 Erdős–Rényi graph, 5 k-nearest-neighbour graph, 6 stochastic block model, 7 Watts–Strogatz small-world graph; default: 0

Parameter: optional; GraphType 4: edge probability p in (0, 1], default 2 ln(n) / n (at most 1); GraphType 5: number of neighbours k from 1 to n - 1, default 3 (at most n - 1); GraphType 6: number of blocks from 1 to n, default min(3, n); GraphType 7: rewiring probability in [0, 1], default 0.1; ignored for the other graph types

DistanceType: optional; 0 correlation distance sqrt(2(1 - ρ)), 1 Euclidean distance between random points in the unit square, 2 unit distances; default: 0

Seed: optional; integer seed of the random number generator, which makes the graph reproducible; default: empty, i.e. a new random graph whenever the function recalculates

Algorithm

First, distances between all pairs of nodes are generated. DistanceType 0: 250 observations of a factor model are simulated, x(i) = β(i) f + γ(i) g(b(i)) + σ(i) e(i), with a market factor f, standard normal factors and errors, market loadings β(i) uniform on [0.3, 0.8] and σ(i) = sqrt(1 - β(i)² - γ(i)²). Block factors g(b) with loadings γ(i) uniform on [0.4, 0.7] are used only for GraphType 6 (node i belongs to block (i - 1) mod number of blocks); the total factor variance is capped at 0.95. ρ is the sample correlation of the simulated observations. DistanceType 1: points are uniformly distributed in the unit square; for GraphType 6, they are normally distributed (standard deviation 0.08) around random block centres. DistanceType 2: the distances of DistanceType 0 are used to select the edges of GraphTypes 1 and 5, and all reported distances are set to 1.

Then the edges are selected. GraphType 0: all n(n - 1)/2 pairs. GraphType 1: minimum spanning tree of the distances (Kruskal). GraphType 2: tree decoded from a random Prüfer sequence, so that all n^(n - 2) labelled trees are equally likely. GraphType 3: the nodes are added in random order, and each new node is attached to an existing node with a probability proportional to its degree, which produces hubs. GraphType 4: each pair is linked independently with probability p. GraphType 5: each node is linked to its k nearest nodes; the graph is the union of these links. GraphType 6: pairs within a block are linked with probability 0.5, pairs across blocks with probability min(0.5, 2 / n). GraphType 7: ring lattice in which each node is linked to its two nearest neighbours on each side; each link is rewired to a random node with the rewiring probability.

Graphs of GraphTypes 4 to 7 that are not connected are connected by adding the shortest edges between their components (Kruskal on the distances), so that all n nodes are always part of a single connected graph. Trees (GraphTypes 1 to 3) have n - 1 edges.

Remarks

The function is not volatile, because the number of edges of GraphTypes 4 to 7 is random and Excel cannot spill a volatile array whose size changes between calculation passes (#SPILL!). Without Seed, a new graph is generated whenever the function recalculates, i.e. when an argument changes or with Ctrl+Alt+F9. The edge list must fit into the 1,048,576 rows of a worksheet; a complete graph allows at most 1,448 nodes.

Pressing Esc aborts the calculation; the function then returns "Calculation aborted by user."