MCPcopy
hub / github.com/networkx/networkx / lattice_reference

Function lattice_reference

networkx/algorithms/smallworld.py:126–243  ·  view source on GitHub ↗

Latticize the given graph by swapping edges. Parameters ---------- G : graph An undirected graph. niter : integer (optional, default=1) An edge is rewired approximately niter times. D : numpy.array (optional, default=None) Distance to the diagonal matri

(G, niter=5, D=None, connectivity=True, seed=None)

Source from the content-addressed store, hash-verified

124@py_random_state(4)
125@nx._dispatchable(returns_graph=True)
126def lattice_reference(G, niter=5, D=None, connectivity=True, seed=None):
127 """Latticize the given graph by swapping edges.
128
129 Parameters
130 ----------
131 G : graph
132 An undirected graph.
133
134 niter : integer (optional, default=1)
135 An edge is rewired approximately niter times.
136
137 D : numpy.array (optional, default=None)
138 Distance to the diagonal matrix.
139
140 connectivity : boolean (optional, default=True)
141 Ensure connectivity for the latticized graph when set to True.
142
143 seed : integer, random_state, or None (default)
144 Indicator of random number generation state.
145 See :ref:`Randomness<randomness>`.
146
147 Returns
148 -------
149 G : graph
150 The latticized graph.
151
152 Raises
153 ------
154 NetworkXError
155 If there are fewer than 4 nodes or 2 edges in `G`
156
157 Notes
158 -----
159 The implementation is adapted from the algorithm by Sporns et al. [1]_.
160 which is inspired from the original work by Maslov and Sneppen(2002) [2]_.
161
162 References
163 ----------
164 .. [1] Sporns, Olaf, and Jonathan D. Zwi.
165 "The small world of the cerebral cortex."
166 Neuroinformatics 2.2 (2004): 145-162.
167 .. [2] Maslov, Sergei, and Kim Sneppen.
168 "Specificity and stability in topology of protein networks."
169 Science 296.5569 (2002): 910-913.
170 """
171 import numpy as np
172
173 from networkx.utils import cumulative_distribution, discrete_sequence
174
175 local_conn = nx.connectivity.local_edge_connectivity
176
177 if len(G) < 4:
178 raise nx.NetworkXError("Graph has fewer than four nodes.")
179 if len(G.edges) < 2:
180 raise nx.NetworkXError("Graph has fewer that 2 edges")
181 # Instead of choosing uniformly at random from a generated edge list,
182 # this algorithm chooses nonuniformly from the set of nodes with
183 # probability weighted by degree.

Callers 2

test_lattice_referenceFunction · 0.90
omegaFunction · 0.85

Calls 10

cumulative_distributionFunction · 0.90
discrete_sequenceFunction · 0.90
appendMethod · 0.80
choiceMethod · 0.80
copyMethod · 0.45
degreeMethod · 0.45
number_of_edgesMethod · 0.45
neighborsMethod · 0.45
add_edgeMethod · 0.45
remove_edgeMethod · 0.45

Tested by 1

test_lattice_referenceFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…