index
int64
0
731k
package
stringlengths
2
98
name
stringlengths
1
76
docstring
stringlengths
0
281k
code
stringlengths
4
8.19k
signature
stringlengths
2
42.8k
embed_func_code
listlengths
768
768
30,674
networkx.convert_matrix
from_pandas_edgelist
Returns a graph from Pandas DataFrame containing an edge list. The Pandas DataFrame should contain at least two columns of node names and zero or more columns of edge attributes. Each row will be processed as one edge instance. Note: This function iterates over DataFrame.values, which is not guaranteed to retain the data type across columns in the row. This is only a problem if your row is entirely numeric and a mix of ints and floats. In that case, all values will be returned as floats. See the DataFrame.iterrows documentation for an example. Parameters ---------- df : Pandas DataFrame An edge list representation of a graph source : str or int A valid column name (string or integer) for the source nodes (for the directed case). target : str or int A valid column name (string or integer) for the target nodes (for the directed case). edge_attr : str or int, iterable, True, or None A valid column name (str or int) or iterable of column names that are used to retrieve items and add them to the graph as edge attributes. If `True`, all of the remaining columns will be added. If `None`, no edge attributes are added to the graph. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. edge_key : str or None, optional (default=None) A valid column name for the edge keys (for a MultiGraph). The values in this column are used for the edge keys when adding edges if create_using is a multigraph. If you have node attributes stored in a separate dataframe `df_nodes`, you can load those attributes to the graph `G` using the following code: ``` df_nodes = pd.DataFrame({"node_id": [1, 2, 3], "attribute1": ["A", "B", "C"]}) G.add_nodes_from((n, dict(d)) for n, d in df_nodes.iterrows()) ``` See Also -------- to_pandas_edgelist Examples -------- Simple integer weights on edges: >>> import pandas as pd >>> pd.options.display.max_columns = 20 >>> import numpy as np >>> rng = np.random.RandomState(seed=5) >>> ints = rng.randint(1, 11, size=(3, 2)) >>> a = ["A", "B", "C"] >>> b = ["D", "A", "E"] >>> df = pd.DataFrame(ints, columns=["weight", "cost"]) >>> df[0] = a >>> df["b"] = b >>> df[["weight", "cost", 0, "b"]] weight cost 0 b 0 4 7 A D 1 7 1 B A 2 10 9 C E >>> G = nx.from_pandas_edgelist(df, 0, "b", ["weight", "cost"]) >>> G["E"]["C"]["weight"] 10 >>> G["E"]["C"]["cost"] 9 >>> edges = pd.DataFrame( ... { ... "source": [0, 1, 2], ... "target": [2, 2, 3], ... "weight": [3, 4, 5], ... "color": ["red", "blue", "blue"], ... } ... ) >>> G = nx.from_pandas_edgelist(edges, edge_attr=True) >>> G[0][2]["color"] 'red' Build multigraph with custom keys: >>> edges = pd.DataFrame( ... { ... "source": [0, 1, 2, 0], ... "target": [2, 2, 3, 2], ... "my_edge_key": ["A", "B", "C", "D"], ... "weight": [3, 4, 5, 6], ... "color": ["red", "blue", "blue", "blue"], ... } ... ) >>> G = nx.from_pandas_edgelist( ... edges, ... edge_key="my_edge_key", ... edge_attr=["weight", "color"], ... create_using=nx.MultiGraph(), ... ) >>> G[0][2] AtlasView({'A': {'weight': 3, 'color': 'red'}, 'D': {'weight': 6, 'color': 'blue'}})
def to_numpy_array( G, nodelist=None, dtype=None, order=None, multigraph_weight=sum, weight="weight", nonedge=0.0, ): """Returns the graph adjacency matrix as a NumPy array. Parameters ---------- G : graph The NetworkX graph used to construct the NumPy array. nodelist : list, optional The rows and columns are ordered according to the nodes in `nodelist`. If `nodelist` is ``None``, then the ordering is produced by ``G.nodes()``. dtype : NumPy data type, optional A NumPy data type used to initialize the array. If None, then the NumPy default is used. The dtype can be structured if `weight=None`, in which case the dtype field names are used to look up edge attributes. The result is a structured array where each named field in the dtype corresponds to the adjacency for that edge attribute. See examples for details. order : {'C', 'F'}, optional Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory. If None, then the NumPy default is used. multigraph_weight : callable, optional An function that determines how weights in multigraphs are handled. The function should accept a sequence of weights and return a single value. The default is to sum the weights of the multiple edges. weight : string or None optional (default = 'weight') The edge attribute that holds the numerical value used for the edge weight. If an edge does not have that attribute, then the value 1 is used instead. `weight` must be ``None`` if a structured dtype is used. nonedge : array_like (default = 0.0) The value used to represent non-edges in the adjacency matrix. The array values corresponding to nonedges are typically set to zero. However, this could be undesirable if there are array values corresponding to actual edges that also have the value zero. If so, one might prefer nonedges to have some other value, such as ``nan``. Returns ------- A : NumPy ndarray Graph adjacency matrix Raises ------ NetworkXError If `dtype` is a structured dtype and `G` is a multigraph ValueError If `dtype` is a structured dtype and `weight` is not `None` See Also -------- from_numpy_array Notes ----- For directed graphs, entry ``i, j`` corresponds to an edge from ``i`` to ``j``. Entries in the adjacency matrix are given by the `weight` edge attribute. When an edge does not have a weight attribute, the value of the entry is set to the number 1. For multiple (parallel) edges, the values of the entries are determined by the `multigraph_weight` parameter. The default is to sum the weight attributes for each of the parallel edges. When `nodelist` does not contain every node in `G`, the adjacency matrix is built from the subgraph of `G` that is induced by the nodes in `nodelist`. The convention used for self-loop edges in graphs is to assign the diagonal array entry value to the weight attribute of the edge (or the number 1 if the edge has no weight attribute). If the alternate convention of doubling the edge weight is desired the resulting NumPy array can be modified as follows: >>> import numpy as np >>> G = nx.Graph([(1, 1)]) >>> A = nx.to_numpy_array(G) >>> A array([[1.]]) >>> A[np.diag_indices_from(A)] *= 2 >>> A array([[2.]]) Examples -------- >>> G = nx.MultiDiGraph() >>> G.add_edge(0, 1, weight=2) 0 >>> G.add_edge(1, 0) 0 >>> G.add_edge(2, 2, weight=3) 0 >>> G.add_edge(2, 2) 1 >>> nx.to_numpy_array(G, nodelist=[0, 1, 2]) array([[0., 2., 0.], [1., 0., 0.], [0., 0., 4.]]) When `nodelist` argument is used, nodes of `G` which do not appear in the `nodelist` and their edges are not included in the adjacency matrix. Here is an example: >>> G = nx.Graph() >>> G.add_edge(3, 1) >>> G.add_edge(2, 0) >>> G.add_edge(2, 1) >>> G.add_edge(3, 0) >>> nx.to_numpy_array(G, nodelist=[1, 2, 3]) array([[0., 1., 1.], [1., 0., 0.], [1., 0., 0.]]) This function can also be used to create adjacency matrices for multiple edge attributes with structured dtypes: >>> G = nx.Graph() >>> G.add_edge(0, 1, weight=10) >>> G.add_edge(1, 2, cost=5) >>> G.add_edge(2, 3, weight=3, cost=-4.0) >>> dtype = np.dtype([("weight", int), ("cost", float)]) >>> A = nx.to_numpy_array(G, dtype=dtype, weight=None) >>> A["weight"] array([[ 0, 10, 0, 0], [10, 0, 1, 0], [ 0, 1, 0, 3], [ 0, 0, 3, 0]]) >>> A["cost"] array([[ 0., 1., 0., 0.], [ 1., 0., 5., 0.], [ 0., 5., 0., -4.], [ 0., 0., -4., 0.]]) As stated above, the argument "nonedge" is useful especially when there are actually edges with weight 0 in the graph. Setting a nonedge value different than 0, makes it much clearer to differentiate such 0-weighted edges and actual nonedge values. >>> G = nx.Graph() >>> G.add_edge(3, 1, weight=2) >>> G.add_edge(2, 0, weight=0) >>> G.add_edge(2, 1, weight=0) >>> G.add_edge(3, 0, weight=1) >>> nx.to_numpy_array(G, nonedge=-1.0) array([[-1., 2., -1., 1.], [ 2., -1., 0., -1.], [-1., 0., -1., 0.], [ 1., -1., 0., -1.]]) """ import numpy as np if nodelist is None: nodelist = list(G) nlen = len(nodelist) # Input validation nodeset = set(nodelist) if nodeset - set(G): raise nx.NetworkXError(f"Nodes {nodeset - set(G)} in nodelist is not in G") if len(nodeset) < nlen: raise nx.NetworkXError("nodelist contains duplicates.") A = np.full((nlen, nlen), fill_value=nonedge, dtype=dtype, order=order) # Corner cases: empty nodelist or graph without any edges if nlen == 0 or G.number_of_edges() == 0: return A # If dtype is structured and weight is None, use dtype field names as # edge attributes edge_attrs = None # Only single edge attribute by default if A.dtype.names: if weight is None: edge_attrs = dtype.names else: raise ValueError( "Specifying `weight` not supported for structured dtypes\n." "To create adjacency matrices from structured dtypes, use `weight=None`." ) # Map nodes to row/col in matrix idx = dict(zip(nodelist, range(nlen))) if len(nodelist) < len(G): G = G.subgraph(nodelist).copy() # Collect all edge weights and reduce with `multigraph_weights` if G.is_multigraph(): if edge_attrs: raise nx.NetworkXError( "Structured arrays are not supported for MultiGraphs" ) d = defaultdict(list) for u, v, wt in G.edges(data=weight, default=1.0): d[(idx[u], idx[v])].append(wt) i, j = np.array(list(d.keys())).T # indices wts = [multigraph_weight(ws) for ws in d.values()] # reduced weights else: i, j, wts = [], [], [] # Special branch: multi-attr adjacency from structured dtypes if edge_attrs: # Extract edges with all data for u, v, data in G.edges(data=True): i.append(idx[u]) j.append(idx[v]) wts.append(data) # Map each attribute to the appropriate named field in the # structured dtype for attr in edge_attrs: attr_data = [wt.get(attr, 1.0) for wt in wts] A[attr][i, j] = attr_data if not G.is_directed(): A[attr][j, i] = attr_data return A for u, v, wt in G.edges(data=weight, default=1.0): i.append(idx[u]) j.append(idx[v]) wts.append(wt) # Set array values with advanced indexing A[i, j]
(df, source='source', target='target', edge_attr=None, create_using=None, edge_key=None, *, backend=None, **backend_kwargs)
[ 0.0068152411840856075, 0.06676866114139557, 0.02268478274345398, 0.02024415321648121, 0.0021614283323287964, -0.04271102324128151, -0.04020502045750618, -0.00416759354993701, 0.07626968622207642, -0.03107444755733013, -0.038788583129644394, -0.009925954975187778, 0.04170862212777138, 0.03693631663918495, 0.0014750012196600437, -0.0062432182021439075, 0.0079974215477705, -0.0002667736553121358, -0.008133617229759693, 0.08136885613203049, -0.02985413372516632, -0.11706306785345078, 0.02383972331881523, 0.03554167225956917, 0.034844350069761276, 0.013096594251692295, 0.0011168060591444373, -0.009321245364844799, 0.021148493513464928, -0.00015764671843498945, -0.009495575912296772, -0.05944677069783211, -0.0624539740383625, 0.024951081722974777, 0.05613448843359947, 0.025321535766124725, -0.021976564079523087, -0.018446367233991623, -0.07592102140188217, 0.002819254295900464, 0.04528240114450455, -0.08023570477962494, -0.018315618857741356, -0.009691697545349598, 0.02610602229833603, 0.016485147178173065, 0.06262830644845963, 0.02071266621351242, -0.05979543179273605, -0.028829939663410187, 0.04170862212777138, -0.02405763790011406, 0.025016456842422485, 0.058749448508024216, -0.02344748005270958, 0.03896291181445122, 0.017269635573029518, -0.023774350062012672, 0.010105732828378677, -0.041773997247219086, -0.03562883660197258, -0.03632616251707077, 0.03584675118327141, -0.012399271130561829, -0.03098728321492672, -0.0012087383074685931, -0.0380912609398365, -0.014436761848628521, 0.01750933937728405, 0.008378769271075726, -0.013281820341944695, 0.0033449705224484205, 0.055088501423597336, -0.02414480224251747, 0.02634572796523571, 0.06380503624677658, -0.004418193828314543, 0.011222539469599724, -0.045413147658109665, 0.04576180875301361, -0.0005417190259322524, 0.04434537515044212, 0.012017923407256603, -0.004551665857434273, 0.021290138363838196, 0.01933981291949749, -0.00807369127869606, 0.08733968436717987, -0.024624211713671684, -0.09222093969583511, 0.017542026937007904, -0.010824847035109997, -0.007828538306057453, 0.055480748414993286, 0.007474428974092007, -0.005861870013177395, 0.007964733988046646, -0.06254114210605621, 0.010034911334514618, 0.03177177160978317, -0.06716090440750122, 0.009457441046833992, 0.0029881373047828674, 0.014523927122354507, -0.06297696381807327, -0.05818287283182144, -0.038548875600099564, 0.03127057105302811, 0.008711087517440319, -0.020908789709210396, -0.027980078011751175, 0.027696790173649788, 0.056831810623407364, -0.03386373817920685, 0.049074094742536545, 0.032251179218292236, 0.011898070573806763, 0.011108134873211384, -0.020462065935134888, -0.000994910835288465, 0.03142311051487923, 0.03379836678504944, 0.014502136036753654, -0.0063576227985322475, 0.008111825212836266, -0.015482746064662933, 0.011582096107304096, -0.01896936073899269, 0.05391177162528038, -0.005327982362359762, -0.022510452196002007, -0.029570845887064934, -0.03218580782413483, 0.022510452196002007, -0.03312283381819725, -0.01622365042567253, -0.02124655432999134, -0.026454685255885124, 0.03142311051487923, -0.03312283381819725, 0.0152321457862854, -0.07221649587154388, 0.028045453131198883, 0.021126702427864075, 0.015885885804891586, -0.0068915109150111675, 0.02567019686102867, 0.003745386144146323, -0.044890157878398895, -0.04685137793421745, -0.018675176426768303, -0.044802989810705185, -0.009876923635601997, -0.01713888719677925, 0.029418306425213814, 0.003366761840879917, -0.05748555064201355, -0.03022458590567112, 0.005731122102588415, 0.031009074300527573, -0.07304456830024719, -0.03610824793577194, -0.009653562679886818, -0.005845526698976755, -0.0029009717982262373, 0.033231791108846664, 0.016430668532848358, -0.03813484311103821, -0.08306857943534851, -0.01834830641746521, -0.020189674571156502, -0.0685119703412056, -0.03342791274189949, -0.01689918339252472, 0.0148507971316576, 0.013968247920274734, 0.03249088674783707, 0.01088477298617363, 0.017542026937007904, 0.06044917181134224, 0.05718047171831131, 0.01828293316066265, -0.011658365838229656, 0.030791161581873894, 0.012769724242389202, -0.01789068803191185, 0.03617362305521965, -0.04105488210916519, 0.0510353147983551, 0.02787112072110176, 0.0418611615896225, 0.013630482368171215, -0.005033798981457949, 0.0578777939081192, 0.05792137607932091, -0.0074253985658288, -0.04201370105147362, 0.04563106223940849, -0.04249310865998268, 0.112704798579216, 0.07012452930212021, -0.04051009938120842, 0.05260429158806801, 0.041904743760824203, 0.017465757206082344, 0.0037535580340772867, 0.024711377918720245, -0.04201370105147362, 0.007861224934458733, 0.011124477721750736, -0.004344648215919733, -0.02466779574751854, 0.06332562863826752, 0.006717179901897907, -0.013684960082173347, 0.0005362711963243783, -0.016801122575998306, 0.0540425181388855, -0.01949235238134861, -0.04528240114450455, -0.04885618016123772, 0.02200925163924694, -0.035977497696876526, -0.019154585897922516, -0.00025281356647610664, -0.06480743736028671, 0.03266521543264389, 0.00011244670895393938, 0.01073768176138401, 0.031706396490335464, 0.03052966482937336, -0.009228631854057312, 0.012562706135213375, -0.02946188859641552, 0.020690875127911568, 0.0009172791615128517, 0.0032441855873912573, 0.04654629901051521, 0.0036909079644829035, 0.02169327810406685, -0.04170862212777138, -0.05822645500302315, -0.036827363073825836, 0.02567019686102867, 0.006303144618868828, 0.003859790740534663, 0.030420707538723946, 0.029026063159108162, -0.01024192851036787, -0.0076106246560812, -0.09039047360420227, -0.016397982835769653, 0.014229743741452694, -0.01889309100806713, -0.018184872344136238, -0.0011883089318871498, -0.031706396490335464, 0.016180068254470825, -0.04323401674628258, -0.041621457785367966, 0.0335150770843029, -0.005774704739451408, -0.0048540206626057625, -0.012268523685634136, 0.05818287283182144, 0.010056702420115471, 0.05160189047455788, 0.03774259611964226, -0.047243621200323105, 0.029723385348916054, -0.008509517647325993, 0.020995954051613808, 0.01773814857006073, -0.01274793315678835, 0.021115805953741074, -0.004208452068269253, 0.011320600286126137, 0.026934094727039337, -0.035367343574762344, 0.007991973310709, -0.10285511612892151, 0.013815708458423615, -0.02298986166715622, 0.044890157878398895, -0.06886062771081924, -0.035977497696876526, -0.007490772288292646, 0.009468336589634418, -0.04234056919813156, -0.03462643548846245, 0.05731121823191643, -0.004559837747365236, -0.0156025979667902, 0.0016575036570429802, -0.01894756779074669, -0.014763631857931614, -0.010236481204628944, -0.004006882198154926, 0.01244285423308611, 0.06794539093971252, 0.05792137607932091, 0.032098639756441116, 0.06071066856384277, -0.013848395086824894, 0.007741373032331467, 0.024340923875570297, 0.0041839368641376495, 0.05574224144220352, -0.0018250246066600084, 0.04319043084979057, -0.03800409287214279, 0.004322856664657593, -0.06258472055196762, 0.04438895732164383, -0.03168460726737976, 0.037502892315387726, 0.009811550378799438, -0.004745063837617636, 0.10067598521709442, 0.036042872816324234, -0.01758560910820961, 0.038178425282239914, -0.031946100294589996, -0.0036718405317515135, -0.08110736310482025, 0.01682291366159916, 0.07448279112577438, 0.014349596574902534, 0.015210353769361973, 0.014763631857931614, -0.0008893589838407934, 0.03312283381819725, -0.012007026933133602, 0.014567509293556213, -0.04301610216498375, 0.034691810607910156, 0.01789068803191185, -0.05073023587465286, -0.016572313383221626, -0.006417549215257168, -0.060579922050237656, 0.05657031387090683, -0.002734812907874584, -0.019154585897922516, 0.03190251812338829, -0.03473539277911186, -0.03473539277911186, 0.034975096583366394, -0.003930612467229366, -0.011059104464948177, 0.023403897881507874, 0.05055590346455574, -0.029178602620959282, 0.048681847751140594, -0.033624034374952316, -0.012758828699588776, -0.004448156803846359, -0.024188386276364326, 0.002467869082465768, 0.0213337205350399, -0.032098639756441116, 0.04242773726582527, 0.04964066669344902, -0.03462643548846245, 0.010694099590182304, 0.016343504190444946, 0.0016806569183245301, 0.019274437800049782, 0.07191141694784164, -0.07300098240375519, 0.03800409287214279, -0.056395985186100006, -0.03926799073815346, 0.039921730756759644, 0.004497187212109566, 0.023316731676459312, -0.032861337065696716, 0.008732878603041172, 0.014665571041405201, -0.027043050155043602, 0.0042030042968690395, -0.012780619785189629, 0.020309526473283768, 0.01473094429820776, 0.017084408551454544, -0.018326515331864357, 0.09344125539064407, 0.06341279298067093, -0.05687539279460907, -0.027304546907544136, -0.03061683103442192, 0.009217736311256886, -0.010312750935554504, 0.017683671787381172, -0.02991950698196888, 0.029963089153170586, 0.020745353773236275, 0.027980078011751175, -0.02460242062807083, -0.03473539277911186, -0.06890421360731125, -0.02131192944943905, -0.0152321457862854, 0.01134239137172699, -0.031967893242836, 0.013434359803795815, 0.005861870013177395, -0.020527441054582596, 0.040619052946567535, 0.018217558041214943, 0.005567687097936869, 0.06145157292485237, 0.0078012989833951, 0.019579516723752022, 0.04319043084979057, 0.04850751906633377, 0.06794539093971252, -0.027827538549900055, 0.07640042901039124, 0.013695855624973774, 0.04048830643296242, 0.026585431769490242, 0.01621275581419468, -0.002586359390988946, 0.04430178925395012, -0.02695588581264019, -0.002083796774968505, -0.00026915708440355957, -0.05338877812027931, 0.04319043084979057, 0.014970649033784866, -0.02138819918036461, 0.012388375587761402, -0.03896291181445122, -0.05382460728287697, 0.0020197846461087465, 0.010715890675783157, -0.003927888814359903, -0.010024015791714191, -0.004290169570595026, -0.008280708454549313, 0.004551665857434273, 0.003099817782640457, -0.028873523697257042, -0.023403897881507874, -0.057529132813215256, 0.014589301310479641, 0.016866495832800865, -0.043059684336185455, -0.050207242369651794, 0.023185983300209045, 0.005649404600262642, 0.06271547079086304, -0.006826136726886034, -0.0784488171339035, 0.055393580347299576, 0.04889976233243942, -0.03523659333586693, 0.008841835893690586, 0.013946456834673882, 0.039006493985652924, 0.011669261381030083, -0.037110649049282074, -0.03534555062651634, 0.004309237003326416, -0.02155163325369358, 0.009511918760836124, -0.011015521362423897, -0.03974740207195282, -0.005954483058303595, 0.05604732036590576, -0.0220746248960495, -0.027696790173649788, -0.07326247543096542, 0.04218802973628044, 0.012649871408939362, -0.016866495832800865, -0.008798252791166306, -0.032774172723293304, -0.008967136032879353, -0.018936673179268837, -0.016463356092572212, 0.007174798287451267, -0.0013932837173342705, 0.026999467983841896, 0.022216269746422768, 0.04475940763950348, -0.02665080688893795, -0.01518856268376112, -0.017956063151359558, -0.05975184962153435, 0.00428199814632535, 0.02717379853129387, 0.021508051082491875, 0.07670550793409348, 0.047243621200323105, -0.0022009252570569515, 0.00007614200148964301, 0.036195412278175354, 0.0403357669711113, 0.002345292828977108, -0.02802366018295288, -0.05687539279460907, 0.020995954051613808, 0.000039794729673303664, -0.02612781524658203, -0.023098818957805634, 0.027304546907544136, 0.050817400217056274, 0.021126702427864075, -0.029222184792160988, 0.06716090440750122, -0.0388321653008461, 0.02900427207350731, -0.009675353765487671, 0.028372323140501976, 0.003042615484446287, -0.0018127670045942068, 0.012660767883062363, -0.043822381645441055, 0.031009074300527573, 0.0036990796215832233, -0.012856889516115189, 0.039333365857601166, -0.06820689141750336, 0.09527172893285751, 0.0005454644560813904, -0.025866318494081497, -0.012660767883062363, 0.006335831712931395, -0.008667504414916039, 0.028808148577809334, -0.0041866609826684, 0.08193542808294296, 0.006352175027132034, -0.03340611979365349, 0.10477275401353836, 0.05168905481696129, -0.00027818005764856935, 0.004483568016439676, 0.010786712169647217, 0.017400383949279785, -0.026541849598288536, 0.017531132325530052, 0.019819222390651703, 0.037720806896686554, 0.004617039579898119, -0.02169327810406685, -0.017106199637055397, -0.07435204833745956, -0.04545672982931137, 0.03989994153380394, 0.018108602613210678, -0.012965845875442028, 0.06005692854523659, -0.01887129805982113, 0.01107544731348753, -0.05038157477974892, 0.017411278560757637, 0.010187450796365738, -0.03412523493170738, -0.060579922050237656, -0.0395730696618557, 0.003290492109954357, 0.0004681732680182904, -0.010476185940206051, 0.006973228417336941, 0.0358031690120697, -0.03610824793577194, 0.00046340643893927336, -0.0213337205350399, -0.08516055345535278, -0.018773237243294716, -0.04584897682070732, -0.02124655432999134, 0.004832229111343622, -0.050904564559459686, -0.002578187733888626, -0.008171752095222473, -0.014970649033784866, -0.020810728892683983, -0.024188386276364326, -0.006041648332029581, 0.031030865386128426, 0.05286578834056854, -0.03342791274189949, -0.02671618014574051, 0.04319043084979057, 0.004725996404886246, -0.052342794835567474, -0.01118985190987587, -0.044802989810705185, 0.0845068097114563, 0.012987637892365456, -0.021431781351566315, 0.01881682127714157, -0.009996776469051838, -0.0010412173578515649, 0.044890157878398895, -0.06297696381807327, 0.010247376747429371, 0.011996131390333176, 0.014894379302859306, 0.008847283199429512, -0.017073513939976692, 0.021813130006194115, -0.044890157878398895, -0.03569421172142029, 0.02169327810406685, -0.03192431107163429, -0.040379349142313004, 0.010138420388102531, -0.0426238588988781, -0.055698659271001816, -0.022946279495954514, -0.009190496988594532, -0.07099618017673492, 0.062018148601055145, -0.0631512999534607, -0.005665747914463282, 0.00394150847569108, -0.05195055156946182, -0.010988282039761543, -0.030551455914974213, -0.02597527578473091, 0.031706396490335464, -0.010715890675783157, -0.017182469367980957, 0.009157809428870678, 0.06445877999067307, -0.0006758719682693481, -0.019067421555519104, 0.02588810957968235, 0.04746153578162193, 0.04654629901051521, -0.1256052702665329, -0.029200393706560135, 0.02512541227042675, 0.04253669083118439, 0.04746153578162193, -0.04142533242702484, 0.002051109680905938, 0.017247844487428665, -0.033994488418102264, -0.014142578467726707, -0.04811527580022812, 0.02909143641591072, -0.07147558778524399, 0.014349596574902534, -0.01896936073899269, 0.020614605396986008, -0.03456106409430504, -0.03325358033180237, 0.04471582546830177, 0.022129103541374207, 0.05626523494720459, -0.038178425282239914, 0.0418611615896225, -0.005949035286903381, -0.02336031384766102, -0.0023766178637742996, 0.018326515331864357, 0.02162790298461914, -0.02071266621351242, 0.04042293131351471, 0.02878635749220848, 0.017171574756503105, -0.002501918002963066, 0.045718226581811905, -0.008139064535498619, -0.07291381806135178, 0.018620697781443596, 0.03737214580178261, 0.002383427694439888, 0.0028791804797947407, 0.01683380827307701, 0.028960688039660454, -0.0072783068753778934, 0.010465290397405624, -0.017106199637055397, 0.041381750255823135, 0.1134892925620079, 0.035912126302719116, -0.019819222390651703, 0.0031488484237343073, -0.06293338537216187, 0.014022726565599442, -0.006090679205954075, 0.005791048053652048, -0.06223606318235397, 0.0014123511500656605, -0.024319132789969444, 0.07975629717111588, 0.041773997247219086, -0.0023711700923740864, -0.002702126046642661, -0.013423464260995388, 0.04584897682070732, -0.020908789709210396, -0.014218848198652267, -0.009185048751533031, 0.0037671776954084635, -0.04781019687652588, 0.04467224329710007, 0.041142046451568604, -0.009876923635601997, -0.07042960822582245, 0.029352933168411255, 0.006984123960137367, -0.01077581662684679, -0.06010051071643829, -0.020156987011432648, -0.004941185936331749, 0.013238238170742989, 0.016659477725625038, 0.03238192945718765, 0.005458730272948742, -0.008149960078299046, -0.06641999632120132, 0.03122698701918125, -0.014872588217258453, 0.02147536352276802, 0.029440097510814667, 0.05687539279460907, -0.0913492888212204, 0.027217380702495575, -0.00791570357978344, -0.07500578463077545, 0.03146669268608093, -0.03153206780552864, 0.021148493513464928, 0.03669661283493042, 0.06689941138029099, 0.07182425260543823, -0.028742775321006775, -0.012094193138182163, -0.06280263513326645, -0.01503602322191, -0.0008028746233321726, 0.06894779205322266, -0.032708797603845596, -0.022510452196002007, -0.03052966482937336, 0.021268345415592194, -0.029352933168411255, -0.007207484915852547, -0.019819222390651703, 0.010764921084046364, -0.031096240505576134, -0.018925776705145836, -0.0032687007915228605, -0.0418611615896225, -0.03329716622829437, -0.014120787382125854, 0.035149428993463516, -0.01424063928425312, -0.007071289233863354, -0.03312283381819725, 0.0021723241079598665, -0.07596460729837418, -0.053781021386384964, 0.022968070581555367, -0.06563550978899002, 0.03388553112745285, -0.10363960266113281, -0.005292571149766445, 0.03830917179584503, 0.03395090624690056 ]
30,676
networkx.convert_matrix
from_scipy_sparse_array
Creates a new graph from an adjacency matrix given as a SciPy sparse array. Parameters ---------- A: scipy.sparse array An adjacency matrix representation of a graph parallel_edges : Boolean If this is True, `create_using` is a multigraph, and `A` is an integer matrix, then entry *(i, j)* in the matrix is interpreted as the number of parallel edges joining vertices *i* and *j* in the graph. If it is False, then the entries in the matrix are interpreted as the weight of a single edge joining the vertices. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. edge_attribute: string Name of edge attribute to store matrix numeric value. The data will have the same type as the matrix entry (int, float, (real,imag)). Notes ----- For directed graphs, explicitly mention create_using=nx.DiGraph, and entry i,j of A corresponds to an edge from i to j. If `create_using` is :class:`networkx.MultiGraph` or :class:`networkx.MultiDiGraph`, `parallel_edges` is True, and the entries of `A` are of type :class:`int`, then this function returns a multigraph (constructed from `create_using`) with parallel edges. In this case, `edge_attribute` will be ignored. If `create_using` indicates an undirected multigraph, then only the edges indicated by the upper triangle of the matrix `A` will be added to the graph. Examples -------- >>> import scipy as sp >>> A = sp.sparse.eye(2, 2, 1) >>> G = nx.from_scipy_sparse_array(A) If `create_using` indicates a multigraph and the matrix has only integer entries and `parallel_edges` is False, then the entries will be treated as weights for edges joining the nodes (without creating parallel edges): >>> A = sp.sparse.csr_array([[1, 1], [1, 2]]) >>> G = nx.from_scipy_sparse_array(A, create_using=nx.MultiGraph) >>> G[1][1] AtlasView({0: {'weight': 2}}) If `create_using` indicates a multigraph and the matrix has only integer entries and `parallel_edges` is True, then the entries will be treated as the number of parallel edges joining those two vertices: >>> A = sp.sparse.csr_array([[1, 1], [1, 2]]) >>> G = nx.from_scipy_sparse_array(A, parallel_edges=True, create_using=nx.MultiGraph) >>> G[1][1] AtlasView({0: {'weight': 1}, 1: {'weight': 1}})
def to_numpy_array( G, nodelist=None, dtype=None, order=None, multigraph_weight=sum, weight="weight", nonedge=0.0, ): """Returns the graph adjacency matrix as a NumPy array. Parameters ---------- G : graph The NetworkX graph used to construct the NumPy array. nodelist : list, optional The rows and columns are ordered according to the nodes in `nodelist`. If `nodelist` is ``None``, then the ordering is produced by ``G.nodes()``. dtype : NumPy data type, optional A NumPy data type used to initialize the array. If None, then the NumPy default is used. The dtype can be structured if `weight=None`, in which case the dtype field names are used to look up edge attributes. The result is a structured array where each named field in the dtype corresponds to the adjacency for that edge attribute. See examples for details. order : {'C', 'F'}, optional Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory. If None, then the NumPy default is used. multigraph_weight : callable, optional An function that determines how weights in multigraphs are handled. The function should accept a sequence of weights and return a single value. The default is to sum the weights of the multiple edges. weight : string or None optional (default = 'weight') The edge attribute that holds the numerical value used for the edge weight. If an edge does not have that attribute, then the value 1 is used instead. `weight` must be ``None`` if a structured dtype is used. nonedge : array_like (default = 0.0) The value used to represent non-edges in the adjacency matrix. The array values corresponding to nonedges are typically set to zero. However, this could be undesirable if there are array values corresponding to actual edges that also have the value zero. If so, one might prefer nonedges to have some other value, such as ``nan``. Returns ------- A : NumPy ndarray Graph adjacency matrix Raises ------ NetworkXError If `dtype` is a structured dtype and `G` is a multigraph ValueError If `dtype` is a structured dtype and `weight` is not `None` See Also -------- from_numpy_array Notes ----- For directed graphs, entry ``i, j`` corresponds to an edge from ``i`` to ``j``. Entries in the adjacency matrix are given by the `weight` edge attribute. When an edge does not have a weight attribute, the value of the entry is set to the number 1. For multiple (parallel) edges, the values of the entries are determined by the `multigraph_weight` parameter. The default is to sum the weight attributes for each of the parallel edges. When `nodelist` does not contain every node in `G`, the adjacency matrix is built from the subgraph of `G` that is induced by the nodes in `nodelist`. The convention used for self-loop edges in graphs is to assign the diagonal array entry value to the weight attribute of the edge (or the number 1 if the edge has no weight attribute). If the alternate convention of doubling the edge weight is desired the resulting NumPy array can be modified as follows: >>> import numpy as np >>> G = nx.Graph([(1, 1)]) >>> A = nx.to_numpy_array(G) >>> A array([[1.]]) >>> A[np.diag_indices_from(A)] *= 2 >>> A array([[2.]]) Examples -------- >>> G = nx.MultiDiGraph() >>> G.add_edge(0, 1, weight=2) 0 >>> G.add_edge(1, 0) 0 >>> G.add_edge(2, 2, weight=3) 0 >>> G.add_edge(2, 2) 1 >>> nx.to_numpy_array(G, nodelist=[0, 1, 2]) array([[0., 2., 0.], [1., 0., 0.], [0., 0., 4.]]) When `nodelist` argument is used, nodes of `G` which do not appear in the `nodelist` and their edges are not included in the adjacency matrix. Here is an example: >>> G = nx.Graph() >>> G.add_edge(3, 1) >>> G.add_edge(2, 0) >>> G.add_edge(2, 1) >>> G.add_edge(3, 0) >>> nx.to_numpy_array(G, nodelist=[1, 2, 3]) array([[0., 1., 1.], [1., 0., 0.], [1., 0., 0.]]) This function can also be used to create adjacency matrices for multiple edge attributes with structured dtypes: >>> G = nx.Graph() >>> G.add_edge(0, 1, weight=10) >>> G.add_edge(1, 2, cost=5) >>> G.add_edge(2, 3, weight=3, cost=-4.0) >>> dtype = np.dtype([("weight", int), ("cost", float)]) >>> A = nx.to_numpy_array(G, dtype=dtype, weight=None) >>> A["weight"] array([[ 0, 10, 0, 0], [10, 0, 1, 0], [ 0, 1, 0, 3], [ 0, 0, 3, 0]]) >>> A["cost"] array([[ 0., 1., 0., 0.], [ 1., 0., 5., 0.], [ 0., 5., 0., -4.], [ 0., 0., -4., 0.]]) As stated above, the argument "nonedge" is useful especially when there are actually edges with weight 0 in the graph. Setting a nonedge value different than 0, makes it much clearer to differentiate such 0-weighted edges and actual nonedge values. >>> G = nx.Graph() >>> G.add_edge(3, 1, weight=2) >>> G.add_edge(2, 0, weight=0) >>> G.add_edge(2, 1, weight=0) >>> G.add_edge(3, 0, weight=1) >>> nx.to_numpy_array(G, nonedge=-1.0) array([[-1., 2., -1., 1.], [ 2., -1., 0., -1.], [-1., 0., -1., 0.], [ 1., -1., 0., -1.]]) """ import numpy as np if nodelist is None: nodelist = list(G) nlen = len(nodelist) # Input validation nodeset = set(nodelist) if nodeset - set(G): raise nx.NetworkXError(f"Nodes {nodeset - set(G)} in nodelist is not in G") if len(nodeset) < nlen: raise nx.NetworkXError("nodelist contains duplicates.") A = np.full((nlen, nlen), fill_value=nonedge, dtype=dtype, order=order) # Corner cases: empty nodelist or graph without any edges if nlen == 0 or G.number_of_edges() == 0: return A # If dtype is structured and weight is None, use dtype field names as # edge attributes edge_attrs = None # Only single edge attribute by default if A.dtype.names: if weight is None: edge_attrs = dtype.names else: raise ValueError( "Specifying `weight` not supported for structured dtypes\n." "To create adjacency matrices from structured dtypes, use `weight=None`." ) # Map nodes to row/col in matrix idx = dict(zip(nodelist, range(nlen))) if len(nodelist) < len(G): G = G.subgraph(nodelist).copy() # Collect all edge weights and reduce with `multigraph_weights` if G.is_multigraph(): if edge_attrs: raise nx.NetworkXError( "Structured arrays are not supported for MultiGraphs" ) d = defaultdict(list) for u, v, wt in G.edges(data=weight, default=1.0): d[(idx[u], idx[v])].append(wt) i, j = np.array(list(d.keys())).T # indices wts = [multigraph_weight(ws) for ws in d.values()] # reduced weights else: i, j, wts = [], [], [] # Special branch: multi-attr adjacency from structured dtypes if edge_attrs: # Extract edges with all data for u, v, data in G.edges(data=True): i.append(idx[u]) j.append(idx[v]) wts.append(data) # Map each attribute to the appropriate named field in the # structured dtype for attr in edge_attrs: attr_data = [wt.get(attr, 1.0) for wt in wts] A[attr][i, j] = attr_data if not G.is_directed(): A[attr][j, i] = attr_data return A for u, v, wt in G.edges(data=weight, default=1.0): i.append(idx[u]) j.append(idx[v]) wts.append(wt) # Set array values with advanced indexing A[i, j]
(A, parallel_edges=False, create_using=None, edge_attribute='weight', *, backend=None, **backend_kwargs)
[ 0.0068152411840856075, 0.06676866114139557, 0.02268478274345398, 0.02024415321648121, 0.0021614283323287964, -0.04271102324128151, -0.04020502045750618, -0.00416759354993701, 0.07626968622207642, -0.03107444755733013, -0.038788583129644394, -0.009925954975187778, 0.04170862212777138, 0.03693631663918495, 0.0014750012196600437, -0.0062432182021439075, 0.0079974215477705, -0.0002667736553121358, -0.008133617229759693, 0.08136885613203049, -0.02985413372516632, -0.11706306785345078, 0.02383972331881523, 0.03554167225956917, 0.034844350069761276, 0.013096594251692295, 0.0011168060591444373, -0.009321245364844799, 0.021148493513464928, -0.00015764671843498945, -0.009495575912296772, -0.05944677069783211, -0.0624539740383625, 0.024951081722974777, 0.05613448843359947, 0.025321535766124725, -0.021976564079523087, -0.018446367233991623, -0.07592102140188217, 0.002819254295900464, 0.04528240114450455, -0.08023570477962494, -0.018315618857741356, -0.009691697545349598, 0.02610602229833603, 0.016485147178173065, 0.06262830644845963, 0.02071266621351242, -0.05979543179273605, -0.028829939663410187, 0.04170862212777138, -0.02405763790011406, 0.025016456842422485, 0.058749448508024216, -0.02344748005270958, 0.03896291181445122, 0.017269635573029518, -0.023774350062012672, 0.010105732828378677, -0.041773997247219086, -0.03562883660197258, -0.03632616251707077, 0.03584675118327141, -0.012399271130561829, -0.03098728321492672, -0.0012087383074685931, -0.0380912609398365, -0.014436761848628521, 0.01750933937728405, 0.008378769271075726, -0.013281820341944695, 0.0033449705224484205, 0.055088501423597336, -0.02414480224251747, 0.02634572796523571, 0.06380503624677658, -0.004418193828314543, 0.011222539469599724, -0.045413147658109665, 0.04576180875301361, -0.0005417190259322524, 0.04434537515044212, 0.012017923407256603, -0.004551665857434273, 0.021290138363838196, 0.01933981291949749, -0.00807369127869606, 0.08733968436717987, -0.024624211713671684, -0.09222093969583511, 0.017542026937007904, -0.010824847035109997, -0.007828538306057453, 0.055480748414993286, 0.007474428974092007, -0.005861870013177395, 0.007964733988046646, -0.06254114210605621, 0.010034911334514618, 0.03177177160978317, -0.06716090440750122, 0.009457441046833992, 0.0029881373047828674, 0.014523927122354507, -0.06297696381807327, -0.05818287283182144, -0.038548875600099564, 0.03127057105302811, 0.008711087517440319, -0.020908789709210396, -0.027980078011751175, 0.027696790173649788, 0.056831810623407364, -0.03386373817920685, 0.049074094742536545, 0.032251179218292236, 0.011898070573806763, 0.011108134873211384, -0.020462065935134888, -0.000994910835288465, 0.03142311051487923, 0.03379836678504944, 0.014502136036753654, -0.0063576227985322475, 0.008111825212836266, -0.015482746064662933, 0.011582096107304096, -0.01896936073899269, 0.05391177162528038, -0.005327982362359762, -0.022510452196002007, -0.029570845887064934, -0.03218580782413483, 0.022510452196002007, -0.03312283381819725, -0.01622365042567253, -0.02124655432999134, -0.026454685255885124, 0.03142311051487923, -0.03312283381819725, 0.0152321457862854, -0.07221649587154388, 0.028045453131198883, 0.021126702427864075, 0.015885885804891586, -0.0068915109150111675, 0.02567019686102867, 0.003745386144146323, -0.044890157878398895, -0.04685137793421745, -0.018675176426768303, -0.044802989810705185, -0.009876923635601997, -0.01713888719677925, 0.029418306425213814, 0.003366761840879917, -0.05748555064201355, -0.03022458590567112, 0.005731122102588415, 0.031009074300527573, -0.07304456830024719, -0.03610824793577194, -0.009653562679886818, -0.005845526698976755, -0.0029009717982262373, 0.033231791108846664, 0.016430668532848358, -0.03813484311103821, -0.08306857943534851, -0.01834830641746521, -0.020189674571156502, -0.0685119703412056, -0.03342791274189949, -0.01689918339252472, 0.0148507971316576, 0.013968247920274734, 0.03249088674783707, 0.01088477298617363, 0.017542026937007904, 0.06044917181134224, 0.05718047171831131, 0.01828293316066265, -0.011658365838229656, 0.030791161581873894, 0.012769724242389202, -0.01789068803191185, 0.03617362305521965, -0.04105488210916519, 0.0510353147983551, 0.02787112072110176, 0.0418611615896225, 0.013630482368171215, -0.005033798981457949, 0.0578777939081192, 0.05792137607932091, -0.0074253985658288, -0.04201370105147362, 0.04563106223940849, -0.04249310865998268, 0.112704798579216, 0.07012452930212021, -0.04051009938120842, 0.05260429158806801, 0.041904743760824203, 0.017465757206082344, 0.0037535580340772867, 0.024711377918720245, -0.04201370105147362, 0.007861224934458733, 0.011124477721750736, -0.004344648215919733, -0.02466779574751854, 0.06332562863826752, 0.006717179901897907, -0.013684960082173347, 0.0005362711963243783, -0.016801122575998306, 0.0540425181388855, -0.01949235238134861, -0.04528240114450455, -0.04885618016123772, 0.02200925163924694, -0.035977497696876526, -0.019154585897922516, -0.00025281356647610664, -0.06480743736028671, 0.03266521543264389, 0.00011244670895393938, 0.01073768176138401, 0.031706396490335464, 0.03052966482937336, -0.009228631854057312, 0.012562706135213375, -0.02946188859641552, 0.020690875127911568, 0.0009172791615128517, 0.0032441855873912573, 0.04654629901051521, 0.0036909079644829035, 0.02169327810406685, -0.04170862212777138, -0.05822645500302315, -0.036827363073825836, 0.02567019686102867, 0.006303144618868828, 0.003859790740534663, 0.030420707538723946, 0.029026063159108162, -0.01024192851036787, -0.0076106246560812, -0.09039047360420227, -0.016397982835769653, 0.014229743741452694, -0.01889309100806713, -0.018184872344136238, -0.0011883089318871498, -0.031706396490335464, 0.016180068254470825, -0.04323401674628258, -0.041621457785367966, 0.0335150770843029, -0.005774704739451408, -0.0048540206626057625, -0.012268523685634136, 0.05818287283182144, 0.010056702420115471, 0.05160189047455788, 0.03774259611964226, -0.047243621200323105, 0.029723385348916054, -0.008509517647325993, 0.020995954051613808, 0.01773814857006073, -0.01274793315678835, 0.021115805953741074, -0.004208452068269253, 0.011320600286126137, 0.026934094727039337, -0.035367343574762344, 0.007991973310709, -0.10285511612892151, 0.013815708458423615, -0.02298986166715622, 0.044890157878398895, -0.06886062771081924, -0.035977497696876526, -0.007490772288292646, 0.009468336589634418, -0.04234056919813156, -0.03462643548846245, 0.05731121823191643, -0.004559837747365236, -0.0156025979667902, 0.0016575036570429802, -0.01894756779074669, -0.014763631857931614, -0.010236481204628944, -0.004006882198154926, 0.01244285423308611, 0.06794539093971252, 0.05792137607932091, 0.032098639756441116, 0.06071066856384277, -0.013848395086824894, 0.007741373032331467, 0.024340923875570297, 0.0041839368641376495, 0.05574224144220352, -0.0018250246066600084, 0.04319043084979057, -0.03800409287214279, 0.004322856664657593, -0.06258472055196762, 0.04438895732164383, -0.03168460726737976, 0.037502892315387726, 0.009811550378799438, -0.004745063837617636, 0.10067598521709442, 0.036042872816324234, -0.01758560910820961, 0.038178425282239914, -0.031946100294589996, -0.0036718405317515135, -0.08110736310482025, 0.01682291366159916, 0.07448279112577438, 0.014349596574902534, 0.015210353769361973, 0.014763631857931614, -0.0008893589838407934, 0.03312283381819725, -0.012007026933133602, 0.014567509293556213, -0.04301610216498375, 0.034691810607910156, 0.01789068803191185, -0.05073023587465286, -0.016572313383221626, -0.006417549215257168, -0.060579922050237656, 0.05657031387090683, -0.002734812907874584, -0.019154585897922516, 0.03190251812338829, -0.03473539277911186, -0.03473539277911186, 0.034975096583366394, -0.003930612467229366, -0.011059104464948177, 0.023403897881507874, 0.05055590346455574, -0.029178602620959282, 0.048681847751140594, -0.033624034374952316, -0.012758828699588776, -0.004448156803846359, -0.024188386276364326, 0.002467869082465768, 0.0213337205350399, -0.032098639756441116, 0.04242773726582527, 0.04964066669344902, -0.03462643548846245, 0.010694099590182304, 0.016343504190444946, 0.0016806569183245301, 0.019274437800049782, 0.07191141694784164, -0.07300098240375519, 0.03800409287214279, -0.056395985186100006, -0.03926799073815346, 0.039921730756759644, 0.004497187212109566, 0.023316731676459312, -0.032861337065696716, 0.008732878603041172, 0.014665571041405201, -0.027043050155043602, 0.0042030042968690395, -0.012780619785189629, 0.020309526473283768, 0.01473094429820776, 0.017084408551454544, -0.018326515331864357, 0.09344125539064407, 0.06341279298067093, -0.05687539279460907, -0.027304546907544136, -0.03061683103442192, 0.009217736311256886, -0.010312750935554504, 0.017683671787381172, -0.02991950698196888, 0.029963089153170586, 0.020745353773236275, 0.027980078011751175, -0.02460242062807083, -0.03473539277911186, -0.06890421360731125, -0.02131192944943905, -0.0152321457862854, 0.01134239137172699, -0.031967893242836, 0.013434359803795815, 0.005861870013177395, -0.020527441054582596, 0.040619052946567535, 0.018217558041214943, 0.005567687097936869, 0.06145157292485237, 0.0078012989833951, 0.019579516723752022, 0.04319043084979057, 0.04850751906633377, 0.06794539093971252, -0.027827538549900055, 0.07640042901039124, 0.013695855624973774, 0.04048830643296242, 0.026585431769490242, 0.01621275581419468, -0.002586359390988946, 0.04430178925395012, -0.02695588581264019, -0.002083796774968505, -0.00026915708440355957, -0.05338877812027931, 0.04319043084979057, 0.014970649033784866, -0.02138819918036461, 0.012388375587761402, -0.03896291181445122, -0.05382460728287697, 0.0020197846461087465, 0.010715890675783157, -0.003927888814359903, -0.010024015791714191, -0.004290169570595026, -0.008280708454549313, 0.004551665857434273, 0.003099817782640457, -0.028873523697257042, -0.023403897881507874, -0.057529132813215256, 0.014589301310479641, 0.016866495832800865, -0.043059684336185455, -0.050207242369651794, 0.023185983300209045, 0.005649404600262642, 0.06271547079086304, -0.006826136726886034, -0.0784488171339035, 0.055393580347299576, 0.04889976233243942, -0.03523659333586693, 0.008841835893690586, 0.013946456834673882, 0.039006493985652924, 0.011669261381030083, -0.037110649049282074, -0.03534555062651634, 0.004309237003326416, -0.02155163325369358, 0.009511918760836124, -0.011015521362423897, -0.03974740207195282, -0.005954483058303595, 0.05604732036590576, -0.0220746248960495, -0.027696790173649788, -0.07326247543096542, 0.04218802973628044, 0.012649871408939362, -0.016866495832800865, -0.008798252791166306, -0.032774172723293304, -0.008967136032879353, -0.018936673179268837, -0.016463356092572212, 0.007174798287451267, -0.0013932837173342705, 0.026999467983841896, 0.022216269746422768, 0.04475940763950348, -0.02665080688893795, -0.01518856268376112, -0.017956063151359558, -0.05975184962153435, 0.00428199814632535, 0.02717379853129387, 0.021508051082491875, 0.07670550793409348, 0.047243621200323105, -0.0022009252570569515, 0.00007614200148964301, 0.036195412278175354, 0.0403357669711113, 0.002345292828977108, -0.02802366018295288, -0.05687539279460907, 0.020995954051613808, 0.000039794729673303664, -0.02612781524658203, -0.023098818957805634, 0.027304546907544136, 0.050817400217056274, 0.021126702427864075, -0.029222184792160988, 0.06716090440750122, -0.0388321653008461, 0.02900427207350731, -0.009675353765487671, 0.028372323140501976, 0.003042615484446287, -0.0018127670045942068, 0.012660767883062363, -0.043822381645441055, 0.031009074300527573, 0.0036990796215832233, -0.012856889516115189, 0.039333365857601166, -0.06820689141750336, 0.09527172893285751, 0.0005454644560813904, -0.025866318494081497, -0.012660767883062363, 0.006335831712931395, -0.008667504414916039, 0.028808148577809334, -0.0041866609826684, 0.08193542808294296, 0.006352175027132034, -0.03340611979365349, 0.10477275401353836, 0.05168905481696129, -0.00027818005764856935, 0.004483568016439676, 0.010786712169647217, 0.017400383949279785, -0.026541849598288536, 0.017531132325530052, 0.019819222390651703, 0.037720806896686554, 0.004617039579898119, -0.02169327810406685, -0.017106199637055397, -0.07435204833745956, -0.04545672982931137, 0.03989994153380394, 0.018108602613210678, -0.012965845875442028, 0.06005692854523659, -0.01887129805982113, 0.01107544731348753, -0.05038157477974892, 0.017411278560757637, 0.010187450796365738, -0.03412523493170738, -0.060579922050237656, -0.0395730696618557, 0.003290492109954357, 0.0004681732680182904, -0.010476185940206051, 0.006973228417336941, 0.0358031690120697, -0.03610824793577194, 0.00046340643893927336, -0.0213337205350399, -0.08516055345535278, -0.018773237243294716, -0.04584897682070732, -0.02124655432999134, 0.004832229111343622, -0.050904564559459686, -0.002578187733888626, -0.008171752095222473, -0.014970649033784866, -0.020810728892683983, -0.024188386276364326, -0.006041648332029581, 0.031030865386128426, 0.05286578834056854, -0.03342791274189949, -0.02671618014574051, 0.04319043084979057, 0.004725996404886246, -0.052342794835567474, -0.01118985190987587, -0.044802989810705185, 0.0845068097114563, 0.012987637892365456, -0.021431781351566315, 0.01881682127714157, -0.009996776469051838, -0.0010412173578515649, 0.044890157878398895, -0.06297696381807327, 0.010247376747429371, 0.011996131390333176, 0.014894379302859306, 0.008847283199429512, -0.017073513939976692, 0.021813130006194115, -0.044890157878398895, -0.03569421172142029, 0.02169327810406685, -0.03192431107163429, -0.040379349142313004, 0.010138420388102531, -0.0426238588988781, -0.055698659271001816, -0.022946279495954514, -0.009190496988594532, -0.07099618017673492, 0.062018148601055145, -0.0631512999534607, -0.005665747914463282, 0.00394150847569108, -0.05195055156946182, -0.010988282039761543, -0.030551455914974213, -0.02597527578473091, 0.031706396490335464, -0.010715890675783157, -0.017182469367980957, 0.009157809428870678, 0.06445877999067307, -0.0006758719682693481, -0.019067421555519104, 0.02588810957968235, 0.04746153578162193, 0.04654629901051521, -0.1256052702665329, -0.029200393706560135, 0.02512541227042675, 0.04253669083118439, 0.04746153578162193, -0.04142533242702484, 0.002051109680905938, 0.017247844487428665, -0.033994488418102264, -0.014142578467726707, -0.04811527580022812, 0.02909143641591072, -0.07147558778524399, 0.014349596574902534, -0.01896936073899269, 0.020614605396986008, -0.03456106409430504, -0.03325358033180237, 0.04471582546830177, 0.022129103541374207, 0.05626523494720459, -0.038178425282239914, 0.0418611615896225, -0.005949035286903381, -0.02336031384766102, -0.0023766178637742996, 0.018326515331864357, 0.02162790298461914, -0.02071266621351242, 0.04042293131351471, 0.02878635749220848, 0.017171574756503105, -0.002501918002963066, 0.045718226581811905, -0.008139064535498619, -0.07291381806135178, 0.018620697781443596, 0.03737214580178261, 0.002383427694439888, 0.0028791804797947407, 0.01683380827307701, 0.028960688039660454, -0.0072783068753778934, 0.010465290397405624, -0.017106199637055397, 0.041381750255823135, 0.1134892925620079, 0.035912126302719116, -0.019819222390651703, 0.0031488484237343073, -0.06293338537216187, 0.014022726565599442, -0.006090679205954075, 0.005791048053652048, -0.06223606318235397, 0.0014123511500656605, -0.024319132789969444, 0.07975629717111588, 0.041773997247219086, -0.0023711700923740864, -0.002702126046642661, -0.013423464260995388, 0.04584897682070732, -0.020908789709210396, -0.014218848198652267, -0.009185048751533031, 0.0037671776954084635, -0.04781019687652588, 0.04467224329710007, 0.041142046451568604, -0.009876923635601997, -0.07042960822582245, 0.029352933168411255, 0.006984123960137367, -0.01077581662684679, -0.06010051071643829, -0.020156987011432648, -0.004941185936331749, 0.013238238170742989, 0.016659477725625038, 0.03238192945718765, 0.005458730272948742, -0.008149960078299046, -0.06641999632120132, 0.03122698701918125, -0.014872588217258453, 0.02147536352276802, 0.029440097510814667, 0.05687539279460907, -0.0913492888212204, 0.027217380702495575, -0.00791570357978344, -0.07500578463077545, 0.03146669268608093, -0.03153206780552864, 0.021148493513464928, 0.03669661283493042, 0.06689941138029099, 0.07182425260543823, -0.028742775321006775, -0.012094193138182163, -0.06280263513326645, -0.01503602322191, -0.0008028746233321726, 0.06894779205322266, -0.032708797603845596, -0.022510452196002007, -0.03052966482937336, 0.021268345415592194, -0.029352933168411255, -0.007207484915852547, -0.019819222390651703, 0.010764921084046364, -0.031096240505576134, -0.018925776705145836, -0.0032687007915228605, -0.0418611615896225, -0.03329716622829437, -0.014120787382125854, 0.035149428993463516, -0.01424063928425312, -0.007071289233863354, -0.03312283381819725, 0.0021723241079598665, -0.07596460729837418, -0.053781021386384964, 0.022968070581555367, -0.06563550978899002, 0.03388553112745285, -0.10363960266113281, -0.005292571149766445, 0.03830917179584503, 0.03395090624690056 ]
30,678
networkx.generators.small
frucht_graph
Returns the Frucht Graph. The Frucht Graph is the smallest cubical graph whose automorphism group consists only of the identity element [1]_. It has 12 nodes and 18 edges and no nontrivial symmetries. It is planar and Hamiltonian [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Frucht Graph with 12 nodes and 18 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Frucht_graph .. [2] https://mathworld.wolfram.com/FruchtGraph.html
def sedgewick_maze_graph(create_using=None): """ Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick """ G = empty_graph(0, create_using) G.add_nodes_from(range(8)) G.add_edges_from([[0, 2], [0, 7], [0, 5]]) G.add_edges_from([[1, 7], [2, 6]]) G.add_edges_from([[3, 4], [3, 5]]) G.add_edges_from([[4, 5], [4, 7], [4, 6]]) G.name = "Sedgewick Maze" return G
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.08450420945882797, -0.022285303100943565, -0.013789896853268147, -0.0337739996612072, -0.06197667494416237, 0.023358043283224106, -0.06273797154426575, 0.054986562579870224, -0.00027142910403199494, -0.01580560952425003, -0.006743553560227156, 0.03152470663189888, -0.006907925009727478, 0.07730647176504135, 0.023963622748851776, -0.013400595635175705, 0.04301340505480766, -0.003343660617247224, -0.024517294019460678, 0.05252964422106743, -0.01094367541372776, -0.03989899903535843, 0.04003741592168808, 0.04412074759602547, -0.02699151635169983, 0.0275970958173275, -0.014819380827248096, 0.054225265979766846, -0.008227221667766571, -0.0330992117524147, -0.017293602228164673, -0.04412074759602547, -0.05830859765410423, 0.018582621589303017, 0.030088620260357857, 0.06387992203235626, 0.0019054107833653688, 0.04813487082719803, -0.08042087405920029, -0.05228741094470024, 0.03775351867079735, -0.005316117778420448, 0.052218202501535416, -0.004602399654686451, 0.04014122858643532, -0.012872877530753613, 0.051041651517152786, 0.021022239699959755, -0.025970684364438057, -0.03188805282115936, 0.026697378605604172, -0.023929016664624214, -0.0164111889898777, 0.03595408424735069, 0.03481213375926018, -0.016826441511511803, -0.022423721849918365, -0.00797633919864893, 0.10263697057962418, -0.04758119955658913, 0.0053247688338160515, -0.014222453348338604, 0.027302956208586693, 0.04097173735499382, -0.0458509735763073, -0.013936965726315975, -0.03418925404548645, -0.054882749915122986, -0.0006007126648910344, 0.0047754221595823765, 0.04519348964095116, 0.03578106313943863, 0.04508967325091362, -0.010165073908865452, 0.03668078035116196, 0.0296560637652874, -0.014741520397365093, -0.03595408424735069, -0.044362980872392654, -0.04737357050180435, 0.019759174436330795, 0.017060022801160812, -0.02712993510067463, -0.05346396565437317, 0.03114405833184719, 0.03209568187594414, 0.030469270423054695, 0.04301340505480766, -0.011800137348473072, -0.09647736698389053, 0.01618625968694687, -0.013080503791570663, -0.027147237211465836, -0.011523301713168621, -0.008594894781708717, 0.004172006156295538, 0.02039935812354088, -0.06010803207755089, 0.0057832784950733185, -0.019430430606007576, -0.0417330376803875, 0.009533542208373547, -0.08478104323148727, 0.012500878423452377, -0.05266806110739708, -0.042874984443187714, -0.024448085576295853, 0.004031425341963768, -0.017137883231043816, -0.04034885764122009, -0.04180224612355232, -0.002100061159580946, 0.02726835198700428, 0.004472632892429829, 0.031403589993715286, 0.036265525966882706, 0.024153945967555046, 0.016532303765416145, 0.034587204456329346, -0.06557554006576538, -0.019655359908938408, 0.009767122566699982, -0.04737357050180435, -0.03713063895702362, 0.03695761412382126, -0.02960415743291378, 0.03474292531609535, -0.013080503791570663, 0.008555964566767216, -0.012838272377848625, 0.02053777500987053, 0.006198532413691282, -0.03937993198633194, 0.03216489031910896, -0.051699135452508926, 0.008235872723162174, -0.041836850345134735, -0.043843913823366165, 0.025330500677227974, 0.02905048429965973, 0.011315674521028996, -0.028704440221190453, 0.0018340389942750335, 0.028271883726119995, -0.06311862170696259, -0.0024223155342042446, -0.018582621589303017, 0.008478104136884212, 0.06080012023448944, 0.027960442006587982, 0.028410300612449646, -0.009092334657907486, 0.02119526080787182, 0.02712993510067463, -0.021454794332385063, -0.0317150317132473, -0.00130632019136101, 0.05948514863848686, 0.015130821615457535, 0.05882766470313072, 0.011220511980354786, -0.025693846866488457, 0.012838272377848625, 0.011981811374425888, -0.03681919723749161, -0.010415957309305668, 0.00867275521159172, 0.011704974807798862, -0.012241344898939133, 0.013253526762127876, -0.027475979179143906, 0.010632235556840897, -0.057408880442380905, -0.024949850514531136, 0.06394913047552109, 0.00002722063618421089, -0.025555429980158806, -0.005207978654652834, 0.020139824599027634, -0.0439477264881134, -0.019482338801026344, -0.012379762716591358, 0.014464684762060642, -0.005861138459295034, 0.002755383960902691, 0.003875704947859049, 0.012198089621961117, -0.008499732241034508, 0.032666657119989395, 0.016688024625182152, -0.010493816807866096, 0.005389652214944363, 0.033929720520973206, 0.07197737693786621, 0.04059108719229698, -0.023652181029319763, 0.030330851674079895, 0.024153945967555046, -0.05612851306796074, 0.07543782889842987, -0.014049430377781391, 0.03232061117887497, 0.01176553312689066, -0.026974214240908623, 0.053014107048511505, 0.0350024588406086, 0.004788398742675781, -0.08111296594142914, -0.018859457224607468, 0.037891935557127, -0.0477888248860836, -0.01604784093797207, 0.05637074261903763, 0.026818493381142616, -0.013435200788080692, -0.031317081302404404, 0.008209919556975365, 0.06121537461876869, 0.034033533185720444, -0.026074497029185295, -0.05066100135445595, 0.007076621986925602, -0.04893077537417412, -0.02001870796084404, 0.014274359680712223, -0.04332484304904938, -0.04508967325091362, -0.039172302931547165, -0.015182727947831154, -0.07426127791404724, 0.020780006423592567, -0.028929369524121284, 0.03889546915888786, -0.012613343074917793, 0.013244875706732273, -0.011748231016099453, -0.013305433094501495, -0.018928665667772293, 0.00800229236483574, -0.02086651884019375, -0.05066100135445595, -0.06374150514602661, 0.010069912299513817, -0.034033533185720444, 0.04709673672914505, 0.03803035616874695, -0.007457271683961153, 0.018271179869771004, 0.0030841268599033356, 0.008361314423382282, -0.03287428244948387, -0.0148280318826437, 0.032718561589717865, 0.00009178305481327698, -0.004554818384349346, 0.01382450107485056, -0.05803176015615463, 0.0036075199022889137, -0.016255468130111694, 0.022060373798012733, -0.02147209830582142, -0.02740677073597908, -0.02315041609108448, -0.017233045771718025, 0.04059108719229698, 0.011099396273493767, -0.05623232573270798, 0.0749533623456955, -0.08671889454126358, -0.04564334824681282, 0.037961144000291824, 0.014516591094434261, 0.0148280318826437, 0.0063542528077960014, 0.01721574366092682, -0.003428009105846286, -0.02586686983704567, -0.0038259609136730433, -0.0014371684519574046, -0.03553882986307144, -0.09543923288583755, -0.03550422564148903, 0.012154833413660526, 0.054086845368146896, -0.05093783512711525, -0.002210363047197461, 0.01614300347864628, 0.009455681778490543, 0.041421595960855484, -0.03012322448194027, -0.017466625198721886, -0.042217500507831573, 0.01417054608464241, 0.0007045261445455253, 0.041594620794057846, -0.004481283947825432, 0.022043071687221527, -0.008586243726313114, -0.02872174233198166, 0.04765040799975395, 0.08914121240377426, -0.06121537461876869, 0.007811967749148607, 0.018513411283493042, 0.023133113980293274, 0.038930073380470276, 0.0019032479031011462, -0.023980924859642982, 0.049830492585897446, -0.03550422564148903, -0.08969488739967346, 0.014992402866482735, -0.004965746775269508, 0.05751269310712814, -0.027441374957561493, -0.04207908362150192, -0.029240809381008148, -0.030088620260357857, 0.055920884013175964, 0.04906919226050377, -0.007846572436392307, 0.018080854788422585, -0.016030538827180862, 0.008460802026093006, -0.06737497448921204, 0.014430079609155655, 0.018323088064789772, 0.04616241529583931, 0.012665250338613987, 0.018046250566840172, -0.02685309760272503, -0.03685380145907402, 0.01590942218899727, 0.018167367205023766, -0.051283881068229675, 0.01889406144618988, 0.013660130091011524, -0.007768712006509304, -0.022319907322525978, -0.044639814645051956, 0.09059460461139679, 0.023842506110668182, -0.01316701527684927, -0.011151302605867386, 0.06173444166779518, 0.01647174544632435, -0.007889827713370323, -0.05038416385650635, -0.01213753130286932, 0.0469583161175251, 0.036507755517959595, 0.07042017579078674, -0.01698216237127781, 0.006977133918553591, 0.030296247452497482, 0.033929720520973206, 0.01618625968694687, 0.010216981172561646, -0.035244692116975784, 0.029033182188868523, -0.06332624703645706, 0.0218354444950819, 0.004861933644860983, -0.0016458769096061587, -0.021766236051917076, -0.025641940534114838, -0.01707732491195202, 0.03244172781705856, 0.05370619520545006, -0.05934673175215721, -0.02119526080787182, -0.059277523308992386, -0.021402888000011444, 0.03287428244948387, -0.008179640397429466, 0.0653679147362709, -0.03443148732185364, 0.009749820455908775, 0.06349927186965942, 0.0043169124983251095, 0.011912601999938488, -0.0017972716595977545, 0.008460802026093006, -0.002904615830630064, 0.08055929839611053, -0.028548719361424446, 0.04508967325091362, 0.03503706306219101, 0.017423370853066444, -0.0563015341758728, -0.09433189034461975, -0.024309666827321053, 0.056993626058101654, 0.06806706637144089, -0.005515093449503183, 0.025243988260626793, 0.08215110003948212, 0.046473853290081024, -0.03623092174530029, 0.04657766968011856, 0.07751409709453583, -0.042874984443187714, 0.032061077654361725, 0.04387851804494858, -0.028219977393746376, -0.06543712317943573, -0.027060724794864655, 0.010796606540679932, 0.02655895985662937, 0.01861722581088543, 0.048896171152591705, -0.04872314631938934, -0.04858472943305969, 0.018063552677631378, -0.0027315933257341385, 0.010813908651471138, 0.015442261472344398, 0.026109101250767708, 0.058481618762016296, 0.006951180752366781, 0.05138769373297691, -0.012180786579847336, 0.00034415264963172376, 0.0387224443256855, 0.042563546448946, -0.016956208273768425, -0.02446538768708706, -0.005696767009794712, -0.052356619387865067, 0.04789264127612114, -0.010052609257400036, -0.06090393289923668, 0.057547297328710556, -0.021437492221593857, -0.017734810709953308, 0.0052339318208396435, 0.033185724169015884, -0.018599923700094223, 0.022371815517544746, 0.01866913214325905, 0.03181884437799454, -0.014092685654759407, -0.02960415743291378, -0.03064229153096676, 0.019984103739261627, -0.03086722083389759, -0.007275597658008337, -0.006263415794819593, 0.016454443335533142, 0.009291310794651508, 0.030711501836776733, 0.01162711437791586, -0.03605789691209793, 0.011739579029381275, -0.06173444166779518, 0.008132059127092361, 0.027164539322257042, 0.011514649726450443, -0.03315111994743347, 0.0513530895113945, 0.03841100260615349, -0.014516591094434261, -0.020555077120661736, 0.06661368161439896, -0.03886086121201515, -0.01536440197378397, 0.02174893394112587, 0.0057054185308516026, 0.0009521647007204592, -0.06792864948511124, 0.03188805282115936, -0.029690667986869812, -0.05889687314629555, -0.04592018201947212, 0.08886437863111496, -0.04519348964095116, -0.0634300634264946, -0.022389117628335953, 0.039310719817876816, -0.016956208273768425, -0.061526816338300705, -0.00956814642995596, 0.0049441191367805, 0.030849918723106384, -0.010614932514727116, 0.00042174244299530983, 0.05003811791539192, -0.085127092897892, -0.022146886214613914, -0.04218289628624916, 0.002854872029274702, -0.03474292531609535, -0.02801235020160675, -0.00006535655847983435, -0.006358578335493803, 0.07806777209043503, -0.030573083087801933, -0.03138628974556923, -0.004511562641710043, -0.07654517143964767, 0.02880825288593769, -0.01571044698357582, -0.03834179416298866, -0.02119526080787182, -0.023167718201875687, 0.0439477264881134, 0.023167718201875687, -0.012457623146474361, 0.018513411283493042, 0.027579793706536293, 0.05616311728954315, -0.009066381491720676, 0.003285265527665615, 0.07668358832597733, 0.022233396768569946, 0.03001941181719303, -0.007656247355043888, 0.01492319442331791, 0.05495195835828781, -0.0593121275305748, 0.015338447876274586, 0.02427506260573864, 0.028098860755562782, 0.03591948002576828, -0.0439477264881134, 0.05990040302276611, 0.03045196644961834, 0.03372209519147873, 0.04031425341963768, 0.0376151017844677, 0.031593915075063705, 0.07142370194196701, -0.028548719361424446, 0.07945194840431213, 0.03372209519147873, -0.04439758509397507, 0.047408174723386765, 0.014352220110595226, -0.019707268103957176, -0.03854942321777344, 0.0051776994951069355, -0.029638761654496193, -0.03408544138073921, -0.022942788898944855, -0.011341627687215805, 0.0017929461318999529, 0.09481634944677353, -0.028981275856494904, -0.023652181029319763, -0.09806917607784271, -0.021904652938246727, 0.03221679851412773, -0.005255559924989939, -0.005454535596072674, 0.0862344354391098, -0.049657467752695084, -0.023133113980293274, -0.029500342905521393, 0.016765885055065155, 0.012820970267057419, -0.06394913047552109, -0.01120320986956358, 0.014014826156198978, -0.00910098571330309, -0.009023125283420086, 0.022423721849918365, 0.005463186651468277, 0.02230260521173477, -0.024292364716529846, 0.025659242644906044, 0.0297944825142622, 0.043843913823366165, 0.0862344354391098, -0.025365104898810387, -0.028237279504537582, -0.007786014582961798, 0.00033712360891513526, 0.03150740638375282, 0.04951905086636543, -0.023652181029319763, -0.03396432474255562, -0.014118639752268791, 0.0056362091563642025, 0.04034885764122009, -0.018911363556981087, 0.039310719817876816, -0.03657696396112442, 0.008313733153045177, -0.02193925902247429, 0.01316701527684927, 0.05118006840348244, -0.0513530895113945, 0.04128317907452583, -0.0019908405374735594, -0.042563546448946, -0.002939220517873764, 0.025468917563557625, 0.01996680162847042, 0.02339264750480652, 0.016160305589437485, -0.050764814019203186, 0.07225421071052551, 0.03540041297674179, 0.03418925404548645, 0.03560803830623627, 0.023375345394015312, 0.018582621589303017, -0.018634527921676636, 0.0014447382418438792, -0.0439477264881134, -0.010026656091213226, 0.007548108231276274, -0.01665342040359974, -0.053948428481817245, -0.05906989425420761, 0.008158013224601746, -0.023306136950850487, 0.00897987000644207, -0.031593915075063705, -0.024448085576295853, 0.009299961850047112, -0.010926373302936554, 0.0016653420170769095, -0.032908886671066284, -0.012215391732752323, 0.00398600660264492, 0.02169702760875225, 0.009905540384352207, -0.013357340358197689, 0.04069490358233452, -0.021731631830334663, -0.045435719192028046, -0.011938555166125298, -0.033185724169015884, -0.019932197406888008, -0.030988337472081184, 0.00017856467457022518, 0.000059003388741984963, 0.010796606540679932, 0.05813557282090187, -0.04166382923722267, 0.02718184143304825, 0.027389468625187874, 0.01731090620160103, -0.06761720776557922, -0.01955154724419117, 0.06356848031282425, -0.0008970137569122016, -0.042632754892110825, 0.011332976631820202, -0.008179640397429466, 0.0052901641465723515, 0.023236926645040512, 0.017267649993300438, 0.05502116680145264, 0.03668078035116196, -0.03484674170613289, -0.0669943317770958, 0.05415605381131172, -0.047165945172309875, 0.03886086121201515, 0.008798195980489254, 0.009282659739255905, 0.023600274696946144, 0.02202576957643032, 0.04560874029994011, 0.006112021394073963, 0.028098860755562782, 0.03251093626022339, -0.02787393145263195, -0.025797661393880844, -0.043843913823366165, -0.008741963654756546, -0.05214899405837059, -0.0648142471909523, -0.04540111497044563, -0.024915246292948723, 0.022856278344988823, -0.0466814823448658, -0.03716524317860603, 0.03906849026679993, 0.05187215656042099, -0.013011295348405838, -0.044639814645051956, -0.005575651302933693, 0.036265525966882706, -0.05266806110739708, -0.021454794332385063, 0.030434664338827133, 0.007625968661159277, -0.023133113980293274, -0.040383461862802505, 0.024499991908669472, 0.05014193430542946, -0.010554375126957893, 0.00709824962541461, -0.016688024625182152, -0.018219273537397385, 0.002435292350128293, -0.0634300634264946, 0.03263205289840698, 0.04453600198030472, 0.002398524899035692, 0.02150670252740383, 0.03993360325694084, -0.04353247210383415, -0.039864394813776016, 0.048757750540971756, -0.002727267798036337, 0.006341276224702597, -0.020693495869636536, -0.031542010605335236, 0.04190605878829956, 0.029067786410450935, 0.00045202139881439507, -0.05896608158946037, -0.0037502634804695845, -0.0009943388868123293, -0.02254483662545681, 0.006985784973949194, 0.01216348446905613, 0.0011278906604275107, -0.018686434254050255, 0.020797310397028923, -0.062322720885276794, -0.0014674473786726594, -0.04616241529583931, -0.05969277769327164, 0.003856239840388298, -0.05616311728954315, -0.04346326366066933, 0.008166664279997349, -0.004974398296326399, 0.05256424844264984, 0.006933878175914288, 0.0030365455895662308, 0.0003071149985771626, 0.0598657988011837, -0.018738340586423874, 0.037199847400188446, -0.03443148732185364, -0.01828848198056221, -0.08145901560783386, 0.006172579247504473, -0.009732518345117569, 0.012656599283218384, 0.030711501836776733, 0.04526269808411598, -0.04678529500961304, 0.012544134631752968, 0.05972738191485405, -0.055540237575769424, 0.0669943317770958, 0.028098860755562782, -0.024897944182157516, 0.0253997091203928, -0.04021043702960014, -0.04415535181760788, -0.03616170957684517, -0.07100845128297806, -0.018271179869771004, 0.024205854162573814, 0.014551195316016674, -0.022942788898944855, -0.04467441886663437, 0.022389117628335953, 0.022856278344988823, 0.05616311728954315 ]
30,679
networkx.drawing.layout
spring_layout
Position nodes using Fruchterman-Reingold force-directed algorithm. The algorithm simulates a force-directed representation of the network treating edges as springs holding nodes close, while treating nodes as repelling objects, sometimes called an anti-gravity force. Simulation continues until the positions are close to an equilibrium. There are some hard-coded values: minimal distance between nodes (0.01) and "temperature" of 0.1 to ensure nodes don't fly away. During the simulation, `k` helps determine the distance between nodes, though `scale` and `center` determine the size and place after rescaling occurs at the end of the simulation. Fixing some nodes doesn't allow them to move in the simulation. It also turns off the rescaling feature at the simulation's end. In addition, setting `scale` to `None` turns off rescaling. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. k : float (default=None) Optimal distance between nodes. If None the distance is set to 1/sqrt(n) where n is the number of nodes. Increase this value to move nodes farther apart. pos : dict or None optional (default=None) Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use random initial positions. fixed : list or None optional (default=None) Nodes to keep fixed at initial position. Nodes not in ``G.nodes`` are ignored. ValueError raised if `fixed` specified and `pos` not. iterations : int optional (default=50) Maximum number of iterations taken threshold: float optional (default = 1e-4) Threshold for relative error in node position changes. The iteration stops if the error is below this threshold. weight : string or None optional (default='weight') The edge attribute that holds the numerical value used for the edge weight. Larger means a stronger attractive force. If None, then all edge weights are 1. scale : number or None (default: 1) Scale factor for positions. Not used unless `fixed is None`. If scale is None, no rescaling is performed. center : array-like or None Coordinate pair around which to center the layout. Not used unless `fixed is None`. dim : int Dimension of layout. seed : int, RandomState instance or None optional (default=None) Set the random state for deterministic node layouts. If int, `seed` is the seed used by the random number generator, if numpy.random.RandomState instance, `seed` is the random number generator, if None, the random number generator is the RandomState instance used by numpy.random. Returns ------- pos : dict A dictionary of positions keyed by node Examples -------- >>> G = nx.path_graph(4) >>> pos = nx.spring_layout(G) # The same using longer but equivalent function name >>> pos = nx.fruchterman_reingold_layout(G)
def spectral_layout(G, weight="weight", scale=1, center=None, dim=2): """Position nodes using the eigenvectors of the graph Laplacian. Using the unnormalized Laplacian, the layout shows possible clusters of nodes which are an approximation of the ratio cut. If dim is the number of dimensions then the positions are the entries of the dim eigenvectors corresponding to the ascending eigenvalues starting from the second one. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. weight : string or None optional (default='weight') The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1. scale : number (default: 1) Scale factor for positions. center : array-like or None Coordinate pair around which to center the layout. dim : int Dimension of layout. Returns ------- pos : dict A dictionary of positions keyed by node Examples -------- >>> G = nx.path_graph(4) >>> pos = nx.spectral_layout(G) Notes ----- Directed graphs will be considered as undirected graphs when positioning the nodes. For larger graphs (>500 nodes) this will use the SciPy sparse eigenvalue solver (ARPACK). """ # handle some special cases that break the eigensolvers import numpy as np G, center = _process_params(G, center, dim) if len(G) <= 2: if len(G) == 0: pos = np.array([]) elif len(G) == 1: pos = np.array([center]) else: pos = np.array([np.zeros(dim), np.array(center) * 2.0]) return dict(zip(G, pos)) try: # Sparse matrix if len(G) < 500: # dense solver is faster for small graphs raise ValueError A = nx.to_scipy_sparse_array(G, weight=weight, dtype="d") # Symmetrize directed graphs if G.is_directed(): A = A + np.transpose(A) pos = _sparse_spectral(A, dim) except (ImportError, ValueError): # Dense matrix A = nx.to_numpy_array(G, weight=weight) # Symmetrize directed graphs if G.is_directed(): A += A.T pos = _spectral(A, dim) pos = rescale_layout(pos, scale=scale) + center pos = dict(zip(G, pos)) return pos
(G, k=None, pos=None, fixed=None, iterations=50, threshold=0.0001, weight='weight', scale=1, center=None, dim=2, seed=None)
[ 0.07139292359352112, -0.011950219981372356, 0.0032742638140916824, 0.0031803003512322903, 0.011015404015779495, 0.029355136677622795, -0.0008757872856222093, -0.021683866158127785, 0.03218849375844002, 0.02534603141248226, -0.04024525731801987, -0.04444710910320282, 0.024035360664129257, 0.01658574864268303, -0.016653209924697876, 0.024767793715000153, -0.0028984101954847574, -0.058748822659254074, -0.04741538688540459, -0.020835787057876587, 0.00299719232134521, -0.08133859187364578, 0.04406161606311798, 0.0712001845240593, -0.0216453168541193, -0.0000014634728131568409, -0.006938837468624115, -0.0001295008696615696, 0.006418424658477306, 0.012354985810816288, 0.03656381741166115, -0.03189937770366669, -0.0029706896748393774, 0.013762027025222778, 0.013231976889073849, 0.04695279896259308, 0.044601306319236755, -0.025268932804465294, -0.021568220108747482, -0.019534755498170853, 0.04861041158437729, 0.00931442528963089, 0.046143267303705215, -0.027832448482513428, 0.04814781993627548, 0.08288055658340454, 0.01494741253554821, -0.025673698633909225, -0.03831780329346657, 0.03376900777220726, 0.001949138706550002, -0.02407390996813774, -0.039821214973926544, -0.031590983271598816, -0.03153315931558609, -0.02162604220211506, 0.023052358999848366, 0.030530884861946106, 0.03297875076532364, -0.07910274714231491, 0.03128259256482124, -0.05655152350664139, -0.02048884518444538, 0.010649187490344048, -0.08210957795381546, -0.016951965168118477, 0.017732584848999977, -0.014571558684110641, 0.024709971621632576, -0.054392773658037186, 0.01319342851638794, -0.020161177963018417, 0.0007047256804071367, -0.02347639948129654, 0.03666019067168236, 0.0056908102706074715, 0.021182728931307793, 0.020989982411265373, -0.034597814083099365, 0.011959857307374477, -0.0009390318882651627, 0.01067809946835041, 0.0014841401716694236, 0.03560009226202965, 0.036448169499635696, 0.008114584721624851, 0.061177417635917664, 0.0432906337082386, 0.021876612678170204, -0.01736636832356453, 0.0034597814083099365, -0.0043656849302351475, 0.051964182406663895, 0.03290165215730667, 0.02251267246901989, 0.020508119836449623, 0.008138678036630154, -0.04433146119117737, 0.073821522295475, 0.0008444661507382989, -0.01592077687382698, 0.006789459381252527, 0.011622552759945393, 0.0013733115047216415, -0.03858764469623566, 0.004165711812674999, -0.028410684317350388, 0.005498064681887627, 0.009974578395485878, 0.024594323709607124, 0.03639034554362297, 0.05666717141866684, -0.016556836664676666, 0.015959326177835464, -0.008336242288351059, 0.046027619391679764, 0.04903445020318031, 0.04367612674832344, -0.010475716553628445, -0.013848762959241867, -0.04510244354605675, 0.003666982753202319, -0.06622734665870667, -0.010456442832946777, -0.0023370389826595783, -0.017530201002955437, 0.0180409774184227, -0.019554028287529945, 0.006640081759542227, 0.011959857307374477, 0.01591113954782486, -0.011718925088644028, 0.0002910757903009653, 0.008278418332338333, 0.020989982411265373, -0.03261253610253334, -0.009974578395485878, -0.017202533781528473, 0.004977651871740818, 0.0423269085586071, -0.01940947026014328, -0.007372514810413122, -0.020257549360394478, 0.06472393125295639, -0.013174153864383698, 0.026329033076763153, 0.050807710736989975, -0.03619760274887085, 0.023148732259869576, 0.028121566399931908, 0.012210425920784473, -0.0401681587100029, 0.09776050597429276, 0.009107223711907864, 0.03419305011630058, -0.06017513945698738, 0.007213499862700701, 0.01929382234811783, -0.004801771603524685, 0.0012938040308654308, -0.04163302481174469, -0.0533904992043972, -0.01432098913937807, -0.0003315824724268168, -0.05647442489862442, -0.0035055584739893675, 0.03515677526593208, 0.048070721328258514, -0.030974198132753372, -0.017029063776135445, -0.03085855208337307, -0.04248110577464104, -0.07524783909320831, -0.03170663118362427, 0.010061314329504967, 0.04055364802479744, 0.03486765921115875, 0.003050197148695588, -0.006842464674264193, -0.01498596090823412, 0.019534755498170853, -0.0068713766522705555, 0.04375322535634041, 0.031590983271598816, -0.028005918487906456, 0.0743226557970047, 0.01619062013924122, -0.012875398620963097, -0.022281378507614136, 0.010273334570229053, -0.023553498089313507, -0.003946463577449322, -0.014128243550658226, 0.05076916143298149, 0.000992639223113656, 0.06052207946777344, 0.019139626994729042, 0.004686124622821808, -0.08704385906457901, 0.03621687740087509, 0.07416845858097076, -0.0514630451798439, 0.002691208850592375, -0.022050082683563232, 0.006505160126835108, -0.004469285719096661, 0.0001572080363985151, -0.008085672743618488, -0.007772461511194706, 0.03330641984939575, -0.014378813095390797, -0.0062642283737659454, 0.05154014006257057, -0.0574767030775547, 0.024979814887046814, -0.002977917669340968, -0.04036090523004532, 0.04240400716662407, -0.004524700343608856, -0.061871301382780075, -0.033634085208177567, -0.005266770254820585, -0.022531947121024132, 0.0240546353161335, -0.0432906337082386, -0.012085141614079475, 0.05847897753119469, -0.0543542243540287, 0.002010576194152236, 0.008957846090197563, 0.04903445020318031, -0.04271239787340164, 0.02424738183617592, -0.03864546865224838, -0.028179388493299484, -0.02434375509619713, -0.03725770115852356, 0.09120716154575348, 0.047993626445531845, 0.031976476311683655, 0.017684398218989372, -0.05520230531692505, -0.06322051584720612, 0.06144725903868675, -0.02135619893670082, -0.006582258269190788, 0.0319957509636879, -0.04321353882551193, -0.007488161791115999, -0.01081302110105753, -0.075748972594738, -0.02183806337416172, 0.03205357491970062, 0.011159962974488735, 0.02833358570933342, 0.0010504628298804164, -0.06668993830680847, 0.05878737196326256, -0.008726552128791809, -0.07012080401182175, -0.04078494384884834, -0.01023478526622057, -0.01718325912952423, 0.006509978789836168, 0.059134311974048615, 0.03905023634433746, 0.017019426450133324, 0.030800728127360344, -0.008076035417616367, 0.04240400716662407, -0.007295416668057442, 0.03845272213220596, 0.022050082683563232, 0.008143496699631214, 0.06164000555872917, 0.040013961493968964, -0.019370920956134796, 0.02376551739871502, 0.04772378131747246, 0.04845621436834335, -0.034964028745889664, -0.011159962974488735, -0.019139626994729042, 0.035561542958021164, -0.002322582993656397, 0.0423269085586071, -0.010013127699494362, -0.03282455727458, 0.047608133405447006, -0.039821214973926544, 0.09683533012866974, -0.035850659012794495, -0.014205342158675194, -0.006481066811829805, -0.012335711158812046, 0.022551221773028374, -0.01911071501672268, 0.002288852585479617, 0.012759750708937645, -0.022763241082429886, 0.06241098791360855, -0.06121596321463585, 0.09984216094017029, 0.033614810556173325, 0.05909576639533043, 0.050036728382110596, -0.022878888994455338, -0.028776900842785835, 0.00019922052160836756, -0.012692290358245373, -0.09529336541891098, 0.02241629920899868, -0.034597814083099365, 0.007097852416336536, -0.048841703683137894, 0.03619760274887085, 0.022531947121024132, -0.03509895130991936, 0.029933372512459755, 0.04086204245686531, 0.0318608283996582, 0.0442543625831604, -0.07147002220153809, 0.04606616869568825, 0.001434749225154519, 0.0201997272670269, 0.02029609866440296, 0.04132463037967682, 0.07617301493883133, -0.010986492037773132, -0.022339200600981712, 0.005392055027186871, -0.028275761753320694, 0.016759220510721207, -0.05728395655751228, -0.025982091203331947, 0.03288237750530243, -0.018378281965851784, -0.0331907719373703, -0.06102322041988373, -0.004192214459180832, -0.058671724051237106, -0.025866443291306496, -0.010196235962212086, 0.04494824633002281, 0.015660570934414864, 0.017347093671560287, -0.046644408255815506, -0.05901866778731346, -0.02775534987449646, 0.03893458843231201, 0.03124404326081276, -0.07663560658693314, 0.02058521658182144, -0.012827211990952492, 0.03745044767856598, -0.006895469501614571, -0.06576475501060486, -0.013183791190385818, 0.04649021103978157, 0.006644900422543287, 0.027986643835902214, -0.031976476311683655, -0.040515098720788956, 0.024112459272146225, 0.01930345967411995, -0.007878471165895462, 0.006495522800832987, 0.08742935210466385, -0.014359538443386555, 0.029663529247045517, -0.0906674712896347, -0.10146122425794601, 0.056705720722675323, -0.0055462513118982315, 0.032651085406541824, -0.015477461740374565, -0.000011980712770309765, -0.04533373564481735, -0.025982091203331947, 0.010398618876934052, 0.016248444095253944, 0.059057217091321945, 0.011930945329368114, 0.044986795634031296, -0.020257549360394478, 0.06726817041635513, 0.05928850919008255, -0.059327058494091034, -0.02193443663418293, -0.05200273171067238, -0.0008215776178985834, 0.03930080309510231, 0.021953711286187172, 0.0063172332011163235, 0.039551373571157455, -0.01833009533584118, 0.036718014627695084, -0.03781666234135628, 0.009054219350218773, -0.0382407046854496, -0.04891880229115486, -0.07058339565992355, 0.006678631063550711, -0.030203217640519142, -0.049535587430000305, -0.018474655225872993, 0.005353505723178387, 0.023842616006731987, 0.036525268107652664, 0.020450295880436897, 0.022185005247592926, 0.019554028287529945, -0.0637216567993164, 0.03795158490538597, -0.0028767262119799852, -0.02174169011414051, 0.07104598730802536, 0.028892546892166138, -0.010832295753061771, 0.007941113784909248, -0.02424738183617592, 0.08534769713878632, 0.003573019290342927, 0.060984671115875244, 0.01621953211724758, -0.03951282426714897, -0.03220776841044426, -0.028507057577371597, 0.04356047883629799, -0.018879419192671776, 0.02881545014679432, 0.03240051493048668, 0.022435573861002922, -0.03047306090593338, -0.009907118044793606, 0.02037319727241993, 0.01310669258236885, -0.04063074663281441, -0.026733798906207085, 0.04541083425283432, -0.0035754286218434572, -0.03592775762081146, -0.02881545014679432, 0.007001479621976614, -0.009743284434080124, -0.030588708817958832, 0.008798831142485142, 0.021683866158127785, 0.010591364465653896, 0.05385308712720871, -0.07740658521652222, 0.06464683264493942, -0.014928137883543968, -0.0483405664563179, 0.009256601333618164, 0.023726968094706535, -0.032843831926584244, -0.06241098791360855, 0.0038717747665941715, 0.012538093142211437, -0.02241629920899868, -0.05261951684951782, -0.03336424380540848, 0.024594323709607124, 0.023148732259869576, 0.002789990743622184, 0.001773258438333869, -0.05951980501413345, -0.030049020424485207, 0.04182577133178711, -0.01620025746524334, -0.004531928338110447, -0.040900591760873795, 0.028005918487906456, -0.00892411544919014, -0.05955835431814194, -0.007989300414919853, -0.06217969208955765, -0.013415085151791573, -0.02696509286761284, 0.006249772384762764, 0.004789725411683321, 0.027793899178504944, 0.017800046131014824, 0.028256487101316452, 0.030029745772480965, 0.033923204988241196, -0.016441188752651215, -0.03874184191226959, -0.029740627855062485, 0.03841417282819748, 0.034964028745889664, 0.05007527768611908, 0.03028031438589096, 0.011015404015779495, 0.003076699795201421, -0.04783942922949791, 0.007377333473414183, 0.025500226765871048, 0.00438736891373992, -0.07748368382453918, 0.05500955879688263, -0.0025032819248735905, 0.017780771479010582, -0.015313628129661083, -0.0037994952872395515, 0.044485658407211304, 0.06861738860607147, 0.07609591633081436, -0.006418424658477306, 0.03394247964024544, -0.003334496868774295, -0.03681438788771629, -0.009280694648623466, 0.06044498458504677, -0.041787222027778625, 0.04529518634080887, 0.037315525114536285, -0.01979496143758297, 0.015303990803658962, 0.010032402351498604, -0.02600136585533619, 0.0490729995071888, -0.025153284892439842, 0.01950584352016449, 0.0194191075861454, -0.06965821981430054, -0.007998937740921974, 0.0010751583613455296, -0.021221278235316277, 0.04579632729291916, -0.010340794920921326, 0.05978965014219284, 0.035754285752773285, 0.01441736239939928, 0.046143267303705215, -0.0010299836285412312, -0.0023201736621558666, -0.03679511323571205, -0.014581196010112762, 0.017983153462409973, -0.02648322843015194, 0.007247230038046837, 0.06907998025417328, 0.03400030359625816, 0.009487896226346493, -0.03182227909564972, -0.03781666234135628, -0.08041341602802277, 0.005502883344888687, 0.03359553590416908, -0.025211108848452568, -0.026463953778147697, 0.03153315931558609, 0.01484140194952488, -0.021587494760751724, -0.026521777734160423, -0.014186067506670952, -0.013704204000532627, -0.028796175494790077, -0.0553179532289505, -0.039069510996341705, -0.016344817355275154, 0.04124753177165985, -0.045950524508953094, 0.009140954352915287, -0.0533904992043972, -0.00028460074099712074, -0.010957580991089344, 0.01562202163040638, 0.005902830511331558, 0.05096190422773361, 0.004469285719096661, 0.03561936318874359, -0.0035778379533439875, 0.018281908705830574, 0.008172408677637577, 0.018108438700437546, -0.06726817041635513, 0.021086355671286583, -0.048186369240283966, 0.01601715013384819, 0.06314341723918915, -0.0054836091585457325, 0.046644408255815506, -0.019274547696113586, 0.008509713225066662, -0.04853331297636032, -0.01786750555038452, -0.009728828445076942, -0.04452420771121979, 0.06692123413085938, 0.0027418045792728662, -0.02987555041909218, -0.04529518634080887, 0.012634466402232647, 0.02395826391875744, 0.028873272240161896, 0.013501821085810661, -0.08581028878688812, 0.02222355455160141, 0.009049400687217712, 0.0005508304457180202, -0.039242979139089584, -0.05111610144376755, 0.04564213007688522, 0.012142965570092201, 0.01806025207042694, -0.04290514439344406, -0.009222871623933315, -0.004881279543042183, -0.018224084749817848, -0.025596600025892258, 0.022531947121024132, -0.04610471799969673, 0.018359007313847542, 0.05231112241744995, 0.03357626125216484, 0.00360434059984982, 0.01197913195937872, -0.02087433636188507, 0.006293139886111021, -0.03263181075453758, -0.02309090830385685, 0.08334314823150635, 0.018705949187278748, -0.015554560348391533, 0.006958112120628357, -0.013617468066513538, 0.019342008978128433, -0.03270890936255455, -0.025750797241926193, 0.014301714487373829, 0.01824335940182209, -0.08573319017887115, 0.020623765885829926, -0.04529518634080887, 0.022262103855609894, 0.06433843821287155, 0.04097769036889076, -0.027774624526500702, -0.003173072589561343, -0.026560327038168907, 0.014398087747395039, 0.03978266566991806, 0.0969124287366867, -0.03180300444364548, -0.006259409710764885, 0.018127713352441788, -0.004030789714306593, -0.04309789091348648, -0.03311367332935333, -0.0180409774184227, -0.002616519806906581, 0.045449383556842804, 0.02330292947590351, -0.003218849655240774, 0.009131317026913166, -0.05655152350664139, -0.006042570807039738, 0.02162604220211506, 0.007594171911478043, -0.004290996119379997, 0.045565031468868256, 0.012326073832809925, 0.0017467559082433581, -0.013212703168392181, 0.025885717943310738, -0.061485808342695236, -0.033730458468198776, -0.024497950449585915, 0.01959257759153843, 0.01757838763296604, -0.059249959886074066, 0.032265592366456985, -0.001691341632977128, -0.013174153864383698, -0.029143117368221283, -0.04637456312775612, 0.01014804933220148, 0.04791652783751488, 0.0010709420312196016, -0.013569282367825508, -0.03814433142542839, -0.011265973560512066, 0.0010697373654693365, -0.06379875540733337, 0.05462406948208809, -0.01892760582268238, 0.020238274708390236, -0.03997541218996048, 0.04853331297636032, -0.007170131895691156, 0.022185005247592926, -0.007907383143901825, -0.007227955386042595, 0.009497533552348614, 0.05277371406555176, -0.021182728931307793, 0.06283503025770187, 0.004257265944033861, -0.07027500122785568, 0.05863317474722862, -0.01441736239939928, -0.032651085406541824, -0.05608893558382988, 0.0401681587100029, 0.012008043937385082, 0.0716627687215805, -0.03583138436079025, -0.04660585895180702, 0.026251934468746185, -0.08126149326562881, 0.03569646179676056, -0.002185251796618104, -0.0027008461765944958, -0.011015404015779495, -0.0401681587100029, 0.015756942331790924, -0.02172241546213627, -0.025673698633909225, 0.029837001115083694, 0.005517339333891869, -0.03288237750530243, -0.032651085406541824, 0.03253543749451637, -0.025153284892439842, -0.02039247192442417, 0.030839277431368828, -0.038471996784210205, 0.033229321241378784, 0.008962664753198624, 0.11865411698818207, -0.028969645500183105, 0.04325208440423012, -0.0723952054977417, -0.022743966430425644, -0.026425406336784363, 0.03288237750530243, 0.01852283999323845, 0.022069357335567474, -0.05847897753119469, -0.0286227036267519, -0.0386069193482399, -0.006124487612396479, -0.00781582947820425, 0.008692821487784386, 0.018773410469293594, -0.0070882150903344154, -0.0008480801479890943, 0.011564728803932667, -0.0012468222994357347, -0.002727348590269685, -0.04625891521573067, -0.053429048508405685, 0.03305584937334061, -0.043059341609478, 0.0003990433760918677, -0.0634903609752655, -0.05034511908888817, -0.0801050215959549, -0.045757777988910675, 0.03359553590416908, -0.07278069108724594, 0.016942327842116356, 0.01484140194952488, 0.059327058494091034 ]
30,681
networkx.generators.classic
full_rary_tree
Creates a full r-ary tree of `n` nodes. Sometimes called a k-ary, n-ary, or m-ary tree. "... all non-leaf nodes have exactly r children and all levels are full except for some rightmost position of the bottom level (if a leaf at the bottom level is missing, then so are all of the leaves to its right." [1]_ .. plot:: >>> nx.draw(nx.full_rary_tree(2, 10)) Parameters ---------- r : int branching factor of the tree n : int Number of nodes in the tree create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph An r-ary tree with n nodes References ---------- .. [1] An introduction to data structures and algorithms, James Andrew Storer, Birkhauser Boston 2001, (page 225).
def star_graph(n, create_using=None): """Return the star graph The star graph consists of one center node connected to n outer nodes. .. plot:: >>> nx.draw(nx.star_graph(6)) Parameters ---------- n : int or iterable If an integer, node labels are 0 to n with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Notes ----- The graph has n+1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)). """ n, nodes = n if isinstance(n, numbers.Integral): nodes.append(int(n)) # there should be n+1 nodes G = empty_graph(nodes, create_using) if G.is_directed(): raise NetworkXError("Directed Graph not supported") if len(nodes) > 1: hub, *spokes = nodes G.add_edges_from((hub, node) for node in spokes) return G
(r, n, create_using=None, *, backend=None, **backend_kwargs)
[ 0.02223445102572441, -0.006899428088217974, 0.0217194352298975, -0.05025838315486908, -0.012742186896502972, 0.06673886626958847, -0.047558993101119995, 0.007494359277188778, -0.000560523010790348, 0.005070236045867205, 0.004144540522247553, 0.062441155314445496, 0.016933344304561615, 0.07615121454000473, 0.027011660858988762, -0.007583155296742916, 0.01480224821716547, 0.011827590875327587, -0.022909298539161682, 0.038004569709300995, -0.019801447167992592, 0.01510415319353342, 0.03425739333033562, 0.013905410654842854, -0.02086699567735195, 0.012022941373288631, 0.02223445102572441, 0.032445959746837616, -0.03736524283885956, 0.027313565835356712, 0.03315632417798042, -0.01214725524187088, 0.0010649937903508544, 0.018327437341213226, 0.020671645179390907, 0.04244435951113701, -0.021453047171235085, 0.053099844604730606, -0.10442377626895905, -0.015752362087368965, 0.046422407031059265, -0.00590047612786293, 0.014775608666241169, -0.03294321522116661, 0.012129496783018112, 0.028450151905417442, 0.0834679827094078, 0.004493063781410456, -0.06869237124919891, -0.017599312588572502, 0.0428350605070591, 0.004262194968760014, -0.04326127842068672, -0.0583210326731205, -0.001881359494291246, 0.010087194852530956, -0.0075121186673641205, -0.01229820866137743, 0.05942210182547569, -0.0399225577712059, 0.03361806273460388, 0.03209077566862106, 0.0061757429502904415, -0.02353086695075035, -0.05618993565440178, -0.021843748167157173, -0.038821492344141006, -0.06141112372279167, -0.014225075952708721, -0.01896676793694496, 0.054023321717977524, 0.04144984483718872, 0.03013727068901062, -0.009634336456656456, 0.012902019545435905, 0.02633681334555149, 0.036477286368608475, 0.010877477005124092, -0.010513413697481155, -0.009039404802024364, -0.02278498373925686, -0.036246415227651596, 0.021897027269005775, -0.048020727932453156, 0.04631585255265236, 0.0982435941696167, -0.019712651148438454, 0.021009068936109543, -0.044610973447561264, -0.023939328268170357, -0.02443658374249935, -0.027846340090036392, -0.026088185608386993, 0.005514214746654034, -0.012671150267124176, 0.01594771258533001, 0.050293900072574615, -0.09248962998390198, 0.012431401759386063, -0.0009184808004647493, -0.03757835179567337, -0.03331615775823593, -0.08858262002468109, -0.021897027269005775, -0.056687191128730774, -0.03143368661403656, -0.025324542075395584, 0.056829266250133514, -0.013141768053174019, 0.02853894606232643, -0.019037803635001183, 0.017448360100388527, 0.06613505631685257, -0.01358574628829956, 0.029711050912737846, 0.04269298538565636, -0.018203124403953552, 0.03864390030503273, 0.06528262048959732, -0.02299809269607067, -0.058569662272930145, 0.044220272451639175, -0.04031325876712799, 0.029746567830443382, 0.026851827278733253, -0.0004220572009216994, 0.04457545652985573, -0.05320639908313751, 0.03020830638706684, 0.02111562341451645, -0.0015616948949173093, 0.01896676793694496, -0.0010217058006674051, 0.06815960258245468, -0.03532294183969498, 0.013203924521803856, -0.07885060459375381, -0.02839687280356884, -0.0012253810418769717, -0.014180677942931652, 0.033831171691417694, -0.03407980129122734, 0.038750454783439636, 0.049548014998435974, -0.0607362762093544, 0.015503734350204468, 0.018753657117486, 0.01921539567410946, 0.013328238390386105, -0.014500342309474945, 0.023708458989858627, 0.002048961352556944, 0.0953310951590538, 0.030776599422097206, -0.022110136225819588, -0.018416233360767365, 0.027064938098192215, -0.02225220948457718, -0.01211173739284277, 0.02983536384999752, -0.007432202342897654, 0.011889748275279999, 0.03999359533190727, -0.016658078879117966, -0.0762222558259964, -0.0033631380647420883, -0.006286737509071827, -0.004331011790782213, 0.00652648601680994, -0.027082696557044983, -0.04166295379400253, -0.000924585503526032, 0.0012298207730054855, -0.0560123436152935, -0.004550781100988388, -0.002064500702545047, -0.03081211820244789, -0.011170502752065659, -0.017217490822076797, -0.025839556008577347, 0.029746567830443382, -0.07064588367938995, 0.02907172031700611, -0.04169847443699837, -0.012014062143862247, 0.01766147091984749, 0.009900723583996296, 0.01408300269395113, 0.02914275787770748, 0.033582545816898346, 0.04667103290557861, 0.025093672797083855, -0.01286650076508522, 0.0560123436152935, 0.022873779758810997, -0.05835655331611633, 0.06986448168754578, 0.03619313985109329, -0.07231523841619492, 0.05519542470574379, 0.07735883444547653, 0.07128521054983139, 0.020458536222577095, -0.01040685921907425, 0.048482466489076614, -0.0006132454727776349, -0.05125289410352707, -0.04819831997156143, -0.051821187138557434, 0.02869877964258194, -0.008075971156358719, 0.01967713236808777, 0.03796905279159546, 0.044539935886859894, -0.06489191949367523, 0.06975792348384857, 0.03896356374025345, 0.03171783313155174, 0.010078314691781998, -0.06109146028757095, -0.0351453498005867, -0.015690205618739128, 0.003138928906992078, 0.03422187268733978, -0.008471112698316574, -0.005780601873993874, -0.008382316678762436, -0.016773512586951256, -0.004599618725478649, -0.06268978118896484, 0.026549922302365303, -0.026514403522014618, 0.04425578936934471, -0.015308383852243423, 0.012537957169115543, -0.015219587832689285, 0.03345822915434837, -0.011596721597015858, -0.042337801307439804, 0.03235716372728348, -0.05512438714504242, -0.019481781870126724, 0.0073878043331205845, -0.009323551319539547, -0.013807735405862331, 0.07977408170700073, -0.010442377999424934, 0.03141592815518379, 0.002557317027822137, -0.011667758226394653, -0.004504163283854723, -0.019073322415351868, 0.012857621535658836, -0.030936431139707565, 0.01889573037624359, 0.030563488602638245, -0.056971337646245956, -0.007410003338009119, 0.015157430432736874, 0.04276402294635773, -0.027579952031373978, -0.008701981045305729, -0.05800136923789978, -0.028361355885863304, 0.061695270240306854, 0.018096569925546646, -0.06869237124919891, 0.052886735647916794, -0.0595286563038826, -0.02862774208188057, 0.056971337646245956, 0.08140791952610016, 0.1052762120962143, 0.004497503396123648, 0.012795464135706425, -0.05611889809370041, 0.002475180895999074, 0.039887040853500366, -0.04290609434247017, -0.031629037111997604, -0.05388124659657478, -0.037081096321344376, -0.011729915626347065, 0.0428350605070591, 0.025342300534248352, 0.032303884625434875, 0.0499742366373539, -0.0040379855781793594, 0.025644205510616302, -0.028894130140542984, 0.01967713236808777, -0.01483776606619358, -0.03679694980382919, -0.0030567930079996586, 0.030545730143785477, 0.02026318572461605, -0.026461126282811165, 0.015219587832689285, 0.00234420713968575, 0.052567072212696075, 0.09419450908899307, -0.053099844604730606, 0.03665487468242645, 0.02253635600209236, 0.04539237543940544, 0.027011660858988762, 0.00040624046232551336, 0.010415738448500633, 0.012777704745531082, 0.014704572036862373, -0.054485056549310684, 0.014367148280143738, 0.005074675660580397, 0.009367949329316616, -0.010575571097433567, -0.05853414162993431, -0.020405258983373642, -0.021506324410438538, 0.038004569709300995, 0.03818216174840927, 0.01912659965455532, 0.00527446623891592, -0.05263810604810715, 0.02125769667327404, -0.05253155156970024, 0.053419508039951324, -0.010069435462355614, 0.05714892968535423, -0.049157314002513885, 0.02102682739496231, 0.019002284854650497, -0.019535059109330177, -0.031096262857317924, 0.03544725477695465, -0.07206661254167557, 0.03551829233765602, 0.01389653142541647, -0.032605789601802826, -0.015521492809057236, -0.05111081898212433, 0.0297643281519413, 0.010557811707258224, -0.015548131428658962, 0.00705926027148962, -0.030101751908659935, 0.03864390030503273, 0.04699070006608963, -0.09348414093255997, -0.03789801523089409, -0.0267985500395298, 0.031540241092443466, 0.07870852947235107, -0.026283536106348038, -0.029782086610794067, 0.04024222493171692, 0.06641920655965805, 0.005354382563382387, 0.012369244359433651, -0.06403947621583939, -0.010611089877784252, -0.0037383001763373613, 0.0035695882979780436, 0.06219252571463585, -0.0098296869546175, -0.005789481569081545, 0.021080106496810913, -0.013567986898124218, 0.08701981604099274, 0.011667758226394653, -0.006579763256013393, -0.024116920307278633, -0.07366493344306946, -0.07679054141044617, 0.05043597146868706, -0.005873837508261204, 0.054236430674791336, -0.015423817560076714, -0.03180662915110588, 0.027207011356949806, -0.001864710240624845, -0.04191158339381218, -0.01973041146993637, 0.042479876428842545, 0.006899428088217974, 0.026443367823958397, -0.00005601761586149223, 0.041130181401968, 0.019268672913312912, -0.04269298538565636, -0.027544435113668442, -0.053632620722055435, -0.0464579239487648, 0.06240563839673996, -0.004879325162619352, -0.029338108375668526, 0.002209903672337532, 0.09561523795127869, 0.04905075952410698, -0.052886735647916794, 0.017377324402332306, 0.051821187138557434, -0.04564100503921509, 0.025555409491062164, 0.002635013312101364, -0.004746131598949432, -0.037010058760643005, 0.010557811707258224, -0.009882964193820953, -0.02612370252609253, -0.026603199541568756, 0.02005007490515709, -0.07870852947235107, -0.03043917566537857, -0.0004514707834459841, 0.07153383642435074, 0.006242339499294758, 0.010486775077879429, 0.0009223656379617751, 0.029515700414776802, 0.004639576654881239, 0.02390380948781967, -0.09383932501077652, -0.01514855120331049, 0.09682285785675049, 0.05313536152243614, -0.050684601068496704, 0.0279528945684433, -0.016302894800901413, -0.012005181983113289, 0.07267042249441147, 0.03409755975008011, -0.023868290707468987, 0.03599778935313225, 0.006744035519659519, 0.007356726098805666, -0.06155319884419441, 0.025448855012655258, 0.006171302869915962, -0.0017281868495047092, 0.0013607945293188095, 0.03098970837891102, -0.005345502868294716, 0.018629344180226326, -0.02111562341451645, -0.0026949504390358925, -0.015814518555998802, 0.03818216174840927, 0.034648094326257706, -0.0023464271798729897, -0.03391996771097183, -0.006712956819683313, -0.03143368661403656, 0.05221188813447952, 0.0003610101412050426, -0.038821492344141006, -0.00772522808983922, 0.01898452639579773, -0.04578307643532753, -0.05967072769999504, 0.04713277146220207, -0.010948513634502888, 0.02688734605908394, -0.0208137184381485, 0.021897027269005775, -0.016702476888895035, -0.042408838868141174, 0.028112728148698807, -0.0058693974278867245, -0.04120121896266937, -0.07046829164028168, 0.024472102522850037, 0.013141768053174019, -0.03896356374025345, -0.031078504398465157, 0.0381111279129982, -0.034807924181222916, -0.026372330263257027, -0.04656447842717171, -0.00030939761199988425, -0.030865395441651344, -0.06084283068776131, 0.015352780930697918, -0.01017598994076252, 0.039602894335985184, -0.04713277146220207, -0.023708458989858627, 0.023211203515529633, -0.047558993101119995, 0.0018902390729635954, -0.03542949631810188, -0.0030767719727009535, -0.022660668939352036, -0.015281744301319122, 0.01599211059510708, -0.030652284622192383, 0.0708945095539093, -0.017439480870962143, -0.03843079134821892, -0.0020167729817330837, -0.009279153309762478, 0.019268672913312912, -0.002179935108870268, -0.022039098665118217, 0.01488216407597065, 0.006943826097995043, 0.05807240679860115, -0.006610841955989599, -0.012884260155260563, 0.008280201815068722, 0.04276402294635773, 0.039141155779361725, 0.038537345826625824, 0.024560898542404175, 0.041947100311517715, -0.022607391700148582, 0.008036013692617416, -0.021701674908399582, -0.007720788475126028, 0.043225761502981186, -0.05739755928516388, 0.04120121896266937, 0.038217682391405106, 0.009838566184043884, 0.04191158339381218, -0.0252890232950449, -0.005887156818062067, 0.03843079134821892, -0.026674237102270126, 0.01627625711262226, -0.0005452612531371415, 0.022376522421836853, 0.061766307801008224, -0.03946082293987274, 0.01081531960517168, -0.041343290358781815, -0.08091066777706146, 0.03468361124396324, 0.04663551598787308, 0.008107050321996212, -0.020298702642321587, 0.0026327932719141245, -0.0022676209919154644, -0.011108345352113247, 0.0019856945145875216, 0.001187642803415656, 0.029657773673534393, 0.006122465245425701, -0.06748475134372711, 0.026301294565200806, -0.05967072769999504, 0.03425739333033562, -0.0038870328571647406, 0.007472160272300243, 0.006508726626634598, 0.08368109166622162, -0.006113586015999317, 0.007942778058350086, -0.0267985500395298, 0.004124561324715614, 0.03242820128798485, -0.06219252571463585, 0.006517606321722269, -0.001732626580633223, -0.029640013352036476, 0.018664861097931862, -0.0000353622053808067, 0.008617625571787357, -0.023033611476421356, 0.02468521147966385, 0.0075653959065675735, -0.00563408900052309, 0.06421706825494766, 0.0897902399301529, -0.009234755299985409, -0.01610754430294037, -0.0072501711547374725, -0.04265746846795082, -0.0047106132842600346, -0.039673931896686554, -0.017865700647234917, -0.02035197988152504, -0.019659373909235, 0.002575076185166836, 0.0005624654586426914, -0.0026128143072128296, 0.06393292546272278, -0.09426554292440414, -0.004599618725478649, -0.017847940325737, 0.015610288828611374, 0.04507271200418472, -0.056829266250133514, 0.06428810954093933, 0.03349374979734421, -0.04375853389501572, 0.010726523585617542, -0.020156629383563995, -0.04564100503921509, 0.026549922302365303, 0.005975952371954918, -0.046813108026981354, 0.08872468769550323, -0.02086699567735195, 0.03285441920161247, 0.06222804635763168, 0.042941614985466, 0.03155800327658653, -0.01604538783431053, -0.016258496791124344, -0.08453353494405746, -0.006055868696421385, 0.05377469211816788, -0.020938033238053322, -0.04869557544589043, -0.05015182867646217, 0.012706669047474861, -0.028681019321084023, 0.05192774161696434, -0.06531813740730286, -0.029959678649902344, -0.01587667688727379, 0.03535845875740051, -0.015219587832689285, -0.007742987480014563, -0.028947407379746437, 0.0012020721333101392, 0.018469510599970818, -0.02907172031700611, 0.0013308259658515453, 0.004164519719779491, 0.01067324634641409, -0.05491127818822861, -0.02299809269607067, -0.034648094326257706, -0.011499046348035336, -0.007507678586989641, 0.009367949329316616, -0.02756219357252121, 0.003969169221818447, 0.09625456482172012, -0.043083686381578445, 0.00829796027392149, -0.02907172031700611, -0.02633681334555149, -0.003831535577774048, -0.03120281919836998, 0.018718140199780464, -0.03651280328631401, -0.006517606321722269, -0.028148245066404343, -0.03910563886165619, -0.002948018256574869, 0.017696987837553024, 0.018860211595892906, 0.04269298538565636, 0.037329722195863724, -0.03484344482421875, -0.06240563839673996, 0.005474256817251444, -0.06173079088330269, 0.05381020903587341, -0.015592529438436031, 0.029817605391144753, 0.06158871576189995, 0.001169883762486279, 0.06109146028757095, -0.003711661323904991, -0.06155319884419441, 0.0060425493866205215, -0.0004769995575770736, 0.004644016735255718, 0.008111489936709404, 0.03825319930911064, -0.016933344304561615, -0.05512438714504242, -0.015050875954329967, -0.014908802695572376, 0.028219282627105713, -0.0446464903652668, -0.009856325574219227, 0.009456745348870754, -0.00911044143140316, 0.0327833816409111, -0.02445434406399727, -0.019908001646399498, -0.01780354417860508, -0.041023626923561096, -0.051963258534669876, 0.018735898658633232, 0.011063947342336178, -0.017483878880739212, 0.028201522305607796, 0.010762042365968227, 0.016258496791124344, -0.019552819430828094, 0.014926562085747719, -0.016009869053959846, 0.027135973796248436, 0.0042177969589829445, -0.050826676189899445, 0.03665487468242645, -0.0013496950268745422, -0.009367949329316616, 0.037684906274080276, 0.017510516569018364, 0.02278498373925686, -0.03425739333033562, 0.012182774022221565, -0.04137880727648735, 0.03573140129446983, -0.07132072746753693, -0.0232289619743824, 0.004302152898162603, 0.0217194352298975, -0.08723292499780655, 0.005198989994823933, 0.029728809371590614, 0.005203429609537125, -0.05185670405626297, -0.0015394958900287747, 0.03365357965230942, -0.04731036350131035, -0.02582179754972458, 0.05111081898212433, -0.03598002716898918, 0.009021646343171597, -0.032144054770469666, -0.03711661323904991, -0.04212469235062599, -0.029480181634426117, -0.02102682739496231, 0.030421415343880653, 0.011818711645901203, -0.016054267063736916, 0.01889573037624359, -0.0016882288036867976, 0.02095579169690609, 0.027597712352871895, -0.016516005620360374, -0.016658078879117966, 0.0029435784090310335, -0.021541843190789223, -0.06663231551647186, -0.02088475599884987, -0.01666695810854435, -0.014535860158503056, 0.008342358283698559, -0.018469510599970818, 0.001189862727187574, 0.029284831136465073, 0.041343290358781815, -0.0027837459929287434, 0.008995006792247295, 0.026514403522014618, -0.04478856548666954, -0.024045882746577263, 0.015343901701271534, -0.005527534056454897, -0.017865700647234917, -0.043545424938201904, -0.022802742198109627, 0.02839687280356884, 0.06403947621583939, -0.011019549332559109, -0.04510822892189026, 0.003316520480439067, 0.045676521956920624, -0.0030634526629000902 ]
30,683
networkx.generators.community
gaussian_random_partition_graph
Generate a Gaussian random partition graph. A Gaussian random partition graph is created by creating k partitions each with a size drawn from a normal distribution with mean s and variance s/v. Nodes are connected within clusters with probability p_in and between clusters with probability p_out[1] Parameters ---------- n : int Number of nodes in the graph s : float Mean cluster size v : float Shape parameter. The variance of cluster size distribution is s/v. p_in : float Probability of intra cluster connection. p_out : float Probability of inter cluster connection. directed : boolean, optional default=False Whether to create a directed graph or not seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- G : NetworkX Graph or DiGraph gaussian random partition graph Raises ------ NetworkXError If s is > n If p_in or p_out is not in [0,1] Notes ----- Note the number of partitions is dependent on s,v and n, and that the last partition may be considerably smaller, as it is sized to simply fill out the nodes [1] See Also -------- random_partition_graph Examples -------- >>> G = nx.gaussian_random_partition_graph(100, 10, 10, 0.25, 0.1) >>> len(G) 100 References ---------- .. [1] Ulrik Brandes, Marco Gaertler, Dorothea Wagner, Experiments on Graph Clustering Algorithms, In the proceedings of the 11th Europ. Symp. Algorithms, 2003.
def _generate_communities(degree_seq, community_sizes, mu, max_iters, seed): """Returns a list of sets, each of which represents a community. ``degree_seq`` is the degree sequence that must be met by the graph. ``community_sizes`` is the community size distribution that must be met by the generated list of sets. ``mu`` is a float in the interval [0, 1] indicating the fraction of intra-community edges incident to each node. ``max_iters`` is the number of times to try to add a node to a community. This must be greater than the length of ``degree_seq``, otherwise this function will always fail. If the number of iterations exceeds this value, :exc:`~networkx.exception.ExceededMaxIterations` is raised. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. The communities returned by this are sets of integers in the set {0, ..., *n* - 1}, where *n* is the length of ``degree_seq``. """ # This assumes the nodes in the graph will be natural numbers. result = [set() for _ in community_sizes] n = len(degree_seq) free = list(range(n)) for i in range(max_iters): v = free.pop() c = seed.choice(range(len(community_sizes))) # s = int(degree_seq[v] * (1 - mu) + 0.5) s = round(degree_seq[v] * (1 - mu)) # If the community is large enough, add the node to the chosen # community. Otherwise, return it to the list of unaffiliated # nodes. if s < community_sizes[c]: result[c].add(v) else: free.append(v) # If the community is too big, remove a node from it. if len(result[c]) > community_sizes[c]: free.append(result[c].pop()) if not free: return result msg = "Could not assign communities; try increasing min_community" raise nx.ExceededMaxIterations(msg)
(n, s, v, p_in, p_out, directed=False, seed=None, *, backend=None, **backend_kwargs)
[ -0.002049380447715521, 0.025805650278925896, -0.03889227658510208, -0.01565065048635006, 0.0060470509342849255, 0.059955865144729614, -0.03407669439911842, -0.04183309152722359, 0.05385367199778557, -0.012204381637275219, -0.01999754086136818, 0.019905641674995422, -0.003329094499349594, 0.05131722241640091, -0.010099861770868301, 0.015237097628414631, 0.010825875215232372, -0.0412081703543663, 0.020787885412573814, 0.03411345183849335, -0.011754069477319717, -0.01856389455497265, -0.011735689826309681, 0.016826976090669632, -0.03602498397231102, 0.02700035646557808, 0.022846456617116928, 0.00829861219972372, -0.05514027923345566, -0.0011688590748235583, -0.02615487389266491, -0.015623079612851143, -0.022221533581614494, -0.009879300370812416, 0.0027041712310165167, 0.053265511989593506, 0.037238068878650665, 0.083372101187706, -0.013454228639602661, -0.024372003972530365, -0.018986636772751808, -0.0491851307451725, 0.00639627268537879, -0.013913731090724468, 0.011358898133039474, 0.018894735723733902, 0.01270983461290598, 0.05583872273564339, -0.06635213643312454, -0.050214413553476334, 0.010614504106342793, -0.036245543509721756, 0.03459133580327034, 0.001712794997729361, -0.026926835998892784, 0.012314662337303162, 0.0008070009644143283, 0.03856143727898598, 0.06524933129549026, 0.005151021294295788, -0.014557033777236938, -0.002333123004063964, 0.017470279708504677, -0.009704689495265484, -0.06671974062919617, 0.001172305317595601, -0.06833718717098236, -0.03914959728717804, 0.036796946078538895, 0.06341132521629333, 0.07432910054922104, 0.04370786249637604, -0.0020287027582526207, 0.012654694728553295, 0.06991787254810333, 0.04528855159878731, -0.00010037254105554894, 0.002816749271005392, -0.00521994661539793, -0.05815461650490761, 0.02045704424381256, 0.016817785799503326, 0.02087978646159172, -0.010743164457380772, 0.06973407417535782, -0.004241206683218479, 0.03383775055408478, 0.008422677405178547, -0.009465748444199562, -0.046685438603162766, 0.022772936150431633, 0.0018483481835573912, 0.0420168936252594, -0.03613526374101639, 0.0006622577202506363, 0.059110380709171295, -0.018104391172528267, -0.03389289230108261, 0.036208782345056534, -0.034811895340681076, 0.04620755463838577, -0.006345727480947971, -0.06278640031814575, 0.01999754086136818, -0.02087978646159172, -0.05532408133149147, 0.0010539834620431066, 0.002802964299917221, -0.00229636300355196, -0.033249590545892715, -0.07543190568685532, 0.045398831367492676, 0.05444183573126793, -0.004921270068734884, 0.01087182480841875, -0.00143709359690547, -0.005743779242038727, 0.009594408795237541, 0.013757499866187572, 0.007356632500886917, -0.04106112942099571, 0.03117263875901699, -0.021798791363835335, 0.025621850043535233, 0.0143732326105237, 0.009286542423069477, 0.028250204399228096, 0.011175096966326237, 0.032220304012298584, -0.022846456617116928, 0.021541468799114227, -0.016128532588481903, 0.005412937607616186, 0.020493803545832634, -0.003469242714345455, -0.04205365478992462, -0.10336964577436447, -0.03661314770579338, 0.04830288514494896, 0.006120570935308933, -0.01264550443738699, -0.027625281363725662, -0.017075106501579285, 0.04403870552778244, 0.009484128095209599, 0.04157577082514763, 0.010835065506398678, -0.02045704424381256, 0.00532563216984272, 0.008261851966381073, 0.044222503900527954, -0.0045973206870257854, -0.01243413332849741, -0.04528855159878731, -0.03155862167477608, -0.0062951818108558655, -0.017010776326060295, -0.0298860315233469, -0.0020999256521463394, 0.019629940390586853, -0.024206582456827164, 0.02503368817269802, -0.02617325261235237, 0.05120693892240524, -0.009107336401939392, -0.037091027945280075, 0.06065430864691734, -0.0168545451015234, -0.06186739355325699, -0.027202539145946503, -0.011175096966326237, -0.029242727905511856, -0.03801003471016884, -0.05848545581102371, 0.030363913625478745, -0.04889104887843132, 0.02001592144370079, 0.0001707338378764689, -0.03856143727898598, 0.010642074048519135, -0.03585956245660782, -0.009167071431875229, -0.015172767452895641, -0.021229008212685585, -0.0038023819215595722, 0.052236225455999374, 0.05447859689593315, -0.007434747647494078, 0.05517704039812088, -0.04047296568751335, -0.04444306716322899, -0.042825616896152496, -0.05098637938499451, 0.07704935222864151, -0.0012957965955138206, 0.014547844417393208, -0.024647705256938934, 0.02856266498565674, -0.10631045699119568, 0.028397243469953537, 0.007154451217502356, 0.022497234866023064, 0.005619713570922613, -0.04940569028258324, 0.03558386117219925, -0.02246047370135784, -0.03405831381678581, -0.03032715432345867, 0.05131722241640091, 0.03245924413204193, 0.01429971307516098, -0.024372003972530365, 0.07837271690368652, 0.021633369848132133, 0.015163577161729336, -0.0397377610206604, 0.017837880179286003, 0.0038460346404463053, -0.014557033777236938, -0.049368929117918015, -0.0012854577507823706, -0.029977932572364807, 0.056978289037942886, -0.031687282025814056, 0.022056112065911293, -0.034517817199230194, -0.01577931083738804, -0.05102314054965973, -0.041943375021219254, -0.011404847726225853, 0.06344807893037796, -0.039370160549879074, 0.02415144257247448, -0.00008026931755011901, -0.022552374750375748, -0.01698320545256138, 0.016569653525948524, -0.006350322160869837, -0.023949261754751205, 0.044259265065193176, -0.08645995706319809, -0.015457659028470516, 0.023930881172418594, 0.017111867666244507, 0.036208782345056534, 0.05514027923345566, -0.007880465127527714, -0.0025938907638192177, -0.020512184128165245, 0.027092257514595985, -0.021210627630352974, -0.0666094571352005, -0.027331199496984482, -0.06583749502897263, 0.03948044031858444, -0.07421881705522537, -0.05642688646912575, 0.007264731917530298, 0.011404847726225853, -0.025364529341459274, -0.028838366270065308, -0.03104397840797901, -0.04620755463838577, 0.07874032109975815, 0.005206161644309759, -0.0330657884478569, 0.0018736207857728004, 0.07241756469011307, -0.070028156042099, 0.006998220458626747, 0.04003184288740158, 0.050655536353588104, 0.049111608415842056, -0.010403132997453213, 0.000704187317751348, -0.01300391647964716, -0.018802834674715996, 0.008684594184160233, 0.012241141870617867, 0.05359635129570961, 0.0110740065574646, 0.04212717339396477, -0.03718293085694313, -0.0018747695721685886, -0.002147024730220437, 0.018738504499197006, -0.024261724203824997, -0.020971687510609627, -0.007857490330934525, -0.012728214263916016, -0.002407792257145047, -0.020218102261424065, -0.002922434825450182, -0.0031958387698978186, 0.04256829619407654, 0.010237712413072586, 0.03492217883467674, 0.01877526566386223, 0.026614375412464142, 0.03400317206978798, 0.04701627790927887, -0.04102436825633049, -0.03718293085694313, -0.004204446449875832, 0.03716455027461052, -0.01509005669504404, -0.004397437442094088, -0.049663010984659195, 0.016459373757243156, 0.03556548058986664, -0.040252406150102615, -0.012737404555082321, 0.04675895720720291, 0.029224349185824394, 0.02942653000354767, 0.0041309259831905365, 0.01645018346607685, -0.025052066892385483, 0.026687895879149437, 0.07142504304647446, -0.013638028874993324, -0.002469825092703104, -0.02073274552822113, 0.0034232924226671457, -0.05462563782930374, -0.01042151264846325, -0.025934312492609024, 0.041686050593853, -0.0021114132832735777, -0.008767304942011833, -0.05705181136727333, -0.03870847821235657, 0.04874400794506073, 0.04672219604253769, -0.010495033115148544, 0.03630068525671959, 0.07260137051343918, -0.070028156042099, 0.04933217167854309, -0.0778580754995346, 0.02027324214577675, -0.007269327063113451, -0.07010167837142944, -0.005619713570922613, 0.001089594908989966, -0.007370417471975088, 0.03429725393652916, -0.017433518543839455, -0.04356082156300545, -0.01885797642171383, 0.022625895217061043, 0.10160515457391739, 0.012250332161784172, 0.07256460934877396, 0.004245801363140345, 0.11028055846691132, -0.005445102695375681, -0.02870970591902733, 0.018021682277321815, 0.02870970591902733, -0.053375791758298874, -0.0060470509342849255, 0.08263690024614334, 0.027662040665745735, -0.03889227658510208, -0.004608808550983667, -0.009047601372003555, 0.005187781527638435, 0.08844500780105591, -0.07624062895774841, -0.004815584514290094, -0.016018250957131386, -0.04499446973204613, 0.030419055372476578, -0.03900256007909775, 0.008652429096400738, -0.11535346508026123, 0.015751739963889122, -0.0217436496168375, 0.0006748940795660019, -0.03405831381678581, -0.022681035101413727, 0.033800993114709854, 0.039553962647914886, 0.004075785633176565, -0.05330226942896843, 0.05506676062941551, 0.020401904359459877, 0.0020241078455001116, 0.025511570274829865, -0.03100721724331379, -0.007788564544171095, 0.018986636772751808, 0.04613403603434563, 0.007848300039768219, 0.01387697085738182, 0.07039576023817062, -0.007852895185351372, -0.05870601907372475, 0.03356204926967621, 0.036098502576351166, -0.002104520797729492, 0.010724784806370735, 0.053081709891557693, -0.03455457463860512, -0.023048637434840202, 0.03201812133193016, 0.01379426009953022, 0.014143481850624084, 0.03804679214954376, -0.07322629541158676, -0.006658188998699188, 0.04686923697590828, -0.042935896664857864, -0.04286237806081772, -0.06440384685993195, -0.033506911247968674, 0.02856266498565674, 0.10711918771266937, -0.012820115312933922, 0.09601760655641556, -0.06087486818432808, 0.05598576366901398, 0.014161862432956696, -0.003931042272597551, -0.03497731685638428, 0.023838981986045837, -0.0477147214114666, -0.04190661385655403, -0.017203766852617264, -0.032532766461372375, 0.004305536858737469, 0.07300572842359543, -0.06565369665622711, 0.042531535029411316, -0.012976345606148243, -0.014630554243922234, 0.016826976090669632, -0.029665470123291016, -0.004248098935931921, 0.08895964920520782, 0.01739675924181938, -0.004714494105428457, -0.027551760897040367, 0.051942143589258194, 0.01515438687056303, -0.020236482843756676, -0.009971200488507748, -0.01536575797945261, 0.03299226611852646, 0.047825004905462265, -0.009952820837497711, 0.02200097218155861, 0.004342297092080116, 0.0012797140516340733, 0.03948044031858444, 0.05929418280720711, 0.022386953234672546, -0.04947921261191368, -0.010449083521962166, 0.09550296515226364, -0.03214678168296814, -0.02087978646159172, 0.06624186038970947, -0.011680549010634422, 0.04947921261191368, -0.002904054708778858, -0.004971815273165703, 0.01165297906845808, -0.0011878135846927762, 0.03389289230108261, 0.029665470123291016, -0.03014335408806801, -0.072307288646698, -0.028231823816895485, -0.03668666630983353, -0.07749047130346298, 0.008771899156272411, -0.015338188037276268, -0.006230851635336876, -0.015705790370702744, -0.005242921877652407, 0.060691069811582565, -0.009520888328552246, -0.039223119616508484, -0.048964567482471466, -0.0016702909488230944, -0.036796946078538895, -0.011414038017392159, 0.012112481519579887, -0.016146911308169365, -0.09138582646846771, 0.013996440917253494, 0.0050820959731936455, 0.03703588992357254, 0.009952820837497711, 0.0019402486504986882, -0.02644895389676094, 0.036245543509721756, -0.005435912404209375, 0.015126816928386688, 0.04675895720720291, 0.03161375969648361, -0.03602498397231102, 0.05690477043390274, 0.015889590606093407, 0.0211738683283329, -0.04572967067360878, -0.05047173798084259, 0.0018253730377182364, 0.015687409788370132, 0.00047472334699705243, -0.001066045369952917, -0.02271779626607895, 0.0281766839325428, 0.020512184128165245, 0.04929541051387787, 0.03199974447488785, 0.022644275799393654, -0.006483578123152256, 0.020677605643868446, 0.04716331884264946, -0.023214057087898254, 0.09337087720632553, -0.01742432825267315, 0.00010152129834750667, -0.018113581463694572, -0.045509111136198044, -0.021045206114649773, 0.017479468137025833, -0.025805650278925896, 0.01100967638194561, -0.03889227658510208, 0.057235609740018845, 0.02372870035469532, -0.02273617498576641, -0.011276187375187874, 0.025805650278925896, 0.052236225455999374, 0.011855159886181355, -0.022221533581614494, -0.016523703932762146, 0.04484742879867554, 0.0099344402551651, 0.001003438257612288, 0.031246159225702286, 0.028489144518971443, 0.02056732401251793, 0.0048753200098872185, -0.037238068878650665, -0.04231097549200058, 0.04205365478992462, -0.03319444879889488, -0.012838494963943958, 0.08998893946409225, -0.04106112942099571, -0.039553962647914886, -0.0499938540160656, 0.038524676114320755, 0.07080011814832687, 0.00754502834752202, -0.02832372486591339, -0.0674181804060936, -0.005417532753199339, 0.036925606429576874, 0.011744880117475986, -0.016376662999391556, -0.04142872989177704, 0.008202116936445236, 0.0034209948498755693, 0.017764359712600708, -0.010109051130712032, -0.036539625376462936, 0.006345727480947971, -0.010007960721850395, -0.031209398061037064, -0.04675895720720291, -0.017938971519470215, 0.010807494632899761, -0.010155001655220985, -0.022919977083802223, 0.022111251950263977, 0.07579950243234634, -0.03503245860338211, 0.04198013246059418, 0.045950233936309814, -0.09116526693105698, -0.04047296568751335, 0.021247388795018196, 0.03878199681639671, 0.028048021718859673, 0.0032050288282334805, -0.021780410781502724, -0.010412323288619518, -0.06763874739408493, -0.0013107304694131017, 0.011625409126281738, -0.007986150681972504, -0.02828696370124817, -0.035510338842868805, -0.05613280460238457, 0.026210013777017593, 0.003986182622611523, 0.05594900622963905, 0.027809081599116325, -0.013638028874993324, -0.048670485615730286, -0.032679807394742966, 0.01235142257064581, 0.030768277123570442, -0.04374462366104126, 0.022809695452451706, -0.01500734593719244, -0.06874155253171921, -0.0030373104382306337, -0.03848791494965553, -0.025217488408088684, 0.006933890283107758, 0.019556419923901558, -0.05157454311847687, 0.02317729778587818, -0.00023420259822160006, 0.006658188998699188, -0.02132090926170349, -0.016211241483688354, 0.024978546425700188, -0.023067018017172813, -0.002132090739905834, 0.022129632532596588, 0.029977932572364807, -0.003094748128205538, -0.01100967638194561, 0.039112839847803116, -0.020934926345944405, 0.024059541523456573, -0.028470763936638832, 0.024224963039159775, 0.0025157753843814135, 0.010090671479701996, -0.005546193104237318, -0.02014458179473877, 0.04517826810479164, -0.017727600410580635, -0.07668174803256989, -0.10675158351659775, -0.0011590946232900023, 0.03291874751448631, 0.05135397985577583, 0.0006760428077541292, 0.020512184128165245, 0.0070671457797288895, -0.0006323900888673961, 0.05477267876267433, -0.05385367199778557, 0.014759214594960213, -0.028525905683636665, -0.03573090210556984, 0.028544284403324127, 0.04297265782952309, -0.04900132864713669, 0.029775751754641533, 0.04433278366923332, 0.06047050654888153, -0.004700708668678999, 0.008702973835170269, 0.022919977083802223, 0.01858227513730526, -0.013307187706232071, -0.027956122532486916, 0.038083553314208984, -0.045362070202827454, -0.01279254537075758, 0.06510229408740997, -0.016679935157299042, -0.037109408527612686, 0.04183309152722359, -0.04128168895840645, 0.014492703601717949, -0.03804679214954376, 0.04069352522492409, 0.02758852019906044, 0.02332433871924877, -0.03479351848363876, -0.0003719097003340721, -0.006786849349737167, -0.005500243045389652, -0.0348486565053463, -0.053265511989593506, -0.011873540468513966, 0.005785134620964527, 0.009061385877430439, -0.010724784806370735, -0.00507290568202734, -0.025493189692497253, -0.028103163465857506, 0.045251790434122086, -0.03358042985200882, 0.000030298435376607813, 0.005408342462033033, 0.01343584805727005, 0.05561816319823265, 0.028342103585600853, -0.008611073717474937, 0.04628107696771622, -0.021835550665855408, -0.024096302688121796, -0.03962748125195503, 0.05359635129570961, 0.02889350615441799, 0.011634599417448044, -0.020695984363555908, -0.00872135441750288, 0.00011221908789593726, 0.00664440356194973, -0.03760566934943199, -0.02258913405239582, 0.024519044905900955, 0.09910546243190765, -0.012553603388369083, -0.007457722909748554, 0.009860919788479805, 0.020548945292830467, 0.03387451171875, -0.0024675275199115276, -0.06102190911769867, -0.020493803545832634, 0.05414775386452675, -0.02771718055009842, 0.03830411657691002, -0.028195062652230263, -0.028948647901415825, 0.08116649091243744, -0.02431686408817768, 0.042788855731487274, -0.009465748444199562, -0.05675772950053215, -0.018407663330435753, 0.025805650278925896, -0.047089800238609314, 0.003232599003240466, -0.06668297946453094, 0.009759829379618168, -0.04047296568751335, 0.008537553250789642, -0.02360004000365734, -0.02758852019906044, 0.04374462366104126, 0.009962010197341442, -0.00607921602204442, -0.020934926345944405, 0.007177426479756832, -0.0022584539838135242, 0.02374708093702793, 0.007696663960814476, -0.04642811417579651, -0.03688884899020195, 0.0035381680354475975, -0.05433155596256256, -0.05414775386452675, -0.0757259875535965, -0.006819014437496662, 0.012571983970701694, -0.006387082394212484, -0.0028305344749242067, -0.007944795303046703, 0.04113464802503586, 0.03999508172273636, 0.02301187627017498 ]
30,686
networkx.readwrite.adjlist
generate_adjlist
Generate a single line of the graph G in adjacency list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels Returns ------- lines : string Lines of data in adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> for line in nx.generate_adjlist(G): ... print(line) 0 1 2 3 1 2 3 2 3 3 4 4 5 5 6 6 See Also -------- write_adjlist, read_adjlist Notes ----- The default `delimiter=" "` will result in unexpected results if node names contain whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are valid in node names. NB: This option is not available for data that isn't user-generated.
def generate_adjlist(G, delimiter=" "): """Generate a single line of the graph G in adjacency list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels Returns ------- lines : string Lines of data in adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> for line in nx.generate_adjlist(G): ... print(line) 0 1 2 3 1 2 3 2 3 3 4 4 5 5 6 6 See Also -------- write_adjlist, read_adjlist Notes ----- The default `delimiter=" "` will result in unexpected results if node names contain whitespace characters. To avoid this problem, specify an alternate delimiter when spaces are valid in node names. NB: This option is not available for data that isn't user-generated. """ directed = G.is_directed() seen = set() for s, nbrs in G.adjacency(): line = str(s) + delimiter for t, data in nbrs.items(): if not directed and t in seen: continue if G.is_multigraph(): for d in data.values(): line += str(t) + delimiter else: line += str(t) + delimiter if not directed: seen.add(s) yield line[: -len(delimiter)]
(G, delimiter=' ')
[ 0.001802587416023016, 0.005652334541082382, -0.023696323856711388, -0.021649165078997612, 0.05054491385817528, -0.0006793671054765582, -0.02389560639858246, 0.015498627908527851, 0.074857197701931, -0.014592804946005344, -0.005353412590920925, -0.01144960056990385, -0.01393155474215746, 0.03837065398693085, -0.0038316305726766586, -0.004886914044618607, -0.013071022927761078, -0.04833470657467842, 0.035308972001075745, 0.039276476949453354, 0.01204744353890419, -0.022011494264006615, 0.004241515416651964, -0.007939537055790424, -0.0048823850229382515, 0.0064856912940740585, -0.02519999071955681, 0.022174542769789696, 0.0070246560499072075, 0.002040365943685174, 0.02675800584256649, -0.08406035602092743, -0.03898661211133003, -0.010743058286607265, 0.005887848325073719, 0.028424719348549843, -0.03621479496359825, 0.007427746895700693, -0.019638238474726677, -0.015571094118058681, 0.03224729374051094, -0.0225368719547987, 0.040580861270427704, -0.005253772251307964, -0.003799926722422242, 0.032682087272405624, -0.0056704506278038025, 0.019783170893788338, -0.06297279894351959, -0.05322614684700966, 0.031504515558481216, 0.02010926604270935, -0.031250886619091034, -0.0009901775047183037, -0.016540324315428734, -0.04913182929158211, 0.030000850558280945, -0.016857363283634186, 0.033932123333215714, 0.040798258036375046, -0.02815297245979309, -0.013125372119247913, 0.04253743961453438, -0.011340901255607605, 0.025997115299105644, 0.03826195374131203, -0.0511971041560173, -0.07724856585264206, 0.038225721567869186, 0.014955134131014347, 0.003120559500530362, 0.003967504017055035, -0.023442694917321205, 0.02016361616551876, 0.027591362595558167, 0.015779433771967888, 0.02132306806743145, 0.01008180808275938, 0.03731989860534668, -0.041885245591402054, -0.007486625574529171, -0.003555354429408908, 0.017726952210068703, 0.01326124556362629, 0.055436354130506516, -0.022247008979320526, -0.025181874632835388, 0.005484757013618946, -0.027192801237106323, -0.003414951963350177, 0.005969372112303972, 0.01263622846454382, -0.01194780319929123, 0.014230476692318916, -0.04532737284898758, -0.030345063656568527, -0.012119908817112446, -0.03895037993788719, 0.039421409368515015, 0.03971127048134804, 0.003014125395566225, 0.043551959097385406, -0.06431341916322708, 0.008967645466327667, -0.031341470777988434, -0.11413367092609406, -0.01595154032111168, 0.004800860770046711, 0.03190308064222336, -0.008655136451125145, -0.024420982226729393, 0.023297762498259544, 0.06808163970708847, -0.039530105888843536, 0.02121436968445778, 0.03244657441973686, 0.035381440073251724, -0.010860815644264221, 0.0033560735173523426, -0.046124495565891266, -0.0043524787761271, -0.031595099717378616, -0.06797294318675995, 0.021939028054475784, 0.04442154988646507, -0.039602573961019516, -0.006299997679889202, -0.03579811751842499, 0.042138878256082535, -0.06536417454481125, 0.04837093874812126, 0.061994511634111404, 0.02670365571975708, 0.024475332349538803, -0.013686982914805412, -0.023352112621068954, -0.042247574776411057, -0.004760098643600941, 0.05184929817914963, 0.012455063872039318, -0.00027585134375840425, -0.11427860707044601, 0.03496475890278816, 0.027663828805088997, -0.00007557959179393947, -0.03433068469166756, 0.007377926725894213, 0.027537012472748756, 0.02804427407681942, -0.0020301754120737314, 0.054168201982975006, 0.0007818383164703846, 0.04116058722138405, -0.04938545823097229, 0.01263622846454382, 0.027011636644601822, -0.10471311956644058, 0.03891414776444435, 0.046233195811510086, -0.04626942798495293, -0.02291731722652912, -0.012192375026643276, -0.003265491221100092, 0.05880601704120636, 0.010661534033715725, 0.05583491921424866, 0.05355224385857582, -0.02422170154750347, 0.004499674774706364, -0.025652902200818062, 0.02273615263402462, -0.09152433276176453, -0.04692162200808525, -0.028696466237306595, 0.014203301630914211, 0.044638946652412415, -0.005190364550799131, 0.1020318791270256, 0.027627594769001007, 0.02808050625026226, -0.002343816449865699, 0.01994621753692627, 0.00004415886360220611, -0.0668497234582901, 0.02144988439977169, -0.015697909519076347, 0.04032723233103752, -0.048660799860954285, 0.03585246577858925, -0.006798200309276581, -0.02688482031226158, -0.03164944797754288, 0.0018592013511806726, 0.05514649301767349, -0.015552978031337261, -0.012273899279534817, -0.055327657610177994, 0.027355847880244255, -0.07703117281198502, 0.05768279731273651, 0.04706655442714691, -0.0027129394002258778, -0.007563620340079069, -0.012192375026643276, 0.04047216475009918, 0.07963994145393372, -0.046015799045562744, -0.05485662817955017, -0.025779716670513153, 0.003788603935390711, 0.02947547473013401, -0.036649592220783234, 0.023714441806077957, -0.0010167860891669989, -0.019692588597536087, 0.031413935124874115, -0.027518896386027336, 0.0797124058008194, -0.05181306600570679, -0.04536360502243042, -0.006272823084145784, -0.031540751457214355, -0.016984177753329277, 0.0035530899185687304, 0.05786396190524101, -0.062320608645677567, 0.029819685965776443, -0.051486968994140625, -0.04152291640639305, 0.009828177280724049, 0.029004447162151337, -0.012083676643669605, -0.007785547059029341, 0.018324796110391617, 0.03652277588844299, -0.027029752731323242, 0.02288108319044113, 0.011676056310534477, -0.014411641284823418, 0.03061681054532528, -0.06177711486816406, -0.016485974192619324, 0.015598269179463387, -0.03750106319785118, 0.00365725951269269, 0.05761032924056053, -0.02804427407681942, -0.01204744353890419, -0.005271888803690672, 0.005774620454758406, -0.0807993933558464, 0.0057383873499929905, -0.0001093356404453516, -0.02259122021496296, 0.00797577016055584, -0.006567215546965599, -0.055436354130506516, -0.004914088640362024, -0.04174031317234039, 0.011721347458660603, -0.008356215432286263, 0.03760976344347, -0.05340731143951416, 0.03242845460772514, 0.0715237706899643, 0.006358875893056393, 0.010453195311129093, 0.01126843597739935, 0.015154415741562843, 0.0038316305726766586, 0.001984884263947606, 0.030345063656568527, -0.02664930745959282, 0.0008254310232587159, 0.013397119008004665, 0.04195771366357803, -0.017799418419599533, 0.05050867795944214, 0.009855352342128754, -0.0053987037390470505, -0.05786396190524101, 0.02275426872074604, -0.010878931730985641, 0.019040394574403763, -0.10782914608716965, 0.01326124556362629, -0.0296022891998291, -0.01144960056990385, -0.0030163899064064026, -0.02933054231107235, 0.1009448915719986, -0.010290146805346012, 0.02965663932263851, 0.01528123114258051, 0.07054547965526581, 0.04032723233103752, 0.07083534449338913, 0.01607835479080677, 0.005285475868731737, 0.0011362414807081223, 0.06300903111696243, -0.04775497689843178, 0.012011210434138775, -0.0008446797728538513, -0.02559855207800865, -0.02947547473013401, 0.0050816661678254604, -0.01729215681552887, 0.01756390370428562, -0.021848445758223534, -0.06565403938293457, 0.03333427757024765, 0.022011494264006615, -0.0080754105001688, -0.009755712002515793, -0.00812523066997528, -0.06101622432470322, 0.010389787144958973, 0.060907524079084396, -0.01865994930267334, -0.02414923533797264, 0.07942254096269608, 0.0323016420006752, 0.04518244042992592, -0.07232089340686798, 0.09108953922986984, 0.032682087272405624, 0.07021938264369965, 0.022337591275572777, -0.016766780987381935, 0.008197695948183537, -0.052827585488557816, -0.10956832766532898, 0.058045126497745514, -0.008356215432286263, 0.019438957795500755, 0.05873354896903038, -0.048878200352191925, -0.027627594769001007, -0.02965663932263851, 0.020489711314439774, 0.028460953384637833, -0.02423981763422489, 0.022518755868077278, 0.05710307136178017, 0.02288108319044113, 0.01755484566092491, 0.00023438164498656988, -0.0024638380855321884, 0.06844396889209747, 0.023714441806077957, 0.04855210334062576, -0.031486399471759796, 0.018053049221634865, 0.05503779277205467, 0.007400572299957275, -0.003448920324444771, -0.015580152161419392, -0.014221417717635632, 0.08021967113018036, -0.021757863461971283, 0.0007784414920024574, 0.0726107582449913, 0.03451184928417206, -0.02677612192928791, -0.01266340259462595, -0.001568205771036446, -0.02121436968445778, 0.042247574776411057, 0.03308064863085747, -0.029747221618890762, 0.012409772723913193, 0.022228891029953957, -0.013143489137291908, -0.00025179042131640017, 0.0015455601969733834, 0.03501911088824272, -0.019058512523770332, 0.029076911509037018, 0.016993235796689987, -0.055581286549568176, 0.016812071204185486, 0.10362613201141357, 0.029855920001864433, -0.011648881249129772, -0.018125513568520546, 0.07351657748222351, 0.03347920998930931, -0.03456619754433632, 0.008478501811623573, -0.0508347749710083, 0.008931413292884827, 0.004515526816248894, 0.0063769924454391, -0.04982025548815727, -0.07387890666723251, 0.031105956062674522, -0.026468142867088318, -0.0017414443427696824, -0.010860815644264221, -0.021775979548692703, 0.02152235060930252, -0.0668497234582901, -0.011594532057642937, -0.036903221160173416, -0.011250318959355354, -0.01265434455126524, -0.0016259519616141915, 0.003324369667097926, -0.020362896844744682, 0.001293061999604106, 0.01008180808275938, 0.01887734793126583, -0.005434936843812466, 0.0675743818283081, -0.016295751556754112, -0.009148810058832169, 0.04934922605752945, 0.04286353662610054, 0.06445834785699844, -0.02128683589398861, 0.016893595457077026, 0.026051463559269905, 0.0014549779007211328, -0.005185835529118776, 0.021087555214762688, -0.05594361573457718, 0.053950805217027664, -0.06558156758546829, -0.023623859509825706, 0.011413367465138435, 0.00017748466052580625, 0.023750673979520798, -0.04927676171064377, -0.025997115299105644, -0.005575339309871197, 0.07434993237257004, -0.005453053396195173, 0.006526453420519829, -0.018351970240473747, 0.04184901341795921, -0.005511931609362364, 0.01595154032111168, 0.0402185320854187, 0.04036346450448036, -0.011485832743346691, -0.014275767840445042, 0.021848445758223534, 0.10101735591888428, -0.004637812729924917, -0.010860815644264221, 0.01885922998189926, 0.011404309421777725, -0.020471595227718353, -0.07550939172506332, 0.0171834584325552, 0.07145130634307861, -0.027555130422115326, -0.04945792630314827, 0.05713930353522301, 0.04931299388408661, 0.025707250460982323, 0.02389560639858246, -0.033877771347761154, 0.021033205091953278, -0.01885922998189926, 0.015743199735879898, 0.03895037993788719, -0.056921906769275665, -0.007989357225596905, 0.03616044670343399, -0.028877630829811096, -0.03826195374131203, -0.045907098799943924, 0.023714441806077957, 0.004116964526474476, -0.00662609376013279, 0.01587001606822014, -0.02818920649588108, -0.0069974809885025024, -0.03376907482743263, -0.014366350136697292, -0.014493164606392384, 0.020362896844744682, 0.0033153113909065723, 0.022355707362294197, 0.01137713436037302, -0.01847878471016884, -0.06445834785699844, -0.03168568015098572, 0.03498287498950958, -0.010308263823390007, -0.01749143749475479, -0.06326266378164291, 0.0649656131863594, 0.07920514792203903, -0.005788207519799471, -0.02389560639858246, 0.021830329671502113, 0.017808476462960243, -0.004155462142080069, -0.04916806146502495, -0.014828319661319256, -0.009293741546571255, 0.04539983719587326, 0.0036595240235328674, 0.007287344429641962, 0.025018826127052307, -0.01739179715514183, 0.01127749402076006, -0.006431342102587223, 0.06014663353562355, 0.03213859349489212, 0.05790019407868385, -0.009198630228638649, 0.02293543331325054, -0.01889546401798725, 0.006879724096506834, -0.01058906875550747, 0.010136157274246216, 0.016440683975815773, 0.01882299780845642, -0.010235797613859177, -0.007957653142511845, -0.0856546014547348, 0.04275483638048172, -0.01393155474215746, 0.0063452888280153275, -0.018931696191430092, -0.0006329437019303441, -0.027518896386027336, 0.05786396190524101, 0.02000056765973568, 0.07434993237257004, -0.0043524787761271, 0.019149094820022583, 0.04268237203359604, 0.035164039582014084, 0.0007982563693076372, 0.02125060372054577, 0.011105387471616268, 0.009130693972110748, -0.056994371116161346, 0.011748521588742733, -0.04101565480232239, 0.010743058286607265, 0.05862485244870186, 0.018261387944221497, -0.028768932446837425, -0.07478473335504532, -0.060690127313137054, 0.022083960473537445, -0.020489711314439774, -0.017690720036625862, 0.021739747375249863, -0.0323922224342823, 0.0019124184036627412, 0.025834066793322563, 0.009801003150641918, 0.018125513568520546, -0.028787048533558846, -0.006852549500763416, -0.10232174396514893, -0.005747445859014988, 0.08174145221710205, -0.00942055694758892, -0.006422283593565226, 0.019692588597536087, 0.01460186392068863, -0.014837377704679966, 0.019638238474726677, -0.06438588351011276, 0.04532737284898758, -0.024801427498459816, -0.04043592885136604, -0.0021694456227123737, -0.03579811751842499, -0.005453053396195173, 0.059530675411224365, -0.0424649715423584, -0.05126957222819328, 0.023623859509825706, -0.02933054231107235, 0.04101565480232239, 0.016467858105897903, -0.013659807853400707, -0.03592493385076523, 0.036903221160173416, 0.022065844386816025, -0.0035327088553458452, -0.004873326513916254, -0.019348375499248505, 0.025906533002853394, -0.006915957201272249, -0.03572565317153931, -0.02250063791871071, 0.03179438039660454, 0.022210774943232536, -0.04775497689843178, -0.04550853744149208, -0.02824355475604534, 0.04322586581110954, 0.0347292460501194, 0.04119681939482689, 0.030073316767811775, -0.021160021424293518, -0.03358791023492813, -0.07703117281198502, -0.008396977558732033, -0.008618904277682304, -0.06565403938293457, 0.074857197701931, -0.039167776703834534, -0.08369802683591843, -0.06576273590326309, 0.008931413292884827, -0.027156567201018333, 0.012627169489860535, -0.011666997335851192, -0.03376907482743263, 0.08108925819396973, -0.020326664671301842, 0.019420841708779335, -0.004932205192744732, -0.0294211246073246, 0.046160731464624405, -0.012020268477499485, -0.06782801449298859, 0.008655136451125145, -0.03195742890238762, -0.020471595227718353, -0.02027231454849243, -0.021087555214762688, 0.027355847880244255, 0.0428273007273674, -0.053914573043584824, -0.00192600570153445, -0.009791944175958633, 0.014266708865761757, -0.015208764933049679, -0.06569027155637741, 0.020652759820222855, -0.09558242559432983, -0.04982025548815727, -0.018062107264995575, -0.000680499360896647, 0.030345063656568527, -0.023207180202007294, 0.0002887310110963881, -0.035164039582014084, 0.010534719564020634, 0.054023273289203644, 0.02257310412824154, -0.007862541824579239, 0.0009811193449422717, 0.03183061257004738, 0.0030028026085346937, -0.005797266028821468, 0.022210774943232536, -0.020779574289917946, 0.02416735328733921, 0.02385937236249447, 0.03974750638008118, -0.009166927076876163, 0.011802870780229568, 0.04029100015759468, 0.013976845890283585, 0.03924024477601051, 0.04558100178837776, -0.012228608131408691, -0.0370662696659565, 0.0068887826055288315, 0.02134118601679802, -0.0007014465518295765, -0.010480369441211224, -0.07652390748262405, 0.025181874632835388, 0.02659495733678341, 0.017726952210068703, 0.01265434455126524, -0.012165199965238571, 0.011621706187725067, 0.048769500106573105, -0.07094404101371765, -0.04014606773853302, -0.040653329342603683, 0.009357149712741375, -0.07181363552808762, 0.03498287498950958, -0.0006391712231561542, -0.0031318822875618935, 0.008070881478488445, 0.042138878256082535, -0.0035938520450145006, 0.030109550803899765, -0.01409460324794054, -0.005099782254546881, -0.018279504030942917, -0.006612506695091724, -0.01266340259462595, 0.027210917323827744, 0.009357149712741375, 0.015272172167897224, 0.0670308843255043, 0.01463809609413147, -0.036703940480947495, -0.030055200681090355, -0.0006329437019303441, -0.08964022248983383, 0.03565318509936333, -0.02130495198071003, 0.014810202643275261, 0.0030548875220119953, 0.0021524615585803986, 0.06061766296625137, -0.08645173162221909, -0.027174683287739754, -0.019638238474726677, -0.03728366643190384, 0.048914432525634766, -0.02940300852060318, 0.011241260915994644, 0.0018252329900860786, 0.020489711314439774, -0.0511971041560173, 0.02543550357222557, -0.032591503113508224, -0.0069974809885025024, -0.05434936657547951, -0.013623574748635292, -0.005394174717366695, 0.07920514792203903, 0.006834432948380709, 0.05800889432430267, 0.030109550803899765, -0.0006521923933178186, -0.1023942083120346, -0.0005316047463566065, 0.030399413779377937, 0.017156284302473068, -0.01616893708705902, -0.0005870864260941744, -0.020888274535536766, -0.007812721654772758, -0.00568856718018651, -0.012590937316417694, 0.02798992395401001, 0.048660799860954285, -0.04369689151644707, 0.01981940306723118, 0.003557619173079729, -0.028497185558080673, -0.001470829825848341, -0.04953039065003395, 0.02154046669602394, -0.014973251149058342, 0.00011973845539614558, -0.037247434258461, -0.04953039065003395, -0.053987037390470505, -0.035562604665756226, 0.000986214610747993, -0.005235655698925257, -0.026450026780366898, -0.031051605939865112, 0.0020981121342629194, 0.012147083878517151, 0.027826877310872078 ]
30,687
networkx.readwrite.edgelist
generate_edgelist
Generate a single line of the graph G in edge list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels data : bool or list of keys If False generate no edge data. If True use a dictionary representation of edge data. If a list of keys use a list of data values corresponding to the keys. Returns ------- lines : string Lines of data in adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> G[1][2]["weight"] = 3 >>> G[3][4]["capacity"] = 12 >>> for line in nx.generate_edgelist(G, data=False): ... print(line) 0 1 0 2 0 3 1 2 1 3 2 3 3 4 4 5 5 6 >>> for line in nx.generate_edgelist(G): ... print(line) 0 1 {} 0 2 {} 0 3 {} 1 2 {'weight': 3} 1 3 {} 2 3 {} 3 4 {'capacity': 12} 4 5 {} 5 6 {} >>> for line in nx.generate_edgelist(G, data=["weight"]): ... print(line) 0 1 0 2 0 3 1 2 3 1 3 2 3 3 4 4 5 5 6 See Also -------- write_adjlist, read_adjlist
def generate_edgelist(G, delimiter=" ", data=True): """Generate a single line of the graph G in edge list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels data : bool or list of keys If False generate no edge data. If True use a dictionary representation of edge data. If a list of keys use a list of data values corresponding to the keys. Returns ------- lines : string Lines of data in adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> G[1][2]["weight"] = 3 >>> G[3][4]["capacity"] = 12 >>> for line in nx.generate_edgelist(G, data=False): ... print(line) 0 1 0 2 0 3 1 2 1 3 2 3 3 4 4 5 5 6 >>> for line in nx.generate_edgelist(G): ... print(line) 0 1 {} 0 2 {} 0 3 {} 1 2 {'weight': 3} 1 3 {} 2 3 {} 3 4 {'capacity': 12} 4 5 {} 5 6 {} >>> for line in nx.generate_edgelist(G, data=["weight"]): ... print(line) 0 1 0 2 0 3 1 2 3 1 3 2 3 3 4 4 5 5 6 See Also -------- write_adjlist, read_adjlist """ if data is True: for u, v, d in G.edges(data=True): e = u, v, dict(d) yield delimiter.join(map(str, e)) elif data is False: for u, v in G.edges(data=False): e = u, v yield delimiter.join(map(str, e)) else: for u, v, d in G.edges(data=True): e = [u, v] try: e.extend(d[k] for k in data) except KeyError: pass # missing data for this edge, should warn? yield delimiter.join(map(str, e))
(G, delimiter=' ', data=True)
[ 0.04086281731724739, -0.008968869224190712, -0.007355863228440285, -0.04965091869235039, 0.023824281990528107, 0.0034577655605971813, -0.013515876606106758, 0.006730128079652786, 0.09640955179929733, -0.031073538586497307, 0.012162434868514538, 0.0007792718824930489, -0.008509996347129345, 0.006975787226110697, -0.0005706935189664364, 0.012032653205096722, -0.025251885876059532, -0.027995849028229713, 0.05506468564271927, 0.04864973947405815, 0.010938775725662708, -0.028032930567860603, 0.012653753161430359, -0.008431199938058853, 0.004292078781872988, 0.0469440333545208, -0.026086198166012764, 0.030202144756913185, 0.018744241446256638, 0.011652576737105846, -0.02224835753440857, -0.10308405756950378, -0.027291318401694298, -0.011485714465379715, 0.03418830782175064, 0.03003528155386448, -0.0267165694385767, 0.011837979778647423, -0.055769216269254684, 0.010846073739230633, 0.04601701721549034, -0.03769242390990257, 0.03819301351904869, 0.00009719171794131398, -0.007314147427678108, 0.03335399553179741, -0.023954065516591072, 0.034744519740343094, -0.06444607675075531, -0.07349374145269394, 0.03845257684588432, 0.0029061916284263134, -0.011949221603572369, 0.006146108731627464, -0.005353510845452547, -0.03246406093239784, 0.014758077450096607, -0.008231892250478268, 0.03754410147666931, 0.03848965838551521, -0.007008232641965151, -0.013933033682405949, 0.014044275507330894, -0.031184781342744827, -0.018799861893057823, 0.03248260170221329, -0.06270328909158707, -0.06878450512886047, -0.0016628329176455736, 0.04334721714258194, 0.006883085705339909, 0.018660809844732285, -0.028644759207963943, 0.024899620562791824, 0.012551781721413136, 0.026271602138876915, -0.013256313279271126, 0.03613504022359848, 0.042642686516046524, -0.03848965838551521, -0.011893601156771183, 0.0022723451256752014, 0.0010098668280988932, 0.01280207559466362, 0.05276568606495857, 0.001604894525371492, -0.01684386096894741, 0.03685811161994934, -0.008004773408174515, -0.021080318838357925, -0.0073929438367486, -0.008570252917706966, -0.024899620562791824, 0.029200969263911247, -0.023138292133808136, -0.04549789056181908, -0.0372103787958622, -0.027031753212213516, 0.04586869478225708, 0.05283984914422035, 0.029757177457213402, 0.019560014829039574, -0.021840469911694527, 0.01110563799738884, -0.029886959120631218, -0.1282247006893158, -0.03517094627022743, 0.006841369904577732, 0.015036181546747684, -0.045534972101449966, -0.05525008589029312, 0.029293671250343323, 0.06274037063121796, -0.020616810768842697, 0.024324869737029076, 0.0333910770714283, 0.022341059520840645, -0.017001453787088394, 0.010326946154236794, -0.05918063223361969, 0.0009687305428087711, -0.016500864177942276, -0.0675237625837326, 0.03418830782175064, 0.04078865423798561, -0.03617212176322937, 0.011875060386955738, -0.04460795596241951, 0.012709374539554119, -0.08684275299310684, 0.059773918241262436, 0.05925479158759117, 0.005144932772964239, 0.010586510412395, -0.010762643069028854, -0.045349568128585815, -0.002370840637013316, 0.01734444871544838, 0.0660405382514, 0.001280439319089055, 0.024714216589927673, -0.09203403443098068, 0.01968979649245739, 0.04249436408281326, -0.018707159906625748, -0.03581985458731651, 0.04605409875512123, 0.03018360398709774, 0.04635074362158775, -0.00041686699842102826, 0.03908294811844826, 0.03533780574798584, 0.014646835625171661, -0.04824185371398926, 0.030480248853564262, 0.004180836956948042, -0.11546897143125534, 0.013515876606106758, 0.009154272265732288, -0.02350909821689129, -0.02339785546064377, -0.01904088631272316, -0.00717509537935257, 0.02426924929022789, 0.02845935709774494, 0.06155378744006157, 0.032760705798864365, -0.03617212176322937, 0.030276305973529816, -0.017770875245332718, 0.008102109655737877, -0.08083570003509521, -0.053173575550317764, -0.014813697896897793, 0.02319391258060932, 0.05669622868299484, -0.009066205471754074, 0.07104641944169998, 0.019059425219893456, 0.02387990429997444, -0.01586122438311577, 0.004973434843122959, 0.006345416884869337, -0.04438547417521477, 0.02148820459842682, -0.03418830782175064, 0.031203320249915123, -0.033706262707710266, 0.013098720461130142, -0.007624697405844927, -0.05614002048969269, -0.0770534798502922, -0.014822968281805515, 0.056881632655858994, -0.008625873364508152, -0.01179162971675396, -0.0408257357776165, 0.03259384259581566, -0.04509000480175018, 0.05606586113572121, 0.026920512318611145, -0.028514977544546127, 0.01572217233479023, -0.02282310649752617, 0.021043237298727036, 0.05665915086865425, 0.001552749890834093, -0.058216534554958344, -0.011569146066904068, 0.029553234577178955, 0.01987519860267639, -0.025344587862491608, 0.029219510033726692, 0.008264337666332722, 0.015295745804905891, 0.033372536301612854, -0.01781722530722618, 0.05550965294241905, -0.08120650053024292, -0.03739577904343605, 0.008931788615882397, -0.03190785273909569, -0.013886682689189911, 0.01509180199354887, 0.06956319510936737, -0.06033013015985489, 0.02423216961324215, -0.04753732308745384, -0.026308681815862656, 0.032983191311359406, 0.03437371179461479, 0.006498374510556459, 0.00707775866612792, 0.012663023546338081, 0.022841647267341614, 0.01408135611563921, 0.032983191311359406, -0.010021030902862549, 0.004549325443804264, 0.05410058796405792, -0.05695579573512077, -0.007040678057819605, -0.01846613734960556, -0.03772950544953346, 0.009854168631136417, 0.018123140558600426, 0.009487997740507126, 0.009650224819779396, -0.01600954681634903, -0.004982705228030682, -0.07189927250146866, 0.025326047092676163, 0.01634327322244644, -0.015323556028306484, 0.001615323475562036, -0.02171068824827671, -0.014702456071972847, -0.03632044419646263, -0.009474092163145542, -0.009265514090657234, 0.009603873826563358, 0.027309859171509743, -0.05803113058209419, 0.05135662481188774, 0.07912999391555786, -0.014822968281805515, -0.008649049326777458, -0.0005689553800038993, -0.010271324776113033, 0.02621598169207573, 0.015295745804905891, 0.01108709815889597, 0.015267935581505299, 0.009195988066494465, 0.03274216502904892, 0.03094375692307949, 0.010855344124138355, 0.006730128079652786, -0.01633400283753872, -0.012996749021112919, -0.04987340047955513, 0.018364164978265762, -0.029089726507663727, -0.005900449585169554, -0.0869910791516304, 0.00013347565254662186, -0.025696853175759315, -0.011383743025362492, 0.023249533027410507, -0.014192597940564156, 0.07471740245819092, 0.0015237807529047132, -0.00018974835984408855, 0.028292493894696236, 0.08239307999610901, 0.02167360857129097, 0.07735012471675873, 0.01152279507368803, 0.04305057227611542, 0.0015539086889475584, 0.09247900545597076, -0.03240843862295151, 0.07964912056922913, -0.004438083618879318, -0.021617986261844635, -0.032371360808610916, 0.036301903426647186, -0.029275130480527878, -0.0008418454090133309, -0.056881632655858994, -0.04453379660844803, 0.028626220300793648, 0.012811345979571342, -0.001687167095951736, -0.009149637073278427, -0.002727741375565529, -0.036060880869627, 0.018123140558600426, 0.03912002965807915, -0.0032978553790599108, -0.0202274639159441, 0.049354273825883865, 0.04238311946392059, 0.0228972677141428, -0.022711865603923798, 0.06578097492456436, 0.03426247090101242, 0.059736840426921844, 0.04842725768685341, -0.0021947077475488186, 0.009205257520079613, -0.042679764330387115, -0.0683024600148201, 0.07742428034543991, -0.03170390799641609, 0.0289970263838768, 0.03576423600316048, -0.012579591944813728, -0.05413766950368881, -0.026531165465712547, -0.00391432037577033, 0.029516154900193214, -0.008686129935085773, 0.00910792127251625, 0.04976215958595276, 0.013274853117763996, 0.037414319813251495, -0.01691802218556404, 0.009478727355599403, 0.10130418837070465, 0.016463784500956535, 0.03398436680436134, -0.014387271367013454, 0.017261017113924026, 0.04486751928925514, -0.03659854829311371, -0.02362033911049366, -0.027828987687826157, 0.007416118867695332, 0.09040249139070511, 0.023360775783658028, 0.0069387066178023815, 0.053247734904289246, 0.045349568128585815, -0.020783673971891403, -0.02762504294514656, -0.008088205009698868, 0.050615012645721436, 0.062258318066596985, 0.029015565291047096, -0.019244829192757607, -0.003657073713839054, 0.019930820912122726, -0.034781597554683685, 0.024399030953645706, -0.009460186585783958, 0.019560014829039574, -0.009659495204687119, 0.01915212720632553, 0.02781044691801071, -0.04850141704082489, 0.00832922849804163, 0.09329477697610855, 0.025159183889627457, 0.015889035537838936, -0.01307091023772955, 0.07256672531366348, 0.0499846413731575, -0.0007479851483367383, -0.01734444871544838, -0.06440899521112442, 0.020004982128739357, 0.045534972101449966, 0.022118575870990753, -0.06578097492456436, -0.08039072901010513, 0.047908131033182144, -0.038712140172719955, -0.030572950839996338, -0.013627118431031704, -0.03956499695777893, 0.03772950544953346, -0.08773268759250641, -0.0005985039751976728, -0.0015191456768661737, -0.027903148904442787, -0.008370944298803806, -0.006373227573931217, 0.023601798340678215, -0.03137018531560898, 0.008579522371292114, -0.0006257350323721766, 0.012088274583220482, -0.005052231252193451, 0.07712763547897339, -0.009622414596378803, 0.007040678057819605, 0.06733836233615875, 0.03602379932999611, 0.062295399606227875, -0.010957315564155579, -0.0040788655169308186, 0.03908294811844826, 0.006850639823824167, 0.006516914814710617, 0.01350660715252161, -0.05862442031502724, 0.032260119915008545, -0.051579106599092484, 0.002648944966495037, -0.007272431626915932, -0.030498789623379707, 0.021766308695077896, -0.048056453466415405, -0.0038795573636889458, -0.03674687072634697, 0.05428599193692207, -0.02773628570139408, 0.022489381954073906, -0.034707438200712204, 0.02708737552165985, -0.0183178149163723, 0.020505569875240326, -0.009789276868104935, 0.011800899170339108, -0.009047665633261204, -0.011680387891829014, 0.0375811830163002, 0.12169851362705231, 0.0033557938877493143, 0.0010793929686769843, 0.017084883525967598, 0.03240843862295151, -0.015824144706130028, -0.07905583083629608, 0.015481148846447468, 0.0747915580868721, -0.029089726507663727, -0.032334279268980026, 0.03735870122909546, 0.05102289840579033, 0.0060673123225569725, -0.003721964778378606, -0.014683916233479977, 0.028218332678079605, 0.0077266693115234375, 0.023249533027410507, 0.03201909363269806, -0.05224655941128731, -0.03494846075773239, 0.017622552812099457, -0.027031753212213516, -0.03978747874498367, -0.04038076847791672, 0.044014666229486465, 0.036079417914152145, -0.0037567277904599905, 0.010493808425962925, -0.04171567037701607, -0.06882158666849136, 0.0016825320199131966, -0.03255676105618477, 0.015638740733265877, -0.008278243243694305, -0.015379177406430244, -0.0012676928890869021, 0.013951574452221394, -0.018595919013023376, -0.07252964377403259, -0.02582663483917713, 0.004206330049782991, -0.02838519588112831, -0.030276305973529816, -0.040269527584314346, 0.06385278701782227, 0.07382746785879135, 0.003578277537599206, -0.02365742065012455, 0.009140366688370705, -0.013228502124547958, 0.005905084777623415, -0.046684470027685165, 0.014266759157180786, -0.03848965838551521, 0.022619163617491722, 0.011837979778647423, 0.025808094069361687, 0.04757440462708473, -0.00165472156368196, -0.004959529731422663, 0.0037822206504642963, 0.04438547417521477, 0.03904586657881737, 0.054211828857660294, -0.019022345542907715, 0.005274714902043343, -0.024565894156694412, 0.058587342500686646, -0.011040747165679932, 0.013135801069438457, 0.007550536189228296, 0.03162974864244461, -0.009256243705749512, 0.0115413349121809, -0.06314825266599655, 0.05391518399119377, -0.02827395312488079, -0.01752985082566738, -0.0039467657916247845, 0.03418830782175064, -0.017140505835413933, 0.06251788139343262, 0.02625306136906147, 0.06719003617763519, -0.03581985458731651, 0.010345485992729664, 0.03578277304768562, 0.0499846413731575, -0.010901695117354393, 0.000861544453073293, 0.022637704387307167, 0.02538166753947735, -0.04319889470934868, -0.018707159906625748, -0.03452203422784805, 0.009140366688370705, 0.05131954327225685, 0.015138152986764908, -0.002938637277111411, -0.09826357662677765, -0.05480511859059334, 0.01789138652384281, -0.000587495684158057, -0.007128744386136532, -0.00845437590032816, -0.03841549530625343, -0.0028969214763492346, 0.021580906584858894, 0.02141404338181019, -0.010299134999513626, -0.04375510290265083, 0.01663064770400524, -0.11420823633670807, -0.021877551451325417, 0.08832597732543945, 0.007907437160611153, -0.015314285643398762, 0.007485645357519388, -0.010364026762545109, -0.01871643029153347, -0.0015156692825257778, -0.04549789056181908, 0.05139370635151863, -0.02823687344789505, -0.005636250600218773, 0.004674472380429506, -0.05206115543842316, -0.025047942996025085, 0.05131954327225685, -0.08580449968576431, -0.036839570850133896, -0.006489104125648737, -0.018123140558600426, 0.03307589143514633, 0.012060463428497314, -0.027717744931578636, -0.040009964257478714, 0.046461984515190125, -0.01846613734960556, 0.02751380205154419, 0.016575025394558907, -0.017604012042284012, 0.025585610419511795, -0.004139121621847153, -0.030387548729777336, -0.031036458909511566, 0.04850141704082489, 0.03704351559281349, -0.055843375623226166, -0.041344862431287766, -0.05387810617685318, 0.05795697122812271, 0.03296465054154396, 0.015536769293248653, 0.007564441300928593, -0.02228543721139431, -0.0013812521938234568, -0.05280276760458946, -0.003578277537599206, -0.013571497984230518, -0.04453379660844803, 0.07883334904909134, -0.011272501200437546, -0.07238132506608963, -0.05491636320948601, 0.0037242823746055365, -0.02679073065519333, 0.02224835753440857, 0.004936354234814644, -0.029775718227028847, 0.07638602703809738, -0.038971707224845886, 0.007314147427678108, 0.002124022925272584, -0.055806297808885574, 0.0396762378513813, -0.018836941570043564, -0.03324275463819504, -0.019986441358923912, -0.05565797537565231, -0.02816271223127842, -0.07356790453195572, -0.008370944298803806, 0.025696853175759315, 0.009585333988070488, -0.04193815216422081, -0.0047509511932730675, -0.003052196465432644, 0.004092770628631115, -0.03090667724609375, -0.0343366302549839, 0.023434937000274658, -0.08676858991384506, -0.04242020100355148, -0.02762504294514656, 0.033910203725099564, 0.03372479975223541, -0.030591491609811783, -0.0033511589281260967, -0.03353939950466156, 0.02675364911556244, 0.051727429032325745, 0.01734444871544838, 0.005029055755585432, 0.0054369424469769, 0.05780864879488945, 0.010688481852412224, -0.041307784616947174, 0.014609755016863346, -0.0269019715487957, 0.015555310063064098, 0.020635351538658142, 0.03704351559281349, -0.017409339547157288, -0.012653753161430359, 0.019411692395806313, 0.011365202255547047, 0.053136494010686874, 0.04946551471948624, -0.010688481852412224, -0.053173575550317764, 0.006470563821494579, 0.010048841126263142, -0.0012827567989006639, -0.001789138768799603, -0.05565797537565231, 0.00437319278717041, 0.0005967658362351358, -0.005316430237144232, 0.010725562460720539, -0.0038494293112307787, 0.007244621403515339, 0.026735110208392143, -0.021840469911694527, -0.030239226296544075, 0.0012781217228621244, 0.002136769238859415, -0.05013296380639076, 0.01480442751199007, -0.001854029716923833, 0.020635351538658142, -0.021117398515343666, 0.03411414846777916, -0.03313151374459267, 0.0035968178417533636, -0.025251885876059532, -0.01572217233479023, -0.023323694244027138, 0.008408024907112122, -0.009335040114820004, 0.017010722309350967, 0.01662137731909752, 0.02499232068657875, 0.05473095923662186, 0.004880733322352171, -0.0686732605099678, -0.04564621299505234, -0.007504185661673546, -0.0755702555179596, 0.024621514603495598, -0.020653892308473587, 0.022415220737457275, -0.01568509265780449, -0.03570861369371414, 0.04379218444228172, -0.08335717767477036, -0.027272777631878853, 0.008125285618007183, -0.051727429032325745, 0.03724745661020279, -0.00430134916678071, 0.011875060386955738, 0.0153606366366148, 0.019634176045656204, -0.05246904119849205, 0.006628156639635563, -0.05751200392842293, -0.028422275558114052, -0.02805147133767605, -0.013209962286055088, -0.004815842490643263, 0.062443722039461136, 0.021617986261844635, 0.062369562685489655, 0.026586787775158882, -0.0251777246594429, -0.09522297233343124, -0.0000741611875128001, 0.03316859155893326, 0.0534331388771534, -0.01756693236529827, 0.026012036949396133, -0.026382843032479286, 0.008394120261073112, -0.010920234955847263, -0.0322415791451931, 0.04720359668135643, 0.05473095923662186, -0.03365064039826393, 0.01922628842294216, -0.012143895030021667, -0.03148142620921135, -0.032612383365631104, -0.05013296380639076, -0.0022445349022746086, -0.0025284329894930124, -0.01457267440855503, -0.04939135164022446, -0.042791008949279785, -0.046869874000549316, -0.019893739372491837, 0.02931221015751362, -0.01604662835597992, 0.0015863542212173343, -0.042605604976415634, 0.020357247442007065, 0.02311975136399269, 0.0408257357776165 ]
30,688
networkx.readwrite.gexf
generate_gexf
Generate lines of GEXF format representation of G. "GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics" [1]_. Parameters ---------- G : graph A NetworkX graph encoding : string (optional, default: 'utf-8') Encoding for text data. prettyprint : bool (optional, default: True) If True use line breaks and indenting in output XML. version : string (default: 1.2draft) Version of GEFX File Format (see http://gexf.net/schema.html) Supported values: "1.1draft", "1.2draft" Examples -------- >>> G = nx.path_graph(4) >>> linefeed = chr(10) # linefeed= >>> s = linefeed.join(nx.generate_gexf(G)) >>> for line in nx.generate_gexf(G): # doctest: +SKIP ... print(line) Notes ----- This implementation does not support mixed graphs (directed and undirected edges together). The node id attribute is set to be the string of the node label. If you want to specify an id use set it as node data, e.g. node['a']['id']=1 to set the id of node 'a' to 1. References ---------- .. [1] GEXF File Format, https://gephi.org/gexf/format/
def generate_gexf(G, encoding="utf-8", prettyprint=True, version="1.2draft"): """Generate lines of GEXF format representation of G. "GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics" [1]_. Parameters ---------- G : graph A NetworkX graph encoding : string (optional, default: 'utf-8') Encoding for text data. prettyprint : bool (optional, default: True) If True use line breaks and indenting in output XML. version : string (default: 1.2draft) Version of GEFX File Format (see http://gexf.net/schema.html) Supported values: "1.1draft", "1.2draft" Examples -------- >>> G = nx.path_graph(4) >>> linefeed = chr(10) # linefeed=\n >>> s = linefeed.join(nx.generate_gexf(G)) >>> for line in nx.generate_gexf(G): # doctest: +SKIP ... print(line) Notes ----- This implementation does not support mixed graphs (directed and undirected edges together). The node id attribute is set to be the string of the node label. If you want to specify an id use set it as node data, e.g. node['a']['id']=1 to set the id of node 'a' to 1. References ---------- .. [1] GEXF File Format, https://gephi.org/gexf/format/ """ writer = GEXFWriter(encoding=encoding, prettyprint=prettyprint, version=version) writer.add_graph(G) yield from str(writer).splitlines()
(G, encoding='utf-8', prettyprint=True, version='1.2draft')
[ 0.07383064925670624, 0.004707201384007931, 0.007097011432051659, 0.008337178267538548, 0.014103500172495842, -0.07136841863393784, -0.0835709348320961, -0.0078030917793512344, 0.0876987874507904, -0.0021205036900937557, 0.044754624366760254, -0.05721060559153557, -0.06604565680027008, 0.061591923236846924, -0.026975886896252632, 0.004987823311239481, -0.06361964344978333, -0.044827044010162354, 0.04852038621902466, 0.021942801773548126, 0.001432528137229383, -0.008214971981942654, -0.018629655241966248, 0.0009001391590572894, 0.03566610440611839, -0.0006574240978807211, 0.02534647099673748, 0.04765136539936066, 0.004474104382097721, -0.01568765379488468, -0.0069883838295936584, -0.14440245926380157, -0.037512775510549545, -0.03228054195642471, 0.0037634982727468014, 0.023246334865689278, -0.0786464735865593, -0.005929263774305582, -0.03291420266032219, -0.037766240537166595, 0.055291514843702316, 0.034091003239154816, 0.014058238826692104, -0.012075782753527164, -0.028207000344991684, 0.0015637866454198956, -0.030017461627721786, -0.0016724143642932177, -0.05047568306326866, 0.022612672299146652, 0.011369702406227589, -0.03228054195642471, -0.009242408908903599, -0.003935492131859064, -0.02458607591688633, -0.009423455223441124, 0.010029960423707962, 0.000037270059692673385, 0.05297412350773811, -0.008219498209655285, -0.010247215628623962, -0.005549066700041294, 0.031194262206554413, 0.01572386361658573, 0.019589200615882874, 0.05167058855295181, -0.036607544869184494, -0.06571977585554123, -0.006409035995602608, 0.022504044696688652, -0.03505054861307144, 0.03463413938879967, -0.017154129222035408, -0.014664743095636368, 0.0006353590870276093, 0.07303404062986374, -0.03244348242878914, 0.02847857028245926, 0.032425377517938614, -0.045515019446611404, -0.0035485057160258293, 0.0403008870780468, -0.014302651397883892, 0.002862793393433094, 0.07647392153739929, 0.007097011432051659, 0.03559368476271629, -0.000882034539245069, 0.015171673148870468, -0.0022155530750751495, -0.007861931808292866, 0.036752380430698395, -0.018285667523741722, -0.02091083861887455, 0.026432747021317482, -0.0844399556517601, 0.017896417528390884, 0.014266441576182842, 0.04040951654314995, 0.018403347581624985, 0.015452294610440731, 0.0002096175740007311, -0.0418216772377491, 0.01471000537276268, -0.004125590436160564, -0.00597452512010932, -0.020965151488780975, 0.003385564312338829, 0.06785611808300018, -0.011885683983564377, -0.011324441060423851, -0.053553469479084015, 0.07589457184076309, -0.07437378168106079, 0.03990258648991585, -0.008070135489106178, 0.03599198907613754, 0.023427380248904228, 0.01788736693561077, -0.04844796657562256, 0.0827743262052536, -0.011912841349840164, -0.09146454930305481, 0.06307650357484818, 0.0431976281106472, 0.0015660497592762113, 0.03961291164159775, 0.0034330887719988823, 0.06955795735120773, -0.07401169091463089, 0.032497797161340714, 0.04388560354709625, -0.005377072375267744, -0.005503804888576269, -0.027175037190318108, -0.06586461514234543, -0.03572041913866997, 0.00788003671914339, 0.0436321385204792, 0.02217816188931465, -0.01585964858531952, -0.054639749228954315, 0.009183568879961967, 0.01279996708035469, -0.061664339154958725, 0.0002944829757325351, -0.009106624871492386, 0.02378947287797928, 0.03954049199819565, -0.028786348178982735, 0.02603444643318653, 0.02080221101641655, -0.006929543800652027, -0.046384040266275406, -0.020096130669116974, 0.0063004083931446075, -0.06792853772640228, 0.05116366222500801, 0.0416044220328331, 0.014963469468057156, -0.027627652511000633, 0.05188784375786781, 0.028894975781440735, 0.01665625162422657, 0.01810462214052677, 0.05855034664273262, 0.002179343719035387, -0.00371823669411242, -0.003385564312338829, 0.01585964858531952, 0.02545509859919548, -0.061845388263463974, -0.037367939949035645, -0.014990626834332943, 0.020096130669116974, 0.05876760184764862, 0.046456459909677505, 0.09001617878675461, -0.00010007046512328088, 0.0787188932299614, -0.022522149607539177, -0.022956660017371178, -0.011206761002540588, -0.009586396627128124, 0.01528935320675373, -0.01752527430653572, 0.028062162920832634, -0.021616918966174126, 0.018557237461209297, -0.05833309143781662, 0.0029420009814202785, -0.015597131103277206, 0.03219001740217209, 0.04949803650379181, -0.005847792606800795, 0.014438435435295105, -0.02206953428685665, 0.01214820146560669, -0.016176478937268257, 0.06981141865253448, -0.009242408908903599, 0.014284546487033367, -0.001567181316204369, -0.05022222176194191, -0.041314747184515, -0.0025685932487249374, 0.022377312183380127, -0.046709924936294556, -0.10797595977783203, 0.007667307276278734, 0.05159817263484001, -0.021797964349389076, 0.001025739940814674, 0.027048304677009583, 0.012600816786289215, 0.018158935010433197, 0.012718496844172478, 0.046058155596256256, -0.023554112762212753, 0.01744380220770836, -0.008106344379484653, -0.01842145249247551, -0.04917215183377266, 0.0038110227324068546, 0.07035455852746964, -0.025907713919878006, 0.03432636335492134, -0.011351597495377064, -0.01576007343828678, -0.05214130878448486, 0.05923832207918167, 0.0398663766682148, 0.0042410073801875114, 0.005657694302499294, 0.02552751637995243, -0.03309524804353714, 0.02945621870458126, 0.05152575299143791, 0.04978770762681961, 0.03575662896037102, 0.004553312435746193, -0.04352350905537605, -0.0009369141771458089, -0.02916654571890831, 0.05941936746239662, -0.006427140440791845, 0.0074681565165519714, 0.023010974749922752, 0.007744251750409603, 0.002681747078895569, -0.054784584790468216, -0.004996875766664743, 0.025364574044942856, 0.04330625385046005, -0.006807337515056133, 0.0433424636721611, -0.05970904231071472, -0.04852038621902466, 0.017072658985853195, -0.001546813640743494, 0.022721299901604652, 0.0035349272657185793, -0.062424734234809875, 0.03032524138689041, 0.07698085159063339, -0.03651702031493187, 0.007703516632318497, -0.02018665336072445, 0.019100375473499298, 0.03132099658250809, 0.008015820756554604, 0.06662500649690628, -0.05702955648303032, 0.005779900588095188, 0.06256957352161407, -0.033040933310985565, 0.020313385874032974, 0.011731795035302639, -0.004541996866464615, -0.006427140440791845, -0.01440222654491663, 0.006323039066046476, 0.010772249661386013, 0.046927180141210556, -0.09189905971288681, 0.01618553139269352, -0.05156196281313896, -0.004229692276567221, 0.01038300059735775, -0.0828467458486557, 0.053517259657382965, 0.04895489662885666, 0.005644115619361401, 0.0224316269159317, 0.05054810270667076, -0.030904589220881462, 0.06492317467927933, -0.013225425966084003, -0.03057870641350746, -0.013442681171000004, 0.12130096554756165, -0.02465849369764328, 0.05565360561013222, 0.0069883838295936584, 0.002851477824151516, -0.011279178783297539, 0.025762876495718956, -0.01690971665084362, 0.007649202365428209, 0.0108537208288908, -0.054748374968767166, 0.021363453939557076, -0.0107994070276618, -0.027627652511000633, -0.033258188515901566, -0.0032339380122721195, 0.030741646885871887, -0.014474645256996155, 0.03514106944203377, -0.04439253360033035, 0.0017516221851110458, 0.05757269635796547, 0.054277654737234116, 0.053770724684000015, -0.10855530947446823, 0.022884242236614227, -0.001560392091050744, 0.04142337292432785, -0.005322758574038744, -0.038236960768699646, -0.025943921878933907, -0.02375326305627823, 0.011722742579877377, 0.06608186662197113, -0.03677048534154892, 0.05623295530676842, 0.05822446197271347, -0.0418940931558609, 0.009504926390945911, -0.02465849369764328, 0.021870382130146027, 0.007748777978122234, -0.05626916512846947, 0.0015185251832008362, -0.01622174121439457, -0.005653168074786663, -0.009586396627128124, -0.015732916072010994, -0.005612432491034269, 0.045333974063396454, 0.002421493176370859, 0.02491195872426033, 0.013017223216593266, 0.003652607323601842, 0.014393174089491367, -0.029655370861291885, -0.062135059386491776, -0.012573659420013428, -0.016819193959236145, 0.10022718459367752, -0.05572602525353432, 0.03287799283862114, -0.031031321734189987, -0.0025142792146652937, -0.0400836318731308, -0.0391421914100647, 0.010980453342199326, 0.04316141828894615, 0.006929543800652027, 0.037766240537166595, 0.018955538049340248, -0.011143394745886326, -0.03450740873813629, -0.043270044028759, -0.014528959058225155, 0.018177039921283722, -0.003713710466399789, -0.036969635635614395, -0.04917215183377266, -0.023264437913894653, 0.02836994268000126, 0.005435912404209375, -0.019390050321817398, 0.020168548449873924, 0.026559479534626007, -0.0422561876475811, 0.0853813961148262, 0.012818071991205215, -0.0032407273538410664, -0.015850596129894257, -0.04345109313726425, 0.000801129499450326, 0.04960666224360466, 0.04909973219037056, -0.021544499322772026, -0.054603539407253265, 0.019444363191723824, 0.0035575581714510918, -0.02570856176316738, -0.02829752303659916, -0.03381943330168724, 0.0832088440656662, -0.045406389981508255, -0.01436601672321558, 0.01027437299489975, -0.04964287206530571, -0.0035304012708365917, -0.0210918840020895, 0.016348473727703094, 0.007201113272458315, 0.014664743095636368, 0.02855098806321621, -0.047180645167827606, -0.015515660867094994, 0.0224316269159317, 0.01305343210697174, -0.04243723303079605, -0.003333513392135501, -0.009323880076408386, 0.00856348592787981, -0.023662740364670753, 0.06876135617494583, -0.021616918966174126, 0.0202590711414814, -0.032787468284368515, -0.0010642122942954302, -0.062388524413108826, 0.02985452115535736, -0.02610686421394348, 0.06908723711967468, -0.032678842544555664, -0.053879354149103165, 0.01471000537276268, 0.03003556653857231, -0.016339421272277832, -0.027736280113458633, 0.008056556805968285, -0.0435597188770771, -0.006101257633417845, 0.025219738483428955, 0.012102939188480377, -0.06760265678167343, 0.015334614552557468, -0.01799599453806877, 0.0065810298547148705, -0.01906416565179825, -0.014121605083346367, 0.007662781048566103, 0.06264199316501617, 0.018285667523741722, -0.020965151488780975, 0.00498329708352685, 0.017072658985853195, -0.006196306552737951, -0.01748906448483467, -0.02945621870458126, 0.04895489662885666, -0.028677720576524734, -0.04783241078257561, 0.05156196281313896, -0.022250579670071602, -0.0007123036775738001, 0.05565360561013222, -0.008056556805968285, 0.0002958974218927324, -0.0436321385204792, 0.05778995156288147, 0.03620924428105354, -0.05022222176194191, -0.005648641847074032, 0.005164343398064375, -0.023409275338053703, -0.05833309143781662, -0.002532383892685175, 0.04801345616579056, 0.007762356661260128, -0.05069294199347496, 0.03141151741147041, 0.005521909333765507, -0.053987979888916016, -0.01299911830574274, -0.006323039066046476, 0.022051429376006126, -0.0022574199829250574, 0.030162299051880836, 0.042835533618927, 0.0880608782172203, -0.022866137325763702, -0.03132099658250809, -0.022793717682361603, 0.021399661898612976, 0.026016341522336006, -0.06803716719150543, 0.005567171145230532, 0.04366834834218025, 0.017027396708726883, 0.008056556805968285, -0.0050240326672792435, -0.009387246333062649, -0.029220858588814735, -0.02389810048043728, -0.0018896699184551835, -0.0402284674346447, 0.012700391933321953, 0.0448632538318634, 0.013795721344649792, 0.001963219838216901, 0.03441688418388367, 0.025219738483428955, -0.038164541125297546, -0.019498677924275398, -0.018846910446882248, 0.030089881271123886, 0.0813983753323555, -0.02862340584397316, -0.009595449082553387, 0.015298404730856419, 0.030596809461712837, -0.007196587044745684, 0.010355843231081963, 0.011641271412372589, 0.007685411721467972, 0.015569974668323994, -0.04214755818247795, -0.029981253668665886, 0.018367137759923935, 0.0027156933210790157, 0.006092205177992582, 0.022051429376006126, 0.023409275338053703, 0.001391792786307633, 0.05301033332943916, 0.03021661378443241, 0.01676487922668457, -0.023065287619829178, -0.034054793417453766, 0.001615837449207902, 0.015361770987510681, -0.034561723470687866, -0.032208122313022614, -0.0012741127284243703, -0.0422561876475811, -0.0793706625699997, 0.03553937375545502, -0.00495614018291235, -0.03535832464694977, 0.09486822038888931, -0.019589200615882874, 0.025219738483428955, -0.07202018797397614, -0.023590322583913803, 0.016348473727703094, 0.016429943963885307, -0.027337977662682533, -0.002593487035483122, 0.027265559881925583, -0.010500680655241013, 0.08929198980331421, -0.017389489337801933, -0.05905727669596672, -0.0011835896875709295, -0.0012956119608134031, -0.014519906602799892, 0.003550768829882145, -0.019480573013424873, 0.007278057746589184, 0.010989504866302013, -0.0397215411067009, -0.004379055462777615, 0.018937435001134872, 0.013750459998846054, 0.018539132550358772, 0.012238724157214165, -0.023264437913894653, -0.022703194990754128, 0.005707481876015663, -0.023047182708978653, 0.0030777857173234224, 0.03910598158836365, -0.03591956943273544, -0.0021193723659962416, -0.04214755818247795, 0.007866458036005497, 0.0053861248306930065, -0.013297844678163528, 0.05022222176194191, -0.005540014244616032, 0.03954049199819565, 0.02447744831442833, 0.00699291005730629, 0.03320387750864029, -0.04678234085440636, 0.036861009895801544, -0.0014178181299939752, 0.005363494157791138, -0.020059920847415924, 0.0003459680010564625, 0.022775614634156227, -0.053698308765888214, -0.01319826953113079, -0.029220858588814735, 0.07806713134050369, 0.038490425795316696, -0.014465592801570892, -0.02022286131978035, -0.02527405135333538, 0.019498677924275398, -0.01748001202940941, 0.01601353846490383, -0.05630537122488022, -0.03577473387122154, 0.016212688758969307, -0.06423519551753998, -0.09001617878675461, -0.053191378712654114, 0.005408755503594875, -0.0053861248306930065, 0.023735158145427704, -0.0424734428524971, -0.055110469460487366, 0.010618360713124275, 0.02920275367796421, -0.027084514498710632, -0.010473523288965225, 0.05547256022691727, 0.003005367238074541, 0.0029555794317275286, 0.0014065027935430408, 0.007278057746589184, -0.018865015357732773, -0.015769125893712044, -0.0405181422829628, -0.027736280113458633, -0.010373948141932487, 0.052901703864336014, -0.037911076098680496, -0.00743647338822484, 0.021182406693696976, -0.03961291164159775, -0.016954978927969933, -0.06311271339654922, 0.06637154519557953, -0.03932323679327965, -0.061302248388528824, -0.045044299215078354, 0.03568420931696892, 0.018050307407975197, -0.037512775510549545, 0.044428739696741104, -0.06622670590877533, 0.006549346726387739, 0.010944243520498276, 0.04652887582778931, -0.0439942292869091, 0.019951293244957924, 0.027012094855308533, -0.04019226133823395, 0.007554153446108103, 0.015017783269286156, 0.005404229741543531, -0.0014144235756248236, 0.017923574894666672, 0.037838660180568695, 0.062098853290081024, -0.045985739678144455, 0.0044130017049610615, 0.025618039071559906, -0.04323383793234825, 0.0056622205302119255, -0.033258188515901566, -0.06409036368131638, 0.003994332160800695, 0.027917325496673584, 0.009749338962137699, -0.029546741396188736, -0.04710822552442551, 0.046601295471191406, 0.04207514226436615, -0.018539132550358772, 0.0404457226395607, -0.007504365406930447, 0.053770724684000015, 0.03445309400558472, -0.03637218475341797, -0.01420307531952858, -0.029220858588814735, -0.04964287206530571, 0.01978835090994835, 0.011288231238722801, 0.04374076426029205, -0.03219001740217209, -0.008681165985763073, 0.045515019446611404, -0.023572217673063278, 0.03881630674004555, -0.011396858841180801, 0.02505679614841938, -0.02974589355289936, -0.0204763263463974, -0.03211759775876999, 0.015298404730856419, 0.02022286131978035, 0.028243210166692734, 0.045116715133190155, 0.02592581883072853, -0.06684226542711258, -0.046890970319509506, 0.013180164620280266, -0.09334743022918701, 0.06477833539247513, -0.015479451045393944, -0.015488503500819206, 0.02822510525584221, -0.0026907993014901876, 0.07397548109292984, -0.005277497228235006, -0.027337977662682533, 0.05011359229683876, -0.05735544115304947, 0.02228678949177265, -0.010862773284316063, 0.04852038621902466, 0.01758863963186741, 0.03523159399628639, -0.0391421914100647, 0.05721060559153557, -0.045189134776592255, -0.05087398737668991, -0.03396426886320114, 0.0041369060054421425, 0.027989745140075684, 0.03439877927303314, -0.008033925667405128, 0.009441560134291649, 0.008070135489106178, -0.045189134776592255, -0.06586461514234543, 0.055074259638786316, 0.024893853813409805, -0.04909973219037056, -0.01568765379488468, 0.02650516666471958, -0.05246719345450401, -0.035557474941015244, -0.026885362342000008, 0.015017783269286156, 0.016212688758969307, 0.0027202193159610033, -0.0855262354016304, 0.05167058855295181, 0.023354962468147278, -0.002105793682858348, 0.016918769106268883, -0.008042978122830391, 0.053191378712654114, 0.0037997073959559202, 0.0023400222416967154, -0.023318752646446228, -0.019878873601555824, -0.019190898165106773, -0.02815268561244011, -0.019661618396639824, -0.010373948141932487, -0.04946182668209076, 0.02909412607550621, 0.0007994322222657502, 0.014121605083346367, 0.0392146110534668 ]
30,689
networkx.readwrite.gml
generate_gml
Generate a single entry of the graph `G` in GML format. Parameters ---------- G : NetworkX graph The graph to be converted to GML. stringizer : callable, optional A `stringizer` which converts non-int/non-float/non-dict values into strings. If it cannot convert a value into a string, it should raise a `ValueError` to indicate that. Default value: None. Returns ------- lines: generator of strings Lines of GML data. Newlines are not appended. Raises ------ NetworkXError If `stringizer` cannot convert a value into a string, or the value to convert is not a string while `stringizer` is None. See Also -------- literal_stringizer Notes ----- Graph attributes named 'directed', 'multigraph', 'node' or 'edge', node attributes named 'id' or 'label', edge attributes named 'source' or 'target' (or 'key' if `G` is a multigraph) are ignored because these attribute names are used to encode the graph structure. GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a `stringizer`/`destringizer`, the code is capable of writing `int`/`float`/`str`/`dict`/`list` data as required by the GML specification. For writing other data types, and for reading data other than `str` you need to explicitly supply a `stringizer`/`destringizer`. For additional documentation on the GML file format, please see the `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_. See the module docstring :mod:`networkx.readwrite.gml` for more details. Examples -------- >>> G = nx.Graph() >>> G.add_node("1") >>> print("\n".join(nx.generate_gml(G))) graph [ node [ id 0 label "1" ] ] >>> G = nx.MultiGraph([("a", "b"), ("a", "b")]) >>> print("\n".join(nx.generate_gml(G))) graph [ multigraph 1 node [ id 0 label "a" ] node [ id 1 label "b" ] edge [ source 0 target 1 key 0 ] edge [ source 0 target 1 key 1 ] ]
def generate_gml(G, stringizer=None): r"""Generate a single entry of the graph `G` in GML format. Parameters ---------- G : NetworkX graph The graph to be converted to GML. stringizer : callable, optional A `stringizer` which converts non-int/non-float/non-dict values into strings. If it cannot convert a value into a string, it should raise a `ValueError` to indicate that. Default value: None. Returns ------- lines: generator of strings Lines of GML data. Newlines are not appended. Raises ------ NetworkXError If `stringizer` cannot convert a value into a string, or the value to convert is not a string while `stringizer` is None. See Also -------- literal_stringizer Notes ----- Graph attributes named 'directed', 'multigraph', 'node' or 'edge', node attributes named 'id' or 'label', edge attributes named 'source' or 'target' (or 'key' if `G` is a multigraph) are ignored because these attribute names are used to encode the graph structure. GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a `stringizer`/`destringizer`, the code is capable of writing `int`/`float`/`str`/`dict`/`list` data as required by the GML specification. For writing other data types, and for reading data other than `str` you need to explicitly supply a `stringizer`/`destringizer`. For additional documentation on the GML file format, please see the `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_. See the module docstring :mod:`networkx.readwrite.gml` for more details. Examples -------- >>> G = nx.Graph() >>> G.add_node("1") >>> print("\n".join(nx.generate_gml(G))) graph [ node [ id 0 label "1" ] ] >>> G = nx.MultiGraph([("a", "b"), ("a", "b")]) >>> print("\n".join(nx.generate_gml(G))) graph [ multigraph 1 node [ id 0 label "a" ] node [ id 1 label "b" ] edge [ source 0 target 1 key 0 ] edge [ source 0 target 1 key 1 ] ] """ valid_keys = re.compile("^[A-Za-z][0-9A-Za-z_]*$") def stringize(key, value, ignored_keys, indent, in_list=False): if not isinstance(key, str): raise NetworkXError(f"{key!r} is not a string") if not valid_keys.match(key): raise NetworkXError(f"{key!r} is not a valid key") if not isinstance(key, str): key = str(key) if key not in ignored_keys: if isinstance(value, int | bool): if key == "label": yield indent + key + ' "' + str(value) + '"' elif value is True: # python bool is an instance of int yield indent + key + " 1" elif value is False: yield indent + key + " 0" # GML only supports signed 32-bit integers elif value < -(2**31) or value >= 2**31: yield indent + key + ' "' + str(value) + '"' else: yield indent + key + " " + str(value) elif isinstance(value, float): text = repr(value).upper() # GML matches INF to keys, so prepend + to INF. Use repr(float(*)) # instead of string literal to future proof against changes to repr. if text == repr(float("inf")).upper(): text = "+" + text else: # GML requires that a real literal contain a decimal point, but # repr may not output a decimal point when the mantissa is # integral and hence needs fixing. epos = text.rfind("E") if epos != -1 and text.find(".", 0, epos) == -1: text = text[:epos] + "." + text[epos:] if key == "label": yield indent + key + ' "' + text + '"' else: yield indent + key + " " + text elif isinstance(value, dict): yield indent + key + " [" next_indent = indent + " " for key, value in value.items(): yield from stringize(key, value, (), next_indent) yield indent + "]" elif isinstance(value, tuple) and key == "label": yield indent + key + f" \"({','.join(repr(v) for v in value)})\"" elif isinstance(value, list | tuple) and key != "label" and not in_list: if len(value) == 0: yield indent + key + " " + f'"{value!r}"' if len(value) == 1: yield indent + key + " " + f'"{LIST_START_VALUE}"' for val in value: yield from stringize(key, val, (), indent, True) else: if stringizer: try: value = stringizer(value) except ValueError as err: raise NetworkXError( f"{value!r} cannot be converted into a string" ) from err if not isinstance(value, str): raise NetworkXError(f"{value!r} is not a string") yield indent + key + ' "' + escape(value) + '"' multigraph = G.is_multigraph() yield "graph [" # Output graph attributes if G.is_directed(): yield " directed 1" if multigraph: yield " multigraph 1" ignored_keys = {"directed", "multigraph", "node", "edge"} for attr, value in G.graph.items(): yield from stringize(attr, value, ignored_keys, " ") # Output node data node_id = dict(zip(G, range(len(G)))) ignored_keys = {"id", "label"} for node, attrs in G.nodes.items(): yield " node [" yield " id " + str(node_id[node]) yield from stringize("label", node, (), " ") for attr, value in attrs.items(): yield from stringize(attr, value, ignored_keys, " ") yield " ]" # Output edge data ignored_keys = {"source", "target"} kwargs = {"data": True} if multigraph: ignored_keys.add("key") kwargs["keys"] = True for e in G.edges(**kwargs): yield " edge [" yield " source " + str(node_id[e[0]]) yield " target " + str(node_id[e[1]]) if multigraph: yield from stringize("key", e[2], (), " ") for attr, value in e[-1].items(): yield from stringize(attr, value, ignored_keys, " ") yield " ]" yield "]"
(G, stringizer=None)
[ 0.0423707589507103, 0.02536698430776596, -0.018614545464515686, -0.03784779831767082, 0.03230077028274536, -0.007163133006542921, -0.05768908932805061, -0.0013074184535071254, 0.11503682285547256, -0.07390347868204117, -0.011424743570387363, 0.053678158670663834, -0.030657995492219925, 0.08806972950696945, 0.00901925377547741, 0.02244412712752819, -0.021142710000276566, -0.023894889280200005, 0.05888383090496063, 0.010918043553829193, -0.015819696709513664, -0.012182125821709633, 0.0356716550886631, 0.01005932129919529, 0.030807338654994965, -0.061870694160461426, 0.018166515976190567, 0.004640302155166864, -0.04591232165694237, 0.025388319045305252, -0.015563679859042168, -0.12493613362312317, -0.007669832557439804, -0.054915573447942734, -0.006059060804545879, -0.026561729609966278, -0.07966385036706924, 0.022060101851820946, -0.10189463198184967, -0.061870694160461426, 0.038466501981019974, -0.017729153856635094, -0.03688773512840271, -0.03584233298897743, -0.010448680259287357, 0.05453154817223549, -0.021121375262737274, 0.07027657330036163, -0.05713438615202904, -0.045272279530763626, 0.01600104197859764, -0.011840770952403545, -0.04902718961238861, 0.0485578253865242, -0.04497359320521355, -0.005733706522732973, -0.02045999839901924, 0.008965916931629181, 0.07189801335334778, 0.031234033405780792, -0.004528294783085585, 0.031127359718084335, -0.0056163654662668705, -0.00933927483856678, -0.011584754101932049, 0.0013947574188932776, -0.043693508952856064, -0.06310810893774033, -0.03306881710886955, -0.007947184145450592, -0.02690308354794979, -0.002386821899563074, 0.017259789630770683, 0.010667361319065094, -0.0002680174366105348, 0.015371667221188545, -0.035095617175102234, 0.04394952580332756, 0.015350332483649254, -0.014443607069551945, -0.0023148173931986094, 0.02459893375635147, 0.0009973982814699411, -0.09293404966592789, 0.02858852781355381, 0.008261870592832565, 0.040514636784791946, 0.041880059987306595, -0.007168466690927744, 0.014870300889015198, -0.03929855674505234, 0.011808768846094608, 0.026945753023028374, 0.043416157364845276, -0.023638872429728508, -0.018891897052526474, -0.020107975229620934, -0.04441889002919197, 0.03272746503353119, -0.0014827632112428546, 0.014219592325389385, 0.010358007624745369, -0.04179472103714943, -0.0035628986079245806, -0.04437622055411339, -0.06460154056549072, -0.028673866763710976, -0.0006710437010042369, 0.04505893215537071, -0.04424821212887764, -0.08222401887178421, -0.06477221846580505, 0.06980720907449722, -0.02353219874203205, 0.060761287808418274, 0.013942240737378597, -0.01615038514137268, -0.003640237031504512, 0.024065567180514336, -0.016619747504591942, -0.011766099371016026, -0.021932093426585197, -0.060163915157318115, 0.04390685632824898, 0.0018707884009927511, 0.015008976683020592, 0.05589697137475014, 0.007323143072426319, 0.0423707589507103, -0.025900352746248245, 0.04074931889772415, 0.025452323257923126, 0.04254143685102463, 0.0458269827067852, 0.02782047726213932, -0.03887186199426651, -0.0485578253865242, -0.0050216601230204105, 0.07006322592496872, 0.07326343655586243, 0.0388931967318058, -0.0802612230181694, 0.026028361171483994, 0.010085989721119404, -0.002526831114664674, -0.047704439610242844, 0.0010060655185952783, 0.010864706709980965, -0.004098933655768633, -0.05973722040653229, 0.04685105010867119, 0.006347079761326313, 0.03490360453724861, -0.01967061311006546, -0.007376479916274548, 0.027159100398421288, -0.05043528228998184, 0.04345882683992386, 0.007227137219160795, 0.0012107454240322113, 0.00039869261672720313, 0.002702842466533184, 0.03460491821169853, 0.045741643756628036, 0.01565968617796898, 0.018017172813415527, 0.046467024832963943, -0.05790243670344353, 0.011179394088685513, 0.010507350787520409, -0.0012094120029360056, -0.06810043007135391, -0.08824040740728378, -0.010496683418750763, 0.04476024582982063, 0.007749837823212147, 0.03027397021651268, 0.10368674993515015, -0.009381944313645363, 0.059865228831768036, -0.015104983001947403, -0.026540394872426987, -0.03699440881609917, -0.007387147285044193, -0.02334018610417843, -0.017771823331713676, 0.05308078974485397, -0.005520359147340059, 0.04318147525191307, -0.024854950606822968, 0.004842981696128845, -0.04147469997406006, -0.01888122968375683, 0.05751841142773628, 0.025601666420698166, -0.0051976717077195644, -0.006427085027098656, -0.0048003122210502625, 0.01376089546829462, 0.08265071362257004, -0.00466963741928339, -0.02856719307601452, 0.028823209926486015, -0.03622635826468468, -0.05342214182019234, -0.01428359653800726, -0.0388931967318058, -0.010806036181747913, -0.0470643974840641, 0.002850852208212018, -0.001160075538791716, -0.01413425337523222, 0.012416807934641838, 0.045869652181863785, -0.016097048297524452, -0.03151138499379158, -0.010459347628057003, 0.05205672234296799, -0.08137062937021255, -0.05504358187317848, 0.010576688684523106, -0.01699310541152954, 0.019787954166531563, -0.033900871872901917, 0.04949655383825302, -0.050008587539196014, 0.059993237257003784, -0.038189150393009186, -0.00775517150759697, 0.002141472650691867, 0.10641759634017944, 0.011094055138528347, 0.05640900507569313, 0.03983192518353462, 0.025430988520383835, -0.06054794043302536, 0.02641238644719124, 0.00033435510704293847, 0.017643814906477928, 0.030999351292848587, -0.040493302047252655, -0.052654094994068146, -0.06822843849658966, -0.03131937235593796, 0.03306881710886955, 0.02272147871553898, 0.00953662022948265, 0.017110446467995644, 0.016811760142445564, 0.011243398301303387, -0.02487628534436226, 0.019243918359279633, -0.01236347109079361, -0.008741902187466621, -0.027777807787060738, -0.004437622148543596, -0.05086197704076767, -0.0460829995572567, 0.03163939341902733, -0.011584754101932049, 0.013451541773974895, -0.008192533627152443, -0.09856641292572021, 0.07078860700130463, 0.07369013130664825, 0.012331468984484673, 0.022977495566010475, 0.0107793677598238, 0.014827631413936615, -0.001713444828055799, 0.041709382086992264, 0.05849980562925339, -0.023894889280200005, -0.025601666420698166, 0.006283075548708439, -0.0035255628172308207, 0.04333081841468811, 0.01949993520975113, 0.005467022303491831, -0.013782230205833912, -0.02348952926695347, -0.0012380805565044284, -0.02319084294140339, -0.013451541773974895, -0.023788215592503548, 0.030145961791276932, -0.03714375197887421, -0.025623001158237457, 0.016513073816895485, -0.035885002464056015, 0.061572007834911346, -0.016246391460299492, -0.03661038354039192, 0.03560765087604523, 0.04744842275977135, -0.030060622841119766, 0.012448810040950775, -0.03974658623337746, -0.005008325912058353, 0.0021014700178056955, 0.08781371265649796, -0.017921166494488716, 0.08717367053031921, 0.007856511510908604, -0.011478080414235592, 0.039255887269973755, 0.019681280478835106, -0.018102511763572693, -0.024790946394205093, 0.023852219805121422, -0.046936389058828354, -0.0011480747489258647, 0.04207207262516022, 0.012800833210349083, -0.01605437882244587, 0.010944711975753307, 0.005947053898125887, -0.010822037234902382, 0.07270873337984085, -0.008635228499770164, -0.02272147871553898, 0.03202341869473457, 0.007808508351445198, 0.023596202954649925, -0.031276702880859375, 0.010944711975753307, 0.03577832877635956, 0.050307273864746094, 0.03200208395719528, -0.05320879817008972, -0.0005950386985205114, -0.024684272706508636, -0.021612072363495827, 0.06315077841281891, -0.04166671261191368, 0.054915573447942734, 0.027137765660881996, -0.0075151557102799416, -0.009456615895032883, -0.08013321459293365, 0.033260829746723175, 0.01873188652098179, -0.009600624442100525, 0.0012107454240322113, 0.023745546117424965, 0.018795890733599663, 0.01138207409530878, -0.0522700697183609, 0.018411865457892418, 0.045272279530763626, -0.019606608897447586, 0.04813113436102867, 0.016214389353990555, 0.021836087107658386, 0.016011709347367287, -0.028396515175700188, -0.008405880071222782, -0.046936389058828354, -0.02021464891731739, 0.053720828145742416, 0.03313282132148743, 0.002334818709641695, -0.0023361521307379007, 0.06430285423994064, 0.0018587876111268997, -0.030786003917455673, -0.00868323165923357, 0.05470222607254982, 0.08115728199481964, 0.009995317086577415, 0.015190321952104568, -0.026049695909023285, -0.04578431323170662, -0.007883179932832718, -0.020790686830878258, 0.008080526255071163, 0.016182387247681618, 0.015585014596581459, -0.03876518830657005, -0.006677767727524042, -0.014752959832549095, 0.04702172800898552, 0.025772344321012497, 0.05197138339281082, 0.023126838728785515, -0.02227344922721386, 0.09771302342414856, 0.01957460679113865, -0.039703916758298874, -0.05056329071521759, -0.022977495566010475, 0.011019383557140827, 0.039703916758298874, 0.013707558624446392, -0.032492782920598984, -0.06426018476486206, 0.06400416791439056, -0.02905789203941822, -0.011008716188371181, -0.022828152403235435, -0.012320801615715027, -0.0014374268939718604, -0.07518356293439865, 0.0057177054695785046, 0.006789775099605322, -0.04284012317657471, 0.029249902814626694, -0.015819696709513664, 0.017899831756949425, 0.012267464771866798, 0.04377884790301323, -0.022188110277056694, -0.06622297316789627, -0.015403669327497482, 0.025430988520383835, -0.018635880202054977, -0.016406401991844177, 0.04983790963888168, -0.009584623388946056, 0.040941331535577774, 0.010107324458658695, 0.023233512416481972, 0.05069129914045334, 0.01553167775273323, -0.0421147421002388, 0.01283283531665802, -0.04328814893960953, -0.010902042500674725, -0.06878314167261124, 0.05730506405234337, -0.0250256285071373, -0.04851515591144562, 0.03027397021651268, -0.005835046526044607, -0.0058563812635838985, -0.03906387463212013, -0.019286587834358215, -0.019318589940667152, 0.01481696404516697, -0.01888122968375683, 0.003426889656111598, -0.038807857781648636, 0.024364251643419266, -0.009936646558344364, 0.026561729609966278, -0.0015000976854935288, -0.02041732892394066, 0.039255887269973755, 0.06720437109470367, 0.03658904880285263, -0.008656563237309456, -0.012342136353254318, 0.06532692164182663, 0.013088852167129517, -0.02794848568737507, -0.022870821878314018, 0.04284012317657471, -0.00414426950737834, -0.037719789892435074, 0.054787565022706985, -0.0036669052205979824, -0.01766514964401722, 0.029420580714941025, 0.04902718961238861, -0.018326526507735252, 0.018870562314987183, 0.014518278650939465, 0.05700637772679329, -0.06822843849658966, 0.006485755555331707, -0.010886041447520256, 0.02060934156179428, -0.02410823479294777, -0.02491895481944084, -0.007243138272315264, -0.01884922757744789, -0.017803825438022614, 0.02645505592226982, -0.03422089293599129, -0.05606764927506447, 0.026561729609966278, -0.039575908333063126, 0.018198518082499504, 0.008864576928317547, 0.010742032900452614, 0.039085209369659424, 0.06532692164182663, -0.03929855674505234, -0.007099128793925047, 0.004458956886082888, -0.05529959872364998, 0.0030802004039287567, 0.017089111730456352, -0.05483023449778557, 0.005293678026646376, 0.03688773512840271, -0.017259789630770683, -0.03242877870798111, -0.01996929943561554, -0.029313907027244568, -0.02950591966509819, 0.0022548134438693523, -0.016715753823518753, 0.0001936792687047273, 0.049069859087467194, 0.018913231790065765, 0.006368414498865604, 0.044034864753484726, 0.01315285637974739, -0.03720775619149208, -0.0037735789082944393, -0.027095096185803413, 0.056921038776636124, 0.03025263547897339, -0.03801847621798515, -0.019905295222997665, 0.027607129886746407, 0.022678809240460396, -0.05291011184453964, -0.03289814293384552, 0.02950591966509819, -0.016779758036136627, -0.004960322752594948, 0.02641238644719124, -0.030209966003894806, 0.030167296528816223, 0.01823052018880844, -0.021537402644753456, -0.016257058829069138, -0.01788916438817978, 0.011424743570387363, 0.05043528228998184, 0.024620268493890762, 0.05960921198129654, -0.03029530495405197, -0.019137244671583176, 0.06899648904800415, 0.02229478396475315, -0.02257213555276394, 0.01929725520312786, 0.03857317566871643, -0.004906985908746719, -0.013408872298896313, 0.04181605577468872, 0.029292572289705276, 0.000243682530708611, 0.06856979429721832, 0.010656693950295448, 0.024556264281272888, -0.07300741970539093, -0.06771640479564667, 0.0017094445647671819, -0.02814049832522869, -0.016022376716136932, 0.034668922424316406, -0.01788916438817978, 0.001393423997797072, 0.06810043007135391, 0.013718225993216038, 0.0003260212251916528, -0.01236347109079361, 0.03044464811682701, -0.06306543946266174, -0.02718043513596058, 0.1045401394367218, 0.02735111303627491, -0.03853050619363785, -0.014400937594473362, -0.002794848522171378, 0.008805906400084496, 0.008480551652610302, -0.03870118409395218, 0.062468066811561584, -0.011008716188371181, -0.03012462705373764, 0.02673240564763546, -0.06323611736297607, 0.01657707802951336, 0.006763106677681208, -0.04241342842578888, -0.015264993533492088, 0.04761910066008568, 0.06310810893774033, 0.04975257068872452, 0.06251073628664017, 0.02006530575454235, -0.012779498472809792, 0.0869603231549263, -0.016715753823518753, 0.016961103305220604, 0.006944451946765184, -0.005600364413112402, 0.018326526507735252, -0.016235724091529846, 0.011008716188371181, -0.03921321779489517, 0.028844544664025307, -0.03027397021651268, -0.026241708546876907, -0.042050737887620926, -0.03424222767353058, 0.0646442100405693, 0.028673866763710976, 0.038807857781648636, 0.010592689737677574, 0.021537402644753456, 0.03545830771327019, -0.023169508203864098, 0.016619747504591942, -0.040194615721702576, -0.02383088506758213, 0.013419539667665958, -0.03409288451075554, -0.058030445128679276, -0.06127332150936127, -0.02796982042491436, -0.013899571262300014, 0.01830519177019596, -0.029548589140176773, -0.10718563944101334, 0.06656432896852493, -0.039234552532434464, -0.0634067952632904, -0.002220144495368004, 0.01483829878270626, 0.005219006445258856, -0.015467673540115356, -0.016065046191215515, -0.020097307860851288, -0.046467024832963943, -0.01964927837252617, -0.030145961791276932, 0.0032988814637064934, 0.0072858077473938465, 0.006352413445711136, -0.012736828997731209, 0.02828984148800373, 0.0408773273229599, -0.03872251883149147, -0.02767113409936428, -0.056622352451086044, 0.02782047726213932, -0.017398465424776077, -0.02380955033004284, -0.020054638385772705, 0.03347417712211609, 0.03671705722808838, -0.02519630640745163, 0.03483960032463074, -0.021334722638130188, 0.009755301289260387, 0.056622352451086044, 0.03853050619363785, -0.03897853568196297, 0.020940029993653297, 0.0406213104724884, -0.021249383687973022, -0.02598569169640541, -0.05133134126663208, -0.022230779752135277, 0.007765838876366615, -0.0018521205056458712, 0.04209340736269951, 0.0014080916298553348, -0.06827110797166824, 0.032492782920598984, -0.01268349215388298, 0.02536698430776596, 0.03673839196562767, -0.01865721493959427, -0.05640900507569313, 0.0005760375061072409, 0.05145934969186783, -0.030039288103580475, -0.04070664942264557, -0.051117993891239166, 0.05086197704076767, 0.05346481129527092, -0.018422532826662064, -0.0009527286747470498, 0.011350071988999844, 0.04166671261191368, -0.014144920744001865, -0.029143230989575386, -0.021846754476428032, -0.05619565770030022, -0.021473398432135582, -0.06332145631313324, -0.0033682191278785467, 0.013878236524760723, -0.016758423298597336, -0.012267464771866798, 0.028652532026171684, -0.02858852781355381, -0.001360755180940032, -0.04006660729646683, 0.01867854967713356, 0.01830519177019596, 0.003970925230532885, -0.04497359320521355, -0.012427475303411484, -0.024662937968969345, 0.002349486341699958, 0.040194615721702576, 0.026945753023028374, -0.03823181986808777, -0.03149005025625229, 0.03428489714860916, -0.007349811494350433, 0.020182646811008453, -0.008864576928317547, 0.039853259921073914, -0.029399245977401733, -0.0035388970281928778, 0.0013454209547489882, -0.06532692164182663, -0.03761311620473862, 0.06370548158884048, -0.04936854541301727, 0.0015894367825239897, -0.023617537692189217, 0.029420580714941025, 0.03409288451075554, 0.021014701575040817, -0.032194096595048904, 0.02856719307601452, -0.0002988527703564614, -0.04320280998945236, -0.014518278650939465, -0.02474827691912651, 0.023297516629099846, 0.06536959111690521, -0.021868089213967323, 0.03959724307060242, 0.0010927377734333277, -0.045741643756628036, -0.06703369319438934, 0.007168466690927744, 0.02903655730187893, 0.022636139765381813, -0.02767113409936428, 0.02658306434750557, -0.022486796602606773, -0.028503188863396645, -0.02321217767894268, -0.03597034141421318, 0.03584233298897743, 0.0431174710392952, -0.04685105010867119, 0.046509694308042526, 0.042178746312856674, 0.007893847301602364, -0.031874075531959534, -0.004808312747627497, 0.045869652181863785, 0.024470925331115723, -0.010283336043357849, -0.007947184145450592, -0.020299987867474556, -0.03106335550546646, -0.03091401234269142, -0.02210277132689953, 0.036909069865942, -0.03488226979970932, -0.014720957726240158, -0.009584623388946056, 0.010976714082062244, 0.03897853568196297 ]
30,690
networkx.readwrite.graphml
generate_graphml
Generate GraphML lines for G Parameters ---------- G : graph A networkx graph encoding : string (optional) Encoding for text data. prettyprint : bool (optional) If True use line breaks and indenting in output XML. named_key_ids : bool (optional) If True use attr.name as value for key elements' id attribute. edge_id_from_attribute : dict key (optional) If provided, the graphml edge id is set by looking up the corresponding edge data attribute keyed by this parameter. If `None` or the key does not exist in edge data, the edge id is set by the edge key if `G` is a MultiGraph, else the edge id is left unset. Examples -------- >>> G = nx.path_graph(4) >>> linefeed = chr(10) # linefeed = >>> s = linefeed.join(nx.generate_graphml(G)) >>> for line in nx.generate_graphml(G): # doctest: +SKIP ... print(line) Notes ----- This implementation does not support mixed graphs (directed and unidirected edges together) hyperedges, nested graphs, or ports.
def generate_graphml( G, encoding="utf-8", prettyprint=True, named_key_ids=False, edge_id_from_attribute=None, ): """Generate GraphML lines for G Parameters ---------- G : graph A networkx graph encoding : string (optional) Encoding for text data. prettyprint : bool (optional) If True use line breaks and indenting in output XML. named_key_ids : bool (optional) If True use attr.name as value for key elements' id attribute. edge_id_from_attribute : dict key (optional) If provided, the graphml edge id is set by looking up the corresponding edge data attribute keyed by this parameter. If `None` or the key does not exist in edge data, the edge id is set by the edge key if `G` is a MultiGraph, else the edge id is left unset. Examples -------- >>> G = nx.path_graph(4) >>> linefeed = chr(10) # linefeed = \n >>> s = linefeed.join(nx.generate_graphml(G)) >>> for line in nx.generate_graphml(G): # doctest: +SKIP ... print(line) Notes ----- This implementation does not support mixed graphs (directed and unidirected edges together) hyperedges, nested graphs, or ports. """ writer = GraphMLWriter( encoding=encoding, prettyprint=prettyprint, named_key_ids=named_key_ids, edge_id_from_attribute=edge_id_from_attribute, ) writer.add_graph_element(G) yield from str(writer).splitlines()
(G, encoding='utf-8', prettyprint=True, named_key_ids=False, edge_id_from_attribute=None)
[ 0.018342329189181328, 0.03839048743247986, -0.017545651644468307, 0.009147732518613338, -0.008247955702245235, -0.0328231155872345, -0.06647102534770966, 0.021650884300470352, 0.08967777341604233, -0.020601144060492516, -0.0027087037451565266, 0.014162114821374416, -0.02275685966014862, 0.09995023161172867, -0.018539154902100563, 0.030892344191670418, -0.028080541640520096, -0.060210078954696655, 0.030329983681440353, 0.027555670589208603, 0.018136130645871162, 0.012212598696351051, 0.019720112904906273, 0.0328231155872345, 0.04911283031105995, -0.0015418054535984993, -0.0018663343507796526, 0.04663844034075737, -0.014602631330490112, 0.002678242512047291, 0.008716589771211147, -0.08382922410964966, -0.01876409910619259, -0.012943667359650135, -0.028455447405576706, 0.028867846354842186, -0.053949128836393356, -0.0036014511715620756, -0.07235706597566605, -0.1060987040400505, 0.08105491101741791, 0.060959894210100174, 0.035166285932064056, -0.006392166018486023, -0.019007788971066475, 0.0007949201972223818, -0.03259817138314247, 0.03267315402626991, -0.03638473153114319, -0.026599658653140068, 0.027143273502588272, 0.011922045610845089, -0.03490385040640831, 0.03599108010530472, -0.032748132944107056, -0.0262997318059206, -0.008121424354612827, -0.03929026424884796, 0.05529879406094551, -0.005145599599927664, -0.04551371932029724, 0.00028542731888592243, 0.05754823982715607, 0.010694224387407303, 0.009555444121360779, -0.016317831352353096, -0.04851297661662102, -0.05443650856614113, -0.01334669254720211, 0.009461717680096626, -0.02502504736185074, 0.010366180911660194, 0.05848550423979759, 0.0009407824836671352, 0.004449678584933281, 0.05732329189777374, -0.030761126428842545, 0.033872853964567184, 0.01335606537759304, -0.0029781681951135397, -0.032748132944107056, 0.044538963586091995, -0.018108012154698372, -0.048437993973493576, 0.015942923724651337, -0.02151966653764248, 0.030292492359876633, 0.023038040846586227, -0.00962573941797018, -0.061334799975156784, -0.023712873458862305, 0.05181216076016426, -0.011790827848017216, 0.034716397523880005, -0.018895316869020462, -0.04787563532590866, 0.005525193177163601, 0.0015277464408427477, 0.01837982051074505, 0.017920559272170067, -0.006767072714865208, -0.010234963148832321, -0.027949323877692223, 0.005829805042594671, -0.03807181492447853, -0.02663714811205864, -0.04975017160177231, -0.0027789988089352846, 0.02744319848716259, -0.009278950281441212, -0.03177337720990181, -0.04363918676972389, 0.06365922093391418, -0.030723635107278824, 0.06275944411754608, 0.054773926734924316, 0.010853560641407967, -0.028080541640520096, 0.013252965174615383, -0.0524120107293129, -0.031061051413416862, -0.03477263078093529, -0.046076081693172455, -0.006157848984003067, 0.01565237157046795, -0.01919524371623993, 0.0463385172188282, -0.0018487605266273022, 0.026355968788266182, -0.06339678913354874, -0.001548834959976375, 0.02980511263012886, 0.05638602748513222, 0.01651465706527233, -0.012681231833994389, -0.042177047580480576, -0.03424776345491409, -0.00899777002632618, 0.06665848195552826, 0.06069745868444443, 0.008707216940820217, -0.06230955943465233, 0.020113766193389893, 0.029936330392956734, -0.04307682439684868, -0.045701172202825546, 0.0005972152575850487, -0.010722342878580093, -0.0024275234900414944, -0.04746323823928833, 0.03929026424884796, -0.04832552373409271, 0.030404964461922646, 0.004620729945600033, 0.0021006513852626085, 0.03642222285270691, -0.0742316022515297, 0.08120487630367279, 0.02551242709159851, -0.017526905983686447, -0.011247212998569012, 0.005126854404807091, 0.05927281081676483, 0.017170744016766548, 0.0022681879345327616, 0.03263566270470619, 0.02116350457072258, -0.03799683228135109, -0.012671859934926033, 0.0007006076048128307, 0.012334443628787994, -0.061372291296720505, -0.018529782071709633, -0.026112278923392296, -0.0032570052426308393, 0.010019391775131226, 0.043676674365997314, 0.08285446465015411, 0.010094373486936092, 0.07318186014890671, -0.03286060690879822, -0.005272130947560072, -0.0036365988198667765, -0.02116350457072258, -0.019888820126652718, -0.016374066472053528, -0.00422004796564579, -0.006443715654313564, 0.028118031099438667, -0.04416405409574509, 0.008491645567119122, -0.001610928913578391, 0.028886592015624046, 0.05166219547390938, -0.02588733471930027, -0.004358294885605574, -0.0042317635379731655, 0.009700721129775047, -0.018192365765571594, 0.0969509705901146, 0.10040012001991272, 0.04303933307528496, 0.013196729123592377, -0.007001389749348164, -0.015952296555042267, 0.022906823083758354, -0.05556122958660126, -0.024012798443436623, -0.042102064937353134, -0.005501761566847563, 0.02356291003525257, -0.04457645118236542, 0.033497948199510574, 0.039477717131376266, -0.02033871039748192, 0.030423710122704506, -0.03456643223762512, 0.0908774808049202, -0.044538963586091995, -0.0502750389277935, 0.00842135027050972, -0.015877315774559975, -0.05398662015795708, -0.002631379058584571, 0.04232700914144516, -0.0493752621114254, 0.060959894210100174, -0.01688019186258316, -0.007788694929331541, -0.011772082187235355, 0.08427911251783371, -0.0006367562455125153, 0.06272195279598236, 0.025306228548288345, 0.004234106745570898, -0.023300476372241974, 0.009869429282844067, 0.011865809559822083, 0.00040888303192332387, 0.018989043310284615, -0.03570989891886711, -0.04671342298388481, -0.008604117669165134, 0.018557900562882423, 0.056685950607061386, 0.04716331139206886, -0.018257975578308105, -0.0011586971813812852, 0.04427652806043625, -0.010637988336384296, -0.06714586168527603, 0.03518503159284592, 0.013121748343110085, 0.03426650911569595, -0.0008505704463459551, 0.05338677018880844, -0.06148476153612137, -0.056685950607061386, 0.007896480150520802, 0.028886592015624046, 0.02896157279610634, 0.02388158068060875, -0.07333182543516159, 0.05773569270968437, 0.08637859672307968, -0.013543518260121346, -0.023262985050678253, 0.029655151069164276, -0.0035030380822718143, -0.022981803864240646, -0.05732329189777374, 0.041389741003513336, -0.01728321611881256, -0.01760188862681389, 0.061747197061777115, -0.0018335300264880061, -0.008702530525624752, 0.01844542846083641, -0.02592482604086399, -0.013487282209098339, -0.036272261291742325, -0.0032851232681423426, 0.006284379865974188, 0.02545619197189808, -0.047575708478689194, 0.029317734763026237, -0.022194499149918556, -0.014818202704191208, 0.004562150686979294, -0.051137328147888184, 0.09830063581466675, -0.024031544104218483, -0.024950066581368446, 0.029936330392956734, 0.0720946341753006, -0.02159464918076992, 0.028155522421002388, -0.01349665503948927, -0.017011409625411034, -0.020263727754354477, 0.07408163696527481, -0.03214828297495842, 0.10579878091812134, 0.012409424409270287, -0.00862754974514246, 0.03424776345491409, -0.009541385807096958, -0.026355968788266182, -0.00962573941797018, 0.02073236182332039, -0.06129730865359306, 0.041389741003513336, 0.01760188862681389, -0.025774862617254257, -0.04142723232507706, 0.02980511263012886, 0.014752593822777271, -0.023731619119644165, 0.08090495318174362, -0.030873598530888557, -0.0026852719020098448, 0.03269189968705177, 0.0031281309202313423, -0.0008365114335902035, -0.06384667754173279, 0.004597298335283995, 0.04873792082071304, 0.05597362667322159, 0.03377912938594818, -0.06287191808223724, 0.01763937808573246, -0.013609127141535282, -0.02935522422194481, 0.03974015265703201, -0.04577615484595299, 0.03576613590121269, 0.009072751738131046, -0.04191461205482483, -0.0014328480465337634, -0.047050841152668, 0.06647102534770966, -0.012025144882500172, -0.02748068980872631, 0.008247955702245235, 0.025231247767806053, 0.06632106751203537, -0.016224104911088943, 0.002619663253426552, -0.04498885199427605, 0.040152549743652344, 0.011087876744568348, 0.058635469526052475, -0.014621376059949398, 0.0038357682060450315, -0.008880611509084702, -0.0017995539819821715, -0.015830451622605324, -0.017864322289824486, -0.04086487367749214, 0.05481141805648804, -0.010862932540476322, 0.015802333131432533, 0.02268187887966633, 0.002947706962004304, 0.023319220170378685, -0.021444685757160187, -0.004262224771082401, 0.033929090946912766, 0.06268446147441864, 0.027255745604634285, -0.003927151672542095, -0.03557868301868439, -0.042514462023973465, 0.015033774077892303, 0.009030574932694435, 0.05676093325018883, 0.013271710835397243, 0.002436896087601781, -0.03181086480617523, 0.03526001051068306, -0.007249766029417515, -0.00004309234645916149, 0.06463398039340973, 0.02502504736185074, 0.033160533756017685, -0.03456643223762512, 0.10384926199913025, 0.0006970928516238928, -0.05053747445344925, -0.03188584744930267, -0.05304935202002525, 0.019120261073112488, 0.03876539319753647, 0.002619663253426552, -0.029486441984772682, -0.06868297606706619, 0.06613361090421677, 0.008622863329946995, -0.0043044020421803, -0.04457645118236542, -0.04281438887119293, -0.005956336390227079, -0.046488478779792786, -0.004009162541478872, -0.00964448507875204, 0.015239973552525043, -0.041764650493860245, 0.020882325246930122, 0.003650657832622528, 0.023075532168149948, 0.05676093325018883, 0.0022834185510873795, -0.051962122321128845, -0.03248569741845131, 0.04746323823928833, 0.019120261073112488, 0.04082738235592842, -0.0168614462018013, 0.010497398674488068, 0.042177047580480576, -0.020976051688194275, 0.034716397523880005, 0.03959018737077713, -0.02986134961247444, -0.019888820126652718, -0.004517630208283663, -0.046113573014736176, 0.03451019898056984, -0.0502750389277935, 0.05567370355129242, -0.009663229808211327, -0.037865616381168365, 0.026056041941046715, 0.05121230706572533, -0.0328231155872345, -0.03182961046695709, 0.004934714641422033, -0.034303996711969376, 0.0009817879181355238, -0.01331857405602932, 0.040602438151836395, -0.07663100957870483, -0.007582495920360088, 0.0013320917496457696, -0.009011829271912575, -0.02393781766295433, -0.022419443354010582, 0.03572864457964897, 0.05717333033680916, 0.035522446036338806, -0.018932808190584183, 0.033497948199510574, 0.03411654382944107, -0.011322193779051304, -0.03216702863574028, -0.023075532168149948, 0.04348922148346901, -0.04783814400434494, -0.04750072956085205, 0.07273197174072266, 0.004527003038674593, 0.0050940499641001225, 0.020601144060492516, 0.01798616722226143, 0.022925568744540215, -0.008716589771211147, 0.01960764080286026, 0.038652919232845306, -0.07730583846569061, -0.011153485625982285, 0.06103487312793732, -0.012128244154155254, -0.02150092087686062, -0.006912349257618189, 0.04813807085156441, -0.02476261369884014, -0.05436152592301369, 0.009738211520016193, -0.04116479679942131, -0.006307811941951513, 0.018698491156101227, -0.012146989814937115, 0.03053618222475052, 0.013759090565145016, 0.023000549525022507, 0.06200963258743286, 0.05053747445344925, -0.02592482604086399, -0.027143273502588272, -0.03141721338033676, -0.017751850187778473, 0.023281730711460114, -0.012878058478236198, -0.03966517001390457, 0.038221776485443115, 0.02390032634139061, -0.005675156135112047, -0.025681136175990105, -0.03520377725362778, -0.05244950205087662, -0.042177047580480576, -0.03094857931137085, -0.0075871823355555534, 0.002619663253426552, 0.04037749394774437, 0.060547493398189545, -0.00332964351400733, 0.04986264184117317, 0.04510132223367691, -0.006926408503204584, 0.006003199610859156, -0.02275685966014862, 0.03299182280898094, 0.04071490839123726, -0.00978507474064827, -0.014855693094432354, -0.019532660022377968, 0.02776186913251877, -0.002436896087601781, -0.028736628592014313, 0.030367475003004074, -0.012962413020431995, -0.008505704812705517, -0.048025596886873245, -0.05184965208172798, 0.04731327295303345, 0.012840568087995052, -0.006528069730848074, 0.0013695824891328812, 0.010862932540476322, 0.025699879974126816, 0.07805565744638443, 0.022082027047872543, 0.06954526156187057, -0.038259267807006836, -0.010450535453855991, 0.020582398399710655, 0.04551371932029724, -0.012156362645328045, 0.007338806055486202, -0.002249442506581545, 0.011322193779051304, -0.04945024475455284, 0.05087489262223244, 0.018192365765571594, 0.011059759184718132, 0.07003264129161835, 0.03490385040640831, -0.002811803249642253, -0.059797681868076324, -0.025587407872080803, 0.027705634012818336, -0.04468892514705658, -0.0052112084813416, 0.04090236499905586, -0.019326459616422653, 0.008702530525624752, 0.05754823982715607, 0.000616253528278321, -0.027143273502588272, -0.01567111536860466, 0.054736435413360596, -0.04663844034075737, -0.062159594148397446, 0.05458647385239601, 0.007315374445170164, -0.02350667491555214, -0.04577615484595299, -0.022963058203458786, 0.009143047034740448, 0.02592482604086399, -0.020188746973872185, 0.03966517001390457, -0.039440225809812546, -0.026056041941046715, 0.02076985314488411, -0.020544908940792084, 0.02551242709159851, 0.01507126446813345, -0.010741087608039379, -0.011893927119672298, 0.02901780791580677, -0.0019905222579836845, 0.0542115643620491, 0.04303933307528496, -0.0032265440095216036, -0.010375553742051125, 0.05263695493340492, -0.016280340030789375, -0.0067436411045491695, 0.02358165569603443, 0.009841310791671276, 0.038465466350317, -0.020263727754354477, 0.005914159119129181, 0.001376611995510757, 0.045663684606552124, -0.011640865355730057, -0.040227532386779785, -0.01884845457971096, -0.04952522739768028, 0.04990013316273689, 0.00026682839961722493, 0.0500875860452652, -0.006598364561796188, 0.033929090946912766, 0.008468213491141796, -0.0398901142179966, 0.01688019186258316, -0.005014382302761078, -0.06823308765888214, 0.026468440890312195, -0.015849197283387184, -0.06692091375589371, 0.011144112795591354, -0.029505187645554543, -0.016195986419916153, 0.01802365854382515, -0.0052158948965370655, -0.07569374144077301, 0.060247570276260376, -0.030723635107278824, -0.016008533537387848, -0.03175463154911995, 0.03724702075123787, 0.036647167056798935, -0.03959018737077713, -0.03248569741845131, -0.012990530580282211, -0.011668982915580273, -0.0016085857059806585, -0.038952846080064774, -0.01606476865708828, 0.0016097573097795248, 0.06403413414955139, -0.060247570276260376, 0.002600917825475335, 0.010816069319844246, -0.005309621803462505, -0.038952846080064774, -0.094101682305336, 0.016983291134238243, -0.07336931675672531, -0.06200963258743286, -0.01567111536860466, -0.0034538316540420055, 0.0195888951420784, -0.038990337401628494, 0.03404156491160393, -0.05289939045906067, 0.0035499015357345343, -0.00998190138489008, 0.043414242565631866, -0.03700333088636398, 0.07175721973180771, 0.04656346142292023, -0.02161339297890663, -0.02268187887966633, 0.02978636883199215, -0.03801557794213295, -0.014265215024352074, -0.0026665267068892717, 0.023712873458862305, 0.013056139461696148, -0.05803561583161354, 0.02159464918076992, -0.00003304234996903688, -0.009935038164258003, 0.03214828297495842, -0.06695840507745743, -0.0801551342010498, 0.013252965174615383, 0.042926862835884094, -0.02974887751042843, -0.053161825984716415, -0.043414242565631866, 0.04622604325413704, 0.0023654294200241566, 0.00980382040143013, -0.022606898099184036, -0.050762418657541275, 0.0500875860452652, -0.0038732588291168213, -0.04671342298388481, -0.04558870196342468, -0.034641414880752563, -0.007137293461710215, -0.021369703114032745, 0.0177143607288599, 0.0431143157184124, -0.02003878355026245, -0.0020326992962509394, 0.03929026424884796, -0.01016935519874096, 0.047200802713632584, -0.03224201127886772, 0.00004312895907787606, -0.013543518260121346, 0.012503151781857014, -0.042889371514320374, 0.013805953785777092, -0.0033671343699097633, -0.012334443628787994, 0.012072008103132248, 0.007212275173515081, -0.0620846152305603, -0.04858795925974846, 0.06849552690982819, -0.022175753489136696, 0.05053747445344925, -0.043301768600940704, -0.019073398783802986, 0.03850295767188072, -0.026580912992358208, 0.07873048633337021, -0.088028185069561, -0.033085551112890244, 0.02510003000497818, -0.04116479679942131, -0.01838919334113598, 0.0045879255048930645, 0.0376594178378582, 0.0009284808184020221, 0.009860056452453136, -0.04030251130461693, 0.00636404799297452, -0.020207492634654045, -0.05323680490255356, 0.012418797239661217, -0.010844187811017036, 0.00042264917283318937, 0.0493752621114254, -0.029261497780680656, 0.04442648962140083, -0.001361381378956139, -0.02043243683874607, -0.07700591534376144, 0.03340421989560127, 0.012953040190041065, -0.006865486036986113, -0.035091303288936615, 0.01016935519874096, -0.014358941465616226, -0.012587505392730236, -0.008135483600199223, -0.01838919334113598, 0.00569390133023262, 0.04108981788158417, -0.03602857142686844, 0.033966582268476486, 0.03364790976047516, -0.027255745604634285, -0.022494425997138023, -0.0026220064610242844, 0.04630102589726448, 0.027611907571554184, 0.016205359250307083, -0.02002003788948059, 0.011922045610845089, -0.060210078954696655, -0.04435150697827339, -0.012156362645328045, 0.03143595904111862, -0.05559872090816498, -0.01572735235095024, -0.017442552372813225, 0.013393555767834187, 0.05758572742342949 ]
30,691
networkx.readwrite.multiline_adjlist
generate_multiline_adjlist
Generate a single line of the graph G in multiline adjacency list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels Returns ------- lines : string Lines of data in multiline adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> for line in nx.generate_multiline_adjlist(G): ... print(line) 0 3 1 {} 2 {} 3 {} 1 2 2 {} 3 {} 2 1 3 {} 3 1 4 {} 4 1 5 {} 5 1 6 {} 6 0 See Also -------- write_multiline_adjlist, read_multiline_adjlist
def generate_multiline_adjlist(G, delimiter=" "): """Generate a single line of the graph G in multiline adjacency list format. Parameters ---------- G : NetworkX graph delimiter : string, optional Separator for node labels Returns ------- lines : string Lines of data in multiline adjlist format. Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> for line in nx.generate_multiline_adjlist(G): ... print(line) 0 3 1 {} 2 {} 3 {} 1 2 2 {} 3 {} 2 1 3 {} 3 1 4 {} 4 1 5 {} 5 1 6 {} 6 0 See Also -------- write_multiline_adjlist, read_multiline_adjlist """ if G.is_directed(): if G.is_multigraph(): for s, nbrs in G.adjacency(): nbr_edges = [ (u, data) for u, datadict in nbrs.items() for key, data in datadict.items() ] deg = len(nbr_edges) yield str(s) + delimiter + str(deg) for u, d in nbr_edges: if d is None: yield str(u) else: yield str(u) + delimiter + str(d) else: # directed single edges for s, nbrs in G.adjacency(): deg = len(nbrs) yield str(s) + delimiter + str(deg) for u, d in nbrs.items(): if d is None: yield str(u) else: yield str(u) + delimiter + str(d) else: # undirected if G.is_multigraph(): seen = set() # helper dict used to avoid duplicate edges for s, nbrs in G.adjacency(): nbr_edges = [ (u, data) for u, datadict in nbrs.items() if u not in seen for key, data in datadict.items() ] deg = len(nbr_edges) yield str(s) + delimiter + str(deg) for u, d in nbr_edges: if d is None: yield str(u) else: yield str(u) + delimiter + str(d) seen.add(s) else: # undirected single edges seen = set() # helper dict used to avoid duplicate edges for s, nbrs in G.adjacency(): nbr_edges = [(u, d) for u, d in nbrs.items() if u not in seen] deg = len(nbr_edges) yield str(s) + delimiter + str(deg) for u, d in nbr_edges: if d is None: yield str(u) else: yield str(u) + delimiter + str(d) seen.add(s)
(G, delimiter=' ')
[ 0.014640836045145988, -0.0007161021931096911, -0.020799431949853897, -0.0037192446179687977, 0.01805073395371437, -0.010276922024786472, -0.019231446087360382, 0.00946459174156189, 0.08244207501411438, -0.028167078271508217, -0.026731332764029503, 0.016350507736206055, -0.01914643496274948, 0.053500447422266006, -0.012298301793634892, 0.008836452849209309, -0.0022858595475554466, -0.0420900397002697, 0.03887850418686867, 0.045943886041641235, 0.004106518346816301, -0.01164654828608036, 0.03687601536512375, 0.009440978057682514, -0.013091741129755974, -0.005851611495018005, 0.012430542148649693, 0.00315722543746233, -0.005610745865851641, 0.010248584672808647, -0.0023602445144206285, -0.07753030955791473, -0.051195695996284485, -0.010881447233259678, 0.00009534254058962688, -0.0032871037255972624, -0.04027646780014038, 0.03232318535447121, -0.0628328025341034, -0.031208595260977745, 0.02021379955112934, -0.02523891255259514, 0.04027646780014038, -0.03396673873066902, -0.0010549667058512568, 0.033078841865062714, 0.0158876683562994, 0.03814173862338066, -0.08334886282682419, -0.06785791367292404, 0.052178047597408295, 0.0043946122750639915, -0.03510022163391113, 0.02741142362356186, -0.011353732086718082, -0.048021942377090454, -0.00011497188825160265, -0.007159840781241655, 0.02436990663409233, 0.02843155898153782, -0.033078841865062714, -0.0080099543556571, 0.04303461313247681, -0.002200848190113902, -0.008538912981748581, 0.004151385277509689, -0.06763121485710144, -0.05674976855516434, 0.013450677506625652, 0.004302516579627991, -0.000009805448826227803, 0.007348754908889532, -0.0009923889301717281, 0.01795627735555172, 0.023633142933249474, 0.03515689820051193, -0.012326639145612717, 0.038349542766809464, 0.05376492813229561, -0.04318574070930481, -0.006791458465158939, 0.005950791295617819, 0.047833025455474854, -0.019647056236863136, 0.06604433804750443, -0.02021379955112934, 0.008260264992713928, 0.056485287845134735, -0.015160349197685719, -0.019495924934744835, -0.005308483727276325, 0.0212150439620018, -0.016492193564772606, 0.022461876273155212, -0.04046538099646568, -0.02017601579427719, -0.022499658167362213, -0.03774501755833626, 0.02317974902689457, 0.01431968156248331, 0.0030627683736383915, 0.02943280339241028, -0.06253053992986679, 0.0017002261010929942, -0.04428144544363022, -0.10873890668153763, -0.028148187324404716, 0.014659726992249489, 0.043790265917778015, -0.02115836925804615, -0.063286192715168, 0.020912781357765198, 0.05085565149784088, -0.026976920664310455, 0.03617703169584274, 0.02306639961898327, 0.00995576847344637, -0.01532092597335577, 0.028714928776025772, -0.041598863899707794, -0.0019918621983379126, -0.01701170578598976, -0.07843709737062454, 0.0316619873046875, 0.0262968298047781, -0.050137776881456375, 0.02098834700882435, -0.022613007575273514, 0.038349542766809464, -0.05459614843130112, 0.05584298074245453, 0.051346827298402786, 0.033211082220077515, 0.03800949826836586, -0.008227204903960228, -0.01805073395371437, -0.05157352611422539, 0.016076581552624702, 0.06940700858831406, 0.010588630102574825, 0.02531447634100914, -0.11176152527332306, 0.02212182991206646, 0.018485235050320625, -0.025522282347083092, -0.021517306566238403, -0.0023248230572789907, 0.025654522702097893, 0.009133992716670036, -0.01155209168791771, 0.0212717168033123, -0.004321407992392778, 0.031643096357584, -0.033267758786678314, 0.025881219655275345, 0.028922734782099724, -0.0957416221499443, 0.032096490263938904, 0.02969728223979473, -0.020478278398513794, -0.019382577389478683, -0.035515833646059036, 0.034420132637023926, 0.042732350528240204, -0.0059130084700882435, 0.050364475697278976, 0.02333088032901287, -0.06562872976064682, -0.021932916715741158, -0.014631389640271664, 0.0316619873046875, -0.06785791367292404, -0.05512510612607002, -0.031303051859140396, -0.0017958638491109014, 0.05894117057323456, -0.014943097718060017, 0.09219003468751907, 0.003740497399121523, 0.015623188577592373, -0.019297566264867783, -0.018173526972532272, 0.01271391287446022, -0.05002443119883537, 0.01890084706246853, 0.017162837088108063, 0.06498642265796661, -0.0638529360294342, 0.05002443119883537, -0.026844680309295654, -0.02310418337583542, -0.060716964304447174, -0.0069095296785235405, 0.06782013177871704, 0.007764365989714861, -0.007457380648702383, -0.027203617617487907, 0.017739025875926018, -0.042921263724565506, 0.032247621566057205, 0.019477033987641335, -0.020553844049572945, 0.013866288587450981, -0.0034524034708738327, 0.027146942913532257, 0.0529337041079998, -0.027260292321443558, -0.027864815667271614, -0.04099433869123459, 0.0318320095539093, 0.010579184629023075, -0.03553472459316254, 0.04420587792992592, 0.025049997493624687, -0.014999772422015667, 0.010975903831422329, -0.036592643707990646, 0.08954524248838425, -0.0528959222137928, -0.042807914316654205, 0.014489704743027687, -0.03562918305397034, -0.002845517359673977, -0.012005485594272614, 0.043979182839393616, -0.058676689863204956, 0.04938212037086487, -0.031303051859140396, -0.008656984195113182, 0.017285631969571114, 0.059772390872240067, -0.019609274342656136, 0.020874997600913048, 0.044885966926813126, 0.007438489235937595, -0.027222508564591408, 0.0034098979085683823, -0.008316939696669579, -0.0014522764831781387, 0.044999316334724426, -0.09370134770870209, -0.007070106919854879, 0.027732577174901962, -0.030887439846992493, 0.026825789362192154, 0.03918076679110527, 0.011523754335939884, -0.00029016012558713555, -0.00037959907785989344, 0.01214717049151659, -0.07208958268165588, 0.01471640169620514, 0.007306249346584082, -0.020856106653809547, 0.034514591097831726, -0.029376128688454628, -0.056409724056720734, -0.012033822014927864, -0.02750588022172451, 0.000017480080714449286, 0.013979637064039707, 0.006470304913818836, -0.04541492834687233, 0.029772847890853882, 0.08297103643417358, 0.025541173294186592, -0.0061349826864898205, 0.0132050896063447, 0.00399789260700345, 0.0061349826864898205, 0.05928121507167816, 0.04322352632880211, -0.016624432057142258, 0.013847396709024906, -0.006767844315618277, 0.035591401159763336, -0.018541909754276276, 0.03610146790742874, -0.008699489757418633, -0.017483990639448166, -0.05712759494781494, 0.02964060753583908, -0.006512810476124287, 0.003979001194238663, -0.07949501276016235, 0.020629409700632095, -0.03895406797528267, -0.06475972384214401, -0.01221329066902399, -0.03596922755241394, 0.07295858860015869, -0.027808142825961113, 0.01692669466137886, 0.01908976025879383, 0.06710225343704224, 0.020742759108543396, 0.05905451998114586, 0.01673778146505356, 0.007098443806171417, 0.010815327055752277, 0.030169567093253136, -0.04360135272145271, 0.059772390872240067, -0.005251809488981962, -0.023689817637205124, -0.036517076194286346, 0.007924942299723625, -0.03358891233801842, 0.022707464173436165, -0.031321942806243896, -0.060868095606565475, 0.02008155919611454, 0.028091512620449066, -0.02323642373085022, -0.017257295548915863, 0.011996039189398289, -0.04583054035902023, 0.02761922776699066, 0.055351804941892624, 0.011372623033821583, -0.03610146790742874, 0.047039587050676346, 0.005350989289581776, 0.04477262124419212, -0.04617058485746384, 0.06426854431629181, 0.05353822931647301, 0.04923098906874657, 0.0160199087113142, -0.0011641825549304485, 0.015604297630488873, -0.04564162343740463, -0.08652261644601822, 0.06430632621049881, -0.03731051832437515, 0.004968438297510147, 0.061850447207689285, -0.032020922750234604, -0.019552599638700485, -0.06717782467603683, 0.041749995201826096, 0.014272453263401985, -0.010579184629023075, -0.003372115083038807, 0.04828641936182976, 0.031151920557022095, 0.031095245853066444, -0.014848641119897366, -0.009200111962854862, 0.08584252744913101, 0.027713684365153313, 0.054407235234975815, -0.02002488449215889, 0.010173019021749496, 0.04431922733783722, 0.016539420932531357, -0.025843435898423195, -0.053349316120147705, -0.01782403700053692, 0.0848601758480072, -0.014414139091968536, 0.006399461999535561, 0.06751786917448044, 0.05044003948569298, -0.013611254282295704, -0.014489704743027687, -0.03258766606450081, 0.0209694541990757, 0.052178047597408295, 0.022990835830569267, -0.051346827298402786, -0.011278166435658932, 0.024558821693062782, -0.02654241770505905, -0.012288856320083141, 0.01701170578598976, -0.00024086536723189056, 0.001155327190645039, 0.004692151676863432, 0.009219003841280937, -0.04768189415335655, 0.006116091273725033, 0.08795836567878723, 0.027959274128079414, -0.032304294407367706, -0.012921717949211597, 0.08818505704402924, 0.030887439846992493, -0.04004976898431778, 0.018324658274650574, -0.05557850003242493, 0.025786763057112694, 0.03921854868531227, 0.013308991678059101, -0.05788325145840645, -0.05149795860052109, 0.04673732444643974, -0.015575960278511047, -0.008269710466265678, -0.012458878569304943, -0.01480141282081604, 0.003506716340780258, -0.04858868196606636, 0.014442476443946362, -0.040503162890672684, -0.014659726992249489, 0.020686084404587746, 0.005946068558841944, 0.03360780328512192, -0.017266741022467613, -0.006786735728383064, 0.014196887612342834, 0.01781459152698517, -0.010522509925067425, 0.046888455748558044, -0.02219739556312561, -0.0016282026190310717, 0.03519468009471893, 0.05062895268201828, 0.059734608978033066, 0.0029895640909671783, 0.0068764700554311275, 0.024861084297299385, 0.014017419889569283, -0.007070106919854879, -0.0132050896063447, -0.06200157850980759, 0.026636876165866852, -0.05928121507167816, 0.0033839221578091383, 0.00906314980238676, -0.01793738454580307, 0.04896651208400726, -0.04866424947977066, -0.015660971403121948, -0.01887250877916813, 0.04877759888768196, 0.004170276690274477, 0.02960282564163208, -0.015434274449944496, 0.03933189809322357, -0.0131578603759408, 0.0026070133317261934, 0.000369267858332023, 0.07541447132825851, -0.018513573333621025, -0.012865044176578522, 0.011882691644132137, 0.060754746198654175, 0.02202737331390381, -0.008982861414551735, 0.012902827002108097, 0.004996775649487972, -0.04628393054008484, -0.09173664450645447, -0.006862301379442215, 0.08221537619829178, -0.0157365370541811, -0.03734830021858215, 0.04405474662780762, 0.07760587334632874, 0.022877486422657967, 0.008090242743492126, 0.020818324759602547, -0.00956377200782299, -0.023652033880352974, 0.015075338073074818, 0.03391006588935852, -0.063210628926754, -0.019684839993715286, 0.035270243883132935, -0.02202737331390381, -0.042241171002388, -0.025578957051038742, 0.040540944784879684, 0.009795191697776318, -0.026863571256399155, -0.00003475722769508138, -0.032134272158145905, -0.03459015488624573, -0.047152936458587646, -0.018570248037576675, -0.0011818932835012674, -0.016274942085146904, 0.002954142866656184, 0.019628165289759636, 0.023538686335086823, -0.04839976876974106, -0.05161130800843239, -0.03368336707353592, 0.006682833191007376, -0.008161085657775402, -0.01891029253602028, -0.04873981326818466, 0.07541447132825851, 0.07639682292938232, 0.0056013003922998905, -0.038727372884750366, 0.032153163105249405, -0.014669172465801239, 0.001517215627245605, -0.04114546999335289, 0.0021642460487782955, -0.024067644029855728, 0.05814773216843605, 0.03375893458724022, 0.004205698147416115, 0.04299682751297951, -0.023633142933249474, 0.004378082230687141, -0.024823300540447235, 0.027713684365153313, 0.04027646780014038, 0.060868095606565475, -0.009757408872246742, 0.02862047217786312, -0.021744001656770706, 0.011948810890316963, 0.008179976604878902, -0.0001064855168806389, 0.01587822288274765, 0.012326639145612717, -0.024653278291225433, 0.022594114765524864, -0.0852380022406578, 0.06041470170021057, -0.0004737609124276787, -0.006191656459122896, -0.015028109773993492, -0.011854354292154312, -0.025578957051038742, 0.061888229101896286, 0.012298301793634892, 0.05391605943441391, -0.00315722543746233, 0.01790904812514782, 0.02624015510082245, 0.042921263724565506, 0.028148187324404716, 0.011382069438695908, 0.014612498693168163, 0.006201102398335934, -0.059734608978033066, 0.0062813907861709595, -0.05489841103553772, 0.026806898415088654, 0.08901628106832504, 0.02419988438487053, -0.0132050896063447, -0.05943234637379646, -0.061774879693984985, 0.035402484238147736, -0.00027540119481272995, -0.018825281411409378, 0.023614251986145973, -0.021932916715741158, -0.006234162487089634, 0.008855343796312809, 0.030150676146149635, 0.019798187538981438, -0.006427799351513386, 0.025900110602378845, -0.09370134770870209, -0.031605314463377, 0.0946081355214119, 0.012883935123682022, -0.0035539448726922274, 0.017597340047359467, 0.008897850289940834, 0.01912754401564598, -0.005095955450087786, -0.03485463559627533, 0.03481685370206833, -0.020837215706706047, -0.038576241582632065, -0.02637239545583725, -0.042807914316654205, -0.014688064344227314, 0.042921263724565506, -0.05920565128326416, -0.0530470535159111, 0.047039587050676346, 0.023557577282190323, 0.021630654111504555, 0.03353223577141762, -0.011202600784599781, -0.02863936312496662, 0.029168322682380676, 0.019647056236863136, 0.007509331684559584, -0.01222273614257574, -0.028091512620449066, 0.03487352654337883, -0.02104501985013485, -0.029376128688454628, -0.00838778167963028, 0.03374004364013672, 0.0069095296785235405, -0.041825562715530396, -0.03347556293010712, -0.05467171594500542, 0.040540944784879684, 0.024898866191506386, 0.05051560699939728, 0.027638118714094162, -0.029054975137114525, -0.010324150323867798, -0.0841800794005394, -0.01422522496432066, -0.007693523075431585, -0.04575497284531593, 0.08848731964826584, -0.01487697847187519, -0.08130858838558197, -0.08531356602907181, 0.007608511950820684, -0.03986085578799248, 0.016010461375117302, -0.03047182969748974, -0.04824863746762276, 0.05357601121068001, -0.023878730833530426, -0.005691034719347954, -0.015047000721096992, -0.033078841865062714, 0.07258076220750809, -0.021460631862282753, -0.04413031414151192, -0.002906914334744215, -0.024067644029855728, -0.04662397876381874, -0.036460403352975845, 0.00639001652598381, 0.01809796132147312, 0.03391006588935852, -0.063286192715168, -0.00021843182912562042, -0.022877486422657967, -0.019798187538981438, 0.0019257421372458339, -0.05939456447958946, 0.007651017513126135, -0.07530112564563751, -0.04545271024107933, -0.04016311839222908, 0.011911028064787388, 0.027921490371227264, -0.03493019938468933, 0.0007621499826200306, -0.014848641119897366, 0.0015597213059663773, 0.0746210366487503, 0.02329309657216072, -0.021970698609948158, 0.023538686335086823, 0.04662397876381874, -0.0211016945540905, -0.022764138877391815, -0.0034925476647913456, -0.029243888333439827, 0.048135288059711456, 0.014640836045145988, 0.029243888333439827, -0.027883708477020264, 0.006319173611700535, 0.025106672197580338, 0.01778625324368477, 0.046057235449552536, 0.05508732423186302, -0.03914298117160797, -0.03347556293010712, 0.007929665967822075, 0.0313597247004509, -0.00034890056122094393, -0.04110768809914589, -0.0641551986336708, 0.011259274557232857, 0.025125563144683838, -0.0010148223955184221, -0.007915496826171875, 0.010928675532341003, 0.018286876380443573, 0.01776736229658127, -0.0736008957028389, -0.03570474684238434, -0.04023868218064308, -0.002441713586449623, -0.06487306952476501, 0.008619201369583607, -0.026920245960354805, -0.006385293323546648, -0.009851865470409393, 0.0317186638712883, -0.009927431121468544, 0.0050062211230397224, -0.029376128688454628, 0.008425564505159855, -0.006720616016536951, 0.007939111441373825, -0.022348526865243912, 0.017134500667452812, -0.0106075219810009, 0.007273189257830381, 0.06785791367292404, 0.021347282454371452, -0.005322652403265238, -0.044923752546310425, 0.01684168353676796, -0.06041470170021057, 0.05051560699939728, -0.03625259920954704, 0.03249321132898331, 0.003532692091539502, -0.001039027003571391, 0.018711932003498077, -0.05501176044344902, -0.032266512513160706, 0.0025196406058967113, -0.033437781035900116, 0.024917757138609886, -0.036573752760887146, 0.042165607213974, -0.005950791295617819, 0.02622126415371895, -0.06585542112588882, 0.03613924980163574, -0.0317753367125988, -0.014489704743027687, -0.05002443119883537, -0.03398562967777252, -0.021932916715741158, 0.07805927097797394, 0.010513064451515675, 0.08206424862146378, 0.015594851225614548, 0.01048472709953785, -0.08009953796863556, -0.00582327414304018, 0.004538659006357193, 0.034250110387802124, -0.027978165075182915, -0.013403449207544327, -0.024577712640166283, 0.017701242119073868, -0.025919001549482346, -0.010324150323867798, 0.056409724056720734, 0.08939410746097565, -0.03774501755833626, -0.015349263325333595, 0.028299318626523018, -0.01793738454580307, -0.0060216342099010944, -0.037518322467803955, 0.010380825027823448, -0.020553844049572945, 0.010324150323867798, -0.03066074289381504, -0.05618302524089813, -0.04001198709011078, -0.021328391507267952, 0.016605541110038757, 0.021706219762563705, 0.027902599424123764, -0.038538459688425064, 0.016274942085146904, 0.017077825963497162, 0.04613279923796654 ]
30,692
networkx.readwrite.text
generate_network_text
Generate lines in the "network text" format This works via a depth-first traversal of the graph and writing a line for each unique node encountered. Non-tree edges are written to the right of each node, and connection to a non-tree edge is indicated with an ellipsis. This representation works best when the input graph is a forest, but any graph can be represented. This notation is original to networkx, although it is simple enough that it may be known in existing literature. See #5602 for details. The procedure is summarized as follows: 1. Given a set of source nodes (which can be specified, or automatically discovered via finding the (strongly) connected components and choosing one node with minimum degree from each), we traverse the graph in depth first order. 2. Each reachable node will be printed exactly once on it's own line. 3. Edges are indicated in one of four ways: a. a parent "L-style" connection on the upper left. This corresponds to a traversal in the directed DFS tree. b. a backref "<-style" connection shown directly on the right. For directed graphs, these are drawn for any incoming edges to a node that is not a parent edge. For undirected graphs, these are drawn for only the non-parent edges that have already been represented (The edges that have not been represented will be handled in the recursive case). c. a child "L-style" connection on the lower right. Drawing of the children are handled recursively. d. if ``vertical_chains`` is true, and a parent node only has one child a "vertical-style" edge is drawn between them. 4. The children of each node (wrt the directed DFS tree) are drawn underneath and to the right of it. In the case that a child node has already been drawn the connection is replaced with an ellipsis ("...") to indicate that there is one or more connections represented elsewhere. 5. If a maximum depth is specified, an edge to nodes past this maximum depth will be represented by an ellipsis. 6. If a a node has a truthy "collapse" value, then we do not traverse past that node. Parameters ---------- graph : nx.DiGraph | nx.Graph Graph to represent with_labels : bool | str If True will use the "label" attribute of a node to display if it exists otherwise it will use the node value itself. If given as a string, then that attribute name will be used instead of "label". Defaults to True. sources : List Specifies which nodes to start traversal from. Note: nodes that are not reachable from one of these sources may not be shown. If unspecified, the minimal set of nodes needed to reach all others will be used. max_depth : int | None The maximum depth to traverse before stopping. Defaults to None. ascii_only : Boolean If True only ASCII characters are used to construct the visualization vertical_chains : Boolean If True, chains of nodes will be drawn vertically when possible. Yields ------ str : a line of generated text Examples -------- >>> graph = nx.path_graph(10) >>> graph.add_node("A") >>> graph.add_node("B") >>> graph.add_node("C") >>> graph.add_node("D") >>> graph.add_edge(9, "A") >>> graph.add_edge(9, "B") >>> graph.add_edge(9, "C") >>> graph.add_edge("C", "D") >>> graph.add_edge("C", "E") >>> graph.add_edge("C", "F") >>> nx.write_network_text(graph) ╙── 0 └── 1 └── 2 └── 3 └── 4 └── 5 └── 6 └── 7 └── 8 └── 9 ├── A ├── B └── C ├── D ├── E └── F >>> nx.write_network_text(graph, vertical_chains=True) ╙── 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 ├── A ├── B └── C ├── D ├── E └── F
def generate_network_text( graph, with_labels=True, sources=None, max_depth=None, ascii_only=False, vertical_chains=False, ): """Generate lines in the "network text" format This works via a depth-first traversal of the graph and writing a line for each unique node encountered. Non-tree edges are written to the right of each node, and connection to a non-tree edge is indicated with an ellipsis. This representation works best when the input graph is a forest, but any graph can be represented. This notation is original to networkx, although it is simple enough that it may be known in existing literature. See #5602 for details. The procedure is summarized as follows: 1. Given a set of source nodes (which can be specified, or automatically discovered via finding the (strongly) connected components and choosing one node with minimum degree from each), we traverse the graph in depth first order. 2. Each reachable node will be printed exactly once on it's own line. 3. Edges are indicated in one of four ways: a. a parent "L-style" connection on the upper left. This corresponds to a traversal in the directed DFS tree. b. a backref "<-style" connection shown directly on the right. For directed graphs, these are drawn for any incoming edges to a node that is not a parent edge. For undirected graphs, these are drawn for only the non-parent edges that have already been represented (The edges that have not been represented will be handled in the recursive case). c. a child "L-style" connection on the lower right. Drawing of the children are handled recursively. d. if ``vertical_chains`` is true, and a parent node only has one child a "vertical-style" edge is drawn between them. 4. The children of each node (wrt the directed DFS tree) are drawn underneath and to the right of it. In the case that a child node has already been drawn the connection is replaced with an ellipsis ("...") to indicate that there is one or more connections represented elsewhere. 5. If a maximum depth is specified, an edge to nodes past this maximum depth will be represented by an ellipsis. 6. If a a node has a truthy "collapse" value, then we do not traverse past that node. Parameters ---------- graph : nx.DiGraph | nx.Graph Graph to represent with_labels : bool | str If True will use the "label" attribute of a node to display if it exists otherwise it will use the node value itself. If given as a string, then that attribute name will be used instead of "label". Defaults to True. sources : List Specifies which nodes to start traversal from. Note: nodes that are not reachable from one of these sources may not be shown. If unspecified, the minimal set of nodes needed to reach all others will be used. max_depth : int | None The maximum depth to traverse before stopping. Defaults to None. ascii_only : Boolean If True only ASCII characters are used to construct the visualization vertical_chains : Boolean If True, chains of nodes will be drawn vertically when possible. Yields ------ str : a line of generated text Examples -------- >>> graph = nx.path_graph(10) >>> graph.add_node("A") >>> graph.add_node("B") >>> graph.add_node("C") >>> graph.add_node("D") >>> graph.add_edge(9, "A") >>> graph.add_edge(9, "B") >>> graph.add_edge(9, "C") >>> graph.add_edge("C", "D") >>> graph.add_edge("C", "E") >>> graph.add_edge("C", "F") >>> nx.write_network_text(graph) ╙── 0 └── 1 └── 2 └── 3 └── 4 └── 5 └── 6 └── 7 └── 8 └── 9 ├── A ├── B └── C ├── D ├── E └── F >>> nx.write_network_text(graph, vertical_chains=True) ╙── 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 ├── A ├── B └── C ├── D ├── E └── F """ from typing import Any, NamedTuple class StackFrame(NamedTuple): parent: Any node: Any indents: list this_islast: bool this_vertical: bool collapse_attr = "collapse" is_directed = graph.is_directed() if is_directed: glyphs = AsciiDirectedGlyphs if ascii_only else UtfDirectedGlyphs succ = graph.succ pred = graph.pred else: glyphs = AsciiUndirectedGlyphs if ascii_only else UtfUndirectedGlyphs succ = graph.adj pred = graph.adj if isinstance(with_labels, str): label_attr = with_labels elif with_labels: label_attr = "label" else: label_attr = None if max_depth == 0: yield glyphs.empty + " ..." elif len(graph.nodes) == 0: yield glyphs.empty else: # If the nodes to traverse are unspecified, find the minimal set of # nodes that will reach the entire graph if sources is None: sources = _find_sources(graph) # Populate the stack with each: # 1. parent node in the DFS tree (or None for root nodes), # 2. the current node in the DFS tree # 2. a list of indentations indicating depth # 3. a flag indicating if the node is the final one to be written. # Reverse the stack so sources are popped in the correct order. last_idx = len(sources) - 1 stack = [ StackFrame(None, node, [], (idx == last_idx), False) for idx, node in enumerate(sources) ][::-1] num_skipped_children = defaultdict(lambda: 0) seen_nodes = set() while stack: parent, node, indents, this_islast, this_vertical = stack.pop() if node is not Ellipsis: skip = node in seen_nodes if skip: # Mark that we skipped a parent's child num_skipped_children[parent] += 1 if this_islast: # If we reached the last child of a parent, and we skipped # any of that parents children, then we should emit an # ellipsis at the end after this. if num_skipped_children[parent] and parent is not None: # Append the ellipsis to be emitted last next_islast = True try_frame = StackFrame( node, Ellipsis, indents, next_islast, False ) stack.append(try_frame) # Redo this frame, but not as a last object next_islast = False try_frame = StackFrame( parent, node, indents, next_islast, this_vertical ) stack.append(try_frame) continue if skip: continue seen_nodes.add(node) if not indents: # Top level items (i.e. trees in the forest) get different # glyphs to indicate they are not actually connected if this_islast: this_vertical = False this_prefix = indents + [glyphs.newtree_last] next_prefix = indents + [glyphs.endof_forest] else: this_prefix = indents + [glyp
(graph, with_labels=True, sources=None, max_depth=None, ascii_only=False, vertical_chains=False)
[ -0.008577708154916763, -0.0016242837300524116, 0.016623301431536674, -0.0033895783126354218, -0.012877204455435276, -0.0010209974134340882, -0.059128716588020325, 0.0005776783218607306, 0.0913536548614502, -0.032906047999858856, -0.004139861557632685, 0.016431739553809166, 0.02449861541390419, 0.03314017876982689, -0.004866200033575296, 0.035247355699539185, 0.03267191722989082, -0.028053149580955505, 0.055042069405317307, 0.05240277200937271, -0.014164925552904606, -0.01915617287158966, 0.04182431101799011, -0.011238288134336472, 0.01915617287158966, -0.005424921400845051, -0.02903224341571331, 0.017346978187561035, -0.06640806049108505, 0.0005141569999977946, -0.03058602102100849, -0.08598992973566055, -0.031948238611221313, -0.027542319148778915, -0.018964610993862152, 0.02554156258702278, -0.04580453783273697, 0.011632053181529045, -0.04614508897066116, -0.05763879418373108, -0.011451134458184242, 0.023923929780721664, -0.011855541728436947, -0.032778337597846985, -0.013281612657010555, 0.005911807529628277, 0.026988917961716652, 0.018347356468439102, -0.05108312517404556, -0.049465492367744446, 0.01765560545027256, -0.007657147943973541, -0.003706187242642045, 0.019230669364333153, -0.010738098993897438, -0.03522607311606407, 0.010743419639766216, 0.003299118485301733, 0.05529748275876045, -0.05359471216797829, 0.0008660186431370676, 0.028542697429656982, 0.010158092714846134, 0.04512342810630798, -0.05095541849732399, 0.008301007561385632, -0.02739332616329193, -0.04742216691374779, -0.04033438488841057, -0.012994269840419292, -0.011834257282316685, -0.012802708894014359, 0.03522607311606407, 0.017559824511408806, -0.0017945608124136925, -0.02060352824628353, -0.04827355593442917, -0.0028654441703110933, 0.031969524919986725, -0.046187661588191986, -0.008710737340152264, 0.0006199150229804218, 0.010067632421851158, -0.04789043217897415, 0.0518493726849556, -0.015484572388231754, 0.039078593254089355, 0.042973678559064865, 0.015835769474506378, -0.02183803729712963, -0.029266374185681343, 0.012579219415783882, 0.02366851456463337, 0.04086650162935257, -0.0627896785736084, -0.005416939966380596, 0.04942292347550392, -0.05653199180960655, 0.018879471346735954, 0.0070984261110424995, 0.013260328210890293, 0.04861410707235336, -0.043399371206760406, 0.019432872533798218, -0.05849017947912216, 0.002137775532901287, -0.09535516798496246, 0.06364106386899948, 0.05712796375155449, -0.04980604723095894, -0.03624773398041725, -0.029990052804350853, 0.10131486505270004, -0.06802569329738617, 0.08475542068481445, -0.023136399686336517, -0.03256549313664436, -0.008934225887060165, -0.020060770213603973, -0.04959320276975632, 0.018421852961182594, -0.04635793715715408, -0.0777740627527237, -0.02924508973956108, -0.021859321743249893, -0.038333628326654434, 0.021050505340099335, 0.009759005159139633, 0.05938413366675377, -0.0677277147769928, 0.053169019520282745, 0.02285969816148281, 0.025669271126389503, 0.04848640039563179, 0.03584332764148712, -0.0246901772916317, -0.061597734689712524, -0.0017839185893535614, -0.0031953558791428804, 0.011185076087713242, 0.03452368080615997, -0.08492569625377655, 0.017059635370969772, 0.025669271126389503, -0.03507708013057709, 0.003607745748013258, 0.03286347910761833, -0.04942292347550392, 0.005725567229092121, -0.014164925552904606, 0.061001766473054886, -0.04284597188234329, -0.027095342054963112, 0.06308765709400177, 0.0319269523024559, -0.006236398126929998, -0.06725944578647614, 0.020656738430261612, 0.018879471346735954, 0.0319269523024559, 0.007353841792792082, -0.054616376757621765, 0.0220508836209774, 0.05218992754817009, -0.054190684109926224, 0.019518010318279266, -0.021859321743249893, -0.017730101943016052, -0.015729345381259918, 0.006108690518885851, 0.014718325808644295, -0.03620516508817673, -0.07462393492460251, 0.0006209127604961395, -0.016112469136714935, 0.004350047558546066, 0.005217396188527346, 0.05653199180960655, -0.04210101068019867, 0.024243200197815895, -0.05857531726360321, -0.020678022876381874, 0.013696663081645966, -0.007156958803534508, 0.031756676733493805, -0.017102204263210297, 0.023413099348545074, 0.006028872914612293, 0.05129597336053848, -0.01918809860944748, -0.038440052419900894, -0.01899653673171997, 0.04435718059539795, 0.052445340901613235, 0.0442720428109169, -0.03486423194408417, 0.0008380825165659189, -0.009359918534755707, -0.017261840403079987, -0.00890761986374855, -0.015665492042899132, 0.06193828955292702, 0.06845138967037201, -0.05508463829755783, -0.004844915121793747, 0.04063237085938454, -0.01575062982738018, 0.04537884518504143, -0.08335063606500626, 0.029904913157224655, -0.013185831718146801, -0.019092317670583725, 0.050700001418590546, 0.013334824703633785, -0.0141542823985219, -0.02077380381524563, -0.061725445091724396, 0.07377254962921143, -0.033821284770965576, -0.01522915717214346, -0.02213602140545845, 0.012515366077423096, -0.01276013907045126, 0.008785233832895756, 0.016059257090091705, -0.059554412961006165, 0.03816335275769234, 0.010136808268725872, 0.07807204127311707, -0.057383377104997635, 0.05253048241138458, 0.021444270387291908, -0.013537028804421425, 0.013419962488114834, 0.007284666411578655, -0.04418690502643585, 0.008157337084412575, -0.03035189025104046, 0.002511586993932724, -0.0031501261983066797, -0.07402796298265457, -0.013419962488114834, -0.010812594555318356, -0.06483300030231476, 0.06713174283504486, 0.05682997778058052, 0.04393148794770241, 0.004251605831086636, -0.0029133346397429705, -0.007667790167033672, -0.012079031206667423, -0.0033736147452145815, -0.012621789239346981, -0.021593263372778893, -0.008455321192741394, -0.037631236016750336, -0.013984005898237228, -0.06440731137990952, 0.020976008847355843, 0.042037155479192734, -0.01950736902654171, -0.03179924562573433, -0.09646196663379669, 0.0543183907866478, 0.050700001418590546, -0.011461776681244373, -0.0013968042330816388, -0.007140995468944311, -0.03850390762090683, -0.0234556682407856, -0.02020976133644581, 0.05197707936167717, 0.008556423708796501, 0.02975592017173767, -0.012281235307455063, 0.008577708154916763, -0.04716675356030464, 0.02933022752404213, 0.005286571569740772, -0.004368671681731939, -0.02063545398414135, 0.021699685603380203, -0.0430375337600708, -0.032267507165670395, 0.010120844468474388, -0.026222670450806618, -0.0045309667475521564, -0.05236020311713219, -0.022731991484761238, -0.043505795300006866, 0.0871393010020256, -0.0036290304269641638, 0.028904534876346588, 0.017879094928503036, 0.06921763718128204, -0.007438980042934418, 0.01959250681102276, -0.02264685183763504, -0.05648942291736603, -0.013164547272026539, 0.04414433613419533, -0.042654410004615784, 0.07794433832168579, -0.013973363675177097, -0.007572009228169918, 0.014643829315900803, -0.03305504098534584, -0.0180812980979681, 0.03254420682787895, -0.032693199813365936, -0.04899723082780838, 0.01153627224266529, 0.07628413289785385, 0.019475441426038742, -0.004134540446102619, -0.0006328853196464479, 0.014601260423660278, -0.011983250267803669, 0.07879572361707687, 0.009923961013555527, -0.03969584405422211, 0.03635415807366371, -0.02935151197016239, 0.01827285997569561, 0.0007216822123154998, 0.015974119305610657, 0.05946927145123482, 0.06768514215946198, 0.0038924277760088444, -0.05108312517404556, 0.031841814517974854, 0.005371709819883108, 0.005624465178698301, 0.013600882142782211, -0.10157028585672379, 0.04661335423588753, 0.02811700478196144, -0.0015431360807269812, 0.010887091048061848, -0.07121839374303818, 0.04048337787389755, 0.03128841519355774, -0.014920529909431934, 0.01364345196634531, 0.06176801398396492, 0.013217759318649769, 0.0492100790143013, 0.006241719238460064, -0.020167192444205284, 0.11493703722953796, 0.02337053045630455, 0.06657834351062775, -0.0053371223621070385, -0.0010968238348141313, -0.020699309185147285, -0.005954376887530088, 0.005741530563682318, -0.032352644950151443, -0.028776828199625015, 0.017506612464785576, 0.00918964110314846, 0.005741530563682318, -0.012483438476920128, 0.04559168964624405, -0.011610768735408783, -0.015016310848295689, 0.020135264843702316, 0.056957684457302094, 0.05576574429869652, -0.023732369765639305, -0.005555289797484875, -0.0678979903459549, 0.04759244620800018, 0.013398678041994572, -0.016548804938793182, 0.033204030245542526, -0.03267191722989082, -0.023711083456873894, 0.01765560545027256, 0.008306329138576984, -0.01899653673171997, 0.022689422592520714, 0.0013110005529597402, 0.004932714160531759, 0.04027052968740463, -0.021774182096123695, 0.07504962384700775, 0.006225755903869867, -0.017027707770466805, -0.03507708013057709, -0.0004609453899320215, 0.009636619128286839, 0.023647230118513107, -0.012419585138559341, -0.022114736959338188, -0.050912849605083466, 0.020135264843702316, 0.04344194009900093, 0.015676135197281837, 0.007949811406433582, 0.004179770592600107, 0.01959250681102276, -0.0006658100173808634, -0.010817916132509708, 0.005693640094250441, 0.0246901772916317, 0.05797934904694557, -0.006805762182921171, 0.04012154042720795, 0.04124962538480759, 0.03377871587872505, 0.023136399686336517, -0.05385012924671173, 0.002003416419029236, 0.026584509760141373, -0.03729068115353584, -0.0045309667475521564, 0.052658189088106155, 0.04397405683994293, 0.00043533730786293745, -0.013611524365842342, 0.0012937068240717053, 0.03222493827342987, -0.017400190234184265, 0.03328917175531387, -0.0037115083541721106, -0.06798312813043594, -0.011749118566513062, 0.0011387279955670238, 0.05227506533265114, -0.026839924976229668, -0.08735214918851852, 0.027116626501083374, 0.006257683038711548, -0.014697041362524033, -0.02256171405315399, 0.0062842885963618755, -0.05682997778058052, -0.010674244724214077, 0.012568577192723751, 0.015314295887947083, -0.03326788544654846, -0.0023652552627027035, 0.00889697764068842, 0.019379660487174988, 0.0031315020751208067, 0.007438980042934418, 0.0295430738478899, -0.033693578094244, 0.01477153692394495, 0.012164168991148472, 0.025967255234718323, 0.009184320457279682, -0.011036084033548832, -0.07441108673810959, -0.016623301431536674, 0.08445743471384048, 0.021497482433915138, -0.02503073215484619, 0.07658211886882782, 0.016921285539865494, 0.035566627979278564, 0.05104055628180504, 0.04746473953127861, 0.03190566971898079, -0.013068766333162785, 0.023732369765639305, 0.008045592345297337, -0.056446854025125504, -0.023221537470817566, 0.027031486853957176, -0.02254042960703373, -0.06598237156867981, 0.0017440099036321044, 0.044825442135334015, -0.02439219318330288, -0.03322531655430794, -0.022412721067667007, -0.04448488727211952, -0.04201587289571762, -0.025137154385447502, -0.04363350197672844, 0.016921285539865494, -0.04237771034240723, -0.008870371617376804, 0.016037972643971443, 0.03852519020438194, -0.015505856834352016, 0.025052016600966454, -0.02626524120569229, -0.03058602102100849, -0.04827355593442917, -0.010418829508125782, -0.03158640116453171, -0.020507747307419777, 0.03305504098534584, -0.0067791566252708435, -0.018900755792856216, -0.001034300308674574, -0.09356725960969925, -0.010562500916421413, -0.010801952332258224, -0.010104880668222904, -0.05725567042827606, 0.03499194234609604, 0.06606750935316086, 0.04397405683994293, 0.04754987731575966, 0.022774560377001762, -0.01234508864581585, 0.04033438488841057, 0.008237154223024845, 0.015739988535642624, 0.02243400551378727, -0.014590618200600147, 0.032161083072423935, 0.011217002756893635, 0.020294900983572006, 0.07854030281305313, 0.00874798558652401, -0.011142507195472717, 0.018294144421815872, -0.006598236970603466, -0.006683375686407089, -0.01000909972935915, 0.05227506533265114, 0.037418391555547714, 0.03992997854948044, 0.008859729394316673, 0.036588288843631744, 0.007396411150693893, 0.057809069752693176, 0.05031687766313553, 0.04063237085938454, 0.03420440852642059, -0.00761457858607173, 0.017634321004152298, 0.019996915012598038, 0.032991185784339905, -0.005853274837136269, 0.034225694835186005, -0.017698174342513084, -0.06023551896214485, 0.007619899697601795, -0.000352194212609902, -0.0276913121342659, 0.11365995556116104, -0.022008312866091728, 0.07909370958805084, -0.021667759865522385, -0.04601738229393959, 0.021752897650003433, 0.0013129960279911757, 0.011919395998120308, 0.06679118424654007, 0.008285044692456722, -0.0007828755187802017, 0.026286525651812553, 0.004773079417645931, 0.02305126003921032, -0.02449861541390419, 0.04640050604939461, -0.04414433613419533, -0.09978237003087997, 0.10020806640386581, 0.02460503950715065, -0.029990052804350853, 0.005390333943068981, 0.038972169160842896, -0.04099420830607414, 0.018804974853992462, 0.030820153653621674, 0.0175491813570261, -0.006864294875413179, -0.05304131284356117, 0.014111713506281376, -0.0405685156583786, 0.027542319148778915, 0.053679849952459335, -0.023498237133026123, -0.016942569985985756, 0.024434762075543404, 0.013728589750826359, 0.03497065603733063, 0.0411006323993206, 0.005959697999060154, -0.008093482814729214, 0.01620825007557869, -0.028968390077352524, 0.0006937460857443511, 0.008795876055955887, -0.024434762075543404, 0.03965327516198158, 0.0026525978464633226, 0.036694712936878204, -0.012259949930012226, 0.01240894291549921, 0.04290982708334923, 0.0035704977344721556, -0.03612002730369568, -0.05819219350814819, 0.035864610224962234, -0.02256171405315399, 0.06674861907958984, 0.025477709248661995, 0.027755165472626686, 0.020731234923005104, -0.03733325004577637, -0.017293766140937805, 0.0011473748600110412, -0.009769648313522339, 0.07475163787603378, 0.007465586066246033, -0.11434106528759003, -0.06376876682043076, -0.031245846301317215, -0.016942569985985756, -0.02871297299861908, -0.009003400802612305, -0.04542141407728195, 0.05857531726360321, -0.024221915751695633, -0.04529370367527008, -0.01902846433222294, -0.056446854025125504, 0.07521989941596985, -0.016304031014442444, -0.027606172487139702, -0.04686876758933067, 0.005800063256174326, -0.016080541536211967, -0.03354458510875702, -0.02162518911063671, 0.030011337250471115, -0.036290302872657776, -0.044442318379879, 0.00875862780958414, -0.006209792569279671, -0.006603558082133532, -0.004685280378907919, -0.06410932540893555, -0.01991177722811699, -0.06287481635808945, -0.03554534167051315, -0.058532748371362686, -0.011206360533833504, 0.00998249463737011, -0.037013981491327286, -0.02192317508161068, -0.011876827105879784, 0.015080164186656475, 0.01661265827715397, 0.0217848252505064, -0.031437408179044724, 0.05878816545009613, 0.05793678015470505, 0.02377493865787983, -0.008056234568357468, 0.019411588087677956, -0.0032299435697495937, 0.056957684457302094, -0.002729754662141204, 0.07270831614732742, 0.016814861446619034, -0.007188885938376188, 0.002558147069066763, 0.04171788692474365, -0.008359541185200214, 0.03260806202888489, -0.036481864750385284, -0.013909509405493736, -0.020050127059221268, -0.007359162904322147, -0.0481458455324173, -0.0014274008572101593, -0.022689422592520714, 0.007119710557162762, 0.03458753228187561, 0.019251953810453415, -0.05980982631444931, 0.019145529717206955, 0.02135913260281086, 0.002939940430223942, -0.0848405584692955, -0.012621789239346981, 0.008306329138576984, -0.00119060929864645, -0.026073679327964783, 0.0338638573884964, -0.0543183907866478, -0.030288036912679672, -0.009088539518415928, 0.026201386004686356, 0.008066876791417599, -0.007736965082585812, -0.0110254418104887, 0.02171032875776291, -0.055723175406455994, -0.01462254486978054, -0.04746473953127861, 0.03671599552035332, 0.005667034070938826, -0.00011423863179516047, -0.04280340299010277, -0.028159573674201965, -0.003187374211847782, -0.04950806125998497, 0.04384635016322136, -0.03554534167051315, 0.033502016216516495, -0.023753654211759567, 0.03452368080615997, -0.002737736329436302, -0.012887846678495407, -0.016974497586488724, -0.04486801102757454, -0.02664836496114731, 0.005251984111964703, -0.0361625961959362, -0.005081706680357456, 0.04376121237874031, 0.05602116137742996, -0.01041350793093443, 0.021050505340099335, -0.08509597182273865, 0.03605617210268974, -0.049976326525211334, -0.03224622458219528, 0.004719867836683989, -0.04239899292588234, -0.012472796253859997, 0.05682997778058052, -0.015888981521129608, 0.027116626501083374, -0.03358715400099754, 0.01019534096121788, -0.002250850200653076, 0.0012391648488119245, 0.003586461069062352, 0.017112847417593002, -0.028755543753504753, 0.006922828033566475, -0.0714312344789505, 0.0048874844796955585, -0.004256926942616701, 0.005986304022371769, 0.0313948392868042, 0.08709672838449478, 0.015793200582265854, -0.018315428867936134, 0.06585466116666794, -0.0025860832538455725, -0.021082431077957153, -0.02479660138487816, 0.025711840018630028, 0.021720970049500465, -0.0037221508100628853, -0.021401701495051384, -0.04435718059539795, -0.02798929624259472, 0.00031561125069856644, -0.01827285997569561, 0.02047581970691681, -0.010339011438190937, 0.007955132983624935, 0.01394143607467413, -0.005454187747091055, 0.07717809081077576 ]
30,693
networkx.readwrite.pajek
generate_pajek
Generate lines in Pajek graph format. Parameters ---------- G : graph A Networkx graph References ---------- See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.
def generate_pajek(G): """Generate lines in Pajek graph format. Parameters ---------- G : graph A Networkx graph References ---------- See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information. """ if G.name == "": name = "NetworkX" else: name = G.name # Apparently many Pajek format readers can't process this line # So we'll leave it out for now. # yield '*network %s'%name # write nodes with attributes yield f"*vertices {G.order()}" nodes = list(G) # make dictionary mapping nodes to integers nodenumber = dict(zip(nodes, range(1, len(nodes) + 1))) for n in nodes: # copy node attributes and pop mandatory attributes # to avoid duplication. na = G.nodes.get(n, {}).copy() x = na.pop("x", 0.0) y = na.pop("y", 0.0) try: id = int(na.pop("id", nodenumber[n])) except ValueError as err: err.args += ( ( "Pajek format requires 'id' to be an int()." " Refer to the 'Relabeling nodes' section." ), ) raise nodenumber[n] = id shape = na.pop("shape", "ellipse") s = " ".join(map(make_qstr, (id, n, x, y, shape))) # only optional attributes are left in na. for k, v in na.items(): if isinstance(v, str) and v.strip() != "": s += f" {make_qstr(k)} {make_qstr(v)}" else: warnings.warn( f"Node attribute {k} is not processed. {('Empty attribute' if isinstance(v, str) else 'Non-string attribute')}." ) yield s # write edges with attributes if G.is_directed(): yield "*arcs" else: yield "*edges" for u, v, edgedata in G.edges(data=True): d = edgedata.copy() value = d.pop("weight", 1.0) # use 1 as default edge value s = " ".join(map(make_qstr, (nodenumber[u], nodenumber[v], value))) for k, v in d.items(): if isinstance(v, str) and v.strip() != "": s += f" {make_qstr(k)} {make_qstr(v)}" else: warnings.warn( f"Edge attribute {k} is not processed. {('Empty attribute' if isinstance(v, str) else 'Non-string attribute')}." ) yield s
(G)
[ 0.03227005898952484, 0.010722528211772442, -0.016442451626062393, 0.006735350005328655, -0.01789572276175022, -0.03171110898256302, -0.08220294862985611, -0.0012459931895136833, 0.09569227695465088, 0.00898512452840805, -0.005747871473431587, 0.014178703539073467, 0.02088610641658306, 0.11894460767507553, -0.03853030130267143, 0.006241610739380121, 0.017122508957982063, -0.005938846152275801, -0.004928077571094036, 0.028506461530923843, -0.000959531229455024, -0.065322645008564, 0.027407191693782806, 0.017029350623488426, 0.029736151918768883, 0.004091981332749128, 0.03737513720989227, 0.02917720191180706, -0.0402071513235569, -0.013712911866605282, -0.02002904936671257, -0.0771351307630539, -0.03344385325908661, -0.03301532566547394, 0.027984773740172386, 0.0618198923766613, -0.04721266031265259, 0.006516427733004093, -0.09487248212099075, -0.03681618720293045, 0.06442832946777344, 0.02241390384733677, 0.001151088043116033, -0.054069116711616516, -0.03286627307534218, 0.012138535268604755, 0.011859060265123844, 0.08600381016731262, -0.05786997824907303, -0.024798758327960968, -0.003628518432378769, -0.016675347462296486, 0.00657232291996479, 0.04057978466153145, -0.024836020544171333, -0.0189763605594635, -0.007289642468094826, 0.04315095767378807, 0.03355564549565315, -0.02355043590068817, -0.016749875620007515, 0.004033757373690605, 0.041175998747348785, 0.0258793942630291, -0.02565581537783146, 0.0016628769226372242, -0.029307622462511063, -0.070353202521801, -0.025339076295495033, 0.002936817705631256, 0.04847961664199829, -0.003763598157092929, 0.01807272434234619, 0.014038966037333012, 0.04467875510454178, 0.01012631505727768, -0.06051567569375038, 0.017998196184635162, 0.010051787830889225, -0.018175197765231133, -0.01491465512663126, 0.027351297438144684, -0.010228789411485195, -0.04177221283316612, 0.051199838519096375, 0.013163277879357338, 0.06644055247306824, 0.03538154810667038, -0.004213087260723114, -0.04337453842163086, -0.00779735529795289, 0.0014905339339748025, 0.015976659953594208, -0.016945507377386093, -0.0007225595763884485, 0.0033164380583912134, -0.005631423555314541, -0.06945887953042984, 0.022302113473415375, -0.01854783110320568, -0.00021601097250822932, 0.016843033954501152, -0.052131421864032745, -0.015110287815332413, -0.03681618720293045, -0.00814204104244709, -0.037132926285266876, 0.048591405153274536, 0.04639286920428276, -0.036424923688173294, -0.04777161031961441, 0.05526154488325119, 0.043635379523038864, -0.0376918762922287, 0.026065710932016373, -0.005193579010665417, 0.0056453971192240715, -0.011467794887721539, 0.009269258007407188, -0.05123710259795189, -0.010107683017849922, 0.017905037850141525, -0.08428969234228134, 0.0570501871407032, -0.001623284537345171, -0.02809656411409378, 0.04915035516023636, 0.010433737188577652, 0.011123109608888626, -0.0713593140244484, 0.021351898089051247, 0.05265311151742935, 0.03798998147249222, -0.0029018830973654985, -0.031077632680535316, -0.0648382231593132, -0.06196894869208336, -0.03810177370905876, 0.027500350028276443, 0.03636902570724487, 0.01527797244489193, -0.0731106847524643, 0.02045757882297039, 0.01625613495707512, -0.03702113777399063, -0.05936051160097122, 0.007899830117821693, -0.05809355899691582, 0.004126915708184242, -0.006581638939678669, 0.05850345641374588, 0.017383351922035217, 0.029885204508900642, -0.012147851288318634, 0.046206552535295486, -0.03979725390672684, -0.032810378819704056, 0.027910247445106506, 0.015948712825775146, -0.007499248720705509, -0.0319160558283329, -0.02226484939455986, 0.09822618216276169, 0.05261584743857384, -0.02982931025326252, 0.05179605260491371, 0.0001143373447121121, -0.0028296855743974447, 0.026606030762195587, -0.004525167867541313, 0.019339676946401596, -0.0789237692952156, -0.0904754102230072, -0.02817109040915966, -0.00027525387122295797, 0.02845056541264057, 0.0439707487821579, 0.053063008934259415, 0.025450866669416428, 0.008966493420302868, -0.0329221673309803, -0.02731403335928917, 0.012995592318475246, 0.0319160558283329, 0.0022672417107969522, -0.04315095767378807, 0.023867174983024597, -0.013088750652968884, 0.01771872118115425, -0.05772092565894127, -0.03355564549565315, 0.04091515764594078, 0.0037449663504958153, 0.10210157185792923, 0.012082640081644058, 0.008770860731601715, 0.045871179550886154, 0.0005545834428630769, -0.02968025580048561, 0.07448942959308624, 0.019861364737153053, 0.01429980993270874, 0.01344275288283825, -0.0190974660217762, -0.0031650555320084095, 0.013489332050085068, -0.01932104490697384, -0.003684413619339466, -0.022786537185311317, 0.017932986840605736, 0.047957926988601685, -0.02068115770816803, 0.03938736021518707, 0.005608133971691132, -0.012101272121071815, 0.017532404512166977, -0.033686067909002304, 0.06565801799297333, -0.03184153139591217, -0.024016227573156357, -0.05533607304096222, 0.006483822595328093, -0.010797055438160896, -0.030015626922249794, 0.0394618846476078, -0.04482780769467354, 0.06431654095649719, 0.02630792371928692, -0.004564760252833366, -0.04806971922516823, 0.07296163588762283, 0.026643292978405952, 0.0025874737184494734, 0.020792948082089424, 0.01044305320829153, -0.03150616213679314, -0.03363016992807388, 0.01020084135234356, -0.07620354741811752, 0.004383101128041744, -0.022451167926192284, -0.05839166417717934, -0.03405870124697685, -0.02954983524978161, 0.021929480135440826, 0.039871782064437866, 0.05034278333187103, -0.026047080755233765, -0.006982219871133566, 0.020345788449048996, -0.029419412836432457, -0.02839467115700245, 0.014691074378788471, 0.0031161473598331213, -0.01044305320829153, -0.008868676610291004, -0.0412132628262043, -0.042182110249996185, 0.030015626922249794, 0.009068966843187809, -0.012008113786578178, 0.011160372756421566, -0.1007600948214531, 0.03968546539545059, 0.09576680511236191, 0.012874486856162548, -0.027835721150040627, 0.02081158012151718, -0.01635861024260521, -0.007676249835640192, 0.05254131928086281, 0.03905198723077774, -0.035195231437683105, 0.011607532389461994, 0.013014224357903004, 0.03784092888236046, -0.044119805097579956, 0.06789381802082062, -0.040318943560123444, -0.006087899208068848, -0.028841830790042877, 0.0113094262778759, 0.01527797244489193, 0.03262406215071678, -0.0675957128405571, -0.01631203107535839, -0.007094009779393673, 0.00462298421189189, 0.007429379969835281, -0.06073925644159317, 0.04669097438454628, 0.010275368578732014, -0.022283481433987617, -0.0319160558283329, 0.07378143072128296, 0.018929781392216682, 0.00437145633623004, -0.02176179550588131, -0.025544025003910065, -0.04553581029176712, 0.09256215393543243, -0.05872703716158867, 0.12908023595809937, -0.025171391665935516, -0.0016686993185430765, 0.05500070005655289, -0.005924872122704983, -0.013042171485722065, 0.024239808320999146, -0.0016291069332510233, -0.07460122555494308, -0.005216868594288826, 0.05187058076262474, 0.019637783989310265, -0.03307121992111206, 0.009120204485952854, 0.04180947691202164, -0.016414504498243332, 0.081904835999012, 0.0046416157856583595, -0.017905037850141525, 0.044119805097579956, 0.0190974660217762, 0.018184512853622437, -0.03523249551653862, 0.019656416028738022, -0.004569417797029018, 0.05701292306184769, 0.02515275962650776, -0.04162316024303436, -0.014160072430968285, 0.03273585066199303, -0.04028167948126793, 0.036201342940330505, -0.05455354228615761, 0.04922488331794739, 0.024836020544171333, -0.034040067344903946, -0.008626464754343033, -0.07396774739027023, 0.05142341926693916, -0.03359290957450867, -0.04575939103960991, 0.030015626922249794, 0.053212061524391174, 0.03681618720293045, -0.00252924975939095, -0.030965842306613922, -0.028934989124536514, 0.08816508203744888, 0.01318190898746252, 0.0831717923283577, 0.032456375658512115, 0.03446859493851662, 0.004359811544418335, 0.032530903816223145, -0.00657232291996479, -0.04669097438454628, -0.05924872308969498, 0.08406611531972885, 0.01862235739827156, -0.006926324684172869, 0.019861364737153053, 0.04270379617810249, -0.014327757060527802, -0.02578623592853546, 0.03681618720293045, 0.008691675961017609, 0.07735870778560638, -0.007676249835640192, -0.003416583174839616, -0.026196133345365524, -0.07810397446155548, -0.03581007570028305, -0.012520484626293182, 0.039238303899765015, 0.014495442621409893, 0.006497796159237623, -0.017327455803751945, -0.006991535425186157, 0.02068115770816803, -0.030350996181368828, 0.03849303722381592, 0.0374496653676033, 0.011328057385981083, -0.05775818973779678, 0.09338194876909256, -0.003346714423969388, -0.024183912202715874, -0.02573034167289734, -0.020792948082089424, 0.0023825252428650856, 0.08913392573595047, 0.016572874039411545, -0.0002045117289526388, -0.04885224997997284, 0.03329480066895485, 0.02176179550588131, -0.06450285762548447, -0.003176700323820114, -0.028040669858455658, -0.04400801286101341, -0.04490233585238457, 0.01782119646668434, 0.00508178910240531, -0.08056335896253586, 0.03724471479654312, -0.031599320471286774, 0.031170791015028954, 0.04486507177352905, 0.05023099109530449, 0.019581889733672142, -0.01653560996055603, -0.011393268592655659, 0.0422193743288517, 0.00891059823334217, 0.002538565546274185, -0.01167274359613657, 0.03487849235534668, 0.03471080958843231, -0.00479299807921052, 0.0035307020880281925, 0.04810698330402374, 0.01866893656551838, 0.045349493622779846, 0.010946108028292656, -0.037132926285266876, 0.01917199231684208, -0.04065431281924248, 0.06133547052741051, -0.01159821730107069, -0.07352058589458466, 0.008258489891886711, -0.009930682368576527, -0.01628408208489418, -0.005887608975172043, 0.013992386870086193, -0.0329221673309803, 0.032829008996486664, -0.010228789411485195, 0.048814985901117325, -0.030779525637626648, -0.00008930102922022343, -0.03430091217160225, 0.034561753273010254, -0.01932104490697384, -0.005589501932263374, 0.007606381084769964, -0.00387305929325521, 0.03968546539545059, 0.014504757709801197, 0.021165581420063972, 0.042405690997838974, -0.05928598716855049, -0.0037752429489046335, 0.024593809619545937, 0.0836934819817543, -0.04818150773644447, -0.06808013468980789, 0.04691455513238907, 0.06398116797208786, 0.018752779811620712, 0.045871179550886154, 0.021146949380636215, 0.022805169224739075, -0.02925172820687294, 0.009818891994655132, 0.02960572950541973, -0.02759350836277008, -0.033183012157678604, -0.0015091656241565943, -0.021650005131959915, -0.04885224997997284, -0.04136231541633606, 0.012268957681953907, -0.0007400268223136663, -0.05563417822122574, 0.017020033672451973, -0.032475005835294724, -0.018855253234505653, -0.040169887244701385, -0.042107582092285156, 0.04695181921124458, 0.01344275288283825, 0.006115846801549196, 0.042256634682416916, 0.017103876918554306, -0.026978664100170135, -0.03471080958843231, -0.03327617049217224, 0.0014066913863644004, -0.030090153217315674, -0.022581588476896286, 0.0025525393430143595, 0.009362416341900826, 0.0356796570122242, 0.007694881409406662, -0.0002631724055390805, -0.048889514058828354, -0.08212842047214508, -0.015054392628371716, -0.01048963237553835, -0.007005509454756975, -0.04013262689113617, 0.04877772182226181, 0.005426474846899509, 0.01746719516813755, 0.011663427576422691, 0.034915756434202194, 0.03564239293336868, -0.004441325087100267, -0.030425524339079857, 0.008798807859420776, -0.00020101829431951046, -0.001901595271192491, 0.018380146473646164, 0.00751322228461504, 0.03010878525674343, 0.00042794624459929764, -0.0422193743288517, 0.05064088851213455, -0.02405349165201187, 0.027146348729729652, 0.03221416473388672, -0.07057677954435349, 0.09740638732910156, -0.0003810759517364204, -0.010657317005097866, 0.02621476538479328, 0.009464890696108341, 0.009967945516109467, 0.05343564227223396, 0.0268855057656765, 0.048442352563142776, -0.01575308106839657, 0.009939998388290405, 0.028059300035238266, 0.031655214726924896, 0.03458038717508316, -0.005747871473431587, 0.01631203107535839, 0.03148752823472023, -0.04821877181529999, -0.006781929172575474, 0.005873635411262512, 0.03200921416282654, 0.05902514234185219, -0.005254132207483053, -0.0008733597351238132, -0.07005509734153748, 0.0005088775651529431, 0.02414664998650551, 0.015846239402890205, 0.008048882707953453, 0.07039046287536621, 0.04941119998693466, 0.016712611541152, -0.013638385571539402, 0.0022043599747121334, -0.0009781628614291549, -0.037785034626722336, 0.0009146987576968968, -0.038008615374565125, -0.06748392432928085, 0.027109084650874138, 0.005268105771392584, -0.01773735322058201, -0.032884903252124786, -0.009539416991174221, -0.02060663141310215, 0.044790543615818024, 0.011970850639045238, 0.0577954538166523, -0.035847339779138565, -0.050119202584028244, -0.028003405779600143, -0.07396774739027023, 0.0038870328571647406, -0.004199113696813583, -0.010610737837851048, -0.0025129469577223063, 0.03344385325908661, 0.012455274350941181, -0.011980166658759117, 0.05552238970994949, 0.02118421345949173, 0.01044305320829153, 0.008384252898395061, 0.03579144552350044, 0.0027039216365665197, -0.013414804823696613, -0.008374937810003757, 0.018790043890476227, -0.04177221283316612, -0.027220875024795532, -0.011216267943382263, 0.06778202950954437, -0.011458479799330235, -0.045871179550886154, -0.030723629519343376, -0.05470259487628937, 0.05511249229311943, 0.01470039039850235, 0.009688470512628555, 0.0036401632241904736, -0.002401157049462199, -0.0021309976000338793, 0.00871962308883667, 0.023028748109936714, -0.025040969252586365, 0.015380446799099445, 0.05798177048563957, -0.0077414605766534805, -0.108063705265522, -0.04922488331794739, -0.019470099359750748, -0.022283481433987617, 0.0018235751194879413, -0.003363017225638032, -0.03968546539545059, 0.001580198877491057, -0.027425823733210564, -0.025376340374350548, -0.010014524683356285, -0.018128618597984314, 0.005286737345159054, 0.027910247445106506, -0.06975698471069336, 0.006465191021561623, -0.021221475675702095, 0.022451167926192284, -0.045498546212911606, -0.014849443919956684, -0.02681097947061062, 0.004487904254347086, -0.03076089359819889, -0.0051330262795090675, 0.0061205048114061356, -0.04259200766682625, 0.014597916044294834, -0.037486929446458817, 0.008076830767095089, -0.06740939617156982, -0.047510769218206406, -0.013852649368345737, 0.017029350623488426, 0.012585695832967758, -0.053063008934259415, 0.01646108366549015, -0.04501412436366081, 0.021221475675702095, 0.009679154492914677, -0.0008221226162277162, -0.03841851279139519, 0.018082039430737495, 0.05839166417717934, -0.00601803045719862, -0.0017397325718775392, -0.005808424204587936, -0.043337274342775345, 0.037505559623241425, -0.028152458369731903, 0.022730642929673195, 0.02096063271164894, -0.01134668942540884, 0.013340278528630733, 0.004713813308626413, -0.01045236922800541, -0.01036852691322565, 0.007126615382730961, -0.05418090894818306, 0.015892818570137024, 0.01723429746925831, -0.044343382120132446, -0.05425543338060379, -0.014905339106917381, 0.01834288239479065, -0.00022649129095952958, 0.017597615718841553, -0.021370530128479004, 0.015641290694475174, 0.02586076408624649, 0.009395021945238113, -0.05216868594288826, -0.03661124035716057, -0.006567664910107851, 0.0008925736183300614, -0.00871962308883667, -0.0021216818131506443, -0.03139436990022659, -0.033835120499134064, 0.0036075578536838293, 0.0522804781794548, 0.006563006900250912, 0.019265150651335716, -0.04106421023607254, 0.017951617017388344, -0.006875087507069111, -0.027649404481053352, -0.03251226991415024, 0.015361814759671688, -0.03025783784687519, -0.00655369134619832, 0.02817109040915966, -0.040542520582675934, 0.012464589439332485, -0.057161975651979446, 0.04862866923213005, -0.036573976278305054, 0.028208354488015175, -0.044641491025686264, 0.05064088851213455, 0.011570269241929054, -0.056230392307043076, 0.034114595502614975, -0.007322247605770826, -0.02040168270468712, 0.0374496653676033, -0.03957367688417435, 0.004725458100438118, -0.04188400134444237, 0.043635379523038864, 0.0007015989976935089, 0.032661322504282, -0.04546128585934639, 0.02435159683227539, -0.018259041011333466, -0.0789237692952156, 0.004217745270580053, -0.022227587178349495, 0.012259641662240028, 0.08525853604078293, -0.019581889733672142, -0.01437433622777462, -0.010620053857564926, -0.023457277566194534, -0.025953922420740128, 0.0053892116993665695, 0.011439847759902477, 0.00021062525047454983, -0.044343382120132446, 0.009632575325667858, -0.04717539995908737, -0.021650005131959915, 0.020550737157464027, -0.013945807702839375, 0.021594110876321793, 0.08205389231443405, -0.03882840648293495, 0.01650766283273697, 0.059472303837537766, 0.03098447434604168, -0.0034957677125930786, 0.006036662496626377, 0.026680557057261467, -0.05820534750819206, 0.040952417999506, -0.003812506329268217, -0.012268957681953907, -0.05216868594288826, -0.08138315379619598, -0.002401157049462199, 0.014188019558787346, 0.03083541989326477, 0.02118421345949173, -0.006260242313146591, 0.007652960252016783, 0.029065411537885666 ]
30,694
networkx.algorithms.similarity
generate_random_paths
Randomly generate `sample_size` paths of length `path_length`. Parameters ---------- G : NetworkX graph A NetworkX graph sample_size : integer The number of paths to generate. This is ``R`` in [1]_. path_length : integer (default = 5) The maximum size of the path to randomly generate. This is ``T`` in [1]_. According to the paper, ``T >= 5`` is recommended. index_map : dictionary, optional If provided, this will be populated with the inverted index of nodes mapped to the set of generated random path indices within ``paths``. weight : string or None, optional (default="weight") The name of an edge attribute that holds the numerical value used as a weight. If None then each edge has weight 1. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- paths : generator of lists Generator of `sample_size` paths each with length `path_length`. Examples -------- Note that the return value is the list of paths: >>> G = nx.star_graph(3) >>> random_path = nx.generate_random_paths(G, 2) By passing a dictionary into `index_map`, it will build an inverted index mapping of nodes to the paths in which that node is present: >>> G = nx.star_graph(3) >>> index_map = {} >>> random_path = nx.generate_random_paths(G, 3, index_map=index_map) >>> paths_containing_node_0 = [ ... random_path[path_idx] for path_idx in index_map.get(0, []) ... ] References ---------- .. [1] Zhang, J., Tang, J., Ma, C., Tong, H., Jing, Y., & Li, J. Panther: Fast top-k similarity search on large networks. In Proceedings of the ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (Vol. 2015-August, pp. 1445–1454). Association for Computing Machinery. https://doi.org/10.1145/2783258.2783267.
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G, sample_size, path_length=5, index_map=None, weight='weight', seed=None, *, backend=None, **backend_kwargs)
[ 0.04682670906186104, -0.042973026633262634, 0.00014764626394025981, 0.019369229674339294, -0.051442164927721024, -0.056684963405132294, -0.01874188520014286, -0.007528121583163738, 0.01817055605351925, -0.0645267590880394, -0.04120302200317383, 0.008105053566396236, -0.008620371110737324, 0.05565432831645012, -0.011516233906149864, -0.005436043255031109, -0.001982853515073657, -0.06242067366838455, 0.03224097192287445, 0.0031731256749480963, -0.027692733332514763, -0.08321262896060944, 0.032084137201309204, 0.03916415572166443, -0.04389163851737976, -0.0009606196545064449, 0.04597531259059906, 0.01452972274273634, 0.02908184938132763, -0.009174898266792297, 0.006783151067793369, -0.06788752228021622, -0.06264472752809525, 0.0061278012581169605, -0.031591225415468216, 0.005634888540953398, 0.04180796071887016, 0.01990695297718048, 0.014888204634189606, -0.05112849175930023, -0.04906722158193588, -0.014843394048511982, -0.013801556080579758, -0.03788706287741661, 0.04718519002199173, 0.03593781962990761, -0.0442725233733654, 0.006234225817024708, -0.015560357831418514, -0.018069732934236526, 0.015829220414161682, -0.12699224054813385, -0.045370373874902725, 0.03802149370312691, 0.009376544505357742, 0.021475311368703842, 0.009510975331068039, 0.0422784686088562, 0.05350343510508537, -0.0886346697807312, 0.025138547644019127, -0.03613946586847305, -0.017991313710808754, 0.031680844724178314, -0.05789484083652496, -0.00446702167391777, -0.031658440828323364, -0.04158391058444977, 0.02234910987317562, 0.03349566087126732, -0.052652038633823395, 0.011449018493294716, 0.051083680242300034, -0.07967261970043182, -0.000002964740360766882, 0.011269777081906796, 0.013353453949093819, -0.02301006205379963, -0.0055396668612957, -0.02504892833530903, 0.010446389205753803, -0.040934160351753235, 0.04709557071328163, -0.07209968566894531, 0.07375766336917877, 0.0023581392597407103, 0.030515778809785843, 0.01874188520014286, -0.04718519002199173, -0.07904527336359024, 0.0042429701425135136, -0.030022865161299706, -0.017845680937170982, 0.015347509644925594, 0.038133520632982254, 0.009807842783629894, -0.024331964552402496, -0.05493736267089844, 0.015392320230603218, 0.002192901447415352, 0.06479562073945999, 0.056640151888132095, -0.03197211027145386, 0.024376774206757545, 0.009225309826433659, -0.07725286483764648, -0.04151669517159462, 0.05511660501360893, 0.02737906016409397, -0.06134522706270218, -0.05758116766810417, 0.030157295987010002, 0.04142707213759422, -0.026281209662556648, -0.010362369939684868, 0.014899407513439655, -0.042592138051986694, 0.018730683252215385, -0.018842708319425583, 0.009555784985423088, 0.00995347648859024, -0.014036810025572777, -0.03354046866297722, 0.032465025782585144, 0.013868771493434906, -0.049022410064935684, 0.008502744138240814, 0.06954549998044968, 0.024018293246626854, -0.07532602548599243, 0.016803842037916183, -0.06743942201137543, 0.00999828614294529, 0.10136077553033829, -0.0012042754096910357, -0.013006174005568027, -0.03748377040028572, 0.009662209078669548, 0.01833859272301197, 0.022046642377972603, 0.03143438696861267, -0.039769094437360764, -0.00765695096924901, -0.00573571166023612, -0.017968909814953804, -0.0522935576736927, 0.01152743585407734, -0.019470052793622017, 0.007752172648906708, 0.008082648739218712, -0.021508919075131416, 0.005108368117362261, 0.001975851831957698, -0.009578190743923187, 0.025295384228229523, -0.007309671491384506, -0.00019656994845718145, -0.010468794032931328, -0.003923697397112846, 0.015280294232070446, -0.004581847693771124, -0.0484846867620945, 0.0020108597818762064, 0.011505031026899815, 0.05368267744779587, -0.01850663125514984, 0.04568404704332352, 0.007976223714649677, -0.07913489639759064, 0.00585333863273263, -0.03219616413116455, -0.046602655202150345, -0.07460906356573105, -0.014193645678460598, 0.018943531438708305, 0.01651257649064064, -0.009018062613904476, -0.02614677883684635, 0.00726486137136817, -0.016546184197068214, 0.02820805087685585, 0.013767948374152184, 0.04920165240764618, 0.05077001079916954, -0.0012833934742957354, 0.059821680188179016, 0.030112486332654953, -0.02742387168109417, 0.02272999845445156, -0.022449932992458344, -0.020702334120869637, -0.06313763558864594, -0.012513261288404465, 0.050590768456459045, 0.03320439159870148, 0.028544127941131592, -0.0051895868964493275, 0.03900732100009918, 0.004077732563018799, 0.07904527336359024, -0.030739828944206238, -0.012289210222661495, 0.06551258265972137, 0.007477710023522377, 0.03154641389846802, -0.0026031953748315573, 0.029261091724038124, -0.018439415842294693, 0.011986740864813328, 0.029283495619893074, -0.04906722158193588, 0.028006404638290405, 0.027737542986869812, -0.001726594869978726, 0.026774123311042786, 0.03871605172753334, -0.0343918651342392, 0.04006035998463631, -0.020679928362369537, -0.032420214265584946, 0.013252630829811096, -0.019257202744483948, -0.015112255699932575, -0.011818702332675457, 0.04138226434588432, -0.05619204789400101, 0.0095613868907094, 0.028006404638290405, 0.048126205801963806, -0.044138092547655106, 0.008009831421077251, -0.07895565778017044, 0.04911202937364578, -0.016053270548582077, 0.04039643704891205, -0.02865615300834179, -0.027155010029673576, 0.025900322943925858, 0.03468313068151474, -0.0013092993758618832, -0.0727270320057869, -0.05350343510508537, -0.03737174719572067, 0.00824508536607027, -0.004326989408582449, -0.0008121857536025345, 0.041359856724739075, -0.008805213496088982, -0.01117455493658781, 0.008267490193247795, -0.017610426992177963, -0.03535528481006622, -0.00989186204969883, -0.007248057518154383, -0.0403740331530571, -0.003632430685684085, -0.04104618728160858, 0.042121633887290955, -0.01250205934047699, -0.005192387383431196, 0.016333334147930145, 0.008810814470052719, -0.04321948438882828, 0.02141929790377617, 0.02383905090391636, 0.023099683225154877, 0.028364885598421097, 0.013006174005568027, -0.06941106915473938, -0.02735665626823902, 0.03678921237587929, 0.07559488713741302, -0.032868314534425735, 0.06080750375986099, -0.017924098297953606, 0.010737655684351921, -0.002764232223853469, 0.018473023548722267, -0.01168427150696516, -0.04718519002199173, -0.030515778809785843, -0.007679356262087822, -0.04140466824173927, 0.014608140103518963, -0.03667718544602394, -0.015425927937030792, -0.02903703972697258, -0.026908554136753082, 0.014955420047044754, 0.0012700904626399279, 0.04104618728160858, -0.01814815029501915, 0.0422784686088562, 0.03298034146428108, 0.08679744601249695, 0.03750617802143097, 0.01914517767727375, 0.0020654723048210144, -0.03876086324453354, 0.06484042853116989, 0.03062780387699604, -0.04312986135482788, 0.027894379571080208, -0.058298129588365555, 0.01530269905924797, 0.014776178635656834, 0.01493301521986723, -0.013420669361948967, 0.049336083233356476, 0.05126292258501053, -0.0341678149998188, -0.028320075944066048, -0.042973026633262634, 0.03298034146428108, -0.021856198087334633, -0.0027558302972465754, -0.00818347092717886, -0.015694789588451385, 0.07994148135185242, -0.007886603474617004, -0.024421583861112595, 0.029619572684168816, -0.008911637589335442, 0.020343851298093796, -0.04138226434588432, -0.04017238691449165, 0.039791498333215714, 0.03871605172753334, 0.05283128097653389, -0.00446702167391777, 0.00824508536607027, -0.01491060946136713, 0.02500411868095398, 0.013644720427691936, -0.0018792296759784222, 0.035691361874341965, 0.04550480470061302, -0.014843394048511982, -0.01831618882715702, 0.008810814470052719, 0.10395977646112442, 0.07496754080057144, -0.012759718112647533, 0.011953133158385754, 0.012838135473430157, -0.004943130537867546, 0.0483950674533844, -0.026370830833911896, -0.06125560775399208, -0.008334705606102943, -0.03255464509129524, 0.02659488096833229, -0.014585735276341438, -0.03495199233293533, 0.0032991543412208557, 0.05000823736190796, 0.02336854301393032, -0.07590855658054352, 0.04115821048617363, -0.03273388370871544, -0.009886261075735092, 0.008228281512856483, -0.005718907807022333, -0.04225606471300125, -0.02540740929543972, 0.02296525239944458, -0.03320439159870148, -0.01591883972287178, 0.053458623588085175, -0.07442981749773026, 0.03280109912157059, -0.0282528605312109, 0.06887335330247879, 0.019604483619332314, -0.02775994874536991, 0.016478968784213066, -0.051083680242300034, 0.023301327601075172, -0.03300274536013603, 0.024780066683888435, 0.038984913378953934, 0.024847282096743584, -0.014227253384888172, 0.043376319110393524, -0.0056768981739878654, -0.02704298496246338, 0.05955281853675842, 0.03537768870592117, 0.03475034609436989, 0.02097119577229023, -0.02211385779082775, 0.013263832777738571, 0.05287609249353409, -0.0032403410878032446, 0.003399977460503578, 0.008715593256056309, 0.06708093732595444, 0.05005304515361786, -0.07330956310033798, -0.03461591526865959, -0.04624417424201965, 0.03436946123838425, -0.0037080480251461267, 0.011773892678320408, 0.006391061469912529, -0.02896982431411743, 0.03423503041267395, 0.03672199696302414, 0.017733655869960785, 0.06215181201696396, -0.07209968566894531, 0.013599909842014313, 0.03672199696302414, 0.02424234338104725, -0.06197257339954376, -0.0403292216360569, -0.04610974341630936, 0.033742114901542664, 0.05112849175930023, -0.011605854146182537, 0.013398263603448868, 0.00024610626860521734, 0.001900234492495656, -0.04610974341630936, -0.015717193484306335, -0.055430274456739426, -0.013599909842014313, -0.0018302184762433171, -0.022237084805965424, -0.0025233770720660686, -0.02894742041826248, -0.014955420047044754, 0.04570645093917847, -0.027603112161159515, -0.041718341410160065, -0.02374943159520626, 0.043802015483379364, 0.0051335738971829414, 0.0804792046546936, 0.003301955061033368, 0.011549841612577438, -0.01289414893835783, 0.016288524493575096, -0.03022451139986515, -0.03582579270005226, -0.034436676651239395, -0.012334020808339119, 0.012860541231930256, -0.030784640461206436, -0.0061278012581169605, 0.04384682700037956, 0.02581070177257061, -0.010620028711855412, 0.0073208739049732685, -0.04723000153899193, 0.012233197689056396, -0.013308643363416195, 0.007892204448580742, -0.08254047483205795, 0.04151669517159462, 0.005013146437704563, 0.009006859734654427, 0.05677458271384239, 0.03678921237587929, -0.0363859198987484, 0.035288069397211075, 0.06649840623140335, -0.005791724193841219, -0.028454506769776344, -0.011101738549768925, 0.003447588300332427, -0.0923987329006195, -0.08392959088087082, -0.036072250455617905, 0.03540009632706642, 0.026303615421056747, -0.012916553765535355, 0.007074417546391487, -0.03219616413116455, -0.011986740864813328, 0.02294284664094448, -0.04964975267648697, 0.009807842783629894, -0.023480569943785667, 0.032420214265584946, 0.0051111686043441296, 0.03817833214998245, -0.024376774206757545, -0.06295839697122574, -0.026751717552542686, -0.03268907591700554, -0.049784183502197266, 0.00899005588144064, -0.013207820244133472, 0.0008653979166410863, 0.042592138051986694, -0.014652950689196587, -0.058656614273786545, 0.01772245205938816, -0.030112486332654953, -0.010132716968655586, 0.012737312354147434, -0.040418840944767, 0.025900322943925858, 0.03154641389846802, -0.025698676705360413, -0.022517148405313492, 0.05973206087946892, 0.0019142377423122525, 0.003741655731573701, 0.020623916760087013, -0.03907453641295433, 0.09100960940122604, 0.04243530333042145, -0.0008191873203031719, 0.026930958032608032, 0.02016461081802845, 0.013140604831278324, 0.031658440828323364, -0.03302515298128128, -0.008385117165744305, 0.002232110360637307, 0.025071334093809128, -0.0031731256749480963, 0.01129218190908432, 0.03591541200876236, 0.026438046246767044, -0.008228281512856483, 0.021464107558131218, -0.04619936645030975, -0.0302693210542202, 0.05085963010787964, 0.024511205032467842, 0.03190489485859871, 0.010446389205753803, 0.038872890174388885, 0.08567719161510468, -0.04727480933070183, -0.08531870692968369, -0.013174212537705898, 0.01327503565698862, 0.03098628669977188, 0.012468451634049416, 0.017834478989243507, -0.015672383829951286, 0.03533288091421127, 0.06313763558864594, -0.034862373024225235, -0.029709193855524063, -0.040911756455898285, -0.014036810025572777, 0.04568404704332352, 0.0363411121070385, 0.026505261659622192, 0.002426754916086793, 0.013252630829811096, -0.03266666829586029, -0.013711935840547085, 0.02614677883684635, 0.012670096941292286, -0.03237540274858475, -0.03699085861444473, 0.01029515452682972, -0.016120485961437225, 0.0424577072262764, 0.008071445859968662, -0.008564358577132225, 0.014048011973500252, 0.013633517548441887, 0.032397810369729996, -0.04277138039469719, 0.02052309364080429, 0.0262364000082016, -0.03419021889567375, -0.06896296888589859, -0.04563923552632332, -0.04447416961193085, 0.0002581840381026268, 0.010323160327970982, -0.06811157613992691, 0.011006517335772514, 0.034055788069963455, 0.04619936645030975, 0.045370373874902725, 0.04956013336777687, 0.04006035998463631, -0.05816369876265526, 0.05852218344807625, -0.010446389205753803, -0.024466395378112793, 0.019750116392970085, 0.010620028711855412, 0.01746479421854019, -0.010121514089405537, -0.027580706402659416, 0.025698676705360413, -0.030874259769916534, 0.08612529188394547, 0.008962049148976803, -0.023547785356640816, -0.06815638393163681, -0.05193507671356201, 0.043398723006248474, -0.009169296361505985, -0.02894742041826248, 0.013062186539173126, 0.02035505510866642, -0.03777503967285156, 0.014440102502703667, -0.01935802586376667, 0.04478784278035164, 0.026505261659622192, 0.007612140849232674, -0.03885048255324364, -0.10557293891906738, -0.03134476765990257, -0.019414039328694344, 0.08195794373750687, -0.047812532633543015, -0.00517278304323554, -0.017498401924967766, 0.019257202744483948, 0.00545004615560174, -0.02984362468123436, -0.0170839074999094, 0.07855236530303955, 0.010082305409014225, 0.019649293273687363, -0.040530867874622345, 0.029574763029813766, -0.030493373051285744, -0.042547330260276794, 0.0021873002406209707, 0.05045633763074875, 0.021273665130138397, -0.06891816109418869, 0.07559488713741302, -0.0020318645983934402, -0.0323081873357296, 0.050635579973459244, -0.026057159528136253, 0.02177778072655201, -0.019794926047325134, 0.003290752414613962, -0.024376774206757545, 0.008995656855404377, 0.04118061810731888, -0.033652495592832565, 0.03380933031439781, 0.03392135724425316, 0.001585162477567792, 0.08119616657495499, -0.020646320655941963, -0.05274166166782379, 0.014328076504170895, 0.005550869274884462, -0.05726749449968338, -0.03589300811290741, 0.011941931210458279, -0.00564609095454216, 0.028925014659762383, 0.032890722155570984, 0.06121079623699188, -0.0444069541990757, -0.03817833214998245, -0.00032784996437840164, 0.07532602548599243, 0.007819388061761856, 0.02260676957666874, 0.05041152611374855, -0.056281670928001404, -0.05520622432231903, 0.0039937132969498634, 0.009029264561831951, -0.030538182705640793, -0.04550480470061302, 0.04606493562459946, 0.010468794032931328, -0.019884547218680382, -0.010642433539032936, 0.08146502822637558, 0.07115866988897324, 0.004486626014113426, -0.02585551328957081, 0.010188729502260685, 0.05197988823056221, -0.04279378429055214, -0.01755441352725029, 0.05695382505655289, 0.00009364641300635412, 0.015369914472103119, -0.04073251411318779, 0.03414540737867355, -0.012177184224128723, 0.01997416839003563, 0.016647007316350937, -0.03338363394141197, 0.033674899488687515, 0.0015767605509608984, 0.006335048470646143, 0.01119696069508791, 0.014384089037775993, -0.03553452715277672, 0.00989186204969883, -0.007824989035725594, -0.007113626692444086, -0.08271971344947815, 0.017251944169402122, -0.006391061469912529, -0.0170839074999094, -0.003349565900862217, -0.02498171292245388, 0.012210791930556297, 0.012065159156918526, 0.027961594983935356, -0.010015089996159077, -0.0018722281092777848, -0.03215135261416435, -0.026505261659622192, 0.0014262261101976037, 0.004142147023230791, -0.019324418157339096, 0.038066305220127106, 0.016232512891292572, -0.016434157267212868, 0.04057567939162254, 0.0007421697373501956, -0.08433288335800171, 0.013375858776271343, -0.015369914472103119, -0.009494171477854252, 0.080837681889534, 0.022091452032327652, 0.00034727941965684295, -0.03835757076740265, -0.0014703362248837948, -0.007354481611400843, -0.0564609095454216, -0.015627574175596237, 0.06322725862264633, -0.019862141460180283, 0.004080533050000668, -0.0323529988527298, 0.0033551673404872417, -0.05677458271384239, 0.06990398466587067, -0.05758116766810417, 0.0029714794363826513, -0.009695816785097122, 0.003943301737308502, 0.05189026519656181, -0.009679012931883335, 0.06331688165664673, 0.004458619747310877, 0.0362514890730381, 0.009314930066466331, -0.01786808669567108, -0.027177413925528526, -0.017207134515047073, -0.04048605635762215, 0.006038180552423, 0.0005436743376776576, -0.04669227823615074, 0.0011860711965709925, 0.005169982090592384, 0.0008878030348569155, -0.002178898314014077, 0.06927663832902908 ]
30,698
networkx.generators.geometric
geographical_threshold_graph
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 .. math:: (w_u + w_v)p_{dist}(r) \ge \theta where `r` is the distance between `u` and `v`, `p_dist` is any function of `r`, and :math:`\theta` as the threshold parameter. `p_dist` is used to give weight to the distance between nodes when deciding whether or not they should be connected. The larger `p_dist` is, the more prone nodes separated by `r` are to be connected, and vice versa. 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. .. _metric: https://en.wikipedia.org/wiki/Metric_%28mathematics%29 p_dist : function, optional Any function used to give weight to the distance between nodes when deciding whether or not they should be connected. `p_dist` was originally conceived as a probability density function giving the probability of connecting two nodes that are of metric distance `r` apart. The implementation here allows for more arbitrary definitions of `p_dist` that do not need to correspond to valid probability density functions. The :mod:`scipy.stats` package has many probability density functions implemented and tools for custom probability density definitions, and passing the ``.pdf`` method of scipy.stats distributions can be used here. If ``p_dist=None`` (the default), the exponential function :math:`r^{-2}` is used. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. pos_name : string, default="pos" The name of the node attribute which represents the position in 2D coordinates of the node in the returned graph. weight_name : string, default="weight" The name of the node attribute which represents the weight of the node in the returned graph. Returns ------- Graph 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. 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) .. _taxicab metric: https://en.wikipedia.org/wiki/Taxicab_geometry .. _Euclidean metric: https://en.wikipedia.org/wiki/Euclidean_distance 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. 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
def thresholded_random_geometric_graph( n, radius, theta, dim=2, pos=None, weight=None, p=2, seed=None, *, pos_name="pos", weight_name="weight", ): r"""Returns a thresholded random geometric graph in the unit cube. The thresholded random geometric graph [1] model places `n` nodes uniformly at random in the unit cube of dimensions `dim`. Each node `u` is assigned a weight :math:`w_u`. Two nodes `u` and `v` are joined by an edge if they are within the maximum connection distance, `radius` computed by the `p`-Minkowski distance and the summation of weights :math:`w_u` + :math:`w_v` is greater than or equal to the threshold parameter `theta`. Edges within `radius` of each other are determined using a KDTree when SciPy is available. This reduces the time complexity from :math:`O(n^2)` to :math:`O(n)`. Parameters ---------- n : int or iterable Number of nodes or iterable of nodes radius: float Distance threshold value theta: float Threshold value dim : int, optional Dimension of graph pos : dict, optional A dictionary keyed by node with node positions as values. weight : dict, optional Node weights as a dictionary of numbers keyed by node. p : float, optional (default 2) Which Minkowski distance metric to use. `p` has to meet the condition ``1 <= p <= infinity``. If this argument is not specified, the :math:`L^2` metric (the Euclidean distance metric), p = 2 is used. This should not be confused with the `p` of an Erdős-Rényi random graph, which represents probability. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. pos_name : string, default="pos" The name of the node attribute which represents the position in 2D coordinates of the node in the returned graph. weight_name : string, default="weight" The name of the node attribute which represents the weight of the node in the returned graph. Returns ------- Graph A thresholded random geographic 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 nodethre attribute ``'weight'`` that stores the weight of that node as provided or as generated. Examples -------- Default Graph: G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1) Custom Graph: Create a thresholded random geometric graph on 50 uniformly distributed nodes where nodes are joined by an edge if their sum weights drawn from a exponential distribution with rate = 5 are >= theta = 0.1 and their Euclidean distance is at most 0.2. Notes ----- This uses a *k*-d tree to build the graph. The `pos` keyword argument can be used to specify node positions so you can create an arbitrary distribution and domain for positions. For example, to use a 2D Gaussian distribution of node positions with mean (0, 0) and standard deviation 2 If weights are not specified they are assigned to nodes by drawing randomly from the exponential distribution with rate parameter :math:`\lambda=1`. To specify weights from a different distribution, use the `weight` keyword argument:: :: >>> import random >>> import math >>> n = 50 >>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)} >>> w = {i: random.expovariate(5.0) for i in range(n)} >>> G = nx.thresholded_random_geometric_graph(n, 0.2, 0.1, 2, pos, w) References ---------- .. [1] http://cole-maclean.github.io/blog/files/thesis.pdf """ G = nx.empty_graph(n) G.name = f"thresholded_random_geometric_graph({n}, {radius}, {theta}, {dim})" # If no weights are provided, choose them from an exponential # distribution. if weight is None: weight = {v: seed.expovariate(1) for v in G} # If no positions are provided, choose uniformly random vectors in # Euclidean space of the specified dimension. if pos is None: pos = {v: [seed.random() for i in range(dim)] for v in G} # If no distance metric is provided, use Euclidean distance. nx.set_node_attributes(G, weight, weight_name) nx.set_node_attributes(G, pos, pos_name) edges = ( (u, v) for u, v in _geometric_edges(G, radius, p, pos_name) if weight[u] + weight[v] >= theta ) G.add_edges_from(edges) return G
(n, theta, dim=2, pos=None, weight=None, metric=None, p_dist=None, seed=None, *, pos_name='pos', weight_name='weight', backend=None, **backend_kwargs)
[ 0.0217621847987175, -0.03952212631702423, 0.00977951381355524, -0.024898555129766464, 0.01820249855518341, 0.009558236226439476, -0.06261197477579117, -0.01697104051709175, 0.02347468212246895, -0.02478310652077198, 0.022839710116386414, 0.08058357983827591, 0.01618213765323162, 0.02557200938463211, -0.06011057645082474, -0.029016245156526566, -0.011833548545837402, 0.009803565219044685, -0.01013067178428173, -0.055069293826818466, -0.02693815901875496, -0.001343300100415945, 0.048103854060173035, 0.05795552581548691, 0.0054549770429730415, -0.032922279089689255, -0.0514134019613266, 0.04267774149775505, -0.027438439428806305, 0.02786175347864628, -0.04136931523680687, -0.06392040103673935, 0.0163649320602417, 0.014777503907680511, 0.012814867310225964, 0.004798359703272581, 0.055069293826818466, 0.043139535933732986, -0.06961590051651001, -0.03848308324813843, -0.010111430659890175, -0.014421535655856133, -0.024975521489977837, -0.021415837109088898, 0.007335837930440903, 0.009524563327431679, 0.06765326112508774, 0.04698784649372101, -0.0445634126663208, -0.032787587493658066, 0.01451774314045906, -0.0003773146017920226, -0.006412243936210871, -0.0135364243760705, -0.029054729267954826, -0.007836118340492249, 0.0016391389071941376, -0.03144067898392677, 0.05183671414852142, -0.0327298641204834, 0.0373670756816864, 0.012497381307184696, 0.04733419418334961, -0.020453758537769318, -0.039676059037446976, -0.015518303960561752, -0.05091312155127525, -0.027707820758223534, 0.00009372735803481191, 0.003239794634282589, 0.0298243910074234, 0.018135152757167816, 0.06368950754404068, 0.025379594415426254, 0.0015429311897605658, 0.016085928305983543, 0.06245804578065872, -0.01600896380841732, -0.016817107796669006, -0.005772462580353022, 0.007114560343325138, 0.0003544652718119323, 0.023493923246860504, -0.06145748496055603, 0.009938256815075874, -0.02434055134654045, 0.014161774888634682, 0.047526609152555466, 0.05618530139327049, -0.06711450219154358, -0.018616192042827606, 0.014844849705696106, 0.021242663264274597, 0.003355243941769004, 0.054684463888406754, 0.020338309928774834, 0.05510777607560158, -0.0038434979505836964, 0.046218182891607285, 0.008110309951007366, -0.0012068054638803005, 0.01048664003610611, -0.07146308571100235, 0.046526048332452774, -0.013497942127287388, -0.036212582141160965, -0.03829066827893257, 0.012603210285305977, 0.011188956908881664, -0.001683634938672185, -0.04506369307637215, -0.024667656049132347, 0.050605256110429764, 0.0028525586239993572, 0.04887351766228676, -0.001756993355229497, -0.054722946137189865, 0.02166597545146942, 0.007605219259858131, -0.010236500762403011, 0.023628612980246544, 0.0038122304249554873, -0.009620770812034607, 0.01832756958901882, -0.007427235133945942, 0.021300386637449265, 0.04236987605690956, -0.028746863827109337, -0.01679786667227745, -0.01859695091843605, 0.01658620871603489, 0.012179896235466003, 0.05395328253507614, 0.07127067446708679, -0.033922839909791946, 0.0035284177865833044, -0.05337603762745857, 0.010669435374438763, 0.06953893601894379, -0.023263024166226387, 0.029362592846155167, -0.09990208595991135, 0.009298475459218025, 0.019761063158512115, 0.03665513917803764, 0.009817996993660927, -0.007735100109130144, -0.035250503569841385, 0.029843632131814957, -0.03848308324813843, 0.035154297947883606, -0.05991816148161888, 0.058455806225538254, -0.02097328007221222, -0.00390362786129117, -0.018279464915394783, 0.028881555423140526, -0.048411719501018524, -0.05984119698405266, -0.028131134808063507, 0.017885012552142143, 0.006041844375431538, 0.018279464915394783, 0.016682416200637817, -0.036212582141160965, 0.00403591338545084, 0.07123219221830368, -0.06896168738603592, 0.009837238118052483, -0.002583177061751485, -0.05580047145485878, -0.04494824260473251, -0.011285164393484592, 0.0009747043368406594, -0.042793188244104385, 0.03315317630767822, -0.0066479528322815895, -0.012170275673270226, -0.06253501027822495, -0.026091530919075012, -0.00439909752458334, -0.03442312031984329, -0.0009464433533139527, 0.010390432551503181, -0.018135152757167816, 0.07357965409755707, 0.04583335295319557, -0.016961419954895973, -0.03044012002646923, 0.005666634067893028, -0.0599951297044754, -0.020068928599357605, 0.030189979821443558, 0.04213897883892059, 0.06138052046298981, 0.0008159616263583302, 0.03263365477323532, 0.033364832401275635, -0.11475655436515808, 0.08589424192905426, 0.06826899200677872, 0.006494020577520132, 0.018058186396956444, -0.038540810346603394, -0.010582848452031612, -0.023878753185272217, -0.02491779625415802, -0.0051567330956459045, 0.039676059037446976, 0.017567528411746025, 0.016913315281271935, -0.001959029585123062, 0.01542209554463625, 0.04514065757393837, -0.02855444885790348, -0.0001982780813705176, -0.018491121008992195, 0.012805245816707611, -0.04787295684218407, -0.043447401374578476, -0.03465401753783226, 0.014604330062866211, -0.016461139544844627, -0.011285164393484592, 0.0544920451939106, 0.015364371240139008, 0.007287734188139439, -0.03644347935914993, 0.03627030551433563, -0.057532209903001785, 0.09128187596797943, -0.050335872918367386, 0.06107265502214432, -0.02824658341705799, -0.022204739972949028, -0.045294590294361115, 0.014161774888634682, 0.0007582370308227837, -0.002163470955565572, 0.02074238285422325, -0.004661263432353735, -0.046526048332452774, -0.05337603762745857, 0.03022846207022667, 0.04975862801074982, -0.013016902841627598, -0.005151922814548016, -0.020646175369620323, 0.08450885117053986, -0.0011316431919112802, -0.05760917812585831, -0.05226002633571625, -0.0129399374127388, -0.013161214999854565, 0.023128332570195198, -0.02913169376552105, -0.004028697963804007, -0.030998123809695244, 0.020934797823429108, 0.02074238285422325, -0.023705579340457916, 0.002401584992185235, -0.03503884747624397, 0.04610273614525795, 0.03475022315979004, -0.016913315281271935, -0.05364542081952095, 0.04714177921414375, -0.021646734327077866, -0.04109993204474449, -0.05137491598725319, 0.01105426624417305, 0.06407433748245239, -0.0021971436217427254, 0.043678298592567444, -0.038540810346603394, 0.010553985834121704, 0.04664149880409241, 0.033076211810112, 0.012362690642476082, -0.047180261462926865, 0.013632632791996002, 0.022185498848557472, -0.008947317488491535, -0.05580047145485878, 0.06672966480255127, -0.08066054433584213, 0.01318045612424612, 0.012737900950014591, -0.051297951489686966, -0.04425554722547531, -0.016153274103999138, -0.027573129162192345, 0.007874601520597935, 0.02251260355114937, 0.0163649320602417, 0.027188299223780632, -0.01221837941557169, 0.012776384130120277, -0.03194095939397812, 0.13222788274288177, -0.020030444487929344, 0.04444796219468117, -0.04995104297995567, 0.05329907312989235, 0.050605256110429764, 0.01239155326038599, -0.01912609301507473, -0.04756509140133858, 0.025033246725797653, -0.037136174738407135, -0.018106291070580482, 0.04198504611849785, 0.012247241102159023, 0.02566821686923504, -0.10736780613660812, 0.023763304576277733, -0.06576759368181229, 0.02351316437125206, -0.007407993543893099, -0.007047214545309544, 0.002924714470282197, -0.0472957119345665, 0.03509657084941864, -0.06942348182201385, -0.042215943336486816, 0.021916115656495094, 0.03986847400665283, -0.004144147038459778, -0.0024508913047611713, -0.0253603532910347, 0.05299120768904686, 0.017519423738121986, -0.010958057828247547, -0.05291423946619034, 0.07812066376209259, 0.05568502098321915, 0.029882114380598068, -0.015431717038154602, -0.05822490528225899, 0.005618530325591564, -0.030767226591706276, 0.016557347029447556, 0.058455806225538254, -0.016066687181591988, -0.014989160932600498, 0.002472538035362959, -0.023128332570195198, -0.001251902780495584, -0.05214457958936691, 0.07600408792495728, 0.03746328130364418, -0.03269137814640999, 0.014402294531464577, 0.02693815901875496, -0.0018195282900705934, 0.015412474982440472, 0.03249896317720413, -0.003896412206813693, 0.07057797908782959, -0.014161774888634682, -0.00655655562877655, 0.04306257143616676, 0.016345689073204994, 0.022166255861520767, 0.03917577862739563, 0.021338870748877525, 0.06303529441356659, -0.005007611121982336, -0.02114645391702652, 0.010342328809201717, -0.08381615579128265, -0.11591105163097382, 0.017452077940106392, 0.026688018813729286, -0.018616192042827606, -0.033056970685720444, -0.012381932698190212, -0.0025278576649725437, 0.03659741207957268, -0.014921816065907478, 0.005979309324175119, 0.03194095939397812, 0.00995749793946743, -0.014844849705696106, -0.011573787778615952, 0.03698224201798439, 0.05460749566555023, 0.013334388844668865, -0.026688018813729286, -0.055300191044807434, -0.043447401374578476, 0.0507207065820694, 0.05510777607560158, 0.006835557986050844, 0.047526609152555466, 0.06484399735927582, 0.036347273737192154, -0.07331027835607529, -0.002893446944653988, 0.014690916985273361, -0.025148695334792137, -0.017711838707327843, -0.05202912911772728, -0.020030444487929344, -0.005777272861450911, -0.015393233858048916, -0.012651314027607441, 0.055069293826818466, 0.010909954085946083, 0.027919476851820946, 0.014296465553343296, 0.011179336346685886, 0.00088150316150859, 0.025033246725797653, -0.03486567363142967, -0.004502520896494389, 0.0524524450302124, 0.004435175564140081, -0.026380153372883797, 0.04071510210633278, -0.08073750883340836, 0.026822710409760475, 0.008677935227751732, 0.003978188615292311, 0.020819349214434624, 0.008644262328743935, -0.03544291853904724, -0.007027973420917988, 0.051605816930532455, -0.02039603516459465, 0.005695496220141649, 0.002265691524371505, 0.0260530486702919, 0.03852156549692154, -0.042177461087703705, -0.017913876101374626, -0.01579730585217476, -0.04945076256990433, -0.02087707258760929, 0.029939839616417885, 0.00967368483543396, 0.02917017787694931, -0.04163869842886925, 0.006113999988883734, -0.003961352631449699, 0.0038627395406365395, 0.010303845629096031, 0.008350829593837261, -0.00725887157022953, 0.05864822119474411, 0.006479589268565178, 0.07685071974992752, 0.047757506370544434, -0.046256665140390396, 0.06291984021663666, -0.0342884287238121, 0.01364225335419178, -0.031305987387895584, 0.004690126050263643, 0.035154297947883606, 0.007941946387290955, -0.0647670328617096, -0.01847187988460064, 0.0063208467327058315, -0.020607691258192062, -0.0005333515000529587, -0.0017726270016282797, 0.006720108445733786, -0.0011743353679776192, 0.08350829035043716, -0.011275543831288815, -0.03665513917803764, -0.044717345386743546, 0.01907798834145069, 0.01561451144516468, -0.07842852175235748, 0.04806537181138992, 0.005315476097166538, -0.030824949964880943, 0.022185498848557472, -0.00725887157022953, 0.0306710172444582, -0.0008851109305396676, -0.0339420810341835, -0.04190807789564133, -0.007537873927503824, 0.008115120232105255, 0.028188858181238174, -0.06188080087304115, -0.03126750513911247, -0.004622780252248049, 0.04987407848238945, 0.007990050129592419, -0.02316681668162346, 0.028362032026052475, -0.01427722442895174, -0.025321869179606438, 0.03832915052771568, -0.010351949371397495, -0.020954038947820663, 0.028573689982295036, 0.0006058079306967556, 0.021338870748877525, 0.06499792635440826, -0.04321650415658951, 0.07211729884147644, 0.012208758853375912, 0.02951652556657791, 0.04521762207150459, 0.053145140409469604, 0.0582633875310421, 0.05568502098321915, 0.01364225335419178, 0.007191526237875223, 0.0008658693986944854, -0.018087049946188927, 0.023359231650829315, -0.013295905664563179, -0.048450201749801636, 0.04852716997265816, 0.0681920275092125, 0.005897532682865858, 0.019934237003326416, 0.013584529049694538, -0.015200817957520485, 0.04083055257797241, -0.04425554722547531, 0.011179336346685886, 0.03742479905486107, 0.0332493856549263, 0.009707357734441757, -0.06088024005293846, 0.014989160932600498, -0.011862410232424736, 0.028939278796315193, -0.02180066704750061, 0.0035212021321058273, -0.028573689982295036, -0.038059771060943604, 0.008220949210226536, -0.005353959277272224, 0.013959738425910473, 0.020242102444171906, 0.030594050884246826, 0.04725722596049309, 0.030209220945835114, -0.022012323141098022, -0.049065932631492615, -0.03921426087617874, 0.07184791564941406, -0.0015898323617875576, -0.08928075432777405, -0.05918698385357857, 0.0969773679971695, -0.024244341999292374, 0.008081447333097458, -0.03496188297867775, -0.0000688110594637692, 0.04194656014442444, -0.04567942023277283, -0.06776870787143707, -0.016605449840426445, -0.004098448436707258, -0.03232578933238983, -0.0163649320602417, -0.04360133409500122, 0.04140779748558998, -0.030805708840489388, 0.009466839022934437, 0.039368193596601486, 0.03149840608239174, 0.020280584692955017, -0.026611052453517914, 0.015364371240139008, -0.006330467294901609, -0.04202352836728096, 0.0064699687063694, -0.017865771427750587, -0.01965523511171341, -0.015364371240139008, 0.00020263748592697084, 0.03232578933238983, 0.008495140820741653, -0.02324378304183483, 0.0411384180188179, -0.05810945853590965, 0.03126750513911247, 0.007023162674158812, 0.03128674626350403, 0.053491488099098206, 0.00008162622543750331, 0.04548700526356697, -0.019145334139466286, -0.030420877039432526, 0.015373991802334785, 0.007480149623006582, 0.014132912270724773, -0.000516815809533, -0.03092115744948387, -0.02676498517394066, 0.03044012002646923, -0.028458241373300552, 0.0036558930296450853, -0.043101053684949875, 0.007465718314051628, 0.014960299246013165, -0.03092115744948387, 0.0296512171626091, -0.05580047145485878, -0.029208660125732422, -0.002503805560991168, -0.03334559127688408, -0.02697664126753807, -0.011602649465203285, 0.0002796036715153605, -0.06942348182201385, 0.06519034504890442, 0.01869315840303898, -0.02601456455886364, -0.02811189368367195, -0.010390432551503181, 0.06049540638923645, -0.007148232776671648, 0.026880433782935143, -0.04333195090293884, -0.014421535655856133, -0.042523808777332306, -0.04848868399858475, 0.043178021907806396, -0.033364832401275635, -0.0476420596241951, -0.011458338238298893, -0.02786175347864628, -0.07465717941522598, -0.02487931400537491, 0.014652433805167675, -0.03005528822541237, -0.003792989067733288, 0.01610517129302025, -0.047757506370544434, 0.02772706188261509, -0.042177461087703705, -0.04983559250831604, -0.011612270958721638, -0.020896313712000847, 0.02807340957224369, 0.02403268590569496, 0.009418734349310398, -0.06796112656593323, -0.04021482169628143, 0.018135152757167816, 0.013065006583929062, -0.017625251784920692, 0.02816961705684662, 0.01798122189939022, -0.0222817063331604, -0.008124740794301033, 0.020107410848140717, -0.021819908171892166, 0.014469639398157597, 0.05179823189973831, 0.04760357365012169, 0.057224344462156296, -0.021723700687289238, 0.031036607921123505, 0.028535205870866776, -0.034365393221378326, 0.03786735609173775, 0.00032921077217906713, -0.018519984558224678, -0.013776944018900394, 0.043447401374578476, 0.0001325110933976248, -0.008668314665555954, 0.019991962239146233, -0.00809106882661581, 0.028496723622083664, -0.0647670328617096, -0.02395571954548359, 0.10567454993724823, 0.029631974175572395, -0.033749666064977646, -0.019116472452878952, 0.05287575721740723, 0.05476142838597298, -0.03815597668290138, -0.05295272544026375, 0.032094892114400864, 0.058455806225538254, -0.01245889812707901, 0.031075090169906616, 0.06395888328552246, 0.037270866334438324, 0.03742479905486107, -0.0043558040633797646, -0.04267774149775505, 0.0072444407269358635, 0.035154297947883606, -0.0370207279920578, 0.03698224201798439, -0.01285335049033165, -0.04567942023277283, 0.05968726426362991, -0.02460993267595768, -0.022628054022789, -0.021377352997660637, 0.02399420365691185, 0.020857831463217735, -0.01006332691758871, -0.07134763896465302, -0.013844289816915989, 0.030497843399643898, -0.0400993749499321, -0.04960469529032707, 0.03192171826958656, 0.014488881453871727, -0.00300408573821187, -0.054645977914333344, -0.05987967923283577, 0.001890481449663639, 0.0017798426561057568, -0.044063132256269455, 0.034673258662223816, -0.01750018261373043, 0.003805015003308654, 0.035635337233543396, -0.11660374701023102, -0.003694375976920128, -0.013603770174086094, 0.014864090830087662, 0.04013785719871521, -0.0113140270113945, 0.016874833032488823, 0.007186715956777334, 0.012699417769908905, -0.014613951556384563, 0.03707845136523247, -0.04633363336324692, 0.047757506370544434, -0.017182696610689163, 0.027804028242826462, -0.03780962899327278, -0.040561169385910034, 0.009928635321557522, -0.01943395659327507, 0.003737669438123703, -0.009211888536810875, 0.005089387763291597, 0.025591250509023666, 0.025533527135849, 0.024532966315746307, 0.03192171826958656, -0.0032133376225829124, -0.01877974532544613, 0.060341477394104004, -0.030940400436520576, -0.045333072543144226, -0.02539883553981781, -0.03646272048354149, -0.04236987605690956, -0.015316267497837543, -0.017259662970900536, 0.0020396034233272076, -0.032960761338472366, 0.033268626779317856, 0.005512701813131571, 0.050951603800058365 ]
30,700
networkx.generators.geometric
geometric_edges
Returns edge list of node pairs within `radius` of each other. Parameters ---------- G : networkx graph The graph from which to generate the edge list. The nodes in `G` should have an attribute ``pos`` corresponding to the node position, which is used to compute the distance to other nodes. radius : scalar The distance threshold. Edges are included in the edge list if the distance between the two nodes is less than `radius`. pos_name : string, default="pos" The name of the node attribute which represents the position of each node in 2D coordinates. Every node in the Graph must have this attribute. p : scalar, default=2 The `Minkowski distance metric <https://en.wikipedia.org/wiki/Minkowski_distance>`_ used to compute distances. The default value is 2, i.e. Euclidean distance. Returns ------- edges : list List of edges whose distances are less than `radius` Notes ----- Radius uses Minkowski distance metric `p`. If scipy is available, `scipy.spatial.cKDTree` is used to speed computation. Examples -------- Create a graph with nodes that have a "pos" attribute representing 2D coordinates. >>> G = nx.Graph() >>> G.add_nodes_from( ... [ ... (0, {"pos": (0, 0)}), ... (1, {"pos": (3, 0)}), ... (2, {"pos": (8, 0)}), ... ] ... ) >>> nx.geometric_edges(G, radius=1) [] >>> nx.geometric_edges(G, radius=4) [(0, 1)] >>> nx.geometric_edges(G, radius=6) [(0, 1), (1, 2)] >>> nx.geometric_edges(G, radius=9) [(0, 1), (0, 2), (1, 2)]
def thresholded_random_geometric_graph( n, radius, theta, dim=2, pos=None, weight=None, p=2, seed=None, *, pos_name="pos", weight_name="weight", ): r"""Returns a thresholded random geometric graph in the unit cube. The thresholded random geometric graph [1] model places `n` nodes uniformly at random in the unit cube of dimensions `dim`. Each node `u` is assigned a weight :math:`w_u`. Two nodes `u` and `v` are joined by an edge if they are within the maximum connection distance, `radius` computed by the `p`-Minkowski distance and the summation of weights :math:`w_u` + :math:`w_v` is greater than or equal to the threshold parameter `theta`. Edges within `radius` of each other are determined using a KDTree when SciPy is available. This reduces the time complexity from :math:`O(n^2)` to :math:`O(n)`. Parameters ---------- n : int or iterable Number of nodes or iterable of nodes radius: float Distance threshold value theta: float Threshold value dim : int, optional Dimension of graph pos : dict, optional A dictionary keyed by node with node positions as values. weight : dict, optional Node weights as a dictionary of numbers keyed by node. p : float, optional (default 2) Which Minkowski distance metric to use. `p` has to meet the condition ``1 <= p <= infinity``. If this argument is not specified, the :math:`L^2` metric (the Euclidean distance metric), p = 2 is used. This should not be confused with the `p` of an Erdős-Rényi random graph, which represents probability. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. pos_name : string, default="pos" The name of the node attribute which represents the position in 2D coordinates of the node in the returned graph. weight_name : string, default="weight" The name of the node attribute which represents the weight of the node in the returned graph. Returns ------- Graph A thresholded random geographic 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 nodethre attribute ``'weight'`` that stores the weight of that node as provided or as generated. Examples -------- Default Graph: G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1) Custom Graph: Create a thresholded random geometric graph on 50 uniformly distributed nodes where nodes are joined by an edge if their sum weights drawn from a exponential distribution with rate = 5 are >= theta = 0.1 and their Euclidean distance is at most 0.2. Notes ----- This uses a *k*-d tree to build the graph. The `pos` keyword argument can be used to specify node positions so you can create an arbitrary distribution and domain for positions. For example, to use a 2D Gaussian distribution of node positions with mean (0, 0) and standard deviation 2 If weights are not specified they are assigned to nodes by drawing randomly from the exponential distribution with rate parameter :math:`\lambda=1`. To specify weights from a different distribution, use the `weight` keyword argument:: :: >>> import random >>> import math >>> n = 50 >>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)} >>> w = {i: random.expovariate(5.0) for i in range(n)} >>> G = nx.thresholded_random_geometric_graph(n, 0.2, 0.1, 2, pos, w) References ---------- .. [1] http://cole-maclean.github.io/blog/files/thesis.pdf """ G = nx.empty_graph(n) G.name = f"thresholded_random_geometric_graph({n}, {radius}, {theta}, {dim})" # If no weights are provided, choose them from an exponential # distribution. if weight is None: weight = {v: seed.expovariate(1) for v in G} # If no positions are provided, choose uniformly random vectors in # Euclidean space of the specified dimension. if pos is None: pos = {v: [seed.random() for i in range(dim)] for v in G} # If no distance metric is provided, use Euclidean distance. nx.set_node_attributes(G, weight, weight_name) nx.set_node_attributes(G, pos, pos_name) edges = ( (u, v) for u, v in _geometric_edges(G, radius, p, pos_name) if weight[u] + weight[v] >= theta ) G.add_edges_from(edges) return G
(G, radius, p=2, *, pos_name='pos', backend=None, **backend_kwargs)
[ 0.0217621847987175, -0.03952212631702423, 0.00977951381355524, -0.024898555129766464, 0.01820249855518341, 0.009558236226439476, -0.06261197477579117, -0.01697104051709175, 0.02347468212246895, -0.02478310652077198, 0.022839710116386414, 0.08058357983827591, 0.01618213765323162, 0.02557200938463211, -0.06011057645082474, -0.029016245156526566, -0.011833548545837402, 0.009803565219044685, -0.01013067178428173, -0.055069293826818466, -0.02693815901875496, -0.001343300100415945, 0.048103854060173035, 0.05795552581548691, 0.0054549770429730415, -0.032922279089689255, -0.0514134019613266, 0.04267774149775505, -0.027438439428806305, 0.02786175347864628, -0.04136931523680687, -0.06392040103673935, 0.0163649320602417, 0.014777503907680511, 0.012814867310225964, 0.004798359703272581, 0.055069293826818466, 0.043139535933732986, -0.06961590051651001, -0.03848308324813843, -0.010111430659890175, -0.014421535655856133, -0.024975521489977837, -0.021415837109088898, 0.007335837930440903, 0.009524563327431679, 0.06765326112508774, 0.04698784649372101, -0.0445634126663208, -0.032787587493658066, 0.01451774314045906, -0.0003773146017920226, -0.006412243936210871, -0.0135364243760705, -0.029054729267954826, -0.007836118340492249, 0.0016391389071941376, -0.03144067898392677, 0.05183671414852142, -0.0327298641204834, 0.0373670756816864, 0.012497381307184696, 0.04733419418334961, -0.020453758537769318, -0.039676059037446976, -0.015518303960561752, -0.05091312155127525, -0.027707820758223534, 0.00009372735803481191, 0.003239794634282589, 0.0298243910074234, 0.018135152757167816, 0.06368950754404068, 0.025379594415426254, 0.0015429311897605658, 0.016085928305983543, 0.06245804578065872, -0.01600896380841732, -0.016817107796669006, -0.005772462580353022, 0.007114560343325138, 0.0003544652718119323, 0.023493923246860504, -0.06145748496055603, 0.009938256815075874, -0.02434055134654045, 0.014161774888634682, 0.047526609152555466, 0.05618530139327049, -0.06711450219154358, -0.018616192042827606, 0.014844849705696106, 0.021242663264274597, 0.003355243941769004, 0.054684463888406754, 0.020338309928774834, 0.05510777607560158, -0.0038434979505836964, 0.046218182891607285, 0.008110309951007366, -0.0012068054638803005, 0.01048664003610611, -0.07146308571100235, 0.046526048332452774, -0.013497942127287388, -0.036212582141160965, -0.03829066827893257, 0.012603210285305977, 0.011188956908881664, -0.001683634938672185, -0.04506369307637215, -0.024667656049132347, 0.050605256110429764, 0.0028525586239993572, 0.04887351766228676, -0.001756993355229497, -0.054722946137189865, 0.02166597545146942, 0.007605219259858131, -0.010236500762403011, 0.023628612980246544, 0.0038122304249554873, -0.009620770812034607, 0.01832756958901882, -0.007427235133945942, 0.021300386637449265, 0.04236987605690956, -0.028746863827109337, -0.01679786667227745, -0.01859695091843605, 0.01658620871603489, 0.012179896235466003, 0.05395328253507614, 0.07127067446708679, -0.033922839909791946, 0.0035284177865833044, -0.05337603762745857, 0.010669435374438763, 0.06953893601894379, -0.023263024166226387, 0.029362592846155167, -0.09990208595991135, 0.009298475459218025, 0.019761063158512115, 0.03665513917803764, 0.009817996993660927, -0.007735100109130144, -0.035250503569841385, 0.029843632131814957, -0.03848308324813843, 0.035154297947883606, -0.05991816148161888, 0.058455806225538254, -0.02097328007221222, -0.00390362786129117, -0.018279464915394783, 0.028881555423140526, -0.048411719501018524, -0.05984119698405266, -0.028131134808063507, 0.017885012552142143, 0.006041844375431538, 0.018279464915394783, 0.016682416200637817, -0.036212582141160965, 0.00403591338545084, 0.07123219221830368, -0.06896168738603592, 0.009837238118052483, -0.002583177061751485, -0.05580047145485878, -0.04494824260473251, -0.011285164393484592, 0.0009747043368406594, -0.042793188244104385, 0.03315317630767822, -0.0066479528322815895, -0.012170275673270226, -0.06253501027822495, -0.026091530919075012, -0.00439909752458334, -0.03442312031984329, -0.0009464433533139527, 0.010390432551503181, -0.018135152757167816, 0.07357965409755707, 0.04583335295319557, -0.016961419954895973, -0.03044012002646923, 0.005666634067893028, -0.0599951297044754, -0.020068928599357605, 0.030189979821443558, 0.04213897883892059, 0.06138052046298981, 0.0008159616263583302, 0.03263365477323532, 0.033364832401275635, -0.11475655436515808, 0.08589424192905426, 0.06826899200677872, 0.006494020577520132, 0.018058186396956444, -0.038540810346603394, -0.010582848452031612, -0.023878753185272217, -0.02491779625415802, -0.0051567330956459045, 0.039676059037446976, 0.017567528411746025, 0.016913315281271935, -0.001959029585123062, 0.01542209554463625, 0.04514065757393837, -0.02855444885790348, -0.0001982780813705176, -0.018491121008992195, 0.012805245816707611, -0.04787295684218407, -0.043447401374578476, -0.03465401753783226, 0.014604330062866211, -0.016461139544844627, -0.011285164393484592, 0.0544920451939106, 0.015364371240139008, 0.007287734188139439, -0.03644347935914993, 0.03627030551433563, -0.057532209903001785, 0.09128187596797943, -0.050335872918367386, 0.06107265502214432, -0.02824658341705799, -0.022204739972949028, -0.045294590294361115, 0.014161774888634682, 0.0007582370308227837, -0.002163470955565572, 0.02074238285422325, -0.004661263432353735, -0.046526048332452774, -0.05337603762745857, 0.03022846207022667, 0.04975862801074982, -0.013016902841627598, -0.005151922814548016, -0.020646175369620323, 0.08450885117053986, -0.0011316431919112802, -0.05760917812585831, -0.05226002633571625, -0.0129399374127388, -0.013161214999854565, 0.023128332570195198, -0.02913169376552105, -0.004028697963804007, -0.030998123809695244, 0.020934797823429108, 0.02074238285422325, -0.023705579340457916, 0.002401584992185235, -0.03503884747624397, 0.04610273614525795, 0.03475022315979004, -0.016913315281271935, -0.05364542081952095, 0.04714177921414375, -0.021646734327077866, -0.04109993204474449, -0.05137491598725319, 0.01105426624417305, 0.06407433748245239, -0.0021971436217427254, 0.043678298592567444, -0.038540810346603394, 0.010553985834121704, 0.04664149880409241, 0.033076211810112, 0.012362690642476082, -0.047180261462926865, 0.013632632791996002, 0.022185498848557472, -0.008947317488491535, -0.05580047145485878, 0.06672966480255127, -0.08066054433584213, 0.01318045612424612, 0.012737900950014591, -0.051297951489686966, -0.04425554722547531, -0.016153274103999138, -0.027573129162192345, 0.007874601520597935, 0.02251260355114937, 0.0163649320602417, 0.027188299223780632, -0.01221837941557169, 0.012776384130120277, -0.03194095939397812, 0.13222788274288177, -0.020030444487929344, 0.04444796219468117, -0.04995104297995567, 0.05329907312989235, 0.050605256110429764, 0.01239155326038599, -0.01912609301507473, -0.04756509140133858, 0.025033246725797653, -0.037136174738407135, -0.018106291070580482, 0.04198504611849785, 0.012247241102159023, 0.02566821686923504, -0.10736780613660812, 0.023763304576277733, -0.06576759368181229, 0.02351316437125206, -0.007407993543893099, -0.007047214545309544, 0.002924714470282197, -0.0472957119345665, 0.03509657084941864, -0.06942348182201385, -0.042215943336486816, 0.021916115656495094, 0.03986847400665283, -0.004144147038459778, -0.0024508913047611713, -0.0253603532910347, 0.05299120768904686, 0.017519423738121986, -0.010958057828247547, -0.05291423946619034, 0.07812066376209259, 0.05568502098321915, 0.029882114380598068, -0.015431717038154602, -0.05822490528225899, 0.005618530325591564, -0.030767226591706276, 0.016557347029447556, 0.058455806225538254, -0.016066687181591988, -0.014989160932600498, 0.002472538035362959, -0.023128332570195198, -0.001251902780495584, -0.05214457958936691, 0.07600408792495728, 0.03746328130364418, -0.03269137814640999, 0.014402294531464577, 0.02693815901875496, -0.0018195282900705934, 0.015412474982440472, 0.03249896317720413, -0.003896412206813693, 0.07057797908782959, -0.014161774888634682, -0.00655655562877655, 0.04306257143616676, 0.016345689073204994, 0.022166255861520767, 0.03917577862739563, 0.021338870748877525, 0.06303529441356659, -0.005007611121982336, -0.02114645391702652, 0.010342328809201717, -0.08381615579128265, -0.11591105163097382, 0.017452077940106392, 0.026688018813729286, -0.018616192042827606, -0.033056970685720444, -0.012381932698190212, -0.0025278576649725437, 0.03659741207957268, -0.014921816065907478, 0.005979309324175119, 0.03194095939397812, 0.00995749793946743, -0.014844849705696106, -0.011573787778615952, 0.03698224201798439, 0.05460749566555023, 0.013334388844668865, -0.026688018813729286, -0.055300191044807434, -0.043447401374578476, 0.0507207065820694, 0.05510777607560158, 0.006835557986050844, 0.047526609152555466, 0.06484399735927582, 0.036347273737192154, -0.07331027835607529, -0.002893446944653988, 0.014690916985273361, -0.025148695334792137, -0.017711838707327843, -0.05202912911772728, -0.020030444487929344, -0.005777272861450911, -0.015393233858048916, -0.012651314027607441, 0.055069293826818466, 0.010909954085946083, 0.027919476851820946, 0.014296465553343296, 0.011179336346685886, 0.00088150316150859, 0.025033246725797653, -0.03486567363142967, -0.004502520896494389, 0.0524524450302124, 0.004435175564140081, -0.026380153372883797, 0.04071510210633278, -0.08073750883340836, 0.026822710409760475, 0.008677935227751732, 0.003978188615292311, 0.020819349214434624, 0.008644262328743935, -0.03544291853904724, -0.007027973420917988, 0.051605816930532455, -0.02039603516459465, 0.005695496220141649, 0.002265691524371505, 0.0260530486702919, 0.03852156549692154, -0.042177461087703705, -0.017913876101374626, -0.01579730585217476, -0.04945076256990433, -0.02087707258760929, 0.029939839616417885, 0.00967368483543396, 0.02917017787694931, -0.04163869842886925, 0.006113999988883734, -0.003961352631449699, 0.0038627395406365395, 0.010303845629096031, 0.008350829593837261, -0.00725887157022953, 0.05864822119474411, 0.006479589268565178, 0.07685071974992752, 0.047757506370544434, -0.046256665140390396, 0.06291984021663666, -0.0342884287238121, 0.01364225335419178, -0.031305987387895584, 0.004690126050263643, 0.035154297947883606, 0.007941946387290955, -0.0647670328617096, -0.01847187988460064, 0.0063208467327058315, -0.020607691258192062, -0.0005333515000529587, -0.0017726270016282797, 0.006720108445733786, -0.0011743353679776192, 0.08350829035043716, -0.011275543831288815, -0.03665513917803764, -0.044717345386743546, 0.01907798834145069, 0.01561451144516468, -0.07842852175235748, 0.04806537181138992, 0.005315476097166538, -0.030824949964880943, 0.022185498848557472, -0.00725887157022953, 0.0306710172444582, -0.0008851109305396676, -0.0339420810341835, -0.04190807789564133, -0.007537873927503824, 0.008115120232105255, 0.028188858181238174, -0.06188080087304115, -0.03126750513911247, -0.004622780252248049, 0.04987407848238945, 0.007990050129592419, -0.02316681668162346, 0.028362032026052475, -0.01427722442895174, -0.025321869179606438, 0.03832915052771568, -0.010351949371397495, -0.020954038947820663, 0.028573689982295036, 0.0006058079306967556, 0.021338870748877525, 0.06499792635440826, -0.04321650415658951, 0.07211729884147644, 0.012208758853375912, 0.02951652556657791, 0.04521762207150459, 0.053145140409469604, 0.0582633875310421, 0.05568502098321915, 0.01364225335419178, 0.007191526237875223, 0.0008658693986944854, -0.018087049946188927, 0.023359231650829315, -0.013295905664563179, -0.048450201749801636, 0.04852716997265816, 0.0681920275092125, 0.005897532682865858, 0.019934237003326416, 0.013584529049694538, -0.015200817957520485, 0.04083055257797241, -0.04425554722547531, 0.011179336346685886, 0.03742479905486107, 0.0332493856549263, 0.009707357734441757, -0.06088024005293846, 0.014989160932600498, -0.011862410232424736, 0.028939278796315193, -0.02180066704750061, 0.0035212021321058273, -0.028573689982295036, -0.038059771060943604, 0.008220949210226536, -0.005353959277272224, 0.013959738425910473, 0.020242102444171906, 0.030594050884246826, 0.04725722596049309, 0.030209220945835114, -0.022012323141098022, -0.049065932631492615, -0.03921426087617874, 0.07184791564941406, -0.0015898323617875576, -0.08928075432777405, -0.05918698385357857, 0.0969773679971695, -0.024244341999292374, 0.008081447333097458, -0.03496188297867775, -0.0000688110594637692, 0.04194656014442444, -0.04567942023277283, -0.06776870787143707, -0.016605449840426445, -0.004098448436707258, -0.03232578933238983, -0.0163649320602417, -0.04360133409500122, 0.04140779748558998, -0.030805708840489388, 0.009466839022934437, 0.039368193596601486, 0.03149840608239174, 0.020280584692955017, -0.026611052453517914, 0.015364371240139008, -0.006330467294901609, -0.04202352836728096, 0.0064699687063694, -0.017865771427750587, -0.01965523511171341, -0.015364371240139008, 0.00020263748592697084, 0.03232578933238983, 0.008495140820741653, -0.02324378304183483, 0.0411384180188179, -0.05810945853590965, 0.03126750513911247, 0.007023162674158812, 0.03128674626350403, 0.053491488099098206, 0.00008162622543750331, 0.04548700526356697, -0.019145334139466286, -0.030420877039432526, 0.015373991802334785, 0.007480149623006582, 0.014132912270724773, -0.000516815809533, -0.03092115744948387, -0.02676498517394066, 0.03044012002646923, -0.028458241373300552, 0.0036558930296450853, -0.043101053684949875, 0.007465718314051628, 0.014960299246013165, -0.03092115744948387, 0.0296512171626091, -0.05580047145485878, -0.029208660125732422, -0.002503805560991168, -0.03334559127688408, -0.02697664126753807, -0.011602649465203285, 0.0002796036715153605, -0.06942348182201385, 0.06519034504890442, 0.01869315840303898, -0.02601456455886364, -0.02811189368367195, -0.010390432551503181, 0.06049540638923645, -0.007148232776671648, 0.026880433782935143, -0.04333195090293884, -0.014421535655856133, -0.042523808777332306, -0.04848868399858475, 0.043178021907806396, -0.033364832401275635, -0.0476420596241951, -0.011458338238298893, -0.02786175347864628, -0.07465717941522598, -0.02487931400537491, 0.014652433805167675, -0.03005528822541237, -0.003792989067733288, 0.01610517129302025, -0.047757506370544434, 0.02772706188261509, -0.042177461087703705, -0.04983559250831604, -0.011612270958721638, -0.020896313712000847, 0.02807340957224369, 0.02403268590569496, 0.009418734349310398, -0.06796112656593323, -0.04021482169628143, 0.018135152757167816, 0.013065006583929062, -0.017625251784920692, 0.02816961705684662, 0.01798122189939022, -0.0222817063331604, -0.008124740794301033, 0.020107410848140717, -0.021819908171892166, 0.014469639398157597, 0.05179823189973831, 0.04760357365012169, 0.057224344462156296, -0.021723700687289238, 0.031036607921123505, 0.028535205870866776, -0.034365393221378326, 0.03786735609173775, 0.00032921077217906713, -0.018519984558224678, -0.013776944018900394, 0.043447401374578476, 0.0001325110933976248, -0.008668314665555954, 0.019991962239146233, -0.00809106882661581, 0.028496723622083664, -0.0647670328617096, -0.02395571954548359, 0.10567454993724823, 0.029631974175572395, -0.033749666064977646, -0.019116472452878952, 0.05287575721740723, 0.05476142838597298, -0.03815597668290138, -0.05295272544026375, 0.032094892114400864, 0.058455806225538254, -0.01245889812707901, 0.031075090169906616, 0.06395888328552246, 0.037270866334438324, 0.03742479905486107, -0.0043558040633797646, -0.04267774149775505, 0.0072444407269358635, 0.035154297947883606, -0.0370207279920578, 0.03698224201798439, -0.01285335049033165, -0.04567942023277283, 0.05968726426362991, -0.02460993267595768, -0.022628054022789, -0.021377352997660637, 0.02399420365691185, 0.020857831463217735, -0.01006332691758871, -0.07134763896465302, -0.013844289816915989, 0.030497843399643898, -0.0400993749499321, -0.04960469529032707, 0.03192171826958656, 0.014488881453871727, -0.00300408573821187, -0.054645977914333344, -0.05987967923283577, 0.001890481449663639, 0.0017798426561057568, -0.044063132256269455, 0.034673258662223816, -0.01750018261373043, 0.003805015003308654, 0.035635337233543396, -0.11660374701023102, -0.003694375976920128, -0.013603770174086094, 0.014864090830087662, 0.04013785719871521, -0.0113140270113945, 0.016874833032488823, 0.007186715956777334, 0.012699417769908905, -0.014613951556384563, 0.03707845136523247, -0.04633363336324692, 0.047757506370544434, -0.017182696610689163, 0.027804028242826462, -0.03780962899327278, -0.040561169385910034, 0.009928635321557522, -0.01943395659327507, 0.003737669438123703, -0.009211888536810875, 0.005089387763291597, 0.025591250509023666, 0.025533527135849, 0.024532966315746307, 0.03192171826958656, -0.0032133376225829124, -0.01877974532544613, 0.060341477394104004, -0.030940400436520576, -0.045333072543144226, -0.02539883553981781, -0.03646272048354149, -0.04236987605690956, -0.015316267497837543, -0.017259662970900536, 0.0020396034233272076, -0.032960761338472366, 0.033268626779317856, 0.005512701813131571, 0.050951603800058365 ]
30,701
networkx.generators.geometric
geometric_soft_configuration_graph
Returns a random graph from the geometric soft configuration model. The $\mathbb{S}^1$ model [1]_ is the geometric soft configuration model which is able to explain many fundamental features of real networks such as small-world property, heteregenous degree distributions, high level of clustering, and self-similarity. In the geometric soft configuration model, a node $i$ is assigned two hidden variables: a hidden degree $\kappa_i$, quantifying its popularity, influence, or importance, and an angular position $\theta_i$ in a circle abstracting the similarity space, where angular distances between nodes are a proxy for their similarity. Focusing on the angular position, this model is often called the $\mathbb{S}^1$ model (a one-dimensional sphere). The circle's radius is adjusted to $R = N/2\pi$, where $N$ is the number of nodes, so that the density is set to 1 without loss of generality. The connection probability between any pair of nodes increases with the product of their hidden degrees (i.e., their combined popularities), and decreases with the angular distance between the two nodes. Specifically, nodes $i$ and $j$ are connected with the probability $p_{ij} = \frac{1}{1 + \frac{d_{ij}^\beta}{\left(\mu \kappa_i \kappa_j\right)^{\max(1, \beta)}}}$ where $d_{ij} = R\Delta\theta_{ij}$ is the arc length of the circle between nodes $i$ and $j$ separated by an angular distance $\Delta\theta_{ij}$. Parameters $\mu$ and $\beta$ (also called inverse temperature) control the average degree and the clustering coefficient, respectively. It can be shown [2]_ that the model undergoes a structural phase transition at $\beta=1$ so that for $\beta<1$ networks are unclustered in the thermodynamic limit (when $N\to \infty$) whereas for $\beta>1$ the ensemble generates networks with finite clustering coefficient. The $\mathbb{S}^1$ model can be expressed as a purely geometric model $\mathbb{H}^2$ in the hyperbolic plane [3]_ by mapping the hidden degree of each node into a radial coordinate as $r_i = \hat{R} - \frac{2 \max(1, \beta)}{\beta \zeta} \ln \left(\frac{\kappa_i}{\kappa_0}\right)$ where $\hat{R}$ is the radius of the hyperbolic disk and $\zeta$ is the curvature, $\hat{R} = \frac{2}{\zeta} \ln \left(\frac{N}{\pi}\right) - \frac{2\max(1, \beta)}{\beta \zeta} \ln (\mu \kappa_0^2)$ The connection probability then reads $p_{ij} = \frac{1}{1 + \exp\left({\frac{\beta\zeta}{2} (x_{ij} - \hat{R})}\right)}$ where $x_{ij} = r_i + r_j + \frac{2}{\zeta} \ln \frac{\Delta\theta_{ij}}{2}$ is a good approximation of the hyperbolic distance between two nodes separated by an angular distance $\Delta\theta_{ij}$ with radial coordinates $r_i$ and $r_j$. For $\beta > 1$, the curvature $\zeta = 1$, for $\beta < 1$, $\zeta = \beta^{-1}$. Parameters ---------- Either `n`, `gamma`, `mean_degree` are provided or `kappas`. The values of `n`, `gamma`, `mean_degree` (if provided) are used to construct a random kappa-dict keyed by node with values sampled from a power-law distribution. beta : positive number Inverse temperature, controlling the clustering coefficient. n : int (default: None) Size of the network (number of nodes). If not provided, `kappas` must be provided and holds the nodes. gamma : float (default: None) Exponent of the power-law distribution for hidden degrees `kappas`. If not provided, `kappas` must be provided directly. mean_degree : float (default: None) The mean degree in the network. If not provided, `kappas` must be provided directly. kappas : dict (default: None) A dict keyed by node to its hidden degree value. If not provided, random values are computed based on a power-law distribution using `n`, `gamma` and `mean_degree`. seed : int, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- Graph A random geometric soft configuration graph (undirected with no self-loops). Each node has three node-attributes: - ``kappa`` that represents the hidden degree. - ``theta`` the position in the similarity space ($\mathbb{S}^1$) which is also the angular position in the hyperbolic plane. - ``radius`` the radial position in the hyperbolic plane (based on the hidden degree). Examples -------- Generate a network with specified parameters: >>> G = nx.geometric_soft_configuration_graph(beta=1.5, n=100, gamma=2.7, mean_degree=5) Create a geometric soft configuration graph with 100 nodes. The $\beta$ parameter is set to 1.5 and the exponent of the powerlaw distribution of the hidden degrees is 2.7 with mean value of 5. Generate a network with predefined hidden degrees: >>> kappas = {i: 10 for i in range(100)} >>> G = nx.geometric_soft_configuration_graph(beta=2.5, kappas=kappas) Create a geometric soft configuration graph with 100 nodes. The $\beta$ parameter is set to 2.5 and all nodes with hidden degree $\kappa=10$. References ---------- .. [1] Serrano, M. Á., Krioukov, D., & Boguñá, M. (2008). Self-similarity of complex networks and hidden metric spaces. Physical review letters, 100(7), 078701. .. [2] van der Kolk, J., Serrano, M. Á., & Boguñá, M. (2022). An anomalous topological phase transition in spatial random graphs. Communications Physics, 5(1), 245. .. [3] Krioukov, D., Papadopoulos, F., Kitsak, M., Vahdat, A., & Boguná, M. (2010). Hyperbolic geometry of complex networks. Physical Review E, 82(3), 036106.
def thresholded_random_geometric_graph( n, radius, theta, dim=2, pos=None, weight=None, p=2, seed=None, *, pos_name="pos", weight_name="weight", ): r"""Returns a thresholded random geometric graph in the unit cube. The thresholded random geometric graph [1] model places `n` nodes uniformly at random in the unit cube of dimensions `dim`. Each node `u` is assigned a weight :math:`w_u`. Two nodes `u` and `v` are joined by an edge if they are within the maximum connection distance, `radius` computed by the `p`-Minkowski distance and the summation of weights :math:`w_u` + :math:`w_v` is greater than or equal to the threshold parameter `theta`. Edges within `radius` of each other are determined using a KDTree when SciPy is available. This reduces the time complexity from :math:`O(n^2)` to :math:`O(n)`. Parameters ---------- n : int or iterable Number of nodes or iterable of nodes radius: float Distance threshold value theta: float Threshold value dim : int, optional Dimension of graph pos : dict, optional A dictionary keyed by node with node positions as values. weight : dict, optional Node weights as a dictionary of numbers keyed by node. p : float, optional (default 2) Which Minkowski distance metric to use. `p` has to meet the condition ``1 <= p <= infinity``. If this argument is not specified, the :math:`L^2` metric (the Euclidean distance metric), p = 2 is used. This should not be confused with the `p` of an Erdős-Rényi random graph, which represents probability. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. pos_name : string, default="pos" The name of the node attribute which represents the position in 2D coordinates of the node in the returned graph. weight_name : string, default="weight" The name of the node attribute which represents the weight of the node in the returned graph. Returns ------- Graph A thresholded random geographic 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 nodethre attribute ``'weight'`` that stores the weight of that node as provided or as generated. Examples -------- Default Graph: G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1) Custom Graph: Create a thresholded random geometric graph on 50 uniformly distributed nodes where nodes are joined by an edge if their sum weights drawn from a exponential distribution with rate = 5 are >= theta = 0.1 and their Euclidean distance is at most 0.2. Notes ----- This uses a *k*-d tree to build the graph. The `pos` keyword argument can be used to specify node positions so you can create an arbitrary distribution and domain for positions. For example, to use a 2D Gaussian distribution of node positions with mean (0, 0) and standard deviation 2 If weights are not specified they are assigned to nodes by drawing randomly from the exponential distribution with rate parameter :math:`\lambda=1`. To specify weights from a different distribution, use the `weight` keyword argument:: :: >>> import random >>> import math >>> n = 50 >>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)} >>> w = {i: random.expovariate(5.0) for i in range(n)} >>> G = nx.thresholded_random_geometric_graph(n, 0.2, 0.1, 2, pos, w) References ---------- .. [1] http://cole-maclean.github.io/blog/files/thesis.pdf """ G = nx.empty_graph(n) G.name = f"thresholded_random_geometric_graph({n}, {radius}, {theta}, {dim})" # If no weights are provided, choose them from an exponential # distribution. if weight is None: weight = {v: seed.expovariate(1) for v in G} # If no positions are provided, choose uniformly random vectors in # Euclidean space of the specified dimension. if pos is None: pos = {v: [seed.random() for i in range(dim)] for v in G} # If no distance metric is provided, use Euclidean distance. nx.set_node_attributes(G, weight, weight_name) nx.set_node_attributes(G, pos, pos_name) edges = ( (u, v) for u, v in _geometric_edges(G, radius, p, pos_name) if weight[u] + weight[v] >= theta ) G.add_edges_from(edges) return G
(*, beta, n=None, gamma=None, mean_degree=None, kappas=None, seed=None, backend=None, **backend_kwargs)
[ 0.021722780540585518, -0.03948197141289711, 0.009793529286980629, -0.024916740134358406, 0.018182486295700073, 0.00954821053892374, -0.06264780461788177, -0.01696070097386837, 0.02337748184800148, -0.024820536375045776, 0.022877223789691925, 0.08065712451934814, 0.016162211075425148, 0.02560940757393837, -0.06010802835226059, -0.02903425693511963, -0.011861908249557018, 0.009841631166636944, -0.010159103199839592, -0.05506695806980133, -0.026975497603416443, -0.0012975464342162013, 0.048063334077596664, 0.057876106351614, 0.0054306951351463795, -0.03301708772778511, -0.051334258168935776, 0.04267593100667, -0.027437275275588036, 0.02789905294775963, -0.041406042873859406, -0.06391769647598267, 0.01644119992852211, 0.014796118251979351, 0.012746981345117092, 0.00477410526946187, 0.05506695806980133, 0.04317618906497955, -0.0695359855890274, -0.03844297304749489, -0.010197584517300129, -0.014430544339120388, -0.024974463507533073, -0.021395687013864517, 0.007297045551240444, 0.009490488097071648, 0.0675734281539917, 0.04698585346341133, -0.044638484716415405, -0.03278619796037674, 0.014497887343168259, -0.00038000434869900346, -0.0064023518934845924, -0.013603193685412407, -0.02903425693511963, -0.007883887737989426, 0.0016763482708483934, -0.03149706870317459, 0.05183451622724533, -0.032766956835985184, 0.037365492433309555, 0.01249685138463974, 0.04729370400309563, -0.02047213353216648, -0.03967437893152237, -0.015527266077697277, -0.050910960882902145, -0.02774512767791748, 0.00012664306268561631, 0.0032420624047517776, 0.02984236739575863, 0.018172865733504295, 0.06372528523206711, 0.02537851780653, 0.0015224224189296365, 0.01611410826444626, 0.062455397099256516, -0.01596980355679989, -0.01686449721455574, -0.005743356887251139, 0.0070372954942286015, 0.00039623869815841317, 0.02347368560731411, -0.061454880982637405, 0.009870492853224277, -0.024339519441127777, 0.014141933992505074, 0.047486111521720886, 0.056182920932769775, -0.06711165606975555, -0.018644263967871666, 0.014824979938566685, 0.02124176174402237, 0.0033118100836873055, 0.05468214303255081, 0.020356688648462296, 0.055143922567367554, -0.0038168791215866804, 0.04617774486541748, 0.008061864413321018, -0.0011983364820480347, 0.010495816357433796, -0.07146006077528, 0.0465625561773777, -0.013535850681364536, -0.03624952957034111, -0.03825056552886963, 0.01266039814800024, 0.011178862303495407, -0.001723247580230236, -0.04513874277472496, -0.024724332615733147, 0.05060311034321785, 0.0028716784436255693, 0.048871446400880814, -0.0017917926888912916, -0.054797589778900146, 0.021722780540585518, 0.0076000867411494255, -0.010245686396956444, 0.023646852001547813, 0.003840930061414838, -0.00964441429823637, 0.018346032127738, -0.007460591848939657, 0.021337965503335, 0.042406562715768814, -0.028726404532790184, -0.01681639440357685, -0.018663505092263222, 0.01657588593661785, 0.012169759720563889, 0.053950995206832886, 0.07138309627771378, -0.03392140194773674, 0.0035354834981262684, -0.05345073714852333, 0.0106689827516675, 0.0695359855890274, -0.023319760337471962, 0.029380589723587036, -0.09997481107711792, 0.009259599260985851, 0.019740985706448555, 0.036653582006692886, 0.009851251728832722, -0.007749202661216259, -0.0352490097284317, 0.02978464402258396, -0.0384814515709877, 0.03515280783176422, -0.05995410308241844, 0.058414846658706665, -0.021010873839259148, -0.003922703210264444, -0.018220968544483185, 0.02884184941649437, -0.04844814911484718, -0.059838660061359406, -0.028110701590776443, 0.017845774069428444, 0.006075259298086166, 0.01824982836842537, 0.016700951382517815, -0.036211047321558, 0.004014096688479185, 0.07122916728258133, -0.06903572380542755, 0.009851251728832722, -0.0025325606111437082, -0.05583658814430237, -0.0449463352560997, -0.011226964183151722, 0.0009764668648131192, -0.042791374027729034, 0.03317101299762726, -0.006609189324080944, -0.012208241038024426, -0.06260932236909866, -0.026071183383464813, -0.004391695838421583, -0.03447938337922096, -0.0008958963444456458, 0.010428473353385925, -0.018172865733504295, 0.07357653975486755, 0.04575444757938385, -0.01696070097386837, -0.030438829213380814, 0.005647153127938509, -0.05995410308241844, -0.020068077370524406, 0.03016945905983448, 0.04206022620201111, 0.06133943423628807, 0.0007750405347906053, 0.03263227269053459, 0.03344038128852844, -0.11475168913602829, 0.08581364154815674, 0.06826609373092651, 0.006551467347890139, 0.018076661974191666, -0.03857765719294548, -0.010620880872011185, -0.023935463279485703, -0.02499370276927948, -0.005180565640330315, 0.03971285745501518, 0.01757640391588211, 0.01692221872508526, -0.0019180598901584744, 0.015431062318384647, 0.04513874277472496, -0.02855323813855648, -0.00025027975789271295, -0.018422994762659073, 0.012785462662577629, -0.047870926558971405, -0.04348404332995415, -0.03467178717255592, 0.014565229415893555, -0.01644119992852211, -0.011294306255877018, 0.05445125699043274, 0.01537334080785513, 0.007277804892510176, -0.03640345484018326, 0.036268770694732666, -0.05749129131436348, 0.09127800911664963, -0.05033373832702637, 0.06107006594538689, -0.02822614647448063, -0.02218455821275711, -0.045215707272291183, 0.01418041530996561, 0.0007431730628013611, -0.002179012168198824, 0.020779984071850777, -0.0046947370283305645, -0.046485595405101776, -0.05341225489974022, 0.030227180570364, 0.0497949980199337, -0.013016351498663425, -0.005175755359232426, -0.020587576553225517, 0.08450526744127274, -0.0010955188190564513, -0.057568252086639404, -0.05221933126449585, -0.012977870181202888, -0.013141416013240814, 0.023108111694455147, -0.02913045883178711, -0.003992450889199972, -0.03097756952047348, 0.020972391590476036, 0.02076074294745922, -0.023685334250330925, 0.0023714194539934397, -0.035037361085414886, 0.04613926261663437, 0.0347679927945137, -0.01692221872508526, -0.05364314466714859, 0.04710129648447037, -0.021645817905664444, -0.04109819233417511, -0.05125729367136955, 0.011092279106378555, 0.06411010026931763, -0.002163379220291972, 0.04375341162085533, -0.03861613944172859, 0.01064012199640274, 0.046639520674943924, 0.033055566251277924, 0.012419888749718666, -0.04713977873325348, 0.0136609161272645, 0.022146075963974, -0.008908456191420555, -0.055759623646736145, 0.06672684103250504, -0.08073408901691437, 0.01327610109001398, 0.01275660190731287, -0.051295775920152664, -0.044253669679164886, -0.016133349388837814, -0.027533479034900665, 0.007883887737989426, 0.022511649876832962, 0.01634499616920948, 0.027167905122041702, -0.012169759720563889, 0.012766221538186073, -0.03192036598920822, 0.1322222650051117, -0.01995263248682022, 0.044407594949007034, -0.05002588778734207, 0.05329681187868118, 0.05060311034321785, 0.012381407432258129, -0.019115662202239037, -0.04756307601928711, 0.025070667266845703, -0.03707687929272652, -0.018076661974191666, 0.041983265429735184, 0.012265963479876518, 0.025686370208859444, -0.10744021832942963, 0.023762296885252, -0.06576479971408844, 0.023492926731705666, -0.007422110065817833, -0.007075777277350426, 0.002900539431720972, -0.047255225479602814, 0.03505660220980644, -0.06942053884267807, -0.042214155197143555, 0.021915188059210777, 0.03986678645014763, -0.004206503741443157, -0.002482053590938449, -0.025359276682138443, 0.052950479090213776, 0.017518680542707443, -0.010957594029605389, -0.052911996841430664, 0.07811734825372696, 0.05564418062567711, 0.02988084778189659, -0.01539258100092411, -0.058222439140081406, 0.005546139553189278, -0.03074668161571026, 0.01653740368783474, 0.05837636440992355, -0.01610448770225048, -0.01498852577060461, 0.002460407791659236, -0.023127352818846703, -0.0012807107996195555, -0.05210388824343681, 0.07592390477657318, 0.037461694329977036, -0.0326707549393177, 0.014392063021659851, 0.026956258341670036, -0.0018531224923208356, 0.015402201563119888, 0.03251682594418526, -0.003872196190059185, 0.0704980194568634, -0.014218896627426147, -0.006541846785694361, 0.04306074604392052, 0.016383478417992592, 0.022223038598895073, 0.039174117147922516, 0.021337965503335, 0.0630711019039154, -0.005007399246096611, -0.021126316860318184, 0.010341890156269073, -0.0837356448173523, -0.11598309874534607, 0.01743209734559059, 0.02670612744987011, -0.018692364916205406, -0.033055566251277924, -0.012391027994453907, -0.0024988893419504166, 0.03659586235880852, -0.014950044453144073, 0.005916523281484842, 0.03197808563709259, 0.009985936805605888, -0.01489232201129198, -0.011631019413471222, 0.03707687929272652, 0.054566700011491776, 0.013381925411522388, -0.02670612744987011, -0.0552978478372097, -0.043407078832387924, 0.050718553364276886, 0.055182404816150665, 0.006825647782534361, 0.047486111521720886, 0.06487973034381866, 0.03634573146700859, -0.073384128510952, -0.002919780323281884, 0.014661433175206184, -0.02508990652859211, -0.017643745988607407, -0.0520654059946537, -0.019971873611211777, -0.005757787264883518, -0.015344479121267796, -0.012621916830539703, 0.05506695806980133, 0.010842149145901203, 0.02789905294775963, 0.014257377944886684, 0.011159621179103851, 0.0008796619367785752, 0.02508990652859211, -0.034806475043296814, -0.004451822955161333, 0.05248870328068733, 0.004398911260068417, -0.026379035785794258, 0.04067489504814148, -0.08081105351448059, 0.026763850823044777, 0.00874010007828474, 0.003961184527724981, 0.020779984071850777, 0.008687187917530537, -0.03544141724705696, -0.007032485678792, 0.05156514793634415, -0.02037592977285385, 0.005733736325055361, 0.0022655955981463194, 0.02609042450785637, 0.03853917494416237, -0.04229111596941948, -0.017941977828741074, -0.015787016600370407, -0.04944866523146629, -0.020876187831163406, 0.029900088906288147, 0.009692516177892685, 0.029188182204961777, -0.041636932641267776, 0.006099310237914324, -0.003910677507519722, 0.003946754150092602, 0.010322649963200092, 0.00833604484796524, -0.007258564233779907, 0.05864573270082474, 0.006488935090601444, 0.07677049934864044, 0.04775548353791237, -0.046254705637693405, 0.06284021586179733, -0.0342869758605957, 0.013670535758137703, -0.031285420060157776, 0.004701952449977398, 0.03515280783176422, 0.007941610179841518, -0.06472580134868622, -0.018471097573637962, 0.006320578511804342, -0.020683780312538147, -0.0005137874977663159, -0.0018134384881705046, 0.006724633742123842, -0.001195330172777176, 0.08350475132465363, -0.01128468569368124, -0.03659586235880852, -0.04467696696519852, 0.019077179953455925, 0.015594609081745148, -0.07842519879341125, 0.04802485182881355, 0.005291199777275324, -0.030862124636769295, 0.02218455821275711, -0.007205652073025703, 0.03068895824253559, -0.0008483957499265671, -0.033940643072128296, -0.04194478318095207, -0.007547175046056509, 0.008162878453731537, 0.02816842310130596, -0.06187817454338074, -0.031285420060157776, -0.0046779015101492405, 0.049910444766283035, 0.007980091497302055, -0.02318507619202137, 0.028380071744322777, -0.014305479824543, -0.02532079629600048, 0.038327526301145554, -0.010409233160316944, -0.020972391590476036, 0.028610959649086, 0.0006824444863013923, 0.021337965503335, 0.06495669484138489, -0.04317618906497955, 0.07203727960586548, 0.012169759720563889, 0.029496032744646072, 0.045215707272291183, 0.05318136885762215, 0.05829939991235733, 0.05572114512324333, 0.013651295565068722, 0.0071671707555651665, 0.0008604212198406458, -0.018086282536387444, 0.02337748184800148, -0.013295342214405537, -0.04840966686606407, 0.048486631363630295, 0.06818913668394089, 0.005950194783508778, 0.019933393225073814, 0.013632054440677166, -0.015219414606690407, 0.04086730256676674, -0.044215187430381775, 0.011207723058760166, 0.03738472983241081, 0.03326721489429474, 0.009692516177892685, -0.06087765842676163, 0.014950044453144073, -0.011890769004821777, 0.02884184941649437, -0.021799743175506592, 0.003542698686942458, -0.028591718524694443, -0.03809663653373718, 0.008206170052289963, -0.005344111938029528, 0.013891804032027721, 0.02024124376475811, 0.030554274097085, 0.047255225479602814, 0.030227180570364, -0.02204987220466137, -0.04902537167072296, -0.039174117147922516, 0.07192183285951614, -0.001542865764349699, -0.08927696943283081, -0.059184473007917404, 0.09697326272726059, -0.024262556806206703, 0.008114776574075222, -0.03496040031313896, -0.00007136355270631611, 0.04190630093216896, -0.04567748308181763, -0.06768887490034103, -0.01662398688495159, -0.004103085026144981, -0.032285939902067184, -0.016364237293601036, -0.04352252185344696, 0.04144452512264252, -0.03078516200184822, 0.009461627341806889, 0.03934728726744652, 0.0315355509519577, 0.020260484889149666, -0.026590684428811073, 0.015363720245659351, -0.006320578511804342, -0.04206022620201111, 0.0064360229298472404, -0.017932357266545296, -0.019635161384940147, -0.015286756679415703, 0.000179028938873671, 0.032285939902067184, 0.008485160768032074, -0.023300519213080406, 0.041175153106451035, -0.058183956891298294, 0.031285420060157776, 0.00704210577532649, 0.031246939674019814, 0.053527701646089554, 0.00008590683864895254, 0.04548507556319237, -0.01914452202618122, -0.030419588088989258, 0.01539258100092411, 0.007470211945474148, 0.014103452675044537, -0.000540844805072993, -0.030919848009943962, -0.026763850823044777, 0.030438829213380814, -0.02845703437924385, 0.0036581431049853563, -0.04309922829270363, 0.007484642323106527, 0.01501738652586937, -0.03093908727169037, 0.02964995987713337, -0.05583658814430237, -0.029188182204961777, -0.002539775799959898, -0.03334417939186096, -0.026994738727808, -0.011621398851275444, 0.0002856045321095735, -0.06942053884267807, 0.06518758088350296, 0.018663505092263222, -0.026013461872935295, -0.028110701590776443, -0.010341890156269073, 0.060454361140728, -0.007133499253541231, 0.026879293844103813, -0.043407078832387924, -0.014401683583855629, -0.04252200573682785, -0.048486631363630295, 0.04313770681619644, -0.03340190276503563, -0.04760155826807022, -0.011467472650110722, -0.027860572561621666, -0.07465402036905289, -0.024859018623828888, 0.0147095350548625, -0.03003477305173874, -0.0037639671936631203, 0.016037145629525185, -0.04775548353791237, 0.027725886553525925, -0.04213719069957733, -0.04983348026871681, -0.011611778289079666, -0.020876187831163406, 0.028091460466384888, 0.024070149287581444, 0.009437575936317444, -0.06807368993759155, -0.040174636989831924, 0.018220968544483185, 0.013054832816123962, -0.01762450486421585, 0.028187664225697517, 0.017941977828741074, -0.02228076197206974, -0.008109966292977333, 0.020106559619307518, -0.021818984299898148, 0.014517128467559814, 0.05179603397846222, 0.04760155826807022, 0.057221919298172, -0.021703539416193962, 0.031016051769256592, 0.028495516628026962, -0.034325454384088516, 0.03790423274040222, 0.00034092162968590856, -0.018557680770754814, -0.01380522083491087, 0.04348404332995415, 0.0001630952174309641, -0.008595794439315796, 0.019933393225073814, -0.008042623288929462, 0.028476275503635406, -0.06480276584625244, -0.023877741768956184, 0.10567007213830948, 0.029688440263271332, -0.03372899442911148, -0.019115662202239037, 0.052950479090213776, 0.054797589778900146, -0.038135118782520294, -0.052950479090213776, 0.03211277350783348, 0.05849180743098259, -0.012458370067179203, 0.031093014404177666, 0.06395617127418518, 0.037269286811351776, 0.037461694329977036, -0.004410936497151852, -0.04267593100667, 0.007277804892510176, 0.035095084458589554, -0.03701915591955185, 0.036942195147275925, -0.012881666421890259, -0.04567748308181763, 0.05968473479151726, -0.024570407345891, -0.02266557514667511, -0.021357206627726555, 0.023973945528268814, 0.020818466320633888, -0.010082140564918518, -0.07138309627771378, -0.013920665718615055, 0.03049655072391033, -0.04005919396877289, -0.04964107275009155, 0.03192036598920822, 0.014565229415893555, -0.0029991483315825462, -0.05460518226027489, -0.05987713858485222, 0.0019084395607933402, 0.0016931839054450393, -0.044022783637046814, 0.034652549773454666, -0.017499441280961037, 0.00382409431040287, 0.03563382476568222, -0.11659879982471466, -0.0036894092336297035, -0.013583952561020851, 0.014921183697879314, 0.0400976724922657, -0.011275066062808037, 0.01682601496577263, 0.0071623604744672775, 0.012650777585804462, -0.01461333129554987, 0.03707687929272652, -0.04640863090753555, 0.04775548353791237, -0.017133867368102074, 0.027783608064055443, -0.037750303745269775, -0.040597934275865555, 0.009918594732880592, -0.01943313330411911, 0.003687004093080759, -0.009230738505721092, 0.005122843198478222, 0.02560940757393837, 0.02551320381462574, 0.024531926959753036, 0.03193960711359978, -0.0032059859950095415, -0.01875970885157585, 0.060415882617235184, -0.03093908727169037, -0.04533115029335022, -0.02537851780653, -0.03640345484018326, -0.04232959821820259, -0.015257895924150944, -0.017278172075748444, 0.002017871243879199, -0.032978605479002, 0.03326721489429474, 0.005498037673532963, 0.050910960882902145 ]
30,702
networkx.classes.function
get_edge_attributes
Get edge attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name default: object (default=None) Default value of the edge attribute if there is no value set for that edge in graph. If `None` then edges without this attribute are not included in the returned dict. Returns ------- Dictionary of attributes keyed by edge. For (di)graphs, the keys are 2-tuples of the form: (u, v). For multi(di)graphs, the keys are 3-tuples of the form: (u, v, key). Examples -------- >>> G = nx.Graph() >>> nx.add_path(G, [1, 2, 3], color="red") >>> color = nx.get_edge_attributes(G, "color") >>> color[(1, 2)] 'red' >>> G.add_edge(3, 4) >>> color = nx.get_edge_attributes(G, "color", default="yellow") >>> color[(3, 4)] 'yellow'
def get_edge_attributes(G, name, default=None): """Get edge attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name default: object (default=None) Default value of the edge attribute if there is no value set for that edge in graph. If `None` then edges without this attribute are not included in the returned dict. Returns ------- Dictionary of attributes keyed by edge. For (di)graphs, the keys are 2-tuples of the form: (u, v). For multi(di)graphs, the keys are 3-tuples of the form: (u, v, key). Examples -------- >>> G = nx.Graph() >>> nx.add_path(G, [1, 2, 3], color="red") >>> color = nx.get_edge_attributes(G, "color") >>> color[(1, 2)] 'red' >>> G.add_edge(3, 4) >>> color = nx.get_edge_attributes(G, "color", default="yellow") >>> color[(3, 4)] 'yellow' """ if G.is_multigraph(): edges = G.edges(keys=True, data=True) else: edges = G.edges(data=True) if default is not None: return {x[:-1]: x[-1].get(name, default) for x in edges} return {x[:-1]: x[-1][name] for x in edges if name in x[-1]}
(G, name, default=None)
[ 0.07192987203598022, 0.009304385632276535, 0.0061586396768689156, 0.004972461145371199, -0.02220526523888111, -0.048813626170158386, 0.003874059533700347, -0.013977929949760437, 0.12298300862312317, -0.030195364728569984, -0.00984053872525692, -0.013939972035586834, 0.005214441567659378, 0.037938740104436874, 0.02429293841123581, 0.017659828066825867, -0.013721714727580547, 0.007306860759854317, 0.032624658197164536, 0.04179144650697708, 0.05936586856842041, -0.06464198976755142, -0.02112347073853016, -0.04361341893672943, 0.032757509499788284, 0.057809602469205856, 0.016634969040751457, 0.032852403819561005, 0.05853080004453659, 0.02537473477423191, -0.034351736307144165, -0.10301724821329117, -0.08236824721097946, 0.01832408830523491, 0.029512125998735428, 0.0007805055938661098, -0.022698715329170227, 0.028752971440553665, -0.055380310863256454, -0.028658077120780945, 0.02848726697266102, -0.03222610056400299, -0.003636823734268546, -0.020136568695306778, 0.03685694560408592, -0.026551423594355583, -0.020269421860575676, -0.04467623308300972, 0.011785871349275112, -0.07280290126800537, 0.04126003757119179, -0.00525714410468936, 0.043727289885282516, 0.06817205995321274, 0.019339457154273987, -0.06114988401532173, -0.046384330838918686, 0.027158746495842934, -0.03744528815150261, 0.06103600934147835, -0.007923673838376999, -0.02448272705078125, 0.06263023614883423, -0.007714906241744757, -0.06278206408023834, 0.016350286081433296, -0.01939639449119568, -0.032814446836709976, -0.051698412746191025, 0.022679736837744713, -0.020914701744914055, 0.011510677635669708, -0.025773290544748306, -0.03626859933137894, -0.008948531933128834, 0.06126375496387482, -0.016103561967611313, 0.024748431518673897, 0.04604271054267883, -0.011596082709729671, -0.025849206373095512, 0.022603821009397507, -0.04186736419796944, 0.024273959919810295, 0.02486230432987213, 0.015145129524171352, -0.026779169216752052, -0.006253533996641636, 0.038261380046606064, -0.05055968090891838, 0.002858690684661269, 0.019149668514728546, -0.03558535873889923, 0.055949676781892776, -0.01748901791870594, -0.08654359728097916, -0.005266633350402117, -0.006381641142070293, 0.07299268990755081, 0.01510717160999775, -0.03357360139489174, -0.02835441567003727, 0.0043295519426465034, -0.014841467142105103, -0.04076658934354782, -0.06821002066135406, -0.006604643072932959, -0.04368933290243149, 0.007069624960422516, -0.04752306267619133, -0.0365532822906971, -0.028240540996193886, 0.057809602469205856, -0.02425498142838478, 0.002117329044267535, 0.04718144237995148, 0.04649820551276207, -0.024236002936959267, -0.006590408738702536, -0.028430329635739326, -0.011273441836237907, 0.045587219297885895, 0.02383744716644287, 0.013541415333747864, -0.010865396820008755, -0.01893141120672226, -0.020041674375534058, 0.006239299662411213, 0.029227443039417267, 0.02998659759759903, 0.05344446748495102, 0.007596288342028856, -0.023951319977641106, 0.015401343815028667, 0.040462926030159, -0.021768750622868538, 0.010874886065721512, 0.08084993809461594, 0.09071894735097885, 0.02089572325348854, 0.005698402412235737, -0.021654877811670303, 0.02639959193766117, 0.007240434642881155, -0.03180856630206108, -0.07101888954639435, 0.03349768742918968, -0.04737123101949692, 0.004550181329250336, -0.0035727701615542173, 0.030157405883073807, 0.051888201385736465, -0.03027128055691719, -0.059441786259412766, 0.031466949731111526, -0.02154100500047207, -0.06293389946222305, 0.009318619966506958, -0.04205715283751488, 0.0008196494891308248, -0.04460031911730766, -0.010106242261826992, -0.014034866355359554, -0.07147438079118729, 0.047219399362802505, 0.04023518040776253, 0.030385153368115425, 0.011577104218304157, 0.052723269909620285, 0.0061349160969257355, -0.042095109820365906, -0.005821764934808016, 0.01016317866742611, -0.04342363029718399, 0.006343683693557978, 0.05302693322300911, 0.03814750537276268, -0.01116905827075243, 0.04463827610015869, -0.007672203704714775, 0.01189025491476059, -0.022888503968715668, -0.010884375311434269, -0.013484478928148746, 0.029322337359189987, -0.024691496044397354, 0.02256586402654648, -0.00023738401068840176, -0.03698979690670967, -0.029018675908446312, 0.0006577360909432173, -0.017849616706371307, -0.005636720918118954, 0.05818917974829674, 0.020554104819893837, -0.01179536059498787, -0.0163218192756176, 0.03440866991877556, 0.014253122732043266, 0.07618113607168198, 0.041715532541275024, -0.011747913435101509, -0.03511088714003563, 0.05708840861916542, 0.0056177424266934395, 0.005484890192747116, 0.06092213839292526, -0.07933162897825241, -0.02685508504509926, -0.006675813812762499, -0.011947191320359707, 0.014082313515245914, 0.031049413606524467, 0.0023260964080691338, 0.010153689421713352, 0.026095930486917496, -0.0007550027221441269, 0.051508624106645584, -0.00483723683282733, 0.035376593470573425, -0.06912100315093994, -0.032624658197164536, 0.044562362134456635, 0.05177432671189308, 0.04391707852482796, -0.05815122276544571, 0.015230534598231316, -0.003105415729805827, 0.009565345011651516, -0.010504798032343388, 0.06464198976755142, 0.002020062180235982, 0.02710181102156639, -0.0033236725721508265, -0.008307995274662971, 0.05055968090891838, 0.034161947667598724, -0.017052505165338516, 0.00020891572057735175, -0.007017433177679777, 0.047636937350034714, -0.0076295011676847935, -0.05063559487462044, 0.0631236881017685, 0.058682631701231, -0.07564973086118698, 0.003798144171014428, 0.0010468027321621776, -0.016056114807724953, -0.055342353880405426, -0.05204002931714058, 0.04513172805309296, 0.02009861171245575, 0.005261888727545738, -0.024122130125761032, 0.00046379584819078445, -0.0847216248512268, 0.014053844846785069, -0.00033005423028953373, -0.020952660590410233, 0.03670511394739151, 0.02770913392305374, -0.06255432218313217, 0.03833729401230812, 0.053786084055900574, 0.012886645272374153, 0.03232099488377571, -0.003601238364353776, -0.06635008752346039, -0.005821764934808016, 0.09322415292263031, -0.03366849571466446, -0.018817538395524025, -0.046004753559827805, 0.022679736837744713, -0.007748119067400694, 0.0036890157498419285, 0.0010527336271479726, -0.010922333225607872, -0.048623837530612946, -0.04418278485536575, 0.03196039795875549, -0.07416938245296478, 0.0674508661031723, -0.05302693322300911, 0.008820424787700176, -0.01870366558432579, -0.013655289076268673, -0.011956681497395039, 0.005627231672406197, 0.10248583555221558, 0.007624756544828415, -0.043727289885282516, -0.0015337290242314339, 0.01730871945619583, 0.004035379737615585, 0.04957278072834015, -0.0032714807894080877, 0.05181228369474411, 0.055190522223711014, 0.05602559074759483, -0.01958618313074112, 0.053558338433504105, -0.0069889649748802185, -0.03072677180171013, 0.01664445921778679, 0.04080454632639885, -0.01046684104949236, -0.015600621700286865, -0.013190306723117828, -0.054772987961769104, 0.017147399485111237, -0.02909458987414837, 0.02144611068069935, -0.046384330838918686, 0.023856425657868385, 0.02774709090590477, -0.027595261111855507, 0.016492627561092377, -0.012231874279677868, -0.014319549314677715, 0.0745869129896164, -0.026190824806690216, -0.026323677971959114, -0.011036206036806107, 0.04714348539710045, 0.005869212094694376, 0.04585292190313339, 0.08062218874692917, 0.02042125165462494, -0.012715835124254227, -0.023609699681401253, -0.037521202117204666, 0.02956906147301197, -0.0694626197218895, 0.07329635322093964, 0.004153997637331486, 0.009081384167075157, -0.009100362658500671, -0.007434967905282974, -0.02835441567003727, 0.015021766535937786, -0.02233811654150486, -0.02527984045445919, 0.04585292190313339, 0.02653244510293007, 0.030290259048342705, 0.004407839849591255, -0.014841467142105103, -0.004526457749307156, -0.0060115535743534565, 0.039703771471977234, -0.031694695353507996, 0.013750183396041393, -0.026570402085781097, 0.006438578013330698, -0.0029844255186617374, -0.036591239273548126, 0.04387912154197693, 0.046801865100860596, -0.0035727701615542173, 0.016872204840183258, 0.012564004398882389, -0.037141624838113785, 0.030859624966979027, -0.013171328231692314, 0.008013823069632053, 0.06194699555635452, 0.018314598128199577, -0.035471487790346146, -0.0020093866623938084, 0.019832907244563103, 0.008597423322498798, -0.016900673508644104, 0.02374255284667015, -0.035983916372060776, 0.00885838270187378, 0.0012798868119716644, 0.02080082893371582, 0.026475507766008377, -0.04084250330924988, -0.012402684427797794, -0.005826509557664394, 0.05215390399098396, 0.028278499841690063, -0.03632553666830063, 0.06794431805610657, 0.01674884371459484, 0.01725178211927414, 0.00926168356090784, -0.05970748886466026, -0.028752971440553665, -0.019643118605017662, 0.025640437379479408, -0.02634265646338463, -0.04615658521652222, 0.004654564894735813, -0.04368933290243149, -0.08381064236164093, 0.0025336777325719595, -0.07819289714097977, 0.08191275596618652, -0.021237343549728394, -0.014604232273995876, -0.0019939662888646126, 0.019434351474046707, -0.009831048548221588, -0.013361116871237755, 0.04452440142631531, -0.006386385764926672, 0.01940588280558586, 0.05784756317734718, -0.022414032369852066, -0.04365137591958046, 0.043119966983795166, 0.038223423063755035, 0.0694626197218895, 0.020022695884108543, 0.04809242859482765, -0.002642806153744459, -0.021578961983323097, 0.009304385632276535, -0.006661579478532076, -0.018409492447972298, 0.015069213695824146, 0.0032003100495785475, -0.024406813085079193, 0.06524931639432907, -0.047219399362802505, 0.03890665993094444, -0.0161889661103487, -0.012639920227229595, 0.011766892857849598, -0.03977968916296959, 0.035983916372060776, 0.02928437851369381, 0.000030303157473099418, -0.057012490928173065, -0.00993543304502964, -0.023514805361628532, -0.0302143432199955, -0.01990882307291031, -0.043157923966646194, -0.010571224614977837, -0.039703771471977234, -0.07781331986188889, -0.0252229031175375, 0.05082538351416588, 0.09109852463006973, -0.06881733983755112, -0.013418053276836872, -0.03196039795875549, 0.06653987616300583, -0.00040774891385808587, -0.03516782447695732, 0.03408602997660637, -0.019756991416215897, 0.018115321174263954, 0.002479113405570388, 0.009712430648505688, -0.011871276423335075, -0.02009861171245575, -0.03799567371606827, -0.012886645272374153, 0.0042702434584498405, 0.03977968916296959, 0.03473130986094475, 0.005252399016171694, -0.03340279310941696, -0.007961630821228027, 0.080394446849823, -0.04737123101949692, -0.02592512033879757, -0.05583580210804939, 0.013788141310214996, -0.00459525641053915, -0.029929660260677338, 0.018058383837342262, 0.008379166014492512, -0.040083348751068115, 0.05564601346850395, -0.00984053872525692, 0.02867705561220646, -0.02093368209898472, 0.05693657696247101, 0.02009861171245575, -0.015752453356981277, 0.006965241394937038, -0.06726107746362686, 0.03245384991168976, -0.03444662690162659, -0.012582983821630478, -0.02550758607685566, 0.04137391224503517, 0.04144982621073723, 0.04034905508160591, 0.03605983033776283, -0.014993298798799515, 0.006694792304188013, -0.004668799228966236, -0.005200207233428955, -0.07287881523370743, 0.016900673508644104, -0.025109030306339264, -0.02490026317536831, -0.017640849575400352, -0.05686065927147865, -0.007610522210597992, 0.09049119800329208, 0.018864985555410385, 0.0306888148188591, 0.020952660590410233, 0.08221641927957535, 0.02374255284667015, 0.02639959193766117, -0.019206605851650238, 0.024520685896277428, 0.004438680596649647, 0.03539557009935379, -0.021977517753839493, 0.015894794836640358, 0.03562331944704056, -0.037236519157886505, 0.01958618313074112, -0.05997319519519806, 0.053975872695446014, 0.020307378843426704, -0.029720893129706383, -0.010371946729719639, 0.019889844581484795, 0.011225994676351547, 0.07633297145366669, -0.042322855442762375, 0.038735851645469666, 0.003855080809444189, 0.0030722026713192463, 0.017318207770586014, 0.05526643618941307, -0.04938299208879471, 0.0188839640468359, 0.08145726472139359, -0.010893864557147026, -0.009973390027880669, 0.052343692630529404, -0.040500883013010025, -0.04034905508160591, 0.017963489517569542, 0.02230015955865383, 0.030802687630057335, -0.09922147542238235, -0.025488607585430145, 0.01566704735159874, -0.049079328775405884, -0.0528751015663147, -0.025052092969417572, -0.05173636972904205, -0.002281021559610963, 0.0031362564768642187, -0.012440642341971397, -0.010267562232911587, -0.01669190637767315, -0.0008143116720020771, -0.014376485720276833, -0.015875814482569695, 0.027025895193219185, -0.0035609083715826273, 0.02672223374247551, 0.006614132318645716, -0.020041674375534058, 0.00972666498273611, -0.04023518040776253, -0.010286541655659676, 0.04520764201879501, -0.0021137704607099295, 0.020724913105368614, 0.010409903712570667, -0.007121816743165255, 0.002434038557112217, 0.011833318509161472, -0.017697785049676895, -0.020686956122517586, -0.021332237869501114, -0.00818463321775198, 0.010922333225607872, -0.000245242437813431, 0.026570402085781097, 0.010457350872457027, 0.038223423063755035, -0.04634637385606766, 0.01361733116209507, -0.031144307926297188, -0.033744409680366516, 0.019510267302393913, -0.018912432715296745, -0.01613203063607216, -0.0012253226013854146, 0.03125818073749542, 0.033972159028053284, -0.06995607167482376, 0.015277981758117676, -0.04551130160689354, 0.01627437211573124, 0.049079328775405884, 0.02383744716644287, -0.04042496904730797, -0.010030326433479786, 0.00450036209076643, -0.03727447986602783, -0.01375967264175415, -0.022964419797062874, -0.022641777992248535, -0.004284477327018976, -0.029682934284210205, -0.005788552109152079, 0.008336463943123817, -0.012212895788252354, -0.02416008710861206, 0.06889325380325317, -0.021009596064686775, 0.04080454632639885, -0.014613721519708633, -0.04737123101949692, -0.03545250743627548, -0.003952347207814455, 0.006025787442922592, -0.010855907574295998, -0.01813429966568947, 0.019054774194955826, -0.03232099488377571, -0.003634451422840357, -0.0020568338222801685, -0.04243673011660576, 0.02397029846906662, -0.026152867823839188, 0.01786859519779682, -0.07640888541936874, 0.04873770847916603, -0.016663437709212303, -0.05078742653131485, 0.045587219297885895, -0.04448644444346428, 0.07948346436023712, -0.03309912979602814, 0.01800144836306572, -0.021009596064686775, 0.0810776874423027, 0.04349954426288605, -0.0438411645591259, 0.053975872695446014, -0.03273853287100792, 0.021806709468364716, -0.016578033566474915, 0.03884972259402275, -0.011453741230070591, -0.004851470701396465, 0.0035182060673832893, -0.05686065927147865, -0.014860446564853191, -0.03309912979602814, -0.03427581861615181, -0.03769201412796974, 0.0014293453423306346, 0.021389173343777657, -0.010637650266289711, -0.029720893129706383, 0.003442290471866727, -0.056784745305776596, 0.012478599324822426, 0.042740389704704285, -0.04342363029718399, -0.04023518040776253, 0.042133066803216934, 0.07170213013887405, -0.011719445697963238, -0.04691573977470398, 0.00037246011197566986, 0.05674678832292557, -0.006253533996641636, 0.02028840035200119, -0.003295204369351268, 0.006799176335334778, 0.03473130986094475, 0.0018777208169922233, 0.01448086928576231, 0.02410314977169037, 0.01116905827075243, -0.016312329098582268, -0.0160845834761858, 0.019946780055761337, 0.0640726238489151, 0.00009163230424746871, -0.0667676255106926, 0.046612076461315155, 0.017754722386598587, -0.002766168676316738, -0.032757509499788284, -0.006609387695789337, 0.029815787449479103, -0.013332648202776909, -0.0016428574454039335, -0.019424861297011375, 0.01822919398546219, -0.03309912979602814, 0.014310059137642384, 0.009982879273593426, -0.038356274366378784, -0.07811698317527771, 0.049686651676893234, -0.01112161111086607, -0.003786282381042838, -0.07139846682548523, -0.04562517628073692, 0.0003330196486786008, -0.016075093299150467, 0.05078742653131485, 0.028145648539066315, -0.013512947596609592, -0.05572193115949631, -0.11379723995923996, 0.07477670162916183, -0.049041371792554855, 0.05185024067759514, 0.010504798032343388, 0.024558642879128456, -0.054772987961769104, -0.005546571686863899, -0.05568397045135498, -0.04448644444346428, -0.02527984045445919, 0.02313522808253765, -0.033972159028053284, 0.04832017421722412, 0.02195853926241398, 0.0906430333852768, -0.05036989226937294, -0.0160845834761858, -0.01030552014708519, -0.01781165972352028, -0.018172256648540497, 0.012193916365504265, -0.008644870482385159, 0.023514805361628532, -0.03600289672613144, 0.02937927283346653, -0.03600289672613144, -0.054165661334991455, 0.015078702941536903, 0.04243673011660576, -0.03615472465753555, 0.0018207842949777842, 0.0015266119735315442, 0.016056114807724953, -0.010732544586062431, -0.0014779786579310894, 0.020041674375534058, -0.04399299621582031, 0.004407839849591255, -0.042930178344249725, 0.04304405301809311, -0.000019405142666073516, -0.01907375268638134, 0.02966395579278469, -0.03366849571466446, -0.043385669589042664, -0.04649820551276207, 0.010580713860690594, -0.0010521404910832644, 0.035376593470573425 ]
30,703
networkx.classes.function
get_node_attributes
Get node attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name default: object (default=None) Default value of the node attribute if there is no value set for that node in graph. If `None` then nodes without this attribute are not included in the returned dict. Returns ------- Dictionary of attributes keyed by node. Examples -------- >>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3], color="red") >>> color = nx.get_node_attributes(G, "color") >>> color[1] 'red' >>> G.add_node(4) >>> color = nx.get_node_attributes(G, "color", default="yellow") >>> color[4] 'yellow'
def get_node_attributes(G, name, default=None): """Get node attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name default: object (default=None) Default value of the node attribute if there is no value set for that node in graph. If `None` then nodes without this attribute are not included in the returned dict. Returns ------- Dictionary of attributes keyed by node. Examples -------- >>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3], color="red") >>> color = nx.get_node_attributes(G, "color") >>> color[1] 'red' >>> G.add_node(4) >>> color = nx.get_node_attributes(G, "color", default="yellow") >>> color[4] 'yellow' """ if default is not None: return {n: d.get(name, default) for n, d in G.nodes.items()} return {n: d[name] for n, d in G.nodes.items() if name in d}
(G, name, default=None)
[ 0.025426369160413742, 0.029146846383810043, 0.014236897230148315, -0.02207981050014496, 0.010179895907640457, 0.003662051633000374, -0.013638629578053951, -0.004087382461875677, 0.13790066540241241, -0.02925902046263218, -0.003961185459047556, 0.0068567064590752125, 0.02006065845489502, 0.058891959488391876, 0.016639314591884613, -0.0301190298050642, -0.0027389435563236475, -0.006057458464056253, 0.035746484994888306, 0.014152766205370426, 0.059041526168584824, -0.028137268498539925, -0.008478572592139244, -0.03563430905342102, 0.027576394379138947, 0.008385092951357365, 0.04217785969376564, 0.016461703926324844, 0.023837221786379814, 0.05421799421310425, -0.019387606531381607, -0.08211221545934677, -0.077774778008461, 0.008212156593799591, 0.011301646940410137, -0.008146720938384533, -0.02108892984688282, 0.03505473583936691, -0.07437212765216827, -0.05040403828024864, 0.02886640839278698, -0.010301418602466583, -0.042290035635232925, -0.040682192891836166, 0.02006065845489502, -0.037167370319366455, 0.027127692475914955, -0.012946883216500282, 0.020808491855859756, -0.07029643654823303, 0.05287189409136772, -0.03090425580739975, 0.012357963249087334, 0.07067035138607025, 0.0008325499948114157, -0.058480650186538696, -0.02866075374186039, 0.01658322848379612, -0.0231641698628664, 0.05548931285738945, 0.008773032575845718, -0.0057629989460110664, 0.04214046895503998, -0.023182867094874382, -0.05687280744314194, 0.015171690843999386, -0.03314775973558426, -0.04397266358137131, -0.04752487689256668, -0.010133156552910805, -0.03211948648095131, 0.00797378458082676, 0.011460562236607075, -0.026454642415046692, 0.01619996316730976, 0.0651363730430603, -0.018779991194605827, 0.001889450359158218, 0.020995451137423515, 0.01381624024361372, -0.027090301737189293, 0.031240781769156456, -0.04367353022098541, 0.012142960913479328, 0.014049938879907131, -0.018153680488467216, -0.026548121124505997, -0.017695631831884384, 0.037148673087358475, -0.04827271029353142, -0.03294210508465767, 0.04778661951422691, 0.015611043199896812, 0.07145557552576065, -0.000996723072603345, -0.05447973683476448, 0.0163588784635067, 0.0031105238012969494, 0.07321298867464066, 0.03944826498627663, -0.02069631777703762, 0.024117659777402878, -0.013657325878739357, -0.0020787459798157215, -0.0198363084346056, -0.04629094898700714, -0.04565529152750969, -0.021743284538388252, 0.014171461574733257, -0.0026968778111040592, -0.0656224712729454, -0.06666943430900574, 0.09108623117208481, -0.03974739834666252, 0.044309187680482864, 0.022846341133117676, 0.034699514508247375, 0.0030754690524190664, -0.015704521909356117, -0.024024181067943573, -0.0038186293095350266, 0.03125947713851929, 0.05305885151028633, 0.010002285242080688, -0.0142275495454669, -0.007520409766584635, 0.012946883216500282, 0.024828102439641953, 0.024454185739159584, 0.04587963968515396, 0.04161698371171951, 0.012647748924791813, -0.005061903968453407, 0.05133883282542229, 0.05444234609603882, -0.01866781711578369, 0.002629105234518647, 0.08405658602714539, 0.10694032162427902, 0.0381021611392498, 0.009249776601791382, -0.05915370211005211, 0.015826046466827393, -0.0018485531909391284, -0.024454185739159584, -0.08697313815355301, 0.029240325093269348, -0.02357547916471958, -0.023295041173696518, -0.032026007771492004, 0.04524398222565651, 0.04857184365391731, 0.01861172914505005, -0.0348677784204483, -0.0034657451324164867, 0.008263570256531239, -0.04382309690117836, -0.036157794296741486, -0.05515278875827789, 0.004818858113139868, -0.039597831666469574, 0.01260100957006216, -0.0034143314696848392, -0.05302146077156067, 0.039597831666469574, 0.0074643222615122795, 0.029651634395122528, 0.011815783567726612, 0.03711128234863281, 0.017125407233834267, -0.02456635981798172, -0.030175117775797844, 0.01879868656396866, -0.03718606382608414, 0.00741758244112134, 0.02146284654736519, 0.03806477040052414, -0.04875880479812622, 0.025706807151436806, -0.003788248635828495, -0.011843827553093433, -0.02520201914012432, -0.020004570484161377, -0.009516192600131035, -0.004117763135582209, -0.0005240683094598353, 0.01721888780593872, -0.00030088648782111704, -0.04386048763990402, -0.022865036502480507, 0.025314195081591606, 0.0060621327720582485, -0.026118116453289986, 0.0659216046333313, 0.03316645696759224, -0.003519495716318488, -0.006501485127955675, 0.032829929143190384, -0.02047196589410305, 0.09392800182104111, 0.0744469165802002, -0.005141361616551876, -0.020845884457230568, 0.06423897296190262, -0.0011755021987482905, -0.004991794470697641, 0.022416336461901665, -0.022659381851553917, -0.036139097064733505, -0.021761981770396233, -0.011572737246751785, 0.009852718561887741, 0.01595691591501236, 0.027707263827323914, -0.037952594459056854, 0.022584598511457443, -0.008319657295942307, 0.036943018436431885, 0.0025917135644704103, -0.006655726116150618, -0.05649888888001442, -0.04214046895503998, 0.04666486755013466, 0.035952139645814896, 0.05466669425368309, -0.04075697436928749, 0.007450300268828869, 0.010292070917785168, 0.00017863309767562896, -0.035559527575969696, 0.07141818851232529, 0.01135773491114378, 0.030455555766820908, 0.03481169044971466, 0.007515735924243927, -0.03569039702415466, 0.059490226209163666, -0.003232046728953719, 0.01903238520026207, -0.02398678846657276, 0.009572280570864677, -0.014666901901364326, -0.043523963540792465, 0.047375310212373734, 0.0527971088886261, -0.04999272897839546, -0.01677018590271473, 0.0022154594771564007, -0.017097363248467445, -0.04730052500963211, -0.05021708086133003, 0.032680362462997437, 0.030025551095604897, 0.011236212216317654, -0.03189513832330704, 0.03361515700817108, -0.07235297560691833, 0.03133426234126091, -0.011133384890854359, -0.01124555990099907, 0.0369243249297142, 0.004617877304553986, -0.07635389268398285, 0.03180165961384773, 0.07040861248970032, -0.009291842579841614, 0.024921581149101257, 0.012311223894357681, -0.05773281678557396, -0.028941191732883453, 0.07919566333293915, 0.005833108443766832, -0.009492822922766209, -0.07889652997255325, 0.039186522364616394, -0.029614241793751717, 0.009656411595642567, 0.007137144450098276, 0.007814869284629822, -0.03464343026280403, -0.05040403828024864, 0.032418619841337204, -0.07497040182352066, 0.03479299694299698, -0.05429277941584587, -0.010469681583344936, -0.019387606531381607, 0.01966804452240467, -0.05219884216785431, 0.00025180986267514527, 0.07186688482761383, 0.0006672085146419704, -0.05874239280819893, 0.0021149690728634596, 0.008343027904629707, -0.00022069878468755633, -0.015816697850823402, 0.014564074575901031, 0.01921934448182583, 0.04812314361333847, 0.055377136915922165, -0.03767215833067894, 0.022865036502480507, -0.028155965730547905, -0.01681692525744438, 0.03630736097693443, 0.042290035635232925, 0.0033442219719290733, -0.041056107729673386, 0.02746421843767166, -0.04745009168982506, -0.011367082595825195, -0.001073259161785245, 0.010563161224126816, -0.0527971088886261, -0.01964934915304184, 0.03557822108268738, -0.03481169044971466, 0.03168948367238045, -0.015405388548970222, -0.018994994461536407, 0.05799455940723419, -0.03458734229207039, 0.002467853482812643, -0.028529882431030273, 0.0401587076485157, 0.013189929537475109, 0.07927044481039047, 0.05567627027630806, 0.03073599375784397, -0.030193813145160675, -0.001831025816500187, -0.04161698371171951, 0.03133426234126091, -0.07111905515193939, 0.06005110219120979, 0.008969338610768318, -0.001645235694013536, -0.01095577422529459, 0.001899966737255454, -0.03464343026280403, 0.009805978275835514, -0.036980412900447845, -0.014208853244781494, 0.02293981984257698, 0.02598724514245987, 0.04176655039191246, 0.0007232960779219866, -0.01167556457221508, -0.04434657841920853, -0.004456625785678625, 0.06678161025047302, -0.0348677784204483, 0.011525997892022133, -0.024865493178367615, 0.016471052542328835, 0.039597831666469574, -0.022154593840241432, 0.026099421083927155, 0.06068676337599754, -0.018125636503100395, 0.030605122447013855, 0.023874612525105476, -0.03621388226747513, 0.02535158582031727, -0.013844284228980541, 0.035316478461027145, 0.07482083141803741, 0.0388873890042305, -0.05586323142051697, 0.005412451457232237, 0.02146284654736519, -0.049057938158512115, -0.015480171889066696, -0.009843369945883751, -0.013591890223324299, 0.010376201942563057, -0.03129686787724495, -0.0171908438205719, 0.00266415998339653, -0.03952304646372795, -0.019518477842211723, -0.007038991432636976, 0.04318743571639061, -0.021818067878484726, -0.05582583695650101, 0.06165894493460655, 0.020808491855859756, -0.002409429056569934, -0.008417811244726181, -0.07156775146722794, -0.04520658776164055, -0.031633395701646805, 0.044944848865270615, -0.04225264489650726, -0.03008163906633854, 0.03206339851021767, -0.04771183431148529, -0.08084090054035187, -0.024435488507151604, -0.052909284830093384, 0.05466669425368309, -0.01196535024791956, -0.020397182554006577, -0.00551995262503624, 0.03821433708071709, 0.002131327986717224, -0.05197449028491974, 0.05915370211005211, 0.042514387518167496, 0.009992937557399273, 0.05623714625835419, 0.0009727689903229475, -0.05892935022711754, 0.04872141033411026, 0.007945740595459938, 0.06117285415530205, 0.04464571550488472, 0.05541452765464783, -0.020995451137423515, -0.038401298224925995, -0.020322399213910103, -0.018163027241826057, -0.001194198033772409, 0.04528137296438217, 0.007515735924243927, 0.010441637597978115, 0.035129521042108536, -0.049431852996349335, 0.04625355824828148, -0.02090197242796421, 0.00772139010950923, 0.015078211203217506, -0.0284550990909338, 0.07448430359363556, 0.007908348925411701, -0.003554550465196371, -0.0450570210814476, -0.026697687804698944, 0.016957145184278488, -0.01239535491913557, -0.010516420938074589, -0.015498868189752102, -0.016835622489452362, -0.06244417279958725, -0.034531254321336746, -0.017461933195590973, 0.032250359654426575, 0.049656204879283905, -0.06610856205224991, -0.02333243377506733, -0.029726417735219002, 0.07859739661216736, 0.009226406924426556, -0.026062028482556343, 0.03724215179681778, -0.07710172981023788, 0.01290014386177063, -0.012965578585863113, -0.02867944911122322, -0.009174993261694908, 0.0018625750672072172, 0.008847815915942192, 0.015480171889066696, 0.011441865935921669, 0.02725856378674507, 0.024921581149101257, -0.006160285789519548, -0.02065892517566681, 0.005893869791179895, 0.0828600525856018, -0.018695859238505363, -0.041280459612607956, -0.0945262685418129, 0.01147925853729248, -0.008759010583162308, -0.056984979659318924, 0.03587735444307327, -0.010151851922273636, -0.0458422489464283, 0.036326054483652115, -0.010750119574368, 0.07852261513471603, 0.0066977920942008495, 0.039373479783535004, 0.00920303724706173, -0.003327863058075309, -0.016471052542328835, -0.03234383836388588, 0.0184154212474823, -0.019817611202597618, -0.0323251411318779, -0.016414964571595192, 0.026379859074950218, 0.008656183257699013, 0.014096678234636784, 0.011525997892022133, -0.047225743532180786, 0.015816697850823402, 0.031839050352573395, -0.030866865068674088, -0.02030370384454727, 0.04475788772106171, 0.01697584055364132, 0.0017281986074522138, -0.0007501713698729873, -0.06902511417865753, -0.0031128607224673033, 0.07612954080104828, 0.02826813980937004, 0.039223913103342056, 0.03146513178944588, 0.04976838082075119, 0.0060901762917637825, 0.040831759572029114, -0.039822183549404144, -0.005992023274302483, 0.0071558402851223946, 0.013975155539810658, -0.04255177825689316, 0.011217515915632248, 0.027183780446648598, -0.021257193759083748, 0.006875402759760618, -0.04049523174762726, 0.0641641914844513, 0.04195351153612137, -0.0328112356364727, -0.031614698469638824, 0.033054281026124954, 0.011367082595825195, 0.03475560247898102, -0.0687633752822876, 0.026678992435336113, -0.014068634249269962, -0.0012444432359188795, 0.042476993054151535, 0.06730509549379349, -0.03174557164311409, 0.01860238052904606, 0.10237853229045868, -0.030866865068674088, 0.050067514181137085, 0.05631193146109581, -0.029932072386145592, -0.014003199525177479, 0.033652547746896744, 0.017256278544664383, 0.003785911714658141, -0.08816967904567719, -0.0017539053224027157, -0.05833108350634575, -0.06794075667858124, -0.042065683752298355, -0.004680975805968046, -0.06794075667858124, 0.010329462587833405, -0.02454766444861889, 0.00848792027682066, -0.006337896455079317, 0.0030520991422235966, -0.018480857834219933, -0.00430705863982439, -0.00922173261642456, -0.019611956551671028, -0.0243420097976923, -0.01188121922314167, 0.006613660603761673, -0.0147416852414608, 0.04561789706349373, -0.015087558887898922, 0.02436070516705513, 0.04890837147831917, 0.009609672240912914, 0.017779763787984848, -0.01054446492344141, 0.007398886606097221, 0.024472881108522415, -0.0027062257286161184, -0.03813955560326576, -0.02950206771492958, -0.004267330281436443, 0.0068567064590752125, 0.01576060988008976, -0.005702237132936716, 0.03335341438651085, -0.0463283397257328, 0.02209850586950779, -0.02886640839278698, 0.0006683769752271473, -0.02230416052043438, -0.0017924655694514513, 0.027595089748501778, -0.014162113890051842, -0.020752403885126114, 0.012002741917967796, 0.007651280611753464, 0.03380211442708969, -0.03576517850160599, 0.011909263208508492, -0.045318763703107834, -0.00023486674763262272, 0.042103078216314316, 0.03664388507604599, -0.04116828367114067, -0.007740085944533348, -0.008300961926579475, -0.015872785821557045, -0.006950186099857092, -0.038176946341991425, -0.021219801157712936, -0.03707389160990715, -0.031016431748867035, 0.0011182461166754365, 0.020845884457230568, -0.0034657451324164867, -0.012638401240110397, 0.034923866391181946, 0.021986331790685654, -0.0011988719925284386, -0.005767672788351774, -0.04887097701430321, -0.016414964571595192, 0.0012210733257234097, 0.034736908972263336, -0.02030370384454727, -0.01657387986779213, 0.006412679795175791, -0.03929869830608368, 0.0004995299968868494, 0.006716487929224968, -0.054965827614068985, 0.032231662422418594, -0.03322254493832588, -0.0005524042644537985, -0.03828912228345871, 0.038176946341991425, -0.02378113381564617, -0.07347472757101059, 0.0352603904902935, -0.05100230500102043, 0.04920750483870506, -0.021388063207268715, 0.005664845462888479, -0.0031619372311979532, 0.012918839231133461, 0.05709715560078621, 0.005108643788844347, 0.08308440446853638, -0.03157730773091316, -0.022808948531746864, -0.016938449814915657, 0.04397266358137131, -0.011310995556414127, 0.010525769554078579, -0.025875071063637733, -0.05504061281681061, 0.005604084115475416, -0.0328112356364727, -0.044309187680482864, -0.051226656883955, 0.009062818251550198, 0.03911174088716507, 0.027071604505181313, -0.013077754527330399, -0.049431852996349335, -0.055788446217775345, -0.017153451219201088, 0.007903674617409706, -0.020322399213910103, -0.03855086490511894, 0.04685182496905327, 0.09362886846065521, -0.01906977780163288, -0.026978125795722008, 0.004152818117290735, 0.06184590607881546, 0.020752403885126114, 0.008665530942380428, -0.01985500380396843, 0.04303786903619766, 0.022584598511457443, 0.006099524442106485, 0.014077982865273952, 0.0011445372365415096, 0.029015975072979927, -0.04098132625222206, -0.04195351153612137, 0.02454766444861889, 0.1223457083106041, -0.015255821868777275, -0.06760422885417938, 0.07022164762020111, 0.03542865440249443, 0.0054545169696211815, -0.00773541210219264, -0.027314651757478714, 0.07564345002174377, -0.008744988590478897, -0.00941336527466774, -0.033054281026124954, -0.0034353642258793116, -0.04625355824828148, 0.021500239148736, -0.0036784105468541384, -0.03821433708071709, -0.05111448094248772, 0.052535366266965866, -0.00973119493573904, 0.005225493106991053, -0.045131806284189224, -0.03331602364778519, 0.0076980204321444035, 0.01740584522485733, 0.02598724514245987, 0.0396726168692112, -0.014040591195225716, -0.051226656883955, -0.09497497230768204, 0.06218243017792702, -0.03273645043373108, 0.02004196122288704, 0.018546292558312416, 0.07762520760297775, -0.04315004497766495, -0.0010060709901154041, -0.05365711823105812, -0.09243233501911163, -0.004641247447580099, 0.021780677139759064, -0.0028254117351025343, 0.06573464721441269, 0.010937077924609184, 0.028567275032401085, -0.044720496982336044, -0.026959430426359177, -0.00551995262503624, -0.015386693179607391, -0.051488399505615234, 0.029184237122535706, -0.011525997892022133, 0.03709258511662483, -0.015022123232483864, 0.020378487184643745, -0.005384407471865416, -0.05339537560939789, 0.00982467457652092, 0.022995907813310623, -0.01783584989607334, 0.007927044294774532, 0.022397641092538834, -0.00212081172503531, -0.020135441794991493, -0.02439809776842594, 0.06121024489402771, -0.020378487184643745, -0.013517106883227825, -0.021257193759083748, 0.05059099569916725, -0.02107023447751999, -0.017714327201247215, -0.008558030240237713, -0.04561789706349373, -0.03671867027878761, -0.03712997958064079, -0.01576060988008976, 0.014171461574733257, 0.05526496097445488 ]
30,705
networkx.algorithms.cycles
girth
Returns the girth of the graph. The girth of a graph is the length of its shortest cycle, or infinity if the graph is acyclic. The algorithm follows the description given on the Wikipedia page [1]_, and runs in time O(mn) on a graph with m edges and n nodes. Parameters ---------- G : NetworkX Graph Returns ------- int or math.inf Examples -------- All examples below (except P_5) can easily be checked using Wikipedia, which has a page for each of these famous graphs. >>> nx.girth(nx.chvatal_graph()) 4 >>> nx.girth(nx.tutte_graph()) 4 >>> nx.girth(nx.petersen_graph()) 5 >>> nx.girth(nx.heawood_graph()) 6 >>> nx.girth(nx.pappus_graph()) 6 >>> nx.girth(nx.path_graph(5)) inf References ---------- .. [1] `Wikipedia: Girth <https://en.wikipedia.org/wiki/Girth_(graph_theory)>`_
def recursive_simple_cycles(G): """Find simple cycles (elementary circuits) of a directed graph. A `simple cycle`, or `elementary circuit`, is a closed path where no node appears twice. Two elementary circuits are distinct if they are not cyclic permutations of each other. This version uses a recursive algorithm to build a list of cycles. You should probably use the iterator version called simple_cycles(). Warning: This recursive version uses lots of RAM! It appears in NetworkX for pedagogical value. Parameters ---------- G : NetworkX DiGraph A directed graph Returns ------- A list of cycles, where each cycle is represented by a list of nodes along the cycle. Example: >>> edges = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)] >>> G = nx.DiGraph(edges) >>> nx.recursive_simple_cycles(G) [[0], [2], [0, 1, 2], [0, 2], [1, 2]] Notes ----- The implementation follows pp. 79-80 in [1]_. The time complexity is $O((n+e)(c+1))$ for $n$ nodes, $e$ edges and $c$ elementary circuits. References ---------- .. [1] Finding all the elementary circuits of a directed graph. D. B. Johnson, SIAM Journal on Computing 4, no. 1, 77-84, 1975. https://doi.org/10.1137/0204007 See Also -------- simple_cycles, cycle_basis """ # Jon Olav Vik, 2010-08-09 def _unblock(thisnode): """Recursively unblock and remove nodes from B[thisnode].""" if blocked[thisnode]: blocked[thisnode] = False while B[thisnode]: _unblock(B[thisnode].pop()) def circuit(thisnode, startnode, component): closed = False # set to True if elementary path is closed path.append(thisnode) blocked[thisnode] = True for nextnode in component[thisnode]: # direct successors of thisnode if nextnode == startnode: result.append(path[:]) closed = True elif not blocked[nextnode]: if circuit(nextnode, startnode, component): closed = True if closed: _unblock(thisnode) else: for nextnode in component[thisnode]: if thisnode not in B[nextnode]: # TODO: use set for speedup? B[nextnode].append(thisnode) path.pop() # remove thisnode from path return closed path = [] # stack of nodes in current path blocked = defaultdict(bool) # vertex: blocked from search? B = defaultdict(list) # graph portions that yield no elementary circuit result = [] # list to accumulate the circuits found # Johnson's algorithm exclude self cycle edges like (v, v) # To be backward compatible, we record those cycles in advance # and then remove from subG for v in G: if G.has_edge(v, v): result.append([v]) G.remove_edge(v, v) # Johnson's algorithm requires some ordering of the nodes. # They might not be sortable so we assign an arbitrary ordering. ordering = dict(zip(G, range(len(G)))) for s in ordering: # Build the subgraph induced by s and following nodes in the ordering subgraph = G.subgraph(node for node in G if ordering[node] >= ordering[s]) # Find the strongly connected component in the subgraph # that contains the least node according to the ordering strongcomp = nx.strongly_connected_components(subgraph) mincomp = min(strongcomp, key=lambda ns: min(ordering[n] for n in ns)) component = G.subgraph(mincomp) if len(component) > 1: # smallest node in the component according to the ordering startnode = min(component, key=ordering.__getitem__) for node in component: blocked[node] = False B[node][:] = [] dummy = circuit(startnode, startnode, component) return result
(G, *, backend=None, **backend_kwargs)
[ 0.021086517721414566, -0.03180550038814545, -0.041313957422971725, 0.02907206118106842, -0.03901005908846855, -0.0010500549105927348, -0.03861956670880318, -0.014575080014765263, 0.0755990743637085, -0.0590813010931015, -0.025030478835105896, 0.03914673253893852, 0.00014147674664855003, 0.0024771778844296932, -0.029950665310025215, -0.028408225625753403, 0.0031507748644798994, 0.003004340687766671, -0.03617899864912033, 0.0388343371450901, -0.01596132293343544, -0.04217303544282913, 0.04107966274023056, 0.047639913856983185, -0.018850957974791527, 0.05915939807891846, -0.0024283663369715214, 0.024249495938420296, -0.09793516248464584, -0.020598404109477997, 0.012895967811346054, 0.002019571140408516, -0.07954303175210953, -0.04998285695910454, 0.02434711903333664, 0.06618823856115341, 0.015102243050932884, 0.052364856004714966, -0.07841061055660248, 0.009113085456192493, 0.03194217011332512, -0.010006333701312542, 0.011265668086707592, -0.050334300845861435, 0.043266411870718, -0.014672702178359032, 0.029755420982837677, 0.08582994341850281, -0.014331023208796978, -0.0543954074382782, 0.05154482275247574, -0.005764624569565058, -0.04147015139460564, 0.0011775746243074536, 0.04455503448843956, 0.011177807115018368, 0.010221104137599468, 0.04357880353927612, 0.0726313441991806, -0.02495237998664379, -0.01398934330791235, -0.02180892787873745, 0.024444742128252983, 0.05216960981488228, -0.05865176022052765, -0.014897234737873077, -0.013432892970740795, -0.04736656695604324, -0.008351627737283707, 0.002242883201688528, 0.0036852597258985043, -0.004822564776986837, 0.01771853305399418, -0.04775705933570862, -0.014760563150048256, -0.052208658307790756, -0.00852734874933958, -0.008083165623247623, -0.00513495784252882, -0.022257991135120392, 0.02448379062116146, -0.011236380785703659, 0.002489380771294236, -0.04728846997022629, 0.02909158542752266, -0.00035967890289612114, 0.015375586226582527, 0.03649139031767845, -0.04025962948799133, -0.023780906572937965, -0.00722896633669734, -0.024718085303902626, 0.0066139427945017815, 0.09004724770784378, 0.027431998401880264, 0.0034119158517569304, -0.035651836544275284, -0.05533258616924286, 0.030751172453165054, 0.0014680024469271302, 0.007111818995326757, 0.003907351288944483, -0.11691302806138992, -0.013393844477832317, -0.024249495938420296, -0.026280049234628677, -0.03362128138542175, 0.0233708918094635, 0.008244243450462818, -0.08645472675561905, -0.05185721442103386, 0.05642596259713173, 0.01596132293343544, -0.03463656082749367, -0.010865414515137672, 0.0594327412545681, 0.028330128639936447, -0.027236752212047577, 0.007121581118553877, -0.014272449538111687, -0.014496981166303158, -0.021594157442450523, -0.041626349091529846, 0.044515982270240784, 0.02087174914777279, -0.001635181368328631, 0.009059392847120762, 0.02132081240415573, 0.008717713877558708, -0.008200312964618206, 0.06189283728599548, 0.03807288035750389, 0.023448988795280457, 0.07032744586467743, -0.000648581306450069, -0.022824203595519066, -0.05181816592812538, -0.01975884847342968, -0.019075488671660423, 0.016488486900925636, -0.01609799452126026, -0.1049640029668808, 0.012261420488357544, 0.06646158546209335, 0.03955674543976784, -0.01547320932149887, 0.03572993353009224, -0.024600937962532043, 0.002818857552483678, 0.030243534594774246, 0.014428645372390747, 0.0024259258061647415, 0.025694312527775764, 0.0019536756444722414, 0.02194559946656227, -0.003343579825013876, -0.040532976388931274, 0.045453161001205444, -0.04619509354233742, 0.02434711903333664, -0.03192264586687088, -0.0063991728238761425, -0.024679036810994148, 0.006950741168111563, -0.0279786866158247, 0.019046202301979065, 0.02356613613665104, -0.00853222981095314, -0.05216960981488228, 0.025499068200588226, 0.007282658945769072, 0.006438221782445908, -0.07173321396112442, 0.01114852074533701, 0.003756036050617695, 0.03569088503718376, 0.013208361342549324, 0.03719427436590195, 0.010679931379854679, -0.01879238337278366, -0.02167225442826748, -0.009357142262160778, -0.026280049234628677, -0.015365824103355408, 0.014428645372390747, 0.028701094910502434, 0.06833594292402267, -0.051154330372810364, 0.05818317085504532, 0.009220470674335957, -0.06318145990371704, 0.010289439931511879, 0.044945523142814636, 0.05763648450374603, 0.06997600197792053, -0.037838585674762726, -0.020305536687374115, 0.02987256832420826, -0.05865176022052765, 0.08145643770694733, 0.014126014895737171, 0.030712123960256577, 0.0536925233900547, -0.0022843729238957167, 0.04521886631846428, 0.03270362690091133, 0.014662940055131912, -0.005520567763596773, 0.016390863806009293, 0.01359885185956955, -0.056152619421482086, -0.05107623338699341, 0.03194217011332512, -0.016566583886742592, -0.041196808218955994, 0.026319099590182304, -0.0032850061543285847, 0.01930978335440159, 0.017738057300448418, -0.06872642785310745, -0.03321126848459244, 0.01026015356183052, -0.00892272125929594, -0.022785155102610588, -0.009981928393244743, -0.02514762617647648, 0.03916625678539276, 0.012544525787234306, 0.02684626169502735, -0.021691780537366867, 0.02782248891890049, 0.004729823209345341, 0.0436178557574749, -0.011343766003847122, 0.010416349396109581, -0.05345822870731354, -0.03676473721861839, 0.004651724826544523, 0.020305536687374115, -0.0024247055407613516, -0.048772335052490234, -0.06966360658407211, -0.0008285732474178076, -0.012817869894206524, 0.014487219043076038, -0.015678217634558678, 0.0404939241707325, -0.0001376633590552956, -0.013921007513999939, -0.0012947219656780362, -0.080987848341465, -0.051896266639232635, -0.0007260693819262087, -0.06544630229473114, 0.008517586626112461, -0.04029868170619011, -0.04529696702957153, -0.026963409036397934, -0.00047469072160311043, 0.011412101797759533, 0.011441389098763466, 0.016781354323029518, -0.04724942147731781, 0.021906549111008644, -0.0024356881622225046, 0.008595684543251991, 0.01122661866247654, 0.017347566783428192, -0.03362128138542175, 0.026924360543489456, 0.07606766372919083, -0.05869080871343613, 0.011343766003847122, 0.008615209721028805, -0.04724942147731781, 0.027080556377768517, -0.005569379311054945, 0.031239286065101624, -0.02276563085615635, -0.05259915068745613, -0.07876205444335938, 0.027412474155426025, 0.0006626145332120359, -0.00446136062964797, -0.047015126794576645, -0.014721513725817204, 0.0048030405305325985, -0.042446382343769073, 0.0006296669016592205, -0.00560842826962471, 0.07442759722471237, -0.033718906342983246, 0.05123243108391762, 0.028564423322677612, 0.04467217996716499, 0.0063991728238761425, -0.020949846133589745, -0.07844965904951096, 0.0022831526584923267, 0.026299575343728065, 0.010943512432277203, -0.050178103148937225, 0.0018121226457878947, -0.0262410007417202, 0.007311945781111717, -0.04471122846007347, 0.00930833164602518, -0.02368328347802162, -0.00001654057632549666, -0.01170497015118599, -0.0490066297352314, 0.024054251611232758, 0.011480437591671944, 0.022082271054387093, -0.004783515818417072, -0.060135625302791595, -0.028369177132844925, -0.021633205935359, 0.0679454505443573, 0.052403904497623444, 0.01565869338810444, 0.04350070655345917, -0.04311021417379379, 0.04088441655039787, -0.059510841965675354, 0.0448283776640892, 0.0637671947479248, 0.05259915068745613, 0.037038080394268036, 0.005383895710110664, -0.005623071454465389, 0.022882778197526932, -0.014126014895737171, 0.043071165680885315, 0.0037169870920479298, 0.011421863920986652, 0.06263477355241776, -0.05470779910683632, -0.02210179530084133, -0.07985542714595795, 0.07618480920791626, 0.0540439672768116, -0.013921007513999939, -0.01878262124955654, 0.0026846262626349926, -0.009152134880423546, 0.04931902512907982, 0.01168544590473175, -0.020637454465031624, 0.026026230305433273, 0.03289887309074402, 0.06817974150180817, -0.03602280095219612, 0.019485505297780037, -0.025030478835105896, 0.029911616817116737, 0.010660406202077866, -0.005315559916198254, -0.010650644078850746, -0.0052081746980547905, 0.026201952248811722, 0.036881882697343826, -0.008092927746474743, -0.013891720212996006, 0.04849899187684059, -0.006013562902808189, -0.017630672082304955, 0.04346165806055069, 0.002008588518947363, -0.05502019450068474, -0.0341484434902668, -0.00020088936435058713, 0.006135591305792332, -0.0031971456483006477, 0.002235561376437545, 0.03522229567170143, 0.024913331493735313, -0.016195617616176605, 0.05275534465909004, 0.02704150788486004, -0.0010939851636067033, -0.006775020156055689, 0.0010787316132336855, 0.011529249139130116, 0.030224010348320007, -0.0028115357272326946, 0.04459408298134804, 0.02700245939195156, 0.08278410881757736, -0.011382815428078175, -0.04611699655652046, -0.05076384171843529, 0.02383948117494583, 0.009078918024897575, -0.045765556395053864, -0.01257381308823824, 0.14377881586551666, 0.035476114600896835, -0.00799042358994484, -0.013950293883681297, -0.0002571749791968614, 0.013755048625171185, 0.030263058841228485, 0.028954913839697838, 0.005530329886823893, -0.028310604393482208, 0.047952305525541306, 0.0001777039433363825, 0.002721234690397978, -0.007526715751737356, -0.031239286065101624, 0.009825731627643108, 0.004722501616925001, -0.016966838389635086, 0.013247409835457802, -0.05584022402763367, -0.037877634167671204, -0.000935958290938288, 0.07345137000083923, 0.024718085303902626, 0.04287591949105263, -0.00845413189381361, 0.04572650417685509, -0.008205194026231766, 0.009576793760061264, 0.020910797640681267, 0.026943884789943695, 0.03338698670268059, -0.04642938822507858, 0.06825783848762512, -0.003219110891222954, -0.029150160029530525, -0.028954913839697838, -0.049240924417972565, -0.01974908635020256, -0.024620462208986282, 0.04365690425038338, -0.02053983137011528, 0.05736314132809639, 0.026338623836636543, -0.021633205935359, 0.06478247046470642, -0.009366905316710472, -0.03559326380491257, 0.051622919738292694, -0.01848975196480751, 0.004141645971685648, 0.033133167773485184, 0.011968552134931087, -0.017025411128997803, 0.02132081240415573, -0.028818242251873016, 0.03096594288945198, -0.05150577425956726, -0.12277039885520935, 0.031375959515571594, 0.01800163835287094, 0.018684998154640198, -0.05041239783167839, 0.025245249271392822, 0.06681302189826965, 0.022238466888666153, 0.016966838389635086, 0.013833146542310715, -0.053497277200222015, -0.04279782250523567, 0.011353528127074242, 0.01492652203887701, -0.021847976371645927, 0.004007414914667606, 0.03446083888411522, -0.022843727841973305, -0.08051925897598267, -0.03266457840800285, 0.030380206182599068, -0.02118414081633091, -0.07161606848239899, -0.0131205003708601, -0.0017755141016095877, -0.08122214674949646, -0.07544288039207458, -0.014653177931904793, 0.022179894149303436, -0.017611147835850716, -0.0037804418243467808, -0.030868319794535637, 0.03908815607428551, -0.005461994092911482, -0.02292182669043541, -0.05974513664841652, -0.052208658307790756, -0.020481256768107414, -0.021613681688904762, 0.01020157989114523, 0.025538116693496704, 0.06892167776823044, -0.04428168758749962, -0.018440941348671913, 0.08871957659721375, -0.024425217881798744, 0.012417616322636604, -0.004517493769526482, -0.0007468141848221421, 0.008620090782642365, 0.04541411250829697, 0.031102614477276802, 0.015307250432670116, -0.0072143226861953735, 0.025401445105671883, 0.006770139094442129, 0.02811535820364952, -0.006130710244178772, 0.01930978335440159, 0.044984571635723114, 0.010953274555504322, 0.0017303635831922293, -0.013803860172629356, -0.004153849091380835, 0.03639376908540726, -0.0270219836384058, 0.012964303605258465, 0.02022743783891201, 0.0049079847522079945, 0.05357537791132927, -0.008478538133203983, 0.019866233691573143, -0.0006253958563320339, -0.05060764402151108, -0.026768164709210396, -0.008341865614056587, 0.006042849738150835, 0.020325060933828354, -0.025674788281321526, 0.09606080502271652, 0.010230866260826588, -0.016869215294718742, 0.04721037298440933, 0.01836284250020981, -0.05869080871343613, 0.0008950787596404552, 0.022980399429798126, 0.03901005908846855, 0.07067888975143433, 0.009176540188491344, 0.006731090135872364, 0.020500781014561653, 0.05642596259713173, 0.016781354323029518, -0.03297697380185127, -0.036745209246873856, -0.004078191239386797, 0.006745733320713043, -0.007448617368936539, -0.0279786866158247, 0.06279096752405167, -0.08512705564498901, -0.0206765029579401, 0.014487219043076038, 0.0028969557024538517, 0.0245033148676157, -0.03303554654121399, 0.0034216782078146935, -0.06575869768857956, -0.08247171342372894, 0.04107966274023056, -0.022316565737128258, 0.07532572746276855, -0.02954065054655075, 0.018597137182950974, 0.03328936547040939, 0.012964303605258465, -0.0020781448110938072, 0.03297697380185127, -0.026768164709210396, -0.0010213782079517841, 0.03711617738008499, -0.02052030712366104, -0.021535582840442657, 0.001021988340653479, -0.0695074126124382, -0.007604813668876886, -0.044320739805698395, -0.007121581118553877, 0.012495714239776134, 0.059354644268751144, -0.008088046684861183, -0.022550860419869423, 0.004124562256038189, -0.030399730429053307, -0.007282658945769072, 0.030067812651395798, -0.05923749879002571, 0.03065354935824871, -0.00568652618676424, -0.02055935561656952, 0.032176464796066284, -0.002796892309561372, 0.02731485106050968, -0.003531503723934293, -0.014096728526055813, -0.03205931931734085, 0.015756314620375633, 0.04041582718491554, 0.04998285695910454, -0.034656085073947906, 0.023468514904379845, 0.019788134843111038, -0.06306430697441101, 0.04408644512295723, -0.018860720098018646, 0.0019732003565877676, 0.05263819918036461, -0.0033240553457289934, 0.006482151802629232, -0.06696922332048416, 0.011822117492556572, -0.04342260956764221, 0.015209627337753773, -0.024229971691966057, -0.008039235137403011, 0.0068677617236971855, 0.0013142465613782406, 0.013286459259688854, -0.028056783601641655, -0.07095222920179367, 0.02559669129550457, 0.023468514904379845, 0.009513339027762413, 0.029325880110263824, 0.06997600197792053, 0.013696474954485893, -0.004859173204749823, -0.012261420488357544, 0.058222219347953796, 0.007219203747808933, -0.06942931562662125, 0.00199760589748621, -0.002643136540427804, -0.013208361342549324, 0.08747000247240067, -0.06646158546209335, -0.015512258745729923, -0.05244295299053192, 0.01819688454270363, -0.07821536064147949, -0.04549220949411392, 0.031161189079284668, -0.04475027695298195, 0.019075488671660423, 0.04127490893006325, -0.03098546713590622, 0.023312317207455635, 0.029950665310025215, -0.014496981166303158, -0.0058378418907523155, 0.05338013172149658, 0.03981056436896324, -0.0318835973739624, 0.017738057300448418, -0.04045487567782402, 0.05642596259713173, 0.005349727813154459, 0.015346299856901169, -0.012964303605258465, -0.02098889648914337, -0.003016543574631214, 0.07349041849374771, -0.02132081240415573, -0.03463656082749367, 0.01540487352758646, -0.022257991135120392, -0.06786735355854034, 0.0022892539855092764, -0.024151872843503952, -0.07770772278308868, -0.004075750708580017, -0.038014307618141174, 0.04076727107167244, -0.007492547854781151, -0.017171844840049744, 0.016664206981658936, 0.012271182611584663, -0.029755420982837677, -0.0334455631673336, -0.0006211248692125082, -0.002493041567504406, -0.0021623442880809307, -0.05341918021440506, 0.03748714551329613, -0.07860585302114487, 0.001820664736442268, 0.013179074041545391, 0.03364080563187599, 0.018265221267938614, -0.014487219043076038, 0.024737609550356865, 0.01658610813319683, 0.010055145248770714, 0.04439883679151535, -0.053184885531663895, 0.05431731045246124, -0.013149787671864033, 0.02052030712366104, 0.028876814991235733, -0.0026114091742783785, 0.00008618260471848771, -0.05146672576665878, 0.004973880015313625, 0.029970191419124603, 0.04381309822201729, -0.0016046742675825953, 0.009571912698447704, -0.003389950841665268, -0.0037340710405260324, 0.017777105793356895, -0.06743781268596649, -0.014584842137992382, -0.02368328347802162, -0.04611699655652046, 0.029267307370901108, -0.0051447199657559395, 0.009147253818809986, -0.026748638600111008, 0.03082927130162716, -0.022531336173415184, 0.09020344167947769, 0.051115281879901886, -0.02321469411253929, 0.01500461995601654, -0.020617928355932236, -0.04127490893006325, 0.06279096752405167, -0.010982561856508255, 0.03125881031155586, 0.02530382201075554, -0.04443788528442383, -0.020656978711485863, 0.0033240553457289934, -0.010103956796228886, 0.029755420982837677, -0.00609166081994772, -0.035964228212833405, -0.06283001601696014, 0.029618749395012856, -0.01830426976084709, -0.022004172205924988, 0.011002086102962494, 0.062205228954553604, 0.01800163835287094, -0.09746657311916351, -0.005691407714039087, -0.031668826937675476, -0.027900587767362595, -0.0395372211933136, -0.008751881308853626, 0.010113718919456005, -0.05970608815550804, -0.010016096755862236, -0.05138862505555153, -0.05353632941842079, -0.013940531760454178, 0.007770772557705641, 0.022082271054387093, 0.0233708918094635, -0.03426559269428253, 0.029345404356718063, 0.00032368049141950905, 0.05599642172455788 ]
30,707
networkx.algorithms.distance_regular
global_parameters
Returns global parameters for a given intersection array. Given a distance-regular graph G with integers b_i, c_i,i = 0,....,d such that for any 2 vertices x,y in G at a distance i=d(x,y), there are exactly c_i neighbors of y at a distance of i-1 from x and b_i neighbors of y at a distance of i+1 from x. Thus, a distance regular graph has the global parameters, [[c_0,a_0,b_0],[c_1,a_1,b_1],......,[c_d,a_d,b_d]] for the intersection array [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d] where a_i+b_i+c_i=k , k= degree of every vertex. Parameters ---------- b : list c : list Returns ------- iterable An iterable over three tuples. Examples -------- >>> G = nx.dodecahedral_graph() >>> b, c = nx.intersection_array(G) >>> list(nx.global_parameters(b, c)) [(0, 0, 3), (1, 0, 2), (1, 1, 1), (1, 1, 1), (2, 0, 1), (3, 0, 0)] References ---------- .. [1] Weisstein, Eric W. "Global Parameters." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/GlobalParameters.html See Also -------- intersection_array
def global_parameters(b, c): """Returns global parameters for a given intersection array. Given a distance-regular graph G with integers b_i, c_i,i = 0,....,d such that for any 2 vertices x,y in G at a distance i=d(x,y), there are exactly c_i neighbors of y at a distance of i-1 from x and b_i neighbors of y at a distance of i+1 from x. Thus, a distance regular graph has the global parameters, [[c_0,a_0,b_0],[c_1,a_1,b_1],......,[c_d,a_d,b_d]] for the intersection array [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d] where a_i+b_i+c_i=k , k= degree of every vertex. Parameters ---------- b : list c : list Returns ------- iterable An iterable over three tuples. Examples -------- >>> G = nx.dodecahedral_graph() >>> b, c = nx.intersection_array(G) >>> list(nx.global_parameters(b, c)) [(0, 0, 3), (1, 0, 2), (1, 1, 1), (1, 1, 1), (2, 0, 1), (3, 0, 0)] References ---------- .. [1] Weisstein, Eric W. "Global Parameters." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/GlobalParameters.html See Also -------- intersection_array """ return ((y, b[0] - x - y, x) for x, y in zip(b + [0], [0] + c))
(b, c)
[ -0.019646411761641502, -0.01520707830786705, -0.06116834655404091, 0.004930493887513876, -0.0033743656240403652, 0.011995645239949226, -0.028789550065994263, -0.0476047657430172, 0.03372004255652428, -0.035816919058561325, -0.007537421304732561, -0.06320855021476746, -0.04397773742675781, 0.005294141359627247, -0.08387506753206253, -0.03262437880039215, -0.030263030901551247, 0.00489743473008275, -0.01148559432476759, -0.044506680220365524, -0.03269994258880615, -0.03249214217066765, -0.02561589889228344, 0.06267961114645004, -0.015339314006268978, -0.03079197183251381, 0.015556558035314083, -0.018767990171909332, 0.02520030178129673, 0.0019315823446959257, -0.00673928577452898, -0.06305742263793945, -0.052251897752285004, -0.008151371963322163, -0.01021046657115221, -0.0026140117552131414, 0.0435243584215641, 0.06800681352615356, -0.09233813732862473, 0.016227180138230324, -0.03285106644034386, -0.08833328634500504, 0.052251897752285004, 0.011353359557688236, 0.07680991291999817, 0.012911848723888397, 0.03509907051920891, 0.012666268274188042, -0.07722551375627518, 0.011343914084136486, 0.039670638740062714, -0.06694892793893814, 0.021913304924964905, -0.018333502113819122, -0.04643353819847107, 0.02557811699807644, 0.013393563218414783, 0.013752488419413567, -0.0021677170880138874, -0.027637211605906487, 0.012477360665798187, -0.007277673110365868, 0.05546333268284798, 0.007650766056030989, -0.013695815578103065, 0.01614217273890972, -0.06317076832056046, 0.006318965926766396, -0.028902893885970116, 0.07050039619207382, -0.023575693368911743, 0.014895380474627018, -0.010276584886014462, -0.0735606998205185, 0.011032216250896454, 0.03156649321317673, 0.02040204219520092, 0.02340567670762539, -0.013884724117815495, -0.009700415655970573, -0.010928316973149776, 0.018834108486771584, 0.020949875935912132, 0.009289541281759739, 0.05731462687253952, 0.017020592465996742, -0.015839919447898865, 0.013979177922010422, -0.0008075808873400092, -0.00956345722079277, -0.01563212089240551, -0.0037474585697054863, 0.018579082563519478, 0.09324489533901215, 0.01742674596607685, 0.020137572661042213, -0.009927105158567429, -0.01149503979831934, 0.01821071282029152, -0.041559718549251556, 0.00848668348044157, -0.05519885942339897, -0.046660229563713074, -0.02861953340470791, 0.07042483240365982, -0.09724973887205124, 0.00892117153853178, -0.04114412143826485, 0.07019814103841782, 0.03940616920590401, -0.0823638066649437, 0.030640846118330956, 0.02648487500846386, -0.01643497869372368, -0.012713495641946793, 0.027032706886529922, -0.020949875935912132, 0.058901455253362656, 0.011391140520572662, -0.02047760598361492, 0.010371038690209389, 0.026277076452970505, 0.026295967400074005, 0.04514896497130394, 0.04915381222963333, -0.0028997347690165043, -0.0013908337568864226, 0.020647622644901276, -0.005095788277685642, -0.02342456765472889, 0.052780840545892715, -0.013601361773908138, -0.012137326411902905, 0.009738197550177574, 0.02336789481341839, -0.016803348436951637, -0.018342947587370872, -0.024973612278699875, 0.03222767263650894, -0.03160427510738373, 0.030999770388007164, 0.020232025533914566, 0.013573026284575462, 0.023991290479898453, -0.0476803295314312, 0.023160096257925034, 0.055312205106019974, -0.03766821697354317, -0.0238212738186121, 0.03814048692584038, -0.03285106644034386, 0.015443213284015656, -0.024085745215415955, -0.03338000923395157, -0.05285640433430672, -0.03589248284697533, 0.021403254941105843, -0.020572060719132423, 0.011334468610584736, -0.02308453433215618, -0.04673578962683678, 0.025729242712259293, -0.04084186628460884, 0.06128169223666191, 0.007442967500537634, -0.01191063690930605, 0.0016612079925835133, -0.01567934826016426, -0.03264326974749565, -0.059770431369543076, -0.01647276058793068, -0.060148246586322784, -0.06305742263793945, -0.028449514880776405, -0.006965975277125835, 0.02087431214749813, -0.03549577668309212, -0.023632366210222244, 0.027996137738227844, 0.01571713015437126, 0.04945606365799904, -0.022045541554689407, 0.019854210317134857, -0.026994924992322922, 0.02251780964434147, 0.06411530822515488, 0.04205087944865227, 0.00007161524263210595, 0.01864520087838173, -0.007131269667297602, 0.012297898530960083, -0.0346079096198082, -0.005105233285576105, 0.10080120712518692, -0.007518530823290348, 0.03345557302236557, -0.013695815578103065, 0.054065413773059845, -0.03230323642492294, 0.07733885943889618, 0.0003955257125198841, -0.04375104606151581, -0.0477558933198452, 0.01651998795568943, 0.03254881501197815, 0.01566045731306076, 0.01688835769891739, -0.036326970905065536, -0.01347857154905796, 0.022253340110182762, -0.0049068802036345005, -0.04443111643195152, 0.06796903163194656, -0.020213134586811066, 0.0025738689582794905, 0.06823349744081497, -0.025842588394880295, 0.04620685055851936, -0.02000533603131771, -0.05081620067358017, 0.023141205310821533, -0.04435555264353752, 0.08304387331008911, -0.023292332887649536, 0.006611773278564215, -0.026636000722646713, -0.0005761688225902617, 0.017540089786052704, -0.058372512459754944, -0.03594915568828583, 0.06736452132463455, -0.010597728192806244, 0.0015348759479820728, -0.043637704104185104, 0.014300321228802204, -0.07061373442411423, 0.061848416924476624, -0.0173228457570076, 0.004677829332649708, 0.005024947691708803, -0.03313443064689636, 0.014564791694283485, -0.030961988493800163, 0.022310011088848114, -0.0022043180651962757, -0.009823205880820751, 0.01912691444158554, 0.03307775780558586, 0.00958234816789627, 0.023197878152132034, -0.08002134412527084, -0.0033436680678278208, -0.025105847045779228, -0.014914271421730518, 0.01731340028345585, -0.013506907969713211, -0.041030775755643845, 0.04480893164873123, 0.005228023510426283, 0.01475369930267334, 0.022706719115376472, 0.014290875755250454, -0.005133569706231356, 0.07129380851984024, 0.029469618573784828, 0.011136115528643131, 0.016293298453092575, 0.03003634139895439, -0.029450727626681328, 0.02045871503651142, 0.06781790405511856, 0.058939237147569656, 0.03133980557322502, -0.011844519525766373, -0.012014536187052727, 0.022291122004389763, 0.01066384557634592, 0.03122645989060402, -0.01614217273890972, -0.03132091462612152, 0.044128865003585815, -0.008373338729143143, -0.06339745968580246, 0.020647622644901276, -0.039292823523283005, -0.015877701342105865, -0.04091743007302284, -0.024576906114816666, 0.04291985183954239, -0.037120383232831955, 0.008425287902355194, -0.01871131733059883, 0.02310342527925968, -0.009237592108547688, 0.05179851874709129, 0.054027631878852844, 0.024520233273506165, -0.00952095352113247, 0.06626886129379272, 0.027977246791124344, 0.0737496092915535, -0.038839444518089294, -0.003759265411645174, -0.014564791694283485, -0.027882792055606842, 0.004555039573460817, 0.08742653578519821, 0.006465369835495949, -0.0151787418872118, -0.0051241242326796055, -0.04658466577529907, -0.014942607842385769, -0.005568057764321566, -0.018125703558325768, -0.03642142564058304, -0.06589104235172272, -0.014942607842385769, -0.006871521472930908, -0.0006788874161429703, 0.0023400953505188227, 0.028827331960201263, 0.034532345831394196, 0.025918150320649147, 0.020647622644901276, 0.0021582716144621372, 0.036648113280534744, 0.01917414180934429, -0.015018170699477196, 0.0348534919321537, -0.002325927373021841, 0.005870310124009848, 0.01652943342924118, -0.039255041629076004, 0.0348534919321537, 0.06615551561117172, 0.05425432324409485, 0.02644709311425686, 0.014186976477503777, 0.05293196812272072, -0.07276728749275208, -0.002939877798780799, 0.02423687092959881, -0.032832175493240356, 0.005705015733838081, -0.0521385557949543, 0.01021991204470396, -0.03139647841453552, 0.012137326411902905, -0.010814972221851349, 0.00618200795724988, 0.0014427833957597613, 0.051382921636104584, 0.03343668207526207, 0.0477936752140522, 0.021592162549495697, 0.07665878534317017, -0.019202478229999542, 0.004448778927326202, 0.04938049986958504, 0.0609416589140892, 0.06275517493486404, 0.07949240505695343, 0.028789550065994263, -0.01452701073139906, 0.004370854236185551, 0.007277673110365868, -0.04035070911049843, 0.041559718549251556, -0.02212110348045826, -0.06320855021476746, -0.020666513592004776, -0.056672342121601105, 0.018512964248657227, 0.00662594148889184, 0.027070488780736923, -0.013780824840068817, -0.06785568594932556, -0.028336171060800552, -0.03562801331281662, 0.0016730147181078792, -0.009077019989490509, -0.027070488780736923, 0.06883800774812698, 0.0059317052364349365, -0.0390283539891243, -0.025842588394880295, 0.06437978148460388, -0.009275373071432114, 0.008297774940729141, 0.06052606180310249, -0.0008010871824808419, -0.054556574672460556, 0.019363049417734146, 0.0239535104483366, -0.044960059225559235, -0.05289418622851372, 0.06211288645863533, -0.004063879139721394, -0.055312205106019974, -0.04299541562795639, 0.018050141632556915, -0.004720333963632584, -0.0913558155298233, 0.008656700141727924, 0.012505697086453438, -0.05330978333950043, 0.008803104050457478, 0.03679924085736275, -0.008798381313681602, 0.020307589322328568, -0.06358636915683746, 0.010692181997001171, 0.026220403611660004, 0.02478470467031002, -0.017587317153811455, -0.0015148044330999255, -0.07291841506958008, 0.05958152189850807, 0.019325269386172295, 0.02601260505616665, 0.07208722084760666, -0.059770431369543076, 0.05999711900949478, 0.01786123216152191, 0.02431243471801281, -0.012449024245142937, -0.021554380655288696, -0.021006548777222633, -0.015792692080140114, -0.010342702269554138, -0.05383872613310814, -0.021648835390806198, -0.026182621717453003, -0.05569002032279968, -0.02036426216363907, 0.022744499146938324, 0.018928561359643936, 0.07182274758815765, 0.06721339374780655, 0.010758299380540848, 0.05958152189850807, 0.04511118307709694, 0.02742941305041313, -0.027561649680137634, -0.05040060356259346, -0.006692058872431517, -0.03379560634493828, 0.02648487500846386, -0.030149685218930244, -0.012760722078382969, 0.033266663551330566, -0.014612019062042236, 0.051949646323919296, -0.03551466763019562, 0.02909180149435997, -0.002131116110831499, -0.009374549612402916, 0.009681524708867073, -0.03249214217066765, 0.026239294558763504, 0.030508611351251602, 0.03436233103275299, 0.014016958884894848, -0.05002278834581375, -0.027542758733034134, -0.026579327881336212, 0.018012359738349915, 0.005223300773650408, -0.03355002775788307, 0.005790024064481258, 0.022291122004389763, 0.02176217921078205, -0.06823349744081497, 0.0009256482589989901, 0.03593026474118233, -0.022498920559883118, -0.05818360298871994, 0.029677417129278183, -0.04586681351065636, -0.06249070167541504, -0.04809592664241791, 0.005081620067358017, 0.015981599688529968, 0.008954229764640331, 0.012288453057408333, -0.029828542843461037, 0.06203732267022133, -0.00782078318297863, -0.07926571369171143, -0.04737807810306549, -0.03339890018105507, 0.024860266596078873, 0.0047156112268567085, -0.050136130303144455, 0.013969732448458672, -0.007244614418596029, 0.028846221044659615, 0.0035349372774362564, 0.06396418064832687, 0.036175843328237534, 0.007211555261164904, -0.007787724491208792, -0.012260116636753082, -0.03175540268421173, 0.022763390094041824, -0.026295967400074005, -0.01564156636595726, -0.03606250137090683, -0.01562267541885376, 0.060186028480529785, -0.03955729305744171, -0.028600642457604408, 0.05251637101173401, 0.07212500274181366, -0.00759881641715765, -0.04518674686551094, 0.006659000180661678, -0.02782611921429634, 0.019023016095161438, -0.01155171263962984, 0.06403974443674088, 0.037517089396715164, -0.019703084602952003, 0.011164451017975807, 0.006767622195184231, 0.026787126436829567, -0.0119578642770648, -0.06880022585391998, -0.05440544709563255, -0.015292086638510227, -0.05066507309675217, 0.042806509882211685, -0.03186874836683273, 0.04907824844121933, -0.04567790776491165, 0.016274407505989075, 0.03604361042380333, 0.02306564338505268, -0.02826060727238655, 0.00953984446823597, 0.03678034991025925, 0.029639635235071182, 0.06619329750537872, 0.028562860563397408, 0.026824908331036568, 0.020496496930718422, -0.008481960743665695, 0.024520233273506165, -0.02176217921078205, 0.00952095352113247, 0.0019941581413149834, -0.0434487946331501, -0.0477558933198452, 0.02480359561741352, 0.006092276889830828, -0.03855608403682709, -0.021592162549495697, -0.03245436027646065, -0.02697603404521942, 0.04938049986958504, 0.005449990276247263, 0.008415842428803444, -0.04295763373374939, 0.03817826882004738, -0.007924682460725307, 0.02829838916659355, 0.04288207367062569, 0.01023880299180746, -0.060979440808296204, 0.032341014593839645, -0.021006548777222633, 0.017908459529280663, -0.055009953677654266, -0.012486806139349937, 0.01324243750423193, 0.02042093314230442, -0.0303574837744236, -0.043184325098991394, -0.02346234954893589, -0.012637931853532791, -0.018116258084774017, -0.0004887989489361644, 0.07295619696378708, -0.014999279752373695, 0.051080670207738876, 0.058825891464948654, -0.011740620248019695, -0.000870156567543745, -0.012260116636753082, 0.003095726715400815, -0.04205087944865227, -0.003856080584228039, -0.0014864682452753186, -0.012316788546741009, -0.03243546932935715, 0.011221123859286308, 0.009813760407269001, 0.027656102553009987, -0.058825891464948654, -0.07858564704656601, -0.04560234397649765, 0.00934621412307024, 0.01998644508421421, 0.04477114975452423, -0.0086992047727108, -0.02644709311425686, 0.007697992958128452, -0.037498198449611664, -0.023160096257925034, -0.0478692390024662, -0.035401321947574615, -0.05172295868396759, -0.01477259024977684, -0.020099790766835213, -0.007981354370713234, 0.010937761515378952, -0.05682346969842911, 0.10284140706062317, 0.03339890018105507, 0.009280095808207989, -0.03827271983027458, 0.011835074052214622, -0.015792692080140114, 0.00015016694669611752, -0.033247772604227066, 0.04288207367062569, 0.004080408718436956, -0.0779055804014206, 0.034947942942380905, 0.08568858355283737, 0.04382660984992981, 0.009355658665299416, 0.029431836679577827, 0.011410031467676163, 0.030697518959641457, -0.037101492285728455, 0.033266663551330566, -0.015140960924327374, -0.06445534527301788, 0.05693681165575981, -0.054972171783447266, 0.08198598772287369, -0.029639635235071182, -0.039330605417490005, 0.03432454913854599, -0.014035849831998348, 0.0010260054841637611, -0.000721982039976865, 0.10813082754611969, -0.02997966855764389, -0.020213134586811066, 0.05735240876674652, 0.024217979982495308, 0.006635386496782303, -0.0649842843413353, -0.03698814660310745, -0.017889568582177162, -0.000552555313333869, -0.0051902420818805695, -0.03207654505968094, 0.03591137379407883, 0.041521936655044556, 0.024029072374105453, -0.06377527862787247, -0.053272001445293427, -0.01321410108357668, 0.018050141632556915, -0.01872076280415058, -0.016264962032437325, 0.028581751510500908, -0.015528221614658833, -0.026749344542622566, 0.0007054525776766241, 0.030206358060240746, -0.04745364189147949, -0.01151393074542284, -0.008637809194624424, -0.006918748375028372, -0.018985234200954437, -0.0009404066950082779, 0.0694425106048584, 0.02125212736427784, 0.0014663968468084931, -0.01021991204470396, 0.013119647279381752, -0.04998500645160675, 0.0065314872190356255, -0.03390895202755928, 0.02996077761054039, 0.030640846118330956, -0.015480994246900082, 0.004640047904103994, 0.07159605622291565, -0.04435555264353752, -0.001130495104007423, 0.0346456915140152, -0.022291122004389763, -0.011712283827364445, -0.02780722826719284, 0.017908459529280663, -0.00997433252632618, -0.01155171263962984, -0.048398178070783615, 0.0952850952744484, -0.02731606923043728, 0.007414631545543671, 0.03689369559288025, -0.042353130877017975, -0.04201309755444527, -0.007759388070553541, -0.021384363994002342, -0.061055004596710205, 0.004739224445074797, -0.015093733556568623, -0.006810126360505819, -0.0012373460922390223, 0.01151393074542284, -0.0004938167985528708, -0.007244614418596029, 0.052214115858078, -0.01642553322017193, 0.015150406397879124, 0.040615178644657135, 0.047113608568906784, -0.0004135310009587556, 0.024104636162519455, 0.0692536011338234, -0.040199581533670425, -0.0002523690345697105, -0.024199089035391808, -0.037630435079336166, 0.03156649321317673, -0.003841912606731057, 0.0476047657430172, 0.011589493602514267, 0.044506680220365524, -0.02686269022524357, -0.03940616920590401, -0.06192397698760033, 0.0067534539848566055, 0.0026423479430377483, 0.02911069244146347, -0.005095788277685642, -0.024029072374105453, -0.031963199377059937, 0.0032940797973424196, -0.03738485649228096, 0.002081527840346098, -0.00023967678134795278, -0.041975315660238266, 0.029620744287967682, 0.03305886685848236, 0.050967324525117874, -0.05349868908524513, 0.017710106447339058, 0.011287241242825985, -0.005185519345104694, -0.04439333453774452, -0.051005106419324875, -0.019835319370031357, -0.059694867581129074, 0.04201309755444527, 0.024104636162519455, 0.05527442321181297, 0.009738197550177574, 0.0347779281437397, -0.005204409826546907, 0.034456782042980194 ]
30,712
networkx.generators.random_graphs
gnm_random_graph
Returns a $G_{n,m}$ random graph. In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set of all graphs with $n$ nodes and $m$ edges. This algorithm should be faster than :func:`dense_gnm_random_graph` for sparse graphs. Parameters ---------- n : int The number of nodes. m : int The number of edges. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. directed : bool, optional (default=False) If True return a directed graph See also -------- dense_gnm_random_graph
def dual_barabasi_albert_graph(n, m1, m2, p, seed=None, initial_graph=None): """Returns a random graph using dual Barabási–Albert preferential attachment A graph of $n$ nodes is grown by attaching new nodes each with either $m_1$ edges (with probability $p$) or $m_2$ edges (with probability $1-p$) that are preferentially attached to existing nodes with high degree. Parameters ---------- n : int Number of nodes m1 : int Number of edges to link each new node to existing nodes with probability $p$ m2 : int Number of edges to link each new node to existing nodes with probability $1-p$ p : float The probability of attaching $m_1$ edges (as opposed to $m_2$ edges) seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. initial_graph : Graph or None (default) Initial network for Barabási–Albert algorithm. A copy of `initial_graph` is used. It should be connected for most use cases. If None, starts from an star graph on max(m1, m2) + 1 nodes. Returns ------- G : Graph Raises ------ NetworkXError If `m1` and `m2` do not satisfy ``1 <= m1,m2 < n``, or `p` does not satisfy ``0 <= p <= 1``, or the initial graph number of nodes m0 does not satisfy m1, m2 <= m0 <= n. References ---------- .. [1] N. Moshiri "The dual-Barabasi-Albert model", arXiv:1810.10538. """ if m1 < 1 or m1 >= n: raise nx.NetworkXError( f"Dual Barabási–Albert must have m1 >= 1 and m1 < n, m1 = {m1}, n = {n}" ) if m2 < 1 or m2 >= n: raise nx.NetworkXError( f"Dual Barabási–Albert must have m2 >= 1 and m2 < n, m2 = {m2}, n = {n}" ) if p < 0 or p > 1: raise nx.NetworkXError( f"Dual Barabási–Albert network must have 0 <= p <= 1, p = {p}" ) # For simplicity, if p == 0 or 1, just return BA if p == 1: return barabasi_albert_graph(n, m1, seed) elif p == 0: return barabasi_albert_graph(n, m2, seed) if initial_graph is None: # Default initial graph : empty graph on max(m1, m2) nodes G = star_graph(max(m1, m2)) else: if len(initial_graph) < max(m1, m2) or len(initial_graph) > n: raise nx.NetworkXError( f"Barabási–Albert initial graph must have between " f"max(m1, m2) = {max(m1, m2)} and n = {n} nodes" ) G = initial_graph.copy() # Target nodes for new edges targets = list(G) # List of existing nodes, with nodes repeated once for each adjacent edge repeated_nodes = [n for n, d in G.degree() for _ in range(d)] # Start adding the remaining nodes. source = len(G) while source < n: # Pick which m to use (m1 or m2) if seed.random() < p: m = m1 else: m = m2 # Now choose m unique nodes from the existing nodes # Pick uniformly from repeated_nodes (preferential attachment) targets = _random_subset(repeated_nodes, m, seed) # Add edges to m nodes from the source. G.add_edges_from(zip([source] * m, targets)) # Add one node to the list for each new edge just created. repeated_nodes.extend(targets) # And the new node "source" has m edges to add to the list. repeated_nodes.extend([source] * m) source += 1 return G
(n, m, seed=None, directed=False, *, backend=None, **backend_kwargs)
[ 0.0035330478567630053, 0.0015030424110591412, 0.015339415520429611, 0.004939081147313118, -0.024930143728852272, -0.04081568494439125, -0.06480687856674194, -0.03633170947432518, 0.012043501250445843, -0.03002731315791607, 0.006491227075457573, 0.04196542128920555, -0.036868251860141754, 0.10723219066858292, -0.043038509786129, 0.013011197559535503, 0.034664589911699295, 0.04740751534700394, -0.005897196009755135, 0.027287105098366737, -0.04004919156432152, 0.0020264126360416412, 0.00006875221151858568, 0.07101546227931976, -0.034492127597332, 0.010740465484559536, -0.03911023959517479, 0.01075004693120718, -0.015617269091308117, 0.05932645872235298, 0.03920605406165123, -0.12348181754350662, 0.020982710644602776, 0.039052754640579224, -0.000130992237245664, 0.010136852972209454, 0.02770867571234703, 0.06116604059934616, -0.10960831493139267, -0.03681076690554619, 0.07097713649272919, -0.05541735142469406, 0.08339430391788483, 0.013078264892101288, 0.024681033566594124, -0.02391454204916954, 0.03092794120311737, 0.012992034666240215, -0.09650131314992905, -0.009839837439358234, 0.016125069931149483, -0.07051724195480347, 0.026252342388033867, -0.002377321943640709, -0.02046532928943634, 0.018501194193959236, -0.003140220884233713, 0.04460981860756874, 0.017878420650959015, 0.02531339041888714, 0.06300561875104904, -0.01954553835093975, -0.014620830304920673, -0.035239458084106445, -0.024431923404335976, 0.02195998840034008, -0.048595577478408813, -0.02678888663649559, -0.0014802871737629175, 0.06200918182730675, 0.05035850778222084, 0.06407871097326279, -0.008052953518927097, 0.05514908209443092, 0.05472750961780548, 0.044341545552015305, 0.048595577478408813, 0.02701883390545845, -0.052044790238142014, 0.019698837772011757, 0.0041654035449028015, -0.02584993466734886, 0.011832715943455696, -0.034338828176259995, 0.0055139497853815556, -0.015492714010179043, 0.006074447184801102, 0.0031306396704167128, 0.0003173754957970232, -0.10186675190925598, -0.048595577478408813, -0.04982196167111397, 0.05564729869365692, 0.01627836748957634, 0.031560298055410385, -0.03324658051133156, -0.006275651045143604, -0.032365113496780396, 0.00747808488085866, -0.024566059932112694, -0.04506971314549446, 0.0436900295317173, -0.03813296556472778, 0.0006335533107630908, 0.006472064647823572, 0.007200231775641441, -0.05219808593392372, 0.015138211660087109, 0.020848575979471207, -0.03533526882529259, -0.1171199381351471, 0.04357505589723587, 0.07979179173707962, 0.018204178661108017, -0.022860616445541382, -0.013317793607711792, 0.014965751208364964, 0.01162193063646555, 0.03194354474544525, 0.03223097696900368, 0.016364598646759987, 0.027076320722699165, -0.032959144562482834, -0.00023264222545549273, 0.0007874504663050175, -0.02402951568365097, 0.04825065657496452, -0.008623031899333, -0.012877061031758785, -0.03874615579843521, 0.010520098730921745, 0.014831614680588245, -0.04706259444355965, 0.07021064311265945, -0.012053082697093487, -0.034434642642736435, -0.04786740988492966, 0.005729525815695524, 0.06913755089044571, 0.003978571388870478, -0.0008503267890773714, -0.06687640398740768, 0.08906634151935577, 0.01288664247840643, -0.039512649178504944, -0.021480930969119072, 0.017236482352018356, -0.057103633880615234, 0.0017617333214730024, -0.012215961702167988, 0.040087517350912094, -0.0013257911195978522, 0.020867737010121346, -0.034664589911699295, -0.03955097496509552, 0.01768679730594158, -0.04154385253787041, -0.000426959857577458, -0.0232438612729311, 0.014601667411625385, -0.030621344223618507, -0.05465086176991463, 0.0487871989607811, 0.05430594086647034, 0.010098529048264027, -0.03069799393415451, 0.049515366554260254, 0.0018515565898269415, 0.01745685003697872, -0.03545024245977402, -0.07434970140457153, -0.0011694987770169973, -0.0660332664847374, -0.061702582985162735, 0.05269630625844002, -0.0021868967451155186, -0.026022395119071007, -0.0310429148375988, 0.029260821640491486, 0.03435799106955528, 0.0382670983672142, -0.04729254171252251, 0.06779619306325912, -0.05924981087446213, -0.030640507116913795, -0.03543107956647873, -0.006357091013342142, 0.042961861938238144, 0.018060460686683655, 0.008560754358768463, 0.021327633410692215, 0.024776846170425415, 0.03612092137336731, 0.0609360933303833, 0.025217577815055847, 0.005255259107798338, 0.025140928104519844, 0.014592085964977741, -0.012915385887026787, 0.011104549281299114, 0.04568290710449219, 0.0022635459899902344, 0.020503653213381767, 0.023148050531744957, 0.02793862298130989, 0.00764575507491827, -0.032844170928001404, -0.04196542128920555, 0.0232438612729311, -0.027210457250475883, 0.004929500166326761, -0.010500936768949032, 0.028570979833602905, -0.027076320722699165, -0.0153585784137249, -0.06289064884185791, 0.01924852281808853, 0.017159834504127502, -0.0001020990966935642, -0.03487537428736687, 0.03209684044122696, -0.058828242123126984, 0.01093208882957697, 0.025792445987462997, 0.005758269224315882, 0.043766677379608154, -0.014572924003005028, 0.004060010891407728, -0.015166955068707466, 0.028954224660992622, 0.033763960003852844, -0.0008096069213934243, 0.03677244111895561, -0.02830270677804947, -0.03918689116835594, -0.030161449685692787, 0.003053990425541997, -0.03955097496509552, -0.035833489149808884, 0.018951507285237312, -0.029394958168268204, 0.019852135330438614, -0.020312031731009483, -0.008963163010776043, 0.02230490930378437, 0.015569363720715046, 0.02828354574739933, -0.058138396590948105, -0.06852436065673828, -0.019813811406493187, -0.09335869550704956, -0.012522558681666851, 0.024776846170425415, 0.03148364648222923, 0.026137368753552437, -0.026482289656996727, -0.021480930969119072, 0.009753607213497162, -0.00399533798918128, 0.058598294854164124, 0.007185860071331263, -0.020407842472195625, -0.11121795326471329, 0.03163694590330124, -0.0014742990024387836, -0.005988216493278742, -0.0707855150103569, 0.06952080130577087, -0.013499835506081581, -0.031330350786447525, 0.061932533979415894, 0.0006814590306021273, 0.008833817206323147, 0.00045091271749697626, 0.026961347088217735, 0.02335883490741253, -0.012417166493833065, 0.019468890503048897, -0.019641350954771042, -0.043536730110645294, -0.04127557948231697, -0.043421756476163864, 0.02473852038383484, 0.04541463404893875, -0.005897196009755135, 0.004232471343129873, -0.02335883490741253, -0.06200918182730675, 0.024336112663149834, -0.033495690673589706, 0.01547355204820633, -0.028570979833602905, 0.005748688243329525, 0.05001358687877655, -0.0017198158893734217, -0.004850455559790134, 0.058713268488645554, 0.023492971435189247, 0.020139571279287338, -0.008972743526101112, 0.03801799193024635, -0.00966737698763609, 0.09121251851320267, 0.003942641895264387, -0.016661614179611206, -0.03205851837992668, 0.013605228625237942, -0.025351714342832565, -0.019832974299788475, 0.020043758675456047, -0.09052267670631409, 0.025160090997815132, 0.057563528418540955, 0.030870454385876656, -0.009447010233998299, -0.0673362985253334, 0.011554863303899765, 0.0006736743962392211, 0.04047076404094696, -0.003894736059010029, -0.01734187640249729, 0.03750060871243477, -0.0013174077030271292, 0.04656437411904335, -0.01759098470211029, -0.0022407907526940107, 0.046411074697971344, 0.07500121742486954, 0.0013808828080073, 0.02230490930378437, -0.04208039492368698, 0.016594545915722847, -0.01063507329672575, 0.018817372620105743, -0.08753335475921631, 0.08086487650871277, -0.02747872844338417, -0.02333967387676239, 0.06664645671844482, -0.08592372387647629, 0.021672554314136505, -0.04671766981482506, -0.005303164478391409, -0.01064465381205082, 0.04637274891138077, 0.04407327622175217, 0.01213931292295456, -0.004071987234055996, -0.056988660246133804, 0.06932917982339859, -0.013595647178590298, 0.04192709922790527, -0.002723440993577242, 0.02577328495681286, -0.019095225259661674, 0.03357233852148056, -0.009868580847978592, 0.004416908603161573, 0.010175177827477455, 0.0702872946858406, -0.02333967387676239, -0.005734316073358059, -0.027747001498937607, -0.013672295957803726, 0.027632027864456177, 0.006304394453763962, 0.0023533692583441734, 0.04384332895278931, 0.03851620852947235, -0.052504684776067734, 0.06971242278814316, -0.0671830028295517, -0.04510803893208504, 0.04920876771211624, 0.010424287989735603, -0.02876260317862034, -0.03773055598139763, 0.02012040838599205, 0.03207767754793167, 0.033054955303668976, -0.01235967967659235, -0.0395892970263958, 0.009973973967134953, 0.0395892970263958, -0.00618463009595871, -0.0120722446590662, 0.07258676737546921, 0.0037893434055149555, -0.006558294873684645, -0.026999671012163162, 0.012867479585111141, -0.02979736588895321, 0.07327660918235779, 0.006984655745327473, -0.05499578267335892, 0.0050827981904149055, 0.04116060584783554, -0.026022395119071007, -0.0371173620223999, -0.0035570007748901844, 0.002562956651672721, 0.016929885372519493, -0.050550129264593124, -0.023627107962965965, -0.005676829256117344, -0.03393642231822014, 0.02784281224012375, 0.027976948767900467, 0.01131533458828926, 0.015004076063632965, -0.015147793106734753, 0.023033076897263527, -0.019008995965123177, -0.011688998900353909, 0.023665431886911392, -0.0010718908160924911, -0.005901986267417669, -0.020177895203232765, 0.010893763974308968, 0.014975332655012608, 0.03242260217666626, -0.007851749658584595, 0.006486436352133751, -0.02483433298766613, 0.044111598283052444, 0.0057678502053022385, -0.05104834958910942, 0.019622188061475754, -0.08155471831560135, 0.022132448852062225, 0.053999342024326324, -0.0395892970263958, 0.03343820199370384, -0.04300018772482872, 0.024642709642648697, 0.008536801673471928, 0.028915900737047195, 0.005365442018955946, 0.05672038719058037, -0.022975590080022812, 0.012129731476306915, 0.02220909856259823, 0.011688998900353909, -0.05741023272275925, -0.029586581513285637, -0.04564458131790161, -0.021710878238081932, -0.0012862689327448606, 0.01614423282444477, -0.020503653213381767, -0.005691200960427523, -0.005245677661150694, 0.07116875797510147, -0.00673075532540679, -0.047445837408304214, 0.03577600046992302, 0.059748031198978424, -0.02795778587460518, -0.034664589911699295, 0.10064036399126053, 0.014869939535856247, 0.006975074764341116, 0.01230219192802906, 0.09581146389245987, 0.03426218032836914, -0.019162293523550034, 0.05419096723198891, -0.02002459578216076, -0.01529151014983654, 0.03797966614365578, -0.018980251625180244, 0.00016737065743654966, 0.015550200827419758, -0.033054955303668976, -0.016814911738038063, -0.038707833737134933, -0.009442220441997051, -0.03966594859957695, -0.011305753141641617, -0.011229104362428188, 0.01736103743314743, 0.004014500416815281, 0.010309313423931599, 0.03221181407570839, 0.022860616445541382, -0.027804488316178322, -0.035584378987550735, 0.025370877236127853, 0.011986014433205128, 0.0026731400284916162, -0.07312331348657608, -0.08009838312864304, 0.022381559014320374, 0.03700238838791847, -0.051469918340444565, -0.012618370354175568, -0.01717899553477764, -0.04798238351941109, -0.007521199993789196, -0.07634257525205612, 0.01924852281808853, -0.011152454651892185, -0.014678317122161388, -0.04656437411904335, 0.007391854654997587, 0.00042666043736971915, -0.002123421523720026, -0.017466429620981216, 0.0022312095388770103, 0.06346551328897476, -0.00010831186955329031, -0.023857055231928825, 0.0376155823469162, 0.03688741475343704, -0.014601667411625385, 0.016287948936223984, -0.008613450452685356, 0.00457499735057354, 0.05139327049255371, -0.02876260317862034, 0.03487537428736687, 0.03468375280499458, 0.031445324420928955, -0.045951180160045624, 0.027517054229974747, -0.008824235759675503, 0.014007636345922947, -0.011114129796624184, 0.02150009386241436, -0.007027771323919296, -0.024700196459889412, 0.03637003153562546, 0.040087517350912094, 0.02012040838599205, -0.010845857672393322, -0.01402679830789566, 0.010079366154968739, 0.005442091263830662, -0.05231305956840515, -0.05169986933469772, 0.00828769151121378, 0.019229361787438393, -0.007578686811029911, -0.012695019133388996, -0.006438530515879393, -0.01300161611288786, -0.040662385523319244, 0.0009185924427583814, -0.01270460058003664, -0.01921978034079075, -0.0024443899746984243, 0.01506156288087368, -0.01851077564060688, -0.022343233227729797, 0.006706802640110254, -0.05649043992161751, -0.07795220613479614, 0.04840395227074623, 0.060322899371385574, 0.024566059932112694, -0.0671830028295517, 0.01495616976171732, -0.02218993566930294, 0.0018060461152344942, 0.037768881767988205, 0.043076835572719574, -0.024681033566594124, -0.0013497440377250314, -0.019583864137530327, -0.0110470624640584, 0.023991191759705544, 0.034223854541778564, 0.0301422867923975, 0.01765805296599865, -0.04292353615164757, -0.007209812756627798, -0.049745313823223114, -0.05005190894007683, -0.009806303307414055, 0.008915256708860397, 0.00004528588760877028, 0.061817560344934464, -0.022745642811059952, 0.0163454357534647, 0.04426489770412445, 0.02851349301636219, -0.029394958168268204, 0.018769467249512672, 0.001994076184928417, -0.028609303757548332, -0.07691744714975357, -0.022477369755506516, 0.03230762481689453, -0.044571492820978165, 0.004704343155026436, 0.04234866797924042, 0.04775243625044823, -0.015234023332595825, -0.05672038719058037, -0.07542278617620468, 0.0356418639421463, 0.03253757581114769, 0.00194856571033597, -0.0015305881388485432, 0.05511075630784035, 0.01678616926074028, -0.003621673444285989, -0.06315892189741135, 0.02529422752559185, 0.0034971185959875584, -0.036523330956697464, -0.0017341875936836004, -0.027191294357180595, -0.06384876370429993, -0.03801799193024635, -0.05392269417643547, -0.04503139108419418, 0.0186449121683836, 0.02333967387676239, 0.047215890139341354, -0.03545024245977402, 0.019832974299788475, 0.018290409818291664, 0.05104834958910942, -0.02531339041888714, -0.0061415149830281734, -0.025696635246276855, -0.02575412206351757, 0.015722662210464478, -0.0032647757325321436, 0.016680777072906494, -0.05794677510857582, 0.029241660609841347, -0.0018838929245248437, 0.024546897038817406, -0.0238187313079834, 0.05169986933469772, 0.007952352054417133, 0.001982099609449506, 0.08776330202817917, -0.06664645671844482, 0.010769208893179893, -0.06335054337978363, -0.0037342519499361515, -0.03782636672258377, 0.005815756041556597, -0.020216219127178192, 0.01920061744749546, 0.010989575646817684, -0.026022395119071007, -0.022285746410489082, 0.05070342868566513, 0.008096069097518921, -0.0031234538182616234, -0.03274836018681526, -0.002467145211994648, 0.01775386556982994, -0.005700782407075167, -0.00301806116476655, -0.03414720669388771, 0.06587996333837509, 0.004637274891138077, 0.02897338755428791, 0.04414992406964302, 0.007813424803316593, 0.058138396590948105, 0.02263066917657852, -0.039742596447467804, -0.03659997880458832, 0.007899655029177666, -0.028091922402381897, -0.027402078732848167, -0.006179839838296175, -0.06515179574489594, -0.04798238351941109, 0.02991233952343464, -0.021327633410692215, -0.004816921427845955, 0.011516538448631763, 0.011995595879852772, 0.07733901590108871, -0.002864762907847762, -0.0029318309389054775, -0.0053414893336594105, 0.0016228067688643932, 0.05070342868566513, -0.014735803939402103, 0.018223341554403305, -0.057218607515096664, -0.0021785132121294737, 0.02150009386241436, -0.025160090997815132, 0.023435484617948532, 0.05035850778222084, 0.038707833737134933, 0.06384876370429993, -0.02577328495681286, -0.017322713509202003, -0.05380772054195404, -0.04752248898148537, 0.02117433398962021, -0.038937781006097794, -0.036044273525476456, 0.058253370225429535, -0.07599765807390213, 0.03541191667318344, -0.0510866753757, 0.00902544055134058, -0.03253757581114769, 0.010261408053338528, -0.018089205026626587, -0.04526133835315704, 0.04920876771211624, -0.008584707044064999, 0.004359421785920858, -0.04012584313750267, -0.005533112213015556, 0.03157946094870567, -0.054574210196733475, 0.0015521458117291331, -0.061932533979415894, -0.013739364221692085, 0.036159247159957886, 0.007319996133446693, 0.023780405521392822, -0.008373922668397427, 0.031560298055410385, -0.053769394755363464, -0.01218721829354763, -0.036044273525476456, 0.014218421652913094, 0.032825008034706116, 0.0014120214618742466, 0.015013656578958035, -0.0038492255844175816, -0.03395558521151543, 0.011037481017410755, 0.009264969266951084, 0.023550458252429962, 0.008484105579555035, 0.016642451286315918, 0.0034348410554230213, -0.05219808593392372, 0.044571492820978165, -0.006045703776180744, 0.035948462784290314, -0.030276423320174217, 0.0081296032294631, 0.008383503183722496, 0.00030450080521404743, 0.0545358881354332, -0.017916744574904442, -0.01867365464568138, 0.05495745688676834, 0.027651188895106316, 0.004898361396044493, 0.04798238351941109, -0.029241660609841347, -0.03207767754793167, -0.0734299048781395, -0.016335854306817055, 0.013710620813071728, 0.06185588240623474, -0.0407390370965004, -0.002257557585835457, 0.020618626847863197, 0.015904704108834267, 0.047100916504859924 ]
30,715
networkx.algorithms.shortest_paths.weighted
goldberg_radzik
Compute shortest path lengths and predecessors on shortest paths in weighted graphs. The algorithm has a running time of $O(mn)$ where $n$ is the number of nodes and $m$ is the number of edges. It is slower than Dijkstra but can handle negative edge weights. Parameters ---------- G : NetworkX graph The algorithm works for all types of graphs, including directed graphs and multigraphs. source: node label Starting node for path weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number. Returns ------- pred, dist : dictionaries Returns two dictionaries keyed by node to predecessor in the path and to the distance from the source respectively. Raises ------ NodeNotFound If `source` is not in `G`. NetworkXUnbounded If the (di)graph contains a negative (di)cycle, the algorithm raises an exception to indicate the presence of the negative (di)cycle. Note: any negative weight edge in an undirected graph is a negative cycle. As of NetworkX v3.2, a zero weight cycle is no longer incorrectly reported as a negative weight cycle. Examples -------- >>> G = nx.path_graph(5, create_using=nx.DiGraph()) >>> pred, dist = nx.goldberg_radzik(G, 0) >>> sorted(pred.items()) [(0, None), (1, 0), (2, 1), (3, 2), (4, 3)] >>> sorted(dist.items()) [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)] >>> G = nx.cycle_graph(5, create_using=nx.DiGraph()) >>> G[1][2]["weight"] = -7 >>> nx.goldberg_radzik(G, 0) Traceback (most recent call last): ... networkx.exception.NetworkXUnbounded: Negative cycle detected. Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. The dictionaries returned only have keys for nodes reachable from the source. In the case where the (di)graph is not connected, if a component not containing the source contains a negative (di)cycle, it will not be detected.
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, source, weight='weight', *, backend=None, **backend_kwargs)
[ 0.00868748314678669, -0.0040619331412017345, -0.034225184470415115, -0.04419538378715515, -0.038967348635196686, -0.021786730736494064, -0.010757319629192352, 0.04058045893907547, 0.07362010329961777, -0.010543533600866795, -0.052863433957099915, 0.029735680669546127, 0.028666751459240913, 0.0255182683467865, -0.027247989550232887, 0.035896603018045425, 0.00011251092655584216, 0.03593547269701958, -0.0012693540193140507, 0.013672582805156708, -0.015033039264380932, -0.0565560981631279, 0.05550660565495491, 0.049598339945077896, -0.02098989300429821, -0.009280253201723099, 0.014858122915029526, -0.04003627598285675, -0.02579035796225071, -0.016296319663524628, 0.017744233831763268, -0.018745141103863716, -0.006330979056656361, -0.005538999568670988, 0.016578128561377525, 0.05853847786784172, 0.007871209643781185, -0.0030440203845500946, -0.023360973224043846, -0.044039905071258545, -0.03018268756568432, -0.03045477904379368, 0.005704197566956282, -0.03782067820429802, 0.0800725519657135, 0.08388183265924454, -0.01746242493391037, 0.008672907017171383, -0.019396215677261353, -0.018832597881555557, 0.015169084072113037, 0.0014722077175974846, -0.00927539449185133, 0.009528051130473614, -0.007817762903869152, 0.03945322334766388, -0.03325343132019043, 0.05418501794338226, 0.027286861091852188, -0.038248248398303986, 0.03949209302663803, 0.010572686791419983, 0.07086032629013062, 0.04003627598285675, -0.06378595530986786, -0.023555323481559753, -0.04656646400690079, -0.037529151886701584, -0.0399974063038826, 0.02135915867984295, 0.001062248949892819, -0.009537768550217152, -0.01345879677683115, -0.03552733734250069, -0.0018937061540782452, 0.03795672208070755, -0.00001619906834093854, -0.03482767194509506, 0.011097433976829052, -0.03984192758798599, 0.04388442263007164, -0.056478358805179596, -0.025809794664382935, -0.07105467468500137, 0.0730370506644249, 0.025071261450648308, -0.004120238125324249, 0.002691759495064616, -0.009110196493566036, -0.03410857543349266, -0.036712877452373505, 0.03076574020087719, -0.0033209703397005796, 0.0004876991733908653, 0.05678931996226311, 0.02678154781460762, 0.009037314914166927, -0.05706141144037247, 0.04998704046010971, 0.031096138060092926, 0.06845036894083023, 0.0048903534188866615, -0.01456659659743309, 0.036129824817180634, 0.02647058665752411, -0.06724539399147034, -0.0110585642978549, 0.015849312767386436, -0.01391552109271288, -0.05566208437085152, -0.022641874849796295, 0.012380149215459824, 0.025945840403437614, -0.026800982654094696, 0.023497018963098526, 0.0032699531875550747, 0.006797421257942915, 0.04400103539228439, -0.0005387162673287094, -0.02108706720173359, -0.025226742029190063, 0.0525524728000164, -0.08310442417860031, -0.003947751596570015, 0.040424980223178864, -0.05640061944723129, 0.02470199391245842, -0.019920963793992996, 0.06627364456653595, 0.017938584089279175, 0.026159625500440598, 0.004798037000000477, -0.02786991372704506, 0.06561285257339478, 0.03199015185236931, -0.024546513333916664, -0.0566338412463665, 0.04691629856824875, 0.06506866961717606, 0.010446358472108841, 0.04256283864378929, -0.07548587024211884, 0.0077157290652394295, 0.02876392751932144, 0.005932559724897146, -0.028472401201725006, 0.011136304587125778, 0.014061284251511097, 0.03130992501974106, 0.059743452817201614, 0.015460610389709473, 0.0028715338557958603, 0.006928608287125826, 0.011661051772534847, 0.0016568410210311413, -0.06817828118801117, -0.04197978600859642, 0.02044571004807949, 0.005801373161375523, -0.0004734265385195613, 0.016616998240351677, -0.044622957706451416, 0.005718774162232876, 0.014887276105582714, -0.049831561744213104, 0.03496371954679489, 0.022194867953658104, 0.05216376855969429, -0.027170250192284584, 0.012370431795716286, -0.005893689580261707, -0.06413578242063522, -0.04777144268155098, -0.02917206473648548, -0.02446877397596836, 0.0032796708401292562, 0.02511013112962246, -0.0023237073328346014, 0.011835967190563679, -0.019444802775979042, 0.009911893866956234, -0.026626067236065865, 0.023147188127040863, -0.013633713126182556, 0.030066078528761864, 0.02917206473648548, 0.02225317247211933, -0.02163125015795231, 0.002961421152576804, 0.03482767194509506, -0.04827675223350525, -0.09328841418027878, -0.060559727251529694, 0.08318217098712921, -0.009085902944207191, 0.006709963548928499, -0.037257060408592224, -0.022175433114171028, -0.027286861091852188, 0.06370820850133896, -0.009115055203437805, -0.029327545315027237, 0.039919666945934296, -0.008867258206009865, 0.009251100942492485, -0.028841666877269745, -0.032456591725349426, 0.008566014468669891, 0.0010033362777903676, 0.01850220188498497, -0.03506089374423027, -0.045361489057540894, 0.02998833730816841, -0.02971624583005905, 0.001164283137768507, 0.013779476284980774, -0.03169862553477287, 0.04003627598285675, 0.014012697152793407, -0.05908266082406044, -0.004423911217600107, -0.015266260132193565, -0.009571779519319534, 0.02116480842232704, 0.06184244155883789, -0.05029800161719322, 0.047032907605171204, 0.030649131163954735, 0.025848664343357086, -0.07330914586782455, 0.07723502814769745, -0.03278699144721031, 0.09632028639316559, -0.01477066520601511, 0.07377558946609497, -0.047888051718473434, 0.003481309860944748, 0.040697067975997925, 0.0455947108566761, 0.027928218245506287, -0.021689556539058685, -0.023458149284124374, -0.014654054306447506, -0.058110907673835754, 0.005859678145498037, -0.0001001362397801131, 0.03148483857512474, -0.012321844696998596, 0.026159625500440598, -0.0064670247957110405, 0.005023969803005457, 0.027714433148503304, -0.042368486523628235, -0.05752785503864288, -0.012953484430909157, -0.043223630636930466, -0.02098989300429821, -0.03749028220772743, -0.03651852533221245, -0.06592381000518799, -0.03222337365150452, -0.027850478887557983, -0.06098730117082596, 0.10152889043092728, -0.0038797289598733187, 0.03261207416653633, 0.03121274709701538, -0.014333375729620457, -0.08022803068161011, 0.006617646664381027, 0.0427183173596859, 0.04306815192103386, -0.006875161547213793, -0.00362950237467885, -0.02511013112962246, 0.0051940265111625195, -0.03220393881201744, 0.034847110509872437, 0.012836874462664127, -0.023011142387986183, -0.04369007423520088, -0.008391098119318485, -0.041241250932216644, -0.0064961775206029415, 0.017938584089279175, 0.029774552211165428, 0.0120983412489295, -0.03482767194509506, 0.01646151766180992, 0.006695386953651905, 0.07019952684640884, -0.012176081538200378, 0.010592121630907059, -0.03774293512105942, 0.062270015478134155, 0.047654829919338226, -0.003481309860944748, -0.07284270226955414, 0.016403213143348694, 0.05364083871245384, 0.015460610389709473, -0.02569318376481533, 0.025673748925328255, -0.005694480147212744, -0.042640578001737595, 0.008245334960520267, 0.031232183799147606, -0.016821065917611122, -0.0025897251907736063, -0.030960092321038246, -0.021417465060949326, -0.025168435648083687, 0.00179774546995759, 0.007331886328756809, 0.003678089939057827, -0.03721819072961807, -0.03515807166695595, 0.007331886328756809, -0.006748833693563938, 0.03220393881201744, -0.038928475230932236, 0.07645762711763382, -0.06833375990390778, 0.02923036925494671, -0.030551955103874207, 0.02926923893392086, 0.03179579973220825, 0.025673748925328255, 0.03509976342320442, 0.022505829110741615, 0.03789841756224632, 0.022505829110741615, 0.02623736672103405, 0.030862916260957718, -0.019794635474681854, 0.08979009836912155, 0.074397511780262, -0.005407812539488077, 0.00005898852396057919, -0.003167918883264065, 0.04738273844122887, 0.02170899137854576, -0.022019952535629272, 0.02374967560172081, 0.006107475608587265, -0.04384555295109749, 0.033991966396570206, -0.038889605551958084, 0.007448496762663126, -0.04738273844122887, 0.02184503711760044, 0.06790619343519211, 0.0183175690472126, 0.02647058665752411, 0.05049235373735428, 0.0030998962465673685, -0.010932235978543758, -0.040697067975997925, 0.022311478853225708, -0.0048952121287584305, 0.008405674248933792, 0.018162088468670845, 0.009149067103862762, -0.002898257225751877, -0.046294376254081726, 0.013653147965669632, 0.019386498257517815, -0.013361621648073196, -0.018210675567388535, -0.05060896277427673, -0.008425110019743443, -0.060598596930503845, -0.025071261450648308, 0.05546773597598076, 0.01203031837940216, 0.0005007571307942271, 0.016412930563092232, -0.007404767908155918, -0.003508032998070121, 0.0440787747502327, -0.022019952535629272, 0.05741124227643013, 0.005208603106439114, 0.045944541692733765, 0.024915780872106552, -0.04120238125324249, 0.06646799296140671, 0.007409626618027687, 0.033719874918460846, 0.006326120346784592, -0.024682559072971344, -0.017812255769968033, 0.044350866228342056, 0.028627881780266762, -0.0026820418424904346, -0.04162995517253876, 0.07179320603609085, 0.03026042878627777, -0.05057009309530258, -0.025051824748516083, 0.015781288966536522, -0.02126198448240757, -0.0552733838558197, 0.06907229870557785, 0.0096786729991436, -0.047615960240364075, 0.04590567201375961, 0.02786991372704506, 0.025984710082411766, 0.04854884371161461, -0.041824303567409515, -0.002395374234765768, -0.014605467207729816, 0.01715146377682686, -0.04388442263007164, -0.05881056934595108, -0.06856698542833328, 0.04217413440346718, 0.05678931996226311, 0.0029930032324045897, 0.0366351380944252, -0.02940528467297554, 0.06398030370473862, -0.0828712061047554, 0.01221495121717453, -0.043184760957956314, -0.013040942139923573, -0.028025394305586815, -0.0009158783941529691, 0.05080331489443779, -0.0248380396515131, -0.02357475832104683, 0.0393560491502285, -0.055117905139923096, -0.007127817720174789, -0.0051940265111625195, 0.016169991344213486, 0.002457323716953397, 0.07198755443096161, -0.034089140594005585, -0.009445452131330967, -0.02777273766696453, -0.026256801560521126, -0.02701476961374283, -0.05196942016482353, -0.07906193286180496, 0.02054288610816002, -0.022855661809444427, 0.030862916260957718, -0.03587716817855835, 0.007006348576396704, -0.03875356167554855, 0.021203678101301193, 0.023147188127040863, -0.026081884279847145, 0.02497408539056778, 0.015985358506441116, 0.010242289863526821, -0.11987560987472534, 0.027034204453229904, 0.05080331489443779, -0.031873539090156555, 0.028491836041212082, -0.011933142319321632, -0.047926921397447586, 0.0592770129442215, 0.034361232072114944, 0.0010300595313310623, -0.0007033071597106755, -0.025906968861818314, 0.045361489057540894, -0.010825342498719692, -0.0855143740773201, -0.005927701015025377, 0.022311478853225708, -0.004173684865236282, -0.0635138601064682, 0.014760947786271572, 0.002158509334549308, -0.01669473946094513, 0.040735941380262375, -0.0400751456618309, 0.06689556688070297, -0.007866350933909416, 0.005466117989271879, -0.05500129237771034, 0.03904508799314499, -0.019619720056653023, 0.014488856308162212, 0.0029225510079413652, 0.040697067975997925, -0.06285306811332703, 0.06946099549531937, -0.031193312257528305, -0.003928316757082939, 0.0427183173596859, 0.033175691962242126, -0.016539258882403374, 0.08077221363782883, -0.013439361937344074, 0.002604301553219557, -0.010388053022325039, -0.054806940257549286, 0.059471361339092255, 0.033914223313331604, 0.015237106941640377, 0.014547161757946014, 0.04897641763091087, -0.025712618604302406, 0.026451151818037033, 0.017336096614599228, 0.0029759975150227547, 0.047071777284145355, 0.055117905139923096, 0.04578906297683716, -0.0077788932248950005, -0.006695386953651905, 0.06891681253910065, 0.0022192439064383507, -0.02238921821117401, 0.04337911307811737, 0.06219227612018585, -0.015557786449790001, 0.027714433148503304, -0.07435863465070724, 0.03533298522233963, 0.004346170928329229, -0.04749935120344162, 0.023108316585421562, 0.004088656045496464, 0.010932235978543758, 0.03373930975794792, -0.00041663963929750025, 0.0269175935536623, 0.018424460664391518, 0.014469421468675137, 0.05612852796912193, -0.018657682463526726, -0.014722077175974846, -0.017034852877259254, 0.059471361339092255, 0.00023580224660690874, -0.004640126600861549, -0.005650751292705536, 0.06992743909358978, -0.005121144931763411, -0.002141503617167473, -0.008075278252363205, -0.00027725365362130105, -0.050997667014598846, -0.022000517696142197, -0.0023589334450662136, 0.007239569444209337, 0.05212489888072014, 0.06957760453224182, -0.009693249128758907, 0.014148742891848087, 0.009372570551931858, 0.006641940679401159, 0.08504793792963028, -0.02542109228670597, -0.08535889536142349, -0.046216633170843124, -0.01691824197769165, -0.015431458130478859, -0.030551955103874207, 0.01570354960858822, -0.012807721272110939, 0.0013628853484988213, -0.006374708376824856, -0.029774552211165428, 0.04058045893907547, -0.005713915452361107, 0.026315106078982353, -0.028375225141644478, -0.007910080254077911, -0.02637341059744358, -0.045167140662670135, 0.023244362324476242, -0.051036536693573, -0.017851125448942184, 0.021242549642920494, 0.06300854682922363, 0.05196942016482353, 0.02538222260773182, -0.0021548650693148375, -0.05228038132190704, 0.00411537941545248, -0.04800466075539589, 0.010504663921892643, 0.010728167369961739, -0.05332987383008003, 0.014352810569107533, 0.03785954788327217, 0.011291785165667534, -0.05585643649101257, -0.019697459414601326, 0.01728750951588154, 0.03148483857512474, -0.003073172876611352, -0.09313292801380157, -0.009853588417172432, 0.006977195851504803, -0.006194933783262968, 0.03121274709701538, -0.014867840334773064, -0.006311544217169285, -0.08714692294597626, -0.015071908943355083, -0.05107540637254715, 0.019959833472967148, 0.013546254485845566, 0.025945840403437614, -0.02474086359143257, -0.02963850647211075, -0.00761369476094842, -0.009873023256659508, 0.016160273924469948, -0.029910597950220108, -0.035896603018045425, 0.015217672102153301, -0.03978361934423447, 0.019979268312454224, -0.012603653594851494, 0.0028618164360523224, 0.0385592095553875, -0.0024621824268251657, 0.019376780837774277, -0.06048198789358139, 0.033000774681568146, -0.021786730736494064, -0.049015287309885025, 0.044622957706451416, 0.0538351871073246, -0.022505829110741615, -0.01592705212533474, 0.06930551677942276, -0.010504663921892643, -0.015217672102153301, -0.011952578090131283, -0.03488598018884659, 0.0440787747502327, -0.021320289000868797, -0.03335060551762581, -0.03593547269701958, -0.004389899782836437, -0.003908881451934576, -0.02248639427125454, 0.009552344679832458, 0.0007834769203327596, -0.005728491581976414, -0.015324565581977367, -0.03053252026438713, 0.006729398388415575, 0.020367970690131187, 0.07272609323263168, -0.018793728202581406, -0.034089140594005585, 0.012137210927903652, 0.012535630725324154, 0.03253433480858803, 0.05402953922748566, 0.06934438645839691, -0.04384555295109749, -0.03747084364295006, -0.012982637621462345, 0.01764705777168274, -0.0621534027159214, -0.017928866669535637, 0.007662282790988684, -0.06409691274166107, -0.011505571193993092, 0.00855143740773201, 0.016296319663524628, -0.03288416564464569, -0.06048198789358139, 0.026839854195713997, -0.004122667480260134, -0.07579683512449265, -0.06771183758974075, 0.04302927851676941, 0.04610002413392067, 0.024935215711593628, -0.013128400780260563, -0.011554158292710781, 0.053679708391427994, -0.05189168080687523, -0.08395957201719284, 0.03492484986782074, 0.014148742891848087, 0.019920963793992996, -0.03457501903176308, 0.04038610681891441, 0.008808952756226063, -0.03809276968240738, -0.05138636752963066, -0.0024719000793993473, -0.019920963793992996, 0.030843481421470642, -0.035993777215480804, 0.02040684036910534, 0.05329100415110588, 0.00805098470300436, -0.030066078528761864, -0.011146022006869316, -0.03140709921717644, -0.08038351684808731, 0.0387146919965744, 0.02303057722747326, 0.009805000387132168, -0.03622699901461601, -0.03026042878627777, -0.013964109122753143, 0.026800982654094696, 0.01151528861373663, -0.01490671094506979, 0.02071780152618885, -0.01307009533047676, -0.012506477534770966, -0.0026601774152368307, 0.014479138888418674, -0.02361362986266613, -0.003226224333047867, 0.028608446940779686, -0.0884685143828392, -0.0008581805159337819, 0.023419277742505074, -0.08349312841892242, 0.002066192450001836, -0.017928866669535637, -0.026256801560521126, 0.0881575495004654, 0.009839012287557125, 0.032048456370830536, 0.004761596210300922, -0.014605467207729816, 0.02524617686867714, -0.015003886073827744, -0.009873023256659508, 0.05993780493736267, -0.02654832787811756, 0.0183175690472126, -0.039880797266960144, -0.017715081572532654, -0.0013142976677045226, -0.010961388237774372, 0.010125679895281792, 0.012535630725324154, -0.02750064618885517, -0.01092251855880022, 0.03103783167898655, -0.0007300304132513702, 0.024099506437778473, -0.018405025824904442, 0.011690204031765461, -0.01182624977082014, -0.040152888745069504, -0.05196942016482353, -0.026081884279847145, -0.048199012875556946, -0.06125938892364502, -0.008716636337339878, -0.018764575943350792, 0.0227584857493639, 0.0220782570540905, 0.04660533741116524, 0.02569318376481533, 0.08504793792963028 ]
30,722
networkx.algorithms.similarity
graph_edit_distance
Returns GED (graph edit distance) between graphs G1 and G2. Graph edit distance is a graph similarity measure analogous to Levenshtein distance for strings. It is defined as minimum cost of edit path (sequence of node and edge edit operations) transforming graph G1 to graph isomorphic to G2. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. upper_bound : numeric Maximum edit distance to consider. Return None if no edit distance under or equal to upper_bound exists. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Examples -------- >>> G1 = nx.cycle_graph(6) >>> G2 = nx.wheel_graph(7) >>> nx.graph_edit_distance(G1, G2) 7.0 >>> G1 = nx.star_graph(5) >>> G2 = nx.star_graph(5) >>> nx.graph_edit_distance(G1, G2, roots=(0, 0)) 0.0 >>> nx.graph_edit_distance(G1, G2, roots=(1, 0)) 8.0 See Also -------- optimal_edit_paths, optimize_graph_edit_distance, is_isomorphic: test for graph edit distance of 0 References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, roots=None, upper_bound=None, timeout=None, *, backend=None, **backend_kwargs)
[ 0.04682270437479019, -0.0429469496011734, 0.0001637359382584691, 0.019333967939019203, -0.05139295756816864, -0.056680116802453995, -0.018740283325314522, -0.0075666834600269794, 0.018157800659537315, -0.06452123820781708, -0.04119949787855148, 0.008081957697868347, -0.008630835451185703, 0.055649567395448685, -0.01148164365440607, -0.005457981489598751, -0.0019840840250253677, -0.062415335327386856, 0.03226061910390854, 0.003150450997054577, -0.02771276794373989, -0.08325032144784927, 0.032058991491794586, 0.03913840278983116, -0.04388788342475891, -0.0009409347549080849, 0.04597138240933418, 0.014539682306349277, 0.029079364612698555, -0.009168513119220734, 0.006782571319490671, -0.06788171827793121, -0.06259456276893616, 0.006127277389168739, -0.03161092475056648, 0.005645608529448509, 0.04184919223189354, 0.019882846623659134, 0.014920536428689957, -0.051124121993780136, -0.049018219113349915, -0.01483092363923788, -0.01376677118241787, -0.03783901780843735, 0.047181155532598495, 0.03591234236955643, -0.044313546270132065, 0.006261696573346853, -0.015570229850709438, -0.01805698499083519, 0.015816664323210716, -0.12698137760162354, -0.045366495847702026, 0.0380406454205513, 0.009375742636620998, 0.021462272852659225, 0.009549367241561413, 0.04227485507726669, 0.05349886044859886, -0.08853747695684433, 0.025158802047371864, -0.03613637387752533, -0.01796737313270569, 0.03163332864642143, -0.05788988992571831, -0.004452637396752834, -0.03165573254227638, -0.04158035293221474, 0.02232479676604271, 0.0334927961230278, -0.05264753848314285, 0.01147044263780117, 0.051079314202070236, -0.07971061021089554, -0.00003478622966213152, 0.011257612146437168, 0.01335231214761734, -0.02300809510052204, -0.005491586402058601, -0.025046786293387413, 0.010434294119477272, -0.04095306247472763, 0.047091543674468994, -0.07213833183050156, 0.07379616796970367, 0.0023495364002883434, 0.03051316924393177, 0.018740283325314522, -0.047181155532598495, -0.07903851568698883, 0.00424540787935257, -0.030042702332139015, -0.017832953482866287, 0.015323794446885586, 0.03810785710811615, 0.00980700459331274, -0.024329883977770805, -0.05497747287154198, 0.015391003340482712, 0.0022151172161102295, 0.06474526971578598, 0.056635309010744095, -0.031991779804229736, 0.024352287873625755, 0.009196517057716846, -0.07724626362323761, -0.041535548865795135, 0.05511189252138138, 0.027399122714996338, -0.061384789645671844, -0.057576242834329605, 0.030132314190268517, 0.041445933282375336, -0.026278963312506676, -0.010333479382097721, 0.014909334480762482, -0.04261090233922005, 0.018751485273241997, -0.018829897046089172, 0.009566170163452625, 0.00996942725032568, -0.014046811498701572, -0.03356000408530235, 0.03246224671602249, 0.01390119083225727, -0.04892860725522041, 0.008502017706632614, 0.06949475407600403, 0.024038642644882202, -0.07531958818435669, 0.016780002042651176, -0.06747846305370331, 0.010025435127317905, 0.10135211050510406, -0.0012097732396796346, -0.012993860989809036, -0.037480566650629044, 0.009638980031013489, 0.018337026238441467, 0.02202235348522663, 0.03140929713845253, -0.03978809714317322, -0.007661897223442793, -0.00575202377513051, -0.018045783042907715, -0.05228908732533455, 0.011526450514793396, -0.019490791484713554, 0.0077627114951610565, 0.008020348846912384, -0.02145107090473175, 0.005155538208782673, 0.001968681812286377, -0.009599774144589901, 0.025315625593066216, -0.007281042635440826, -0.00022088162950240076, -0.010434294119477272, -0.003906559199094772, 0.015290189534425735, -0.004581456072628498, -0.04843573644757271, 0.0020246899221092463, 0.011492845602333546, 0.053722891956567764, -0.018482645973563194, 0.04570254310965538, 0.007975541986525059, -0.07917293906211853, 0.005908845923841, -0.03221581131219864, -0.04659867286682129, -0.07460268586874008, -0.01421483512967825, 0.0189755167812109, 0.016499962657690048, -0.009050896391272545, -0.026144543662667274, 0.007269841153174639, -0.016533566638827324, 0.028205638751387596, 0.01373316626995802, 0.04919744282960892, 0.05076567083597183, -0.0012993860291317105, 0.05981656536459923, 0.030109912157058716, -0.027443930506706238, 0.022728053852915764, -0.022470418363809586, -0.02064455673098564, -0.06313224136829376, -0.012489788234233856, 0.05058644339442253, 0.03315674886107445, 0.02851928398013115, -0.005200344603508711, 0.03902638703584671, 0.004071782808750868, 0.07903851568698883, -0.030714798718690872, -0.01229936070740223, 0.06550697982311249, 0.007437864784151316, 0.03156612068414688, -0.0026127740275114775, 0.029280992224812508, -0.01844904199242592, 0.0119521114975214, 0.029280992224812508, -0.049107830971479416, 0.028048817068338394, 0.02775757387280464, -0.0016914422158151865, 0.02677183412015438, 0.038712743669748306, -0.03436652198433876, 0.04001212865114212, -0.020655756816267967, -0.03243984654545784, 0.013273900374770164, -0.019266758114099503, -0.015088560059666634, -0.011795288883149624, 0.041356321424245834, -0.05618724599480629, 0.009549367241561413, 0.028026413172483444, 0.048077285289764404, -0.044134318828582764, 0.008031549863517284, -0.07894890755414963, 0.049152638763189316, -0.016051897779107094, 0.040348175913095474, -0.02865370362997055, -0.027175091207027435, 0.025898108258843422, 0.034702569246292114, -0.0012993860291317105, -0.07272081077098846, -0.05354366824030876, -0.03741335868835449, 0.008227578364312649, -0.004349022638052702, -0.0007799117011018097, 0.041356321424245834, -0.008810061030089855, -0.011196003295481205, 0.008244380354881287, -0.01759772002696991, -0.03535226359963417, -0.009879814460873604, -0.007269841153174639, -0.040415387600660324, -0.003640521317720413, -0.04106507822871208, 0.04211803153157234, -0.012512191198766232, -0.005189143121242523, 0.016320737078785896, 0.008832464925944805, -0.04323819279670715, 0.02142866887152195, 0.0238370131701231, 0.023097706958651543, 0.028362460434436798, 0.013038666918873787, -0.06944994628429413, -0.027354316785931587, 0.036786068230867386, 0.0755884200334549, -0.032843101769685745, 0.06080230697989464, -0.01794496923685074, 0.010708733461797237, -0.002784998854622245, 0.018505049869418144, -0.011705676093697548, -0.047225963324308395, -0.03051316924393177, -0.00763949379324913, -0.041401129215955734, 0.014595690183341503, -0.036674052476882935, -0.015424608252942562, -0.029012154787778854, -0.026883849874138832, 0.014942939393222332, 0.00128188356757164, 0.04102027416229248, -0.018157800659537315, 0.042297255247831345, 0.032977521419525146, 0.08679002523422241, 0.037525374442338943, 0.01915474236011505, 0.0020582948345690966, -0.03877995163202286, 0.06487969309091568, 0.03062518499791622, -0.043126173317432404, 0.027824783697724342, -0.05829314514994621, 0.015301390551030636, 0.01476371381431818, 0.014954141341149807, -0.013408320024609566, 0.04933186247944832, 0.05125853791832924, -0.03414249047636986, -0.028362460434436798, -0.0429917573928833, 0.032977521419525146, -0.021876731887459755, -0.002726190257817507, -0.008216376416385174, -0.015682244673371315, 0.07997944951057434, -0.00790273118764162, -0.024419495835900307, 0.02959463745355606, -0.008866069838404655, 0.02033091150224209, -0.041423533111810684, -0.04019135609269142, 0.03976569324731827, 0.038712743669748306, 0.052781958132982254, -0.004441435914486647, 0.00823877938091755, -0.014898133464157581, 0.025024382397532463, 0.013621150515973568, -0.0018734682817012072, 0.035733114928007126, 0.04550091549754143, -0.014842125587165356, -0.018314622342586517, 0.008815662004053593, 0.10395088791847229, 0.07496113330125809, -0.012747425585985184, 0.011974514462053776, 0.01280343346297741, -0.004965111147612333, 0.04843573644757271, -0.026368575170636177, -0.06125036999583244, -0.008356396108865738, -0.03257426247000694, 0.02657020464539528, -0.014562085270881653, -0.03497140854597092, 0.0032652674708515406, 0.050048764795064926, 0.023388948291540146, -0.0759468749165535, 0.04117709770798683, -0.032775893807411194, -0.009919020347297192, 0.008261183276772499, -0.005740821827203035, -0.04225245118141174, -0.025427641347050667, 0.02296328730881214, -0.0331791490316391, -0.015883874148130417, 0.05345405265688896, -0.07442345470190048, 0.032798297703266144, -0.028228042647242546, 0.06886745989322662, 0.01963641121983528, -0.02777997776865959, 0.016466358676552773, -0.051079314202070236, 0.023276932537555695, -0.032977521419525146, 0.02477794699370861, 0.03898158296942711, 0.02486756071448326, -0.014259641990065575, 0.043395012617111206, -0.005656810011714697, -0.027063075453042984, 0.059502918273210526, 0.03535226359963417, 0.034769777208566666, 0.02099180594086647, -0.022089563310146332, 0.013262699358165264, 0.052826765924692154, -0.003228862304240465, 0.0033716827165335417, 0.008737251162528992, 0.0671648159623146, 0.050048764795064926, -0.07330329716205597, -0.03461295738816261, -0.046195413917303085, 0.03443372994661331, -0.0036713257431983948, 0.011795288883149624, 0.006379313301295042, -0.028944944962859154, 0.03420969843864441, 0.036718856543302536, 0.01770973578095436, 0.06214649975299835, -0.07209352403879166, 0.013576343655586243, 0.036741260439157486, 0.024240270256996155, -0.06201208010315895, -0.04032577574253082, -0.046150609850883484, 0.033716827630996704, 0.051079314202070236, -0.011604861356317997, 0.01339711807668209, 0.0002537863329052925, 0.0018902706215158105, -0.046195413917303085, -0.015727052465081215, -0.05547034367918968, -0.013621150515973568, -0.0018412636127322912, -0.022201579064130783, -0.00256376713514328, -0.028922541067004204, -0.014954141341149807, 0.04570254310965538, -0.02760075218975544, -0.04173717647790909, -0.02374739944934845, 0.04384307935833931, 0.005144336726516485, 0.08047232031822205, 0.0033016728702932596, 0.011537652462720871, -0.012859441339969635, 0.016275931149721146, -0.030221927911043167, -0.035845134407281876, -0.03443372994661331, -0.012276957742869854, 0.01287064328789711, -0.030759604647755623, -0.006121676415205002, 0.04384307935833931, 0.02583089843392372, -0.010591116733849049, 0.007370655424892902, -0.047181155532598495, 0.012254554778337479, -0.013273900374770164, 0.007936336100101471, -0.08253341913223267, 0.041535548865795135, 0.004993115086108446, 0.009000488556921482, 0.056769728660583496, 0.036786068230867386, -0.03642761707305908, 0.03528505191206932, 0.0664927214384079, -0.0057688262313604355, -0.0284296702593565, -0.011067184619605541, 0.0034388923086225986, -0.09239082783460617, -0.08392241597175598, -0.03604676201939583, 0.03537466377019882, 0.026301365345716476, -0.012904247269034386, 0.0070906151086091995, -0.03214860334992409, -0.01198571640998125, 0.02298569120466709, -0.04960070177912712, 0.00973979476839304, -0.023456158116459846, 0.03239503875374794, 0.005169540178030729, 0.0381750650703907, -0.024397093802690506, -0.06295301765203476, -0.02674943022429943, -0.03266387805342674, -0.04977992922067642, 0.008994887582957745, -0.01325149741023779, 0.0008716247975826263, 0.0425884984433651, -0.014674101024866104, -0.058606792241334915, 0.017765743657946587, -0.030087508261203766, -0.01015425380319357, 0.012758626602590084, -0.040415387600660324, 0.025875704362988472, 0.03149890899658203, -0.02569647878408432, -0.022537626326084137, 0.05968214571475983, 0.001930876518599689, 0.0037385353352874517, 0.020633354783058167, -0.03909359872341156, 0.09100183099508286, 0.042431674897670746, -0.0008226177887991071, 0.026906251907348633, 0.02016288787126541, 0.013139481656253338, 0.03170054033398628, -0.033022329211235046, -0.008333993144333363, 0.0022655243519693613, 0.025024382397532463, -0.0032232615631073713, 0.011302418075501919, 0.03593474626541138, 0.026435784995555878, -0.008244380354881287, 0.0214734748005867, -0.046195413917303085, -0.030244329944252968, 0.050855282694101334, 0.024509109556674957, 0.031902167946100235, 0.01045109611004591, 0.03880235552787781, 0.0857146754860878, -0.0473155751824379, -0.0853114128112793, -0.013184287585318089, 0.01325149741023779, 0.030983636155724525, 0.012489788234233856, 0.017877759411931038, -0.015659842640161514, 0.03532985970377922, 0.06317704916000366, -0.03490419685840607, -0.029729057103395462, -0.04088585451245308, -0.014058012515306473, 0.04568013921380043, 0.03631560131907463, 0.02650299482047558, 0.002419546479359269, 0.013262699358165264, -0.03268628194928169, -0.013710763305425644, 0.026122139766812325, 0.012669013813138008, -0.03230542689561844, -0.03698769584298134, 0.010305475443601608, -0.016096705570816994, 0.042476482689380646, 0.008093158714473248, -0.00855802558362484, 0.014046811498701572, 0.013621150515973568, 0.03237263485789299, -0.04279012605547905, 0.02057734690606594, 0.026278963312506676, -0.03414249047636986, -0.06895707547664642, -0.04559052735567093, -0.04455998167395592, 0.0002459102252032608, 0.010344681330025196, -0.06810574978590012, 0.011005575768649578, 0.03407527878880501, 0.046240221709012985, 0.045366495847702026, 0.04955589398741722, 0.04003453254699707, -0.05820353329181671, 0.058517180383205414, -0.010456697084009647, -0.024441899731755257, 0.019748426973819733, 0.0106359226629138, 0.017429696395993233, -0.010092644952237606, -0.02757834829390049, 0.02569647878408432, -0.030871620401740074, 0.0861179307103157, 0.00888847280293703, -0.023545771837234497, -0.06819536536931992, -0.051930636167526245, 0.043417416512966156, -0.009174113161861897, -0.028967346996068954, 0.013105876743793488, 0.02037571743130684, -0.03779421001672745, 0.014438867568969727, -0.01941237971186638, 0.04478401318192482, 0.026458188891410828, 0.007583485916256905, -0.03884716331958771, -0.10565353184938431, -0.03134208917617798, -0.019445983693003654, 0.08199574053287506, -0.0478532537817955, -0.005155538208782673, -0.017496906220912933, 0.019233154132962227, 0.0054635824635624886, -0.029841072857379913, -0.017082445323467255, 0.07854564487934113, 0.010053439065814018, 0.019670017063617706, -0.040549807250499725, 0.02961704134941101, -0.03046836331486702, -0.04252128675580025, 0.002202515257522464, 0.05045202374458313, 0.021260643377900124, -0.06886745989322662, 0.0755884200334549, -0.0019840840250253677, -0.03230542689561844, 0.05063125118613243, -0.026077333837747574, 0.02179832197725773, -0.01980443485081196, 0.0032848704140633345, -0.024374689906835556, 0.009000488556921482, 0.04113228991627693, -0.033672019839286804, 0.033828843384981155, 0.03391845524311066, 0.0015794261125847697, 0.08123403042554855, -0.020610950887203217, -0.052737150341272354, 0.0143156498670578, 0.0054635824635624886, -0.0573074072599411, -0.03591234236955643, 0.0119521114975214, -0.005676412954926491, 0.028944944962859154, 0.032910313457250595, 0.06125036999583244, -0.044403158128261566, -0.03819746896624565, -0.0003267717838753015, 0.07527478039264679, 0.007801916915923357, 0.022604836151003838, 0.05040721595287323, -0.05627685785293579, -0.05520150437951088, 0.004007373936474323, 0.009034093469381332, -0.03055797517299652, -0.04550091549754143, 0.046060994267463684, 0.010456697084009647, -0.01987164467573166, -0.010624721646308899, 0.08150286972522736, 0.07110778242349625, 0.0045058452524244785, -0.02583089843392372, 0.010165455751121044, 0.051930636167526245, -0.042812529951334, -0.01753051020205021, 0.0569489561021328, 0.00007189154712250456, 0.015391003340482712, -0.04070662707090378, 0.03414249047636986, -0.012198546901345253, 0.019972460344433784, 0.016623180359601974, -0.03338078036904335, 0.033694423735141754, 0.001564023899845779, 0.006323305424302816, 0.01118480134755373, 0.014382859691977501, -0.03550908342003822, 0.00984060950577259, -0.007835522294044495, -0.00712422002106905, -0.08275745064020157, 0.01727287285029888, -0.006401716731488705, -0.01707124523818493, -0.0033352775499224663, -0.02495717443525791, 0.012187344953417778, 0.012086530216038227, 0.028004009276628494, -0.010042238049209118, -0.0018552656983956695, -0.03212619945406914, -0.02650299482047558, 0.0014394060708582401, 0.0041753980331122875, -0.019311565905809402, 0.03806304931640625, 0.016231123358011246, -0.016410348936915398, 0.040572211146354675, 0.0007617090595886111, -0.08428087085485458, 0.01336351316422224, -0.015391003340482712, -0.009465355426073074, 0.08083077520132065, 0.022111965343356133, 0.0003316724905744195, -0.038421500474214554, -0.0014380059437826276, -0.007370655424892902, -0.05645608529448509, -0.015615035779774189, 0.06322184950113297, -0.019849242642521858, 0.004063381813466549, -0.03232783079147339, 0.003377283690497279, -0.056769728660583496, 0.06989800930023193, -0.057621050626039505, 0.002948822220787406, -0.009694987908005714, 0.003942964598536491, 0.051885828375816345, -0.009661382995545864, 0.06335627287626266, 0.004466639366000891, 0.03629319742321968, 0.009342137724161148, -0.017866557464003563, -0.027197495102882385, -0.017239268869161606, -0.040460191667079926, 0.0060544670559465885, 0.0005275255534797907, -0.04668828472495079, 0.001162866479717195, 0.005169540178030729, 0.0008926278096623719, -0.0021983147598803043, 0.06927071511745453 ]
30,744
networkx.generators.degree_seq
havel_hakimi_graph
Returns a simple graph with given degree sequence constructed using the Havel-Hakimi algorithm. Parameters ---------- deg_sequence: list of integers Each integer corresponds to the degree of a node (need not be sorted). create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Directed graphs are not allowed. Raises ------ NetworkXException For a non-graphical degree sequence (i.e. one not realizable by some simple graph). Notes ----- The Havel-Hakimi algorithm constructs a simple graph by successively connecting the node of highest degree to other nodes of highest degree, resorting remaining nodes by degree, and repeating the process. The resulting graph has a high degree-associativity. Nodes are labeled 1,.., len(deg_sequence), corresponding to their position in deg_sequence. The basic algorithm is from Hakimi [1]_ and was generalized by Kleitman and Wang [2]_. References ---------- .. [1] Hakimi S., On Realizability of a Set of Integers as Degrees of the Vertices of a Linear Graph. I, Journal of SIAM, 10(3), pp. 496-506 (1962) .. [2] Kleitman D.J. and Wang D.L. Algorithms for Constructing Graphs and Digraphs with Given Valences and Factors Discrete Mathematics, 6(1), pp. 79-88 (1973)
def generate(self): # remaining_degree is mapping from int->remaining degree self.remaining_degree = dict(enumerate(self.degree)) # add all nodes to make sure we get isolated nodes self.graph = nx.Graph() self.graph.add_nodes_from(self.remaining_degree) # remove zero degree nodes for n, d in list(self.remaining_degree.items()): if d == 0: del self.remaining_degree[n] if len(self.remaining_degree) > 0: # build graph in three phases according to how many unmatched edges self.phase1() self.phase2() self.phase3() return self.graph
(deg_sequence, create_using=None, *, backend=None, **backend_kwargs)
[ -0.022558806464076042, 0.003677771892398596, -0.030307188630104065, -0.021222256124019623, -0.01597539149224758, 0.04854929819703102, -0.07159576565027237, -0.03922956809401512, 0.03422653302550316, -0.03128251060843468, 0.03236619755625725, 0.08040977269411087, -0.03390142694115639, 0.04034937918186188, -0.01369964424520731, 0.005088826175779104, 0.02394954301416874, 0.0136635210365057, -0.014422103762626648, 0.0017372900620102882, -0.01916324533522129, -0.01542451698333025, -0.006989798508584499, 0.03352213650941849, -0.0339917354285717, -0.0049398187547922134, -0.01680622063577175, 0.013410660438239574, -0.028988700360059738, -0.018106648698449135, -0.05855536833405495, 0.0012981699546799064, -0.027236733585596085, 0.004366366192698479, 0.013428721576929092, 0.04641804099082947, -0.01871170848608017, 0.026803258806467056, -0.051836490631103516, 0.02956666797399521, 0.09702634811401367, -0.029295744374394417, -0.03583400696516037, 0.015559977851808071, -0.024003727361559868, -0.030885156244039536, 0.03973528742790222, 0.03760403394699097, -0.0005898206727579236, -0.07845913618803024, 0.021294502541422844, -0.018061494454741478, 0.00945519283413887, 0.015379362739622593, 0.010755619965493679, 0.015162625350058079, -0.0108278663828969, 0.016896529123187065, 0.08337186276912689, 0.021475117653608322, -0.02089715003967285, -0.012715292163193226, 0.00039904617005959153, -0.0006377965328283608, -0.029404113069176674, 0.020969396457076073, -0.04887440428137779, -0.024419141933321953, 0.009554530493915081, 0.05671309307217598, 0.051005661487579346, -0.012859784066677094, 0.05129464715719223, -0.002062397077679634, 0.05357039347290993, -0.019650906324386597, 0.009536469355225563, -0.027706332504749298, 0.020535919815301895, -0.03001820482313633, -0.03193272277712822, -0.003436199389398098, -0.021059703081846237, -0.001605215365998447, 0.0531369186937809, 0.038543231785297394, 0.00278598559089005, -0.042191650718450546, -0.03807363286614418, -0.05064443126320839, -0.019127123057842255, -0.027254795655608177, -0.004849511198699474, 0.012624984607100487, 0.03825424611568451, -0.017013927921652794, -0.03825424611568451, -0.052017103880643845, 0.03959079831838608, -0.022956160828471184, -0.017320973798632622, 0.025394462049007416, -0.1437695026397705, 0.0341181643307209, 0.022396253421902657, -0.0657077208161354, -0.004129309207201004, -0.044936999678611755, 0.03565338999032974, -0.010231836698949337, -0.04981360211968422, 0.046923764050006866, 0.07199312001466751, 0.04013264179229736, -0.01070143561810255, 0.020734596997499466, -0.0009871736401692033, -0.020788781344890594, 0.025845998898148537, 0.021059703081846237, -0.0336124412715435, 0.02349800430238247, -0.018675586208701134, 0.05703820288181305, 0.003018527291715145, 0.022631052881479263, 0.015559977851808071, -0.030505865812301636, 0.0689949095249176, -0.052414458245038986, 0.05497919023036957, 0.005495209712535143, 0.02599049173295498, -0.007879327051341534, -0.06614119559526443, -0.012733354233205318, -0.016950713470578194, -0.0420471616089344, 0.02248656190931797, 0.051511384546756744, -0.012724323198199272, -0.03959079831838608, 0.009933821856975555, 0.048007454723119736, 0.010231836698949337, 0.044359032064676285, -0.007233628537505865, 0.008985593914985657, -0.015749623998999596, -0.03469613194465637, 0.028627470135688782, -0.010186683386564255, 0.009265546686947346, -0.002749862615019083, -0.006872398778796196, 0.02382311224937439, -0.0021594774443656206, 0.03307059779763222, -0.050933416932821274, -0.002255429280921817, -0.037459541112184525, 0.002772439504042268, 0.008881740272045135, 0.017420312389731407, 0.0017260016174986959, -0.02976534329354763, 0.09659287333488464, -0.056749217212200165, -0.0255570150911808, -0.008448264561593533, -0.03839873895049095, -0.04258900508284569, -0.044611893594264984, -0.025051293894648552, -0.03379305824637413, 0.00718395970761776, 0.02024693600833416, 0.0065698688849806786, -0.004479250870645046, 0.05122239887714386, 0.003838067641481757, -0.03402785584330559, -0.037206679582595825, -0.02983758971095085, 0.039121199399232864, -0.014169243164360523, 0.06285399943590164, 0.0055719711817801, 0.05497919023036957, -0.05064443126320839, -0.03991590440273285, 0.007495520636439323, 0.05270344391465187, 0.08575598150491714, 0.08012079447507858, -0.01737515814602375, 0.028970638290047646, 0.06567159295082092, -0.06765835732221603, 0.051077909767627716, 0.03236619755625725, -0.010502759367227554, 0.02414821833372116, -0.03810975328087807, -0.025087416172027588, 0.020680412650108337, -0.02938605286180973, -0.00929263886064291, 0.011839309707283974, 0.033756934106349945, -0.015162625350058079, -0.002573763020336628, 0.0710178017616272, 0.009789329953491688, -0.05382325500249863, 0.0011548068141564727, 0.02030112035572529, 0.01396153587847948, 0.013744797557592392, -0.04118020832538605, -0.04656253382563591, 0.0033323457464575768, -0.006583414971828461, -0.07694196701049805, -0.012769477441906929, -0.032546814531087875, -0.034136224538087845, -0.0440700463950634, -0.10562362521886826, 0.001038535963743925, 0.06913940608501434, -0.03419040888547897, -0.036050744354724884, -0.012354062870144844, 0.02432883344590664, 0.029873711988329887, -0.017799602821469307, -0.005436509847640991, -0.013401629403233528, 0.03195078298449516, -0.043347589671611786, -0.056749217212200165, 0.009337793104350567, 0.03364856541156769, 0.046923764050006866, 0.0647323951125145, 0.02158348634839058, -0.03632166609168053, 0.007125259842723608, 0.03706218674778938, -0.04836868494749069, -0.05165587738156319, -0.02656845934689045, -0.02210726961493492, 0.006429892033338547, -0.05270344391465187, -0.02216145396232605, -0.03901283070445061, 0.03545471653342247, 0.013293260708451271, 0.021258380264043808, 0.05154750496149063, -0.0866229310631752, 0.02624335139989853, 0.03466000780463219, -0.002652782015502453, -0.003950952086597681, 0.014665934257209301, -0.053245287388563156, -0.00788835808634758, 0.010683374479413033, 0.05277568846940994, 0.016372745856642723, -0.009671930223703384, 0.036177173256874084, -0.018025372177362442, 0.012037986889481544, 0.04847705364227295, -0.0428057424724102, 0.021944716572761536, -0.0460929349064827, 0.011667725630104542, -0.0011841567466035485, -0.0007179444073699415, -0.06577996164560318, 0.048260316252708435, 0.009861576370894909, -0.03832649067044258, 0.02945829927921295, -0.061228469014167786, 0.001301556476391852, 0.008231526240706444, -0.014512411318719387, 0.04009651765227318, 0.09435325115919113, -0.014169243164360523, -0.003824521554633975, -0.00486757280305028, 0.0010588550940155983, 0.0639738142490387, 0.0624566487967968, -0.02089715003967285, 0.001774541917257011, -0.03531022369861603, -0.0029349930118769407, -0.005860954988747835, 0.025827938690781593, 0.0011672241380438209, 0.044684138149023056, 0.011432926170527935, -0.06303461641073227, -0.014078935608267784, 0.09298057854175568, 0.020264998078346252, 0.02115001156926155, -0.0435643270611763, -0.013509998098015785, -0.0440700463950634, 0.06729713082313538, 0.05487082153558731, 0.0017982475692406297, 0.05302854999899864, -0.06444341689348221, 0.014033781364560127, -0.08683966845273972, 0.047429487109184265, 0.037784647196531296, 0.037026066333055496, -0.001774541917257011, -0.04757397621870041, -0.056171249598264694, -0.0014302446506917477, -0.01609279215335846, 0.031210264191031456, -0.07018697261810303, 0.020535919815301895, 0.09102993458509445, -0.04854929819703102, 0.003725183429196477, -0.016011515632271767, 0.09883250296115875, 0.007242659572511911, -0.05082504823803902, 0.029530543833971024, 0.006804668344557285, -0.009143631905317307, 0.030307188630104065, -0.04197491332888603, -0.02216145396232605, 0.010927204042673111, -0.020391426980495453, 0.09160790592432022, -0.006113816052675247, 0.06520199775695801, 0.04732111841440201, 0.04446740075945854, 0.011685787700116634, 0.009717084467411041, -0.0508611686527729, 0.030180757865309715, -0.010773682035505772, 0.01642693020403385, -0.029530543833971024, 0.04804357513785362, -0.011198126710951328, -0.047935206443071365, 0.0420471616089344, 0.0589165985584259, 0.03390142694115639, -0.021890532225370407, 0.001844530226662755, -0.042697373777627945, -0.043347589671611786, 0.02286585234105587, -0.011125881224870682, 0.025918245315551758, 0.007974149659276009, 0.004391200840473175, 0.06780285388231277, -0.03597849979996681, -0.0261891670525074, -0.0049307881854474545, -0.0041541438549757, 0.024816494435071945, 0.01673397421836853, -0.032980289310216904, 0.06653854995965958, 0.006253792438656092, 0.060072533786296844, -0.016011515632271767, 0.0009019459248520434, -0.03590625151991844, 0.025845998898148537, -0.015541916713118553, 0.023136775940656662, 0.030830971896648407, 0.06932001560926437, 0.022703299298882484, -0.04049387201666832, -0.008570179343223572, -0.017926033586263657, -0.0657077208161354, 0.008678548038005829, 0.05555715784430504, -0.007576797157526016, -0.08221592754125595, 0.07802566140890121, 0.03915731981396675, 0.05978354811668396, -0.03731504827737808, -0.02860940806567669, 0.011685787700116634, -0.008755309507250786, 0.0022576868068426847, 0.0341181643307209, -0.05320916324853897, 0.01369964424520731, -0.01891038566827774, 0.060831114649772644, 0.01641789823770523, 0.06003640964627266, 0.0366467721760273, 0.06538261473178864, 0.01034923642873764, 0.012697231024503708, 0.027038058266043663, -0.02115001156926155, 0.013618366792798042, -0.05089729279279709, 0.07242659479379654, -0.010990419425070286, -0.014918794855475426, 0.009861576370894909, -0.05049993842840195, 0.012363092973828316, -0.024112096056342125, 0.016056669875979424, -0.0181337408721447, -0.021294502541422844, 0.005504240747541189, 0.035743698477745056, 0.002835654653608799, 0.024057911708950996, -0.01986764371395111, 0.03666483610868454, -0.011026542633771896, -0.020337242633104324, -0.015280025079846382, -0.02772439457476139, 0.026171106845140457, 0.016688821837306023, 0.007220082450658083, 0.03140893951058388, -0.020680412650108337, -0.03767627850174904, 0.08207143098115921, 0.014413072727620602, -0.040277134627103806, -0.05512368306517601, 0.005228803027421236, 0.055990636348724365, 0.02241431549191475, -0.03531022369861603, 0.06433504819869995, -0.03326927497982979, -0.014449195936322212, -0.0008054297650232911, 0.006863368209451437, -0.04248063638806343, 0.0035377952735871077, 0.004695988725870848, 0.0009860447607934475, -0.01923549175262451, -0.089657261967659, -0.008601786568760872, -0.04146919399499893, -0.02535833977162838, -0.01916324533522129, 0.008186372928321362, -0.054509591311216354, -0.04421453922986984, -0.00782062765210867, 0.0034542609937489033, 0.03455163910984993, -0.038868337869644165, 0.04024101048707962, -0.017546743154525757, -0.026676828041672707, -0.0355089008808136, -0.044539645314216614, -0.060831114649772644, -0.08163795620203018, -0.03261905908584595, 0.013862197287380695, 0.01420536544173956, 0.04425066336989403, -0.009780299849808216, -0.035599205642938614, -0.002233981154859066, -0.02389535866677761, -0.0016458537429571152, 0.0018016340909525752, 0.0069085219874978065, 0.02248656190931797, 0.017230667173862457, 0.006962706334888935, -0.03065035678446293, -0.03760403394699097, 0.010945266112685204, 0.03980753570795059, 0.03485868498682976, 0.007220082450658083, -0.0014460484962910414, 0.04782683774828911, 0.003549083834514022, 0.010051221586763859, 0.007314905524253845, 0.00038070246228016913, -0.024834556505084038, -0.009446161799132824, 0.010891081765294075, 0.027760518714785576, 0.0066737225279212, 0.031842414289712906, -0.005048187915235758, 0.037640154361724854, -0.043781064450740814, -0.07018697261810303, 0.014069904573261738, -0.010854958556592464, 0.039121199399232864, 0.004230905324220657, 0.005436509847640991, 0.09225811809301376, -0.016399838030338287, -0.06328748166561127, 0.0632152333855629, -0.0448286309838295, -0.06585220992565155, -0.05064443126320839, -0.0020827162079513073, 0.007531643379479647, -0.00945519283413887, -0.02017468959093094, 0.0010351494420319796, 0.009373916313052177, 0.08366084843873978, -0.016083762049674988, 0.03502123802900314, -0.03001820482313633, -0.030072389170527458, 0.045840073376894, -0.01763704977929592, -0.0508611686527729, 0.12433533370494843, -0.0136635210365057, -0.02178216353058815, 0.003585206810384989, 0.02873583883047104, 0.019434168934822083, 0.004754688590764999, -0.03865160048007965, -0.0639738142490387, -0.02689356543123722, -0.0038087177090346813, -0.006461499724537134, -0.014096996746957302, -0.006217669695615768, 0.003740987041965127, 0.04779071733355522, 0.008755309507250786, -0.03431684151291847, 0.011098789051175117, -0.019578659906983376, 0.006447953637689352, -0.03977141156792641, -0.009410038590431213, 0.022558806464076042, 0.01795312575995922, -0.02561119943857193, 0.0037432448007166386, 0.00455149682238698, -0.014187304303050041, -0.014449195936322212, 0.004172205459326506, 0.024491386488080025, -0.045948442071676254, 0.02344381995499134, 0.08171020448207855, 0.00202062982134521, -0.003908055834472179, -0.04396167770028114, 0.0020115990191698074, -0.002440559444949031, -0.07434111088514328, 0.046923764050006866, -0.030830971896648407, -0.0051926798187196255, -0.044359032064676285, -0.01672494411468506, -0.0503554493188858, 0.07860362529754639, 0.017898941412568092, 0.09102993458509445, -0.020788781344890594, 0.04262512922286987, -0.016490144655108452, 0.010421482846140862, -0.017357096076011658, -0.017989249899983406, 0.0005020531243644655, -0.004912726581096649, -0.0013026853557676077, -0.04034937918186188, -0.040782853960990906, -0.0433114655315876, -0.01405184343457222, 0.007355543784797192, -0.036809325218200684, -0.003761306405067444, -0.021059703081846237, -0.012959122657775879, -0.06408218294382095, 0.006962706334888935, -0.004646319430321455, 0.022468499839305878, 0.055412665009498596, -0.0072471750900149345, 0.024942925199866295, 0.024130158126354218, 0.009581622667610645, -0.05906108766794205, -0.07506357133388519, -0.019723152741789818, -0.00001359021644020686, -0.015325178392231464, 0.015677377581596375, 0.02739928849041462, 0.025376399978995323, -0.027290919795632362, -0.07528030872344971, 0.04038550332188606, -0.052667319774627686, -0.04750173166394234, -0.05747167766094208, -0.024617817252874374, 0.01510844100266695, 0.03397367149591446, -0.017853787168860435, -0.023353513330221176, -0.018729770556092262, 0.009861576370894909, 0.06234828010201454, -0.02785082533955574, 0.014963948167860508, -0.007635497022420168, 0.015036194585263729, 0.006962706334888935, 0.04013264179229736, -0.04042162746191025, 0.006398284807801247, 0.026658765971660614, 0.08770661801099777, -0.005982870236039162, 0.0181337408721447, 0.040204886347055435, 0.04490087553858757, -0.031463123857975006, -0.042191650718450546, -0.013744797557592392, -0.02790500968694687, -0.04233614355325699, 0.06758611649274826, 0.0130313690751791, -0.05653247982263565, 0.016571421176195145, -0.011875432915985584, 0.00494884978979826, 0.03621329739689827, 0.03046974167227745, 0.01725775934755802, 0.03231201320886612, -0.022450437769293785, -0.07286006957292557, -0.00999703723937273, -0.012462431564927101, -0.042516760528087616, -0.03839873895049095, 0.003910313826054335, -0.00221930630505085, -0.02951248362660408, 0.0022938097827136517, 0.05747167766094208, 0.006122846622020006, 0.009599684737622738, 0.02113194949924946, -0.03169792518019676, -0.01711326651275158, 0.024997109547257423, -0.030162695795297623, 0.03717055544257164, -0.018603339791297913, -0.014458226971328259, 0.030234942212700844, -0.006497622933238745, -0.008687579073011875, 0.011315526440739632, 0.00616348534822464, -0.035364408046007156, 0.017330003902316093, -0.014521442353725433, 0.0023457366041839123, -0.00694464473053813, 0.04815194755792618, -0.011875432915985584, -0.005919654853641987, 0.0033165421336889267, 0.07658074051141739, -0.03027106635272503, -0.024744248017668724, -0.001944997231476009, 0.016499176621437073, -0.013112645596265793, 0.04598456621170044, -0.025538954883813858, 0.044359032064676285, 0.0006406186730600893, -0.04623742774128914, -0.018494971096515656, -0.01986764371395111, -0.026297537609934807, 0.04067448526620865, 0.0037658216897398233, -0.029042884707450867, 0.0037838832940906286, -0.008055427111685276, 0.020138567313551903, 0.058338627219200134, -0.022016962990164757, 0.033124782145023346, -0.01794409565627575, 0.00833086483180523, -0.02543058432638645, 0.03731504827737808, 0.007721289061009884, -0.010385359637439251, 0.03193272277712822, 0.017320973798632622, 0.0033165421336889267, 0.010412451811134815, 0.028826145455241203, -0.003612298984080553, 0.03155343234539032, 0.025466708466410637, -0.04479250684380531, -0.02299228310585022, -0.012769477441906929, -0.025249969214200974, -0.027110304683446884, -0.0861172080039978, -0.032926104962825775, -0.032745491713285446, 0.044539645314216614, 0.011875432915985584, -0.012191508896648884, 0.04034937918186188, 0.06942838430404663, -0.00470953481271863 ]
30,745
networkx.generators.small
heawood_graph
Returns the Heawood Graph, a (3,6) cage. The Heawood Graph is an undirected graph with 14 nodes and 21 edges, named after Percy John Heawood [1]_. It is cubic symmetric, nonplanar, Hamiltonian, and can be represented in LCF notation as ``[5,-5]^7`` [2]_. It is the unique (3,6)-cage: the regular cubic graph of girth 6 with minimal number of vertices [3]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Heawood Graph with 14 nodes and 21 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Heawood_graph .. [2] https://mathworld.wolfram.com/HeawoodGraph.html .. [3] https://www.win.tue.nl/~aeb/graphs/Heawood.html
def sedgewick_maze_graph(create_using=None): """ Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick """ G = empty_graph(0, create_using) G.add_nodes_from(range(8)) G.add_edges_from([[0, 2], [0, 7], [0, 5]]) G.add_edges_from([[1, 7], [2, 6]]) G.add_edges_from([[3, 4], [3, 5]]) G.add_edges_from([[4, 5], [4, 7], [4, 6]]) G.name = "Sedgewick Maze" return G
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.08457178622484207, -0.022319477051496506, -0.0137723283842206, -0.03377334773540497, -0.06194087117910385, 0.023340290412306786, -0.06273676455020905, 0.055020105093717575, -0.0003484714834485203, -0.01570149138569832, -0.006721796002238989, 0.031558699905872345, -0.006855885498225689, 0.07730497419834137, 0.024015065282583237, -0.013383034616708755, 0.04301257058978081, -0.00340631534345448, -0.024516820907592773, 0.05242481827735901, -0.010960766114294529, -0.03996743634343147, 0.040105849504470825, 0.04422370716929436, -0.026990994811058044, 0.027631165459752083, -0.014827745035290718, 0.05425881966948509, -0.008274642750620842, -0.03318508341908455, -0.017284618690609932, -0.044085290282964706, -0.058272864669561386, 0.01856495998799801, 0.030053434893488884, 0.06387868523597717, 0.001934570842422545, 0.048099335283041, -0.08041932433843613, -0.05232100561261177, 0.03778739273548126, -0.005294387228786945, 0.05221719294786453, -0.004671518225222826, 0.04014045372605324, -0.012872627936303616, 0.05107526853680611, 0.020969927310943604, -0.025935577228665352, -0.03187013790011406, 0.026644956320524216, -0.02394585683941841, -0.01641952246427536, 0.035918787121772766, 0.03484606742858887, -0.016843419522047043, -0.022457892075181007, -0.008071345277130604, 0.1026349887251854, -0.04761488363146782, 0.005277085583657026, -0.014213526621460915, 0.027233222499489784, 0.04100554808974266, -0.045746274292469025, -0.013962648808956146, -0.0341193862259388, -0.054881688207387924, -0.0005574462120421231, 0.004684494808316231, 0.04522721841931343, 0.03581497445702553, 0.04512340575456619, -0.010164877399802208, 0.03664546459913254, 0.02963818795979023, -0.014775839634239674, -0.03598799183964729, -0.04436212033033371, -0.04737265780568123, 0.019793396815657616, 0.0170596931129694, -0.02716401405632496, -0.05353213846683502, 0.031108852475881577, 0.03212966397404671, 0.030520586296916008, 0.04297797009348869, -0.011817211285233498, -0.0964755043387413, 0.016185946762561798, -0.01314080785959959, -0.027129409834742546, -0.01160958781838417, -0.00867258757352829, 0.004171925596892834, 0.020416265353560448, -0.06003766134381294, 0.005752888508141041, -0.019412754103541374, -0.041663020849227905, 0.009481452405452728, -0.08477940410375595, 0.012491986155509949, -0.0526670441031456, -0.04280494898557663, -0.024516820907592773, 0.0040313471108675, -0.01718945801258087, -0.040348075330257416, -0.041663020849227905, -0.0021605773363262415, 0.02719861827790737, 0.004455244168639183, 0.03140298277139664, 0.03633403033018112, 0.024170782417058945, 0.01656658761203289, 0.034621141850948334, -0.06564348191022873, -0.019568471238017082, 0.009680423885583878, -0.047441862523555756, -0.03716452419757843, 0.03692229837179184, -0.029603583738207817, 0.03477685898542404, -0.013011043891310692, 0.008538497611880302, -0.012829373590648174, 0.02050277404487133, 0.006189761683344841, -0.039379168301820755, 0.03216426819562912, -0.05180194601416588, 0.00830492191016674, -0.04183604195713997, -0.04387766867876053, 0.025330010801553726, 0.029032621532678604, 0.01134140882641077, -0.02866928093135357, 0.0018275153124704957, 0.028288638219237328, -0.06311739981174469, -0.0024525471962988377, -0.018547657877206802, 0.008516870439052582, 0.06086815521121025, 0.027994506061077118, 0.02842705324292183, -0.009048904292285442, 0.02128136157989502, 0.027094805613160133, -0.02147168293595314, -0.03173172101378441, -0.001255470560863614, 0.05951860547065735, 0.0151132270693779, 0.058861132711172104, 0.011332757771015167, -0.025676049292087555, 0.012855326756834984, 0.011981579475104809, -0.0368184857070446, -0.010407105088233948, 0.008616356179118156, 0.011670145206153393, -0.01221515517681837, 0.013279223814606667, -0.027440844103693962, 0.01064068078994751, -0.057407770305871964, -0.025001274421811104, 0.06401710212230682, -0.000020174309611320496, -0.025624142959713936, -0.00525978347286582, 0.020122133195400238, -0.04398148134350777, -0.019516564905643463, -0.012353571131825447, 0.014455754309892654, -0.00586535083130002, 0.0027142385952174664, 0.003914559260010719, 0.01217190083116293, -0.008499568328261375, 0.032631419599056244, 0.01676556095480919, -0.010536869056522846, 0.005398198962211609, 0.033929064869880676, 0.07197598367929459, 0.04055570065975189, -0.023599818348884583, 0.0303648691624403, 0.02415348030626774, -0.0561620332300663, 0.07536716014146805, -0.014144319109618664, 0.03235458955168724, 0.011748003773391247, -0.02700829692184925, 0.052978478372097015, 0.035001784563064575, 0.004732075147330761, -0.08111140131950378, -0.0188071858137846, 0.03792580962181091, -0.04775329679250717, -0.0159869734197855, 0.05626584216952324, 0.026887184008955956, -0.013417638838291168, -0.0312991738319397, 0.00830492191016674, 0.06121419370174408, 0.03406748175621033, -0.026004785671830177, -0.050694625824689865, 0.00709378719329834, -0.048999037593603134, -0.020018320530653, 0.014222177676856518, -0.0432548001408577, -0.04508880153298378, -0.039136942476034164, -0.015199736692011356, -0.07425983995199203, 0.020710397511720657, -0.028928808867931366, 0.03892932087182999, -0.012595797888934612, 0.013210015371441841, -0.011722050607204437, -0.013305176049470901, -0.018910998478531837, 0.008079996332526207, -0.02084881253540516, -0.05062541738152504, -0.06377487629652023, 0.010026462376117706, -0.03406748175621033, 0.04716503247618675, 0.03799501433968544, -0.007534985896199942, 0.01832273229956627, 0.0030667653772979975, 0.008343851193785667, -0.03287364915013313, -0.014801791869103909, 0.03278713673353195, 0.0000961067562457174, -0.00454175379127264, 0.013884790241718292, -0.05799603462219238, 0.0036182638723403215, -0.01628110557794571, 0.02205994725227356, -0.021488985046744347, -0.027423541992902756, -0.02313266694545746, -0.017327873036265373, 0.04055570065975189, 0.011090530082583427, -0.056231237947940826, 0.07495191693305969, -0.08664801716804504, -0.045642465353012085, 0.037821996957063675, 0.014516310766339302, 0.014749886468052864, 0.006427663378417492, 0.01718945801258087, -0.0034149663988500834, -0.02579716220498085, -0.0038367006927728653, -0.0014328152174130082, -0.03560734912753105, -0.09550659358501434, -0.035434331744909286, 0.012180551886558533, 0.054155007004737854, -0.05097145587205887, -0.0021995066199451685, 0.01612538844347, 0.009507404640316963, 0.04145539924502373, -0.030139943584799767, -0.017466288059949875, -0.04225128889083862, 0.014170272275805473, 0.0006991056725382805, 0.041663020849227905, -0.004550404846668243, 0.02200804278254509, -0.008568775840103626, -0.028773091733455658, 0.04761488363146782, 0.08907028287649155, -0.061248794198036194, 0.0077728875912725925, 0.018530355766415596, 0.023149969056248665, 0.03892932087182999, 0.0018610376864671707, -0.024015065282583237, 0.04989873617887497, -0.035538144409656525, -0.08969315141439438, 0.014966160990297794, -0.004918070510029793, 0.0575115829706192, -0.027388939633965492, -0.04211287200450897, -0.02920564077794552, -0.02998422645032406, 0.05591980367898941, 0.048999037593603134, -0.007790189236402512, 0.018045902252197266, -0.015961021184921265, 0.008460639044642448, -0.06737367808818817, 0.014386545866727829, 0.018236223608255386, 0.04609231278300285, 0.012578495778143406, 0.018011298030614853, -0.02681797556579113, -0.03688769415020943, 0.01593506895005703, 0.01811511069536209, -0.05135209858417511, 0.018789885565638542, 0.013607960194349289, -0.007729632779955864, -0.022371381521224976, -0.04463895410299301, 0.09066206216812134, 0.02385934814810753, -0.0131667610257864, -0.011107832193374634, 0.06169864535331726, 0.016488729044795036, -0.007937255315482616, -0.05038319155573845, -0.012180551886558533, 0.046957410871982574, 0.036507051438093185, 0.07038421183824539, -0.017016438767313957, 0.0068991403095424175, 0.030295660719275475, 0.033877160400152206, 0.01622054912149906, 0.010216783732175827, -0.035244010388851166, 0.02904992364346981, -0.06339423358440399, 0.021852323785424232, 0.0048531885258853436, -0.0016058344626799226, -0.02176581509411335, -0.025676049292087555, -0.017016438767313957, 0.03235458955168724, 0.053705159574747086, -0.0593801885843277, -0.021160248667001724, -0.05931098014116287, -0.02138517238199711, 0.03290824964642525, -0.008196784183382988, 0.06533204764127731, -0.03441351652145386, 0.009784235619008541, 0.06349804252386093, 0.004316829144954681, 0.011955626308918, -0.0017561448039487004, 0.008374129422008991, -0.0029456517659127712, 0.08055774122476578, -0.028496261686086655, 0.04505419731140137, 0.03508829325437546, 0.01738842949271202, -0.05630044639110565, -0.09439927339553833, -0.02429189532995224, 0.0569579191505909, 0.06813496351242065, -0.005510661285370588, 0.02536461502313614, 0.08214951306581497, 0.04650755971670151, -0.03623022139072418, 0.04654216393828392, 0.07758180797100067, -0.04290876165032387, 0.03206045553088188, 0.043843064457178116, -0.028236733749508858, -0.06550506502389908, -0.02711210772395134, 0.010822351090610027, 0.026489239186048508, 0.018616866320371628, 0.04892982915043831, -0.04872220754623413, -0.04858379065990448, 0.018063204362988472, -0.002822375623509288, 0.010822351090610027, 0.015364104881882668, 0.026056692004203796, 0.05841128155589104, 0.0069380695931613445, 0.05138670280575752, -0.012223806232213974, 0.00034171290462836623, 0.03872169554233551, 0.042528118938207626, -0.01690397597849369, -0.024447612464427948, -0.0057139587588608265, -0.05235560983419418, 0.04789171367883682, -0.01003511343151331, -0.060902755707502365, 0.05758078768849373, -0.02141977660357952, -0.017769072204828262, 0.005207877606153488, 0.033254288136959076, -0.018582262098789215, 0.022284872829914093, 0.018616866320371628, 0.03183553367853165, -0.014127016998827457, -0.029568981379270554, -0.030624397099018097, 0.020018320530653, -0.030866624787449837, -0.007249504327774048, -0.0062935734167695045, 0.016393568366765976, 0.009273828938603401, 0.030676303431391716, 0.011644192039966583, -0.036126408725976944, 0.011773956008255482, -0.061629436910152435, 0.008157854899764061, 0.027129409834742546, 0.011574984528124332, -0.033150479197502136, 0.05135209858417511, 0.03837565705180168, -0.014524961821734905, -0.020537378266453743, 0.06661239266395569, -0.03882550820708275, -0.015355453826487064, 0.02171390876173973, 0.005688006058335304, 0.0009910755325108767, -0.06785812973976135, 0.031852833926677704, -0.02963818795979023, -0.05882652848958969, -0.04585008695721626, 0.08886265754699707, -0.04519261419773102, -0.06346344202756882, -0.022388683632016182, 0.03934456408023834, -0.016921278089284897, -0.061525627970695496, -0.009516055695712566, 0.004896443337202072, 0.030814718455076218, -0.010632029734551907, 0.0004055137396790087, 0.05000254884362221, -0.0851946547627449, -0.022077249363064766, -0.04221668466925621, 0.0028504913207143545, -0.03472495451569557, -0.02797720395028591, -0.00000925923086469993, -0.006401710212230682, 0.07806625962257385, -0.03055519051849842, -0.03136838227510452, -0.004442268051207066, -0.07647448778152466, 0.028842300176620483, -0.015718793496489525, -0.03834105283021927, -0.021160248667001724, -0.02321917563676834, 0.043946877121925354, 0.023236477747559547, -0.012448730878531933, 0.018495751544833183, 0.027561958879232407, 0.0561620332300663, -0.009048904292285442, 0.0033089921344071627, 0.07661289721727371, 0.022181060165166855, 0.030053434893488884, -0.007638797629624605, 0.014948858879506588, 0.05498550087213516, -0.059207167476415634, 0.015364104881882668, 0.02418808452785015, 0.02808101661503315, 0.035918787121772766, -0.04398148134350777, 0.059933848679065704, 0.030434077605605125, 0.03375604376196861, 0.04027887061238289, 0.037683580070734024, 0.03159330412745476, 0.07135311514139175, -0.028582772240042686, 0.07938120514154434, 0.03365223482251167, -0.04439672455191612, 0.04737265780568123, 0.014343291521072388, -0.0196203775703907, -0.03851407393813133, 0.005190575961023569, -0.029655490070581436, -0.034032877534627914, -0.022907741367816925, -0.011367361061275005, 0.0017896672943606973, 0.09481451660394669, -0.029032621532678604, -0.0236517246812582, -0.0980672836303711, -0.02186962589621544, 0.03225077688694, -0.005220854189246893, -0.005398198962211609, 0.08637118339538574, -0.049725718796253204, -0.023098062723875046, -0.029499772936105728, 0.0167223047465086, 0.012812071479856968, -0.063947893679142, -0.011202992871403694, 0.014005904085934162, -0.009126762859523296, -0.009048904292285442, 0.022457892075181007, 0.005428477190434933, 0.02235407941043377, -0.024274593219161034, 0.025676049292087555, 0.029811207205057144, 0.043946877121925354, 0.08623276650905609, -0.025381917133927345, -0.02827133610844612, -0.0078118168748915195, 0.0003411722427699715, 0.031454890966415405, 0.04958730190992355, -0.023634422570466995, -0.033929064869880676, -0.01413566805422306, 0.00561014749109745, 0.040348075330257416, -0.01894560270011425, 0.039275359362363815, -0.0365416556596756, 0.008313572034239769, -0.021921532228589058, 0.013210015371441841, 0.05124828591942787, -0.051282890141010284, 0.04128238186240196, -0.0019540356006473303, -0.04256272315979004, -0.0029759302269667387, 0.025468425825238228, 0.019931811839342117, 0.023392194882035255, 0.016203247010707855, -0.05066002160310745, 0.07225281745195389, 0.03536512330174446, 0.0341193862259388, 0.03560734912753105, 0.023392194882035255, 0.018582262098789215, -0.018547657877206802, 0.0014079436659812927, -0.043946877121925354, -0.0100091602653265, 0.007491731084883213, -0.016644446179270744, -0.05391278117895126, -0.05906875431537628, 0.008188133127987385, -0.02327108196914196, 0.008945092558860779, -0.03159330412745476, -0.024447612464427948, 0.009239224717020988, -0.010908860713243484, 0.001664228388108313, -0.03283904492855072, -0.012223806232213974, 0.003934023901820183, 0.021696606650948524, 0.009965905919671059, -0.013383034616708755, 0.04076332226395607, -0.021748512983322144, -0.045400235801935196, -0.011903720907866955, -0.03321968764066696, -0.01996641606092453, -0.03095313347876072, 0.0001635572116356343, 0.00005423746188171208, 0.010874256491661072, 0.058169055730104446, -0.04159381613135338, 0.027215920388698578, 0.02749275043606758, 0.017284618690609932, -0.06761590391397476, -0.01953386701643467, 0.06356725096702576, -0.0008569856872782111, -0.04270113632082939, 0.011410616338253021, -0.008248690515756607, 0.005281411111354828, 0.02321917563676834, 0.017284618690609932, 0.05495089665055275, 0.03664546459913254, -0.03488067165017128, -0.06706224381923676, 0.054155007004737854, -0.04713042825460434, 0.03886011242866516, 0.008858582936227322, 0.009239224717020988, 0.023669026792049408, 0.021973438560962677, 0.045642465353012085, 0.006111903116106987, 0.028167525306344032, 0.03259681537747383, -0.027907997369766235, -0.02574525587260723, -0.04387766867876053, -0.008702865801751614, -0.05214798450469971, -0.06481298804283142, -0.045400235801935196, -0.024949368089437485, 0.022907741367816925, -0.046715185046195984, -0.03716452419757843, 0.03910233825445175, 0.05180194601416588, -0.013036996126174927, -0.0446043498814106, -0.005571218207478523, 0.03629942610859871, -0.0526670441031456, -0.021402474492788315, 0.030451377853751183, 0.007643123157322407, -0.023063458502292633, -0.040348075330257416, 0.02448221668601036, 0.05017556622624397, -0.010597425512969494, 0.00714136753231287, -0.016705002635717392, -0.018253525719046593, 0.002502290066331625, -0.06349804252386093, 0.03266602382063866, 0.04453514143824577, 0.0023790139239281416, 0.021437078714370728, 0.03996743634343147, -0.0435316301882267, -0.039863623678684235, 0.048756808042526245, -0.002757493406534195, 0.006306549534201622, -0.02069309540092945, -0.03152409940958023, 0.041905250400304794, 0.029032621532678604, 0.00041659778798930347, -0.059103358536958694, -0.0036939599085599184, -0.0009683668031357229, -0.022475194185972214, 0.007015928626060486, 0.012197853066027164, 0.0011321944184601307, -0.01865146867930889, 0.02079690806567669, -0.062356118112802505, -0.0014447103021666408, -0.04619612544775009, -0.059691622853279114, 0.0038475145120173693, -0.0561620332300663, -0.04339321330189705, 0.008054043166339397, -0.0049916040152311325, 0.052494022995233536, 0.006989975459873676, 0.003062439849600196, 0.0003533376439008862, 0.05986464396119118, -0.018720677122473717, 0.03716452419757843, -0.03441351652145386, -0.018288129940629005, -0.08145743608474731, 0.0061767855659127235, -0.009766933508217335, 0.012690958566963673, 0.03071090765297413, 0.04522721841931343, -0.046818993985652924, 0.012639052234590054, 0.0596570186316967, -0.055608369410037994, 0.06699303537607193, 0.028115618973970413, -0.02496667020022869, 0.02545112371444702, -0.04020966216921806, -0.04415449872612953, -0.03616101294755936, -0.0709378719329834, -0.018253525719046593, 0.024136178195476532, 0.01448170654475689, -0.022942345589399338, -0.04470815882086754, 0.02235407941043377, 0.022821232676506042, 0.05612742900848389 ]
30,752
networkx.generators.small
hoffman_singleton_graph
Returns the Hoffman-Singleton Graph. The Hoffman–Singleton graph is a symmetrical undirected graph with 50 nodes and 175 edges. All indices lie in ``Z % 5``: that is, the integers mod 5 [1]_. It is the only regular graph of vertex degree 7, diameter 2, and girth 5. It is the unique (7,5)-cage graph and Moore graph, and contains many copies of the Petersen graph [2]_. Returns ------- G : networkx Graph Hoffman–Singleton Graph with 50 nodes and 175 edges Notes ----- Constructed from pentagon and pentagram as follows: Take five pentagons $P_h$ and five pentagrams $Q_i$ . Join vertex $j$ of $P_h$ to vertex $h·i+j$ of $Q_i$ [3]_. References ---------- .. [1] https://blogs.ams.org/visualinsight/2016/02/01/hoffman-singleton-graph/ .. [2] https://mathworld.wolfram.com/Hoffman-SingletonGraph.html .. [3] https://en.wikipedia.org/wiki/Hoffman%E2%80%93Singleton_graph
def sedgewick_maze_graph(create_using=None): """ Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick """ G = empty_graph(0, create_using) G.add_nodes_from(range(8)) G.add_edges_from([[0, 2], [0, 7], [0, 5]]) G.add_edges_from([[1, 7], [2, 6]]) G.add_edges_from([[3, 4], [3, 5]]) G.add_edges_from([[4, 5], [4, 7], [4, 6]]) G.name = "Sedgewick Maze" return G
(*, backend=None, **backend_kwargs)
[ 0.08457178622484207, -0.022319477051496506, -0.0137723283842206, -0.03377334773540497, -0.06194087117910385, 0.023340290412306786, -0.06273676455020905, 0.055020105093717575, -0.0003484714834485203, -0.01570149138569832, -0.006721796002238989, 0.031558699905872345, -0.006855885498225689, 0.07730497419834137, 0.024015065282583237, -0.013383034616708755, 0.04301257058978081, -0.00340631534345448, -0.024516820907592773, 0.05242481827735901, -0.010960766114294529, -0.03996743634343147, 0.040105849504470825, 0.04422370716929436, -0.026990994811058044, 0.027631165459752083, -0.014827745035290718, 0.05425881966948509, -0.008274642750620842, -0.03318508341908455, -0.017284618690609932, -0.044085290282964706, -0.058272864669561386, 0.01856495998799801, 0.030053434893488884, 0.06387868523597717, 0.001934570842422545, 0.048099335283041, -0.08041932433843613, -0.05232100561261177, 0.03778739273548126, -0.005294387228786945, 0.05221719294786453, -0.004671518225222826, 0.04014045372605324, -0.012872627936303616, 0.05107526853680611, 0.020969927310943604, -0.025935577228665352, -0.03187013790011406, 0.026644956320524216, -0.02394585683941841, -0.01641952246427536, 0.035918787121772766, 0.03484606742858887, -0.016843419522047043, -0.022457892075181007, -0.008071345277130604, 0.1026349887251854, -0.04761488363146782, 0.005277085583657026, -0.014213526621460915, 0.027233222499489784, 0.04100554808974266, -0.045746274292469025, -0.013962648808956146, -0.0341193862259388, -0.054881688207387924, -0.0005574462120421231, 0.004684494808316231, 0.04522721841931343, 0.03581497445702553, 0.04512340575456619, -0.010164877399802208, 0.03664546459913254, 0.02963818795979023, -0.014775839634239674, -0.03598799183964729, -0.04436212033033371, -0.04737265780568123, 0.019793396815657616, 0.0170596931129694, -0.02716401405632496, -0.05353213846683502, 0.031108852475881577, 0.03212966397404671, 0.030520586296916008, 0.04297797009348869, -0.011817211285233498, -0.0964755043387413, 0.016185946762561798, -0.01314080785959959, -0.027129409834742546, -0.01160958781838417, -0.00867258757352829, 0.004171925596892834, 0.020416265353560448, -0.06003766134381294, 0.005752888508141041, -0.019412754103541374, -0.041663020849227905, 0.009481452405452728, -0.08477940410375595, 0.012491986155509949, -0.0526670441031456, -0.04280494898557663, -0.024516820907592773, 0.0040313471108675, -0.01718945801258087, -0.040348075330257416, -0.041663020849227905, -0.0021605773363262415, 0.02719861827790737, 0.004455244168639183, 0.03140298277139664, 0.03633403033018112, 0.024170782417058945, 0.01656658761203289, 0.034621141850948334, -0.06564348191022873, -0.019568471238017082, 0.009680423885583878, -0.047441862523555756, -0.03716452419757843, 0.03692229837179184, -0.029603583738207817, 0.03477685898542404, -0.013011043891310692, 0.008538497611880302, -0.012829373590648174, 0.02050277404487133, 0.006189761683344841, -0.039379168301820755, 0.03216426819562912, -0.05180194601416588, 0.00830492191016674, -0.04183604195713997, -0.04387766867876053, 0.025330010801553726, 0.029032621532678604, 0.01134140882641077, -0.02866928093135357, 0.0018275153124704957, 0.028288638219237328, -0.06311739981174469, -0.0024525471962988377, -0.018547657877206802, 0.008516870439052582, 0.06086815521121025, 0.027994506061077118, 0.02842705324292183, -0.009048904292285442, 0.02128136157989502, 0.027094805613160133, -0.02147168293595314, -0.03173172101378441, -0.001255470560863614, 0.05951860547065735, 0.0151132270693779, 0.058861132711172104, 0.011332757771015167, -0.025676049292087555, 0.012855326756834984, 0.011981579475104809, -0.0368184857070446, -0.010407105088233948, 0.008616356179118156, 0.011670145206153393, -0.01221515517681837, 0.013279223814606667, -0.027440844103693962, 0.01064068078994751, -0.057407770305871964, -0.025001274421811104, 0.06401710212230682, -0.000020174309611320496, -0.025624142959713936, -0.00525978347286582, 0.020122133195400238, -0.04398148134350777, -0.019516564905643463, -0.012353571131825447, 0.014455754309892654, -0.00586535083130002, 0.0027142385952174664, 0.003914559260010719, 0.01217190083116293, -0.008499568328261375, 0.032631419599056244, 0.01676556095480919, -0.010536869056522846, 0.005398198962211609, 0.033929064869880676, 0.07197598367929459, 0.04055570065975189, -0.023599818348884583, 0.0303648691624403, 0.02415348030626774, -0.0561620332300663, 0.07536716014146805, -0.014144319109618664, 0.03235458955168724, 0.011748003773391247, -0.02700829692184925, 0.052978478372097015, 0.035001784563064575, 0.004732075147330761, -0.08111140131950378, -0.0188071858137846, 0.03792580962181091, -0.04775329679250717, -0.0159869734197855, 0.05626584216952324, 0.026887184008955956, -0.013417638838291168, -0.0312991738319397, 0.00830492191016674, 0.06121419370174408, 0.03406748175621033, -0.026004785671830177, -0.050694625824689865, 0.00709378719329834, -0.048999037593603134, -0.020018320530653, 0.014222177676856518, -0.0432548001408577, -0.04508880153298378, -0.039136942476034164, -0.015199736692011356, -0.07425983995199203, 0.020710397511720657, -0.028928808867931366, 0.03892932087182999, -0.012595797888934612, 0.013210015371441841, -0.011722050607204437, -0.013305176049470901, -0.018910998478531837, 0.008079996332526207, -0.02084881253540516, -0.05062541738152504, -0.06377487629652023, 0.010026462376117706, -0.03406748175621033, 0.04716503247618675, 0.03799501433968544, -0.007534985896199942, 0.01832273229956627, 0.0030667653772979975, 0.008343851193785667, -0.03287364915013313, -0.014801791869103909, 0.03278713673353195, 0.0000961067562457174, -0.00454175379127264, 0.013884790241718292, -0.05799603462219238, 0.0036182638723403215, -0.01628110557794571, 0.02205994725227356, -0.021488985046744347, -0.027423541992902756, -0.02313266694545746, -0.017327873036265373, 0.04055570065975189, 0.011090530082583427, -0.056231237947940826, 0.07495191693305969, -0.08664801716804504, -0.045642465353012085, 0.037821996957063675, 0.014516310766339302, 0.014749886468052864, 0.006427663378417492, 0.01718945801258087, -0.0034149663988500834, -0.02579716220498085, -0.0038367006927728653, -0.0014328152174130082, -0.03560734912753105, -0.09550659358501434, -0.035434331744909286, 0.012180551886558533, 0.054155007004737854, -0.05097145587205887, -0.0021995066199451685, 0.01612538844347, 0.009507404640316963, 0.04145539924502373, -0.030139943584799767, -0.017466288059949875, -0.04225128889083862, 0.014170272275805473, 0.0006991056725382805, 0.041663020849227905, -0.004550404846668243, 0.02200804278254509, -0.008568775840103626, -0.028773091733455658, 0.04761488363146782, 0.08907028287649155, -0.061248794198036194, 0.0077728875912725925, 0.018530355766415596, 0.023149969056248665, 0.03892932087182999, 0.0018610376864671707, -0.024015065282583237, 0.04989873617887497, -0.035538144409656525, -0.08969315141439438, 0.014966160990297794, -0.004918070510029793, 0.0575115829706192, -0.027388939633965492, -0.04211287200450897, -0.02920564077794552, -0.02998422645032406, 0.05591980367898941, 0.048999037593603134, -0.007790189236402512, 0.018045902252197266, -0.015961021184921265, 0.008460639044642448, -0.06737367808818817, 0.014386545866727829, 0.018236223608255386, 0.04609231278300285, 0.012578495778143406, 0.018011298030614853, -0.02681797556579113, -0.03688769415020943, 0.01593506895005703, 0.01811511069536209, -0.05135209858417511, 0.018789885565638542, 0.013607960194349289, -0.007729632779955864, -0.022371381521224976, -0.04463895410299301, 0.09066206216812134, 0.02385934814810753, -0.0131667610257864, -0.011107832193374634, 0.06169864535331726, 0.016488729044795036, -0.007937255315482616, -0.05038319155573845, -0.012180551886558533, 0.046957410871982574, 0.036507051438093185, 0.07038421183824539, -0.017016438767313957, 0.0068991403095424175, 0.030295660719275475, 0.033877160400152206, 0.01622054912149906, 0.010216783732175827, -0.035244010388851166, 0.02904992364346981, -0.06339423358440399, 0.021852323785424232, 0.0048531885258853436, -0.0016058344626799226, -0.02176581509411335, -0.025676049292087555, -0.017016438767313957, 0.03235458955168724, 0.053705159574747086, -0.0593801885843277, -0.021160248667001724, -0.05931098014116287, -0.02138517238199711, 0.03290824964642525, -0.008196784183382988, 0.06533204764127731, -0.03441351652145386, 0.009784235619008541, 0.06349804252386093, 0.004316829144954681, 0.011955626308918, -0.0017561448039487004, 0.008374129422008991, -0.0029456517659127712, 0.08055774122476578, -0.028496261686086655, 0.04505419731140137, 0.03508829325437546, 0.01738842949271202, -0.05630044639110565, -0.09439927339553833, -0.02429189532995224, 0.0569579191505909, 0.06813496351242065, -0.005510661285370588, 0.02536461502313614, 0.08214951306581497, 0.04650755971670151, -0.03623022139072418, 0.04654216393828392, 0.07758180797100067, -0.04290876165032387, 0.03206045553088188, 0.043843064457178116, -0.028236733749508858, -0.06550506502389908, -0.02711210772395134, 0.010822351090610027, 0.026489239186048508, 0.018616866320371628, 0.04892982915043831, -0.04872220754623413, -0.04858379065990448, 0.018063204362988472, -0.002822375623509288, 0.010822351090610027, 0.015364104881882668, 0.026056692004203796, 0.05841128155589104, 0.0069380695931613445, 0.05138670280575752, -0.012223806232213974, 0.00034171290462836623, 0.03872169554233551, 0.042528118938207626, -0.01690397597849369, -0.024447612464427948, -0.0057139587588608265, -0.05235560983419418, 0.04789171367883682, -0.01003511343151331, -0.060902755707502365, 0.05758078768849373, -0.02141977660357952, -0.017769072204828262, 0.005207877606153488, 0.033254288136959076, -0.018582262098789215, 0.022284872829914093, 0.018616866320371628, 0.03183553367853165, -0.014127016998827457, -0.029568981379270554, -0.030624397099018097, 0.020018320530653, -0.030866624787449837, -0.007249504327774048, -0.0062935734167695045, 0.016393568366765976, 0.009273828938603401, 0.030676303431391716, 0.011644192039966583, -0.036126408725976944, 0.011773956008255482, -0.061629436910152435, 0.008157854899764061, 0.027129409834742546, 0.011574984528124332, -0.033150479197502136, 0.05135209858417511, 0.03837565705180168, -0.014524961821734905, -0.020537378266453743, 0.06661239266395569, -0.03882550820708275, -0.015355453826487064, 0.02171390876173973, 0.005688006058335304, 0.0009910755325108767, -0.06785812973976135, 0.031852833926677704, -0.02963818795979023, -0.05882652848958969, -0.04585008695721626, 0.08886265754699707, -0.04519261419773102, -0.06346344202756882, -0.022388683632016182, 0.03934456408023834, -0.016921278089284897, -0.061525627970695496, -0.009516055695712566, 0.004896443337202072, 0.030814718455076218, -0.010632029734551907, 0.0004055137396790087, 0.05000254884362221, -0.0851946547627449, -0.022077249363064766, -0.04221668466925621, 0.0028504913207143545, -0.03472495451569557, -0.02797720395028591, -0.00000925923086469993, -0.006401710212230682, 0.07806625962257385, -0.03055519051849842, -0.03136838227510452, -0.004442268051207066, -0.07647448778152466, 0.028842300176620483, -0.015718793496489525, -0.03834105283021927, -0.021160248667001724, -0.02321917563676834, 0.043946877121925354, 0.023236477747559547, -0.012448730878531933, 0.018495751544833183, 0.027561958879232407, 0.0561620332300663, -0.009048904292285442, 0.0033089921344071627, 0.07661289721727371, 0.022181060165166855, 0.030053434893488884, -0.007638797629624605, 0.014948858879506588, 0.05498550087213516, -0.059207167476415634, 0.015364104881882668, 0.02418808452785015, 0.02808101661503315, 0.035918787121772766, -0.04398148134350777, 0.059933848679065704, 0.030434077605605125, 0.03375604376196861, 0.04027887061238289, 0.037683580070734024, 0.03159330412745476, 0.07135311514139175, -0.028582772240042686, 0.07938120514154434, 0.03365223482251167, -0.04439672455191612, 0.04737265780568123, 0.014343291521072388, -0.0196203775703907, -0.03851407393813133, 0.005190575961023569, -0.029655490070581436, -0.034032877534627914, -0.022907741367816925, -0.011367361061275005, 0.0017896672943606973, 0.09481451660394669, -0.029032621532678604, -0.0236517246812582, -0.0980672836303711, -0.02186962589621544, 0.03225077688694, -0.005220854189246893, -0.005398198962211609, 0.08637118339538574, -0.049725718796253204, -0.023098062723875046, -0.029499772936105728, 0.0167223047465086, 0.012812071479856968, -0.063947893679142, -0.011202992871403694, 0.014005904085934162, -0.009126762859523296, -0.009048904292285442, 0.022457892075181007, 0.005428477190434933, 0.02235407941043377, -0.024274593219161034, 0.025676049292087555, 0.029811207205057144, 0.043946877121925354, 0.08623276650905609, -0.025381917133927345, -0.02827133610844612, -0.0078118168748915195, 0.0003411722427699715, 0.031454890966415405, 0.04958730190992355, -0.023634422570466995, -0.033929064869880676, -0.01413566805422306, 0.00561014749109745, 0.040348075330257416, -0.01894560270011425, 0.039275359362363815, -0.0365416556596756, 0.008313572034239769, -0.021921532228589058, 0.013210015371441841, 0.05124828591942787, -0.051282890141010284, 0.04128238186240196, -0.0019540356006473303, -0.04256272315979004, -0.0029759302269667387, 0.025468425825238228, 0.019931811839342117, 0.023392194882035255, 0.016203247010707855, -0.05066002160310745, 0.07225281745195389, 0.03536512330174446, 0.0341193862259388, 0.03560734912753105, 0.023392194882035255, 0.018582262098789215, -0.018547657877206802, 0.0014079436659812927, -0.043946877121925354, -0.0100091602653265, 0.007491731084883213, -0.016644446179270744, -0.05391278117895126, -0.05906875431537628, 0.008188133127987385, -0.02327108196914196, 0.008945092558860779, -0.03159330412745476, -0.024447612464427948, 0.009239224717020988, -0.010908860713243484, 0.001664228388108313, -0.03283904492855072, -0.012223806232213974, 0.003934023901820183, 0.021696606650948524, 0.009965905919671059, -0.013383034616708755, 0.04076332226395607, -0.021748512983322144, -0.045400235801935196, -0.011903720907866955, -0.03321968764066696, -0.01996641606092453, -0.03095313347876072, 0.0001635572116356343, 0.00005423746188171208, 0.010874256491661072, 0.058169055730104446, -0.04159381613135338, 0.027215920388698578, 0.02749275043606758, 0.017284618690609932, -0.06761590391397476, -0.01953386701643467, 0.06356725096702576, -0.0008569856872782111, -0.04270113632082939, 0.011410616338253021, -0.008248690515756607, 0.005281411111354828, 0.02321917563676834, 0.017284618690609932, 0.05495089665055275, 0.03664546459913254, -0.03488067165017128, -0.06706224381923676, 0.054155007004737854, -0.04713042825460434, 0.03886011242866516, 0.008858582936227322, 0.009239224717020988, 0.023669026792049408, 0.021973438560962677, 0.045642465353012085, 0.006111903116106987, 0.028167525306344032, 0.03259681537747383, -0.027907997369766235, -0.02574525587260723, -0.04387766867876053, -0.008702865801751614, -0.05214798450469971, -0.06481298804283142, -0.045400235801935196, -0.024949368089437485, 0.022907741367816925, -0.046715185046195984, -0.03716452419757843, 0.03910233825445175, 0.05180194601416588, -0.013036996126174927, -0.0446043498814106, -0.005571218207478523, 0.03629942610859871, -0.0526670441031456, -0.021402474492788315, 0.030451377853751183, 0.007643123157322407, -0.023063458502292633, -0.040348075330257416, 0.02448221668601036, 0.05017556622624397, -0.010597425512969494, 0.00714136753231287, -0.016705002635717392, -0.018253525719046593, 0.002502290066331625, -0.06349804252386093, 0.03266602382063866, 0.04453514143824577, 0.0023790139239281416, 0.021437078714370728, 0.03996743634343147, -0.0435316301882267, -0.039863623678684235, 0.048756808042526245, -0.002757493406534195, 0.006306549534201622, -0.02069309540092945, -0.03152409940958023, 0.041905250400304794, 0.029032621532678604, 0.00041659778798930347, -0.059103358536958694, -0.0036939599085599184, -0.0009683668031357229, -0.022475194185972214, 0.007015928626060486, 0.012197853066027164, 0.0011321944184601307, -0.01865146867930889, 0.02079690806567669, -0.062356118112802505, -0.0014447103021666408, -0.04619612544775009, -0.059691622853279114, 0.0038475145120173693, -0.0561620332300663, -0.04339321330189705, 0.008054043166339397, -0.0049916040152311325, 0.052494022995233536, 0.006989975459873676, 0.003062439849600196, 0.0003533376439008862, 0.05986464396119118, -0.018720677122473717, 0.03716452419757843, -0.03441351652145386, -0.018288129940629005, -0.08145743608474731, 0.0061767855659127235, -0.009766933508217335, 0.012690958566963673, 0.03071090765297413, 0.04522721841931343, -0.046818993985652924, 0.012639052234590054, 0.0596570186316967, -0.055608369410037994, 0.06699303537607193, 0.028115618973970413, -0.02496667020022869, 0.02545112371444702, -0.04020966216921806, -0.04415449872612953, -0.03616101294755936, -0.0709378719329834, -0.018253525719046593, 0.024136178195476532, 0.01448170654475689, -0.022942345589399338, -0.04470815882086754, 0.02235407941043377, 0.022821232676506042, 0.05612742900848389 ]
30,753
networkx.generators.small
house_graph
Returns the House graph (square with triangle on top) The house graph is a simple undirected graph with 5 nodes and 6 edges [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph House graph in the form of a square with a triangle on top References ---------- .. [1] https://mathworld.wolfram.com/HouseGraph.html
def _raise_on_directed(func): """ A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. """ @wraps(func) def wrapper(*args, **kwargs): if kwargs.get("create_using") is not None: G = nx.empty_graph(create_using=kwargs["create_using"]) if G.is_directed(): raise NetworkXError("Directed Graph not supported") return func(*args, **kwargs) return wrapper
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.02052009478211403, -0.0038575809448957443, 0.036478180438280106, 0.005170276388525963, 0.00016338811838068068, 0.03903648257255554, -0.06011117249727249, -0.01791706494987011, 0.08021979033946991, -0.03696121647953987, 0.019178327172994614, 0.010814644396305084, 0.04418886825442314, -0.02679956518113613, 0.011020381934940815, 0.04515494033694267, -0.048804547637701035, 0.09403105080127716, 0.02340042032301426, 0.04737332835793495, -0.009213468991219997, -0.0318446084856987, -0.0025985559914261103, -0.019929716363549232, 0.0007553031318821013, 0.04354482144117355, -0.025261005386710167, 0.0009990575490519404, 0.0061900196596980095, 0.023686664178967476, -0.03436713293194771, -0.04680084064602852, 0.0008659989689476788, 0.06558558344841003, 0.046335697174072266, 0.0627589300274849, -0.04669350013136864, 0.08093540370464325, -0.10204587131738663, -0.07342150807380676, -0.031218452379107475, 0.007688326295465231, 0.03205929324030876, 0.011396076530218124, -0.0013283495791256428, -0.020001277327537537, 0.00983068160712719, 0.00007330801599891856, -0.08937959372997284, -0.04211360216140747, 0.022327007725834846, 0.0055862246081233025, 0.05513769015669823, 0.06147083267569542, 0.012317423708736897, 0.04036036133766174, -0.009696505032479763, 0.028982173651456833, 0.03946584835648537, -0.016262220218777657, 0.004969011526554823, 0.051022935658693314, 0.012451600283384323, -0.02416970022022724, -0.03297169506549835, 0.0007687208126299083, -0.0782160833477974, -0.026656443253159523, -0.021951312199234962, 0.05460098385810852, 0.011637594550848007, -0.005832215305417776, 0.017201457172632217, 0.009490767493844032, 0.07224074751138687, -0.030717525631189346, 0.019893936812877655, -0.01023321133106947, 0.04837518185377121, -0.023597214370965958, -0.03599514439702034, -0.018766852095723152, -0.022416459396481514, 0.007053223438560963, 0.062007538974285126, -0.021861860528588295, -0.051237620413303375, 0.026423869654536247, 0.030145037919282913, -0.044367771595716476, -0.005693565588444471, -0.035368986427783966, -0.017407193779945374, 0.005206056870520115, -0.03220241516828537, 0.05964602902531624, 0.029590440914034843, -0.05266883969306946, 0.06401124596595764, -0.011789661832153797, 0.00182033097371459, 0.008247395977377892, -0.019088875502347946, 0.03345473110675812, -0.01619960367679596, -0.09732285141944885, 0.009839626960456371, -0.028033990412950516, -0.019589802250266075, -0.02334675006568432, -0.08279598504304886, -0.018256980925798416, 0.050021082162857056, 0.0009481821907684207, 0.01736246794462204, -0.0011528016766533256, -0.010072199627757072, -0.018587948754429817, 0.0018002043943852186, -0.03640661761164665, -0.021718740463256836, 0.02901795320212841, -0.05656890943646431, -0.05109449848532677, 0.05646156519651413, -0.02390134707093239, -0.0005350296851247549, -0.016593188047409058, 0.042328283190727234, 0.015197750180959702, 0.018587948754429817, 0.0473017692565918, -0.029858794063329697, 0.03710433840751648, 0.0044054691679775715, 0.036478180438280106, -0.053956933319568634, 0.052704617381095886, -0.014151171781122684, 0.00281771132722497, -0.002945179119706154, -0.018927862867712975, 0.027944540604948997, 0.04261452704668045, 0.013900709338486195, 0.041684236377477646, -0.05560283735394478, -0.02275637350976467, 0.024294933304190636, -0.02846335619688034, 0.05925244092941284, 0.005693565588444471, 0.008998786099255085, 0.016870487481355667, -0.043151237070560455, 0.03436713293194771, -0.03315059840679169, 0.025511467829346657, 0.021343044936656952, 0.014347964897751808, -0.03150469437241554, -0.022810043767094612, 0.04236406460404396, 0.023293079808354378, 0.015636060386896133, -0.022219665348529816, 0.010000638663768768, -0.020001277327537537, 0.007943262346088886, -0.004262347240000963, -0.045369625091552734, -0.02234489843249321, -0.0057651265524327755, -0.03928694501519203, -0.028803270310163498, 0.030270269140601158, 0.03746214136481285, 0.04261452704668045, -0.033490512520074844, 0.01608331687748432, 0.054422080516815186, -0.04408152773976326, -0.01951824128627777, -0.02826656401157379, 0.041326433420181274, 0.01865950971841812, 0.009911187924444675, -0.02527889609336853, 0.00324260420165956, 0.00035025717807002366, 0.017568206414580345, 0.017398249357938766, 0.03252444043755531, 0.04980640113353729, 0.03799884766340256, -0.09267139434814453, -0.009374480694532394, -0.0014714713906869292, -0.01695099286735058, 0.07463803887367249, 0.05274039879441261, 0.032130852341651917, 0.03604881465435028, 0.014061721041798592, -0.0048303622752428055, 0.0473017692565918, -0.025099992752075195, -0.05184588581323624, -0.05216791108250618, -0.010340552777051926, -0.03885757923126221, -0.034295570105314255, 0.03497540205717087, 0.05155964195728302, -0.03443869203329086, 0.023167848587036133, 0.021504057571291924, 0.05402849614620209, -0.010322663001716137, -0.027211040258407593, -0.01205801498144865, -0.01827486976981163, -0.00807296670973301, -0.02046642266213894, 0.06268736720085144, -0.041326433420181274, 0.008180308155715466, -0.05252571776509285, 0.025654589757323265, -0.0178365595638752, 0.04104018956422806, -0.01583285443484783, 0.016789980232715607, 0.02279215306043625, 0.03896491974592209, -0.04773113504052162, 0.019679253920912743, -0.04508338123559952, 0.010260047391057014, 0.013596574775874615, -0.06182863563299179, -0.001155038014985621, 0.00443006819114089, -0.0005481678526848555, 0.08279598504304886, 0.029590440914034843, -0.009660724550485611, 0.04884032905101776, 0.0059171938337385654, -0.04161267727613449, -0.04211360216140747, -0.011494472622871399, -0.0037748385220766068, -0.023597214370965958, 0.008372628130018711, -0.02876749075949192, -0.05996805056929588, -0.058858856558799744, 0.039251163601875305, 0.006954826880246401, -0.036317165940999985, 0.05825059115886688, -0.05671203136444092, 0.020359082147479057, 0.004615679383277893, -0.03345473110675812, -0.025296784937381744, 0.022183885797858238, -0.03408088907599449, 0.025064213201403618, -0.02234489843249321, 0.04093284532427788, 0.07385087013244629, -0.024133920669555664, 0.00657018693163991, 0.020090728998184204, -0.020037058740854263, 0.01165548525750637, -0.013364002108573914, 0.034957509487867355, -0.04619257524609566, -0.016620023176074028, -0.052096351981163025, 0.03644239902496338, -0.0749242827296257, 0.03179093822836876, 0.009794901125133038, 0.012782569974660873, 0.011494472622871399, -0.011923838406801224, 0.030502842739224434, 0.01205801498144865, 0.03472493588924408, 0.03204140067100525, -0.04773113504052162, 0.0033186376094818115, 0.02694268710911274, -0.042077820748090744, 0.033848315477371216, 0.03230975568294525, 0.029250526800751686, -0.03760526329278946, -0.00848444178700447, 0.018283816054463387, 0.008690179325640202, 0.0038419270422309637, 0.034653376787900925, -0.027980320155620575, 0.004700657911598682, -0.015287201851606369, -0.06551402062177658, 0.03517219424247742, -0.01551977451890707, 0.019178327172994614, 0.03572678938508034, 0.024652738124132156, -0.01182544231414795, -0.0379272885620594, 0.03377675637602806, 0.06944987177848816, -0.03572678938508034, 0.10562392324209213, -0.06744616478681564, 0.0013551849406212568, -0.08301066607236862, 0.0482320599257946, 0.06107724457979202, 0.03857133537530899, 0.05646156519651413, 0.08995208144187927, 0.0020909206941723824, -0.028427576646208763, -0.007598875090479851, -0.018239090219140053, -0.08723276108503342, 0.027819307520985603, 0.06930675357580185, -0.04884032905101776, 0.05535237118601799, -0.017603985965251923, 0.008649926632642746, 0.0038150916807353497, -0.00886013638228178, 0.0017923774430528283, -0.006682001054286957, 0.032631780952215195, 0.008998786099255085, -0.023668775334954262, 0.023597214370965958, 0.04494025930762291, -0.010143760591745377, 0.11027538031339645, -0.02128937467932701, 0.009902242571115494, 0.04064660146832466, 0.014661043882369995, -0.024688517674803734, 0.03368730470538139, -0.027264710515737534, -0.005223947111517191, -0.03654973953962326, -0.04100440815091133, 0.05746341869235039, 0.013954379595816135, 0.061792854219675064, -0.012111686170101166, 0.0321129634976387, 0.01312248408794403, 0.04576320946216583, -0.05342022702097893, -0.03272123262286186, -0.06984345614910126, -0.0356731191277504, -0.00004801011164090596, 0.018239090219140053, 0.009875407442450523, -0.012290588580071926, -0.014285349287092686, 0.037283241748809814, 0.06898472458124161, -0.03651396185159683, 0.01167337503284216, 0.04583476856350899, -0.005062934942543507, 0.05714139714837074, -0.04282921180129051, 0.053706470876932144, 0.0844418853521347, -0.017460864037275314, -0.037390582263469696, -0.00903903879225254, -0.040324579924345016, 0.02921474538743496, 0.03175516054034233, -0.033240046352148056, -0.03345473110675812, 0.014661043882369995, 0.00010356766142649576, -0.027622515335679054, 0.003723404137417674, -0.03390198573470116, -0.008050603792071342, -0.016602134332060814, 0.028642259538173676, 0.02710369974374771, 0.02204076386988163, -0.008471024222671986, 0.01586863398551941, 0.039251163601875305, -0.0073886653408408165, 0.04186313971877098, -0.013310330919921398, -0.04111174866557121, 0.007683854084461927, 0.04973484203219414, 0.029894575476646423, 0.008998786099255085, 0.03656763210892677, 0.024026580154895782, -0.034760717302560806, 0.07177560031414032, -0.041075967252254486, 0.07699955254793167, 0.038893360644578934, 0.042435627430677414, -0.039608970284461975, -0.031415242701768875, 0.007402082905173302, -0.04615679383277893, 0.029339978471398354, 0.018570059910416603, -0.04962749779224396, 0.030896427109837532, -0.05223947390913963, 0.025690371170639992, -0.013256660662591457, -0.015376652590930462, 0.014437415637075901, 0.0032716759014874697, 0.057964347302913666, 0.02209443412721157, -0.007795667741447687, -0.004906395450234413, -0.017228292301297188, -0.019804485142230988, -0.03635294735431671, 0.020913679152727127, 0.023167848587036133, 0.0012388984905555844, -0.022309117019176483, 0.06873426586389542, -0.00034438693546690047, 0.08129320293664932, 0.023364640772342682, -0.140330970287323, -0.010823589749634266, -0.009159797802567482, -0.030162928625941277, -0.024581177160143852, 0.05571017786860466, 0.011807551607489586, -0.0083905179053545, -0.10404957830905914, -0.02416970022022724, -0.032077182084321976, 0.04039613902568817, -0.010000638663768768, 0.014598428271710873, -0.0241160299628973, 0.0016570825828239322, 0.06841224431991577, -0.041576895862817764, -0.005474410485476255, -0.028499137610197067, 0.005286563187837601, -0.013462398201227188, -0.015770237892866135, -0.0025605391710996628, 0.035404764115810394, 0.013641300611197948, 0.002107692649587989, -0.017487701028585434, 0.026101846247911453, 0.011226119473576546, -0.02932208776473999, 0.004861670080572367, -0.01509040966629982, -0.013838092796504498, 0.0028512554708868265, 0.06512043625116348, -0.05059356987476349, -0.040109895169734955, 0.017183566465973854, -0.06537090241909027, 0.03585202246904373, 0.028695929795503616, -0.0438668429851532, -0.01890997402369976, -0.01655740849673748, -0.07642706483602524, 0.015886524692177773, -0.023221518844366074, -0.04039613902568817, -0.004785636439919472, 0.041219089180231094, -0.03164781630039215, -0.01728196255862713, 0.014097501523792744, 0.006820650305598974, -0.015627115964889526, 0.006780397146940231, 0.06444060802459717, 0.04919813200831413, 0.08129320293664932, 0.025958724319934845, 0.011109832674264908, -0.02780141867697239, -0.018283816054463387, 0.016351670026779175, -0.0396447516977787, 0.052346814423799515, 0.034206122159957886, 0.0005364273674786091, -0.010421059094369411, -0.004018593113869429, 0.01352501381188631, 0.04261452704668045, -0.0027282601222395897, 0.03198773041367531, 0.017621876671910286, 0.010662577114999294, 0.04458245262503624, 0.016789980232715607, 0.052203692495822906, -0.01170021016150713, -0.005156858824193478, -0.005921666044741869, 0.04894766956567764, -0.08358315378427505, -0.015859689563512802, 0.011342406272888184, -0.012120630592107773, -0.04322279617190361, -0.028695929795503616, 0.018391156569123268, -0.02683534473180771, 0.017541371285915375, 0.00886013638228178, 0.003882179968059063, -0.049412816762924194, -0.036478180438280106, 0.004262347240000963, -0.0004743706376757473, -0.005098715424537659, 0.06648009270429611, 0.008784103207290173, -0.015385597944259644, 0.061792854219675064, 0.018695291131734848, 0.014687879011034966, -0.06125614792108536, 0.0028288925532251596, -0.0038240368012338877, -0.03939428552985191, 0.03975209221243858, -0.01772027276456356, 0.04755223169922829, -0.021718740463256836, -0.02350776270031929, -0.009186632931232452, -0.04554852470755577, -0.04919813200831413, 0.010081144981086254, -0.025815602391958237, -0.0200191680341959, 0.024688517674803734, -0.0030279215425252914, -0.03433135151863098, 0.012988307513296604, -0.06533512473106384, -0.05159542337059975, -0.02018018066883087, -0.0309858787804842, 0.01860583946108818, 0.0134445084258914, -0.024491725489497185, 0.0009761356632225215, -0.01147658284753561, -0.027032138779759407, -0.026048175990581512, -0.05463676154613495, -0.06254424154758453, 0.02184397168457508, -0.05563861504197121, 0.013533959165215492, 0.011843332089483738, 0.0008995431708171964, -0.01672736555337906, 0.049913741648197174, -0.022416459396481514, -0.07066641002893448, 0.06336719542741776, 0.018695291131734848, 0.023740336298942566, 0.05145230144262314, -0.002459906740114093, -0.029089514166116714, -0.06143505126237869, -0.016986774280667305, -0.07363618910312653, -0.06859114021062851, 0.05023576691746712, -0.017899176105856895, -0.01605648174881935, 0.008412880823016167, -0.04393840581178665, -0.05349178984761238, 0.03266756236553192, 0.00557280657812953, 0.021772410720586777, 0.03155836462974548, -0.0417557992041111, -0.05019998550415039, -0.02112836204469204, -0.020108619704842567, 0.05778544396162033, 0.009839626960456371, -0.04028879851102829, -0.007795667741447687, 0.045727428048849106, -0.018892083317041397, -0.010975656099617481, 0.02375822514295578, 0.002826656447723508, -0.03209507465362549, -0.06730304658412933, 0.03408088907599449, 0.02577982097864151, 0.024294933304190636, -0.004081208724528551, -0.07199028879404068, 0.004611206706613302, -0.038249313831329346, -0.012997251935303211, -0.008649926632642746, -0.031361572444438934, 0.02891061268746853, -0.0348859503865242, 0.04758801311254501, -0.02309628762304783, 0.013793367892503738, 0.048053160309791565, -0.0006490799132734537, -0.0516669861972332, 0.05538815259933472, 0.04791003838181496, -0.03229186683893204, -0.021164141595363617, 0.004369688685983419, -0.02187975123524666, 0.02386556752026081, -0.0027282601222395897, 0.03799884766340256, 0.003510957583785057, 0.0004592757613863796, 0.03835665434598923, -0.016047537326812744, -0.05316976457834244, -0.025135774165391922, -0.05177432671189308, -0.04161267727613449, -0.018641620874404907, 0.011154558509588242, -0.01000958401709795, -0.01786339469254017, -0.03195195272564888, 0.021146252751350403, 0.011154558509588242, -0.038499776273965836, -0.02284582331776619, -0.03588780015707016, 0.03053862228989601, -0.052847739309072495, -0.017621876671910286, -0.03281068056821823, -0.034098777920007706, -0.01807807758450508, -0.0322381965816021, 0.02699635736644268, -0.015439269132912159, -0.006932464428246021, -0.015788128599524498, 0.03603092208504677, 0.019536131992936134, -0.023489871993660927, -0.06640853732824326, -0.06819755584001541, 0.014634208753705025, -0.0031330266501754522, -0.01150341797620058, 0.04873298853635788, 0.017264071851968765, 0.00815347209572792, 0.03481438755989075, 0.030950099229812622, -0.0713462382555008, -0.05238259583711624, 0.018981534987688065, 0.003922433126717806, 0.016405340284109116, -0.03365152329206467, -0.023686664178967476, 0.03746214136481285, 0.001698453794233501, -0.010304772295057774, -0.052346814423799515, 0.01185227744281292, 0.014419525861740112, -0.03261388838291168, -0.030395500361919403, -0.015197750180959702, -0.013399782590568066, -0.017487701028585434, 0.0013540667714551091, -0.004651459865272045, -0.03547632694244385, -0.010304772295057774, -0.02826656401157379, 0.036370839923620224, -0.017183566465973854, 0.023668775334954262, 0.037641044706106186, 0.001227717031724751, 0.06333141773939133, -0.024760078638792038, 0.03640661761164665, -0.01061785127967596, 0.07442335784435272, -0.028141332790255547, 0.0322381965816021, -0.006364449393004179, 0.007554149720817804, -0.06454794853925705, -0.012281643226742744, 0.05692671239376068, -0.026549100875854492, 0.01840904727578163, 0.08937959372997284, -0.0004710162174887955, -0.024098141118884087, 0.04490447789430618, -0.008202670142054558, 0.025815602391958237, 0.03291802480816841, 0.02422337234020233, -0.03599514439702034, 0.04075394570827484, -0.013149319216609001, 0.011199284344911575, -0.06841224431991577, -0.015501884743571281, 0.004000702872872353, 0.034653376787900925, -0.024742187932133675, -0.04665772244334221, 0.019643472507596016, 0.04422464966773987, 0.05696249380707741 ]
30,754
networkx.generators.small
house_x_graph
Returns the House graph with a cross inside the house square. The House X-graph is the House graph plus the two edges connecting diagonally opposite vertices of the square base. It is also one of the two graphs obtained by removing two edges from the pentatope graph [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph House graph with diagonal vertices connected References ---------- .. [1] https://mathworld.wolfram.com/HouseGraph.html
def _raise_on_directed(func): """ A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. """ @wraps(func) def wrapper(*args, **kwargs): if kwargs.get("create_using") is not None: G = nx.empty_graph(create_using=kwargs["create_using"]) if G.is_directed(): raise NetworkXError("Directed Graph not supported") return func(*args, **kwargs) return wrapper
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.02052009478211403, -0.0038575809448957443, 0.036478180438280106, 0.005170276388525963, 0.00016338811838068068, 0.03903648257255554, -0.06011117249727249, -0.01791706494987011, 0.08021979033946991, -0.03696121647953987, 0.019178327172994614, 0.010814644396305084, 0.04418886825442314, -0.02679956518113613, 0.011020381934940815, 0.04515494033694267, -0.048804547637701035, 0.09403105080127716, 0.02340042032301426, 0.04737332835793495, -0.009213468991219997, -0.0318446084856987, -0.0025985559914261103, -0.019929716363549232, 0.0007553031318821013, 0.04354482144117355, -0.025261005386710167, 0.0009990575490519404, 0.0061900196596980095, 0.023686664178967476, -0.03436713293194771, -0.04680084064602852, 0.0008659989689476788, 0.06558558344841003, 0.046335697174072266, 0.0627589300274849, -0.04669350013136864, 0.08093540370464325, -0.10204587131738663, -0.07342150807380676, -0.031218452379107475, 0.007688326295465231, 0.03205929324030876, 0.011396076530218124, -0.0013283495791256428, -0.020001277327537537, 0.00983068160712719, 0.00007330801599891856, -0.08937959372997284, -0.04211360216140747, 0.022327007725834846, 0.0055862246081233025, 0.05513769015669823, 0.06147083267569542, 0.012317423708736897, 0.04036036133766174, -0.009696505032479763, 0.028982173651456833, 0.03946584835648537, -0.016262220218777657, 0.004969011526554823, 0.051022935658693314, 0.012451600283384323, -0.02416970022022724, -0.03297169506549835, 0.0007687208126299083, -0.0782160833477974, -0.026656443253159523, -0.021951312199234962, 0.05460098385810852, 0.011637594550848007, -0.005832215305417776, 0.017201457172632217, 0.009490767493844032, 0.07224074751138687, -0.030717525631189346, 0.019893936812877655, -0.01023321133106947, 0.04837518185377121, -0.023597214370965958, -0.03599514439702034, -0.018766852095723152, -0.022416459396481514, 0.007053223438560963, 0.062007538974285126, -0.021861860528588295, -0.051237620413303375, 0.026423869654536247, 0.030145037919282913, -0.044367771595716476, -0.005693565588444471, -0.035368986427783966, -0.017407193779945374, 0.005206056870520115, -0.03220241516828537, 0.05964602902531624, 0.029590440914034843, -0.05266883969306946, 0.06401124596595764, -0.011789661832153797, 0.00182033097371459, 0.008247395977377892, -0.019088875502347946, 0.03345473110675812, -0.01619960367679596, -0.09732285141944885, 0.009839626960456371, -0.028033990412950516, -0.019589802250266075, -0.02334675006568432, -0.08279598504304886, -0.018256980925798416, 0.050021082162857056, 0.0009481821907684207, 0.01736246794462204, -0.0011528016766533256, -0.010072199627757072, -0.018587948754429817, 0.0018002043943852186, -0.03640661761164665, -0.021718740463256836, 0.02901795320212841, -0.05656890943646431, -0.05109449848532677, 0.05646156519651413, -0.02390134707093239, -0.0005350296851247549, -0.016593188047409058, 0.042328283190727234, 0.015197750180959702, 0.018587948754429817, 0.0473017692565918, -0.029858794063329697, 0.03710433840751648, 0.0044054691679775715, 0.036478180438280106, -0.053956933319568634, 0.052704617381095886, -0.014151171781122684, 0.00281771132722497, -0.002945179119706154, -0.018927862867712975, 0.027944540604948997, 0.04261452704668045, 0.013900709338486195, 0.041684236377477646, -0.05560283735394478, -0.02275637350976467, 0.024294933304190636, -0.02846335619688034, 0.05925244092941284, 0.005693565588444471, 0.008998786099255085, 0.016870487481355667, -0.043151237070560455, 0.03436713293194771, -0.03315059840679169, 0.025511467829346657, 0.021343044936656952, 0.014347964897751808, -0.03150469437241554, -0.022810043767094612, 0.04236406460404396, 0.023293079808354378, 0.015636060386896133, -0.022219665348529816, 0.010000638663768768, -0.020001277327537537, 0.007943262346088886, -0.004262347240000963, -0.045369625091552734, -0.02234489843249321, -0.0057651265524327755, -0.03928694501519203, -0.028803270310163498, 0.030270269140601158, 0.03746214136481285, 0.04261452704668045, -0.033490512520074844, 0.01608331687748432, 0.054422080516815186, -0.04408152773976326, -0.01951824128627777, -0.02826656401157379, 0.041326433420181274, 0.01865950971841812, 0.009911187924444675, -0.02527889609336853, 0.00324260420165956, 0.00035025717807002366, 0.017568206414580345, 0.017398249357938766, 0.03252444043755531, 0.04980640113353729, 0.03799884766340256, -0.09267139434814453, -0.009374480694532394, -0.0014714713906869292, -0.01695099286735058, 0.07463803887367249, 0.05274039879441261, 0.032130852341651917, 0.03604881465435028, 0.014061721041798592, -0.0048303622752428055, 0.0473017692565918, -0.025099992752075195, -0.05184588581323624, -0.05216791108250618, -0.010340552777051926, -0.03885757923126221, -0.034295570105314255, 0.03497540205717087, 0.05155964195728302, -0.03443869203329086, 0.023167848587036133, 0.021504057571291924, 0.05402849614620209, -0.010322663001716137, -0.027211040258407593, -0.01205801498144865, -0.01827486976981163, -0.00807296670973301, -0.02046642266213894, 0.06268736720085144, -0.041326433420181274, 0.008180308155715466, -0.05252571776509285, 0.025654589757323265, -0.0178365595638752, 0.04104018956422806, -0.01583285443484783, 0.016789980232715607, 0.02279215306043625, 0.03896491974592209, -0.04773113504052162, 0.019679253920912743, -0.04508338123559952, 0.010260047391057014, 0.013596574775874615, -0.06182863563299179, -0.001155038014985621, 0.00443006819114089, -0.0005481678526848555, 0.08279598504304886, 0.029590440914034843, -0.009660724550485611, 0.04884032905101776, 0.0059171938337385654, -0.04161267727613449, -0.04211360216140747, -0.011494472622871399, -0.0037748385220766068, -0.023597214370965958, 0.008372628130018711, -0.02876749075949192, -0.05996805056929588, -0.058858856558799744, 0.039251163601875305, 0.006954826880246401, -0.036317165940999985, 0.05825059115886688, -0.05671203136444092, 0.020359082147479057, 0.004615679383277893, -0.03345473110675812, -0.025296784937381744, 0.022183885797858238, -0.03408088907599449, 0.025064213201403618, -0.02234489843249321, 0.04093284532427788, 0.07385087013244629, -0.024133920669555664, 0.00657018693163991, 0.020090728998184204, -0.020037058740854263, 0.01165548525750637, -0.013364002108573914, 0.034957509487867355, -0.04619257524609566, -0.016620023176074028, -0.052096351981163025, 0.03644239902496338, -0.0749242827296257, 0.03179093822836876, 0.009794901125133038, 0.012782569974660873, 0.011494472622871399, -0.011923838406801224, 0.030502842739224434, 0.01205801498144865, 0.03472493588924408, 0.03204140067100525, -0.04773113504052162, 0.0033186376094818115, 0.02694268710911274, -0.042077820748090744, 0.033848315477371216, 0.03230975568294525, 0.029250526800751686, -0.03760526329278946, -0.00848444178700447, 0.018283816054463387, 0.008690179325640202, 0.0038419270422309637, 0.034653376787900925, -0.027980320155620575, 0.004700657911598682, -0.015287201851606369, -0.06551402062177658, 0.03517219424247742, -0.01551977451890707, 0.019178327172994614, 0.03572678938508034, 0.024652738124132156, -0.01182544231414795, -0.0379272885620594, 0.03377675637602806, 0.06944987177848816, -0.03572678938508034, 0.10562392324209213, -0.06744616478681564, 0.0013551849406212568, -0.08301066607236862, 0.0482320599257946, 0.06107724457979202, 0.03857133537530899, 0.05646156519651413, 0.08995208144187927, 0.0020909206941723824, -0.028427576646208763, -0.007598875090479851, -0.018239090219140053, -0.08723276108503342, 0.027819307520985603, 0.06930675357580185, -0.04884032905101776, 0.05535237118601799, -0.017603985965251923, 0.008649926632642746, 0.0038150916807353497, -0.00886013638228178, 0.0017923774430528283, -0.006682001054286957, 0.032631780952215195, 0.008998786099255085, -0.023668775334954262, 0.023597214370965958, 0.04494025930762291, -0.010143760591745377, 0.11027538031339645, -0.02128937467932701, 0.009902242571115494, 0.04064660146832466, 0.014661043882369995, -0.024688517674803734, 0.03368730470538139, -0.027264710515737534, -0.005223947111517191, -0.03654973953962326, -0.04100440815091133, 0.05746341869235039, 0.013954379595816135, 0.061792854219675064, -0.012111686170101166, 0.0321129634976387, 0.01312248408794403, 0.04576320946216583, -0.05342022702097893, -0.03272123262286186, -0.06984345614910126, -0.0356731191277504, -0.00004801011164090596, 0.018239090219140053, 0.009875407442450523, -0.012290588580071926, -0.014285349287092686, 0.037283241748809814, 0.06898472458124161, -0.03651396185159683, 0.01167337503284216, 0.04583476856350899, -0.005062934942543507, 0.05714139714837074, -0.04282921180129051, 0.053706470876932144, 0.0844418853521347, -0.017460864037275314, -0.037390582263469696, -0.00903903879225254, -0.040324579924345016, 0.02921474538743496, 0.03175516054034233, -0.033240046352148056, -0.03345473110675812, 0.014661043882369995, 0.00010356766142649576, -0.027622515335679054, 0.003723404137417674, -0.03390198573470116, -0.008050603792071342, -0.016602134332060814, 0.028642259538173676, 0.02710369974374771, 0.02204076386988163, -0.008471024222671986, 0.01586863398551941, 0.039251163601875305, -0.0073886653408408165, 0.04186313971877098, -0.013310330919921398, -0.04111174866557121, 0.007683854084461927, 0.04973484203219414, 0.029894575476646423, 0.008998786099255085, 0.03656763210892677, 0.024026580154895782, -0.034760717302560806, 0.07177560031414032, -0.041075967252254486, 0.07699955254793167, 0.038893360644578934, 0.042435627430677414, -0.039608970284461975, -0.031415242701768875, 0.007402082905173302, -0.04615679383277893, 0.029339978471398354, 0.018570059910416603, -0.04962749779224396, 0.030896427109837532, -0.05223947390913963, 0.025690371170639992, -0.013256660662591457, -0.015376652590930462, 0.014437415637075901, 0.0032716759014874697, 0.057964347302913666, 0.02209443412721157, -0.007795667741447687, -0.004906395450234413, -0.017228292301297188, -0.019804485142230988, -0.03635294735431671, 0.020913679152727127, 0.023167848587036133, 0.0012388984905555844, -0.022309117019176483, 0.06873426586389542, -0.00034438693546690047, 0.08129320293664932, 0.023364640772342682, -0.140330970287323, -0.010823589749634266, -0.009159797802567482, -0.030162928625941277, -0.024581177160143852, 0.05571017786860466, 0.011807551607489586, -0.0083905179053545, -0.10404957830905914, -0.02416970022022724, -0.032077182084321976, 0.04039613902568817, -0.010000638663768768, 0.014598428271710873, -0.0241160299628973, 0.0016570825828239322, 0.06841224431991577, -0.041576895862817764, -0.005474410485476255, -0.028499137610197067, 0.005286563187837601, -0.013462398201227188, -0.015770237892866135, -0.0025605391710996628, 0.035404764115810394, 0.013641300611197948, 0.002107692649587989, -0.017487701028585434, 0.026101846247911453, 0.011226119473576546, -0.02932208776473999, 0.004861670080572367, -0.01509040966629982, -0.013838092796504498, 0.0028512554708868265, 0.06512043625116348, -0.05059356987476349, -0.040109895169734955, 0.017183566465973854, -0.06537090241909027, 0.03585202246904373, 0.028695929795503616, -0.0438668429851532, -0.01890997402369976, -0.01655740849673748, -0.07642706483602524, 0.015886524692177773, -0.023221518844366074, -0.04039613902568817, -0.004785636439919472, 0.041219089180231094, -0.03164781630039215, -0.01728196255862713, 0.014097501523792744, 0.006820650305598974, -0.015627115964889526, 0.006780397146940231, 0.06444060802459717, 0.04919813200831413, 0.08129320293664932, 0.025958724319934845, 0.011109832674264908, -0.02780141867697239, -0.018283816054463387, 0.016351670026779175, -0.0396447516977787, 0.052346814423799515, 0.034206122159957886, 0.0005364273674786091, -0.010421059094369411, -0.004018593113869429, 0.01352501381188631, 0.04261452704668045, -0.0027282601222395897, 0.03198773041367531, 0.017621876671910286, 0.010662577114999294, 0.04458245262503624, 0.016789980232715607, 0.052203692495822906, -0.01170021016150713, -0.005156858824193478, -0.005921666044741869, 0.04894766956567764, -0.08358315378427505, -0.015859689563512802, 0.011342406272888184, -0.012120630592107773, -0.04322279617190361, -0.028695929795503616, 0.018391156569123268, -0.02683534473180771, 0.017541371285915375, 0.00886013638228178, 0.003882179968059063, -0.049412816762924194, -0.036478180438280106, 0.004262347240000963, -0.0004743706376757473, -0.005098715424537659, 0.06648009270429611, 0.008784103207290173, -0.015385597944259644, 0.061792854219675064, 0.018695291131734848, 0.014687879011034966, -0.06125614792108536, 0.0028288925532251596, -0.0038240368012338877, -0.03939428552985191, 0.03975209221243858, -0.01772027276456356, 0.04755223169922829, -0.021718740463256836, -0.02350776270031929, -0.009186632931232452, -0.04554852470755577, -0.04919813200831413, 0.010081144981086254, -0.025815602391958237, -0.0200191680341959, 0.024688517674803734, -0.0030279215425252914, -0.03433135151863098, 0.012988307513296604, -0.06533512473106384, -0.05159542337059975, -0.02018018066883087, -0.0309858787804842, 0.01860583946108818, 0.0134445084258914, -0.024491725489497185, 0.0009761356632225215, -0.01147658284753561, -0.027032138779759407, -0.026048175990581512, -0.05463676154613495, -0.06254424154758453, 0.02184397168457508, -0.05563861504197121, 0.013533959165215492, 0.011843332089483738, 0.0008995431708171964, -0.01672736555337906, 0.049913741648197174, -0.022416459396481514, -0.07066641002893448, 0.06336719542741776, 0.018695291131734848, 0.023740336298942566, 0.05145230144262314, -0.002459906740114093, -0.029089514166116714, -0.06143505126237869, -0.016986774280667305, -0.07363618910312653, -0.06859114021062851, 0.05023576691746712, -0.017899176105856895, -0.01605648174881935, 0.008412880823016167, -0.04393840581178665, -0.05349178984761238, 0.03266756236553192, 0.00557280657812953, 0.021772410720586777, 0.03155836462974548, -0.0417557992041111, -0.05019998550415039, -0.02112836204469204, -0.020108619704842567, 0.05778544396162033, 0.009839626960456371, -0.04028879851102829, -0.007795667741447687, 0.045727428048849106, -0.018892083317041397, -0.010975656099617481, 0.02375822514295578, 0.002826656447723508, -0.03209507465362549, -0.06730304658412933, 0.03408088907599449, 0.02577982097864151, 0.024294933304190636, -0.004081208724528551, -0.07199028879404068, 0.004611206706613302, -0.038249313831329346, -0.012997251935303211, -0.008649926632642746, -0.031361572444438934, 0.02891061268746853, -0.0348859503865242, 0.04758801311254501, -0.02309628762304783, 0.013793367892503738, 0.048053160309791565, -0.0006490799132734537, -0.0516669861972332, 0.05538815259933472, 0.04791003838181496, -0.03229186683893204, -0.021164141595363617, 0.004369688685983419, -0.02187975123524666, 0.02386556752026081, -0.0027282601222395897, 0.03799884766340256, 0.003510957583785057, 0.0004592757613863796, 0.03835665434598923, -0.016047537326812744, -0.05316976457834244, -0.025135774165391922, -0.05177432671189308, -0.04161267727613449, -0.018641620874404907, 0.011154558509588242, -0.01000958401709795, -0.01786339469254017, -0.03195195272564888, 0.021146252751350403, 0.011154558509588242, -0.038499776273965836, -0.02284582331776619, -0.03588780015707016, 0.03053862228989601, -0.052847739309072495, -0.017621876671910286, -0.03281068056821823, -0.034098777920007706, -0.01807807758450508, -0.0322381965816021, 0.02699635736644268, -0.015439269132912159, -0.006932464428246021, -0.015788128599524498, 0.03603092208504677, 0.019536131992936134, -0.023489871993660927, -0.06640853732824326, -0.06819755584001541, 0.014634208753705025, -0.0031330266501754522, -0.01150341797620058, 0.04873298853635788, 0.017264071851968765, 0.00815347209572792, 0.03481438755989075, 0.030950099229812622, -0.0713462382555008, -0.05238259583711624, 0.018981534987688065, 0.003922433126717806, 0.016405340284109116, -0.03365152329206467, -0.023686664178967476, 0.03746214136481285, 0.001698453794233501, -0.010304772295057774, -0.052346814423799515, 0.01185227744281292, 0.014419525861740112, -0.03261388838291168, -0.030395500361919403, -0.015197750180959702, -0.013399782590568066, -0.017487701028585434, 0.0013540667714551091, -0.004651459865272045, -0.03547632694244385, -0.010304772295057774, -0.02826656401157379, 0.036370839923620224, -0.017183566465973854, 0.023668775334954262, 0.037641044706106186, 0.001227717031724751, 0.06333141773939133, -0.024760078638792038, 0.03640661761164665, -0.01061785127967596, 0.07442335784435272, -0.028141332790255547, 0.0322381965816021, -0.006364449393004179, 0.007554149720817804, -0.06454794853925705, -0.012281643226742744, 0.05692671239376068, -0.026549100875854492, 0.01840904727578163, 0.08937959372997284, -0.0004710162174887955, -0.024098141118884087, 0.04490447789430618, -0.008202670142054558, 0.025815602391958237, 0.03291802480816841, 0.02422337234020233, -0.03599514439702034, 0.04075394570827484, -0.013149319216609001, 0.011199284344911575, -0.06841224431991577, -0.015501884743571281, 0.004000702872872353, 0.034653376787900925, -0.024742187932133675, -0.04665772244334221, 0.019643472507596016, 0.04422464966773987, 0.05696249380707741 ]
30,757
networkx.generators.small
icosahedral_graph
Returns the Platonic Icosahedral graph. The icosahedral graph has 12 nodes and 30 edges. It is a Platonic graph whose nodes have the connectivity of the icosahedron. It is undirected, regular and Hamiltonian [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Icosahedral graph with 12 nodes and 30 edges. References ---------- .. [1] https://mathworld.wolfram.com/IcosahedralGraph.html
def _raise_on_directed(func): """ A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. """ @wraps(func) def wrapper(*args, **kwargs): if kwargs.get("create_using") is not None: G = nx.empty_graph(create_using=kwargs["create_using"]) if G.is_directed(): raise NetworkXError("Directed Graph not supported") return func(*args, **kwargs) return wrapper
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.02052009478211403, -0.0038575809448957443, 0.036478180438280106, 0.005170276388525963, 0.00016338811838068068, 0.03903648257255554, -0.06011117249727249, -0.01791706494987011, 0.08021979033946991, -0.03696121647953987, 0.019178327172994614, 0.010814644396305084, 0.04418886825442314, -0.02679956518113613, 0.011020381934940815, 0.04515494033694267, -0.048804547637701035, 0.09403105080127716, 0.02340042032301426, 0.04737332835793495, -0.009213468991219997, -0.0318446084856987, -0.0025985559914261103, -0.019929716363549232, 0.0007553031318821013, 0.04354482144117355, -0.025261005386710167, 0.0009990575490519404, 0.0061900196596980095, 0.023686664178967476, -0.03436713293194771, -0.04680084064602852, 0.0008659989689476788, 0.06558558344841003, 0.046335697174072266, 0.0627589300274849, -0.04669350013136864, 0.08093540370464325, -0.10204587131738663, -0.07342150807380676, -0.031218452379107475, 0.007688326295465231, 0.03205929324030876, 0.011396076530218124, -0.0013283495791256428, -0.020001277327537537, 0.00983068160712719, 0.00007330801599891856, -0.08937959372997284, -0.04211360216140747, 0.022327007725834846, 0.0055862246081233025, 0.05513769015669823, 0.06147083267569542, 0.012317423708736897, 0.04036036133766174, -0.009696505032479763, 0.028982173651456833, 0.03946584835648537, -0.016262220218777657, 0.004969011526554823, 0.051022935658693314, 0.012451600283384323, -0.02416970022022724, -0.03297169506549835, 0.0007687208126299083, -0.0782160833477974, -0.026656443253159523, -0.021951312199234962, 0.05460098385810852, 0.011637594550848007, -0.005832215305417776, 0.017201457172632217, 0.009490767493844032, 0.07224074751138687, -0.030717525631189346, 0.019893936812877655, -0.01023321133106947, 0.04837518185377121, -0.023597214370965958, -0.03599514439702034, -0.018766852095723152, -0.022416459396481514, 0.007053223438560963, 0.062007538974285126, -0.021861860528588295, -0.051237620413303375, 0.026423869654536247, 0.030145037919282913, -0.044367771595716476, -0.005693565588444471, -0.035368986427783966, -0.017407193779945374, 0.005206056870520115, -0.03220241516828537, 0.05964602902531624, 0.029590440914034843, -0.05266883969306946, 0.06401124596595764, -0.011789661832153797, 0.00182033097371459, 0.008247395977377892, -0.019088875502347946, 0.03345473110675812, -0.01619960367679596, -0.09732285141944885, 0.009839626960456371, -0.028033990412950516, -0.019589802250266075, -0.02334675006568432, -0.08279598504304886, -0.018256980925798416, 0.050021082162857056, 0.0009481821907684207, 0.01736246794462204, -0.0011528016766533256, -0.010072199627757072, -0.018587948754429817, 0.0018002043943852186, -0.03640661761164665, -0.021718740463256836, 0.02901795320212841, -0.05656890943646431, -0.05109449848532677, 0.05646156519651413, -0.02390134707093239, -0.0005350296851247549, -0.016593188047409058, 0.042328283190727234, 0.015197750180959702, 0.018587948754429817, 0.0473017692565918, -0.029858794063329697, 0.03710433840751648, 0.0044054691679775715, 0.036478180438280106, -0.053956933319568634, 0.052704617381095886, -0.014151171781122684, 0.00281771132722497, -0.002945179119706154, -0.018927862867712975, 0.027944540604948997, 0.04261452704668045, 0.013900709338486195, 0.041684236377477646, -0.05560283735394478, -0.02275637350976467, 0.024294933304190636, -0.02846335619688034, 0.05925244092941284, 0.005693565588444471, 0.008998786099255085, 0.016870487481355667, -0.043151237070560455, 0.03436713293194771, -0.03315059840679169, 0.025511467829346657, 0.021343044936656952, 0.014347964897751808, -0.03150469437241554, -0.022810043767094612, 0.04236406460404396, 0.023293079808354378, 0.015636060386896133, -0.022219665348529816, 0.010000638663768768, -0.020001277327537537, 0.007943262346088886, -0.004262347240000963, -0.045369625091552734, -0.02234489843249321, -0.0057651265524327755, -0.03928694501519203, -0.028803270310163498, 0.030270269140601158, 0.03746214136481285, 0.04261452704668045, -0.033490512520074844, 0.01608331687748432, 0.054422080516815186, -0.04408152773976326, -0.01951824128627777, -0.02826656401157379, 0.041326433420181274, 0.01865950971841812, 0.009911187924444675, -0.02527889609336853, 0.00324260420165956, 0.00035025717807002366, 0.017568206414580345, 0.017398249357938766, 0.03252444043755531, 0.04980640113353729, 0.03799884766340256, -0.09267139434814453, -0.009374480694532394, -0.0014714713906869292, -0.01695099286735058, 0.07463803887367249, 0.05274039879441261, 0.032130852341651917, 0.03604881465435028, 0.014061721041798592, -0.0048303622752428055, 0.0473017692565918, -0.025099992752075195, -0.05184588581323624, -0.05216791108250618, -0.010340552777051926, -0.03885757923126221, -0.034295570105314255, 0.03497540205717087, 0.05155964195728302, -0.03443869203329086, 0.023167848587036133, 0.021504057571291924, 0.05402849614620209, -0.010322663001716137, -0.027211040258407593, -0.01205801498144865, -0.01827486976981163, -0.00807296670973301, -0.02046642266213894, 0.06268736720085144, -0.041326433420181274, 0.008180308155715466, -0.05252571776509285, 0.025654589757323265, -0.0178365595638752, 0.04104018956422806, -0.01583285443484783, 0.016789980232715607, 0.02279215306043625, 0.03896491974592209, -0.04773113504052162, 0.019679253920912743, -0.04508338123559952, 0.010260047391057014, 0.013596574775874615, -0.06182863563299179, -0.001155038014985621, 0.00443006819114089, -0.0005481678526848555, 0.08279598504304886, 0.029590440914034843, -0.009660724550485611, 0.04884032905101776, 0.0059171938337385654, -0.04161267727613449, -0.04211360216140747, -0.011494472622871399, -0.0037748385220766068, -0.023597214370965958, 0.008372628130018711, -0.02876749075949192, -0.05996805056929588, -0.058858856558799744, 0.039251163601875305, 0.006954826880246401, -0.036317165940999985, 0.05825059115886688, -0.05671203136444092, 0.020359082147479057, 0.004615679383277893, -0.03345473110675812, -0.025296784937381744, 0.022183885797858238, -0.03408088907599449, 0.025064213201403618, -0.02234489843249321, 0.04093284532427788, 0.07385087013244629, -0.024133920669555664, 0.00657018693163991, 0.020090728998184204, -0.020037058740854263, 0.01165548525750637, -0.013364002108573914, 0.034957509487867355, -0.04619257524609566, -0.016620023176074028, -0.052096351981163025, 0.03644239902496338, -0.0749242827296257, 0.03179093822836876, 0.009794901125133038, 0.012782569974660873, 0.011494472622871399, -0.011923838406801224, 0.030502842739224434, 0.01205801498144865, 0.03472493588924408, 0.03204140067100525, -0.04773113504052162, 0.0033186376094818115, 0.02694268710911274, -0.042077820748090744, 0.033848315477371216, 0.03230975568294525, 0.029250526800751686, -0.03760526329278946, -0.00848444178700447, 0.018283816054463387, 0.008690179325640202, 0.0038419270422309637, 0.034653376787900925, -0.027980320155620575, 0.004700657911598682, -0.015287201851606369, -0.06551402062177658, 0.03517219424247742, -0.01551977451890707, 0.019178327172994614, 0.03572678938508034, 0.024652738124132156, -0.01182544231414795, -0.0379272885620594, 0.03377675637602806, 0.06944987177848816, -0.03572678938508034, 0.10562392324209213, -0.06744616478681564, 0.0013551849406212568, -0.08301066607236862, 0.0482320599257946, 0.06107724457979202, 0.03857133537530899, 0.05646156519651413, 0.08995208144187927, 0.0020909206941723824, -0.028427576646208763, -0.007598875090479851, -0.018239090219140053, -0.08723276108503342, 0.027819307520985603, 0.06930675357580185, -0.04884032905101776, 0.05535237118601799, -0.017603985965251923, 0.008649926632642746, 0.0038150916807353497, -0.00886013638228178, 0.0017923774430528283, -0.006682001054286957, 0.032631780952215195, 0.008998786099255085, -0.023668775334954262, 0.023597214370965958, 0.04494025930762291, -0.010143760591745377, 0.11027538031339645, -0.02128937467932701, 0.009902242571115494, 0.04064660146832466, 0.014661043882369995, -0.024688517674803734, 0.03368730470538139, -0.027264710515737534, -0.005223947111517191, -0.03654973953962326, -0.04100440815091133, 0.05746341869235039, 0.013954379595816135, 0.061792854219675064, -0.012111686170101166, 0.0321129634976387, 0.01312248408794403, 0.04576320946216583, -0.05342022702097893, -0.03272123262286186, -0.06984345614910126, -0.0356731191277504, -0.00004801011164090596, 0.018239090219140053, 0.009875407442450523, -0.012290588580071926, -0.014285349287092686, 0.037283241748809814, 0.06898472458124161, -0.03651396185159683, 0.01167337503284216, 0.04583476856350899, -0.005062934942543507, 0.05714139714837074, -0.04282921180129051, 0.053706470876932144, 0.0844418853521347, -0.017460864037275314, -0.037390582263469696, -0.00903903879225254, -0.040324579924345016, 0.02921474538743496, 0.03175516054034233, -0.033240046352148056, -0.03345473110675812, 0.014661043882369995, 0.00010356766142649576, -0.027622515335679054, 0.003723404137417674, -0.03390198573470116, -0.008050603792071342, -0.016602134332060814, 0.028642259538173676, 0.02710369974374771, 0.02204076386988163, -0.008471024222671986, 0.01586863398551941, 0.039251163601875305, -0.0073886653408408165, 0.04186313971877098, -0.013310330919921398, -0.04111174866557121, 0.007683854084461927, 0.04973484203219414, 0.029894575476646423, 0.008998786099255085, 0.03656763210892677, 0.024026580154895782, -0.034760717302560806, 0.07177560031414032, -0.041075967252254486, 0.07699955254793167, 0.038893360644578934, 0.042435627430677414, -0.039608970284461975, -0.031415242701768875, 0.007402082905173302, -0.04615679383277893, 0.029339978471398354, 0.018570059910416603, -0.04962749779224396, 0.030896427109837532, -0.05223947390913963, 0.025690371170639992, -0.013256660662591457, -0.015376652590930462, 0.014437415637075901, 0.0032716759014874697, 0.057964347302913666, 0.02209443412721157, -0.007795667741447687, -0.004906395450234413, -0.017228292301297188, -0.019804485142230988, -0.03635294735431671, 0.020913679152727127, 0.023167848587036133, 0.0012388984905555844, -0.022309117019176483, 0.06873426586389542, -0.00034438693546690047, 0.08129320293664932, 0.023364640772342682, -0.140330970287323, -0.010823589749634266, -0.009159797802567482, -0.030162928625941277, -0.024581177160143852, 0.05571017786860466, 0.011807551607489586, -0.0083905179053545, -0.10404957830905914, -0.02416970022022724, -0.032077182084321976, 0.04039613902568817, -0.010000638663768768, 0.014598428271710873, -0.0241160299628973, 0.0016570825828239322, 0.06841224431991577, -0.041576895862817764, -0.005474410485476255, -0.028499137610197067, 0.005286563187837601, -0.013462398201227188, -0.015770237892866135, -0.0025605391710996628, 0.035404764115810394, 0.013641300611197948, 0.002107692649587989, -0.017487701028585434, 0.026101846247911453, 0.011226119473576546, -0.02932208776473999, 0.004861670080572367, -0.01509040966629982, -0.013838092796504498, 0.0028512554708868265, 0.06512043625116348, -0.05059356987476349, -0.040109895169734955, 0.017183566465973854, -0.06537090241909027, 0.03585202246904373, 0.028695929795503616, -0.0438668429851532, -0.01890997402369976, -0.01655740849673748, -0.07642706483602524, 0.015886524692177773, -0.023221518844366074, -0.04039613902568817, -0.004785636439919472, 0.041219089180231094, -0.03164781630039215, -0.01728196255862713, 0.014097501523792744, 0.006820650305598974, -0.015627115964889526, 0.006780397146940231, 0.06444060802459717, 0.04919813200831413, 0.08129320293664932, 0.025958724319934845, 0.011109832674264908, -0.02780141867697239, -0.018283816054463387, 0.016351670026779175, -0.0396447516977787, 0.052346814423799515, 0.034206122159957886, 0.0005364273674786091, -0.010421059094369411, -0.004018593113869429, 0.01352501381188631, 0.04261452704668045, -0.0027282601222395897, 0.03198773041367531, 0.017621876671910286, 0.010662577114999294, 0.04458245262503624, 0.016789980232715607, 0.052203692495822906, -0.01170021016150713, -0.005156858824193478, -0.005921666044741869, 0.04894766956567764, -0.08358315378427505, -0.015859689563512802, 0.011342406272888184, -0.012120630592107773, -0.04322279617190361, -0.028695929795503616, 0.018391156569123268, -0.02683534473180771, 0.017541371285915375, 0.00886013638228178, 0.003882179968059063, -0.049412816762924194, -0.036478180438280106, 0.004262347240000963, -0.0004743706376757473, -0.005098715424537659, 0.06648009270429611, 0.008784103207290173, -0.015385597944259644, 0.061792854219675064, 0.018695291131734848, 0.014687879011034966, -0.06125614792108536, 0.0028288925532251596, -0.0038240368012338877, -0.03939428552985191, 0.03975209221243858, -0.01772027276456356, 0.04755223169922829, -0.021718740463256836, -0.02350776270031929, -0.009186632931232452, -0.04554852470755577, -0.04919813200831413, 0.010081144981086254, -0.025815602391958237, -0.0200191680341959, 0.024688517674803734, -0.0030279215425252914, -0.03433135151863098, 0.012988307513296604, -0.06533512473106384, -0.05159542337059975, -0.02018018066883087, -0.0309858787804842, 0.01860583946108818, 0.0134445084258914, -0.024491725489497185, 0.0009761356632225215, -0.01147658284753561, -0.027032138779759407, -0.026048175990581512, -0.05463676154613495, -0.06254424154758453, 0.02184397168457508, -0.05563861504197121, 0.013533959165215492, 0.011843332089483738, 0.0008995431708171964, -0.01672736555337906, 0.049913741648197174, -0.022416459396481514, -0.07066641002893448, 0.06336719542741776, 0.018695291131734848, 0.023740336298942566, 0.05145230144262314, -0.002459906740114093, -0.029089514166116714, -0.06143505126237869, -0.016986774280667305, -0.07363618910312653, -0.06859114021062851, 0.05023576691746712, -0.017899176105856895, -0.01605648174881935, 0.008412880823016167, -0.04393840581178665, -0.05349178984761238, 0.03266756236553192, 0.00557280657812953, 0.021772410720586777, 0.03155836462974548, -0.0417557992041111, -0.05019998550415039, -0.02112836204469204, -0.020108619704842567, 0.05778544396162033, 0.009839626960456371, -0.04028879851102829, -0.007795667741447687, 0.045727428048849106, -0.018892083317041397, -0.010975656099617481, 0.02375822514295578, 0.002826656447723508, -0.03209507465362549, -0.06730304658412933, 0.03408088907599449, 0.02577982097864151, 0.024294933304190636, -0.004081208724528551, -0.07199028879404068, 0.004611206706613302, -0.038249313831329346, -0.012997251935303211, -0.008649926632642746, -0.031361572444438934, 0.02891061268746853, -0.0348859503865242, 0.04758801311254501, -0.02309628762304783, 0.013793367892503738, 0.048053160309791565, -0.0006490799132734537, -0.0516669861972332, 0.05538815259933472, 0.04791003838181496, -0.03229186683893204, -0.021164141595363617, 0.004369688685983419, -0.02187975123524666, 0.02386556752026081, -0.0027282601222395897, 0.03799884766340256, 0.003510957583785057, 0.0004592757613863796, 0.03835665434598923, -0.016047537326812744, -0.05316976457834244, -0.025135774165391922, -0.05177432671189308, -0.04161267727613449, -0.018641620874404907, 0.011154558509588242, -0.01000958401709795, -0.01786339469254017, -0.03195195272564888, 0.021146252751350403, 0.011154558509588242, -0.038499776273965836, -0.02284582331776619, -0.03588780015707016, 0.03053862228989601, -0.052847739309072495, -0.017621876671910286, -0.03281068056821823, -0.034098777920007706, -0.01807807758450508, -0.0322381965816021, 0.02699635736644268, -0.015439269132912159, -0.006932464428246021, -0.015788128599524498, 0.03603092208504677, 0.019536131992936134, -0.023489871993660927, -0.06640853732824326, -0.06819755584001541, 0.014634208753705025, -0.0031330266501754522, -0.01150341797620058, 0.04873298853635788, 0.017264071851968765, 0.00815347209572792, 0.03481438755989075, 0.030950099229812622, -0.0713462382555008, -0.05238259583711624, 0.018981534987688065, 0.003922433126717806, 0.016405340284109116, -0.03365152329206467, -0.023686664178967476, 0.03746214136481285, 0.001698453794233501, -0.010304772295057774, -0.052346814423799515, 0.01185227744281292, 0.014419525861740112, -0.03261388838291168, -0.030395500361919403, -0.015197750180959702, -0.013399782590568066, -0.017487701028585434, 0.0013540667714551091, -0.004651459865272045, -0.03547632694244385, -0.010304772295057774, -0.02826656401157379, 0.036370839923620224, -0.017183566465973854, 0.023668775334954262, 0.037641044706106186, 0.001227717031724751, 0.06333141773939133, -0.024760078638792038, 0.03640661761164665, -0.01061785127967596, 0.07442335784435272, -0.028141332790255547, 0.0322381965816021, -0.006364449393004179, 0.007554149720817804, -0.06454794853925705, -0.012281643226742744, 0.05692671239376068, -0.026549100875854492, 0.01840904727578163, 0.08937959372997284, -0.0004710162174887955, -0.024098141118884087, 0.04490447789430618, -0.008202670142054558, 0.025815602391958237, 0.03291802480816841, 0.02422337234020233, -0.03599514439702034, 0.04075394570827484, -0.013149319216609001, 0.011199284344911575, -0.06841224431991577, -0.015501884743571281, 0.004000702872872353, 0.034653376787900925, -0.024742187932133675, -0.04665772244334221, 0.019643472507596016, 0.04422464966773987, 0.05696249380707741 ]
30,763
networkx.classes.function
induced_subgraph
Returns a SubGraph view of `G` showing only nodes in nbunch. The induced subgraph of a graph on a set of nodes N is the graph with nodes N and edges from G which have both ends in N. Parameters ---------- G : NetworkX Graph nbunch : node, container of nodes or None (for all nodes) Returns ------- subgraph : SubGraph View A read-only view of the subgraph in `G` induced by the nodes. Changes to the graph `G` will be reflected in the view. Notes ----- To create a mutable subgraph with its own copies of nodes edges and attributes use `subgraph.copy()` or `Graph(subgraph)` For an inplace reduction of a graph to a subgraph you can remove nodes: `G.remove_nodes_from(n in G if n not in set(nbunch))` If you are going to compute subgraphs of your subgraphs you could end up with a chain of views that can be very slow once the chain has about 15 views in it. If they are all induced subgraphs, you can short-cut the chain by making them all subgraphs of the original graph. The graph class method `G.subgraph` does this when `G` is a subgraph. In contrast, this function allows you to choose to build chains or not, as you wish. The returned subgraph is a view on `G`. Examples -------- >>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> H = nx.induced_subgraph(G, [0, 1, 3]) >>> list(H.edges) [(0, 1)] >>> list(H.nodes) [0, 1, 3]
def induced_subgraph(G, nbunch): """Returns a SubGraph view of `G` showing only nodes in nbunch. The induced subgraph of a graph on a set of nodes N is the graph with nodes N and edges from G which have both ends in N. Parameters ---------- G : NetworkX Graph nbunch : node, container of nodes or None (for all nodes) Returns ------- subgraph : SubGraph View A read-only view of the subgraph in `G` induced by the nodes. Changes to the graph `G` will be reflected in the view. Notes ----- To create a mutable subgraph with its own copies of nodes edges and attributes use `subgraph.copy()` or `Graph(subgraph)` For an inplace reduction of a graph to a subgraph you can remove nodes: `G.remove_nodes_from(n in G if n not in set(nbunch))` If you are going to compute subgraphs of your subgraphs you could end up with a chain of views that can be very slow once the chain has about 15 views in it. If they are all induced subgraphs, you can short-cut the chain by making them all subgraphs of the original graph. The graph class method `G.subgraph` does this when `G` is a subgraph. In contrast, this function allows you to choose to build chains or not, as you wish. The returned subgraph is a view on `G`. Examples -------- >>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> H = nx.induced_subgraph(G, [0, 1, 3]) >>> list(H.edges) [(0, 1)] >>> list(H.nodes) [0, 1, 3] """ induced_nodes = nx.filters.show_nodes(G.nbunch_iter(nbunch)) return nx.subgraph_view(G, filter_node=induced_nodes)
(G, nbunch)
[ -0.0025152924936264753, -0.04930713027715683, -0.006588771939277649, 0.009792995639145374, -0.040762536227703094, 0.019475022330880165, 0.010736229829490185, -0.025744758546352386, 0.07945365458726883, -0.03293923661112785, -0.0004288481140974909, 0.031811051070690155, -0.02716885879635811, 0.026207128539681435, -0.03151513636112213, 0.019622981548309326, 0.020177824422717094, -0.03630528971552849, 0.05552138388156891, 0.06140273064374924, -0.018957167863845825, -0.04605204612016678, 0.03075684979557991, 0.050786715000867844, -0.07967559248209, 0.010412571020424366, -0.00513230636715889, -0.034492798149585724, -0.01521197147667408, -0.020788153633475304, 0.007929644547402859, -0.06380705535411835, -0.016127463430166245, -0.04890024662017822, 0.044054608792066574, 0.02981361374258995, 0.003183417022228241, 0.04579311981797218, -0.051785435527563095, 0.01314055360853672, -0.01271517388522625, -0.052303288131952286, 0.03998575359582901, -0.025467336177825928, 0.02515292540192604, 0.038358211517333984, 0.02962866611778736, 0.029554687440395355, -0.020288793370127678, -0.0010732762748375535, 0.03366053104400635, -0.018430065363645554, -0.04893723502755165, 0.011614733375608921, -0.014499921351671219, 0.01483282819390297, -0.0016356336418539286, 0.016830265522003174, 0.07098303735256195, 0.013880345970392227, -0.04538623243570328, -0.05034283921122551, 0.026724983006715775, -0.00822093803435564, -0.03121921978890896, 0.005386610049754381, -0.08189496397972107, -0.028518978506326675, -0.05522546544671059, 0.002116498537361622, -0.04220512881875038, 0.01302033755928278, -0.01596101000905037, -0.002512980718165636, 0.012114092707633972, -0.017172420397400856, -0.012548720464110374, 0.00002226961441920139, -0.0017396669136360288, -0.010421819053590298, 0.04601505771279335, -0.01582229882478714, -0.04202017933130264, 0.010042674839496613, 0.07346133887767792, 0.02335892990231514, 0.02948070876300335, -0.034825704991817474, -0.03297622501850128, -0.01573907397687435, -0.004734668415039778, 0.010190634056925774, 0.0034839576110243797, 0.027002405375242233, 0.024339154362678528, 0.0119846286252141, -0.057481832802295685, -0.025874221697449684, -0.020233308896422386, -0.06036702170968056, 0.008891373872756958, -0.0010484238155186176, -0.08256077766418457, 0.005862851161509752, -0.006778343580663204, -0.03149664029479027, -0.01587778329849243, 0.009136429987847805, -0.011901402845978737, -0.05792570859193802, -0.021786872297525406, 0.0501948818564415, -0.01982642337679863, -0.0019442656775936484, -0.003964822273701429, 0.024893997237086296, 0.031533628702163696, -0.04113243147730827, 0.007462651003152132, -0.011485269293189049, -0.033753007650375366, 0.03846918046474457, -0.024431627243757248, 0.04745765030384064, 0.005765753332525492, -0.01373238768428564, 0.01264119427651167, 0.02881489507853985, 0.05652010440826416, -0.10416270047426224, 0.06780193001031876, -0.03288375213742256, -0.05089768394827843, 0.019789433106780052, -0.00491036893799901, 0.010310850106179714, -0.015813052654266357, -0.02213827334344387, 0.008646317757666111, 0.09395357221364975, -0.06809784471988678, -0.04686581715941429, 0.025134431198239326, 0.100389763712883, -0.030442437157034874, -0.017107687890529633, 0.00003771204865188338, 0.02674347721040249, 0.02938823401927948, 0.0070973788388073444, -0.06469480693340302, 0.022545158863067627, 0.02570776827633381, -0.03408591449260712, -0.00031383358873426914, -0.03710056468844414, -0.028981348499655724, 0.06539760529994965, 0.014601643197238445, -0.020991595461964607, -0.03721153363585472, 0.0007490392890758812, -0.017634790390729904, 0.030590396374464035, -0.057666778564453125, -0.0019465774530544877, 0.08174701035022736, -0.006704364437609911, -0.013649160973727703, 0.01179968100041151, -0.01271517388522625, 0.0007444156217388809, -0.04527526721358299, -0.005164672154933214, -0.026761973276734352, 0.06169864535331726, 0.02938823401927948, 0.03898703306913376, -0.004975100513547659, 0.03258783370256424, -0.012049361132085323, -0.024524101987481117, -0.034215375781059265, -0.01860576681792736, -0.010477302595973015, 0.012169577181339264, -0.008433627896010876, -0.012844637036323547, 0.07061313837766647, -0.05289512127637863, 0.0004701724392361939, 0.0023719577584415674, 0.024690555408596992, 0.03428935632109642, 0.03475172445178032, -0.025985190644860268, -0.0654715821146965, 0.02180536650121212, -0.07475597411394119, 0.06166165694594383, -0.005164672154933214, -0.037562936544418335, 0.06613739579916, -0.00542822340503335, 0.021176543086767197, 0.05052778869867325, -0.010662251152098179, -0.016451122239232063, -0.0011882907710969448, 0.03423387184739113, -0.018578024581074715, -0.04841938242316246, 0.09602499008178711, 0.010514292865991592, -0.01620144210755825, -0.018781468272209167, -0.041280388832092285, -0.004302352201193571, 0.011106126010417938, -0.04390665143728256, 0.021879345178604126, -0.04668087139725685, 0.02528238855302334, 0.015988752245903015, -0.015424661338329315, -0.04224211722612381, 0.010024180635809898, -0.04379568248987198, 0.011198599822819233, -0.036101844161748886, 0.013417975977063179, -0.020991595461964607, 0.028703926131129265, -0.03569496050477028, -0.03297622501850128, 0.06724708527326584, -0.06987334787845612, -0.005118435248732567, 0.0926959291100502, 0.028611453250050545, -0.07538479566574097, -0.048160452395677567, -0.03626829758286476, 0.0017408228013664484, -0.01653434894979, -0.0020332718268036842, -0.022545158863067627, -0.003860789118334651, -0.011078383773565292, 0.02298903465270996, -0.02143547125160694, -0.017033709213137627, -0.010958167724311352, -0.00337298889644444, 0.024265175685286522, 0.044017620384693146, -0.0958770290017128, -0.04479439929127693, -0.028666937723755836, -0.0007600206299684942, 0.020566215738654137, 0.0060894121415913105, -0.04072554409503937, 0.03898703306913376, -0.015415414236485958, -0.0209176167845726, -0.010042674839496613, 0.0012056296691298485, -0.041650284081697464, 0.005742634646594524, 0.015942515805363655, 0.06277134269475937, 0.02972114086151123, -0.0046722483821213245, -0.00301465205848217, 0.016377143561840057, -0.013011090457439423, 0.04449848458170891, -0.03606485575437546, -0.02147245965898037, -0.04812346398830414, 0.018855446949601173, -0.036379266530275345, 0.011318816803395748, -0.013621418736875057, -0.044720422476530075, 0.03895004466176033, -0.008563091047108173, 0.011309568770229816, -0.041650284081697464, 0.07016926258802414, -0.02411721646785736, 0.027538754045963287, 0.015665093436837196, -0.0069771623238921165, 0.07642050832509995, -0.04760561138391495, -0.012918616645038128, -0.01155924890190363, 0.060256052762269974, 0.10808359831571579, -0.03769239783287048, -0.035824425518512726, 0.024320660158991814, 0.05448567494750023, -0.00596919609233737, -0.003876972012221813, -0.004901121370494366, -0.007934268563985825, 0.0033660533372312784, -0.09469336271286011, -0.031533628702163696, -0.019253084436058998, -0.02585572749376297, -0.05322802811861038, -0.07246261835098267, -0.032236434519290924, -0.018485549837350845, 0.03397494554519653, 0.0450163371860981, 0.012770658358931541, 0.05463363230228424, -0.018578024581074715, 0.05759280174970627, -0.019715454429388046, 0.06269736588001251, 0.021361492574214935, 0.08041538298130035, -0.015674341470003128, 0.006880064960569143, -0.09291786700487137, 0.006131025496870279, -0.004808647558093071, 0.05907238647341728, -0.04812346398830414, 0.018152644857764244, 0.07523683458566666, -0.003400730900466442, -0.01884619891643524, -0.020603204146027565, 0.047642599791288376, 0.06262338906526566, -0.016404885798692703, -0.00343309692107141, 0.07164885103702545, -0.006477802991867065, 0.000923006038647145, -0.011411290615797043, 0.001750070252455771, 0.0353250652551651, -0.030035551637411118, 0.03182954713702202, -0.020899122580885887, -0.04930713027715683, 0.010283107869327068, 0.05222931131720543, 0.012141834944486618, -0.03136717900633812, -0.02533787302672863, -0.009719016030430794, 0.010985909961163998, 0.02938823401927948, -0.010412571020424366, -0.05430072546005249, 0.044350527226924896, -0.008974600583314896, -0.03234740346670151, 0.02774219773709774, -0.030349964275956154, -0.029351243749260902, -0.011614733375608921, -0.048345401883125305, -0.012872379273176193, 0.02622562274336815, -0.0005377940251491964, 0.008798900060355663, -0.014916054904460907, -0.013270017690956593, -0.023303445428609848, 0.0470137782394886, -0.00248523848131299, 0.025929706171154976, 0.003157986793667078, 0.03924596309661865, 0.05330200865864754, -0.0015685900580137968, -0.020233308896422386, 0.018661251291632652, 0.045756131410598755, -0.0434257872402668, -0.009709768928587437, -0.021601924672722816, 0.0427599735558033, 0.04719872400164604, -0.022156767547130585, -0.08226486295461655, 0.05959023907780647, 0.002367334207519889, 0.011207847855985165, -0.0008299540495499969, -0.0017824361566454172, 0.009261270053684711, 0.00407347921282053, 0.06728407740592957, 0.026299603283405304, -0.052340276539325714, 0.02929575927555561, 0.011966134421527386, 0.044017620384693146, -0.08722146600484848, 0.0351216197013855, -0.01648811250925064, -0.0335310697555542, 0.05200737342238426, 0.03663819655776024, -0.012308288365602493, 0.007592114619910717, 0.032994721084833145, -0.004348589573055506, 0.025115935131907463, 0.05389384180307388, 0.01769952103495598, 0.06103283166885376, 0.01090268325060606, 0.030368458479642868, -0.02585572749376297, -0.05615020543336868, -0.016987472772598267, -0.007416414096951485, 0.06957743316888809, -0.03347558528184891, -0.06909656524658203, 0.014324220828711987, -0.002234402811154723, -0.024838512763381004, -0.038876064121723175, 0.021601924672722816, -0.0014460620004683733, -0.02237870544195175, 0.05381986126303673, 0.011457527056336403, 0.028426503762602806, 0.006001561880111694, -0.050231870263814926, 0.03872810676693916, -0.041095439344644547, -0.01606273278594017, 0.04786453768610954, 0.025837233290076256, -0.034733232110738754, 0.04675484821200371, -0.0456821508705616, -0.023802805691957474, -0.027150362730026245, -0.0596272274851799, 0.008281045593321323, 0.036952607333660126, 0.024006247520446777, -0.06406597793102264, 0.07294348627328873, 0.01808791235089302, 0.004785528872162104, -0.011328063905239105, 0.006561029702425003, 0.002367334207519889, -0.004817894659936428, 0.07997150719165802, 0.0013454965082928538, -0.056816019117832184, -0.011596238240599632, 0.04964003711938858, -0.005872098263353109, -0.04168727621436119, -0.06484276056289673, 0.1037188246846199, 0.03536205366253853, -0.05947927013039589, -0.0030493298545479774, 0.02162041887640953, -0.03584291785955429, -0.01638639159500599, -0.0057102688588202, 0.03362354263663292, 0.01945652812719345, -0.022785590961575508, 0.021490955725312233, -0.0199188981205225, -0.0002683190687093884, -0.04756861925125122, -0.005955324973911047, 0.024524101987481117, -0.005492954980581999, -0.06517566740512848, 0.0019280826672911644, 0.016830265522003174, 0.05185941234230995, -0.012696678750216961, -0.018679745495319366, 0.07753019034862518, -0.03075684979557991, 0.0020829765126109123, -0.010579024441540241, 0.05600224807858467, 0.021879345178604126, 0.006278983782976866, 0.01606273278594017, -0.008595457300543785, 0.07405316829681396, 0.027871660888195038, -0.015415414236485958, 0.04623699560761452, 0.01283538993448019, 0.0009698209469206631, 0.01930856890976429, 0.05652010440826416, 0.005946077406406403, 0.004679183941334486, 0.009210409596562386, 0.05119360238313675, -0.033512573689222336, 0.04446149617433548, -0.007920397445559502, 0.05167446658015251, 0.028463494032621384, 0.027816176414489746, -0.0016818706644698977, 0.006676622200757265, 0.004487300291657448, -0.01879071444272995, 0.01859651878476143, -0.0032319659367203712, 0.07209271937608719, 0.015859289094805717, 0.10342290997505188, 0.04253803566098213, -0.020510731264948845, 0.019696960225701332, -0.022027304396033287, 0.03406741842627525, 0.015285950154066086, -0.018559530377388, 0.028999842703342438, 0.03364203870296478, 0.06125476956367493, -0.01822662353515625, 0.03316117450594902, 0.01111537404358387, 0.04812346398830414, -0.005742634646594524, -0.04964003711938858, -0.05674203857779503, 0.02345140464603901, 0.03580592945218086, 0.025929706171154976, 0.03502914682030678, -0.026410572230815887, -0.045941077172756195, 0.045053329318761826, -0.03231041133403778, 0.013408728875219822, -0.03569496050477028, -0.013122059404850006, 0.03931993991136551, -0.018762972205877304, 0.02877790480852127, 0.00006288953591138124, -0.014731106348335743, -0.004605204798281193, 0.015285950154066086, 0.006750601343810558, 0.0049427347257733345, -0.008609328418970108, -0.016784029081463814, 0.0025869598612189293, -0.06698815524578094, 0.009977943263947964, -0.012946358881890774, 0.05271017551422119, 0.03538054972887039, -0.04290793091058731, -0.009617295116186142, -0.022582149133086205, 0.04830841347575188, 0.03145965188741684, 0.0007224530563689768, 0.03565797209739685, -0.02999856323003769, 0.038358211517333984, -0.012604204937815666, -0.031348682940006256, 0.05326501652598381, -0.020788153633475304, 0.05426373705267906, -0.002771907951682806, 0.01988190785050392, -0.009719016030430794, -0.04168727621436119, -0.024080226197838783, 0.007693835999816656, -0.05796269699931145, -0.028278546407818794, 0.026392076164484024, 0.05796269699931145, 0.006727482657879591, -0.006232746876776218, -0.021601924672722816, 0.02482001855969429, -0.02317398227751255, 0.024098722264170647, -0.04516429826617241, 0.017764253541827202, 0.07394219934940338, -0.03179255872964859, -0.0141762625426054, -0.064805768430233, -0.032088473439216614, -0.04239007830619812, -0.0008553843945264816, -0.0420941598713398, -0.010551282204687595, 0.01682101935148239, 0.003587990766391158, -0.023469898849725723, -0.03390096500515938, -0.03142266348004341, 0.020288793370127678, 0.047679588198661804, 0.002836639527231455, -0.004771657753735781, -0.007925020530819893, 0.03846918046474457, -0.05000993236899376, -0.002637820551171899, 0.017061451449990273, 0.013954324647784233, -0.1152595803141594, -0.012650441378355026, 0.003042394295334816, -0.0351216197013855, 0.07102002203464508, -0.027390796691179276, -0.0191236212849617, -0.04412858933210373, -0.0317370742559433, -0.022878065705299377, -0.05548439547419548, -0.014564653858542442, -0.03325364738702774, -0.010357086546719074, 0.008142334409058094, 0.013075822032988071, 0.031533628702163696, 0.0629562959074974, -0.008100721053779125, -0.04031866043806076, 0.06702514737844467, 0.06106982380151749, -0.03009103611111641, 0.03157062083482742, 0.025818737223744392, 0.06036702170968056, -0.013168295845389366, 0.013982066884636879, 0.010255365632474422, 0.08729544281959534, 0.056076228618621826, 0.026262613013386726, -0.04120640829205513, -0.011069136671721935, -0.007162110414355993, -0.03438182920217514, -0.03626829758286476, -0.024228185415267944, -0.034825704991817474, -0.07153788208961487, -0.032994721084833145, -0.008840513415634632, 0.003215783042833209, -0.013380986638367176, -0.04349976405501366, 0.005312630906701088, 0.006903183180838823, 0.012770658358931541, -0.05256221443414688, -0.051267579197883606, -0.008618575520813465, -0.045053329318761826, -0.0735723078250885, 0.01327926479279995, -0.030534911900758743, 0.03615732863545418, -0.047346681356430054, 0.003446968039497733, 0.039874784648418427, 0.0017789683770388365, 0.0018402324058115482, -0.0006386485183611512, 0.032569337636232376, -0.006635008845478296, -0.02807510271668434, 0.051082633435726166, 0.019530506804585457, 0.010847198776900768, 0.016645317897200584, -0.023858290165662766, 0.0235068891197443, -0.04708775505423546, -0.002351151080802083, -0.008248680271208286, 0.02604067511856556, -0.01653434894979, 0.005525320768356323, 0.03325364738702774, 0.01743134669959545, 0.042833950370550156, -0.03547302260994911, -0.03179255872964859, 0.017459088936448097, -0.07020625472068787, 0.033272139728069305, 0.01671929657459259, -0.03057190030813217, 0.009224280714988708, 0.03489968553185463, -0.022434189915657043, 0.0828566923737526, 0.07257358729839325, -0.031145239248871803, 0.003981005400419235, -0.03787734732031822, -0.018827704712748528, 0.06310424953699112, 0.016182947903871536, 0.01644187606871128, 0.006903183180838823, -0.0015604986110702157, -0.05485557019710541, 0.0011565028689801693, -0.006385329179465771, -0.04723571240901947, 0.006131025496870279, -0.014074541628360748, -0.020603204146027565, 0.030460931360721588, -0.05393083021044731, -0.006787590682506561, 0.028666937723755836, -0.003712830599397421, 0.001052469597198069, 0.016728544607758522, 0.036749161779880524, 0.043351806700229645, -0.0040781027637422085, -0.050416819751262665, 0.04756861925125122, -0.004461870063096285, -0.011207847855985165, -0.018124902620911598, -0.031533628702163696, -0.0893668606877327, -0.037562936544418335, -0.003918585367500782, 0.008031366392970085, -0.010273859836161137, -0.014046799391508102, 0.0629562959074974, 0.03075684979557991, 0.011133868247270584 ]
30,771
networkx.algorithms.dag
is_aperiodic
Returns True if `G` is aperiodic. A directed graph is aperiodic if there is no integer k > 1 that divides the length of every cycle in the graph. Parameters ---------- G : NetworkX DiGraph A directed graph Returns ------- bool True if the graph is aperiodic False otherwise Raises ------ NetworkXError If `G` is not directed Examples -------- A graph consisting of one cycle, the length of which is 2. Therefore ``k = 2`` divides the length of every cycle in the graph and thus the graph is *not aperiodic*:: >>> DG = nx.DiGraph([(1, 2), (2, 1)]) >>> nx.is_aperiodic(DG) False A graph consisting of two cycles: one of length 2 and the other of length 3. The cycle lengths are coprime, so there is no single value of k where ``k > 1`` that divides each cycle length and therefore the graph is *aperiodic*:: >>> DG = nx.DiGraph([(1, 2), (2, 3), (3, 1), (1, 4), (4, 1)]) >>> nx.is_aperiodic(DG) True A graph consisting of two cycles: one of length 2 and the other of length 4. The lengths of the cycles share a common factor ``k = 2``, and therefore the graph is *not aperiodic*:: >>> DG = nx.DiGraph([(1, 2), (2, 1), (3, 4), (4, 5), (5, 6), (6, 3)]) >>> nx.is_aperiodic(DG) False An acyclic graph, therefore the graph is *not aperiodic*:: >>> DG = nx.DiGraph([(1, 2), (2, 3)]) >>> nx.is_aperiodic(DG) False Notes ----- This uses the method outlined in [1]_, which runs in $O(m)$ time given $m$ edges in `G`. Note that a graph is not aperiodic if it is acyclic as every integer trivial divides length 0 cycles. References ---------- .. [1] Jarvis, J. P.; Shier, D. R. (1996), "Graph-theoretic analysis of finite Markov chains," in Shier, D. R.; Wallenius, K. T., Applied Mathematical Modeling: A Multidisciplinary Approach, CRC Press.
def transitive_closure_dag(G, topo_order=None): """Returns the transitive closure of a directed acyclic graph. This function is faster than the function `transitive_closure`, but fails if the graph has a cycle. The transitive closure of G = (V,E) is a graph G+ = (V,E+) such that for all v, w in V there is an edge (v, w) in E+ if and only if there is a non-null path from v to w in G. Parameters ---------- G : NetworkX DiGraph A directed acyclic graph (DAG) topo_order: list or tuple, optional A topological order for G (if None, the function will compute one) Returns ------- NetworkX DiGraph The transitive closure of `G` Raises ------ NetworkXNotImplemented If `G` is not directed NetworkXUnfeasible If `G` has a cycle Examples -------- >>> DG = nx.DiGraph([(1, 2), (2, 3)]) >>> TC = nx.transitive_closure_dag(DG) >>> TC.edges() OutEdgeView([(1, 2), (1, 3), (2, 3)]) Notes ----- This algorithm is probably simple enough to be well-known but I didn't find a mention in the literature. """ if topo_order is None: topo_order = list(topological_sort(G)) TC = G.copy() # idea: traverse vertices following a reverse topological order, connecting # each vertex to its descendants at distance 2 as we go for v in reversed(topo_order): TC.add_edges_from((v, u) for u in nx.descendants_at_distance(TC, v, 2)) return TC
(G, *, backend=None, **backend_kwargs)
[ -0.03266729414463043, 0.021180087700486183, -0.02476874180138111, 0.007968920283019543, -0.0362735390663147, -0.030996110290288925, -0.01892838440835476, -0.012648242525756359, 0.09302350878715515, -0.07761341333389282, 0.012155681848526001, 0.028199071064591408, 0.0005280179320834577, -0.01179505791515112, -0.03152385354042053, 0.022429080680012703, -0.013993986882269382, -0.017257198691368103, 0.0031994422897696495, 0.02943047136068344, 0.0009411417995579541, -0.06410319358110428, 0.013510222546756268, -0.023853987455368042, -0.015709152445197105, 0.01653594896197319, -0.047074683010578156, 0.032069187611341476, -0.06069045141339302, -0.03133034706115723, 0.031154433265328407, -0.04542108625173569, -0.09049034118652344, 0.013501427136361599, 0.05266875773668289, 0.08092060685157776, -0.000371893955161795, 0.018171953037381172, -0.01715165004134178, -0.06040899083018303, 0.012199660763144493, -0.01841823384165764, -0.011487207375466824, -0.0325089730322361, 0.04591364786028862, 0.013475039973855019, -0.009129955433309078, 0.03806786611676216, -0.03739939257502556, -0.04953748360276222, 0.08640912920236588, -0.03722347691655159, -0.005787582136690617, -0.010598840191960335, 0.0153133450075984, 0.03905298560857773, 0.019508901983499527, 0.059459052979946136, 0.06821958720684052, -0.01778494194149971, -0.009947956539690495, -0.05516674369573593, -0.009059589356184006, 0.035481926053762436, -0.05097997933626175, 0.021268045529723167, -0.03683646768331528, -0.06002197787165642, -0.021162496879696846, 0.007291649933904409, -0.013615771196782589, 0.020247742533683777, 0.0055720871314406395, -0.07606536895036697, -0.027354681864380836, -0.07641719281673431, 0.027987973764538765, -0.045209988951683044, -0.02853330783545971, -0.03511250391602516, -0.034408848732709885, -0.06839550286531448, 0.023449383676052094, -0.00835153367370367, 0.06135892868041992, -0.02795279026031494, 0.03368759900331497, -0.0014183095190674067, -0.0676918476819992, -0.04074176400899887, 0.007828189060091972, -0.03437366336584091, -0.031224798411130905, 0.032772842794656754, 0.037469759583473206, -0.008830900304019451, -0.000948288303334266, -0.04851717874407768, 0.01008868869394064, 0.009983140043914318, 0.03894743695855141, 0.007489553652703762, -0.0854240134358406, -0.006231766194105148, 0.023203102871775627, -0.04535071924328804, -0.01750347763299942, 0.016852594912052155, -0.01738033816218376, -0.08753498643636703, -0.0025023818016052246, -0.0012940700398758054, 0.09787874668836594, -0.03891225531697273, 0.03155903518199921, 0.013132006861269474, 0.007766618859022856, 0.000716850976459682, -0.00036419768002815545, -0.005690829362720251, 0.014143514446914196, 0.022182799875736237, 0.0010791246313601732, 0.012709812261164188, -0.007265262771397829, 0.00804368406534195, 0.00934984814375639, 0.0276713278144598, 0.03439125791192055, -0.010862711817026138, 0.060936734080314636, -0.013738911598920822, 0.03324781358242035, 0.08169462531805038, 0.051718819886446, 0.003834933042526245, -0.032350651919841766, 0.015392506495118141, -0.02033570036292076, 0.022763317450881004, -0.010097484104335308, -0.061394110321998596, -0.02153191715478897, 0.04932638630270958, 0.04978376254439354, 0.00397786358371377, -0.005827162880450487, -0.013316716998815536, 0.011926993727684021, 0.019297804683446884, 0.008527448400855064, 0.003876712638884783, -0.014847171492874622, 0.032579340040683746, 0.00015502452151849866, -0.007841382175683975, -0.04362675920128822, 0.0724063515663147, -0.053724244236946106, 0.01210290752351284, -0.03127757087349892, 0.047250594943761826, -0.040038108825683594, 0.024733558297157288, 0.016659090295433998, -0.001907571335323155, 0.11406286805868149, 0.006236163899302483, -0.031506262719631195, 0.03141830489039421, -0.056855518370866776, -0.030714645981788635, -0.007291649933904409, -0.004886021371930838, -0.006174593698233366, 0.029870256781578064, 0.003823938313871622, 0.030538732185959816, -0.016069777309894562, 0.021778197959065437, -0.01654474437236786, 0.0005359890637919307, -0.04573773220181465, 0.02119768038392067, 0.03243860602378845, 0.03108406625688076, 0.041234325617551804, -0.040038108825683594, 0.0769801214337349, -0.020951399579644203, -0.05495564639568329, 0.012665833346545696, 0.03789195045828819, 0.023273469880223274, 0.07529134303331375, -0.056011129170656204, -0.029923031106591225, 0.03715311363339424, -0.047707974910736084, 0.07152678072452545, 0.06396245956420898, 0.015049473382532597, 0.07198415696620941, 0.033318180590867996, 0.023713255301117897, 0.08155389875173569, 0.03433848172426224, -0.033036716282367706, -0.023713255301117897, 0.008641792461276054, -0.01300886645913124, -0.025525173172354698, 0.010642818175256252, -0.03996774181723595, -0.051718819886446, 0.032245103269815445, -0.038278963416814804, 0.013475039973855019, 0.0480949841439724, 0.0019152675522491336, -0.026299195364117622, 0.03715311363339424, 0.02568349614739418, -0.01687898300588131, 0.07043610513210297, -0.07754305005073547, -0.00044555807835422456, 0.01127611007541418, 0.020300516858696938, -0.05956460162997246, 0.011029830202460289, -0.007181703578680754, 0.032808028161525726, -0.01971999928355217, 0.06199222058057785, -0.04436559975147247, -0.0351300984621048, 0.0032126358710229397, 0.0188756100833416, 0.017925672233104706, -0.05073370039463043, -0.006007475312799215, -0.024592826142907143, 0.010546065866947174, -0.01703730598092079, -0.00518507556989789, 0.026633433997631073, 0.005959098692983389, 0.0325089730322361, 0.026387153193354607, -0.051226262003183365, -0.03567543253302574, -0.04865790903568268, -0.029641568660736084, -0.03097851760685444, -0.012604263611137867, -0.004096605349332094, -0.056855518370866776, -0.005330204963684082, 0.01733635924756527, 0.0003204939712304622, 0.017239606007933617, -0.057594358921051025, 0.06923989206552505, 0.008874879218637943, -0.029518429189920425, 0.03414497524499893, -0.08183535933494568, -0.06681226938962936, -0.0055720871314406395, -0.016659090295433998, 0.0038591211196035147, 0.04408413916826248, 0.0054357536137104034, 0.003689803648740053, -0.04091767966747284, 0.015498055145144463, 0.016043389216065407, -0.0029795493464916945, -0.029905440285801888, -0.04183243215084076, 0.029236966744065285, -0.031242389231920242, -0.023167921230196953, -0.06269587576389313, -0.00639008916914463, -0.011346476152539253, -0.026897305622696877, 0.02211243472993374, 0.018541373312473297, 0.07648756355047226, 0.0026431132573634386, 0.07296927273273468, 0.02478633262217045, 0.06301252543926239, 0.035376377403736115, 0.02647511102259159, -0.0254548080265522, -0.002396833151578903, 0.033036716282367706, 0.07353220134973526, 0.00951696652919054, -0.016386421397328377, -0.05185955390334129, 0.001837205607444048, 0.004586966708302498, 0.009886386804282665, -0.007986512035131454, -0.02943047136068344, 0.040143657475709915, -0.05164845660328865, -0.049924492835998535, -0.07040092349052429, 0.04506925866007805, -0.06916952133178711, -0.03416256979107857, -0.03268488869071007, -0.049361567944288254, 0.05442790314555168, 0.011768670752644539, 0.0023418599739670753, 0.015621194615960121, -0.00858462043106556, -0.006566003430634737, -0.07648756355047226, 0.04682840034365654, 0.009719268418848515, 0.05784064158797264, 0.05857948213815689, 0.010238215327262878, -0.005646850913763046, 0.03859560936689377, 0.005242247600108385, 0.057136982679367065, -0.003085097996518016, 0.07068239152431488, 0.09661216288805008, -0.029958214610815048, 0.015295753255486488, -0.028199071064591408, 0.04563218355178833, 0.04186761751770973, -0.02876199781894684, 0.009675289504230022, -0.012349187396466732, 0.010018322616815567, 0.003030124818906188, -0.00140621536411345, 0.037082746624946594, -0.02285127528011799, 0.04313420131802559, 0.03817341476678848, -0.01818954385817051, 0.027319500222802162, -0.03919371962547302, 0.06575678288936615, 0.04911528900265694, -0.008654986508190632, 0.014979107305407524, 0.02784724347293377, 0.0034369267523288727, -0.0221652090549469, 0.019420944154262543, -0.0362735390663147, 0.05516674369573593, 0.0032676090486347675, -0.009041997604072094, 0.03743457421660423, -0.02091621607542038, -0.04450633376836777, 0.01698453165590763, -0.011346476152539253, 0.0407065823674202, 0.00928827840834856, -0.051296625286340714, 0.030468367040157318, 0.04777833819389343, -0.05404089018702507, 0.05302058532834053, 0.036062441766262054, -0.02000146172940731, 0.017635414376854897, -0.008114049211144447, 0.03127757087349892, 0.020388474687933922, 0.015295753255486488, 0.043556395918130875, 0.008606609888374805, 0.02351974882185459, -0.027829650789499283, -0.0056028724648058414, -0.027020445093512535, 0.04542108625173569, -0.004026239737868309, 0.000395807292079553, -0.034232933074235916, 0.06614379584789276, 0.04461188241839409, 0.025753861293196678, 0.002953162183985114, -0.014512934722006321, 0.007625887170433998, 0.022006886079907417, 0.008967234753072262, 0.023678071796894073, -0.03342372924089432, 0.012173273600637913, 0.036801282316446304, 0.061745937913656235, 0.04886900633573532, -0.003621636889874935, 0.006319723092019558, 0.032069187611341476, -0.01716044545173645, -0.020212559029459953, -0.01977277360856533, -0.07113976776599884, 0.0029311729595065117, 0.05872021242976189, 0.0023330640979111195, 0.04897455498576164, 0.02897309511899948, 0.028427759185433388, -0.03898262232542038, 0.0046485369093716145, -0.03407461196184158, 0.03143589571118355, 0.0392289012670517, -0.010299785993993282, 0.09196802228689194, 0.010704388841986656, -0.032069187611341476, 0.013246350921690464, -0.03330058604478836, 0.00008575824904255569, 0.020986583083868027, 0.014187492430210114, 0.008193210698664188, 0.04007329046726227, 0.06614379584789276, -0.007696253247559071, 0.04024920612573624, -0.025243710726499557, -0.06090154871344566, -0.011979768052697182, -0.029465654864907265, 0.008998019620776176, 0.03289598599076271, 0.04911528900265694, -0.02227075770497322, 0.04626547545194626, 0.0464765727519989, -0.006715530529618263, -0.011610347777605057, -0.08514254540205002, 0.05003004148602486, 0.024680783972144127, -0.005317011382430792, -0.11863664537668228, 0.0101414630189538, 0.008593415841460228, -0.03215714544057846, 0.05959978327155113, -0.04528035596013069, -0.016298465430736542, -0.02221798337996006, 0.0026189249474555254, 0.000970827357377857, -0.040882498025894165, -0.032596930861473083, 0.05136699229478836, -0.032755251973867416, -0.05921277403831482, -0.04397859051823616, 0.04489334300160408, 0.015216591767966747, -0.05312613397836685, 0.033318180590867996, 0.057312898337841034, -0.03335336223244667, 0.020705120638012886, -0.02960638701915741, 0.003511690301820636, 0.01113537885248661, 0.0026299196761101484, 0.0008718755561858416, 0.015295753255486488, -0.02045883983373642, 0.011205744929611683, -0.0004617751983460039, 0.0015909255016595125, -0.022974414750933647, -0.005928313825279474, -0.011513594537973404, 0.006222970318049192, 0.039017803966999054, -0.015841087326407433, -0.035992078483104706, 0.009481783956289291, 0.006165798287838697, -0.0015722345560789108, 0.04211389645934105, -0.01813676953315735, 0.021056948229670525, -0.0009680786752142012, -0.03620317578315735, 0.009569740854203701, 0.026334378868341446, 0.0127274040132761, 0.013993986882269382, 0.04109359532594681, 0.022816091775894165, 0.008830900304019451, 0.0339866541326046, 0.010150258429348469, 0.014811988919973373, -0.023343835026025772, 0.004881623201072216, 0.02432895451784134, -0.029483245685696602, 0.004186761565506458, 0.013167189434170723, 0.020705120638012886, 0.08056877553462982, -0.011293701827526093, -0.013017662800848484, 0.021391185000538826, -0.03416256979107857, -0.006966208573430777, -0.0029839472845196724, 0.000460400857264176, 0.032368242740631104, -0.013906029984354973, 0.05724253132939339, -0.0036370293237268925, -0.05280948802828789, -0.008030490018427372, -0.024416912347078323, -0.11610347777605057, 0.0005799676291644573, 0.014064352959394455, 0.048270899802446365, 0.015929045155644417, 0.013228759169578552, 0.03915853425860405, -0.010801141150295734, 0.04626547545194626, -0.04091767966747284, -0.02812870591878891, -0.010809937492012978, -0.07895036041736603, 0.031172024086117744, -0.012692220509052277, 0.025331666693091393, 0.03630872443318367, -0.03425052389502525, -0.027002854272723198, 0.049748580902814865, -0.02142636850476265, 0.01048449520021677, -0.057312898337841034, -0.009736859239637852, -0.06589751690626144, -0.05302058532834053, 0.01463607419282198, 0.006895842961966991, 0.05115589499473572, -0.009077181108295918, 0.0321747362613678, -0.02290404960513115, 0.013914825394749641, -0.08148352801799774, 0.012041337788105011, -0.0020878834184259176, -0.02091621607542038, 0.05073370039463043, -0.012472327798604965, 0.01179505791515112, 0.03722347691655159, -0.06178112328052521, -0.01989591307938099, -0.035763390362262726, 0.018330276012420654, 0.03887707367539406, 0.007581908721476793, -0.011381658725440502, -0.0007525836117565632, 0.03425052389502525, 0.0020944802090525627, -0.03936963155865669, 0.018224727362394333, -0.04042511805891991, 0.01959685981273651, 0.006843068636953831, -0.0017976248636841774, -0.015665173530578613, -0.010862711817026138, 0.06741037964820862, -0.01716044545173645, -0.023431792855262756, -0.03863079100847244, 0.005400570575147867, 0.02825184538960457, 0.016799820587038994, -0.06938061863183975, 0.0019592461176216602, 0.008034888654947281, -0.03739939257502556, 0.06948617100715637, -0.03982701152563095, -0.0021736416965723038, 0.01744190789759159, -0.036625370383262634, -0.04436559975147247, -0.04911528900265694, -0.010616431012749672, -0.07508024573326111, 0.028937911614775658, -0.07916145771741867, 0.004325294401496649, 0.018453415483236313, -0.02568349614739418, 0.014855967834591866, -0.03388110548257828, -0.039123352617025375, 0.08085023611783981, 0.033670008182525635, -0.04689876735210419, 0.0020988781470805407, 0.0531965009868145, -0.03233305737376213, -0.020881034433841705, -0.006319723092019558, 0.03595689311623573, 0.015761926770210266, -0.07958365231752396, 0.00137433095369488, 0.024293772876262665, -0.018365459516644478, -0.02784724347293377, -0.10695593059062958, 0.04496371001005173, -0.039475180208683014, 0.00080975575838238, -0.0509096160531044, -0.02074030227959156, 0.009780838154256344, -0.04644139111042023, -0.005163086578249931, -0.0428527370095253, -0.013061640784144402, 0.0188756100833416, 0.037082746624946594, 0.004243934061378241, 0.013431061059236526, 0.06684745848178864, 0.04176206886768341, -0.04471743106842041, 0.03456716984510422, 0.011496002785861492, 0.0783170685172081, 0.013686137273907661, 0.01852378249168396, -0.01994868740439415, -0.001963644055649638, 0.02573627047240734, 0.05013559013605118, -0.06646044552326202, -0.0048728277906775475, -0.04257127270102501, -0.024469686672091484, 0.02313273772597313, 0.012665833346545696, -0.027759285643696785, -0.0224994458258152, -0.0050971186719834805, 0.03697719797492027, 0.02920178323984146, 0.012322800233960152, -0.029923031106591225, 0.02744263969361782, 0.06445501744747162, 0.007084950804710388, -0.04573773220181465, -0.014987902715802193, -0.01457450445741415, -0.014011578634381294, -0.039123352617025375, 0.06389209628105164, -0.05330204963684082, 0.03849006071686745, -0.002238510176539421, 0.007274058647453785, -0.016447992995381355, 0.05784064158797264, 0.00563805503770709, -0.001755845150910318, 0.014618483372032642, 0.015981819480657578, -0.019051523879170418, -0.005180677864700556, 0.0022604994010180235, 0.03403942659497261, 0.0369420163333416, -0.025665905326604843, -0.005558893550187349, -0.0343208909034729, -0.03143589571118355, 0.002088983077555895, 0.01709887571632862, -0.03461994603276253, -0.032368242740631104, -0.006095432210713625, 0.015955431386828423, 0.017705779522657394, -0.04904492199420929, -0.04130469262599945, 0.006508831400424242, -0.04426005110144615, -0.0021901337895542383, 0.01903393305838108, 0.03249138221144676, -0.05745362862944603, 0.021461552008986473, 0.024223407730460167, 0.05192991718649864, 0.022816091775894165, -0.03595689311623573, -0.03143589571118355, -0.029289741069078445, -0.011970971710979939, 0.04858754575252533, 0.021795788779854774, 0.008052479475736618, -0.019983870908617973, -0.0037755619268864393, -0.04777833819389343, 0.03358205035328865, -0.041339874267578125, 0.032755251973867416, -0.0351300984621048, 0.015445280820131302, -0.05506119504570961, 0.02176060527563095, -0.010194237343966961, -0.01796085573732853, -0.025595538318157196, -0.0008449386223219335, 0.015295753255486488, -0.0188052449375391, 0.004564977716654539, 0.006412078160792589, 0.004802461713552475, -0.08401669561862946, -0.01862933114171028, -0.01022941991686821, -0.057136982679367065, -0.020423656329512596, -0.06227368116378784, -0.06104228273034096, -0.04422486945986748, -0.013000071048736572, 0.015436484478414059, -0.026228830218315125, 0.05618704482913017, 0.014363407157361507, 0.03419775143265724, 0.04960784688591957 ]
30,782
networkx.classes.function
is_directed
Return True if graph is directed.
def is_directed(G): """Return True if graph is directed.""" return G.is_directed()
(G)
[ 0.03736710920929909, 0.029667746275663376, 0.008876861073076725, 0.03691522777080536, 0.006673939526081085, 0.009124526754021645, -0.04275492578744888, 0.011853194795548916, 0.09371323138475418, 0.001610913430340588, -0.018561894074082375, -0.044631969183683395, 0.022437645122408867, 0.031909774988889694, 0.00918535701930523, -0.022541925311088562, -0.04855986312031746, 0.04668281599879265, 0.018474994227290154, 0.02215956524014473, -0.035733383148908615, -0.015311825089156628, 0.02370638959109783, -0.05259203538298607, -0.011401313357055187, 0.019987057894468307, 0.027008598670363426, 0.007947028614580631, -0.027634281665086746, 0.07960063219070435, -0.030484609305858612, -0.0741780549287796, -0.011262273415923119, 0.03001534752547741, 0.047621339559555054, 0.07389997690916061, -0.035159844905138016, 0.050367388874292374, -0.1016385406255722, -0.050993070006370544, -0.06208154186606407, 0.015103264711797237, -0.01833595335483551, 0.03163169324398041, -0.007156236097216606, -0.01266136672347784, 0.012687437236309052, -0.004010446835309267, -0.04424960911273956, -0.04258112609386444, 0.028329482302069664, -0.031996674835681915, 0.008598780259490013, 0.04734325781464577, -0.013643340207636356, -0.00013184397539589554, 0.012000924907624722, 0.03182287514209747, -0.005161874927580357, 0.0011709809768944979, 0.022090045735239983, -0.016606638208031654, 0.022976428270339966, -0.026869559660553932, -0.008915966376662254, 0.005483406130224466, -0.06649607419967651, -0.011835814453661442, -0.0014544930309057236, 0.028624944388866425, -0.053356755524873734, 0.024731812998652458, -0.005861422047019005, 0.027842842042446136, -0.0035194603260606527, -0.005413885693997145, 0.029737267643213272, 0.02299380674958229, -0.014303782023489475, -0.033925861120224, -0.008915966376662254, -0.037610430270433426, 0.007108441088348627, 0.00024169133394025266, 0.012391976080834866, -0.032239995896816254, -0.010419340804219246, 0.027616901323199272, -0.015242304652929306, -0.06503614783287048, 0.01745826192200184, -0.020508460700511932, 0.025965796783566475, 0.010758251883089542, -0.02852066420018673, 0.04108643904328346, 0.00031609967118129134, -0.04730849713087082, 0.02203790470957756, -0.031127670779824257, -0.028677083551883698, 0.025062033906579018, -0.02299380674958229, 0.007994823157787323, -0.03034556843340397, -0.06746935844421387, -0.039139874279499054, -0.01676305942237377, -0.03210095316171646, -0.044666729867458344, -0.06614847481250763, 0.00404303427785635, 0.07466469705104828, 0.0032087918370962143, 0.018700934946537018, -0.0180404931306839, 0.04129499942064285, -0.011853194795548916, -0.06395858526229858, -0.0037888512015342712, -0.01830119453370571, 0.051410190761089325, -0.006878155283629894, -0.03310899809002876, 0.06833835691213608, -0.008246834389865398, 0.029824167490005493, -0.009480818174779415, -0.018857356160879135, -0.003467320231720805, 0.04497957229614258, 0.02012609876692295, -0.025218453258275986, 0.08516225218772888, 0.015146714635193348, -0.008016548119485378, -0.04584857448935509, 0.018770454451441765, 0.03646334633231163, 0.05530332401394844, -0.020091338083148003, -0.044875290244817734, 0.02374115027487278, 0.031040770933032036, 0.0012155172880738974, 0.016450218856334686, -0.04577905312180519, -0.015285754576325417, -0.014981604181230068, -0.01400832086801529, 0.078349269926548, -0.008199038915336132, 0.032239995896816254, -0.012982898391783237, -0.05401719734072685, 0.0007826454238966107, -0.05676324665546417, -0.001123185851611197, 0.02944180555641651, 0.011314413510262966, -0.0562070831656456, -0.027842842042446136, 0.004753443878144026, 0.046300455927848816, -0.0072257560677826405, -0.017953593283891678, 0.05711084604263306, 0.012061755172908306, -0.028538044542074203, 0.03420393913984299, -0.021690303459763527, -0.02706073969602585, -0.07355237752199173, 0.006135157775133848, 0.005322640761733055, 0.05825792998075485, 0.028746604919433594, 0.07605510205030441, 0.012148655951023102, -0.0010042410576716065, 0.017597300931811333, -0.030953871086239815, -0.035107702016830444, -0.006513174157589674, 0.03983507677912712, 0.001568549545481801, 0.005431266035884619, -0.020265139639377594, 0.026174357160925865, 0.011340483091771603, -0.015537765808403492, 0.017536470666527748, -0.015728946775197983, 0.014521032571792603, 0.02893778495490551, -0.055442363023757935, -0.009028936736285686, 0.004040861967951059, -0.051896832883358, 0.07125820964574814, 0.07737598568201065, -0.025340113788843155, -0.004597023595124483, 0.0106192110106349, -0.005161874927580357, 0.05766700953245163, -0.035941947251558304, -0.024262551218271255, 0.013495609164237976, -0.030675789341330528, -0.02693907916545868, -0.0626029446721077, 0.04595285654067993, 0.04445816949009895, -0.0075559769757092, 0.010210780426859856, -0.0328482948243618, 0.03031080961227417, -0.027912361547350883, -0.009993528947234154, 0.013547750189900398, -0.027251919731497765, -0.0023962745908647776, 0.0014501480618491769, 0.02765166200697422, -0.04842082038521767, 0.008820375427603722, -0.009028936736285686, -0.006647869478911161, -0.07077156752347946, 0.06402810662984848, -0.011583804152905941, 0.040182676166296005, 0.026504578068852425, 0.040356479585170746, -0.03583766520023346, 0.013217528350651264, 0.026035316288471222, 0.0010330267250537872, 0.029841547831892967, -0.031666453927755356, -0.02902468480169773, -0.03356087952852249, -0.007269206456840038, 0.034030139446258545, -0.004347185138612986, 0.005583341233432293, 0.003971341531723738, 0.019013775512576103, -0.027964502573013306, -0.07049348950386047, -0.06020449846982956, -0.032083574682474136, -0.040425997227430344, -0.01249625626951456, -0.023671628907322884, -0.06656559556722641, 0.007994823157787323, 0.017953593283891678, 0.007369141560047865, -0.03865323215723038, 0.0249056126922369, -0.05168827250599861, 0.11352649331092834, 0.01154035422950983, 0.019309235736727715, 0.0019389619119465351, 0.018110012635588646, 0.004197282250970602, -0.04963742569088936, 0.09871868789196014, 0.008698715828359127, 0.006978090386837721, -0.0066565596498548985, 0.033908478915691376, -0.00827724952250719, -0.0015772396000102162, 0.042094483971595764, 0.007447351701557636, -0.01068873144686222, -0.03288305550813675, 0.000994464848190546, -0.03844467177987099, -0.005374780856072903, -0.08314616233110428, 0.022611446678638458, -0.005483406130224466, -0.009837108664214611, 0.0014425442786887288, 0.0035324953496456146, 0.06538375467061996, 0.02494037337601185, 0.04011315852403641, 0.03962651640176773, 0.006087362766265869, 0.02308070845901966, 0.04796893894672394, -0.03171859309077263, 0.021342702209949493, 0.03712378814816475, 0.06733031570911407, -0.04070407897233963, 0.025705095380544662, -0.011670703999698162, -0.008199038915336132, 0.018857356160879135, -0.0028829160146415234, -0.017154110595583916, 0.016537118703126907, -0.0009618771728128195, -0.0720229297876358, 0.02308070845901966, -0.021151522174477577, 0.05766700953245163, -0.01625903695821762, 0.003243552055209875, -0.03771471232175827, -0.04751706123352051, 0.006474068854004145, 0.0498807467520237, -0.031666453927755356, 0.09426939487457275, -0.04796893894672394, 0.006721734534949064, -0.08773449808359146, 0.04814274236559868, 0.05061070993542671, 0.027999261394143105, 0.07038920372724533, 0.06319386512041092, 0.02565295435488224, -0.007343071512877941, 0.03990459814667702, 0.007338726427406073, -0.036393824964761734, 0.03439512103796005, 0.03246593475341797, -0.026209115982055664, 0.02075178176164627, -0.038687992841005325, -0.00003189171548001468, 0.006148193031549454, 0.010393270291388035, 0.003995239268988371, 0.03896607458591461, 0.05259203538298607, -0.027286680415272713, -0.014182121492922306, 0.04543145373463631, 0.019587317481637, -0.04744753986597061, 0.09517315775156021, -0.023271888494491577, 0.0248708538711071, -0.030623650178313255, 0.04073883965611458, 0.018318573012948036, 0.03684570640325546, -0.0206301212310791, 0.05825792998075485, 0.01266136672347784, -0.0001425707305315882, 0.023914949968457222, -0.006261163391172886, 0.022959047928452492, 0.018805215135216713, 0.015815846621990204, 0.005904872436076403, 0.05193159356713295, -0.04219876229763031, -0.02174244448542595, -0.01704983040690422, -0.049498386681079865, -0.02365424856543541, -0.008268559351563454, 0.01172284409403801, 0.03326541930437088, 0.0016978137427940965, 0.04956790432333946, 0.047829899936914444, -0.0180404931306839, 0.02024775929749012, 0.03566386550664902, 0.052070632576942444, 0.04730849713087082, -0.014460202306509018, 0.044006288051605225, 0.053739119321107864, -0.03269187733530998, -0.0455704927444458, -0.038687992841005325, -0.03441249951720238, 0.01187057513743639, -0.011410003527998924, -0.06048257648944855, -0.031996674835681915, 0.024088751524686813, 0.0045448835007846355, -0.05891837179660797, 0.012800407595932484, -0.011853194795548916, 0.033943239599466324, -0.005101045127958059, 0.019552556797862053, -0.010384580120444298, 0.033734679222106934, 0.011253583244979382, 0.02186410501599312, 0.022611446678638458, 0.0018694417085498571, 0.07087584584951401, 0.022055285051465034, -0.06413238495588303, -0.003534667892381549, 0.046126656234264374, -0.01432116236537695, 0.03389110043644905, 0.040634557604789734, 0.06666987389326096, 0.03900083526968956, 0.03858371451497078, 0.015164094045758247, 0.015911437571048737, -0.009854489006102085, 0.0021105899941176176, -0.019517797976732254, -0.012418046593666077, 0.05321771651506424, -0.05064546689391136, 0.04452769085764885, -0.024853473529219627, -0.03983507677912712, 0.06861644238233566, -0.026973839849233627, 0.01878783479332924, 0.009724138304591179, -0.00819469429552555, -0.020925581455230713, -0.009698068723082542, 0.05342627689242363, 0.022889526560902596, -0.004381945356726646, -0.06069113686680794, -0.03948747739195824, -0.006739114876836538, -0.052279192954301834, 0.008720440790057182, 0.006582694128155708, 0.07223149389028549, -0.012418046593666077, 0.0003780161205213517, 0.006495794281363487, 0.03538578376173973, -0.010401960462331772, -0.11151041090488434, 0.03580290451645851, 0.0037149859126657248, -0.006808634847402573, -0.0307626910507679, 0.03903559595346451, -0.017849313095211983, -0.012252936139702797, -0.09607692062854767, 0.003688915865495801, 0.0024723121896386147, -0.018700934946537018, 0.010584451258182526, 0.030380329117178917, -0.02843376435339451, -0.0035107703879475594, 0.06472331285476685, -0.023828050121665, -0.02956346608698368, -0.05276583507657051, 0.009480818174779415, 0.019900158047676086, -0.041016921401023865, 0.021846724674105644, -0.028294723480939865, 0.02096034213900566, -0.06392382830381393, -0.023045947775244713, 0.0024353796616196632, 0.028451142832636833, 0.025374874472618103, -0.030623650178313255, -0.046091895550489426, 0.02540963515639305, -0.004835999105125666, -0.008716095238924026, 0.03503818437457085, -0.04859462380409241, 0.024766571819782257, -0.046126656234264374, 0.0625334233045578, 0.036185264587402344, -0.04411057010293007, -0.0333523191511631, -0.0003810033085756004, 0.013017658144235611, -0.00020923951524309814, 0.020925581455230713, -0.047621339559555054, -0.012053065001964569, 0.03182287514209747, -0.02768642082810402, 0.013956180773675442, 0.01154035422950983, 0.0033760748337954283, 0.0508192703127861, 0.04310252517461777, 0.022541925311088562, 0.04345012828707695, 0.0677126795053482, 0.07688934355974197, 0.04171212390065193, -0.003962651826441288, -0.008203384466469288, 0.02693907916545868, -0.03562910482287407, 0.037818990647792816, -0.028259962797164917, -0.01143607310950756, 0.0014360267668962479, -0.05679800733923912, 0.06027401611208916, 0.00962854828685522, -0.002188800135627389, 0.0005632222746498883, -0.0007945942343212664, 0.02427993156015873, 0.055442363023757935, -0.007955718785524368, 0.08029583841562271, -0.01363465003669262, 0.038896553218364716, 0.020508460700511932, 0.035733383148908615, -0.08418896794319153, 0.00020733858400490135, -0.0024831746704876423, -0.05575520545244217, -0.005005454644560814, 0.03524674475193024, 0.03371730074286461, -0.015077194198966026, 0.05092354863882065, -0.01683257892727852, 0.008385874330997467, -0.028659703209996223, -0.06809504330158234, 0.018318573012948036, -0.05467763915657997, -0.04935934394598007, 0.09294851124286652, 0.03300471603870392, -0.003647638252004981, 0.08613553643226624, 0.023515209555625916, 0.007825368084013462, -0.05898789316415787, -0.06958972662687302, -0.009463437832891941, -0.013730240054428577, -0.004866414237767458, -0.03747139126062393, 0.02311546728014946, -0.020612740889191628, 0.03060626983642578, 0.022802626714110374, -0.0017227975185960531, -0.05526856333017349, 0.010575761087238789, -0.03010224923491478, 0.020195620134472847, 0.0402521975338459, -0.026869559660553932, 0.040425997227430344, -0.0249056126922369, -0.048003699630498886, -0.051896832883358, 0.009072386659681797, -0.0025918001774698496, 0.05638088658452034, 0.007955718785524368, 0.0022268190514296293, -0.036324307322502136, -0.011114542372524738, -0.02129056304693222, -0.02789498120546341, -0.03875751420855522, -0.0456400141119957, 0.040808361023664474, -0.03514246270060539, 0.008142554201185703, -0.01031506061553955, 0.027217159047722816, 0.004190764855593443, 0.025670334696769714, -0.020143479108810425, -0.03962651640176773, 0.028068782761693, 0.02598317712545395, -0.03844467177987099, 0.011175372637808323, -0.014425442554056644, -0.00506193982437253, -0.05547712370753288, 0.0033934549428522587, -0.06920736283063889, -0.02215956524014473, 0.04796893894672394, -0.031614311039447784, -0.06649607419967651, 0.02753000147640705, -0.01700638048350811, -0.04000887647271156, 0.0424768440425396, -0.020717021077871323, 0.028346862643957138, 0.0328482948243618, -0.03747139126062393, 0.004273320082575083, -0.02282000705599785, -0.010132569819688797, 0.01118406280875206, 0.01592881605029106, -0.05165351182222366, -0.004505778197199106, -0.017953593283891678, -0.007695017382502556, -0.05210539326071739, -0.012991588562726974, -0.01609392650425434, 0.0006555538275279105, -0.1082429587841034, -0.020317278802394867, -0.0015055469702929258, 0.00925487745553255, 0.05575520545244217, -0.12054803222417831, 0.03774946928024292, -0.03788851201534271, -0.01917019672691822, -0.009698068723082542, -0.011601184494793415, 0.021846724674105644, -0.0307626910507679, 0.036115746945142746, -0.04709993675351143, -0.013087178580462933, 0.07028492540121078, 0.028068782761693, -0.023636870086193085, 0.029459185898303986, 0.0508192703127861, 0.0071866512298583984, 0.006209023296833038, 0.005431266035884619, -0.06302006542682648, 0.042928725481033325, 0.0013241426786407828, 0.03427346050739288, 0.009350467473268509, 0.007060645613819361, 0.05724988877773285, -0.026452437043190002, -0.02753000147640705, 0.009663308039307594, -0.06910308450460434, -0.07115393131971359, 0.04046075791120529, 0.04536193236708641, -0.024592772126197815, -0.005174910183995962, -0.03097125142812729, 0.033161137253046036, -0.004631783813238144, 0.0065175192430615425, -0.027790701016783714, -0.021690303459763527, 0.022229084745049477, -0.028259962797164917, -0.03163169324398041, -0.020942961797118187, -0.01625903695821762, -0.03093649074435234, -0.04678709805011749, 0.030710550025105476, 0.007664602715522051, -0.04324156790971756, -0.0227852463722229, 0.06041305884718895, -0.0005491009796969593, 0.07522086054086685, -0.0097936587408185, -0.03460368141531944, 0.06621799618005753, -0.028381623327732086, -0.008959416300058365, 0.0185097549110651, -0.0021084174513816833, 0.0066956644877791405, 0.032830916345119476, 0.01845761388540268, -0.05933549255132675, -0.058153651654720306, 0.046752337366342545, -0.016415458172559738, 0.0009982666233554482, -0.06580087542533875, -0.0055876863189041615, 0.01220079604536295, -0.024088751524686813, 0.0018987705698236823, -0.04859462380409241, -0.019900158047676086, -0.005887492094188929, -0.03472534194588661, -0.027338819578289986, -0.010306370444595814, -0.036185264587402344, -0.025461774319410324, 0.036532867699861526, -0.0011063488200306892, -0.015120644122362137, -0.015529075637459755, -0.029997967183589935, 0.018944256007671356, -0.02195100486278534, -0.03559434413909912, 0.051896832883358, -0.00436456548050046, 0.05509475991129875, -0.09482555836439133, 0.027217159047722816, -0.011974855326116085, 0.05061070993542671, -0.030484609305858612, 0.025305354967713356, 0.02669575810432434, 0.008020893670618534, 0.017145419493317604, -0.0445624515414238, 0.015250994823873043, -0.034829623997211456, -0.007942683063447475, 0.039278917014598846, -0.04112119972705841, -0.052244432270526886, 0.09197522699832916, 0.01436461228877306, 0.030953871086239815, -0.05825792998075485, 0.027634281665086746, 0.04258112609386444, -0.00869002565741539, -0.03142313286662102, 0.012704817578196526, -0.0784187912940979, -0.059265974909067154, -0.032657116651535034, 0.003791023511439562, -0.03366515785455704, -0.057145606726408005, 0.02640029788017273, -0.0031066841911524534, 0.05950929597020149 ]
30,783
networkx.algorithms.dag
is_directed_acyclic_graph
Returns True if the graph `G` is a directed acyclic graph (DAG) or False if not. Parameters ---------- G : NetworkX graph Returns ------- bool True if `G` is a DAG, False otherwise Examples -------- Undirected graph:: >>> G = nx.Graph([(1, 2), (2, 3)]) >>> nx.is_directed_acyclic_graph(G) False Directed graph with cycle:: >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)]) >>> nx.is_directed_acyclic_graph(G) False Directed acyclic graph:: >>> G = nx.DiGraph([(1, 2), (2, 3)]) >>> nx.is_directed_acyclic_graph(G) True See also -------- topological_sort
def transitive_closure_dag(G, topo_order=None): """Returns the transitive closure of a directed acyclic graph. This function is faster than the function `transitive_closure`, but fails if the graph has a cycle. The transitive closure of G = (V,E) is a graph G+ = (V,E+) such that for all v, w in V there is an edge (v, w) in E+ if and only if there is a non-null path from v to w in G. Parameters ---------- G : NetworkX DiGraph A directed acyclic graph (DAG) topo_order: list or tuple, optional A topological order for G (if None, the function will compute one) Returns ------- NetworkX DiGraph The transitive closure of `G` Raises ------ NetworkXNotImplemented If `G` is not directed NetworkXUnfeasible If `G` has a cycle Examples -------- >>> DG = nx.DiGraph([(1, 2), (2, 3)]) >>> TC = nx.transitive_closure_dag(DG) >>> TC.edges() OutEdgeView([(1, 2), (1, 3), (2, 3)]) Notes ----- This algorithm is probably simple enough to be well-known but I didn't find a mention in the literature. """ if topo_order is None: topo_order = list(topological_sort(G)) TC = G.copy() # idea: traverse vertices following a reverse topological order, connecting # each vertex to its descendants at distance 2 as we go for v in reversed(topo_order): TC.add_edges_from((v, u) for u in nx.descendants_at_distance(TC, v, 2)) return TC
(G, *, backend=None, **backend_kwargs)
[ -0.032719120383262634, 0.02121465466916561, -0.024732839316129684, 0.007946699857711792, -0.03627248480916023, -0.031065572053194046, -0.018945425748825073, -0.012603897601366043, 0.09302080422639847, -0.07761115580797195, 0.01216412428766489, 0.028215842321515083, 0.00047687895130366087, -0.011759532615542412, -0.031628482043743134, 0.022358065471053123, -0.014019967056810856, -0.017283083871006966, 0.0031113948207348585, 0.02939443476498127, 0.0009158275206573308, -0.06413651257753372, 0.013457057066261768, -0.02385329268872738, -0.015717491507530212, 0.016544263809919357, -0.04700294882059097, 0.0320858471095562, -0.060583144426345825, -0.03134702891111374, 0.03117111697793007, -0.04538458585739136, -0.09055808186531067, 0.013465852476656437, 0.05263204500079155, 0.08098861575126648, -0.00045076743117533624, 0.01811865158379078, -0.017230309545993805, -0.060407232493162155, 0.012190510518848896, -0.018435288220643997, -0.011522055603563786, -0.03243766352534294, 0.0458771288394928, 0.013404284603893757, -0.009138485416769981, 0.03806675970554352, -0.03736312314867973, -0.04950086027383804, 0.08640661835670471, -0.03718721494078636, -0.0057874140329658985, -0.010624918155372143, 0.01527771819382906, 0.039051853120326996, 0.019525926560163498, 0.05945732444524765, 0.06814724206924438, -0.017775628715753555, -0.009921281598508358, -0.055165138095617294, -0.009032939560711384, 0.03548089414834976, -0.05097850039601326, 0.02121465466916561, -0.036800213158130646, -0.06012577936053276, -0.021144291386008263, 0.0073090288788080215, -0.013720921240746975, 0.020229563117027283, 0.005602709483355284, -0.07606315612792969, -0.02731870487332344, -0.07641497254371643, 0.027951978147029877, -0.04524385556578636, -0.02855006977915764, -0.03518185019493103, -0.034372664988040924, -0.06842869520187378, 0.023431111127138138, -0.008236950263381004, 0.06135714426636696, -0.028022343292832375, 0.033756982535123825, -0.0014820353826507926, -0.06768987327814102, -0.04074057936668396, 0.007810370530933142, -0.03433748334646225, -0.031188709661364555, 0.032719120383262634, 0.03739830479025841, -0.008830644190311432, -0.0009653019951656461, -0.048515770584344864, 0.010079599916934967, 0.009982849471271038, 0.038911122828722, 0.0075377109460532665, -0.08542152494192123, -0.0062755621038377285, 0.023202428594231606, -0.04534940421581268, -0.017476582899689674, 0.016799332574009895, -0.01732706092298031, -0.08753243833780289, -0.0024121555034071207, -0.0012995295692235231, 0.09773517400026321, -0.038875941187143326, 0.031628482043743134, 0.013096443377435207, 0.007761995308101177, 0.0006920929299667478, -0.00040569069096818566, -0.005659880116581917, 0.014151898212730885, 0.022217337042093277, 0.0010757949203252792, 0.012700647115707397, -0.007265051826834679, 0.008043450303375721, 0.009384757839143276, 0.027652932330965996, 0.034425437450408936, -0.010853600688278675, 0.06100532412528992, -0.01369453500956297, 0.03329962119460106, 0.08169225603342056, 0.051682136952877045, 0.003786446526646614, -0.03236730024218559, 0.015392058528959751, -0.02029992640018463, 0.022727474570274353, -0.01018514484167099, -0.06135714426636696, -0.02158406376838684, 0.049360133707523346, 0.049852680414915085, 0.003960156813263893, -0.0057874140329658985, -0.013245966285467148, 0.01191785093396902, 0.019244471564888954, 0.008527200669050217, 0.003850213484838605, -0.014811558648943901, 0.03263116627931595, 0.00012416718527674675, -0.007814767770469189, -0.04366067424416542, 0.07247460633516312, -0.0536523200571537, 0.012040987610816956, -0.031259071081876755, 0.04724922403693199, -0.040107306092977524, 0.02476802095770836, 0.01670258305966854, -0.0018371521728113294, 0.1141299158334732, 0.006240380462259054, -0.031487755477428436, 0.03139980137348175, -0.05678350478410721, -0.030713753774762154, -0.007326620165258646, -0.004815515596419573, -0.00616122130304575, 0.029922163113951683, 0.003839219221845269, 0.030590618029236794, -0.016069309785962105, 0.02183033712208271, -0.016482695937156677, 0.0005914948415011168, -0.045771583914756775, 0.021249836310744286, 0.032420072704553604, 0.030995208770036697, 0.0412331260740757, -0.04007212445139885, 0.07697788625955582, -0.020968381315469742, -0.05498922988772392, 0.012753420509397984, 0.037890851497650146, 0.023255201056599617, 0.07528915256261826, -0.05590395629405975, -0.03001011721789837, 0.03715203329920769, -0.04770658537745476, 0.07163024693727493, 0.06396060436964035, 0.015049035660922527, 0.07191170006990433, 0.033387575298547745, 0.023677384480834007, 0.08155152201652527, 0.034302301704883575, -0.033018164336681366, -0.023800520226359367, 0.0086019616574049, -0.012920534238219261, -0.025577204301953316, 0.010660099796950817, -0.039861034601926804, -0.05175250023603439, 0.03226175531744957, -0.03831303492188454, 0.013553807511925697, 0.04812876880168915, 0.0018855271628126502, -0.026333613321185112, 0.03708167001605034, 0.02568274922668934, -0.01694885641336441, 0.07046924531459808, -0.0775407925248146, -0.0003512687690090388, 0.011258191429078579, 0.02024715393781662, -0.05956286936998367, 0.011064691469073296, -0.007159505970776081, 0.032842256128787994, -0.01970183476805687, 0.06202559918165207, -0.04439949244260788, -0.03511148318648338, 0.003170764073729515, 0.018945425748825073, 0.017889970913529396, -0.05066186189651489, -0.006020493805408478, -0.024592112749814987, 0.010598531924188137, -0.017028015106916428, -0.0051409476436674595, 0.02657988667488098, 0.006007300689816475, 0.03252561762928963, 0.026368794962763786, -0.05129513517022133, -0.035639211535453796, -0.048691678792238235, -0.029623117297887802, -0.031065572053194046, -0.012489556334912777, -0.0040788957849144936, -0.05678350478410721, -0.005343243479728699, 0.017300674691796303, 0.00032900527003221214, 0.017212718725204468, -0.057663049548864365, 0.06923788040876389, 0.008843837305903435, -0.02951757051050663, 0.03428471088409424, -0.08183298259973526, -0.06688069552183151, -0.0055279480293393135, -0.01653546839952469, 0.003927174024283886, 0.04401249438524246, 0.005347641184926033, 0.0037534635048359632, -0.04091649129986763, 0.01555037684738636, 0.016113286837935448, -0.0030036503449082375, -0.029974935576319695, -0.04183121770620346, 0.029253706336021423, -0.031188709661364555, -0.023079292848706245, -0.0627996027469635, -0.0064030964858829975, -0.011275782249867916, -0.026843750849366188, 0.022094201296567917, 0.01848806068301201, 0.07648533582687378, 0.002709002234041691, 0.07296715676784515, 0.024803202599287033, 0.06301069259643555, 0.035392940044403076, 0.02640397660434246, -0.025401294231414795, -0.00243854196742177, 0.033018164336681366, 0.07360042631626129, 0.009534280747175217, -0.01634196937084198, -0.05175250023603439, 0.0017843793611973524, 0.004586833529174328, 0.009833326563239098, -0.007973086088895798, -0.02939443476498127, 0.0401424877345562, -0.05164695531129837, -0.049923043698072433, -0.07029333710670471, 0.04506794735789299, -0.06920269876718521, -0.03416157513856888, -0.03266634792089462, -0.049360133707523346, 0.054426319897174835, 0.01179471518844366, 0.0023923655971884727, 0.015699900686740875, -0.008474428206682205, -0.006552619393914938, -0.07655569911003113, 0.0468270406126976, 0.009718985296785831, 0.05780377611517906, 0.05854259431362152, 0.010281895287334919, -0.005783016327768564, 0.03859448805451393, 0.0052420953288674355, 0.05710013955831528, -0.003096002619713545, 0.0708562433719635, 0.09660935401916504, -0.02999252639710903, 0.01527771819382906, -0.028198251500725746, 0.0455956757068634, 0.04190158098936081, -0.02884911559522152, 0.009701394475996494, -0.012340033426880836, 0.010000440292060375, 0.002994854934513569, -0.0013698932016268373, 0.037046488374471664, -0.022762656211853027, 0.04309776425361633, 0.03806675970554352, -0.01811865158379078, 0.027283523231744766, -0.03915739804506302, 0.06575487554073334, 0.049113862216472626, -0.008645939640700817, 0.014952285215258598, 0.02786402404308319, 0.003362065413966775, -0.02212938293814659, 0.019437970593571663, -0.03627248480916023, 0.05523550137877464, 0.0032103436533361673, -0.00899775791913271, 0.03743348643183708, -0.020968381315469742, -0.04457540065050125, 0.017063196748495102, -0.011293373070657253, 0.04063503444194794, 0.009270417504012585, -0.0513303168118, 0.03050266206264496, 0.04784731566905975, -0.054074499756097794, 0.05298386514186859, 0.03606139495968819, -0.019895335659384727, 0.017643697559833527, -0.008017064072191715, 0.03134702891111374, 0.02042306400835514, 0.015233740210533142, 0.0435551293194294, 0.008641541935503483, 0.02353665605187416, -0.027846433222293854, -0.005576322786509991, -0.027054840698838234, 0.04541976749897003, -0.003964554518461227, 0.0003606139507610351, -0.03431989252567291, 0.06614187359809875, 0.044610582292079926, 0.025753112509846687, 0.002924491185694933, -0.0145740807056427, 0.007630063220858574, 0.021988654509186745, 0.008962576277554035, 0.023677384480834007, -0.033387575298547745, 0.012172919698059559, 0.03683539479970932, 0.06177932769060135, 0.04883240535855293, -0.0036830997560173273, 0.006319539621472359, 0.03206825628876686, -0.0172039233148098, -0.020159199833869934, -0.019737016409635544, -0.07110251486301422, 0.0030410310719162226, 0.05861296132206917, 0.002311007585376501, 0.04897313192486763, 0.029007434844970703, 0.028374161571264267, -0.03898148983716965, 0.0046527995727956295, -0.03407362103462219, 0.03139980137348175, 0.03919257968664169, -0.010352258570492268, 0.09196535497903824, 0.010712873190641403, -0.0320858471095562, 0.01320198830217123, -0.03333480283617973, 0.00012389232870191336, 0.020950790494680405, 0.014169489964842796, 0.00820176862180233, 0.03996657952666283, 0.06617705523967743, -0.007691631559282541, 0.040212854743003845, -0.02524297684431076, -0.06086459755897522, -0.012005805969238281, -0.02944720722734928, 0.009024144150316715, 0.03293021023273468, 0.049113862216472626, -0.02227010950446129, 0.046264130622148514, 0.04654558748006821, -0.006746119353920221, -0.011583623476326466, -0.08506970852613449, 0.05006377026438713, 0.024644885212183, -0.005347641184926033, -0.1187739223241806, 0.01021153200417757, 0.008579973131418228, -0.03213861957192421, 0.05963323265314102, -0.04534940421581268, -0.016377151012420654, -0.022234927862882614, 0.002658428391441703, 0.0009548573871143162, -0.04084612801671028, -0.032543208450078964, 0.05140068009495735, -0.03275430202484131, -0.059246234595775604, -0.04397730901837349, 0.04489203914999962, 0.015145786106586456, -0.05312459170818329, 0.03333480283617973, 0.057346414774656296, -0.033387575298547745, 0.02066933549940586, -0.02957034297287464, 0.003522582584992051, 0.011135054752230644, 0.002658428391441703, 0.0009592550923116505, 0.015224944800138474, -0.02042306400835514, 0.011196623556315899, -0.0004318022110965103, 0.0016249616164714098, -0.022956157103180885, -0.005967720877379179, -0.011513260193169117, 0.006209596060216427, 0.03901667147874832, -0.015840627253055573, -0.03599103167653084, 0.009402348659932613, 0.006170016713440418, -0.0016007741214707494, 0.042112674564123154, -0.01817142404615879, 0.02109151892364025, -0.000988390063866973, -0.03623730316758156, 0.009578258730471134, 0.0262808408588171, 0.012744625099003315, 0.013958398252725601, 0.04105721786618233, 0.02281542867422104, 0.008716302923858166, 0.034056030213832855, 0.010132372379302979, 0.014741194434463978, -0.023272793740034103, 0.004903470166027546, 0.024310657754540443, -0.029552752152085304, 0.0041800434701144695, 0.013149215839803219, 0.020686926320195198, 0.08049607276916504, -0.01131096389144659, -0.012973306700587273, 0.02140815556049347, -0.03419675678014755, -0.006939619779586792, -0.0030388322193175554, 0.0004485685785766691, 0.03236730024218559, -0.013914421200752258, 0.05731123313307762, -0.0036215316504240036, -0.05277277156710625, -0.007990676909685135, -0.024486565962433815, -0.11624082922935486, 0.0006970403483137488, 0.014037557877600193, 0.04816395044326782, 0.015893399715423584, 0.013272352516651154, 0.03915739804506302, -0.010774441063404083, 0.04615858569741249, -0.04084612801671028, -0.028127888217568398, -0.010844805277884007, -0.07901842892169952, 0.031083162873983383, -0.012727033346891403, 0.02531334012746811, 0.03634284809231758, -0.03423193842172623, -0.027002068236470222, 0.049782317131757736, -0.021478518843650818, 0.01043141819536686, -0.05731123313307762, -0.009710189886391163, -0.06589560210704803, -0.053019046783447266, 0.014582876116037369, 0.006847267504781485, 0.05122477188706398, -0.009068121202290058, 0.03212102875113487, -0.022903382778167725, 0.013923216611146927, -0.08141079545021057, 0.012058578431606293, -0.002079027472063899, -0.020968381315469742, 0.050767406821250916, -0.012445579282939434, 0.01180351059883833, 0.03718721494078636, -0.06163859739899635, -0.019842563197016716, -0.035762347280979156, 0.01822419837117195, 0.038911122828722, 0.007612472400069237, -0.011354941874742508, -0.0006898940773680806, 0.03431989252567291, 0.002115308539941907, -0.03943885117769241, 0.018259380012750626, -0.04038876295089722, 0.019596289843320847, 0.0068604606203734875, -0.0017821805085986853, -0.015655921772122383, -0.010862396098673344, 0.06737323850393295, -0.01726549305021763, -0.023501474410295486, -0.03866485133767128, 0.005488368216902018, 0.02818066067993641, 0.01683451421558857, -0.06937860697507858, 0.0019415982533246279, 0.008012666366994381, -0.03732794150710106, 0.0694841518998146, -0.039861034601926804, -0.002166982041671872, 0.01737103797495365, -0.0365891233086586, -0.044364310801029205, -0.04904349520802498, -0.010572145693004131, -0.07507806271314621, 0.02897225320339203, -0.07915916293859482, 0.0042811911553144455, 0.01834733411669731, -0.02568274922668934, 0.01482035405933857, -0.03395048528909683, -0.039051853120326996, 0.08077752590179443, 0.033686619251966476, -0.04700294882059097, 0.0021636837627738714, 0.05319495499134064, -0.03233211860060692, -0.02086283639073372, -0.006253573577851057, 0.03593825921416283, 0.015840627253055573, -0.07958134263753891, 0.0013237170642241836, 0.02432824857532978, -0.01834733411669731, -0.027899205684661865, -0.10695281624794006, 0.04499758407473564, -0.03940366953611374, 0.0007652051863260567, -0.050837770104408264, -0.020704517140984535, 0.009780554100871086, -0.046440038830041885, -0.005158538464456797, -0.04288667440414429, -0.013087647967040539, 0.018875062465667725, 0.03708167001605034, 0.0042657991871237755, 0.01338669378310442, 0.06695105880498886, 0.04176085442304611, -0.04475131258368492, 0.034601349383592606, 0.011486873961985111, 0.07824443280696869, 0.01365935243666172, 0.01847046986222267, -0.019842563197016716, -0.001994370948523283, 0.025753112509846687, 0.05006377026438713, -0.06645850837230682, -0.004859492648392916, -0.04257003590464592, -0.024486565962433815, 0.023149656131863594, 0.01268305629491806, -0.027846433222293854, -0.02244601957499981, -0.005044197663664818, 0.03711685165762901, 0.029200933873653412, 0.012348828837275505, -0.029904570430517197, 0.027371477335691452, 0.06448832899332047, 0.007128722034394741, -0.045771583914756775, -0.01503144484013319, -0.01451251283288002, -0.014099125750362873, -0.039122216403484344, 0.06381987035274506, -0.053265318274497986, 0.03848894312977791, -0.0022890190593898296, 0.00731782428920269, -0.01640353724360466, 0.05787413939833641, 0.005624698009341955, -0.0016458508325740695, 0.01463564857840538, 0.0159725584089756, -0.019121333956718445, -0.005176129285246134, 0.002228550147265196, 0.03398566693067551, 0.03694093972444534, -0.025700340047478676, -0.005637891124933958, -0.034302301704883575, -0.03141739219427109, 0.0020823257509618998, 0.017124764621257782, -0.03458375856280327, -0.03243766352534294, -0.006095255259424448, 0.015954967588186264, 0.01780201494693756, -0.04904349520802498, -0.04126830771565437, 0.006477857939898968, -0.04429394751787186, -0.0021603854838758707, 0.018998198211193085, 0.03245525434613228, -0.05745195969939232, 0.021548882126808167, 0.024222703650593758, 0.05203395336866379, 0.022903382778167725, -0.03592066839337349, -0.03145257383584976, -0.029288889840245247, -0.011900260113179684, 0.04862131550908089, 0.021742383018136024, 0.0079862792044878, -0.019965698942542076, -0.003854611190035939, -0.04774176701903343, 0.0336514376103878, -0.04133867099881172, 0.032771892845630646, -0.035093892365694046, 0.015418444760143757, -0.05495404824614525, 0.02175997383892536, -0.01021153200417757, -0.018083469942212105, -0.025647567585110664, -0.0008784467936493456, 0.015260126441717148, -0.018822288140654564, 0.004622015170753002, 0.006416289601475, 0.00480232248082757, -0.08401425182819366, -0.01854083500802517, -0.010264304466545582, -0.05713532119989395, -0.020440654829144478, -0.062307052314281464, -0.06100532412528992, -0.04429394751787186, -0.012982102110981941, 0.015436036512255669, -0.026316022500395775, 0.05607986822724342, 0.014292625710368156, 0.03419675678014755, 0.04957122355699539 ]
30,787
networkx.classes.function
is_empty
Returns True if `G` has no edges. Parameters ---------- G : graph A NetworkX graph. Returns ------- bool True if `G` has no edges, and False otherwise. Notes ----- An empty graph can have nodes but not edges. The empty graph with zero nodes is known as the null graph. This is an $O(n)$ operation where n is the number of nodes in the graph.
def is_empty(G): """Returns True if `G` has no edges. Parameters ---------- G : graph A NetworkX graph. Returns ------- bool True if `G` has no edges, and False otherwise. Notes ----- An empty graph can have nodes but not edges. The empty graph with zero nodes is known as the null graph. This is an $O(n)$ operation where n is the number of nodes in the graph. """ return not any(G._adj.values())
(G)
[ 0.027003008872270584, 0.011737627908587456, -0.03845435380935669, 0.0015168414684012532, -0.01764800027012825, 0.041557300835847855, -0.053821321576833725, -0.010038396343588829, 0.06915134936571121, -0.009341157041490078, -0.0003815190866589546, 0.002242939779534936, 0.051494110375642776, 0.0014591229846701026, -0.018710019066929817, 0.014563524164259434, -0.024694271385669708, -0.010786428116261959, 0.06904052942991257, 0.007166325580328703, -0.04067074507474899, -0.065863698720932, -0.007480314001441002, -0.0050099631771445274, -0.01780499331653118, -0.012171670794487, 0.016863027587532997, -0.01577330380678177, 0.013658499345183372, 0.05071837455034256, -0.01640128158032894, -0.025783995166420937, -0.03767861798405647, 0.018543791025877, 0.05725672468543053, 0.06180031970143318, 0.02746475674211979, 0.02886847034096718, -0.10926799476146698, -0.031712837517261505, 0.021702144294977188, -0.005601000506430864, -0.024103233590722084, 0.00871318019926548, 0.03224846348166466, -0.03176824748516083, 0.05644404888153076, 0.06590063869953156, 0.0011330136330798268, -0.026910660788416862, 0.05116165429353714, 0.015579369850456715, -0.023087387904524803, 0.05633322894573212, -0.03215611353516579, 0.044069208204746246, 0.0214435663074255, 0.013575384393334389, -0.02646738290786743, 0.01549625489860773, -0.03295031934976578, 0.013242926448583603, 0.028886940330266953, -0.027963444590568542, 0.026929130777716637, 0.035480696707963943, -0.0415942408144474, -0.03167589753866196, -0.007314084563404322, -0.028536012396216393, -0.037826377898454666, 0.018682314082980156, -0.026522791013121605, 0.05895595625042915, -0.04118790104985237, -0.010906482115387917, 0.020150672644376755, 0.06331485509872437, -0.04447554424405098, -0.03985806554555893, 0.014711284078657627, -0.05119859427213669, -0.0451035238802433, 0.01460969913750887, 0.047135211527347565, -0.011460579931735992, -0.0007693872321397066, 0.05108777433633804, -0.00515310512855649, -0.017287837341427803, 0.04207445681095123, 0.016419751569628716, 0.04211139678955078, -0.05921453237533569, 0.03790025785565376, -0.01443423517048359, -0.023937003687024117, -0.023105857893824577, -0.02755710668861866, -0.04587925970554352, -0.05020121857523918, -0.0001056969485944137, -0.013409155420958996, 0.014655874110758305, -0.04096626117825508, -0.013464565388858318, -0.000017784503143047914, -0.029995135962963104, -0.011081946082413197, -0.025636235252022743, 0.0025696263182908297, -0.012097791768610477, 0.07033342123031616, -0.013316805474460125, 0.039303969591856, 0.0038094189949333668, 0.046839695423841476, 0.013381450437009335, -0.058919016271829605, -0.02347525581717491, 0.0050699906423687935, 0.03389228507876396, -0.02334596775472164, -0.02439875155687332, 0.08237580209970474, -0.03093709982931614, 0.01781422831118107, -0.01799892820417881, 0.0010631742188706994, -0.03291337937116623, 0.060581307858228683, 0.048686683177948, -0.006713812705129385, 0.035443760454654694, -0.04957323893904686, -0.030826281756162643, -0.010823368094861507, -0.02672596089541912, 0.0075311060063540936, 0.030087484046816826, -0.015727128833532333, -0.08658694475889206, 0.005277777090668678, 0.08488771319389343, 0.042887132614851, 0.017287837341427803, -0.006727665197104216, -0.03542529046535492, 0.03871293365955353, 0.00735102454200387, 0.026559730991721153, -0.00234914175234735, 0.0009263814426958561, -0.03564692661166191, -0.04554679989814758, 0.005577913019806147, 0.0002545384631957859, 0.0077573624439537525, -0.005522503517568111, -0.038528233766555786, -0.023272087797522545, 0.04791094735264778, 0.01511762198060751, 0.03163895756006241, -0.0176849402487278, -0.0034446383360773325, 0.011986971832811832, -0.004130333662033081, -0.008768590167164803, 0.030863221734762192, 0.033245839178562164, -0.04994263872504234, -0.03621949627995491, -0.034612610936164856, 0.007147855591028929, 0.03309807926416397, 0.0008363406523130834, 0.03952560946345329, -0.03893457353115082, 0.010500144213438034, 0.0056194704957306385, -0.04864974319934845, -0.0532672218978405, 0.0037239957600831985, 0.03882375359535217, -0.011497518979012966, -0.008934819139540195, -0.03978418931365013, -0.011358994990587234, -0.023013507947325706, -0.048501987010240555, -0.02052007056772709, -0.021295806393027306, 0.05607464909553528, 0.042222216725349426, -0.02567317523062229, 0.008662387728691101, 0.06305627524852753, -0.034834250807762146, 0.019485756754875183, 0.024860499426722527, -0.06065518781542778, 0.0015618618344888091, -0.04506658390164375, -0.018359091132879257, 0.019633514806628227, -0.06741517782211304, -0.04576843976974487, -0.019319526851177216, -0.03719840198755264, -0.04957323893904686, -0.04307183250784874, 0.028240494430065155, 0.008052880875766277, 0.004282710608094931, 0.0670827180147171, -0.03182365745306015, 0.016170406714081764, -0.023309027776122093, -0.026005635038018227, -0.02962573617696762, -0.0416681170463562, -0.0011076175142079592, -0.017694175243377686, 0.0532672218978405, -0.0008224882185459137, 0.0440322682261467, 0.042702432721853256, -0.003740157000720501, -0.04466024413704872, 0.06409058719873428, 0.054523177444934845, 0.0026227273046970367, -0.013861668296158314, 0.005545590538531542, -0.016290461644530296, 0.0330796092748642, 0.010380090214312077, 0.030974039807915688, -0.010795663110911846, 0.00506537314504385, -0.04048604518175125, -0.05910371616482735, -0.03549916669726372, 0.02870224043726921, -0.005813404452055693, -0.05404295772314072, 0.030401473864912987, 0.04842810705304146, 0.02175755426287651, -0.07240205258131027, -0.036016326397657394, -0.008634683676064014, -0.07151549309492111, 0.02035384252667427, -0.05481869354844093, -0.07698258757591248, -0.0001201987179229036, 0.007272527553141117, 0.005554825533181429, 0.022274712100625038, 0.0031006361823529005, -0.04011664539575577, 0.14465634524822235, 0.03067852184176445, 0.03248857334256172, 0.04144648090004921, -0.011977736838161945, -0.017915813252329826, -0.03165742754936218, 0.166820228099823, -0.02184990420937538, 0.0306415818631649, -0.03361523896455765, 0.057552240788936615, 0.0330796092748642, 0.008528481237590313, -0.020889468491077423, 0.05814328044652939, -0.002825896255671978, -0.008403809741139412, -0.012245550751686096, -0.016899967566132545, 0.030253713950514793, -0.04772625118494034, 0.046396415680646896, -0.03444638475775719, -0.03169436752796173, 0.025045199319720268, -0.024675801396369934, 0.07942061871290207, 0.04558373987674713, 0.022034604102373123, 0.06793233007192612, -0.024842029437422752, 0.032322343438863754, 0.08385339379310608, -0.013381450437009335, -0.004954553674906492, 0.029034700244665146, 0.07406434416770935, -0.038306593894958496, -0.0295703262090683, -0.03841741383075714, 0.008694710209965706, 0.024842029437422752, 0.03524059057235718, 0.023142797872424126, 0.039045389741659164, 0.004894526209682226, -0.06298239529132843, -0.002341061132028699, 0.01809127815067768, 0.027889564633369446, 0.002846674993634224, 0.02096334844827652, 0.019042478874325752, -0.06534654647111893, 0.020501600578427315, -0.023973943665623665, -0.022625640034675598, 0.06863418966531754, 0.007235587574541569, 0.009027169086039066, -0.13704673945903778, 0.05921453237533569, 0.021000288426876068, 0.04761543124914169, 0.006940069142729044, 0.01987362466752529, 0.03657042235136032, -0.06235441938042641, 0.03363370895385742, 0.00718479510396719, -0.025119079276919365, 0.03213764354586601, 0.007327937055379152, 0.016198111698031425, 0.0014521967386826873, -0.007651160471141338, 0.009724408388137817, 0.04835422709584236, 0.009419654496014118, -0.01676144450902939, 0.03860211372375488, 0.0015653249574825168, -0.012735003605484962, -0.022995037958025932, 0.008667005226016045, -0.008810147643089294, -0.0052454546093940735, 0.07816465944051743, 0.02526683732867241, -0.021702144294977188, 0.04820646718144417, 0.008131378330290318, 0.027224648743867874, 0.040633805096149445, -0.007050888612866402, 0.08710409700870514, 0.01643821969628334, 0.029607266187667847, -0.0347973108291626, -0.027261588722467422, -0.005808786954730749, -0.022219302132725716, 0.035406820476055145, 0.029958195984363556, -0.043847568333148956, -0.007743509951978922, 0.001811205642297864, -0.03989500552415848, -0.06992708146572113, -0.011460579931735992, -0.01167298387736082, 0.01602264679968357, 0.0048437342047691345, -0.00817293580621481, 0.06567900627851486, 0.00012871218496002257, -0.02462039142847061, -0.03512977063655853, 0.01072178315371275, -0.006399824284017086, 0.03559151664376259, -0.025156019255518913, 0.033559828996658325, 0.03749391809105873, -0.015154561959207058, -0.04321959242224693, 0.007055506110191345, -0.01640128158032894, -0.04033828526735306, -0.0014972171047702432, -0.02184990420937538, 0.007166325580328703, 0.04255467280745506, -0.005688732489943504, -0.01933799684047699, -0.015459314920008183, 0.014517350122332573, 0.007738892454653978, 0.006192037370055914, 0.018802369013428688, 0.0150529770180583, -0.030290653929114342, -0.03714299201965332, -0.0009390795021317899, 0.04321959242224693, 0.04414308816194534, 0.08725185692310333, 0.008976376615464687, -0.04429084435105324, 0.017860403284430504, 0.007845094427466393, -0.007969766855239868, 0.024343341588974, 0.014037132263183594, 0.05618546903133392, 0.019725864753127098, 0.025082139298319817, 0.02975502610206604, 0.024343341588974, -0.009387332014739513, -0.007406434044241905, -0.010195390321314335, -0.05075531452894211, -0.03424321487545967, -0.010472439229488373, 0.019670454785227776, -0.05160493031144142, -0.02456498146057129, 0.032636333256959915, -0.015016037039458752, -0.05278700590133667, 0.029108580201864243, -0.0033569063525646925, -0.04007970541715622, -0.03956254944205284, 0.04451248422265053, -0.009585883468389511, 0.01298434752970934, -0.007637307979166508, -0.01037085521966219, 0.03032759390771389, 0.0007751590455882251, 0.0010273887310177088, 0.0015122239710763097, 0.07949449867010117, 0.012975112535059452, -0.0670827180147171, 0.01134052500128746, 0.015394670888781548, -0.019319526851177216, -0.07905121892690659, 0.0032183818984776735, -0.021646736189723015, 0.009359627030789852, -0.06675025820732117, 0.041114021092653275, -0.05485563352704048, 0.011950031854212284, -0.07376882433891296, -0.036515012383461, 0.005457858555018902, -0.021425096318125725, 0.017823463305830956, 0.022865749895572662, 0.010121511295437813, 0.023549135774374008, -0.01443423517048359, 0.020372310653328896, -0.05142023041844368, -0.016715269535779953, 0.05607464909553528, -0.0295333880931139, -0.01618887670338154, 0.01422183122485876, 0.01072178315371275, 0.004532054532319307, -0.0023664573673158884, 0.05119859427213669, 0.009493534453213215, 0.021554386243224144, 0.008343782275915146, 0.013676969334483147, -0.015680953860282898, 0.005263924598693848, 0.008417662233114243, -0.03138037770986557, 0.018783899024128914, -0.065863698720932, -0.014905218034982681, -0.0462486557662487, 0.05552055314183235, 0.007738892454653978, -0.021462036296725273, -0.005873431451618671, 0.03213764354586601, -0.009909107349812984, 0.01634587161242962, 0.06989014148712158, -0.007628072984516621, 0.013012052513659, -0.03719840198755264, -0.06734129786491394, -0.016558274626731873, 0.005716437473893166, 0.015505489893257618, 0.024860499426722527, 0.021000288426876068, 0.026799840852618217, 0.006053513381630182, 0.027039948850870132, 0.03697676211595535, 0.02153591625392437, 0.02962573617696762, -0.06272381544113159, -0.002208308782428503, -0.01360308937728405, 0.0037216870114207268, 0.05215902626514435, -0.011331290006637573, 0.0521220862865448, -0.10742100328207016, 0.08769513666629791, -0.026097983121871948, -0.004774471744894981, 0.007143238093703985, -0.019060947000980377, 0.03402157500386238, 0.04835422709584236, -0.0045874640345573425, 0.09611741453409195, -0.035979386419057846, 0.015062212012708187, 0.05075531452894211, -0.025783995166420937, -0.05422765761613846, 0.008763972669839859, -0.005268542096018791, -0.04580537974834442, 0.05688732489943504, 0.005947311408817768, -0.02478661946952343, 0.02351219579577446, 0.06464468687772751, 0.01653056964278221, 0.03819577395915985, -0.02290268987417221, -0.018469911068677902, 0.021074168384075165, -0.004488188307732344, -0.08865556865930557, 0.06560512632131577, 0.009585883468389511, 0.0353698804974556, 0.053821321576833725, 0.029607266187667847, -0.019762804731726646, -0.02984737604856491, -0.0695946216583252, -0.05167881026864052, -0.00303830043412745, -0.0029805819503962994, -0.036939822137355804, -0.027390876784920692, -0.01898706890642643, 0.048243407160043716, 0.07572663575410843, -0.016050351783633232, -0.02689219079911709, -0.011220471002161503, -0.0753202959895134, 0.0207971204072237, -0.02255176194012165, -0.06386895477771759, 0.04924078285694122, 0.020021382719278336, -0.05142023041844368, -0.016484394669532776, -0.028277432546019554, -0.06553124636411667, 0.006496791262179613, -0.0026550497859716415, 0.01628122664988041, -0.05951005220413208, -0.012522599659860134, -0.022921159863471985, -0.010010691359639168, 0.018876248970627785, 0.007498783990740776, 0.05736754462122917, -0.03409545496106148, 0.014378825202584267, 0.018525321036577225, 0.030216773971915245, -0.0173986554145813, -0.02914551831781864, -0.039968885481357574, -0.006986243650317192, 0.08606978505849838, 0.027003008872270584, -0.016031881794333458, -0.01277194358408451, 0.017943518236279488, -0.029699616134166718, 0.060544367879629135, 0.003719378262758255, -0.0649402067065239, -0.009234955534338951, 0.008768590167164803, -0.06024884805083275, -0.030161364004015923, 0.006122775375843048, -0.018968598917126656, -0.03222999349236488, 0.03642266243696213, -0.033818405121564865, 0.04695051163434982, 0.002932098228484392, -0.03208223357796669, -0.026208803057670593, 0.03173130750656128, 0.03271021321415901, -0.004042601678520441, 0.02478661946952343, -0.03978418931365013, -0.022976569831371307, 0.01518226694315672, 0.0089671416208148, -0.061948079615831375, -0.044069208204746246, 0.015523959882557392, 0.03826965391635895, -0.09833380579948425, -0.008020558394491673, 0.015099151991307735, 0.049647118896245956, 0.033467479050159454, -0.09404878318309784, 0.016105761751532555, -0.013409155420958996, 0.00524083711206913, 0.011774567887187004, -0.007147855591028929, -0.005513268522918224, -0.009165693074464798, -0.008879409171640873, -0.04488188400864601, 0.03215611353516579, -0.006358266808092594, 0.04262855276465416, -0.035536106675863266, -0.004467409569770098, 0.06235441938042641, 0.0002887366572394967, -0.028332842513918877, 0.009862932376563549, -0.051715750247240067, 0.05703508481383324, -0.019282586872577667, -0.027797216549515724, 0.06686107814311981, 0.03409545496106148, -0.001216705422848463, -0.016927672550082207, -0.009604353457689285, -0.009364244528114796, 0.02615339308977127, -0.04347816854715347, 0.03915620967745781, 0.012310195714235306, -0.049203842878341675, -0.05666568502783775, -0.006838484667241573, 0.024417221546173096, 0.0236968956887722, 0.02593175508081913, 0.029958195984363556, 0.027704866603016853, 0.011294350028038025, -0.026966068893671036, -0.0260610431432724, -0.017121607437729836, -0.010703313164412975, -0.05042285472154617, -0.05585300922393799, 0.04946242272853851, -0.02452804148197174, -0.008680857717990875, -0.058919016271829605, 0.0809720903635025, 0.03341206908226013, 0.026042575016617775, -0.02105569839477539, -0.013852433301508427, 0.049647118896245956, 0.0006095070275478065, -0.043182652443647385, 0.007965149357914925, 0.025728585198521614, -0.037069112062454224, 0.01832215115427971, 0.0010256572859361768, -0.0007214808720164001, -0.056148529052734375, 0.03863905370235443, -0.022847279906272888, 0.034261684864759445, -0.05673956498503685, 0.006228977348655462, -0.03230387344956398, -0.02918245829641819, 0.023438315838575363, -0.01786963827908039, 0.027667926624417305, 0.005222367122769356, -0.032285403460264206, -0.01494215801358223, 0.007688100449740887, -0.028628362342715263, -0.02879459038376808, 0.03459414467215538, -0.02360454574227333, 0.017851168289780617, -0.02988431602716446, -0.05330416187644005, 0.027852624654769897, -0.017740348353981972, -0.020316902548074722, 0.023419847711920738, 0.018469911068677902, 0.06767375022172928, -0.008763972669839859, -0.022958099842071533, -0.025211427360773087, 0.0093965670093894, -0.017287837341427803, -0.01943034678697586, -0.005134635139256716, -0.04724603146314621, 0.06209583953022957, -0.021240398287773132, 0.01832215115427971, -0.0556313693523407, -0.005841109436005354, 0.017832698300480843, -0.05991639196872711, 0.037863317877054214, 0.02716923877596855, 0.02242247201502323, 0.0027843390125781298, -0.02236706204712391, 0.0243064034730196, 0.04118790104985237, -0.02325361780822277, -0.021462036296725273, -0.0341508649289608, -0.05629628896713257, -0.05644404888153076, -0.043884508311748505, 0.0011491747573018074, -0.05552055314183235, -0.05489257350564003, 0.03819577395915985, 0.006852336693555117, 0.00989063736051321 ]
30,790
networkx.classes.function
is_frozen
Returns True if graph is frozen. Parameters ---------- G : graph A NetworkX graph See Also -------- freeze
def is_frozen(G): """Returns True if graph is frozen. Parameters ---------- G : graph A NetworkX graph See Also -------- freeze """ try: return G.frozen except AttributeError: return False
(G)
[ 0.10933555662631989, 0.020491821691393852, -0.028468504548072815, 0.016503481194376945, 0.007439459674060345, -0.024789603427052498, -0.04700053855776787, 0.03434786945581436, 0.03140818700194359, 0.0009315441129729152, 0.03892070800065994, -0.02590702660381794, -0.027144787833094597, 0.004265548195689917, -0.03806115314364433, -0.029723456129431725, -0.006652965676039457, 0.010409226641058922, 0.027110405266284943, 0.01897900365293026, -0.022176552563905716, -0.04081173241138458, -0.0394020602107048, 0.0425308458507061, 0.012463565915822983, -0.00633922778069973, 0.015575160272419453, 0.040605440735816956, 0.04937291517853737, 0.05686824396252632, -0.015841621905565262, -0.01928844302892685, -0.0200792346149683, -0.008728793822228909, 0.040364764630794525, 0.055802393704652786, 0.016262805089354515, 0.032181788235902786, -0.05270799249410629, -0.08540551364421844, -0.030978409573435783, -0.006231782957911491, -0.040846116840839386, 0.0220562145113945, 0.027454227209091187, -0.029328061267733574, 0.04772256687283516, 0.0535331666469574, -0.03761418163776398, -0.004525563679635525, 0.09008149802684784, -0.025185000151395798, 0.021678010001778603, 0.03118470311164856, -0.053258106112480164, 0.02881232649087906, 0.04748189076781273, 0.037132833153009415, -0.05236417055130005, -0.03531057387590408, -0.0022584842517971992, -0.000013187138392822817, 0.040983643382787704, -0.039573971182107925, 0.009670007973909378, 0.020766880363225937, -0.043493546545505524, -0.0449032224714756, -0.022262508049607277, 0.004538457375019789, -0.054220810532569885, 0.028210638090968132, -0.03109874576330185, 0.0378204770386219, -0.08856867998838425, -0.049407295882701874, 0.02740265429019928, 0.0078821312636137, -0.07206519693136215, -0.0543583407998085, -0.02857165038585663, -0.030067279934883118, -0.0433216355741024, -0.008522500284016132, -0.01351222489029169, 0.004308525938540697, 0.017380228266119957, 0.05370507761836052, -0.0007633934146724641, -0.008947980590164661, -0.0006521883187815547, 0.04431872069835663, 0.021763965487480164, -0.011810303665697575, 0.009962256997823715, 0.0141740832477808, -0.007125721778720617, -0.05002617463469505, -0.013572393916547298, -0.0535331666469574, -0.02960311807692051, 0.026439951732754707, -0.03795800730586052, -0.011122658848762512, -0.0036230296827852726, -0.005625796038657427, -0.03757980093359947, -0.05566486716270447, -0.029964132234454155, -0.10775397717952728, -0.03252561017870903, 0.02087002620100975, 0.01880709081888199, -0.013641158118844032, 0.06659842282533646, 0.0026023066602647305, -0.008905002847313881, 0.013159806840121746, 0.02188430353999138, 0.012979299761354923, 0.008801856078207493, 0.07295913994312286, 0.0038637055549770594, 0.004336461424827576, 0.0017298570601269603, 0.020921600982546806, 0.06116602569818497, 0.03830182924866676, 0.0032899517100304365, -0.013830260373651981, 0.031769201159477234, 0.018067874014377594, -0.015300101600587368, 0.058862414211034775, -0.030978409573435783, 0.022417228668928146, -0.02614770270884037, 0.022571947425603867, -0.014655434526503086, 0.02771209552884102, -0.021368568763136864, -0.003956107888370752, 0.014096722938120365, 0.059825118631124496, 0.017105169594287872, 0.015953363850712776, -0.042633991688489914, -0.035620011389255524, 0.031545717269182205, 0.030531439930200577, 0.08341134339570999, -0.015729879960417747, -0.008384971879422665, -0.0032491227611899376, -0.05315496027469635, 0.03247403725981712, -0.039264529943466187, -0.005471075884997845, 0.02078407071530819, -0.045006368309259415, -0.06824877113103867, 0.024841176345944405, 0.003696091938763857, -0.008870621211826801, -0.0012356122024357319, -0.030806496739387512, 0.04844459146261215, -0.012773006223142147, -0.04851335659623146, 0.041155554354190826, 0.02456611953675747, -0.0014752134447917342, -0.005324951373040676, 0.020990364253520966, -0.0033565673511475325, 0.031923919916152954, 0.00802825577557087, 0.016666796058416367, -0.007688730955123901, 0.014939088374376297, 0.006455267779529095, -0.03696092218160629, -0.05948129668831825, 0.016589436680078506, 0.03046267479658127, -0.0015633179573342204, -0.01834293082356453, -0.030101660639047623, 0.06188805401325226, 0.010976533405482769, -0.046106599271297455, 0.015214146114885807, 0.012222890742123127, 0.0338493250310421, 0.002060786122456193, -0.017844388261437416, 0.04139623045921326, 0.022743860259652138, -0.06910832226276398, 0.022864196449518204, 0.0346229262650013, -0.05174528807401657, 0.014285825192928314, -0.04136184975504875, -0.009308994747698307, 0.008690114133059978, -0.027230743318796158, -0.07901041209697723, 0.040055323392152786, -0.017758432775735855, -0.04449063539505005, -0.06965844333171844, 0.004727559629827738, 0.04466254636645317, 0.007456650957465172, 0.054530251771211624, -0.020990364253520966, -0.005389417987316847, 0.023964429274201393, -0.012076766230165958, -0.003891641041263938, -0.018927428871393204, 0.014345994219183922, 0.012575308792293072, -0.002832238096743822, -0.048857178539037704, -0.002503457712009549, 0.019821368157863617, -0.01621123217046261, -0.06553257256746292, 0.0535675473511219, 0.0151539770886302, 0.029654692858457565, -0.009988044388592243, 0.028726371005177498, -0.01173294335603714, 0.022571947425603867, 0.009945066645741463, 0.0322677418589592, 0.004482585936784744, 0.023603415116667747, -0.0394020602107048, -0.015093808062374592, 0.009927875362336636, 0.02504746988415718, -0.03369460627436638, -0.003938916604965925, -0.011182826943695545, 0.008767474442720413, -0.007723113056272268, -0.08231110870838165, -0.016804326325654984, -0.033110108226537704, -0.04418119415640831, 0.01149226725101471, -0.0011507309973239899, -0.003221187274903059, -0.009420736692845821, 0.015274315141141415, 0.07791018486022949, -0.008165785111486912, -0.025064662098884583, -0.02700725942850113, 0.08794979751110077, 0.06725168228149414, 0.01473279483616352, 0.022657904773950577, -0.005918045062571764, -0.05150461196899414, -0.01205097883939743, 0.04765380173921585, -0.01606510765850544, 0.00758128659799695, 0.010185741819441319, 0.011354738846421242, -0.07515960186719894, -0.020612159743905067, 0.0010970087023451924, 0.034915175288915634, -0.0028580245561897755, -0.0040764459408819675, -0.005600009113550186, -0.027454227209091187, 0.009816132485866547, -0.06604830175638199, 0.025460056960582733, -0.037064068019390106, -0.030445484444499016, 0.007955193519592285, -0.00330714276060462, 0.06591077893972397, 0.04497198387980461, 0.0590687096118927, -0.019357208162546158, 0.011114062741398811, 0.04796323925256729, 0.06821438670158386, -0.03568877652287483, 0.04136184975504875, 0.03565439581871033, 0.08705586194992065, -0.014896110631525517, -0.022881388664245605, 0.0019468950340524316, 0.024841176345944405, 0.021437333896756172, 0.03254280239343643, 0.03617012873291969, 0.009025340899825096, 0.08203605562448502, -0.032628756016492844, -0.010400631465017796, -0.000058087203797185794, 0.053361255675554276, -0.006055573932826519, -0.012472162023186684, 0.032181788235902786, -0.05817477032542229, 0.004955342039465904, 0.006171614397317171, 0.008105616085231304, 0.03843935579061508, 0.007031170651316643, 0.006781899370253086, -0.13292178511619568, 0.019116532057523727, 0.017981918528676033, 0.030445484444499016, -0.006442374549806118, 0.022726668044924736, 0.022331273183226585, -0.011861876584589481, 0.07275284081697464, 0.05717768520116806, 0.005380822345614433, 0.10287169367074966, 0.05105764418840408, -0.01779281534254551, 0.031683243811130524, -0.0511607900261879, 0.02298453450202942, 0.007516819983720779, 0.0181022547185421, 0.014139700680971146, 0.005260484293103218, 0.036101363599300385, -0.0057246447540819645, 0.04638165608048439, 0.042083874344825745, 0.03795800730586052, -0.038164298981428146, 0.06511998176574707, -0.02038867585361004, 0.019872941076755524, -0.033986855298280716, -0.02056058682501316, 0.007938002236187458, -0.02197025902569294, 0.0054152044467628, 0.06254131346940994, -0.03017042577266693, -0.00019098266784567386, 0.022468801587820053, -0.020354293286800385, -0.011569627560675144, -0.03278347849845886, -0.01271283719688654, 0.004400928039103746, 0.003947512246668339, -0.03551686555147171, -0.0007918662158772349, 0.0004998857039026916, -0.04070858657360077, -0.05363631248474121, -0.002385268686339259, 0.015145381912589073, -0.008470927365124226, 0.00755979772657156, 0.026405569165945053, 0.014749986119568348, 0.00933478120714426, -0.020440248772501945, 0.005294866859912872, 0.02056058682501316, 0.02803872711956501, 0.03761418163776398, 0.021007556468248367, -0.03830182924866676, 0.018067874014377594, -0.043665461242198944, 0.00016640473040752113, -0.05346440151333809, -0.005900853779166937, 0.04088049754500389, -0.0645354837179184, 0.037064068019390106, 0.03402123972773552, -0.01193064171820879, -0.029259296134114265, -0.0005283585051074624, -0.013348909094929695, 0.003981894347816706, -0.0017029958544299006, -0.005733240395784378, 0.021867111325263977, -0.026990067213773727, 0.0016986981499940157, 0.05329249054193497, 0.025064662098884583, 0.01568690314888954, 0.03929891437292099, -0.026199275627732277, -0.05284551903605461, -0.005720347166061401, -0.006683050189167261, 0.0303251463919878, 0.01741461083292961, -0.03314448893070221, 0.10074000060558319, 0.01630578376352787, 0.04810076951980591, -0.014621052891016006, 0.03118470311164856, -0.042633991688489914, -0.02473803050816059, -0.0006865705945529044, -0.020526204258203506, 0.0020844240207225084, -0.008178678341209888, 0.026439951732754707, -0.02258913964033127, -0.007220272906124592, 0.049579206854104996, -0.0029611713252961636, -0.006468161009252071, -0.029723456129431725, 0.006167316343635321, -0.05652442201972008, -0.06477615982294083, 0.07983558624982834, 0.05188281834125519, 0.02755737490952015, -0.006236081011593342, -0.06195681914687157, 0.014982066117227077, 0.029585927724838257, 0.002688262378796935, 0.05604306980967522, 0.08471786975860596, 0.033505503088235855, -0.012601095251739025, 0.02716197818517685, 0.0018630882259458303, -0.025924216955900192, -0.0976455956697464, 0.032714713364839554, -0.016194039955735207, -0.04679424315690994, -0.05236417055130005, 0.060443997383117676, -0.053980134427547455, -0.0035607118625193834, -0.026732200756669044, -0.00730193080380559, 0.0061630187556147575, -0.03757980093359947, 0.01449211873114109, -0.016322974115610123, 0.014801559038460255, 0.014621052891016006, 0.05016370490193367, -0.03881756216287613, -0.006644370034337044, -0.06340087205171585, 0.0220562145113945, 0.0338493250310421, -0.042393315583467484, 0.07316543161869049, 0.002542137634009123, -0.0031051470432430506, -0.047756947576999664, 0.0184976514428854, -0.019271252676844597, 0.033264826983213425, 0.022657904773950577, -0.02920772321522236, -0.05140146613121033, 0.004620115272700787, 0.012979299761354923, -0.025064662098884583, 0.002206910867244005, -0.04063982143998146, -0.013323122635483742, 0.016245614737272263, 0.06120040640234947, 0.05315496027469635, -0.015695497393608093, 0.00590944942086935, 0.01295351330190897, -0.014156891964375973, -0.012798793613910675, 0.07055237889289856, 0.003513436298817396, -0.012145530432462692, -0.016804326325654984, -0.07612230628728867, 0.02473803050816059, -0.011363334022462368, 0.004959639627486467, -0.0021843474823981524, 0.0049768309108912945, 0.0036273275036364794, 0.004456799477338791, 0.059171855449676514, 0.028330976143479347, 0.0013140466762706637, -0.009369163773953915, -0.048238299787044525, 0.032319314777851105, -0.038473740220069885, 0.035482484847307205, 0.014956279657781124, 0.0354137197136879, -0.003846514504402876, -0.05858735740184784, -0.005281973630189896, 0.045556481927633286, -0.03223336115479469, 0.03369460627436638, -0.032491229474544525, 0.04748189076781273, 0.07062114775180817, 0.021832730621099472, 0.05377384275197983, 0.015463417395949364, -0.02999851480126381, 0.020130807533860207, 0.01177592109888792, -0.053120579570531845, -0.01126878336071968, -0.00610284972935915, -0.049888648092746735, 0.09496378153562546, 0.04088049754500389, 0.026491524651646614, 0.013864642940461636, 0.05332687124609947, -0.020526204258203506, -0.008681518957018852, -0.05205472931265831, -0.08127964287996292, 0.0016589435981586576, -0.00811850931495428, -0.10101505368947983, 0.03482922166585922, 0.002163932891562581, 0.02148890681564808, 0.06673595309257507, 0.029104575514793396, -0.02740265429019928, -0.03109874576330185, -0.03235369920730591, 0.007680135313421488, -0.047997623682022095, 0.008415056392550468, -0.07295913994312286, -0.008930790238082409, -0.00810991320759058, 0.03506989777088165, 0.014724199660122395, 0.03819868341088295, 0.02276105061173439, 0.06732045114040375, -0.011002320796251297, 0.08946261554956436, 0.003532776376232505, -0.04517827928066254, 0.07454071938991547, -0.04473130777478218, -0.05456463247537613, 0.012944918125867844, -0.02709321491420269, -0.048375826328992844, 0.010684284381568432, -0.017457587644457817, 0.016013532876968384, -0.05521789565682411, -0.011638391762971878, -0.041224319487810135, 0.012919130735099316, 0.017457587644457817, 0.0004144673002883792, 0.092969611287117, -0.04026161506772041, 0.017775624990463257, 0.025013087317347527, 0.0240331944078207, -0.011621201410889626, -0.011810303665697575, -0.01449211873114109, -0.030032897368073463, 0.013434864580631256, 0.041224319487810135, -0.03395247459411621, -0.03360865265130997, -0.014113914221525192, -0.03929891437292099, 0.02172958292067051, 0.04737874120473862, -0.04710368439555168, 0.0005025718128308654, 0.04002094268798828, -0.07096496969461441, -0.06594515591859818, 0.0354137197136879, 0.009420736692845821, -0.05621498078107834, -0.00830331351608038, -0.008445140905678272, 0.01983855850994587, 0.00330714276060462, -0.005879364907741547, 0.011440694332122803, -0.023500269278883934, 0.013606776483356953, -0.0065970947034657, -0.01566111482679844, -0.04514389485120773, -0.01985575072467327, -0.05411766469478607, -0.0181194469332695, -0.06594515591859818, -0.009326186031103134, -0.02497870661318302, 0.01597915217280388, -0.0543239563703537, -0.03213021531701088, 0.0072331661358475685, 0.0063005476258695126, 0.021678010001778603, -0.07172137498855591, -0.002855875762179494, -0.025185000151395798, 0.015033639967441559, -0.03347112238407135, -0.027282316237688065, 0.032955389469861984, -0.017741242423653603, 0.05649004131555557, -0.04810076951980591, -0.054530251771211624, 0.024359825998544693, 0.0075683933682739735, -0.056421276181936264, -0.014792963862419128, 0.06078781932592392, 0.0056730713695287704, -0.013305931352078915, 0.008522500284016132, -0.049579206854104996, 0.048478975892066956, -0.035963837057352066, -0.04002094268798828, 0.04572839289903641, 0.060203321278095245, 0.040914878249168396, -0.046037834137678146, -0.0067604100331664085, 0.0131855932995677, -0.03716721385717392, -0.06333211064338684, 0.04916661977767944, 0.04985426366329193, -0.08767474442720413, -0.06192243471741676, 0.027144787833094597, -0.022039024159312248, 0.07990435510873795, 0.0035714562982320786, 0.01842888630926609, 0.0057375384494662285, 0.04651918634772301, 0.0009213368757627904, 0.01763809472322464, 0.00854828767478466, 0.0031825071200728416, -0.045247044414281845, -0.011200018227100372, 0.029946941882371902, 0.01891023851931095, -0.00657560583204031, -0.013993576169013977, 0.050438761711120605, 0.037064068019390106, 0.058484211564064026, -0.03278347849845886, 0.001726633752696216, 0.10252787172794342, -0.0010577914072200656, -0.016821516677737236, 0.0018802793929353356, 0.016873089596629143, -0.011741538532078266, 0.041533760726451874, -0.003440374042838812, 0.004865088500082493, -0.09331343322992325, 0.009876301512122154, -0.042565226554870605, -0.0005017659859731793, -0.03641080483794212, 0.012025192379951477, 0.017122361809015274, 0.006171614397317171, 0.0002943980216514319, -0.039264529943466187, 0.006885045673698187, -0.04149937629699707, 0.002003840636461973, 0.01098512951284647, -0.03589507192373276, 0.002995553659275174, -0.019976088777184486, 0.04995741322636604, -0.02284700609743595, 0.02410195767879486, -0.025717923417687416, -0.05473654344677925, -0.022571947425603867, -0.006532627623528242, 0.021557671949267387, 0.009214443154633045, -0.06054714694619179, 0.05569924786686897, 0.020663732662796974, -0.00399478804320097, -0.03128784894943237, 0.061612993478775024, -0.03723597899079323, 0.03709844872355461, -0.004020574502646923, -0.02582107111811638, -0.02190149389207363, -0.026749391108751297, -0.024428589269518852, -0.007207379676401615, -0.0645354837179184, 0.012265868484973907, -0.021523289382457733, 0.02944839932024479, 0.0629882887005806, -0.02164362743496895, -0.0017287825467064977, -0.0826549306511879, 0.0630226656794548, 0.0472755953669548, -0.05346440151333809, -0.018789900466799736, -0.04517827928066254, -0.05937814712524414, -0.0141740832477808, -0.020216764882206917, -0.007280441932380199, -0.024909941479563713, -0.001479511265642941, -0.01686449535191059, -0.010813218541443348, 0.00034247947041876614 ]
30,794
networkx.algorithms.connectivity.edge_augmentation
is_k_edge_connected
Tests to see if a graph is k-edge-connected. Is it impossible to disconnect the graph by removing fewer than k edges? If so, then G is k-edge-connected. Parameters ---------- G : NetworkX graph An undirected graph. k : integer edge connectivity to test for Returns ------- boolean True if G is k-edge-connected. See Also -------- :func:`is_locally_k_edge_connected` Examples -------- >>> G = nx.barbell_graph(10, 0) >>> nx.is_k_edge_connected(G, k=1) True >>> nx.is_k_edge_connected(G, k=2) False
def unconstrained_bridge_augmentation(G): """Finds an optimal 2-edge-augmentation of G using the fewest edges. This is an implementation of the algorithm detailed in [1]_. The basic idea is to construct a meta-graph of bridge-ccs, connect leaf nodes of the trees to connect the entire graph, and finally connect the leafs of the tree in dfs-preorder to bridge connect the entire graph. Parameters ---------- G : NetworkX graph An undirected graph. Yields ------ edge : tuple Edges in the bridge augmentation of G Notes ----- Input: a graph G. First find the bridge components of G and collapse each bridge-cc into a node of a metagraph graph C, which is guaranteed to be a forest of trees. C contains p "leafs" --- nodes with exactly one incident edge. C contains q "isolated nodes" --- nodes with no incident edges. Theorem: If p + q > 1, then at least :math:`ceil(p / 2) + q` edges are needed to bridge connect C. This algorithm achieves this min number. The method first adds enough edges to make G into a tree and then pairs leafs in a simple fashion. Let n be the number of trees in C. Let v(i) be an isolated vertex in the i-th tree if one exists, otherwise it is a pair of distinct leafs nodes in the i-th tree. Alternating edges from these sets (i.e. adding edges A1 = [(v(i)[0], v(i + 1)[1]), v(i + 1)[0], v(i + 2)[1])...]) connects C into a tree T. This tree has p' = p + 2q - 2(n -1) leafs and no isolated vertices. A1 has n - 1 edges. The next step finds ceil(p' / 2) edges to biconnect any tree with p' leafs. Convert T into an arborescence T' by picking an arbitrary root node with degree >= 2 and directing all edges away from the root. Note the implementation implicitly constructs T'. The leafs of T are the nodes with no existing edges in T'. Order the leafs of T' by DFS preorder. Then break this list in half and add the zipped pairs to A2. The set A = A1 + A2 is the minimum augmentation in the metagraph. To convert this to edges in the original graph References ---------- .. [1] Eswaran, Kapali P., and R. Endre Tarjan. (1975) Augmentation problems. http://epubs.siam.org/doi/abs/10.1137/0205044 See Also -------- :func:`bridge_augmentation` :func:`k_edge_augmentation` Examples -------- >>> G = nx.path_graph((1, 2, 3, 4, 5, 6, 7)) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 7)] >>> G = nx.path_graph((1, 2, 3, 2, 4, 5, 6, 7)) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 3), (3, 7)] >>> G = nx.Graph([(0, 1), (0, 2), (1, 2)]) >>> G.add_node(4) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 4), (4, 0)] """ # ----- # Mapping of terms from (Eswaran and Tarjan): # G = G_0 - the input graph # C = G_0' - the bridge condensation of G. (This is a forest of trees) # A1 = A_1 - the edges to connect the forest into a tree # leaf = pendant - a node with degree of 1 # alpha(v) = maps the node v in G to its meta-node in C # beta(x) = maps the meta-node x in C to any node in the bridge # component of G corresponding to x. # find the 2-edge-connected components of G bridge_ccs = list(nx.connectivity.bridge_components(G)) # condense G into an forest C C = collapse(G, bridge_ccs) # Choose pairs of distinct leaf nodes in each tree. If this is not # possible then make a pair using the single isolated node in the tree. vset1 = [ tuple(cc) * 2 # case1: an isolated node if len(cc) == 1 else sorted(cc, key=C.degree)[0:2] # case2: pair of leaf nodes for cc in nx.connected_components(C) ] if len(vset1) > 1: # Use this set to construct edges that connect C into a tree. nodes1 = [vs[0] for vs in vset1] nodes2 = [vs[1] for vs in vset1] A1 = list(zip(nodes1[1:], nodes2)) else: A1 = [] # Connect each tree in the forest to construct an arborescence T = C.copy() T.add_edges_from(A1) # If there are only two leaf nodes, we simply connect them. leafs = [n for n, d in T.degree() if d == 1] if len(leafs) == 1: A2 = [] if len(leafs) == 2: A2 = [tuple(leafs)] else: # Choose an arbitrary non-leaf root try: root = next(n for n, d in T.degree() if d > 1) except StopIteration: # no nodes found with degree > 1 return # order the leaves of C by (induced directed) preorder v2 = [n for n in nx.dfs_preorder_nodes(T, root) if T.degree(n) == 1] # connecting first half of the leafs in pre-order to the second # half will bridge connect the tree with the fewest edges. half = math.ceil(len(v2) / 2) A2 = list(zip(v2[:half], v2[-half:])) # collect the edges used to augment the original forest aug_tree_edges = A1 + A2 # Construct the mapping (beta) from meta-nodes to regular nodes inverse = defaultdict(list) for k, v in C.graph["mapping"].items(): inverse[v].append(k) # sort so we choose minimum degree nodes first inverse = { mu: sorted(mapped, key=lambda u: (G.degree(u), u)) for mu, mapped in inverse.items() } # For each meta-edge, map back to an arbitrary pair in the original graph G2 = G.copy() for mu, mv in aug_tree_edges: # Find the first available edge that doesn't exist and return it for u, v in it.product(inverse[mu], inverse[mv]): if not G2.has_edge(u, v): G2.add_edge(u, v) yield u, v break
(G, k, *, backend=None, **backend_kwargs)
[ 0.005627615377306938, -0.00863529834896326, -0.05353046581149101, 0.02833719179034233, 0.012083129957318306, -0.03596643730998039, -0.014346751384437084, -0.03787374868988991, 0.05965062975883484, -0.08480197936296463, 0.007880757562816143, 0.013550291769206524, -0.02173496223986149, 0.05621327832341194, -0.033723775297403336, 0.006413595285266638, 0.002093326300382614, 0.04080807417631149, 0.08400552719831467, 0.021462488919496536, -0.03363993763923645, -0.09264082461595535, -0.02793896198272705, 0.011663940735161304, -0.0342058427631855, 0.006759426556527615, -0.011276190169155598, 0.0040949550457298756, -0.028316233307123184, 0.006953301373869181, 0.010877960361540318, -0.07956212013959885, -0.03102000430226326, -0.038754045963287354, 0.03470886871218681, -0.004794477019459009, 0.004941192921251059, 0.06816016882658005, -0.06367484480142593, -0.0353376530110836, 0.0026697113644331694, -0.06836976855993271, 0.007351531181484461, -0.05709357559680939, 0.07734041661024094, 0.046446166932582855, 0.007912197150290012, 0.0413530170917511, 0.011108514852821827, -0.009620392695069313, 0.0030050629284232855, -0.06631574034690857, 0.02760361135005951, 0.026555638760328293, -0.029322287067770958, 0.0396343432366848, 0.019942928105592728, 0.034289680421352386, 0.04749413952231407, -0.04355376213788986, 0.025172313675284386, -0.03799950331449509, 0.0035264294128865004, 0.004194512497633696, -0.03439447656273842, 0.014860258437693119, -0.039089396595954895, -0.07817879319190979, -0.04321841150522232, 0.013393096625804901, -0.005166507326066494, -0.01736491359770298, 0.013707487843930721, -0.006979500874876976, 0.023747069761157036, -0.0019046911038458347, 0.02349555678665638, -0.0016217384254559875, 0.01607590727508068, -0.015090812928974628, 0.03215181455016136, -0.019513258710503578, 0.005407541058957577, -0.03152303025126457, 0.05013503134250641, -0.016421739012002945, 0.02703770622611046, -0.003589307889342308, -0.04590122029185295, -0.07235205918550491, -0.015447123907506466, -0.03095712512731552, 0.054704196751117706, 0.06191425025463104, 0.028546787798404694, 0.01237656269222498, -0.029469003900885582, -0.07822071015834808, 0.023139245808124542, -0.06120162829756737, 0.00218371395021677, 0.05516530200839043, -0.07461568713188171, -0.005114108789712191, -0.005769092123955488, -0.04481133073568344, -0.04703303426504135, 0.040221206843853, -0.015069853514432907, -0.05998598039150238, -0.0809873640537262, -0.01659989356994629, 0.026241246610879898, -0.008609099313616753, -0.01613878645002842, -0.0152584882453084, -0.0017501150723546743, 0.027645530179142952, 0.01584535278379917, -0.004550823010504246, 0.018171854317188263, -0.0011881395475938916, -0.041772209107875824, 0.002452257089316845, -0.006602230481803417, -0.020833704620599747, 0.06992076337337494, 0.04384719580411911, -0.035610124468803406, -0.05780619755387306, 0.021860718727111816, -0.0008822623640298843, -0.05776427686214447, 0.019209347665309906, -0.011863055638968945, -0.0638425201177597, -0.05432692542672157, -0.01716579869389534, 0.040053531527519226, -0.010647406801581383, -0.00525296526029706, -0.09783876687288284, 0.05667438358068466, -0.0019426801009103656, -0.013749406673014164, -0.027016745880246162, 0.05776427686214447, -0.0390474759042263, 0.03938283026218414, -0.02360035479068756, 0.007115737535059452, 0.01214600820094347, 0.008247548714280128, -0.011370508000254631, 0.007781200110912323, 0.02001628652215004, -0.0536143034696579, 0.0367838554084301, -0.024082422256469727, -0.008577659726142883, -0.063884437084198, -0.007990795187652111, -0.00714193657040596, 0.020131563767790794, 0.0026186227332800627, -0.031040962785482407, 0.06568695604801178, -0.020058205351233482, -0.02747785486280918, 0.005737652536481619, -0.01679900847375393, -0.05285976454615593, -0.09205395728349686, -0.0209489818662405, 0.022657178342342377, 0.0906287133693695, 0.012240326032042503, -0.0004208266909699887, 0.009756629355251789, 0.058938007801771164, 0.04602697864174843, -0.028840219601988792, 0.016851406544446945, -0.016778049990534782, -0.020005807280540466, 0.01945038139820099, 0.04099670797586441, -0.008609099313616753, 0.04820676147937775, -0.012711913324892521, 0.02731017954647541, -0.023306921124458313, 0.03672097623348236, 0.04795524850487709, 0.04602697864174843, -0.00292384484782815, 0.009416038170456886, 0.0689985454082489, -0.03164878860116005, 0.07889141142368317, 0.0013911842834204435, -0.0019112409790977836, 0.034876544028520584, 0.013634130358695984, 0.038125261664390564, -0.00913308560848236, 0.007000460289418697, -0.04640424996614456, -0.011674419976770878, 0.015813913196325302, -0.016924764961004257, -0.002667091554030776, 0.03814622014760971, -0.03290635347366333, -0.030600814148783684, -0.01630646176636219, -0.019901009276509285, 0.0444759801030159, 0.04757797718048096, -0.0026631616055965424, -0.06363292783498764, -0.007734041661024094, -0.0047656577080488205, -0.0016806868370622396, 0.053404707461595535, -0.04699111357331276, 0.017113400623202324, -0.009473676793277264, 0.04032600298523903, -0.0032041778322309256, 0.03028642199933529, -0.028840219601988792, 0.004411966539919376, -0.054201167076826096, 0.05826730281114578, 0.026471801102161407, -0.001579819479957223, -0.022950610145926476, -0.01542616356164217, 0.03516997769474983, -0.001482881954871118, -0.016746610403060913, -0.04116438329219818, 0.00960991345345974, 0.013801805675029755, -0.033157870173454285, 0.021315772086381912, -0.026890989392995834, 0.022342786192893982, 0.017605947330594063, -0.09255698323249817, -0.046907275915145874, -0.027456894516944885, 0.016065428033471107, -0.02999299019575119, -0.0570097379386425, -0.03403816744685173, -0.0159711092710495, -0.0031858382280915976, 0.011496264487504959, 0.019659975543618202, -0.0033011152409017086, -0.04204468056559563, 0.054997626692056656, -0.020026765763759613, 0.03667905926704407, 0.02485792152583599, 0.004891414660960436, -0.013235900551080704, -0.027100583538413048, 0.10672558099031448, 0.04782949388027191, -0.034876544028520584, 0.017784103751182556, -0.009473676793277264, 0.052440572530031204, -0.007068578619509935, 0.03164878860116005, -0.009222162887454033, -0.04156261309981346, -0.02452257089316845, -0.008016994222998619, -0.033891450613737106, 0.0026618517003953457, -0.03405912593007088, -0.007812639698386192, -0.05000927671790123, -0.06530968099832535, -0.004438166040927172, -0.031627826392650604, 0.041939884424209595, -0.01978573203086853, 0.018318569287657738, 0.043260328471660614, 0.08023282140493393, 0.017752664163708687, -0.005355142522603273, 0.0074982475489377975, 0.013099663890898228, 0.0024168880190700293, 0.06635765731334686, -0.010972278192639351, 0.07054954767227173, -0.004485324956476688, 0.03164878860116005, 0.0005976721295155585, 0.01859104260802269, 0.009070207364857197, -0.04300881549715996, 0.05977638438344002, -0.06707027554512024, -0.0035840680357068777, 0.01736491359770298, -0.0020671270322054625, -0.05516530200839043, -0.06836976855993271, 0.023244043812155724, -0.006382156163454056, 0.04699111357331276, -0.005831970367580652, -0.010542609728872776, 0.039550505578517914, -0.05336279049515724, 0.03489750251173973, -0.05805771052837372, 0.0121145686134696, 0.021389130502939224, 0.07465760409832001, 0.007508727256208658, -0.03403816744685173, -0.0570097379386425, 0.030663693323731422, -0.040640395134687424, 0.04363759979605675, -0.07532830536365509, 0.046152736991643906, 0.02867254428565502, -0.030579855665564537, 0.0305169764906168, -0.03978106006979942, 0.027750328183174133, 0.043763358145952225, -0.014692583121359348, 0.012848149985074997, 0.023411719128489494, 0.02965763956308365, 0.02084418572485447, 0.008603858761489391, -0.06409403681755066, 0.05005119368433952, 0.020624110475182533, 0.030810408294200897, -0.03751743584871292, 0.027498813346028328, -0.013225420378148556, 0.010285856202244759, -0.03470886871218681, -0.033053070306777954, 0.0433441661298275, 0.04053559899330139, 0.018507204949855804, -0.006534112151712179, -0.01045353151857853, 0.01663133315742016, 0.026429882273077965, 0.0015038413694128394, -0.05285976454615593, 0.07440608739852905, -0.005255585070699453, -0.10429428517818451, 0.04435022175312042, -0.05206330493092537, 0.013330217450857162, 0.034813664853572845, -0.015468083322048187, 0.010081500746309757, -0.02084418572485447, 0.0007538856589235365, 0.008451903238892555, 0.0735677108168602, -0.005737652536481619, 0.047242626547813416, -0.0057900515384972095, 0.02349555678665638, 0.0008016994106583297, -0.019272224977612495, 0.06430362910032272, 0.0017881040694192052, 0.03437351807951927, -0.018203292042016983, 0.02292965166270733, -0.014367710798978806, 0.05047038570046425, -0.01713436096906662, -0.05617135763168335, 0.006995220202952623, 0.0621657632291317, 0.0168304480612278, -0.004430306144058704, -0.014399150386452675, -0.015656718984246254, 0.022321827709674835, 0.020100124180316925, 0.007681642659008503, 0.042799219489097595, -0.04235907271504402, 0.05537489801645279, 0.06480665504932404, 0.040242165327072144, 0.021881679072976112, -0.048667870461940765, 0.03353513777256012, -0.005184846930205822, 0.003992777317762375, -0.0028242873959243298, -0.03548436984419823, 0.02435489557683468, 0.00141476362477988, 0.0036993450485169888, -0.002639582147821784, 0.04156261309981346, -0.0007237564423121512, -0.013686528429389, -0.002784988610073924, 0.0010230836924165487, -0.041311100125312805, -0.017836501821875572, 0.007199575193226337, -0.0872751995921135, 0.012764312326908112, 0.03317882865667343, -0.06015365570783615, 0.029238449409604073, -0.04653000459074974, -0.041478775441646576, 0.04110150411725044, 0.035316694527864456, 0.005048610270023346, 0.0444759801030159, 0.009070207364857197, -0.012994866818189621, 0.04126917943358421, -0.004053035750985146, -0.056883979588747025, 0.03699345141649246, -0.032424286007881165, -0.02134721167385578, 0.025633422657847404, -0.007320092059671879, 0.01969141513109207, 0.015824394300580025, -0.03519093617796898, -0.0010368383955210447, 0.04300881549715996, -0.07570557296276093, 0.01802513748407364, 0.04556586965918541, 0.011098034679889679, -0.0798555463552475, 0.052775926887989044, 0.01679900847375393, -0.020362116396427155, 0.05319511517882347, 0.023977624252438545, 0.007582085207104683, 0.05030271038413048, 0.051183007657527924, -0.03032834082841873, -0.08685600757598877, -0.03632274642586708, 0.013571251183748245, -0.04891938343644142, -0.029406124725937843, -0.0396343432366848, 0.01710292138159275, 0.001909930957481265, -0.005339422728866339, -0.014294353313744068, -0.0019426801009103656, -0.0575966015458107, 0.03261292353272438, -0.010427332483232021, 0.03454119339585304, 0.009803788736462593, 0.003783182939514518, 0.016013028100132942, 0.018612002953886986, 0.017406832426786423, -0.03808334097266197, -0.0123975221067667, -0.05667438358068466, -0.030265463516116142, -0.02021540142595768, 0.044392138719558716, -0.002292441204190254, 0.033053070306777954, -0.0046530007384717464, -0.037328802049160004, 0.06820208579301834, -0.086688332259655, 0.0063454769551754, -0.026304123923182487, -0.03596643730998039, -0.04736838489770889, 0.000014245883903640788, 0.02521423250436783, -0.053740061819553375, 0.017784103751182556, 0.023935705423355103, 0.03864924609661102, 0.019460860639810562, -0.016987644135951996, 0.0564647912979126, 0.017637386918067932, 0.005072189960628748, 0.04305073618888855, 0.03439447656273842, -0.001342715579085052, 0.035652045160532, -0.03810430318117142, 0.010741724632680416, -0.042233314365148544, 0.04418254643678665, 0.006602230481803417, 0.010139139369130135, 0.02372611127793789, 0.06371676176786423, -0.0017527349991723895, -0.00937935896217823, -0.04824868217110634, -0.03326266631484032, 0.05621327832341194, 0.01328829862177372, 0.06350716948509216, 0.003555248724296689, 0.016212143003940582, 0.032298531383275986, 0.0121145686134696, -0.043889112770557404, -0.026995787397027016, -0.007954115979373455, 0.019198866561055183, -0.02144153043627739, 0.0313553549349308, -0.01007626112550497, -0.011590582318603992, 0.030013948678970337, -0.010091980919241905, -0.02578013762831688, -0.035149019211530685, -0.0746995210647583, 0.05265016853809357, 0.046446166932582855, 0.035547249019145966, 0.06820208579301834, -0.05109916999936104, -0.011223792098462582, -0.005475659389048815, 0.002253142185509205, 0.03250812366604805, -0.021881679072976112, 0.011087555438280106, -0.021588245406746864, -0.04933857172727585, 0.05709357559680939, 0.01502793375402689, -0.007760240696370602, 0.026262205094099045, 0.0008331385906785727, 0.021714001893997192, 0.012732872739434242, -0.02999299019575119, 0.006408355664461851, -0.026031652465462685, -0.07444801181554794, 0.010909399949014187, -0.053111277520656586, 0.004241670947521925, -0.011160913854837418, -0.05428500473499298, 0.001968879485502839, -0.01620166376233101, 0.05667438358068466, 0.0026343422941863537, 0.058644574135541916, 0.010825562290847301, -0.042338114231824875, 0.0975034162402153, -0.0399068146944046, -0.020938502624630928, -0.009725190699100494, -0.006125402636826038, 0.017553549259901047, -0.03028642199933529, 0.0016269782790914178, -0.028043759986758232, -0.013403575867414474, -0.0011134714586660266, -0.03661618009209633, -0.07863990217447281, 0.043889112770557404, -0.023055408149957657, 0.03250812366604805, 0.02873542159795761, -0.024480652064085007, -0.020561231300234795, 0.012565197423100471, -0.05713549256324768, 0.014053319580852985, -0.04942241311073303, -0.009756629355251789, 0.05675822123885155, -0.014462028630077839, -0.06048900634050369, -0.0615788996219635, -0.012628075666725636, -0.07331620156764984, 0.038292936980724335, 0.01199929229915142, 0.023809948936104774, 0.016851406544446945, -0.02969955839216709, 0.020404037088155746, 0.0024601167533546686, 0.005915808025747538, 0.033094990998506546, 0.006130642723292112, -0.026597557589411736, -0.015751035884022713, 0.04917089641094208, 0.03078944981098175, -0.05365622416138649, 0.022217029705643654, 0.024669285863637924, 0.021881679072976112, -0.06245919689536095, 0.05336279049515724, 0.026639476418495178, -0.038125261664390564, 0.014755461364984512, -0.08434087783098221, -0.03319978713989258, -0.03552628681063652, -0.001966259442269802, -0.015195610001683235, -0.017375394701957703, 0.021755920723080635, -0.007314852438867092, -0.005045990459620953, 0.01353981252759695, 0.01793082058429718, 0.020456435158848763, 0.017637386918067932, -0.01676756888628006, -0.037140168249607086, 0.06790865957736969, 0.016348380595445633, 0.028588706627488136, -0.016683731228113174, -0.0019819792360067368, 0.02213319204747677, 0.004286210052669048, -0.004524623975157738, 0.05424308776855469, 0.02787608467042446, 0.021651124581694603, 0.0350651815533638, -0.0672798752784729, 0.0006166666862554848, 0.03317882865667343, -0.05218905955553055, -0.058938007801771164, 0.002109045861288905, -0.00848334189504385, -0.0467396005988121, -0.05805771052837372, 0.008357585407793522, 0.04214947670698166, 0.005795291159301996, 0.0030705612152814865, 0.07210054993629456, 0.032696761190891266, 0.009332200512290001, -0.025046557188034058, 0.03456215187907219, -0.01730203628540039, -0.01214600820094347, -0.007807399611920118, 0.011737299151718616, -0.02703770622611046, 0.050847653299570084, -0.02890309877693653, 0.06610614061355591, 0.0030024428851902485, -0.01776314340531826, 0.009599433280527592, -0.009531315416097641, 0.017480190843343735, 0.004613701719790697, -0.08128079026937485, 0.06547735631465912, -0.009044007398188114, -0.04317649081349373, -0.008808214217424393, -0.032026056200265884, 0.03734976053237915, -0.034080084413290024, 0.013330217450857162, -0.034289680421352386, 0.005179606843739748, -0.037538398057222366, 0.0033666135277599096, 0.016977164894342422, -0.041709329932928085, 0.04766181483864784, -0.015300407074391842, -0.004849495366215706, 0.0040949550457298756, -0.05604560300707817, 0.032067976891994476, -0.04305073618888855, 0.015761515125632286, 0.05428500473499298, 0.016757089644670486, -0.02890309877693653, 0.02902885526418686, 0.05382389947772026, -0.07193287461996078, -0.028840219601988792, -0.018276650458574295, 0.04160453379154205, 0.07708889991044998, 0.00614636205136776, 0.07327427715063095, -0.0056485747918486595, -0.028211435303092003, -0.0361969918012619, -0.011056115850806236, 0.003290635533630848, 0.02959476038813591, 0.018276650458574295, -0.042904019355773926, -0.06032133102416992, -0.009997663088142872, 0.006612710189074278, 0.02810663916170597, -0.03644850477576256, 0.024962719529867172, 0.011255230754613876, 0.035714924335479736, 0.06778290122747421, 0.014640184119343758, 0.042799219489097595, -0.026136448606848717, 0.026241246610879898, 0.020236359909176826, 0.01969141513109207, -0.027456894516944885, -0.04179316759109497, -0.05554257333278656, -0.03091520629823208, -0.0073358118534088135, -0.017616428434848785, -0.021284334361553192, 0.04942241311073303, 0.032990194857120514, 0.014158116653561592, 0.041709329932928085 ]
30,797
networkx.algorithms.matching
is_matching
Return True if ``matching`` is a valid matching of ``G`` A *matching* in a graph is a set of edges in which no two distinct edges share a common endpoint. Each node is incident to at most one edge in the matching. The edges are said to be independent. Parameters ---------- G : NetworkX graph matching : dict or set A dictionary or set representing a matching. If a dictionary, it must have ``matching[u] == v`` and ``matching[v] == u`` for each edge ``(u, v)`` in the matching. If a set, it must have elements of the form ``(u, v)``, where ``(u, v)`` is an edge in the matching. Returns ------- bool Whether the given set or dictionary represents a valid matching in the graph. Raises ------ NetworkXError If the proposed matching has an edge to a node not in G. Or if the matching is not a collection of 2-tuple edges. Examples -------- >>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)]) >>> nx.is_maximal_matching(G, {1: 3, 2: 4}) # using dict to represent matching True >>> nx.is_matching(G, {(1, 3), (2, 4)}) # using set to represent matching True
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, matching, *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,798
networkx.algorithms.matching
is_maximal_matching
Return True if ``matching`` is a maximal matching of ``G`` A *maximal matching* in a graph is a matching in which adding any edge would cause the set to no longer be a valid matching. Parameters ---------- G : NetworkX graph matching : dict or set A dictionary or set representing a matching. If a dictionary, it must have ``matching[u] == v`` and ``matching[v] == u`` for each edge ``(u, v)`` in the matching. If a set, it must have elements of the form ``(u, v)``, where ``(u, v)`` is an edge in the matching. Returns ------- bool Whether the given set or dictionary represents a valid maximal matching in the graph. Examples -------- >>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (3, 5)]) >>> nx.is_maximal_matching(G, {(1, 2), (3, 4)}) True
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, matching, *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,801
networkx.classes.function
is_negatively_weighted
Returns True if `G` has negatively weighted edges. Parameters ---------- G : graph A NetworkX graph. edge : tuple, optional A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested. weight: string, optional The attribute name used to query for edge weights. Returns ------- bool A boolean signifying if `G`, or the specified edge, is negatively weighted. Raises ------ NetworkXError If the specified edge does not exist. Examples -------- >>> G = nx.Graph() >>> G.add_edges_from([(1, 3), (2, 4), (2, 6)]) >>> G.add_edge(1, 2, weight=4) >>> nx.is_negatively_weighted(G, (1, 2)) False >>> G[2][4]["weight"] = -2 >>> nx.is_negatively_weighted(G) True >>> G = nx.DiGraph() >>> edges = [("0", "3", 3), ("0", "1", -5), ("1", "0", -2)] >>> G.add_weighted_edges_from(edges) >>> nx.is_negatively_weighted(G) True
def set_edge_attributes(G, values, name=None): """Sets edge attributes from a given value or dictionary of values. .. Warning:: The call order of arguments `values` and `name` switched between v1.x & v2.x. Parameters ---------- G : NetworkX Graph values : scalar value, dict-like What the edge attribute should be set to. If `values` is not a dictionary, then it is treated as a single attribute value that is then applied to every edge in `G`. This means that if you provide a mutable object, like a list, updates to that object will be reflected in the edge attribute for each edge. The attribute name will be `name`. If `values` is a dict or a dict of dict, it should be keyed by edge tuple to either an attribute value or a dict of attribute key/value pairs used to update the edge's attributes. For multigraphs, the edge tuples must be of the form ``(u, v, key)``, where `u` and `v` are nodes and `key` is the edge key. For non-multigraphs, the keys must be tuples of the form ``(u, v)``. name : string (optional, default=None) Name of the edge attribute to set if values is a scalar. Examples -------- After computing some property of the edges of a graph, you may want to assign a edge attribute to store the value of that property for each edge:: >>> G = nx.path_graph(3) >>> bb = nx.edge_betweenness_centrality(G, normalized=False) >>> nx.set_edge_attributes(G, bb, "betweenness") >>> G.edges[1, 2]["betweenness"] 2.0 If you provide a list as the second argument, updates to the list will be reflected in the edge attribute for each edge:: >>> labels = [] >>> nx.set_edge_attributes(G, labels, "labels") >>> labels.append("foo") >>> G.edges[0, 1]["labels"] ['foo'] >>> G.edges[1, 2]["labels"] ['foo'] If you provide a dictionary of dictionaries as the second argument, the entire dictionary will be used to update edge attributes:: >>> G = nx.path_graph(3) >>> attrs = {(0, 1): {"attr1": 20, "attr2": "nothing"}, (1, 2): {"attr2": 3}} >>> nx.set_edge_attributes(G, attrs) >>> G[0][1]["attr1"] 20 >>> G[0][1]["attr2"] 'nothing' >>> G[1][2]["attr2"] 3 The attributes of one Graph can be used to set those of another. >>> H = nx.path_graph(3) >>> nx.set_edge_attributes(H, G.edges) Note that if the dict contains edges that are not in `G`, they are silently ignored:: >>> G = nx.Graph([(0, 1)]) >>> nx.set_edge_attributes(G, {(1, 2): {"weight": 2.0}}) >>> (1, 2) in G.edges() False For multigraphs, the `values` dict is expected to be keyed by 3-tuples including the edge key:: >>> MG = nx.MultiGraph() >>> edges = [(0, 1), (0, 1)] >>> MG.add_edges_from(edges) # Returns list of edge keys [0, 1] >>> attributes = {(0, 1, 0): {"cost": 21}, (0, 1, 1): {"cost": 7}} >>> nx.set_edge_attributes(MG, attributes) >>> MG[0][1][0]["cost"] 21 >>> MG[0][1][1]["cost"] 7 If MultiGraph attributes are desired for a Graph, you must convert the 3-tuple multiedge to a 2-tuple edge and the last multiedge's attribute value will overwrite the previous values. Continuing from the previous case we get:: >>> H = nx.path_graph([0, 1, 2]) >>> nx.set_edge_attributes(H, {(u, v): ed for u, v, ed in MG.edges.data()}) >>> nx.get_edge_attributes(H, "cost") {(0, 1): 7} """ if name is not None: # `values` does not contain attribute names try: # if `values` is a dict using `.items()` => {edge: value} if G.is_multigraph(): for (u, v, key), value in values.items(): try: G._adj[u][v][key][name] = value except KeyError: pass else: for (u, v), value in values.items(): try: G._adj[u][v][name] = value except KeyError: pass except AttributeError: # treat `values` as a constant for u, v, data in G.edges(data=True): data[name] = values else: # `values` consists of doct-of-dict {edge: {attr: value}} shape if G.is_multigraph(): for (u, v, key), d in values.items(): try: G._adj[u][v][key].update(d) except KeyError: pass else: for (u, v), d in values.items(): try: G._adj[u][v].update(d) except KeyError: pass nx._clear_cache(G)
(G, edge=None, weight='weight', *, backend=None, **backend_kwargs)
[ 0.06647735834121704, 0.0003525592037476599, 0.005198776721954346, 0.0026948866434395313, -0.07711038738489151, -0.026666296645998955, -0.04295073822140694, 0.025305770337581635, 0.07824067026376724, -0.02314986102283001, -0.021852130070328712, 0.014275049790740013, 0.0791616439819336, 0.07899419218301773, 0.009638798423111439, 0.040355272591114044, 0.015729766339063644, 0.03616904094815254, 0.020596260204911232, 0.028801273554563522, 0.029261760413646698, -0.06823557615280151, -0.03020366095006466, -0.014787863940000534, 0.038345880806446075, -0.0253476332873106, -0.008911441080272198, 0.05077899247407913, 0.05446287617087364, 0.03503875806927681, -0.024552248418331146, -0.08560843765735626, -0.06384003162384033, -0.02597556822001934, 0.0734265074133873, -0.028675686568021774, -0.031187426298856735, 0.0186182651668787, -0.06580756604671478, -0.004667648579925299, 0.009010863490402699, -0.03616904094815254, -0.02798495814204216, -0.0019845354836434126, 0.06425865739583969, 0.06111898273229599, -0.017383327707648277, 0.01682865060865879, 0.024782491847872734, -0.05530012026429176, 0.0022697225213050842, -0.025431357324123383, 0.04491826519370079, 0.05563502013683319, -0.013040111400187016, 0.03962268307805061, -0.023840589448809624, 0.05098830163478851, -0.03773887827992439, -0.01925666630268097, 0.011240032501518726, -0.019089216366410255, 0.0007646413869224489, -0.035938799381256104, -0.0828455239534378, 0.02281496301293373, -0.03522713854908943, -0.01119816955178976, -0.030538560822606087, 0.004999930504709482, -0.024217350408434868, -0.018157780170440674, 0.0060700359754264355, -0.04123438149690628, -0.025494150817394257, 0.06836116313934326, -0.028424512594938278, 0.08037564903497696, -0.0007868807297199965, -0.01765543222427368, 0.0010354382684454322, 0.03273633122444153, 0.011041185818612576, -0.03334333375096321, 0.002462027594447136, 0.04680206999182701, -0.040229685604572296, 0.04818352684378624, 0.042322803288698196, -0.059695664793252945, -0.02461504191160202, 0.006017708219587803, -0.01905781961977482, 0.013657581061124802, 0.012035416439175606, 0.01125049777328968, 0.03051762841641903, -0.0765661746263504, -0.0024829586036503315, 0.018283367156982422, -0.013333148322999477, -0.06044918671250343, 0.006326442584395409, 0.003241713158786297, -0.03522713854908943, -0.09100867807865143, -0.03051762841641903, -0.05525825917720795, 0.00670843617990613, -0.0925157219171524, -0.03985292464494705, -0.007639872841536999, 0.08707361668348312, -0.031061839312314987, -0.010831874795258045, 0.03246422857046127, -0.0028728016186505556, -0.05881655588746071, 0.0025156636256724596, 0.018670594319701195, 0.0021716076880693436, 0.046132273972034454, 0.02062765695154667, 0.06647735834121704, 0.021810267120599747, 0.007838718593120575, 0.022459132596850395, 0.039287783205509186, 0.02189399115741253, -0.06677039712667465, -0.018450817093253136, -0.031920015811920166, 0.011951691471040249, 0.03912033513188362, 0.03673418238759041, -0.03493410348892212, -0.06354700028896332, 0.014002945274114609, 0.06312837451696396, -0.023212654516100883, 0.001780456630513072, -0.012768006883561611, 0.03520620986819267, -0.021852130070328712, -0.026143016293644905, -0.028529169037938118, -0.007953840307891369, -0.03974827006459236, -0.026770951226353645, 0.021600956097245216, -0.008848647587001324, -0.008503283374011517, 0.008414325304329395, 0.0056514129973948, -0.011334222741425037, -0.009403322823345661, -0.06283533573150635, 0.02231261506676674, 0.004366762936115265, 0.028340788558125496, -0.051406923681497574, -0.020763710141181946, 0.016703063622117043, -0.021433506160974503, 0.023819658905267715, 0.0049188220873475075, 0.03459920361638069, -0.02199864760041237, 0.007807322312146425, 0.02578718774020672, 0.0270430576056242, -0.05672343820333481, 0.005756068509072065, -0.005300815682858229, -0.004583923611789942, 0.004597005899995565, 0.07844997942447662, -0.04604854807257652, 0.00415221881121397, 0.048434700816869736, 0.004717359784990549, -0.001327166217379272, 0.013699443079531193, 0.04156928136944771, 0.034327100962400436, -0.023589415475726128, -0.0008647185168229043, 0.013542459346354008, 0.03598066046833992, 0.008330601267516613, 0.04617413505911827, -0.027419818565249443, -0.02419641986489296, 0.04089948534965515, 0.02430107444524765, -0.01156446523964405, 0.013123836368322372, -0.036985356360673904, 0.01310290489345789, 0.07413816452026367, 0.0324014350771904, -0.05157437548041344, 0.041066933423280716, 0.023819658905267715, 0.06279347836971283, -0.014714604243636131, 0.07309160381555557, -0.060951534658670425, -0.022584719583392143, -0.01800079643726349, -0.017697295174002647, -0.016493752598762512, 0.02767099253833294, 0.01341687235981226, 0.008492817170917988, 0.007864883169531822, -0.007383466232568026, 0.039413370192050934, -0.017697295174002647, -0.0162007175385952, -0.027964027598500252, -0.004249025136232376, 0.03325961157679558, -0.0032155492808669806, 0.02999434992671013, -0.05056967958807945, 0.008817250840365887, -0.03441082313656807, 0.03799005225300789, 0.02599649876356125, 0.04847656190395355, 0.015489057637751102, 0.040648311376571655, -0.0038722644094377756, 0.0006743757403455675, 0.0053217471577227116, 0.036441147327423096, -0.011313291266560555, 0.0035190510097891092, 0.041297174990177155, 0.011836569756269455, -0.04776490479707718, -0.058649107813835144, 0.03041297383606434, 0.006629944313317537, -0.021014884114265442, 0.023401034995913506, 0.009084123186767101, -0.024175487458705902, 0.0018524075858294964, -0.052746519446372986, 0.019225269556045532, -0.02291961945593357, 0.030643215402960777, -0.03784353286027908, 0.00352428387850523, 0.008660267107188702, -0.025619737803936005, 0.01399247907102108, -0.013259888626635075, 0.005389773286879063, -0.03840867429971695, -0.0509464405477047, 0.032966576516628265, 0.034871309995651245, 0.005808396730571985, 0.034766655415296555, 0.002375686541199684, -0.121233269572258, -0.010408018715679646, 0.07514286041259766, -0.033175885677337646, -0.005656645633280277, 0.0042908876203000546, 0.011773776262998581, 0.02197771705687046, 0.0013474433217197657, -0.03556203842163086, -0.020010188221931458, -0.04893704876303673, 0.015572781674563885, -0.03323867917060852, -0.041925109922885895, 0.05672343820333481, 0.0037754576187580824, 0.009429486468434334, -0.014735535718500614, 0.025829048827290535, 0.014233187772333622, -0.0148925194516778, 0.0972042977809906, 0.022898687049746513, -0.035603899508714676, 0.015698369592428207, 0.03899474814534187, 0.02252192609012127, -0.02126605622470379, -0.00662471167743206, 0.03924592211842537, 0.047932352870702744, 0.0797058492898941, 0.006404934450984001, 0.06371444463729858, 0.029701314866542816, 0.008163152262568474, -0.02492900937795639, 0.06647735834121704, 0.03520620986819267, -0.010088818147778511, 0.060951534658670425, -0.02798495814204216, 0.04031341150403023, -0.058439794927835464, 0.02009391225874424, 0.04562992602586746, 0.029931556433439255, 0.02882220596075058, -0.02250099554657936, 0.02291961945593357, 0.0009373234352096915, -0.02798495814204216, 0.0013893056893721223, -0.045588064938783646, -0.021402109414339066, -0.006122363731265068, 0.02547322027385235, 0.058858416974544525, 0.06727274507284164, 0.03081066533923149, -0.023484759032726288, -0.04219721630215645, -0.01520648691803217, 0.034494549036026, 0.021067211404442787, -0.000565795402508229, 0.08397580683231354, -0.005630481522530317, 0.020575329661369324, 0.02672909013926983, -0.017247274518013, 0.010266733355820179, 0.05463032424449921, -0.047932352870702744, -0.021297452971339226, 0.003966454416513443, 0.009973697364330292, 0.0002619665174279362, -0.0020591027569025755, -0.004416474606841803, 0.020910227671265602, -0.05743509903550148, 0.0710822120308876, -0.002666106214746833, 0.01382503006607294, -0.04525316506624222, 0.0035059689544141293, -0.025305770337581635, -0.08385021984577179, 0.014138997532427311, -0.02976410835981369, -0.022794032469391823, 0.010748149827122688, 0.03457827493548393, -0.025389496237039566, 0.018168246373534203, 0.0012401711428537965, -0.02323358692228794, 0.03838774561882019, 0.028843136504292488, -0.04629972204566002, 0.06162133067846298, -0.05236975848674774, -0.002849254058673978, 0.048644013702869415, 0.010779546573758125, 0.018858972936868668, -0.04470895603299141, 0.012349383905529976, 0.01860780082643032, 0.026770951226353645, -0.022856825962662697, -0.036566734313964844, 0.009152148850262165, 0.04768117889761925, 0.06651922315359116, -0.02892686054110527, 0.1332896202802658, -0.018775248900055885, 0.016786789521574974, -0.016022801399230957, -0.005057491362094879, -0.01561464462429285, 0.016682133078575134, -0.008927139453589916, -0.03493410348892212, -0.02409176342189312, 0.02838265150785446, -0.0011943841818720102, -0.04617413505911827, -0.0643005222082138, -0.07099848985671997, -0.01830429770052433, 0.04395543411374092, 0.023735933005809784, 0.0406273789703846, -0.015405332669615746, 0.05132320150732994, 0.052244171500205994, 0.053374454379081726, 0.031187426298856735, 0.013762236572802067, -0.011606327258050442, -0.05504894629120827, -0.014944847673177719, 0.022647513076663017, 0.009293434210121632, 0.027733784168958664, -0.0414227619767189, 0.05479777231812477, -0.0011283202329650521, 0.0509464405477047, 0.0020826503168791533, 0.009345762431621552, -0.01683911681175232, 0.021318385377526283, -0.043285634368658066, 0.001103464514017105, 0.0005818207864649594, -0.0348922424018383, 0.04198790341615677, -0.019392717629671097, -0.01650421880185604, 0.01576116308569908, 0.014976243488490582, 0.03399220108985901, 0.002455486450344324, 0.014285515993833542, -0.04948125779628754, -0.0040501793846488, -0.04242745786905289, -0.0530395545065403, -0.036985356360673904, -0.026059292256832123, -0.08682244271039963, -0.05764441192150116, -0.07233808189630508, -0.015844887122511864, 0.013040111400187016, 0.07242181152105331, -0.03857612609863281, -0.003924592398107052, 0.020041584968566895, 0.04089948534965515, 0.010926065035164356, -0.03397126868367195, 0.045295026153326035, -0.0034013132099062204, -0.02155909314751625, 0.0197904109954834, 0.036566734313964844, -0.019392717629671097, -0.050444092601537704, -0.06145388260483742, 0.0023482143878936768, -0.014243653044104576, 0.03480851650238037, 0.06597501039505005, -0.004667648579925299, -0.01703796349465847, -0.00442170724272728, 0.03815750032663345, -0.08138034492731094, 0.01156446523964405, -0.006609013304114342, 0.0010727219050750136, -0.019863668829202652, -0.028047751635313034, -0.006148527842015028, -0.06363072246313095, -0.05471405014395714, 0.04483454301953316, -0.02430107444524765, 0.030036212876439095, 0.011365619488060474, 0.07476609945297241, 0.014233187772333622, 0.01330175157636404, -0.0330502986907959, -0.02314986102283001, 0.05952821671962738, -0.013165698386728764, -0.07945467531681061, -0.005954914726316929, 0.007660803850740194, 0.02147536911070347, 0.032987505197525024, -0.031166495755314827, -0.016870513558387756, 0.0002776648907456547, -0.05379307642579079, -0.04274142533540726, -0.04029247909784317, -0.002938211429864168, -0.023589415475726128, 0.023275448009371758, 0.020491603761911392, -0.025703461840748787, -0.009999861009418964, 0.046969518065452576, -0.011334222741425037, 0.035603899508714676, 0.005965379998087883, 0.037403982132673264, 0.02492900937795639, 0.015635576099157333, 0.003898428287357092, 0.007304974365979433, 0.02545228973031044, 0.028864067047834396, -0.059277042746543884, 0.00930390041321516, -0.006122363731265068, -0.008016633801162243, 0.016169320791959763, -0.047388143837451935, -0.009152148850262165, 0.02536856383085251, -0.04165300726890564, 0.029282690957188606, -0.01799033023416996, 0.018586868420243263, 0.07999888807535172, -0.01382503006607294, 0.0509464405477047, 0.028236132115125656, 0.001643095980398357, 0.08146406710147858, 0.008267807774245739, -0.0074462597258389, 0.013448269106447697, 0.015133227221667767, 0.04483454301953316, -0.02147536911070347, 0.021642817184329033, -0.02714771218597889, -0.03470386192202568, -0.00951321143656969, -0.04081575945019722, 0.04952312260866165, -0.08992026001214981, -0.038241226226091385, 0.005520592909306288, -0.00199892558157444, -0.016964703798294067, -0.01673446036875248, -0.06744018942117691, 0.038010984659194946, -0.013448269106447697, -0.015039036981761456, 0.023066136986017227, -0.048225387930870056, -0.022898687049746513, 0.01726820506155491, -0.016912376508116722, 0.03271540254354477, 0.0007986545097082853, -0.01934039033949375, 0.0036734184250235558, -0.016472822055220604, 0.012642419897019863, -0.04839283972978592, 0.05689089000225067, 0.026059292256832123, 0.006509590428322554, 0.010120214894413948, 0.005682809744030237, 0.00946088321506977, -0.0029643753077834845, -0.010266733355820179, -0.01903688907623291, -0.017498448491096497, 0.03537365794181824, -0.03399220108985901, 0.0154157979413867, 0.058021172881126404, 0.026980264112353325, -0.004288271069526672, 0.10122308135032654, -0.04378798231482506, 0.019947394728660583, -0.035938799381256104, -0.01883804239332676, 0.0197904109954834, -0.016462355852127075, -0.04479267820715904, -0.010350458323955536, -0.013280820101499557, -0.018283367156982422, -0.01800079643726349, 0.037383049726486206, -0.06195623055100441, -0.008037565276026726, 0.01664027012884617, 0.027063988149166107, -0.04031341150403023, -0.01235984917730093, 0.026477916166186333, -0.028005890548229218, -0.027838440611958504, -0.03399220108985901, 0.02398710697889328, 0.04893704876303673, 0.004978999495506287, -0.015426264144480228, 0.01744612120091915, -0.048560287803411484, -0.03081066533923149, 0.08992026001214981, -0.050653405487537384, -0.010031257756054401, -0.05630481615662575, -0.08217573165893555, -0.06388189643621445, -0.0321502611041069, 0.01520648691803217, 0.020596260204911232, -0.025494150817394257, -0.014222722500562668, -0.06744018942117691, -0.018367091193795204, 0.002917280187830329, -0.0734265074133873, -0.016765857115387917, -0.03323867917060852, 0.033406127244234085, -0.08899928629398346, 0.030475767329335213, 0.015698369592428207, -0.006059570237994194, 0.03840867429971695, 0.005986311472952366, 0.043494947254657745, -0.008581775240600109, -0.002468568505719304, -0.045295026153326035, 0.0548814982175827, 0.01252729818224907, -0.08757596462965012, 0.013866892084479332, 0.014578551985323429, 0.0410250723361969, 0.01199355348944664, -0.025305770337581635, 0.0060438718646764755, 0.02631046622991562, 0.03556203842163086, -0.04378798231482506, -0.036545801907777786, -0.0002747214457485825, -0.016169320791959763, -0.012799403630197048, -0.00013997712812852114, 0.04215535148978233, 0.0011983087752014399, 0.003385614836588502, 0.028989654034376144, -0.029722245410084724, 0.006745066028088331, 0.05257907137274742, 0.01088420208543539, -0.04998360574245453, -0.018660128116607666, 0.014641345478594303, 0.009738221764564514, -0.036671388894319534, -0.029324553906917572, 0.019612494856119156, -0.001988460076972842, 0.05814675986766815, 0.04923008382320404, -0.014568086713552475, 0.057058338075876236, 0.01493438147008419, -0.01341687235981226, -0.0036394051276147366, -0.007550915237516165, 0.005531058646738529, 0.005766534246504307, -0.0003221436054445803, 0.020491603761911392, 0.0007698741974309087, -0.0697844848036766, 0.005750835873186588, 0.00481155002489686, -0.02945014089345932, -0.041925109922885895, 0.0034745722077786922, -0.012328452430665493, 0.02576625533401966, 0.02176840417087078, 0.008508515544235706, 0.042636770755052567, -0.05810489505529404, 0.001093653030693531, 0.008487585000693798, -0.04209256172180176, -0.0925157219171524, 0.022773100063204765, 0.0030768802389502525, -0.02367313951253891, -0.044960130006074905, 0.010298130102455616, 0.013594787567853928, -0.01766589842736721, 0.041590213775634766, -0.008335833437740803, -0.005473497789353132, -0.060867808759212494, -0.06229112669825554, 0.052872106432914734, -0.033824753016233444, 0.04408102110028267, 0.032568883150815964, -0.015740230679512024, -0.05764441192150116, -0.043913569301366806, -0.008492817170917988, 0.011553999967873096, 0.03127115219831467, -0.032966576516628265, -0.026791883632540703, 0.06601687520742416, -0.004154834896326065, 0.04512757807970047, -0.06614246219396591, -0.05986311286687851, -0.031417667865753174, -0.0043876939453184605, 0.007231715135276318, 0.08138034492731094, -0.01818917691707611, -0.01125049777328968, -0.04579737409949303, -0.02020903304219246, -0.04789049178361893, -0.018335694447159767, -0.041694868355989456, 0.06254230439662933, -0.002692270325496793, -0.0009033103124238551, 0.020648587495088577, 0.028780343011021614, -0.031061839312314987, 0.01924620009958744, 0.08326414972543716, -0.06120270863175392, 0.03365730121731758, -0.019539237022399902, 0.028905929997563362, -0.030747871845960617, -0.02905244752764702, 0.03857612609863281, 0.0041391365230083466, -0.030140867456793785, -0.03219212219119072, 0.051699962466955185, 0.017017031088471413, 0.04215535148978233 ]
30,802
networkx.classes.function
is_path
Returns whether or not the specified path exists. For it to return True, every node on the path must exist and each consecutive pair must be connected via one or more edges. Parameters ---------- G : graph A NetworkX graph. path : list A list of nodes which defines the path to traverse Returns ------- bool True if `path` is a valid path in `G`
def is_path(G, path): """Returns whether or not the specified path exists. For it to return True, every node on the path must exist and each consecutive pair must be connected via one or more edges. Parameters ---------- G : graph A NetworkX graph. path : list A list of nodes which defines the path to traverse Returns ------- bool True if `path` is a valid path in `G` """ try: return all(nbr in G._adj[node] for node, nbr in nx.utils.pairwise(path)) except (KeyError, TypeError): return False
(G, path)
[ 0.04038195684552193, 0.030403126031160355, -0.0792563185095787, 0.025485502555966377, -0.012670961208641529, 0.015210537239909172, -0.0037689825985580683, 0.009225034154951572, 0.03390289470553398, 0.0076950062066316605, 0.06342659145593643, 0.01117234118282795, 0.0443304143846035, -0.011037735268473625, -0.05219143629074097, -0.033220890909433365, 0.02970317378640175, -0.02654440701007843, 0.021662676706910133, -0.015372064895927906, -0.018162906169891357, -0.018934650346636772, -0.00480545312166214, 0.027603311464190483, -0.00043578862096183, 0.02640082687139511, 0.027477677911520004, 0.040776804089546204, 0.01319143921136856, 0.011899217031896114, -0.0020662101451307535, -0.013110675849020481, -0.059837087988853455, 0.030062124133110046, 0.04275103285908699, 0.08105107396841049, -0.0018227966502308846, -0.005693856161087751, -0.05725264176726341, -0.05172479897737503, -0.0014851586893200874, 0.007259778678417206, -0.029254484921693802, 0.011342843063175678, 0.040705014020204544, -0.011414633132517338, -0.012832488864660263, 0.017086055129766464, -0.01643994264304638, -0.006649562157690525, 0.02072940394282341, -0.0036388630978763103, -0.0007291186484508216, -0.04145880788564682, 0.010598020628094673, 0.001963011920452118, 0.03103129006922245, 0.08385089039802551, -0.005631039384752512, -0.02514449879527092, -0.010113436728715897, -0.016502760350704193, 0.03445927053689957, 0.009628853760659695, 0.0032597212120890617, -0.034943852573633194, -0.021303726360201836, -0.08385089039802551, -0.03524896129965782, 0.025700872763991356, -0.055206622928380966, 0.048099398612976074, -0.03733087703585625, -0.010212148539721966, -0.022901056334376335, -0.005200298503041267, 0.01180947944521904, 0.05800643935799599, 0.009041071869432926, -0.031605612486600876, -0.008300735615193844, -0.05420156195759773, -0.01336194109171629, 0.014438793063163757, 0.016287390142679214, 0.036164287477731705, 0.04099217429757118, 0.008543027564883232, -0.055314306169748306, 0.048063501715660095, 0.007591807749122381, -0.010777495801448822, 0.0132542559877038, -0.029146799817681313, 0.025934189558029175, -0.020065346732735634, 0.0192397590726614, -0.0388384684920311, -0.024767599999904633, -0.037653930485248566, -0.017391161993145943, -0.02785457670688629, -0.004904164467006922, -0.006052806507796049, -0.009251954965293407, -0.009413482621312141, -0.04745328798890114, -0.010454440489411354, 0.0007106103003025055, -0.07904095202684402, -0.012940173968672752, 0.019508972764015198, 0.06611872464418411, -0.013604233041405678, -0.0036074549425393343, -0.004466693382710218, 0.05118637531995773, -0.027046937495470047, -0.05517072603106499, -0.040489643812179565, 0.047919921576976776, 0.05463230237364769, -0.022685686126351357, 0.025431659072637558, 0.09196317940950394, -0.0207473523914814, 0.00968269631266594, 0.02200368046760559, -0.025700872763991356, -0.01902438886463642, 0.0048009660094976425, 0.02518039382994175, 0.012976069003343582, 0.059801191091537476, -0.046807173639535904, 0.02076529897749424, -0.046807173639535904, -0.04031016677618027, 0.019778184592723846, 0.004074090626090765, 0.005429129581898451, -0.024875285103917122, 0.0029591000638902187, 0.029918543994426727, 0.0530170239508152, 0.04278692603111267, -0.037582140415906906, 0.01094799768179655, 0.05427335202693939, 0.031910721212625504, -0.016484811902046204, -0.03596686199307442, 0.04853013902902603, 0.006864932831376791, -0.02360101044178009, -0.03203635290265083, -0.033292680978775024, 0.04881729930639267, 0.03593096882104874, -0.049642886966466904, -0.007591807749122381, -0.015363091602921486, -0.00047701186849735677, 0.04713023081421852, -0.02216520719230175, 0.025772662833333015, -0.019688447937369347, 0.04296640306711197, -0.02677772380411625, 0.044976525008678436, 0.00628612469881773, -0.03243120014667511, -0.03124666027724743, -0.04307408630847931, -0.06565208733081818, 0.018100090324878693, 0.019921764731407166, 0.04013069346547127, 0.021644728258252144, 0.0032619647681713104, -0.011495397426187992, -0.024247121065855026, -0.00952116772532463, 0.01940128766000271, 0.01778600923717022, 0.024354806169867516, 0.013281176798045635, -0.034943852573633194, 0.027298202738165855, 0.0061963871121406555, -0.0875839814543724, 0.020442243665456772, 0.0439714640378952, 0.06540082395076752, 0.018037274479866028, -0.011441554874181747, 0.024031750857830048, 0.018862860277295113, -0.06812884658575058, 0.07279520481824875, 0.0852866917848587, -0.030259545892477036, 0.011621030047535896, 0.0033045902382582426, 0.001729693845845759, 0.016673261299729347, -0.010867233388125896, -0.02929037995636463, 0.016727104783058167, 0.015129772946238518, -0.03374136984348297, -0.03686423972249031, 0.060088351368904114, 0.0012686664704233408, 0.01397215761244297, 0.07573860138654709, -0.01709502935409546, 0.04002300649881363, 0.007152093108743429, -0.0219857320189476, 0.06550850719213486, 0.01416060607880354, 0.03718729689717293, -0.0020549928303807974, 0.055529676377773285, -0.042069025337696075, 0.002606879686936736, 0.03995121642947197, -0.013317071832716465, -0.021842151880264282, 0.025880347937345505, 0.036002758890390396, 0.022972846403717995, 0.0073181078769266605, -0.0030106992926448584, 0.006945696659386158, -0.002965830499306321, 0.0072328574024140835, 0.01906028389930725, 0.014259317889809608, 0.02498297020792961, -0.02498297020792961, -0.07265162467956543, -0.08837366849184036, 0.023277955129742622, 0.014546478167176247, 0.0017364241648465395, -0.013308098539710045, -0.005204785615205765, -0.019867923110723495, -0.08155360817909241, 0.04002300649881363, -0.020316611975431442, -0.05427335202693939, -0.013604233041405678, -0.041997235268354416, -0.08284582942724228, -0.01778600923717022, 0.013828576542437077, 0.019706394523382187, -0.03433363884687424, 0.013523468747735023, -0.0061380574479699135, 0.08155360817909241, 0.005276575684547424, -0.004009030759334564, 0.02518039382994175, -0.0058957659639418125, -0.013577311299741268, -0.03736677020788193, 0.06357017159461975, -0.01640404760837555, -0.010912102647125721, 0.006811090279370546, 0.07480533421039581, 0.033472154289484024, 0.02941601164638996, 0.0014571156352758408, 0.004184019286185503, 0.025647029280662537, -0.04547905921936035, 0.018503909930586815, 0.004832374397665262, -0.014322133734822273, -0.055493783205747604, 0.031731244176626205, -0.0053214444778859615, 0.0439714640378952, -0.010669810697436333, 0.008623790927231312, 0.08349193632602692, -0.020944776013493538, 0.024157384410500526, 0.033005520701408386, 0.029954439029097557, 0.1351090520620346, 0.07168246060609818, -0.01902438886463642, -0.017032211646437645, -0.0253598690032959, 0.07351311296224594, 0.02361895889043808, -0.01895259879529476, -0.055673256516456604, 0.036271970719099045, 0.002514898544177413, -0.029003219678997993, 0.046735383570194244, -0.029128851369023323, 0.01574896275997162, -0.03419005870819092, 0.005743211600929499, -0.03819235786795616, 0.0237625390291214, 0.030151860788464546, 0.008942360058426857, -0.01119926292449236, -0.03675655648112297, -0.07853841781616211, -0.008543027564883232, -0.011872295290231705, 0.08686607331037521, 0.00735400291159749, 0.018844913691282272, -0.11651540547609329, 0.030187755823135376, 0.034531060606241226, 0.021267831325531006, 0.0015793832717463374, 0.052586283534765244, -0.012895304709672928, -0.03419005870819092, 0.0250906553119421, 0.027011042460799217, 0.019921764731407166, 0.05728853493928909, -0.013747813180088997, -0.004049412906169891, 0.019491024315357208, 0.03862309828400612, 0.039197418838739395, 0.004908651113510132, -0.01904233545064926, -0.011423607356846333, 0.03442337363958359, -0.010436492040753365, -0.05348365753889084, 0.07774873077869415, 0.004565404728055, 0.03715139999985695, 0.02514449879527092, 0.057216744869947433, 0.0035872638691216707, 0.005173377227038145, 0.015623330138623714, 0.04264334589242935, 0.0016029393300414085, 0.026077769696712494, 0.014546478167176247, 0.07240036129951477, 0.08808650821447372, 0.008049470372498035, -0.011665898375213146, -0.031892772763967514, -0.01941923424601555, 0.032018404453992844, 0.00855648797005415, 0.03991531953215599, -0.022470315918326378, 0.01026599109172821, 0.008444315753877163, -0.02046019211411476, 0.004233375191688538, -0.012482511810958385, 0.018342383205890656, 0.02352922037243843, 0.06647767871618271, -0.007937298156321049, 0.025736767798662186, 0.03241325169801712, 0.007668084930628538, -0.013828576542437077, 0.05517072603106499, 0.024803495034575462, 0.0560322105884552, 0.02056787721812725, 0.07846663147211075, -0.0006545242504216731, -0.008991715498268604, -0.026275193318724632, -0.009041071869432926, -0.03729498013854027, -0.019473077729344368, -0.051114585250616074, -0.024713758379220963, -0.04332535341382027, 0.07825125753879547, 0.0313902422785759, -0.005545788910239935, -0.03666681796312332, 0.009637827053666115, -0.003867694176733494, -0.014986192807555199, 0.04720202088356018, -0.00779820466414094, 0.0043904162012040615, -0.007968706078827381, 0.03261067345738411, 0.02501886524260044, -0.010068568401038647, 0.017364241182804108, -0.04576621949672699, 0.008924412541091442, -0.008704555220901966, -0.021429358050227165, 0.009359640069305897, -0.048135291785001755, 0.01783985085785389, 0.021519096568226814, -0.0022625112906098366, 0.02072940394282341, -0.008044983260333538, -0.026131613180041313, 0.0061380574479699135, 0.018001379445195198, -0.01106465607881546, -0.05563736334443092, 0.0032911296002566814, 0.05377081781625748, 0.042033132165670395, -0.06407270580530167, -0.04109985753893852, 0.03603865206241608, -0.05326828733086586, -0.05341186746954918, -0.01617073081433773, -0.01940128766000271, -0.056857794523239136, -0.02087298408150673, -0.011567187495529652, -0.02798021025955677, 0.057037271559238434, -0.0471661277115345, -0.012778646312654018, 0.008058443665504456, -0.047740448266267776, -0.022524157539010048, -0.0012024849420413375, 0.10617762804031372, 0.0082468930631876, -0.05010952055454254, -0.023080531507730484, 0.0019013171549886465, -0.02681361883878708, -0.039089735597372055, 0.0008188563515432179, -0.009871144779026508, 0.006483547389507294, -0.05915508046746254, 0.046412330120801926, -0.016000228002667427, 0.00821099802851677, -0.01177358441054821, -0.04551495239138603, 0.012482511810958385, -0.03259272500872612, 0.03704371675848961, 0.0342259518802166, 0.04372020065784454, 0.021411411464214325, 0.004578865133225918, -0.021913941949605942, -0.05280165374279022, -0.004071847535669804, 0.07326184213161469, -0.011701793409883976, 0.03225172311067581, 0.03937689587473869, -0.050755634903907776, 0.006479060743004084, -0.008884030394256115, -0.0342259518802166, 0.03548227995634079, 0.0207473523914814, 0.00952116772532463, -0.017247581854462624, -0.043468933552503586, 0.018198801204562187, -0.032072246074676514, -0.05477588251233101, 0.042356185615062714, -0.06698020547628403, -0.024426598101854324, -0.011791531927883625, 0.04619695991277695, -0.01689760573208332, -0.03603865206241608, 0.012087665498256683, 0.00913978274911642, 0.009386561810970306, -0.015022087842226028, 0.04174596816301346, 0.028967324644327164, 0.02062171883881092, -0.003472848329693079, 0.033328574150800705, 0.025377817451953888, -0.014654163271188736, 0.01940128766000271, 0.037618037313222885, 0.024588124826550484, 0.02358306385576725, 0.01824367046356201, 0.07537965476512909, 0.03287988528609276, 0.0356438085436821, -0.01473492756485939, -0.05897560343146324, 0.03099539503455162, 0.017669349908828735, 0.017561664804816246, 0.023439481854438782, 0.02805200032889843, 0.039340998977422714, -0.06945696473121643, 0.04389967396855354, 0.010499308817088604, -0.058293599635362625, -0.005083639640361071, -0.006461113225668669, -0.003457144135609269, 0.07990243285894394, 0.00552784139290452, 0.07175425440073013, 0.020944776013493538, 0.034890010952949524, 0.05351955443620682, -0.00480993976816535, -0.06963644176721573, -0.007152093108743429, -0.008507132530212402, -0.019849974662065506, -0.0018250400898978114, 0.013846524059772491, 0.019437182694673538, 0.00114135118201375, 0.03851541504263878, -0.04422273114323616, 0.005213759373873472, -0.042248502373695374, -0.027531521394848824, 0.01918591745197773, -0.012392774224281311, -0.04562263935804367, 0.04695075377821922, 0.018037274479866028, -0.002208668738603592, 0.027567416429519653, 0.007053381763398647, -0.005056718364357948, -0.09009663015604019, -0.10122410953044891, -0.06306764483451843, -0.03682834655046463, 0.0034795785322785378, -0.04099217429757118, 0.0016208868473768234, -0.06012424826622009, 0.04142291471362114, 0.004365738481283188, 0.010095489211380482, -0.01941923424601555, -0.008264840580523014, -0.07415921986103058, 0.0009226155234500766, -0.0035423950757831335, -0.014977219514548779, 0.023977909237146378, 0.046448223292827606, -0.03514127805829048, 0.007219396531581879, -0.001633225823752582, -0.02058582380414009, 0.042176712304353714, 0.012303036637604237, 0.020065346732735634, -0.039089735597372055, 0.015973307192325592, -0.04892498627305031, -0.017193740233778954, 0.012204324826598167, -0.02365485392510891, 0.051006898283958435, -0.017884720116853714, 0.009234007447957993, 0.007923837751150131, 0.057144954800605774, 0.0019181430106982589, -0.00038587203016504645, 0.005124021787196398, -0.05495535582304001, 0.03804877772927284, 0.02817763201892376, -0.046699490398168564, -0.022613896057009697, -0.03567970171570778, 0.028626320883631706, 0.013200413435697556, -0.00018045687465928495, -0.0413152277469635, 0.004827887285500765, 0.02814173698425293, -0.015345144085586071, -0.04490473493933678, -0.015237458981573582, 0.019616657868027687, -0.04630464315414429, 0.0176424290984869, -0.05208374932408333, 0.0026786697562783957, -0.022488262504339218, -0.05761159211397171, 0.03837183490395546, -0.017471926286816597, 0.001853083143942058, 0.015883570536971092, 0.03977173939347267, -0.019598709419369698, -0.023260006681084633, -0.03413621336221695, 0.02491118013858795, -0.058150019496679306, -0.04748918116092682, 0.01904233545064926, 0.01608099229633808, -0.1104850322008133, -0.03366957977414131, -0.02654440701007843, 0.02964933030307293, 0.01599125564098358, -0.1539180725812912, 0.024624019861221313, -0.08686607331037521, -0.020908880978822708, 0.012931199744343758, 0.018826965242624283, 0.027387941256165504, -0.04016658663749695, 0.05025310069322586, -0.018118038773536682, 0.02806994691491127, 0.05883202329277992, 0.005801541265100241, -0.013514495454728603, 0.02512655034661293, 0.061452366411685944, 0.025934189558029175, -0.018862860277295113, -0.007551426067948341, 0.006398296914994717, 0.0565706342458725, -0.008525080047547817, 0.010633915662765503, 0.027118727564811707, -0.013424756936728954, 0.034890010952949524, 0.022936951369047165, -0.04605337977409363, -0.006241255905479193, -0.01326322928071022, -0.06374964863061905, -0.005447077564895153, -0.004657385870814323, -0.04458168148994446, -0.010544178076088428, -0.00391929317265749, -0.013711918145418167, -0.04458168148994446, -0.021644728258252144, 0.0035738032311201096, -0.04293050616979599, 0.010481361299753189, -0.00402024807408452, -0.018611595034599304, -0.017669349908828735, 0.031767141073942184, -0.006200873758643866, -0.020190978422760963, 0.04013069346547127, -0.02675977721810341, -0.008534053340554237, -0.06540082395076752, 0.057216744869947433, 0.06295996159315109, 0.009099400602281094, -0.007739874999970198, -0.007300160359591246, 0.0558527335524559, -0.010544178076088428, -0.048207081854343414, -0.0034033015836030245, 0.0072328574024140835, -0.014501609839498997, 0.03241325169801712, -0.00965577457100153, -0.02975701540708542, -0.06787758320569992, -0.012240219861268997, -0.016215600073337555, 0.019616657868027687, -0.0675545260310173, -0.021231936290860176, 0.03106718510389328, -0.06030372157692909, 0.034584902226924896, -0.06575977057218552, 0.02683156728744507, -0.06220616027712822, -0.004480153787881136, -0.02645466849207878, 0.004827887285500765, -0.05046847462654114, -0.05190427601337433, 0.008435342460870743, -0.10222917050123215, -0.023313850164413452, -0.024606073275208473, -0.03429774194955826, 0.04407915100455284, -0.005011849571019411, -0.054022084921598434, 0.03693602979183197, -0.01927565410733223, 0.10402391850948334, 0.01041854452341795, -0.028859639540314674, -0.026921303942799568, 0.06087804213166237, -0.013658075593411922, -0.00439714640378952, 0.028572477400302887, -0.030277494341135025, 0.05624758079648018, -0.06748273968696594, -0.04422273114323616, -0.018198801204562187, 0.00006684756226604804, 0.009736538864672184, -0.0356438085436821, -0.027334097772836685, 0.03725908696651459, 0.007488609757274389, 0.011656925082206726, -0.027226412668824196, 0.03217993304133415, 0.014600320719182491, -0.055206622928380966, -0.031910721212625504, -0.030133914202451706, -0.037689827382564545, -0.09813713282346725, -0.007820638827979565, -0.006550850812345743, -0.04142291471362114, 0.0335080511868, 0.012877357192337513, -0.03402853012084961, 0.046591803431510925 ]
30,803
networkx.algorithms.matching
is_perfect_matching
Return True if ``matching`` is a perfect matching for ``G`` A *perfect matching* in a graph is a matching in which exactly one edge is incident upon each vertex. Parameters ---------- G : NetworkX graph matching : dict or set A dictionary or set representing a matching. If a dictionary, it must have ``matching[u] == v`` and ``matching[v] == u`` for each edge ``(u, v)`` in the matching. If a set, it must have elements of the form ``(u, v)``, where ``(u, v)`` is an edge in the matching. Returns ------- bool Whether the given set or dictionary represents a valid perfect matching in the graph. Examples -------- >>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5), (4, 6)]) >>> my_match = {1: 2, 3: 5, 4: 6} >>> nx.is_perfect_matching(G, my_match) True
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, matching, *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,804
networkx.algorithms.planarity
is_planar
Returns True if and only if `G` is planar. A graph is *planar* iff it can be drawn in a plane without any edge intersections. Parameters ---------- G : NetworkX graph Returns ------- bool Whether the graph is planar. Examples -------- >>> G = nx.Graph([(0, 1), (0, 2)]) >>> nx.is_planar(G) True >>> nx.is_planar(nx.complete_graph(5)) False See Also -------- check_planarity : Check if graph is planar *and* return a `PlanarEmbedding` instance if True.
def sign_recursive(self, e): """Recursive version of :meth:`sign`.""" if self.ref[e] is not None: self.side[e] = self.side[e] * self.sign_recursive(self.ref[e]) self.ref[e] = None return self.side[e]
(G, *, backend=None, **backend_kwargs)
[ -0.020766358822584152, -0.04132557287812233, 0.08016540110111237, 0.10716339200735092, -0.0260140523314476, -0.03217663615942001, -0.029794462025165558, 0.008057106286287308, 0.016476716846227646, -0.04205058515071869, 0.0060546970926225185, 0.00435869162902236, 0.032487355172634125, -0.03436892852187157, -0.06345564126968384, 0.028568848967552185, -0.0001560335949761793, 0.0012331644538789988, -0.008164994418621063, 0.013654355891048908, 0.025668809190392494, 0.029518267139792442, 0.048230431973934174, -0.0033682759385555983, -0.05409955978393555, 0.020075874403119087, 0.041774388402700424, -0.019885990768671036, -0.008001004345715046, -0.024305099621415138, -0.021750301122665405, 0.01758149452507496, -0.006248896475881338, -0.029518267139792442, 0.036354076117277145, -0.04795423522591591, -0.06276515871286392, 0.04363870248198509, -0.09390606731176376, 0.003150341333821416, -0.04788518697023392, -0.0006041750311851501, 0.006438779644668102, -0.0366993173956871, 0.01613147370517254, 0.0005370145081542432, 0.05496266856789589, 0.030812928453087807, 0.031676035374403, -0.037493377923965454, 0.023079486563801765, 0.0012892663944512606, 0.014405259862542152, -0.02599678933620453, -0.012057607993483543, 0.04602087661623955, 0.050163790583610535, 0.00832898449152708, 0.008057106286287308, 0.022406263276934624, 0.07367483526468277, 0.021871136501431465, -0.0029539845418184996, 0.02468486689031124, 0.007897431030869484, 0.015794862061738968, 0.019575271755456924, 0.010020675137639046, 0.011444801464676857, 0.054928142577409744, -0.04702208191156387, -0.0292593352496624, 0.004050130490213633, 0.01683059148490429, 0.026859896257519722, -0.0423613004386425, 0.04246487468481064, 0.017883582040667534, 0.012290646322071552, -0.0597270205616951, -0.058138903230428696, -0.04536491632461548, 0.04391489550471306, 0.053063832223415375, -0.016217784956097603, 0.07498675584793091, 0.06963548809289932, 0.0053728423081338406, 0.011142713949084282, 0.03385106474161148, -0.02323484607040882, -0.005338318180292845, -0.045710157603025436, -0.008505921810865402, 0.05534243583679199, 0.030087918043136597, 0.006999799516052008, -0.04205058515071869, -0.015354677103459835, -0.036837417632341385, 0.04139462113380432, 0.04726375266909599, -0.03887435048818588, -0.04205058515071869, 0.04101485386490822, -0.037804096937179565, 0.048230431973934174, -0.04940425604581833, 0.017900843173265457, 0.03190044313669205, 0.007189683150500059, 0.043949417769908905, 0.00932155828922987, -0.02504737116396427, -0.052511442452669144, -0.0007028929539956152, -0.020541951060295105, -0.016243677586317062, 0.03531834855675697, 0.038287434726953506, 0.05727579444646835, -0.027740266174077988, -0.035266559571027756, -0.007988057099282742, -0.04277559369802475, 0.031054597347974777, 0.027308711782097816, 0.029880771413445473, -0.06017583608627319, -0.01248916145414114, 0.02551344968378544, 0.025530710816383362, 0.03921959176659584, 0.03939221426844597, -0.035076677799224854, 0.0332641527056694, 0.05264953896403313, -0.03407547250390053, -0.02637655660510063, 0.006943697575479746, -0.022354476153850555, -0.016942795366048813, 0.03317784145474434, 0.052166201174259186, 0.04567563533782959, 0.08444640785455704, -0.012394219636917114, 0.0653199553489685, -0.019109193235635757, 0.028914092108607292, -0.005476415157318115, 0.01709815487265587, 0.054824572056531906, 0.014310318045318127, 0.01590706594288349, 0.03215937316417694, 0.040635086596012115, 0.013490365818142891, -0.06718426942825317, 0.024046167731285095, 0.001624799333512783, 0.009571858681738377, -0.026739060878753662, -0.017849057912826538, 0.028448013588786125, -0.03247009217739105, 0.0174606591463089, 0.019264552742242813, -0.04771256819367409, 0.017011843621730804, -0.021025292575359344, -0.016191890463232994, -0.031589724123477936, 0.006559615023434162, 0.03859815374016762, 0.009416500106453896, 0.05675793066620827, 0.04073866084218025, -0.04916258528828621, -0.010866519995033741, 0.024719391018152237, -0.02268245816230774, 0.04505419731140137, -0.04315536096692085, 0.03642312437295914, 0.013749297708272934, 0.030139703303575516, -0.01822882518172264, 0.07284624874591827, -0.03119269572198391, -0.012661783024668694, 0.0318659171462059, 0.03883982449769974, -0.014474308118224144, 0.02275150641798973, 0.022613409906625748, -0.01194540411233902, 0.01173825841397047, 0.032487355172634125, -0.030450422316789627, -0.019523484632372856, -0.018004417419433594, 0.020852670073509216, -0.027895625680685043, -0.015725813806056976, 0.011453432962298393, 0.01551003661006689, 0.027049779891967773, -0.008691489696502686, 0.016813328489661217, 0.013455841690301895, -0.01173825841397047, -0.0073364111594855785, -0.030623044818639755, -0.00965816993266344, -0.045226819813251495, 0.014344842173159122, 0.011065034195780754, -0.007625552359968424, 0.032314732670784, -0.026946207508444786, -0.00516138132661581, -0.0034977418836206198, -0.05817342549562454, 0.008385086432099342, -0.028085509315133095, -0.006024488247931004, -0.024995585903525352, -0.015207949094474316, -0.03234925866127014, 0.0054548378102481365, -0.03034684993326664, -0.03184865787625313, -0.05762103945016861, 0.005791449453681707, -0.022216379642486572, 0.002431804547086358, -0.017452027648687363, 0.028258129954338074, 0.034299880266189575, -0.0028245183639228344, 0.013188278302550316, -0.002802940784022212, 0.07132717967033386, 0.022337215021252632, 0.027981935068964958, 0.07512485235929489, 0.0024749599397182465, 0.02780931442975998, 0.03271176293492317, 0.001410101423971355, -0.04004817456007004, -0.05409955978393555, 0.004246487282216549, 0.047747090458869934, -0.046193499118089676, 0.04785066470503807, 0.028517061844468117, 0.03687193989753723, 0.03642312437295914, 0.008898635394871235, -0.04301726445555687, 0.07553914189338684, -0.044432759284973145, -0.06777118146419525, 0.023027701303362846, -0.008626756258308887, -0.031520675867795944, 0.001146853668615222, 0.043707750737667084, 0.045951828360557556, -0.09224890172481537, 0.008031212724745274, 0.03070935420691967, 0.006818546913564205, -0.004613308236002922, 0.01779727078974247, 0.10536812990903854, -0.03376475349068642, -0.00332512054592371, 0.0215949434787035, -0.00039136517443694174, -0.024425935000181198, 0.051199521869421005, -0.09245604276657104, 0.03818386420607567, -0.008108892478048801, -0.02093898132443428, 0.027947410941123962, -0.018729425966739655, 0.0349213182926178, 0.09542513638734818, 0.023200321942567825, 0.014957647770643234, 0.04360417649149895, -0.03542191907763481, -0.044432759284973145, -0.01828061044216156, 0.046297069638967514, 0.04301726445555687, 0.012704938650131226, -8.091629979389836e-7, 0.0026670012157410383, -0.03583621233701706, 0.03438619151711464, -0.022406263276934624, 0.06566520035266876, -0.003305700607597828, 0.02654917724430561, -0.025358090177178383, -0.06124608963727951, 0.060003213584423065, -0.03169329836964607, -0.006956644356250763, -0.007599659264087677, -0.0030273485463112593, 0.03070935420691967, -0.0585186704993248, 0.03443797677755356, 0.06362826377153397, 0.028465276584029198, 0.034058209508657455, -0.0387362502515316, 0.015069851651787758, 0.034248095005750656, -0.01564813405275345, -0.019333600997924805, -0.0023692292161285877, 0.018297873437404633, -0.0023368627298623323, -0.02648012898862362, -0.015484143048524857, 0.03970293328166008, -0.03783861920237541, -0.08120112866163254, -0.015622240491211414, 0.0407731831073761, -0.009399238042533398, -0.019955039024353027, -0.029880771413445473, 0.033989161252975464, -0.00604606606066227, -0.012307909317314625, -0.011539743281900883, 0.0017337666358798742, 0.040566038340330124, 0.04132557287812233, -0.04270654544234276, 0.04947330430150032, 0.03486953303217888, 0.015207949094474316, 0.05513528734445572, -0.013412686064839363, -0.012169811874628067, -0.00866991188377142, 0.010849257931113243, -0.03656122088432312, -0.0002120007120538503, -0.021646728739142418, -0.026393819600343704, 0.04940425604581833, -0.03341951221227646, -0.03697551414370537, 0.003773936303332448, 0.021025292575359344, -0.04650421813130379, -0.0658378154039383, 0.010115616954863071, -0.023303894326090813, -0.005239060614258051, -0.004453633446246386, -0.0665283054113388, -0.005981333088129759, -0.012109394185245037, -0.027015255764126778, 0.05751746520400047, 0.010650742799043655, 0.03209032490849495, 0.031279005110263824, -0.061694905161857605, 0.029483743011951447, 0.022302690893411636, -0.011703734286129475, 0.012998394668102264, 0.011893616989254951, -0.018194301053881645, 0.08202970772981644, -0.010935568250715733, 0.06866881251335144, 0.0003150341217406094, -0.03476595878601074, -0.07215576618909836, 0.0387362502515316, -0.03970293328166008, -0.020403854548931122, -0.05862224102020264, 0.02654917724430561, -0.015337415039539337, -0.05351264774799347, 0.023424729704856873, 0.011039141565561295, 0.06021035835146904, -0.026739060878753662, -0.05116499587893486, 0.0017391610890626907, -0.025133682414889336, 0.00871738325804472, -0.004138599149882793, 0.016994580626487732, 0.013775191269814968, -0.05568767711520195, -0.020196709781885147, -0.0030683460645377636, 0.012247491627931595, 0.04850662499666214, -0.052097152918577194, -0.008941791020333767, 0.02292412705719471, -0.031762346625328064, -0.04705660417675972, -0.007116319146007299, -0.003532266244292259, -0.021336009725928307, 0.025979526340961456, 0.00020350450358819216, -0.021991971880197525, -0.0044493176974356174, -0.018142513930797577, -0.06973906606435776, 0.12159454822540283, -0.0496114045381546, -0.04640064388513565, 0.04788518697023392, -0.023908069357275963, 0.034955840557813644, -0.032487355172634125, -0.016813328489661217, -0.021560417488217354, -0.020541951060295105, 0.04916258528828621, 0.05365074425935745, 0.03452428802847862, -0.051199521869421005, -0.04457085579633713, 0.044432759284973145, -0.01985146664083004, -0.00818657223135233, 0.003685467876493931, -0.01721898838877678, -0.018660377711057663, 0.04646969214081764, 0.016399037092924118, 0.08354877680540085, -0.032970696687698364, -0.07243195921182632, -0.009045363403856754, -0.042568448930978775, -0.013645725324749947, -0.013852871023118496, -0.038770776242017746, -0.022975914180278778, -0.02492653578519821, -0.006296366918832064, -0.025444401428103447, -0.021025292575359344, -0.04864472150802612, 0.032970696687698364, -0.008881373330950737, -0.0585186704993248, -0.03814933821558952, 0.04615897312760353, -0.04633159562945366, -0.03794219344854355, 0.004427739884704351, -0.012722200714051723, -0.01809072680771351, -0.07402007281780243, -0.07326053828001022, -0.021646728739142418, -0.08734644949436188, -0.08762264251708984, -0.03811481595039368, 0.001905309152789414, 0.017054999247193336, 0.023562826216220856, -0.04101485386490822, -0.02074909768998623, -0.008592232130467892, 0.04104937985539436, -0.022458050400018692, -0.017710959538817406, 0.016157366335392, -0.0009402474388480186, 0.06884143501520157, 0.005485046189278364, 0.04422561451792717, -0.0480232872068882, -0.03776957094669342, -0.03742432966828346, -0.0031740767881274223, -0.0138183468952775, 0.004065235145390034, 0.01529426034539938, 0.0013432105770334601, 0.0173657163977623, 0.0011080139083787799, -0.01810798980295658, -0.01888478547334671, -0.017952630296349525, 0.02183661237359047, 0.018315134570002556, 0.007487454917281866, 0.059761542826890945, 0.048713769763708115, -0.0011339071206748486, 0.05085427686572075, -0.0025526396930217743, 0.017037736251950264, 0.05320192873477936, -0.05182095617055893, 0.04239582642912865, -0.1251160204410553, -0.0288450438529253, 0.04788518697023392, 0.05358169600367546, -0.02490927465260029, -0.02986351028084755, -0.033143315464258194, -0.006529406178742647, -0.0011274338467046618, -0.007802489213645458, 0.03728623315691948, -0.039254117757081985, -0.005338318180292845, -0.06877238303422928, 0.01032276265323162, -0.010124247521162033, -0.022837817668914795, 0.02466760389506817, -0.012014452368021011, 0.018315134570002556, 0.00834193080663681, -0.005907969083636999, 0.010434966534376144, -0.013084704987704754, -0.005217483267188072, -0.01614873670041561, -0.05751746520400047, 0.05503171682357788, -0.007910377345979214, -0.002859042724594474, 0.0015298575162887573, 0.004509735386818647, 0.005213167518377304, 0.08686310797929764, 0.008177940733730793, 0.02860337309539318, 0.045951828360557556, -0.004742774181067944, 0.010158771649003029, 0.002626003697514534, -0.015527298673987389, 0.026048576459288597, -0.11565636843442917, -0.023131273686885834, -0.014457046054303646, 0.054272182285785675, -0.021128864958882332, 0.033937375992536545, 0.018142513930797577, -0.021456845104694366, -0.005437575280666351, 0.04867924749851227, -0.021042553707957268, 0.005295162554830313, 0.03172782063484192, -0.002500853268429637, -0.009097150526940823, -0.05772460997104645, 0.00986531563103199, 0.028206344693899155, -0.10419430583715439, -0.011298073455691338, 0.022958651185035706, -0.014854075387120247, 0.04650421813130379, 0.05706864967942238, 0.03597430884838104, -0.04312083497643471, 0.01833239756524563, -0.04253392294049263, -0.08064873516559601, 0.022527098655700684, -0.04325893521308899, -0.016787435859441757, 0.0019117825431749225, -0.020852670073509216, 0.015734445303678513, 0.03257366642355919, -0.018988357856869698, -0.01840144582092762, -0.050163790583610535, 0.025530710816383362, 0.016640707850456238, -0.0653199553489685, 0.00042130419751629233, 0.04001365229487419, -0.02630750834941864, -0.04553753510117531, -0.037010036408901215, 0.022337215021252632, 0.02623846009373665, 0.017495183274149895, -0.027653954923152924, -0.008385086432099342, 0.017279407009482384, -0.02503011003136635, 0.0288450438529253, -0.05575672537088394, -0.01369751151651144, -0.10743958503007889, 0.00818657223135233, -0.07636772841215134, -0.032487355172634125, -0.028931353241205215, 0.01644219271838665, 0.05327097699046135, 0.028758732602000237, 0.00000856364204082638, 0.006840124726295471, -0.003074819454923272, -0.0018697059713304043, -0.054030511528253555, -0.008816639892756939, 0.014129064977169037, -0.022406263276934624, -0.00598564837127924, 0.006391308736056089, -0.053478121757507324, 0.08644881844520569, -0.001488859998062253, 0.004734143149107695, -0.0504399873316288, 0.020110398530960083, -0.04936973378062248, 0.03849458321928978, -0.02437414787709713, -0.00482908496633172, -0.05178643390536308, -0.002431804547086358, -0.008773485198616982, 0.08541309088468552, -0.020403854548931122, -0.03673384338617325, 0.030364111065864563, 0.0050923326052725315, 0.06859976053237915, 0.003890455700457096, -0.004022079519927502, 0.009779004380106926, -0.012178442440927029, 0.004466579761356115, -0.04481252655386925, 0.010771578177809715, -0.02679084800183773, -0.02565154619514942, 0.01641630008816719, -0.02394259348511696, 0.021077077835798264, -0.02219911850988865, 0.00018529832595959306, -0.03763147443532944, -0.043535128235816956, 0.03621597960591316, -0.0022915496956557035, -0.022613409906625748, 0.043189886957407, 0.005148434545844793, 0.03102007322013378, 0.029552791267633438, -0.07001525908708572, 0.03359213471412659, 0.005614512600004673, 0.016278201714158058, -0.0037221498787403107, -0.027101567015051842, 0.040635086596012115, 0.06231633946299553, -0.020904457196593285, -0.04912806302309036, -0.016329988837242126, -0.06821999698877335, 0.011772782541811466, 0.02052468992769718, -0.021008029580116272, 0.039116017520427704, -0.009830791503190994, 0.008562023751437664, 0.025979526340961456, 0.006218687631189823, 0.07402007281780243, -0.00712063442915678, 0.021405059844255447, 0.009416500106453896, 0.01888478547334671, -0.0070774792693555355, 0.04615897312760353, -0.010089723393321037, 0.01620052196085453, -0.0007633104687556624, -0.015725813806056976, 0.03141710162162781, -0.007228523027151823, -0.0013647882733494043, -0.026946207508444786, 0.03022601455450058, -0.024943798780441284, 0.017305299639701843, -0.005256323143839836, -0.0012482687598094344, -0.0823059007525444, -0.028206344693899155, 0.04173986613750458, -0.012204336002469063, -0.004365164786577225, 0.001410101423971355, 0.07091289013624191, 0.004669410176575184, -0.05744841694831848, -0.004531312733888626, -0.056930553168058395, 0.01188498642295599, 0.0718105211853981, 0.0117986761033535, -0.015777599066495895, 0.011988558806478977, 0.017011843621730804, 0.057828184217214584, -0.054686471819877625, -0.04108390212059021, 0.0443982370197773, 0.03512846305966377, -0.02335568144917488, -0.02021397091448307, 0.04488157480955124, 0.051199521869421005, -0.06179847568273544, 0.006223002914339304, 0.006641610059887171, -0.0709819346666336, 0.024822963401675224, 0.043293457478284836, 0.013723405078053474, -0.0012568999081850052, -0.05579125136137009, -0.0067365518771111965, -0.015043959021568298, 0.025081895291805267, 0.010236451402306557, -0.0001924459356814623, -0.05178643390536308, -0.04760899394750595, -0.00497581297531724, 0.08078683912754059, -0.028637897223234177, 0.06487113982439041, 0.02231995202600956, 0.03963388502597809 ]
30,810
networkx.algorithms.simple_paths
is_simple_path
Returns True if and only if `nodes` form a simple path in `G`. A *simple path* in a graph is a nonempty sequence of nodes in which no node appears more than once in the sequence, and each adjacent pair of nodes in the sequence is adjacent in the graph. Parameters ---------- G : graph A NetworkX graph. nodes : list A list of one or more nodes in the graph `G`. Returns ------- bool Whether the given list of nodes represents a simple path in `G`. Notes ----- An empty list of nodes is not a path but a list of one node is a path. Here's an explanation why. This function operates on *node paths*. One could also consider *edge paths*. There is a bijection between node paths and edge paths. The *length of a path* is the number of edges in the path, so a list of nodes of length *n* corresponds to a path of length *n* - 1. Thus the smallest edge path would be a list of zero edges, the empty path. This corresponds to a list of one node. To convert between a node path and an edge path, you can use code like the following:: >>> from networkx.utils import pairwise >>> nodes = [0, 1, 2, 3] >>> edges = list(pairwise(nodes)) >>> edges [(0, 1), (1, 2), (2, 3)] >>> nodes = [edges[0][0]] + [v for u, v in edges] >>> nodes [0, 1, 2, 3] Examples -------- >>> G = nx.cycle_graph(4) >>> nx.is_simple_path(G, [2, 3, 0]) True >>> nx.is_simple_path(G, [0, 2]) False
def _bidirectional_dijkstra( G, source, target, weight="weight", ignore_nodes=None, ignore_edges=None ): """Dijkstra's algorithm for shortest paths using bidirectional search. This function returns the shortest path between source and target ignoring nodes and edges in the containers ignore_nodes and ignore_edges. This is a custom modification of the standard Dijkstra bidirectional shortest path implementation at networkx.algorithms.weighted Parameters ---------- G : NetworkX graph source : node Starting node. target : node Ending node. weight: string, function, optional (default='weight') Edge data key or weight function corresponding to the edge weight ignore_nodes : container of nodes nodes to ignore, optional ignore_edges : container of edges edges to ignore, optional Returns ------- length : number Shortest path length. Returns a tuple of two dictionaries keyed by node. The first dictionary stores distance from the source. The second stores the path from the source to that node. Raises ------ NetworkXNoPath If no path exists between source and target. Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. In practice bidirectional Dijkstra is much more than twice as fast as ordinary Dijkstra. Ordinary Dijkstra expands nodes in a sphere-like manner from the source. The radius of this sphere will eventually be the length of the shortest path. Bidirectional Dijkstra will expand nodes from both the source and the target, making two spheres of half this radius. Volume of the first sphere is pi*r*r while the others are 2*pi*r/2*r/2, making up half the volume. This algorithm is not guaranteed to work if edge weights are negative or are floating point numbers (overflows and roundoff errors can cause problems). See Also -------- shortest_path shortest_path_length """ if ignore_nodes and (source in ignore_nodes or target in ignore_nodes): raise nx.NetworkXNoPath(f"No path between {source} and {target}.") if source == target: if source not in G: raise nx.NodeNotFound(f"Node {source} not in graph") return (0, [source]) # handle either directed or undirected if G.is_directed(): Gpred = G.predecessors Gsucc = G.successors else: Gpred = G.neighbors Gsucc = G.neighbors # support optional nodes filter if ignore_nodes: def filter_iter(nodes): def iterate(v): for w in nodes(v): if w not in ignore_nodes: yield w return iterate Gpred = filter_iter(Gpred) Gsucc = filter_iter(Gsucc) # support optional edges filter if ignore_edges: if G.is_directed(): def filter_pred_iter(pred_iter): def iterate(v): for w in pred_iter(v): if (w, v) not in ignore_edges: yield w return iterate def filter_succ_iter(succ_iter): def iterate(v): for w in succ_iter(v): if (v, w) not in ignore_edges: yield w return iterate Gpred = filter_pred_iter(Gpred) Gsucc = filter_succ_iter(Gsucc) else: def filter_iter(nodes): def iterate(v): for w in nodes(v): if (v, w) not in ignore_edges and (w, v) not in ignore_edges: yield w return iterate Gpred = filter_iter(Gpred) Gsucc = filter_iter(Gsucc) push = heappush pop = heappop # Init: Forward Backward dists = [{}, {}] # dictionary of final distances paths = [{source: [source]}, {target: [target]}] # dictionary of paths fringe = [[], []] # heap of (distance, node) tuples for # extracting next node to expand seen = [{source: 0}, {target: 0}] # dictionary of distances to # nodes seen c = count() # initialize fringe heap push(fringe[0], (0, next(c), source)) push(fringe[1], (0, next(c), target)) # neighs for extracting correct neighbor information neighs = [Gsucc, Gpred] # variables to hold shortest discovered path # finaldist = 1e30000 finalpath = [] dir = 1 while fringe[0] and fringe[1]: # choose direction # dir == 0 is forward direction and dir == 1 is back dir = 1 - dir # extract closest to expand (dist, _, v) = pop(fringe[dir]) if v in dists[dir]: # Shortest path to v has already been found continue # update distance dists[dir][v] = dist # equal to seen[dir][v] if v in dists[1 - dir]: # if we have scanned v in both directions we are done # we have now discovered the shortest path return (finaldist, finalpath) wt = _weight_function(G, weight) for w in neighs[dir](v): if dir == 0: # forward minweight = wt(v, w, G.get_edge_data(v, w)) vwLength = dists[dir][v] + minweight else: # back, must remember to change v,w->w,v minweight = wt(w, v, G.get_edge_data(w, v)) vwLength = dists[dir][v] + minweight if w in dists[dir]: if vwLength < dists[dir][w]: raise ValueError("Contradictory paths found: negative weights?") elif w not in seen[dir] or vwLength < seen[dir][w]: # relaxing seen[dir][w] = vwLength push(fringe[dir], (vwLength, next(c), w)) paths[dir][w] = paths[dir][v] + [w] if w in seen[0] and w in seen[1]: # see if this path is better than the already # discovered shortest path totaldist = seen[0][w] + seen[1][w] if finalpath == [] or finaldist > totaldist: finaldist = totaldist revpath = paths[1][w][:] revpath.reverse() finalpath = paths[0][w] + revpath[1:] raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
(G, nodes, *, backend=None, **backend_kwargs)
[ -0.006647453643381596, -0.0178696122020483, -0.0346086323261261, -0.03584390878677368, -0.026610752567648888, -0.03079812414944172, -0.018037106841802597, 0.04576798155903816, 0.07177156209945679, -0.05305400863289833, -0.029793154448270798, 0.029667533934116364, 0.021083420142531395, 0.01687511056661606, -0.02832757495343685, 0.041517797857522964, 0.006610814481973648, 0.025626718997955322, 0.007087127771228552, 0.03368741273880005, -0.014551118947565556, -0.04974598437547684, 0.034294579178094864, 0.0673748254776001, -0.034043338149785995, -0.025501098483800888, 0.007505865301936865, -0.00942158792167902, -0.021711526438593864, -0.019429408013820648, 0.03984284773468971, -0.028181016445159912, 0.00198769336566329, -0.024747371673583984, 0.023386474698781967, 0.04706606641411781, 0.005105977412313223, 0.015116414986550808, -0.04861539602279663, -0.06791917979717255, -0.05745074898004532, -0.05087657645344734, 0.006652688141912222, -0.025082360953092575, 0.03728855028748512, 0.04928537458181381, 0.00002273612335557118, 0.03031657636165619, 0.005126914009451866, 0.0045904070138931274, 0.018665213137865067, -0.0018947860226035118, -0.013870671391487122, 0.03860757499933243, 0.012258533388376236, 0.029939712956547737, -0.019146760925650597, 0.04208309203386307, 0.057032011449337006, -0.040408145636320114, 0.03502736985683441, 0.009316903539001942, 0.07064097374677658, 0.03439926356077194, -0.052886515855789185, -0.003904724959284067, -0.04279494658112526, -0.03580203652381897, -0.05431022122502327, 0.026150140911340714, 0.006035050377249718, -0.020978735759854317, -0.009992117993533611, 0.0018332840409129858, -0.01544093620032072, 0.014174255542457104, 0.013169286772608757, -0.017743991687893867, 0.009484399110078812, -0.0588744580745697, 0.0444280207157135, -0.036074213683605194, -0.0028343277517706156, -0.07964382320642471, 0.03975910320878029, 0.018372096121311188, 0.01840350218117237, 0.017000732943415642, -0.011483868584036827, -0.03287087380886078, -0.07248342037200928, 0.03609514981508255, 0.01739853248000145, 0.04269026219844818, 0.05364024266600609, 0.023239918053150177, 0.0033577491994947195, -0.06670484691858292, 0.04756855219602585, 0.004213543608784676, 0.011944480240345001, 0.0540589801967144, -0.0673748254776001, 0.03446207568049431, 0.002313523320481181, -0.05171405151486397, -0.02034016139805317, 0.001134516205638647, -0.0065008956007659435, -0.05439396947622299, -0.05728325620293617, 0.004574704449623823, 0.02158590592443943, -0.015315314754843712, 0.009484399110078812, 0.026150140911340714, -0.006171140354126692, 0.019021140411496162, 0.012991323135793209, -0.004360101651400328, 0.015870140865445137, 0.022632747888565063, -0.09044724702835083, -0.019680650904774666, 0.04158060997724533, -0.023930834606289864, 0.03477612882852554, 0.008448024280369282, 0.04639608785510063, 0.01985861361026764, 0.019240977242588997, 0.031635597348213196, -0.02043437771499157, 0.10644301027059555, 0.00027790412423200905, 0.009630956687033176, -0.06875665485858917, 0.029500039294362068, 0.05472895875573158, 0.016833238303661346, 0.03599046543240547, -0.10233938694000244, 0.06197311356663704, 0.012687738984823227, 0.017115885391831398, -0.004310376476496458, 0.001689343131147325, 0.0063491035252809525, 0.04911787807941437, 0.038775067776441574, 0.028495069593191147, -0.01951315626502037, 0.010128207504749298, -0.003713676007464528, -0.0002201641909778118, -0.039298489689826965, -0.0466473288834095, 0.035299550741910934, -0.0030751016456633806, -0.0056791240349411964, 0.009557677432894707, -0.07621017843484879, 0.02880912274122238, -0.0019445110810920596, -0.04400928318500519, 0.015262972563505173, 0.049662236124277115, 0.025961710140109062, -0.022758370265364647, 0.03377115726470947, 0.002159113995730877, -0.04451176896691322, -0.07407461851835251, -0.021753400564193726, -0.045809853821992874, 0.036409202963113785, 0.024182075634598732, -0.0073540727607905865, 0.007762341760098934, -0.0144359664991498, 0.008871995843946934, -0.057325128465890884, 0.013661302626132965, -0.04706606641411781, 0.0533052533864975, 0.04865726828575134, 0.030609693378210068, -0.03205433487892151, 0.003480753395706415, 0.03762354329228401, -0.0422087162733078, -0.06452740728855133, 0.017283380031585693, 0.06318745017051697, 0.012624927796423435, 0.008249123580753803, -0.005331048741936684, 0.011169816367328167, -0.05230028182268143, 0.052844639867544174, -0.005228981375694275, -0.017618369311094284, 0.05112781748175621, -0.012603990733623505, 0.005595376715064049, -0.0027087065391242504, -0.019701587036252022, 0.00476051913574338, 0.020936861634254456, 0.012813359498977661, -0.034231770783662796, -0.03247307240962982, 0.01293898094445467, -0.050625331699848175, -0.031195925548672676, 0.010683033615350723, -0.026087330654263496, 0.0607169009745121, 0.04446989670395851, -0.04208309203386307, -0.0050719548016786575, 0.00301229115575552, -0.019963297992944717, -0.010421323589980602, 0.056110791862010956, -0.06163812428712845, 0.034524887800216675, 0.009981648996472359, 0.04350680112838745, -0.0692591443657875, 0.06364805996417999, -0.02929067052900791, 0.07198093086481094, -0.010897637344896793, 0.0744096115231514, -0.04216684028506279, -0.02042390964925289, 0.005993176717311144, 0.028516005724668503, -0.002526817610487342, -0.03379209712147713, -0.04656358063220978, -0.031635597348213196, -0.027552910149097443, 0.017702117562294006, 0.004328696522861719, 0.0448048859834671, -0.016749490052461624, 0.04086875542998314, 0.0069405697286129, -0.039738163352012634, -0.003048930549994111, -0.02954191341996193, -0.06607674062252045, 0.004933248274028301, -0.03412708640098572, -0.0327661894261837, -0.03605327755212784, -0.057032011449337006, -0.019063012674450874, -0.02169059030711651, -0.021711526438593864, -0.04354867339134216, 0.06138687953352928, 0.007406414952129126, 0.036597635596990585, 0.02038203552365303, -0.02790883742272854, -0.046186719089746475, -0.005126914009451866, 0.02115670032799244, 0.01088716834783554, -0.03613702580332756, 0.03527861461043358, -0.03234745189547539, 0.01136871613562107, -0.02543828822672367, 0.05326337739825249, -0.009725173003971577, -0.0036875049117952585, -0.09136846661567688, 0.007636720780283213, -0.0049541848711669445, 0.003514775773510337, -0.028201954439282417, 0.04346492514014244, 0.007024317514151335, -0.05870696157217026, 0.013263502158224583, -0.02024594508111477, 0.0773826465010643, -0.001619989750906825, 0.029269734397530556, -0.012687738984823227, 0.07909946888685226, 0.04606109857559204, 0.005105977412313223, -0.07880634814500809, 0.01965971291065216, 0.027196984738111496, 0.019680650904774666, -0.043004315346479416, 0.015221099369227886, -0.04819665849208832, -0.0007439128821715713, 0.006061221472918987, 0.02713417448103428, -0.014258002862334251, 0.003017525188624859, -0.017754459753632545, -0.05648765340447426, -0.03565547615289688, 0.008249123580753803, -0.009777515195310116, 0.02395177073776722, -0.0755401998758316, -0.024831118062138557, 0.009725173003971577, -0.007552972994744778, 0.040408145636320114, -0.03827258571982384, 0.08927477896213531, -0.06871478259563446, 0.033080242574214935, -0.0721902996301651, 0.0346086323261261, 0.03613702580332756, 0.05841384455561638, 0.025375477969646454, -0.020549530163407326, 0.03565547615289688, 0.02038203552365303, -0.013818329200148582, 0.008929572068154812, -0.0488666370511055, 0.06188936531543732, 0.075163334608078, 0.023679591715335846, -0.00301229115575552, -0.011588552966713905, 0.07298590242862701, 0.03387584164738655, -0.005888492334634066, 0.05024847015738487, 0.02991877682507038, -0.02269555814564228, 0.019303787499666214, -0.044888634234666824, -0.004388889763504267, -0.01947128213942051, 0.03366647660732269, 0.059251319617033005, -0.017953360453248024, -0.0015885843895375729, 0.047442931681871414, 0.0032556820660829544, -0.017429938539862633, -0.010908105410635471, 0.010342810302972794, 0.023637717589735985, -0.022130263969302177, 0.022967737168073654, -0.03362460061907768, 0.016634337604045868, -0.017482280731201172, 0.00016111570585053414, -0.002085834974423051, 0.0014394093304872513, -0.029855966567993164, -0.03243120014667511, -0.020643746480345726, -0.0755401998758316, -0.019921423867344856, 0.03546704351902008, 0.00021542068861890584, 0.05280276760458946, 0.017796333879232407, 0.0006631097057834268, 0.01599576324224472, 0.05870696157217026, -0.014216129668056965, 0.05276089161634445, 0.004137647338211536, 0.04038720950484276, 0.0176811795681715, -0.029018491506576538, 0.09061474353075027, 0.0006071690004318953, 0.04333930462598801, -0.011431527324020863, -0.05267714709043503, -0.04467926546931267, 0.03839820623397827, 0.02365865372121334, 0.006532301194965839, -0.014132382348179817, 0.09212219715118408, 0.050667207688093185, -0.026275763288140297, -0.01923050731420517, 0.021816210821270943, -0.016759958118200302, -0.05049971118569374, 0.05422647297382355, 0.009301201440393925, -0.021229978650808334, 0.07449335604906082, 0.03634639456868172, 0.04317181184887886, 0.034483011811971664, -0.03913099691271782, 0.0030384622514247894, -0.017325254157185555, 0.012499307282269001, -0.026568878442049026, -0.04610297083854675, -0.04271119832992554, 0.056990139186382294, 0.052258409559726715, -0.005579673685133457, 0.02443331852555275, -0.014634867198765278, 0.06431803852319717, -0.05682264640927315, 0.03546704351902008, -0.013818329200148582, -0.003831445937976241, -0.023156169801950455, -0.0017586963949725032, 0.08043942600488663, -0.0001346174831269309, -0.03310117870569229, 0.02138700522482395, -0.05008097365498543, -0.009992117993533611, 0.016644805669784546, 0.022569937631487846, -0.028118206188082695, 0.0688822790980339, -0.011536210775375366, -0.038042280822992325, -0.00422924617305398, -0.02254900150001049, -0.010908105410635471, 0.01195494830608368, -0.07252529263496399, -0.016131851822137833, 0.004286822397261858, 0.03471331670880318, -0.036848876625299454, 0.01965971291065216, -0.05761824548244476, 0.018330223858356476, 0.0036273114383220673, -0.08186313509941101, 0.022925864905118942, -0.021962769329547882, 0.024161139503121376, -0.10753172636032104, 0.025145171210169792, 0.057660117745399475, -0.007825152017176151, 0.024600813165307045, -0.013682239688932896, -0.03601140156388283, 0.044595517218112946, 0.012132911942899227, -0.024056455120444298, -0.03471331670880318, -0.031300608068704605, 0.04463738948106766, -0.04698231816291809, -0.07114345580339432, -0.029520975425839424, 0.07152032107114792, -0.012708675116300583, -0.06113563850522041, 0.007615783717483282, 0.017482280731201172, -0.05313775688409805, -0.006909164600074291, -0.030442198738455772, 0.039633478969335556, 0.022569937631487846, 0.003873319597914815, -0.03906818479299545, 0.007479694206267595, -0.010703970678150654, 0.01927238143980503, -0.020465783774852753, 0.015064072795212269, -0.016602931544184685, 0.031635597348213196, -0.033268675208091736, -0.0034545823000371456, 0.06469490379095078, -0.017241505905985832, -0.031447168439626694, 0.07729889452457428, -0.019450346007943153, 0.005783808417618275, -0.03282900154590607, -0.044595517218112946, 0.03988472372293472, 0.022758370265364647, 0.041852787137031555, -0.020067982375621796, 0.028181016445159912, -0.030777188017964363, 0.033331483602523804, 0.024684561416506767, 0.021313725039362907, 0.0496203638613224, 0.06586737185716629, 0.019052544608712196, 0.005427881609648466, -0.021858084946870804, 0.036409202963113785, 0.02221401035785675, -0.0510859452188015, 0.0123108746483922, 0.052593398839235306, 0.006621282547712326, 0.007448288612067699, -0.04509800300002098, 0.02236056886613369, 0.020601872354745865, -0.04719168692827225, 0.030609693378210068, -0.0006516598514281213, 0.007401180919259787, 0.04143404960632324, 0.016707615926861763, 0.04413490742444992, 0.04853164777159691, 0.030567819252610207, 0.058916330337524414, -0.019827209413051605, -0.021962769329547882, -0.02650606818497181, 0.031070303171873093, -0.01149433758109808, -0.05200716480612755, -0.014299876987934113, 0.03421083465218544, 0.020664682611823082, 0.02839038521051407, 0.010897637344896793, -0.03243120014667511, -0.05049971118569374, -0.04761042445898056, -0.013389123603701591, 0.027887901291251183, 0.041413113474845886, 0.07474459707736969, -0.05200716480612755, 0.022088389843702316, 0.026108266785740852, 0.011023257859051228, 0.07859697937965393, -0.04920162633061409, -0.05941881611943245, -0.04072219878435135, -0.0392356812953949, -0.010541710071265697, -0.00129808543715626, 0.02173246257007122, 0.013022728264331818, 0.029667533934116364, 0.008259592577815056, -0.00526562100276351, 0.031928714364767075, -0.011850263923406601, -0.004328696522861719, -0.034818001091480255, -0.01595388911664486, -0.017796333879232407, -0.03779103606939316, 0.02023547701537609, -0.06716545671224594, 0.005019612610340118, 0.0022153817117214203, 0.03668138384819031, 0.049662236124277115, 0.008620752952992916, -0.005637250375002623, -0.031447168439626694, 0.04065938666462898, -0.034189894795417786, -0.006867290940135717, 0.013284439221024513, -0.06377368420362473, 0.044595517218112946, -0.0034676678478717804, 0.003616842906922102, -0.041371241211891174, -0.010170080699026585, 0.01671808399260044, 0.05008097365498543, -0.02631763555109501, -0.04451176896691322, 0.003734612837433815, 0.03473425656557083, 0.02409832924604416, 0.0039492156356573105, 0.00988219864666462, 0.0015990529209375381, -0.08274248242378235, -0.015451404266059399, -0.046186719089746475, 0.023239918053150177, 0.03165653720498085, 0.03035845048725605, -0.030965618789196014, -0.07520520687103271, 0.004786690231412649, -0.011222158558666706, 0.011452463455498219, -0.05719950795173645, -0.01849771849811077, 0.0055901422165334225, -0.046479836106300354, 0.034043338149785995, -0.009840325452387333, -0.01643543690443039, 0.03215901926159859, 0.03494362160563469, 0.015430467203259468, -0.04143404960632324, 0.028348511084914207, -0.02991877682507038, -0.0814443975687027, 0.016686679795384407, 0.05853946879506111, -0.03532048687338829, -0.022381506860256195, 0.06708170473575592, -0.0027165578212589025, -0.02910223789513111, 0.020853115245699883, -0.052258409559726715, 0.027217920869588852, -0.029604723677039146, -0.02265368588268757, -0.03454582393169403, -0.024182075634598732, 0.018728023394942284, -0.012876170687377453, -0.01864427514374256, 0.009892667643725872, -0.005600610747933388, 0.015618899837136269, -0.010541710071265697, -0.024558939039707184, 0.01101278979331255, 0.07277653366327286, 0.0033080242574214935, -0.01749274879693985, 0.022863054648041725, 0.001995544647797942, 0.043255556374788284, 0.050290342420339584, 0.060591280460357666, -0.04235527291893959, -0.021962769329547882, 0.015912014991044998, 0.013504276052117348, -0.038712259382009506, 0.015451404266059399, -0.025145171210169792, -0.041852787137031555, -0.018110385164618492, 0.004776221700012684, 0.015315314754843712, -0.05297026038169861, -0.0444280207157135, 0.003946598619222641, 0.008898166939616203, -0.01806851290166378, -0.07064097374677658, 0.02790883742272854, 0.022088389843702316, 0.021460283547639847, -0.044218651950359344, 0.0071080648340284824, 0.03760260343551636, -0.06272684037685394, -0.06348056346178055, 0.04208309203386307, -0.009358777664601803, 0.002170891035348177, -0.04798728972673416, 0.03965441882610321, 0.029458165168762207, -0.0034153256565332413, -0.05761824548244476, -0.015273441560566425, -0.013253034092485905, 0.0327661894261837, -0.06574174761772156, 0.05422647297382355, 0.029625659808516502, -0.002559531480073929, -0.041706230491399765, 0.010217188857495785, -0.010541710071265697, -0.06511364132165909, 0.023930834606289864, -0.02535453997552395, 0.02954191341996193, -0.004805009812116623, -0.03666044771671295, -0.023721465840935707, 0.004579938482493162, 0.02328179031610489, -0.0044961911626160145, -0.018958328291773796, -0.04622859135270119, -0.02139747329056263, 0.012258533388376236, -0.01730431616306305, -0.038000404834747314, -0.025270793586969376, 0.046144843101501465, -0.07918321341276169, 0.018037106841802597, 0.004341782070696354, -0.0714784488081932, -0.0270294900983572, -0.025166109204292297, -0.035299550741910934, 0.075163334608078, 0.01671808399260044, 0.06063315272331238, 0.018372096121311188, -0.0004887448740191758, 0.0062601217068731785, 0.015681710094213486, 0.004286822397261858, 0.06352244317531586, -0.0026393532752990723, 0.02139747329056263, -0.060591280460357666, 0.006537535227835178, -0.005228981375694275, 0.005574439652264118, 0.010908105410635471, 0.019157228991389275, -0.015053603798151016, -0.030086271464824677, 0.044218651950359344, -0.007610549684613943, 0.04354867339134216, -0.02640138380229473, 0.0270294900983572, 0.00889293197542429, -0.03513205423951149, -0.019795803353190422, -0.03527861461043358, -0.05715763568878174, -0.044218651950359344, -0.02071702480316162, -0.03217995911836624, 0.03643013909459114, -0.009102300740778446, 0.05058345943689346, 0.029520975425839424, 0.0896097719669342 ]
30,821
networkx.classes.function
is_weighted
Returns True if `G` has weighted edges. Parameters ---------- G : graph A NetworkX graph. edge : tuple, optional A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested. weight: string, optional The attribute name used to query for edge weights. Returns ------- bool A boolean signifying if `G`, or the specified edge, is weighted. Raises ------ NetworkXError If the specified edge does not exist. Examples -------- >>> G = nx.path_graph(4) >>> nx.is_weighted(G) False >>> nx.is_weighted(G, (2, 3)) False >>> G = nx.DiGraph() >>> G.add_edge(1, 2, weight=1) >>> nx.is_weighted(G) True
def is_weighted(G, edge=None, weight="weight"): """Returns True if `G` has weighted edges. Parameters ---------- G : graph A NetworkX graph. edge : tuple, optional A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested. weight: string, optional The attribute name used to query for edge weights. Returns ------- bool A boolean signifying if `G`, or the specified edge, is weighted. Raises ------ NetworkXError If the specified edge does not exist. Examples -------- >>> G = nx.path_graph(4) >>> nx.is_weighted(G) False >>> nx.is_weighted(G, (2, 3)) False >>> G = nx.DiGraph() >>> G.add_edge(1, 2, weight=1) >>> nx.is_weighted(G) True """ if edge is not None: data = G.get_edge_data(*edge) if data is None: msg = f"Edge {edge!r} does not exist." raise nx.NetworkXError(msg) return weight in data if is_empty(G): # Special handling required since: all([]) == True return False return all(weight in data for u, v, data in G.edges(data=True))
(G, edge=None, weight='weight')
[ 0.06127315014600754, 0.006483640056103468, -0.022187640890479088, 0.02233457751572132, 0.008673934265971184, -0.02464885264635086, -0.01991010084748268, 0.058224186301231384, 0.06847311556339264, -0.008843831717967987, 0.0469466969370842, 0.021765192970633507, 0.05264054238796234, -0.01926724798977375, -0.03370390832424164, -0.004798444453626871, -0.059620101004838943, 0.02626517042517662, 0.0389753095805645, 0.03901204094290733, -0.058811940252780914, -0.09359951317310333, 0.02196723222732544, 0.024685585871338844, 0.009220360778272152, 0.020203977823257446, 0.004876505117863417, 0.016383588314056396, 0.05150177329778671, 0.033997781574726105, -0.03691817447543144, -0.06722414493560791, -0.03871816769242287, 0.035393692553043365, 0.054440535604953766, 0.06435885280370712, 0.00006503872282337397, -0.004020132124423981, -0.10572189837694168, -0.015566245652735233, -0.0066902716644108295, -0.01526318583637476, 0.03083861619234085, 0.004522935952991247, 0.002525497227907181, 0.002472691237926483, 0.019689694046974182, 0.009133116342127323, -0.04382426291704178, -0.029148828238248825, 0.07934653013944626, 0.021140707656741142, 0.00995505042374134, 0.020865198224782944, -0.023565184324979782, -0.006502007134258747, -0.024263139814138412, 0.00011027525761164725, -0.0049958922900259495, 0.009133116342127323, 0.00207894342020154, -0.025365173816680908, 0.04544058069586754, -0.01861521042883396, -0.040297750383615494, -0.04136304929852486, -0.032803911715745926, -0.018808064982295036, -0.02589782513678074, -0.010524434968829155, -0.032859012484550476, 0.021930499002337456, -0.009133116342127323, 0.010836678557097912, -0.11079126596450806, 0.020424384623765945, 0.028561076149344444, 0.028597811236977577, -0.02185702882707119, -0.0358712412416935, 0.03131616488099098, -0.03752429410815239, -0.01673256605863571, 0.005119871348142624, 0.04742424562573433, 0.01926724798977375, -0.03419982269406319, 0.029259031638503075, 0.011176472529768944, -0.027569245547056198, -0.007470879703760147, 0.029093727469444275, 0.04837934300303459, -0.03309778869152069, 0.008380058221518993, -0.015942774713039398, -0.0025966702960431576, -0.020277446135878563, -0.03025086410343647, 0.008958627469837666, -0.06336701661348343, -0.045293644070625305, 0.0472773052752018, 0.01970806159079075, 0.0023831508588045835, -0.04893035814166069, -0.02475905604660511, -0.02540190890431404, -0.006681087892502546, -0.03978346660733223, 0.023399878293275833, -0.06017111614346504, 0.04279569536447525, -0.0018401690758764744, 0.04555078595876694, 0.02283049374818802, 0.015419308096170425, 0.02213253825902939, -0.0041395192965865135, -0.014978493563830853, 0.03265697509050369, 0.05829765647649765, 0.01739378832280636, -0.003122432855889201, 0.025438643991947174, -0.044485483318567276, 0.012260140851140022, -0.033520232886075974, 0.011323411017656326, 0.007709654048085213, 0.01739378832280636, 0.04624874144792557, -0.013288706541061401, 0.05021606758236885, -0.017320318147540092, 0.03677123785018921, -0.015786653384566307, 0.03993040695786476, 0.0549180842936039, 0.01076320931315422, -0.0006313743069767952, 0.0157223679125309, 0.04312630742788315, 0.027605978772044182, 0.014895841479301453, 0.010634638369083405, -0.05120789632201195, -0.0033703907392919064, 0.03871816769242287, 0.006437721662223339, 0.018266232684254646, -0.05201605707406998, 0.011865244247019291, -0.0153642063960433, -0.009725459851324558, -0.01658562757074833, -0.05017933249473572, 0.04698342829942703, -0.008324956521391869, -0.04235488176345825, 0.008324956521391869, 0.03440186381340027, -0.011176472529768944, 0.02955290861427784, -0.013646868057549, 0.020791729912161827, 0.05194258689880371, 0.053154826164245605, 0.012195855379104614, 0.01813766174018383, 0.0025140175130218267, -0.077068991959095, -0.023601919412612915, 0.007484654895961285, -0.03677123785018921, 0.050032392144203186, 0.009753010235726833, 0.008200977928936481, -0.008040264248847961, 0.0020261374302208424, 0.027899855747818947, -0.06424864381551743, -0.035283491015434265, 0.021838663145899773, -0.00788414292037487, -0.004690536763519049, 0.009165259078145027, -0.003811204805970192, -0.02185702882707119, 0.01116728875786066, -0.013389726169407368, -0.03816714882850647, -0.04338344931602478, 0.018707046285271645, -0.005133647006005049, 0.024667218327522278, 0.01586930640041828, -0.012829525396227837, -0.05264054238796234, 0.04657934978604317, 0.0615670271217823, -0.08052203059196472, 0.0308937169611454, 0.010515251196920872, 0.020589688792824745, -0.006052009295672178, -0.007930060848593712, -0.02944270521402359, -0.03574267029762268, -0.03882836923003197, -0.012058100663125515, -0.01463869959115982, 0.04220794513821602, 0.056828275322914124, 0.060795605182647705, 0.08985259383916855, -0.046101801097393036, 0.016181549057364464, -0.01814684458076954, -0.021452950313687325, -0.0007283763261511922, 0.01620909944176674, 0.040554892271757126, 0.021618254482746124, 0.08801586925983429, -0.069097600877285, 0.03401615098118782, 0.0008248044177889824, -0.012287691235542297, -0.017889702692627907, 0.042612023651599884, 0.02018561027944088, 0.07464451342821121, 0.007760163862258196, -0.039636529982089996, -0.011130554601550102, -0.000518874847330153, 0.033556967973709106, 0.07545267045497894, 0.006722413934767246, 0.048526279628276825, -0.0346590057015419, -0.10484027117490768, -0.03247329965233803, 0.004336967132985592, -0.04510996863245964, -0.009762194007635117, 0.017292767763137817, 0.006368844769895077, -0.016383588314056396, -0.0616772323846817, -0.0004396660951897502, -0.0017070064786821604, -0.04408140480518341, -0.0195427555590868, 0.020277446135878563, -0.04404466971755028, -0.016457058489322662, -0.023620285093784332, 0.009133116342127323, 0.03449369966983795, 0.005606603808701038, -0.0020008825231343508, 0.07868530601263046, 0.02196723222732544, 0.027257001027464867, 0.02227947674691677, -0.015639714896678925, -0.013876458629965782, -0.03574267029762268, 0.03530185669660568, -0.020901933312416077, 0.03014066070318222, 0.002076647477224469, 0.012379528023302555, -0.039856936782598495, 0.01020300853997469, 0.045293644070625305, -0.019891733303666115, -0.0030811065807938576, -0.07537920027971268, 0.02696312591433525, -0.018165212124586105, 0.03989367187023163, -0.052236463874578476, 0.02896515652537346, -0.006768332328647375, 0.035779405385255814, 0.026301903650164604, -0.010919331572949886, 0.07236697524785995, -0.0065295579843223095, 0.009991784580051899, 0.009854030795395374, -0.025071298703551292, 0.054881349205970764, 0.07890571653842926, -0.03063657507300377, 0.0474977120757103, 0.016062160953879356, 0.08235875517129898, 0.0036367159336805344, -0.001195019343867898, -0.04323650896549225, -0.024208037182688713, 0.05194258689880371, 0.047240570187568665, 0.002334936987608671, -0.018651943653821945, 0.011516266502439976, -0.024299874901771545, 0.0025094258598983288, -0.05965683236718178, 0.020112140104174614, 0.006355069112032652, -0.02696312591433525, 0.01391319278627634, -0.02464885264635086, -0.0688771978020668, 0.006515782792121172, -0.0015084105543792248, 0.07493838667869568, 0.04981198534369469, 0.019561123102903366, -0.06347722560167313, 0.013481562957167625, 0.0024152935948222876, 0.012820341624319553, 0.023620285093784332, 0.027165165171027184, -0.031518202275037766, -0.020846830680966377, 0.07185269147157669, 0.0023223094176501036, 0.0016806034836918116, 0.10366477072238922, 0.03003045730292797, 0.017155013978481293, 0.0022557280026376247, 0.0029364642687141895, -0.010184640996158123, 0.032859012484550476, 0.017099911347031593, 0.03326309472322464, 0.021140707656741142, -0.021452950313687325, -0.055211957544088364, 0.006864760536700487, 0.029993722215294838, -0.022187640890479088, 0.002081239130347967, 0.029185563325881958, 0.012214221991598606, 0.0011031830217689276, 0.018284598365426064, -0.0024474363308399916, -0.004626251757144928, 0.022463148459792137, 0.0020663158502429724, 0.077950619161129, -0.03871816769242287, 0.009486685506999493, 0.01159891951829195, -0.02227947674691677, -0.023565184324979782, 0.01754072494804859, 0.04926097020506859, 0.058371126651763916, -0.05319156125187874, 0.004233651328831911, 0.03623858839273453, -0.04290590062737465, -0.04466915503144264, -0.019946835935115814, 0.029038624837994576, 0.01797235570847988, 0.011057085357606411, -0.013196870684623718, 0.05587318167090416, 0.022316209971904755, 0.00695659639313817, 0.048048730939626694, 0.023969262838363647, 0.04117937758564949, 0.06373436003923416, -0.032601870596408844, 0.02233457751572132, -0.0010119207436218858, -0.02294069714844227, -0.02674271911382675, -0.05473440885543823, 0.0057948678731918335, -0.04466915503144264, 0.03192228451371193, -0.043787527829408646, -0.027257001027464867, 0.00947750173509121, 0.0033198806922882795, -0.0544772669672966, -0.0010750582441687584, -0.028065159916877747, -0.024263139814138412, -0.0472773052752018, -0.006387211848050356, -0.028836585581302643, 0.06186090409755707, -0.058481328189373016, 0.024134568870067596, 0.05635072663426399, -0.013711153529584408, 0.006630578078329563, -0.009936682879924774, -0.07302819192409515, 0.036422260105609894, -0.04081203415989876, 0.02180192805826664, 0.03813041374087334, 0.026118231937289238, 0.03607328236103058, 0.010735658928751945, 0.03267534077167511, -0.010395864956080914, 0.038240619003772736, -0.0024175895377993584, 0.026246802881360054, -0.06979555636644363, -0.0028285568114370108, -0.05080381780862808, 0.010010152123868465, 0.03359370306134224, -0.05249360576272011, -0.02852434106171131, 0.034585535526275635, 0.009899948723614216, 0.011846877634525299, -0.0004390921094454825, -0.017053993418812752, -0.035650834441185, -0.04687322676181793, -0.015437674708664417, 0.009192809462547302, -0.03783654049038887, -0.026228435337543488, -0.0538160465657711, -0.04117937758564949, -0.0626690611243248, -0.016980525106191635, 0.04499976709485054, 0.03967326506972313, -0.043677326291799545, -0.013187686912715435, -0.01739378832280636, 0.022187640890479088, -0.006814250256866217, -0.07218329608440399, 0.01658562757074833, 0.011773408390581608, -0.002791822189465165, -0.006074968725442886, 0.04040795564651489, -0.055469099432229996, -0.028891686350107193, -0.04121611267328262, -0.045624252408742905, -0.017366236075758934, -0.010028519667685032, 0.014546863734722137, -0.01108463667333126, 0.021122340112924576, 0.05954663082957268, 0.051648713648319244, 0.0018803473794832826, -0.05635072663426399, -0.05388951674103737, 0.10792597383260727, 0.04687322676181793, -0.05506502091884613, 0.043787527829408646, -0.024244772270321846, -0.0006537593435496092, 0.0040913051925599575, 0.003939775284379721, 0.03375900909304619, 0.04015081375837326, 0.01861521042883396, -0.03653246536850929, -0.021306011825799942, 0.02696312591433525, 0.009707092307507992, -0.04430181160569191, 0.013417277485132217, -0.010561170056462288, 0.04139978438615799, -0.005739766173064709, 0.04051815718412399, 0.004940790589898825, 0.0007312461966648698, 0.04742424562573433, 0.04970178380608559, 0.026246802881360054, 0.0030397800728678703, 0.026173334568738937, -0.024612117558717728, 0.012765239924192429, -0.01631012000143528, -0.0397467315196991, -0.03309778869152069, -0.005813234951347113, 0.06314661353826523, 0.019414184615015984, 0.01829378306865692, 0.04988545551896095, -0.007879550568759441, 0.05050994083285332, 0.057195622473955154, -0.011341777630150318, 0.004644618835300207, -0.0029938621446490288, 0.04624874144792557, -0.024373343214392662, 0.06817923486232758, 0.032914116978645325, -0.0021041983272880316, 0.04937117174267769, -0.048526279628276825, 0.04154672473669052, -0.018394801765680313, -0.04536711052060127, 0.028175363317131996, 0.03014066070318222, 0.03697327896952629, 0.09933009743690491, -0.017788683995604515, 0.013059115968644619, -0.040665093809366226, -0.013802989386022091, 0.01700807549059391, 0.016879504546523094, -0.08030162751674652, 0.006102519575506449, 0.013463195413351059, -0.04323650896549225, 0.012939728796482086, 0.016438690945506096, 0.05297115445137024, 0.0389753095805645, 0.022352945059537888, -0.029736580327153206, -0.01127749215811491, -0.08963219076395035, -0.04566098749637604, -0.006437721662223339, -0.03702837973833084, -0.036091648042201996, 0.07942000031471252, -0.02213253825902939, -0.01636522077023983, 0.0157223679125309, -0.024428443983197212, 0.012664220295846462, -0.0625588595867157, -0.09595052152872086, -0.030930452048778534, -0.00019170819723512977, 0.025163134559988976, -0.07912611961364746, 0.0008184906328096986, -0.011112187057733536, -0.0025002420879900455, 0.0067637404426932335, 0.006919862236827612, 0.014207068830728531, 0.03882836923003197, -0.03882836923003197, -0.0011026090942323208, 0.00630915118381381, -0.027642713859677315, -0.003476002486422658, 0.0003136782324872911, -0.040775299072265625, -0.02277539297938347, -0.0382038839161396, -0.002426773076876998, 0.040775299072265625, -0.02411620132625103, -0.00651119090616703, 0.00695659639313817, 0.025659050792455673, -0.08617914468050003, 0.0549180842936039, 0.015410124324262142, -0.0549180842936039, 0.07471798360347748, 0.00012204177619423717, 0.03256513923406601, 0.030103925615549088, 0.01597950980067253, 0.0007622409611940384, 0.01456523034721613, -0.02057132124900818, -0.040775299072265625, 0.030397802591323853, 0.03730388730764389, -0.04474262520670891, -0.027532510459423065, 0.033667173236608505, 0.01689787209033966, 0.018716229125857353, -0.0008718704921193421, -0.0698690265417099, -0.046322207897901535, 0.024263139814138412, -0.015171349979937077, -0.04907729849219322, 0.006837209686636925, 0.01722848229110241, -0.05914255231618881, 0.019561123102903366, -0.027844753116369247, -0.002504833973944187, 0.0036642667837440968, -0.031132491305470467, 0.012857075780630112, 0.001011346816085279, 0.03530185669660568, -0.007525981403887272, 0.017347868531942368, -0.06443231552839279, -0.04569772258400917, -0.02272029034793377, -0.021489685401320457, -0.07203636318445206, 0.03838755562901497, -0.024777421727776527, 0.02367538772523403, -0.07442410290241241, -0.03317125514149666, -0.03419982269406319, -0.023546816781163216, -0.01173667423427105, -0.04676302149891853, 0.07978734374046326, -0.00914689153432846, -0.02826720103621483, 0.024244772270321846, 0.048305872827768326, 0.023657020181417465, -0.04195080325007439, -0.006534149870276451, -0.021673357114195824, -0.03003045730292797, 0.01673256605863571, 0.021838663145899773, -0.04408140480518341, 0.04397119954228401, 0.08654648810625076, 0.024832524359226227, -0.0534854382276535, -0.02960800938308239, -0.005317319184541702, 0.03651409596204758, 0.04048142209649086, 0.029644744470715523, 0.01313258521258831, 0.014271354302763939, 0.06325681507587433, -0.0394161231815815, 0.00027192142442800105, 0.042171210050582886, -0.056167054921388626, -0.0354304276406765, 0.07493838667869568, 0.03779980540275574, -0.0549180842936039, -0.02453864924609661, 0.017044808715581894, 0.0006445757462643087, -0.03559573367238045, -0.014546863734722137, -0.020479485392570496, 0.015345838852226734, 0.017742766067385674, -0.01251728180795908, 0.012563200667500496, 0.020497852936387062, 0.040665093809366226, -0.071742482483387, -0.026852922514081, 0.05050994083285332, -0.019028473645448685, -0.026081496849656105, -0.10168110579252243, 0.03838755562901497, 0.012985646724700928, 0.03405288606882095, -0.045514050871133804, -0.00891270861029625, 0.04948137700557709, 0.029736580327153206, -0.06564455479383469, -0.014023397117853165, -0.009505053050816059, -0.012094835750758648, 0.01915704272687435, 0.03816714882850647, -0.050252802670001984, -0.09962397068738937, 0.02169172465801239, 0.03779980540275574, -0.00839842576533556, -0.07225676625967026, -0.0316651426255703, -0.03230799734592438, -0.011865244247019291, 0.028138630092144012, -0.015621347352862358, -0.027789652347564697, -0.03019576147198677, -0.054073188453912735, -0.00434844708070159, -0.005638746079057455, -0.013270338997244835, -0.017843784764409065, 0.0013683602446690202, -0.07155881077051163, -0.03217942640185356, -0.029424337670207024, -0.014473394490778446, 0.009381073527038097, -0.009633623994886875, -0.009091789834201336, 0.012710138224065304, 0.026761086657643318, 0.09506889432668686, 0.009615256451070309, 0.03440186381340027, -0.03172024339437485, 0.007089759223163128, 0.0025507521349936724, 0.03142636641860008, 0.03658756613731384, -0.004780077375471592, 0.01604379527270794, -0.032161056995391846, 0.004940790589898825, -0.0012925952905789018, -0.008784138597548008, 0.005037218797951937, -0.009440767578780651, 0.005620379000902176, 0.040885500609874725, -0.010147906839847565, 0.012058100663125515, -0.0469466969370842, 0.07853836566209793, 0.031022287905216217, -0.054771143943071365, -0.08544445782899857, -0.017568277195096016, -0.05587318167090416, -0.04635894298553467, 0.0036849298048764467, 0.0006066932692192495, -0.023877426981925964, -0.05583644658327103, 0.021599888801574707, 0.018587658181786537, 0.051648713648319244 ]
30,826
networkx.algorithms.shortest_paths.weighted
johnson
Uses Johnson's Algorithm to compute shortest paths. Johnson's Algorithm finds a shortest path between each pair of nodes in a weighted graph even if negative weights are present. Parameters ---------- G : NetworkX graph weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number. Returns ------- distance : dictionary Dictionary, keyed by source and target, of shortest paths. Examples -------- >>> graph = nx.DiGraph() >>> graph.add_weighted_edges_from( ... [("0", "3", 3), ("0", "1", -5), ("0", "2", 2), ("1", "2", 4), ("2", "3", 1)] ... ) >>> paths = nx.johnson(graph, weight="weight") >>> paths["0"]["2"] ['0', '1', '2'] Notes ----- Johnson's algorithm is suitable even for graphs with negative weights. It works by using the Bellman–Ford algorithm to compute a transformation of the input graph that removes all negative weights, allowing Dijkstra's algorithm to be used on the transformed graph. The time complexity of this algorithm is $O(n^2 \log n + n m)$, where $n$ is the number of nodes and $m$ the number of edges in the graph. For dense graphs, this may be faster than the Floyd–Warshall algorithm. See Also -------- floyd_warshall_predecessor_and_distance floyd_warshall_numpy all_pairs_shortest_path all_pairs_shortest_path_length all_pairs_dijkstra_path bellman_ford_predecessor_and_distance all_pairs_bellman_ford_path all_pairs_bellman_ford_path_length
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, weight='weight', *, backend=None, **backend_kwargs)
[ 0.00868748314678669, -0.0040619331412017345, -0.034225184470415115, -0.04419538378715515, -0.038967348635196686, -0.021786730736494064, -0.010757319629192352, 0.04058045893907547, 0.07362010329961777, -0.010543533600866795, -0.052863433957099915, 0.029735680669546127, 0.028666751459240913, 0.0255182683467865, -0.027247989550232887, 0.035896603018045425, 0.00011251092655584216, 0.03593547269701958, -0.0012693540193140507, 0.013672582805156708, -0.015033039264380932, -0.0565560981631279, 0.05550660565495491, 0.049598339945077896, -0.02098989300429821, -0.009280253201723099, 0.014858122915029526, -0.04003627598285675, -0.02579035796225071, -0.016296319663524628, 0.017744233831763268, -0.018745141103863716, -0.006330979056656361, -0.005538999568670988, 0.016578128561377525, 0.05853847786784172, 0.007871209643781185, -0.0030440203845500946, -0.023360973224043846, -0.044039905071258545, -0.03018268756568432, -0.03045477904379368, 0.005704197566956282, -0.03782067820429802, 0.0800725519657135, 0.08388183265924454, -0.01746242493391037, 0.008672907017171383, -0.019396215677261353, -0.018832597881555557, 0.015169084072113037, 0.0014722077175974846, -0.00927539449185133, 0.009528051130473614, -0.007817762903869152, 0.03945322334766388, -0.03325343132019043, 0.05418501794338226, 0.027286861091852188, -0.038248248398303986, 0.03949209302663803, 0.010572686791419983, 0.07086032629013062, 0.04003627598285675, -0.06378595530986786, -0.023555323481559753, -0.04656646400690079, -0.037529151886701584, -0.0399974063038826, 0.02135915867984295, 0.001062248949892819, -0.009537768550217152, -0.01345879677683115, -0.03552733734250069, -0.0018937061540782452, 0.03795672208070755, -0.00001619906834093854, -0.03482767194509506, 0.011097433976829052, -0.03984192758798599, 0.04388442263007164, -0.056478358805179596, -0.025809794664382935, -0.07105467468500137, 0.0730370506644249, 0.025071261450648308, -0.004120238125324249, 0.002691759495064616, -0.009110196493566036, -0.03410857543349266, -0.036712877452373505, 0.03076574020087719, -0.0033209703397005796, 0.0004876991733908653, 0.05678931996226311, 0.02678154781460762, 0.009037314914166927, -0.05706141144037247, 0.04998704046010971, 0.031096138060092926, 0.06845036894083023, 0.0048903534188866615, -0.01456659659743309, 0.036129824817180634, 0.02647058665752411, -0.06724539399147034, -0.0110585642978549, 0.015849312767386436, -0.01391552109271288, -0.05566208437085152, -0.022641874849796295, 0.012380149215459824, 0.025945840403437614, -0.026800982654094696, 0.023497018963098526, 0.0032699531875550747, 0.006797421257942915, 0.04400103539228439, -0.0005387162673287094, -0.02108706720173359, -0.025226742029190063, 0.0525524728000164, -0.08310442417860031, -0.003947751596570015, 0.040424980223178864, -0.05640061944723129, 0.02470199391245842, -0.019920963793992996, 0.06627364456653595, 0.017938584089279175, 0.026159625500440598, 0.004798037000000477, -0.02786991372704506, 0.06561285257339478, 0.03199015185236931, -0.024546513333916664, -0.0566338412463665, 0.04691629856824875, 0.06506866961717606, 0.010446358472108841, 0.04256283864378929, -0.07548587024211884, 0.0077157290652394295, 0.02876392751932144, 0.005932559724897146, -0.028472401201725006, 0.011136304587125778, 0.014061284251511097, 0.03130992501974106, 0.059743452817201614, 0.015460610389709473, 0.0028715338557958603, 0.006928608287125826, 0.011661051772534847, 0.0016568410210311413, -0.06817828118801117, -0.04197978600859642, 0.02044571004807949, 0.005801373161375523, -0.0004734265385195613, 0.016616998240351677, -0.044622957706451416, 0.005718774162232876, 0.014887276105582714, -0.049831561744213104, 0.03496371954679489, 0.022194867953658104, 0.05216376855969429, -0.027170250192284584, 0.012370431795716286, -0.005893689580261707, -0.06413578242063522, -0.04777144268155098, -0.02917206473648548, -0.02446877397596836, 0.0032796708401292562, 0.02511013112962246, -0.0023237073328346014, 0.011835967190563679, -0.019444802775979042, 0.009911893866956234, -0.026626067236065865, 0.023147188127040863, -0.013633713126182556, 0.030066078528761864, 0.02917206473648548, 0.02225317247211933, -0.02163125015795231, 0.002961421152576804, 0.03482767194509506, -0.04827675223350525, -0.09328841418027878, -0.060559727251529694, 0.08318217098712921, -0.009085902944207191, 0.006709963548928499, -0.037257060408592224, -0.022175433114171028, -0.027286861091852188, 0.06370820850133896, -0.009115055203437805, -0.029327545315027237, 0.039919666945934296, -0.008867258206009865, 0.009251100942492485, -0.028841666877269745, -0.032456591725349426, 0.008566014468669891, 0.0010033362777903676, 0.01850220188498497, -0.03506089374423027, -0.045361489057540894, 0.02998833730816841, -0.02971624583005905, 0.001164283137768507, 0.013779476284980774, -0.03169862553477287, 0.04003627598285675, 0.014012697152793407, -0.05908266082406044, -0.004423911217600107, -0.015266260132193565, -0.009571779519319534, 0.02116480842232704, 0.06184244155883789, -0.05029800161719322, 0.047032907605171204, 0.030649131163954735, 0.025848664343357086, -0.07330914586782455, 0.07723502814769745, -0.03278699144721031, 0.09632028639316559, -0.01477066520601511, 0.07377558946609497, -0.047888051718473434, 0.003481309860944748, 0.040697067975997925, 0.0455947108566761, 0.027928218245506287, -0.021689556539058685, -0.023458149284124374, -0.014654054306447506, -0.058110907673835754, 0.005859678145498037, -0.0001001362397801131, 0.03148483857512474, -0.012321844696998596, 0.026159625500440598, -0.0064670247957110405, 0.005023969803005457, 0.027714433148503304, -0.042368486523628235, -0.05752785503864288, -0.012953484430909157, -0.043223630636930466, -0.02098989300429821, -0.03749028220772743, -0.03651852533221245, -0.06592381000518799, -0.03222337365150452, -0.027850478887557983, -0.06098730117082596, 0.10152889043092728, -0.0038797289598733187, 0.03261207416653633, 0.03121274709701538, -0.014333375729620457, -0.08022803068161011, 0.006617646664381027, 0.0427183173596859, 0.04306815192103386, -0.006875161547213793, -0.00362950237467885, -0.02511013112962246, 0.0051940265111625195, -0.03220393881201744, 0.034847110509872437, 0.012836874462664127, -0.023011142387986183, -0.04369007423520088, -0.008391098119318485, -0.041241250932216644, -0.0064961775206029415, 0.017938584089279175, 0.029774552211165428, 0.0120983412489295, -0.03482767194509506, 0.01646151766180992, 0.006695386953651905, 0.07019952684640884, -0.012176081538200378, 0.010592121630907059, -0.03774293512105942, 0.062270015478134155, 0.047654829919338226, -0.003481309860944748, -0.07284270226955414, 0.016403213143348694, 0.05364083871245384, 0.015460610389709473, -0.02569318376481533, 0.025673748925328255, -0.005694480147212744, -0.042640578001737595, 0.008245334960520267, 0.031232183799147606, -0.016821065917611122, -0.0025897251907736063, -0.030960092321038246, -0.021417465060949326, -0.025168435648083687, 0.00179774546995759, 0.007331886328756809, 0.003678089939057827, -0.03721819072961807, -0.03515807166695595, 0.007331886328756809, -0.006748833693563938, 0.03220393881201744, -0.038928475230932236, 0.07645762711763382, -0.06833375990390778, 0.02923036925494671, -0.030551955103874207, 0.02926923893392086, 0.03179579973220825, 0.025673748925328255, 0.03509976342320442, 0.022505829110741615, 0.03789841756224632, 0.022505829110741615, 0.02623736672103405, 0.030862916260957718, -0.019794635474681854, 0.08979009836912155, 0.074397511780262, -0.005407812539488077, 0.00005898852396057919, -0.003167918883264065, 0.04738273844122887, 0.02170899137854576, -0.022019952535629272, 0.02374967560172081, 0.006107475608587265, -0.04384555295109749, 0.033991966396570206, -0.038889605551958084, 0.007448496762663126, -0.04738273844122887, 0.02184503711760044, 0.06790619343519211, 0.0183175690472126, 0.02647058665752411, 0.05049235373735428, 0.0030998962465673685, -0.010932235978543758, -0.040697067975997925, 0.022311478853225708, -0.0048952121287584305, 0.008405674248933792, 0.018162088468670845, 0.009149067103862762, -0.002898257225751877, -0.046294376254081726, 0.013653147965669632, 0.019386498257517815, -0.013361621648073196, -0.018210675567388535, -0.05060896277427673, -0.008425110019743443, -0.060598596930503845, -0.025071261450648308, 0.05546773597598076, 0.01203031837940216, 0.0005007571307942271, 0.016412930563092232, -0.007404767908155918, -0.003508032998070121, 0.0440787747502327, -0.022019952535629272, 0.05741124227643013, 0.005208603106439114, 0.045944541692733765, 0.024915780872106552, -0.04120238125324249, 0.06646799296140671, 0.007409626618027687, 0.033719874918460846, 0.006326120346784592, -0.024682559072971344, -0.017812255769968033, 0.044350866228342056, 0.028627881780266762, -0.0026820418424904346, -0.04162995517253876, 0.07179320603609085, 0.03026042878627777, -0.05057009309530258, -0.025051824748516083, 0.015781288966536522, -0.02126198448240757, -0.0552733838558197, 0.06907229870557785, 0.0096786729991436, -0.047615960240364075, 0.04590567201375961, 0.02786991372704506, 0.025984710082411766, 0.04854884371161461, -0.041824303567409515, -0.002395374234765768, -0.014605467207729816, 0.01715146377682686, -0.04388442263007164, -0.05881056934595108, -0.06856698542833328, 0.04217413440346718, 0.05678931996226311, 0.0029930032324045897, 0.0366351380944252, -0.02940528467297554, 0.06398030370473862, -0.0828712061047554, 0.01221495121717453, -0.043184760957956314, -0.013040942139923573, -0.028025394305586815, -0.0009158783941529691, 0.05080331489443779, -0.0248380396515131, -0.02357475832104683, 0.0393560491502285, -0.055117905139923096, -0.007127817720174789, -0.0051940265111625195, 0.016169991344213486, 0.002457323716953397, 0.07198755443096161, -0.034089140594005585, -0.009445452131330967, -0.02777273766696453, -0.026256801560521126, -0.02701476961374283, -0.05196942016482353, -0.07906193286180496, 0.02054288610816002, -0.022855661809444427, 0.030862916260957718, -0.03587716817855835, 0.007006348576396704, -0.03875356167554855, 0.021203678101301193, 0.023147188127040863, -0.026081884279847145, 0.02497408539056778, 0.015985358506441116, 0.010242289863526821, -0.11987560987472534, 0.027034204453229904, 0.05080331489443779, -0.031873539090156555, 0.028491836041212082, -0.011933142319321632, -0.047926921397447586, 0.0592770129442215, 0.034361232072114944, 0.0010300595313310623, -0.0007033071597106755, -0.025906968861818314, 0.045361489057540894, -0.010825342498719692, -0.0855143740773201, -0.005927701015025377, 0.022311478853225708, -0.004173684865236282, -0.0635138601064682, 0.014760947786271572, 0.002158509334549308, -0.01669473946094513, 0.040735941380262375, -0.0400751456618309, 0.06689556688070297, -0.007866350933909416, 0.005466117989271879, -0.05500129237771034, 0.03904508799314499, -0.019619720056653023, 0.014488856308162212, 0.0029225510079413652, 0.040697067975997925, -0.06285306811332703, 0.06946099549531937, -0.031193312257528305, -0.003928316757082939, 0.0427183173596859, 0.033175691962242126, -0.016539258882403374, 0.08077221363782883, -0.013439361937344074, 0.002604301553219557, -0.010388053022325039, -0.054806940257549286, 0.059471361339092255, 0.033914223313331604, 0.015237106941640377, 0.014547161757946014, 0.04897641763091087, -0.025712618604302406, 0.026451151818037033, 0.017336096614599228, 0.0029759975150227547, 0.047071777284145355, 0.055117905139923096, 0.04578906297683716, -0.0077788932248950005, -0.006695386953651905, 0.06891681253910065, 0.0022192439064383507, -0.02238921821117401, 0.04337911307811737, 0.06219227612018585, -0.015557786449790001, 0.027714433148503304, -0.07435863465070724, 0.03533298522233963, 0.004346170928329229, -0.04749935120344162, 0.023108316585421562, 0.004088656045496464, 0.010932235978543758, 0.03373930975794792, -0.00041663963929750025, 0.0269175935536623, 0.018424460664391518, 0.014469421468675137, 0.05612852796912193, -0.018657682463526726, -0.014722077175974846, -0.017034852877259254, 0.059471361339092255, 0.00023580224660690874, -0.004640126600861549, -0.005650751292705536, 0.06992743909358978, -0.005121144931763411, -0.002141503617167473, -0.008075278252363205, -0.00027725365362130105, -0.050997667014598846, -0.022000517696142197, -0.0023589334450662136, 0.007239569444209337, 0.05212489888072014, 0.06957760453224182, -0.009693249128758907, 0.014148742891848087, 0.009372570551931858, 0.006641940679401159, 0.08504793792963028, -0.02542109228670597, -0.08535889536142349, -0.046216633170843124, -0.01691824197769165, -0.015431458130478859, -0.030551955103874207, 0.01570354960858822, -0.012807721272110939, 0.0013628853484988213, -0.006374708376824856, -0.029774552211165428, 0.04058045893907547, -0.005713915452361107, 0.026315106078982353, -0.028375225141644478, -0.007910080254077911, -0.02637341059744358, -0.045167140662670135, 0.023244362324476242, -0.051036536693573, -0.017851125448942184, 0.021242549642920494, 0.06300854682922363, 0.05196942016482353, 0.02538222260773182, -0.0021548650693148375, -0.05228038132190704, 0.00411537941545248, -0.04800466075539589, 0.010504663921892643, 0.010728167369961739, -0.05332987383008003, 0.014352810569107533, 0.03785954788327217, 0.011291785165667534, -0.05585643649101257, -0.019697459414601326, 0.01728750951588154, 0.03148483857512474, -0.003073172876611352, -0.09313292801380157, -0.009853588417172432, 0.006977195851504803, -0.006194933783262968, 0.03121274709701538, -0.014867840334773064, -0.006311544217169285, -0.08714692294597626, -0.015071908943355083, -0.05107540637254715, 0.019959833472967148, 0.013546254485845566, 0.025945840403437614, -0.02474086359143257, -0.02963850647211075, -0.00761369476094842, -0.009873023256659508, 0.016160273924469948, -0.029910597950220108, -0.035896603018045425, 0.015217672102153301, -0.03978361934423447, 0.019979268312454224, -0.012603653594851494, 0.0028618164360523224, 0.0385592095553875, -0.0024621824268251657, 0.019376780837774277, -0.06048198789358139, 0.033000774681568146, -0.021786730736494064, -0.049015287309885025, 0.044622957706451416, 0.0538351871073246, -0.022505829110741615, -0.01592705212533474, 0.06930551677942276, -0.010504663921892643, -0.015217672102153301, -0.011952578090131283, -0.03488598018884659, 0.0440787747502327, -0.021320289000868797, -0.03335060551762581, -0.03593547269701958, -0.004389899782836437, -0.003908881451934576, -0.02248639427125454, 0.009552344679832458, 0.0007834769203327596, -0.005728491581976414, -0.015324565581977367, -0.03053252026438713, 0.006729398388415575, 0.020367970690131187, 0.07272609323263168, -0.018793728202581406, -0.034089140594005585, 0.012137210927903652, 0.012535630725324154, 0.03253433480858803, 0.05402953922748566, 0.06934438645839691, -0.04384555295109749, -0.03747084364295006, -0.012982637621462345, 0.01764705777168274, -0.0621534027159214, -0.017928866669535637, 0.007662282790988684, -0.06409691274166107, -0.011505571193993092, 0.00855143740773201, 0.016296319663524628, -0.03288416564464569, -0.06048198789358139, 0.026839854195713997, -0.004122667480260134, -0.07579683512449265, -0.06771183758974075, 0.04302927851676941, 0.04610002413392067, 0.024935215711593628, -0.013128400780260563, -0.011554158292710781, 0.053679708391427994, -0.05189168080687523, -0.08395957201719284, 0.03492484986782074, 0.014148742891848087, 0.019920963793992996, -0.03457501903176308, 0.04038610681891441, 0.008808952756226063, -0.03809276968240738, -0.05138636752963066, -0.0024719000793993473, -0.019920963793992996, 0.030843481421470642, -0.035993777215480804, 0.02040684036910534, 0.05329100415110588, 0.00805098470300436, -0.030066078528761864, -0.011146022006869316, -0.03140709921717644, -0.08038351684808731, 0.0387146919965744, 0.02303057722747326, 0.009805000387132168, -0.03622699901461601, -0.03026042878627777, -0.013964109122753143, 0.026800982654094696, 0.01151528861373663, -0.01490671094506979, 0.02071780152618885, -0.01307009533047676, -0.012506477534770966, -0.0026601774152368307, 0.014479138888418674, -0.02361362986266613, -0.003226224333047867, 0.028608446940779686, -0.0884685143828392, -0.0008581805159337819, 0.023419277742505074, -0.08349312841892242, 0.002066192450001836, -0.017928866669535637, -0.026256801560521126, 0.0881575495004654, 0.009839012287557125, 0.032048456370830536, 0.004761596210300922, -0.014605467207729816, 0.02524617686867714, -0.015003886073827744, -0.009873023256659508, 0.05993780493736267, -0.02654832787811756, 0.0183175690472126, -0.039880797266960144, -0.017715081572532654, -0.0013142976677045226, -0.010961388237774372, 0.010125679895281792, 0.012535630725324154, -0.02750064618885517, -0.01092251855880022, 0.03103783167898655, -0.0007300304132513702, 0.024099506437778473, -0.018405025824904442, 0.011690204031765461, -0.01182624977082014, -0.040152888745069504, -0.05196942016482353, -0.026081884279847145, -0.048199012875556946, -0.06125938892364502, -0.008716636337339878, -0.018764575943350792, 0.0227584857493639, 0.0220782570540905, 0.04660533741116524, 0.02569318376481533, 0.08504793792963028 ]
30,827
networkx.algorithms.tree.operations
join
A deprecated name for `join_trees` Returns a new rooted tree with a root node joined with the roots of each of the given rooted trees. .. deprecated:: 3.2 `join` is deprecated in NetworkX v3.2 and will be removed in v3.4. It has been renamed join_trees with the same syntax/interface.
def join(rooted_trees, label_attribute=None): """A deprecated name for `join_trees` Returns a new rooted tree with a root node joined with the roots of each of the given rooted trees. .. deprecated:: 3.2 `join` is deprecated in NetworkX v3.2 and will be removed in v3.4. It has been renamed join_trees with the same syntax/interface. """ import warnings warnings.warn( "The function `join` is deprecated and is renamed `join_trees`.\n" "The ``join`` function itself will be removed in v3.4", DeprecationWarning, stacklevel=2, ) return join_trees(rooted_trees, label_attribute=label_attribute)
(rooted_trees, label_attribute=None)
[ -0.07776042819023132, 0.0007257925462909043, 0.012246411293745041, 0.004418984521180391, -0.04600539803504944, -0.011681191623210907, -0.02461271733045578, 0.03562592342495918, 0.08063790202140808, -0.0014965456211939454, -0.009488827548921108, -0.06861415505409241, 0.02887755073606968, 0.036208268254995346, 0.03098427504301071, -0.006410096772015095, -0.03259429335594177, -0.008011550642549992, 0.050801195204257965, 0.039257027208805084, -0.01437882799655199, -0.00851253978908062, 0.022249072790145874, 0.0038559066597372293, -0.030641719698905945, 0.019405851140618324, -0.018772121518850327, 0.014764204621315002, -0.033878881484270096, -0.006825447082519531, 0.004641646519303322, -0.03211471438407898, -0.03644805774092674, -0.031172681599855423, 0.021324170753359795, 0.027798496186733246, -0.02166672609746456, 0.028946062549948692, 0.09899895638227463, -0.030127882957458496, -0.029853837564587593, -0.03423856571316719, -0.03531762212514877, -0.03720168396830559, 0.027729984372854233, 0.005909107159823179, 0.04706732556223869, 0.023636428639292717, -0.011107409372925758, 0.008384081535041332, -0.009942715056240559, 0.013916376046836376, 0.015346551313996315, 0.042990896850824356, -0.05165758728981018, 0.009557338431477547, -0.035112086683511734, -0.016417041420936584, -0.007771760690957308, 0.000563613255508244, 0.0690937340259552, 0.046245187520980835, 0.007412075996398926, 0.06881969422101974, -0.033176641911268234, 0.007737505249679089, -0.06919649988412857, 0.021632472053170204, -0.0046887481585145, 0.006195998750627041, -0.05984469875693321, 0.010516498237848282, -0.00575067475438118, -0.009668669663369656, -0.004744413774460554, 0.03151524066925049, 0.010602137073874474, 0.028483610600233078, -0.028706273064017296, -0.0019247418968006968, -0.07138887047767639, -0.021838005632162094, -0.014241805300116539, 0.037338707596063614, 0.02158108726143837, -0.025263573974370956, -0.0337589867413044, 0.062345363199710846, -0.06015300005674362, -0.10064323246479034, -0.0304019283503294, 0.043196432292461395, -0.018789248540997505, 0.016939440742135048, -0.020193731412291527, -0.022231945767998695, 0.00869666412472725, 0.0016410618554800749, -0.01083336304873228, -0.028226692229509354, 0.045628584921360016, -0.04206599295139313, -0.055768270045518875, 0.009651541709899902, 0.005583678372204304, -0.006731243804097176, -0.04042172059416771, -0.028295204043388367, 0.013890684582293034, -0.00010336923151044175, -0.07591062039136887, -0.05744680017232895, 0.06303048133850098, -0.02015947550535202, -0.027901263907551765, -0.04134662449359894, 0.00012591644190251827, -0.01099607814103365, -0.015629161149263382, -0.031669389456510544, 0.026102839037775993, 0.0028239537496119738, -0.03059033490717411, -0.041278112679719925, -0.006341585423797369, -0.0024492822121828794, 0.030538951978087425, -0.006525709759443998, -0.02512655220925808, -0.0654626339673996, 0.009754309430718422, 0.0597761869430542, -0.04415559023618698, 0.016297146677970886, 0.07796595990657806, -0.05470634624361992, -0.06926501542329788, 0.04425835609436035, 0.052274189889431, 0.017179230228066444, -0.005236839409917593, -0.0936550721526146, 0.03716742992401123, 0.03942830488085747, -0.012957216240465641, -0.0005828820285387337, -0.03293684870004654, -0.043196432292461395, -0.01570623554289341, -0.004731568042188883, 0.04586837440729141, -0.020844589918851852, 0.021803749725222588, 0.006589939352124929, -0.00560080586001277, 0.012683170847594738, -0.010816236026585102, -0.036002736538648605, 0.048882875591516495, -0.04182620346546173, 0.025469109416007996, -0.02675369754433632, -0.00572498282417655, -0.002248029923066497, 0.008855096995830536, -0.01119304820895195, 0.024047497659921646, -0.005699291359633207, -0.03218322619795799, -0.006341585423797369, 0.01933733932673931, 0.005960491020232439, 0.022249072790145874, 0.030744485557079315, -0.07029268890619278, -0.04377877712249756, -0.02481825090944767, 0.03009362705051899, -0.016168687492609024, -0.010199633426964283, -0.010156813077628613, 0.03283408284187317, 0.06029002368450165, -0.06775776296854019, 0.01834392361342907, 0.009446008130908012, -0.03785254433751106, 0.011835342273116112, -0.00040598350460641086, -0.030419057235121727, 0.04059299826622009, -0.0688539445400238, 0.029202979058027267, 0.0729646310210228, 0.008002987131476402, -0.04812924936413765, -0.017590299248695374, -0.029220107942819595, -0.010096865706145763, 0.08344687521457672, -0.035112086683511734, 0.038948725908994675, 0.04042172059416771, -0.003776690224185586, 0.06772350519895554, -0.021050123497843742, -0.03963384032249451, 0.030521823093295097, -0.00397366052493453, -0.0010426577646285295, 0.07899363338947296, -0.007977294735610485, -0.04343622177839279, 0.0791991651058197, -0.0595363974571228, 0.05741254612803459, -0.04103832319378853, 0.02856924943625927, 0.01356525532901287, -0.05066417157649994, -0.0393255390226841, 0.010148249566555023, 0.060427043586969376, -0.012126515619456768, -0.07495146244764328, -0.014575798064470291, 0.029117340222001076, 0.023585045710206032, 0.0828302726149559, -0.06618200242519379, 0.06666158139705658, -0.06995012611150742, -0.02815818041563034, -0.0228999312967062, 0.010970386676490307, -0.08002129942178726, 0.02807254157960415, -0.01069634035229683, 0.039462558925151825, -0.022557374089956284, -0.024869633838534355, -0.05261674523353577, -0.011467093601822853, -0.021307041868567467, 0.06875117868185043, 0.009480263106524944, -0.033365048468112946, -0.05066417157649994, 0.017967112362384796, 0.0008301653433591127, -0.06436645239591599, 0.015620596706867218, 0.034701019525527954, 0.000716158130671829, 0.03156662359833717, -0.02887755073606968, -0.0191489327698946, -0.02098161354660988, -0.022608758881688118, -0.005121226422488689, -0.0014216112904250622, -0.030624590814113617, -0.015355114825069904, 0.026513908058404922, -0.025451980531215668, -0.011432837694883347, -0.01499543059617281, -0.00003535963696776889, 0.03201194852590561, -0.035523153841495514, 0.020741822198033333, -0.01474707666784525, 0.019200317561626434, 0.011312942951917648, 0.005712137091904879, 0.018789248540997505, -0.04408707842230797, 0.04162066802382469, 0.005956208799034357, -0.012905833311378956, -0.018104134127497673, -0.02219768986105919, -0.09146270155906677, 0.028894677758216858, -0.055665504187345505, 0.02098161354660988, -0.020193731412291527, -0.015757620334625244, 0.03846914693713188, -0.02733604423701763, 0.016665395349264145, 0.03201194852590561, 0.01956000179052353, 0.021495448425412178, -0.018480947241187096, -0.019971070811152458, -0.031241193413734436, -0.022266201674938202, 0.060529813170433044, -0.01671677827835083, -0.02409888058900833, -0.061249181628227234, 0.0457998625934124, 0.012666042894124985, 0.04648497700691223, -0.012888705357909203, 0.05439804494380951, -0.012477636337280273, 0.013976323418319225, 0.0010555036133155227, -0.036208268254995346, -0.03685912862420082, 0.0107391607016325, -0.04497772827744484, -0.003624680684879422, -0.0031087042298167944, 0.025195064023137093, -0.06354431062936783, 0.03795531019568443, -0.01645129732787609, -0.05724126473069191, 0.007540534716099501, -0.01356525532901287, 0.044909216463565826, 0.005853442009538412, 0.008906480856239796, 0.08687244355678558, -0.00033854259527288377, 0.015158144757151604, 0.025589004158973694, -0.0032564320135861635, -0.01119304820895195, 0.043504733592271805, -0.02774711325764656, -0.08502263575792313, 0.04617667570710182, 0.04956799000501633, -0.0023507969453930855, -0.009223345667123795, -0.011484221555292606, -0.04223727062344551, 0.009052067063748837, -0.00671411631628871, 0.042579829692840576, -0.015021122060716152, 0.046347953379154205, 0.02615422196686268, 0.036105502396821976, -0.0012374869547784328, -0.02409888058900833, -0.02139268070459366, 0.035386133939027786, -0.029528409242630005, 0.02695923112332821, 0.019919686019420624, 0.0409012995660305, -0.01038803905248642, 0.07262207567691803, 0.0004185617726761848, 0.0035904250107705593, 0.02471548318862915, -0.03822935372591019, 0.031069915741682053, -0.008011550642549992, 0.04672476649284363, 0.01443877536803484, -0.0024878198746591806, 0.0260172002017498, -0.027284661307930946, -0.03709891811013222, 0.0005422034300863743, -0.03959958255290985, 0.028620632365345955, 0.07323867827653885, -0.0040764277800917625, 0.06433219462633133, -0.0401134192943573, -0.013128494843840599, -0.0372701957821846, 0.021529704332351685, -0.045628584921360016, -0.008469720371067524, 0.0514863096177578, 0.024064624682068825, 0.006106077693402767, 0.01220359094440937, 0.04264834150671959, -0.07481443881988525, 0.02310546673834324, 0.03141247108578682, -0.015483574010431767, 0.011655500158667564, 0.004598827101290226, 0.060940880328416824, -0.09495678544044495, 0.0009966265643015504, 0.024441437795758247, -0.06303048133850098, -0.012803065590560436, -0.033056747168302536, 0.020502032712101936, 0.030915765091776848, -0.031069915741682053, -0.020827462896704674, -0.019285956397652626, 0.06436645239591599, 0.021632472053170204, -0.04627944529056549, -0.014241805300116539, -0.03576294705271721, -0.026462523266673088, 0.044326867908239365, -0.059604909271001816, 0.0327313169836998, 0.05001331493258476, -0.005027023144066334, 0.043607499450445175, 0.05785786733031273, 0.053849950432777405, -0.0061189234256744385, -0.038126587867736816, -0.02695923112332821, -0.00025638245278969407, -0.0002586572663858533, 0.03403303399682045, -0.03386175259947777, 0.0023293872363865376, -0.017119282856583595, -0.00693677831441164, 0.02533208578824997, -0.01791572757065296, -0.032765571027994156, 0.0315837487578392, 0.0027597243897616863, 0.04014767333865166, 0.006808319129049778, 0.006696988362818956, -0.0023507969453930855, 0.019114676862955093, 0.01356525532901287, -0.013231261633336544, -0.009103450924158096, 0.011912417598068714, -0.04997905716300011, -0.0034576840698719025, -0.038434889167547226, -0.03860616683959961, -0.005091252736747265, -0.026376884430646896, 0.024441437795758247, 0.02267727069556713, -0.04326494410634041, 0.029425641521811485, 0.05371293053030968, -0.05193163454532623, 0.017967112362384796, 0.026513908058404922, -0.00599902868270874, 0.010242452844977379, 0.08885927498340607, 0.029117340222001076, -0.01413903757929802, 0.05621359497308731, 0.07234802842140198, 0.012486200779676437, 0.020519161596894264, 0.034786656498909, -0.04292238503694534, 0.00167210609652102, 0.010576445609331131, 0.11352337151765823, -0.032782699912786484, -0.015423626638948917, -0.004294807557016611, 0.08098046481609344, 0.03281695395708084, -0.0496707558631897, -0.018087007105350494, -0.020090965554118156, -0.06289345771074295, -0.08351538330316544, -0.03583145514130592, 0.032063331454992294, -0.029254363849759102, -0.0326114222407341, -0.02046777680516243, 0.03069310262799263, 0.029322873800992966, 0.05230844393372536, -0.015509265474975109, -0.002385052852332592, -0.011518477462232113, 0.008803713135421276, -0.04508049413561821, 0.03761275112628937, 0.0551174134016037, -0.032662805169820786, -0.03452974185347557, -0.06172876060009003, -0.001065138028934598, 0.03867467865347862, -0.025777410715818405, -0.00862815324217081, -0.017239177599549294, 0.04569709673523903, 0.03675635904073715, -0.003260714001953602, 0.01337684877216816, -0.0055665504187345505, 0.007784606423228979, 0.00293742585927248, -0.02947702445089817, 0.017204923555254936, 0.027233276516199112, 0.04535454139113426, 0.07282760739326477, -0.039462558925151825, 0.03322802484035492, 0.07186844944953918, 0.020947357639670372, -0.03973660618066788, 0.09906747192144394, -0.006367277354001999, -0.024681227281689644, -0.016280019655823708, -0.008940736763179302, 0.041791945695877075, 0.06854564696550369, -0.01580900326371193, 0.0297681987285614, -0.007951603271067142, 0.05066417157649994, 0.014336008578538895, 0.009291857481002808, -0.009762872941792011, 0.05107524245977402, -0.046759024262428284, 0.017016516998410225, 0.08906480669975281, -0.056693173944950104, 0.0035604513250291348, -0.006452916655689478, -0.021718110889196396, -0.013094238936901093, -0.02642826922237873, 0.024869633838534355, -0.00354760535992682, 0.02541772462427616, 0.05806340277194977, -0.0058405958116054535, 0.009805692359805107, 0.05895404890179634, -0.002395757706835866, 0.0615917406976223, 0.027404556050896645, -0.05744680017232895, -0.05439804494380951, 0.0025713180657476187, -0.0002193167310906574, 0.04042172059416771, -0.03151524066925049, 0.016682524234056473, 0.035112086683511734, 0.0023122592829167843, 0.05611082911491394, -0.025297829881310463, -0.018172645941376686, 0.015980280935764313, 0.01985117420554161, -0.025914432480931282, -0.050390128046274185, -0.015038250014185905, 0.008456874638795853, -0.04997905716300011, -0.00787452794611454, -0.005836314056068659, -0.028706273064017296, 0.008923608809709549, -0.033981647342443466, -0.024646973237395287, -0.06686711311340332, 0.058885540813207626, -0.011569861322641373, 0.01469569280743599, 0.048985645174980164, -0.01812126301229, 0.0261370949447155, 0.013505307957530022, 0.02014234848320484, -0.03720168396830559, -0.038640424609184265, -0.010191068984568119, 0.05491187795996666, -0.004314076621085405, 0.049088411033153534, -0.05052714794874191, -0.06926501542329788, 0.04103832319378853, 0.041278112679719925, -0.0172734335064888, 0.06621626019477844, -0.00788309145718813, 0.008456874638795853, 0.05943363159894943, -0.000007029275366221555, -0.009634413756430149, -0.01781296171247959, -0.04353898763656616, -0.02939138561487198, 0.025657515972852707, 0.007356410380452871, 0.045731350779533386, 0.006512864027172327, -0.0035775790456682444, 0.01200662087649107, -0.05357590690255165, -0.0182411577552557, 0.008546795696020126, 0.007005289662629366, 0.02483537793159485, 0.0019215303473174572, 0.0017545338487252593, -0.00693677831441164, -0.0015768324956297874, -0.03365622088313103, 0.004177053924649954, 0.008127163164317608, -0.029100213199853897, 0.0022951315622776747, 0.036311037838459015, -0.047546904534101486, -0.07803447544574738, 0.018155518919229507, -0.03326227888464928, -0.04946522414684296, -0.031258322298526764, 0.06840862333774567, -0.04720434546470642, 0.011295814998447895, 0.02024511620402336, -0.04689604416489601, -0.040867045521736145, -0.06741520762443542, -0.049499478191137314, 0.02827807515859604, -0.06929927319288254, -0.016065921634435654, -0.021957900375127792, -0.026411140337586403, -0.0004977780627086759, -0.016023101285099983, 0.011561296880245209, -0.006731243804097176, 0.020176604390144348, 0.006658450700342655, 0.05295930430293083, -0.025503365322947502, 0.017487531527876854, -0.0006117852753959596, 0.01307711098343134, 0.016588320955634117, -0.03178928419947624, 0.0530620701611042, 0.05381569638848305, -0.0486430861055851, 0.035386133939027786, 0.008949300274252892, 0.022865675389766693, -0.004091414622962475, 0.01746184006333351, -0.015757620334625244, -0.03644805774092674, 0.018206901848316193, -0.032354503870010376, -0.02714763768017292, -0.014550106599926949, 0.020433522760868073, 0.0021399103570729494, 0.023961858823895454, -0.048985645174980164, 0.04730711504817009, 0.038948725908994675, -0.04285387322306633, -0.01580900326371193, -0.010216761380434036, 0.041380878537893295, 0.006208844482898712, 0.035386133939027786, 0.03303961828351021, -0.07426634430885315, 0.026565290987491608, 0.0028239537496119738, 0.027284661307930946, 0.053952720016241074, -0.07796595990657806, 0.032166097313165665, 0.0030508977361023426, -0.0097714364528656, 0.0021987874060869217, 0.010533626191318035, 0.08008981496095657, 0.041380878537893295, -0.0520344004034996, -0.04559433087706566, 0.010516498237848282, -0.009026375599205494, -0.01120161172002554, 0.03213184326887131, -0.00951451901346445, 0.02411600947380066, -0.011475658044219017, 0.008148573338985443, 0.037030406296253204, 0.0022201971150934696, 0.057789355516433716, -0.06426368653774261, -0.00906919501721859, -0.058097656816244125, -0.055357202887535095, 0.021341297775506973, 0.006333021447062492, -0.013556690886616707, 0.0962584987282753, -0.027901263907551765, 0.029939476400613785, -0.01367658656090498, 0.043299198150634766, -0.005660753697156906, -0.032662805169820786, 0.03583145514130592, -0.01655406504869461, 0.10571307688951492, 0.014849843457341194, 0.040969811379909515, -0.03151524066925049, -0.03098427504301071, 0.006225972436368465, 0.0008344473317265511, -0.010242452844977379, 0.018789248540997505, -0.000019921159037039615, -0.01762455515563488, 0.006384405307471752, -0.003479094011709094, 0.03233737498521805, -0.07639019936323166, 0.008897916413843632, 0.015560649335384369, -0.0190290380269289, 0.01945723406970501, 0.04747839272022247, 0.026205606758594513, -0.020502032712101936, -0.029922349378466606, 0.05056140571832657, 0.0026184197049587965, 0.033056747168302536, -0.007904501631855965, -0.005279658827930689, -0.09392911195755005, 0.001383073627948761, -0.003633244661614299, -0.048471808433532715, 0.00014451620518229902, -0.030624590814113617, 0.04295664280653, 0.013205570168793201, 0.03822935372591019 ]
30,837
networkx.algorithms.connectivity.edge_augmentation
k_edge_augmentation
Finds set of edges to k-edge-connect G. Adding edges from the augmentation to G make it impossible to disconnect G unless k or more edges are removed. This function uses the most efficient function available (depending on the value of k and if the problem is weighted or unweighted) to search for a minimum weight subset of available edges that k-edge-connects G. In general, finding a k-edge-augmentation is NP-hard, so solutions are not guaranteed to be minimal. Furthermore, a k-edge-augmentation may not exist. Parameters ---------- G : NetworkX graph An undirected graph. k : integer Desired edge connectivity avail : dict or a set of 2 or 3 tuples The available edges that can be used in the augmentation. If unspecified, then all edges in the complement of G are available. Otherwise, each item is an available edge (with an optional weight). In the unweighted case, each item is an edge ``(u, v)``. In the weighted case, each item is a 3-tuple ``(u, v, d)`` or a dict with items ``(u, v): d``. The third item, ``d``, can be a dictionary or a real number. If ``d`` is a dictionary ``d[weight]`` correspondings to the weight. weight : string key to use to find weights if ``avail`` is a set of 3-tuples where the third item in each tuple is a dictionary. partial : boolean If partial is True and no feasible k-edge-augmentation exists, then all a partial k-edge-augmentation is generated. Adding the edges in a partial augmentation to G, minimizes the number of k-edge-connected components and maximizes the edge connectivity between those components. For details, see :func:`partial_k_edge_augmentation`. Yields ------ edge : tuple Edges that, once added to G, would cause G to become k-edge-connected. If partial is False, an error is raised if this is not possible. Otherwise, generated edges form a partial augmentation, which k-edge-connects any part of G where it is possible, and maximally connects the remaining parts. Raises ------ NetworkXUnfeasible If partial is False and no k-edge-augmentation exists. NetworkXNotImplemented If the input graph is directed or a multigraph. ValueError: If k is less than 1 Notes ----- When k=1 this returns an optimal solution. When k=2 and ``avail`` is None, this returns an optimal solution. Otherwise when k=2, this returns a 2-approximation of the optimal solution. For k>3, this problem is NP-hard and this uses a randomized algorithm that produces a feasible solution, but provides no guarantees on the solution weight. Examples -------- >>> # Unweighted cases >>> G = nx.path_graph((1, 2, 3, 4)) >>> G.add_node(5) >>> sorted(nx.k_edge_augmentation(G, k=1)) [(1, 5)] >>> sorted(nx.k_edge_augmentation(G, k=2)) [(1, 5), (5, 4)] >>> sorted(nx.k_edge_augmentation(G, k=3)) [(1, 4), (1, 5), (2, 5), (3, 5), (4, 5)] >>> complement = list(nx.k_edge_augmentation(G, k=5, partial=True)) >>> G.add_edges_from(complement) >>> nx.edge_connectivity(G) 4 >>> # Weighted cases >>> G = nx.path_graph((1, 2, 3, 4)) >>> G.add_node(5) >>> # avail can be a tuple with a dict >>> avail = [(1, 5, {"weight": 11}), (2, 5, {"weight": 10})] >>> sorted(nx.k_edge_augmentation(G, k=1, avail=avail, weight="weight")) [(2, 5)] >>> # or avail can be a 3-tuple with a real number >>> avail = [(1, 5, 11), (2, 5, 10), (4, 3, 1), (4, 5, 51)] >>> sorted(nx.k_edge_augmentation(G, k=2, avail=avail)) [(1, 5), (2, 5), (4, 5)] >>> # or avail can be a dict >>> avail = {(1, 5): 11, (2, 5): 10, (4, 3): 1, (4, 5): 51} >>> sorted(nx.k_edge_augmentation(G, k=2, avail=avail)) [(1, 5), (2, 5), (4, 5)] >>> # If augmentation is infeasible, then a partial solution can be found >>> avail = {(1, 5): 11} >>> sorted(nx.k_edge_augmentation(G, k=2, avail=avail, partial=True)) [(1, 5)]
def unconstrained_bridge_augmentation(G): """Finds an optimal 2-edge-augmentation of G using the fewest edges. This is an implementation of the algorithm detailed in [1]_. The basic idea is to construct a meta-graph of bridge-ccs, connect leaf nodes of the trees to connect the entire graph, and finally connect the leafs of the tree in dfs-preorder to bridge connect the entire graph. Parameters ---------- G : NetworkX graph An undirected graph. Yields ------ edge : tuple Edges in the bridge augmentation of G Notes ----- Input: a graph G. First find the bridge components of G and collapse each bridge-cc into a node of a metagraph graph C, which is guaranteed to be a forest of trees. C contains p "leafs" --- nodes with exactly one incident edge. C contains q "isolated nodes" --- nodes with no incident edges. Theorem: If p + q > 1, then at least :math:`ceil(p / 2) + q` edges are needed to bridge connect C. This algorithm achieves this min number. The method first adds enough edges to make G into a tree and then pairs leafs in a simple fashion. Let n be the number of trees in C. Let v(i) be an isolated vertex in the i-th tree if one exists, otherwise it is a pair of distinct leafs nodes in the i-th tree. Alternating edges from these sets (i.e. adding edges A1 = [(v(i)[0], v(i + 1)[1]), v(i + 1)[0], v(i + 2)[1])...]) connects C into a tree T. This tree has p' = p + 2q - 2(n -1) leafs and no isolated vertices. A1 has n - 1 edges. The next step finds ceil(p' / 2) edges to biconnect any tree with p' leafs. Convert T into an arborescence T' by picking an arbitrary root node with degree >= 2 and directing all edges away from the root. Note the implementation implicitly constructs T'. The leafs of T are the nodes with no existing edges in T'. Order the leafs of T' by DFS preorder. Then break this list in half and add the zipped pairs to A2. The set A = A1 + A2 is the minimum augmentation in the metagraph. To convert this to edges in the original graph References ---------- .. [1] Eswaran, Kapali P., and R. Endre Tarjan. (1975) Augmentation problems. http://epubs.siam.org/doi/abs/10.1137/0205044 See Also -------- :func:`bridge_augmentation` :func:`k_edge_augmentation` Examples -------- >>> G = nx.path_graph((1, 2, 3, 4, 5, 6, 7)) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 7)] >>> G = nx.path_graph((1, 2, 3, 2, 4, 5, 6, 7)) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 3), (3, 7)] >>> G = nx.Graph([(0, 1), (0, 2), (1, 2)]) >>> G.add_node(4) >>> sorted(unconstrained_bridge_augmentation(G)) [(1, 4), (4, 0)] """ # ----- # Mapping of terms from (Eswaran and Tarjan): # G = G_0 - the input graph # C = G_0' - the bridge condensation of G. (This is a forest of trees) # A1 = A_1 - the edges to connect the forest into a tree # leaf = pendant - a node with degree of 1 # alpha(v) = maps the node v in G to its meta-node in C # beta(x) = maps the meta-node x in C to any node in the bridge # component of G corresponding to x. # find the 2-edge-connected components of G bridge_ccs = list(nx.connectivity.bridge_components(G)) # condense G into an forest C C = collapse(G, bridge_ccs) # Choose pairs of distinct leaf nodes in each tree. If this is not # possible then make a pair using the single isolated node in the tree. vset1 = [ tuple(cc) * 2 # case1: an isolated node if len(cc) == 1 else sorted(cc, key=C.degree)[0:2] # case2: pair of leaf nodes for cc in nx.connected_components(C) ] if len(vset1) > 1: # Use this set to construct edges that connect C into a tree. nodes1 = [vs[0] for vs in vset1] nodes2 = [vs[1] for vs in vset1] A1 = list(zip(nodes1[1:], nodes2)) else: A1 = [] # Connect each tree in the forest to construct an arborescence T = C.copy() T.add_edges_from(A1) # If there are only two leaf nodes, we simply connect them. leafs = [n for n, d in T.degree() if d == 1] if len(leafs) == 1: A2 = [] if len(leafs) == 2: A2 = [tuple(leafs)] else: # Choose an arbitrary non-leaf root try: root = next(n for n, d in T.degree() if d > 1) except StopIteration: # no nodes found with degree > 1 return # order the leaves of C by (induced directed) preorder v2 = [n for n in nx.dfs_preorder_nodes(T, root) if T.degree(n) == 1] # connecting first half of the leafs in pre-order to the second # half will bridge connect the tree with the fewest edges. half = math.ceil(len(v2) / 2) A2 = list(zip(v2[:half], v2[-half:])) # collect the edges used to augment the original forest aug_tree_edges = A1 + A2 # Construct the mapping (beta) from meta-nodes to regular nodes inverse = defaultdict(list) for k, v in C.graph["mapping"].items(): inverse[v].append(k) # sort so we choose minimum degree nodes first inverse = { mu: sorted(mapped, key=lambda u: (G.degree(u), u)) for mu, mapped in inverse.items() } # For each meta-edge, map back to an arbitrary pair in the original graph G2 = G.copy() for mu, mv in aug_tree_edges: # Find the first available edge that doesn't exist and return it for u, v in it.product(inverse[mu], inverse[mv]): if not G2.has_edge(u, v): G2.add_edge(u, v) yield u, v break
(G, k, avail=None, weight=None, partial=False, *, backend=None, **backend_kwargs)
[ 0.005580552853643894, -0.008635446429252625, -0.05353138595819473, 0.02833767980337143, 0.012083337642252445, -0.0359041765332222, -0.01430507842451334, -0.037853438407182693, 0.059609733521938324, -0.08480343967676163, 0.007870413362979889, 0.013571484945714474, -0.02175629511475563, 0.05621424317359924, -0.03370339423418045, 0.006460865028202534, 0.002082882449030876, 0.04082973301410675, 0.08392313122749329, 0.021504778414964676, -0.03364051505923271, -0.0926424115896225, -0.027939442545175552, 0.01162222120910883, -0.0342693105340004, 0.006717623211443424, -0.011276384815573692, 0.004081925377249718, -0.028316719457507133, 0.006958661135286093, 0.010825748555362225, -0.07952156662940979, -0.0309576578438282, -0.038775671273469925, 0.03470946475863457, -0.004828618839383125, 0.004922938067466021, 0.06828710436820984, -0.06363402307033539, -0.035380180925130844, 0.0026422475930303335, -0.06832902133464813, 0.007320217788219452, -0.05709455534815788, 0.0772998258471489, 0.04648888483643532, 0.007933292537927628, 0.04131180793046951, 0.011129665188491344, -0.009615318849682808, 0.00304179429076612, -0.0663168802857399, 0.027646005153656006, 0.02657705545425415, -0.029280871152877808, 0.03957214578986168, 0.019901352003216743, 0.034227389842271805, 0.04749495908617973, -0.04363834857940674, 0.025172745808959007, -0.03797919675707817, 0.00355530995875597, 0.004142184741795063, -0.034436989575624466, 0.014860513620078564, -0.03911102935671806, -0.07818013429641724, -0.043219152837991714, 0.013435246422886848, -0.005108956713229418, -0.017354732379317284, 0.013739163987338543, -0.006953421048820019, 0.023747479543089867, -0.001916513778269291, 0.02351692132651806, -0.001602116390131414, 0.016065703704953194, -0.015091071836650372, 0.03213140740990639, -0.01951359398663044, 0.005418113898485899, -0.03152357414364815, 0.05013589560985565, -0.01642202027142048, 0.026996251195669174, -0.003605089383199811, -0.04598585143685341, -0.07239522784948349, -0.01551026850938797, -0.0309576578438282, 0.05470513552427292, 0.061957236379384995, 0.028568238019943237, 0.01238725520670414, -0.02949047088623047, -0.07822205871343613, 0.023160602897405624, -0.06120268255472183, 0.0022178112994879484, 0.055208172649145126, -0.07461696863174438, -0.0051246765069663525, -0.005763951223343611, -0.04481210187077522, -0.04703384265303612, 0.04024285823106766, -0.015112032182514668, -0.059987012296915054, -0.08107259124517441, -0.016621138900518417, 0.026262657716870308, -0.008583047427237034, -0.0161600224673748, -0.01529019046574831, -0.001763245090842247, 0.027666965499520302, 0.015877066180109978, -0.0045509012416005135, 0.018151206895709038, -0.0012300795642659068, -0.041731007397174835, 0.0024509893264621496, -0.006618063896894455, -0.020855022594332695, 0.06992197036743164, 0.04388986900448799, -0.035652656108140945, -0.05776527151465416, 0.021840134635567665, -0.0008953774231486022, -0.05776527151465416, 0.019199198111891747, -0.011863259598612785, -0.06384361535310745, -0.05441169813275337, -0.017155613750219345, 0.04005422070622444, -0.0106213903054595, -0.005224235821515322, -0.09784045070409775, 0.05667535960674286, -0.0019204437267035246, -0.013823002576828003, -0.026996251195669174, 0.057681430131196976, -0.039048150181770325, 0.03936254605650902, -0.023600760847330093, 0.007115859538316727, 0.012209096923470497, 0.00821101013571024, -0.011328783817589283, 0.007781334221363068, 0.020006150007247925, -0.053573306649923325, 0.03678448870778084, -0.024145714938640594, -0.0085673276335001, -0.06388553977012634, -0.007975212298333645, -0.007094899658113718, 0.02013191021978855, 0.0025767481420189142, -0.031062455847859383, 0.06564616411924362, -0.020100468769669533, -0.027499286457896233, 0.005737751256674528, -0.01683073677122593, -0.052860673516988754, -0.0920555368065834, -0.020917901769280434, 0.022657567635178566, 0.09063027054071426, 0.012230056338012218, -0.0004607886075973511, 0.009762037545442581, 0.058939021080732346, 0.046111609786748886, -0.028903594240546227, 0.01687265746295452, -0.016851697117090225, -0.020016631111502647, 0.019440235570073128, 0.04097645357251167, -0.008598767220973969, 0.0482495091855526, -0.012701652012765408, 0.02735256776213646, -0.023328281939029694, 0.03667968884110451, 0.04791415482759476, 0.0460277684032917, -0.002955334959551692, 0.009442400187253952, 0.06895781308412552, -0.031586453318595886, 0.07876700907945633, 0.0013807283248752356, -0.001907343859784305, 0.034877143800258636, 0.013634364120662212, 0.03814687579870224, -0.009117522276937962, 0.006984860636293888, -0.04636312648653984, -0.011643181554973125, 0.015866585075855255, -0.016914576292037964, -0.0026566574815660715, 0.03814687579870224, -0.0328650027513504, -0.030601341277360916, -0.016317222267389297, -0.019943270832300186, 0.04443482309579849, 0.04757879674434662, -0.0026592775247991085, -0.06363402307033539, -0.007755134254693985, -0.004731679800897837, -0.0016925056697800756, 0.05336370691657066, -0.046991921961307526, 0.01710321567952633, -0.009494799189269543, 0.04034765809774399, -0.0031832729000598192, 0.030265983194112778, -0.02888263575732708, 0.004372742958366871, -0.05420210212469101, 0.05835214629769325, 0.02647225558757782, -0.0015300670638680458, -0.02297196537256241, -0.015468348748981953, 0.03517058119177818, -0.001561506767757237, -0.016704978421330452, -0.0411231704056263, 0.009615318849682808, 0.013791562989354134, -0.03315844014286995, 0.021337099373340607, -0.026891451328992844, 0.022343169897794724, 0.01761673018336296, -0.09255857765674591, -0.04690808057785034, -0.027478327974677086, 0.016065703704953194, -0.030014464631676674, -0.057010717689991, -0.03403875231742859, -0.015971384942531586, -0.003206852823495865, 0.011506942100822926, 0.01968127302825451, -0.003264492377638817, -0.04204540327191353, 0.054998572915792465, -0.02005854994058609, 0.0367216095328331, 0.024858349934220314, 0.004852198995649815, -0.01323612779378891, -0.027101051062345505, 0.10664357244968414, 0.04783031344413757, -0.03485618531703949, 0.017805369570851326, -0.009552438743412495, 0.05239955708384514, -0.007084419950842857, 0.03162837028503418, -0.00926424190402031, -0.04150044918060303, -0.02450203150510788, -0.00805905181914568, -0.033954910933971405, 0.002631767652928829, -0.0339968316257, -0.007786573842167854, -0.050010137259960175, -0.06531080603599548, -0.0044408622197806835, -0.03162837028503418, 0.04191964492201805, -0.019775591790676117, 0.018318884074687958, 0.043219152837991714, 0.08023419976234436, 0.01775296963751316, -0.005347374826669693, 0.007498376537114382, 0.013099889270961285, 0.0024405093863606453, 0.0663168802857399, -0.011003906838595867, 0.07055076211690903, -0.004453962203115225, 0.031649332493543625, 0.0005406978889368474, 0.018622802570462227, 0.009054643101990223, -0.04309339448809624, 0.05977741256356239, -0.06702951341867447, -0.0035972294863313437, 0.017386171966791153, -0.002095982199534774, -0.05512433126568794, -0.06837093830108643, 0.02324444241821766, -0.006371785886585712, 0.046991921961307526, -0.005811110604554415, -0.010563750751316547, 0.03953022509813309, -0.05336370691657066, 0.034877143800258636, -0.058016788214445114, 0.012156696990132332, 0.02134757861495018, 0.07461696863174438, 0.007545535918325186, -0.03397587314248085, -0.056968796998262405, 0.0306851789355278, -0.040683016180992126, 0.04363834857940674, -0.07532960176467896, 0.046111609786748886, 0.028693996369838715, -0.030559420585632324, 0.03051750175654888, -0.039823662489652634, 0.027687925845384598, 0.04380602762103081, -0.0146613959223032, 0.012858850881457329, 0.023391161113977432, 0.029679108411073685, 0.02083406411111355, 0.008598767220973969, -0.06405321508646011, 0.05005205422639847, 0.020624464377760887, 0.030810939148068428, -0.037539042532444, 0.027541207149624825, -0.01323612779378891, 0.010291272774338722, -0.03470946475863457, -0.03299076110124588, 0.04334491118788719, 0.04049437493085861, 0.018486563116312027, -0.006555184256285429, -0.010417032055556774, 0.016652578487992287, 0.02647225558757782, 0.001503867213614285, -0.052860673516988754, 0.07440736889839172, -0.005266155581921339, -0.10429607331752777, 0.044309064745903015, -0.05202227830886841, 0.013351406902074814, 0.034772343933582306, -0.015489309094846249, 0.010024035349488258, -0.020865503698587418, 0.0007394887506961823, 0.008425848558545113, 0.07361089438199997, -0.005790150724351406, 0.04728535935282707, -0.005779671017080545, 0.02345404028892517, 0.0007407987141050398, -0.019293516874313354, 0.06417897343635559, 0.001763245090842247, 0.03431122750043869, -0.01819312572479248, 0.022951005026698112, -0.014367958530783653, 0.0504293330013752, -0.017113694921135902, -0.05621424317359924, 0.006984860636293888, 0.06216683238744736, 0.016820257529616356, -0.004453962203115225, -0.014367958530783653, -0.01564650796353817, 0.022343169897794724, 0.020079510286450386, 0.007681774906814098, 0.04279995709657669, -0.042338840663433075, 0.055375851690769196, 0.06484968960285187, 0.04024285823106766, 0.02186109498143196, -0.04866870865225792, 0.03353571519255638, -0.005224235821515322, 0.003990225959569216, -0.0028321959543973207, -0.03550593927502632, 0.024355312809348106, 0.0014134780503809452, 0.003688928671181202, -0.0026422475930303335, 0.04160524904727936, -0.000731628795620054, -0.013686764054000378, -0.0027745564002543688, 0.0010224463185295463, -0.04133277013897896, -0.01778440922498703, 0.007225898560136557, -0.08719286322593689, 0.012743571773171425, 0.033179398626089096, -0.060154691338539124, 0.02925991266965866, -0.04648888483643532, -0.04147948697209358, 0.04110221192240715, 0.035317301750183105, 0.0050958567298948765, 0.04451866075396538, 0.009054643101990223, -0.012995089404284954, 0.04126989096403122, -0.004045245703309774, -0.056926876306533813, 0.037015046924352646, -0.03240388631820679, -0.021337099373340607, 0.02565482258796692, -0.007362137548625469, 0.0197231937199831, 0.015856105834245682, -0.035212501883506775, -0.0010565060656517744, 0.04300955682992935, -0.07570687681436539, 0.017994007095694542, 0.04560857266187668, 0.011087746359407902, -0.07981500029563904, 0.05273491144180298, 0.016820257529616356, -0.020341508090496063, 0.05327986925840378, 0.023978035897016525, 0.007613655645400286, 0.050345491617918015, 0.05118388682603836, -0.030349822714924812, -0.08685750514268875, -0.03634433075785637, 0.013581965118646622, -0.048920225352048874, -0.029406631365418434, -0.03967694193124771, 0.0171346552670002, 0.0019676033407449722, -0.005376194603741169, -0.01433651801198721, -0.0018719740910455585, -0.05759759247303009, 0.03261348232626915, -0.01042227167636156, 0.03456274792551994, 0.009777757339179516, 0.0037596682086586952, 0.01598186418414116, 0.01860184222459793, 0.01737569272518158, -0.03810495510697365, -0.012345335446298122, -0.05671728029847145, -0.030328862369060516, -0.020247187465429306, 0.04435098543763161, -0.002297720406204462, 0.03303268179297447, -0.004639980848878622, -0.03732944279909134, 0.06828710436820984, -0.08668982237577438, 0.006350826006382704, -0.026325536891818047, -0.03596705570816994, -0.04741111770272255, 0.000013519495041691698, 0.025256585329771042, -0.053740985691547394, 0.017773929983377457, 0.023915156722068787, 0.038628950715065, 0.019492635503411293, -0.016977455466985703, 0.0564657598733902, 0.01761673018336296, 0.0050722770392894745, 0.04300955682992935, 0.03437411040067673, -0.0013440486509352922, 0.03567361831665039, -0.03812591731548309, 0.01074190903455019, -0.04225500300526619, 0.044141385704278946, 0.00663378369063139, 0.01016551349312067, 0.023663640022277832, 0.06371785700321198, -0.001763245090842247, -0.009358560666441917, -0.048207592219114304, -0.03326323628425598, 0.05621424317359924, 0.013319967314600945, 0.06346634030342102, 0.0035291099920868874, 0.01625434309244156, 0.03229908645153046, 0.01216717716306448, -0.04388986900448799, -0.026996251195669174, -0.007938533090054989, 0.019230637699365616, -0.021389499306678772, 0.031376853585243225, -0.010076434351503849, -0.011569822207093239, 0.029993506148457527, -0.010092154145240784, -0.025780580937862396, -0.035107702016830444, -0.07478464394807816, 0.0526091530919075, 0.046446967869997025, 0.0356316976249218, 0.06828710436820984, -0.05114196613430977, -0.01118206512182951, -0.00549671333283186, 0.0022322211880236864, 0.032529644668102264, -0.021882055327296257, 0.011161105707287788, -0.021567657589912415, -0.04938134178519249, 0.05709455534815788, 0.015091071836650372, -0.007702734787017107, 0.026241697371006012, 0.0008089181501418352, 0.02175629511475563, 0.012691172771155834, -0.029951585456728935, 0.006434665527194738, -0.025990178808569908, -0.07444928586483002, 0.010920067317783833, -0.05307026952505112, 0.00421816436573863, -0.011161105707287788, -0.05432786047458649, 0.00194271351210773, -0.01619146205484867, 0.056759197264909744, 0.002619977807626128, 0.05868750065565109, 0.010836227796971798, -0.04229691997170448, 0.09750509262084961, -0.03997037932276726, -0.020865503698587418, -0.00970439799129963, -0.0061569479294121265, 0.01754337176680565, -0.030328862369060516, 0.001609976403415203, -0.028086161240935326, -0.013435246422886848, -0.0011141455033794045, -0.03657488897442818, -0.07859933376312256, 0.043931785970926285, -0.02311868406832218, 0.03250868618488312, 0.028735917061567307, -0.024460112676024437, -0.02056158520281315, 0.01257589366286993, -0.057178396731615067, 0.014043080620467663, -0.04938134178519249, -0.009762037545442581, 0.056759197264909744, -0.014399398118257523, -0.060490045696496964, -0.061579957604408264, -0.012617813423275948, -0.07327553629875183, 0.03829359635710716, 0.012041417881846428, 0.023852277547121048, 0.01693553663790226, -0.029721027240157127, 0.020414866507053375, 0.0024667091201990843, 0.00590542983263731, 0.03309556096792221, 0.006135988049209118, -0.02657705545425415, -0.01581418514251709, 0.04921366274356842, 0.030727099627256393, -0.053740985691547394, 0.022217411547899246, 0.024627791717648506, 0.021882055327296257, -0.06237643212080002, 0.05336370691657066, 0.02663993462920189, -0.03814687579870224, 0.014776675030589104, -0.08434232324361801, -0.03320035710930824, -0.03552689775824547, -0.0019911830313503742, -0.015206350944936275, -0.017417611554265022, 0.021777255460619926, -0.007294018287211657, -0.0050486973486840725, 0.013581965118646622, 0.017910167574882507, 0.020488226786255836, 0.017637690529227257, -0.016820257529616356, -0.037119846791028976, 0.06790982186794281, 0.01632770150899887, 0.028568238019943237, -0.016684018075466156, -0.0019898731261491776, 0.02213357202708721, 0.004273183643817902, -0.004506361670792103, 0.0542440190911293, 0.027876563370227814, 0.021630536764860153, 0.035002902150154114, -0.06728103011846542, 0.0005934249493293464, 0.033179398626089096, -0.05218995735049248, -0.058939021080732346, 0.0020972921047359705, -0.008462528698146343, -0.046782322227954865, -0.058058708906173706, 0.008321049623191357, 0.04215020313858986, 0.005805870983749628, 0.0030339343938976526, 0.07218562811613083, 0.03265540301799774, 0.009358560666441917, -0.02504698745906353, 0.03462562710046768, -0.017323292791843414, -0.012209096923470497, -0.007823253981769085, 0.011768939904868603, -0.026996251195669174, 0.050890449434518814, -0.028903594240546227, 0.06610728055238724, 0.0029631948564201593, -0.01778440922498703, 0.009599599055945873, -0.00953671894967556, 0.017501451075077057, 0.004634740762412548, -0.08128219097852707, 0.06547848135232925, -0.009023203514516354, -0.04309339448809624, -0.008855524472892284, -0.03198469057679176, 0.03739232197403908, -0.03408066928386688, 0.013319967314600945, -0.03429026901721954, 0.005169216077774763, -0.037539042532444, 0.0033666715025901794, 0.016987936571240425, -0.04168908670544624, 0.04757879674434662, -0.015311149880290031, -0.004886258393526077, 0.004100265447050333, -0.05600464344024658, 0.0320475697517395, -0.043051473796367645, 0.01578274555504322, 0.054285939782857895, 0.01679929718375206, -0.02888263575732708, 0.029008394107222557, 0.05382482334971428, -0.07193411141633987, -0.028840715065598488, -0.018276965245604515, 0.04158428683876991, 0.07709022611379623, 0.006099308375269175, 0.07323361933231354, -0.005622472148388624, -0.028149042278528214, -0.0361766517162323, -0.011077266186475754, 0.0032828322146087885, 0.02959526889026165, 0.01826648600399494, -0.04290475696325302, -0.06032237038016319, -0.009940195828676224, 0.006659983657300472, 0.028128081932663918, -0.0364491306245327, 0.024963147938251495, 0.011276384815573692, 0.03571553900837898, 0.06786790490150452, 0.0146613959223032, 0.042778998613357544, -0.02613689750432968, 0.026220737025141716, 0.020247187465429306, 0.0197231937199831, -0.027436407282948494, -0.04177292436361313, -0.05550161004066467, -0.03085285797715187, -0.007288778200745583, -0.017595771700143814, -0.02128469944000244, 0.049465179443359375, 0.03299076110124588, 0.014137400314211845, 0.04171004518866539 ]
30,844
networkx.drawing.layout
kamada_kawai_layout
Position nodes using Kamada-Kawai path-length cost-function. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. dist : dict (default=None) A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length(). pos : dict or None optional (default=None) Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout() for dim >= 2 and a linear layout for dim == 1. weight : string or None optional (default='weight') The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1. scale : number (default: 1) Scale factor for positions. center : array-like or None Coordinate pair around which to center the layout. dim : int Dimension of layout. Returns ------- pos : dict A dictionary of positions keyed by node Examples -------- >>> G = nx.path_graph(4) >>> pos = nx.kamada_kawai_layout(G)
def kamada_kawai_layout( G, dist=None, pos=None, weight="weight", scale=1, center=None, dim=2 ): """Position nodes using Kamada-Kawai path-length cost-function. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. dist : dict (default=None) A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length(). pos : dict or None optional (default=None) Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout() for dim >= 2 and a linear layout for dim == 1. weight : string or None optional (default='weight') The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1. scale : number (default: 1) Scale factor for positions. center : array-like or None Coordinate pair around which to center the layout. dim : int Dimension of layout. Returns ------- pos : dict A dictionary of positions keyed by node Examples -------- >>> G = nx.path_graph(4) >>> pos = nx.kamada_kawai_layout(G) """ import numpy as np G, center = _process_params(G, center, dim) nNodes = len(G) if nNodes == 0: return {} if dist is None: dist = dict(nx.shortest_path_length(G, weight=weight)) dist_mtx = 1e6 * np.ones((nNodes, nNodes)) for row, nr in enumerate(G): if nr not in dist: continue rdist = dist[nr] for col, nc in enumerate(G): if nc not in rdist: continue dist_mtx[row][col] = rdist[nc] if pos is None: if dim >= 3: pos = random_layout(G, dim=dim) elif dim == 2: pos = circular_layout(G, dim=dim) else: pos = dict(zip(G, np.linspace(0, 1, len(G)))) pos_arr = np.array([pos[n] for n in G]) pos = _kamada_kawai_solve(dist_mtx, pos_arr, dim) pos = rescale_layout(pos, scale=scale) + center return dict(zip(G, pos))
(G, dist=None, pos=None, weight='weight', scale=1, center=None, dim=2)
[ 0.07804381102323532, 0.021608516573905945, -0.0063469368033111095, -0.03611063212156296, -0.018679160624742508, 0.018317513167858124, -0.027702298015356064, 0.014691983349621296, 0.02361566759645939, -0.008810669183731079, -0.013805943541228771, -0.017033658921718597, 0.048858754336833954, 0.03721366077661514, -0.031047550961375237, -0.0020760903134942055, 0.031770847737789154, -0.017250647768378258, -0.04911191016435623, -0.0015709120780229568, 0.01693420484662056, -0.06961739808320999, 0.058550942689180374, 0.008647927083075047, -0.02556857094168663, -0.030703984200954437, 0.012702914886176586, 0.025369664654135704, 0.0625290796160698, -0.017404349520802498, 0.05992520973086357, -0.011346731334924698, -0.009018616750836372, 0.04632721096277237, -0.004904862027615309, 0.031300704926252365, 0.0341758131980896, -0.025948302820324898, -0.0053252787329256535, -0.049907535314559937, 0.05779147893190384, -0.008634365163743496, -0.007535857148468494, -0.052619900554418564, 0.05891259014606476, 0.06574775278568268, -0.0032231949735432863, -0.003205112647265196, -0.011780709959566593, 0.0003441314329393208, 0.026418445631861687, -0.054572805762290955, -0.0037114208098500967, -0.02638228051364422, -0.004678831435739994, 0.015080755576491356, 0.015469527803361416, 0.03509801626205444, 0.026020631194114685, -0.08440883457660675, 0.039202731102705, 0.02081288956105709, 0.05139029771089554, -0.00043539126636460423, -0.08477047830820084, -0.021120291203260422, 0.014908972196280956, -0.04701434448361397, 0.008204907178878784, -0.026273787021636963, 0.01829943060874939, 0.02829901874065399, 0.004387252032756805, -0.02799161709845066, 0.014827601611614227, 0.028371348977088928, -0.005189660470932722, -0.019872602075338364, -0.0009001665166579187, 0.024320881813764572, -0.04184276610612869, -0.024809109047055244, 0.01092179398983717, -0.011690298095345497, 0.0632162094116211, 0.0024004438892006874, 0.04538692533969879, 0.06827929615974426, 0.04234907403588295, -0.04401266202330589, 0.0025925699155777693, -0.01929396390914917, 0.044446639716625214, -0.03413964807987213, 0.02802778221666813, 0.03992602974176407, 0.0370328389108181, -0.055693916976451874, 0.016852835193276405, 0.013055521994829178, 0.03884108364582062, 0.026165291666984558, -0.008458061143755913, -0.01280236802995205, -0.03432047367095947, -0.040902480483055115, -0.05034151300787926, 0.020433157682418823, -0.007418321445584297, 0.00123864714987576, 0.006292689125984907, 0.018968479707837105, 0.04318086802959442, 0.0063921427354216576, 0.04502527788281441, 0.007617228198796511, 0.055042948573827744, 0.03001685068011284, -0.02967328578233719, 0.0020546172745525837, -0.05815313011407852, 0.0020241031888872385, -0.024953767657279968, -0.04943739250302315, 0.020487405359745026, -0.01565939374268055, 0.002988123334944248, -0.0009781470289453864, 0.014312251470983028, -0.0043601286597549915, 0.029058482497930527, -0.02388690412044525, 0.029004234820604324, 0.029492460191249847, -0.014981302432715893, -0.019583282992243767, -0.011798792518675327, 0.01718735881149769, 0.02168084681034088, 0.029492460191249847, 0.03401307016611099, -0.03668927028775215, -0.029383966699242592, 0.0011617968557402492, -0.014411705546081066, -0.019908767193555832, 0.03093905560672283, -0.04455513507127762, 0.0013810463715344667, -0.006414745934307575, 0.03880491852760315, -0.04694201424717903, 0.10907328128814697, 0.03728599101305008, 0.006012411322444677, -0.04191509634256363, 0.004448280204087496, -0.015478569082915783, 0.00938478671014309, -0.011599885299801826, -0.019926849752664566, -0.05030534788966179, 0.029166975989937782, 0.004240332171320915, -0.039564378559589386, -0.013064563274383545, 0.027322567999362946, 0.04867792874574661, -0.004950067959725857, -0.012775244191288948, -0.04875025898218155, -0.01161796785891056, -0.026490775868296623, -0.02967328578233719, 0.007956273853778839, -0.010243702679872513, -0.02336251363158226, -0.038009289652109146, 0.027412978932261467, -0.07012370228767395, -0.02998068556189537, 0.011373855173587799, 0.03262072429060936, 0.04538692533969879, -0.019474787637591362, 0.04502527788281441, 0.018435047939419746, 0.02202441170811653, -0.031987838447093964, 0.007657913491129875, -0.04097481071949005, -0.005311716813594103, -0.019926849752664566, 0.05681502819061279, -0.0010804258054122329, 0.0704130232334137, 0.02911273017525673, -0.017313936725258827, -0.05739366635680199, 0.06940040737390518, 0.071100153028965, 0.006568446755409241, 0.0011069844476878643, 0.044446639716625214, 0.04231291264295578, 0.02699708379805088, -0.011934410780668259, 0.00877450406551361, -0.031427282840013504, -0.021518103778362274, -0.040251512080430984, 0.009475198574364185, 0.007264620624482632, -0.022386061027646065, 0.005799942649900913, -0.010071919299662113, -0.010288909077644348, 0.07789915055036545, -0.002232051221653819, -0.050160691142082214, -0.025026097893714905, 0.026056796312332153, -0.011699339374899864, -0.008304361253976822, 0.03374183550477028, -0.03222290799021721, 0.047954633831977844, -0.013082645833492279, 0.021970165893435478, -0.027666134759783745, 0.04426581412553787, -0.07171496003866196, 0.04585706815123558, -0.02808202989399433, 0.050775494426488876, -0.05627255514264107, -0.016048166900873184, 0.00777544965967536, 0.006695023737847805, 0.043542515486478806, -0.0024094851687550545, -0.03374183550477028, -0.03585748001933098, -0.009285333566367626, -0.04064932465553284, 0.01263058464974165, 0.008950808085501194, -0.051281802356243134, 0.019673695787787437, -0.0034560065250843763, -0.06994287669658661, -0.02137344516813755, 0.015478569082915783, 0.011084536090493202, 0.0040888916701078415, 0.012422637082636356, -0.05431964993476868, 0.03119220957159996, -0.009181358851492405, -0.013534707017242908, -0.042927712202072144, -0.03410348296165466, -0.08556611090898514, 0.016699133440852165, 0.05782764405012131, 0.07099166512489319, 0.01985451951622963, 0.019709860906004906, -0.03724982589483261, -0.007666954770684242, 0.024682531133294106, 0.05826162174344063, 0.010243702679872513, -0.0013934781309217215, 0.06932807713747025, 0.023760326206684113, 0.005162536632269621, 0.023254018276929855, 0.0006046316120773554, -0.0006662249215878546, -0.04365101084113121, -0.04151728376746178, -0.026671599596738815, 0.011862080544233322, -0.04625488445162773, 0.0605761744081974, -0.0027055852115154266, 0.013399088755249977, 0.07500596344470978, 0.00806476827710867, 0.038479432463645935, -0.02150002121925354, -0.05670653283596039, 0.00023690822126809508, 0.042457569390535355, 0.037575311958789825, -0.04383183643221855, 0.036146797239780426, -0.012205647304654121, -0.011193030513823032, 0.04802696034312248, -0.06180578097701073, 0.05023302137851715, 0.00969218835234642, 0.07471664249897003, 0.09894711524248123, 0.028280936181545258, 0.005759257357567549, 0.008720257319509983, 0.022169072180986404, -0.04119179770350456, -0.01724160648882389, -0.009637940675020218, -0.0015765627613291144, -0.04936506226658821, -0.022693462669849396, 0.024555955082178116, -0.008887519128620625, 0.054789796471595764, 0.03327168896794319, -0.01705174148082733, 0.027521474286913872, -0.07428266853094101, 0.012928945012390614, -0.0032525788992643356, 0.008882998488843441, 0.03437471762299538, 0.027412978932261467, 0.06133563816547394, 0.007947232574224472, -0.0033633338753134012, 0.02898615226149559, -0.024320881813764572, -0.024103892967104912, -0.07048535346984863, -0.004617803264409304, 0.018344635143876076, 0.018163811415433884, -0.0676644891500473, -0.05865943804383278, 0.03996219485998154, -0.03819011524319649, -0.020559735596179962, -0.0026016111951321363, 0.08144330978393555, 0.00997246615588665, -0.012531131505966187, -0.014239922165870667, -0.03764764219522476, -0.0021088647190481424, 0.012250853702425957, 0.06354169547557831, -0.0249176025390625, -0.01889614947140217, 0.05088398605585098, 0.009818765334784985, 0.05818929523229599, -0.062312088906764984, -0.01895039714872837, 0.062275923788547516, 0.03213249519467354, -0.02262113243341446, -0.013118810951709747, -0.026707764714956284, -0.02414005808532238, 0.018570667132735252, -0.03149961307644844, -0.01621994934976101, 0.10234661400318146, -0.0006419266574084759, 0.04502527788281441, -0.05750216171145439, -0.0876636728644371, 0.044121153652668, -0.014610611833631992, 0.08860395848751068, 0.00694365706294775, 0.021952083334326744, -0.06390334665775299, -0.024320881813764572, 0.043289363384246826, -0.022512638941407204, 0.04520609974861145, 0.047050509601831436, 0.04408498853445053, -0.05272839590907097, 0.07370402663946152, 0.012142359279096127, -0.05356018990278244, -0.037105169147253036, -0.060286857187747955, -0.02802778221666813, 0.08592775464057922, 0.019655613228678703, 0.012277977541089058, 0.06585624814033508, -0.028787245973944664, 0.011364813894033432, -0.06715818494558334, -0.005307196173816919, 0.019239716231822968, -0.08694037050008774, 0.019312046468257904, -0.017964905127882957, -0.0012013521045446396, -0.029872192069888115, -0.0008453541086055338, 0.007124481722712517, 0.012540172785520554, 0.10531213134527206, 0.013073604553937912, 0.034410882741212845, 0.0031237415969371796, -0.007630790118128061, 0.024085810407996178, -0.030053015798330307, -0.028226690366864204, 0.07558459788560867, 0.031770847737789154, -0.03775613754987717, -0.009845889173448086, -0.04715900495648384, 0.054825957864522934, -0.03392265737056732, 0.0526922307908535, -0.013706489466130733, -0.017467638477683067, -0.014194715768098831, -0.02907656505703926, 0.024067727848887444, -0.007165167015045881, 0.016789546236395836, 0.04151728376746178, 0.035188429057598114, -0.01898656226694584, 0.017702709883451462, 0.03404923528432846, -0.0026106522418558598, 0.022657297551631927, -0.024754861369729042, 0.04115563631057739, -0.0008950807969085872, 0.01929396390914917, 0.012467842549085617, -0.023000864312052727, -0.005465417634695768, -0.004656228236854076, -0.03970903903245926, 0.03819011524319649, 0.0054835001938045025, 0.03135495260357857, 0.0031802491284906864, 0.028606420382857323, 0.04607405886054039, -0.04451896995306015, 0.001356183085590601, -0.020776724442839622, -0.031553857028484344, -0.105384461581707, 0.017350101843476295, 0.025839807465672493, -0.018679160624742508, -0.02093946561217308, 0.03054124116897583, 0.035839397460222244, -0.00026233665994368494, -0.004692393355071545, -0.0028434637933969498, -0.0249176025390625, -0.05305388197302818, -0.005447335075587034, -0.04694201424717903, -0.05710434541106224, -0.02041507512331009, 0.012784285470843315, -0.04401266202330589, -0.027666134759783745, -0.02509842813014984, -0.07117248326539993, 0.024935685098171234, -0.004323963541537523, -0.03410348296165466, 0.04802696034312248, 0.029564790427684784, 0.0003161601780448109, -0.006355977617204189, 0.040685489773750305, -0.03775613754987717, -0.0477738082408905, -0.021174537017941475, -0.030920973047614098, -0.026183374226093292, 0.039347391575574875, 0.006288168486207724, 0.03318127989768982, 0.01574980653822422, 0.0031915507279336452, -0.07283607125282288, -0.060503844171762466, -0.04368717595934868, -0.01131056621670723, 0.006518719717860222, 0.007789011113345623, 0.007165167015045881, 0.023507172241806984, -0.048569437116384506, 0.049835205078125, 0.03837093710899353, 0.04878642410039902, 0.06585624814033508, -0.03084864281117916, -0.006360498256981373, 0.038045454770326614, -0.0037023797631263733, 0.0013177578803151846, 0.05428348481655121, -0.053234703838825226, 0.021264949813485146, 0.03178893029689789, -0.05905725061893463, 0.017946822568774223, 0.008882998488843441, 0.014004849828779697, 0.04148111864924431, -0.06636255979537964, 0.07471664249897003, 0.10661406815052032, -0.020957548171281815, -0.0115727623924613, -0.010316031984984875, -0.03222290799021721, 0.0017788601107895374, 0.007400238886475563, 0.0833238884806633, -0.016545433551073074, 0.03075823187828064, -0.009190400131046772, -0.01600296050310135, -0.09345005452632904, -0.023597585037350655, 0.013037439435720444, 0.011328648775815964, -0.042855385690927505, -0.07081083953380585, 0.06958123296499252, 0.03222290799021721, 0.029094647616147995, -0.022386061027646065, -0.05160728469491005, -0.05265606567263603, -0.026617351919412613, 0.013760737143456936, -0.019022727385163307, 0.022042494267225266, 0.06813463568687439, 0.03681584820151329, -0.01500842534005642, -0.02262113243341446, 0.05580241233110428, 0.01650022715330124, -0.03855176270008087, -0.04979903995990753, -0.05793613940477371, -0.04379567131400108, 0.00685776537284255, -0.018914232030510902, -0.0192577987909317, -0.03775613754987717, -0.014221839606761932, 0.0648074671626091, -0.017919698730111122, -0.03041466511785984, 0.06513295322656631, -0.03876875340938568, -0.016201866790652275, -0.0491480715572834, -0.029492460191249847, 0.017006535083055496, 0.027629969641566277, -0.039202731102705, 0.022114824503660202, 0.014664859510958195, 0.0051399338990449905, 0.09894711524248123, 0.0012103933840990067, 0.06144413352012634, -0.017350101843476295, 0.008788065984845161, -0.026942836120724678, -0.0012171742273494601, -0.00598076730966568, -0.030920973047614098, 0.04592939838767052, 0.021554268896579742, -0.02366991527378559, -0.03941972181200981, 0.03444704785943031, 0.025586653500795364, 0.0390942357480526, 0.006889409851282835, -0.061263307929039, -0.010759051889181137, -0.011057412251830101, -0.008381211198866367, 0.03632762283086777, 0.04187893122434616, 0.024845274165272713, 0.02032466232776642, 0.01873340830206871, -0.04719517007470131, 0.006098303012549877, -0.030613571405410767, 0.016418855637311935, -0.0281181950122118, -0.050124526023864746, -0.05464513599872589, 0.037141334265470505, -0.008643406443297863, -0.032168660312891006, -0.018624912947416306, -0.012196606025099754, -0.011889204382896423, 0.014375540427863598, -0.04426581412553787, 0.012666749767959118, 0.05887642502784729, 0.011518514715135098, -0.016346525400877, -0.014710064977407455, 0.02699708379805088, 0.001955163897946477, -0.003001685021445155, -0.026508858427405357, 0.0019359512953087687, -0.011988658457994461, -0.057646822184324265, 0.006866806652396917, -0.05142645910382271, 0.03967287391424179, 0.026291867718100548, -0.020360827445983887, 0.000864566711243242, -0.02582172490656376, 0.01643693819642067, 0.016988452523946762, -0.06647104769945145, 0.0597805492579937, -0.03448321297764778, -0.05681502819061279, -0.00036899480619467795, 0.012377430684864521, -0.036146797239780426, -0.03611063212156296, -0.03265688940882683, 0.020867137238383293, 0.03663502633571625, 0.01665392704308033, -0.012232771143317223, -0.017576131969690323, -0.06513295322656631, -0.013634160161018372, 0.04545925557613373, -0.05196893587708473, 0.024121975526213646, 0.017359143123030663, 0.00655488483607769, -0.013028398156166077, -0.0006328854360617697, 0.044410474598407745, -0.05533226951956749, -0.019095057621598244, 0.013182098977267742, 0.004301360342651606, -0.023687997832894325, -0.030251922085881233, 0.024628283455967903, 0.04614638909697533, 0.0377199724316597, 0.003727243049070239, -0.023037029430270195, 0.055223774164915085, 0.04961821809411049, 0.0033158676233142614, -0.007305305916815996, -0.040251512080430984, 0.0469781793653965, 0.012793326750397682, -0.06064850464463234, 0.03144536539912224, -0.02019808627665043, 0.027756545692682266, -0.01075001060962677, 0.051498789340257645, 0.02189783565700054, 0.019583282992243767, -0.015089796856045723, -0.0202884990721941, 0.02016192115843296, 0.009547528810799122, -0.019366294145584106, 0.029130810871720314, -0.015370074659585953, -0.029745614156126976, 0.015587063506245613, -0.043325528502464294, -0.03374183550477028, -0.06563925743103027, 0.03001685068011284, -0.021319197490811348, 0.07055768370628357, -0.01584021747112274, -0.02786504104733467, 0.0055196648463606834, -0.060973990708589554, 0.0029203142039477825, 0.009574652649462223, -0.011988658457994461, -0.04093864560127258, -0.035369254648685455, -0.004093412309885025, -0.02482719160616398, -0.03963670879602432, -0.005668845027685165, -0.002703324891626835, -0.051679614931344986, -0.030125346034765244, 0.003736284328624606, -0.07374019175767899, 0.007228455506265163, 0.00949328113347292, -0.03884108364582062, 0.04900341480970383, -0.03243989869952202, 0.01621994934976101, -0.026671599596738815, 0.01568651758134365, -0.02820860780775547, -0.0019811573438346386, -0.017422432079911232, 0.07833313196897507, -0.008439979515969753, 0.03728599101305008, -0.04039617255330086, -0.022548804059624672, 0.051715780049562454, -0.052800726145505905, -0.026743929833173752, 0.03837093710899353, 0.0007543768151663244, 0.028190525248646736, 0.02638228051364422, 0.016021043062210083, 0.026273787021636963, 0.007535857148468494, 0.01584021747112274, -0.024194305762648582, -0.007996959611773491, -0.009809724055230618, 0.026328032836318016, -0.0562363900244236, -0.07992438971996307, -0.07023219764232635, -0.02730448544025421, 0.04307237267494202, -0.026201456785202026, -0.04191509634256363, 0.005252948962152004, 0.06813463568687439 ]
30,849
networkx.algorithms.distance_measures
kemeny_constant
Returns the Kemeny constant of the given graph. The *Kemeny constant* (or Kemeny's constant) of a graph `G` can be computed by regarding the graph as a Markov chain. The Kemeny constant is then the expected number of time steps to transition from a starting state i to a random destination state sampled from the Markov chain's stationary distribution. The Kemeny constant is independent of the chosen initial state [1]_. The Kemeny constant measures the time needed for spreading across a graph. Low values indicate a closely connected graph whereas high values indicate a spread-out graph. If weight is not provided, then a weight of 1 is used for all edges. Since `G` represents a Markov chain, the weights must be positive. Parameters ---------- G : NetworkX graph weight : string or None, optional (default=None) The edge data key used to compute the Kemeny constant. If None, then each edge has weight 1. Returns ------- float The Kemeny constant of the graph `G`. Raises ------ NetworkXNotImplemented If the graph `G` is directed. NetworkXError If the graph `G` is not connected, or contains no nodes, or has edges with negative weights. Examples -------- >>> G = nx.complete_graph(5) >>> round(nx.kemeny_constant(G), 10) 3.2 Notes ----- The implementation is based on equation (3.3) in [2]_. Self-loops are allowed and indicate a Markov chain where the state can remain the same. Multi-edges are contracted in one edge with weight equal to the sum of the weights. References ---------- .. [1] Wikipedia "Kemeny's constant." https://en.wikipedia.org/wiki/Kemeny%27s_constant .. [2] Lovász L. Random walks on graphs: A survey. Paul Erdös is Eighty, vol. 2, Bolyai Society, Mathematical Studies, Keszthely, Hungary (1993), pp. 1-46
def effective_graph_resistance(G, weight=None, invert_weight=True): """Returns the Effective graph resistance of G. Also known as the Kirchhoff index. The effective graph resistance is defined as the sum of the resistance distance of every node pair in G [1]_. If weight is not provided, then a weight of 1 is used for all edges. The effective graph resistance of a disconnected graph is infinite. Parameters ---------- G : NetworkX graph A graph weight : string or None, optional (default=None) The edge data key used to compute the effective graph resistance. If None, then each edge has weight 1. invert_weight : boolean (default=True) Proper calculation of resistance distance requires building the Laplacian matrix with the reciprocal of the weight. Not required if the weight is already inverted. Weight cannot be zero. Returns ------- RG : float The effective graph resistance of `G`. Raises ------ NetworkXNotImplemented If `G` is a directed graph. NetworkXError If `G` does not contain any nodes. Examples -------- >>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)]) >>> round(nx.effective_graph_resistance(G), 10) 10.25 Notes ----- The implementation is based on Theorem 2.2 in [2]_. Self-loops are ignored. Multi-edges are contracted in one edge with weight equal to the harmonic sum of the weights. References ---------- .. [1] Wolfram "Kirchhoff Index." https://mathworld.wolfram.com/KirchhoffIndex.html .. [2] W. Ellens, F. M. Spieksma, P. Van Mieghem, A. Jamakovic, R. E. Kooij. Effective graph resistance. Lin. Alg. Appl. 435:2491-2506, 2011. """ import numpy as np if len(G) == 0: raise nx.NetworkXError("Graph G must contain at least one node.") # Disconnected graphs have infinite Effective graph resistance if not nx.is_connected(G): return float("inf") # Invert weights G = G.copy() if invert_weight and weight is not None: if G.is_multigraph(): for u, v, k, d in G.edges(keys=True, data=True): d[weight] = 1 / d[weight] else: for u, v, d in G.edges(data=True): d[weight] = 1 / d[weight] # Get Laplacian eigenvalues mu = np.sort(nx.laplacian_spectrum(G, weight=weight)) # Compute Effective graph resistance based on spectrum of the Laplacian # Self-loops are ignored return float(np.sum(1 / mu[1:]) * G.number_of_nodes())
(G, *, weight=None, backend=None, **backend_kwargs)
[ 0.05050341412425041, -0.01460190862417221, 0.002688575303182006, 0.05920565873384476, 0.05627957731485367, -0.009362512268126011, -0.03188289329409599, -0.049477383494377136, 0.10077881813049316, -0.008711744099855423, 0.03178789094090462, -0.00025027262745425105, 0.015181425027549267, -0.0045506274327635765, -0.0597376711666584, 0.04510726407170296, -0.057001594454050064, 0.0002977739495690912, -0.005847413558512926, 0.046361297369003296, 0.0052963984198868275, -0.10412291437387466, -0.003640976967290044, 0.060573697090148926, -0.027987783774733543, 0.007414957508444786, 0.020349569618701935, 0.013442876748740673, -0.0035554745700210333, 0.0004773883556481451, -0.006654936354607344, -0.05027540773153305, -0.02329465188086033, -0.006521932780742645, 0.022876640781760216, 0.023807667195796967, 0.007091948762536049, 0.007742716930806637, -0.09257058799266815, -0.05354350060224533, -0.011514321900904179, 0.033858947455883026, 0.03212989866733551, -0.02663874626159668, 0.03323192894458771, 0.017765497788786888, -0.003809606656432152, 0.018905529752373695, -0.030400851741433144, -0.03906509280204773, 0.025840723887085915, -0.010934806428849697, -0.046209294348955154, 0.009115505032241344, 0.0019618049263954163, 0.03342193737626076, 0.02604972943663597, 0.054113514721393585, 0.029184816405177116, -0.07300004363059998, 0.011105811223387718, -0.08056225627660751, 0.027702774852514267, 0.01686297170817852, -0.06129571422934532, 0.014962919056415558, -0.019684551283717155, -0.00551015418022871, 0.008022974245250225, 0.01382288709282875, -0.029108814895153046, -0.0022598758805543184, 0.02608773112297058, -0.06821191310882568, 0.018744025379419327, 0.026429740712046623, 0.023883668705821037, -0.013243370689451694, -0.026885753497481346, -0.0140983946621418, 0.03176888823509216, -0.01316736824810505, 0.046323295682668686, -0.03650002181529999, 0.025441711768507957, -0.0372980460524559, 0.01105831004679203, -0.01658746413886547, 0.0259737279266119, -0.031521882861852646, -0.006773689761757851, 0.026030728593468666, 0.03380194678902626, 0.037450049072504044, 0.07322805374860764, 0.0010616547660902143, -0.04989539831876755, -0.07349405437707901, 0.07071997970342636, -0.022059617564082146, -0.013347873464226723, 0.08641441911458969, -0.018098006024956703, 0.005229896400123835, 0.028690803796052933, -0.046057287603616714, -0.01536193024367094, -0.03435296192765236, 0.05358149856328964, -0.03119887411594391, -0.05631757527589798, 0.021717607975006104, 0.016596965491771698, -0.013699383474886417, -0.03613901138305664, 0.04514526203274727, -0.016872473061084747, 0.01526692695915699, 0.0593576617538929, 0.027664775028824806, 0.013148368336260319, 0.03220590204000473, -0.017698995769023895, -0.0010082157095894217, 0.010744800791144371, 0.021755609661340714, 0.009562017396092415, 0.0013478501932695508, -0.011875332333147526, 0.022021615877747536, 0.049249377101659775, 0.00007481459761038423, 0.025213705375790596, 0.04848935827612877, 0.02737976610660553, 0.009842275641858578, -0.007728466298431158, 0.037488050758838654, 0.06722388416528702, 0.020748581737279892, -0.010421792045235634, -0.02329465188086033, 0.023199649527668953, 0.051187433302402496, 0.03176888823509216, 0.008345983922481537, 0.017385486513376236, 0.03955910727381706, 0.039863117039203644, -0.0028168288990855217, 0.026239734143018723, -0.014012892730534077, 0.04389122873544693, -0.010982307605445385, 0.009671270847320557, 0.017280984669923782, -0.014345401898026466, 0.013860887847840786, -0.0404331311583519, -0.03480897471308708, -0.07429207861423492, -0.030704859644174576, 0.04016712307929993, -0.021793609485030174, 0.013860887847840786, -0.02726576291024685, 0.049515385180711746, 0.015599437057971954, -0.0649058148264885, 0.028253791853785515, -0.04510726407170296, -0.05164344608783722, -0.03399195149540901, -0.03872308507561684, 0.03045785240828991, 0.08542639017105103, 0.026619745418429375, -0.014620909467339516, 0.012160340324044228, 0.0235606599599123, -0.014962919056415558, -0.058711644262075424, -0.0018086131894961, -0.021508602425456047, 0.028918810188770294, 0.04503126069903374, 0.03461897000670433, -0.004811884835362434, 0.004662255756556988, 0.00047798213199712336, 0.008203479461371899, -0.041497163474559784, 0.02538471110165119, 0.0289378110319376, 0.02905181422829628, -0.014924918301403522, 0.03585400432348251, 0.018354514613747597, -0.034789975732564926, 0.07056797295808792, 0.029070813208818436, -0.0009963404154404998, 0.03735504671931267, 0.032034896314144135, 0.005581406410783529, 0.011305316351354122, -0.00924850907176733, -0.02901381254196167, -0.008236730471253395, 0.009984779171645641, -0.0667678713798523, 0.00509214261546731, 0.0056099072098731995, -0.03496097773313522, -0.024244679138064384, 0.02998283877968788, -0.02648674137890339, 0.008925500325858593, 0.01370888389647007, -0.06406979262828827, -0.05475953221321106, -0.010060781612992287, -0.009842275641858578, -0.013072365894913673, 0.044537246227264404, -0.049287378787994385, 0.022382626309990883, 0.000094705777883064, 0.01421239785850048, 0.007096698507666588, 0.0545315258204937, 0.0031350876670330763, 0.0790422111749649, -0.051263436675071716, 0.014316900633275509, -0.021128591150045395, -0.05981367453932762, 0.07250603288412094, 0.052441466599702835, 0.0411931537091732, -0.03570200130343437, -0.06281575560569763, -0.04282720014452934, 0.058901648968458176, -0.036310017108917236, -0.037013035267591476, 0.013851387426257133, 0.001788425026461482, 0.028519798070192337, 0.009001501835882664, -0.0879344642162323, -0.06794590502977371, -0.014050893485546112, -0.023199649527668953, 0.02760777249932289, -0.01100130844861269, -0.08519838750362396, 0.016558963805437088, -0.018098006024956703, -0.027322765439748764, 0.014535406604409218, -0.008360234089195728, -0.07227802276611328, -0.004586253315210342, -0.04829935356974602, 0.010089282877743244, 0.0004114802577532828, 0.010250787250697613, -0.025517715141177177, 0.05076942220330238, 0.04499325901269913, 0.010345789603888988, 0.013613881543278694, -0.00948126520961523, -0.004897387232631445, 0.02014056406915188, 0.02118559367954731, 0.044613249599933624, -0.005115893203765154, 0.036348018795251846, -0.08443836122751236, 0.0016031698323786259, -0.007661964278668165, 0.024472685530781746, -0.057001594454050064, 0.017394987866282463, -0.009239008650183678, -0.0563935786485672, 0.023161647841334343, -0.00903475284576416, 0.09249459207057953, 0.007742716930806637, 0.0035958506632596254, 0.003405845258384943, 0.07376006245613098, 0.01045979280024767, -0.013908389024436474, -0.04829935356974602, 0.016340456902980804, 0.06957995146512985, 0.043169207870960236, -0.024358682334423065, 0.004624254535883665, -0.049287378787994385, 0.055557556450366974, 0.04073714092373848, 0.03484697639942169, -0.0001445821690140292, 0.017261983826756477, 0.05783762037754059, -0.09614269435405731, 0.004944888409227133, -0.043093208223581314, 0.022800637409090996, -0.052555471658706665, -0.029659830033779144, 0.05004740133881569, -0.027284763753414154, 0.02010256238281727, 0.025631718337535858, 0.016074450686573982, 0.09705471992492676, 0.014440404251217842, 0.0387800857424736, -0.07117599248886108, -0.002365566324442625, 0.019912557676434517, 0.07820618897676468, 0.07942222058773041, -0.049439385533332825, -0.04282720014452934, 0.01838301494717598, -0.010288788005709648, 0.0047335075214505196, -0.041459161788225174, 0.04225718230009079, 0.10951906442642212, -0.033858947455883026, -0.027911782264709473, -0.029507827013731003, 0.027778778225183487, 0.004241868853569031, -0.005367650184780359, -0.0026671995874494314, -0.00512064341455698, 0.019333040341734886, 0.01705297827720642, -0.027398766949772835, -0.03480897471308708, -0.05308748781681061, -0.012882360257208347, 0.003909359220415354, -0.031958892941474915, 0.02682875096797943, -0.016767969354987144, 0.04556327685713768, -0.01172332838177681, -0.047995343804359436, 0.02196461521089077, 0.02375066466629505, -0.10359089821577072, 0.006384178530424833, -0.028633801266551018, -0.019418543204665184, -0.006906693335622549, 0.012122339569032192, -0.01643545925617218, 0.017204981297254562, 0.018259510397911072, -0.04096514731645584, -0.002365566324442625, -0.0820062980055809, -0.07737016677856445, 0.004840385634452105, 0.010915805585682392, 0.037564050406217575, -0.03399195149540901, -0.0211475919932127, -0.01573244109749794, -0.006379428785294294, 0.009144006296992302, 0.019333040341734886, -0.044499244540929794, 0.011153312399983406, 0.044765252619981766, -0.012720855884253979, 0.04894537106156349, 0.004039987921714783, 0.02422567829489708, -0.0032609663903713226, -0.04183917120099068, -0.027550771832466125, 0.06764189153909683, -0.010830303654074669, -0.04343521595001221, 0.03477097302675247, 0.061789728701114655, 0.02831079252064228, -0.04582928121089935, -0.01421239785850048, -0.046095289289951324, -0.007799718528985977, -0.02141360007226467, 0.008630991913378239, -0.02667674608528614, 0.015048420988023281, 0.0076667144894599915, 0.04351121932268143, 0.044651251286268234, 0.01441190391778946, -0.049591388553380966, 0.015675438567996025, 0.013509377837181091, 0.004265619441866875, -0.01970355212688446, -0.020121563225984573, -0.013138867914676666, 0.0023465657141059637, 0.03695603460073471, 0.029925838112831116, 0.02137559838593006, -0.029659830033779144, 0.07512810081243515, -0.005980417598038912, 0.022648634389042854, -0.04670330882072449, 0.00008602193702245131, -0.020026560872793198, -0.06646385788917542, 0.054075513035058975, -0.023826666176319122, 0.0016684841830283403, 0.018924530595541, -0.031293876469135284, 0.00020692766702268273, -0.002209999365732074, 0.018003003671765327, 0.01760399341583252, -0.02010256238281727, -0.03731704503297806, 0.04016712307929993, 0.01222684234380722, 0.027759777382016182, -0.04818534851074219, -0.003346468787640333, -0.06281575560569763, -0.006930443923920393, -0.000914400618057698, -0.005267897620797157, -0.03165488690137863, 0.0054911538027226925, -0.04434724152088165, 0.026695746928453445, 0.028804806992411613, -0.11704327911138535, 0.029184816405177116, -0.03714603930711746, -0.013993891887366772, -0.06809790432453156, 0.025593716651201248, 0.016216954216361046, 0.03157888352870941, -0.009096505120396614, -0.02998283877968788, -0.01958954893052578, -0.032927922904491425, 0.007818718440830708, -0.015570935793220997, -0.027170760557055473, -0.021166592836380005, 0.04902137070894241, -0.020159564912319183, -0.020007560029625893, -0.043245211243629456, 0.05650758370757103, 0.012549851089715958, -0.0912785530090332, -0.011875332333147526, 0.006227424368262291, -0.04419523850083351, -0.020083561539649963, 0.02017856575548649, 0.055633556097745895, 0.023902669548988342, 0.02088158391416073, -0.0393311008810997, -0.003954485524445772, -0.005776161793619394, 0.019855555146932602, -0.04187717288732529, -0.015570935793220997, 0.03165488690137863, 0.025631718337535858, 0.012074838392436504, 0.0006828316254541278, -0.004695506300777197, 0.01228384394198656, 0.0046266294084489346, 0.032775916159152985, 0.014383402653038502, -0.026410739868879318, -0.031445879489183426, -0.015371430665254593, 0.04848935827612877, 0.036937035620212555, 0.03165488690137863, -0.03860908001661301, 0.007714216131716967, 0.08960650861263275, 0.035340990871191025, -0.014050893485546112, 0.019143035635352135, 0.07414007931947708, 0.0475013293325901, 0.011846831999719143, -0.026239734143018723, -0.036519020795822144, 0.05434152111411095, 0.06524782627820969, -0.02846279740333557, -0.01884852722287178, 0.02422567829489708, 0.0005765474052168429, -0.0018810526235029101, -0.01678697019815445, 0.008992001414299011, -0.004419998731464148, -0.07748416811227798, -0.0021779360249638557, -0.015352429822087288, -0.014383402653038502, 0.019969558343291283, -0.019447043538093567, 0.0471213199198246, -0.00040999584598466754, -0.007799718528985977, -0.01864902302622795, -0.04202917590737343, -0.10222285985946655, -0.011846831999719143, -0.015494933351874352, 0.0030353348702192307, 0.014677911065518856, 0.011305316351354122, 0.08246231079101562, 0.020387571305036545, 0.0012374096550047398, 0.002453443594276905, -0.022496629506349564, -0.07071997970342636, -0.044841255992650986, 0.02831079252064228, -0.020824583247303963, -0.033858947455883026, 0.061941735446453094, 0.03680403158068657, -0.05016140267252922, 0.004477000329643488, 0.025422710925340652, -0.017632493749260902, -0.016596965491771698, -0.08732644468545914, -0.01810750737786293, -0.06292976438999176, 0.006445930339396, -0.04039512947201729, 0.032376907765865326, -0.024985698983073235, -0.04503126069903374, 0.033934950828552246, -0.03176888823509216, 0.03245290741324425, 0.07835819572210312, 0.004446124657988548, -0.0065314327366650105, -0.01331937313079834, 0.025289708748459816, -0.06315776705741882, 0.035150982439517975, -0.06353777647018433, -0.012711355462670326, -0.06106770783662796, 0.016368959099054337, 0.04123115539550781, 0.017157480120658875, 0.041649166494607925, -0.016767969354987144, 0.05346749722957611, -0.03855207934975624, -0.01460190862417221, -0.02433968149125576, -0.057343605905771255, 0.03828607127070427, 0.0035174735821783543, -0.0019499296322464943, -0.03349793702363968, -0.022059617564082146, 0.008003974333405495, 0.04598128795623779, 0.003222965169698, -0.05206145718693733, -0.009357761591672897, 0.01951354555785656, -0.006944694556295872, -0.0437772274017334, 0.049477383494377136, 0.005267897620797157, -0.07033997029066086, 0.036196012049913406, -0.05323949083685875, 0.0015497308922931552, -0.02430167980492115, -0.016188453882932663, -0.0006103920750319958, -0.0034319711849093437, 0.012720855884253979, -0.0022812513634562492, 0.016530463472008705, -0.04233318567276001, 0.01760399341583252, -0.004800009541213512, -0.004712131805717945, 0.03781105950474739, -0.032775916159152985, -0.018554018810391426, 0.057001594454050064, 0.040015120059251785, 0.005989917553961277, -0.03323192894458771, 0.04183917120099068, -0.00209362106397748, -0.04214318096637726, -0.009842275641858578, 0.04225718230009079, 0.0317118875682354, -0.07128999382257462, 0.04024312645196915, -0.01748999021947384, -0.020121563225984573, 0.041687168180942535, -0.03570200130343437, 0.07596412301063538, -0.057381607592105865, -0.0005976260872557759, -0.06391778588294983, 0.019304540008306503, 0.0489833727478981, -0.017157480120658875, -0.005168144591152668, -0.00566690880805254, -0.020026560872793198, 0.03184489160776138, 0.03344093635678291, -0.01790800131857395, -0.008554989472031593, 0.03594900667667389, 0.026524743065238, -0.024719692766666412, 0.009571517817676067, -0.05137743800878525, 0.0011893145274370909, 0.036272015422582626, 0.03332693129777908, 0.011761329136788845, 0.024016672745347023, 0.016986476257443428, 0.033079925924539566, -0.03625301644206047, -0.002664824714884162, -0.06247374787926674, -0.019760552793741226, -0.012293344363570213, 0.02293364144861698, 0.031293876469135284, -0.06874392181634903, 0.0230096448212862, -0.0032300904858857393, 0.03792506083846092, -0.0005946572637185454, -0.02088158391416073, 0.004719256889075041, 0.06726188212633133, -0.025536714121699333, -0.004386747721582651, 0.01751849055290222, -0.02133759669959545, -0.030704859644174576, -0.02103358879685402, 0.029260819777846336, -0.0048878868110477924, -0.03967311233282089, -0.04278919845819473, 0.020748581737279892, -0.0009155881125479937, 0.0578756220638752, -0.04016712307929993, -0.04985739663243294, 0.0482233501970768, 0.07030196487903595, -0.05924366042017937, 0.0790422111749649, 0.025422710925340652, -0.01662546582520008, 0.02675274945795536, -0.023959670215845108, -0.025802722200751305, -0.07611612975597382, -0.011248314753174782, -0.04560127481818199, 0.033972952514886856, -0.011998835951089859, -0.023997671902179718, 0.01838301494717598, -0.004146866034716368, 0.039939116686582565, 0.023845667019486427, -0.0036481020506471395, -0.030913865193724632, -0.04366322234272957, -0.006303426343947649, -0.018202509731054306, -0.00931026041507721, 0.012739856727421284, 0.030400851741433144, -0.032034896314144135, 0.012122339569032192, 0.07262003421783447, -0.044651251286268234, 0.006797440350055695, 0.047805339097976685, -0.02722776308655739, 0.004241868853569031, 0.015599437057971954, 0.03699403628706932, 0.022762637585401535, 0.020786581560969353, -0.0058426633477211, 0.02831079252064228, 0.03750704973936081, 0.05206145718693733, 0.02593572624027729, 0.041611164808273315, -0.04753933101892471, -0.03245290741324425, 0.0013027240056544542, -0.0070491973310709, -0.04020512476563454, 0.02329465188086033, 0.019295040518045425, -0.023028643801808357, 0.05080742388963699, -0.004740632604807615, 0.03169288858771324, -0.008863748051226139, 0.05760961398482323, -0.007851969450712204, -0.015665939077734947, -0.05175744742155075, -0.002624448388814926, -0.005343899596482515, -0.0039117345586419106, -0.06650186330080032, -0.05175744742155075, 0.014183897525072098, -0.02924181893467903, 0.008787745609879494, 0.006578934378921986, 0.05460752919316292 ]
30,851
networkx.generators.classic
kneser_graph
Returns the Kneser Graph with parameters `n` and `k`. The Kneser Graph has nodes that are k-tuples (subsets) of the integers between 0 and ``n-1``. Nodes are adjacent if their corresponding sets are disjoint. Parameters ---------- n: int Number of integers from which to make node subsets. Subsets are drawn from ``set(range(n))``. k: int Size of the subsets. Returns ------- G : NetworkX Graph Examples -------- >>> G = nx.kneser_graph(5, 2) >>> G.number_of_nodes() 10 >>> G.number_of_edges() 15 >>> nx.is_isomorphic(G, nx.petersen_graph()) True
def star_graph(n, create_using=None): """Return the star graph The star graph consists of one center node connected to n outer nodes. .. plot:: >>> nx.draw(nx.star_graph(6)) Parameters ---------- n : int or iterable If an integer, node labels are 0 to n with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Notes ----- The graph has n+1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)). """ n, nodes = n if isinstance(n, numbers.Integral): nodes.append(int(n)) # there should be n+1 nodes G = empty_graph(nodes, create_using) if G.is_directed(): raise NetworkXError("Directed Graph not supported") if len(nodes) > 1: hub, *spokes = nodes G.add_edges_from((hub, node) for node in spokes) return G
(n, k, *, backend=None, **backend_kwargs)
[ 0.022217122837901115, -0.006895122118294239, 0.021790895611047745, -0.05022383853793144, -0.012715795077383518, 0.06666912883520126, -0.047630954533815384, 0.007454546168446541, -0.0007092696614563465, 0.005079214461147785, 0.004164600279182196, 0.06254892796278, 0.016978072002530098, 0.07622373104095459, 0.026994425803422928, -0.007707618642598391, 0.01481141522526741, 0.011898858472704887, -0.022998539730906487, 0.03793426975607872, -0.01989062875509262, 0.015148845501244068, 0.03429357707500458, 0.013834643177688122, -0.02090292051434517, 0.012005415745079517, 0.022288160398602486, 0.032446589320898056, -0.03736596927046776, 0.02733185514807701, 0.03315696865320206, -0.012138611637055874, 0.0011665765196084976, 0.018345553427934647, 0.02067204751074314, 0.04230310767889023, -0.021524501964449883, 0.053065355867147446, -0.10456787794828415, -0.015672750771045685, 0.04631675034761429, -0.005865071900188923, 0.014775896444916725, -0.03297937288880348, 0.01212973240762949, 0.02841518446803093, 0.08339856564998627, 0.004519790410995483, -0.06876474618911743, -0.01759965531527996, 0.042764853686094284, 0.004255617968738079, -0.043262120336294174, -0.0583932027220726, -0.0018203477375209332, 0.010140668600797653, -0.00753002380952239, -0.012262928299605846, 0.05945877358317375, -0.039958853274583817, 0.03365423530340195, 0.03205588087439537, 0.006304618902504444, -0.02354908362030983, -0.05619102716445923, -0.02182641439139843, -0.03878672793507576, -0.06141231954097748, -0.014234231784939766, -0.018984895199537277, 0.05409540608525276, 0.04155720770359039, 0.03013785555958748, -0.009599004872143269, 0.012822352349758148, 0.02633732371032238, 0.03644247353076935, 0.011002004146575928, -0.010522497817873955, -0.009030700661242008, -0.022785427048802376, -0.03633591905236244, 0.0218974519520998, -0.048057179898023605, 0.04621019586920738, 0.09824550151824951, -0.019713034853339195, 0.021009476855397224, -0.044682879000902176, -0.02390427328646183, -0.024437058717012405, -0.027811361476778984, -0.026106450706720352, 0.005501002073287964, -0.012689155526459217, 0.015992421656847, 0.05025935918092728, -0.0925624668598175, 0.01237836480140686, -0.0009334832429885864, -0.037472523748874664, -0.03333456441760063, -0.08858434110879898, -0.0218974519520998, -0.056652773171663284, -0.031381018459796906, -0.02534279227256775, 0.05690140649676323, -0.01316866185516119, 0.02855726145207882, -0.019091451540589333, 0.017466459423303604, 0.06613634526729584, -0.013701447285711765, 0.029729386791586876, 0.042622778564691544, -0.018221236765384674, 0.03864465281367302, 0.0652838870882988, -0.022927502170205116, -0.05846424400806427, 0.04422113299369812, -0.04027852416038513, 0.029818184673786163, 0.02683459036052227, -0.00038293900433927774, 0.04457632079720497, -0.053136397153139114, 0.030173374339938164, 0.021062755957245827, -0.001531756017357111, 0.018984895199537277, -0.0009223835077136755, 0.06826747953891754, -0.03535914421081543, 0.01327521912753582, -0.07885213941335678, -0.028450703248381615, -0.0012476042611524463, -0.014296390116214752, 0.03386734798550606, -0.03413373976945877, 0.03878672793507576, 0.04958449676632881, -0.06066641956567764, 0.015441876836121082, 0.01868298463523388, 0.019162490963935852, 0.013292978517711163, -0.014465104788541794, 0.023744437843561172, 0.0020645407494157553, 0.09533294290304184, 0.030688399448990822, -0.022128324955701828, -0.018434351310133934, 0.027100982144474983, -0.02232367917895317, -0.012147491797804832, 0.029818184673786163, -0.007467865943908691, 0.011907738633453846, 0.03992333635687828, -0.016640642657876015, -0.07622373104095459, -0.0034142620861530304, -0.006313499063253403, -0.004335535690188408, 0.006544372066855431, -0.027100982144474983, -0.04162824526429176, -0.0009035140974447131, 0.0012575938599184155, -0.05594239383935928, -0.004559749271720648, -0.0021200391929596663, -0.03084823489189148, -0.011117440648376942, -0.017235584557056427, -0.025822298601269722, 0.029711628332734108, -0.07064725458621979, 0.029072286561131477, -0.04173480346798897, -0.012040934525430202, 0.0177150908857584, 0.009909795597195625, 0.014109915122389793, 0.029214361682534218, 0.03358319774270058, 0.04667194187641144, 0.025076400488615036, -0.01292002946138382, 0.05594239383935928, 0.02289198338985443, -0.058428723365068436, 0.06993687152862549, 0.0361938402056694, -0.07224560528993607, 0.05519649758934975, 0.07728930562734604, 0.07128659635782242, 0.020441172644495964, -0.010398182086646557, 0.04844788834452629, -0.0006665358669124544, -0.05128940939903259, -0.04816373810172081, -0.05175115540623665, 0.028717096894979477, -0.008045049384236336, 0.019695274531841278, 0.037898752838373184, 0.0445052832365036, -0.06485766172409058, 0.06961720436811447, 0.03907087817788124, 0.03168293088674545, 0.010060750879347324, -0.0611281655728817, -0.03514603152871132, -0.01566386967897415, 0.003230007365345955, 0.03420477733016014, -0.008449077606201172, -0.005749634932726622, -0.008373599499464035, -0.016729440540075302, -0.004617467522621155, -0.06269100308418274, 0.026514919474720955, -0.026532677933573723, 0.044185612350702286, -0.01531756017357111, 0.01255595963448286, -0.01527316216379404, 0.033529918640851974, -0.01166798546910286, -0.0423741452395916, 0.03235779330134392, -0.05516097694635391, -0.01946440152823925, 0.007370188366621733, -0.009297093376517296, -0.013799124397337437, 0.07970459014177322, -0.010389301925897598, 0.03143429756164551, 0.0025085280649363995, -0.011614706367254257, -0.004413233604282141, -0.019073693081736565, 0.012760194018483162, -0.030901513993740082, 0.01889609731733799, 0.03054632432758808, -0.05690140649676323, -0.007316910196095705, 0.015211003832519054, 0.042764853686094284, -0.027562730014324188, -0.008839786052703857, -0.058002494275569916, -0.02841518446803093, 0.06176750734448433, 0.018105801194906235, -0.06876474618911743, 0.052781205624341965, -0.059494294226169586, -0.02862829901278019, 0.05718556046485901, 0.0814095064997673, 0.10534929484128952, 0.004519790410995483, 0.012777953408658504, -0.05604895204305649, 0.0025440470781177282, 0.03985229507088661, -0.04287140816450119, -0.03168293088674545, -0.05377573519945145, -0.03715285286307335, -0.011747903190553188, 0.04280037060379982, 0.02534279227256775, 0.03226899355649948, 0.0499752052128315, -0.003991445526480675, 0.02562694437801838, -0.02877037413418293, 0.01974855363368988, -0.014775896444916725, -0.036833181977272034, -0.0031101307831704617, 0.03054632432758808, 0.020228059962391853, -0.026532677933573723, 0.015335319563746452, 0.0023176134563982487, 0.052497055381536484, 0.09412530064582825, -0.05310087651014328, 0.03665558993816376, 0.02248351462185383, 0.04535773769021034, 0.026994425803422928, 0.0003787766327150166, 0.010433700866997242, 0.01274243462830782, 0.014758136123418808, -0.05445059761404991, 0.01427863072603941, 0.00493713840842247, 0.009385890327394009, -0.010460339486598969, -0.058641836047172546, -0.020441172644495964, -0.021417945623397827, 0.03793426975607872, 0.038182903081178665, 0.019162490963935852, 0.005239049904048443, -0.052639130502939224, 0.021240349858999252, -0.05246153473854065, 0.053420547395944595, -0.010060750879347324, 0.057079002261161804, -0.049193788319826126, 0.021009476855397224, 0.019055932760238647, -0.019517680630087852, -0.031096868216991425, 0.035447943955659866, -0.07206801325082779, 0.0354834608733654, 0.01388792134821415, -0.03255314752459526, -0.01549515500664711, -0.05111181363463402, 0.029747147113084793, 0.010522497817873955, -0.015548434108495712, 0.007032758090645075, -0.03006681799888611, 0.03871569037437439, 0.04692057520151138, -0.09348595887422562, -0.03786323219537735, -0.026781311258673668, 0.031665172427892685, 0.07871006429195404, -0.026301804929971695, -0.02985370345413685, 0.0402430035173893, 0.06642049551010132, 0.005416644737124443, 0.012333965860307217, -0.06418279558420181, -0.010575776919722557, -0.003642915515229106, 0.0035696576815098524, 0.062158215790987015, -0.009829877875745296, -0.0057274354621768, 0.021080514416098595, -0.013621529564261436, 0.08695046603679657, 0.011650226078927517, -0.006442255340516567, -0.02411738783121109, -0.073595330119133, -0.07686307281255722, 0.05033039674162865, -0.005878391209989786, 0.05416644737124443, -0.01535307988524437, -0.03177172690629959, 0.027172019705176353, -0.0018625265220180154, -0.04198343679308891, -0.01976631209254265, 0.042551737278699875, 0.006859603337943554, 0.02633732371032238, 0.000029483529942808673, 0.04116649925708771, 0.019304566085338593, -0.042693816125392914, -0.027598248794674873, -0.05359814316034317, -0.04645882546901703, 0.06233581155538559, -0.00501261604949832, -0.02935643680393696, 0.002181087387725711, 0.09568813443183899, 0.04908723011612892, -0.052923280745744705, 0.017404301092028618, 0.051786672323942184, -0.04564189165830612, 0.025520388036966324, 0.002612865064293146, -0.004746223799884319, -0.03708181530237198, 0.010620174929499626, -0.00994531437754631, -0.026159729808568954, -0.02662147581577301, 0.020085982978343964, -0.07871006429195404, -0.030475284904241562, -0.00039487116737291217, 0.0715707466006279, 0.006184742320328951, 0.010424820706248283, 0.0009146137745119631, 0.029374197125434875, 0.004639666993170977, 0.023868754506111145, -0.09384115040302277, -0.015219883061945438, 0.09689577668905258, 0.05310087651014328, -0.05072110518813133, 0.02805999480187893, -0.016347611322999, -0.012005415745079517, 0.07267183810472488, 0.03422253951430321, -0.023779958486557007, 0.03598072752356529, 0.006739726755768061, 0.007414587307721376, -0.061589911580085754, 0.025378311052918434, 0.006153663620352745, -0.001698251231573522, 0.0013053225120529532, 0.03099031001329422, -0.005327847320586443, 0.018665224313735962, -0.021098274737596512, -0.002623964799568057, -0.015814825892448425, 0.038253940641880035, 0.03464876487851143, -0.002267664996907115, -0.03392062708735466, -0.0067663658410310745, -0.03141653910279274, 0.052212901413440704, 0.0002676410658750683, -0.038822244852781296, -0.007747577503323555, 0.01896713487803936, -0.04574844613671303, -0.05967188626527786, 0.04709816724061966, -0.010913207195699215, 0.026870109140872955, -0.02090292051434517, 0.021861933171749115, -0.016685040667653084, -0.042409662157297134, 0.028024476021528244, -0.005798473488539457, -0.04120201617479324, -0.07054069638252258, 0.024454819038510323, 0.013142023235559464, -0.038964323699474335, -0.03106134943664074, 0.03814738616347313, -0.034808602184057236, -0.026426121592521667, -0.04660090431571007, -0.00026597612304612994, -0.030830474570393562, -0.06077297776937485, 0.015459636226296425, -0.010176188312470913, 0.0395326241850853, -0.047062650322914124, -0.023797716945409775, 0.02317613549530506, -0.04752439633011818, 0.0019024853827431798, -0.035447943955659866, -0.0030568523798137903, -0.022661110386252403, -0.015184364281594753, 0.015992421656847, -0.030688399448990822, 0.07089588791131973, -0.017466459423303604, -0.03836049884557724, -0.0019846230279654264, -0.009252694435417652, 0.019198009744286537, -0.002133358735591173, -0.022004008293151855, 0.014900212176144123, 0.006855163257569075, 0.05810905247926712, -0.0065621319226920605, -0.012893389910459518, 0.008275922387838364, 0.04280037060379982, 0.03914191573858261, 0.03857361152768135, 0.024561375379562378, 0.04194791615009308, -0.022590070962905884, 0.007974010892212391, -0.021773135289549828, -0.007743137888610363, 0.043120041489601135, -0.05732763558626175, 0.04123753681778908, 0.038111865520477295, 0.009803238324820995, 0.04194791615009308, -0.025289515033364296, -0.005958308931440115, 0.038467057049274445, -0.026674754917621613, 0.016223294660449028, -0.0006398966652341187, 0.022412477061152458, 0.06173199042677879, -0.03942606970667839, 0.0107711311429739, -0.04145064949989319, -0.08091223984956741, 0.03468428552150726, 0.04674297943711281, 0.008164925500750542, -0.02024581842124462, 0.0026905627455562353, -0.0022654449567198753, -0.011144080199301243, 0.0019513240549713373, 0.0011127430479973555, 0.02964058890938759, 0.006064866203814745, -0.06748606264591217, 0.026355084031820297, -0.05960084870457649, 0.03429357707500458, -0.003911527805030346, 0.007467865943908691, 0.006486653815954924, 0.08361168205738068, -0.006064866203814745, 0.008036169223487377, -0.026852348819375038, 0.004117981996387243, 0.032393310219049454, -0.062229253351688385, 0.006468894425779581, -0.0017182306619361043, -0.02964058890938759, 0.018718503415584564, 0.0000308189592033159, 0.008719909936189651, -0.02303405851125717, 0.024738969281315804, 0.007596622221171856, -0.005589799489825964, 0.06428935378789902, 0.08964990824460983, -0.009226054884493351, -0.016072338446974754, -0.007259191945195198, -0.04265829548239708, -0.004781742580235004, -0.039745740592479706, -0.01792820543050766, -0.020281337201595306, -0.019659755751490593, 0.002606205176562071, 0.0006493313703685999, -0.002650603884831071, 0.063969686627388, -0.09426737576723099, -0.004559749271720648, -0.01788380742073059, 0.015610592439770699, 0.04507358744740486, -0.056865889579057693, 0.06421831995248795, 0.03344111889600754, -0.0437949039041996, 0.010780010372400284, -0.02005046419799328, -0.04567740857601166, 0.026532677933573723, 0.005949429236352444, -0.04681401699781418, 0.08865537494421005, -0.020885160192847252, 0.03278401866555214, 0.06219373643398285, 0.04301348701119423, 0.03168293088674545, -0.015992421656847, -0.016329851001501083, -0.08453517407178879, -0.0060293469578027725, 0.05381125584244728, -0.020991718396544456, -0.048696521669626236, -0.05022383853793144, 0.012760194018483162, -0.028681576251983643, 0.051999788731336594, -0.065390445291996, -0.02992474101483822, -0.015859225764870644, 0.03535914421081543, -0.015228763222694397, -0.007703179027885199, -0.028965728357434273, 0.001172126387245953, 0.018487630411982536, -0.02898348867893219, 0.0013896800810471177, 0.004106882028281689, 0.010655694641172886, -0.05487682670354843, -0.023016300052404404, -0.03464876487851143, -0.011543668806552887, -0.007525584194809198, 0.009350371547043324, -0.02761600725352764, 0.0038626892492175102, 0.09625643491744995, -0.043049003928899765, 0.008298122324049473, -0.029072286561131477, -0.026248527690768242, -0.003844929626211524, -0.031079107895493507, 0.01868298463523388, -0.03647799417376518, -0.00654881214722991, -0.028219830244779587, -0.039106398820877075, -0.0028770375065505505, 0.017652934417128563, 0.018878338858485222, 0.04272933304309845, 0.037330448627471924, -0.034808602184057236, -0.062442369759082794, 0.005416644737124443, -0.06173199042677879, 0.053917814046144485, -0.015637231990695, 0.02976490557193756, 0.06155439466238022, 0.0012131951516494155, 0.06109264865517616, -0.0036961939185857773, -0.06148335710167885, 0.006055986043065786, -0.00036351458402350545, 0.004630787298083305, 0.008142726495862007, 0.03828946128487587, -0.016898155212402344, -0.05501890182495117, -0.015042288228869438, -0.014891332946717739, 0.02811327390372753, -0.044611841440200806, -0.00976771954447031, 0.00941252987831831, -0.009190536104142666, 0.03285505622625351, -0.02440153993666172, -0.019926147535443306, -0.017821649089455605, -0.04102442413568497, -0.051999788731336594, 0.01875402219593525, 0.011152960360050201, -0.017484217882156372, 0.028219830244779587, 0.010717852041125298, 0.016241053119301796, -0.019428882747888565, 0.014829174615442753, -0.015939142554998398, 0.02718978002667427, 0.004248958081007004, -0.05075662210583687, 0.03662006929516792, -0.0014229791704565287, -0.009323732927441597, 0.037685640156269073, 0.017493098974227905, 0.02283870428800583, -0.03413373976945877, 0.012165251187980175, -0.04134409502148628, 0.03569657728075981, -0.07132211327552795, -0.02324717305600643, 0.004233418498188257, 0.021773135289549828, -0.08730565756559372, 0.005176891572773457, 0.029782665893435478, 0.005185771267861128, -0.05185771360993385, -0.0015117765869945288, 0.03358319774270058, -0.047346800565719604, -0.02591109648346901, 0.05111181363463402, -0.03594520688056946, 0.009061779826879501, -0.03218019753694534, -0.03715285286307335, -0.042196549475193024, -0.029462995007634163, -0.021009476855397224, 0.030439766123890877, 0.011889979243278503, -0.016072338446974754, 0.018949376419186592, -0.0016771618975326419, 0.02097395807504654, 0.027562730014324188, -0.01657848432660103, -0.016667282208800316, 0.0030235531739890575, -0.0215422622859478, -0.06656257063150406, -0.020991718396544456, -0.016667282208800316, -0.014509503729641438, 0.008298122324049473, -0.018434351310133934, 0.0012020955327898264, 0.029249880462884903, 0.04134409502148628, -0.0026905627455562353, 0.008933023549616337, 0.026568198576569557, -0.04486047104001045, -0.024064108729362488, 0.01531756017357111, -0.005478802602738142, -0.01783052831888199, -0.043475233018398285, -0.022803185507655144, 0.02841518446803093, 0.06404072046279907, -0.011037522926926613, -0.04514462500810623, 0.0032921654637902975, 0.04571292921900749, -0.0031234503258019686 ]
30,853
networkx.generators.small
krackhardt_kite_graph
Returns the Krackhardt Kite Social Network. A 10 actor social network introduced by David Krackhardt to illustrate different centrality measures [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Krackhardt Kite graph with 10 nodes and 18 edges Notes ----- The traditional labeling is: Andre=1, Beverley=2, Carol=3, Diane=4, Ed=5, Fernando=6, Garth=7, Heather=8, Ike=9, Jane=10. References ---------- .. [1] Krackhardt, David. "Assessing the Political Landscape: Structure, Cognition, and Power in Organizations". Administrative Science Quarterly. 35 (2): 342–369. doi:10.2307/2393394. JSTOR 2393394. June 1990.
def _raise_on_directed(func): """ A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. """ @wraps(func) def wrapper(*args, **kwargs): if kwargs.get("create_using") is not None: G = nx.empty_graph(create_using=kwargs["create_using"]) if G.is_directed(): raise NetworkXError("Directed Graph not supported") return func(*args, **kwargs) return wrapper
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.02052106149494648, -0.003826453583315015, 0.036479901522397995, 0.005174993071705103, 0.0002132951485691592, 0.039002541452646255, -0.060078226029872894, -0.017846345901489258, 0.08022357523441315, -0.0368913933634758, 0.019215013831853867, 0.010833045467734337, 0.04422673583030701, -0.02680082991719246, 0.011011956259608269, 0.04515707120299339, -0.048806849867105484, 0.09403548389673233, 0.02332996018230915, 0.04737556353211403, -0.009178120642900467, -0.03184611350297928, -0.0025740782730281353, -0.019894873723387718, 0.0007603706326335669, 0.04347531124949455, -0.025244304910302162, 0.0010136411292478442, 0.0061903116293251514, 0.023687781766057014, -0.034297190606594086, -0.04676726832985878, 0.0009113266132771969, 0.06562446057796478, 0.04633788391947746, 0.06276188790798187, -0.046624138951301575, 0.08093921840190887, -0.10212225466966629, -0.07342496514320374, -0.031255707144737244, 0.0077378894202411175, 0.03207869455218315, 0.011396613903343678, -0.0013496578903868794, -0.020002221688628197, 0.009822200052440166, 0.00007624672434758395, -0.08931224048137665, -0.0420440249145031, 0.022363843396306038, 0.005568597000092268, 0.05514029040932655, 0.06147373095154762, 0.012344840914011002, 0.04036226496100426, -0.0097327446565032, 0.028965650126338005, 0.03943192586302757, -0.016307713463902473, 0.0049737184308469296, 0.05102534219622612, 0.012487969361245632, -0.024188732728362083, -0.03299114108085632, 0.000811248377431184, -0.07821977883577347, -0.026621919125318527, -0.021916566416621208, 0.05456777662038803, 0.011664980091154575, -0.005783289670944214, 0.01718437671661377, 0.009500160813331604, 0.07224415987730026, -0.030629519373178482, 0.019876983016729355, -0.010251585394144058, 0.04827011749148369, -0.023634109646081924, -0.03599684312939644, -0.018767736852169037, -0.022399624809622765, 0.00704908324405551, 0.06197468191385269, -0.021898675709962845, -0.051275819540023804, 0.02640722505748272, 0.030182242393493652, -0.044441428035497665, -0.0055909608490765095, -0.03537065535783768, -0.017408015206456184, 0.005219720769673586, -0.03220393508672714, 0.059684623032808304, 0.02960972860455513, -0.05263553932309151, 0.06397847831249237, -0.011781272478401661, 0.0017879892839118838, 0.00821200292557478, -0.019107667729258537, 0.033456310629844666, -0.016254041343927383, -0.09739901125431061, 0.00984009075909853, -0.028071096166968346, -0.01962650753557682, -0.02338363416492939, -0.08279988914728165, -0.01825784146785736, 0.049987662583589554, 0.000976181763689965, 0.0173632875084877, -0.001127696828916669, -0.010063729248940945, -0.018588826060295105, 0.001818180433474481, -0.03640833497047424, -0.021719764918088913, 0.02898354083299637, -0.05653579533100128, -0.05109690874814987, 0.05646422877907753, -0.023974038660526276, -0.0005283457576297224, -0.016611862927675247, 0.042258717119693756, 0.015198467299342155, 0.018660390749573708, 0.047304000705480576, -0.029878094792366028, 0.03699874132871628, 0.0043810768984258175, 0.03644411638379097, -0.05395948141813278, 0.052742887288331985, -0.014169731177389622, 0.0027954804245382547, -0.00294308178126812, -0.018910866230726242, 0.027945857495069504, 0.04261653870344162, 0.013874527998268604, 0.041686203330755234, -0.05564124137163162, -0.0227216649800539, 0.02433186024427414, -0.02842891775071621, 0.05921945720911026, 0.005613324698060751, 0.009039465337991714, 0.01686233840882778, -0.043153271079063416, 0.03426140546798706, -0.03318794444203377, 0.025494780391454697, 0.02136194333434105, 0.014357587322592735, -0.03152407333254814, -0.022864792495965958, 0.04233027994632721, 0.02332996018230915, 0.015609961934387684, -0.022274388000369072, 0.01001005619764328, -0.020038003101944923, 0.007903382182121277, -0.004305039532482624, -0.04537176340818405, -0.022292278707027435, -0.0057564531452953815, -0.039288800209760666, -0.028804630041122437, 0.03023591637611389, 0.03746391087770462, 0.04261653870344162, -0.03352787345647812, 0.01607513055205345, 0.054424647241830826, -0.044047825038433075, -0.01951916143298149, -0.02832156978547573, 0.04132838174700737, 0.01867828145623207, 0.009884818457067013, -0.025280088186264038, 0.0032472300808876753, 0.0003916467831004411, 0.017560089007019997, 0.017381178215146065, 0.03250808268785477, 0.04973718523979187, 0.03796485811471939, -0.09267576783895493, -0.009374923072755337, -0.0015274505130946636, -0.016924956813454628, 0.07457000017166138, 0.05270710587501526, 0.0321502611041069, 0.03605051338672638, 0.014035548083484173, -0.004799280781298876, 0.047304000705480576, -0.025136958807706833, -0.05188411474227905, -0.05217037349939346, -0.010349986143410206, -0.03885941207408905, -0.034297190606594086, 0.034959159791469574, 0.05152629315853119, -0.03444031625986099, 0.02315104939043522, 0.02154085412621498, 0.05399526283144951, -0.010349986143410206, -0.027212323620915413, -0.012112257070839405, -0.01820416748523712, -0.008082292973995209, -0.02041371539235115, 0.0626545399427414, -0.0413641631603241, 0.008122547529637814, -0.05252819508314133, 0.025637909770011902, -0.017846345901489258, 0.04104212298989296, -0.01584254577755928, 0.01684444583952427, 0.02277533710002899, 0.0389309786260128, -0.047697603702545166, 0.01968018151819706, -0.045121289789676666, 0.010224749334156513, 0.013606161810457706, -0.061831552535295486, -0.0011215467238798738, 0.004445931874215603, -0.0005487527814693749, 0.08279988914728165, 0.029538163915276527, -0.009705907665193081, 0.048806849867105484, 0.005948781967163086, -0.04161464050412178, -0.04211558774113655, -0.011459233239293098, -0.0037660710513591766, -0.023652000352740288, 0.008435641415417194, -0.028697283938527107, -0.059970881789922714, -0.058790069073438644, 0.03925301507115364, 0.006990937050431967, -0.03628309816122055, 0.05825333669781685, -0.05667892470955849, 0.020342150703072548, 0.004568933043628931, -0.033456310629844666, -0.025315869599580765, 0.02214914932847023, -0.03408249467611313, 0.025047503411769867, -0.022453298792243004, 0.04086321219801903, 0.0739259198307991, -0.02411716803908348, 0.006566024385392666, 0.020109567791223526, -0.020038003101944923, 0.011584470979869366, -0.01340041495859623, 0.034959159791469574, -0.046230535954236984, -0.01668342761695385, -0.052063025534152985, 0.03644411638379097, -0.07492782175540924, 0.03184611350297928, 0.009768527001142502, 0.012792117893695831, 0.0114950155839324, -0.01191545557230711, 0.030540063977241516, 0.012022801674902439, 0.0347265750169754, 0.03202502429485321, -0.04776916652917862, 0.0033366852439939976, 0.026943957433104515, -0.042079806327819824, 0.033849913626909256, 0.03229339048266411, 0.029305579140782356, -0.03760703653097153, -0.008435641415417194, 0.01833835057914257, 0.008672698400914669, 0.003736998187378049, 0.03465501219034195, -0.027963748201727867, 0.004723243415355682, -0.01530581433326006, -0.0655171126127243, 0.03517385199666023, -0.01555628888309002, 0.0191255584359169, 0.03572847694158554, 0.024689681828022003, -0.011870727874338627, -0.037929076701402664, 0.033778347074985504, 0.06938158720731735, -0.035692691802978516, 0.10555733740329742, -0.06744935363531113, 0.0013709035702049732, -0.08308614790439606, 0.048198554664850235, 0.06108012795448303, 0.03857315704226494, 0.056500013917684555, 0.09002788364887238, 0.0021156196016818285, -0.02842891775071621, -0.007567924447357655, -0.01825784146785736, -0.08716531097888947, 0.027802729979157448, 0.06938158720731735, -0.04884263128042221, 0.05535498261451721, -0.017622707411646843, 0.008650334551930428, 0.003819744335487485, -0.008784517645835876, 0.0018002893775701523, -0.006673370487987995, 0.032669100910425186, 0.00895895529538393, -0.023634109646081924, 0.023616217076778412, 0.04490659758448601, -0.010197912342846394, 0.1102805808186531, -0.021326160058379173, 0.00981325376778841, 0.04061273857951164, 0.014625953510403633, -0.024653900414705276, 0.03374256566166878, -0.027265997603535652, -0.005233139265328646, -0.03656935691833496, -0.040970560163259506, 0.05743034929037094, 0.01393714640289545, 0.06175998970866203, -0.012112257070839405, 0.032096587121486664, 0.013078375719487667, 0.045729584991931915, -0.05338696390390396, -0.03279433771967888, -0.0698467567563057, -0.0356748029589653, -0.00005566500112763606, 0.018275732174515724, 0.009911655448377132, -0.012273277156054974, -0.01424129493534565, 0.03739234432578087, 0.06891641765832901, -0.03651568293571472, 0.01163814403116703, 0.04587271437048912, -0.0051079015247523785, 0.05714409053325653, -0.04279544949531555, 0.05367322266101837, 0.08451743423938751, -0.01752430759370327, -0.03739234432578087, -0.009061829186975956, -0.04032647982239723, 0.029180342331528664, 0.0317387655377388, -0.03324161469936371, -0.03342052549123764, 0.014608061872422695, 0.0001255869574379176, -0.02764170989394188, 0.0037638347130268812, -0.033849913626909256, -0.008033092133700848, -0.016585025936365128, 0.028572045266628265, 0.027069196105003357, 0.022006021812558174, -0.008471423760056496, 0.015860436484217644, 0.039217233657836914, -0.007397959008812904, 0.04193667694926262, -0.013257285580039024, -0.04111368954181671, 0.007715525571256876, 0.04973718523979187, 0.02994965761899948, 0.009008156135678291, 0.03660513833165169, 0.024045603349804878, -0.034798137843608856, 0.07185055315494537, -0.04104212298989296, 0.07700318098068237, 0.03885941207408905, 0.04240184649825096, -0.039610836654901505, -0.03139883652329445, 0.007433741353452206, -0.046230535954236984, 0.02932346984744072, 0.018642500042915344, -0.04970140382647514, 0.03089788556098938, -0.052241936326026917, 0.02567369118332863, -0.01323044952005148, -0.015359487384557724, 0.0144112603738904, 0.0032539390958845615, 0.05796708166599274, 0.02209547720849514, -0.007813926786184311, -0.004875317681580782, -0.017202267423272133, -0.01978752762079239, -0.0363546647131443, 0.02091466635465622, 0.023133158683776855, 0.0012356023071333766, -0.022328060120344162, 0.06873750686645508, -0.00034076906740665436, 0.08129703998565674, 0.02338363416492939, -0.14048071205615997, -0.010859882459044456, -0.009093138389289379, -0.030146460980176926, -0.024600226432085037, 0.05567702278494835, 0.011834945529699326, -0.008422222919762135, -0.10412605106830597, -0.02417084202170372, -0.032096587121486664, 0.04043382778763771, -0.010045838542282581, 0.014608061872422695, -0.02411716803908348, 0.0016392696416005492, 0.06848703324794769, -0.041578855365514755, -0.0054567777551710606, -0.028500480577349663, 0.005309176165610552, -0.013391468673944473, -0.01578887365758419, -0.0025584236718714237, 0.03544221818447113, 0.01368667185306549, 0.0020887828432023525, -0.017479579895734787, 0.026049403473734856, 0.0111550847068429, -0.029341362416744232, 0.004870845004916191, -0.015091121196746826, -0.01382085494697094, 0.0029028267599642277, 0.06508772820234299, -0.05052439495921135, -0.04004022479057312, 0.017220158129930496, -0.06540976464748383, 0.03585371375083923, 0.02871517464518547, -0.04390469565987587, -0.018928756937384605, -0.01645084284245968, -0.07643067091703415, 0.01592305675148964, -0.02322261407971382, -0.04036226496100426, -0.0047724442556500435, 0.041185252368450165, -0.03170298412442207, -0.017229104414582253, 0.01413394883275032, 0.006812026724219322, -0.015609961934387684, 0.006803080905228853, 0.06444364786148071, 0.049200452864170074, 0.08122547715902328, 0.02595994807779789, 0.011146139353513718, -0.02782062068581581, -0.018275732174515724, 0.016406115144491196, -0.039682403206825256, 0.05231350287795067, 0.034243516623973846, 0.00048249991959892213, -0.010394713841378689, -0.004097056109458208, 0.013534598052501678, 0.04261653870344162, -0.002706025028601289, 0.0320071317255497, 0.017640599980950356, 0.010716753080487251, 0.04458455741405487, 0.01676393672823906, 0.05217037349939346, -0.011700762435793877, -0.005085537675768137, -0.0060114008374512196, 0.04894997924566269, -0.08351553231477737, -0.015833601355552673, 0.011342940852046013, -0.012112257070839405, -0.04322483390569687, -0.028679391369223595, 0.018374133855104446, -0.026836611330509186, 0.017560089007019997, 0.008909755386412144, 0.0038465808611363173, -0.04934358224272728, -0.03651568293571472, 0.004211111459881067, -0.0005071001360192895, -0.005045283120125532, 0.06641166657209396, 0.008744262158870697, -0.015431051142513752, 0.06179577112197876, 0.01867828145623207, 0.014670681208372116, -0.061259038746356964, 0.0028357352130115032, -0.003799616824835539, -0.039396144449710846, 0.039789747446775436, -0.017703218385577202, 0.04759025573730469, -0.021737655624747276, -0.023508870974183083, -0.009119975380599499, -0.04555067420005798, -0.0492362380027771, 0.010027946904301643, -0.02579892985522747, -0.01996643841266632, 0.024743355810642242, -0.0030057004187256098, -0.03433297201991081, 0.012997865676879883, -0.06530242413282394, -0.05159785971045494, -0.020199023187160492, -0.03095155768096447, 0.018588826060295105, 0.013436196371912956, -0.02451077103614807, 0.0010186730651184916, -0.011450287885963917, -0.027069196105003357, -0.026049403473734856, -0.054639339447021484, -0.06254719197750092, 0.021898675709962845, -0.055605459958314896, 0.013561434112489223, 0.011826000176370144, 0.0008956718957051635, -0.01671026274561882, 0.049987662583589554, -0.022417515516281128, -0.0706697404384613, 0.06337018311023712, 0.018660390749573708, 0.023705672472715378, 0.05149051174521446, -0.0024533134419471025, -0.029126668348908424, -0.061437949538230896, -0.01705019362270832, -0.07363966107368469, -0.06859438121318817, 0.05023813620209694, -0.017900019884109497, -0.016021456569433212, 0.00843116920441389, -0.043940477073192596, -0.05349431186914444, 0.032669100910425186, 0.005573069676756859, 0.02180922031402588, 0.03157774731516838, -0.04175776615738869, -0.05020235478878021, -0.02114724926650524, -0.02007378451526165, 0.057788170874118805, 0.009822200052440166, -0.04021913558244705, -0.007787090260535479, 0.04569380357861519, -0.018928756937384605, -0.010913555510342121, 0.02372356504201889, 0.0028737538959831, -0.032114479690790176, -0.06730622053146362, 0.0340467132627964, 0.025727365165948868, 0.024349752813577652, -0.004065746441483498, -0.07192211598157883, 0.004651679191738367, -0.038215335458517075, -0.0129531379789114, -0.008650334551930428, -0.03134516254067421, 0.028911976143717766, -0.03488759323954582, 0.04759025573730469, -0.023061593994498253, 0.01379401795566082, 0.0480196438729763, -0.0006591742858290672, -0.05170520395040512, 0.055426549166440964, 0.047912295907735825, -0.032275497913360596, -0.021165139973163605, 0.0043721310794353485, -0.021845001727342606, 0.023813020437955856, -0.0027216796297580004, 0.037929076701402664, 0.003479813924059272, 0.0004858544853050262, 0.03843002766370773, -0.016093021258711815, -0.05310070887207985, -0.025101177394390106, -0.051848333328962326, -0.04165042191743851, -0.018588826060295105, 0.011199812404811382, -0.010001110844314098, -0.01786423847079277, -0.03195345774292946, 0.02114724926650524, 0.011137194000184536, -0.038501590490341187, -0.02282901108264923, -0.03585371375083923, 0.030522173270583153, -0.05288601666688919, -0.017640599980950356, -0.032830122858285904, -0.03410038724541664, -0.018141549080610275, -0.03225760534405708, 0.02697974070906639, -0.015431051142513752, -0.0069641005247831345, -0.01578887365758419, 0.036032624542713165, 0.019501270726323128, -0.023419415578246117, -0.06641166657209396, -0.06820077449083328, 0.014679626561701298, -0.003153301775455475, -0.0114950155839324, 0.048699505627155304, 0.01726488582789898, 0.008149384520947933, 0.034851811826229095, 0.030969450250267982, -0.0713496059179306, -0.052349284291267395, 0.019089777022600174, 0.0039449818432331085, 0.01642400585114956, -0.03365311026573181, -0.02366989105939865, 0.03746391087770462, 0.001657160697504878, -0.01031420473009348, -0.05231350287795067, 0.011933346278965473, 0.014402315020561218, -0.03263331949710846, -0.03039693459868431, -0.015225304290652275, -0.013436196371912956, -0.017542198300361633, 0.001302693854086101, -0.0046829888597130775, -0.03549589216709137, -0.010269477032124996, -0.02826789766550064, 0.0363546647131443, -0.017166486009955406, 0.02359832637012005, 0.03767860308289528, 0.001203174702823162, 0.0633344054222107, -0.024761246517300606, 0.03644411638379097, -0.010627297684550285, 0.07442686706781387, -0.02816055156290531, 0.032275497913360596, -0.0064094774425029755, 0.007545560598373413, -0.06451521068811417, -0.012326950207352638, 0.057000961154699326, -0.026550354436039925, 0.0184456966817379, 0.08931224048137665, -0.00048082260764203966, -0.024045603349804878, 0.04490659758448601, -0.008243312127888203, 0.02579892985522747, 0.0329553596675396, 0.024206623435020447, -0.03596105799078941, 0.04075586795806885, -0.01320361252874136, 0.011199812404811382, -0.06841547042131424, -0.015520506538450718, 0.003951691091060638, 0.034690793603658676, -0.024743355810642242, -0.04673148691654205, 0.019662290811538696, 0.04422673583030701, 0.0569651797413826 ]
30,854
networkx.generators.classic
ladder_graph
Returns the Ladder graph of length n. This is two paths of n nodes, with each pair connected by a single edge. Node labels are the integers 0 to 2*n - 1. .. plot:: >>> nx.draw(nx.ladder_graph(5))
def star_graph(n, create_using=None): """Return the star graph The star graph consists of one center node connected to n outer nodes. .. plot:: >>> nx.draw(nx.star_graph(6)) Parameters ---------- n : int or iterable If an integer, node labels are 0 to n with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Notes ----- The graph has n+1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)). """ n, nodes = n if isinstance(n, numbers.Integral): nodes.append(int(n)) # there should be n+1 nodes G = empty_graph(nodes, create_using) if G.is_directed(): raise NetworkXError("Directed Graph not supported") if len(nodes) > 1: hub, *spokes = nodes G.add_edges_from((hub, node) for node in spokes) return G
(n, create_using=None, *, backend=None, **backend_kwargs)
[ 0.022217122837901115, -0.006895122118294239, 0.021790895611047745, -0.05022383853793144, -0.012715795077383518, 0.06666912883520126, -0.047630954533815384, 0.007454546168446541, -0.0007092696614563465, 0.005079214461147785, 0.004164600279182196, 0.06254892796278, 0.016978072002530098, 0.07622373104095459, 0.026994425803422928, -0.007707618642598391, 0.01481141522526741, 0.011898858472704887, -0.022998539730906487, 0.03793426975607872, -0.01989062875509262, 0.015148845501244068, 0.03429357707500458, 0.013834643177688122, -0.02090292051434517, 0.012005415745079517, 0.022288160398602486, 0.032446589320898056, -0.03736596927046776, 0.02733185514807701, 0.03315696865320206, -0.012138611637055874, 0.0011665765196084976, 0.018345553427934647, 0.02067204751074314, 0.04230310767889023, -0.021524501964449883, 0.053065355867147446, -0.10456787794828415, -0.015672750771045685, 0.04631675034761429, -0.005865071900188923, 0.014775896444916725, -0.03297937288880348, 0.01212973240762949, 0.02841518446803093, 0.08339856564998627, 0.004519790410995483, -0.06876474618911743, -0.01759965531527996, 0.042764853686094284, 0.004255617968738079, -0.043262120336294174, -0.0583932027220726, -0.0018203477375209332, 0.010140668600797653, -0.00753002380952239, -0.012262928299605846, 0.05945877358317375, -0.039958853274583817, 0.03365423530340195, 0.03205588087439537, 0.006304618902504444, -0.02354908362030983, -0.05619102716445923, -0.02182641439139843, -0.03878672793507576, -0.06141231954097748, -0.014234231784939766, -0.018984895199537277, 0.05409540608525276, 0.04155720770359039, 0.03013785555958748, -0.009599004872143269, 0.012822352349758148, 0.02633732371032238, 0.03644247353076935, 0.011002004146575928, -0.010522497817873955, -0.009030700661242008, -0.022785427048802376, -0.03633591905236244, 0.0218974519520998, -0.048057179898023605, 0.04621019586920738, 0.09824550151824951, -0.019713034853339195, 0.021009476855397224, -0.044682879000902176, -0.02390427328646183, -0.024437058717012405, -0.027811361476778984, -0.026106450706720352, 0.005501002073287964, -0.012689155526459217, 0.015992421656847, 0.05025935918092728, -0.0925624668598175, 0.01237836480140686, -0.0009334832429885864, -0.037472523748874664, -0.03333456441760063, -0.08858434110879898, -0.0218974519520998, -0.056652773171663284, -0.031381018459796906, -0.02534279227256775, 0.05690140649676323, -0.01316866185516119, 0.02855726145207882, -0.019091451540589333, 0.017466459423303604, 0.06613634526729584, -0.013701447285711765, 0.029729386791586876, 0.042622778564691544, -0.018221236765384674, 0.03864465281367302, 0.0652838870882988, -0.022927502170205116, -0.05846424400806427, 0.04422113299369812, -0.04027852416038513, 0.029818184673786163, 0.02683459036052227, -0.00038293900433927774, 0.04457632079720497, -0.053136397153139114, 0.030173374339938164, 0.021062755957245827, -0.001531756017357111, 0.018984895199537277, -0.0009223835077136755, 0.06826747953891754, -0.03535914421081543, 0.01327521912753582, -0.07885213941335678, -0.028450703248381615, -0.0012476042611524463, -0.014296390116214752, 0.03386734798550606, -0.03413373976945877, 0.03878672793507576, 0.04958449676632881, -0.06066641956567764, 0.015441876836121082, 0.01868298463523388, 0.019162490963935852, 0.013292978517711163, -0.014465104788541794, 0.023744437843561172, 0.0020645407494157553, 0.09533294290304184, 0.030688399448990822, -0.022128324955701828, -0.018434351310133934, 0.027100982144474983, -0.02232367917895317, -0.012147491797804832, 0.029818184673786163, -0.007467865943908691, 0.011907738633453846, 0.03992333635687828, -0.016640642657876015, -0.07622373104095459, -0.0034142620861530304, -0.006313499063253403, -0.004335535690188408, 0.006544372066855431, -0.027100982144474983, -0.04162824526429176, -0.0009035140974447131, 0.0012575938599184155, -0.05594239383935928, -0.004559749271720648, -0.0021200391929596663, -0.03084823489189148, -0.011117440648376942, -0.017235584557056427, -0.025822298601269722, 0.029711628332734108, -0.07064725458621979, 0.029072286561131477, -0.04173480346798897, -0.012040934525430202, 0.0177150908857584, 0.009909795597195625, 0.014109915122389793, 0.029214361682534218, 0.03358319774270058, 0.04667194187641144, 0.025076400488615036, -0.01292002946138382, 0.05594239383935928, 0.02289198338985443, -0.058428723365068436, 0.06993687152862549, 0.0361938402056694, -0.07224560528993607, 0.05519649758934975, 0.07728930562734604, 0.07128659635782242, 0.020441172644495964, -0.010398182086646557, 0.04844788834452629, -0.0006665358669124544, -0.05128940939903259, -0.04816373810172081, -0.05175115540623665, 0.028717096894979477, -0.008045049384236336, 0.019695274531841278, 0.037898752838373184, 0.0445052832365036, -0.06485766172409058, 0.06961720436811447, 0.03907087817788124, 0.03168293088674545, 0.010060750879347324, -0.0611281655728817, -0.03514603152871132, -0.01566386967897415, 0.003230007365345955, 0.03420477733016014, -0.008449077606201172, -0.005749634932726622, -0.008373599499464035, -0.016729440540075302, -0.004617467522621155, -0.06269100308418274, 0.026514919474720955, -0.026532677933573723, 0.044185612350702286, -0.01531756017357111, 0.01255595963448286, -0.01527316216379404, 0.033529918640851974, -0.01166798546910286, -0.0423741452395916, 0.03235779330134392, -0.05516097694635391, -0.01946440152823925, 0.007370188366621733, -0.009297093376517296, -0.013799124397337437, 0.07970459014177322, -0.010389301925897598, 0.03143429756164551, 0.0025085280649363995, -0.011614706367254257, -0.004413233604282141, -0.019073693081736565, 0.012760194018483162, -0.030901513993740082, 0.01889609731733799, 0.03054632432758808, -0.05690140649676323, -0.007316910196095705, 0.015211003832519054, 0.042764853686094284, -0.027562730014324188, -0.008839786052703857, -0.058002494275569916, -0.02841518446803093, 0.06176750734448433, 0.018105801194906235, -0.06876474618911743, 0.052781205624341965, -0.059494294226169586, -0.02862829901278019, 0.05718556046485901, 0.0814095064997673, 0.10534929484128952, 0.004519790410995483, 0.012777953408658504, -0.05604895204305649, 0.0025440470781177282, 0.03985229507088661, -0.04287140816450119, -0.03168293088674545, -0.05377573519945145, -0.03715285286307335, -0.011747903190553188, 0.04280037060379982, 0.02534279227256775, 0.03226899355649948, 0.0499752052128315, -0.003991445526480675, 0.02562694437801838, -0.02877037413418293, 0.01974855363368988, -0.014775896444916725, -0.036833181977272034, -0.0031101307831704617, 0.03054632432758808, 0.020228059962391853, -0.026532677933573723, 0.015335319563746452, 0.0023176134563982487, 0.052497055381536484, 0.09412530064582825, -0.05310087651014328, 0.03665558993816376, 0.02248351462185383, 0.04535773769021034, 0.026994425803422928, 0.0003787766327150166, 0.010433700866997242, 0.01274243462830782, 0.014758136123418808, -0.05445059761404991, 0.01427863072603941, 0.00493713840842247, 0.009385890327394009, -0.010460339486598969, -0.058641836047172546, -0.020441172644495964, -0.021417945623397827, 0.03793426975607872, 0.038182903081178665, 0.019162490963935852, 0.005239049904048443, -0.052639130502939224, 0.021240349858999252, -0.05246153473854065, 0.053420547395944595, -0.010060750879347324, 0.057079002261161804, -0.049193788319826126, 0.021009476855397224, 0.019055932760238647, -0.019517680630087852, -0.031096868216991425, 0.035447943955659866, -0.07206801325082779, 0.0354834608733654, 0.01388792134821415, -0.03255314752459526, -0.01549515500664711, -0.05111181363463402, 0.029747147113084793, 0.010522497817873955, -0.015548434108495712, 0.007032758090645075, -0.03006681799888611, 0.03871569037437439, 0.04692057520151138, -0.09348595887422562, -0.03786323219537735, -0.026781311258673668, 0.031665172427892685, 0.07871006429195404, -0.026301804929971695, -0.02985370345413685, 0.0402430035173893, 0.06642049551010132, 0.005416644737124443, 0.012333965860307217, -0.06418279558420181, -0.010575776919722557, -0.003642915515229106, 0.0035696576815098524, 0.062158215790987015, -0.009829877875745296, -0.0057274354621768, 0.021080514416098595, -0.013621529564261436, 0.08695046603679657, 0.011650226078927517, -0.006442255340516567, -0.02411738783121109, -0.073595330119133, -0.07686307281255722, 0.05033039674162865, -0.005878391209989786, 0.05416644737124443, -0.01535307988524437, -0.03177172690629959, 0.027172019705176353, -0.0018625265220180154, -0.04198343679308891, -0.01976631209254265, 0.042551737278699875, 0.006859603337943554, 0.02633732371032238, 0.000029483529942808673, 0.04116649925708771, 0.019304566085338593, -0.042693816125392914, -0.027598248794674873, -0.05359814316034317, -0.04645882546901703, 0.06233581155538559, -0.00501261604949832, -0.02935643680393696, 0.002181087387725711, 0.09568813443183899, 0.04908723011612892, -0.052923280745744705, 0.017404301092028618, 0.051786672323942184, -0.04564189165830612, 0.025520388036966324, 0.002612865064293146, -0.004746223799884319, -0.03708181530237198, 0.010620174929499626, -0.00994531437754631, -0.026159729808568954, -0.02662147581577301, 0.020085982978343964, -0.07871006429195404, -0.030475284904241562, -0.00039487116737291217, 0.0715707466006279, 0.006184742320328951, 0.010424820706248283, 0.0009146137745119631, 0.029374197125434875, 0.004639666993170977, 0.023868754506111145, -0.09384115040302277, -0.015219883061945438, 0.09689577668905258, 0.05310087651014328, -0.05072110518813133, 0.02805999480187893, -0.016347611322999, -0.012005415745079517, 0.07267183810472488, 0.03422253951430321, -0.023779958486557007, 0.03598072752356529, 0.006739726755768061, 0.007414587307721376, -0.061589911580085754, 0.025378311052918434, 0.006153663620352745, -0.001698251231573522, 0.0013053225120529532, 0.03099031001329422, -0.005327847320586443, 0.018665224313735962, -0.021098274737596512, -0.002623964799568057, -0.015814825892448425, 0.038253940641880035, 0.03464876487851143, -0.002267664996907115, -0.03392062708735466, -0.0067663658410310745, -0.03141653910279274, 0.052212901413440704, 0.0002676410658750683, -0.038822244852781296, -0.007747577503323555, 0.01896713487803936, -0.04574844613671303, -0.05967188626527786, 0.04709816724061966, -0.010913207195699215, 0.026870109140872955, -0.02090292051434517, 0.021861933171749115, -0.016685040667653084, -0.042409662157297134, 0.028024476021528244, -0.005798473488539457, -0.04120201617479324, -0.07054069638252258, 0.024454819038510323, 0.013142023235559464, -0.038964323699474335, -0.03106134943664074, 0.03814738616347313, -0.034808602184057236, -0.026426121592521667, -0.04660090431571007, -0.00026597612304612994, -0.030830474570393562, -0.06077297776937485, 0.015459636226296425, -0.010176188312470913, 0.0395326241850853, -0.047062650322914124, -0.023797716945409775, 0.02317613549530506, -0.04752439633011818, 0.0019024853827431798, -0.035447943955659866, -0.0030568523798137903, -0.022661110386252403, -0.015184364281594753, 0.015992421656847, -0.030688399448990822, 0.07089588791131973, -0.017466459423303604, -0.03836049884557724, -0.0019846230279654264, -0.009252694435417652, 0.019198009744286537, -0.002133358735591173, -0.022004008293151855, 0.014900212176144123, 0.006855163257569075, 0.05810905247926712, -0.0065621319226920605, -0.012893389910459518, 0.008275922387838364, 0.04280037060379982, 0.03914191573858261, 0.03857361152768135, 0.024561375379562378, 0.04194791615009308, -0.022590070962905884, 0.007974010892212391, -0.021773135289549828, -0.007743137888610363, 0.043120041489601135, -0.05732763558626175, 0.04123753681778908, 0.038111865520477295, 0.009803238324820995, 0.04194791615009308, -0.025289515033364296, -0.005958308931440115, 0.038467057049274445, -0.026674754917621613, 0.016223294660449028, -0.0006398966652341187, 0.022412477061152458, 0.06173199042677879, -0.03942606970667839, 0.0107711311429739, -0.04145064949989319, -0.08091223984956741, 0.03468428552150726, 0.04674297943711281, 0.008164925500750542, -0.02024581842124462, 0.0026905627455562353, -0.0022654449567198753, -0.011144080199301243, 0.0019513240549713373, 0.0011127430479973555, 0.02964058890938759, 0.006064866203814745, -0.06748606264591217, 0.026355084031820297, -0.05960084870457649, 0.03429357707500458, -0.003911527805030346, 0.007467865943908691, 0.006486653815954924, 0.08361168205738068, -0.006064866203814745, 0.008036169223487377, -0.026852348819375038, 0.004117981996387243, 0.032393310219049454, -0.062229253351688385, 0.006468894425779581, -0.0017182306619361043, -0.02964058890938759, 0.018718503415584564, 0.0000308189592033159, 0.008719909936189651, -0.02303405851125717, 0.024738969281315804, 0.007596622221171856, -0.005589799489825964, 0.06428935378789902, 0.08964990824460983, -0.009226054884493351, -0.016072338446974754, -0.007259191945195198, -0.04265829548239708, -0.004781742580235004, -0.039745740592479706, -0.01792820543050766, -0.020281337201595306, -0.019659755751490593, 0.002606205176562071, 0.0006493313703685999, -0.002650603884831071, 0.063969686627388, -0.09426737576723099, -0.004559749271720648, -0.01788380742073059, 0.015610592439770699, 0.04507358744740486, -0.056865889579057693, 0.06421831995248795, 0.03344111889600754, -0.0437949039041996, 0.010780010372400284, -0.02005046419799328, -0.04567740857601166, 0.026532677933573723, 0.005949429236352444, -0.04681401699781418, 0.08865537494421005, -0.020885160192847252, 0.03278401866555214, 0.06219373643398285, 0.04301348701119423, 0.03168293088674545, -0.015992421656847, -0.016329851001501083, -0.08453517407178879, -0.0060293469578027725, 0.05381125584244728, -0.020991718396544456, -0.048696521669626236, -0.05022383853793144, 0.012760194018483162, -0.028681576251983643, 0.051999788731336594, -0.065390445291996, -0.02992474101483822, -0.015859225764870644, 0.03535914421081543, -0.015228763222694397, -0.007703179027885199, -0.028965728357434273, 0.001172126387245953, 0.018487630411982536, -0.02898348867893219, 0.0013896800810471177, 0.004106882028281689, 0.010655694641172886, -0.05487682670354843, -0.023016300052404404, -0.03464876487851143, -0.011543668806552887, -0.007525584194809198, 0.009350371547043324, -0.02761600725352764, 0.0038626892492175102, 0.09625643491744995, -0.043049003928899765, 0.008298122324049473, -0.029072286561131477, -0.026248527690768242, -0.003844929626211524, -0.031079107895493507, 0.01868298463523388, -0.03647799417376518, -0.00654881214722991, -0.028219830244779587, -0.039106398820877075, -0.0028770375065505505, 0.017652934417128563, 0.018878338858485222, 0.04272933304309845, 0.037330448627471924, -0.034808602184057236, -0.062442369759082794, 0.005416644737124443, -0.06173199042677879, 0.053917814046144485, -0.015637231990695, 0.02976490557193756, 0.06155439466238022, 0.0012131951516494155, 0.06109264865517616, -0.0036961939185857773, -0.06148335710167885, 0.006055986043065786, -0.00036351458402350545, 0.004630787298083305, 0.008142726495862007, 0.03828946128487587, -0.016898155212402344, -0.05501890182495117, -0.015042288228869438, -0.014891332946717739, 0.02811327390372753, -0.044611841440200806, -0.00976771954447031, 0.00941252987831831, -0.009190536104142666, 0.03285505622625351, -0.02440153993666172, -0.019926147535443306, -0.017821649089455605, -0.04102442413568497, -0.051999788731336594, 0.01875402219593525, 0.011152960360050201, -0.017484217882156372, 0.028219830244779587, 0.010717852041125298, 0.016241053119301796, -0.019428882747888565, 0.014829174615442753, -0.015939142554998398, 0.02718978002667427, 0.004248958081007004, -0.05075662210583687, 0.03662006929516792, -0.0014229791704565287, -0.009323732927441597, 0.037685640156269073, 0.017493098974227905, 0.02283870428800583, -0.03413373976945877, 0.012165251187980175, -0.04134409502148628, 0.03569657728075981, -0.07132211327552795, -0.02324717305600643, 0.004233418498188257, 0.021773135289549828, -0.08730565756559372, 0.005176891572773457, 0.029782665893435478, 0.005185771267861128, -0.05185771360993385, -0.0015117765869945288, 0.03358319774270058, -0.047346800565719604, -0.02591109648346901, 0.05111181363463402, -0.03594520688056946, 0.009061779826879501, -0.03218019753694534, -0.03715285286307335, -0.042196549475193024, -0.029462995007634163, -0.021009476855397224, 0.030439766123890877, 0.011889979243278503, -0.016072338446974754, 0.018949376419186592, -0.0016771618975326419, 0.02097395807504654, 0.027562730014324188, -0.01657848432660103, -0.016667282208800316, 0.0030235531739890575, -0.0215422622859478, -0.06656257063150406, -0.020991718396544456, -0.016667282208800316, -0.014509503729641438, 0.008298122324049473, -0.018434351310133934, 0.0012020955327898264, 0.029249880462884903, 0.04134409502148628, -0.0026905627455562353, 0.008933023549616337, 0.026568198576569557, -0.04486047104001045, -0.024064108729362488, 0.01531756017357111, -0.005478802602738142, -0.01783052831888199, -0.043475233018398285, -0.022803185507655144, 0.02841518446803093, 0.06404072046279907, -0.011037522926926613, -0.04514462500810623, 0.0032921654637902975, 0.04571292921900749, -0.0031234503258019686 ]
30,867
networkx.algorithms.dag
lexicographical_topological_sort
Generate the nodes in the unique lexicographical topological sort order. Generates a unique ordering of nodes by first sorting topologically (for which there are often multiple valid orderings) and then additionally by sorting lexicographically. A topological sort arranges the nodes of a directed graph so that the upstream node of each directed edge precedes the downstream node. It is always possible to find a solution for directed graphs that have no cycles. There may be more than one valid solution. Lexicographical sorting is just sorting alphabetically. It is used here to break ties in the topological sort and to determine a single, unique ordering. This can be useful in comparing sort results. The lexicographical order can be customized by providing a function to the `key=` parameter. The definition of the key function is the same as used in python's built-in `sort()`. The function takes a single argument and returns a key to use for sorting purposes. Lexicographical sorting can fail if the node names are un-sortable. See the example below. The solution is to provide a function to the `key=` argument that returns sortable keys. Parameters ---------- G : NetworkX digraph A directed acyclic graph (DAG) key : function, optional A function of one argument that converts a node name to a comparison key. It defines and resolves ambiguities in the sort order. Defaults to the identity function. Yields ------ nodes Yields the nodes of G in lexicographical topological sort order. Raises ------ NetworkXError Topological sort is defined for directed graphs only. If the graph `G` is undirected, a :exc:`NetworkXError` is raised. NetworkXUnfeasible If `G` is not a directed acyclic graph (DAG) no topological sort exists and a :exc:`NetworkXUnfeasible` exception is raised. This can also be raised if `G` is changed while the returned iterator is being processed RuntimeError If `G` is changed while the returned iterator is being processed. TypeError Results from un-sortable node names. Consider using `key=` parameter to resolve ambiguities in the sort order. Examples -------- >>> DG = nx.DiGraph([(2, 1), (2, 5), (1, 3), (1, 4), (5, 4)]) >>> list(nx.lexicographical_topological_sort(DG)) [2, 1, 3, 5, 4] >>> list(nx.lexicographical_topological_sort(DG, key=lambda x: -x)) [2, 5, 1, 4, 3] The sort will fail for any graph with integer and string nodes. Comparison of integer to strings is not defined in python. Is 3 greater or less than 'red'? >>> DG = nx.DiGraph([(1, "red"), (3, "red"), (1, "green"), (2, "blue")]) >>> list(nx.lexicographical_topological_sort(DG)) Traceback (most recent call last): ... TypeError: '<' not supported between instances of 'str' and 'int' ... Incomparable nodes can be resolved using a `key` function. This example function allows comparison of integers and strings by returning a tuple where the first element is True for `str`, False otherwise. The second element is the node name. This groups the strings and integers separately so they can be compared only among themselves. >>> key = lambda node: (isinstance(node, str), node) >>> list(nx.lexicographical_topological_sort(DG, key=key)) [1, 2, 3, 'blue', 'green', 'red'] Notes ----- This algorithm is based on a description and proof in "Introduction to Algorithms: A Creative Approach" [1]_ . See also -------- topological_sort References ---------- .. [1] Manber, U. (1989). *Introduction to Algorithms - A Creative Approach.* Addison-Wesley.
def transitive_closure_dag(G, topo_order=None): """Returns the transitive closure of a directed acyclic graph. This function is faster than the function `transitive_closure`, but fails if the graph has a cycle. The transitive closure of G = (V,E) is a graph G+ = (V,E+) such that for all v, w in V there is an edge (v, w) in E+ if and only if there is a non-null path from v to w in G. Parameters ---------- G : NetworkX DiGraph A directed acyclic graph (DAG) topo_order: list or tuple, optional A topological order for G (if None, the function will compute one) Returns ------- NetworkX DiGraph The transitive closure of `G` Raises ------ NetworkXNotImplemented If `G` is not directed NetworkXUnfeasible If `G` has a cycle Examples -------- >>> DG = nx.DiGraph([(1, 2), (2, 3)]) >>> TC = nx.transitive_closure_dag(DG) >>> TC.edges() OutEdgeView([(1, 2), (1, 3), (2, 3)]) Notes ----- This algorithm is probably simple enough to be well-known but I didn't find a mention in the literature. """ if topo_order is None: topo_order = list(topological_sort(G)) TC = G.copy() # idea: traverse vertices following a reverse topological order, connecting # each vertex to its descendants at distance 2 as we go for v in reversed(topo_order): TC.add_edges_from((v, u) for u in nx.descendants_at_distance(TC, v, 2)) return TC
(G, key=None, *, backend=None, **backend_kwargs)
[ -0.032722052186727524, 0.021163780242204666, -0.02473505772650242, 0.007943014614284039, -0.036240555346012115, -0.03105076588690281, -0.018982309848070145, -0.012622619979083538, 0.09309951961040497, -0.07768848538398743, 0.012130030430853367, 0.02825355716049671, 0.0004870923876296729, -0.011769384145736694, -0.03159613162279129, 0.022412847727537155, -0.0140036316588521, -0.017328614369034767, 0.0031908401288092136, 0.029432255774736404, 0.0009450471843592823, -0.06410707533359528, 0.013493448495864868, -0.02392580173909664, -0.01571889966726303, 0.016536951065063477, -0.047042351216077805, 0.032123908400535583, -0.06058857589960098, -0.031314652413129807, 0.031156320124864578, -0.04542383924126625, -0.09056620299816132, 0.01345826406031847, 0.052671950310468674, 0.08099588006734848, -0.0004252437502145767, 0.01810268498957157, -0.017143893986940384, -0.06041265279054642, 0.012200400233268738, -0.018436942249536514, -0.01149670034646988, -0.03244057297706604, 0.0458812452852726, 0.01345826406031847, -0.009192082099616528, 0.03807017579674721, -0.037331290543079376, -0.04947011545300484, 0.08634399622678757, -0.03715536370873451, -0.005783535074442625, -0.010634667240083218, 0.015261495485901833, 0.03905535489320755, 0.019527677446603775, 0.059427469968795776, 0.06815335154533386, -0.017803611233830452, -0.009974948130548, -0.0552404560148716, -0.009068934246897697, 0.035501670092344284, -0.0509478859603405, 0.02125174179673195, -0.03680351376533508, -0.06006080284714699, -0.02114618755877018, 0.007336073089390993, -0.013695762492716312, 0.02019619196653366, 0.005590017419308424, -0.07606998085975647, -0.027356339618563652, -0.07635145634412766, 0.027936892583966255, -0.04521273076534271, -0.028570223599672318, -0.03513222560286522, -0.03439334034919739, -0.06843483448028564, 0.023450804874300957, -0.008272874169051647, 0.06129227578639984, -0.027989670634269714, 0.03368964046239853, -0.0014414855977520347, -0.06769594550132751, -0.04070904850959778, 0.00783306173980236, -0.03432296961545944, -0.03119150549173355, 0.032722052186727524, 0.037436842918395996, -0.008875417523086071, -0.0009587913518771529, -0.04852012172341347, 0.01012448500841856, 0.009992540813982487, 0.03894979879260063, 0.007503202185034752, -0.08535882085561752, -0.006254134234040976, 0.023222101852297783, -0.045353468507528305, -0.017478151246905327, 0.016809634864330292, -0.017337409779429436, -0.0874699205160141, -0.0024475567042827606, -0.001305143698118627, 0.09788467735052109, -0.03894979879260063, 0.03154335543513298, 0.013167987577617168, 0.007797876372933388, 0.0007004014914855361, -0.00035075051710009575, -0.005682378076016903, 0.014170760288834572, 0.02218414470553398, 0.001111076446250081, 0.01265780534595251, -0.007274499628692865, 0.008057366125285625, 0.009315229952335358, 0.027637820690870285, 0.03437574952840805, -0.010854573920369148, 0.06101079657673836, -0.013722151517868042, 0.03332019969820976, 0.08169957995414734, 0.05168677121400833, 0.003749402007088065, -0.032370202243328094, 0.015402235090732574, -0.020284155383706093, 0.022764697670936584, -0.010133281350135803, -0.06139783188700676, -0.021550815552473068, 0.04936455935239792, 0.049786780029535294, 0.003953914623707533, -0.005801127292215824, -0.013255950063467026, 0.011927716434001923, 0.01926378905773163, 0.00851037260144949, 0.0038505587726831436, -0.014848071150481701, 0.032616499811410904, 0.00014486325380858034, -0.007828663103282452, -0.043664589524269104, 0.07241073995828629, -0.053657129406929016, 0.012059659697115421, -0.0312618762254715, 0.04725345969200134, -0.04004053398966789, 0.024752650409936905, 0.016633709892630577, -0.0018450135830789804, 0.11414015293121338, 0.006320106331259012, -0.0314553938806057, 0.03140261396765709, -0.056788597255945206, -0.030769284814596176, -0.007309684529900551, -0.0049039097502827644, -0.006152977701276541, 0.029924845322966576, 0.0038505587726831436, 0.030610952526330948, -0.016079546883702278, 0.021867480129003525, -0.016545748338103294, 0.0005662586772814393, -0.045705318450927734, 0.02119896560907364, 0.0324229821562767, 0.031015580520033836, 0.0412016399204731, -0.04011090472340584, 0.07698478549718857, -0.020970262587070465, -0.05506452918052673, 0.012701786123216152, 0.03785906359553337, 0.023310065269470215, 0.07522553950548172, -0.05597934126853943, -0.02996003068983555, 0.03715536370873451, -0.04771086573600769, 0.07153110951185226, 0.06396633386611938, 0.015076774172484875, 0.07188296318054199, 0.03332019969820976, 0.023697100579738617, 0.08155883848667145, 0.03434056416153908, -0.033056311309337616, -0.023714693263173103, 0.008615927770733833, -0.012974469922482967, -0.025561904534697533, 0.010661056265234947, -0.03997016325592995, -0.05175714194774628, 0.03224705532193184, -0.03824609890580177, 0.013502244837582111, 0.04809790104627609, 0.0018900943687185645, -0.02637116052210331, 0.03712017834186554, 0.025614682585000992, -0.016888801008462906, 0.070440374314785, -0.07754775136709213, -0.00043513954733498394, 0.011250404641032219, 0.020284155383706093, -0.05949784070253372, 0.010977720841765404, -0.007142555899918079, 0.03284519910812378, -0.019721195101737976, 0.06196079030632973, -0.04436828941106796, -0.035149820148944855, 0.0032238259445875883, 0.01885916106402874, 0.01790916733443737, -0.050666406750679016, -0.006034228019416332, -0.024611910805106163, 0.010590686462819576, -0.017055930569767952, -0.005202982574701309, 0.026599863544106483, 0.0060122376307845116, 0.032510943710803986, 0.026406345888972282, -0.051229365170001984, -0.035607222467660904, -0.04862567409873009, -0.029572995379567146, -0.031015580520033836, -0.01246428769081831, -0.004105649888515472, -0.056788597255945206, -0.005409694276750088, 0.01731102168560028, 0.0003754899662453681, 0.017231855541467667, -0.05766822025179863, 0.06931445747613907, 0.008849028497934341, -0.029520217329263687, 0.03423500806093216, -0.08184032142162323, -0.06681632250547409, -0.005568027030676603, -0.016589729115366936, 0.003883544821292162, 0.04401643946766853, 0.0053613148629665375, 0.0037713926285505295, -0.040920160710811615, 0.015525382943451405, 0.01602676883339882, -0.0030325076077133417, -0.029924845322966576, -0.04183496907353401, 0.029273923486471176, -0.03124428354203701, -0.0231341402977705, -0.06273486465215683, -0.006421263329684734, -0.011294386349618435, -0.026898935437202454, 0.022078590467572212, 0.018524903804063797, 0.07656256854534149, 0.0026586668100208044, 0.07297369837760925, 0.024840611964464188, 0.06305152922868729, 0.035343337804079056, 0.02642393857240677, -0.02547394298017025, -0.0024365615099668503, 0.03298594057559967, 0.07360702753067017, 0.009543932043015957, -0.01631704531610012, -0.0518626943230629, 0.0017900370294228196, 0.004587244708091021, 0.009869393892586231, -0.007995791733264923, -0.02939707040786743, 0.04014609009027481, -0.05168677121400833, -0.049927521497011185, -0.07040519267320633, 0.04507198929786682, -0.06924408674240112, -0.034164637327194214, -0.032669275999069214, -0.049329373985528946, 0.05446638539433479, 0.011742995120584965, 0.0023859830107539892, 0.015639733523130417, -0.00848398357629776, -0.006579595617949963, -0.07656256854534149, 0.04683123901486397, 0.009658283554017544, 0.057844147086143494, 0.05854784697294235, 0.010194854810833931, -0.005691174417734146, 0.0385979488492012, 0.005255760159343481, 0.05710526183247566, -0.003030308522284031, 0.07079222798347473, 0.09661801904439926, -0.029977623373270035, 0.015279088169336319, -0.028183188289403915, 0.04556458070874214, 0.041870154440402985, -0.02881651744246483, 0.009746246039867401, -0.012349936179816723, 0.010036522522568703, 0.0030325076077133417, -0.0014019025256857276, 0.037049807608127594, -0.02288784459233284, 0.043171998113393784, 0.03810535743832588, -0.01820823922753334, 0.02726837806403637, -0.039231278002262115, 0.06572558730840683, 0.04911826550960541, -0.00865551084280014, 0.014909645542502403, 0.027901707217097282, 0.0033777602948248386, -0.0220961831510067, 0.01940452866256237, -0.03627573698759079, 0.0552404560148716, 0.0032722053583711386, -0.009024953469634056, 0.037436842918395996, -0.02095266990363598, -0.044509030878543854, 0.01701194979250431, -0.011320775374770164, 0.04070904850959778, 0.009262451902031898, -0.05129973590373993, 0.030470212921500206, 0.047781236469745636, -0.05407935008406639, 0.0530238002538681, 0.03602944314479828, -0.019985081627964973, 0.01761009357869625, -0.008066162467002869, 0.03124428354203701, 0.020424894988536835, 0.015270291827619076, 0.04359421879053116, 0.00858074240386486, 0.023503582924604416, -0.02781374566257, -0.005638396833091974, -0.02702208235859871, 0.04542383924126625, -0.003953914623707533, 0.0003326082369312644, -0.034305378794670105, 0.06611262261867523, 0.044614583253860474, 0.025790607556700706, 0.0029071609023958445, -0.014584183692932129, 0.007670330815017223, 0.02199062705039978, 0.008941388688981533, 0.02367950789630413, -0.03349612280726433, 0.012174011208117008, 0.036838699132204056, 0.06178486719727516, 0.048836786299943924, -0.0037032216787338257, 0.006342096719890833, 0.032071132212877274, -0.017152689397335052, -0.020161006599664688, -0.01970360241830349, -0.07110889256000519, 0.0029599384870380163, 0.058688584715127945, 0.0023002196103334427, 0.0488719716668129, 0.029027627781033516, 0.0284646674990654, -0.03902016952633858, 0.004644420463591814, -0.034059084951877594, 0.031420208513736725, 0.039231278002262115, -0.010397168807685375, 0.09197360277175903, 0.010705037042498589, -0.032071132212877274, 0.013203172944486141, -0.03330260515213013, 0.00006892687088111416, 0.02098785527050495, 0.014188352972269058, 0.00813213363289833, 0.04000534862279892, 0.0661478042602539, -0.0076571363024413586, 0.0402868278324604, -0.02528042532503605, -0.060870055109262466, -0.011971697211265564, -0.029432255774736404, 0.009016157127916813, 0.0329507552087307, 0.04918863624334335, -0.022272108122706413, 0.046268280595541, 0.04651457443833351, -0.006702743005007505, -0.011619847267866135, -0.08507733792066574, 0.050033073872327805, 0.024611910805106163, -0.005387703888118267, -0.11864383518695831, 0.010168465785682201, 0.00858074240386486, -0.03214149922132492, 0.05963858217000961, -0.04528310149908066, -0.01631704531610012, -0.022166552022099495, 0.002638875273987651, 0.0009549430105835199, -0.040920160710811615, -0.03254612907767296, 0.05140529200434685, -0.03277483209967613, -0.05921636149287224, -0.04398125410079956, 0.045001618564128876, 0.015191125683486462, -0.05312935635447502, 0.03330260515213013, 0.05735155567526817, -0.0333377905189991, 0.020688781514763832, -0.029572995379567146, 0.0035053060855716467, 0.011136054061353207, 0.0026564677245914936, 0.0009477960411459208, 0.01532306894659996, -0.020424894988536835, 0.011224016547203064, -0.0004618031671270728, 0.001651496160775423, -0.0229406226426363, -0.005941867362707853, -0.01147031132131815, 0.006192560773342848, 0.03894979879260063, -0.015806863084435463, -0.03601185232400894, 0.0094559695571661, 0.0062365420162677765, -0.001593220978975296, 0.042116448283195496, -0.018173053860664368, 0.021111002191901207, -0.0009796824306249619, -0.03620536997914314, 0.009508747607469559, 0.026300789788365364, 0.012728175148367882, 0.013994835317134857, 0.04109608381986618, 0.022817475721240044, 0.008809445425868034, 0.03404149040579796, 0.01012448500841856, 0.014786497689783573, -0.023310065269470215, 0.004947890993207693, 0.024348022416234016, -0.029520217329263687, 0.004156228620558977, 0.013132802210748196, 0.020688781514763832, 0.08043292164802551, -0.011294386349618435, -0.013000858947634697, 0.021410074084997177, -0.03412945196032524, -0.0069578345865011215, -0.00297973002307117, 0.00040710149914957583, 0.03240538761019707, -0.013924465514719486, 0.05728118494153023, -0.0036680365446954966, -0.052812691777944565, -0.008000190369784832, -0.02443598583340645, -0.11611051112413406, 0.000672363443300128, 0.014047612436115742, 0.04827382415533066, 0.015947602689266205, 0.01323835738003254, 0.03916090726852417, -0.010757815092802048, 0.04623309522867203, -0.04088497534394264, -0.02816559560596943, -0.010889758355915546, -0.07895515114068985, 0.031138727441430092, -0.012710582464933395, 0.025333203375339508, 0.03631092235445976, -0.03428778797388077, -0.027004489675164223, 0.049786780029535294, -0.021480444818735123, 0.010432353243231773, -0.05728118494153023, -0.009667079895734787, -0.0659015104174614, -0.05309417098760605, 0.014619369059801102, 0.006891862489283085, 0.05119417980313301, -0.009060138836503029, 0.032123908400535583, -0.0229406226426363, 0.013906872831285, -0.0814884677529335, 0.01204206794500351, -0.002123194979503751, -0.020935077220201492, 0.050771959125995636, -0.01243789866566658, 0.011857346631586552, 0.03722573444247246, -0.06167931109666824, -0.019826749339699745, -0.03578314930200577, 0.0182610172778368, 0.03894979879260063, 0.007595562841743231, -0.011391145177185535, -0.0007410841644741595, 0.03434056416153908, 0.0021275931503623724, -0.03940720483660698, 0.0182610172778368, -0.04039238393306732, 0.019580453634262085, 0.006817094516009092, -0.0017944352002814412, -0.01563093811273575, -0.010836981236934662, 0.06741447001695633, -0.017231855541467667, -0.023415619507431984, -0.03866831958293915, 0.0054228887893259525, 0.028200780972838402, 0.016800839453935623, -0.06942000985145569, 0.0019406728679314256, 0.008057366125285625, -0.03740165755152702, 0.06942000985145569, -0.03979424014687538, -0.0021781716495752335, 0.017434168606996536, -0.03662759065628052, -0.044403474777936935, -0.04904789477586746, -0.01059948280453682, -0.07508479803800583, 0.028922073543071747, -0.07916625589132309, 0.00427937600761652, 0.018436942249536514, -0.025685053318738937, 0.01487446017563343, -0.033953528851270676, -0.039125725626945496, 0.08078476786613464, 0.03367204964160919, -0.04690160974860191, 0.002126493724063039, 0.05319972708821297, -0.03235261142253876, -0.020917484536767006, -0.006280523259192705, 0.035941481590270996, 0.01582445576786995, -0.07958848029375076, 0.0013590208254754543, 0.024295244365930557, -0.018348978832364082, -0.02786652371287346, -0.10689204186201096, 0.0449664331972599, -0.039477575570344925, 0.0008081555715762079, -0.05084232985973358, -0.02070637419819832, 0.00977263506501913, -0.04640901833772659, -0.005172195378690958, -0.0428905189037323, -0.013088821433484554, 0.01880638487637043, 0.03708499297499657, 0.004274977836757898, 0.01340548601001501, 0.06695706397294998, 0.04179978370666504, -0.04472013935446739, 0.03458685800433159, 0.011514292098581791, 0.07825145125389099, 0.013607800006866455, 0.01850731112062931, -0.019932305440306664, -0.001981355482712388, 0.025702646002173424, 0.05010344460606575, -0.06642928719520569, -0.004846734460443258, -0.04253866896033287, -0.024471169337630272, 0.023116547614336014, 0.012728175148367882, -0.027778560295701027, -0.02248321659862995, -0.005075437016785145, 0.037049807608127594, 0.029168367385864258, 0.012376325204968452, -0.02990725263953209, 0.027356339618563652, 0.06449411064386368, 0.007129361387342215, -0.045705318450927734, -0.015041588805615902, -0.014540202915668488, -0.014021224342286587, -0.03905535489320755, 0.06389596313238144, -0.05319972708821297, 0.038492392748594284, -0.002324409317225218, 0.007296490017324686, -0.016440192237496376, 0.057879332453012466, 0.005651591345667839, -0.0016613919287919998, 0.014601776376366615, 0.015947602689266205, -0.019035087898373604, -0.005172195378690958, 0.0023002196103334427, 0.03398871421813965, 0.036944255232810974, -0.025702646002173424, -0.005629600491374731, -0.034305378794670105, -0.0314553938806057, 0.00208251248113811, 0.01710870862007141, -0.03458685800433159, -0.03244057297706604, -0.0060430243611335754, 0.01597399078309536, 0.01775963045656681, -0.04911826550960541, -0.04130719602108002, 0.006469642743468285, -0.04429791867733002, -0.0021968637593090534, 0.019017495214939117, 0.03249334916472435, -0.05742192640900612, 0.02149803750216961, 0.024260060861706734, 0.05200343579053879, 0.022817475721240044, -0.03595907241106033, -0.031420208513736725, -0.02925633080303669, -0.011945309117436409, 0.048590488731861115, 0.02179710939526558, 0.007995791733264923, -0.019985081627964973, -0.003815373871475458, -0.047781236469745636, 0.033619269728660583, -0.04130719602108002, 0.032722052186727524, -0.035061854869127274, 0.015498993918299675, -0.054994162172079086, 0.021726740524172783, -0.010203651152551174, -0.01801472157239914, -0.025614682585000992, -0.0008636818965896964, 0.015270291827619076, -0.018823977559804916, 0.004543263465166092, 0.006399272475391626, 0.004780762363225222, -0.08402179181575775, -0.018595274537801743, -0.010168465785682201, -0.057140447199344635, -0.020460080355405807, -0.062312640249729156, -0.06104598194360733, -0.0441923663020134, -0.01300965528935194, 0.015367050655186176, -0.02626560442149639, 0.05619044974446297, 0.014399462379515171, 0.034164637327194214, 0.04961085692048073 ]
30,879
networkx.generators.classic
lollipop_graph
Returns the Lollipop Graph; ``K_m`` connected to ``P_n``. This is the Barbell Graph without the right barbell. .. plot:: >>> nx.draw(nx.lollipop_graph(3, 4)) Parameters ---------- m, n : int or iterable container of nodes If an integer, nodes are from ``range(m)`` and ``range(m, m+n)``. If a container of nodes, those nodes appear in the graph. Warning: `m` and `n` are not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. The nodes for `m` appear in the complete graph $K_m$ and the nodes for `n` appear in the path $P_n$ create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- Networkx graph A complete graph with `m` nodes connected to a path of length `n`. Notes ----- The 2 subgraphs are joined via an edge ``(m-1, m)``. If ``n=0``, this is merely a complete graph. (This graph is an extremal example in David Aldous and Jim Fill's etext on Random Walks on Graphs.)
def star_graph(n, create_using=None): """Return the star graph The star graph consists of one center node connected to n outer nodes. .. plot:: >>> nx.draw(nx.star_graph(6)) Parameters ---------- n : int or iterable If an integer, node labels are 0 to n with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Notes ----- The graph has n+1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)). """ n, nodes = n if isinstance(n, numbers.Integral): nodes.append(int(n)) # there should be n+1 nodes G = empty_graph(nodes, create_using) if G.is_directed(): raise NetworkXError("Directed Graph not supported") if len(nodes) > 1: hub, *spokes = nodes G.add_edges_from((hub, node) for node in spokes) return G
(m, n, create_using=None, *, backend=None, **backend_kwargs)
[ 0.022217122837901115, -0.006895122118294239, 0.021790895611047745, -0.05022383853793144, -0.012715795077383518, 0.06666912883520126, -0.047630954533815384, 0.007454546168446541, -0.0007092696614563465, 0.005079214461147785, 0.004164600279182196, 0.06254892796278, 0.016978072002530098, 0.07622373104095459, 0.026994425803422928, -0.007707618642598391, 0.01481141522526741, 0.011898858472704887, -0.022998539730906487, 0.03793426975607872, -0.01989062875509262, 0.015148845501244068, 0.03429357707500458, 0.013834643177688122, -0.02090292051434517, 0.012005415745079517, 0.022288160398602486, 0.032446589320898056, -0.03736596927046776, 0.02733185514807701, 0.03315696865320206, -0.012138611637055874, 0.0011665765196084976, 0.018345553427934647, 0.02067204751074314, 0.04230310767889023, -0.021524501964449883, 0.053065355867147446, -0.10456787794828415, -0.015672750771045685, 0.04631675034761429, -0.005865071900188923, 0.014775896444916725, -0.03297937288880348, 0.01212973240762949, 0.02841518446803093, 0.08339856564998627, 0.004519790410995483, -0.06876474618911743, -0.01759965531527996, 0.042764853686094284, 0.004255617968738079, -0.043262120336294174, -0.0583932027220726, -0.0018203477375209332, 0.010140668600797653, -0.00753002380952239, -0.012262928299605846, 0.05945877358317375, -0.039958853274583817, 0.03365423530340195, 0.03205588087439537, 0.006304618902504444, -0.02354908362030983, -0.05619102716445923, -0.02182641439139843, -0.03878672793507576, -0.06141231954097748, -0.014234231784939766, -0.018984895199537277, 0.05409540608525276, 0.04155720770359039, 0.03013785555958748, -0.009599004872143269, 0.012822352349758148, 0.02633732371032238, 0.03644247353076935, 0.011002004146575928, -0.010522497817873955, -0.009030700661242008, -0.022785427048802376, -0.03633591905236244, 0.0218974519520998, -0.048057179898023605, 0.04621019586920738, 0.09824550151824951, -0.019713034853339195, 0.021009476855397224, -0.044682879000902176, -0.02390427328646183, -0.024437058717012405, -0.027811361476778984, -0.026106450706720352, 0.005501002073287964, -0.012689155526459217, 0.015992421656847, 0.05025935918092728, -0.0925624668598175, 0.01237836480140686, -0.0009334832429885864, -0.037472523748874664, -0.03333456441760063, -0.08858434110879898, -0.0218974519520998, -0.056652773171663284, -0.031381018459796906, -0.02534279227256775, 0.05690140649676323, -0.01316866185516119, 0.02855726145207882, -0.019091451540589333, 0.017466459423303604, 0.06613634526729584, -0.013701447285711765, 0.029729386791586876, 0.042622778564691544, -0.018221236765384674, 0.03864465281367302, 0.0652838870882988, -0.022927502170205116, -0.05846424400806427, 0.04422113299369812, -0.04027852416038513, 0.029818184673786163, 0.02683459036052227, -0.00038293900433927774, 0.04457632079720497, -0.053136397153139114, 0.030173374339938164, 0.021062755957245827, -0.001531756017357111, 0.018984895199537277, -0.0009223835077136755, 0.06826747953891754, -0.03535914421081543, 0.01327521912753582, -0.07885213941335678, -0.028450703248381615, -0.0012476042611524463, -0.014296390116214752, 0.03386734798550606, -0.03413373976945877, 0.03878672793507576, 0.04958449676632881, -0.06066641956567764, 0.015441876836121082, 0.01868298463523388, 0.019162490963935852, 0.013292978517711163, -0.014465104788541794, 0.023744437843561172, 0.0020645407494157553, 0.09533294290304184, 0.030688399448990822, -0.022128324955701828, -0.018434351310133934, 0.027100982144474983, -0.02232367917895317, -0.012147491797804832, 0.029818184673786163, -0.007467865943908691, 0.011907738633453846, 0.03992333635687828, -0.016640642657876015, -0.07622373104095459, -0.0034142620861530304, -0.006313499063253403, -0.004335535690188408, 0.006544372066855431, -0.027100982144474983, -0.04162824526429176, -0.0009035140974447131, 0.0012575938599184155, -0.05594239383935928, -0.004559749271720648, -0.0021200391929596663, -0.03084823489189148, -0.011117440648376942, -0.017235584557056427, -0.025822298601269722, 0.029711628332734108, -0.07064725458621979, 0.029072286561131477, -0.04173480346798897, -0.012040934525430202, 0.0177150908857584, 0.009909795597195625, 0.014109915122389793, 0.029214361682534218, 0.03358319774270058, 0.04667194187641144, 0.025076400488615036, -0.01292002946138382, 0.05594239383935928, 0.02289198338985443, -0.058428723365068436, 0.06993687152862549, 0.0361938402056694, -0.07224560528993607, 0.05519649758934975, 0.07728930562734604, 0.07128659635782242, 0.020441172644495964, -0.010398182086646557, 0.04844788834452629, -0.0006665358669124544, -0.05128940939903259, -0.04816373810172081, -0.05175115540623665, 0.028717096894979477, -0.008045049384236336, 0.019695274531841278, 0.037898752838373184, 0.0445052832365036, -0.06485766172409058, 0.06961720436811447, 0.03907087817788124, 0.03168293088674545, 0.010060750879347324, -0.0611281655728817, -0.03514603152871132, -0.01566386967897415, 0.003230007365345955, 0.03420477733016014, -0.008449077606201172, -0.005749634932726622, -0.008373599499464035, -0.016729440540075302, -0.004617467522621155, -0.06269100308418274, 0.026514919474720955, -0.026532677933573723, 0.044185612350702286, -0.01531756017357111, 0.01255595963448286, -0.01527316216379404, 0.033529918640851974, -0.01166798546910286, -0.0423741452395916, 0.03235779330134392, -0.05516097694635391, -0.01946440152823925, 0.007370188366621733, -0.009297093376517296, -0.013799124397337437, 0.07970459014177322, -0.010389301925897598, 0.03143429756164551, 0.0025085280649363995, -0.011614706367254257, -0.004413233604282141, -0.019073693081736565, 0.012760194018483162, -0.030901513993740082, 0.01889609731733799, 0.03054632432758808, -0.05690140649676323, -0.007316910196095705, 0.015211003832519054, 0.042764853686094284, -0.027562730014324188, -0.008839786052703857, -0.058002494275569916, -0.02841518446803093, 0.06176750734448433, 0.018105801194906235, -0.06876474618911743, 0.052781205624341965, -0.059494294226169586, -0.02862829901278019, 0.05718556046485901, 0.0814095064997673, 0.10534929484128952, 0.004519790410995483, 0.012777953408658504, -0.05604895204305649, 0.0025440470781177282, 0.03985229507088661, -0.04287140816450119, -0.03168293088674545, -0.05377573519945145, -0.03715285286307335, -0.011747903190553188, 0.04280037060379982, 0.02534279227256775, 0.03226899355649948, 0.0499752052128315, -0.003991445526480675, 0.02562694437801838, -0.02877037413418293, 0.01974855363368988, -0.014775896444916725, -0.036833181977272034, -0.0031101307831704617, 0.03054632432758808, 0.020228059962391853, -0.026532677933573723, 0.015335319563746452, 0.0023176134563982487, 0.052497055381536484, 0.09412530064582825, -0.05310087651014328, 0.03665558993816376, 0.02248351462185383, 0.04535773769021034, 0.026994425803422928, 0.0003787766327150166, 0.010433700866997242, 0.01274243462830782, 0.014758136123418808, -0.05445059761404991, 0.01427863072603941, 0.00493713840842247, 0.009385890327394009, -0.010460339486598969, -0.058641836047172546, -0.020441172644495964, -0.021417945623397827, 0.03793426975607872, 0.038182903081178665, 0.019162490963935852, 0.005239049904048443, -0.052639130502939224, 0.021240349858999252, -0.05246153473854065, 0.053420547395944595, -0.010060750879347324, 0.057079002261161804, -0.049193788319826126, 0.021009476855397224, 0.019055932760238647, -0.019517680630087852, -0.031096868216991425, 0.035447943955659866, -0.07206801325082779, 0.0354834608733654, 0.01388792134821415, -0.03255314752459526, -0.01549515500664711, -0.05111181363463402, 0.029747147113084793, 0.010522497817873955, -0.015548434108495712, 0.007032758090645075, -0.03006681799888611, 0.03871569037437439, 0.04692057520151138, -0.09348595887422562, -0.03786323219537735, -0.026781311258673668, 0.031665172427892685, 0.07871006429195404, -0.026301804929971695, -0.02985370345413685, 0.0402430035173893, 0.06642049551010132, 0.005416644737124443, 0.012333965860307217, -0.06418279558420181, -0.010575776919722557, -0.003642915515229106, 0.0035696576815098524, 0.062158215790987015, -0.009829877875745296, -0.0057274354621768, 0.021080514416098595, -0.013621529564261436, 0.08695046603679657, 0.011650226078927517, -0.006442255340516567, -0.02411738783121109, -0.073595330119133, -0.07686307281255722, 0.05033039674162865, -0.005878391209989786, 0.05416644737124443, -0.01535307988524437, -0.03177172690629959, 0.027172019705176353, -0.0018625265220180154, -0.04198343679308891, -0.01976631209254265, 0.042551737278699875, 0.006859603337943554, 0.02633732371032238, 0.000029483529942808673, 0.04116649925708771, 0.019304566085338593, -0.042693816125392914, -0.027598248794674873, -0.05359814316034317, -0.04645882546901703, 0.06233581155538559, -0.00501261604949832, -0.02935643680393696, 0.002181087387725711, 0.09568813443183899, 0.04908723011612892, -0.052923280745744705, 0.017404301092028618, 0.051786672323942184, -0.04564189165830612, 0.025520388036966324, 0.002612865064293146, -0.004746223799884319, -0.03708181530237198, 0.010620174929499626, -0.00994531437754631, -0.026159729808568954, -0.02662147581577301, 0.020085982978343964, -0.07871006429195404, -0.030475284904241562, -0.00039487116737291217, 0.0715707466006279, 0.006184742320328951, 0.010424820706248283, 0.0009146137745119631, 0.029374197125434875, 0.004639666993170977, 0.023868754506111145, -0.09384115040302277, -0.015219883061945438, 0.09689577668905258, 0.05310087651014328, -0.05072110518813133, 0.02805999480187893, -0.016347611322999, -0.012005415745079517, 0.07267183810472488, 0.03422253951430321, -0.023779958486557007, 0.03598072752356529, 0.006739726755768061, 0.007414587307721376, -0.061589911580085754, 0.025378311052918434, 0.006153663620352745, -0.001698251231573522, 0.0013053225120529532, 0.03099031001329422, -0.005327847320586443, 0.018665224313735962, -0.021098274737596512, -0.002623964799568057, -0.015814825892448425, 0.038253940641880035, 0.03464876487851143, -0.002267664996907115, -0.03392062708735466, -0.0067663658410310745, -0.03141653910279274, 0.052212901413440704, 0.0002676410658750683, -0.038822244852781296, -0.007747577503323555, 0.01896713487803936, -0.04574844613671303, -0.05967188626527786, 0.04709816724061966, -0.010913207195699215, 0.026870109140872955, -0.02090292051434517, 0.021861933171749115, -0.016685040667653084, -0.042409662157297134, 0.028024476021528244, -0.005798473488539457, -0.04120201617479324, -0.07054069638252258, 0.024454819038510323, 0.013142023235559464, -0.038964323699474335, -0.03106134943664074, 0.03814738616347313, -0.034808602184057236, -0.026426121592521667, -0.04660090431571007, -0.00026597612304612994, -0.030830474570393562, -0.06077297776937485, 0.015459636226296425, -0.010176188312470913, 0.0395326241850853, -0.047062650322914124, -0.023797716945409775, 0.02317613549530506, -0.04752439633011818, 0.0019024853827431798, -0.035447943955659866, -0.0030568523798137903, -0.022661110386252403, -0.015184364281594753, 0.015992421656847, -0.030688399448990822, 0.07089588791131973, -0.017466459423303604, -0.03836049884557724, -0.0019846230279654264, -0.009252694435417652, 0.019198009744286537, -0.002133358735591173, -0.022004008293151855, 0.014900212176144123, 0.006855163257569075, 0.05810905247926712, -0.0065621319226920605, -0.012893389910459518, 0.008275922387838364, 0.04280037060379982, 0.03914191573858261, 0.03857361152768135, 0.024561375379562378, 0.04194791615009308, -0.022590070962905884, 0.007974010892212391, -0.021773135289549828, -0.007743137888610363, 0.043120041489601135, -0.05732763558626175, 0.04123753681778908, 0.038111865520477295, 0.009803238324820995, 0.04194791615009308, -0.025289515033364296, -0.005958308931440115, 0.038467057049274445, -0.026674754917621613, 0.016223294660449028, -0.0006398966652341187, 0.022412477061152458, 0.06173199042677879, -0.03942606970667839, 0.0107711311429739, -0.04145064949989319, -0.08091223984956741, 0.03468428552150726, 0.04674297943711281, 0.008164925500750542, -0.02024581842124462, 0.0026905627455562353, -0.0022654449567198753, -0.011144080199301243, 0.0019513240549713373, 0.0011127430479973555, 0.02964058890938759, 0.006064866203814745, -0.06748606264591217, 0.026355084031820297, -0.05960084870457649, 0.03429357707500458, -0.003911527805030346, 0.007467865943908691, 0.006486653815954924, 0.08361168205738068, -0.006064866203814745, 0.008036169223487377, -0.026852348819375038, 0.004117981996387243, 0.032393310219049454, -0.062229253351688385, 0.006468894425779581, -0.0017182306619361043, -0.02964058890938759, 0.018718503415584564, 0.0000308189592033159, 0.008719909936189651, -0.02303405851125717, 0.024738969281315804, 0.007596622221171856, -0.005589799489825964, 0.06428935378789902, 0.08964990824460983, -0.009226054884493351, -0.016072338446974754, -0.007259191945195198, -0.04265829548239708, -0.004781742580235004, -0.039745740592479706, -0.01792820543050766, -0.020281337201595306, -0.019659755751490593, 0.002606205176562071, 0.0006493313703685999, -0.002650603884831071, 0.063969686627388, -0.09426737576723099, -0.004559749271720648, -0.01788380742073059, 0.015610592439770699, 0.04507358744740486, -0.056865889579057693, 0.06421831995248795, 0.03344111889600754, -0.0437949039041996, 0.010780010372400284, -0.02005046419799328, -0.04567740857601166, 0.026532677933573723, 0.005949429236352444, -0.04681401699781418, 0.08865537494421005, -0.020885160192847252, 0.03278401866555214, 0.06219373643398285, 0.04301348701119423, 0.03168293088674545, -0.015992421656847, -0.016329851001501083, -0.08453517407178879, -0.0060293469578027725, 0.05381125584244728, -0.020991718396544456, -0.048696521669626236, -0.05022383853793144, 0.012760194018483162, -0.028681576251983643, 0.051999788731336594, -0.065390445291996, -0.02992474101483822, -0.015859225764870644, 0.03535914421081543, -0.015228763222694397, -0.007703179027885199, -0.028965728357434273, 0.001172126387245953, 0.018487630411982536, -0.02898348867893219, 0.0013896800810471177, 0.004106882028281689, 0.010655694641172886, -0.05487682670354843, -0.023016300052404404, -0.03464876487851143, -0.011543668806552887, -0.007525584194809198, 0.009350371547043324, -0.02761600725352764, 0.0038626892492175102, 0.09625643491744995, -0.043049003928899765, 0.008298122324049473, -0.029072286561131477, -0.026248527690768242, -0.003844929626211524, -0.031079107895493507, 0.01868298463523388, -0.03647799417376518, -0.00654881214722991, -0.028219830244779587, -0.039106398820877075, -0.0028770375065505505, 0.017652934417128563, 0.018878338858485222, 0.04272933304309845, 0.037330448627471924, -0.034808602184057236, -0.062442369759082794, 0.005416644737124443, -0.06173199042677879, 0.053917814046144485, -0.015637231990695, 0.02976490557193756, 0.06155439466238022, 0.0012131951516494155, 0.06109264865517616, -0.0036961939185857773, -0.06148335710167885, 0.006055986043065786, -0.00036351458402350545, 0.004630787298083305, 0.008142726495862007, 0.03828946128487587, -0.016898155212402344, -0.05501890182495117, -0.015042288228869438, -0.014891332946717739, 0.02811327390372753, -0.044611841440200806, -0.00976771954447031, 0.00941252987831831, -0.009190536104142666, 0.03285505622625351, -0.02440153993666172, -0.019926147535443306, -0.017821649089455605, -0.04102442413568497, -0.051999788731336594, 0.01875402219593525, 0.011152960360050201, -0.017484217882156372, 0.028219830244779587, 0.010717852041125298, 0.016241053119301796, -0.019428882747888565, 0.014829174615442753, -0.015939142554998398, 0.02718978002667427, 0.004248958081007004, -0.05075662210583687, 0.03662006929516792, -0.0014229791704565287, -0.009323732927441597, 0.037685640156269073, 0.017493098974227905, 0.02283870428800583, -0.03413373976945877, 0.012165251187980175, -0.04134409502148628, 0.03569657728075981, -0.07132211327552795, -0.02324717305600643, 0.004233418498188257, 0.021773135289549828, -0.08730565756559372, 0.005176891572773457, 0.029782665893435478, 0.005185771267861128, -0.05185771360993385, -0.0015117765869945288, 0.03358319774270058, -0.047346800565719604, -0.02591109648346901, 0.05111181363463402, -0.03594520688056946, 0.009061779826879501, -0.03218019753694534, -0.03715285286307335, -0.042196549475193024, -0.029462995007634163, -0.021009476855397224, 0.030439766123890877, 0.011889979243278503, -0.016072338446974754, 0.018949376419186592, -0.0016771618975326419, 0.02097395807504654, 0.027562730014324188, -0.01657848432660103, -0.016667282208800316, 0.0030235531739890575, -0.0215422622859478, -0.06656257063150406, -0.020991718396544456, -0.016667282208800316, -0.014509503729641438, 0.008298122324049473, -0.018434351310133934, 0.0012020955327898264, 0.029249880462884903, 0.04134409502148628, -0.0026905627455562353, 0.008933023549616337, 0.026568198576569557, -0.04486047104001045, -0.024064108729362488, 0.01531756017357111, -0.005478802602738142, -0.01783052831888199, -0.043475233018398285, -0.022803185507655144, 0.02841518446803093, 0.06404072046279907, -0.011037522926926613, -0.04514462500810623, 0.0032921654637902975, 0.04571292921900749, -0.0031234503258019686 ]
30,888
networkx.algorithms.matching
max_weight_matching
Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986.
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, maxcardinality=False, weight='weight', *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,890
networkx.algorithms.matching
maximal_matching
Find a maximal matching in the graph. A matching is a subset of edges in which no node occurs more than once. A maximal matching cannot add more edges and still be a matching. Parameters ---------- G : NetworkX graph Undirected graph Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)]) >>> sorted(nx.maximal_matching(G)) [(1, 2), (3, 5)] Notes ----- The algorithm greedily selects a maximal matching M of the graph G (i.e. no superset of M exists). It runs in $O(|E|)$ time.
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,891
networkx.algorithms.tree.branchings
maximum_branching
Returns a maximum branching from G. Parameters ---------- G : (multi)digraph-like The graph to be searched. attr : str The edge attribute used to in determining optimality. default : float The value of the edge attribute used if an edge does not have the attribute `attr`. preserve_attrs : bool If True, preserve the other attributes of the original graph (that are not passed to `attr`) partition : str The key for the edge attribute containing the partition data on the graph. Edges can be included, excluded or open using the `EdgePartition` enum. Returns ------- B : (multi)digraph-like A maximum branching.
@nx._dispatchable(preserve_edge_attrs=True, returns_graph=True) def maximum_branching( G, attr="weight", default=1, preserve_attrs=False, partition=None, ): ####################################### ### Data Structure Helper Functions ### ####################################### def edmonds_add_edge(G, edge_index, u, v, key, **d): """ Adds an edge to `G` while also updating the edge index. This algorithm requires the use of an external dictionary to track the edge keys since it is possible that the source or destination node of an edge will be changed and the default key-handling capabilities of the MultiDiGraph class do not account for this. Parameters ---------- G : MultiDiGraph The graph to insert an edge into. edge_index : dict A mapping from integers to the edges of the graph. u : node The source node of the new edge. v : node The destination node of the new edge. key : int The key to use from `edge_index`. d : keyword arguments, optional Other attributes to store on the new edge. """ if key in edge_index: uu, vv, _ = edge_index[key] if (u != uu) or (v != vv): raise Exception(f"Key {key!r} is already in use.") G.add_edge(u, v, key, **d) edge_index[key] = (u, v, G.succ[u][v][key]) def edmonds_remove_node(G, edge_index, n): """ Remove a node from the graph, updating the edge index to match. Parameters ---------- G : MultiDiGraph The graph to remove an edge from. edge_index : dict A mapping from integers to the edges of the graph. n : node The node to remove from `G`. """ keys = set() for keydict in G.pred[n].values(): keys.update(keydict) for keydict in G.succ[n].values(): keys.update(keydict) for key in keys: del edge_index[key] G.remove_node(n) ####################### ### Algorithm Setup ### ####################### # Pick an attribute name that the original graph is unlikly to have candidate_attr = "edmonds' secret candidate attribute" new_node_base_name = "edmonds new node base name " G_original = G G = nx.MultiDiGraph() G.__networkx_cache__ = None # Disable caching # A dict to reliably track mutations to the edges using the key of the edge. G_edge_index = {} # Each edge is given an arbitrary numerical key for key, (u, v, data) in enumerate(G_original.edges(data=True)): d = {attr: data.get(attr, default)} if data.get(partition) is not None: d[partition] = data.get(partition) if preserve_attrs: for d_k, d_v in data.items(): if d_k != attr: d[d_k] = d_v edmonds_add_edge(G, G_edge_index, u, v, key, **d) level = 0 # Stores the number of contracted nodes # These are the buckets from the paper. # # In the paper, G^i are modified versions of the original graph. # D^i and E^i are the nodes and edges of the maximal edges that are # consistent with G^i. In this implementation, D^i and E^i are stored # together as the graph B^i. We will have strictly more B^i then the # paper will have. # # Note that the data in graphs and branchings are tuples with the graph as # the first element and the edge index as the second. B = nx.MultiDiGraph() B_edge_index = {} graphs = [] # G^i list branchings = [] # B^i list selected_nodes = set() # D^i bucket uf = nx.utils.UnionFind() # A list of lists of edge indices. Each list is a circuit for graph G^i. # Note the edge list is not required to be a circuit in G^0. circuits = [] # Stores the index of the minimum edge in the circuit found in G^i and B^i. # The ordering of the edges seems to preserver the weight ordering from # G^0. So even if the circuit does not form a circuit in G^0, it is still # true that the minimum edges in circuit G^0 (despite their weights being # different) minedge_circuit = [] ########################### ### Algorithm Structure ### ########################### # Each step listed in the algorithm is an inner function. Thus, the overall # loop structure is: # # while True: # step_I1() # if cycle detected: # step_I2() # elif every node of G is in D and E is a branching: # break ################################## ### Algorithm Helper Functions ### ################################## def edmonds_find_desired_edge(v): """ Find the edge directed towards v with maximal weight. If an edge partition exists in this graph, return the included edge if it exists and never return any excluded edge. Note: There can only be one included edge for each vertex otherwise the edge partition is empty. Parameters ---------- v : node The node to search for the maximal weight incoming edge. """ edge = None max_weight = -INF for u, _, key, data in G.in_edges(v, data=True, keys=True): # Skip excluded edges if data.get(partition) == nx.EdgePartition.EXCLUDED: continue new_weight = data[attr] # Return the included edge if data.get(partition) == nx.EdgePartition.INCLUDED: max_weight = new_weight edge = (u, v, key, new_weight, data) break # Find the best open edge if new_weight > max_weight: max_weight = new_weight edge = (u, v, key, new_weight, data) return edge, max_weight def edmonds_step_I2(v, desired_edge, level): """ Perform step I2 from Edmonds' paper First, check if the last step I1 created a cycle. If it did not, do nothing. If it did, store the cycle for later reference and contract it. Parameters ---------- v : node The current node to consider desired_edge : edge The minimum desired edge to remove from the cycle. level : int The current level, i.e. the number of cycles that have already been removed. """ u = desired_edge[0] Q_nodes = nx.shortest_path(B, v, u) Q_edges = [ list(B[Q_nodes[i]][vv].keys())[0] for i, vv in enumerate(Q_nodes[1:]) ] Q_edges.append(desired_edge[2]) # Add the new edge key to complete the circuit # Get the edge in the circuit with the minimum weight. # Also, save the incoming weights for each node. minweight = INF minedge = None Q_incoming_weight = {} for edge_key in Q_edges: u, v, data = B_edge_index[edge_key] w = data[attr] # We cannot remove an included edge, even if it is the # minimum edge in the circuit Q_incoming_weight[v] = w if data.get(partition) == nx.EdgePartition.INCLUDED: continue if w < minweight: minweight = w minedge = edge_key circuits.append(Q_edges) minedge_circuit.append(minedge) graphs.append((G.copy(), G_edge_index.copy())) branchings.append((B.copy(), B_edge_index.copy())) # Mutate the graph to contract the circuit new_node = new_node_base_name + str(level) G.add_node(new_node) new_edges = [] for u, v, key, data in G.edges(data=True, keys=True): if u in Q_incoming_weight: if v in Q_incoming_weight: # Circuit edge. For the moment do nothing, # eventually it will be removed. continue else: #
(G, attr='weight', default=1, preserve_attrs=False, partition=None, *, backend=None, **backend_kwargs)
[ 0.05934286117553711, 0.015630874782800674, -0.03579306975007057, 0.014857499860227108, -0.035684142261743546, -0.05433226749300957, -0.04394073039293289, -0.04126115143299103, 0.017765823751688004, -0.07045330852270126, -0.031239964067935944, 0.05241516977548599, 0.004386992659419775, 0.022416962310671806, -0.04836312308907509, -0.0001257754338439554, -0.015445699915289879, 0.006764301564544439, 0.04797099158167839, 0.03906084597110748, -0.020837534219026566, -0.07106329500675201, -0.003205146174877882, 0.07454892247915268, 0.013332536444067955, 0.020510757341980934, 0.013180040754377842, 0.023702288046479225, -0.00812587607651949, -0.004937069024890661, -0.03106568194925785, -0.04971380531787872, -0.02666507288813591, -0.041130442172288895, 0.047143153846263885, 0.02803754061460495, 0.04012832045555115, 0.03906084597110748, -0.12574411928653717, -0.03991046920418739, -0.022253572940826416, -0.02259124256670475, 0.012929510325193405, -0.04128293693065643, 0.04450714588165283, 0.022286251187324524, 0.028582170605659485, 0.07711957395076752, 0.009111655876040459, -0.011709540151059628, 0.019693812355399132, -0.048145271837711334, 0.03411560878157616, 0.03853800147771835, -0.0033440268598496914, 0.015282311476767063, 0.000021572444893536158, 0.018386701121926308, 0.056815776973962784, -0.05816645920276642, -0.00729259243234992, -0.008425422944128513, 0.04010653495788574, -0.02278731018304825, -0.0625234991312027, 0.012177921831607819, -0.040847234427928925, -0.02415977604687214, -0.04967023432254791, 0.031610313802957535, 0.0031969768460839987, -0.03642483800649643, 0.02000969834625721, -0.014694111421704292, -0.042742542922496796, -0.026926495134830475, -0.0015413023065775633, -0.023026946932077408, -0.014705004170536995, -0.02670864388346672, 0.06783908605575562, -0.017613327130675316, 0.02605508826673031, -0.056467216461896896, 0.029998207464814186, -0.010887148790061474, 0.04300396516919136, 0.061739232391119, 0.0019143735989928246, -0.09698767215013504, -0.03760123997926712, 0.02178519032895565, 0.01657853089272976, 0.08343727886676788, 0.06949476152658463, 0.018147064372897148, -0.03337491303682327, -0.039757974445819855, 0.04587961360812187, -0.010375197045505047, -0.012798799201846123, 0.03977975994348526, -0.07589960843324661, -0.01751529425382614, -0.04779670760035515, -0.055290814489126205, -0.034072037786245346, 0.017842071130871773, -0.03997582569718361, -0.09175922721624374, -0.0701918825507164, 0.01953042298555374, 0.006432077381759882, 0.011360976845026016, 0.009160672314465046, 0.056467216461896896, -0.012352203018963337, -0.008049627766013145, 0.03328777104616165, 0.008665059693157673, 0.02339729480445385, -0.033875972032547, -0.03908263146877289, -0.009966724552214146, 0.016959771513938904, -0.014977319166064262, 0.03936583921313286, 0.014236622489988804, 0.03017248958349228, -0.02742755599319935, 0.001910288934595883, -0.029911067336797714, -0.018408486619591713, 0.04522605612874031, -0.036816973239183426, -0.03771016374230385, -0.07537676393985748, 0.004318913910537958, 0.015097137540578842, -0.001639335649088025, 0.03041212633252144, -0.038995493203401566, 0.04470321163535118, 0.016611207276582718, 0.005269293207675219, -0.036686260253190994, 0.020358260720968246, -0.02912680059671402, 0.00255567510612309, 0.001967475051060319, -0.008893804624676704, -0.018887760117650032, -0.020282013341784477, -0.006791533436626196, 0.02481333166360855, 0.03121817857027054, -0.05132590979337692, 0.015587303787469864, -0.04749171435832977, 0.014552507549524307, -0.04293861240148544, -0.027950400486588478, 0.011077769100666046, 0.017656898126006126, -0.0016951601719483733, -0.014824822545051575, 0.014258407056331635, -0.013822703622281551, -0.061259955167770386, 0.03137067332863808, 0.006377614568918943, -0.003918610978871584, -0.0851365253329277, -0.006780640687793493, -0.025183681398630142, 0.09419916570186615, 0.04513891413807869, -0.0278414748609066, 0.01236309576779604, 0.002110440284013748, -0.006018158979713917, -0.023331940174102783, 0.045923180878162384, 0.011524366214871407, 0.02880002185702324, -0.001371786231175065, 0.037492312490940094, -0.01641514152288437, 0.05237159878015518, -0.010211808606982231, -0.020118623971939087, -0.07245754450559616, 0.023593362420797348, 0.015413022600114346, 0.014214836992323399, 0.0185609832406044, 0.04228505492210388, 0.045443907380104065, -0.0055987942032516, 0.05620579421520233, -0.0021553724072873592, 0.0003000569704454392, 0.055857229977846146, -0.008305603638291359, 0.016491388902068138, 0.020271120592951775, -0.0027966739144176245, -0.031000327318906784, 0.0075376760214567184, 0.007276253774762154, -0.050323791801929474, 0.02038004621863365, 0.03049926646053791, 0.00801150407642126, 0.010544032789766788, -0.017537077888846397, -0.02973678521811962, 0.04078187793493271, 0.04285147041082382, -0.04272076115012169, -0.05760004371404648, 0.0007311654626391828, 0.018212419003248215, 0.01066929753869772, 0.030804259702563286, -0.077468141913414, 0.05394013226032257, 0.02472619153559208, 0.05193589627742767, -0.009629053995013237, 0.045966751873493195, -0.024639051407575607, 0.02908322960138321, -0.027209702879190445, 0.02339729480445385, -0.01207988802343607, -0.057905036956071854, 0.0001592191110830754, -0.009422095492482185, 0.03097854182124138, -0.021806975826621056, -0.05873287469148636, -0.03784087672829628, 0.018049031496047974, 0.030717119574546814, -0.030934970825910568, 0.07594317197799683, 0.01543480809777975, 0.0003877083072438836, 0.0004251516074873507, -0.05550866574048996, -0.0649634376168251, -0.010603941977024078, -0.029780356213450432, 0.013909844681620598, -0.02481333166360855, -0.036816973239183426, -0.036642689257860184, -0.01276612188667059, -0.027100777253508568, 0.009961278177797794, -0.007042062934488058, -0.04036795720458031, 0.04849383607506752, 0.015990329906344414, 0.03662090748548508, 0.035117726773023605, 0.008643274195492268, -0.024747977033257484, 0.006856888998299837, 0.09498342871665955, -0.011753110215067863, 0.005331925582140684, 0.028059326112270355, -0.0701918825507164, -0.029475362971425056, -0.018495626747608185, 0.0018449333729222417, -0.03300456330180168, -0.05672863870859146, -0.08574651181697845, -0.006159762851893902, -0.015630874782800674, 0.04853740707039833, -0.060214266180992126, 0.031327106058597565, -0.021251453086733818, -0.07755527645349503, -0.01032618060708046, -0.012820584699511528, 0.004136463161557913, -0.01010288204997778, 0.02162180282175541, 0.03973618894815445, 0.07494105398654938, -0.016927093267440796, 0.022525887936353683, -0.03888656571507454, 0.0029028765857219696, 0.04888596758246422, 0.04897310957312584, -0.051456619054079056, 0.030237844213843346, -0.037100180983543396, -0.01875704899430275, -0.005920125637203455, 0.05119519680738449, -0.02254767343401909, 0.0017768546240404248, 0.02089199796319008, -0.037209104746580124, 0.04736100509762764, -0.011546150781214237, 0.02723148837685585, -0.004030260257422924, -0.04433286190032959, 0.0071945590898394585, -0.01254826970398426, 0.04744814708828926, 0.051979467272758484, -0.006039944011718035, 0.0467945896089077, -0.05128233879804611, 0.03097854182124138, -0.10108328610658646, -0.014955533668398857, 0.03718731924891472, 0.04723029211163521, 0.019780952483415604, -0.033745259046554565, -0.02557581476867199, 0.030804259702563286, 0.010968843474984169, -0.0004152801993768662, -0.04627174511551857, 0.026360081508755684, 0.06849264353513718, -0.03352740779519081, 0.009678071364760399, -0.05350442975759506, 0.046446025371551514, 0.08038735389709473, 0.018953116610646248, 0.029627859592437744, 0.000499357411172241, -0.013702885247766972, 0.04736100509762764, 0.02199215069413185, -0.03925691545009613, 0.016850845888257027, -0.00033835123758763075, 0.0923692062497139, -0.025967948138713837, 0.008899250067770481, 0.0009136164444498718, -0.028342533856630325, -0.02581545151770115, -0.0215891245752573, 0.011622399091720581, 0.03391954302787781, -0.019573993980884552, 0.0017346458043903112, -0.017852963879704475, 0.034311674535274506, 0.006029051728546619, 0.0027422108687460423, -0.025510458275675774, 0.03167566657066345, 0.06261064112186432, -0.07559461146593094, 0.010075651109218597, -0.07803455740213394, 0.011350084096193314, 0.04300396516919136, -0.016121041029691696, 0.0621313638985157, -0.05938643217086792, -0.006464755162596703, 0.038385506719350815, 0.049234531819820404, -0.0032868406269699335, -0.01022270042449236, -0.01069108210504055, 0.01981363072991371, 0.013822703622281551, -0.013790025375783443, 0.10587602853775024, -0.011916499584913254, 0.05176161229610443, -0.01791832037270069, 0.012918618507683277, -0.028168251737952232, -0.006464755162596703, 0.003981243818998337, -0.03675161674618721, 0.013223610818386078, 0.08021306991577148, -0.009149780496954918, -0.03204601630568504, -0.016872629523277283, -0.037579454481601715, 0.061303526163101196, -0.006998492404818535, 0.017569756135344505, 0.013103792443871498, -0.0609113946557045, 0.06369990110397339, 0.05280730128288269, 0.024094421416521072, 0.021839654073119164, -0.021273238584399223, 0.05028022080659866, -0.04631531611084938, 0.019225431606173515, -0.023375509306788445, -0.048711687326431274, 0.07162971049547195, -0.02775433287024498, 0.051413051784038544, -0.04566175863146782, 0.04862454533576965, 0.021393056958913803, 0.05973499268293381, -0.04675101861357689, -0.030521051958203316, -0.044354647397994995, -0.004365207627415657, 0.005078672431409359, -0.054811540991067886, 0.05455011874437332, -0.0074995518662035465, -0.04775313660502434, 0.001688352320343256, -0.023135872557759285, -0.015097137540578842, -0.02594616264104843, -0.004259004723280668, 0.0028865376953035593, 0.051500190049409866, -0.0009347208542749286, -0.030324986204504967, 0.0009633139125071466, -0.013288966380059719, -0.0516309030354023, 0.000268740754108876, -0.026360081508755684, 0.0039839670062065125, 0.02166537195444107, -0.03311349079012871, -0.002544782590121031, 0.046010322868824005, -0.04219791293144226, 0.019857201725244522, 0.007063847966492176, -0.06313348561525345, 0.018288668245077133, 0.013278073631227016, -0.001277837553061545, -0.02267838455736637, -0.019857201725244522, 0.05720791220664978, 0.0019239046378061175, -0.014149481430649757, 0.03524843975901604, -0.04117400944232941, 0.031131038442254066, 0.010217254981398582, -0.0215782318264246, -0.011764002963900566, 0.003847809275612235, 0.0355098620057106, -0.0431564636528492, -0.07036616653203964, -0.03082604520022869, 0.028691096231341362, -0.012210599146783352, -0.03058640845119953, -0.04731743410229683, 0.013321644626557827, -0.056990060955286026, 0.03365812078118324, -0.012341310270130634, 0.024050850421190262, -0.02524903602898121, 0.00417731050401926, -0.02178519032895565, 0.020870212465524673, -0.0034012128598988056, -0.005980034824460745, -0.01345235574990511, -0.06139066815376282, -0.009716195054352283, 0.03206780180335045, 0.044921062886714935, 0.035597000271081924, 0.05019307881593704, -0.02032558247447014, -0.03143602982163429, 0.11363155394792557, -0.08400369435548782, -0.002802120288833976, -0.004106508567929268, -0.0726318284869194, -0.024878688156604767, 0.018288668245077133, -0.00822935625910759, -0.038625143468379974, 0.01551105547696352, 0.02424691803753376, 0.0018748879665508866, 0.05659792572259903, -0.02727505937218666, 0.06483272463083267, 0.06256707012653351, -0.0011062792036682367, 0.0021744342520833015, 0.029475362971425056, 0.04333074390888214, 0.0674033835530281, -0.030281415209174156, 0.03803694248199463, -0.021970365196466446, -0.011426332406699657, 0.016404248774051666, -0.021327702328562737, 0.02742755599319935, 0.010347966104745865, -0.04291682690382004, 0.01686173863708973, 0.01184025127440691, -0.006900459062308073, 0.04696886986494064, 0.023767642676830292, 0.05542152374982834, -0.010990628972649574, 0.0007536314660683274, 0.040520455688238144, 0.03442060202360153, -0.0629156306385994, -0.04784027859568596, 0.01131740678101778, 0.005201214458793402, 0.02537974715232849, 0.024747977033257484, -0.002773527055978775, 0.05006236955523491, 0.06579127907752991, 0.005729505326598883, -0.008479885756969452, -0.03339669853448868, -0.030934970825910568, 0.0589071549475193, -0.028102897107601166, -0.024072635918855667, 0.1004732996225357, -0.05912500619888306, -0.00400575203821063, 0.01831045374274254, 0.018615445122122765, 0.02533617615699768, -0.04587961360812187, -0.026316510513424873, 0.016556745395064354, -0.05437583476305008, 0.06513772159814835, -0.0019497745670378208, 0.022852664813399315, -0.038015156984329224, 0.027078991755843163, 0.06139066815376282, -0.013866273686289787, 0.01771136000752449, 0.020064160227775574, -0.010658404789865017, -0.022199109196662903, -0.010157344862818718, -0.03764481097459793, -0.012265062890946865, -0.008283819071948528, -0.06570413708686829, 0.008267479948699474, -0.015358559787273407, 0.055726516991853714, -0.001524963416159153, 0.05058521404862404, 0.037862662225961685, -0.03703482449054718, 0.044311076402664185, -0.028821807354688644, 0.008779431693255901, 0.01264630351215601, -0.024334058165550232, 0.010533140040934086, -0.02065236121416092, -0.0049724699929356575, 0.03167566657066345, -0.013376107439398766, 0.036969467997550964, -0.025924377143383026, -0.01912739686667919, -0.01968291960656643, -0.002502573886886239, 0.030564622953534126, 0.03784087672829628, -0.024900473654270172, 0.010282610543072224, 0.021120741963386536, -0.05232802778482437, 0.002306506969034672, -0.05537795647978783, 0.004226326942443848, 0.04054224118590355, -0.03614163026213646, -0.020968245342373848, -0.06156494840979576, -0.008419976569712162, -0.030717119574546814, 0.02259124256670475, -0.017820285633206367, -0.038472648710012436, 0.028538599610328674, -0.03646840900182724, -0.005822092294692993, -0.032656002789735794, -0.006655375938862562, 0.05333014577627182, 0.014933748170733452, 0.014574293047189713, -0.02036915346980095, 0.07838311791419983, -0.0012921341694891453, -0.03178459405899048, -0.006704392377287149, 0.031610313802957535, 0.014127695932984352, -0.027732547372579575, 0.07572532445192337, 0.0005517780664376915, -0.03278671205043793, 0.03742695972323418, -0.04892953857779503, 0.025074753910303116, 0.00008007759606698528, -0.005331925582140684, -0.055334385484457016, 0.007559461053460836, 0.04470321163535118, -0.02267838455736637, -0.01650228165090084, 0.01548927091062069, -0.01747172325849533, 0.007412411272525787, -0.0029001536313444376, -0.0560750812292099, 0.019105613231658936, 0.024377629160881042, 0.013310751877725124, 0.011546150781214237, 0.01626264490187168, -0.05450654774904251, 0.037383388727903366, 0.023026946932077408, 0.04740457609295845, -0.021436627954244614, -0.008801217190921307, -0.009367631748318672, 0.04688173159956932, -0.059647854417562485, -0.010429659858345985, -0.017689574509859085, -0.021088065579533577, -0.08173803985118866, 0.006639036815613508, -0.026076873764395714, -0.08918856829404831, -0.03041212633252144, 0.012907725758850574, 0.046010322868824005, 0.01050590816885233, -0.01107232365757227, 0.08252230286598206, 0.036403052508831024, -0.0009265514090657234, -0.03740517422556877, 0.0786881074309349, 0.00031537466566078365, -0.07655315846204758, -0.0027667193207889795, 0.00435703806579113, -0.032612431794404984, 0.011328299529850483, -0.043025750666856766, 0.029017874971032143, -0.010315287858247757, -0.0038695945404469967, -0.016317108646035194, -0.02633829601109028, 0.03069533407688141, 0.024660836905241013, -0.03400668129324913, 0.045400336384773254, 0.010963397100567818, -0.009345847181975842, -0.0031534063164144754, 0.014378226362168789, -0.0020736779551953077, -0.06400489062070847, 0.026774000376462936, -0.00130574987269938, -0.02553224377334118, -0.0016189119778573513, 0.02557581476867199, -0.033788830041885376, 0.0007897131727077067, 0.02941000834107399, 0.028255391865968704, -0.050367362797260284, -0.013430570252239704, -0.07406964898109436, 0.012265062890946865, -0.03651197999715805, 0.009002730250358582, 0.006421185098588467, 0.01751529425382614, -0.036119844764471054, 0.01456340029835701, 0.049190960824489594, -0.061259955167770386, 0.00612163869664073, -0.02259124256670475, 0.026926495134830475, 0.08099734038114548, -0.02956250309944153, 0.03707839548587799, 0.038908351212739944, -0.009645393118262291, -0.007488659583032131, -0.002608776558190584, 0.007461427710950375, 0.06313348561525345, -0.020151302218437195, -0.010898041538894176, -0.047099582850933075, -0.013561281375586987, -0.02307051792740822, 0.035117726773023605, -0.031523171812295914, 0.04958309605717659, -0.0007066571270115674, -0.049757376313209534, 0.03474738076329231, 0.005187598522752523, 0.03202423080801964, -0.013321644626557827, 0.010037526488304138, 0.005882001481950283, -0.0005017401999793947, -0.004493195563554764, -0.026207584887742996, -0.059604283422231674, 0.005587901454418898, -0.025641169399023056, 0.01351771131157875, 0.0049561308696866035, -0.028495030477643013, 0.03193708881735802, 0.029998207464814186, 0.06139066815376282 ]
30,894
networkx.algorithms.tree.branchings
maximum_spanning_arborescence
Returns a maximum spanning arborescence from G. Parameters ---------- G : (multi)digraph-like The graph to be searched. attr : str The edge attribute used to in determining optimality. default : float The value of the edge attribute used if an edge does not have the attribute `attr`. preserve_attrs : bool If True, preserve the other attributes of the original graph (that are not passed to `attr`) partition : str The key for the edge attribute containing the partition data on the graph. Edges can be included, excluded or open using the `EdgePartition` enum. Returns ------- B : (multi)digraph-like A maximum spanning arborescence. Raises ------ NetworkXException If the graph does not contain a maximum spanning arborescence.
@nx._dispatchable(preserve_edge_attrs=True, returns_graph=True) def maximum_branching( G, attr="weight", default=1, preserve_attrs=False, partition=None, ): ####################################### ### Data Structure Helper Functions ### ####################################### def edmonds_add_edge(G, edge_index, u, v, key, **d): """ Adds an edge to `G` while also updating the edge index. This algorithm requires the use of an external dictionary to track the edge keys since it is possible that the source or destination node of an edge will be changed and the default key-handling capabilities of the MultiDiGraph class do not account for this. Parameters ---------- G : MultiDiGraph The graph to insert an edge into. edge_index : dict A mapping from integers to the edges of the graph. u : node The source node of the new edge. v : node The destination node of the new edge. key : int The key to use from `edge_index`. d : keyword arguments, optional Other attributes to store on the new edge. """ if key in edge_index: uu, vv, _ = edge_index[key] if (u != uu) or (v != vv): raise Exception(f"Key {key!r} is already in use.") G.add_edge(u, v, key, **d) edge_index[key] = (u, v, G.succ[u][v][key]) def edmonds_remove_node(G, edge_index, n): """ Remove a node from the graph, updating the edge index to match. Parameters ---------- G : MultiDiGraph The graph to remove an edge from. edge_index : dict A mapping from integers to the edges of the graph. n : node The node to remove from `G`. """ keys = set() for keydict in G.pred[n].values(): keys.update(keydict) for keydict in G.succ[n].values(): keys.update(keydict) for key in keys: del edge_index[key] G.remove_node(n) ####################### ### Algorithm Setup ### ####################### # Pick an attribute name that the original graph is unlikly to have candidate_attr = "edmonds' secret candidate attribute" new_node_base_name = "edmonds new node base name " G_original = G G = nx.MultiDiGraph() G.__networkx_cache__ = None # Disable caching # A dict to reliably track mutations to the edges using the key of the edge. G_edge_index = {} # Each edge is given an arbitrary numerical key for key, (u, v, data) in enumerate(G_original.edges(data=True)): d = {attr: data.get(attr, default)} if data.get(partition) is not None: d[partition] = data.get(partition) if preserve_attrs: for d_k, d_v in data.items(): if d_k != attr: d[d_k] = d_v edmonds_add_edge(G, G_edge_index, u, v, key, **d) level = 0 # Stores the number of contracted nodes # These are the buckets from the paper. # # In the paper, G^i are modified versions of the original graph. # D^i and E^i are the nodes and edges of the maximal edges that are # consistent with G^i. In this implementation, D^i and E^i are stored # together as the graph B^i. We will have strictly more B^i then the # paper will have. # # Note that the data in graphs and branchings are tuples with the graph as # the first element and the edge index as the second. B = nx.MultiDiGraph() B_edge_index = {} graphs = [] # G^i list branchings = [] # B^i list selected_nodes = set() # D^i bucket uf = nx.utils.UnionFind() # A list of lists of edge indices. Each list is a circuit for graph G^i. # Note the edge list is not required to be a circuit in G^0. circuits = [] # Stores the index of the minimum edge in the circuit found in G^i and B^i. # The ordering of the edges seems to preserver the weight ordering from # G^0. So even if the circuit does not form a circuit in G^0, it is still # true that the minimum edges in circuit G^0 (despite their weights being # different) minedge_circuit = [] ########################### ### Algorithm Structure ### ########################### # Each step listed in the algorithm is an inner function. Thus, the overall # loop structure is: # # while True: # step_I1() # if cycle detected: # step_I2() # elif every node of G is in D and E is a branching: # break ################################## ### Algorithm Helper Functions ### ################################## def edmonds_find_desired_edge(v): """ Find the edge directed towards v with maximal weight. If an edge partition exists in this graph, return the included edge if it exists and never return any excluded edge. Note: There can only be one included edge for each vertex otherwise the edge partition is empty. Parameters ---------- v : node The node to search for the maximal weight incoming edge. """ edge = None max_weight = -INF for u, _, key, data in G.in_edges(v, data=True, keys=True): # Skip excluded edges if data.get(partition) == nx.EdgePartition.EXCLUDED: continue new_weight = data[attr] # Return the included edge if data.get(partition) == nx.EdgePartition.INCLUDED: max_weight = new_weight edge = (u, v, key, new_weight, data) break # Find the best open edge if new_weight > max_weight: max_weight = new_weight edge = (u, v, key, new_weight, data) return edge, max_weight def edmonds_step_I2(v, desired_edge, level): """ Perform step I2 from Edmonds' paper First, check if the last step I1 created a cycle. If it did not, do nothing. If it did, store the cycle for later reference and contract it. Parameters ---------- v : node The current node to consider desired_edge : edge The minimum desired edge to remove from the cycle. level : int The current level, i.e. the number of cycles that have already been removed. """ u = desired_edge[0] Q_nodes = nx.shortest_path(B, v, u) Q_edges = [ list(B[Q_nodes[i]][vv].keys())[0] for i, vv in enumerate(Q_nodes[1:]) ] Q_edges.append(desired_edge[2]) # Add the new edge key to complete the circuit # Get the edge in the circuit with the minimum weight. # Also, save the incoming weights for each node. minweight = INF minedge = None Q_incoming_weight = {} for edge_key in Q_edges: u, v, data = B_edge_index[edge_key] w = data[attr] # We cannot remove an included edge, even if it is the # minimum edge in the circuit Q_incoming_weight[v] = w if data.get(partition) == nx.EdgePartition.INCLUDED: continue if w < minweight: minweight = w minedge = edge_key circuits.append(Q_edges) minedge_circuit.append(minedge) graphs.append((G.copy(), G_edge_index.copy())) branchings.append((B.copy(), B_edge_index.copy())) # Mutate the graph to contract the circuit new_node = new_node_base_name + str(level) G.add_node(new_node) new_edges = [] for u, v, key, data in G.edges(data=True, keys=True): if u in Q_incoming_weight: if v in Q_incoming_weight: # Circuit edge. For the moment do nothing, # eventually it will be removed. continue else: #
(G, attr='weight', default=1, preserve_attrs=False, partition=None, *, backend=None, **backend_kwargs)
[ 0.05934286117553711, 0.015630874782800674, -0.03579306975007057, 0.014857499860227108, -0.035684142261743546, -0.05433226749300957, -0.04394073039293289, -0.04126115143299103, 0.017765823751688004, -0.07045330852270126, -0.031239964067935944, 0.05241516977548599, 0.004386992659419775, 0.022416962310671806, -0.04836312308907509, -0.0001257754338439554, -0.015445699915289879, 0.006764301564544439, 0.04797099158167839, 0.03906084597110748, -0.020837534219026566, -0.07106329500675201, -0.003205146174877882, 0.07454892247915268, 0.013332536444067955, 0.020510757341980934, 0.013180040754377842, 0.023702288046479225, -0.00812587607651949, -0.004937069024890661, -0.03106568194925785, -0.04971380531787872, -0.02666507288813591, -0.041130442172288895, 0.047143153846263885, 0.02803754061460495, 0.04012832045555115, 0.03906084597110748, -0.12574411928653717, -0.03991046920418739, -0.022253572940826416, -0.02259124256670475, 0.012929510325193405, -0.04128293693065643, 0.04450714588165283, 0.022286251187324524, 0.028582170605659485, 0.07711957395076752, 0.009111655876040459, -0.011709540151059628, 0.019693812355399132, -0.048145271837711334, 0.03411560878157616, 0.03853800147771835, -0.0033440268598496914, 0.015282311476767063, 0.000021572444893536158, 0.018386701121926308, 0.056815776973962784, -0.05816645920276642, -0.00729259243234992, -0.008425422944128513, 0.04010653495788574, -0.02278731018304825, -0.0625234991312027, 0.012177921831607819, -0.040847234427928925, -0.02415977604687214, -0.04967023432254791, 0.031610313802957535, 0.0031969768460839987, -0.03642483800649643, 0.02000969834625721, -0.014694111421704292, -0.042742542922496796, -0.026926495134830475, -0.0015413023065775633, -0.023026946932077408, -0.014705004170536995, -0.02670864388346672, 0.06783908605575562, -0.017613327130675316, 0.02605508826673031, -0.056467216461896896, 0.029998207464814186, -0.010887148790061474, 0.04300396516919136, 0.061739232391119, 0.0019143735989928246, -0.09698767215013504, -0.03760123997926712, 0.02178519032895565, 0.01657853089272976, 0.08343727886676788, 0.06949476152658463, 0.018147064372897148, -0.03337491303682327, -0.039757974445819855, 0.04587961360812187, -0.010375197045505047, -0.012798799201846123, 0.03977975994348526, -0.07589960843324661, -0.01751529425382614, -0.04779670760035515, -0.055290814489126205, -0.034072037786245346, 0.017842071130871773, -0.03997582569718361, -0.09175922721624374, -0.0701918825507164, 0.01953042298555374, 0.006432077381759882, 0.011360976845026016, 0.009160672314465046, 0.056467216461896896, -0.012352203018963337, -0.008049627766013145, 0.03328777104616165, 0.008665059693157673, 0.02339729480445385, -0.033875972032547, -0.03908263146877289, -0.009966724552214146, 0.016959771513938904, -0.014977319166064262, 0.03936583921313286, 0.014236622489988804, 0.03017248958349228, -0.02742755599319935, 0.001910288934595883, -0.029911067336797714, -0.018408486619591713, 0.04522605612874031, -0.036816973239183426, -0.03771016374230385, -0.07537676393985748, 0.004318913910537958, 0.015097137540578842, -0.001639335649088025, 0.03041212633252144, -0.038995493203401566, 0.04470321163535118, 0.016611207276582718, 0.005269293207675219, -0.036686260253190994, 0.020358260720968246, -0.02912680059671402, 0.00255567510612309, 0.001967475051060319, -0.008893804624676704, -0.018887760117650032, -0.020282013341784477, -0.006791533436626196, 0.02481333166360855, 0.03121817857027054, -0.05132590979337692, 0.015587303787469864, -0.04749171435832977, 0.014552507549524307, -0.04293861240148544, -0.027950400486588478, 0.011077769100666046, 0.017656898126006126, -0.0016951601719483733, -0.014824822545051575, 0.014258407056331635, -0.013822703622281551, -0.061259955167770386, 0.03137067332863808, 0.006377614568918943, -0.003918610978871584, -0.0851365253329277, -0.006780640687793493, -0.025183681398630142, 0.09419916570186615, 0.04513891413807869, -0.0278414748609066, 0.01236309576779604, 0.002110440284013748, -0.006018158979713917, -0.023331940174102783, 0.045923180878162384, 0.011524366214871407, 0.02880002185702324, -0.001371786231175065, 0.037492312490940094, -0.01641514152288437, 0.05237159878015518, -0.010211808606982231, -0.020118623971939087, -0.07245754450559616, 0.023593362420797348, 0.015413022600114346, 0.014214836992323399, 0.0185609832406044, 0.04228505492210388, 0.045443907380104065, -0.0055987942032516, 0.05620579421520233, -0.0021553724072873592, 0.0003000569704454392, 0.055857229977846146, -0.008305603638291359, 0.016491388902068138, 0.020271120592951775, -0.0027966739144176245, -0.031000327318906784, 0.0075376760214567184, 0.007276253774762154, -0.050323791801929474, 0.02038004621863365, 0.03049926646053791, 0.00801150407642126, 0.010544032789766788, -0.017537077888846397, -0.02973678521811962, 0.04078187793493271, 0.04285147041082382, -0.04272076115012169, -0.05760004371404648, 0.0007311654626391828, 0.018212419003248215, 0.01066929753869772, 0.030804259702563286, -0.077468141913414, 0.05394013226032257, 0.02472619153559208, 0.05193589627742767, -0.009629053995013237, 0.045966751873493195, -0.024639051407575607, 0.02908322960138321, -0.027209702879190445, 0.02339729480445385, -0.01207988802343607, -0.057905036956071854, 0.0001592191110830754, -0.009422095492482185, 0.03097854182124138, -0.021806975826621056, -0.05873287469148636, -0.03784087672829628, 0.018049031496047974, 0.030717119574546814, -0.030934970825910568, 0.07594317197799683, 0.01543480809777975, 0.0003877083072438836, 0.0004251516074873507, -0.05550866574048996, -0.0649634376168251, -0.010603941977024078, -0.029780356213450432, 0.013909844681620598, -0.02481333166360855, -0.036816973239183426, -0.036642689257860184, -0.01276612188667059, -0.027100777253508568, 0.009961278177797794, -0.007042062934488058, -0.04036795720458031, 0.04849383607506752, 0.015990329906344414, 0.03662090748548508, 0.035117726773023605, 0.008643274195492268, -0.024747977033257484, 0.006856888998299837, 0.09498342871665955, -0.011753110215067863, 0.005331925582140684, 0.028059326112270355, -0.0701918825507164, -0.029475362971425056, -0.018495626747608185, 0.0018449333729222417, -0.03300456330180168, -0.05672863870859146, -0.08574651181697845, -0.006159762851893902, -0.015630874782800674, 0.04853740707039833, -0.060214266180992126, 0.031327106058597565, -0.021251453086733818, -0.07755527645349503, -0.01032618060708046, -0.012820584699511528, 0.004136463161557913, -0.01010288204997778, 0.02162180282175541, 0.03973618894815445, 0.07494105398654938, -0.016927093267440796, 0.022525887936353683, -0.03888656571507454, 0.0029028765857219696, 0.04888596758246422, 0.04897310957312584, -0.051456619054079056, 0.030237844213843346, -0.037100180983543396, -0.01875704899430275, -0.005920125637203455, 0.05119519680738449, -0.02254767343401909, 0.0017768546240404248, 0.02089199796319008, -0.037209104746580124, 0.04736100509762764, -0.011546150781214237, 0.02723148837685585, -0.004030260257422924, -0.04433286190032959, 0.0071945590898394585, -0.01254826970398426, 0.04744814708828926, 0.051979467272758484, -0.006039944011718035, 0.0467945896089077, -0.05128233879804611, 0.03097854182124138, -0.10108328610658646, -0.014955533668398857, 0.03718731924891472, 0.04723029211163521, 0.019780952483415604, -0.033745259046554565, -0.02557581476867199, 0.030804259702563286, 0.010968843474984169, -0.0004152801993768662, -0.04627174511551857, 0.026360081508755684, 0.06849264353513718, -0.03352740779519081, 0.009678071364760399, -0.05350442975759506, 0.046446025371551514, 0.08038735389709473, 0.018953116610646248, 0.029627859592437744, 0.000499357411172241, -0.013702885247766972, 0.04736100509762764, 0.02199215069413185, -0.03925691545009613, 0.016850845888257027, -0.00033835123758763075, 0.0923692062497139, -0.025967948138713837, 0.008899250067770481, 0.0009136164444498718, -0.028342533856630325, -0.02581545151770115, -0.0215891245752573, 0.011622399091720581, 0.03391954302787781, -0.019573993980884552, 0.0017346458043903112, -0.017852963879704475, 0.034311674535274506, 0.006029051728546619, 0.0027422108687460423, -0.025510458275675774, 0.03167566657066345, 0.06261064112186432, -0.07559461146593094, 0.010075651109218597, -0.07803455740213394, 0.011350084096193314, 0.04300396516919136, -0.016121041029691696, 0.0621313638985157, -0.05938643217086792, -0.006464755162596703, 0.038385506719350815, 0.049234531819820404, -0.0032868406269699335, -0.01022270042449236, -0.01069108210504055, 0.01981363072991371, 0.013822703622281551, -0.013790025375783443, 0.10587602853775024, -0.011916499584913254, 0.05176161229610443, -0.01791832037270069, 0.012918618507683277, -0.028168251737952232, -0.006464755162596703, 0.003981243818998337, -0.03675161674618721, 0.013223610818386078, 0.08021306991577148, -0.009149780496954918, -0.03204601630568504, -0.016872629523277283, -0.037579454481601715, 0.061303526163101196, -0.006998492404818535, 0.017569756135344505, 0.013103792443871498, -0.0609113946557045, 0.06369990110397339, 0.05280730128288269, 0.024094421416521072, 0.021839654073119164, -0.021273238584399223, 0.05028022080659866, -0.04631531611084938, 0.019225431606173515, -0.023375509306788445, -0.048711687326431274, 0.07162971049547195, -0.02775433287024498, 0.051413051784038544, -0.04566175863146782, 0.04862454533576965, 0.021393056958913803, 0.05973499268293381, -0.04675101861357689, -0.030521051958203316, -0.044354647397994995, -0.004365207627415657, 0.005078672431409359, -0.054811540991067886, 0.05455011874437332, -0.0074995518662035465, -0.04775313660502434, 0.001688352320343256, -0.023135872557759285, -0.015097137540578842, -0.02594616264104843, -0.004259004723280668, 0.0028865376953035593, 0.051500190049409866, -0.0009347208542749286, -0.030324986204504967, 0.0009633139125071466, -0.013288966380059719, -0.0516309030354023, 0.000268740754108876, -0.026360081508755684, 0.0039839670062065125, 0.02166537195444107, -0.03311349079012871, -0.002544782590121031, 0.046010322868824005, -0.04219791293144226, 0.019857201725244522, 0.007063847966492176, -0.06313348561525345, 0.018288668245077133, 0.013278073631227016, -0.001277837553061545, -0.02267838455736637, -0.019857201725244522, 0.05720791220664978, 0.0019239046378061175, -0.014149481430649757, 0.03524843975901604, -0.04117400944232941, 0.031131038442254066, 0.010217254981398582, -0.0215782318264246, -0.011764002963900566, 0.003847809275612235, 0.0355098620057106, -0.0431564636528492, -0.07036616653203964, -0.03082604520022869, 0.028691096231341362, -0.012210599146783352, -0.03058640845119953, -0.04731743410229683, 0.013321644626557827, -0.056990060955286026, 0.03365812078118324, -0.012341310270130634, 0.024050850421190262, -0.02524903602898121, 0.00417731050401926, -0.02178519032895565, 0.020870212465524673, -0.0034012128598988056, -0.005980034824460745, -0.01345235574990511, -0.06139066815376282, -0.009716195054352283, 0.03206780180335045, 0.044921062886714935, 0.035597000271081924, 0.05019307881593704, -0.02032558247447014, -0.03143602982163429, 0.11363155394792557, -0.08400369435548782, -0.002802120288833976, -0.004106508567929268, -0.0726318284869194, -0.024878688156604767, 0.018288668245077133, -0.00822935625910759, -0.038625143468379974, 0.01551105547696352, 0.02424691803753376, 0.0018748879665508866, 0.05659792572259903, -0.02727505937218666, 0.06483272463083267, 0.06256707012653351, -0.0011062792036682367, 0.0021744342520833015, 0.029475362971425056, 0.04333074390888214, 0.0674033835530281, -0.030281415209174156, 0.03803694248199463, -0.021970365196466446, -0.011426332406699657, 0.016404248774051666, -0.021327702328562737, 0.02742755599319935, 0.010347966104745865, -0.04291682690382004, 0.01686173863708973, 0.01184025127440691, -0.006900459062308073, 0.04696886986494064, 0.023767642676830292, 0.05542152374982834, -0.010990628972649574, 0.0007536314660683274, 0.040520455688238144, 0.03442060202360153, -0.0629156306385994, -0.04784027859568596, 0.01131740678101778, 0.005201214458793402, 0.02537974715232849, 0.024747977033257484, -0.002773527055978775, 0.05006236955523491, 0.06579127907752991, 0.005729505326598883, -0.008479885756969452, -0.03339669853448868, -0.030934970825910568, 0.0589071549475193, -0.028102897107601166, -0.024072635918855667, 0.1004732996225357, -0.05912500619888306, -0.00400575203821063, 0.01831045374274254, 0.018615445122122765, 0.02533617615699768, -0.04587961360812187, -0.026316510513424873, 0.016556745395064354, -0.05437583476305008, 0.06513772159814835, -0.0019497745670378208, 0.022852664813399315, -0.038015156984329224, 0.027078991755843163, 0.06139066815376282, -0.013866273686289787, 0.01771136000752449, 0.020064160227775574, -0.010658404789865017, -0.022199109196662903, -0.010157344862818718, -0.03764481097459793, -0.012265062890946865, -0.008283819071948528, -0.06570413708686829, 0.008267479948699474, -0.015358559787273407, 0.055726516991853714, -0.001524963416159153, 0.05058521404862404, 0.037862662225961685, -0.03703482449054718, 0.044311076402664185, -0.028821807354688644, 0.008779431693255901, 0.01264630351215601, -0.024334058165550232, 0.010533140040934086, -0.02065236121416092, -0.0049724699929356575, 0.03167566657066345, -0.013376107439398766, 0.036969467997550964, -0.025924377143383026, -0.01912739686667919, -0.01968291960656643, -0.002502573886886239, 0.030564622953534126, 0.03784087672829628, -0.024900473654270172, 0.010282610543072224, 0.021120741963386536, -0.05232802778482437, 0.002306506969034672, -0.05537795647978783, 0.004226326942443848, 0.04054224118590355, -0.03614163026213646, -0.020968245342373848, -0.06156494840979576, -0.008419976569712162, -0.030717119574546814, 0.02259124256670475, -0.017820285633206367, -0.038472648710012436, 0.028538599610328674, -0.03646840900182724, -0.005822092294692993, -0.032656002789735794, -0.006655375938862562, 0.05333014577627182, 0.014933748170733452, 0.014574293047189713, -0.02036915346980095, 0.07838311791419983, -0.0012921341694891453, -0.03178459405899048, -0.006704392377287149, 0.031610313802957535, 0.014127695932984352, -0.027732547372579575, 0.07572532445192337, 0.0005517780664376915, -0.03278671205043793, 0.03742695972323418, -0.04892953857779503, 0.025074753910303116, 0.00008007759606698528, -0.005331925582140684, -0.055334385484457016, 0.007559461053460836, 0.04470321163535118, -0.02267838455736637, -0.01650228165090084, 0.01548927091062069, -0.01747172325849533, 0.007412411272525787, -0.0029001536313444376, -0.0560750812292099, 0.019105613231658936, 0.024377629160881042, 0.013310751877725124, 0.011546150781214237, 0.01626264490187168, -0.05450654774904251, 0.037383388727903366, 0.023026946932077408, 0.04740457609295845, -0.021436627954244614, -0.008801217190921307, -0.009367631748318672, 0.04688173159956932, -0.059647854417562485, -0.010429659858345985, -0.017689574509859085, -0.021088065579533577, -0.08173803985118866, 0.006639036815613508, -0.026076873764395714, -0.08918856829404831, -0.03041212633252144, 0.012907725758850574, 0.046010322868824005, 0.01050590816885233, -0.01107232365757227, 0.08252230286598206, 0.036403052508831024, -0.0009265514090657234, -0.03740517422556877, 0.0786881074309349, 0.00031537466566078365, -0.07655315846204758, -0.0027667193207889795, 0.00435703806579113, -0.032612431794404984, 0.011328299529850483, -0.043025750666856766, 0.029017874971032143, -0.010315287858247757, -0.0038695945404469967, -0.016317108646035194, -0.02633829601109028, 0.03069533407688141, 0.024660836905241013, -0.03400668129324913, 0.045400336384773254, 0.010963397100567818, -0.009345847181975842, -0.0031534063164144754, 0.014378226362168789, -0.0020736779551953077, -0.06400489062070847, 0.026774000376462936, -0.00130574987269938, -0.02553224377334118, -0.0016189119778573513, 0.02557581476867199, -0.033788830041885376, 0.0007897131727077067, 0.02941000834107399, 0.028255391865968704, -0.050367362797260284, -0.013430570252239704, -0.07406964898109436, 0.012265062890946865, -0.03651197999715805, 0.009002730250358582, 0.006421185098588467, 0.01751529425382614, -0.036119844764471054, 0.01456340029835701, 0.049190960824489594, -0.061259955167770386, 0.00612163869664073, -0.02259124256670475, 0.026926495134830475, 0.08099734038114548, -0.02956250309944153, 0.03707839548587799, 0.038908351212739944, -0.009645393118262291, -0.007488659583032131, -0.002608776558190584, 0.007461427710950375, 0.06313348561525345, -0.020151302218437195, -0.010898041538894176, -0.047099582850933075, -0.013561281375586987, -0.02307051792740822, 0.035117726773023605, -0.031523171812295914, 0.04958309605717659, -0.0007066571270115674, -0.049757376313209534, 0.03474738076329231, 0.005187598522752523, 0.03202423080801964, -0.013321644626557827, 0.010037526488304138, 0.005882001481950283, -0.0005017401999793947, -0.004493195563554764, -0.026207584887742996, -0.059604283422231674, 0.005587901454418898, -0.025641169399023056, 0.01351771131157875, 0.0049561308696866035, -0.028495030477643013, 0.03193708881735802, 0.029998207464814186, 0.06139066815376282 ]
30,895
networkx.algorithms.tree.mst
maximum_spanning_edges
Generate edges in a maximum spanning forest of an undirected weighted graph. A maximum spanning tree is a subgraph of the graph (a tree) with the maximum possible sum of edge weights. A spanning forest is a union of the spanning trees for each connected component of the graph. Parameters ---------- G : undirected Graph An undirected graph. If `G` is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found. algorithm : string The algorithm to use when finding a maximum spanning tree. Valid choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'. weight : string Edge data key to use for weight (default 'weight'). keys : bool Whether to yield edge key in multigraphs in addition to the edge. If `G` is not a multigraph, this is ignored. data : bool, optional If True yield the edge data along with the edge. ignore_nan : bool (default: False) If a NaN is found as an edge weight normally an exception is raised. If `ignore_nan is True` then that edge is ignored instead. Returns ------- edges : iterator An iterator over edges in a maximum spanning tree of `G`. Edges connecting nodes `u` and `v` are represented as tuples: `(u, v, k, d)` or `(u, v, k)` or `(u, v, d)` or `(u, v)` If `G` is a multigraph, `keys` indicates whether the edge key `k` will be reported in the third position in the edge tuple. `data` indicates whether the edge datadict `d` will appear at the end of the edge tuple. If `G` is not a multigraph, the tuples are `(u, v, d)` if `data` is True or `(u, v)` if `data` is False. Examples -------- >>> from networkx.algorithms import tree Find maximum spanning edges by Kruskal's algorithm >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> mst = tree.maximum_spanning_edges(G, algorithm="kruskal", data=False) >>> edgelist = list(mst) >>> sorted(sorted(e) for e in edgelist) [[0, 1], [0, 3], [1, 2]] Find maximum spanning edges by Prim's algorithm >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) # assign weight 2 to edge 0-3 >>> mst = tree.maximum_spanning_edges(G, algorithm="prim", data=False) >>> edgelist = list(mst) >>> sorted(sorted(e) for e in edgelist) [[0, 1], [0, 3], [2, 3]] Notes ----- For Borůvka's algorithm, each edge must have a weight attribute, and each edge weight must be distinct. For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used. Modified code from David Eppstein, April 2006 http://www.ics.uci.edu/~eppstein/PADS/
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, algorithm='kruskal', weight='weight', keys=True, data=True, ignore_nan=False, *, backend=None, **backend_kwargs)
[ -0.0005006426945328712, -0.029431641101837158, -0.02168872393667698, 0.0029356777667999268, 0.009683993645012379, 0.0067590102553367615, -0.048724763095378876, -0.054029304534196854, 0.07293742150068283, -0.02320736087858677, -0.025153785943984985, 0.03413727879524231, 0.011486039496958256, 0.041901588439941406, -0.05638212338089943, 0.03621203824877739, 0.030629439279437065, 0.0033206846565008163, 0.0363403744995594, 0.03221224620938301, -0.04275715723633766, -0.08222036808729172, 0.019239651039242744, 0.059676073491573334, -0.04132407531142235, -0.03343143314123154, -0.019335903227329254, -0.03770928829908371, -0.019646048545837402, 0.006523728370666504, -0.0037832276429980993, -0.059462178498506546, -0.08328983187675476, -0.037987351417541504, 0.01413830928504467, 0.0019410765962675214, 0.029902204871177673, 0.050820913165807724, -0.06600730121135712, -0.05869216471910477, -0.01999897137284279, -0.035527583211660385, 0.020908014848828316, -0.025153785943984985, 0.022694019600749016, 0.023121803998947144, 0.06968625634908676, 0.06532283872365952, -0.039120979607105255, -0.005149467382580042, 0.03266141936182976, -0.024768779054284096, -0.022886522114276886, 0.021175380796194077, -0.012748006731271744, 0.00654511759057641, 0.014523317106068134, -0.0066467165015637875, 0.0716540664434433, -0.04188019782304764, 0.04504580795764923, 0.006331224925816059, -0.008389942348003387, -0.00009800631960388273, -0.07901197671890259, -0.013346906751394272, -0.05672435462474823, -0.03623342886567116, -0.0181701872497797, 0.025538792833685875, 0.0015333435731008649, -0.020512312650680542, 0.04821142181754112, 0.006769705098122358, 0.017400173470377922, 0.02414849027991295, 0.005197593476623297, -0.04962311312556267, -0.020138001069426537, -0.013058151118457317, 0.07037071138620377, -0.02485433593392372, 0.03623342886567116, -0.026137692853808403, 0.04919533059000969, -0.012608977034687996, 0.029260525479912758, 0.04624360799789429, 0.018202271312475204, -0.08363205939531326, -0.025774074718356133, -0.003216411918401718, 0.04143102094531059, 0.051248699426651, 0.04641472175717354, 0.018351996317505836, -0.011250757612287998, -0.07058460265398026, -0.025410456582903862, -0.03467201068997383, -0.013977889902889729, 0.0681462287902832, -0.02825522981584072, 0.014491233043372631, -0.01138978824019432, -0.034393951296806335, -0.03899264708161354, 0.0386076383292675, -0.006496991962194443, -0.04958033561706543, -0.05086369067430496, 0.01855519413948059, 0.022009562700986862, 0.004764460492879152, 0.010256156325340271, 0.011207979172468185, -0.02485433593392372, 0.006935472134500742, 0.007454161997884512, 0.04359133914113045, 0.03413727879524231, 0.020597869530320168, -0.021774280816316605, 0.008149312809109688, -0.00018030489445663989, -0.03167751431465149, 0.05035034939646721, -0.002622859552502632, 0.013400379568338394, -0.01310092955827713, 0.044190239161252975, 0.02919635735452175, 0.020672732964158058, 0.04868198558688164, 0.01884395070374012, -0.009507532231509686, -0.08222036808729172, -0.0014370918506756425, 0.05364429950714111, 0.030800553038716316, 0.004555915016680956, -0.1007862538099289, 0.044190239161252975, 0.014694430865347385, 0.04714195802807808, -0.01291912142187357, 0.006037122569978237, -0.0060585117898881435, 0.007908684201538563, 0.003743122797459364, 0.02472599968314171, -0.028811350464820862, 0.02547462470829487, -0.0008488867897540331, 0.007550413720309734, -0.015464444644749165, 0.01845894381403923, 0.0029249831568449736, -0.054200418293476105, 0.0027832791674882174, -0.012651755474507809, -0.003152244258671999, 0.02178497426211834, 0.027271322906017303, -0.002366188447922468, 0.01424525585025549, 0.023635147139430046, 0.028019947931170464, -0.04331327974796295, -0.032361969351768494, -0.01609542779624462, -0.0460297167301178, -0.10206961631774902, 0.03189140558242798, 0.019367987290024757, 0.015004575252532959, 0.02485433593392372, 0.010742762126028538, -0.012961899861693382, -0.0061333742924034595, 0.01395650114864111, -0.043612729758024216, 0.032083909958601, -0.007550413720309734, -0.021635249257087708, 0.03257586434483528, 0.06010385975241661, -0.020277030766010284, 0.019474932923913002, -0.010432617738842964, -0.02168872393667698, -0.07028514891862869, 0.01698308251798153, 0.0577082596719265, 0.04620083048939705, 0.02489711344242096, 0.00473505025729537, 0.0013996605994179845, -0.04996534436941147, 0.05372985452413559, 0.00246110325679183, -0.023784872144460678, 0.049837008118629456, 0.0021469483617693186, 0.015956398099660873, -0.008347163908183575, -0.01009573694318533, -0.005598642397671938, 0.022907912731170654, -0.0022044319193810225, -0.037987351417541504, -0.03150640055537224, 0.055526554584503174, 0.053216513246297836, -0.03390199691057205, -0.026351584121584892, -0.06480950117111206, 0.012288137339055538, 0.025217954069375992, -0.04145241156220436, -0.037067610770463943, -0.0006129363900981843, 0.01957118511199951, -0.008347163908183575, 0.06232834234833717, -0.05565489083528519, 0.012737312354147434, -0.004507789388298988, 0.03619065135717392, -0.03486451506614685, 0.09282944351434708, -0.02188122645020485, 0.047783635556697845, -0.02226623333990574, -0.025496013462543488, -0.08303315937519073, -0.03971987962722778, -0.030415546149015427, 0.02299346961081028, 0.01744295284152031, -0.032083909958601, -0.07571803033351898, -0.03112139366567135, 0.012694533914327621, 0.000025545978132868186, -0.007673401851207018, 0.011101032607257366, 0.015582085587084293, 0.036105092614889145, 0.00369767053052783, -0.08042366802692413, -0.06498061120510101, -0.006881998851895332, -0.03548480570316315, 0.0067322738468647, -0.028982466086745262, -0.0075771501287817955, 0.02262985147535801, -0.020041748881340027, 0.012416473589837551, 0.002919635735452175, -0.05133425444364548, -0.0467141717672348, 0.04034017026424408, -0.018972285091876984, -0.009208082221448421, 0.02885412983596325, 0.02410571090877056, -0.04151657968759537, -0.021421357989311218, 0.07961087673902512, 0.009929969906806946, 0.0037217335775494576, -0.007422077935189009, -0.030223043635487556, -0.026736591011285782, -0.030629439279437065, 0.08551431447267532, 0.003449020441621542, -0.02677937038242817, -0.044746361672878265, 0.017581982538104057, -0.0005237029981799424, 0.03073638677597046, -0.052874285727739334, 0.038885697722435, -0.028725793585181236, -0.046286389231681824, 0.024276824668049812, -0.024790167808532715, 0.011817573569715023, -0.05313095450401306, -0.0019143399549648166, 0.0204374510794878, 0.03394477814435959, 0.01744295284152031, -0.0032271065283566713, -0.04448968917131424, 0.008218828588724136, 0.05112036317586899, 0.052660390734672546, -0.01763545535504818, 0.04530248045921326, -0.015047353692352772, 0.012908426113426685, 0.06776122003793716, 0.05360151827335358, -0.0373028926551342, 0.002130906330421567, 0.015143605880439281, -0.09300056099891663, 0.008657308295369148, 0.03392338752746582, 0.021485524252057076, 0.0077268751338124275, -0.08649822324514389, -0.014566095545887947, -0.06053164228796959, 0.063611701130867, 0.011475345119833946, -0.03206251934170723, 0.049837008118629456, 0.006748315878212452, 0.028961075469851494, -0.0632694736123085, 0.010550258681178093, 0.01848033256828785, 0.08085145056247711, 0.020309114828705788, -0.014427064917981625, -0.0823059231042862, 0.0027832791674882174, 0.04697084426879883, 0.06194333732128143, -0.06528006494045258, 0.0625850111246109, 0.09180276095867157, -0.009234818629920483, 0.003662913106381893, -0.058863282203674316, 0.06806066632270813, 0.051548149436712265, -0.02108982391655445, 0.027249934151768684, -0.0060959430411458015, 0.013165097683668137, 0.03221224620938301, 0.013731913641095161, 0.006101290229707956, 0.023079026490449905, 0.010416575707495213, 0.07208184897899628, 0.010181293822824955, 0.013967195525765419, 0.0031468968372792006, 0.0026696487329900265, 0.010721373371779919, -0.023827649652957916, 0.011924520134925842, 0.02243734709918499, -0.031185559928417206, -0.002668311819434166, 0.019966887310147285, 0.02070481702685356, 0.01609542779624462, -0.011347009800374508, -0.017667539417743683, 0.062456678599119186, 0.02583824284374714, -0.0937705710530281, 0.02975247986614704, -0.11943770200014114, -0.04164491593837738, 0.07473412156105042, -0.0032271065283566713, 0.049665894359350204, -0.05638212338089943, -0.00447035813704133, 0.003058666130527854, 0.007496940437704325, 0.020523007959127426, 0.03670399263501167, 0.0017900147940963507, 0.053045399487018585, 0.048510871827602386, -0.05432875454425812, 0.08521486818790436, -0.0073204790242016315, 0.01884395070374012, -0.018255744129419327, -0.02958136424422264, -0.006037122569978237, 0.05261761322617531, 0.030030539259314537, -0.06836012005805969, 0.0170365571975708, 0.08200647681951523, 0.015357498079538345, -0.058863282203674316, 0.020394671708345413, 0.008523625321686268, -0.022565683349967003, -0.020736901089549065, 0.008304385468363762, 0.0013983238022774458, -0.061772219836711884, 0.013421769253909588, 0.020405367016792297, 0.045174144208431244, -0.010020874440670013, -0.06750454753637314, -0.00034523624344728887, 0.004997069016098976, 0.03700344264507294, -0.029260525479912758, -0.04359133914113045, 0.027955779805779457, 0.0340731143951416, 0.06823178380727768, -0.01957118511199951, 0.0719962939620018, -0.021774280816316605, 0.040810734033584595, 0.007518329657614231, 0.05313095450401306, -0.017100723460316658, -0.009561005048453808, -0.04170908406376839, -0.03563452884554863, 0.06322669237852097, -0.007641317788511515, -0.07434911280870438, 0.01111172791570425, -0.02041606232523918, 0.01997758075594902, -0.01633070968091488, -0.004280528519302607, 0.006042469758540392, 0.013977889902889729, 0.007694791071116924, -0.009769550524652004, 0.021817058324813843, -0.024255435913801193, -0.04337744787335396, 0.008577099069952965, -0.04979422688484192, -0.018319912254810333, 0.031591955572366714, -0.030650828033685684, -0.04224381595849991, 0.07486245781183243, -0.019817162305116653, 0.011550207622349262, -0.0001762944011716172, -0.08008144050836563, 0.035720087587833405, 0.004932901356369257, 0.0024410507176071405, -0.0728946402668953, 0.02583824284374714, 0.05313095450401306, -0.01178548950701952, -0.003272558795288205, 0.04709918051958084, -0.030479714274406433, -0.0222234558314085, 0.06788955628871918, -0.030800553038716316, -0.015464444644749165, -0.002197747817263007, 0.03790179267525673, -0.024041542783379555, -0.10129959881305695, -0.03315337374806404, 0.012748006731271744, 0.002836752450093627, -0.06438171118497849, -0.03736706078052521, -0.05308817699551582, -0.04198714345693588, 0.012566198594868183, -0.019528405740857124, 0.054970432072877884, 0.013389685191214085, -0.017207670956850052, -0.019624657928943634, 0.03249030560255051, 0.012202580459415913, 0.021410662680864334, -0.04200853407382965, -0.049280885607004166, -0.0554409958422184, 0.02979525737464428, 0.018031157553195953, -0.033474214375019073, 0.050992026925086975, -0.012031466700136662, -0.031399454921483994, 0.04846809431910515, -0.0531737320125103, 0.021795669570565224, 0.008892590180039406, -0.015036659315228462, 0.017015166580677032, 0.0509064719080925, 0.01727183908224106, -0.021004267036914825, 0.019314514473080635, 0.014181088656187057, 0.01942146010696888, 0.052703168243169785, -0.004061288200318813, 0.03437256067991257, 0.054927654564380646, 0.05257483571767807, 0.0024971975944936275, 0.02026633732020855, 0.015603475272655487, 0.028362177312374115, -0.051719263195991516, 0.0007385983481071889, -0.0017525835428386927, 0.01633070968091488, 0.03582703322172165, 0.0005684868083335459, 0.044917475432157516, -0.018587278202176094, 0.015122216194868088, 0.018801171332597733, -0.02089731954038143, -0.01280148047953844, 0.050435908138751984, -0.03676816076040268, 0.0587349459528923, 0.03169890493154526, -0.035142574459314346, 0.029517197981476784, -0.022330401465296745, -0.02680075913667679, -0.021795669570565224, 0.008668002672493458, 0.00419229781255126, 0.0230148583650589, 0.035720087587833405, 0.037409838289022446, 0.055911559611558914, 0.0441046804189682, -0.022373180836439133, -0.022522903978824615, -0.046842508018016815, -0.01836269162595272, 0.02395598590373993, 0.030757775530219078, 0.013453853316605091, 0.11173756420612335, -0.07242407649755478, -0.01990271918475628, 0.018587278202176094, 0.002216463442891836, 0.01412761490792036, -0.047569744288921356, -0.04389078915119171, -0.013977889902889729, -0.020202169194817543, 0.046842508018016815, -0.023421254009008408, -0.03182723745703697, -0.014181088656187057, -0.0008535656961612403, 0.0116785429418087, 0.0015012596268206835, 0.03261864185333252, 0.03734567016363144, -0.017966989427804947, -0.05415764078497887, -0.014662346802651882, -0.05723769590258598, 0.009732119739055634, -0.0075022876262664795, -0.03492868319153786, -0.017453646287322044, -0.029838036745786667, 0.043441615998744965, 0.02846912294626236, 0.04123852029442787, 0.044233016669750214, -0.040981847792863846, 0.05424319580197334, -0.011817573569715023, 0.03298225998878479, 0.0044596632942557335, -0.057366032153367996, 0.07182517647743225, -0.005914133973419666, -0.008545015007257462, -0.0048339758068323135, -0.03293948248028755, 0.01291912142187357, 0.01903645321726799, -0.05334484949707985, 0.002983803628012538, 0.012341611087322235, 0.03901403397321701, 0.04692806676030159, -0.023827649652957916, 0.021870531141757965, -0.000911049370188266, -0.026308806613087654, 0.018619362264871597, -0.0431421659886837, -0.002957066986709833, 0.004638798534870148, -0.0134645476937294, -0.06202889233827591, -0.02320736087858677, 0.009138567373156548, -0.06241390109062195, 0.012202580459415913, -0.012683839537203312, -0.06729065626859665, -0.0001161370673798956, 0.012223970144987106, -0.010667900554835796, -0.01715419813990593, -0.019357291981577873, 0.0134645476937294, 0.03755956515669823, -0.025538792833685875, -0.032083909958601, 0.019913412630558014, -0.00039703838410787284, -0.0632694736123085, 0.03640454262495041, 0.009994138032197952, 0.004911512136459351, -0.04374106228351593, 0.03969849273562431, 0.011368398554623127, -0.05672435462474823, 0.018491026014089584, -0.010261503979563713, -0.02103635109961033, -0.0073579102754592896, -0.006197541952133179, -0.03880014270544052, -0.013111624866724014, -0.0005567895132116973, 0.005785798653960228, 0.0014624915784224868, 0.028191061690449715, -0.013892333023250103, 0.03317476436495781, 0.019122010096907616, -0.027228545397520065, -0.0002235847496194765, 0.009010231122374535, 0.004521157592535019, -0.01179618388414383, 0.02045883983373642, -0.010154557414352894, 0.00484467064961791, 0.02750660479068756, 0.005328602623194456, 0.040661007165908813, -0.007545066066086292, 0.005339297465980053, 0.017207670956850052, -0.04160213842988014, -0.012010077014565468, 0.027228545397520065, -0.023891817778348923, -0.04893865808844566, 0.003761838423088193, -0.01901506446301937, -0.07644526660442352, -0.020950794219970703, 0.020277030766010284, 0.02449071779847145, -0.015592779964208603, -0.027057431638240814, 0.0399123840034008, 0.062456678599119186, 0.013689135201275349, -0.035313691943883896, 0.029666922986507416, 0.04466080293059349, -0.07610303163528442, -0.024576274678111076, 0.04168769344687462, -0.03882152959704399, 0.0022552316077053547, -0.07242407649755478, 0.021827753633260727, 0.02885412983596325, -0.0031201601959764957, 0.0005985654424875975, 0.002965088002383709, 0.004360738210380077, 0.004194971174001694, -0.053216513246297836, 0.030051929876208305, -0.028340786695480347, -0.014919018372893333, -0.020683428272604942, -0.026244638487696648, 0.017667539417743683, -0.08251981437206268, 0.060617201030254364, 0.040233224630355835, -0.026629645377397537, -0.029431641101837158, -0.02028772607445717, -0.013079540804028511, 0.005812535062432289, 0.016630159690976143, 0.01925034634768963, -0.025731295347213745, 0.024447940289974213, -0.05488487705588341, -0.012608977034687996, -0.040233224630355835, -0.001961129019036889, 0.030223043635487556, 0.016352100297808647, -0.027036041021347046, 0.024918504059314728, 0.08880826085805893, -0.08624155074357986, -0.02070481702685356, 0.00095449632499367, 0.011079643853008747, 0.07481967657804489, 0.018833255395293236, 0.0027565425261855125, 0.0028795308899134398, -0.0035907241981476545, -0.004638798534870148, 0.016950998455286026, -0.0009658593917265534, 0.02600935660302639, -0.015507223084568977, 0.012384389527142048, -0.08829492330551147, -0.027078820392489433, -0.023464033380150795, 0.01705794595181942, -0.005344644654542208, 0.012780090793967247, 0.021057739853858948, -0.04128129780292511, 0.046072494238615036, 0.008486194536089897, 0.029281916096806526, -0.013913722708821297, 0.049066994339227676, 0.019410764798521996, -0.004045246168971062, -0.04598693922162056, -0.03813707455992699, -0.07417800277471542, -0.02938886173069477, -0.017207670956850052, -0.01630932092666626, 0.002265926217660308, 0.01479068212211132, 0.037794847041368484, 0.023485422134399414, 0.05976162850856781 ]
30,896
networkx.algorithms.tree.mst
maximum_spanning_tree
Returns a maximum spanning tree or forest on an undirected graph `G`. Parameters ---------- G : undirected graph An undirected graph. If `G` is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found. weight : str Data key to use for edge weights. algorithm : string The algorithm to use when finding a maximum spanning tree. Valid choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'. ignore_nan : bool (default: False) If a NaN is found as an edge weight normally an exception is raised. If `ignore_nan is True` then that edge is ignored instead. Returns ------- G : NetworkX Graph A maximum spanning tree or forest. Examples -------- >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> T = nx.maximum_spanning_tree(G) >>> sorted(T.edges(data=True)) [(0, 1, {}), (0, 3, {'weight': 2}), (1, 2, {})] Notes ----- For Borůvka's algorithm, each edge must have a weight attribute, and each edge weight must be distinct. For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used. There may be more than one tree with the same minimum or maximum weight. See :mod:`networkx.tree.recognition` for more detailed definitions. Isolated nodes with self-loops are in the tree as edgeless isolated nodes.
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, weight='weight', algorithm='kruskal', ignore_nan=False, *, backend=None, **backend_kwargs)
[ -0.0004805855278391391, -0.029452741146087646, -0.021688511595129967, 0.00295703811571002, 0.009667856618762016, 0.006726860534399748, -0.048681508749723434, -0.053985998034477234, 0.07297948747873306, -0.02322852425277233, -0.025132151320576668, 0.034136947244405746, 0.011475233361124992, 0.04187978804111481, -0.056424353271722794, 0.036190297454595566, 0.03056497313082218, 0.0033447148744016886, 0.03638279810547829, 0.03225471079349518, -0.042735349386930466, -0.08226234465837479, 0.019218074157834053, 0.059675488620996475, -0.04136645048856735, -0.03345249593257904, -0.019346408545970917, -0.03768753260374069, -0.01959238201379776, 0.006518317386507988, -0.0037778434343636036, -0.05937604233622551, -0.08333179354667664, -0.03792281076312065, 0.014127477072179317, 0.0019611099269241095, 0.029859133064746857, 0.05082041770219803, -0.06596387177705765, -0.058691591024398804, -0.020041553303599358, -0.03552723675966263, 0.020950589329004288, -0.025153540074825287, 0.02267240732908249, 0.02307880111038685, 0.06968557089567184, 0.06532220542430878, -0.039056431502103806, -0.005128028336912394, 0.03263971209526062, -0.024747148156166077, -0.02286490984261036, 0.021207258105278015, -0.01275857724249363, 0.0065290117636322975, 0.014523174613714218, -0.006684082560241222, 0.07169614732265472, -0.04187978804111481, 0.04504536837339401, 0.006331162992864847, -0.00836312398314476, -0.00005234472337178886, -0.07901120185852051, -0.013389553874731064, -0.05672379955649376, -0.036233074963092804, -0.018191399052739143, 0.025559931993484497, 0.0015172867570072412, -0.02052280679345131, 0.04816817119717598, 0.00678033335134387, 0.017378615215420723, 0.024169642478227615, 0.00520823709666729, -0.04962262883782387, -0.020159192383289337, -0.013058023527264595, 0.07037001848220825, -0.024832703173160553, 0.036211684346199036, -0.026073269546031952, 0.04919484630227089, -0.012630242854356766, 0.029324406757950783, 0.04624315723776817, 0.01825556717813015, -0.08358846604824066, -0.025773823261260986, -0.0031709286849945784, 0.04143061861395836, 0.05124819651246071, 0.0464998260140419, 0.01837320625782013, -0.011272036470472813, -0.07058390974998474, -0.025410208851099014, -0.0346502847969532, -0.013924281112849712, 0.06814555823802948, -0.028212176635861397, 0.014512480236589909, -0.011346898972988129, -0.034393616020679474, -0.03894948586821556, 0.03858587145805359, -0.006523664575070143, -0.04962262883782387, -0.05086319521069527, 0.018501540645956993, 0.021945180371403694, 0.00471361493691802, 0.010223972611129284, 0.01120786927640438, -0.024832703173160553, 0.006935404147952795, 0.007459436077624559, 0.043569523841142654, 0.03409416973590851, 0.02059766836464405, -0.021774066612124443, 0.008143885992467403, -0.00015523782349191606, -0.03167720511555672, 0.050307080149650574, -0.0026415493339300156, 0.013400249183177948, -0.013122190721333027, 0.04423258453607559, 0.029217461124062538, 0.020661836490035057, 0.04872428998351097, 0.018811682239174843, -0.009518133476376534, -0.08226234465837479, -0.0014170254580676556, 0.05368655174970627, 0.03082164190709591, 0.00449170358479023, -0.1007852703332901, 0.044189807027578354, 0.014715676195919514, 0.04714149609208107, -0.012929689139127731, 0.0060584526509046555, -0.006015674211084843, 0.007951384410262108, 0.0037858644500374794, 0.024747148156166077, -0.02876829169690609, 0.025410208851099014, -0.0008408575667999685, 0.007555686868727207, -0.015485682524740696, 0.018437372520565987, 0.002916933735832572, -0.05419988930225372, 0.002842071931809187, -0.012630242854356766, -0.003136171493679285, 0.021763373166322708, 0.027228279039263725, -0.00236883875913918, 0.014213033020496368, 0.023592138662934303, 0.028041062876582146, -0.043334245681762695, -0.032297488301992416, -0.0160845760256052, -0.046029265969991684, -0.10206861793994904, 0.031891096383333206, 0.019346408545970917, 0.015004429034888744, 0.02491826005280018, 0.01074265781790018, -0.012961773201823235, -0.006138661410659552, 0.013956364244222641, -0.04359091445803642, 0.03197665140032768, -0.007534298114478588, -0.021592261269688606, 0.03259693458676338, 0.060060493648052216, -0.020276833325624466, 0.01945335417985916, -0.010432516224682331, -0.0216992050409317, -0.07028446346521378, 0.017004305496811867, 0.05770769715309143, 0.046200379729270935, 0.02491826005280018, 0.004726983141154051, 0.0013608791632577777, -0.04996485263109207, 0.053772106766700745, 0.002469100058078766, -0.023784639313817024, 0.04983652010560036, 0.002150937682017684, 0.015945548191666603, -0.008368471637368202, -0.01004751306027174, -0.0056092822924256325, 0.022929076105356216, -0.002201736904680729, -0.038029756397008896, -0.031484704464673996, 0.05548323318362236, 0.053173214197158813, -0.03392305597662926, -0.026394104585051537, -0.06476608663797379, 0.012309406884014606, 0.025239095091819763, -0.04140922799706459, -0.0371314138174057, -0.0006279695662669837, 0.01957099325954914, -0.008347081951797009, 0.06237051263451576, -0.05565434694290161, 0.012737187556922436, -0.004510418977588415, 0.0361689068377018, -0.03482139855623245, 0.09282854199409485, -0.021891707554459572, 0.04778316989541054, -0.022308794781565666, -0.02549576386809349, -0.0830751284956932, -0.03971949219703674, -0.0304152499884367, 0.022993244230747223, 0.017453476786613464, -0.03206220641732216, -0.07571728527545929, -0.031099699437618256, 0.012737187556922436, 0.0000955823779804632, -0.007737494073808193, 0.011090230196714401, 0.015549849718809128, 0.03610474243760109, 0.0036949608474969864, -0.08042287826538086, -0.06497997790575027, -0.006839153356850147, -0.03548445925116539, 0.00678033335134387, -0.029024960473179817, -0.007555686868727207, 0.02262962982058525, -0.020030857995152473, 0.012427045963704586, 0.002906239125877619, -0.05133375525474548, -0.04671371728181839, 0.04033977538347244, -0.019014878198504448, -0.009229381568729877, 0.028853848576545715, 0.02408408559858799, -0.041516173630952835, -0.021378370001912117, 0.07952453941106796, 0.009919178672134876, 0.003702981863170862, -0.007400616072118282, -0.03017996996641159, -0.02669355273246765, -0.0305863618850708, 0.08551348000764847, 0.0034275974612683058, -0.026779107749462128, -0.04474592208862305, 0.017592504620552063, -0.0005033113993704319, 0.030757473781704903, -0.05287376791238785, 0.03890670835971832, -0.02874690294265747, -0.04624315723776817, 0.02425519935786724, -0.024789925664663315, 0.0118495412170887, -0.05308765918016434, -0.0019022899214178324, 0.02040516771376133, 0.033944446593523026, 0.01742139272391796, -0.003248464083299041, -0.04448925331234932, 0.008208053186535835, 0.051119863986968994, 0.0527026541531086, -0.017667368054389954, 0.04530203714966774, -0.015047206543385983, 0.012908300384879112, 0.0677177757024765, 0.053558215498924255, -0.03728114068508148, 0.0021094963885843754, 0.015143457800149918, -0.0929996520280838, 0.008657223545014858, 0.03385888785123825, 0.02150670439004898, 0.007721452042460442, -0.08649737387895584, -0.014533868990838528, -0.06053105369210243, 0.06361107528209686, 0.011464538052678108, -0.03206220641732216, 0.04983652010560036, 0.006726860534399748, 0.02893940359354019, -0.0633116289973259, 0.010496683418750763, 0.01844806782901287, 0.0808078870177269, 0.020298222079873085, -0.014405534602701664, -0.08230511844158173, 0.0027645365335047245, 0.047013163566589355, 0.061942730098962784, -0.0652366429567337, 0.06258440017700195, 0.09188742190599442, -0.009266812354326248, 0.003676245454698801, -0.058862704783678055, 0.068060003221035, 0.05154764652252197, -0.021089617162942886, 0.027206890285015106, -0.006117272190749645, 0.013186357915401459, 0.03221192955970764, 0.013742473907768726, 0.0060798414051532745, 0.02305741049349308, 0.010427168570458889, 0.0721239224076271, 0.010165153071284294, 0.013988448306918144, 0.0031468661036342382, 0.002638875739648938, 0.010683837346732616, -0.02387019619345665, 0.011913708411157131, 0.02245851792395115, -0.031121088191866875, -0.002638875739648938, 0.019988080486655235, 0.020651141181588173, 0.016095271334052086, -0.011368287727236748, -0.017645977437496185, 0.06249884516000748, 0.025773823261260986, -0.09385521709918976, 0.02977357804775238, -0.11943653225898743, -0.04160172864794731, 0.07469061017036438, -0.0032377697061747313, 0.04962262883782387, -0.05638157203793526, -0.0044729881919920444, 0.0030399207025766373, 0.0075182560831308365, 0.020565586164593697, 0.03668224439024925, 0.0017311774427071214, 0.05308765918016434, 0.048467621207237244, -0.05441378057003021, 0.08525680750608444, -0.00728832371532917, 0.018918627873063087, -0.018266260623931885, -0.02958107553422451, -0.00607449421659112, 0.05261709913611412, 0.030073024332523346, -0.06831666827201843, 0.017047084867954254, 0.08200567215681076, 0.015357348136603832, -0.058862704783678055, 0.02038377895951271, 0.008528889156877995, -0.022501295432448387, -0.020747391507029533, 0.00830430444329977, 0.0014036573702469468, -0.06177161633968353, 0.013410943560302258, 0.020415861159563065, 0.045216482132673264, -0.009961957111954689, -0.06754666566848755, -0.0003049612569157034, 0.00504781911149621, 0.037003081291913986, -0.029260240495204926, -0.04359091445803642, 0.02795550785958767, 0.03409416973590851, 0.06818833947181702, -0.019581688567996025, 0.07199559360742569, -0.02179545722901821, 0.04081033542752266, 0.007507561706006527, 0.053173214197158813, -0.0171540305018425, -0.009576953947544098, -0.04166589677333832, -0.03567695990204811, 0.06326885521411896, -0.007625201251357794, -0.07434839010238647, 0.01113300770521164, -0.02042655646800995, 0.01997738517820835, -0.016309160739183426, -0.004296528175473213, 0.006031716242432594, 0.013977753929793835, 0.0077535356394946575, -0.009694593027234077, 0.021827539429068565, -0.02427658811211586, -0.0433984100818634, 0.00857701525092125, -0.049708183854818344, -0.018309038132429123, 0.03163442760705948, -0.03062913939356804, -0.04220062494277954, 0.07486172765493393, -0.019838357344269753, 0.01151801086962223, -0.00021873660443816334, -0.08008065819740295, 0.03571973741054535, 0.004927505739033222, 0.0024664264637976885, -0.07289393246173859, 0.025837989524006844, 0.053130436688661575, -0.011774679645895958, -0.003334020497277379, 0.047055941075086594, -0.030458027496933937, -0.02226601541042328, 0.06788889318704605, -0.03080025315284729, -0.015474988147616386, -0.0021910422947257757, 0.03790142014622688, -0.02406269684433937, -0.10129860788583755, -0.03311027213931084, 0.012726493179798126, 0.002809988334774971, -0.06450942158699036, -0.03738808259367943, -0.05308765918016434, -0.04202951118350029, 0.012619547545909882, -0.019538911059498787, 0.055012673139572144, 0.013346776366233826, -0.01722889207303524, -0.01968863420188427, 0.03248998895287514, 0.012255934067070484, 0.021367674693465233, -0.04198673367500305, -0.049237627536058426, -0.05544045567512512, 0.029794966802001, 0.018052371218800545, -0.03345249593257904, 0.05094875022768974, -0.012042042799293995, -0.03142053633928299, 0.048467621207237244, -0.053173214197158813, 0.021784761920571327, 0.008908545598387718, -0.015036512166261673, 0.01701500080525875, 0.050905972719192505, 0.01727166958153248, -0.020993366837501526, 0.019271546974778175, 0.014213033020496368, 0.019442658871412277, 0.052745431661605835, -0.004053227603435516, 0.03432944789528847, 0.054969895631074905, 0.05257432162761688, 0.0024784577544778585, 0.020276833325624466, 0.015571238473057747, 0.02836189977824688, -0.05167597904801369, 0.0006911341333761811, -0.0017445455305278301, 0.01631985604763031, 0.035826683044433594, 0.0005868624430149794, 0.04483147710561752, -0.018597790971398354, 0.015089984983205795, 0.018822375684976578, -0.020939894020557404, -0.012822744436562061, 0.05043541267514229, -0.03674641251564026, 0.05873437225818634, 0.03169859200716019, -0.035163622349500656, 0.029495520517230034, -0.022287404164671898, -0.026821887120604515, -0.021806150674819946, 0.008694654330611229, 0.004213645588606596, 0.022993244230747223, 0.03574112802743912, 0.037409473210573196, 0.0558682344853878, 0.04406147077679634, -0.022287404164671898, -0.022522684186697006, -0.046842049807310104, -0.018383901566267014, 0.023912973701953888, 0.03077886439859867, 0.01346441637724638, 0.11165091395378113, -0.07246614992618561, -0.019870441406965256, 0.01866195909678936, 0.002225799486041069, 0.014138171449303627, -0.04756927862763405, -0.043933138251304626, -0.013945669867098331, -0.020201971754431725, 0.046842049807310104, -0.023421024903655052, -0.03178415074944496, -0.01418094988912344, -0.0008301630732603371, 0.011699818074703217, 0.0015146131627261639, 0.03259693458676338, 0.03734530508518219, -0.017934730276465416, -0.054157111793756485, -0.014683593064546585, -0.05727991461753845, 0.00972667708992958, -0.0075182560831308365, -0.03494973108172417, -0.01742139272391796, -0.029859133064746857, 0.04348396882414818, 0.028511622920632362, 0.04123811423778534, 0.044189807027578354, -0.040917281061410904, 0.05424266681075096, -0.01183884683996439, 0.03300332650542259, 0.004489029757678509, -0.05740824714303017, 0.07182447612285614, -0.005919423419982195, -0.008528889156877995, -0.004828581120818853, -0.032939158380031586, 0.012918994762003422, 0.019025573506951332, -0.053344327956438065, 0.002973079914227128, 0.012320101261138916, 0.03903504088521004, 0.04688482731580734, -0.02389158494770527, 0.02185962349176407, -0.0008836357155814767, -0.02632993832230568, 0.018608486279845238, -0.043163131922483444, -0.002989121712744236, 0.00466548977419734, -0.013453721068799496, -0.06202828511595726, -0.023207135498523712, 0.009149172343313694, -0.062413290143013, 0.01223454438149929, -0.012715798802673817, -0.06733277440071106, -0.00014755112351849675, 0.012170377187430859, -0.010683837346732616, -0.017121946439146996, -0.019335713237524033, 0.013453721068799496, 0.03760197386145592, -0.02551715448498726, -0.03208359703421593, 0.01990252360701561, -0.0003843347367364913, -0.06326885521411896, 0.036404188722372055, 0.01001008227467537, 0.0049435473047196865, -0.043740637600421906, 0.03971949219703674, 0.011368287727236748, -0.05672379955649376, 0.018555013462901115, -0.010277445428073406, -0.02102545090019703, -0.007363185286521912, -0.006192134227603674, -0.038821153342723846, -0.013111496344208717, -0.0005507683963514864, 0.005791089031845331, 0.001470498158596456, 0.02819078601896763, -0.013913586735725403, 0.03319582715630531, 0.019121823832392693, -0.027228279039263725, -0.0002421308890916407, 0.009004795923829079, 0.0045291343703866005, -0.011796069331467152, 0.020447945222258568, -0.010165153071284294, 0.004836602136492729, 0.02752772532403469, 0.005299140699207783, 0.040681999176740646, -0.0075182560831308365, 0.005309835076332092, 0.017186112701892853, -0.04160172864794731, -0.011977875605225563, 0.027228279039263725, -0.023912973701953888, -0.04893817752599716, 0.003756454447284341, -0.019014878198504448, -0.0764017403125763, -0.020939894020557404, 0.02030891738831997, 0.02449047937989235, -0.01561401691287756, -0.027057167142629623, 0.039890605956315994, 0.06249884516000748, 0.013656917959451675, -0.03529195487499237, 0.029666632413864136, 0.04466036707162857, -0.07614506781101227, -0.024554645642638206, 0.04164450988173485, -0.038821153342723846, 0.0022485253866761923, -0.07246614992618561, 0.02181684598326683, 0.028875237330794334, -0.0031174561008810997, 0.0005775047466158867, 0.002940996317192912, 0.004368716385215521, 0.004210972227156162, -0.05321599170565605, 0.030051635578274727, -0.028276342898607254, -0.01490817777812481, -0.02071530930697918, -0.026222992688417435, 0.017645977437496185, -0.08251900970935822, 0.06061660870909691, 0.04021143913269043, -0.026629384607076645, -0.029452741146087646, -0.020298222079873085, -0.013090107589960098, 0.005807131063193083, 0.016672775149345398, 0.019271546974778175, -0.0257310438901186, 0.024383533746004105, -0.05492711812257767, -0.012598158791661263, -0.040275607258081436, -0.0019677940290421247, 0.03020135872066021, 0.016351940110325813, -0.027078555896878242, 0.02491826005280018, 0.08880739659070969, -0.08628348261117935, -0.020704613998532295, 0.0009705288102850318, 0.011090230196714401, 0.07481894642114639, 0.01885445974767208, 0.0027859255205839872, 0.002898218110203743, -0.003628120059147477, -0.004660142585635185, 0.016972223296761513, -0.0009464661125093699, 0.026009101420640945, -0.0155177665874362, 0.012416351586580276, -0.08837961405515671, -0.027035776525735855, -0.023506581783294678, 0.01705777831375599, -0.00537132890895009, 0.012801354750990868, 0.021057533100247383, -0.041280895471572876, 0.04607204347848892, 0.008448680862784386, 0.029324406757950783, -0.013902891427278519, 0.049066513776779175, 0.019442658871412277, -0.0041120476089417934, -0.04594371095299721, -0.03813670203089714, -0.07413449883460999, -0.02940996363759041, -0.017186112701892853, -0.01631985604763031, 0.002268577693030238, 0.014801232144236565, 0.03779447823762894, 0.02348519302904606, 0.05976104736328125 ]
30,901
networkx.algorithms.matching
min_weight_matching
Computing a minimum-weight maximal matching of G. Use the maximum-weight algorithm with edge weights subtracted from the maximum weight of all edges. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. This method replaces the edge weights with 1 plus the maximum edge weight minus the original edge weight. new_weight = (max_weight + 1) - edge_weight then runs :func:`max_weight_matching` with the new weights. The max weight matching with these new weights corresponds to the min weight matching using the original weights. Adding 1 to the max edge weight keeps all edge weights positive and as integers if they started as integers. You might worry that adding 1 to each weight would make the algorithm favor matchings with more edges. But we use the parameter `maxcardinality=True` in `max_weight_matching` to ensure that the number of edges in the competing matchings are the same and thus the optimum does not change due to changes in the number of edges. Read the documentation of `max_weight_matching` for more information. Parameters ---------- G : NetworkX graph Undirected graph weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A minimal weight matching of the graph. See Also -------- max_weight_matching
@not_implemented_for("multigraph") @not_implemented_for("directed") @nx._dispatchable(edge_attrs="weight") def max_weight_matching(G, maxcardinality=False, weight="weight"): """Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- G : NetworkX graph Undirected graph maxcardinality: bool, optional (default=False) If maxcardinality is True, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. weight: string, optional (default='weight') Edge data key corresponding to the edge weight. If key not found, uses 1 as weight. Returns ------- matching : set A maximal matching of the graph. Examples -------- >>> G = nx.Graph() >>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)] >>> G.add_weighted_edges_from(edges) >>> sorted(nx.max_weight_matching(G)) [(2, 4), (5, 3)] Notes ----- If G has edges with weight attributes the edge data are used as weight values else the weights are assumed to be 1. This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. Bipartite graphs can also be matched using the functions present in :mod:`networkx.algorithms.bipartite.matching`. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986. """ # # The algorithm is taken from "Efficient Algorithms for Finding Maximum # Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986. # It is based on the "blossom" method for finding augmenting paths and # the "primal-dual" method for finding a matching of maximum weight, both # methods invented by Jack Edmonds. # # A C program for maximum weight matching by Ed Rothberg was used # extensively to validate this new code. # # Many terms used in the code comments are explained in the paper # by Galil. You will probably need the paper to make sense of this code. # class NoNode: """Dummy value which is different from any node.""" class Blossom: """Representation of a non-trivial blossom or sub-blossom.""" __slots__ = ["childs", "edges", "mybestedges"] # b.childs is an ordered list of b's sub-blossoms, starting with # the base and going round the blossom. # b.edges is the list of b's connecting edges, such that # b.edges[i] = (v, w) where v is a vertex in b.childs[i] # and w is a vertex in b.childs[wrap(i+1)]. # If b is a top-level S-blossom, # b.mybestedges is a list of least-slack edges to neighboring # S-blossoms, or None if no such list has been computed yet. # This is used for efficient computation of delta3. # Generate the blossom's leaf vertices. def leaves(self): stack = [*self.childs] while stack: t = stack.pop() if isinstance(t, Blossom): stack.extend(t.childs) else: yield t # Get a list of vertices. gnodes = list(G) if not gnodes: return set() # don't bother with empty graphs # Find the maximum edge weight. maxweight = 0 allinteger = True for i, j, d in G.edges(data=True): wt = d.get(weight, 1) if i != j and wt > maxweight: maxweight = wt allinteger = allinteger and (str(type(wt)).split("'")[1] in ("int", "long")) # If v is a matched vertex, mate[v] is its partner vertex. # If v is a single vertex, v does not occur as a key in mate. # Initially all vertices are single; updated during augmentation. mate = {} # If b is a top-level blossom, # label.get(b) is None if b is unlabeled (free), # 1 if b is an S-blossom, # 2 if b is a T-blossom. # The label of a vertex is found by looking at the label of its top-level # containing blossom. # If v is a vertex inside a T-blossom, label[v] is 2 iff v is reachable # from an S-vertex outside the blossom. # Labels are assigned during a stage and reset after each augmentation. label = {} # If b is a labeled top-level blossom, # labeledge[b] = (v, w) is the edge through which b obtained its label # such that w is a vertex in b, or None if b's base vertex is single. # If w is a vertex inside a T-blossom and label[w] == 2, # labeledge[w] = (v, w) is an edge through which w is reachable from # outside the blossom. labeledge = {} # If v is a vertex, inblossom[v] is the top-level blossom to which v # belongs. # If v is a top-level vertex, inblossom[v] == v since v is itself # a (trivial) top-level blossom. # Initially all vertices are top-level trivial blossoms. inblossom = dict(zip(gnodes, gnodes)) # If b is a sub-blossom, # blossomparent[b] is its immediate parent (sub-)blossom. # If b is a top-level blossom, blossomparent[b] is None. blossomparent = dict(zip(gnodes, repeat(None))) # If b is a (sub-)blossom, # blossombase[b] is its base VERTEX (i.e. recursive sub-blossom). blossombase = dict(zip(gnodes, gnodes)) # If w is a free vertex (or an unreached vertex inside a T-blossom), # bestedge[w] = (v, w) is the least-slack edge from an S-vertex, # or None if there is no such edge. # If b is a (possibly trivial) top-level S-blossom, # bestedge[b] = (v, w) is the least-slack edge to a different S-blossom # (v inside b), or None if there is no such edge. # This is used for efficient computation of delta2 and delta3. bestedge = {} # If v is a vertex, # dualvar[v] = 2 * u(v) where u(v) is the v's variable in the dual # optimization problem (if all edge weights are integers, multiplication # by two ensures that all values remain integers throughout the algorithm). # Initially, u(v) = maxweight / 2. dualvar = dict(zip(gnodes, repeat(maxweight))) # If b is a non-trivial blossom, # blossomdual[b] = z(b) where z(b) is b's variable in the dual # optimization problem. blossomdual = {} # If (v, w) in allowedge or (w, v) in allowedg, then the edge # (v, w) is known to have zero slack in the optimization problem; # otherwise the edge may or may not have zero slack. allowedge = {} # Queue of newly discovered S-vertices. queue = [] # Return 2 * slack of edge (v, w) (does not work inside blossoms). def slack(v, w): return dualvar[v] + dualvar[w] - 2 * G[v][w].get(weight, 1) # Assign label t to the top-level blossom containing vertex w, # coming through an edge from vertex v. def assignLabel(w, t, v): b = inblossom[w] assert label.get(w) is None and label.get(b) is None label[w] = label[b] = t if v is not None: labeledge[w] = labeledge[b] = (v, w) else: labeledge[w] = labeledge[b] = None bestedge[w] = bestedge[b] = None if t == 1: # b became an S-vertex/blossom; add it(s vertices) to the queue. if isinstance(b, Blossom): queue.extend(b.leaves()) else: queue.append(b) elif t == 2: # b became a T-vertex/blossom; assign label S to its mate. # (If b is a non-trivial blos
(G, weight='weight', *, backend=None, **backend_kwargs)
[ 0.0731075257062912, -0.042679108679294586, -0.04481636732816696, 0.04574178159236908, -0.013671857304871082, -0.03338092193007469, -0.035584285855293274, -0.030979258939623833, 0.02232005074620247, -0.04552144557237625, -0.05689078941941261, 0.03853679075837135, -0.024236973375082016, 0.027740318328142166, -0.049972232431173325, 0.03479107469320297, 0.009782924316823483, 0.018486201763153076, 0.052395932376384735, 0.034196168184280396, -0.037302907556295395, -0.04534517601132393, 0.011358327232301235, 0.09650722146034241, 0.00027593658887781203, -0.03719273954629898, -0.015533696860074997, 0.028533529490232468, -0.017527738586068153, 0.01189815066754818, -0.006075768731534481, -0.10849350690841675, -0.0014266764046624303, -0.06310426443815231, 0.004844640847295523, -0.00036975156399421394, 0.042657073587179184, 0.05380608141422272, -0.11052060127258301, -0.08385992795228958, 0.006857961881905794, -0.04582991451025009, 0.041731663048267365, -0.022187847644090652, 0.05019257217645645, 0.030847057700157166, 0.031177561730146408, 0.09589028358459473, -0.03778764605522156, 0.027475915849208832, 0.021581923589110374, -0.06486696004867554, 0.011578663252294064, 0.029833512380719185, -0.03080299124121666, 0.03338092193007469, -0.011253667995333672, 0.048650216311216354, 0.0598873607814312, -0.04869428649544716, 0.030538586899638176, -0.010565117001533508, 0.016161656007170677, -0.0066321175545454025, -0.054643359035253525, -0.003134281374514103, -0.025713225826621056, -0.053101006895303726, -0.054423023015260696, 0.02972334437072277, -0.003643808653578162, -0.009628688916563988, 0.01890484057366848, -0.0019169243751093745, -0.029899612069129944, 0.02514035254716873, 0.007849474437534809, -0.007061772979795933, -0.012504075653851032, -0.02240818366408348, 0.07068382948637009, -0.021108200773596764, 0.01821078173816204, -0.09650722146034241, 0.022672588005661964, -0.0015781575348228216, 0.04684346169233322, 0.05116204917430878, 0.011545613408088684, -0.0918361023068428, -0.073151595890522, 0.004538924433290958, 0.0739007368683815, 0.07143297046422958, 0.0026137372478842735, -0.002043617656454444, -0.02224293164908886, -0.06654150784015656, 0.041731663048267365, -0.027167445048689842, -0.01303288247436285, 0.03664189949631691, -0.06786353141069412, -0.009777415543794632, -0.018717553466558456, -0.0319046713411808, -0.027828453108668327, -0.006185936741530895, -0.004191895015537739, -0.05111798271536827, -0.05715519189834595, 0.019841268658638, 0.0326978825032711, 0.024545444175601006, 0.006538474466651678, 0.009617672301828861, -0.01898195780813694, 0.002393401227891445, 0.042899444699287415, 0.029899612069129944, 0.021747175604104996, -0.0015161880291998386, -0.03617919236421585, 0.03126569837331772, 0.03159620240330696, -0.009413860738277435, 0.06464662402868271, 0.004789556842297316, 0.06975841522216797, -0.018012478947639465, 0.012471024878323078, 0.002745938953012228, -0.03842662274837494, 0.06275173276662827, 0.014211680740118027, -0.010532067157328129, -0.07213804870843887, -0.0038035523612052202, 0.030847057700157166, -0.004745489452034235, 0.0136167723685503, -0.0598873607814312, 0.0521315298974514, -0.03307245299220085, -0.035914789885282516, -0.02076668106019497, 0.04300961270928383, -0.04688752815127373, 0.014993873424828053, -0.020964981988072395, 0.019003991037607193, -0.018387049436569214, 0.01303288247436285, -0.018254848197102547, -0.008907088078558445, 0.006819403264671564, -0.013947277329862118, -0.024986116215586662, -0.02840132638812065, -0.0015933056129142642, 0.007166432682424784, -0.02176920883357525, -0.0175057053565979, 0.0006926817004568875, -0.0013137541245669127, 0.0040101176127791405, 0.05741959437727928, 0.04285537824034691, -0.02505221776664257, 0.019709067419171333, -0.022914957255125046, -0.007006688974797726, -0.11536800116300583, 0.0016566523117944598, 0.022187847644090652, 0.10329357534646988, -0.002222640672698617, -0.02395053766667843, 0.030913159251213074, 0.020987017080187798, 0.024479344487190247, -0.04012320935726166, 0.02978944405913353, -0.017692990601062775, 0.014189646579325199, 0.042524874210357666, 0.058300938457250595, 0.013815075159072876, 0.03853679075837135, 0.009353268891572952, -0.014112529344856739, -0.07610409706830978, 0.02333359606564045, 0.02271665446460247, 0.0004489348502829671, 0.05772806704044342, 0.018783655017614365, 0.028379293158650398, -0.030692823231220245, 0.05808060243725777, -0.01454218477010727, -0.02677083946764469, 0.005511157214641571, -0.018155697733163834, 0.01147951278835535, -0.008840987458825111, 0.019389579072594643, -0.02729964628815651, -0.0012917205458506942, -0.0350114107131958, -0.044838402420282364, -0.018486201763153076, 0.04104861989617348, -0.00005551437789108604, 0.03516564518213272, -0.03992490842938423, -0.02480984851717949, 0.049002755433321, 0.020964981988072395, -0.03620122745633125, -0.037831712514162064, -0.016393007710576057, -0.004409476649016142, 0.02815895713865757, 0.019389579072594643, -0.049355294555425644, 0.059711091220378876, 0.021659040823578835, 0.05865347757935524, -0.03829441964626312, 0.06645337492227554, -0.013143050484359264, 0.0801582857966423, -0.019312461838126183, -0.0073206680826842785, -0.014299814589321613, -0.015170142985880375, 0.011854084208607674, -0.00636220583692193, -0.02176920883357525, -0.0031122479122132063, -0.07434140890836716, -0.05746366083621979, 0.00410100631415844, -0.023531898856163025, -0.008168961852788925, 0.08275824785232544, -0.025184419006109238, -0.022738687694072723, 0.004299308639019728, -0.0474604032933712, -0.030935192480683327, -0.009033781476318836, -0.03842662274837494, 0.009689281694591045, -0.0855344831943512, -0.06451442092657089, -0.022298015654087067, -0.00979944970458746, -0.02311326004564762, -0.006174920126795769, -0.003888932755216956, -0.0614737793803215, 0.060107696801424026, 0.012382890097796917, 0.044001124799251556, 0.03606902435421944, 0.027586083859205246, -0.059006016701459885, -0.01570996642112732, 0.12973392009735107, 0.004866674076765776, -0.006599067244678736, 0.007315159309655428, -0.0964190885424614, -0.01547861285507679, -0.026726773008704185, 0.022606486454606056, 0.03910966217517853, -0.04177572950720787, -0.05173492431640625, 0.0006221053190529346, -0.01642605848610401, 0.03417413309216499, -0.020204823464155197, 0.043053679168224335, -0.025691192597150803, -0.07888033241033554, -0.009760890156030655, -0.03360125795006752, 0.028048789128661156, -0.0412469245493412, 0.02877589873969555, 0.027497949078679085, 0.033645328134298325, 0.017836209386587143, 0.055348437279462814, -0.012471024878323078, 0.024853914976119995, 0.013087966479361057, 0.04098251834511757, -0.04098251834511757, 0.07865999639034271, -0.01655825972557068, -0.03443853557109833, 0.0076621887274086475, 0.07517869025468826, -0.03227924183011055, -0.006643134169280529, 0.015423528850078583, -0.06433814764022827, 0.009937159717082977, 0.027828453108668327, 0.03710460290312767, -0.01163374725729227, -0.03073688969016075, -0.010322747752070427, -0.02932673878967762, 0.019742116332054138, 0.03611309081315994, -0.004370918031781912, 0.03571648523211479, -0.03126569837331772, 0.027343714609742165, -0.054246753454208374, -0.03842662274837494, 0.023928504437208176, 0.03166230022907257, 0.027806419879198074, -0.03957236930727959, -0.018486201763153076, 0.000619006808847189, 0.016161656007170677, 0.020006520673632622, -0.05790433660149574, 0.04754853621125221, 0.05561283975839615, 0.012415940873324871, 0.03175043687224388, -0.07407701015472412, 0.06015176326036453, 0.05887381359934807, -0.016448091715574265, 0.04948749393224716, 0.039946939796209335, -0.01431083120405674, -0.001944466377608478, -0.020987017080187798, -0.014806588180363178, -0.020403126254677773, 0.010724861174821854, 0.04109268635511398, -0.027960654348134995, 0.007948625832796097, -0.013782025314867496, 0.0024774044286459684, 0.00025820638984441757, -0.014938789419829845, 0.018089596182107925, 0.05358574539422989, -0.050853580236434937, 0.02714541181921959, -0.03417413309216499, 0.018530268222093582, 0.017307402566075325, 0.008697768673300743, -0.005717722699046135, 0.019114159047603607, 0.03957236930727959, -0.0949208065867424, 0.03313855454325676, -0.05790433660149574, -0.0026426564436405897, 0.0365537628531456, -0.012393907643854618, 0.042282503098249435, -0.0590941496193409, -0.005230228882282972, 0.020590411499142647, 0.026330167427659035, 0.02186836116015911, 0.012889663688838482, -0.0033683886285871267, 0.03230127692222595, 0.02910640276968479, -0.007794390432536602, 0.05927041918039322, -0.014806588180363178, 0.026726773008704185, -0.0001479522616136819, -0.0018067562486976385, -0.005031926557421684, 0.0427672415971756, 0.005877466406673193, -0.04408925771713257, 0.012460008263587952, 0.06402967870235443, 0.008659210056066513, -0.04728413373231888, -0.01875060424208641, -0.014982856810092926, -0.0008049154421314597, -0.05345354601740837, 0.009661739692091942, -0.019015008583664894, -0.03516564518213272, 0.050677310675382614, 0.08919206261634827, -0.023686133325099945, 0.046182453632354736, -0.06090090796351433, 0.0026881007943302393, -0.05266033485531807, -0.021504806354641914, -0.055216234177351, -0.05248406529426575, 0.017935361713171005, 0.028886066749691963, 0.03461480513215065, 0.004720701370388269, 0.04217233508825302, 0.03926389664411545, 0.07094823569059372, -0.0299436803907156, -0.021207353100180626, -0.02778438664972782, -0.044926535338163376, -0.02613186463713646, -0.03327075392007828, 0.02176920883357525, -0.01912517659366131, -0.044684167951345444, 0.04177572950720787, -0.05618571490049362, -0.007298634387552738, -0.03525378182530403, 0.0018246585968881845, -0.011545613408088684, 0.016216740012168884, 0.006356697529554367, 0.025228487327694893, 0.02381833642721176, -0.01765994168817997, 0.012614243663847446, 0.01953279785811901, -0.057684000581502914, 0.004089989233762026, 0.031618233770132065, 0.0031673319172114134, -0.0036768591962754726, 0.025316622108221054, -0.027630150318145752, 0.049046821892261505, 0.021978529170155525, -0.03547411784529686, 0.04144522547721863, 0.011209600605070591, -0.00396605022251606, -0.018992973491549492, -0.000435508118243888, 0.005516665987670422, -0.004403968341648579, 0.013737957924604416, 0.04085031896829605, -0.07583969831466675, 0.008460907265543938, 0.034747008234262466, -0.03034028597176075, -0.021659040823578835, -0.004134056624025106, 0.03851475566625595, -0.03137586638331413, -0.05014850199222565, -0.05578910931944847, 0.0397045724093914, -0.02659457176923752, -0.04051981493830681, -0.03111146204173565, 0.017781125381588936, -0.035363949835300446, 0.04413332790136337, -0.0007966528064571321, 0.008973188698291779, -0.01897094026207924, 0.02311326004564762, 0.0020105671137571335, 0.026264065876603127, -0.0272335447371006, 0.014465066604316235, -0.031397897750139236, -0.05089764669537544, -0.002795514650642872, 0.03787577897310257, 0.03428430110216141, -0.0023851385340094566, 0.05266033485531807, -0.013484571129083633, -0.03531988337635994, 0.06702625006437302, -0.06244326010346413, -0.002270839177072048, -0.009766398929059505, -0.08236164599657059, -0.04023337736725807, 0.002905682660639286, -0.035518184304237366, -0.025382721796631813, 0.0167235117405653, 0.034041933715343475, 0.024853914976119995, -0.006637625861912966, -0.03384362906217575, 0.05257220193743706, 0.03747917711734772, -0.00788803305476904, -0.017615873366594315, 0.039175763726234436, 0.02388443611562252, 0.02637423388659954, -0.03952830284833908, 0.04957563057541847, 0.013870159164071083, -0.022121747955679893, -0.007810915820300579, -0.008802428841590881, -0.012008318677544594, 0.01275746151804924, -0.029899612069129944, 0.04349435120820999, -0.021978529170155525, 0.007012197282165289, 0.031772468239068985, -0.006532966159284115, 0.03560631722211838, 0.04395705834031105, -0.00454718666151166, 0.05243999883532524, -0.00036252179415896535, -0.049355294555425644, -0.024831881746649742, 0.031001294031739235, -0.001307557220570743, 0.025426790118217468, 0.012349840253591537, 0.007166432682424784, 0.05618571490049362, 0.024060705676674843, -0.010471474379301071, -0.02932673878967762, -0.03919779881834984, -0.01819976419210434, 0.026043729856610298, -0.026109831407666206, 0.0034923276398330927, 0.06090090796351433, -0.04688752815127373, -0.01346253789961338, 0.007541004102677107, 0.02403867244720459, 0.04662312567234039, -0.03179450333118439, -0.01303288247436285, 0.02575729414820671, -0.006780844181776047, 0.03946220129728317, 0.011022314429283142, 0.010923163965344429, 0.016789613291621208, -0.002382384380325675, 0.03335889056324959, 0.001699342392385006, 0.0349893756210804, -0.015698948875069618, -0.01658029295504093, -0.016128605231642723, 0.0149718401953578, -0.05530436709523201, -0.014685402624309063, -0.0024650103878229856, -0.027894554659724236, 0.004800573457032442, 0.022198865190148354, 0.062355123460292816, 0.029370805248618126, 0.07438547909259796, 0.05548063665628433, -0.03545208275318146, 0.06989061832427979, -0.04785700887441635, 0.022738687694072723, -0.00752447871491313, 0.005844415631145239, 0.034041933715343475, -0.024787815287709236, -0.014409982599318027, 0.035209715366363525, 0.021130234003067017, 0.023906469345092773, -0.015324377454817295, -0.03648766130208969, -0.015809116885066032, 0.0023906470742076635, 0.027123376727104187, 0.02474374696612358, -0.003828340210020542, 0.0017255073180422187, 0.025294587016105652, -0.0229590255767107, 0.022848857566714287, -0.03595885634422302, -0.012592209503054619, 0.02514035254716873, -0.019951436668634415, -0.023774268105626106, -0.09007340669631958, -0.004390197340399027, -0.03985880687832832, 0.06967028230428696, 0.003946770913898945, -0.042524874210357666, 0.013782025314867496, 0.007788882125169039, 0.03335889056324959, 0.0036851216573268175, -0.0013667725725099444, 0.02791658788919449, -0.006059243343770504, -0.02162599191069603, -0.004993367474526167, 0.034262269735336304, -0.0073592266999185085, -0.03825035318732262, 0.031772468239068985, 0.0012538502924144268, -0.0011195829138159752, -0.033028386533260345, 0.04922309145331383, -0.006037210114300251, -0.053101006895303726, 0.06852453947067261, -0.05354167893528938, 0.008460907265543938, 0.005067730788141489, -0.00949097890406847, -0.04272317513823509, 0.05243999883532524, 0.02364206686615944, -0.004993367474526167, 0.01509302482008934, 0.023664100095629692, 0.0056048003025352955, -0.01586420089006424, 0.008813445456326008, -0.07024315744638443, 0.004987859167158604, 0.008741836063563824, 0.027652183547616005, -0.0007973413448780775, -0.006461357232183218, -0.023906469345092773, 0.029458940029144287, -0.018717553466558456, 0.03366735950112343, 0.0013612641487270594, -0.01380405854433775, 0.006428306456655264, 0.02458951249718666, -0.04036558046936989, 0.03058265522122383, 0.00599314272403717, -0.02745388261973858, -0.035584285855293274, 0.00630161352455616, -0.022848857566714287, -0.098005510866642, -0.019433647394180298, 0.00026560830883681774, 0.04684346169233322, 0.01601843722164631, -0.037831712514162064, 0.09580215066671371, 0.04596211761236191, -0.00017162118456326425, -0.020281940698623657, 0.04389095678925514, 0.00879692006856203, -0.06781946122646332, -0.000024873883376130834, 0.028687763959169388, -0.05825687199831009, -0.007755831815302372, -0.041885897517204285, 0.03351312503218651, 0.011611714027822018, -0.01851925253868103, 0.02176920883357525, 0.00265367329120636, 0.01686673052608967, 0.01772604137659073, -0.03756731003522873, 0.02395053766667843, -0.005965600721538067, -0.028357259929180145, 0.005491877906024456, -0.009579113684594631, 0.008736327290534973, -0.07720577716827393, 0.007992693223059177, -0.020414141938090324, -0.015996402129530907, -0.03990287333726883, -0.0030020796693861485, -0.005690180696547031, -0.01889382302761078, 0.02520645409822464, -0.008912596851587296, -0.021339554339647293, 0.011776966042816639, -0.07711764425039291, 0.021284470334649086, -0.061033107340335846, 0.021725142374634743, 0.05001630261540413, 0.04419942945241928, -0.027718285098671913, 0.014795571565628052, 0.056053511798381805, -0.06407374888658524, -0.02130650356411934, -0.03910966217517853, -0.002259822329506278, 0.06037209928035736, -0.05221966281533241, 0.023994604125618935, 0.012460008263587952, 0.00018814639770425856, 0.011975268833339214, -0.0591382160782814, -0.014509133994579315, 0.047019731253385544, -0.010030802339315414, 0.004660109058022499, -0.08218537271022797, -0.003525378182530403, -0.05477556213736534, 0.050456974655389786, -0.03681816905736923, 0.0521315298974514, -0.03587072342634201, -0.014872688800096512, 0.08544635027647018, -0.005469844210892916, 0.029392840340733528, 0.004610533360391855, 0.045785848051309586, 0.0299436803907156, 0.030692823231220245, -0.04419942945241928, -0.03064875490963459, -0.07262279093265533, -0.026087798178195953, -0.025889495387673378, -0.008091844618320465, 0.009634197689592838, -0.03476903960108757, 0.023708168417215347, -0.02831319347023964, 0.043450284749269485 ]
30,902
networkx.algorithms.d_separation
minimal_d_separator
Returns a minimal_d-separating set between `x` and `y` if possible .. deprecated:: 3.3 minimal_d_separator is deprecated and will be removed in NetworkX v3.5. Please use `find_minimal_d_separator(G, x, y)`.
def minimal_d_separator(G, u, v): """Returns a minimal_d-separating set between `x` and `y` if possible .. deprecated:: 3.3 minimal_d_separator is deprecated and will be removed in NetworkX v3.5. Please use `find_minimal_d_separator(G, x, y)`. """ import warnings warnings.warn( ( "This function is deprecated and will be removed in NetworkX v3.5." "Please use `is_d_separator(G, x, y)`." ), category=DeprecationWarning, stacklevel=2, ) return nx.find_minimal_d_separator(G, u, v)
(G, u, v)
[ -0.01171156670898199, 0.03124804049730301, -0.024781743064522743, 0.04072391986846924, -0.008095771074295044, -0.013947254978120327, 0.008138764649629593, 0.02278682217001915, 0.02380147948861122, 0.014299805276095867, -0.014411590062081814, -0.025332067161798477, -0.0023259755689650774, -0.0008652543183416128, -0.0033900770358741283, -0.005008801352232695, -0.016552690416574478, -0.0039038555696606636, 0.03470475971698761, 0.021582989022135735, -0.00011339667980792001, -0.03430921584367752, 0.038419440388679504, 0.048531629145145416, -0.06228971108794212, -0.0018412182107567787, -0.002332424744963646, -0.0038243166636675596, 0.016234535723924637, -0.04657110571861267, -0.00241196365095675, 0.025504043325781822, -0.04020799323916435, -0.026725072413682938, 0.030250580981373787, 0.059434909373521805, 0.04130863770842552, 0.055273089557886124, -0.04419783502817154, -0.01542624831199646, -0.06352794170379639, -0.023956257849931717, 0.03436080738902092, -0.0046605500392615795, 0.062220919877290726, 0.05688966438174248, 0.03800669685006142, 0.006664070300757885, -0.034807946532964706, 0.04691505432128906, 0.05644252523779869, -0.006401807069778442, 0.008370932191610336, 0.0038049693685024977, -0.06363112479448318, 0.006904836744070053, 0.0596756748855114, 0.002171197207644582, 0.0034846640191972256, 0.02103266678750515, -0.0280836820602417, 0.01788550615310669, 0.02700023353099823, 0.05386288836598396, -0.012347877956926823, -0.0062040346674621105, -0.028169671073555946, -0.010043399408459663, -0.05179917439818382, 0.04701824113726616, -0.012365074828267097, -0.0030332268215715885, -0.014463182538747787, -0.0012532752007246017, 0.03553024306893349, 0.02658749185502529, 0.034549981355667114, 0.000039870221371529624, 0.02911553904414177, -0.046467918902635574, 0.02940789796411991, -0.05327816680073738, 0.017713529989123344, 0.002981634112074971, 0.06163620203733444, 0.014953314326703548, -0.02070591226220131, 0.060776323080062866, -0.015271469950675964, -0.015357458032667637, -0.01746416464447975, 0.024300210177898407, -0.029390700161457062, 0.05578901991248131, -0.009415687061846256, 0.06449100375175476, -0.019209720194339752, 0.02557283267378807, -0.000027324704205966555, -0.037353191524744034, 0.06266805529594421, 0.0349283292889595, -0.04983864724636078, -0.015615422278642654, -0.024059444665908813, -0.08000323921442032, 0.0065909805707633495, -0.0026140352711081505, -0.056236155331134796, -0.02177216298878193, -0.03900415822863579, 0.007085411809384823, 0.012141506187617779, -0.0010603396221995354, -0.020482342690229416, 0.005722501780837774, 0.007382070180028677, -0.03303659334778786, 0.03718121349811554, -0.0075884414836764336, -0.06865282356739044, 0.01900334842503071, -0.08192937076091766, -0.0024549574591219425, 0.0005535478121601045, -0.06022600084543228, 0.042581260204315186, 0.04973546415567398, -0.005821388214826584, 0.0032653945963829756, 0.03219391033053398, 0.011427805759012699, -0.026535898447036743, 0.024007851257920265, -0.0018487421330064535, -0.029201526194810867, -0.04409464821219444, 0.03652770444750786, 0.06713943183422089, 0.01577020063996315, -0.046089570969343185, -0.07436242699623108, -0.015194080770015717, 0.10270407050848007, -0.013457123190164566, 0.0073476750403642654, 0.013525913469493389, 0.03835064917802811, 0.026862652972340584, 0.02108425833284855, -0.038041092455387115, 0.05179917439818382, 0.08289244025945663, -0.0630464032292366, 0.011144045740365982, -0.08131025731563568, -0.011470800265669823, -0.02940789796411991, 0.056992851197719574, 0.017644738778471947, 0.015933576971292496, -0.06789612770080566, 0.03394806385040283, 0.034171633422374725, 0.011316021904349327, 0.020809097215533257, 0.02206452190876007, 0.02701743133366108, -0.026759468019008636, 0.027206605300307274, 0.03890097513794899, 0.04024238511919975, -0.0630808025598526, -0.011806152760982513, -0.02352631837129593, -0.01821225881576538, 0.022150510922074318, 0.02739577926695347, 0.02246006764471531, -0.01819506287574768, 0.03776593133807182, 0.058299869298934937, 0.06067313626408577, -0.05537627637386322, 0.0041016279719769955, 0.003340634051710367, 0.040483154356479645, -0.0351690948009491, -0.0012188799446448684, -0.0074680582620203495, -0.021479804068803787, -0.029631467536091805, 0.006001962814480066, 0.03921053186058998, 0.020895086228847504, 0.01822945661842823, 0.01350871566683054, 0.01190073974430561, -0.06521330028772354, -0.008839567191898823, -0.01644950546324253, 0.00945008173584938, 0.028582412749528885, -0.011195638217031956, 0.017954295501112938, 0.023560713976621628, -0.017747923731803894, 0.006251328159123659, 0.03086969442665577, 0.020413553342223167, 0.05441321060061455, -0.014884524047374725, -0.029906628653407097, 0.03255505859851837, -0.04333795607089996, -0.015675613656640053, 0.011926536448299885, 0.049288325011730194, 0.041205450892448425, -0.048875581473112106, -0.0021088558714836836, -0.026415515691041946, 0.06844644993543625, 0.037009239196777344, 0.020619923248887062, -0.05506671965122223, -0.020052403211593628, -0.054103653877973557, 0.0013424877543002367, -0.06067313626408577, 0.03934811055660248, -0.0873638167977333, -0.01349151786416769, -0.022322487086057663, 0.02072311006486416, -0.022993192076683044, 0.006960729137063026, -0.026398317888379097, 0.09892059862613678, 0.021135851740837097, -0.04058633744716644, -0.035908591002225876, 0.008873961865901947, 0.014669553376734257, 0.03683726117014885, -0.00693493289873004, -0.04983864724636078, -0.0072401901707053185, 0.04247807338833809, 0.05929733067750931, -0.07663250714540482, -0.029304713010787964, -0.002252885838970542, -0.00787220150232315, 0.047499775886535645, 0.02034476213157177, -0.04275323823094368, 0.009329698979854584, -0.008977147750556469, -0.03128243610262871, -0.0524870790541172, -0.017326584085822105, -0.06882479786872864, 0.03473915532231331, -0.01822945661842823, -0.020430749282240868, 0.051076874136924744, 0.007618537172675133, -0.01649249903857708, -0.006982225924730301, -0.03676846995949745, 0.055960994213819504, -0.04987304285168648, -0.030766507610678673, 0.0062556276097893715, 0.04027678072452545, -0.047121427953243256, -0.04516090080142021, 0.04371630400419235, -0.014858727343380451, -0.05334695801138878, -0.007833506911993027, -0.04832525923848152, 0.05816228687763214, -0.06056995317339897, 0.04099908098578453, 0.012906800024211407, -0.09898938983678818, -0.022941600531339645, -0.025039708241820335, -0.022666437551379204, 0.012012524530291557, -0.010009003803133965, 0.008452621288597584, 0.02211611531674862, 0.027602149173617363, 0.01434279978275299, -0.01860780455172062, 0.009579063393175602, -0.0013779577566310763, 0.04278763011097908, -0.06531649082899094, -0.035599034279584885, 0.035220686346292496, 0.006109447684139013, 0.003276142990216613, 0.06125785410404205, -0.040448758751153946, 0.037353191524744034, -0.016191542148590088, -0.07910896837711334, -0.019450487568974495, 0.0012038321001455188, -0.037043631076812744, 0.0158131942152977, 0.01605396158993244, -0.03365570679306984, 0.044335417449474335, 0.0037340291310101748, 0.04357872158288956, 0.02834164723753929, 0.06768976151943207, -0.06232410669326782, 0.054138049483299255, -0.07752678543329239, 0.06266805529594421, 0.022597648203372955, 0.023595109581947327, -0.018521815538406372, 0.058437447994947433, -0.00673716003075242, -0.02208171971142292, -0.038075488060712814, 0.03532387316226959, 0.06342475116252899, 0.018796978518366814, 0.09156002849340439, 0.018831374123692513, 0.012279087677598, -0.01682785339653492, 0.04106787219643593, 0.029717454686760902, -0.025056904181838036, -0.005709603428840637, 0.03047414869070053, 0.011969530023634434, 0.0491507425904274, 0.0036458915565162897, 0.03683726117014885, 0.05506671965122223, 0.017799517139792442, 0.07663250714540482, -0.030577335506677628, -0.07078532874584198, 0.06070753186941147, 0.00007342569733737037, -0.030663322657346725, -0.005761196371167898, 0.054172445088624954, 0.059813257306814194, 0.0315404012799263, 0.010980668477714062, 0.048600420355796814, -0.0012102811597287655, -0.03817867487668991, -0.03931371495127678, -0.04663989320397377, -0.04106787219643593, -0.02693144418299198, 0.0035341070033609867, -0.050664134323596954, -0.001843367819674313, 0.0526590533554554, 0.006169639527797699, -0.0025366460904479027, 0.047568563371896744, -0.0036630891263484955, -0.004411184694617987, -0.05001062527298927, 0.0385570228099823, 0.013758081011474133, -0.005967567674815655, 0.0491507425904274, 0.03133402764797211, 0.011083854362368584, 0.015598224475979805, 0.07257387787103653, 0.021600186824798584, -0.03081810101866722, -0.011995326727628708, -0.0011877092765644193, -0.04237489029765129, 0.046467918902635574, 0.10009004175662994, -0.05431002378463745, -0.052796635776758194, 0.016896642744541168, -0.015004906803369522, -0.0038092685863375664, -0.02663908340036869, 0.022975994274020195, 0.011634177528321743, -0.0351862907409668, 0.025762006640434265, 0.011874943971633911, -0.07057895511388779, 0.026398317888379097, 0.0026871252339333296, 0.0050474959425628185, -0.01067111175507307, -0.03370729833841324, -0.017042823135852814, 0.021170247346162796, 0.018298247829079628, 0.03752516582608223, -0.053106192499399185, -0.017352379858493805, 0.0630808025598526, 0.03191874921321869, 0.0061911363154649734, -0.009604860097169876, -0.06380309909582138, -0.03645891323685646, 0.010112189687788486, -0.024558175355196, -0.03896976262331009, -0.04873800277709961, -0.038728997111320496, 0.0018379936227574944, -0.0032954902853816748, -0.008091471157968044, -0.0280320905148983, 0.0280836820602417, -0.061464227735996246, -0.005503232590854168, -0.01746416464447975, 0.04495453089475632, 0.012055518105626106, 0.027550557628273964, 0.04062073305249214, -0.020791899412870407, -0.015598224475979805, -0.014721146784722805, -0.032090723514556885, 0.037697140127420425, -0.011616979725658894, -0.04354432597756386, 0.037043631076812744, 0.0028956460300832987, -0.014953314326703548, 0.015151086263358593, -0.04811888933181763, 0.0008856764761731029, -0.012193099595606327, 0.003658789675682783, 0.010395949706435204, -0.027464568614959717, -0.03009580262005329, -0.04278763011097908, 0.06421584635972977, 0.06345915049314499, 0.005395747255533934, -0.04736219346523285, 0.03398245945572853, -0.05716482549905777, 0.06521330028772354, 0.04065512865781784, -0.05881579592823982, -0.028204066678881645, 0.01862500235438347, 0.05496353283524513, -0.04134303331375122, -0.06493814289569855, -0.018040284514427185, 0.011169841513037682, 0.007597040385007858, 0.0028870473615825176, 0.018470223993062973, 0.04237489029765129, -0.03931371495127678, -0.05214312672615051, -0.027516162022948265, 0.0013672092463821173, -0.007618537172675133, -0.0065909805707633495, 0.0010995715856552124, -0.018109073862433434, -0.0012887452030554414, 0.0005409183213487267, -0.00805707648396492, 0.09981487691402435, 0.014274008572101593, -0.0385570228099823, -0.04347553476691246, 0.06390628963708878, 0.02031036652624607, 0.0063631124794483185, -0.07394968718290329, 0.09362374246120453, -0.013912859372794628, 0.023921864107251167, 0.02488492801785469, -0.01791989989578724, -0.0018412182107567787, 0.04660549759864807, 0.008650393225252628, 0.03793790936470032, 0.040483154356479645, -0.04478255286812782, -0.01434279978275299, 0.0037232807371765375, -0.020224379375576973, 0.016354918479919434, 0.09149123728275299, -0.0016326972981914878, 0.013646296225488186, -0.06504132598638535, -0.016931038349866867, 0.0595724917948246, -0.02491932362318039, 0.010215374641120434, 0.02423142082989216, 0.02000080980360508, -0.016595685854554176, -0.05365651473402977, 0.0351346991956234, -0.055582646280527115, -0.009768237359821796, -0.016759062185883522, 0.028255658224225044, -0.041549403220415115, 0.02878878451883793, 0.013826871290802956, 0.04976985603570938, 0.006500693038105965, 0.045092109590768814, -0.0036824364215135574, 0.024042246863245964, -0.010275566950440407, -0.0028225563000887632, 0.052762240171432495, -0.024265814572572708, 0.015864787623286247, 0.025160090997815132, 0.01089468039572239, 0.05001062527298927, 0.020499540492892265, 0.09004663676023483, -0.011960932053625584, -0.03535826876759529, -0.026381120085716248, 0.01817786507308483, -0.011101051233708858, 0.00447997497394681, 0.011496596038341522, -0.058059100061655045, -0.043957069516181946, 0.03260665014386177, -0.023629503324627876, 0.029958222061395645, -0.03649330884218216, -0.02517728880047798, 0.018487421795725822, 0.017300786450505257, -0.05575462430715561, -0.0065350886434316635, -0.030921287834644318, -0.06218652427196503, 0.01716320589184761, 0.05035457760095596, -0.04320037364959717, 0.0019057091558352113, -0.04306279495358467, -0.0002177915011998266, -0.049907438457012177, 0.016974031925201416, 0.021462606266140938, -0.0016885894583538175, -0.05547946318984032, -0.0633559599518776, -0.07566944509744644, 0.027584951370954514, 0.04302839934825897, 0.047843728214502335, 0.0022872809786349535, -0.039795249700546265, 0.011118249036371708, 0.005120585672557354, 0.0001829932298278436, 0.012691829353570938, 0.04137742891907692, -0.014265410602092743, 0.04942590743303299, -0.016354918479919434, -0.002242137212306261, -0.020877888426184654, -0.026879850775003433, 0.01014658436179161, 0.07917775213718414, -0.0073476750403642654, -0.007949590682983398, 0.018005888909101486, 0.006212633568793535, 0.02870279550552368, 0.04058633744716644, -0.061808180063962936, -0.005675208289176226, -0.07484395802021027, -0.04000161960721016, -0.0947931781411171, 0.020172785967588425, 0.05228070914745331, -0.03473915532231331, -0.0072401901707053185, -0.03900415822863579, -0.009114728309214115, 0.015452045015990734, -0.026398317888379097, -0.01489312294870615, -0.02003520540893078, -0.008581602945923805, -0.006831747014075518, 0.00402853824198246, -0.057955916970968246, 0.012597243301570415, 0.007966788485646248, 0.025383658707141876, 0.005589220207184553, 0.031058868393301964, -0.006087950896471739, -0.029029550030827522, -0.03475635126233101, 0.022614846006035805, 0.020430749282240868, -0.06596999615430832, -0.02949388511478901, 0.004634753335267305, -0.040827106684446335, -0.03016459196805954, 0.0349799208343029, -0.00874927919358015, 0.03336334601044655, -0.03442959859967232, -0.016569888219237328, -0.007996884174644947, -0.025314869359135628, 0.006251328159123659, 0.04130863770842552, 0.025813600048422813, 0.008061375468969345, -0.009252309799194336, 0.06056995317339897, -0.02211611531674862, -0.032142315059900284, -0.0027043228037655354, 0.0023754185531288385, -0.01368929073214531, 0.028530821204185486, 0.020791899412870407, -0.023698294535279274, 0.0015585325891152024, 0.020533936098217964, 0.04024238511919975, 0.024283012375235558, 0.012055518105626106, 0.035908591002225876, 0.012064117006957531, -0.04130863770842552, -0.012537050992250443, -0.07140444219112396, 0.023595109581947327, -0.040792711079120636, -0.006565184332430363, -0.023749887943267822, -0.057646360248327255, -0.08186057955026627, 0.03293340653181076, -0.00763143552467227, -0.010499135591089725, -0.015108092688024044, 0.03642451763153076, 0.003858711803331971, 0.017068618908524513, -0.013697889633476734, -0.04987304285168648, -0.006019160617142916, -0.027103420346975327, -0.06211773678660393, 0.0158389899879694, 0.052452683448791504, 0.019416091963648796, -0.033483728766441345, 0.028582412749528885, 0.02354351617395878, -0.0010189578169956803, 0.0008829893195070326, 0.02211611531674862, 0.01316476333886385, -0.022374078631401062, 0.02626073732972145, 0.02732698805630207, 0.020155588164925575, -0.07938412576913834, 0.04037996754050255, 0.00474223867058754, -0.02906394563615322, 0.015194080770015717, 0.011101051233708858, 0.006689867004752159, 0.0052194721065461636, 0.03176397085189819, 0.0024571071844547987, -0.0035513045731931925, -0.08543768525123596, 0.026742270216345787, -0.000577731931116432, -0.047499775886535645, -0.046467918902635574, 0.021944139152765274, 0.047809332609176636, -0.03879778832197189, -0.03759395703673363, -0.002012119395658374, 0.025349264964461327, -0.013104571960866451, 0.02316516824066639, -0.000060729027609340847, -0.07883380353450775, -0.07140444219112396, -0.011109650135040283, -0.04949469491839409, 0.0945180132985115, -0.008624597452580929, 0.05424123257398605, 0.02524607814848423, -0.0032245502807199955, 0.012803614139556885, 0.022494463250041008, -0.03442959859967232, 0.022236498072743416, -0.04130863770842552, -0.020533936098217964, 0.008366633206605911, -0.03124804049730301, -0.021634582430124283, -0.020602725446224213, 0.030732113867998123, 0.01896895468235016, -0.07938412576913834, 0.007038118317723274, 0.034463994204998016, -0.024558175355196, -0.012846607714891434, -0.030594533309340477, -0.0010442167986184359, -0.025056904181838036, 0.028221262618899345, 0.007382070180028677, 0.0018100475426763296, -0.0632183849811554, -0.04423223063349724, 0.00839242897927761, -0.0011350417044013739, 0.02593398280441761, -0.031110459938645363, 0.054860346019268036, 0.033810485154390335, 0.07511912286281586 ]
30,903
networkx.algorithms.tree.branchings
minimum_branching
Returns a minimum branching from G. Parameters ---------- G : (multi)digraph-like The graph to be searched. attr : str The edge attribute used to in determining optimality. default : float The value of the edge attribute used if an edge does not have the attribute `attr`. preserve_attrs : bool If True, preserve the other attributes of the original graph (that are not passed to `attr`) partition : str The key for the edge attribute containing the partition data on the graph. Edges can be included, excluded or open using the `EdgePartition` enum. Returns ------- B : (multi)digraph-like A minimum branching. See Also -------- minimal_branching
@nx._dispatchable(preserve_edge_attrs=True, returns_graph=True) def maximum_branching( G, attr="weight", default=1, preserve_attrs=False, partition=None, ): ####################################### ### Data Structure Helper Functions ### ####################################### def edmonds_add_edge(G, edge_index, u, v, key, **d): """ Adds an edge to `G` while also updating the edge index. This algorithm requires the use of an external dictionary to track the edge keys since it is possible that the source or destination node of an edge will be changed and the default key-handling capabilities of the MultiDiGraph class do not account for this. Parameters ---------- G : MultiDiGraph The graph to insert an edge into. edge_index : dict A mapping from integers to the edges of the graph. u : node The source node of the new edge. v : node The destination node of the new edge. key : int The key to use from `edge_index`. d : keyword arguments, optional Other attributes to store on the new edge. """ if key in edge_index: uu, vv, _ = edge_index[key] if (u != uu) or (v != vv): raise Exception(f"Key {key!r} is already in use.") G.add_edge(u, v, key, **d) edge_index[key] = (u, v, G.succ[u][v][key]) def edmonds_remove_node(G, edge_index, n): """ Remove a node from the graph, updating the edge index to match. Parameters ---------- G : MultiDiGraph The graph to remove an edge from. edge_index : dict A mapping from integers to the edges of the graph. n : node The node to remove from `G`. """ keys = set() for keydict in G.pred[n].values(): keys.update(keydict) for keydict in G.succ[n].values(): keys.update(keydict) for key in keys: del edge_index[key] G.remove_node(n) ####################### ### Algorithm Setup ### ####################### # Pick an attribute name that the original graph is unlikly to have candidate_attr = "edmonds' secret candidate attribute" new_node_base_name = "edmonds new node base name " G_original = G G = nx.MultiDiGraph() G.__networkx_cache__ = None # Disable caching # A dict to reliably track mutations to the edges using the key of the edge. G_edge_index = {} # Each edge is given an arbitrary numerical key for key, (u, v, data) in enumerate(G_original.edges(data=True)): d = {attr: data.get(attr, default)} if data.get(partition) is not None: d[partition] = data.get(partition) if preserve_attrs: for d_k, d_v in data.items(): if d_k != attr: d[d_k] = d_v edmonds_add_edge(G, G_edge_index, u, v, key, **d) level = 0 # Stores the number of contracted nodes # These are the buckets from the paper. # # In the paper, G^i are modified versions of the original graph. # D^i and E^i are the nodes and edges of the maximal edges that are # consistent with G^i. In this implementation, D^i and E^i are stored # together as the graph B^i. We will have strictly more B^i then the # paper will have. # # Note that the data in graphs and branchings are tuples with the graph as # the first element and the edge index as the second. B = nx.MultiDiGraph() B_edge_index = {} graphs = [] # G^i list branchings = [] # B^i list selected_nodes = set() # D^i bucket uf = nx.utils.UnionFind() # A list of lists of edge indices. Each list is a circuit for graph G^i. # Note the edge list is not required to be a circuit in G^0. circuits = [] # Stores the index of the minimum edge in the circuit found in G^i and B^i. # The ordering of the edges seems to preserver the weight ordering from # G^0. So even if the circuit does not form a circuit in G^0, it is still # true that the minimum edges in circuit G^0 (despite their weights being # different) minedge_circuit = [] ########################### ### Algorithm Structure ### ########################### # Each step listed in the algorithm is an inner function. Thus, the overall # loop structure is: # # while True: # step_I1() # if cycle detected: # step_I2() # elif every node of G is in D and E is a branching: # break ################################## ### Algorithm Helper Functions ### ################################## def edmonds_find_desired_edge(v): """ Find the edge directed towards v with maximal weight. If an edge partition exists in this graph, return the included edge if it exists and never return any excluded edge. Note: There can only be one included edge for each vertex otherwise the edge partition is empty. Parameters ---------- v : node The node to search for the maximal weight incoming edge. """ edge = None max_weight = -INF for u, _, key, data in G.in_edges(v, data=True, keys=True): # Skip excluded edges if data.get(partition) == nx.EdgePartition.EXCLUDED: continue new_weight = data[attr] # Return the included edge if data.get(partition) == nx.EdgePartition.INCLUDED: max_weight = new_weight edge = (u, v, key, new_weight, data) break # Find the best open edge if new_weight > max_weight: max_weight = new_weight edge = (u, v, key, new_weight, data) return edge, max_weight def edmonds_step_I2(v, desired_edge, level): """ Perform step I2 from Edmonds' paper First, check if the last step I1 created a cycle. If it did not, do nothing. If it did, store the cycle for later reference and contract it. Parameters ---------- v : node The current node to consider desired_edge : edge The minimum desired edge to remove from the cycle. level : int The current level, i.e. the number of cycles that have already been removed. """ u = desired_edge[0] Q_nodes = nx.shortest_path(B, v, u) Q_edges = [ list(B[Q_nodes[i]][vv].keys())[0] for i, vv in enumerate(Q_nodes[1:]) ] Q_edges.append(desired_edge[2]) # Add the new edge key to complete the circuit # Get the edge in the circuit with the minimum weight. # Also, save the incoming weights for each node. minweight = INF minedge = None Q_incoming_weight = {} for edge_key in Q_edges: u, v, data = B_edge_index[edge_key] w = data[attr] # We cannot remove an included edge, even if it is the # minimum edge in the circuit Q_incoming_weight[v] = w if data.get(partition) == nx.EdgePartition.INCLUDED: continue if w < minweight: minweight = w minedge = edge_key circuits.append(Q_edges) minedge_circuit.append(minedge) graphs.append((G.copy(), G_edge_index.copy())) branchings.append((B.copy(), B_edge_index.copy())) # Mutate the graph to contract the circuit new_node = new_node_base_name + str(level) G.add_node(new_node) new_edges = [] for u, v, key, data in G.edges(data=True, keys=True): if u in Q_incoming_weight: if v in Q_incoming_weight: # Circuit edge. For the moment do nothing, # eventually it will be removed. continue else: #
(G, attr='weight', default=1, preserve_attrs=False, partition=None, *, backend=None, **backend_kwargs)
[ 0.05934286117553711, 0.015630874782800674, -0.03579306975007057, 0.014857499860227108, -0.035684142261743546, -0.05433226749300957, -0.04394073039293289, -0.04126115143299103, 0.017765823751688004, -0.07045330852270126, -0.031239964067935944, 0.05241516977548599, 0.004386992659419775, 0.022416962310671806, -0.04836312308907509, -0.0001257754338439554, -0.015445699915289879, 0.006764301564544439, 0.04797099158167839, 0.03906084597110748, -0.020837534219026566, -0.07106329500675201, -0.003205146174877882, 0.07454892247915268, 0.013332536444067955, 0.020510757341980934, 0.013180040754377842, 0.023702288046479225, -0.00812587607651949, -0.004937069024890661, -0.03106568194925785, -0.04971380531787872, -0.02666507288813591, -0.041130442172288895, 0.047143153846263885, 0.02803754061460495, 0.04012832045555115, 0.03906084597110748, -0.12574411928653717, -0.03991046920418739, -0.022253572940826416, -0.02259124256670475, 0.012929510325193405, -0.04128293693065643, 0.04450714588165283, 0.022286251187324524, 0.028582170605659485, 0.07711957395076752, 0.009111655876040459, -0.011709540151059628, 0.019693812355399132, -0.048145271837711334, 0.03411560878157616, 0.03853800147771835, -0.0033440268598496914, 0.015282311476767063, 0.000021572444893536158, 0.018386701121926308, 0.056815776973962784, -0.05816645920276642, -0.00729259243234992, -0.008425422944128513, 0.04010653495788574, -0.02278731018304825, -0.0625234991312027, 0.012177921831607819, -0.040847234427928925, -0.02415977604687214, -0.04967023432254791, 0.031610313802957535, 0.0031969768460839987, -0.03642483800649643, 0.02000969834625721, -0.014694111421704292, -0.042742542922496796, -0.026926495134830475, -0.0015413023065775633, -0.023026946932077408, -0.014705004170536995, -0.02670864388346672, 0.06783908605575562, -0.017613327130675316, 0.02605508826673031, -0.056467216461896896, 0.029998207464814186, -0.010887148790061474, 0.04300396516919136, 0.061739232391119, 0.0019143735989928246, -0.09698767215013504, -0.03760123997926712, 0.02178519032895565, 0.01657853089272976, 0.08343727886676788, 0.06949476152658463, 0.018147064372897148, -0.03337491303682327, -0.039757974445819855, 0.04587961360812187, -0.010375197045505047, -0.012798799201846123, 0.03977975994348526, -0.07589960843324661, -0.01751529425382614, -0.04779670760035515, -0.055290814489126205, -0.034072037786245346, 0.017842071130871773, -0.03997582569718361, -0.09175922721624374, -0.0701918825507164, 0.01953042298555374, 0.006432077381759882, 0.011360976845026016, 0.009160672314465046, 0.056467216461896896, -0.012352203018963337, -0.008049627766013145, 0.03328777104616165, 0.008665059693157673, 0.02339729480445385, -0.033875972032547, -0.03908263146877289, -0.009966724552214146, 0.016959771513938904, -0.014977319166064262, 0.03936583921313286, 0.014236622489988804, 0.03017248958349228, -0.02742755599319935, 0.001910288934595883, -0.029911067336797714, -0.018408486619591713, 0.04522605612874031, -0.036816973239183426, -0.03771016374230385, -0.07537676393985748, 0.004318913910537958, 0.015097137540578842, -0.001639335649088025, 0.03041212633252144, -0.038995493203401566, 0.04470321163535118, 0.016611207276582718, 0.005269293207675219, -0.036686260253190994, 0.020358260720968246, -0.02912680059671402, 0.00255567510612309, 0.001967475051060319, -0.008893804624676704, -0.018887760117650032, -0.020282013341784477, -0.006791533436626196, 0.02481333166360855, 0.03121817857027054, -0.05132590979337692, 0.015587303787469864, -0.04749171435832977, 0.014552507549524307, -0.04293861240148544, -0.027950400486588478, 0.011077769100666046, 0.017656898126006126, -0.0016951601719483733, -0.014824822545051575, 0.014258407056331635, -0.013822703622281551, -0.061259955167770386, 0.03137067332863808, 0.006377614568918943, -0.003918610978871584, -0.0851365253329277, -0.006780640687793493, -0.025183681398630142, 0.09419916570186615, 0.04513891413807869, -0.0278414748609066, 0.01236309576779604, 0.002110440284013748, -0.006018158979713917, -0.023331940174102783, 0.045923180878162384, 0.011524366214871407, 0.02880002185702324, -0.001371786231175065, 0.037492312490940094, -0.01641514152288437, 0.05237159878015518, -0.010211808606982231, -0.020118623971939087, -0.07245754450559616, 0.023593362420797348, 0.015413022600114346, 0.014214836992323399, 0.0185609832406044, 0.04228505492210388, 0.045443907380104065, -0.0055987942032516, 0.05620579421520233, -0.0021553724072873592, 0.0003000569704454392, 0.055857229977846146, -0.008305603638291359, 0.016491388902068138, 0.020271120592951775, -0.0027966739144176245, -0.031000327318906784, 0.0075376760214567184, 0.007276253774762154, -0.050323791801929474, 0.02038004621863365, 0.03049926646053791, 0.00801150407642126, 0.010544032789766788, -0.017537077888846397, -0.02973678521811962, 0.04078187793493271, 0.04285147041082382, -0.04272076115012169, -0.05760004371404648, 0.0007311654626391828, 0.018212419003248215, 0.01066929753869772, 0.030804259702563286, -0.077468141913414, 0.05394013226032257, 0.02472619153559208, 0.05193589627742767, -0.009629053995013237, 0.045966751873493195, -0.024639051407575607, 0.02908322960138321, -0.027209702879190445, 0.02339729480445385, -0.01207988802343607, -0.057905036956071854, 0.0001592191110830754, -0.009422095492482185, 0.03097854182124138, -0.021806975826621056, -0.05873287469148636, -0.03784087672829628, 0.018049031496047974, 0.030717119574546814, -0.030934970825910568, 0.07594317197799683, 0.01543480809777975, 0.0003877083072438836, 0.0004251516074873507, -0.05550866574048996, -0.0649634376168251, -0.010603941977024078, -0.029780356213450432, 0.013909844681620598, -0.02481333166360855, -0.036816973239183426, -0.036642689257860184, -0.01276612188667059, -0.027100777253508568, 0.009961278177797794, -0.007042062934488058, -0.04036795720458031, 0.04849383607506752, 0.015990329906344414, 0.03662090748548508, 0.035117726773023605, 0.008643274195492268, -0.024747977033257484, 0.006856888998299837, 0.09498342871665955, -0.011753110215067863, 0.005331925582140684, 0.028059326112270355, -0.0701918825507164, -0.029475362971425056, -0.018495626747608185, 0.0018449333729222417, -0.03300456330180168, -0.05672863870859146, -0.08574651181697845, -0.006159762851893902, -0.015630874782800674, 0.04853740707039833, -0.060214266180992126, 0.031327106058597565, -0.021251453086733818, -0.07755527645349503, -0.01032618060708046, -0.012820584699511528, 0.004136463161557913, -0.01010288204997778, 0.02162180282175541, 0.03973618894815445, 0.07494105398654938, -0.016927093267440796, 0.022525887936353683, -0.03888656571507454, 0.0029028765857219696, 0.04888596758246422, 0.04897310957312584, -0.051456619054079056, 0.030237844213843346, -0.037100180983543396, -0.01875704899430275, -0.005920125637203455, 0.05119519680738449, -0.02254767343401909, 0.0017768546240404248, 0.02089199796319008, -0.037209104746580124, 0.04736100509762764, -0.011546150781214237, 0.02723148837685585, -0.004030260257422924, -0.04433286190032959, 0.0071945590898394585, -0.01254826970398426, 0.04744814708828926, 0.051979467272758484, -0.006039944011718035, 0.0467945896089077, -0.05128233879804611, 0.03097854182124138, -0.10108328610658646, -0.014955533668398857, 0.03718731924891472, 0.04723029211163521, 0.019780952483415604, -0.033745259046554565, -0.02557581476867199, 0.030804259702563286, 0.010968843474984169, -0.0004152801993768662, -0.04627174511551857, 0.026360081508755684, 0.06849264353513718, -0.03352740779519081, 0.009678071364760399, -0.05350442975759506, 0.046446025371551514, 0.08038735389709473, 0.018953116610646248, 0.029627859592437744, 0.000499357411172241, -0.013702885247766972, 0.04736100509762764, 0.02199215069413185, -0.03925691545009613, 0.016850845888257027, -0.00033835123758763075, 0.0923692062497139, -0.025967948138713837, 0.008899250067770481, 0.0009136164444498718, -0.028342533856630325, -0.02581545151770115, -0.0215891245752573, 0.011622399091720581, 0.03391954302787781, -0.019573993980884552, 0.0017346458043903112, -0.017852963879704475, 0.034311674535274506, 0.006029051728546619, 0.0027422108687460423, -0.025510458275675774, 0.03167566657066345, 0.06261064112186432, -0.07559461146593094, 0.010075651109218597, -0.07803455740213394, 0.011350084096193314, 0.04300396516919136, -0.016121041029691696, 0.0621313638985157, -0.05938643217086792, -0.006464755162596703, 0.038385506719350815, 0.049234531819820404, -0.0032868406269699335, -0.01022270042449236, -0.01069108210504055, 0.01981363072991371, 0.013822703622281551, -0.013790025375783443, 0.10587602853775024, -0.011916499584913254, 0.05176161229610443, -0.01791832037270069, 0.012918618507683277, -0.028168251737952232, -0.006464755162596703, 0.003981243818998337, -0.03675161674618721, 0.013223610818386078, 0.08021306991577148, -0.009149780496954918, -0.03204601630568504, -0.016872629523277283, -0.037579454481601715, 0.061303526163101196, -0.006998492404818535, 0.017569756135344505, 0.013103792443871498, -0.0609113946557045, 0.06369990110397339, 0.05280730128288269, 0.024094421416521072, 0.021839654073119164, -0.021273238584399223, 0.05028022080659866, -0.04631531611084938, 0.019225431606173515, -0.023375509306788445, -0.048711687326431274, 0.07162971049547195, -0.02775433287024498, 0.051413051784038544, -0.04566175863146782, 0.04862454533576965, 0.021393056958913803, 0.05973499268293381, -0.04675101861357689, -0.030521051958203316, -0.044354647397994995, -0.004365207627415657, 0.005078672431409359, -0.054811540991067886, 0.05455011874437332, -0.0074995518662035465, -0.04775313660502434, 0.001688352320343256, -0.023135872557759285, -0.015097137540578842, -0.02594616264104843, -0.004259004723280668, 0.0028865376953035593, 0.051500190049409866, -0.0009347208542749286, -0.030324986204504967, 0.0009633139125071466, -0.013288966380059719, -0.0516309030354023, 0.000268740754108876, -0.026360081508755684, 0.0039839670062065125, 0.02166537195444107, -0.03311349079012871, -0.002544782590121031, 0.046010322868824005, -0.04219791293144226, 0.019857201725244522, 0.007063847966492176, -0.06313348561525345, 0.018288668245077133, 0.013278073631227016, -0.001277837553061545, -0.02267838455736637, -0.019857201725244522, 0.05720791220664978, 0.0019239046378061175, -0.014149481430649757, 0.03524843975901604, -0.04117400944232941, 0.031131038442254066, 0.010217254981398582, -0.0215782318264246, -0.011764002963900566, 0.003847809275612235, 0.0355098620057106, -0.0431564636528492, -0.07036616653203964, -0.03082604520022869, 0.028691096231341362, -0.012210599146783352, -0.03058640845119953, -0.04731743410229683, 0.013321644626557827, -0.056990060955286026, 0.03365812078118324, -0.012341310270130634, 0.024050850421190262, -0.02524903602898121, 0.00417731050401926, -0.02178519032895565, 0.020870212465524673, -0.0034012128598988056, -0.005980034824460745, -0.01345235574990511, -0.06139066815376282, -0.009716195054352283, 0.03206780180335045, 0.044921062886714935, 0.035597000271081924, 0.05019307881593704, -0.02032558247447014, -0.03143602982163429, 0.11363155394792557, -0.08400369435548782, -0.002802120288833976, -0.004106508567929268, -0.0726318284869194, -0.024878688156604767, 0.018288668245077133, -0.00822935625910759, -0.038625143468379974, 0.01551105547696352, 0.02424691803753376, 0.0018748879665508866, 0.05659792572259903, -0.02727505937218666, 0.06483272463083267, 0.06256707012653351, -0.0011062792036682367, 0.0021744342520833015, 0.029475362971425056, 0.04333074390888214, 0.0674033835530281, -0.030281415209174156, 0.03803694248199463, -0.021970365196466446, -0.011426332406699657, 0.016404248774051666, -0.021327702328562737, 0.02742755599319935, 0.010347966104745865, -0.04291682690382004, 0.01686173863708973, 0.01184025127440691, -0.006900459062308073, 0.04696886986494064, 0.023767642676830292, 0.05542152374982834, -0.010990628972649574, 0.0007536314660683274, 0.040520455688238144, 0.03442060202360153, -0.0629156306385994, -0.04784027859568596, 0.01131740678101778, 0.005201214458793402, 0.02537974715232849, 0.024747977033257484, -0.002773527055978775, 0.05006236955523491, 0.06579127907752991, 0.005729505326598883, -0.008479885756969452, -0.03339669853448868, -0.030934970825910568, 0.0589071549475193, -0.028102897107601166, -0.024072635918855667, 0.1004732996225357, -0.05912500619888306, -0.00400575203821063, 0.01831045374274254, 0.018615445122122765, 0.02533617615699768, -0.04587961360812187, -0.026316510513424873, 0.016556745395064354, -0.05437583476305008, 0.06513772159814835, -0.0019497745670378208, 0.022852664813399315, -0.038015156984329224, 0.027078991755843163, 0.06139066815376282, -0.013866273686289787, 0.01771136000752449, 0.020064160227775574, -0.010658404789865017, -0.022199109196662903, -0.010157344862818718, -0.03764481097459793, -0.012265062890946865, -0.008283819071948528, -0.06570413708686829, 0.008267479948699474, -0.015358559787273407, 0.055726516991853714, -0.001524963416159153, 0.05058521404862404, 0.037862662225961685, -0.03703482449054718, 0.044311076402664185, -0.028821807354688644, 0.008779431693255901, 0.01264630351215601, -0.024334058165550232, 0.010533140040934086, -0.02065236121416092, -0.0049724699929356575, 0.03167566657066345, -0.013376107439398766, 0.036969467997550964, -0.025924377143383026, -0.01912739686667919, -0.01968291960656643, -0.002502573886886239, 0.030564622953534126, 0.03784087672829628, -0.024900473654270172, 0.010282610543072224, 0.021120741963386536, -0.05232802778482437, 0.002306506969034672, -0.05537795647978783, 0.004226326942443848, 0.04054224118590355, -0.03614163026213646, -0.020968245342373848, -0.06156494840979576, -0.008419976569712162, -0.030717119574546814, 0.02259124256670475, -0.017820285633206367, -0.038472648710012436, 0.028538599610328674, -0.03646840900182724, -0.005822092294692993, -0.032656002789735794, -0.006655375938862562, 0.05333014577627182, 0.014933748170733452, 0.014574293047189713, -0.02036915346980095, 0.07838311791419983, -0.0012921341694891453, -0.03178459405899048, -0.006704392377287149, 0.031610313802957535, 0.014127695932984352, -0.027732547372579575, 0.07572532445192337, 0.0005517780664376915, -0.03278671205043793, 0.03742695972323418, -0.04892953857779503, 0.025074753910303116, 0.00008007759606698528, -0.005331925582140684, -0.055334385484457016, 0.007559461053460836, 0.04470321163535118, -0.02267838455736637, -0.01650228165090084, 0.01548927091062069, -0.01747172325849533, 0.007412411272525787, -0.0029001536313444376, -0.0560750812292099, 0.019105613231658936, 0.024377629160881042, 0.013310751877725124, 0.011546150781214237, 0.01626264490187168, -0.05450654774904251, 0.037383388727903366, 0.023026946932077408, 0.04740457609295845, -0.021436627954244614, -0.008801217190921307, -0.009367631748318672, 0.04688173159956932, -0.059647854417562485, -0.010429659858345985, -0.017689574509859085, -0.021088065579533577, -0.08173803985118866, 0.006639036815613508, -0.026076873764395714, -0.08918856829404831, -0.03041212633252144, 0.012907725758850574, 0.046010322868824005, 0.01050590816885233, -0.01107232365757227, 0.08252230286598206, 0.036403052508831024, -0.0009265514090657234, -0.03740517422556877, 0.0786881074309349, 0.00031537466566078365, -0.07655315846204758, -0.0027667193207889795, 0.00435703806579113, -0.032612431794404984, 0.011328299529850483, -0.043025750666856766, 0.029017874971032143, -0.010315287858247757, -0.0038695945404469967, -0.016317108646035194, -0.02633829601109028, 0.03069533407688141, 0.024660836905241013, -0.03400668129324913, 0.045400336384773254, 0.010963397100567818, -0.009345847181975842, -0.0031534063164144754, 0.014378226362168789, -0.0020736779551953077, -0.06400489062070847, 0.026774000376462936, -0.00130574987269938, -0.02553224377334118, -0.0016189119778573513, 0.02557581476867199, -0.033788830041885376, 0.0007897131727077067, 0.02941000834107399, 0.028255391865968704, -0.050367362797260284, -0.013430570252239704, -0.07406964898109436, 0.012265062890946865, -0.03651197999715805, 0.009002730250358582, 0.006421185098588467, 0.01751529425382614, -0.036119844764471054, 0.01456340029835701, 0.049190960824489594, -0.061259955167770386, 0.00612163869664073, -0.02259124256670475, 0.026926495134830475, 0.08099734038114548, -0.02956250309944153, 0.03707839548587799, 0.038908351212739944, -0.009645393118262291, -0.007488659583032131, -0.002608776558190584, 0.007461427710950375, 0.06313348561525345, -0.020151302218437195, -0.010898041538894176, -0.047099582850933075, -0.013561281375586987, -0.02307051792740822, 0.035117726773023605, -0.031523171812295914, 0.04958309605717659, -0.0007066571270115674, -0.049757376313209534, 0.03474738076329231, 0.005187598522752523, 0.03202423080801964, -0.013321644626557827, 0.010037526488304138, 0.005882001481950283, -0.0005017401999793947, -0.004493195563554764, -0.026207584887742996, -0.059604283422231674, 0.005587901454418898, -0.025641169399023056, 0.01351771131157875, 0.0049561308696866035, -0.028495030477643013, 0.03193708881735802, 0.029998207464814186, 0.06139066815376282 ]
30,906
networkx.algorithms.cycles
minimum_cycle_basis
Returns a minimum weight cycle basis for G Minimum weight means a cycle basis for which the total weight (length for unweighted graphs) of all the cycles is minimum. Parameters ---------- G : NetworkX Graph weight: string name of the edge attribute to use for edge weights Returns ------- A list of cycle lists. Each cycle list is a list of nodes which forms a cycle (loop) in G. Note that the nodes are not necessarily returned in a order by which they appear in the cycle Examples -------- >>> G = nx.Graph() >>> nx.add_cycle(G, [0, 1, 2, 3]) >>> nx.add_cycle(G, [0, 3, 4, 5]) >>> nx.minimum_cycle_basis(G) [[5, 4, 3, 0], [3, 2, 1, 0]] References: [1] Kavitha, Telikepalli, et al. "An O(m^2n) Algorithm for Minimum Cycle Basis of Graphs." http://link.springer.com/article/10.1007/s00453-007-9064-z [2] de Pina, J. 1995. Applications of shortest path methods. Ph.D. thesis, University of Amsterdam, Netherlands See Also -------- simple_cycles, cycle_basis
def recursive_simple_cycles(G): """Find simple cycles (elementary circuits) of a directed graph. A `simple cycle`, or `elementary circuit`, is a closed path where no node appears twice. Two elementary circuits are distinct if they are not cyclic permutations of each other. This version uses a recursive algorithm to build a list of cycles. You should probably use the iterator version called simple_cycles(). Warning: This recursive version uses lots of RAM! It appears in NetworkX for pedagogical value. Parameters ---------- G : NetworkX DiGraph A directed graph Returns ------- A list of cycles, where each cycle is represented by a list of nodes along the cycle. Example: >>> edges = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)] >>> G = nx.DiGraph(edges) >>> nx.recursive_simple_cycles(G) [[0], [2], [0, 1, 2], [0, 2], [1, 2]] Notes ----- The implementation follows pp. 79-80 in [1]_. The time complexity is $O((n+e)(c+1))$ for $n$ nodes, $e$ edges and $c$ elementary circuits. References ---------- .. [1] Finding all the elementary circuits of a directed graph. D. B. Johnson, SIAM Journal on Computing 4, no. 1, 77-84, 1975. https://doi.org/10.1137/0204007 See Also -------- simple_cycles, cycle_basis """ # Jon Olav Vik, 2010-08-09 def _unblock(thisnode): """Recursively unblock and remove nodes from B[thisnode].""" if blocked[thisnode]: blocked[thisnode] = False while B[thisnode]: _unblock(B[thisnode].pop()) def circuit(thisnode, startnode, component): closed = False # set to True if elementary path is closed path.append(thisnode) blocked[thisnode] = True for nextnode in component[thisnode]: # direct successors of thisnode if nextnode == startnode: result.append(path[:]) closed = True elif not blocked[nextnode]: if circuit(nextnode, startnode, component): closed = True if closed: _unblock(thisnode) else: for nextnode in component[thisnode]: if thisnode not in B[nextnode]: # TODO: use set for speedup? B[nextnode].append(thisnode) path.pop() # remove thisnode from path return closed path = [] # stack of nodes in current path blocked = defaultdict(bool) # vertex: blocked from search? B = defaultdict(list) # graph portions that yield no elementary circuit result = [] # list to accumulate the circuits found # Johnson's algorithm exclude self cycle edges like (v, v) # To be backward compatible, we record those cycles in advance # and then remove from subG for v in G: if G.has_edge(v, v): result.append([v]) G.remove_edge(v, v) # Johnson's algorithm requires some ordering of the nodes. # They might not be sortable so we assign an arbitrary ordering. ordering = dict(zip(G, range(len(G)))) for s in ordering: # Build the subgraph induced by s and following nodes in the ordering subgraph = G.subgraph(node for node in G if ordering[node] >= ordering[s]) # Find the strongly connected component in the subgraph # that contains the least node according to the ordering strongcomp = nx.strongly_connected_components(subgraph) mincomp = min(strongcomp, key=lambda ns: min(ordering[n] for n in ns)) component = G.subgraph(mincomp) if len(component) > 1: # smallest node in the component according to the ordering startnode = min(component, key=ordering.__getitem__) for node in component: blocked[node] = False B[node][:] = [] dummy = circuit(startnode, startnode, component) return result
(G, weight=None, *, backend=None, **backend_kwargs)
[ 0.021066512912511826, -0.03182429447770119, -0.04127396270632744, 0.02901282347738743, -0.03898964449763298, -0.001081147463992238, -0.0385991595685482, -0.01456498447805643, 0.07563639432191849, -0.05904090031981468, -0.025049429386854172, 0.039106786251068115, 0.00018090306548401713, 0.0024563767947256565, -0.02993045747280121, -0.02840757556259632, 0.0031262976117432117, 0.0029334970749914646, -0.03619769588112831, 0.03887249901890755, -0.015921909362077713, -0.04217207059264183, 0.04107872396707535, 0.04756072536110878, -0.018879812210798264, 0.05911899730563164, -0.0024588173255324364, 0.024248940870165825, -0.09793291985988617, -0.02061745710670948, 0.012934721074998379, 0.002019524807110429, -0.07958026230335236, -0.04994266852736473, 0.024366086348891258, 0.06618672609329224, 0.015043324790894985, 0.05236365646123886, -0.07833071798086166, 0.009073829278349876, 0.03194143995642662, -0.009932889603078365, 0.011255647987127304, -0.05033314973115921, 0.04330446943640709, -0.014701653271913528, 0.02975473925471306, 0.08582797646522522, -0.014311171136796474, -0.05439416319131851, 0.051582690328359604, -0.00570592051371932, -0.04146920517086983, 0.001165955327451229, 0.04459306225180626, 0.011128741316497326, 0.01022087037563324, 0.043538760393857956, 0.07259063422679901, -0.024971334263682365, -0.013979260809719563, -0.021847477182745934, 0.02452227845788002, 0.052129365503787994, -0.0586504191160202, -0.014955466613173485, -0.013403300195932388, -0.04736548662185669, -0.008292865008115768, 0.00224893307313323, 0.003702258924022317, -0.004832216538488865, 0.017698602750897408, -0.04775596782565117, -0.014828559942543507, -0.05220746248960495, -0.008483224548399448, -0.008034170605242252, -0.0051641263999044895, -0.022257482632994652, 0.02450275421142578, -0.011197075247764587, 0.0024392930790781975, -0.04732643812894821, 0.029071396216750145, -0.0004176328657194972, 0.015297138132154942, 0.03647103160619736, -0.040219660848379135, -0.02378036268055439, -0.007243443746119738, -0.0247370433062315, 0.006647958420217037, 0.09004518389701843, 0.02747041918337345, 0.0033825517166405916, -0.03567054495215416, -0.05533131957054138, 0.030750470235943794, 0.0015033562667667866, 0.00706284586340189, 0.003931667190045118, -0.11691035330295563, -0.013354489579796791, -0.024287989363074303, -0.026240400969982147, -0.03358146548271179, 0.02337035723030567, 0.008200124837458134, -0.08645274490118027, -0.05181698128581047, 0.05646371841430664, 0.01596095785498619, -0.03469434008002281, -0.010894452221691608, 0.05943138152360916, 0.028309956192970276, -0.027197081595659256, 0.0071799904108047485, -0.014262360520660877, -0.014525935985147953, -0.021593661978840828, -0.04154730215668678, 0.044514965265989304, 0.02081269770860672, -0.0016168401343747973, 0.00902013760060072, 0.02133984863758087, 0.008693109266459942, -0.008234292268753052, 0.06189142167568207, 0.03813058137893677, 0.023467976599931717, 0.07036488503217697, -0.000671751331537962, -0.02284320630133152, -0.05181698128581047, -0.01970958709716797, -0.019084814935922623, 0.016497870907187462, -0.016087865456938744, -0.10496160387992859, 0.01226113922894001, 0.06653815507888794, 0.03955584019422531, -0.015472855418920517, 0.035748641937971115, -0.024600375443696976, 0.0028749248012900352, 0.030223319306969643, 0.014389267191290855, 0.0024319717194885015, 0.025752298533916473, 0.002019524807110429, 0.02194509655237198, -0.003353265579789877, -0.04053204879164696, 0.04549117013812065, -0.04619403928518295, 0.024405134841799736, -0.03196096420288086, -0.0063697402365505695, -0.024639423936605453, 0.006887129042297602, -0.027997570112347603, 0.019055528566241264, 0.023526549339294434, -0.008566202595829964, -0.05216841399669647, 0.0254399124532938, 0.0073117781430482864, 0.00645759841427207, -0.07165347784757614, 0.011187314055860043, 0.0037535096053034067, 0.0356900691986084, 0.013237345032393932, 0.03721294924616814, 0.010660163126885891, -0.018840763717889786, -0.021652234718203545, -0.009342285804450512, -0.026338020339608192, -0.015394758433103561, 0.014399029314517975, 0.028719961643218994, 0.06829532980918884, -0.05115316063165665, 0.05814279243350029, 0.009166568517684937, -0.06310191750526428, 0.01029896643012762, 0.04498354345560074, 0.05763516575098038, 0.0699744001030922, -0.03785724565386772, -0.02028554677963257, 0.029813311994075775, -0.05872851610183716, 0.0814545750617981, 0.01412569172680378, 0.030711421743035316, 0.05365224927663803, -0.0022013431880623102, 0.045217834413051605, 0.0326833575963974, 0.014730938710272312, -0.005510679446160793, 0.01635144092142582, 0.013598540797829628, -0.056190382689237595, -0.050996970385313034, 0.03192191570997238, -0.01655644364655018, -0.04127396270632744, 0.026298973709344864, -0.003289812011644244, 0.01930934190750122, 0.017727889120578766, -0.0687248557806015, -0.03326907753944397, 0.01022087037563324, -0.00890787411481142, -0.022765109315514565, -0.009991462342441082, -0.025127526372671127, 0.039087262004613876, 0.012514952570199966, 0.026865171268582344, -0.021632710471749306, 0.027821853756904602, 0.004732155706733465, 0.043538760393857956, -0.011392316780984402, 0.010396587662398815, -0.05345700681209564, -0.03678341954946518, 0.004641856532543898, 0.020324595272541046, -0.0024356325156986713, -0.048732172697782516, -0.06970106065273285, -0.0008627215283922851, -0.012768765911459923, 0.014545460231602192, -0.015726668760180473, 0.04045395180583, -0.00018059799913316965, -0.013891402631998062, -0.001361806527711451, -0.08098600059747696, -0.05181698128581047, -0.0006955463322810829, -0.06544480472803116, 0.008492986671626568, -0.04025870934128761, -0.04529592767357826, -0.02696279250085354, -0.0005201344029046595, 0.011460650712251663, 0.01142160315066576, 0.016820019111037254, -0.047248341143131256, 0.021886523813009262, -0.0024405133444815874, 0.008619893342256546, 0.011167789809405804, 0.017366694286465645, -0.03358146548271179, 0.026982316747307777, 0.07606592029333115, -0.05872851610183716, 0.011372792534530163, 0.008629655465483665, -0.047248341143131256, 0.027060413733124733, -0.005559489596635103, 0.03125809505581856, -0.022706536576151848, -0.05263699218630791, -0.07876025140285492, 0.027411846444010735, 0.0007028678664937615, -0.0045320335775613785, -0.04697500169277191, -0.014701653271913528, 0.004827335476875305, -0.042445410043001175, 0.000629042333457619, -0.005627823993563652, 0.07442589849233627, -0.033698610961437225, 0.0512312576174736, 0.028563769534230232, 0.044671159237623215, 0.006384382955729961, -0.020929843187332153, -0.0784478634595871, 0.0023477738723158836, 0.026279449462890625, 0.010943261906504631, -0.05013790726661682, 0.0017644912004470825, -0.02622087672352791, 0.007365469355136156, -0.04474925622344017, 0.009317880496382713, -0.023663219064474106, -0.00004362417894299142, -0.011665654368698597, -0.04904455691576004, 0.024034176021814346, 0.011480174958705902, 0.02208176627755165, -0.0047565605491399765, -0.06017329916357994, -0.028329480439424515, -0.021613186225295067, 0.06794389337301254, 0.05240270495414734, 0.015707144513726234, 0.043460663408041, -0.04314827919006348, 0.04084443300962448, -0.05950947850942612, 0.04482734948396683, 0.06376573443412781, 0.05255889892578125, 0.03699818253517151, 0.005374010652303696, -0.005608299747109413, 0.02286273054778576, -0.014096405357122421, 0.04307018220424652, 0.0036924968007951975, 0.011460650712251663, 0.0627114325761795, -0.054667502641677856, -0.02212081290781498, -0.07989265024662018, 0.0761440172791481, 0.05408177897334099, -0.013891402631998062, -0.01875290460884571, 0.002579622669145465, -0.009127520024776459, 0.04935694485902786, 0.01171446405351162, -0.02059793286025524, 0.025928014889359474, 0.03291764482855797, 0.06821723282337189, -0.03606102615594864, 0.019416725262999535, -0.025049429386854172, 0.029852360486984253, 0.010640638880431652, -0.005325200501829386, -0.010650401003658772, -0.005222698673605919, 0.02618182823061943, 0.03692008554935455, -0.008102504536509514, -0.01392068900167942, 0.04845883324742317, -0.005984139163047075, -0.017600983381271362, 0.04349971190094948, 0.0019841373432427645, -0.05497988685965538, -0.03420623764395714, -0.00011455159983597696, 0.006106164772063494, -0.003219037316739559, 0.0021805986762046814, 0.035221491008996964, 0.024990858510136604, -0.016273343935608864, 0.05279318615794182, 0.027001840993762016, -0.001082367729395628, -0.006823675706982613, 0.0010701651917770505, 0.011538747698068619, 0.030242841690778732, -0.002774863736703992, 0.04463211074471474, 0.026982316747307777, 0.08278221637010574, -0.011382554657757282, -0.04607689380645752, -0.050801727920770645, 0.02378036268055439, 0.00910799577832222, -0.045803554356098175, -0.012544238939881325, 0.14377552270889282, 0.03553387522697449, -0.007965835742652416, -0.01392068900167942, -0.0002666260988917202, 0.013754733838140965, 0.03028189018368721, 0.028895679861307144, 0.005486274138092995, -0.02825138345360756, 0.04795120656490326, 0.00021827341697644442, 0.002745577599853277, -0.007492376025766134, -0.031238572672009468, 0.009830388240516186, 0.004666261840611696, -0.016966449096798897, 0.013286154717206955, -0.05579989776015282, -0.03785724565386772, -0.0009133621351793408, 0.07344969362020493, 0.02469799667596817, 0.042796842753887177, -0.008410009555518627, 0.04572546109557152, -0.008200124837458134, 0.009596099145710468, 0.020910318940877914, 0.026982316747307777, 0.03346432000398636, -0.04642832651734352, 0.06825628131628036, -0.0031995130702853203, -0.02916901744902134, -0.02895425073802471, -0.04920075088739395, -0.019777920097112656, -0.024619899690151215, 0.04369495436549187, -0.020578408613801003, 0.05736182630062103, 0.026318496093153954, -0.021652234718203545, 0.06478098779916763, -0.009395976550877094, -0.035592447966337204, 0.05166078731417656, -0.018460042774677277, 0.004151313565671444, 0.033151935786008835, 0.011938991956412792, -0.017005497589707375, 0.021300802007317543, -0.028856631368398666, 0.030965235084295273, -0.05150459706783295, -0.12284568697214127, 0.03139476478099823, 0.0180207509547472, 0.018616236746311188, -0.050411246716976166, 0.025225147604942322, 0.06681149452924728, 0.022237958386540413, 0.016966449096798897, 0.013754733838140965, -0.05349605530500412, -0.042796842753887177, 0.01141184102743864, 0.014935942366719246, -0.021847477182745934, 0.004026846960186958, 0.03449909761548042, -0.022804157808423042, -0.08043932169675827, -0.03264430910348892, 0.030399035662412643, -0.02118365652859211, -0.07161442935466766, -0.013120200484991074, -0.001753508928231895, -0.08122028410434723, -0.07548020035028458, -0.014633318409323692, 0.022159861400723457, -0.01763026975095272, -0.003787676803767681, -0.030887138098478317, 0.039087262004613876, -0.005447226110845804, -0.022901777178049088, -0.059704720973968506, -0.05224651098251343, -0.02044174075126648, -0.021632710471749306, 0.01023063249886036, 0.02545943669974804, 0.06892009824514389, -0.04428067430853844, -0.018440520390868187, 0.08871754258871078, -0.024366086348891258, 0.012485667131841183, -0.004522271454334259, -0.0007126299315132201, 0.008649179711937904, 0.04537402465939522, 0.031101902946829796, 0.015248327516019344, -0.007204395718872547, 0.0254399124532938, 0.006755341310054064, 0.028134239837527275, -0.006071997340768576, 0.019250769168138504, 0.045022591948509216, 0.01097254827618599, 0.0017400861252099276, -0.013764495961368084, -0.004200123716145754, 0.0363929346203804, -0.027060413733124733, 0.012934721074998379, 0.020226975902915, 0.004895669873803854, 0.05361320078372955, -0.008502748794853687, 0.019807206466794014, -0.0006208056001923978, -0.050606485456228256, -0.026806600391864777, -0.008380723185837269, 0.006125688552856445, 0.020344119518995285, -0.025713250041007996, 0.09613670408725739, 0.010172059759497643, -0.01689811423420906, 0.0471702441573143, 0.018489329144358635, -0.05872851610183716, 0.0009048203355632722, 0.022921301424503326, 0.03906773775815964, 0.0706772655248642, 0.009181211702525616, 0.006735817063599825, 0.020480789244174957, 0.05646371841430664, 0.016810256987810135, -0.03301526606082916, -0.03678341954946518, -0.004046371206641197, 0.006735817063599825, -0.007448446936905384, -0.027978045865893364, 0.06278952956199646, -0.08512511104345322, -0.020695554092526436, 0.014506411738693714, 0.0028700437396764755, 0.02450275421142578, -0.03305431455373764, 0.003421599743887782, -0.0657181441783905, -0.08246982842683792, 0.04111776873469353, -0.02231605537235737, 0.07532400637865067, -0.029500925913453102, 0.01857718825340271, 0.033347174525260925, 0.012944483198225498, -0.0021086037158966064, 0.03291764482855797, -0.026806600391864777, -0.0009993902640417218, 0.03711532801389694, -0.020519837737083435, -0.02153509110212326, 0.00095180026255548, -0.06946677714586258, -0.007580234669148922, -0.04435877129435539, -0.007155585568398237, 0.012485667131841183, 0.059353288263082504, -0.008112266659736633, -0.022589392960071564, 0.004122027195990086, -0.03045760840177536, -0.007267849054187536, 0.03010617382824421, -0.05923614278435707, 0.03063332475721836, -0.00571080157533288, -0.020539361983537674, 0.032234299927949905, -0.0027968285139650106, 0.02731422707438469, -0.0034752911888062954, -0.014067119918763638, -0.03196096420288086, 0.01576571725308895, 0.04045395180583, 0.04998171702027321, -0.03467481583356857, 0.023507025092840195, 0.019748635590076447, -0.0630628690123558, 0.0441635325551033, -0.018840763717889786, 0.0019365474581718445, 0.052676040679216385, -0.003360586939379573, 0.0064820037223398685, -0.0669676885008812, 0.011812085285782814, -0.043382566422224045, 0.015199517831206322, -0.024229416623711586, -0.008034170605242252, 0.006935939192771912, 0.0013068949338048697, 0.013256869278848171, -0.02803661860525608, -0.07095060497522354, 0.025596104562282562, 0.02342892810702324, 0.009522883221507072, 0.029383782297372818, 0.0699744001030922, 0.013705923222005367, -0.004810251761227846, -0.012300187721848488, 0.058220889419317245, 0.007267849054187536, -0.0694277286529541, 0.0019219043897464871, -0.0026503975968807936, -0.013169010169804096, 0.08746799826622009, -0.06649910658597946, -0.015531427226960659, -0.05244175344705582, 0.018274564296007156, -0.07829166948795319, -0.04549117013812065, 0.031160475686192513, -0.04474925622344017, 0.019036004319787025, 0.04123491421341896, -0.03104333020746708, 0.02325321175158024, 0.02993045747280121, -0.014477125369012356, -0.005842589307576418, 0.05345700681209564, 0.03980965539813042, -0.03190239146351814, 0.017708364874124527, -0.04045395180583, 0.056385621428489685, 0.005281270947307348, 0.01540452055633068, -0.01292495895177126, -0.021027464419603348, -0.003023796249181032, 0.07344969362020493, -0.02133984863758087, -0.034635767340660095, 0.015394758433103561, -0.022237958386540413, -0.06782674789428711, 0.0022892015986144543, -0.02413179725408554, -0.07766690105199814, -0.004014644771814346, -0.03805248439311981, 0.040766336023807526, -0.007536305580288172, -0.017171451821923256, 0.0166931115090847, 0.01226113922894001, -0.029793787747621536, -0.03340574726462364, -0.0006314828642643988, -0.002591825323179364, -0.002142770914360881, -0.053417958319187164, 0.037466760724782944, -0.07860405743122101, 0.0018511294620111585, 0.013198296539485455, 0.03364003822207451, 0.018264802172780037, -0.014467363245785236, 0.0247370433062315, 0.016624776646494865, 0.010045153088867664, 0.04439781978726387, -0.05314461886882782, 0.0542379692196846, -0.013120200484991074, 0.020480789244174957, 0.028856631368398666, -0.0025405744090676308, 0.00012484751641750336, -0.05142650008201599, 0.004998171702027321, 0.03006712533533573, 0.043812096118927, -0.0016192806651815772, 0.009532645344734192, -0.0033825517166405916, -0.0037998794578015804, 0.017757175490260124, -0.0674753189086914, -0.01457474660128355, -0.02376083843410015, -0.046154990792274475, 0.029286161065101624, -0.005183650646358728, 0.009161687456071377, -0.026787076145410538, 0.0308285653591156, -0.022511295974254608, 0.09020137786865234, 0.05111411213874817, -0.023175114765763283, 0.015004276297986507, -0.02059793286025524, -0.04123491421341896, 0.06278952956199646, -0.010982310399413109, 0.031238572672009468, 0.025361815467476845, -0.04443686828017235, -0.020715078338980675, 0.003350825048983097, -0.010074439458549023, 0.02971569076180458, -0.0060915215872228146, -0.035963404923677444, -0.06278952956199646, 0.029637595638632774, -0.018255040049552917, -0.022003669291734695, 0.01097254827618599, 0.062164757400751114, 0.01804027520120144, -0.09746434539556503, -0.0057205636985599995, -0.03172667324542999, -0.027919473126530647, -0.03953631594777107, -0.008771205320954323, 0.01012325007468462, -0.05982186645269394, -0.009971938095986843, -0.05142650008201599, -0.053574152290821075, -0.013901164755225182, 0.007775475736707449, 0.02212081290781498, 0.02337035723030567, -0.03432337939739227, 0.02936425805091858, 0.0003340452676638961, 0.055995140224695206 ]
30,909
networkx.algorithms.tree.branchings
minimum_spanning_arborescence
Returns a minimum spanning arborescence from G. Parameters ---------- G : (multi)digraph-like The graph to be searched. attr : str The edge attribute used to in determining optimality. default : float The value of the edge attribute used if an edge does not have the attribute `attr`. preserve_attrs : bool If True, preserve the other attributes of the original graph (that are not passed to `attr`) partition : str The key for the edge attribute containing the partition data on the graph. Edges can be included, excluded or open using the `EdgePartition` enum. Returns ------- B : (multi)digraph-like A minimum spanning arborescence. Raises ------ NetworkXException If the graph does not contain a minimum spanning arborescence.
@nx._dispatchable(preserve_edge_attrs=True, returns_graph=True) def maximum_branching( G, attr="weight", default=1, preserve_attrs=False, partition=None, ): ####################################### ### Data Structure Helper Functions ### ####################################### def edmonds_add_edge(G, edge_index, u, v, key, **d): """ Adds an edge to `G` while also updating the edge index. This algorithm requires the use of an external dictionary to track the edge keys since it is possible that the source or destination node of an edge will be changed and the default key-handling capabilities of the MultiDiGraph class do not account for this. Parameters ---------- G : MultiDiGraph The graph to insert an edge into. edge_index : dict A mapping from integers to the edges of the graph. u : node The source node of the new edge. v : node The destination node of the new edge. key : int The key to use from `edge_index`. d : keyword arguments, optional Other attributes to store on the new edge. """ if key in edge_index: uu, vv, _ = edge_index[key] if (u != uu) or (v != vv): raise Exception(f"Key {key!r} is already in use.") G.add_edge(u, v, key, **d) edge_index[key] = (u, v, G.succ[u][v][key]) def edmonds_remove_node(G, edge_index, n): """ Remove a node from the graph, updating the edge index to match. Parameters ---------- G : MultiDiGraph The graph to remove an edge from. edge_index : dict A mapping from integers to the edges of the graph. n : node The node to remove from `G`. """ keys = set() for keydict in G.pred[n].values(): keys.update(keydict) for keydict in G.succ[n].values(): keys.update(keydict) for key in keys: del edge_index[key] G.remove_node(n) ####################### ### Algorithm Setup ### ####################### # Pick an attribute name that the original graph is unlikly to have candidate_attr = "edmonds' secret candidate attribute" new_node_base_name = "edmonds new node base name " G_original = G G = nx.MultiDiGraph() G.__networkx_cache__ = None # Disable caching # A dict to reliably track mutations to the edges using the key of the edge. G_edge_index = {} # Each edge is given an arbitrary numerical key for key, (u, v, data) in enumerate(G_original.edges(data=True)): d = {attr: data.get(attr, default)} if data.get(partition) is not None: d[partition] = data.get(partition) if preserve_attrs: for d_k, d_v in data.items(): if d_k != attr: d[d_k] = d_v edmonds_add_edge(G, G_edge_index, u, v, key, **d) level = 0 # Stores the number of contracted nodes # These are the buckets from the paper. # # In the paper, G^i are modified versions of the original graph. # D^i and E^i are the nodes and edges of the maximal edges that are # consistent with G^i. In this implementation, D^i and E^i are stored # together as the graph B^i. We will have strictly more B^i then the # paper will have. # # Note that the data in graphs and branchings are tuples with the graph as # the first element and the edge index as the second. B = nx.MultiDiGraph() B_edge_index = {} graphs = [] # G^i list branchings = [] # B^i list selected_nodes = set() # D^i bucket uf = nx.utils.UnionFind() # A list of lists of edge indices. Each list is a circuit for graph G^i. # Note the edge list is not required to be a circuit in G^0. circuits = [] # Stores the index of the minimum edge in the circuit found in G^i and B^i. # The ordering of the edges seems to preserver the weight ordering from # G^0. So even if the circuit does not form a circuit in G^0, it is still # true that the minimum edges in circuit G^0 (despite their weights being # different) minedge_circuit = [] ########################### ### Algorithm Structure ### ########################### # Each step listed in the algorithm is an inner function. Thus, the overall # loop structure is: # # while True: # step_I1() # if cycle detected: # step_I2() # elif every node of G is in D and E is a branching: # break ################################## ### Algorithm Helper Functions ### ################################## def edmonds_find_desired_edge(v): """ Find the edge directed towards v with maximal weight. If an edge partition exists in this graph, return the included edge if it exists and never return any excluded edge. Note: There can only be one included edge for each vertex otherwise the edge partition is empty. Parameters ---------- v : node The node to search for the maximal weight incoming edge. """ edge = None max_weight = -INF for u, _, key, data in G.in_edges(v, data=True, keys=True): # Skip excluded edges if data.get(partition) == nx.EdgePartition.EXCLUDED: continue new_weight = data[attr] # Return the included edge if data.get(partition) == nx.EdgePartition.INCLUDED: max_weight = new_weight edge = (u, v, key, new_weight, data) break # Find the best open edge if new_weight > max_weight: max_weight = new_weight edge = (u, v, key, new_weight, data) return edge, max_weight def edmonds_step_I2(v, desired_edge, level): """ Perform step I2 from Edmonds' paper First, check if the last step I1 created a cycle. If it did not, do nothing. If it did, store the cycle for later reference and contract it. Parameters ---------- v : node The current node to consider desired_edge : edge The minimum desired edge to remove from the cycle. level : int The current level, i.e. the number of cycles that have already been removed. """ u = desired_edge[0] Q_nodes = nx.shortest_path(B, v, u) Q_edges = [ list(B[Q_nodes[i]][vv].keys())[0] for i, vv in enumerate(Q_nodes[1:]) ] Q_edges.append(desired_edge[2]) # Add the new edge key to complete the circuit # Get the edge in the circuit with the minimum weight. # Also, save the incoming weights for each node. minweight = INF minedge = None Q_incoming_weight = {} for edge_key in Q_edges: u, v, data = B_edge_index[edge_key] w = data[attr] # We cannot remove an included edge, even if it is the # minimum edge in the circuit Q_incoming_weight[v] = w if data.get(partition) == nx.EdgePartition.INCLUDED: continue if w < minweight: minweight = w minedge = edge_key circuits.append(Q_edges) minedge_circuit.append(minedge) graphs.append((G.copy(), G_edge_index.copy())) branchings.append((B.copy(), B_edge_index.copy())) # Mutate the graph to contract the circuit new_node = new_node_base_name + str(level) G.add_node(new_node) new_edges = [] for u, v, key, data in G.edges(data=True, keys=True): if u in Q_incoming_weight: if v in Q_incoming_weight: # Circuit edge. For the moment do nothing, # eventually it will be removed. continue else: #
(G, attr='weight', default=1, preserve_attrs=False, partition=None, *, backend=None, **backend_kwargs)
[ 0.05934286117553711, 0.015630874782800674, -0.03579306975007057, 0.014857499860227108, -0.035684142261743546, -0.05433226749300957, -0.04394073039293289, -0.04126115143299103, 0.017765823751688004, -0.07045330852270126, -0.031239964067935944, 0.05241516977548599, 0.004386992659419775, 0.022416962310671806, -0.04836312308907509, -0.0001257754338439554, -0.015445699915289879, 0.006764301564544439, 0.04797099158167839, 0.03906084597110748, -0.020837534219026566, -0.07106329500675201, -0.003205146174877882, 0.07454892247915268, 0.013332536444067955, 0.020510757341980934, 0.013180040754377842, 0.023702288046479225, -0.00812587607651949, -0.004937069024890661, -0.03106568194925785, -0.04971380531787872, -0.02666507288813591, -0.041130442172288895, 0.047143153846263885, 0.02803754061460495, 0.04012832045555115, 0.03906084597110748, -0.12574411928653717, -0.03991046920418739, -0.022253572940826416, -0.02259124256670475, 0.012929510325193405, -0.04128293693065643, 0.04450714588165283, 0.022286251187324524, 0.028582170605659485, 0.07711957395076752, 0.009111655876040459, -0.011709540151059628, 0.019693812355399132, -0.048145271837711334, 0.03411560878157616, 0.03853800147771835, -0.0033440268598496914, 0.015282311476767063, 0.000021572444893536158, 0.018386701121926308, 0.056815776973962784, -0.05816645920276642, -0.00729259243234992, -0.008425422944128513, 0.04010653495788574, -0.02278731018304825, -0.0625234991312027, 0.012177921831607819, -0.040847234427928925, -0.02415977604687214, -0.04967023432254791, 0.031610313802957535, 0.0031969768460839987, -0.03642483800649643, 0.02000969834625721, -0.014694111421704292, -0.042742542922496796, -0.026926495134830475, -0.0015413023065775633, -0.023026946932077408, -0.014705004170536995, -0.02670864388346672, 0.06783908605575562, -0.017613327130675316, 0.02605508826673031, -0.056467216461896896, 0.029998207464814186, -0.010887148790061474, 0.04300396516919136, 0.061739232391119, 0.0019143735989928246, -0.09698767215013504, -0.03760123997926712, 0.02178519032895565, 0.01657853089272976, 0.08343727886676788, 0.06949476152658463, 0.018147064372897148, -0.03337491303682327, -0.039757974445819855, 0.04587961360812187, -0.010375197045505047, -0.012798799201846123, 0.03977975994348526, -0.07589960843324661, -0.01751529425382614, -0.04779670760035515, -0.055290814489126205, -0.034072037786245346, 0.017842071130871773, -0.03997582569718361, -0.09175922721624374, -0.0701918825507164, 0.01953042298555374, 0.006432077381759882, 0.011360976845026016, 0.009160672314465046, 0.056467216461896896, -0.012352203018963337, -0.008049627766013145, 0.03328777104616165, 0.008665059693157673, 0.02339729480445385, -0.033875972032547, -0.03908263146877289, -0.009966724552214146, 0.016959771513938904, -0.014977319166064262, 0.03936583921313286, 0.014236622489988804, 0.03017248958349228, -0.02742755599319935, 0.001910288934595883, -0.029911067336797714, -0.018408486619591713, 0.04522605612874031, -0.036816973239183426, -0.03771016374230385, -0.07537676393985748, 0.004318913910537958, 0.015097137540578842, -0.001639335649088025, 0.03041212633252144, -0.038995493203401566, 0.04470321163535118, 0.016611207276582718, 0.005269293207675219, -0.036686260253190994, 0.020358260720968246, -0.02912680059671402, 0.00255567510612309, 0.001967475051060319, -0.008893804624676704, -0.018887760117650032, -0.020282013341784477, -0.006791533436626196, 0.02481333166360855, 0.03121817857027054, -0.05132590979337692, 0.015587303787469864, -0.04749171435832977, 0.014552507549524307, -0.04293861240148544, -0.027950400486588478, 0.011077769100666046, 0.017656898126006126, -0.0016951601719483733, -0.014824822545051575, 0.014258407056331635, -0.013822703622281551, -0.061259955167770386, 0.03137067332863808, 0.006377614568918943, -0.003918610978871584, -0.0851365253329277, -0.006780640687793493, -0.025183681398630142, 0.09419916570186615, 0.04513891413807869, -0.0278414748609066, 0.01236309576779604, 0.002110440284013748, -0.006018158979713917, -0.023331940174102783, 0.045923180878162384, 0.011524366214871407, 0.02880002185702324, -0.001371786231175065, 0.037492312490940094, -0.01641514152288437, 0.05237159878015518, -0.010211808606982231, -0.020118623971939087, -0.07245754450559616, 0.023593362420797348, 0.015413022600114346, 0.014214836992323399, 0.0185609832406044, 0.04228505492210388, 0.045443907380104065, -0.0055987942032516, 0.05620579421520233, -0.0021553724072873592, 0.0003000569704454392, 0.055857229977846146, -0.008305603638291359, 0.016491388902068138, 0.020271120592951775, -0.0027966739144176245, -0.031000327318906784, 0.0075376760214567184, 0.007276253774762154, -0.050323791801929474, 0.02038004621863365, 0.03049926646053791, 0.00801150407642126, 0.010544032789766788, -0.017537077888846397, -0.02973678521811962, 0.04078187793493271, 0.04285147041082382, -0.04272076115012169, -0.05760004371404648, 0.0007311654626391828, 0.018212419003248215, 0.01066929753869772, 0.030804259702563286, -0.077468141913414, 0.05394013226032257, 0.02472619153559208, 0.05193589627742767, -0.009629053995013237, 0.045966751873493195, -0.024639051407575607, 0.02908322960138321, -0.027209702879190445, 0.02339729480445385, -0.01207988802343607, -0.057905036956071854, 0.0001592191110830754, -0.009422095492482185, 0.03097854182124138, -0.021806975826621056, -0.05873287469148636, -0.03784087672829628, 0.018049031496047974, 0.030717119574546814, -0.030934970825910568, 0.07594317197799683, 0.01543480809777975, 0.0003877083072438836, 0.0004251516074873507, -0.05550866574048996, -0.0649634376168251, -0.010603941977024078, -0.029780356213450432, 0.013909844681620598, -0.02481333166360855, -0.036816973239183426, -0.036642689257860184, -0.01276612188667059, -0.027100777253508568, 0.009961278177797794, -0.007042062934488058, -0.04036795720458031, 0.04849383607506752, 0.015990329906344414, 0.03662090748548508, 0.035117726773023605, 0.008643274195492268, -0.024747977033257484, 0.006856888998299837, 0.09498342871665955, -0.011753110215067863, 0.005331925582140684, 0.028059326112270355, -0.0701918825507164, -0.029475362971425056, -0.018495626747608185, 0.0018449333729222417, -0.03300456330180168, -0.05672863870859146, -0.08574651181697845, -0.006159762851893902, -0.015630874782800674, 0.04853740707039833, -0.060214266180992126, 0.031327106058597565, -0.021251453086733818, -0.07755527645349503, -0.01032618060708046, -0.012820584699511528, 0.004136463161557913, -0.01010288204997778, 0.02162180282175541, 0.03973618894815445, 0.07494105398654938, -0.016927093267440796, 0.022525887936353683, -0.03888656571507454, 0.0029028765857219696, 0.04888596758246422, 0.04897310957312584, -0.051456619054079056, 0.030237844213843346, -0.037100180983543396, -0.01875704899430275, -0.005920125637203455, 0.05119519680738449, -0.02254767343401909, 0.0017768546240404248, 0.02089199796319008, -0.037209104746580124, 0.04736100509762764, -0.011546150781214237, 0.02723148837685585, -0.004030260257422924, -0.04433286190032959, 0.0071945590898394585, -0.01254826970398426, 0.04744814708828926, 0.051979467272758484, -0.006039944011718035, 0.0467945896089077, -0.05128233879804611, 0.03097854182124138, -0.10108328610658646, -0.014955533668398857, 0.03718731924891472, 0.04723029211163521, 0.019780952483415604, -0.033745259046554565, -0.02557581476867199, 0.030804259702563286, 0.010968843474984169, -0.0004152801993768662, -0.04627174511551857, 0.026360081508755684, 0.06849264353513718, -0.03352740779519081, 0.009678071364760399, -0.05350442975759506, 0.046446025371551514, 0.08038735389709473, 0.018953116610646248, 0.029627859592437744, 0.000499357411172241, -0.013702885247766972, 0.04736100509762764, 0.02199215069413185, -0.03925691545009613, 0.016850845888257027, -0.00033835123758763075, 0.0923692062497139, -0.025967948138713837, 0.008899250067770481, 0.0009136164444498718, -0.028342533856630325, -0.02581545151770115, -0.0215891245752573, 0.011622399091720581, 0.03391954302787781, -0.019573993980884552, 0.0017346458043903112, -0.017852963879704475, 0.034311674535274506, 0.006029051728546619, 0.0027422108687460423, -0.025510458275675774, 0.03167566657066345, 0.06261064112186432, -0.07559461146593094, 0.010075651109218597, -0.07803455740213394, 0.011350084096193314, 0.04300396516919136, -0.016121041029691696, 0.0621313638985157, -0.05938643217086792, -0.006464755162596703, 0.038385506719350815, 0.049234531819820404, -0.0032868406269699335, -0.01022270042449236, -0.01069108210504055, 0.01981363072991371, 0.013822703622281551, -0.013790025375783443, 0.10587602853775024, -0.011916499584913254, 0.05176161229610443, -0.01791832037270069, 0.012918618507683277, -0.028168251737952232, -0.006464755162596703, 0.003981243818998337, -0.03675161674618721, 0.013223610818386078, 0.08021306991577148, -0.009149780496954918, -0.03204601630568504, -0.016872629523277283, -0.037579454481601715, 0.061303526163101196, -0.006998492404818535, 0.017569756135344505, 0.013103792443871498, -0.0609113946557045, 0.06369990110397339, 0.05280730128288269, 0.024094421416521072, 0.021839654073119164, -0.021273238584399223, 0.05028022080659866, -0.04631531611084938, 0.019225431606173515, -0.023375509306788445, -0.048711687326431274, 0.07162971049547195, -0.02775433287024498, 0.051413051784038544, -0.04566175863146782, 0.04862454533576965, 0.021393056958913803, 0.05973499268293381, -0.04675101861357689, -0.030521051958203316, -0.044354647397994995, -0.004365207627415657, 0.005078672431409359, -0.054811540991067886, 0.05455011874437332, -0.0074995518662035465, -0.04775313660502434, 0.001688352320343256, -0.023135872557759285, -0.015097137540578842, -0.02594616264104843, -0.004259004723280668, 0.0028865376953035593, 0.051500190049409866, -0.0009347208542749286, -0.030324986204504967, 0.0009633139125071466, -0.013288966380059719, -0.0516309030354023, 0.000268740754108876, -0.026360081508755684, 0.0039839670062065125, 0.02166537195444107, -0.03311349079012871, -0.002544782590121031, 0.046010322868824005, -0.04219791293144226, 0.019857201725244522, 0.007063847966492176, -0.06313348561525345, 0.018288668245077133, 0.013278073631227016, -0.001277837553061545, -0.02267838455736637, -0.019857201725244522, 0.05720791220664978, 0.0019239046378061175, -0.014149481430649757, 0.03524843975901604, -0.04117400944232941, 0.031131038442254066, 0.010217254981398582, -0.0215782318264246, -0.011764002963900566, 0.003847809275612235, 0.0355098620057106, -0.0431564636528492, -0.07036616653203964, -0.03082604520022869, 0.028691096231341362, -0.012210599146783352, -0.03058640845119953, -0.04731743410229683, 0.013321644626557827, -0.056990060955286026, 0.03365812078118324, -0.012341310270130634, 0.024050850421190262, -0.02524903602898121, 0.00417731050401926, -0.02178519032895565, 0.020870212465524673, -0.0034012128598988056, -0.005980034824460745, -0.01345235574990511, -0.06139066815376282, -0.009716195054352283, 0.03206780180335045, 0.044921062886714935, 0.035597000271081924, 0.05019307881593704, -0.02032558247447014, -0.03143602982163429, 0.11363155394792557, -0.08400369435548782, -0.002802120288833976, -0.004106508567929268, -0.0726318284869194, -0.024878688156604767, 0.018288668245077133, -0.00822935625910759, -0.038625143468379974, 0.01551105547696352, 0.02424691803753376, 0.0018748879665508866, 0.05659792572259903, -0.02727505937218666, 0.06483272463083267, 0.06256707012653351, -0.0011062792036682367, 0.0021744342520833015, 0.029475362971425056, 0.04333074390888214, 0.0674033835530281, -0.030281415209174156, 0.03803694248199463, -0.021970365196466446, -0.011426332406699657, 0.016404248774051666, -0.021327702328562737, 0.02742755599319935, 0.010347966104745865, -0.04291682690382004, 0.01686173863708973, 0.01184025127440691, -0.006900459062308073, 0.04696886986494064, 0.023767642676830292, 0.05542152374982834, -0.010990628972649574, 0.0007536314660683274, 0.040520455688238144, 0.03442060202360153, -0.0629156306385994, -0.04784027859568596, 0.01131740678101778, 0.005201214458793402, 0.02537974715232849, 0.024747977033257484, -0.002773527055978775, 0.05006236955523491, 0.06579127907752991, 0.005729505326598883, -0.008479885756969452, -0.03339669853448868, -0.030934970825910568, 0.0589071549475193, -0.028102897107601166, -0.024072635918855667, 0.1004732996225357, -0.05912500619888306, -0.00400575203821063, 0.01831045374274254, 0.018615445122122765, 0.02533617615699768, -0.04587961360812187, -0.026316510513424873, 0.016556745395064354, -0.05437583476305008, 0.06513772159814835, -0.0019497745670378208, 0.022852664813399315, -0.038015156984329224, 0.027078991755843163, 0.06139066815376282, -0.013866273686289787, 0.01771136000752449, 0.020064160227775574, -0.010658404789865017, -0.022199109196662903, -0.010157344862818718, -0.03764481097459793, -0.012265062890946865, -0.008283819071948528, -0.06570413708686829, 0.008267479948699474, -0.015358559787273407, 0.055726516991853714, -0.001524963416159153, 0.05058521404862404, 0.037862662225961685, -0.03703482449054718, 0.044311076402664185, -0.028821807354688644, 0.008779431693255901, 0.01264630351215601, -0.024334058165550232, 0.010533140040934086, -0.02065236121416092, -0.0049724699929356575, 0.03167566657066345, -0.013376107439398766, 0.036969467997550964, -0.025924377143383026, -0.01912739686667919, -0.01968291960656643, -0.002502573886886239, 0.030564622953534126, 0.03784087672829628, -0.024900473654270172, 0.010282610543072224, 0.021120741963386536, -0.05232802778482437, 0.002306506969034672, -0.05537795647978783, 0.004226326942443848, 0.04054224118590355, -0.03614163026213646, -0.020968245342373848, -0.06156494840979576, -0.008419976569712162, -0.030717119574546814, 0.02259124256670475, -0.017820285633206367, -0.038472648710012436, 0.028538599610328674, -0.03646840900182724, -0.005822092294692993, -0.032656002789735794, -0.006655375938862562, 0.05333014577627182, 0.014933748170733452, 0.014574293047189713, -0.02036915346980095, 0.07838311791419983, -0.0012921341694891453, -0.03178459405899048, -0.006704392377287149, 0.031610313802957535, 0.014127695932984352, -0.027732547372579575, 0.07572532445192337, 0.0005517780664376915, -0.03278671205043793, 0.03742695972323418, -0.04892953857779503, 0.025074753910303116, 0.00008007759606698528, -0.005331925582140684, -0.055334385484457016, 0.007559461053460836, 0.04470321163535118, -0.02267838455736637, -0.01650228165090084, 0.01548927091062069, -0.01747172325849533, 0.007412411272525787, -0.0029001536313444376, -0.0560750812292099, 0.019105613231658936, 0.024377629160881042, 0.013310751877725124, 0.011546150781214237, 0.01626264490187168, -0.05450654774904251, 0.037383388727903366, 0.023026946932077408, 0.04740457609295845, -0.021436627954244614, -0.008801217190921307, -0.009367631748318672, 0.04688173159956932, -0.059647854417562485, -0.010429659858345985, -0.017689574509859085, -0.021088065579533577, -0.08173803985118866, 0.006639036815613508, -0.026076873764395714, -0.08918856829404831, -0.03041212633252144, 0.012907725758850574, 0.046010322868824005, 0.01050590816885233, -0.01107232365757227, 0.08252230286598206, 0.036403052508831024, -0.0009265514090657234, -0.03740517422556877, 0.0786881074309349, 0.00031537466566078365, -0.07655315846204758, -0.0027667193207889795, 0.00435703806579113, -0.032612431794404984, 0.011328299529850483, -0.043025750666856766, 0.029017874971032143, -0.010315287858247757, -0.0038695945404469967, -0.016317108646035194, -0.02633829601109028, 0.03069533407688141, 0.024660836905241013, -0.03400668129324913, 0.045400336384773254, 0.010963397100567818, -0.009345847181975842, -0.0031534063164144754, 0.014378226362168789, -0.0020736779551953077, -0.06400489062070847, 0.026774000376462936, -0.00130574987269938, -0.02553224377334118, -0.0016189119778573513, 0.02557581476867199, -0.033788830041885376, 0.0007897131727077067, 0.02941000834107399, 0.028255391865968704, -0.050367362797260284, -0.013430570252239704, -0.07406964898109436, 0.012265062890946865, -0.03651197999715805, 0.009002730250358582, 0.006421185098588467, 0.01751529425382614, -0.036119844764471054, 0.01456340029835701, 0.049190960824489594, -0.061259955167770386, 0.00612163869664073, -0.02259124256670475, 0.026926495134830475, 0.08099734038114548, -0.02956250309944153, 0.03707839548587799, 0.038908351212739944, -0.009645393118262291, -0.007488659583032131, -0.002608776558190584, 0.007461427710950375, 0.06313348561525345, -0.020151302218437195, -0.010898041538894176, -0.047099582850933075, -0.013561281375586987, -0.02307051792740822, 0.035117726773023605, -0.031523171812295914, 0.04958309605717659, -0.0007066571270115674, -0.049757376313209534, 0.03474738076329231, 0.005187598522752523, 0.03202423080801964, -0.013321644626557827, 0.010037526488304138, 0.005882001481950283, -0.0005017401999793947, -0.004493195563554764, -0.026207584887742996, -0.059604283422231674, 0.005587901454418898, -0.025641169399023056, 0.01351771131157875, 0.0049561308696866035, -0.028495030477643013, 0.03193708881735802, 0.029998207464814186, 0.06139066815376282 ]
30,910
networkx.algorithms.tree.mst
minimum_spanning_edges
Generate edges in a minimum spanning forest of an undirected weighted graph. A minimum spanning tree is a subgraph of the graph (a tree) with the minimum sum of edge weights. A spanning forest is a union of the spanning trees for each connected component of the graph. Parameters ---------- G : undirected Graph An undirected graph. If `G` is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found. algorithm : string The algorithm to use when finding a minimum spanning tree. Valid choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'. weight : string Edge data key to use for weight (default 'weight'). keys : bool Whether to yield edge key in multigraphs in addition to the edge. If `G` is not a multigraph, this is ignored. data : bool, optional If True yield the edge data along with the edge. ignore_nan : bool (default: False) If a NaN is found as an edge weight normally an exception is raised. If `ignore_nan is True` then that edge is ignored instead. Returns ------- edges : iterator An iterator over edges in a maximum spanning tree of `G`. Edges connecting nodes `u` and `v` are represented as tuples: `(u, v, k, d)` or `(u, v, k)` or `(u, v, d)` or `(u, v)` If `G` is a multigraph, `keys` indicates whether the edge key `k` will be reported in the third position in the edge tuple. `data` indicates whether the edge datadict `d` will appear at the end of the edge tuple. If `G` is not a multigraph, the tuples are `(u, v, d)` if `data` is True or `(u, v)` if `data` is False. Examples -------- >>> from networkx.algorithms import tree Find minimum spanning edges by Kruskal's algorithm >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> mst = tree.minimum_spanning_edges(G, algorithm="kruskal", data=False) >>> edgelist = list(mst) >>> sorted(sorted(e) for e in edgelist) [[0, 1], [1, 2], [2, 3]] Find minimum spanning edges by Prim's algorithm >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> mst = tree.minimum_spanning_edges(G, algorithm="prim", data=False) >>> edgelist = list(mst) >>> sorted(sorted(e) for e in edgelist) [[0, 1], [1, 2], [2, 3]] Notes ----- For Borůvka's algorithm, each edge must have a weight attribute, and each edge weight must be distinct. For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used. Modified code from David Eppstein, April 2006 http://www.ics.uci.edu/~eppstein/PADS/
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, algorithm='kruskal', weight='weight', keys=True, data=True, ignore_nan=False, *, backend=None, **backend_kwargs)
[ -0.0005006426945328712, -0.029431641101837158, -0.02168872393667698, 0.0029356777667999268, 0.009683993645012379, 0.0067590102553367615, -0.048724763095378876, -0.054029304534196854, 0.07293742150068283, -0.02320736087858677, -0.025153785943984985, 0.03413727879524231, 0.011486039496958256, 0.041901588439941406, -0.05638212338089943, 0.03621203824877739, 0.030629439279437065, 0.0033206846565008163, 0.0363403744995594, 0.03221224620938301, -0.04275715723633766, -0.08222036808729172, 0.019239651039242744, 0.059676073491573334, -0.04132407531142235, -0.03343143314123154, -0.019335903227329254, -0.03770928829908371, -0.019646048545837402, 0.006523728370666504, -0.0037832276429980993, -0.059462178498506546, -0.08328983187675476, -0.037987351417541504, 0.01413830928504467, 0.0019410765962675214, 0.029902204871177673, 0.050820913165807724, -0.06600730121135712, -0.05869216471910477, -0.01999897137284279, -0.035527583211660385, 0.020908014848828316, -0.025153785943984985, 0.022694019600749016, 0.023121803998947144, 0.06968625634908676, 0.06532283872365952, -0.039120979607105255, -0.005149467382580042, 0.03266141936182976, -0.024768779054284096, -0.022886522114276886, 0.021175380796194077, -0.012748006731271744, 0.00654511759057641, 0.014523317106068134, -0.0066467165015637875, 0.0716540664434433, -0.04188019782304764, 0.04504580795764923, 0.006331224925816059, -0.008389942348003387, -0.00009800631960388273, -0.07901197671890259, -0.013346906751394272, -0.05672435462474823, -0.03623342886567116, -0.0181701872497797, 0.025538792833685875, 0.0015333435731008649, -0.020512312650680542, 0.04821142181754112, 0.006769705098122358, 0.017400173470377922, 0.02414849027991295, 0.005197593476623297, -0.04962311312556267, -0.020138001069426537, -0.013058151118457317, 0.07037071138620377, -0.02485433593392372, 0.03623342886567116, -0.026137692853808403, 0.04919533059000969, -0.012608977034687996, 0.029260525479912758, 0.04624360799789429, 0.018202271312475204, -0.08363205939531326, -0.025774074718356133, -0.003216411918401718, 0.04143102094531059, 0.051248699426651, 0.04641472175717354, 0.018351996317505836, -0.011250757612287998, -0.07058460265398026, -0.025410456582903862, -0.03467201068997383, -0.013977889902889729, 0.0681462287902832, -0.02825522981584072, 0.014491233043372631, -0.01138978824019432, -0.034393951296806335, -0.03899264708161354, 0.0386076383292675, -0.006496991962194443, -0.04958033561706543, -0.05086369067430496, 0.01855519413948059, 0.022009562700986862, 0.004764460492879152, 0.010256156325340271, 0.011207979172468185, -0.02485433593392372, 0.006935472134500742, 0.007454161997884512, 0.04359133914113045, 0.03413727879524231, 0.020597869530320168, -0.021774280816316605, 0.008149312809109688, -0.00018030489445663989, -0.03167751431465149, 0.05035034939646721, -0.002622859552502632, 0.013400379568338394, -0.01310092955827713, 0.044190239161252975, 0.02919635735452175, 0.020672732964158058, 0.04868198558688164, 0.01884395070374012, -0.009507532231509686, -0.08222036808729172, -0.0014370918506756425, 0.05364429950714111, 0.030800553038716316, 0.004555915016680956, -0.1007862538099289, 0.044190239161252975, 0.014694430865347385, 0.04714195802807808, -0.01291912142187357, 0.006037122569978237, -0.0060585117898881435, 0.007908684201538563, 0.003743122797459364, 0.02472599968314171, -0.028811350464820862, 0.02547462470829487, -0.0008488867897540331, 0.007550413720309734, -0.015464444644749165, 0.01845894381403923, 0.0029249831568449736, -0.054200418293476105, 0.0027832791674882174, -0.012651755474507809, -0.003152244258671999, 0.02178497426211834, 0.027271322906017303, -0.002366188447922468, 0.01424525585025549, 0.023635147139430046, 0.028019947931170464, -0.04331327974796295, -0.032361969351768494, -0.01609542779624462, -0.0460297167301178, -0.10206961631774902, 0.03189140558242798, 0.019367987290024757, 0.015004575252532959, 0.02485433593392372, 0.010742762126028538, -0.012961899861693382, -0.0061333742924034595, 0.01395650114864111, -0.043612729758024216, 0.032083909958601, -0.007550413720309734, -0.021635249257087708, 0.03257586434483528, 0.06010385975241661, -0.020277030766010284, 0.019474932923913002, -0.010432617738842964, -0.02168872393667698, -0.07028514891862869, 0.01698308251798153, 0.0577082596719265, 0.04620083048939705, 0.02489711344242096, 0.00473505025729537, 0.0013996605994179845, -0.04996534436941147, 0.05372985452413559, 0.00246110325679183, -0.023784872144460678, 0.049837008118629456, 0.0021469483617693186, 0.015956398099660873, -0.008347163908183575, -0.01009573694318533, -0.005598642397671938, 0.022907912731170654, -0.0022044319193810225, -0.037987351417541504, -0.03150640055537224, 0.055526554584503174, 0.053216513246297836, -0.03390199691057205, -0.026351584121584892, -0.06480950117111206, 0.012288137339055538, 0.025217954069375992, -0.04145241156220436, -0.037067610770463943, -0.0006129363900981843, 0.01957118511199951, -0.008347163908183575, 0.06232834234833717, -0.05565489083528519, 0.012737312354147434, -0.004507789388298988, 0.03619065135717392, -0.03486451506614685, 0.09282944351434708, -0.02188122645020485, 0.047783635556697845, -0.02226623333990574, -0.025496013462543488, -0.08303315937519073, -0.03971987962722778, -0.030415546149015427, 0.02299346961081028, 0.01744295284152031, -0.032083909958601, -0.07571803033351898, -0.03112139366567135, 0.012694533914327621, 0.000025545978132868186, -0.007673401851207018, 0.011101032607257366, 0.015582085587084293, 0.036105092614889145, 0.00369767053052783, -0.08042366802692413, -0.06498061120510101, -0.006881998851895332, -0.03548480570316315, 0.0067322738468647, -0.028982466086745262, -0.0075771501287817955, 0.02262985147535801, -0.020041748881340027, 0.012416473589837551, 0.002919635735452175, -0.05133425444364548, -0.0467141717672348, 0.04034017026424408, -0.018972285091876984, -0.009208082221448421, 0.02885412983596325, 0.02410571090877056, -0.04151657968759537, -0.021421357989311218, 0.07961087673902512, 0.009929969906806946, 0.0037217335775494576, -0.007422077935189009, -0.030223043635487556, -0.026736591011285782, -0.030629439279437065, 0.08551431447267532, 0.003449020441621542, -0.02677937038242817, -0.044746361672878265, 0.017581982538104057, -0.0005237029981799424, 0.03073638677597046, -0.052874285727739334, 0.038885697722435, -0.028725793585181236, -0.046286389231681824, 0.024276824668049812, -0.024790167808532715, 0.011817573569715023, -0.05313095450401306, -0.0019143399549648166, 0.0204374510794878, 0.03394477814435959, 0.01744295284152031, -0.0032271065283566713, -0.04448968917131424, 0.008218828588724136, 0.05112036317586899, 0.052660390734672546, -0.01763545535504818, 0.04530248045921326, -0.015047353692352772, 0.012908426113426685, 0.06776122003793716, 0.05360151827335358, -0.0373028926551342, 0.002130906330421567, 0.015143605880439281, -0.09300056099891663, 0.008657308295369148, 0.03392338752746582, 0.021485524252057076, 0.0077268751338124275, -0.08649822324514389, -0.014566095545887947, -0.06053164228796959, 0.063611701130867, 0.011475345119833946, -0.03206251934170723, 0.049837008118629456, 0.006748315878212452, 0.028961075469851494, -0.0632694736123085, 0.010550258681178093, 0.01848033256828785, 0.08085145056247711, 0.020309114828705788, -0.014427064917981625, -0.0823059231042862, 0.0027832791674882174, 0.04697084426879883, 0.06194333732128143, -0.06528006494045258, 0.0625850111246109, 0.09180276095867157, -0.009234818629920483, 0.003662913106381893, -0.058863282203674316, 0.06806066632270813, 0.051548149436712265, -0.02108982391655445, 0.027249934151768684, -0.0060959430411458015, 0.013165097683668137, 0.03221224620938301, 0.013731913641095161, 0.006101290229707956, 0.023079026490449905, 0.010416575707495213, 0.07208184897899628, 0.010181293822824955, 0.013967195525765419, 0.0031468968372792006, 0.0026696487329900265, 0.010721373371779919, -0.023827649652957916, 0.011924520134925842, 0.02243734709918499, -0.031185559928417206, -0.002668311819434166, 0.019966887310147285, 0.02070481702685356, 0.01609542779624462, -0.011347009800374508, -0.017667539417743683, 0.062456678599119186, 0.02583824284374714, -0.0937705710530281, 0.02975247986614704, -0.11943770200014114, -0.04164491593837738, 0.07473412156105042, -0.0032271065283566713, 0.049665894359350204, -0.05638212338089943, -0.00447035813704133, 0.003058666130527854, 0.007496940437704325, 0.020523007959127426, 0.03670399263501167, 0.0017900147940963507, 0.053045399487018585, 0.048510871827602386, -0.05432875454425812, 0.08521486818790436, -0.0073204790242016315, 0.01884395070374012, -0.018255744129419327, -0.02958136424422264, -0.006037122569978237, 0.05261761322617531, 0.030030539259314537, -0.06836012005805969, 0.0170365571975708, 0.08200647681951523, 0.015357498079538345, -0.058863282203674316, 0.020394671708345413, 0.008523625321686268, -0.022565683349967003, -0.020736901089549065, 0.008304385468363762, 0.0013983238022774458, -0.061772219836711884, 0.013421769253909588, 0.020405367016792297, 0.045174144208431244, -0.010020874440670013, -0.06750454753637314, -0.00034523624344728887, 0.004997069016098976, 0.03700344264507294, -0.029260525479912758, -0.04359133914113045, 0.027955779805779457, 0.0340731143951416, 0.06823178380727768, -0.01957118511199951, 0.0719962939620018, -0.021774280816316605, 0.040810734033584595, 0.007518329657614231, 0.05313095450401306, -0.017100723460316658, -0.009561005048453808, -0.04170908406376839, -0.03563452884554863, 0.06322669237852097, -0.007641317788511515, -0.07434911280870438, 0.01111172791570425, -0.02041606232523918, 0.01997758075594902, -0.01633070968091488, -0.004280528519302607, 0.006042469758540392, 0.013977889902889729, 0.007694791071116924, -0.009769550524652004, 0.021817058324813843, -0.024255435913801193, -0.04337744787335396, 0.008577099069952965, -0.04979422688484192, -0.018319912254810333, 0.031591955572366714, -0.030650828033685684, -0.04224381595849991, 0.07486245781183243, -0.019817162305116653, 0.011550207622349262, -0.0001762944011716172, -0.08008144050836563, 0.035720087587833405, 0.004932901356369257, 0.0024410507176071405, -0.0728946402668953, 0.02583824284374714, 0.05313095450401306, -0.01178548950701952, -0.003272558795288205, 0.04709918051958084, -0.030479714274406433, -0.0222234558314085, 0.06788955628871918, -0.030800553038716316, -0.015464444644749165, -0.002197747817263007, 0.03790179267525673, -0.024041542783379555, -0.10129959881305695, -0.03315337374806404, 0.012748006731271744, 0.002836752450093627, -0.06438171118497849, -0.03736706078052521, -0.05308817699551582, -0.04198714345693588, 0.012566198594868183, -0.019528405740857124, 0.054970432072877884, 0.013389685191214085, -0.017207670956850052, -0.019624657928943634, 0.03249030560255051, 0.012202580459415913, 0.021410662680864334, -0.04200853407382965, -0.049280885607004166, -0.0554409958422184, 0.02979525737464428, 0.018031157553195953, -0.033474214375019073, 0.050992026925086975, -0.012031466700136662, -0.031399454921483994, 0.04846809431910515, -0.0531737320125103, 0.021795669570565224, 0.008892590180039406, -0.015036659315228462, 0.017015166580677032, 0.0509064719080925, 0.01727183908224106, -0.021004267036914825, 0.019314514473080635, 0.014181088656187057, 0.01942146010696888, 0.052703168243169785, -0.004061288200318813, 0.03437256067991257, 0.054927654564380646, 0.05257483571767807, 0.0024971975944936275, 0.02026633732020855, 0.015603475272655487, 0.028362177312374115, -0.051719263195991516, 0.0007385983481071889, -0.0017525835428386927, 0.01633070968091488, 0.03582703322172165, 0.0005684868083335459, 0.044917475432157516, -0.018587278202176094, 0.015122216194868088, 0.018801171332597733, -0.02089731954038143, -0.01280148047953844, 0.050435908138751984, -0.03676816076040268, 0.0587349459528923, 0.03169890493154526, -0.035142574459314346, 0.029517197981476784, -0.022330401465296745, -0.02680075913667679, -0.021795669570565224, 0.008668002672493458, 0.00419229781255126, 0.0230148583650589, 0.035720087587833405, 0.037409838289022446, 0.055911559611558914, 0.0441046804189682, -0.022373180836439133, -0.022522903978824615, -0.046842508018016815, -0.01836269162595272, 0.02395598590373993, 0.030757775530219078, 0.013453853316605091, 0.11173756420612335, -0.07242407649755478, -0.01990271918475628, 0.018587278202176094, 0.002216463442891836, 0.01412761490792036, -0.047569744288921356, -0.04389078915119171, -0.013977889902889729, -0.020202169194817543, 0.046842508018016815, -0.023421254009008408, -0.03182723745703697, -0.014181088656187057, -0.0008535656961612403, 0.0116785429418087, 0.0015012596268206835, 0.03261864185333252, 0.03734567016363144, -0.017966989427804947, -0.05415764078497887, -0.014662346802651882, -0.05723769590258598, 0.009732119739055634, -0.0075022876262664795, -0.03492868319153786, -0.017453646287322044, -0.029838036745786667, 0.043441615998744965, 0.02846912294626236, 0.04123852029442787, 0.044233016669750214, -0.040981847792863846, 0.05424319580197334, -0.011817573569715023, 0.03298225998878479, 0.0044596632942557335, -0.057366032153367996, 0.07182517647743225, -0.005914133973419666, -0.008545015007257462, -0.0048339758068323135, -0.03293948248028755, 0.01291912142187357, 0.01903645321726799, -0.05334484949707985, 0.002983803628012538, 0.012341611087322235, 0.03901403397321701, 0.04692806676030159, -0.023827649652957916, 0.021870531141757965, -0.000911049370188266, -0.026308806613087654, 0.018619362264871597, -0.0431421659886837, -0.002957066986709833, 0.004638798534870148, -0.0134645476937294, -0.06202889233827591, -0.02320736087858677, 0.009138567373156548, -0.06241390109062195, 0.012202580459415913, -0.012683839537203312, -0.06729065626859665, -0.0001161370673798956, 0.012223970144987106, -0.010667900554835796, -0.01715419813990593, -0.019357291981577873, 0.0134645476937294, 0.03755956515669823, -0.025538792833685875, -0.032083909958601, 0.019913412630558014, -0.00039703838410787284, -0.0632694736123085, 0.03640454262495041, 0.009994138032197952, 0.004911512136459351, -0.04374106228351593, 0.03969849273562431, 0.011368398554623127, -0.05672435462474823, 0.018491026014089584, -0.010261503979563713, -0.02103635109961033, -0.0073579102754592896, -0.006197541952133179, -0.03880014270544052, -0.013111624866724014, -0.0005567895132116973, 0.005785798653960228, 0.0014624915784224868, 0.028191061690449715, -0.013892333023250103, 0.03317476436495781, 0.019122010096907616, -0.027228545397520065, -0.0002235847496194765, 0.009010231122374535, 0.004521157592535019, -0.01179618388414383, 0.02045883983373642, -0.010154557414352894, 0.00484467064961791, 0.02750660479068756, 0.005328602623194456, 0.040661007165908813, -0.007545066066086292, 0.005339297465980053, 0.017207670956850052, -0.04160213842988014, -0.012010077014565468, 0.027228545397520065, -0.023891817778348923, -0.04893865808844566, 0.003761838423088193, -0.01901506446301937, -0.07644526660442352, -0.020950794219970703, 0.020277030766010284, 0.02449071779847145, -0.015592779964208603, -0.027057431638240814, 0.0399123840034008, 0.062456678599119186, 0.013689135201275349, -0.035313691943883896, 0.029666922986507416, 0.04466080293059349, -0.07610303163528442, -0.024576274678111076, 0.04168769344687462, -0.03882152959704399, 0.0022552316077053547, -0.07242407649755478, 0.021827753633260727, 0.02885412983596325, -0.0031201601959764957, 0.0005985654424875975, 0.002965088002383709, 0.004360738210380077, 0.004194971174001694, -0.053216513246297836, 0.030051929876208305, -0.028340786695480347, -0.014919018372893333, -0.020683428272604942, -0.026244638487696648, 0.017667539417743683, -0.08251981437206268, 0.060617201030254364, 0.040233224630355835, -0.026629645377397537, -0.029431641101837158, -0.02028772607445717, -0.013079540804028511, 0.005812535062432289, 0.016630159690976143, 0.01925034634768963, -0.025731295347213745, 0.024447940289974213, -0.05488487705588341, -0.012608977034687996, -0.040233224630355835, -0.001961129019036889, 0.030223043635487556, 0.016352100297808647, -0.027036041021347046, 0.024918504059314728, 0.08880826085805893, -0.08624155074357986, -0.02070481702685356, 0.00095449632499367, 0.011079643853008747, 0.07481967657804489, 0.018833255395293236, 0.0027565425261855125, 0.0028795308899134398, -0.0035907241981476545, -0.004638798534870148, 0.016950998455286026, -0.0009658593917265534, 0.02600935660302639, -0.015507223084568977, 0.012384389527142048, -0.08829492330551147, -0.027078820392489433, -0.023464033380150795, 0.01705794595181942, -0.005344644654542208, 0.012780090793967247, 0.021057739853858948, -0.04128129780292511, 0.046072494238615036, 0.008486194536089897, 0.029281916096806526, -0.013913722708821297, 0.049066994339227676, 0.019410764798521996, -0.004045246168971062, -0.04598693922162056, -0.03813707455992699, -0.07417800277471542, -0.02938886173069477, -0.017207670956850052, -0.01630932092666626, 0.002265926217660308, 0.01479068212211132, 0.037794847041368484, 0.023485422134399414, 0.05976162850856781 ]
30,911
networkx.algorithms.tree.mst
minimum_spanning_tree
Returns a minimum spanning tree or forest on an undirected graph `G`. Parameters ---------- G : undirected graph An undirected graph. If `G` is connected, then the algorithm finds a spanning tree. Otherwise, a spanning forest is found. weight : str Data key to use for edge weights. algorithm : string The algorithm to use when finding a minimum spanning tree. Valid choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'. ignore_nan : bool (default: False) If a NaN is found as an edge weight normally an exception is raised. If `ignore_nan is True` then that edge is ignored instead. Returns ------- G : NetworkX Graph A minimum spanning tree or forest. Examples -------- >>> G = nx.cycle_graph(4) >>> G.add_edge(0, 3, weight=2) >>> T = nx.minimum_spanning_tree(G) >>> sorted(T.edges(data=True)) [(0, 1, {}), (1, 2, {}), (2, 3, {})] Notes ----- For Borůvka's algorithm, each edge must have a weight attribute, and each edge weight must be distinct. For the other algorithms, if the graph edges do not have a weight attribute a default weight of 1 will be used. There may be more than one tree with the same minimum or maximum weight. See :mod:`networkx.tree.recognition` for more detailed definitions. Isolated nodes with self-loops are in the tree as edgeless isolated nodes.
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, weight='weight', algorithm='kruskal', ignore_nan=False, *, backend=None, **backend_kwargs)
[ -0.0005073153879493475, -0.029430976137518883, -0.02168823406100273, 0.002940958831459284, 0.009667733684182167, 0.0067214276641607285, -0.04872366413474083, -0.05402808636426926, 0.07293577492237091, -0.023249614983797073, -0.02513182908296585, 0.034136511385440826, 0.011475086212158203, 0.04187925159931183, -0.05642363056540489, 0.036211222410202026, 0.030585970729589462, 0.0033259568735957146, 0.03638233244419098, 0.03225429728627205, -0.0427989698946476, -0.08226128667593002, 0.019249912351369858, 0.05967472493648529, -0.04132314398884773, -0.03340929001569748, -0.01934616081416607, -0.03768704831600189, -0.019592132419347763, 0.006486150901764631, -0.0038018575869500637, -0.0594608373939991, -0.08333072811365128, -0.03798649087548256, 0.01417007390409708, 0.001965095056220889, 0.029837362468242645, 0.0508197657763958, -0.06600581109523773, -0.05869084224104881, -0.019998518750071526, -0.035526782274246216, 0.020971709862351418, -0.025089051574468613, 0.022672118619084358, 0.02312128245830536, 0.06972745805978775, 0.06527858972549438, -0.03912009671330452, -0.005111921112984419, 0.03263929486274719, -0.02472544275224209, -0.02288600616157055, 0.02118559740483761, -0.012726330198347569, 0.006496845278888941, 0.014480211772024632, -0.006657261401414871, 0.0716952234506607, -0.04192202910780907, 0.04504479467868805, 0.006320387590676546, -0.008346975781023502, -0.000031895200663711876, -0.07901019603013992, -0.01336799468845129, -0.05672307312488556, -0.036232613027095795, -0.01821255497634411, 0.02560238353908062, 0.0015292986063286662, -0.020511850714683533, 0.04821033403277397, 0.006764205172657967, 0.0173890870064497, 0.024169333279132843, 0.0052135176956653595, -0.04957921802997589, -0.020169630646705627, -0.013057856820523739, 0.0704546794295311, -0.024810997769236565, 0.036211222410202026, -0.02609432488679886, 0.04919422045350075, -0.012619386427104473, 0.02930264361202717, 0.04624256491661072, 0.018201861530542374, -0.08363017439842224, -0.02583765983581543, -0.0031896033324301243, 0.04143008962273598, 0.05124754458665848, 0.04649922996759415, 0.01838366501033306, -0.011261198669672012, -0.07058300822973251, -0.02536710537970066, -0.034671228379011154, -0.013988269492983818, 0.06805913150310516, -0.028233204036951065, 0.014469517394900322, -0.011389531195163727, -0.034414563328027725, -0.03894898667931557, 0.03858537971973419, -0.006544969975948334, -0.04962199553847313, -0.050862543284893036, 0.018533388152718544, 0.02194489911198616, 0.004734943620860577, 0.010223842225968838, 0.011197032406926155, -0.024832386523485184, 0.006956704426556826, 0.0074860770255327225, 0.043568968772888184, 0.03411512076854706, 0.02057601697742939, -0.021795177832245827, 0.008159823715686798, -0.00017879692313726991, -0.03169818967580795, 0.05030643567442894, -0.002656220458447933, 0.013442855328321457, -0.013122023083269596, 0.04418924078345299, 0.029174311086535454, 0.020661571994423866, 0.04872366413474083, 0.018800746649503708, -0.00950731709599495, -0.08226128667593002, -0.0014517641393467784, 0.05364308878779411, 0.030821247026324272, 0.004518382251262665, -0.10078398138284683, 0.044232018291950226, 0.014704793691635132, 0.04714089632034302, -0.012918829917907715, 0.006085110828280449, -0.006069069262593985, 0.007945936173200607, 0.0037376913242042065, 0.024746831506490707, -0.02881070226430893, 0.025452660396695137, -0.0008548832265660167, 0.007528854534029961, -0.015474789775907993, 0.018437137827277184, 0.002927590860053897, -0.05419919639825821, 0.002842035610228777, -0.012651469558477402, -0.0031548466067761183, 0.021763095632195473, 0.027249319478869438, -0.0023701454047113657, 0.014212851412594318, 0.023613225668668747, 0.028062094002962112, -0.043290913105010986, -0.03231846168637276, -0.016084371134638786, -0.046071454882621765, -0.10206730663776398, 0.031912077218294144, 0.01934616081416607, 0.014993542805314064, 0.02489655278623104, 0.010763908736407757, -0.012950913049280643, -0.006079763639718294, 0.013988269492983818, -0.04361174628138542, 0.03206179663538933, -0.007560937665402889, -0.021602679044008255, 0.032596517354249954, 0.06010250374674797, -0.020287267863750458, 0.019474493339657784, -0.010459118522703648, -0.021656149998307228, -0.07028356939554214, 0.016993394121527672, 0.057706959545612335, 0.04619978740811348, 0.02491794154047966, 0.004753658547997475, 0.001392945065163076, -0.049964215606451035, 0.05372864380478859, 0.002481099683791399, -0.0237843357026577, 0.04979310557246208, 0.0021335319615900517, 0.015956038609147072, -0.008368364535272121, -0.010079467669129372, -0.005651988089084625, 0.022928783670067787, -0.00218834076076746, -0.03798649087548256, -0.031484298408031464, 0.05552530288696289, 0.053172532469034195, -0.033922623842954636, -0.026372378692030907, -0.06476525962352753, 0.012362721376121044, 0.025260161608457565, -0.04143008962273598, -0.03706677630543709, -0.0006343113491311669, 0.019527966156601906, -0.00838975328952074, 0.06232693791389465, -0.055653635412454605, 0.012747718952596188, -0.004539771005511284, 0.03616844490170479, -0.03482095152139664, 0.09282734990119934, -0.02192351035773754, 0.04778255894780159, -0.022265730425715446, -0.025474049150943756, -0.08303128927946091, -0.039697594940662384, -0.03041486069560051, 0.022971561178565025, 0.017453253269195557, -0.03204040974378586, -0.07575909793376923, -0.03112069144845009, 0.01269424706697464, 0.00006546139775309712, -0.007721353322267532, 0.011079393327236176, 0.015571040101349354, 0.03610428050160408, 0.0036735248286277056, -0.08046463131904602, -0.06497914344072342, -0.006876496132463217, -0.03548400476574898, 0.006748163606971502, -0.028981812298297882, -0.007630451116710901, 0.022586563602089882, -0.02003060281276703, 0.012384110130369663, 0.002911549061536789, -0.051333099603652954, -0.046755898743867874, 0.040339261293411255, -0.01895046792924404, -0.00919183250516653, 0.02883209101855755, 0.024105167016386986, -0.041494254022836685, -0.021420873701572418, 0.07960908114910126, 0.009935093112289906, 0.003697587177157402, -0.007373785600066185, -0.03020097315311432, -0.026693211868405342, -0.0306287482380867, 0.08551238477230072, 0.003414185717701912, -0.0267573781311512, -0.04474535211920738, 0.017613669857382774, -0.0005340513889677823, 0.030735692009329796, -0.05283031240105629, 0.03888482227921486, -0.028725145384669304, -0.046328119933605194, 0.02425488829612732, -0.024810997769236565, 0.01189216785132885, -0.05308697745203972, -0.0019290015334263444, 0.020383518189191818, 0.033965401351451874, 0.017399782314896584, -0.003210992319509387, -0.044488683342933655, 0.008250726386904716, 0.05107643082737923, 0.052701979875564575, -0.017656447365880013, 0.045344237238168716, -0.01506840344518423, 0.012876052409410477, 0.06771691143512726, 0.053600311279296875, -0.03728066384792328, 0.0021255111787468195, 0.015121875330805779, -0.0929984599351883, 0.00870523788034916, 0.0338798463344574, 0.021506428718566895, 0.0077480897307395935, -0.0864962711930275, -0.01453368365764618, -0.06053027883172035, 0.06356748938560486, 0.011517863720655441, -0.03206179663538933, 0.04983588308095932, 0.0067428164184093475, 0.028939034789800644, -0.06331082433462143, 0.010550021193921566, 0.01844783127307892, 0.08080685138702393, 0.020308656617999077, -0.014426739886403084, -0.08230406790971756, 0.002756480360403657, 0.046969786286354065, 0.06194193661212921, -0.06523581594228745, 0.06266915798187256, 0.09180068969726562, -0.009218568913638592, 0.003697587177157402, -0.058861952275037766, 0.06801635771989822, 0.051546987146139145, -0.021100042387843132, 0.02722793072462082, -0.006074416451156139, 0.013164800591766834, 0.03221151977777481, 0.013688826002180576, 0.006058374885469675, 0.02307850494980812, 0.010427035391330719, 0.07212300598621368, 0.01015967596322298, 0.013977575115859509, 0.0031441522296518087, 0.002648199675604701, 0.010656964965164661, -0.023848501965403557, 0.011924250982701778, 0.022458231076598167, -0.031163468956947327, -0.0026254740078002214, 0.01998782530426979, 0.02067226730287075, 0.016073675826191902, -0.011378836818039417, -0.017656447365880013, 0.062498047947883606, 0.02581627108156681, -0.09376846253871918, 0.029773196205496788, -0.11943500488996506, -0.04166536405682564, 0.07473243772983551, -0.003210992319509387, 0.04962199553847313, -0.056380853056907654, -0.004459562711417675, 0.0030372082255780697, 0.007502118591219187, 0.02055462822318077, 0.03674594312906265, 0.0017926479922607541, 0.05308697745203972, 0.0484669990837574, -0.054327528923749924, 0.08525571972131729, -0.007282883394509554, 0.018886301666498184, -0.018244639039039612, -0.029602086171507835, -0.00606372207403183, 0.05265920236706734, 0.030029863119125366, -0.06827302277088165, 0.017004089429974556, 0.08204740285873413, 0.015367846004664898, -0.05881917476654053, 0.020372822880744934, 0.008475308306515217, -0.022543786093592644, -0.020757822319865227, 0.008309544995427132, 0.0013875977601855993, -0.06177082657814026, 0.013432160951197147, 0.020426295697689056, 0.045130349695682526, -0.010009953752160072, -0.0675458014011383, -0.0003569254477042705, 0.004994282498955727, 0.03702399879693985, -0.029217088595032692, -0.043568968772888184, 0.028019316494464874, 0.03409373387694359, 0.06818746775388718, -0.01956004835665226, 0.07195189595222473, -0.021784484386444092, 0.040809813886880875, 0.0075074657797813416, 0.05312975496053696, -0.017100337892770767, -0.009592873044312, -0.04166536405682564, -0.03569789230823517, 0.06326804310083389, -0.007657187059521675, -0.07434743642807007, 0.011154254898428917, -0.02043698914349079, 0.01998782530426979, -0.016319647431373596, -0.004296473227441311, 0.006036986131221056, 0.013988269492983818, 0.0076946173794567585, -0.009710511192679405, 0.021816566586494446, -0.02427627705037594, -0.04339785501360893, 0.008555516600608826, -0.04979310557246208, -0.018340887501835823, 0.031676799058914185, -0.03067152574658394, -0.042221471667289734, 0.07486076653003693, -0.019827408716082573, 0.01154994685202837, -0.0002147234044969082, -0.08007963001728058, 0.03571927919983864, 0.004930116236209869, 0.0024770894087851048, -0.07289300113916397, 0.02585904859006405, 0.05312975496053696, -0.011795918457210064, -0.0033366514835506678, 0.04705534130334854, -0.030457638204097748, -0.022265730425715446, 0.06788802146911621, -0.030821247026324272, -0.015496179461479187, -0.002211066195741296, 0.03790093585848808, -0.02404100075364113, -0.10129731148481369, -0.03310984745621681, 0.012769107706844807, 0.002793910913169384, -0.06442303955554962, -0.037387605756521225, -0.05308697745203972, -0.04202897474169731, 0.012597997672855854, -0.019506577402353287, 0.054969191551208496, 0.013346605934202671, -0.017164504155516624, -0.01967768743634224, 0.03251096233725548, 0.012223693542182446, 0.02135670743882656, -0.04202897474169731, -0.049236997961997986, -0.05539696663618088, 0.029815973713994026, 0.01805214025080204, -0.03343068063259125, 0.05099087581038475, -0.012063277885317802, -0.031420134007930756, 0.0484669990837574, -0.053172532469034195, 0.021795177832245827, 0.008844264782965183, -0.015047014690935612, 0.017004089429974556, 0.050862543284893036, 0.017303531989455223, -0.020993098616600037, 0.019281994551420212, 0.014223545789718628, 0.019388938322663307, 0.05274475738406181, -0.004026439972221851, 0.03432900831103325, 0.05492641404271126, 0.052488092333078384, 0.0024784260895103216, 0.020276574417948723, 0.015613817609846592, 0.02834014780819416, -0.05167531967163086, 0.0007412552949972451, -0.0017725960351526737, 0.016298258677124977, 0.03586900234222412, 0.0005928705213591456, 0.0448736846446991, -0.018586859107017517, 0.01510048657655716, 0.01883283071219921, -0.02090754359960556, -0.012822580523788929, 0.050434768199920654, -0.03676733002066612, 0.05873361974954605, 0.03169818967580795, -0.03516317158937454, 0.02951653115451336, -0.022265730425715446, -0.026842933148145676, -0.02180587314069271, 0.008651765994727612, 0.004237654153257608, 0.022971561178565025, 0.03571927919983864, 0.037387605756521225, 0.055910300463438034, 0.044018130749464035, -0.022308509796857834, -0.022543786093592644, -0.04688423126935959, -0.01838366501033306, 0.023912668228149414, 0.030778469517827034, 0.013442855328321457, 0.11173504590988159, -0.07246522605419159, -0.019880881533026695, 0.018651025369763374, 0.0021896774414926767, 0.01417007390409708, -0.04761144891381264, -0.04393257573246956, -0.013977575115859509, -0.020180324092507362, 0.04679867625236511, -0.023399338126182556, -0.03174096718430519, -0.014212851412594318, -0.0008354996680282056, 0.011710363440215588, 0.0014905313728377223, 0.03261790797114372, 0.03734482824802399, -0.01793450117111206, -0.05419919639825821, -0.014662016183137894, -0.057279180735349655, 0.009731899946928024, -0.007496771402657032, -0.03490650653839111, -0.017421171069145203, -0.029858751222491264, 0.04344063252210617, 0.028511257842183113, 0.041258975863456726, 0.044232018291950226, -0.04095953330397606, 0.05424197390675545, -0.011860084719955921, 0.033002905547618866, 0.0044996668584644794, -0.05740751326084137, 0.07182355970144272, -0.005914000794291496, -0.008550168946385384, -0.004820498637855053, -0.03287457302212715, 0.012876052409410477, 0.019036024808883667, -0.053343646228313446, 0.0029516532085835934, 0.012352026998996735, 0.039013154804706573, 0.04692700877785683, -0.023848501965403557, 0.021870039403438568, -0.0008862980175763369, -0.02632960118353367, 0.0185975544154644, -0.043141189962625504, -0.0029676947742700577, 0.004684145096689463, -0.013464244082570076, -0.062027495354413986, -0.023206837475299835, 0.009181138128042221, -0.06236971542239189, 0.012277166359126568, -0.012715635821223259, -0.06733191013336182, -0.00009925735503202304, 0.012180916033685207, -0.01068904809653759, -0.017100337892770767, -0.019314078614115715, 0.013507021591067314, 0.037601493299007416, -0.025495437905192375, -0.032083187252283096, 0.019945047795772552, -0.00037898262962698936, -0.06326804310083389, 0.03640372306108475, 0.010031342506408691, 0.004900706931948662, -0.043761465698480606, 0.03971898555755615, 0.011368142440915108, -0.05672307312488556, 0.01854408159852028, -0.010282660834491253, -0.02100379206240177, -0.007304272148758173, -0.006192055065184832, -0.038777876645326614, -0.013122023083269596, -0.000529706769157201, 0.005748237483203411, 0.0014343857765197754, 0.028190426528453827, -0.013892020098865032, 0.03319540247321129, 0.019100191071629524, -0.02722793072462082, -0.00027270708233118057, 0.009020722471177578, 0.004529076628386974, -0.011806612834334373, 0.02045837789773941, -0.010154328308999538, 0.004836540203541517, 0.027527373284101486, 0.005325809121131897, 0.0407242588698864, -0.007534201722592115, 0.005341850686818361, 0.017185892909765244, -0.04160119965672493, -0.011988417245447636, 0.027163764461874962, -0.023912668228149414, -0.04893755540251732, 0.003796510398387909, -0.01899324543774128, -0.0764007642865181, -0.0209503211081028, 0.020308656617999077, 0.02446877770125866, -0.015603123232722282, -0.027056820690631866, 0.03984731808304787, 0.062498047947883606, 0.013720909133553505, -0.035312894731760025, 0.029666252434253693, 0.04461701959371567, -0.07610131800174713, -0.024554332718253136, 0.041686754673719406, -0.038777876645326614, 0.00223913905210793, -0.07242244482040405, 0.021837955340743065, 0.028853479772806168, -0.00311206909827888, 0.0005718159372918308, 0.002943632425740361, 0.00436598714441061, 0.0042082443833351135, -0.05321530997753143, 0.030072640627622604, -0.028297370299696922, -0.014929375611245632, -0.02071504481136799, -0.026222657412290573, 0.017635058611631393, -0.08251795172691345, 0.06061583384871483, 0.04021092504262924, -0.026629045605659485, -0.02949514240026474, -0.020330045372247696, -0.013079245574772358, 0.0057856678031384945, 0.0166618674993515, 0.019271301105618477, -0.025730716064572334, 0.02446877770125866, -0.05492641404271126, -0.012587303295731544, -0.04027509316802025, -0.001977126346901059, 0.030243750661611557, 0.016362424939870834, -0.027078209444880486, 0.02493933029472828, 0.08880625665187836, -0.08628237992525101, -0.020704349502921104, 0.0009417752153240144, 0.011090087704360485, 0.07477521151304245, 0.01883283071219921, 0.0028447092045098543, 0.002876792335882783, -0.003636094508692622, -0.004652061965316534, 0.016961311921477318, -0.0009845527820289135, 0.026008769869804382, -0.015506873838603497, 0.012373415753245354, -0.08837848156690598, -0.027056820690631866, -0.02352767065167427, 0.017078949138522148, -0.00536323944106698, 0.012769107706844807, 0.021035876125097275, -0.041258975863456726, 0.046071454882621765, 0.00846996158361435, 0.029324032366275787, -0.013913408853113651, 0.04906588792800903, 0.01944241113960743, -0.004077238496392965, -0.04594312235713005, -0.03813621401786804, -0.07413355261087418, -0.029388198629021645, -0.01717519946396351, -0.01633034273982048, 0.0022551806177943945, 0.014779654331505299, 0.03779399394989014, 0.02352767065167427, 0.05976027995347977 ]
30,915
networkx.algorithms.assortativity.mixing
mixing_dict
Returns a dictionary representation of mixing matrix. Parameters ---------- xy : list or container of two-tuples Pairs of (x,y) items. attribute : string Node attribute key normalized : bool (default=False) Return counts if False or probabilities if True. Returns ------- d: dictionary Counts or Joint probability of occurrence of values in xy.
def mixing_dict(xy, normalized=False): """Returns a dictionary representation of mixing matrix. Parameters ---------- xy : list or container of two-tuples Pairs of (x,y) items. attribute : string Node attribute key normalized : bool (default=False) Return counts if False or probabilities if True. Returns ------- d: dictionary Counts or Joint probability of occurrence of values in xy. """ d = {} psum = 0.0 for x, y in xy: if x not in d: d[x] = {} if y not in d: d[y] = {} v = d[x].get(y, 0) d[x][y] = v + 1 psum += 1 if normalized: for _, jdict in d.items(): for j in jdict: jdict[j] /= psum return d
(xy, normalized=False)
[ -0.011047976091504097, 0.025611218065023422, 0.04135817289352417, 0.0009505564230494201, 0.04541148617863655, -0.005497085861861706, -0.04960828274488449, 0.010321607813239098, -0.014643949456512928, 0.02830147184431553, -0.010796885937452316, 0.05362572893500328, -0.035224393010139465, 0.04193209111690521, -0.04135817289352417, -0.028247667476534843, 0.032695554196834564, 0.000001650758122195839, -0.02623894438147545, 0.005335670430213213, 0.025378063321113586, 0.013469205237925053, 0.024875883013010025, 0.09146863967180252, -0.02536012791097164, -0.07762279361486435, -0.035116784274578094, -0.03673093393445015, 0.01696653477847576, 0.005793013609945774, -0.0361749492585659, -0.02613133378326893, 0.05606489256024361, 0.01867036335170269, 0.022992704063653946, -0.06714873760938644, 0.020894305780529976, 0.0015805242583155632, -0.08164024353027344, -0.026364490389823914, 0.04024619981646538, -0.056208375841379166, -0.011944727972149849, 0.015827661380171776, 0.06524762511253357, 0.016338810324668884, 0.015648311004042625, 0.02738678641617298, -0.05398442968726158, -0.08450984954833984, 0.0031520810443907976, -0.08795337378978729, 0.07353360950946808, 0.05470183119177818, -0.0010127685964107513, 0.027924837544560432, -0.005784046370536089, 0.04551909863948822, 0.013236049562692642, 0.051652878522872925, -0.011621897108852863, 0.06148127093911171, -0.0061965519562363625, -0.07927282154560089, -0.011612930335104465, -0.07654669135808945, -0.038667917251586914, 0.027817226946353912, -0.006860147695988417, -0.02724330499768257, -0.00616068160161376, -0.001498695695772767, 0.051975708454847336, -0.02602372318506241, 0.05402030050754547, 0.03068683110177517, 0.015217870473861694, 0.05516814440488815, 0.055311623960733414, 0.0524778887629509, -0.0322113074362278, 0.01701137237250805, -0.0009415888926014304, -0.006017201580107212, -0.03414829075336456, 0.04896262288093567, 0.027619941160082817, 0.05258549749851227, 0.023172054439783096, 0.013236049562692642, -0.06557045876979828, 0.03439938277006149, 0.03296457976102829, 0.0687270238995552, -0.01983613893389702, 0.028534628450870514, -0.01815921440720558, 0.015388253144919872, 0.0842946246266365, -0.03856030851602554, -0.034793950617313385, -0.0022945625241845846, -0.05337464064359665, 0.030130844563245773, -0.04021032899618149, -0.04046142101287842, 0.012536583468317986, -0.039313577115535736, 0.03307218849658966, 0.00027364928973838687, -0.03791464492678642, 0.034686341881752014, -0.004127298016101122, 0.0027306077536195517, 0.023835651576519012, -0.06779440492391586, -0.03635429963469505, -0.028821587562561035, -0.017379041761159897, 0.00354665145277977, -0.006232421845197678, 0.008398076519370079, -0.012832512147724628, 0.07432275265455246, -0.05265723913908005, -0.0027463010046631098, 0.027727551758289337, 0.023799780756235123, 0.032300982624292374, 0.039564669132232666, 0.008998899720609188, -0.056315984576940536, 0.039241839200258255, 0.024373700842261314, 0.05459422245621681, -0.005667468532919884, 0.01592630334198475, -0.025539478287100792, 0.07267273217439651, 0.0311172716319561, 0.0332874096930027, 0.006528349593281746, -0.010787918232381344, -0.022131823003292084, 0.019549179822206497, -0.006671830080449581, 0.022562263533473015, 0.016195328906178474, -0.03809399530291557, -0.06273672729730606, -0.04824522137641907, 0.039528798311948776, 0.04612888768315315, -0.039062488824129105, -0.027440590783953667, 0.0037260018289089203, -0.043151672929525375, -0.043976686894893646, 0.027297111228108406, -0.012133046053349972, -0.019818205386400223, -0.003968124743551016, -0.012061305344104767, -0.009362083859741688, 0.003362817456945777, 0.0059723639860749245, 0.011765377596020699, -0.03852443769574165, -0.004277504049241543, -0.07618799060583115, -0.07425101101398468, -0.01422247663140297, -0.04239840433001518, 0.0034435251727700233, 0.0401744619011879, 0.005627114791423082, -0.01056373119354248, 0.004882811103016138, 0.030238455161452293, 0.03633636608719826, 0.06833245605230331, -0.04107121005654335, -0.002183589618653059, 0.010536828078329563, -0.04422777518630028, -0.03432764112949371, 0.06901398301124573, 0.013253984972834587, 0.03622875362634659, 0.03841682896018028, 0.0285884328186512, -0.028319407254457474, -0.008617780171334743, 0.015648311004042625, 0.07396405190229416, 0.034973300993442535, 0.0003074175619985908, -0.025934047996997833, -0.020248645916581154, 0.015459992922842503, -0.003526474582031369, -0.07783801853656769, -0.008559491485357285, 0.10029266774654388, 0.001225186511874199, -0.04433538764715195, -0.020966045558452606, -0.003120694775134325, -0.023602494969964027, -0.02403293550014496, 0.026507969945669174, -0.07227815687656403, 0.02862430363893509, -0.006788407452404499, 0.011639832518994808, 0.006447642110288143, 0.01111074909567833, 0.03296457976102829, -0.019907880574464798, -0.06980312615633011, 0.02923409454524517, -0.018939388915896416, 0.06460196524858475, 0.029772143810987473, -0.03542167693376541, 0.011128684505820274, -0.00390759389847517, 0.022418783977627754, -0.05025394633412361, 0.008868870325386524, 0.0492137148976326, -0.006138262804597616, 0.05115069821476936, -0.017997799441218376, -0.002126421546563506, -0.01906493306159973, -0.012339298613369465, 0.027422655373811722, 0.048173483461141586, 0.023835651576519012, -0.008200790733098984, -0.00033067705226130784, 0.06176823377609253, -0.035009171813726425, -0.021791057661175728, -0.013774100691080093, 0.08364896476268768, -0.004797619767487049, -0.05043329671025276, -0.0224367193877697, -0.04060490056872368, 0.03136836364865303, -0.015011617913842201, 0.013621652498841286, 0.06998247653245926, -0.06413565576076508, 0.0023337954189628363, 0.06327477842569351, 0.007882444187998772, -0.033090125769376755, -0.007438552565872669, 0.004084702581167221, 0.030597155913710594, 0.008971997536718845, 0.033090125769376755, -0.006201035343110561, 0.010599601082503796, 0.076690174639225, -0.05836057662963867, 0.04806587100028992, -0.09397953748703003, -0.03698202595114708, 0.06058451905846596, -0.06901398301124573, 0.005393959116190672, 0.016580931842327118, 0.055526841431856155, -0.012850446626543999, 0.047635432332754135, 0.03766355663537979, -0.02507316693663597, -0.005183222703635693, -0.036282557994127274, 0.00132046639919281, 0.017639098688960075, 0.025378063321113586, -0.010249868035316467, 0.04139404371380806, 0.017630131915211678, -0.018760038539767265, -0.008631231263279915, -0.03551135212182999, -0.07460971176624298, -0.010671340860426426, -0.03812986612319946, 0.006896018050611019, -0.05455835163593292, -0.0030377451330423355, 0.047097381204366684, 0.022095952183008194, 0.04038967937231064, 0.04038967937231064, 0.046882160007953644, 0.0318526066839695, -0.02019483968615532, 0.04838870093226433, 0.023243794217705727, 0.0034345577005296946, -0.01577385701239109, -0.02478620782494545, 0.016948601230978966, 0.04932132363319397, 0.009891167283058167, 0.016598867252469063, -0.025736764073371887, 0.016114622354507446, -0.04842457175254822, -0.003116210922598839, 0.047456081956624985, 0.09670566767454147, 0.010061549954116344, 0.01787225343286991, -0.02851669304072857, 0.06722047924995422, 0.0416092611849308, 0.017468716949224472, 0.07227815687656403, 0.0007706456817686558, 0.02478620782494545, -0.0056629846803843975, -0.059544287621974945, 0.011944727972149849, -0.03140423074364662, 0.030812375247478485, -0.043833207339048386, 0.006124811712652445, -0.0014235927956178784, -0.01983613893389702, 0.004452370572835207, -0.01606081612408161, -0.03357436880469322, 0.003636326640844345, -0.005501569714397192, -0.02293889969587326, 0.011299067176878452, -0.0336640439927578, -0.04433538764715195, -0.022974768653512, 0.00900786742568016, 0.028193863108754158, -0.04566257819533348, 0.03615701571106911, 0.032444462180137634, 0.05800187587738037, 0.0005503811407834291, -0.012958057224750519, 0.025539478287100792, -0.09993396699428558, -0.006353483069688082, 0.04878327250480652, 0.002477275673300028, -0.01783638447523117, 0.007721029222011566, -0.03542167693376541, 0.013836872763931751, -0.007680675480514765, -0.013684425503015518, 0.005528471898287535, -0.00042763829696923494, -0.005842335056513548, 0.001817042357288301, -0.013397465460002422, -0.05272898077964783, 0.04846044257283211, 0.016562996432185173, 0.011137651279568672, -0.04250601306557655, 0.002427954226732254, -0.026328619569540024, -0.05796600505709648, -0.003909836057573557, 0.0015760405221953988, 0.010671340860426426, 0.05419965088367462, 0.002234031679108739, -0.026759060099720955, 0.02098398096859455, -0.013352627865970135, -0.04214731231331825, 0.0072188484482467175, 0.007635837886482477, 0.016580931842327118, 0.04519626870751381, -0.056315984576940536, -0.05513227358460426, -0.05782252550125122, 0.035762444138526917, -0.055634453892707825, -0.039744019508361816, -0.036551583558321, -0.02137855254113674, -0.0745379701256752, -0.03830921649932861, -0.02887539379298687, -0.033161863684654236, 0.00841152761131525, 0.01606978476047516, -0.03481188789010048, 0.03723311424255371, -0.06277259439229965, -0.036461908370256424, 0.039528798311948776, 0.02048180066049099, -0.03167325630784035, 0.022167693823575974, -0.019531244412064552, 0.023692170158028603, -0.08257286250591278, -0.008617780171334743, 0.050827864557504654, 0.04932132363319397, -0.007371296174824238, 0.03054335154592991, 0.017558392137289047, 0.023530755192041397, 0.007389231119304895, -0.06470957398414612, -0.043976686894893646, 0.014052093960344791, 0.07604451477527618, -0.039636410772800446, -0.06607263535261154, 0.023620430380105972, -0.05434313043951988, 0.01477846223860979, -0.03542167693376541, 0.03590592369437218, 0.04013859108090401, 0.0004691130598075688, 0.013720295391976833, 0.011325969360768795, 0.038703788071870804, 0.04128643125295639, 0.01653609424829483, -0.04953654482960701, 0.012715933844447136, -0.0033202217891812325, -0.051581136882305145, 0.007317490875720978, 0.008734358474612236, 0.05448660999536514, 0.001128785777837038, 0.06166062131524086, -0.0589703693985939, 0.02873191237449646, 0.033448826521635056, -0.039421189576387405, -0.051401786506175995, -0.014634981751441956, 0.047384340316057205, 0.014697754755616188, -0.01697550341486931, 0.018975257873535156, 0.022382913157343864, -0.06083561107516289, -0.04006684944033623, -0.004340276587754488, -0.012590388767421246, -0.011783313006162643, 0.043582115322351456, 0.02652590535581112, 0.026651449501514435, -0.008546040393412113, -0.03242652863264084, -0.030094975605607033, -0.0019067175453528762, -0.012061305344104767, 0.05036155506968498, -0.03090205043554306, -0.04035381227731705, -0.02127094194293022, -0.032552074640989304, 0.034471120685338974, -0.039349447935819626, 0.010868626646697521, 0.03570863977074623, -0.02521664835512638, -0.028319407254457474, -0.013065666891634464, 0.029144419357180595, -0.038667917251586914, -0.02471446618437767, 0.03970814868807793, -0.0005472985794767737, 0.04609302058815956, 0.01938776485621929, 0.06603676825761795, -0.0037977418396621943, -0.03992336988449097, -0.0495724156498909, -0.05782252550125122, -0.021898668259382248, 0.017343170940876007, 0.000448095437604934, -0.001175865181721747, 0.04042555019259453, -0.008456365205347538, 0.023064443841576576, 0.004842457361519337, 0.01333469245582819, -0.048173483461141586, -0.03769942745566368, 0.030059104785323143, -0.01310153678059578, -0.0013025313382968307, -0.022598134353756905, -0.03656952083110809, -0.022203562781214714, -0.029144419357180595, -0.04598540812730789, 0.05814535543322563, 0.012949089519679546, 0.02862430363893509, 0.04182448238134384, -0.007223332300782204, 0.06503240764141083, 0.05495292320847511, -0.04838870093226433, -0.034686341881752014, -0.03640810400247574, -0.004941099788993597, 0.027619941160082817, -0.011998533271253109, 0.06305955350399017, 0.0142942164093256, 0.036461908370256424, 0.05014633387327194, -0.00853707268834114, 0.030041169375181198, 0.006752537563443184, 0.0828598216176033, 0.009720784611999989, -0.006748053710907698, -0.02670525573194027, 0.10280357301235199, 0.019907880574464798, -0.019782334566116333, -0.03624669089913368, 0.021952472627162933, 0.015397220849990845, -0.039528798311948776, 0.004407532978802919, -0.07331839203834534, -0.016374679282307625, 0.024015000090003014, 0.002272143727168441, -0.03203195706009865, -0.0481376126408577, 0.0048110708594322205, 0.03642604127526283, 0.0021353892516344786, -0.05606489256024361, 0.025808503851294518, -0.006698732730001211, -0.014070028439164162, -0.006927404087036848, 0.0025310807395726442, 0.029933560639619827, -0.03441731631755829, 0.018221987411379814, 0.02756613679230213, 0.021773122251033783, 0.03332328051328659, 0.02322586067020893, -0.021539967507123947, -0.028391147032380104, 0.0067973751574754715, -0.05721273645758629, -0.015648311004042625, -0.016347777098417282, -0.02098398096859455, 0.03812986612319946, -0.014688787050545216, 0.027368851006031036, 0.06277259439229965, 0.024588922038674355, -0.04243427515029907, 0.06689765304327011, 0.046918030828237534, -0.029718339443206787, -0.0835772231221199, -0.035080913454294205, 0.024122610688209534, 0.012133046053349972, 0.007178494706749916, -0.01729833334684372, 0.008711939677596092, 0.0022104920353740454, 0.011819182895123959, -0.07148901373147964, -0.002430196152999997, -0.00724575063213706, -0.026221008971333504, 0.017773611471056938, 0.013684425503015518, -0.06062038987874985, 0.04422777518630028, -0.014760526828467846, -0.006649411283433437, -0.00670321611687541, -0.018401337787508965, -0.024768272414803505, 0.015101292170584202, 0.027619941160082817, 0.0059454613365232944, -0.04469408839941025, -0.016876859590411186, -0.006474544759839773, -0.0046675908379256725, 0.016589900478720665, -0.04577018693089485, -0.07353360950946808, -0.022490523755550385, -0.03240859508514404, -0.017029307782649994, -0.0012038886779919267, 0.010052582249045372, 0.0071471082046628, -0.011559125036001205, -0.0318526066839695, 0.0028180410154163837, 0.004761749412864447, 0.05312354862689972, -0.04042555019259453, -0.016123589128255844, -0.039528798311948776, 0.007936249487102032, -0.0066000898368656635, -0.03335915133357048, 0.03378959000110626, 0.029969429597258568, 0.008272531442344189, 0.010698243975639343, -0.024373700842261314, 0.009882199577987194, -0.019764399155974388, 0.02745852619409561, 0.003465943969786167, 0.004037622828036547, -0.02326172962784767, 0.012007500045001507, -0.029359638690948486, -0.027763420715928078, -0.0039367382414639, -0.0025983371306210756, 0.023889455944299698, -0.030668895691633224, -0.005766110960394144, -0.04150165244936943, 0.020643215626478195, -0.017352137714624405, 0.04609302058815956, -0.05075612664222717, -0.02905474416911602, 0.07812497764825821, 0.003387478180229664, -0.010007744655013084, -0.020930176600813866, -0.05448660999536514, 0.0029615212697535753, 0.052011579275131226, 0.03050748072564602, 0.0029032325837761164, -0.03859617933630943, -0.011532221920788288, 0.006071006413549185, -0.0018573962152004242, 0.0073130070231854916, -0.012850446626543999, -0.03622875362634659, 0.06173236295580864, 0.023333469405770302, -0.000348051602486521, -0.004802103620022535, 0.0571768656373024, -0.0017060694517567754, 0.035798314958810806, -0.05477357283234596, -0.04480169713497162, -0.014733624644577503, 0.019154608249664307, 0.003131904173642397, -0.03423796594142914, 0.023279665037989616, -0.02279541827738285, -0.03527819737792015, -0.004006236791610718, 0.09412302076816559, 0.07292381674051285, -0.028086252510547638, 0.05276484787464142, -0.010698243975639343, -0.006595605984330177, 0.0846533253788948, -0.014966780319809914, -0.0061696493066847324, -0.005949945189058781, -0.025413932278752327, 0.05660294368863106, 0.009720784611999989, -0.02055354043841362, 0.03676680475473404, -0.004932132549583912, 0.007335425820201635, 0.009084091521799564, 0.06596502661705017, -0.0017553907819092274, 0.0640639141201973, -0.004900746047496796, -0.013065666891634464, -0.007205396890640259, 0.031350426375865936, 0.024696532636880875, -0.0014538581017404795, -0.07740757614374161, -0.012339298613369465, 0.07776627689599991, 0.004044348374009132, -0.05606489256024361, -0.04429951682686806, -0.038703788071870804, 0.01224962342530489, -0.05491705238819122, 0.03795051574707031, -0.01472465693950653, 0.050863735377788544, -0.03140423074364662, -0.043582115322351456, 0.03086618147790432, 0.03820160776376724, -0.02293889969587326, 0.01606978476047516, 0.043940816074609756, 0.02315411902964115, 0.014626014046370983, 0.0078734764829278, -0.02421228587627411, 0.06528349965810776, 0.0005512218340300024, -0.039564669132232666, 0.05054090544581413, 0.04634410887956619, -0.04541148617863655, -0.013899645768105984, 0.051114827394485474, -0.08400766551494598, 0.03517058864235878, -0.03430970758199692, 0.006676313932985067, -0.025557413697242737, -0.06976725161075592, -0.016078751534223557, 0.028534628450870514, 0.04530387744307518, -0.05836057662963867, 0.013836872763931751, 0.067292220890522, 0.0071336571127176285 ]
30,921
networkx.generators.small
moebius_kantor_graph
Returns the Moebius-Kantor graph. The Möbius-Kantor graph is the cubic symmetric graph on 16 nodes. Its LCF notation is [5,-5]^8, and it is isomorphic to the generalized Petersen graph [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Moebius-Kantor graph References ---------- .. [1] https://en.wikipedia.org/wiki/M%C3%B6bius%E2%80%93Kantor_graph
def sedgewick_maze_graph(create_using=None): """ Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick """ G = empty_graph(0, create_using) G.add_nodes_from(range(8)) G.add_edges_from([[0, 2], [0, 7], [0, 5]]) G.add_edges_from([[1, 7], [2, 6]]) G.add_edges_from([[3, 4], [3, 5]]) G.add_edges_from([[4, 5], [4, 7], [4, 6]]) G.name = "Sedgewick Maze" return G
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.08463752269744873, -0.02233586274087429, -0.01378906425088644, -0.033806562423706055, -0.0619383305311203, 0.02333933301270008, -0.06276878714561462, 0.055087052285671234, -0.0002595181576907635, -0.01582195609807968, -0.006777748931199312, 0.03148820251226425, -0.006976712960749865, 0.07730180770158768, 0.024048682302236557, -0.013425738550722599, 0.042906999588012695, -0.0033758985809981823, -0.024446610361337662, 0.05245726928114891, -0.01096031628549099, -0.03993119299411774, 0.040000397711992264, 0.04408348351716995, -0.026972586289048195, 0.02773384004831314, -0.014766582287847996, 0.0542219914495945, -0.00820942409336567, -0.03313181549310684, -0.01720605418086052, -0.04411808401346207, -0.05827047675848007, 0.018546897917985916, 0.030034899711608887, 0.06394527107477188, 0.0018804252613335848, 0.04813196510076523, -0.08048523217439651, -0.05231885984539986, 0.03768203407526016, -0.005354724358767271, 0.0521804504096508, -0.00460644718259573, 0.040104202926158905, -0.012802895158529282, 0.051003966480493546, 0.021003669127821922, -0.025917213410139084, -0.03183422610163689, 0.026661165058612823, -0.023962175473570824, -0.016436150297522545, 0.035917311906814575, 0.034810032695531845, -0.016825426369905472, -0.022422367706894875, -0.008023436181247234, 0.1025615707039833, -0.04757832735776901, 0.0053677004761993885, -0.014204293489456177, 0.02726670727133751, 0.04093466326594353, -0.04584820568561554, -0.013996678404510021, -0.0341871902346611, -0.05487943813204765, -0.0006141929770819843, 0.004783784504979849, 0.04515615850687027, 0.03574429824948311, 0.04515615850687027, -0.010147159919142723, 0.03667856380343437, 0.02963697351515293, -0.0147146787494421, -0.035917311906814575, -0.04436030238866806, -0.04747451841831207, 0.019757982343435287, 0.017015740275382996, -0.027128297835588455, -0.05352994427084923, 0.031142177060246468, 0.03209374472498894, 0.030467430129647255, 0.043010808527469635, -0.011799424886703491, -0.09654074907302856, 0.01620258390903473, -0.013088365085422993, -0.027128297835588455, -0.011548557318747044, -0.008624653331935406, 0.004186892881989479, 0.020415427163243294, -0.06006979942321777, 0.005821857135742903, -0.019446559250354767, -0.04173051938414574, 0.00958487018942833, -0.08477593213319778, 0.012448220513761044, -0.05266488343477249, -0.042803194373846054, -0.024481212720274925, 0.004063621629029512, -0.01715414971113205, -0.0403464213013649, -0.041695915162563324, -0.002144268713891506, 0.02721480280160904, 0.004493989050388336, 0.03138439357280731, 0.03626333549618721, 0.02413518726825714, 0.016548607498407364, 0.03458511829376221, -0.06557158380746841, -0.019654175266623497, 0.009792485274374485, -0.04743991792201996, -0.03709379583597183, 0.036920782178640366, -0.02958506904542446, 0.034810032695531845, -0.013071063905954361, 0.008520846255123615, -0.012820196337997913, 0.020501933991909027, 0.0062414114363491535, -0.03937755525112152, 0.03219754993915558, -0.05173061788082123, 0.008235376328229904, -0.04183432459831238, -0.043806664645671844, 0.025346271693706512, 0.029048731550574303, 0.011401497758924961, -0.028702707961201668, 0.0018685306422412395, 0.028252875432372093, -0.06308021396398544, -0.002480560913681984, -0.01858150027692318, 0.008529496379196644, 0.06083105504512787, 0.027924152091145515, 0.028408586978912354, -0.009031231515109539, 0.02128048799932003, 0.02711099572479725, -0.021453499794006348, -0.03176502138376236, -0.0013040787307545543, 0.05944695696234703, 0.015155860222876072, 0.05882411450147629, 0.011280388571321964, -0.025761501863598824, 0.012854798696935177, 0.012015690095722675, -0.036816973239183426, -0.010458581149578094, 0.008633303456008434, 0.011730220168828964, -0.01223195530474186, 0.01323542557656765, -0.027439719066023827, 0.010631593875586987, -0.05744001641869545, -0.02493104338645935, 0.06394527107477188, -0.0000061078003454895224, -0.025553887709975243, -0.005255242343991995, 0.020086703822016716, -0.043910469859838486, -0.019498463720083237, -0.012327112257480621, 0.014472462236881256, -0.0058175320737063885, 0.002709802007302642, 0.003905748249962926, 0.012180051766335964, -0.008520846255123615, 0.03266468271613121, 0.016652414575219154, -0.010536436922848225, 0.005423929542303085, 0.033910371363162994, 0.07204224169254303, 0.040519434958696365, -0.023633452132344246, 0.030311720445752144, 0.024169789627194405, -0.05612512677907944, 0.07550247758626938, -0.014126437716186047, 0.032318659126758575, 0.011747521348297596, -0.026920681819319725, 0.0529417023062706, 0.03500034660100937, 0.004796760622411966, -0.08110807090997696, -0.01889292150735855, 0.03788964822888374, -0.04778594151139259, -0.01604687236249447, 0.05636734142899513, 0.026868779212236404, -0.013451690785586834, -0.031315188854932785, 0.008248351514339447, 0.06121167913079262, 0.03403148055076599, -0.02603832073509693, -0.05065794289112091, 0.007037267088890076, -0.048893220722675323, -0.019982896745204926, 0.0142648471519351, -0.04332222789525986, -0.04505234956741333, -0.039204541593790054, -0.0151645103469491, -0.0742567926645279, 0.020726850256323814, -0.028875719755887985, 0.03896232321858406, -0.012534726411104202, 0.013261377811431885, -0.011704268865287304, -0.013304630294442177, -0.01894482411444187, 0.007993158884346485, -0.020847957581281662, -0.05065794289112091, -0.06380686163902283, 0.010069304145872593, -0.034117985516786575, 0.047093894332647324, 0.03806266188621521, -0.0074957492761313915, 0.01837388426065445, 0.0030882658902555704, 0.008274303749203682, -0.03283769637346268, -0.014827136881649494, 0.03278579190373421, 0.00012948874791618437, -0.0045848204754292965, 0.013823666609823704, -0.057993654161691666, 0.0035878384951502085, -0.01625448651611805, 0.02202443964779377, -0.021557306870818138, -0.02742241695523262, -0.023114416748285294, -0.01726660691201687, 0.04058863967657089, 0.011098725721240044, -0.05615972727537155, 0.07494883984327316, -0.08664445579051971, -0.04564059153199196, 0.03809726610779762, 0.014541666954755783, 0.01480118464678526, 0.006345218978822231, 0.017232004553079605, -0.003449428826570511, -0.025848006829619408, -0.0038062662351876497, -0.0013830154202878475, -0.03557128831744194, -0.09543347358703613, -0.035432878881692886, 0.0121454494073987, 0.05415278673171997, -0.05086555704474449, -0.0022707837633788586, 0.01614202931523323, 0.00942050851881504, 0.04145370051264763, -0.030138708651065826, -0.017500173300504684, -0.04224955290555954, 0.014109136536717415, 0.0007142155664041638, 0.04159210994839668, -0.0044182962737977505, 0.02207634411752224, -0.008594376035034657, -0.028771912679076195, 0.047612931579351425, 0.08920504152774811, -0.06121167913079262, 0.007776893675327301, 0.018512295559048653, 0.023149019107222557, 0.03896232321858406, 0.0019031331175938249, -0.023996777832508087, 0.04982748627662659, -0.03553668409585953, -0.08962026983499527, 0.014965546317398548, -0.00492219440639019, 0.05744001641869545, -0.02747432142496109, -0.04204193875193596, -0.029187140986323357, -0.030000297352671623, 0.055882908403873444, 0.04903163015842438, -0.0078374482691288, 0.018114367499947548, -0.01598631776869297, 0.008529496379196644, -0.06744011491537094, 0.01450706459581852, 0.01832198165357113, 0.04612502455711365, 0.012560678645968437, 0.01804516278207302, -0.026816874742507935, -0.036920782178640366, 0.015908462926745415, 0.01814896985888481, -0.051315389573574066, 0.018858319148421288, 0.013624702580273151, -0.007776893675327301, -0.022266658022999763, -0.04463712126016617, 0.09065833687782288, 0.023858368396759033, -0.013166220858693123, -0.011107376776635647, 0.06166151165962219, 0.016453450545668602, -0.00791097804903984, -0.05045032873749733, -0.012171401642262936, 0.046990085393190384, 0.03654015436768532, 0.0704159215092659, -0.01704169251024723, 0.006898857653141022, 0.030294418334960938, 0.033910371363162994, 0.016159329563379288, 0.010225014761090279, -0.03524256497621536, 0.02906603179872036, -0.06335703283548355, 0.02176492288708687, 0.004930844996124506, -0.0016522655496373773, -0.021799525246024132, -0.02567499503493309, -0.017058992758393288, 0.03243976831436157, 0.053702954202890396, -0.059377752244472504, -0.021193983033299446, -0.05930854752659798, -0.02138429507613182, 0.032906901091337204, -0.008196447975933552, 0.06536397337913513, -0.03446400910615921, 0.009731930680572987, 0.0634954422712326, 0.004292862489819527, 0.011903232894837856, -0.0017668860964477062, 0.008421364240348339, -0.002876326208934188, 0.08062364161014557, -0.028495091944932938, 0.04508695378899574, 0.03500034660100937, 0.017387716099619865, -0.056298136711120605, -0.09439539909362793, -0.02430819906294346, 0.05692097917199135, 0.06806296110153198, -0.00551908602938056, 0.025242464616894722, 0.08214614540338516, 0.04647104814648628, -0.03619413077831268, 0.046505652368068695, 0.07750941812992096, -0.042906999588012695, 0.03202454000711441, 0.04387586936354637, -0.02816637046635151, -0.06543317437171936, -0.027059093117713928, 0.01077000331133604, 0.026557357981801033, 0.018616102635860443, 0.048893220722675323, -0.048789411783218384, -0.04854719340801239, 0.018062463030219078, -0.0027530549559742212, 0.010873810388147831, 0.015441330149769783, 0.026142127811908722, 0.05847809091210365, 0.006890207063406706, 0.05138459429144859, -0.012223305180668831, 0.00031520641641691327, 0.03868550434708595, 0.04249177128076553, -0.016981137916445732, -0.024498512968420982, -0.005752652417868376, -0.052388064563274384, 0.04792435094714165, -0.01003470178693533, -0.06093486025929451, 0.057578425854444504, -0.02138429507613182, -0.017716439440846443, 0.005216314923018217, 0.03325292468070984, -0.01858150027692318, 0.022318560630083084, 0.018650704994797707, 0.031851526349782944, -0.014143738895654678, -0.02958506904542446, -0.03060583956539631, 0.020000198855996132, -0.030848057940602303, -0.0072708334773778915, -0.0062024835497140884, 0.016453450545668602, 0.00929075013846159, 0.030726948752999306, 0.011574509553611279, -0.036021120846271515, 0.011773473583161831, -0.061799921095371246, 0.008092640899121761, 0.027145598083734512, 0.011505304835736752, -0.033218324184417725, 0.05141919478774071, 0.03837408497929573, -0.014550318010151386, -0.02058843895792961, 0.0665750578045845, -0.03885851800441742, -0.015337523072957993, 0.021730320528149605, 0.005709399469196796, 0.0010040107881650329, -0.06792455166578293, 0.031886130571365356, -0.02965427376329899, -0.058893319219350815, -0.04588280990719795, 0.08878980576992035, -0.045190759003162384, -0.06342623382806778, -0.022353162989020348, 0.03927374631166458, -0.01693788543343544, -0.06155770644545555, -0.00958487018942833, 0.004883266519755125, 0.030899960547685623, -0.010562388226389885, 0.000412255380069837, 0.04996589571237564, -0.08519116044044495, -0.022110946476459503, -0.04218034818768501, 0.0029152538627386093, -0.034810032695531845, -0.027976056560873985, -0.000059033620345871896, -0.0063971225172281265, 0.078132264316082, -0.030571237206459045, -0.03140169754624367, -0.004502640105783939, -0.07647135108709335, 0.028789212927222252, -0.015683546662330627, -0.03837408497929573, -0.021142078563570976, -0.023200921714305878, 0.04397967457771301, 0.023166319355368614, -0.012448220513761044, 0.018512295559048653, 0.027595430612564087, 0.05615972727537155, -0.009005280211567879, 0.003328320337459445, 0.07667896151542664, 0.0222320556640625, 0.030052201822400093, -0.007616857532411814, 0.014991498552262783, 0.05494864284992218, -0.05927394703030586, 0.015363474376499653, 0.024273596704006195, 0.02811446599662304, 0.03588270768523216, -0.0439450740814209, 0.05993138998746872, 0.030450129881501198, 0.03372005745768547, 0.04027721658349037, 0.03757822886109352, 0.031522803008556366, 0.07141939550638199, -0.028564298525452614, 0.07937794923782349, 0.03372005745768547, -0.044394902884960175, 0.047509122639894485, 0.014351353980600834, -0.019706077873706818, -0.03847789019346237, 0.005164411384612322, -0.02965427376329899, -0.034066081047058105, -0.022958705201745033, -0.011349593289196491, 0.0017539102118462324, 0.09481062740087509, -0.029031429439783096, -0.023633452132344246, -0.09813246130943298, -0.021903332322835922, 0.03224945440888405, -0.005199013743549585, -0.005363374948501587, 0.0863676369190216, -0.04965447261929512, -0.02313171699643135, -0.029463959857821465, 0.01672161929309368, 0.012768292799592018, -0.06394527107477188, -0.011159280315041542, 0.014022630639374256, -0.009083135053515434, -0.009031231515109539, 0.022422367706894875, 0.005454206373542547, 0.022301260381937027, -0.024256296455860138, 0.025657694786787033, 0.029792683199048042, 0.043910469859838486, 0.08616002649068832, -0.025380875915288925, -0.02821827307343483, -0.007794194854795933, 0.0003316966467536986, 0.03148820251226425, 0.049516063183546066, -0.023633452132344246, -0.03399687632918358, -0.014152389951050282, 0.005631543695926666, 0.04038102552294731, -0.01894482411444187, 0.03937755525112152, -0.036609359085559845, 0.00839108694344759, -0.021886030212044716, 0.013174870982766151, 0.05124618485569954, -0.05138459429144859, 0.04128068685531616, -0.002031810814514756, -0.04259558022022247, -0.0029974346980452538, 0.02546738088130951, 0.01989639177918434, 0.023425837978720665, 0.016176631674170494, -0.05072714760899544, 0.07224985212087631, 0.035398274660110474, 0.034221794456243515, 0.035709697753190994, 0.02333933301270008, 0.018564198166131973, -0.01858150027692318, 0.001433837809599936, -0.0439450740814209, -0.010017400607466698, 0.007556303404271603, -0.016687016934156418, -0.05401437729597092, -0.05906632915139198, 0.00817914679646492, -0.02328742854297161, 0.009005280211567879, -0.03159200772643089, -0.024498512968420982, 0.009264797903597355, -0.010839208029210567, 0.00166740408167243, -0.03283769637346268, -0.012197352945804596, 0.004011718090623617, 0.02166111394762993, 0.009904942475259304, -0.013399787247180939, 0.04065784439444542, -0.021747620776295662, -0.04543297737836838, -0.011894581839442253, -0.03313181549310684, -0.019930994138121605, -0.031003767624497414, 0.0002042353735305369, 0.000031916002626530826, 0.0107959546148777, 0.05813206359744072, -0.0416267104446888, 0.02716290019452572, 0.027439719066023827, 0.01724930666387081, -0.06761312484741211, -0.0195330660790205, 0.06356464326381683, -0.000874251767527312, -0.042699385434389114, 0.011280388571321964, -0.00820942409336567, 0.005302820820361376, 0.023252826184034348, 0.01724930666387081, 0.05501784756779671, 0.03664396330714226, -0.03487923741340637, -0.06699028611183167, 0.05415278673171997, -0.04712849482893944, 0.038927722722291946, 0.008801990188658237, 0.009359954856336117, 0.02361615188419819, 0.022007139399647713, 0.04557138681411743, 0.006120303180068731, 0.028079863637685776, 0.03256087750196457, -0.02778574265539646, -0.025813404470682144, -0.043910469859838486, -0.008771713823080063, -0.052111245691776276, -0.06470652669668198, -0.045398373156785965, -0.024913743138313293, 0.022854898124933243, -0.04674787074327469, -0.037197601050138474, 0.039066132158041, 0.05183442682027817, -0.012958606705069542, -0.04467172548174858, -0.0056531704030931, 0.03633254021406174, -0.05266488343477249, -0.021453499794006348, 0.03043282777070999, 0.007573604583740234, -0.02302790991961956, -0.04045023024082184, 0.024533115327358246, 0.05013890564441681, -0.01051048468798399, 0.007123772986233234, -0.01666971668601036, -0.01814896985888481, 0.002420006785541773, -0.06346084177494049, 0.032630082219839096, 0.04453331604599953, 0.00242216931656003, 0.021470801904797554, 0.03993119299411774, -0.04352984577417374, -0.03993119299411774, 0.04875481128692627, -0.002817934611812234, 0.006301965564489365, -0.02069224789738655, -0.031574707478284836, 0.041903529316186905, 0.029048731550574303, 0.00044280284782871604, -0.058997124433517456, -0.003743549343198538, -0.001001848140731454, -0.022508874535560608, 0.006998339202255011, 0.012188702821731567, 0.0011159280547872186, -0.018650704994797707, 0.020830657333135605, -0.06235355883836746, -0.0015181811759248376, -0.04612502455711365, -0.059689175337553024, 0.00385168194770813, -0.05615972727537155, -0.0434260368347168, 0.008166170679032803, -0.0049870735965669155, 0.052491869777441025, 0.006920483894646168, 0.0030341995880007744, 0.00034142856020480394, 0.05986218526959419, -0.01868530735373497, 0.037197601050138474, -0.03434289991855621, -0.018304679542779922, -0.08152329921722412, 0.006146254949271679, -0.00976653303951025, 0.012742341496050358, 0.030692346394062042, 0.0452253632247448, -0.046817075461149216, 0.012586629949510098, 0.059689175337553024, -0.05553688481450081, 0.06692107766866684, 0.02816637046635151, -0.024896441027522087, 0.025380875915288925, -0.04017340764403343, -0.044187288731336594, -0.03619413077831268, -0.07100416719913483, -0.01827007718384266, 0.024169789627194405, 0.014576269313693047, -0.022958705201745033, -0.044706325978040695, 0.02238776534795761, 0.02282029576599598, 0.05615972727537155 ]
30,924
networkx.algorithms.shortest_paths.weighted
multi_source_dijkstra
Find shortest weighted paths and lengths from a given set of source nodes. Uses Dijkstra's algorithm to compute the shortest paths and lengths between one of the source nodes and the given `target`, or all other reachable nodes if not specified, for a weighted graph. Parameters ---------- G : NetworkX graph sources : non-empty set of nodes Starting nodes for paths. If this is just a set containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in the set, the computed paths may begin from any one of the start nodes. target : node label, optional Ending node for path cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number or None to indicate a hidden edge. Returns ------- distance, path : pair of dictionaries, or numeric and list If target is None, returns a tuple of two dictionaries keyed by node. The first dictionary stores distance from one of the source nodes. The second stores the path from one of the sources to that node. If target is not None, returns a tuple of (distance, path) where distance is the distance from source to target and path is a list representing the path from source to target. Examples -------- >>> G = nx.path_graph(5) >>> length, path = nx.multi_source_dijkstra(G, {0, 4}) >>> for node in [0, 1, 2, 3, 4]: ... print(f"{node}: {length[node]}") 0: 0 1: 1 2: 2 3: 1 4: 0 >>> path[1] [0, 1] >>> path[3] [4, 3] >>> length, path = nx.multi_source_dijkstra(G, {0, 4}, 1) >>> length 1 >>> path [0, 1] Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. The weight function can be used to hide edges by returning None. So ``weight = lambda u, v, d: 1 if d['color']=="red" else None`` will find the shortest red path. Based on the Python cookbook recipe (119466) at https://code.activestate.com/recipes/119466/ This algorithm is not guaranteed to work if edge weights are negative or are floating point numbers (overflows and roundoff errors can cause problems). Raises ------ ValueError If `sources` is empty. NodeNotFound If any of `sources` is not in `G`. See Also -------- multi_source_dijkstra_path multi_source_dijkstra_path_length
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, sources, target=None, cutoff=None, weight='weight', *, backend=None, **backend_kwargs)
[ 0.008667515590786934, -0.004119985271245241, -0.03422308340668678, -0.044231537729501724, -0.0389455184340477, -0.021785393357276917, -0.010727508924901485, 0.0405779667198658, 0.07369332015514374, -0.010572037659585476, -0.052860185503959656, 0.029714420437812805, 0.02866499125957489, 0.025536134839057922, -0.027246316894888878, 0.03587496653199196, 0.00007329462096095085, 0.035991568118333817, -0.0012595591833814979, 0.013720327988266945, -0.015012681484222412, -0.056436024606227875, 0.05550319701433182, 0.049595292657613754, -0.02100803703069687, -0.009240815415978432, 0.014857210218906403, -0.04007268697023392, -0.025788774713873863, -0.01634390279650688, 0.01778201200067997, -0.018782855942845345, -0.006330590229481459, -0.0055289422161877155, 0.016538241878151894, 0.058534882962703705, 0.007841575890779495, -0.00303411646746099, -0.023320671170949936, -0.04403720051050186, -0.030180834233760834, -0.03045290894806385, 0.005698988679796457, -0.037837788462638855, 0.08006763458251953, 0.08379894495010376, -0.017509937286376953, 0.008643223904073238, -0.019346440210938454, -0.018821723759174347, 0.01514871884137392, 0.0014842635719105601, -0.009337984956800938, 0.00955661665648222, -0.007822141982614994, 0.03948966786265373, -0.03327082470059395, 0.05418169125914574, 0.027304617688059807, -0.03822646662592888, 0.03948966786265373, 0.010562320239841938, 0.07085596770048141, 0.04011155292391777, -0.06378203630447388, -0.023592745885252953, -0.04664134234189987, -0.037526845932006836, -0.03999495133757591, 0.021396715193986893, 0.001006311271339655, -0.009512890130281448, -0.01346768718212843, -0.03552515432238579, -0.0019020922482013702, 0.03801269456744194, -0.000060351343563525006, -0.034825533628463745, 0.011145337484776974, -0.0398394800722599, 0.043920595198869705, -0.05647489055991173, -0.02584707736968994, -0.07101143896579742, 0.07303256541490555, 0.025069721043109894, -0.004134560469537973, 0.0026940233074128628, -0.009036759845912457, -0.03406761214137077, -0.036710623651742935, 0.030841587111353874, -0.0033159079030156136, 0.00043513698619790375, 0.05678583309054375, 0.02677990309894085, 0.009046477265655994, -0.05701903998851776, 0.05006170645356178, 0.031035926192998886, 0.06852390617132187, 0.004824463743716478, -0.01453655119985342, 0.036147039383649826, 0.026449527591466904, -0.06720239669084549, -0.011019016616046429, 0.015867773443460464, -0.013885515742003918, -0.055619798600673676, -0.022621050477027893, 0.012369672767817974, 0.025944245979189873, -0.02677990309894085, 0.02345670759677887, 0.0032697522547096014, 0.006724126636981964, 0.04395946487784386, -0.0005186420166864991, -0.021124640479683876, -0.025225192308425903, 0.05254924297332764, -0.08309932053089142, -0.0038770614191889763, 0.040500231087207794, -0.05635828897356987, 0.024739345535635948, -0.019900305196642876, 0.06626956909894943, 0.01792776584625244, 0.026196885854005814, 0.004856043960899115, -0.02790706977248192, 0.06560882180929184, 0.03202705457806587, -0.02458387427031994, -0.05663036182522774, 0.046835679560899734, 0.06506466865539551, 0.010406848974525928, 0.04256022348999977, -0.07548123598098755, 0.007724971976131201, 0.02876215986907482, 0.005893327761441469, -0.02850951999425888, 0.011135620065033436, 0.014031270518898964, 0.031307999044656754, 0.05973978340625763, 0.01545966137200594, 0.002900508465245366, 0.006850447040051222, 0.011621467769145966, 0.001647022319957614, -0.0681740939617157, -0.04201607406139374, 0.02044445462524891, 0.005835026036947966, -0.0005210712552070618, 0.016645127907395363, -0.0446590855717659, 0.005713564343750477, 0.0148183424025774, -0.04982849955558777, 0.03488383814692497, 0.02217407152056694, 0.05212169885635376, -0.02712971344590187, 0.012359955348074436, -0.005893327761441469, -0.06413184106349945, -0.047807373106479645, -0.02917027287185192, -0.024447835981845856, 0.003320766380056739, 0.025050286203622818, -0.002266477793455124, 0.01182552333921194, -0.01942417584359646, 0.00988699309527874, -0.02662443183362484, 0.02314576506614685, -0.013564856722950935, 0.030083665624260902, 0.02917027287185192, 0.02227124013006687, -0.02161048725247383, 0.0029685271438211203, 0.03478666767477989, -0.04827378690242767, -0.09328268468379974, -0.06059487536549568, 0.08325479179620743, -0.009085345081984997, 0.006728985346853733, -0.03729363903403282, -0.02217407152056694, -0.027265751734375954, 0.06374316662549973, -0.009153363294899464, -0.029306309297680855, 0.0398394800722599, -0.008837562054395676, 0.00925053283572197, -0.028859330341219902, -0.03245459869503975, 0.0086140725761652, 0.0010421425104141235, 0.018510783091187477, -0.03511704504489899, -0.04543644189834595, 0.030005929991602898, -0.029772723093628883, 0.0011903259437531233, 0.01374947838485241, -0.031754981726408005, 0.040033817291259766, 0.013963251374661922, -0.05907903239130974, -0.004413922782987356, -0.015284756198525429, -0.00953232403844595, 0.02116350829601288, 0.061799775809049606, -0.050256043672561646, 0.047030020505189896, 0.030627815052866936, 0.02584707736968994, -0.07330463826656342, 0.07719141989946365, -0.032726675271987915, 0.09639210253953934, -0.014808625914156437, 0.0738099217414856, -0.047846242785453796, 0.0034495159052312374, 0.04073343798518181, 0.04559190943837166, 0.027868201956152916, -0.021707657724618912, -0.02345670759677887, -0.014653154648840427, -0.05814620479941368, 0.0059370542876422405, -0.00008912261546356604, 0.03148290514945984, -0.012301653623580933, 0.026099717244505882, -0.006495778448879719, 0.005057670641690493, 0.027673862874507904, -0.04236588627099991, -0.05748545378446579, -0.01292353868484497, -0.043143242597579956, -0.02100803703069687, -0.03748797997832298, -0.03653571754693985, -0.06584202498197556, -0.03224082663655281, -0.027829334139823914, -0.06094468757510185, 0.10152265429496765, -0.0038892077282071114, 0.032629504799842834, 0.031210830435156822, -0.014342212118208408, -0.08022310584783554, 0.006626957096159458, 0.042637959122657776, 0.043104372918605804, -0.006865022238343954, -0.003619562368839979, -0.0251474566757679, 0.005193707533180714, -0.03220196068286896, 0.03484496846795082, 0.012884670868515968, -0.023029161617159843, -0.04372625797986984, -0.008361431770026684, -0.04123871773481369, -0.006461769342422485, 0.01797635108232498, 0.02969498746097088, 0.012117031961679459, -0.03484496846795082, 0.0164507906883955, 0.00665610795840621, 0.07019522041082382, -0.012165616266429424, 0.010591471567749977, -0.037740617990493774, 0.062266189604997635, 0.04769077152013779, -0.003413077211007476, -0.07287709414958954, 0.016392488032579422, 0.0536375418305397, 0.015449943952262402, -0.02571103908121586, 0.025633303448557854, -0.005698988679796457, -0.04267682880163193, 0.008269120939075947, 0.031191397458314896, -0.016781166195869446, -0.0025847076904028654, -0.03091932274401188, -0.02141615003347397, -0.025205757468938828, 0.0017733427230268717, 0.007326577324420214, 0.0036705764941871166, -0.037274204194545746, -0.035136476159095764, 0.0073994542472064495, -0.006758136209100485, 0.03224082663655281, -0.038964953273534775, 0.0764140635728836, -0.06832956522703171, 0.02922857366502285, -0.030530644580721855, 0.029248008504509926, 0.03183271363377571, 0.025672171264886856, 0.03509761020541191, 0.022465579211711884, 0.037896089255809784, 0.022446146234869957, 0.026177452877163887, 0.030841587111353874, -0.01987115480005741, 0.08970684558153152, 0.07435407489538193, -0.00544148962944746, 0.000042245941585861146, -0.003153149038553238, 0.04741869866847992, 0.021746525540947914, -0.022057468071579933, 0.02380651794373989, 0.006082808133214712, -0.0438428595662117, 0.03398987650871277, -0.0389455184340477, 0.0074480390176177025, -0.04737982898950577, 0.02186312898993492, 0.06797975301742554, 0.01834559440612793, 0.02646896056830883, 0.050605855882167816, 0.0031312857754528522, -0.010941280983388424, -0.04061683639883995, 0.02232954278588295, -0.004931350238621235, 0.008390583097934723, 0.018160972744226456, 0.009114495478570461, -0.002917513018473983, -0.0462915301322937, 0.01364259235560894, 0.019356155768036842, -0.013331649824976921, -0.01824842393398285, -0.050605855882167816, -0.008463460020720959, -0.06055600941181183, -0.025108588859438896, 0.05542546138167381, 0.012010145001113415, 0.000449105107691139, 0.016363337635993958, -0.0074528977274894714, -0.003529680659994483, 0.044076066464185715, -0.02197973243892193, 0.05748545378446579, 0.0052228583954274654, 0.046019457280635834, 0.024875381961464882, -0.04123871773481369, 0.06638617813587189, 0.007389737293124199, 0.03381497412919998, 0.0063597410917282104, -0.024661609902977943, -0.01783059537410736, 0.044425878673791885, 0.028606688603758812, -0.0026697309222072363, -0.04170513153076172, 0.07186653465032578, 0.03025856986641884, -0.050566986203193665, -0.025069721043109894, 0.01584833860397339, -0.021241243928670883, -0.0551922544836998, 0.06910692155361176, 0.009721804410219193, -0.047651905566453934, 0.04594172164797783, 0.027926502749323845, 0.025944245979189873, 0.04854586347937584, -0.041782867163419724, -0.002404944272711873, -0.014624004252254963, 0.017198994755744934, -0.04388172924518585, -0.058884695172309875, -0.06852390617132187, 0.0422104150056839, 0.05678583309054375, 0.002992819296196103, 0.03659401834011078, -0.029364611953496933, 0.06405410915613174, -0.0828661173582077, 0.01213646586984396, -0.04318210855126381, -0.013020708225667477, -0.027965370565652847, -0.0009692653547972441, 0.05083906278014183, -0.024894816800951958, -0.023592745885252953, 0.0393536314368248, -0.05515338480472565, -0.00710308738052845, -0.005208283197134733, 0.016178715974092484, 0.002471748273819685, 0.07206087559461594, -0.034164782613515854, -0.009410861879587173, -0.02775159850716591, -0.026196885854005814, -0.027013109996914864, -0.0520050972700119, -0.07901820540428162, 0.020502755418419838, -0.022815389558672905, 0.030899887904524803, -0.03593326732516289, 0.006942757871001959, -0.03877061605453491, 0.021182943135499954, 0.023184632882475853, -0.02615801803767681, 0.024972552433609962, 0.016013527289032936, 0.010241661220788956, -0.11986824870109558, 0.02703254483640194, 0.05080019310116768, -0.03187158331274986, 0.028528952971100807, -0.011942126788198948, -0.04788510873913765, 0.05923450365662575, 0.03439798951148987, 0.0010269597405567765, -0.0007287709740921855, -0.025944245979189873, 0.04531983658671379, -0.010824677534401417, -0.08550912886857986, -0.0059370542876422405, 0.022348975762724876, -0.004205008503049612, -0.06350996345281601, 0.014808625914156437, 0.0021668788976967335, -0.016683995723724365, 0.040694572031497955, -0.04007268697023392, 0.06693032383918762, -0.007822141982614994, 0.00544148962944746, -0.05507564917206764, 0.03908155858516693, -0.019657382741570473, 0.014478249475359917, 0.0029393762815743685, 0.040694572031497955, -0.06284920871257782, 0.06937899440526962, -0.031191397458314896, -0.0038892077282071114, 0.04275456443428993, 0.03317365422844887, -0.016577109694480896, 0.08076725900173187, -0.013419102877378464, 0.002594424644485116, -0.01042628288269043, -0.05488131195306778, 0.05954544618725777, 0.03393157571554184, 0.01530419010668993, 0.014487966895103455, 0.048973407596349716, -0.02574990689754486, 0.026449527591466904, 0.01731559820473194, 0.0029588101897388697, 0.04706888645887375, 0.05507564917206764, 0.04582511633634567, -0.0078027076087892056, -0.00665610795840621, 0.0689125806093216, 0.002187527483329177, -0.022407278418540955, 0.04337644577026367, 0.06218845397233963, -0.015556830912828445, 0.0276349950581789, -0.07439293712377548, 0.03531138226389885, 0.004370196722447872, -0.04753530025482178, 0.023068029433488846, 0.004119985271245241, 0.010892696678638458, 0.0337178036570549, -0.0004078080819454044, 0.02693537436425686, 0.0184913482517004, 0.014487966895103455, 0.056125082075595856, -0.018675969913601875, -0.014653154648840427, -0.016975505277514458, 0.05946771055459976, 0.00020117114763706923, -0.004574252292513847, -0.005635828711092472, 0.06992314755916595, -0.00513540580868721, -0.0021608059760183096, -0.008031056262552738, -0.00024398644745815545, -0.05095566436648369, -0.021999165415763855, -0.0024061587173491716, 0.007200256921350956, 0.05212169885635376, 0.06957333534955978, -0.009697511792182922, 0.014138156548142433, 0.009367136284708977, 0.006651249714195728, 0.08504271507263184, -0.02540009655058384, -0.08527591824531555, -0.04617492854595184, -0.01691720262169838, -0.0154305100440979, -0.030569512397050858, 0.015663716942071915, -0.012797217816114426, 0.0013931671855971217, -0.006330590229481459, -0.02979215607047081, 0.0405779667198658, -0.00573785649612546, 0.026332924142479897, -0.028392916545271873, -0.007924169301986694, -0.026352357119321823, -0.045242100954055786, 0.023223500698804855, -0.05099453404545784, -0.0178403127938509, 0.021241243928670883, 0.06304354965686798, 0.0519273616373539, 0.02534179575741291, -0.0020964310970157385, -0.05227717012166977, 0.004153994377702475, -0.047962844371795654, 0.010523452423512936, 0.010737225413322449, -0.053326599299907684, 0.014332495629787445, 0.037896089255809784, 0.011291091330349445, -0.05585300549864769, -0.01961851492524147, 0.01727673038840294, 0.03152177482843399, -0.0031288566533476114, -0.09312721341848373, -0.009852983057498932, 0.006957333534955978, -0.006160543765872717, 0.031230265274643898, -0.01484749373048544, -0.006277147214859724, -0.08714157342910767, -0.015080700628459454, -0.05099453404545784, 0.019958607852458954, 0.013535706326365471, 0.02596368081867695, -0.024700477719306946, -0.029617251828312874, -0.007613227237015963, -0.00986270047724247, 0.016120413318276405, -0.029967062175273895, -0.03593326732516289, 0.015245888382196426, -0.03972287476062775, 0.01997804082930088, -0.012641746550798416, 0.0028640697710216045, 0.038498539477586746, -0.0024328804574906826, 0.019375590607523918, -0.060478273779153824, 0.03297931328415871, -0.02176595851778984, -0.04901227727532387, 0.044581349939107895, 0.05379301309585571, -0.022504447028040886, -0.015916356816887856, 0.06930126249790192, -0.010513735935091972, -0.015236171893775463, -0.011942126788198948, -0.03488383814692497, 0.04403720051050186, -0.021280111744999886, -0.033387426286935806, -0.03593326732516289, -0.00440663518384099, -0.003928075544536114, -0.02248501405119896, 0.009522607550024986, 0.0007785703055560589, -0.005752432160079479, -0.01530419010668993, -0.030491776764392853, 0.0067678531631827354, 0.020366718992590904, 0.07276049256324768, -0.018792573362588882, -0.0341259129345417, 0.012155899778008461, 0.012583444826304913, 0.032532334327697754, 0.053987354040145874, 0.06926239281892776, -0.0438428595662117, -0.03744911029934883, -0.013040142133831978, 0.017616823315620422, -0.06214958801865578, -0.01788889802992344, 0.007686104159802198, -0.0640929788351059, -0.011485430411994457, 0.008497469127178192, 0.016285602003335953, -0.032823845744132996, -0.06055600941181183, 0.02687707357108593, -0.004073829855769873, -0.07579217851161957, -0.06778541952371597, 0.042948901653289795, 0.04609719291329384, 0.024953117594122887, -0.013088726438581944, -0.011572882533073425, 0.053676411509513855, -0.051888491958379745, -0.08403214812278748, 0.034922704100608826, 0.014215892180800438, 0.01991974003612995, -0.03459232673048973, 0.04042249545454979, 0.008784119039773941, -0.0381292961537838, -0.05142207816243172, -0.0024802505504339933, -0.01991974003612995, 0.0308221522718668, -0.03603043779730797, 0.020425021648406982, 0.053326599299907684, 0.00805049017071724, -0.03014196641743183, -0.011145337484776974, -0.03142460435628891, -0.08037857711315155, 0.03867344558238983, 0.02295142598450184, 0.009828691370785236, -0.03622477501630783, -0.03025856986641884, -0.01392438355833292, 0.02681877091526985, 0.01152429822832346, -0.014944663271307945, 0.020716529339551926, -0.013098442927002907, -0.01246684230864048, -0.0026551554910838604, 0.014468532986938953, -0.023631613701581955, -0.0032187383621931076, 0.028626123443245888, -0.08846307545900345, -0.0008107576868496835, 0.023417839780449867, -0.08348800241947174, 0.002039344049990177, -0.01792776584625244, -0.02631348930299282, 0.08815213292837143, 0.0098578417673707, 0.03198818489909172, 0.004814746789634228, -0.014604570344090462, 0.025283493101596832, -0.014983531087636948, -0.00986270047724247, 0.05993412435054779, -0.026546696200966835, 0.018316444009542465, -0.03995608165860176, -0.017665408551692963, -0.00125227146781981, -0.010999582707881927, 0.01019307691603899, 0.01257372833788395, -0.027576692402362823, -0.010970432311296463, 0.03107479400932789, -0.000737880589440465, 0.02411746047437191, -0.01840389519929886, 0.011689485982060432, -0.011815806850790977, -0.04011155292391777, -0.0519273616373539, -0.02606084942817688, -0.048118315637111664, -0.06125563010573387, -0.008720959536731243, -0.018792573362588882, 0.022776521742343903, 0.02207690104842186, 0.04664134234189987, 0.02571103908121586, 0.08496497571468353 ]
30,925
networkx.algorithms.shortest_paths.weighted
multi_source_dijkstra_path
Find shortest weighted paths in G from a given set of source nodes. Compute shortest path between any of the source nodes and all other reachable nodes for a weighted graph. Parameters ---------- G : NetworkX graph sources : non-empty set of nodes Starting nodes for paths. If this is just a set containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in the set, the computed paths may begin from any one of the start nodes. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number or None to indicate a hidden edge. Returns ------- paths : dictionary Dictionary of shortest paths keyed by target. Examples -------- >>> G = nx.path_graph(5) >>> path = nx.multi_source_dijkstra_path(G, {0, 4}) >>> path[1] [0, 1] >>> path[3] [4, 3] Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. The weight function can be used to hide edges by returning None. So ``weight = lambda u, v, d: 1 if d['color']=="red" else None`` will find the shortest red path. Raises ------ ValueError If `sources` is empty. NodeNotFound If any of `sources` is not in `G`. See Also -------- multi_source_dijkstra, multi_source_bellman_ford
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, sources, cutoff=None, weight='weight', *, backend=None, **backend_kwargs)
[ 0.008667515590786934, -0.004119985271245241, -0.03422308340668678, -0.044231537729501724, -0.0389455184340477, -0.021785393357276917, -0.010727508924901485, 0.0405779667198658, 0.07369332015514374, -0.010572037659585476, -0.052860185503959656, 0.029714420437812805, 0.02866499125957489, 0.025536134839057922, -0.027246316894888878, 0.03587496653199196, 0.00007329462096095085, 0.035991568118333817, -0.0012595591833814979, 0.013720327988266945, -0.015012681484222412, -0.056436024606227875, 0.05550319701433182, 0.049595292657613754, -0.02100803703069687, -0.009240815415978432, 0.014857210218906403, -0.04007268697023392, -0.025788774713873863, -0.01634390279650688, 0.01778201200067997, -0.018782855942845345, -0.006330590229481459, -0.0055289422161877155, 0.016538241878151894, 0.058534882962703705, 0.007841575890779495, -0.00303411646746099, -0.023320671170949936, -0.04403720051050186, -0.030180834233760834, -0.03045290894806385, 0.005698988679796457, -0.037837788462638855, 0.08006763458251953, 0.08379894495010376, -0.017509937286376953, 0.008643223904073238, -0.019346440210938454, -0.018821723759174347, 0.01514871884137392, 0.0014842635719105601, -0.009337984956800938, 0.00955661665648222, -0.007822141982614994, 0.03948966786265373, -0.03327082470059395, 0.05418169125914574, 0.027304617688059807, -0.03822646662592888, 0.03948966786265373, 0.010562320239841938, 0.07085596770048141, 0.04011155292391777, -0.06378203630447388, -0.023592745885252953, -0.04664134234189987, -0.037526845932006836, -0.03999495133757591, 0.021396715193986893, 0.001006311271339655, -0.009512890130281448, -0.01346768718212843, -0.03552515432238579, -0.0019020922482013702, 0.03801269456744194, -0.000060351343563525006, -0.034825533628463745, 0.011145337484776974, -0.0398394800722599, 0.043920595198869705, -0.05647489055991173, -0.02584707736968994, -0.07101143896579742, 0.07303256541490555, 0.025069721043109894, -0.004134560469537973, 0.0026940233074128628, -0.009036759845912457, -0.03406761214137077, -0.036710623651742935, 0.030841587111353874, -0.0033159079030156136, 0.00043513698619790375, 0.05678583309054375, 0.02677990309894085, 0.009046477265655994, -0.05701903998851776, 0.05006170645356178, 0.031035926192998886, 0.06852390617132187, 0.004824463743716478, -0.01453655119985342, 0.036147039383649826, 0.026449527591466904, -0.06720239669084549, -0.011019016616046429, 0.015867773443460464, -0.013885515742003918, -0.055619798600673676, -0.022621050477027893, 0.012369672767817974, 0.025944245979189873, -0.02677990309894085, 0.02345670759677887, 0.0032697522547096014, 0.006724126636981964, 0.04395946487784386, -0.0005186420166864991, -0.021124640479683876, -0.025225192308425903, 0.05254924297332764, -0.08309932053089142, -0.0038770614191889763, 0.040500231087207794, -0.05635828897356987, 0.024739345535635948, -0.019900305196642876, 0.06626956909894943, 0.01792776584625244, 0.026196885854005814, 0.004856043960899115, -0.02790706977248192, 0.06560882180929184, 0.03202705457806587, -0.02458387427031994, -0.05663036182522774, 0.046835679560899734, 0.06506466865539551, 0.010406848974525928, 0.04256022348999977, -0.07548123598098755, 0.007724971976131201, 0.02876215986907482, 0.005893327761441469, -0.02850951999425888, 0.011135620065033436, 0.014031270518898964, 0.031307999044656754, 0.05973978340625763, 0.01545966137200594, 0.002900508465245366, 0.006850447040051222, 0.011621467769145966, 0.001647022319957614, -0.0681740939617157, -0.04201607406139374, 0.02044445462524891, 0.005835026036947966, -0.0005210712552070618, 0.016645127907395363, -0.0446590855717659, 0.005713564343750477, 0.0148183424025774, -0.04982849955558777, 0.03488383814692497, 0.02217407152056694, 0.05212169885635376, -0.02712971344590187, 0.012359955348074436, -0.005893327761441469, -0.06413184106349945, -0.047807373106479645, -0.02917027287185192, -0.024447835981845856, 0.003320766380056739, 0.025050286203622818, -0.002266477793455124, 0.01182552333921194, -0.01942417584359646, 0.00988699309527874, -0.02662443183362484, 0.02314576506614685, -0.013564856722950935, 0.030083665624260902, 0.02917027287185192, 0.02227124013006687, -0.02161048725247383, 0.0029685271438211203, 0.03478666767477989, -0.04827378690242767, -0.09328268468379974, -0.06059487536549568, 0.08325479179620743, -0.009085345081984997, 0.006728985346853733, -0.03729363903403282, -0.02217407152056694, -0.027265751734375954, 0.06374316662549973, -0.009153363294899464, -0.029306309297680855, 0.0398394800722599, -0.008837562054395676, 0.00925053283572197, -0.028859330341219902, -0.03245459869503975, 0.0086140725761652, 0.0010421425104141235, 0.018510783091187477, -0.03511704504489899, -0.04543644189834595, 0.030005929991602898, -0.029772723093628883, 0.0011903259437531233, 0.01374947838485241, -0.031754981726408005, 0.040033817291259766, 0.013963251374661922, -0.05907903239130974, -0.004413922782987356, -0.015284756198525429, -0.00953232403844595, 0.02116350829601288, 0.061799775809049606, -0.050256043672561646, 0.047030020505189896, 0.030627815052866936, 0.02584707736968994, -0.07330463826656342, 0.07719141989946365, -0.032726675271987915, 0.09639210253953934, -0.014808625914156437, 0.0738099217414856, -0.047846242785453796, 0.0034495159052312374, 0.04073343798518181, 0.04559190943837166, 0.027868201956152916, -0.021707657724618912, -0.02345670759677887, -0.014653154648840427, -0.05814620479941368, 0.0059370542876422405, -0.00008912261546356604, 0.03148290514945984, -0.012301653623580933, 0.026099717244505882, -0.006495778448879719, 0.005057670641690493, 0.027673862874507904, -0.04236588627099991, -0.05748545378446579, -0.01292353868484497, -0.043143242597579956, -0.02100803703069687, -0.03748797997832298, -0.03653571754693985, -0.06584202498197556, -0.03224082663655281, -0.027829334139823914, -0.06094468757510185, 0.10152265429496765, -0.0038892077282071114, 0.032629504799842834, 0.031210830435156822, -0.014342212118208408, -0.08022310584783554, 0.006626957096159458, 0.042637959122657776, 0.043104372918605804, -0.006865022238343954, -0.003619562368839979, -0.0251474566757679, 0.005193707533180714, -0.03220196068286896, 0.03484496846795082, 0.012884670868515968, -0.023029161617159843, -0.04372625797986984, -0.008361431770026684, -0.04123871773481369, -0.006461769342422485, 0.01797635108232498, 0.02969498746097088, 0.012117031961679459, -0.03484496846795082, 0.0164507906883955, 0.00665610795840621, 0.07019522041082382, -0.012165616266429424, 0.010591471567749977, -0.037740617990493774, 0.062266189604997635, 0.04769077152013779, -0.003413077211007476, -0.07287709414958954, 0.016392488032579422, 0.0536375418305397, 0.015449943952262402, -0.02571103908121586, 0.025633303448557854, -0.005698988679796457, -0.04267682880163193, 0.008269120939075947, 0.031191397458314896, -0.016781166195869446, -0.0025847076904028654, -0.03091932274401188, -0.02141615003347397, -0.025205757468938828, 0.0017733427230268717, 0.007326577324420214, 0.0036705764941871166, -0.037274204194545746, -0.035136476159095764, 0.0073994542472064495, -0.006758136209100485, 0.03224082663655281, -0.038964953273534775, 0.0764140635728836, -0.06832956522703171, 0.02922857366502285, -0.030530644580721855, 0.029248008504509926, 0.03183271363377571, 0.025672171264886856, 0.03509761020541191, 0.022465579211711884, 0.037896089255809784, 0.022446146234869957, 0.026177452877163887, 0.030841587111353874, -0.01987115480005741, 0.08970684558153152, 0.07435407489538193, -0.00544148962944746, 0.000042245941585861146, -0.003153149038553238, 0.04741869866847992, 0.021746525540947914, -0.022057468071579933, 0.02380651794373989, 0.006082808133214712, -0.0438428595662117, 0.03398987650871277, -0.0389455184340477, 0.0074480390176177025, -0.04737982898950577, 0.02186312898993492, 0.06797975301742554, 0.01834559440612793, 0.02646896056830883, 0.050605855882167816, 0.0031312857754528522, -0.010941280983388424, -0.04061683639883995, 0.02232954278588295, -0.004931350238621235, 0.008390583097934723, 0.018160972744226456, 0.009114495478570461, -0.002917513018473983, -0.0462915301322937, 0.01364259235560894, 0.019356155768036842, -0.013331649824976921, -0.01824842393398285, -0.050605855882167816, -0.008463460020720959, -0.06055600941181183, -0.025108588859438896, 0.05542546138167381, 0.012010145001113415, 0.000449105107691139, 0.016363337635993958, -0.0074528977274894714, -0.003529680659994483, 0.044076066464185715, -0.02197973243892193, 0.05748545378446579, 0.0052228583954274654, 0.046019457280635834, 0.024875381961464882, -0.04123871773481369, 0.06638617813587189, 0.007389737293124199, 0.03381497412919998, 0.0063597410917282104, -0.024661609902977943, -0.01783059537410736, 0.044425878673791885, 0.028606688603758812, -0.0026697309222072363, -0.04170513153076172, 0.07186653465032578, 0.03025856986641884, -0.050566986203193665, -0.025069721043109894, 0.01584833860397339, -0.021241243928670883, -0.0551922544836998, 0.06910692155361176, 0.009721804410219193, -0.047651905566453934, 0.04594172164797783, 0.027926502749323845, 0.025944245979189873, 0.04854586347937584, -0.041782867163419724, -0.002404944272711873, -0.014624004252254963, 0.017198994755744934, -0.04388172924518585, -0.058884695172309875, -0.06852390617132187, 0.0422104150056839, 0.05678583309054375, 0.002992819296196103, 0.03659401834011078, -0.029364611953496933, 0.06405410915613174, -0.0828661173582077, 0.01213646586984396, -0.04318210855126381, -0.013020708225667477, -0.027965370565652847, -0.0009692653547972441, 0.05083906278014183, -0.024894816800951958, -0.023592745885252953, 0.0393536314368248, -0.05515338480472565, -0.00710308738052845, -0.005208283197134733, 0.016178715974092484, 0.002471748273819685, 0.07206087559461594, -0.034164782613515854, -0.009410861879587173, -0.02775159850716591, -0.026196885854005814, -0.027013109996914864, -0.0520050972700119, -0.07901820540428162, 0.020502755418419838, -0.022815389558672905, 0.030899887904524803, -0.03593326732516289, 0.006942757871001959, -0.03877061605453491, 0.021182943135499954, 0.023184632882475853, -0.02615801803767681, 0.024972552433609962, 0.016013527289032936, 0.010241661220788956, -0.11986824870109558, 0.02703254483640194, 0.05080019310116768, -0.03187158331274986, 0.028528952971100807, -0.011942126788198948, -0.04788510873913765, 0.05923450365662575, 0.03439798951148987, 0.0010269597405567765, -0.0007287709740921855, -0.025944245979189873, 0.04531983658671379, -0.010824677534401417, -0.08550912886857986, -0.0059370542876422405, 0.022348975762724876, -0.004205008503049612, -0.06350996345281601, 0.014808625914156437, 0.0021668788976967335, -0.016683995723724365, 0.040694572031497955, -0.04007268697023392, 0.06693032383918762, -0.007822141982614994, 0.00544148962944746, -0.05507564917206764, 0.03908155858516693, -0.019657382741570473, 0.014478249475359917, 0.0029393762815743685, 0.040694572031497955, -0.06284920871257782, 0.06937899440526962, -0.031191397458314896, -0.0038892077282071114, 0.04275456443428993, 0.03317365422844887, -0.016577109694480896, 0.08076725900173187, -0.013419102877378464, 0.002594424644485116, -0.01042628288269043, -0.05488131195306778, 0.05954544618725777, 0.03393157571554184, 0.01530419010668993, 0.014487966895103455, 0.048973407596349716, -0.02574990689754486, 0.026449527591466904, 0.01731559820473194, 0.0029588101897388697, 0.04706888645887375, 0.05507564917206764, 0.04582511633634567, -0.0078027076087892056, -0.00665610795840621, 0.0689125806093216, 0.002187527483329177, -0.022407278418540955, 0.04337644577026367, 0.06218845397233963, -0.015556830912828445, 0.0276349950581789, -0.07439293712377548, 0.03531138226389885, 0.004370196722447872, -0.04753530025482178, 0.023068029433488846, 0.004119985271245241, 0.010892696678638458, 0.0337178036570549, -0.0004078080819454044, 0.02693537436425686, 0.0184913482517004, 0.014487966895103455, 0.056125082075595856, -0.018675969913601875, -0.014653154648840427, -0.016975505277514458, 0.05946771055459976, 0.00020117114763706923, -0.004574252292513847, -0.005635828711092472, 0.06992314755916595, -0.00513540580868721, -0.0021608059760183096, -0.008031056262552738, -0.00024398644745815545, -0.05095566436648369, -0.021999165415763855, -0.0024061587173491716, 0.007200256921350956, 0.05212169885635376, 0.06957333534955978, -0.009697511792182922, 0.014138156548142433, 0.009367136284708977, 0.006651249714195728, 0.08504271507263184, -0.02540009655058384, -0.08527591824531555, -0.04617492854595184, -0.01691720262169838, -0.0154305100440979, -0.030569512397050858, 0.015663716942071915, -0.012797217816114426, 0.0013931671855971217, -0.006330590229481459, -0.02979215607047081, 0.0405779667198658, -0.00573785649612546, 0.026332924142479897, -0.028392916545271873, -0.007924169301986694, -0.026352357119321823, -0.045242100954055786, 0.023223500698804855, -0.05099453404545784, -0.0178403127938509, 0.021241243928670883, 0.06304354965686798, 0.0519273616373539, 0.02534179575741291, -0.0020964310970157385, -0.05227717012166977, 0.004153994377702475, -0.047962844371795654, 0.010523452423512936, 0.010737225413322449, -0.053326599299907684, 0.014332495629787445, 0.037896089255809784, 0.011291091330349445, -0.05585300549864769, -0.01961851492524147, 0.01727673038840294, 0.03152177482843399, -0.0031288566533476114, -0.09312721341848373, -0.009852983057498932, 0.006957333534955978, -0.006160543765872717, 0.031230265274643898, -0.01484749373048544, -0.006277147214859724, -0.08714157342910767, -0.015080700628459454, -0.05099453404545784, 0.019958607852458954, 0.013535706326365471, 0.02596368081867695, -0.024700477719306946, -0.029617251828312874, -0.007613227237015963, -0.00986270047724247, 0.016120413318276405, -0.029967062175273895, -0.03593326732516289, 0.015245888382196426, -0.03972287476062775, 0.01997804082930088, -0.012641746550798416, 0.0028640697710216045, 0.038498539477586746, -0.0024328804574906826, 0.019375590607523918, -0.060478273779153824, 0.03297931328415871, -0.02176595851778984, -0.04901227727532387, 0.044581349939107895, 0.05379301309585571, -0.022504447028040886, -0.015916356816887856, 0.06930126249790192, -0.010513735935091972, -0.015236171893775463, -0.011942126788198948, -0.03488383814692497, 0.04403720051050186, -0.021280111744999886, -0.033387426286935806, -0.03593326732516289, -0.00440663518384099, -0.003928075544536114, -0.02248501405119896, 0.009522607550024986, 0.0007785703055560589, -0.005752432160079479, -0.01530419010668993, -0.030491776764392853, 0.0067678531631827354, 0.020366718992590904, 0.07276049256324768, -0.018792573362588882, -0.0341259129345417, 0.012155899778008461, 0.012583444826304913, 0.032532334327697754, 0.053987354040145874, 0.06926239281892776, -0.0438428595662117, -0.03744911029934883, -0.013040142133831978, 0.017616823315620422, -0.06214958801865578, -0.01788889802992344, 0.007686104159802198, -0.0640929788351059, -0.011485430411994457, 0.008497469127178192, 0.016285602003335953, -0.032823845744132996, -0.06055600941181183, 0.02687707357108593, -0.004073829855769873, -0.07579217851161957, -0.06778541952371597, 0.042948901653289795, 0.04609719291329384, 0.024953117594122887, -0.013088726438581944, -0.011572882533073425, 0.053676411509513855, -0.051888491958379745, -0.08403214812278748, 0.034922704100608826, 0.014215892180800438, 0.01991974003612995, -0.03459232673048973, 0.04042249545454979, 0.008784119039773941, -0.0381292961537838, -0.05142207816243172, -0.0024802505504339933, -0.01991974003612995, 0.0308221522718668, -0.03603043779730797, 0.020425021648406982, 0.053326599299907684, 0.00805049017071724, -0.03014196641743183, -0.011145337484776974, -0.03142460435628891, -0.08037857711315155, 0.03867344558238983, 0.02295142598450184, 0.009828691370785236, -0.03622477501630783, -0.03025856986641884, -0.01392438355833292, 0.02681877091526985, 0.01152429822832346, -0.014944663271307945, 0.020716529339551926, -0.013098442927002907, -0.01246684230864048, -0.0026551554910838604, 0.014468532986938953, -0.023631613701581955, -0.0032187383621931076, 0.028626123443245888, -0.08846307545900345, -0.0008107576868496835, 0.023417839780449867, -0.08348800241947174, 0.002039344049990177, -0.01792776584625244, -0.02631348930299282, 0.08815213292837143, 0.0098578417673707, 0.03198818489909172, 0.004814746789634228, -0.014604570344090462, 0.025283493101596832, -0.014983531087636948, -0.00986270047724247, 0.05993412435054779, -0.026546696200966835, 0.018316444009542465, -0.03995608165860176, -0.017665408551692963, -0.00125227146781981, -0.010999582707881927, 0.01019307691603899, 0.01257372833788395, -0.027576692402362823, -0.010970432311296463, 0.03107479400932789, -0.000737880589440465, 0.02411746047437191, -0.01840389519929886, 0.011689485982060432, -0.011815806850790977, -0.04011155292391777, -0.0519273616373539, -0.02606084942817688, -0.048118315637111664, -0.06125563010573387, -0.008720959536731243, -0.018792573362588882, 0.022776521742343903, 0.02207690104842186, 0.04664134234189987, 0.02571103908121586, 0.08496497571468353 ]
30,926
networkx.algorithms.shortest_paths.weighted
multi_source_dijkstra_path_length
Find shortest weighted path lengths in G from a given set of source nodes. Compute the shortest path length between any of the source nodes and all other reachable nodes for a weighted graph. Parameters ---------- G : NetworkX graph sources : non-empty set of nodes Starting nodes for paths. If this is just a set containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in the set, the computed paths may begin from any one of the start nodes. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number or None to indicate a hidden edge. Returns ------- length : dict Dict keyed by node to shortest path length to nearest source. Examples -------- >>> G = nx.path_graph(5) >>> length = nx.multi_source_dijkstra_path_length(G, {0, 4}) >>> for node in [0, 1, 2, 3, 4]: ... print(f"{node}: {length[node]}") 0: 0 1: 1 2: 2 3: 1 4: 0 Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. The weight function can be used to hide edges by returning None. So ``weight = lambda u, v, d: 1 if d['color']=="red" else None`` will find the shortest red path. Raises ------ ValueError If `sources` is empty. NodeNotFound If any of `sources` is not in `G`. See Also -------- multi_source_dijkstra
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, sources, cutoff=None, weight='weight', *, backend=None, **backend_kwargs)
[ 0.008667515590786934, -0.004119985271245241, -0.03422308340668678, -0.044231537729501724, -0.0389455184340477, -0.021785393357276917, -0.010727508924901485, 0.0405779667198658, 0.07369332015514374, -0.010572037659585476, -0.052860185503959656, 0.029714420437812805, 0.02866499125957489, 0.025536134839057922, -0.027246316894888878, 0.03587496653199196, 0.00007329462096095085, 0.035991568118333817, -0.0012595591833814979, 0.013720327988266945, -0.015012681484222412, -0.056436024606227875, 0.05550319701433182, 0.049595292657613754, -0.02100803703069687, -0.009240815415978432, 0.014857210218906403, -0.04007268697023392, -0.025788774713873863, -0.01634390279650688, 0.01778201200067997, -0.018782855942845345, -0.006330590229481459, -0.0055289422161877155, 0.016538241878151894, 0.058534882962703705, 0.007841575890779495, -0.00303411646746099, -0.023320671170949936, -0.04403720051050186, -0.030180834233760834, -0.03045290894806385, 0.005698988679796457, -0.037837788462638855, 0.08006763458251953, 0.08379894495010376, -0.017509937286376953, 0.008643223904073238, -0.019346440210938454, -0.018821723759174347, 0.01514871884137392, 0.0014842635719105601, -0.009337984956800938, 0.00955661665648222, -0.007822141982614994, 0.03948966786265373, -0.03327082470059395, 0.05418169125914574, 0.027304617688059807, -0.03822646662592888, 0.03948966786265373, 0.010562320239841938, 0.07085596770048141, 0.04011155292391777, -0.06378203630447388, -0.023592745885252953, -0.04664134234189987, -0.037526845932006836, -0.03999495133757591, 0.021396715193986893, 0.001006311271339655, -0.009512890130281448, -0.01346768718212843, -0.03552515432238579, -0.0019020922482013702, 0.03801269456744194, -0.000060351343563525006, -0.034825533628463745, 0.011145337484776974, -0.0398394800722599, 0.043920595198869705, -0.05647489055991173, -0.02584707736968994, -0.07101143896579742, 0.07303256541490555, 0.025069721043109894, -0.004134560469537973, 0.0026940233074128628, -0.009036759845912457, -0.03406761214137077, -0.036710623651742935, 0.030841587111353874, -0.0033159079030156136, 0.00043513698619790375, 0.05678583309054375, 0.02677990309894085, 0.009046477265655994, -0.05701903998851776, 0.05006170645356178, 0.031035926192998886, 0.06852390617132187, 0.004824463743716478, -0.01453655119985342, 0.036147039383649826, 0.026449527591466904, -0.06720239669084549, -0.011019016616046429, 0.015867773443460464, -0.013885515742003918, -0.055619798600673676, -0.022621050477027893, 0.012369672767817974, 0.025944245979189873, -0.02677990309894085, 0.02345670759677887, 0.0032697522547096014, 0.006724126636981964, 0.04395946487784386, -0.0005186420166864991, -0.021124640479683876, -0.025225192308425903, 0.05254924297332764, -0.08309932053089142, -0.0038770614191889763, 0.040500231087207794, -0.05635828897356987, 0.024739345535635948, -0.019900305196642876, 0.06626956909894943, 0.01792776584625244, 0.026196885854005814, 0.004856043960899115, -0.02790706977248192, 0.06560882180929184, 0.03202705457806587, -0.02458387427031994, -0.05663036182522774, 0.046835679560899734, 0.06506466865539551, 0.010406848974525928, 0.04256022348999977, -0.07548123598098755, 0.007724971976131201, 0.02876215986907482, 0.005893327761441469, -0.02850951999425888, 0.011135620065033436, 0.014031270518898964, 0.031307999044656754, 0.05973978340625763, 0.01545966137200594, 0.002900508465245366, 0.006850447040051222, 0.011621467769145966, 0.001647022319957614, -0.0681740939617157, -0.04201607406139374, 0.02044445462524891, 0.005835026036947966, -0.0005210712552070618, 0.016645127907395363, -0.0446590855717659, 0.005713564343750477, 0.0148183424025774, -0.04982849955558777, 0.03488383814692497, 0.02217407152056694, 0.05212169885635376, -0.02712971344590187, 0.012359955348074436, -0.005893327761441469, -0.06413184106349945, -0.047807373106479645, -0.02917027287185192, -0.024447835981845856, 0.003320766380056739, 0.025050286203622818, -0.002266477793455124, 0.01182552333921194, -0.01942417584359646, 0.00988699309527874, -0.02662443183362484, 0.02314576506614685, -0.013564856722950935, 0.030083665624260902, 0.02917027287185192, 0.02227124013006687, -0.02161048725247383, 0.0029685271438211203, 0.03478666767477989, -0.04827378690242767, -0.09328268468379974, -0.06059487536549568, 0.08325479179620743, -0.009085345081984997, 0.006728985346853733, -0.03729363903403282, -0.02217407152056694, -0.027265751734375954, 0.06374316662549973, -0.009153363294899464, -0.029306309297680855, 0.0398394800722599, -0.008837562054395676, 0.00925053283572197, -0.028859330341219902, -0.03245459869503975, 0.0086140725761652, 0.0010421425104141235, 0.018510783091187477, -0.03511704504489899, -0.04543644189834595, 0.030005929991602898, -0.029772723093628883, 0.0011903259437531233, 0.01374947838485241, -0.031754981726408005, 0.040033817291259766, 0.013963251374661922, -0.05907903239130974, -0.004413922782987356, -0.015284756198525429, -0.00953232403844595, 0.02116350829601288, 0.061799775809049606, -0.050256043672561646, 0.047030020505189896, 0.030627815052866936, 0.02584707736968994, -0.07330463826656342, 0.07719141989946365, -0.032726675271987915, 0.09639210253953934, -0.014808625914156437, 0.0738099217414856, -0.047846242785453796, 0.0034495159052312374, 0.04073343798518181, 0.04559190943837166, 0.027868201956152916, -0.021707657724618912, -0.02345670759677887, -0.014653154648840427, -0.05814620479941368, 0.0059370542876422405, -0.00008912261546356604, 0.03148290514945984, -0.012301653623580933, 0.026099717244505882, -0.006495778448879719, 0.005057670641690493, 0.027673862874507904, -0.04236588627099991, -0.05748545378446579, -0.01292353868484497, -0.043143242597579956, -0.02100803703069687, -0.03748797997832298, -0.03653571754693985, -0.06584202498197556, -0.03224082663655281, -0.027829334139823914, -0.06094468757510185, 0.10152265429496765, -0.0038892077282071114, 0.032629504799842834, 0.031210830435156822, -0.014342212118208408, -0.08022310584783554, 0.006626957096159458, 0.042637959122657776, 0.043104372918605804, -0.006865022238343954, -0.003619562368839979, -0.0251474566757679, 0.005193707533180714, -0.03220196068286896, 0.03484496846795082, 0.012884670868515968, -0.023029161617159843, -0.04372625797986984, -0.008361431770026684, -0.04123871773481369, -0.006461769342422485, 0.01797635108232498, 0.02969498746097088, 0.012117031961679459, -0.03484496846795082, 0.0164507906883955, 0.00665610795840621, 0.07019522041082382, -0.012165616266429424, 0.010591471567749977, -0.037740617990493774, 0.062266189604997635, 0.04769077152013779, -0.003413077211007476, -0.07287709414958954, 0.016392488032579422, 0.0536375418305397, 0.015449943952262402, -0.02571103908121586, 0.025633303448557854, -0.005698988679796457, -0.04267682880163193, 0.008269120939075947, 0.031191397458314896, -0.016781166195869446, -0.0025847076904028654, -0.03091932274401188, -0.02141615003347397, -0.025205757468938828, 0.0017733427230268717, 0.007326577324420214, 0.0036705764941871166, -0.037274204194545746, -0.035136476159095764, 0.0073994542472064495, -0.006758136209100485, 0.03224082663655281, -0.038964953273534775, 0.0764140635728836, -0.06832956522703171, 0.02922857366502285, -0.030530644580721855, 0.029248008504509926, 0.03183271363377571, 0.025672171264886856, 0.03509761020541191, 0.022465579211711884, 0.037896089255809784, 0.022446146234869957, 0.026177452877163887, 0.030841587111353874, -0.01987115480005741, 0.08970684558153152, 0.07435407489538193, -0.00544148962944746, 0.000042245941585861146, -0.003153149038553238, 0.04741869866847992, 0.021746525540947914, -0.022057468071579933, 0.02380651794373989, 0.006082808133214712, -0.0438428595662117, 0.03398987650871277, -0.0389455184340477, 0.0074480390176177025, -0.04737982898950577, 0.02186312898993492, 0.06797975301742554, 0.01834559440612793, 0.02646896056830883, 0.050605855882167816, 0.0031312857754528522, -0.010941280983388424, -0.04061683639883995, 0.02232954278588295, -0.004931350238621235, 0.008390583097934723, 0.018160972744226456, 0.009114495478570461, -0.002917513018473983, -0.0462915301322937, 0.01364259235560894, 0.019356155768036842, -0.013331649824976921, -0.01824842393398285, -0.050605855882167816, -0.008463460020720959, -0.06055600941181183, -0.025108588859438896, 0.05542546138167381, 0.012010145001113415, 0.000449105107691139, 0.016363337635993958, -0.0074528977274894714, -0.003529680659994483, 0.044076066464185715, -0.02197973243892193, 0.05748545378446579, 0.0052228583954274654, 0.046019457280635834, 0.024875381961464882, -0.04123871773481369, 0.06638617813587189, 0.007389737293124199, 0.03381497412919998, 0.0063597410917282104, -0.024661609902977943, -0.01783059537410736, 0.044425878673791885, 0.028606688603758812, -0.0026697309222072363, -0.04170513153076172, 0.07186653465032578, 0.03025856986641884, -0.050566986203193665, -0.025069721043109894, 0.01584833860397339, -0.021241243928670883, -0.0551922544836998, 0.06910692155361176, 0.009721804410219193, -0.047651905566453934, 0.04594172164797783, 0.027926502749323845, 0.025944245979189873, 0.04854586347937584, -0.041782867163419724, -0.002404944272711873, -0.014624004252254963, 0.017198994755744934, -0.04388172924518585, -0.058884695172309875, -0.06852390617132187, 0.0422104150056839, 0.05678583309054375, 0.002992819296196103, 0.03659401834011078, -0.029364611953496933, 0.06405410915613174, -0.0828661173582077, 0.01213646586984396, -0.04318210855126381, -0.013020708225667477, -0.027965370565652847, -0.0009692653547972441, 0.05083906278014183, -0.024894816800951958, -0.023592745885252953, 0.0393536314368248, -0.05515338480472565, -0.00710308738052845, -0.005208283197134733, 0.016178715974092484, 0.002471748273819685, 0.07206087559461594, -0.034164782613515854, -0.009410861879587173, -0.02775159850716591, -0.026196885854005814, -0.027013109996914864, -0.0520050972700119, -0.07901820540428162, 0.020502755418419838, -0.022815389558672905, 0.030899887904524803, -0.03593326732516289, 0.006942757871001959, -0.03877061605453491, 0.021182943135499954, 0.023184632882475853, -0.02615801803767681, 0.024972552433609962, 0.016013527289032936, 0.010241661220788956, -0.11986824870109558, 0.02703254483640194, 0.05080019310116768, -0.03187158331274986, 0.028528952971100807, -0.011942126788198948, -0.04788510873913765, 0.05923450365662575, 0.03439798951148987, 0.0010269597405567765, -0.0007287709740921855, -0.025944245979189873, 0.04531983658671379, -0.010824677534401417, -0.08550912886857986, -0.0059370542876422405, 0.022348975762724876, -0.004205008503049612, -0.06350996345281601, 0.014808625914156437, 0.0021668788976967335, -0.016683995723724365, 0.040694572031497955, -0.04007268697023392, 0.06693032383918762, -0.007822141982614994, 0.00544148962944746, -0.05507564917206764, 0.03908155858516693, -0.019657382741570473, 0.014478249475359917, 0.0029393762815743685, 0.040694572031497955, -0.06284920871257782, 0.06937899440526962, -0.031191397458314896, -0.0038892077282071114, 0.04275456443428993, 0.03317365422844887, -0.016577109694480896, 0.08076725900173187, -0.013419102877378464, 0.002594424644485116, -0.01042628288269043, -0.05488131195306778, 0.05954544618725777, 0.03393157571554184, 0.01530419010668993, 0.014487966895103455, 0.048973407596349716, -0.02574990689754486, 0.026449527591466904, 0.01731559820473194, 0.0029588101897388697, 0.04706888645887375, 0.05507564917206764, 0.04582511633634567, -0.0078027076087892056, -0.00665610795840621, 0.0689125806093216, 0.002187527483329177, -0.022407278418540955, 0.04337644577026367, 0.06218845397233963, -0.015556830912828445, 0.0276349950581789, -0.07439293712377548, 0.03531138226389885, 0.004370196722447872, -0.04753530025482178, 0.023068029433488846, 0.004119985271245241, 0.010892696678638458, 0.0337178036570549, -0.0004078080819454044, 0.02693537436425686, 0.0184913482517004, 0.014487966895103455, 0.056125082075595856, -0.018675969913601875, -0.014653154648840427, -0.016975505277514458, 0.05946771055459976, 0.00020117114763706923, -0.004574252292513847, -0.005635828711092472, 0.06992314755916595, -0.00513540580868721, -0.0021608059760183096, -0.008031056262552738, -0.00024398644745815545, -0.05095566436648369, -0.021999165415763855, -0.0024061587173491716, 0.007200256921350956, 0.05212169885635376, 0.06957333534955978, -0.009697511792182922, 0.014138156548142433, 0.009367136284708977, 0.006651249714195728, 0.08504271507263184, -0.02540009655058384, -0.08527591824531555, -0.04617492854595184, -0.01691720262169838, -0.0154305100440979, -0.030569512397050858, 0.015663716942071915, -0.012797217816114426, 0.0013931671855971217, -0.006330590229481459, -0.02979215607047081, 0.0405779667198658, -0.00573785649612546, 0.026332924142479897, -0.028392916545271873, -0.007924169301986694, -0.026352357119321823, -0.045242100954055786, 0.023223500698804855, -0.05099453404545784, -0.0178403127938509, 0.021241243928670883, 0.06304354965686798, 0.0519273616373539, 0.02534179575741291, -0.0020964310970157385, -0.05227717012166977, 0.004153994377702475, -0.047962844371795654, 0.010523452423512936, 0.010737225413322449, -0.053326599299907684, 0.014332495629787445, 0.037896089255809784, 0.011291091330349445, -0.05585300549864769, -0.01961851492524147, 0.01727673038840294, 0.03152177482843399, -0.0031288566533476114, -0.09312721341848373, -0.009852983057498932, 0.006957333534955978, -0.006160543765872717, 0.031230265274643898, -0.01484749373048544, -0.006277147214859724, -0.08714157342910767, -0.015080700628459454, -0.05099453404545784, 0.019958607852458954, 0.013535706326365471, 0.02596368081867695, -0.024700477719306946, -0.029617251828312874, -0.007613227237015963, -0.00986270047724247, 0.016120413318276405, -0.029967062175273895, -0.03593326732516289, 0.015245888382196426, -0.03972287476062775, 0.01997804082930088, -0.012641746550798416, 0.0028640697710216045, 0.038498539477586746, -0.0024328804574906826, 0.019375590607523918, -0.060478273779153824, 0.03297931328415871, -0.02176595851778984, -0.04901227727532387, 0.044581349939107895, 0.05379301309585571, -0.022504447028040886, -0.015916356816887856, 0.06930126249790192, -0.010513735935091972, -0.015236171893775463, -0.011942126788198948, -0.03488383814692497, 0.04403720051050186, -0.021280111744999886, -0.033387426286935806, -0.03593326732516289, -0.00440663518384099, -0.003928075544536114, -0.02248501405119896, 0.009522607550024986, 0.0007785703055560589, -0.005752432160079479, -0.01530419010668993, -0.030491776764392853, 0.0067678531631827354, 0.020366718992590904, 0.07276049256324768, -0.018792573362588882, -0.0341259129345417, 0.012155899778008461, 0.012583444826304913, 0.032532334327697754, 0.053987354040145874, 0.06926239281892776, -0.0438428595662117, -0.03744911029934883, -0.013040142133831978, 0.017616823315620422, -0.06214958801865578, -0.01788889802992344, 0.007686104159802198, -0.0640929788351059, -0.011485430411994457, 0.008497469127178192, 0.016285602003335953, -0.032823845744132996, -0.06055600941181183, 0.02687707357108593, -0.004073829855769873, -0.07579217851161957, -0.06778541952371597, 0.042948901653289795, 0.04609719291329384, 0.024953117594122887, -0.013088726438581944, -0.011572882533073425, 0.053676411509513855, -0.051888491958379745, -0.08403214812278748, 0.034922704100608826, 0.014215892180800438, 0.01991974003612995, -0.03459232673048973, 0.04042249545454979, 0.008784119039773941, -0.0381292961537838, -0.05142207816243172, -0.0024802505504339933, -0.01991974003612995, 0.0308221522718668, -0.03603043779730797, 0.020425021648406982, 0.053326599299907684, 0.00805049017071724, -0.03014196641743183, -0.011145337484776974, -0.03142460435628891, -0.08037857711315155, 0.03867344558238983, 0.02295142598450184, 0.009828691370785236, -0.03622477501630783, -0.03025856986641884, -0.01392438355833292, 0.02681877091526985, 0.01152429822832346, -0.014944663271307945, 0.020716529339551926, -0.013098442927002907, -0.01246684230864048, -0.0026551554910838604, 0.014468532986938953, -0.023631613701581955, -0.0032187383621931076, 0.028626123443245888, -0.08846307545900345, -0.0008107576868496835, 0.023417839780449867, -0.08348800241947174, 0.002039344049990177, -0.01792776584625244, -0.02631348930299282, 0.08815213292837143, 0.0098578417673707, 0.03198818489909172, 0.004814746789634228, -0.014604570344090462, 0.025283493101596832, -0.014983531087636948, -0.00986270047724247, 0.05993412435054779, -0.026546696200966835, 0.018316444009542465, -0.03995608165860176, -0.017665408551692963, -0.00125227146781981, -0.010999582707881927, 0.01019307691603899, 0.01257372833788395, -0.027576692402362823, -0.010970432311296463, 0.03107479400932789, -0.000737880589440465, 0.02411746047437191, -0.01840389519929886, 0.011689485982060432, -0.011815806850790977, -0.04011155292391777, -0.0519273616373539, -0.02606084942817688, -0.048118315637111664, -0.06125563010573387, -0.008720959536731243, -0.018792573362588882, 0.022776521742343903, 0.02207690104842186, 0.04664134234189987, 0.02571103908121586, 0.08496497571468353 ]
30,930
networkx.drawing.layout
multipartite_layout
Position nodes in layers of straight lines. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. subset_key : string or dict (default='subset') If a string, the key of node data in G that holds the node subset. If a dict, keyed by layer number to the nodes in that layer/subset. align : string (default='vertical') The alignment of nodes. Vertical or horizontal. scale : number (default: 1) Scale factor for positions. center : array-like or None Coordinate pair around which to center the layout. Returns ------- pos : dict A dictionary of positions keyed by node. Examples -------- >>> G = nx.complete_multipartite_graph(28, 16, 10) >>> pos = nx.multipartite_layout(G) or use a dict to provide the layers of the layout >>> G = nx.Graph([(0, 1), (1, 2), (1, 3), (3, 4)]) >>> layers = {"a": [0], "b": [1], "c": [2, 3], "d": [4]} >>> pos = nx.multipartite_layout(G, subset_key=layers) Notes ----- This algorithm currently only works in two dimensions and does not try to minimize edge crossings. Network does not need to be a complete multipartite graph. As long as nodes have subset_key data, they will be placed in the corresponding layers.
def multipartite_layout(G, subset_key="subset", align="vertical", scale=1, center=None): """Position nodes in layers of straight lines. Parameters ---------- G : NetworkX graph or list of nodes A position will be assigned to every node in G. subset_key : string or dict (default='subset') If a string, the key of node data in G that holds the node subset. If a dict, keyed by layer number to the nodes in that layer/subset. align : string (default='vertical') The alignment of nodes. Vertical or horizontal. scale : number (default: 1) Scale factor for positions. center : array-like or None Coordinate pair around which to center the layout. Returns ------- pos : dict A dictionary of positions keyed by node. Examples -------- >>> G = nx.complete_multipartite_graph(28, 16, 10) >>> pos = nx.multipartite_layout(G) or use a dict to provide the layers of the layout >>> G = nx.Graph([(0, 1), (1, 2), (1, 3), (3, 4)]) >>> layers = {"a": [0], "b": [1], "c": [2, 3], "d": [4]} >>> pos = nx.multipartite_layout(G, subset_key=layers) Notes ----- This algorithm currently only works in two dimensions and does not try to minimize edge crossings. Network does not need to be a complete multipartite graph. As long as nodes have subset_key data, they will be placed in the corresponding layers. """ import numpy as np if align not in ("vertical", "horizontal"): msg = "align must be either vertical or horizontal." raise ValueError(msg) G, center = _process_params(G, center=center, dim=2) if len(G) == 0: return {} try: # check if subset_key is dict-like if len(G) != sum(len(nodes) for nodes in subset_key.values()): raise nx.NetworkXError( "all nodes must be in one subset of `subset_key` dict" ) except AttributeError: # subset_key is not a dict, hence a string node_to_subset = nx.get_node_attributes(G, subset_key) if len(node_to_subset) != len(G): raise nx.NetworkXError( f"all nodes need a subset_key attribute: {subset_key}" ) subset_key = nx.utils.groups(node_to_subset) # Sort by layer, if possible try: layers = dict(sorted(subset_key.items())) except TypeError: layers = subset_key pos = None nodes = [] width = len(layers) for i, layer in enumerate(layers.values()): height = len(layer) xs = np.repeat(i, height) ys = np.arange(0, height, dtype=float) offset = ((width - 1) / 2, (height - 1) / 2) layer_pos = np.column_stack([xs, ys]) - offset if pos is None: pos = layer_pos else: pos = np.concatenate([pos, layer_pos]) nodes.extend(layer) pos = rescale_layout(pos, scale=scale) + center if align == "horizontal": pos = pos[:, ::-1] # swap x and y coords pos = dict(zip(nodes, pos)) return pos
(G, subset_key='subset', align='vertical', scale=1, center=None)
[ 0.04474076256155968, -0.00022142489615362138, -0.012456458993256092, 0.012259363196790218, -0.019433652982115746, 0.027494873851537704, -0.007410804741084576, -0.00981044676154852, 0.04694823548197746, -0.006011424120515585, -0.013037892058491707, -0.006302140653133392, -0.006730823777616024, 0.0450955331325531, -0.009825228713452816, -0.028815416619181633, 0.014792044647037983, -0.0748964324593544, 0.011884881183505058, 0.0028307894244790077, 0.03892643377184868, -0.03267849609255791, 0.08601263910531998, 0.01848759315907955, 0.010367242619395256, -0.008958007209002972, 0.05518684163689613, -0.008041511289775372, 0.060863204300403595, 0.007701521273702383, 0.013284261338412762, -0.008401211351156235, -0.04411005601286888, 0.006459817290306091, -0.04166606813669205, 0.030411893501877785, 0.005380717106163502, 0.03019508719444275, 0.003663519397377968, -0.006873718462884426, -0.022941960021853447, -0.0316338874399662, 0.021995898336172104, -0.03549696505069733, 0.04915570840239525, 0.08037569373846054, 0.011382286436855793, 0.013284261338412762, -0.04931338503956795, 0.02171996422111988, 0.020182617008686066, -0.045883920043706894, -0.001330397091805935, -0.006415470503270626, -0.04651462659239769, -0.01996581070125103, 0.0007415732252411544, 0.04990467429161072, 0.007745867595076561, -0.04269096627831459, -0.0449378564953804, -0.0014326405944302678, -0.020320584997534752, -0.0014671323588117957, -0.06125739589333534, -0.04809139296412468, -0.06121797859668732, -0.039892204105854034, -0.0282832570374012, -0.02030087448656559, -0.01352077629417181, 0.021444030106067657, -0.000841352972202003, -0.02918989770114422, 0.0030574495904147625, 0.0024058015551418066, 0.012072121724486351, 0.05167853832244873, -0.010377097874879837, 0.024420177564024925, -0.02386830933392048, 0.007292547263205051, 0.00873627420514822, 0.03878846764564514, 0.10863924026489258, 0.029012512415647507, 0.08151885122060776, 0.06098146364092827, 0.045647405087947845, -0.045292630791664124, 0.0008887791773304343, 0.03949801251292229, 0.031318534165620804, -0.007110233418643475, -0.0027470237109810114, 0.008351937867701054, -0.002039942191913724, -0.028973093256354332, -0.036068543791770935, -0.002919482532888651, -0.03794095665216446, 0.020754195749759674, -0.04292748123407364, -0.005907948594540358, -0.0449378564953804, -0.00725805526599288, -0.03796066343784332, 0.029722057282924652, -0.060035400092601776, -0.0022542839869856834, 0.026154622435569763, 0.003340774914249778, -0.032560236752033234, 0.04324283450841904, 0.018339769914746284, 0.028933674097061157, -0.040404655039310455, -0.0026410846039652824, -0.015777524560689926, -0.05293995141983032, -0.018497446551918983, 0.015629703179001808, -0.03143678978085518, -0.00035816014860756695, -0.03691605478525162, -0.03604883328080177, 0.03667953982949257, 0.07529062032699585, 0.03770443797111511, -0.08829894661903381, 0.00441002007573843, 0.0019192210165783763, -0.013974097557365894, 0.03833514824509621, -0.025898396968841553, -0.03417642414569855, -0.05384659022092819, 0.016250554472208023, -0.019680023193359375, 0.029682638123631477, 0.012239653617143631, -0.031417082995176315, -0.013382809236645699, 0.05065364018082619, -0.04466192424297333, -0.04710591211915016, 0.031239695847034454, -0.06594827771186829, 0.00024128846416715533, -0.010130727663636208, -0.008347010239958763, -0.060035400092601776, 0.051205508410930634, -0.037724148482084274, 0.0324222706258297, -0.013097020797431469, -0.029229316860437393, 0.019354814663529396, 0.017038937658071518, 0.007095451466739178, -0.06476569920778275, -0.036482445895671844, 0.030135957524180412, 0.013550341129302979, -0.03567435219883919, -0.010554484091699123, 0.044228311628103256, -0.058616310358047485, -0.0207147765904665, 0.013924823142588139, 0.05483207106590271, -0.0013402518816292286, -0.01757109723985195, -0.05313704535365105, 0.0113527225330472, -0.0025499279145151377, 0.047224171459674835, -0.0208724532276392, -0.008770765736699104, 0.029978280887007713, 0.006247939076274633, -0.0359305776655674, 0.0817553699016571, 0.06212461739778519, -0.015343913808465004, 0.03295442834496498, 0.030254216864705086, -0.0026238388381898403, -0.00736645795404911, -0.05601464584469795, -0.026686780154705048, -0.03492538630962372, -0.05400426685810089, 0.05010176822543144, -0.04395237937569618, 0.03882788494229317, 0.009253650903701782, 0.01460480410605669, -0.025326820090413094, 0.03612767159938812, -0.005893166642636061, -0.06192752346396446, 0.036226220428943634, 0.027593420818448067, -0.037802986800670624, 0.007361530791968107, -0.027514582499861717, 0.012959053739905357, -0.041468970477581024, 0.026745909824967384, -0.01629982888698578, -0.03902498260140419, 0.03171272575855255, 0.0062233018688857555, -0.015018705278635025, -0.0020867525599896908, -0.07414746284484863, 0.04726358875632286, -0.009145248681306839, -0.008135131560266018, -0.014427417889237404, 0.011835606768727303, 0.022488638758659363, -0.003013103036209941, 0.016418086364865303, -0.04623869061470032, 0.05483207106590271, -0.0340975858271122, 0.01988697238266468, -0.042651545256376266, 0.07454165816307068, -0.0782470628619194, 0.022941960021853447, -0.00380641408264637, -0.023730343207716942, -0.054043687880039215, 0.014397853054106236, 0.020261455327272415, 0.09626162052154541, 0.050811316817998886, -0.01954205520451069, -0.03685692697763443, -0.050377704203128815, -0.016851697117090225, -0.018073691055178642, 0.038078922778367996, 0.02455814555287361, 0.00012326191063039005, -0.005651724059134722, 0.038571663200855255, -0.0450955331325531, 0.001444959081709385, -0.0013747436460107565, 0.01880294643342495, 0.05148144066333771, 0.05901050195097923, -0.08672218024730682, 0.00013481049973051995, -0.013432083651423454, -0.006543582770973444, 0.001521333702839911, -0.06496279686689377, -0.048209648579359055, -0.012338201515376568, 0.09405414760112762, 0.008662363514304161, 0.0060656252317130566, 0.033999036997556686, -0.02554362453520298, 0.00994841381907463, -0.022173285484313965, 0.10044005513191223, 0.058773986995220184, 0.0262925885617733, 0.0284409336745739, 0.01772877387702465, -0.014772335067391396, 0.014841319061815739, 0.055029164999723434, -0.013343390077352524, -0.017925869673490524, -0.006479526869952679, -0.03845340386033058, -0.0036043906584382057, 0.004422338679432869, -0.022153574973344803, 0.024262500926852226, -0.016605326905846596, 0.00353540712967515, -0.026745909824967384, 0.02396685816347599, -0.0013008327223360538, -0.01665460132062435, 0.014880738221108913, -0.024242792278528214, -0.002951510716229677, -0.03626564145088196, -0.04407063499093056, 0.014121918939054012, 0.003013103036209941, 0.04470134153962135, -0.07418688386678696, 0.007878907024860382, 0.017442984506487846, 0.03945859149098396, 0.06417441368103027, 0.01756124198436737, 0.010584047995507717, 0.01359961461275816, 0.012752102687954903, -0.032836172729730606, -0.030510440468788147, -0.039990752935409546, -0.04537146911025047, -0.005035799462348223, 0.014368289150297642, 0.05313704535365105, 0.018536865711212158, 0.030766665935516357, 0.0336245559155941, -0.0008536714594811201, 0.04379470273852348, -0.0527428537607193, 0.07083625346422195, 0.030333055183291435, 0.057276058942079544, 0.02570130117237568, 0.021444030106067657, 0.0010384488850831985, 0.04320341348648071, -0.006972266361117363, 0.05183621495962143, -0.02512972243130207, 0.02254776656627655, -0.11305419355630875, 0.006597784347832203, 0.04643578827381134, 0.011618801392614841, -0.007770504802465439, -0.04383412003517151, 0.01690097153186798, -0.013944532722234726, -0.013747436925768852, -0.019522346556186676, 0.061454493552446365, 0.028756286948919296, 0.006597784347832203, 0.000010788304280140437, -0.02503117546439171, 0.04237561300396919, -0.016615182161331177, 0.08640682697296143, -0.0012201466597616673, -0.052624598145484924, -0.04612043499946594, -0.007391095161437988, 0.006366196554154158, -0.08609147369861603, -0.028835125267505646, 0.08104582130908966, 0.05542336031794548, -0.0005931353662163019, -0.011342867277562618, -0.022114155814051628, -0.01721632480621338, 0.006218374706804752, -0.006952556781470776, 0.012456458993256092, 0.08774708211421967, 0.002850499004125595, 0.028224129229784012, -0.04990467429161072, -0.0970500037074089, 0.0452532097697258, -0.04166606813669205, 0.03837456554174423, -0.031830981373786926, 0.004316399339586496, -0.05215156823396683, -0.005957222543656826, 0.01779775694012642, -0.022350670769810677, 0.05073247849941254, 0.033900488168001175, -0.010672741569578648, -0.026923295110464096, 0.08341097086668015, -0.01352077629417181, 0.0028529628179967403, 0.0007120088557712734, -0.026568522676825523, 0.015077834017574787, 0.030234506353735924, 0.024104824289679527, -0.02311934530735016, -0.0340975858271122, 0.022094447165727615, 0.0026731127873063087, -0.016437795013189316, -0.01277181226760149, 0.0031338243279606104, -0.03185069188475609, -0.018674833700060844, 0.0314762108027935, 0.048879776149988174, -0.048130810260772705, 0.038985561579465866, -0.0008333459845744073, 0.05522626265883446, 0.030017700046300888, 0.02944612316787243, 0.05782792717218399, 0.0007532757590524852, 0.01770906336605549, 0.009578859433531761, -0.01459494885057211, -0.0032890373840928078, 0.07024496793746948, 0.008228752762079239, -0.04026668518781662, 0.00807107612490654, 0.0123086366802454, 0.03563493490219116, -0.02164112590253353, -0.027021843940019608, -0.03616709262132645, -0.031259406358003616, -0.03311210498213768, -0.01344193797558546, 0.04395237937569618, -0.05018060654401779, -0.01269297394901514, 0.03455090522766113, 0.057788509875535965, -0.015688830986618996, -0.025977235287427902, 0.026194041594862938, -0.022941960021853447, -0.0391235314309597, 0.010909256525337696, 0.014910302124917507, -0.003476278390735388, 0.015048269182443619, -0.06192752346396446, 0.026016654446721077, 0.028933674097061157, -0.07197941094636917, 0.042060259729623795, -0.06519931554794312, 0.010889546945691109, 0.032166045159101486, -0.014496400952339172, 0.0527428537607193, -0.00586360227316618, -0.03321065381169319, -0.021739674732089043, 0.008287881501019001, -0.012998472899198532, -0.0723341852426529, -0.0030968687497079372, 0.03837456554174423, 0.022173285484313965, -0.024814369156956673, 0.043637026101350784, 0.03171272575855255, 0.013284261338412762, 0.02637142688035965, 0.020990710705518723, -0.057118382304906845, -0.009169884957373142, 0.020576808601617813, -0.04026668518781662, -0.07016612589359283, -0.011392141692340374, 0.06902297586202621, 0.048288486897945404, 0.03537870943546295, -0.004831312689930201, -0.0527428537607193, -0.020576808601617813, -0.019699731841683388, -0.012032702565193176, -0.010288404300808907, 0.007578336168080568, -0.008962934836745262, 0.0282832570374012, 0.01813282072544098, 0.0407988466322422, -0.08774708211421967, -0.019256265833973885, -0.04135071486234665, 0.010130727663636208, 0.011865171603858471, 0.038985561579465866, 0.03967539966106415, 0.0006461049197241664, -0.029406704008579254, -0.01573810540139675, 0.04292748123407364, -0.04777603968977928, 0.036147382110357285, 0.003318601753562689, 0.0900333896279335, 0.024282211437821388, 0.012614135630428791, 0.059444114565849304, -0.026410846039652824, 0.08916617184877396, 0.04919512942433357, -0.006597784347832203, 0.008544106036424637, 0.01863541454076767, -0.0005503286374732852, -0.0015940128359943628, 0.01286050584167242, 0.0898757129907608, -0.009460601955652237, 0.04016813635826111, 0.07765576988458633, -0.046711720526218414, 0.025090303272008896, 0.05747315660119057, 0.02195647917687893, 0.03202807903289795, -0.0492345467209816, 0.0777740329504013, 0.055541615933179855, -0.018694542348384857, -0.015008850023150444, -0.014319014735519886, -0.018921203911304474, 0.044307149946689606, 0.008026729337871075, 0.018911348655819893, 0.008140059188008308, -0.016605326905846596, -0.0003563123755156994, 0.024656692519783974, 0.03181127458810806, -0.013885403983294964, 0.000017727079466567375, 0.041311293840408325, -0.032737623900175095, -0.02505088411271572, 0.03301355987787247, 0.051047831773757935, 0.0822283998131752, 0.004974206909537315, -0.015491735190153122, -0.02652910351753235, -0.012032702565193176, 0.026351718232035637, -0.00881511252373457, -0.032737623900175095, 0.058773986995220184, 0.0011055846698582172, -0.03443264961242676, -0.011470980010926723, -0.01285065058618784, 0.004860877059400082, -0.008539178408682346, -0.00699197594076395, 0.006336632184684277, -0.015205946750938892, 0.03386107087135315, -0.036580994725227356, -0.04927396774291992, -0.029268736019730568, 0.011116206645965576, 0.03642331808805466, 0.007031395100057125, 0.052309244871139526, 0.001330397091805935, 0.0016469823895022273, 0.023355860263109207, -0.039143238216638565, -0.012811231426894665, 0.012890069745481014, -0.021759383380413055, -0.039813365787267685, -0.0020288554951548576, -0.008337154984474182, 0.09113713353872299, 0.04186316207051277, 0.0059325858019292355, 0.07391095161437988, -0.00047580176033079624, 0.02347411774098873, -0.02203531749546528, 0.012949198484420776, 0.0006664303946308792, 0.008420920930802822, 0.08916617184877396, 0.03370339423418045, 0.016112586483359337, -0.040562331676483154, 0.02213386632502079, -0.0079873101785779, -0.00031935691367834806, -0.053452398627996445, -0.054043687880039215, 0.009825228713452816, 0.0007520439103245735, 0.037152569741010666, -0.03311210498213768, -0.06910181045532227, 0.00696733919903636, 0.008805258199572563, -0.0011998211266472936, -0.08530309051275253, 0.010800853371620178, 0.0018711788579821587, -0.013786856085062027, -0.08963920176029205, -0.05447729676961899, -0.057946186512708664, -0.025839269161224365, 0.03380194306373596, 0.02171996422111988, -0.057788509875535965, 0.013658743351697922, -0.00736645795404911, -0.045134954154491425, -0.027435744181275368, 0.016831986606121063, 0.06685491651296616, 0.01839889958500862, -0.019946102052927017, -0.000851823715493083, 0.0357729010283947, 0.0041858237236738205, -0.011411851271986961, -0.009076264686882496, 0.0324222706258297, 0.0559358075261116, -0.09287157654762268, 0.02662765234708786, -0.033663973212242126, -0.013658743351697922, 0.028913963586091995, 0.01831020601093769, -0.06133623421192169, 0.010850127786397934, -0.04935280606150627, 0.010140582919120789, -0.0179652888327837, 0.07647319883108139, -0.0395965613424778, 0.028736578300595284, -0.0008820040384307504, -0.010150437243282795, 0.014082499779760838, 0.007272837683558464, -0.048879776149988174, 0.005193476099520922, 0.0642138347029686, 0.008549033664166927, -0.011677930131554604, -0.006302140653133392, -0.03088492341339588, 0.003892643377184868, 0.010879691690206528, 0.007928181439638138, 0.014427417889237404, 0.015708541497588158, -0.023395279422402382, -0.025661882013082504, -0.06330719590187073, 0.023828890174627304, 0.006415470503270626, -0.012239653617143631, -0.03604883328080177, -0.03297413885593414, 0.005996641702950001, -0.050377704203128815, -0.03293472155928612, 0.01085998211055994, -0.02603636495769024, -0.032323721796274185, -0.005425063893198967, 0.05215156823396683, 0.014328869991004467, 0.003237299621105194, 0.0011530108749866486, -0.013185713440179825, -0.0021434174850583076, -0.005023480858653784, -0.07812879979610443, -0.013205423019826412, 0.028224129229784012, 0.09287157654762268, -0.013836129568517208, 0.04276980459690094, -0.028835125267505646, -0.010475645773112774, -0.02345440909266472, 0.0013279333943501115, 0.009711898863315582, -0.001060006208717823, -0.03504364565014839, -0.019433652982115746, -0.02388801984488964, -0.06811632961034775, 0.025740720331668854, -0.029919153079390526, -0.031988658010959625, -0.10895459353923798, 0.05632999911904335, -0.017492258921265602, 0.02678532898426056, -0.0139839518815279, -0.01848759315907955, 0.03667953982949257, -0.045883920043706894, 0.012091831304132938, -0.0010501514188945293, -0.0029293373227119446, 0.01862555928528309, -0.03555609658360481, 0.003454104997217655, -0.002063347492367029, -0.01423032209277153, -0.010170146822929382, 0.02179880253970623, -0.025425367057323456, -0.00497174309566617, 0.010037107393145561, -0.08900849521160126, -0.032579947263002396, 0.01148083433508873, 0.006016351282596588, 0.08837778866291046, -0.005622159689664841, 0.03979365527629852, -0.008159768767654896, -0.005149129778146744, -0.07004787027835846, -0.014171193353831768, -0.03967539966106415, 0.024341339245438576, 0.013560195453464985, -0.04470134153962135, -0.008499759249389172, 0.005873457062989473, -0.017837176099419594, 0.02721893973648548, 0.0015964765334501863, 0.043400511145591736, -0.03500422462821007, 0.009317707270383835, -0.012890069745481014, 0.029091350734233856, -0.03709344193339348, -0.03809863328933716, 0.0009965660283342004, -0.029584089294075966, -0.0011548586189746857, -0.016694020479917526, -0.008080930449068546, -0.06780097633600235, -0.03551667556166649, -0.06173042580485344, -0.032560236752033234, 0.03993162140250206, -0.03770443797111511, 0.01854672096669674, 0.03526045009493828, 0.08908732980489731 ]
30,934
networkx.generators.geometric
navigable_small_world_graph
Returns a navigable small-world graph. A navigable small-world graph is a directed grid with additional long-range connections that are chosen randomly. [...] we begin with a set of nodes [...] that are identified with the set of lattice points in an $n \times n$ square, $\{(i, j): i \in \{1, 2, \ldots, n\}, j \in \{1, 2, \ldots, n\}\}$, and we define the *lattice distance* between two nodes $(i, j)$ and $(k, l)$ to be the number of "lattice steps" separating them: $d((i, j), (k, l)) = |k - i| + |l - j|$. For a universal constant $p >= 1$, the node $u$ has a directed edge to every other node within lattice distance $p$---these are its *local contacts*. For universal constants $q >= 0$ and $r >= 0$ we also construct directed edges from $u$ to $q$ other nodes (the *long-range contacts*) using independent random trials; the $i$th directed edge from $u$ has endpoint $v$ with probability proportional to $[d(u,v)]^{-r}$. -- [1]_ Parameters ---------- n : int The length of one side of the lattice; the number of nodes in the graph is therefore $n^2$. p : int The diameter of short range connections. Each node is joined with every other node within this lattice distance. q : int The number of long-range connections for each node. r : float Exponent for decaying probability of connections. The probability of connecting to a node at lattice distance $d$ is $1/d^r$. dim : int Dimension of grid seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. References ---------- .. [1] J. Kleinberg. The small-world phenomenon: An algorithmic perspective. Proc. 32nd ACM Symposium on Theory of Computing, 2000.
def thresholded_random_geometric_graph( n, radius, theta, dim=2, pos=None, weight=None, p=2, seed=None, *, pos_name="pos", weight_name="weight", ): r"""Returns a thresholded random geometric graph in the unit cube. The thresholded random geometric graph [1] model places `n` nodes uniformly at random in the unit cube of dimensions `dim`. Each node `u` is assigned a weight :math:`w_u`. Two nodes `u` and `v` are joined by an edge if they are within the maximum connection distance, `radius` computed by the `p`-Minkowski distance and the summation of weights :math:`w_u` + :math:`w_v` is greater than or equal to the threshold parameter `theta`. Edges within `radius` of each other are determined using a KDTree when SciPy is available. This reduces the time complexity from :math:`O(n^2)` to :math:`O(n)`. Parameters ---------- n : int or iterable Number of nodes or iterable of nodes radius: float Distance threshold value theta: float Threshold value dim : int, optional Dimension of graph pos : dict, optional A dictionary keyed by node with node positions as values. weight : dict, optional Node weights as a dictionary of numbers keyed by node. p : float, optional (default 2) Which Minkowski distance metric to use. `p` has to meet the condition ``1 <= p <= infinity``. If this argument is not specified, the :math:`L^2` metric (the Euclidean distance metric), p = 2 is used. This should not be confused with the `p` of an Erdős-Rényi random graph, which represents probability. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. pos_name : string, default="pos" The name of the node attribute which represents the position in 2D coordinates of the node in the returned graph. weight_name : string, default="weight" The name of the node attribute which represents the weight of the node in the returned graph. Returns ------- Graph A thresholded random geographic 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 nodethre attribute ``'weight'`` that stores the weight of that node as provided or as generated. Examples -------- Default Graph: G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1) Custom Graph: Create a thresholded random geometric graph on 50 uniformly distributed nodes where nodes are joined by an edge if their sum weights drawn from a exponential distribution with rate = 5 are >= theta = 0.1 and their Euclidean distance is at most 0.2. Notes ----- This uses a *k*-d tree to build the graph. The `pos` keyword argument can be used to specify node positions so you can create an arbitrary distribution and domain for positions. For example, to use a 2D Gaussian distribution of node positions with mean (0, 0) and standard deviation 2 If weights are not specified they are assigned to nodes by drawing randomly from the exponential distribution with rate parameter :math:`\lambda=1`. To specify weights from a different distribution, use the `weight` keyword argument:: :: >>> import random >>> import math >>> n = 50 >>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)} >>> w = {i: random.expovariate(5.0) for i in range(n)} >>> G = nx.thresholded_random_geometric_graph(n, 0.2, 0.1, 2, pos, w) References ---------- .. [1] http://cole-maclean.github.io/blog/files/thesis.pdf """ G = nx.empty_graph(n) G.name = f"thresholded_random_geometric_graph({n}, {radius}, {theta}, {dim})" # If no weights are provided, choose them from an exponential # distribution. if weight is None: weight = {v: seed.expovariate(1) for v in G} # If no positions are provided, choose uniformly random vectors in # Euclidean space of the specified dimension. if pos is None: pos = {v: [seed.random() for i in range(dim)] for v in G} # If no distance metric is provided, use Euclidean distance. nx.set_node_attributes(G, weight, weight_name) nx.set_node_attributes(G, pos, pos_name) edges = ( (u, v) for u, v in _geometric_edges(G, radius, p, pos_name) if weight[u] + weight[v] >= theta ) G.add_edges_from(edges) return G
(n, p=1, q=1, r=2, dim=2, seed=None, *, backend=None, **backend_kwargs)
[ 0.021722188219428062, -0.039480894804000854, 0.009778832085430622, -0.024916060268878937, 0.018230091780424118, 0.00958643015474081, -0.06256913393735886, -0.01696985773742199, 0.023434564471244812, -0.024819860234856606, 0.02283811941742897, 0.08057796210050583, 0.016171390190720558, 0.02564718760550022, -0.060106389224529266, -0.028994983062148094, -0.01187120471149683, 0.009841362945735455, -0.010149206034839153, -0.05506545677781105, -0.02695552259683609, -0.0012878909474238753, 0.04813898354768753, 0.05787452682852745, 0.0054786475375294685, -0.032958466559648514, -0.05137133598327637, 0.04267476499080658, -0.027475006878376007, 0.02791753225028515, -0.04136643186211586, -0.06391594558954239, 0.01641189120709896, 0.014843815006315708, 0.012765873223543167, 0.004793215077370405, 0.055142417550086975, 0.04317501187324524, -0.06949561089277267, -0.038480401039123535, -0.010168446227908134, -0.014459011144936085, -0.02499302104115486, -0.02143358439207077, 0.0072968462482094765, 0.009499849751591682, 0.06764854490756989, 0.04698457196354866, -0.044598788022994995, -0.03278530389070511, 0.014478251338005066, -0.00031355515238828957, -0.006416607182472944, -0.013573962263762951, -0.029091184958815575, -0.00788367260247469, 0.0016546573024243116, -0.031496208161115646, 0.051833104342222214, -0.03272758424282074, 0.037364471703767776, 0.012506131082773209, 0.047369375824928284, -0.02049081400036812, -0.03967329487204552, -0.015517222695052624, -0.05094805359840393, -0.027725130319595337, 0.00009454755490878597, 0.0032010884024202824, 0.02986079268157482, 0.018181990832090378, 0.06368506699800491, 0.025416305288672447, 0.0015235834289342165, 0.01611366868019104, 0.06249217316508293, -0.015998227521777153, -0.016796695068478584, -0.0057576303370296955, 0.0070900144055485725, 0.0003547412052284926, 0.023511525243520737, -0.0614532046020031, 0.009889463894069195, -0.024358095601201057, 0.014160788618028164, 0.04752329736948013, 0.05618138983845711, -0.06710982322692871, -0.018595654517412186, 0.014834195375442505, 0.02124118246138096, 0.003379060421139002, 0.05468065291643143, 0.02033689245581627, 0.055103935301303864, -0.003819179954007268, 0.04613800346851349, 0.00810493528842926, -0.0012223540106788278, 0.010476289317011833, -0.0714581087231636, 0.04652280732989311, -0.013487380929291248, -0.03615233674645424, -0.03824951872229576, 0.012640812434256077, 0.011130456812679768, -0.0016907326644286513, -0.045099031180143356, -0.024665938690304756, 0.05060172826051712, 0.002857169834896922, 0.04890859127044678, -0.0017256055725738406, -0.05475761368870735, 0.021702947095036507, 0.007609499618411064, -0.01024540700018406, 0.023607727140188217, 0.0038239900022745132, -0.009673011489212513, 0.018345532938838005, -0.007445957977324724, 0.02133738249540329, 0.04240540415048599, -0.028783341869711876, -0.016844796016812325, -0.018662994727492332, 0.01655619405210018, 0.01219828799366951, 0.05394952371716499, 0.07134266942739487, -0.03388199582695961, 0.00352095696143806, -0.05341079831123352, 0.010659071616828442, 0.06953408569097519, -0.023319123312830925, 0.02936054766178131, -0.09989512711763382, 0.009283397346735, 0.019798167049884796, 0.03669106587767601, 0.009817312471568584, -0.00770570058375597, -0.03532500937581062, 0.029841551557183266, -0.038480401039123535, 0.03515184670686722, -0.05995246767997742, 0.058451730757951736, -0.020971819758415222, -0.003867280436679721, -0.01822047121822834, 0.028841061517596245, -0.04848530888557434, -0.059913985431194305, -0.028148414567112923, 0.01781642623245716, 0.0061087640933692455, 0.018249331042170525, 0.016681253910064697, -0.03624853864312172, 0.0040260120294988155, 0.07126570492982864, -0.06903384625911713, 0.009870223701000214, -0.0025685669388622046, -0.0558350645005703, -0.04494510963559151, -0.01129399798810482, 0.0009433711529709399, -0.042790208011865616, 0.03317010775208473, -0.006642679683864117, -0.012188667431473732, -0.06256913393735886, -0.02610895410180092, -0.00437955092638731, -0.034459199756383896, -0.0009343522833660245, 0.010360848158597946, -0.018153129145503044, 0.07349757105112076, 0.04579167813062668, -0.01696023717522621, -0.030437998473644257, 0.00567104946821928, -0.05995246767997742, -0.02008677087724209, 0.03016863577067852, 0.042097561061382294, 0.06133776158094406, 0.0007425515213981271, 0.03263138234615326, 0.03343946859240532, -0.11474855989217758, 0.0858113020658493, 0.0683411955833435, 0.006580148823559284, 0.018105030059814453, -0.0385381244122982, -0.010610970668494701, -0.023915570229291916, -0.024973781779408455, -0.005141943693161011, 0.03971177712082863, 0.017595164477825165, 0.016892896965146065, -0.002010601107031107, 0.015430641360580921, 0.045099031180143356, -0.02857169881463051, -0.00022231451293919235, -0.018460974097251892, 0.012756253592669964, -0.04786962270736694, -0.04348285496234894, -0.03465160354971886, 0.01460331305861473, -0.0164599921554327, -0.011236277408897877, 0.054488249123096466, 0.01541140116751194, 0.00721507566049695, -0.03640246018767357, 0.03630625829100609, -0.05752820149064064, 0.09127551317214966, -0.05033236742019653, 0.06110687926411629, -0.028244616463780403, -0.02218395285308361, -0.04529143497347832, 0.014189648441970348, 0.0007702092989347875, -0.002207813085988164, 0.020760176703333855, -0.004670558962970972, -0.04648432508111, -0.05337231978774071, 0.030207116156816483, 0.049678198993206024, -0.013015996664762497, -0.0051708039827644825, -0.020644735544919968, 0.08450296521186829, -0.0011255517601966858, -0.057643644511699677, -0.05225638672709465, -0.012987135909497738, -0.01317953784018755, 0.023165201768279076, -0.02911042422056198, -0.004035632126033306, -0.03101520426571369, 0.020952578634023666, 0.020760176703333855, -0.023684687912464142, 0.00240262015722692, -0.03499792516231537, 0.04613800346851349, 0.03474780544638634, -0.016940997913479805, -0.053680162876844406, 0.047061532735824585, -0.021664466708898544, -0.04109707102179527, -0.051332857459783554, 0.01112083625048399, 0.06410834938287735, -0.0021849654149264097, 0.0436752587556839, -0.03861508518457413, 0.010582110844552517, 0.04663824662566185, 0.033054664731025696, 0.012409930117428303, -0.04717697575688362, 0.013641302473843098, 0.022126231342554092, -0.00888416264206171, -0.05571962520480156, 0.06680198013782501, -0.08065492659807205, 0.01322763878852129, 0.012775493785738945, -0.05125589668750763, -0.04421398416161537, -0.016123289242386818, -0.027571208775043488, 0.007821141742169857, 0.02249179594218731, 0.01636379212141037, 0.02720564417541027, -0.012207907624542713, 0.012737013399600983, -0.03191949427127838, 0.13221865892410278, -0.02002904936671257, 0.044444866478443146, -0.04994756355881691, 0.053333837538957596, 0.05064021050930023, 0.012381069362163544, -0.019144000485539436, -0.047561779618263245, 0.02505074255168438, -0.037075869739055634, -0.018105030059814453, 0.04198211804032326, 0.012265628203749657, 0.025685667991638184, -0.10736032575368881, 0.02374240942299366, -0.06576301157474518, 0.02349228598177433, -0.007455578073859215, -0.007075584027916193, 0.002919700462371111, -0.047253936529159546, 0.035055648535490036, -0.06941864639520645, -0.04225148260593414, 0.021876109763979912, 0.03986569866538048, -0.004170313477516174, -0.0024723659735172987, -0.025339344516396523, 0.0530259944498539, 0.017547063529491425, -0.010909194126725197, -0.05291055515408516, 0.07811521738767624, 0.05571962520480156, 0.029937753453850746, -0.015392160974442959, -0.05822084844112396, 0.005618138704448938, -0.03072660230100155, 0.016536952927708626, 0.05837476998567581, -0.01611366868019104, -0.014978496357798576, 0.0024086327757686377, -0.023126721382141113, -0.0012325753923505545, -0.05214094743132591, 0.07599879801273346, 0.03738371282815933, -0.032650623470544815, 0.014401290565729141, 0.026936281472444534, -0.00179775629658252, 0.01541140116751194, 0.032554421573877335, -0.003917785827070475, 0.07057306170463562, -0.014131927862763405, -0.006575339008122683, 0.0430595725774765, 0.016306070610880852, 0.022164711728692055, 0.039173051714897156, 0.02133738249540329, 0.06306938081979752, -0.005036122631281614, -0.021068019792437553, 0.010341607965528965, -0.08381031453609467, -0.11597993224859238, 0.01742200180888176, 0.02670539915561676, -0.018682235851883888, -0.03307390585541725, -0.01237144973129034, -0.0025156564079225063, 0.03659486398100853, -0.014891915954649448, 0.005959652364253998, 0.031957972794771194, 0.00996642466634512, -0.014891915954649448, -0.011592221446335316, 0.037018146365880966, 0.054642170667648315, 0.013362320140004158, -0.026686159893870354, -0.055296339094638824, -0.043444376438856125, 0.05071717128157616, 0.055142417550086975, 0.00683989142999053, 0.04752329736948013, 0.06483948230743408, 0.036363981664180756, -0.0733051672577858, -0.002938940655440092, 0.01470913365483284, -0.025089222937822342, -0.017710605636239052, -0.052025504410266876, -0.020009810104966164, -0.005786490626633167, -0.015363301150500774, -0.012631191872060299, 0.05502697452902794, 0.010832233354449272, 0.02795601263642311, 0.014285849407315254, 0.011207417584955692, 0.0008784354431554675, 0.025089222937822342, -0.034863244742155075, -0.004509421996772289, 0.05244879052042961, 0.004427651409059763, -0.026378316804766655, 0.04071226716041565, -0.08073188364505768, 0.026782359927892685, 0.008662900887429714, 0.003934621345251799, 0.02083713747560978, 0.008701381273567677, -0.03538272902369499, -0.006979383062571287, 0.05160222202539444, -0.020394613966345787, 0.005733579862862825, 0.0022727488540112972, 0.026089712977409363, 0.0385381244122982, -0.04225148260593414, -0.01791262812912464, -0.015786584466695786, -0.04940883815288544, -0.02087561786174774, 0.02991851232945919, 0.00974035169929266, 0.029187384992837906, -0.04167427495121956, 0.006113573908805847, -0.003925001248717308, 0.00392981106415391, 0.010341607965528965, 0.008340626955032349, -0.007287226151674986, 0.0586441345512867, 0.006455087568610907, 0.07684536278247833, 0.04763874039053917, -0.04625344276428223, 0.06291545927524567, -0.0343245193362236, 0.013699023053050041, -0.03136152774095535, 0.004742709454149008, 0.03515184670686722, 0.007917342707514763, -0.06472403556108475, -0.018489833921194077, 0.006301166024059057, -0.020663976669311523, -0.00050355214625597, -0.001794148818589747, 0.006705210078507662, -0.001171247218735516, 0.08350247144699097, -0.011265138164162636, -0.03663334250450134, -0.04467574879527092, 0.019095899537205696, 0.015594183467328548, -0.07842306047677994, 0.04810050502419472, 0.00531029561534524, -0.030861282721161842, 0.022164711728692055, -0.007219885475933552, 0.030649641528725624, -0.0008718216558918357, -0.03397819399833679, -0.041943639516830444, -0.007513298653066158, 0.008196325972676277, 0.02820613607764244, -0.061914969235658646, -0.03128456696867943, -0.004670558962970972, 0.049832120537757874, 0.008027973584830761, -0.02314596250653267, 0.028398538008332253, -0.014295469969511032, -0.025339344516396523, 0.03834572061896324, -0.010399328544735909, -0.020952578634023666, 0.028648659586906433, 0.0006120789330452681, 0.02133738249540329, 0.06499340385198593, -0.043136533349752426, 0.07203531265258789, 0.012179047800600529, 0.02951446920633316, 0.045252952724695206, 0.05314143747091293, 0.058259330689907074, 0.05571962520480156, 0.013612442649900913, 0.007166975177824497, 0.0008658090373501182, -0.01807616837322712, 0.023376844823360443, -0.013333459384739399, -0.048408348113298416, 0.048523787409067154, 0.06818727403879166, 0.005901931785047054, 0.019990568980574608, 0.013583581894636154, -0.015228619799017906, 0.04090466722846031, -0.04421398416161537, 0.011188177391886711, 0.037325989454984665, 0.03324706852436066, 0.009697061963379383, -0.06087599694728851, 0.014968876726925373, -0.01187120471149683, 0.028879541903734207, -0.021818388253450394, 0.003492096671834588, -0.028552459552884102, -0.03813407942652702, 0.008220376446843147, -0.0053343456238508224, 0.013978006318211555, 0.020298412069678307, 0.03063040040433407, 0.047253936529159546, 0.030207116156816483, -0.02208775095641613, -0.049024034291505814, -0.03921153023838997, 0.07191987335681915, -0.0015861140564084053, -0.08919757604598999, -0.05918285995721817, 0.09697061777114868, -0.024261893704533577, 0.008100125007331371, -0.034959446638822556, -0.00005779576167697087, 0.041943639516830444, -0.04567623883485794, -0.06776399165391922, -0.016604293137788773, -0.004081327933818102, -0.032342780381441116, -0.01636379212141037, -0.043598297983407974, 0.04140491411089897, -0.03076508268713951, 0.009418078698217869, 0.03930773213505745, 0.03157316893339157, 0.0202791728079319, -0.02655147761106491, 0.015392160974442959, -0.006334836129099131, -0.04202060028910637, 0.006469517946243286, -0.017883766442537308, -0.019653866067528725, -0.015363301150500774, 0.00020593027875293046, 0.03228505700826645, 0.008494548499584198, -0.023319123312830925, 0.0411740317940712, -0.05818236991763115, 0.031246086582541466, 0.0070226737298071384, 0.03126532584428787, 0.05352624133229256, 0.000056668406614335254, 0.04548383504152298, -0.019144000485539436, -0.030399518087506294, 0.015372920781373978, 0.007470007985830307, 0.014093447476625443, -0.0005612727254629135, -0.03091900423169136, -0.026782359927892685, 0.030457239598035812, -0.02845625765621662, 0.003636398119851947, -0.043098051100969315, 0.007455578073859215, 0.014988116919994354, -0.03091900423169136, 0.029687630012631416, -0.05575810372829437, -0.029187384992837906, -0.0025036311708390713, -0.033362507820129395, -0.02701324224472046, -0.011611461639404297, 0.00027763008256442845, -0.06941864639520645, 0.0651858001947403, 0.018662994727492332, -0.026031993329524994, -0.02816765569150448, -0.010341607965528965, 0.060529675334692, -0.007128494791686535, 0.026878561824560165, -0.043444376438856125, -0.014420530758798122, -0.042597804218530655, -0.04848530888557434, 0.043098051100969315, -0.033400990068912506, -0.04763874039053917, -0.01146715972572565, -0.027821330353617668, -0.07465197890996933, -0.024858340620994568, 0.014699514023959637, -0.029995474964380264, -0.0038360152393579483, 0.016084808856248856, -0.04775417968630791, 0.02770588919520378, -0.04217452183365822, -0.049870602786540985, -0.011553741060197353, -0.020894858986139297, 0.028032973408699036, 0.02405025251209736, 0.00941326841711998, -0.06807183474302292, -0.04021202027797699, 0.018133889883756638, 0.013083336874842644, -0.01761440373957157, 0.028186894953250885, 0.017931867390871048, -0.022280152887105942, -0.008124175481498241, 0.02008677087724209, -0.021818388253450394, 0.014516731724143028, 0.051833104342222214, 0.047561779618263245, 0.05722035840153694, -0.021702947095036507, 0.031053684651851654, 0.02851397916674614, -0.0343245193362236, 0.037768516689538956, 0.000412161200074479, -0.018509073182940483, -0.0137278838083148, 0.043444376438856125, 0.00011934937356272712, -0.008619610220193863, 0.01993284933269024, -0.008095314726233482, 0.028475498780608177, -0.06480100005865097, -0.02389633096754551, 0.10566718876361847, 0.02961066924035549, -0.03368959203362465, -0.019095899537205696, 0.05287207290530205, 0.05475761368870735, -0.03813407942652702, -0.052987515926361084, 0.032054174691438675, 0.058451730757951736, -0.012506131082773209, 0.031092165037989616, 0.0639544278383255, 0.037268269807100296, 0.03746067360043526, -0.004398791119456291, -0.04267476499080658, 0.007176595274358988, 0.03513260930776596, -0.037018146365880966, 0.037018146365880966, -0.012862075120210648, -0.04567623883485794, 0.05968310311436653, -0.0246466975659132, -0.022607237100601196, -0.021375862881541252, 0.02399253100156784, 0.02087561786174774, -0.009995284490287304, -0.07138114422559738, -0.013910665176808834, 0.03047647885978222, -0.04005809873342514, -0.049524277448654175, 0.03193873539566994, 0.014516731724143028, -0.0029870413709431887, -0.054642170667648315, -0.05987550690770149, 0.0018831347115337849, 0.001708770403638482, -0.04402158036828041, 0.03467084467411041, -0.017498962581157684, 0.0038552554324269295, 0.035613611340522766, -0.11659561842679977, -0.003710953751578927, -0.013593202456831932, 0.014872675761580467, 0.04009658098220825, -0.011284378357231617, 0.016825556755065918, 0.007162164896726608, 0.01265043206512928, -0.014564832672476768, 0.037075869739055634, -0.04636888578534126, 0.047715701162815094, -0.017181500792503357, 0.02780209109187126, -0.037768516689538956, -0.04059682413935661, 0.00996642466634512, -0.019442223012447357, 0.003737409133464098, -0.009268967434763908, 0.005117893684655428, 0.025589467957615852, 0.025512507185339928, 0.024531256407499313, 0.03191949427127838, -0.003181848209351301, -0.018739955499768257, 0.06033727154135704, -0.03091900423169136, -0.04529143497347832, -0.025416305288672447, -0.036460183560848236, -0.04236692190170288, -0.015295960009098053, -0.017239220440387726, 0.002032246207818389, -0.032958466559648514, 0.03324706852436066, 0.005541177932173014, 0.05090957134962082 ]
30,935
networkx.algorithms.shortest_paths.weighted
negative_edge_cycle
Returns True if there exists a negative edge cycle anywhere in G. Parameters ---------- G : NetworkX graph weight : string or function If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining `u` to `v` will be ``G.edges[u, v][weight]``). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number. heuristic : bool Determines whether to use a heuristic to early detect negative cycles at a negligible cost. In case of graphs with a negative cycle, the performance of detection increases by at least an order of magnitude. Returns ------- negative_cycle : bool True if a negative edge cycle exists, otherwise False. Examples -------- >>> G = nx.cycle_graph(5, create_using=nx.DiGraph()) >>> print(nx.negative_edge_cycle(G)) False >>> G[1][2]["weight"] = -7 >>> print(nx.negative_edge_cycle(G)) True Notes ----- Edge weight attributes must be numerical. Distances are calculated as sums of weighted edges traversed. This algorithm uses bellman_ford_predecessor_and_distance() but finds negative cycles on any component by first adding a new node connected to every node, and starting bellman_ford_predecessor_and_distance on that node. It then removes that extra node.
def _dijkstra_multisource( G, sources, weight, pred=None, paths=None, cutoff=None, target=None ): """Uses Dijkstra's algorithm to find shortest weighted paths Parameters ---------- G : NetworkX graph sources : non-empty iterable of nodes Starting nodes for paths. If this is just an iterable containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in this iterable, the computed paths may begin from any one of the start nodes. weight: function Function with (u, v, data) input that returns that edge's weight or None to indicate a hidden edge pred: dict of lists, optional(default=None) dict to store a list of predecessors keyed by that node If None, predecessors are not stored. paths: dict, optional (default=None) dict to store the path list from source to each node, keyed by node. If None, paths are not stored. target : node label, optional Ending node for path. Search is halted when target is found. cutoff : integer or float, optional Length (sum of edge weights) at which the search is stopped. If cutoff is provided, only return paths with summed weight <= cutoff. Returns ------- distance : dictionary A mapping from node to shortest distance to that node from one of the source nodes. Raises ------ NodeNotFound If any of `sources` is not in `G`. Notes ----- The optional predecessor and path dictionaries can be accessed by the caller through the original pred and paths objects passed as arguments. No need to explicitly return pred or paths. """ G_succ = G._adj # For speed-up (and works for both directed and undirected graphs) push = heappush pop = heappop dist = {} # dictionary of final distances seen = {} # fringe is heapq with 3-tuples (distance,c,node) # use the count c to avoid comparing nodes (may not be able to) c = count() fringe = [] for source in sources: seen[source] = 0 push(fringe, (0, next(c), source)) while fringe: (d, _, v) = pop(fringe) if v in dist: continue # already searched this node. dist[v] = d if v == target: break for u, e in G_succ[v].items(): cost = weight(v, u, e) if cost is None: continue vu_dist = dist[v] + cost if cutoff is not None: if vu_dist > cutoff: continue if u in dist: u_dist = dist[u] if vu_dist < u_dist: raise ValueError("Contradictory paths found:", "negative weights?") elif pred is not None and vu_dist == u_dist: pred[u].append(v) elif u not in seen or vu_dist < seen[u]: seen[u] = vu_dist push(fringe, (vu_dist, next(c), u)) if paths is not None: paths[u] = paths[v] + [u] if pred is not None: pred[u] = [v] elif vu_dist == seen[u]: if pred is not None: pred[u].append(v) # The optional predecessor and path dictionaries can be accessed # by the caller via the pred and paths objects passed as arguments. return dist
(G, weight='weight', heuristic=True, *, backend=None, **backend_kwargs)
[ 0.008667515590786934, -0.004119985271245241, -0.03422308340668678, -0.044231537729501724, -0.0389455184340477, -0.021785393357276917, -0.010727508924901485, 0.0405779667198658, 0.07369332015514374, -0.010572037659585476, -0.052860185503959656, 0.029714420437812805, 0.02866499125957489, 0.025536134839057922, -0.027246316894888878, 0.03587496653199196, 0.00007329462096095085, 0.035991568118333817, -0.0012595591833814979, 0.013720327988266945, -0.015012681484222412, -0.056436024606227875, 0.05550319701433182, 0.049595292657613754, -0.02100803703069687, -0.009240815415978432, 0.014857210218906403, -0.04007268697023392, -0.025788774713873863, -0.01634390279650688, 0.01778201200067997, -0.018782855942845345, -0.006330590229481459, -0.0055289422161877155, 0.016538241878151894, 0.058534882962703705, 0.007841575890779495, -0.00303411646746099, -0.023320671170949936, -0.04403720051050186, -0.030180834233760834, -0.03045290894806385, 0.005698988679796457, -0.037837788462638855, 0.08006763458251953, 0.08379894495010376, -0.017509937286376953, 0.008643223904073238, -0.019346440210938454, -0.018821723759174347, 0.01514871884137392, 0.0014842635719105601, -0.009337984956800938, 0.00955661665648222, -0.007822141982614994, 0.03948966786265373, -0.03327082470059395, 0.05418169125914574, 0.027304617688059807, -0.03822646662592888, 0.03948966786265373, 0.010562320239841938, 0.07085596770048141, 0.04011155292391777, -0.06378203630447388, -0.023592745885252953, -0.04664134234189987, -0.037526845932006836, -0.03999495133757591, 0.021396715193986893, 0.001006311271339655, -0.009512890130281448, -0.01346768718212843, -0.03552515432238579, -0.0019020922482013702, 0.03801269456744194, -0.000060351343563525006, -0.034825533628463745, 0.011145337484776974, -0.0398394800722599, 0.043920595198869705, -0.05647489055991173, -0.02584707736968994, -0.07101143896579742, 0.07303256541490555, 0.025069721043109894, -0.004134560469537973, 0.0026940233074128628, -0.009036759845912457, -0.03406761214137077, -0.036710623651742935, 0.030841587111353874, -0.0033159079030156136, 0.00043513698619790375, 0.05678583309054375, 0.02677990309894085, 0.009046477265655994, -0.05701903998851776, 0.05006170645356178, 0.031035926192998886, 0.06852390617132187, 0.004824463743716478, -0.01453655119985342, 0.036147039383649826, 0.026449527591466904, -0.06720239669084549, -0.011019016616046429, 0.015867773443460464, -0.013885515742003918, -0.055619798600673676, -0.022621050477027893, 0.012369672767817974, 0.025944245979189873, -0.02677990309894085, 0.02345670759677887, 0.0032697522547096014, 0.006724126636981964, 0.04395946487784386, -0.0005186420166864991, -0.021124640479683876, -0.025225192308425903, 0.05254924297332764, -0.08309932053089142, -0.0038770614191889763, 0.040500231087207794, -0.05635828897356987, 0.024739345535635948, -0.019900305196642876, 0.06626956909894943, 0.01792776584625244, 0.026196885854005814, 0.004856043960899115, -0.02790706977248192, 0.06560882180929184, 0.03202705457806587, -0.02458387427031994, -0.05663036182522774, 0.046835679560899734, 0.06506466865539551, 0.010406848974525928, 0.04256022348999977, -0.07548123598098755, 0.007724971976131201, 0.02876215986907482, 0.005893327761441469, -0.02850951999425888, 0.011135620065033436, 0.014031270518898964, 0.031307999044656754, 0.05973978340625763, 0.01545966137200594, 0.002900508465245366, 0.006850447040051222, 0.011621467769145966, 0.001647022319957614, -0.0681740939617157, -0.04201607406139374, 0.02044445462524891, 0.005835026036947966, -0.0005210712552070618, 0.016645127907395363, -0.0446590855717659, 0.005713564343750477, 0.0148183424025774, -0.04982849955558777, 0.03488383814692497, 0.02217407152056694, 0.05212169885635376, -0.02712971344590187, 0.012359955348074436, -0.005893327761441469, -0.06413184106349945, -0.047807373106479645, -0.02917027287185192, -0.024447835981845856, 0.003320766380056739, 0.025050286203622818, -0.002266477793455124, 0.01182552333921194, -0.01942417584359646, 0.00988699309527874, -0.02662443183362484, 0.02314576506614685, -0.013564856722950935, 0.030083665624260902, 0.02917027287185192, 0.02227124013006687, -0.02161048725247383, 0.0029685271438211203, 0.03478666767477989, -0.04827378690242767, -0.09328268468379974, -0.06059487536549568, 0.08325479179620743, -0.009085345081984997, 0.006728985346853733, -0.03729363903403282, -0.02217407152056694, -0.027265751734375954, 0.06374316662549973, -0.009153363294899464, -0.029306309297680855, 0.0398394800722599, -0.008837562054395676, 0.00925053283572197, -0.028859330341219902, -0.03245459869503975, 0.0086140725761652, 0.0010421425104141235, 0.018510783091187477, -0.03511704504489899, -0.04543644189834595, 0.030005929991602898, -0.029772723093628883, 0.0011903259437531233, 0.01374947838485241, -0.031754981726408005, 0.040033817291259766, 0.013963251374661922, -0.05907903239130974, -0.004413922782987356, -0.015284756198525429, -0.00953232403844595, 0.02116350829601288, 0.061799775809049606, -0.050256043672561646, 0.047030020505189896, 0.030627815052866936, 0.02584707736968994, -0.07330463826656342, 0.07719141989946365, -0.032726675271987915, 0.09639210253953934, -0.014808625914156437, 0.0738099217414856, -0.047846242785453796, 0.0034495159052312374, 0.04073343798518181, 0.04559190943837166, 0.027868201956152916, -0.021707657724618912, -0.02345670759677887, -0.014653154648840427, -0.05814620479941368, 0.0059370542876422405, -0.00008912261546356604, 0.03148290514945984, -0.012301653623580933, 0.026099717244505882, -0.006495778448879719, 0.005057670641690493, 0.027673862874507904, -0.04236588627099991, -0.05748545378446579, -0.01292353868484497, -0.043143242597579956, -0.02100803703069687, -0.03748797997832298, -0.03653571754693985, -0.06584202498197556, -0.03224082663655281, -0.027829334139823914, -0.06094468757510185, 0.10152265429496765, -0.0038892077282071114, 0.032629504799842834, 0.031210830435156822, -0.014342212118208408, -0.08022310584783554, 0.006626957096159458, 0.042637959122657776, 0.043104372918605804, -0.006865022238343954, -0.003619562368839979, -0.0251474566757679, 0.005193707533180714, -0.03220196068286896, 0.03484496846795082, 0.012884670868515968, -0.023029161617159843, -0.04372625797986984, -0.008361431770026684, -0.04123871773481369, -0.006461769342422485, 0.01797635108232498, 0.02969498746097088, 0.012117031961679459, -0.03484496846795082, 0.0164507906883955, 0.00665610795840621, 0.07019522041082382, -0.012165616266429424, 0.010591471567749977, -0.037740617990493774, 0.062266189604997635, 0.04769077152013779, -0.003413077211007476, -0.07287709414958954, 0.016392488032579422, 0.0536375418305397, 0.015449943952262402, -0.02571103908121586, 0.025633303448557854, -0.005698988679796457, -0.04267682880163193, 0.008269120939075947, 0.031191397458314896, -0.016781166195869446, -0.0025847076904028654, -0.03091932274401188, -0.02141615003347397, -0.025205757468938828, 0.0017733427230268717, 0.007326577324420214, 0.0036705764941871166, -0.037274204194545746, -0.035136476159095764, 0.0073994542472064495, -0.006758136209100485, 0.03224082663655281, -0.038964953273534775, 0.0764140635728836, -0.06832956522703171, 0.02922857366502285, -0.030530644580721855, 0.029248008504509926, 0.03183271363377571, 0.025672171264886856, 0.03509761020541191, 0.022465579211711884, 0.037896089255809784, 0.022446146234869957, 0.026177452877163887, 0.030841587111353874, -0.01987115480005741, 0.08970684558153152, 0.07435407489538193, -0.00544148962944746, 0.000042245941585861146, -0.003153149038553238, 0.04741869866847992, 0.021746525540947914, -0.022057468071579933, 0.02380651794373989, 0.006082808133214712, -0.0438428595662117, 0.03398987650871277, -0.0389455184340477, 0.0074480390176177025, -0.04737982898950577, 0.02186312898993492, 0.06797975301742554, 0.01834559440612793, 0.02646896056830883, 0.050605855882167816, 0.0031312857754528522, -0.010941280983388424, -0.04061683639883995, 0.02232954278588295, -0.004931350238621235, 0.008390583097934723, 0.018160972744226456, 0.009114495478570461, -0.002917513018473983, -0.0462915301322937, 0.01364259235560894, 0.019356155768036842, -0.013331649824976921, -0.01824842393398285, -0.050605855882167816, -0.008463460020720959, -0.06055600941181183, -0.025108588859438896, 0.05542546138167381, 0.012010145001113415, 0.000449105107691139, 0.016363337635993958, -0.0074528977274894714, -0.003529680659994483, 0.044076066464185715, -0.02197973243892193, 0.05748545378446579, 0.0052228583954274654, 0.046019457280635834, 0.024875381961464882, -0.04123871773481369, 0.06638617813587189, 0.007389737293124199, 0.03381497412919998, 0.0063597410917282104, -0.024661609902977943, -0.01783059537410736, 0.044425878673791885, 0.028606688603758812, -0.0026697309222072363, -0.04170513153076172, 0.07186653465032578, 0.03025856986641884, -0.050566986203193665, -0.025069721043109894, 0.01584833860397339, -0.021241243928670883, -0.0551922544836998, 0.06910692155361176, 0.009721804410219193, -0.047651905566453934, 0.04594172164797783, 0.027926502749323845, 0.025944245979189873, 0.04854586347937584, -0.041782867163419724, -0.002404944272711873, -0.014624004252254963, 0.017198994755744934, -0.04388172924518585, -0.058884695172309875, -0.06852390617132187, 0.0422104150056839, 0.05678583309054375, 0.002992819296196103, 0.03659401834011078, -0.029364611953496933, 0.06405410915613174, -0.0828661173582077, 0.01213646586984396, -0.04318210855126381, -0.013020708225667477, -0.027965370565652847, -0.0009692653547972441, 0.05083906278014183, -0.024894816800951958, -0.023592745885252953, 0.0393536314368248, -0.05515338480472565, -0.00710308738052845, -0.005208283197134733, 0.016178715974092484, 0.002471748273819685, 0.07206087559461594, -0.034164782613515854, -0.009410861879587173, -0.02775159850716591, -0.026196885854005814, -0.027013109996914864, -0.0520050972700119, -0.07901820540428162, 0.020502755418419838, -0.022815389558672905, 0.030899887904524803, -0.03593326732516289, 0.006942757871001959, -0.03877061605453491, 0.021182943135499954, 0.023184632882475853, -0.02615801803767681, 0.024972552433609962, 0.016013527289032936, 0.010241661220788956, -0.11986824870109558, 0.02703254483640194, 0.05080019310116768, -0.03187158331274986, 0.028528952971100807, -0.011942126788198948, -0.04788510873913765, 0.05923450365662575, 0.03439798951148987, 0.0010269597405567765, -0.0007287709740921855, -0.025944245979189873, 0.04531983658671379, -0.010824677534401417, -0.08550912886857986, -0.0059370542876422405, 0.022348975762724876, -0.004205008503049612, -0.06350996345281601, 0.014808625914156437, 0.0021668788976967335, -0.016683995723724365, 0.040694572031497955, -0.04007268697023392, 0.06693032383918762, -0.007822141982614994, 0.00544148962944746, -0.05507564917206764, 0.03908155858516693, -0.019657382741570473, 0.014478249475359917, 0.0029393762815743685, 0.040694572031497955, -0.06284920871257782, 0.06937899440526962, -0.031191397458314896, -0.0038892077282071114, 0.04275456443428993, 0.03317365422844887, -0.016577109694480896, 0.08076725900173187, -0.013419102877378464, 0.002594424644485116, -0.01042628288269043, -0.05488131195306778, 0.05954544618725777, 0.03393157571554184, 0.01530419010668993, 0.014487966895103455, 0.048973407596349716, -0.02574990689754486, 0.026449527591466904, 0.01731559820473194, 0.0029588101897388697, 0.04706888645887375, 0.05507564917206764, 0.04582511633634567, -0.0078027076087892056, -0.00665610795840621, 0.0689125806093216, 0.002187527483329177, -0.022407278418540955, 0.04337644577026367, 0.06218845397233963, -0.015556830912828445, 0.0276349950581789, -0.07439293712377548, 0.03531138226389885, 0.004370196722447872, -0.04753530025482178, 0.023068029433488846, 0.004119985271245241, 0.010892696678638458, 0.0337178036570549, -0.0004078080819454044, 0.02693537436425686, 0.0184913482517004, 0.014487966895103455, 0.056125082075595856, -0.018675969913601875, -0.014653154648840427, -0.016975505277514458, 0.05946771055459976, 0.00020117114763706923, -0.004574252292513847, -0.005635828711092472, 0.06992314755916595, -0.00513540580868721, -0.0021608059760183096, -0.008031056262552738, -0.00024398644745815545, -0.05095566436648369, -0.021999165415763855, -0.0024061587173491716, 0.007200256921350956, 0.05212169885635376, 0.06957333534955978, -0.009697511792182922, 0.014138156548142433, 0.009367136284708977, 0.006651249714195728, 0.08504271507263184, -0.02540009655058384, -0.08527591824531555, -0.04617492854595184, -0.01691720262169838, -0.0154305100440979, -0.030569512397050858, 0.015663716942071915, -0.012797217816114426, 0.0013931671855971217, -0.006330590229481459, -0.02979215607047081, 0.0405779667198658, -0.00573785649612546, 0.026332924142479897, -0.028392916545271873, -0.007924169301986694, -0.026352357119321823, -0.045242100954055786, 0.023223500698804855, -0.05099453404545784, -0.0178403127938509, 0.021241243928670883, 0.06304354965686798, 0.0519273616373539, 0.02534179575741291, -0.0020964310970157385, -0.05227717012166977, 0.004153994377702475, -0.047962844371795654, 0.010523452423512936, 0.010737225413322449, -0.053326599299907684, 0.014332495629787445, 0.037896089255809784, 0.011291091330349445, -0.05585300549864769, -0.01961851492524147, 0.01727673038840294, 0.03152177482843399, -0.0031288566533476114, -0.09312721341848373, -0.009852983057498932, 0.006957333534955978, -0.006160543765872717, 0.031230265274643898, -0.01484749373048544, -0.006277147214859724, -0.08714157342910767, -0.015080700628459454, -0.05099453404545784, 0.019958607852458954, 0.013535706326365471, 0.02596368081867695, -0.024700477719306946, -0.029617251828312874, -0.007613227237015963, -0.00986270047724247, 0.016120413318276405, -0.029967062175273895, -0.03593326732516289, 0.015245888382196426, -0.03972287476062775, 0.01997804082930088, -0.012641746550798416, 0.0028640697710216045, 0.038498539477586746, -0.0024328804574906826, 0.019375590607523918, -0.060478273779153824, 0.03297931328415871, -0.02176595851778984, -0.04901227727532387, 0.044581349939107895, 0.05379301309585571, -0.022504447028040886, -0.015916356816887856, 0.06930126249790192, -0.010513735935091972, -0.015236171893775463, -0.011942126788198948, -0.03488383814692497, 0.04403720051050186, -0.021280111744999886, -0.033387426286935806, -0.03593326732516289, -0.00440663518384099, -0.003928075544536114, -0.02248501405119896, 0.009522607550024986, 0.0007785703055560589, -0.005752432160079479, -0.01530419010668993, -0.030491776764392853, 0.0067678531631827354, 0.020366718992590904, 0.07276049256324768, -0.018792573362588882, -0.0341259129345417, 0.012155899778008461, 0.012583444826304913, 0.032532334327697754, 0.053987354040145874, 0.06926239281892776, -0.0438428595662117, -0.03744911029934883, -0.013040142133831978, 0.017616823315620422, -0.06214958801865578, -0.01788889802992344, 0.007686104159802198, -0.0640929788351059, -0.011485430411994457, 0.008497469127178192, 0.016285602003335953, -0.032823845744132996, -0.06055600941181183, 0.02687707357108593, -0.004073829855769873, -0.07579217851161957, -0.06778541952371597, 0.042948901653289795, 0.04609719291329384, 0.024953117594122887, -0.013088726438581944, -0.011572882533073425, 0.053676411509513855, -0.051888491958379745, -0.08403214812278748, 0.034922704100608826, 0.014215892180800438, 0.01991974003612995, -0.03459232673048973, 0.04042249545454979, 0.008784119039773941, -0.0381292961537838, -0.05142207816243172, -0.0024802505504339933, -0.01991974003612995, 0.0308221522718668, -0.03603043779730797, 0.020425021648406982, 0.053326599299907684, 0.00805049017071724, -0.03014196641743183, -0.011145337484776974, -0.03142460435628891, -0.08037857711315155, 0.03867344558238983, 0.02295142598450184, 0.009828691370785236, -0.03622477501630783, -0.03025856986641884, -0.01392438355833292, 0.02681877091526985, 0.01152429822832346, -0.014944663271307945, 0.020716529339551926, -0.013098442927002907, -0.01246684230864048, -0.0026551554910838604, 0.014468532986938953, -0.023631613701581955, -0.0032187383621931076, 0.028626123443245888, -0.08846307545900345, -0.0008107576868496835, 0.023417839780449867, -0.08348800241947174, 0.002039344049990177, -0.01792776584625244, -0.02631348930299282, 0.08815213292837143, 0.0098578417673707, 0.03198818489909172, 0.004814746789634228, -0.014604570344090462, 0.025283493101596832, -0.014983531087636948, -0.00986270047724247, 0.05993412435054779, -0.026546696200966835, 0.018316444009542465, -0.03995608165860176, -0.017665408551692963, -0.00125227146781981, -0.010999582707881927, 0.01019307691603899, 0.01257372833788395, -0.027576692402362823, -0.010970432311296463, 0.03107479400932789, -0.000737880589440465, 0.02411746047437191, -0.01840389519929886, 0.011689485982060432, -0.011815806850790977, -0.04011155292391777, -0.0519273616373539, -0.02606084942817688, -0.048118315637111664, -0.06125563010573387, -0.008720959536731243, -0.018792573362588882, 0.022776521742343903, 0.02207690104842186, 0.04664134234189987, 0.02571103908121586, 0.08496497571468353 ]
30,937
networkx.classes.function
neighbors
Returns an iterator over all neighbors of node n. This function wraps the :func:`G.neighbors <networkx.Graph.neighbors>` function.
def neighbors(G, n): """Returns an iterator over all neighbors of node n. This function wraps the :func:`G.neighbors <networkx.Graph.neighbors>` function. """ return G.neighbors(n)
(G, n)
[ -0.018914617598056793, -0.07544494420289993, -0.05715310573577881, -0.03311392664909363, -0.05384349077939987, 0.03083634190261364, -0.026032064110040665, 0.027224237099289894, 0.04007123038172722, -0.027224237099289894, -0.009079193696379662, 0.005693958140909672, 0.015880804508924484, 0.0446619838476181, -0.008207307197153568, -0.003685503266751766, -0.02688615769147873, 0.007206415757536888, -0.005951965693384409, 0.014101442880928516, -0.06846984475851059, -0.01905696652829647, 0.006926166359335184, -0.03170822933316231, -0.03058723174035549, 0.03425271809101105, 0.03907478600740433, 0.029359471052885056, 0.011565851978957653, 0.026032064110040665, -0.06704635918140411, -0.0571175180375576, -0.04387906566262245, -0.006080969236791134, 0.022028500214219093, 0.029572995379567146, -0.038540977984666824, 0.05028476566076279, -0.07729548215866089, 0.04992889612913132, 0.03010680340230465, -0.03329186141490936, -0.008193961344659328, -0.025943096727132797, 0.01453738659620285, -0.019768711179494858, 0.042704686522483826, -0.006783817429095507, -0.017446642741560936, -0.039537422358989716, 0.015284718945622444, -0.0019094777526333928, 0.028167298063635826, -0.03800716996192932, -0.004835416097193956, 0.015329202637076378, 0.018914617598056793, -0.0032606807071715593, 0.02460857480764389, 0.021512486040592194, -0.037615709006786346, -0.0456940121948719, 0.040569450706243515, 0.013985784724354744, 0.022188642993569374, -0.014368347823619843, -0.03172602131962776, -0.04839864373207092, -0.014804290607571602, -0.009555173106491566, 0.028274061158299446, 0.01775803230702877, 0.041352368891239166, -0.008750012144446373, -0.042384400963783264, 0.028274061158299446, 0.03099648468196392, 0.09060510993003845, 0.019804298877716064, -0.024270497262477875, 0.008830083534121513, -0.00763346254825592, -0.05252676457166672, -0.03199292719364166, 0.008612111210823059, -0.013985784724354744, 0.022188642993569374, -0.012864786200225353, -0.01751781813800335, 0.03879008814692497, -0.053594380617141724, -0.02279362641274929, -0.02485768496990204, -0.01323845237493515, 0.0086921826004982, 0.008536488749086857, -0.01552493218332529, -0.023060530424118042, 0.0016915058949962258, -0.037722472101449966, -0.025373701006174088, 0.03743777424097061, -0.03099648468196392, 0.03725983947515488, -0.00006279896479099989, -0.08334530889987946, -0.07046273350715637, -0.02580074779689312, -0.006236663553863764, 0.0002908144670072943, -0.07565847039222717, 0.03368332237005234, 0.01930607669055462, -0.03800716996192932, 0.043416429311037064, 0.03072958067059517, 0.026743808761239052, -0.005845203995704651, 0.022153055295348167, -0.01362991239875555, -0.0008724433719180524, 0.035587236285209656, -0.021476898342370987, 0.017900381237268448, -0.014048062264919281, 0.02948402613401413, 0.033558767288923264, 0.03359435126185417, 0.01111211534589529, -0.05238441377878189, 0.0700712725520134, -0.0017949313623830676, 0.01832742802798748, 0.07651256024837494, -0.02008899673819542, 0.012758024968206882, -0.011672614142298698, 0.003961304668337107, -0.0023665514308959246, -0.008104993030428886, -0.016174400225281715, -0.041921764612197876, -0.004254898987710476, 0.03697514161467552, -0.011432399973273277, -0.019590774551033974, -0.020284725353121758, 0.01365660224109888, 0.003863439429551363, -0.03765129670500755, 0.010943075641989708, 0.013336317613720894, 0.09338091313838959, 0.02352316491305828, -0.05580078810453415, 0.00934164971113205, 0.018665505573153496, -0.04896803945302963, -0.00035976473009213805, -0.025213558226823807, -0.01900358498096466, 0.020053409039974213, -0.01564948819577694, -0.0006661486113443971, -0.026387937366962433, 0.020017821341753006, 0.011067630723118782, -0.04266909882426262, 0.027704665437340736, 0.003914596047252417, -0.003976874053478241, -0.027010714635252953, -0.019181521609425545, -0.01331852376461029, -0.045765187591314316, 0.06448407471179962, 0.006076520774513483, 0.007277590222656727, 0.01193951815366745, 0.028879044577479362, 0.004328297916799784, -0.03697514161467552, -0.016476891934871674, -0.09302504360675812, 0.031014278531074524, 0.029110360890626907, 0.024644162505865097, -0.003961304668337107, 0.004210415296256542, -0.012580088339745998, 0.019395044073462486, -0.020480455830693245, 0.03375449404120445, 0.03825628012418747, -0.011432399973273277, -0.014839878305792809, -0.021530279889702797, 0.0654093399643898, -0.06825632601976395, 0.06526699662208557, 0.032064102590084076, 0.036512505263090134, -0.028683314099907875, -0.0015680626966059208, -0.009546276181936264, 0.0225801020860672, -0.04911039024591446, -0.05252676457166672, 0.01023133099079132, -0.03042708896100521, 0.001719308434985578, -0.015142370015382767, 0.02989327907562256, 0.0264769047498703, -0.024181528016924858, 0.055373743176460266, -0.004608547315001488, 0.0009669719729572535, -0.004544045310467482, -0.05558726564049721, 0.01064058393239975, -0.036156635731458664, 0.001336745684966445, -0.022099675610661507, 0.010195743292570114, -0.017072977498173714, -0.009172610938549042, -0.007624565623700619, 0.0044372836127877235, -0.06775809824466705, 0.02959078922867775, 0.06220649182796478, 0.024928860366344452, -0.0006222206284292042, 0.05597872659564018, -0.0032606807071715593, -0.05327409505844116, 0.0062455604784190655, 0.010765139944851398, 0.027651283890008926, -0.05882570520043373, -0.03261570259928703, -0.025818541646003723, 0.016503581777215004, 0.021103233098983765, 0.004764241632074118, -0.02953740768134594, 0.034750938415527344, 0.05010683089494705, 0.04989330843091011, -0.05750897526741028, -0.085124671459198, -0.02923491597175598, -0.032580114901065826, 0.017606785520911217, -0.008523143827915192, -0.05985773354768753, -0.004399472381919622, 0.02601427026093006, 0.022491134703159332, 0.021637041121721268, -0.02501782774925232, -0.016032051295042038, 0.0142793795093894, 0.04074738919734955, 0.04978654533624649, 0.007055169902741909, 0.011023147031664848, -0.0075222523882985115, -0.01386122964322567, 0.1074734553694725, 0.0659075677394867, 0.0007584530394524336, 0.004341642837971449, 0.026103239506483078, -0.043274082243442535, 0.009635244496166706, 0.02241995930671692, 0.012722437269985676, -0.05099651217460632, 0.009902149438858032, 0.0007473320001736283, -0.06494671106338501, 0.008923499844968319, -0.03590752184391022, 0.01982209086418152, 0.008901257999241352, 0.028540965169668198, 0.011049837805330753, -0.05049829185009003, 0.06355880945920944, -0.009403927251696587, 0.010355886071920395, -0.0069795469753444195, 0.04676163196563721, -0.01048933807760477, -0.03900361433625221, 0.0435943678021431, 0.005738442298024893, 0.051637083292007446, 0.08298943936824799, -0.06914600729942322, -0.04548048973083496, 0.0022475565783679485, -0.017669063061475754, 0.06658372282981873, 0.057081930339336395, 0.050640638917684555, 0.003987994976341724, 0.012206423096358776, -0.04266909882426262, -0.053701143711805344, -0.010960869491100311, -0.03836304321885109, 0.0314057357609272, -0.13224217295646667, -0.027580110356211662, -0.005667267832905054, -0.029768723994493484, 0.018718887120485306, -0.00904360692948103, 0.07864779978990555, -0.011512471362948418, 0.029306091368198395, -0.08854104578495026, 0.060711827129125595, 0.03215306997299194, 0.05758015066385269, -0.02160145342350006, -0.01889682374894619, 0.035124603658914566, -0.03617442771792412, -0.016939524561166763, 0.07587198913097382, -0.029964454472064972, 0.05355879291892052, 0.07017803192138672, 0.04740219935774803, -0.0023087221197783947, -0.02658366598188877, -0.0021407948806881905, 0.06266912817955017, -0.03281143307685852, -0.005498228128999472, 0.01838080771267414, 0.02672601491212845, -0.025818541646003723, -0.03758012503385544, -0.009973323903977871, -0.0018505363259464502, 0.03234880045056343, 0.07199298590421677, -0.007250899914652109, -0.024110354483127594, 0.027580110356211662, 0.0487901046872139, 0.04391465336084366, -0.028060536831617355, -0.03690396621823311, 0.053024984896183014, 0.0013456424931064248, 0.046690456569194794, 0.016939524561166763, -0.01120997965335846, 0.027117475867271423, -0.02014237642288208, -0.010649480856955051, 0.04064062610268593, 0.006116556469351053, 0.02553384378552437, -0.025925302878022194, -0.0015113455010578036, -0.08946631848812103, 0.006992892362177372, 0.020177964121103287, -0.027651283890008926, 0.025605017319321632, 0.012793611735105515, 0.008251790888607502, 0.015311408787965775, -0.03482211381196976, -0.041352368891239166, 0.04177941754460335, 0.005422605201601982, 0.01080072671175003, -0.020213551819324493, 0.08569406718015671, 0.03005342185497284, 0.02268686518073082, -0.03188616409897804, -0.06270471215248108, -0.00934164971113205, -0.011592542752623558, 0.042847033590078354, -0.05024918168783188, -0.04654810577630997, 0.0877581313252449, -0.017064081504940987, -0.018238458782434464, -0.06473318487405777, 0.0018038281705230474, 0.020320313051342964, -0.01665482670068741, 0.041815005242824554, 0.001955073792487383, -0.016752691939473152, 0.013149484060704708, -0.010266917757689953, 0.06320293247699738, -0.045765187591314316, -0.0477580726146698, 0.010898591950535774, -0.00820285826921463, -0.0002691284753382206, 0.058327484875917435, 0.0006238887435756624, 0.0321708619594574, 0.05736662819981575, 0.024697544053196907, 0.03161926195025444, 0.03576517477631569, -0.13046281039714813, 0.03375449404120445, 0.04604988545179367, 0.006872785277664661, -0.04523137956857681, 0.03056943789124489, -0.04338084161281586, -0.023220673203468323, 0.024697544053196907, -0.029163742437958717, -0.031903959810733795, 0.012864786200225353, -0.024234909564256668, -0.008109441958367825, -0.039217136800289154, -0.020569423213601112, -0.014599664136767387, 0.00721531268209219, 0.07907484471797943, 0.025462668389081955, 0.03186837211251259, 0.03628119081258774, -0.052206479012966156, 0.02782922051846981, 0.006281147710978985, 0.036512505263090134, 0.014101442880928516, 0.08391470462083817, -0.04444846138358116, -0.021209994331002235, -0.057081930339336395, 0.03676161542534828, -0.040462691336870193, -0.042597923427820206, 0.009217094630002975, -0.09160155057907104, -0.03590752184391022, -0.0565837100148201, 0.04590753838419914, 0.009537380188703537, 0.03725983947515488, -0.03560503199696541, -0.02672601491212845, -0.04896803945302963, -0.05427053943276405, 0.0456940121948719, -0.038185104727745056, -0.029252709820866585, -0.024412846192717552, 0.04081856086850166, 0.002760235220193863, -0.0303737074136734, -0.0727047249674797, 0.04604988545179367, 0.016476891934871674, -0.05071181431412697, 0.00789146963506937, 0.015088989399373531, -0.04971536993980408, -0.017927071079611778, -0.009012468159198761, 0.03419933468103409, -0.006859440356492996, -0.014190411195158958, -0.003047157311812043, -0.0018105007475242019, 0.008487556129693985, -0.030444882810115814, -0.03960859775543213, 0.04110325872898102, -0.0014468436129391193, 0.011298947967588902, -0.04733102768659592, 0.06362998485565186, 0.051210034638643265, 0.03900361433625221, 0.006361218634992838, 0.060391541570425034, -0.010631687007844448, -0.015284718945622444, 0.05049829185009003, 0.03647691756486893, 0.012348772026598454, -0.025658398866653442, 0.01957298070192337, 0.02932388335466385, 0.018807854503393173, 0.01854095049202442, 0.047580137848854065, 0.06508906185626984, 0.013941300101578236, 0.034234922379255295, 0.022864799946546555, 0.006049830466508865, -0.03352317959070206, -0.059003639966249466, -0.00396575266495347, -0.027580110356211662, -0.0028447548393160105, 0.03332744911313057, 0.016281161457300186, 0.028683314099907875, -0.013478666543960571, -0.018238458782434464, 0.0272598247975111, 0.01604984514415264, -0.02268686518073082, -0.006823853123933077, -0.009617450647056103, 0.0006222206284292042, 0.05117444694042206, 0.008327413350343704, -0.001768240937963128, -0.051423560827970505, -0.030071215704083443, 0.08754460513591766, 0.038861263543367386, -0.00005230350870988332, 0.07117447257041931, -0.0038567669689655304, -0.052206479012966156, -0.02169042080640793, 0.021316755563020706, -0.04992889612913132, 0.02580074779689312, 0.014048062264919281, -0.01004449836909771, -0.0018738905200734735, -0.04266909882426262, 0.019199315458536148, -0.021423516795039177, -0.011672614142298698, -0.028113918378949165, 0.02829185500741005, 0.03286481276154518, -0.027704665437340736, -0.04505344480276108, 0.009199300780892372, 0.018069420009851456, -0.03793599456548691, -0.022366579622030258, -0.03971535712480545, -0.02953740768134594, -0.020320313051342964, 0.016637034714221954, 0.04626340791583061, -0.0298576932400465, 0.0064368415623903275, 0.039110373705625534, 0.04377230256795883, 0.01741105690598488, 0.00462189270183444, -0.03227762505412102, -0.009759800508618355, 0.005226875655353069, -0.029163742437958717, -0.054590824991464615, -0.008207307197153568, -0.06174385920166969, -0.03624560311436653, -0.022775832563638687, 0.021939532831311226, 0.02555163763463497, 0.010622791014611721, 0.07444850355386734, -0.10377238690853119, 0.031227800995111465, 0.001004227320663631, 0.041245609521865845, 0.05661929398775101, -0.02736658602952957, 0.005275808274745941, -0.039430659264326096, -0.0173843652009964, -0.0023709996603429317, -0.05622783675789833, -0.03492887318134308, -0.013443078845739365, -0.02008899673819542, 0.016209986060857773, 0.05882570520043373, 0.0029270502272993326, 0.0194662194699049, -0.011734891682863235, -0.004483991768211126, -0.012161938473582268, -0.04199294000864029, 0.003558723721653223, -0.038647741079330444, -0.03409257531166077, 0.015320305712521076, -0.0030160185415297747, -0.038754500448703766, -0.07679726183414459, 0.018363015726208687, -0.000917483470402658, 0.10697523504495621, -0.041352368891239166, 0.02103205770254135, -0.04163706675171852, -0.020213551819324493, 0.004052496515214443, 0.029341677203774452, 0.004973316565155983, -0.06306058913469315, 0.0045240274630486965, -0.06626343727111816, 0.0181672852486372, 0.04782924801111221, -0.04957302287220955, -0.00751335546374321, 0.008927948772907257, -0.00568506121635437, -0.01806052401661873, -0.06377232819795609, 0.020676184445619583, -0.04096091166138649, -0.0508541613817215, 0.03665485605597496, -0.07971541583538055, 0.07615669071674347, -0.012081867083907127, -0.029982248321175575, 0.005146804265677929, 0.019661949947476387, 0.04459080845117569, 0.011396813206374645, 0.02279362641274929, -0.08213534206151962, 0.04017799347639084, 0.038291867822408676, -0.008318517357110977, 0.014866569079458714, -0.007717982400208712, 0.026868363842368126, -0.03704631328582764, 0.03042708896100521, 0.031797196716070175, -0.017090771347284317, 0.060355957597494125, 0.025871921330690384, 0.02024913765490055, -0.02060501091182232, -0.02195732668042183, 0.06259795278310776, 0.019377250224351883, -0.030249152332544327, -0.011494677513837814, -0.0063523221760988235, -0.019537393003702164, 0.03386125713586807, 0.014795394614338875, -0.008945741690695286, -0.04708191752433777, -0.019501807168126106, -0.023914624005556107, 0.03567620739340782, -0.03871891647577286, 0.007442180998623371, -0.005996449384838343, 0.03879008814692497, -0.004572960082441568, 0.006814956199377775, 0.00759342685341835, -0.0004984993720427155, -0.005062284413725138, -0.019537393003702164, 0.01372777670621872, 0.038754500448703766, -0.02222423069179058, 0.00981318112462759, 0.06373674422502518, 0.050178006291389465, 0.04839864373207092, 0.0272598247975111, 0.019608568400144577, -0.025160176679491997, 0.005418157204985619, -0.029341677203774452, 0.009750903584063053, -0.01827404648065567, -0.021459104493260384, 0.05508904531598091, 0.01331852376461029, -0.03747336193919182, 0.0011754909064620733, -0.03704631328582764, -0.024466225877404213, 0.09715315699577332, -0.04558725282549858, -0.04405700042843819, 0.005747338756918907, -0.03379008173942566, -0.026352349668741226, 0.05466199666261673, 0.04551607742905617, -0.026459110900759697, -0.04597871005535126, 0.038754500448703766, 0.04647693410515785, -0.05430612713098526, 0.03391463682055473, 0.07608551532030106, -0.044982269406318665, 0.04377230256795883, -0.02439505234360695, -0.012793611735105515, -0.04818512126803398, 0.016387922689318657, 0.0037255389615893364, -0.04021357744932175, -0.021352343261241913, 0.023790068924427032, -0.012277597561478615, -0.03836304321885109, 0.021370137110352516, 0.033149510622024536, -0.06028478220105171, -0.020266931504011154, 0.03129897639155388, 0.015355893410742283, -0.020284725353121758, -0.01967974193394184, 0.03871891647577286, 0.003747781040146947, -0.01661924086511135, -0.000987545819953084, 0.009288269095122814, -0.021405722945928574, 0.0664413720369339, 0.026192206889390945, 0.06174385920166969, -0.03690396621823311, 0.030658405274152756, 0.02238437347114086, 0.03514239937067032, -0.03291819617152214, -0.06355880945920944, -0.0033941329456865788, -0.04797159507870674, 0.04686839133501053, -0.018861236050724983, -0.013683293014764786, -0.04946625977754593, 0.0015458206180483103, 0.057651326060295105, 0.002200848190113902 ]
30,939
networkx.generators.random_graphs
newman_watts_strogatz_graph
Returns a Newman–Watts–Strogatz small-world graph. Parameters ---------- n : int The number of nodes. k : int Each node is joined with its `k` nearest neighbors in a ring topology. p : float The probability of adding a new edge for each edge. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Notes ----- First create a ring over $n$ nodes [1]_. Then each node in the ring is connected with its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd). Then shortcuts are created by adding new edges as follows: for each edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors" with probability $p$ add a new edge $(u, w)$ with randomly-chosen existing node $w$. In contrast with :func:`watts_strogatz_graph`, no edges are removed. See Also -------- watts_strogatz_graph References ---------- .. [1] M. E. J. Newman and D. J. Watts, Renormalization group analysis of the small-world network model, Physics Letters A, 263, 341, 1999. https://doi.org/10.1016/S0375-9601(99)00757-4
def dual_barabasi_albert_graph(n, m1, m2, p, seed=None, initial_graph=None): """Returns a random graph using dual Barabási–Albert preferential attachment A graph of $n$ nodes is grown by attaching new nodes each with either $m_1$ edges (with probability $p$) or $m_2$ edges (with probability $1-p$) that are preferentially attached to existing nodes with high degree. Parameters ---------- n : int Number of nodes m1 : int Number of edges to link each new node to existing nodes with probability $p$ m2 : int Number of edges to link each new node to existing nodes with probability $1-p$ p : float The probability of attaching $m_1$ edges (as opposed to $m_2$ edges) seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. initial_graph : Graph or None (default) Initial network for Barabási–Albert algorithm. A copy of `initial_graph` is used. It should be connected for most use cases. If None, starts from an star graph on max(m1, m2) + 1 nodes. Returns ------- G : Graph Raises ------ NetworkXError If `m1` and `m2` do not satisfy ``1 <= m1,m2 < n``, or `p` does not satisfy ``0 <= p <= 1``, or the initial graph number of nodes m0 does not satisfy m1, m2 <= m0 <= n. References ---------- .. [1] N. Moshiri "The dual-Barabasi-Albert model", arXiv:1810.10538. """ if m1 < 1 or m1 >= n: raise nx.NetworkXError( f"Dual Barabási–Albert must have m1 >= 1 and m1 < n, m1 = {m1}, n = {n}" ) if m2 < 1 or m2 >= n: raise nx.NetworkXError( f"Dual Barabási–Albert must have m2 >= 1 and m2 < n, m2 = {m2}, n = {n}" ) if p < 0 or p > 1: raise nx.NetworkXError( f"Dual Barabási–Albert network must have 0 <= p <= 1, p = {p}" ) # For simplicity, if p == 0 or 1, just return BA if p == 1: return barabasi_albert_graph(n, m1, seed) elif p == 0: return barabasi_albert_graph(n, m2, seed) if initial_graph is None: # Default initial graph : empty graph on max(m1, m2) nodes G = star_graph(max(m1, m2)) else: if len(initial_graph) < max(m1, m2) or len(initial_graph) > n: raise nx.NetworkXError( f"Barabási–Albert initial graph must have between " f"max(m1, m2) = {max(m1, m2)} and n = {n} nodes" ) G = initial_graph.copy() # Target nodes for new edges targets = list(G) # List of existing nodes, with nodes repeated once for each adjacent edge repeated_nodes = [n for n, d in G.degree() for _ in range(d)] # Start adding the remaining nodes. source = len(G) while source < n: # Pick which m to use (m1 or m2) if seed.random() < p: m = m1 else: m = m2 # Now choose m unique nodes from the existing nodes # Pick uniformly from repeated_nodes (preferential attachment) targets = _random_subset(repeated_nodes, m, seed) # Add edges to m nodes from the source. G.add_edges_from(zip([source] * m, targets)) # Add one node to the list for each new edge just created. repeated_nodes.extend(targets) # And the new node "source" has m edges to add to the list. repeated_nodes.extend([source] * m) source += 1 return G
(n, k, p, seed=None, *, backend=None, **backend_kwargs)
[ 0.00350443203933537, 0.0014875272754579782, 0.015359138138592243, 0.004920097999274731, -0.024950215592980385, -0.04089382663369179, -0.06480924040079117, -0.036313869059085846, 0.012082266621291637, -0.030028408393263817, 0.006501045078039169, 0.04196695238351822, -0.03683127090334892, 0.1072361022233963, -0.043078407645225525, 0.013049997389316559, 0.03468501567840576, 0.04740924388170242, -0.0059022014029324055, 0.027307262644171715, -0.040050651878118515, 0.002032474847510457, 0.00011909499880857766, 0.0710180476307869, -0.034550875425338745, 0.010750438086688519, -0.0391116663813591, 0.010740856640040874, -0.015617838129401207, 0.05932862311601639, 0.03928413242101669, -0.12348631769418716, 0.021021801978349686, 0.039054177701473236, -0.00015315422206185758, 0.01019471138715744, 0.027690524235367775, 0.06116827204823494, -0.10961231589317322, -0.03677378222346306, 0.07090307027101517, -0.05538104847073555, 0.08339734375476837, 0.013088323175907135, 0.024662770330905914, -0.02391541376709938, 0.030948232859373093, 0.01298292726278305, -0.0965048298239708, -0.009821033105254173, 0.016087330877780914, -0.07048148661851883, 0.02625329978764057, -0.002375013427808881, -0.02040858566761017, 0.018473124131560326, -0.003135544480755925, 0.04461144655942917, 0.01784074492752552, 0.02529514953494072, 0.06304624676704407, -0.019584577530622482, -0.014640525914728642, -0.035240743309259415, -0.024432815611362457, 0.021979952231049538, -0.04855902120471001, -0.026789862662553787, -0.0014971087221056223, 0.06204976886510849, 0.05039867013692856, 0.06404271721839905, -0.008091573603451252, 0.05511276423931122, 0.05472950637340546, 0.04430483654141426, 0.048673998564481735, 0.027019819244742393, -0.05204668641090393, 0.019718719646334648, 0.004201485775411129, -0.025831712409853935, 0.011842728592455387, -0.034359242767095566, 0.005475825164467096, -0.015493279322981834, 0.006098621990531683, 0.0030972184613347054, 0.0002688807435333729, -0.1017938107252121, -0.04859734699130058, -0.049862105399370193, 0.05568765476346016, 0.01633645035326481, 0.031599774956703186, -0.03324779123067856, -0.006285461131483316, -0.03234713152050972, 0.007483148481696844, -0.024528630077838898, -0.04503303021192551, 0.043691620230674744, -0.03811519220471382, 0.000591956777498126, 0.006510626524686813, 0.007200494408607483, -0.05216166377067566, 0.0151483453810215, 0.02086849883198738, -0.035336557775735855, -0.11704755574464798, 0.04361496865749359, 0.07979469746351242, 0.01824316754937172, -0.02295726351439953, -0.013289534486830235, 0.014956715516746044, 0.011603191494941711, 0.03194470703601837, 0.03225131705403328, 0.016346031799912453, 0.027134796604514122, -0.03296034783124924, -0.0002215720887761563, 0.0007731069345027208, -0.024068718776106834, 0.0482524149119854, -0.008613765239715576, -0.012906274758279324, -0.03872840851545334, 0.010530063882470131, 0.014860900118947029, -0.04706430807709694, 0.0702132061123848, -0.012043940834701061, -0.03439757227897644, -0.04794580489397049, 0.005729734431952238, 0.06917840242385864, 0.003981111571192741, -0.0008329913252964616, -0.0668405145406723, 0.08906958997249603, 0.01289669331163168, -0.039437439292669296, -0.021520039066672325, 0.01724669337272644, -0.0570673905313015, 0.0017546114977449179, -0.012187662534415722, 0.040050651878118515, -0.0013066765386611223, 0.020906824618577957, -0.0346275269985199, -0.039552416652441025, 0.01769702322781086, -0.041507039219141006, -0.0003955361316911876, -0.023263871669769287, 0.014602200128138065, -0.03058413602411747, -0.05469118058681488, 0.048788975924253464, 0.05430791899561882, 0.010070152580738068, -0.030737439170479774, 0.04947884380817413, 0.0018743801629170775, 0.017476648092269897, -0.03548986092209816, -0.07435240596532822, -0.0011707390658557415, -0.0660356730222702, -0.06166650727391243, 0.052698228508234024, -0.0021666157990694046, -0.026004180312156677, -0.031044047325849533, 0.02930021472275257, 0.03437840938568115, 0.038287658244371414, -0.04733258858323097, 0.0677986666560173, -0.05921364575624466, -0.030622461810708046, -0.03541320934891701, -0.006376485340297222, 0.043001752346754074, 0.018022794276475906, 0.008575438521802425, 0.021309247240424156, 0.024777747690677643, 0.03608391433954239, 0.06089998781681061, 0.025218497961759567, 0.005250659771263599, 0.025141844525933266, 0.014573455788195133, -0.012925437651574612, 0.011114534921944141, 0.045646246522665024, 0.002203744137659669, 0.020466076210141182, 0.023187220096588135, 0.027901316061615944, 0.0076747783459723, -0.03282620385289192, -0.042005278170108795, 0.023206382989883423, -0.027230611070990562, 0.004939261358231306, -0.010462993755936623, 0.028591183945536613, -0.02705814503133297, -0.015378301031887531, -0.06281628459692001, 0.019258806481957436, 0.017189204692840576, -0.00011235801503062248, -0.03491497039794922, 0.032021358609199524, -0.0588303841650486, 0.010942067950963974, 0.025831712409853935, 0.0057680606842041016, 0.043768271803855896, -0.01456387434154749, 0.004084112588316202, -0.015138763934373856, 0.028955280780792236, 0.03372686728835106, -0.0007910722633823752, 0.036812108010053635, -0.02832290157675743, -0.03918831795454025, -0.03018171153962612, 0.0030684741213917732, -0.039552416652441025, -0.03585395961999893, 0.019000107422471046, -0.02939602918922901, 0.019852859899401665, -0.020331934094429016, -0.008953907527029514, 0.022229069843888283, 0.01557951234281063, 0.028284575790166855, -0.05814051628112793, -0.06848853081464767, -0.0197953712195158, -0.09336210042238235, -0.01249427068978548, 0.024758584797382355, 0.03146563097834587, 0.026138320565223694, -0.02646409161388874, -0.021500876173377037, 0.009734800085425377, -0.0040146466344594955, 0.05860042944550514, 0.007138214539736509, -0.020351096987724304, -0.11122200638055801, 0.03167642652988434, -0.0014839342329651117, -0.005998016335070133, -0.07078809291124344, 0.06948500871658325, -0.013481165282428265, -0.031331490725278854, 0.06193479150533676, 0.0006910653901286423, 0.008843720890581608, 0.000496740685775876, 0.026981493458151817, 0.023378850892186165, -0.012417619116604328, 0.019517507404088974, -0.019642066210508347, -0.04353831708431244, -0.04123875871300697, -0.04342333972454071, 0.024739421904087067, 0.04541629180312157, -0.005892619956284761, 0.004208672326058149, -0.02334052510559559, -0.06204976886510849, 0.024336999282240868, -0.0334969088435173, 0.015464534051716328, -0.028476206585764885, 0.0057536885142326355, 0.0500154085457325, -0.0017174831591546535, -0.004843446426093578, 0.05863875523209572, 0.023493828251957893, 0.02017863094806671, -0.008949116803705692, 0.03803854063153267, -0.009643775410950184, 0.0912158414721489, 0.003937995061278343, -0.016690965741872787, -0.03207884728908539, 0.013615305535495281, -0.025352638214826584, -0.019872022792696953, 0.020063651725649834, -0.09052597731351852, 0.025141844525933266, 0.05756562948226929, 0.030852416530251503, -0.009447354823350906, -0.06730043143033981, 0.01157444715499878, 0.0006581289926543832, 0.04047223925590515, -0.0038876920007169247, -0.017332926392555237, 0.03752113878726959, -0.001283920486457646, 0.046527743339538574, -0.017610790207982063, -0.0022360815200954676, 0.046412765979766846, 0.07496562600135803, 0.0013426070800051093, 0.022229069843888283, -0.04208192974328995, 0.016614314168691635, -0.010645042173564434, 0.01878931373357773, -0.08753654360771179, 0.08086782693862915, -0.027498893439769745, -0.023283034563064575, 0.06668721139431, -0.08600350469350815, 0.02165418118238449, -0.04668105021119118, -0.0052602412179112434, -0.01058755349367857, 0.04637444019317627, 0.04411320760846138, 0.012091848067939281, -0.004105670843273401, -0.05695241317152977, 0.06921672821044922, -0.013653631322085857, 0.04189030081033707, -0.0027594708371907473, 0.025755060836672783, -0.019134247675538063, 0.03355439752340317, -0.009859359823167324, 0.004400302190333605, 0.010185129940509796, 0.07032818347215652, -0.02332136034965515, -0.005720152985304594, -0.027767175808548927, -0.01367279514670372, 0.02763303369283676, 0.006290252320468426, 0.0024001647252589464, 0.04384492710232735, 0.03849845007061958, -0.05250659957528114, 0.06975328922271729, -0.06718544661998749, -0.045148007571697235, 0.0492105633020401, 0.010386341251432896, -0.028763651847839355, -0.03771276772022247, 0.02010197937488556, 0.03207884728908539, 0.033075325191020966, -0.012379292398691177, -0.0395907424390316, 0.00999350007623434, 0.0395907424390316, -0.006208809558302164, -0.012034359388053417, 0.07262773811817169, 0.003772713942453265, -0.006577697116881609, -0.027019819244742393, 0.012877530418336391, -0.0298176147043705, 0.07327928394079208, 0.006970538292080164, -0.054959461092948914, 0.005068611353635788, 0.04116210713982582, -0.026023343205451965, -0.037099551409482956, -0.0035547350998967886, 0.00252472423017025, 0.016940085217356682, -0.05059029906988144, -0.023685457184910774, -0.005696199368685484, -0.033975984901189804, 0.027862990275025368, 0.028016293421387672, 0.011296583339571953, 0.014927971176803112, -0.015177089720964432, 0.022995591163635254, -0.019019270315766335, -0.011660680174827576, 0.02370462194085121, -0.001074325293302536, -0.005887829232960939, -0.020159468054771423, 0.010894160717725754, 0.015004622749984264, 0.03244294598698616, -0.0078089190647006035, 0.0065345801413059235, -0.02489272691309452, 0.04411320760846138, 0.005796805024147034, -0.05105021223425865, 0.019642066210508347, -0.08155769109725952, 0.02215241827070713, 0.05400131270289421, -0.0395907424390316, 0.03342025727033615, -0.04304007813334465, 0.024643607437610626, 0.008541903458535671, 0.02891695499420166, 0.005380009766668081, 0.056722454726696014, -0.022995591163635254, 0.012139755301177502, 0.022209906950592995, 0.01170858833938837, -0.057412322610616684, -0.029568497091531754, -0.0456845723092556, -0.021711669862270355, -0.0012815251247957349, 0.01609691232442856, -0.020504401996731758, -0.005700990092009306, -0.0052794041112065315, 0.0711713507771492, -0.006735791452229023, -0.047447569668293, 0.03577730432152748, 0.059750210493803024, -0.027977967634797096, -0.034665852785110474, 0.10064403712749481, 0.014803411439061165, 0.006994491908699274, 0.012340966612100601, 0.09581495821475983, 0.03428259119391441, -0.019182154908776283, 0.054154615849256516, -0.020044488832354546, -0.015292068012058735, 0.03800021484494209, -0.018990524113178253, 0.00020465475972741842, 0.015598675236105919, -0.03305616229772568, -0.016805943101644516, -0.03870924189686775, -0.009461726993322372, -0.03966739401221275, -0.011354072950780392, -0.011200768873095512, 0.017371252179145813, 0.0040074605494737625, 0.010328852571547031, 0.03219382464885712, 0.022880611941218376, -0.027786338701844215, -0.0355856753885746, 0.02539096400141716, 0.012034359388053417, 0.0026708419900387526, -0.07312598079442978, -0.08002465218305588, 0.022382374852895737, 0.03698457404971123, -0.051510121673345566, -0.012628411874175072, -0.017141295596957207, -0.047984130680561066, -0.007531055714935064, -0.07626871019601822, 0.019287550821900368, -0.011200768873095512, -0.014688433147966862, -0.04656606912612915, 0.00739691499620676, 0.0004224840959068388, -0.002133080502972007, -0.017428740859031677, 0.0022420701570808887, 0.06350615620613098, -0.000127179388073273, -0.02381959930062294, 0.03757862746715546, 0.03683127090334892, -0.014573455788195133, 0.016298124566674232, -0.008613765239715576, 0.004589536692947149, 0.05139514431357384, -0.028782814741134644, 0.034838318824768066, 0.03468501567840576, 0.031427305191755295, -0.04595285654067993, 0.02753721922636032, -0.00887246523052454, 0.013998565264046192, -0.01108579058200121, 0.021500876173377037, -0.007051981054246426, -0.02470109611749649, 0.036390520632267, 0.04008897766470909, 0.020121142268180847, -0.010874997824430466, -0.014027310535311699, 0.010041408240795135, 0.005442289635539055, -0.052314966917037964, -0.05166342481970787, 0.008259249851107597, 0.019277969375252724, -0.007535846438258886, -0.01269548200070858, -0.006443555932492018, -0.013011671602725983, -0.040740519762039185, 0.0009282074170187116, -0.012772134505212307, -0.019210899248719215, -0.0024277116172015667, 0.015033367089927197, -0.018501868471503258, -0.02234404906630516, 0.006745373364537954, -0.056530825793743134, -0.07795505225658417, 0.048482369631528854, 0.06028677150607109, 0.024586118757724762, -0.06718544661998749, 0.014956715516746044, -0.022209906950592995, 0.0017761698691174388, 0.03777025640010834, 0.043078407645225525, -0.02470109611749649, -0.0013557816855609417, -0.019565414637327194, -0.011047464795410633, 0.02401122823357582, 0.03422510251402855, 0.03010505996644497, 0.01767786033451557, -0.04292510077357292, -0.007238820195198059, -0.04970880225300789, -0.0500154085457325, -0.009797079488635063, 0.008915581740438938, 0.000039935377571964636, 0.061819810420274734, -0.022765634581446648, 0.01636519469320774, 0.044266510754823685, 0.028495369479060173, -0.029376866295933723, 0.01878931373357773, 0.0019606135319918394, -0.028648672625422478, -0.07688192278146744, -0.022516515105962753, 0.03234713152050972, -0.04461144655942917, 0.004730863496661186, 0.04235021397471428, 0.04775417596101761, -0.01519625261425972, -0.056722454726696014, -0.07546386122703552, 0.03560483828186989, 0.03251959756016731, 0.0019378575962036848, -0.0015414231456816196, 0.055151090025901794, 0.016758035868406296, -0.0036385729908943176, -0.0631612241268158, 0.02527598664164543, 0.003502036677673459, -0.036524660885334015, -0.0017270646058022976, -0.027173122391104698, -0.06385108828544617, -0.037981048226356506, -0.05392466112971306, -0.04499470442533493, 0.018664754927158356, 0.02334052510559559, 0.047217611223459244, -0.035451535135507584, 0.019833697006106377, 0.018262330442667007, 0.05105021223425865, -0.025333475321531296, -0.0061369482427835464, -0.025659246370196342, -0.025735897943377495, 0.01572323404252529, -0.0032936392817646265, 0.01665263995528221, -0.05794888734817505, 0.029185237362980843, -0.0018612055573612452, 0.024586118757724762, -0.02381959930062294, 0.05166342481970787, 0.007928688079118729, 0.001991753466427326, 0.08776650577783585, -0.06661055982112885, 0.010769601911306381, -0.06339117884635925, -0.003746364964172244, -0.0378277450799942, 0.005772851407527924, -0.020197793841362, 0.019230062142014503, 0.010980394668877125, -0.026023343205451965, -0.022286560386419296, 0.050743602216243744, 0.008081992156803608, -0.003118776949122548, -0.03276871517300606, -0.002428909298032522, 0.017783256247639656, -0.005715362261980772, -0.0030421249102801085, -0.03411012515425682, 0.0658823698759079, 0.0046422346495091915, 0.0290127694606781, 0.044151533395051956, 0.0077993376180529594, 0.05814051628112793, 0.022612329572439194, -0.03978237137198448, -0.036620479077100754, 0.007880780845880508, -0.028112109750509262, -0.027403078973293304, -0.006213600281625986, -0.06511584669351578, -0.04802245646715164, 0.0298942681401968, -0.021309247240424156, -0.004853027872741222, 0.011507377028465271, 0.011976869776844978, 0.07730350643396378, -0.0029223563615232706, -0.0029223563615232706, -0.005351265426725149, 0.0016288543120026588, 0.05066695064306259, -0.014736340381205082, 0.018204841762781143, -0.0572206936776638, -0.0022288954351097345, 0.021500876173377037, -0.02519933506846428, 0.02343633957207203, 0.050322018563747406, 0.038690079003572464, 0.06392773985862732, -0.02577422372996807, -0.01731376349925995, -0.053771354258060455, -0.04756254702806473, 0.021194269880652428, -0.038958363234996796, -0.0360647514462471, 0.05825549736618996, -0.07600042968988419, 0.035432372242212296, -0.05108853802084923, 0.008997024968266487, -0.0325387604534626, 0.010233038105070591, -0.018118608742952347, -0.04530131444334984, 0.0492105633020401, -0.008580229245126247, 0.004342813044786453, -0.04016563296318054, -0.005571640096604824, 0.031599774956703186, -0.05453787371516228, 0.001573760760948062, -0.06197311729192734, -0.013806935399770737, 0.03616056591272354, 0.007305890787392855, 0.023800436407327652, -0.008364645764231682, 0.031599774956703186, -0.053771354258060455, -0.012120592407882214, -0.036026425659656525, 0.014190195128321648, 0.032807040959596634, 0.0013665608130395412, 0.015023785643279552, -0.0038852966390550137, -0.033956822007894516, 0.011028301902115345, 0.009255724959075451, 0.023608805611729622, 0.008479624055325985, 0.016633477061986923, 0.003439757041633129, -0.052199989557266235, 0.044534794986248016, -0.006132157519459724, 0.036026425659656525, -0.030296690762043, 0.008077201433479786, 0.008388599380850792, 0.0003173870500177145, 0.05453787371516228, -0.01790781505405903, -0.018674336373806, 0.054959461092948914, 0.027690524235367775, 0.004934470634907484, 0.047984130680561066, -0.02922356314957142, -0.0320596843957901, -0.07335593551397324, -0.01633645035326481, 0.013682376593351364, 0.06185813620686531, -0.040740519762039185, -0.0022947683464735746, 0.020619379356503487, 0.015905283391475677, 0.047102633863687515 ]
30,945
networkx.algorithms.connectivity.connectivity
node_connectivity
Returns node connectivity for a graph or digraph G. Node connectivity is equal to the minimum number of nodes that must be removed to disconnect G or render it trivial. If source and target nodes are provided, this function returns the local node connectivity: the minimum number of nodes that must be removed to break all paths from source to target in G. Parameters ---------- G : NetworkX graph Undirected graph s : node Source node. Optional. Default value: None. t : node Target node. Optional. Default value: None. flow_func : function A function for computing the maximum flow among a pair of nodes. The function has to accept at least three parameters: a Digraph, a source node, and a target node. And return a residual network that follows NetworkX conventions (see :meth:`maximum_flow` for details). If flow_func is None, the default maximum flow function (:meth:`edmonds_karp`) is used. See below for details. The choice of the default function may change from version to version and should not be relied on. Default value: None. Returns ------- K : integer Node connectivity of G, or local node connectivity if source and target are provided. Examples -------- >>> # Platonic icosahedral graph is 5-node-connected >>> G = nx.icosahedral_graph() >>> nx.node_connectivity(G) 5 You can use alternative flow algorithms for the underlying maximum flow computation. In dense networks the algorithm :meth:`shortest_augmenting_path` will usually perform better than the default :meth:`edmonds_karp`, which is faster for sparse networks with highly skewed degree distributions. Alternative flow functions have to be explicitly imported from the flow package. >>> from networkx.algorithms.flow import shortest_augmenting_path >>> nx.node_connectivity(G, flow_func=shortest_augmenting_path) 5 If you specify a pair of nodes (source and target) as parameters, this function returns the value of local node connectivity. >>> nx.node_connectivity(G, 3, 7) 5 If you need to perform several local computations among different pairs of nodes on the same graph, it is recommended that you reuse the data structures used in the maximum flow computations. See :meth:`local_node_connectivity` for details. Notes ----- This is a flow based implementation of node connectivity. The algorithm works by solving $O((n-\delta-1+\delta(\delta-1)/2))$ maximum flow problems on an auxiliary digraph. Where $\delta$ is the minimum degree of G. For details about the auxiliary digraph and the computation of local node connectivity see :meth:`local_node_connectivity`. This implementation is based on algorithm 11 in [1]_. See also -------- :meth:`local_node_connectivity` :meth:`edge_connectivity` :meth:`maximum_flow` :meth:`edmonds_karp` :meth:`preflow_push` :meth:`shortest_augmenting_path` References ---------- .. [1] Abdol-Hossein Esfahanian. Connectivity Algorithms. http://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
@nx._dispatchable def edge_connectivity(G, s=None, t=None, flow_func=None, cutoff=None): r"""Returns the edge connectivity of the graph or digraph G. The edge connectivity is equal to the minimum number of edges that must be removed to disconnect G or render it trivial. If source and target nodes are provided, this function returns the local edge connectivity: the minimum number of edges that must be removed to break all paths from source to target in G. Parameters ---------- G : NetworkX graph Undirected or directed graph s : node Source node. Optional. Default value: None. t : node Target node. Optional. Default value: None. flow_func : function A function for computing the maximum flow among a pair of nodes. The function has to accept at least three parameters: a Digraph, a source node, and a target node. And return a residual network that follows NetworkX conventions (see :meth:`maximum_flow` for details). If flow_func is None, the default maximum flow function (:meth:`edmonds_karp`) is used. See below for details. The choice of the default function may change from version to version and should not be relied on. Default value: None. cutoff : integer, float, or None (default: None) If specified, the maximum flow algorithm will terminate when the flow value reaches or exceeds the cutoff. This only works for flows that support the cutoff parameter (most do) and is ignored otherwise. Returns ------- K : integer Edge connectivity for G, or local edge connectivity if source and target were provided Examples -------- >>> # Platonic icosahedral graph is 5-edge-connected >>> G = nx.icosahedral_graph() >>> nx.edge_connectivity(G) 5 You can use alternative flow algorithms for the underlying maximum flow computation. In dense networks the algorithm :meth:`shortest_augmenting_path` will usually perform better than the default :meth:`edmonds_karp`, which is faster for sparse networks with highly skewed degree distributions. Alternative flow functions have to be explicitly imported from the flow package. >>> from networkx.algorithms.flow import shortest_augmenting_path >>> nx.edge_connectivity(G, flow_func=shortest_augmenting_path) 5 If you specify a pair of nodes (source and target) as parameters, this function returns the value of local edge connectivity. >>> nx.edge_connectivity(G, 3, 7) 5 If you need to perform several local computations among different pairs of nodes on the same graph, it is recommended that you reuse the data structures used in the maximum flow computations. See :meth:`local_edge_connectivity` for details. Notes ----- This is a flow based implementation of global edge connectivity. For undirected graphs the algorithm works by finding a 'small' dominating set of nodes of G (see algorithm 7 in [1]_ ) and computing local maximum flow (see :meth:`local_edge_connectivity`) between an arbitrary node in the dominating set and the rest of nodes in it. This is an implementation of algorithm 6 in [1]_ . For directed graphs, the algorithm does n calls to the maximum flow function. This is an implementation of algorithm 8 in [1]_ . See also -------- :meth:`local_edge_connectivity` :meth:`local_node_connectivity` :meth:`node_connectivity` :meth:`maximum_flow` :meth:`edmonds_karp` :meth:`preflow_push` :meth:`shortest_augmenting_path` :meth:`k_edge_components` :meth:`k_edge_subgraphs` References ---------- .. [1] Abdol-Hossein Esfahanian. Connectivity Algorithms. http://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf """ if (s is not None and t is None) or (s is None and t is not None): raise nx.NetworkXError("Both source and target must be specified.") # Local edge connectivity if s is not None and t is not None: if s not in G: raise nx.NetworkXError(f"node {s} not in graph") if t not in G: raise nx.NetworkXError(f"node {t} not in graph") return local_edge_connectivity(G, s, t, flow_func=flow_func, cutoff=cutoff) # Global edge connectivity # reuse auxiliary digraph and residual network H = build_auxiliary_edge_connectivity(G) R = build_residual_network(H, "capacity") kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R} if G.is_directed(): # Algorithm 8 in [1] if not nx.is_weakly_connected(G): return 0 # initial value for \lambda is minimum degree L = min(d for n, d in G.degree()) nodes = list(G) n = len(nodes) if cutoff is not None: L = min(cutoff, L) for i in range(n): kwargs["cutoff"] = L try: L = min(L, local_edge_connectivity(G, nodes[i], nodes[i + 1], **kwargs)) except IndexError: # last node! L = min(L, local_edge_connectivity(G, nodes[i], nodes[0], **kwargs)) return L else: # undirected # Algorithm 6 in [1] if not nx.is_connected(G): return 0 # initial value for \lambda is minimum degree L = min(d for n, d in G.degree()) if cutoff is not None: L = min(cutoff, L) # A dominating set is \lambda-covering # We need a dominating set with at least two nodes for node in G: D = nx.dominating_set(G, start_with=node) v = D.pop() if D: break else: # in complete graphs the dominating sets will always be of one node # thus we return min degree return L for w in D: kwargs["cutoff"] = L L = min(L, local_edge_connectivity(G, v, w, **kwargs)) return L
(G, s=None, t=None, flow_func=None, *, backend=None, **backend_kwargs)
[ -0.006584456190466881, -0.03910138085484505, 0.022554490715265274, 0.039745792746543884, 0.012160716578364372, 0.01171378418803215, -0.018282650038599968, -0.02072518691420555, 0.03278196603059769, -0.09512382745742798, -0.0315970741212368, 0.019696202129125595, 0.034257881343364716, 0.0040353829972445965, -0.012285442091524601, 0.02974698320031166, -0.0414503738284111, 0.006880678702145815, 0.041658248752355576, 0.04086832329630852, 0.002282732864841819, -0.0695551410317421, 0.029559895396232605, -0.02721090242266655, -0.008611242286860943, 0.029934071004390717, 0.0315970741212368, 0.0025048996321856976, -0.040036819875240326, -0.008647620677947998, -0.05018114298582077, -0.012981824576854706, -0.07512620091438293, 0.006636424921452999, 0.03413315489888191, 0.03878956660628319, 0.025111360475420952, 0.030848722904920578, -0.047686636447906494, -0.0488923154771328, -0.0738789513707161, 0.000686638755723834, -0.002059266669675708, 0.0041549112647771835, 0.03014194592833519, 0.031181324273347855, 0.011547483503818512, 0.023011816665530205, 0.001321308547630906, -0.029310444369912148, -0.0021645035594701767, -0.026192311197519302, -0.008304625749588013, -0.0008464429993182421, 0.032033614814281464, 0.028707604855298996, 0.010591256432235241, 0.012701192870736122, -0.005669804289937019, -0.026795150712132454, -0.000049045625928556547, 0.006854694336652756, 0.057789385318756104, 0.03766703978180885, -0.08223554491996765, 0.012992218136787415, -0.06194689869880676, 0.001605838187970221, -0.013740570284426212, 0.0212032999843359, -0.004053572192788124, -0.014468134380877018, 0.01313773076981306, -0.040889110416173935, 0.00577893853187561, -0.030848722904920578, 0.04523370787501335, -0.029164930805563927, -0.04423590376973152, -0.05234304815530777, 0.04943279176950455, -0.025485536083579063, 0.03517253324389458, -0.008242263458669186, 0.07346320152282715, -0.026649639010429382, -0.019373996183276176, 0.051220521330833435, -0.026878301054239273, -0.050139568746089935, 0.025381598621606827, 0.0012427057372406125, -0.021224087104201317, 0.03174258768558502, 0.019997622817754745, 0.01279473677277565, -0.03282354027032852, -0.041034623980522156, 0.07192491739988327, -0.03708498924970627, 0.022221889346837997, 0.027231689542531967, -0.0980340838432312, 0.025298448279500008, -0.008122734725475311, -0.09545642882585526, -0.0391637422144413, 0.03885192796587944, -0.02059006690979004, -0.04964066669344902, -0.017316028475761414, 0.010066370479762554, 0.02396804466843605, 0.015777749940752983, -0.006179098971188068, 0.03136841207742691, 0.02704460173845291, -0.02974698320031166, -0.01233741082251072, -0.013387181796133518, -0.004822711460292339, 0.0446932315826416, -0.013459938578307629, -0.04727088660001755, 0.04764506220817566, -0.016442950814962387, 0.007790134288370609, 0.0028530911076813936, 0.010388577356934547, -0.04377857968211174, 0.06398407369852066, 0.0012076266575604677, 0.0008243562770076096, 0.09354396909475327, -0.009297231212258339, -0.038955867290496826, -0.04365385323762894, 0.07105184346437454, 0.005126729141920805, 0.008382579311728477, 0.018854307010769844, -0.04269762709736824, -0.03278196603059769, 0.03481914475560188, 0.02251291647553444, -0.004934444557875395, 0.013813326135277748, -0.01787729188799858, 0.057165760546922684, 0.034257881343364716, -0.008683999069035053, -0.05304982513189316, -0.012711586430668831, 0.00662603136152029, 0.004885074216872454, 0.008663211017847061, -0.02042376808822155, 0.016702795401215553, -0.02080833725631237, -0.0032766375225037336, -0.043820153921842575, -0.028250278905034065, -0.023489931598305702, 0.0044355434365570545, -0.0187399759888649, -0.021535901352763176, 0.04018233343958855, 0.01276355516165495, -0.03777097538113594, 0.0037131758872419596, -0.020558886229991913, -0.017544692382216454, -0.0642751008272171, -0.018625644966959953, 0.025194508954882622, 0.02897784300148487, 0.022014014422893524, 0.0060283890925347805, -0.009162112139165401, -0.003453331533819437, 0.0016019404865801334, -0.024861909449100494, 0.0001465684617869556, -0.024861909449100494, 0.042739201337099075, 0.042905502021312714, 0.06660331040620804, -0.03301062807440758, -0.004843499045819044, -0.028707604855298996, -0.03176337480545044, -0.04989011958241463, 0.0017084766877815127, 0.05878718942403793, 0.004266644362360239, -0.024300646036863327, 0.013428756967186928, 0.03590009734034538, -0.016692401841282845, 0.07466887682676315, 0.026566488668322563, 0.03752152621746063, 0.05288352444767952, 0.017295241355895996, 0.015850506722927094, 0.0045784576795995235, 0.04269762709736824, -0.00479672709479928, -0.029767770320177078, 0.024487733840942383, -0.04431905597448349, -0.04885074123740196, 0.030412184074521065, 0.011391577310860157, -0.030412184074521065, 0.010903069749474525, -0.013075368478894234, 0.02997564524412155, 0.005669804289937019, -0.019218089058995247, -0.03020430915057659, 0.00735879223793745, 0.027106964960694313, 0.009037386626005173, 0.04594048485159874, -0.06726851314306259, -0.007363989483565092, 0.0001147375296568498, 0.07046978920698166, -0.06452455371618271, 0.06277839839458466, -0.004349794704467058, 0.05496228113770485, 0.02280394174158573, 0.01703539676964283, 0.0038898701313883066, 0.018220286816358566, -0.0021969841327518225, -0.031493138521909714, -0.009645422920584679, -0.043820153921842575, -0.03739679977297783, -0.019987229257822037, 0.008237066678702831, 0.019519507884979248, -0.031243687495589256, 0.016370195895433426, 0.011661815457046032, 0.025236085057258606, 0.0016370194498449564, -0.06290312111377716, -0.06901466101408005, -0.033260077238082886, -0.08260972052812576, -0.0035001037176698446, -0.06614597886800766, -0.02311575412750244, 0.02174377627670765, -0.01980014145374298, -0.0029960055835545063, -0.011381182819604874, -0.007197688799351454, -0.04032784700393677, 0.047894515097141266, -0.03074478544294834, -0.0044121574610471725, -0.01603759452700615, -0.0012453041272237897, -0.048975467681884766, -0.048434991389513016, 0.05205202475190163, 0.0009620737400837243, 0.022783154621720314, 0.010331411845982075, -0.043362826108932495, -0.04423590376973152, -0.00015322698163799942, 0.025714198127388954, 0.04176218807697296, -0.03739679977297783, -0.05280037596821785, -0.00006837154796812683, -0.048684440553188324, -0.004822711460292339, -0.041512735188007355, 0.02396804466843605, -0.04594048485159874, -0.12164873629808426, -0.012004809454083443, -0.049515943974256516, 0.048684440553188324, -0.03783334046602249, 0.02760586515069008, 0.042656052857637405, 0.08639305830001831, 0.038436178117990494, 0.011505908332765102, -0.0488923154771328, 0.02935202047228813, 0.024009618908166885, 0.0707608163356781, -0.050056420266628265, 0.014249864965677261, -0.03689790144562721, 0.01957147754728794, -0.03933004289865494, 0.0403694212436676, -0.01064322516322136, 0.026545699685811996, 0.004822711460292339, -0.04261447489261627, -0.022367402911186218, 0.008756754919886589, -0.0434875525534153, -0.02712775208055973, -0.009655816480517387, -0.03228306397795677, -0.018293043598532677, -0.0007061270880512893, 0.028478942811489105, 0.03901822865009308, 0.08069726824760437, -0.061614297330379486, 0.03244936466217041, -0.05650055781006813, 0.019238876178860664, 0.059078216552734375, 0.030952660366892815, 0.026795150712132454, -0.007114538922905922, -0.005732166580855846, 0.019623447209596634, 0.013356000185012817, 0.00582051370292902, -0.05803883820772171, 0.06735166162252426, 0.05932766571640968, -0.011266851797699928, -0.027855316177010536, -0.04980696737766266, 0.06086594611406326, 0.08730770647525787, 0.009609044529497623, 0.019831322133541107, 0.01067440677434206, 0.04386172816157341, 0.0255271103233099, -0.011817721650004387, 0.019238876178860664, -0.022014014422893524, 0.0488923154771328, 0.0926293209195137, -0.020465342327952385, -0.036336638033390045, -0.01781493052840233, 0.06327729672193527, -0.002044975059106946, -0.0030661635100841522, 0.03373819217085838, 0.022637641057372093, 0.01025345828384161, 0.004191289655864239, -0.0025997429620474577, -0.02989249676465988, 0.006558471824973822, 0.050056420266628265, -0.005550275556743145, 0.06261210143566132, 0.009032189846038818, -0.06244579702615738, -0.03236621245741844, -0.08248499780893326, -0.003598844399675727, -0.009567469358444214, -0.019477933645248413, 0.051677849143743515, 0.003804121632128954, -0.0029492336325347424, 0.03955870494246483, 0.0414503738284111, 0.028478942811489105, 0.02783452905714512, -0.025922073051333427, 0.011620240285992622, 0.030578484758734703, -0.025610260665416718, 0.028769968077540398, -0.004747356753796339, 0.06518975645303726, 0.017846111208200455, 0.028707604855298996, -0.036045610904693604, 0.05704103410243988, -0.004209478851407766, 0.011318820528686047, 0.011807328090071678, 0.058537740260362625, 0.043279677629470825, 0.00435758987441659, -0.01313773076981306, 0.004544678144156933, 0.05280037596821785, 0.04440220445394516, -0.010965432040393353, 0.0075458805076777935, 0.0075926524586975574, 0.07745441049337387, -0.00801360048353672, 0.021785352379083633, 0.0028972646687179804, 0.00030385551508516073, 0.06884836405515671, -0.04461007937788963, 0.006865088362246752, 0.005022791679948568, -0.05413077771663666, -0.026296250522136688, 0.04176218807697296, 0.05596008151769638, -0.02544395998120308, 0.03775018826127052, -0.04199085012078285, 0.033176928758621216, -0.012056778185069561, -0.012867492623627186, -0.041658248752355576, -0.017991624772548676, 0.014291440136730671, -0.03677317500114441, 0.07275642454624176, -0.02658727578818798, -0.008902267552912235, 0.04772821441292763, -0.0419284887611866, -0.02897784300148487, 0.01433301530778408, 0.020163923501968384, -0.008907465264201164, 0.04411118105053902, -0.002393166534602642, 0.028250278905034065, -0.011630633845925331, -0.02960146963596344, -0.010378183797001839, 0.004295227583497763, -0.05188572406768799, -0.023385992273688316, 0.019477933645248413, -0.03733443841338158, 0.00003065351484110579, 0.020849911496043205, -0.03307298943400383, 0.0010614641942083836, 0.023697806522250175, -0.14160478115081787, 0.03745916485786438, 0.021099362522363663, 0.02968461997807026, -0.11283481866121292, -0.002421749522909522, 0.02536080963909626, -0.0016487125540152192, -0.02459167130291462, -0.007977222092449665, -0.04731246083974838, -0.005264447070658207, 0.021639838814735413, -0.013948445208370686, -0.025547897443175316, -0.023780956864356995, 0.04055650904774666, -0.04943279176950455, -0.09628792852163315, 0.008366988971829414, 0.056375835090875626, 0.026088373735547066, -0.030952660366892815, 0.015351605601608753, 0.0031675028149038553, -0.014894278720021248, 0.022596066817641258, -0.03145156055688858, 0.03429945558309555, -0.030495334416627884, 0.008886677213013172, 0.0010140426456928253, 0.001022487529553473, 0.03797885403037071, -0.01925966516137123, -0.02820870466530323, -0.023011816665530205, -0.004617434460669756, -0.0025048996321856976, 0.009738966822624207, 0.0029362414497882128, 0.05363187566399574, -0.018053986132144928, -0.04124249890446663, 0.021847713738679886, -0.002941438229754567, 0.00017052286420948803, 0.0391637422144413, -0.0631941482424736, 0.03783334046602249, 0.01881273277103901, 0.03192967548966408, -0.008335807360708714, 0.022492127493023872, 0.04668883606791496, 0.04155430942773819, 0.06406722962856293, 0.010414562188088894, 0.08323334902524948, 0.08356595039367676, 0.010570468381047249, 0.00715091684833169, 0.031015023589134216, 0.004217274021357298, 0.0245085209608078, -0.051220521330833435, -0.007639424409717321, 0.02166062593460083, -0.007187295239418745, 0.04063965752720833, -0.042510539293289185, 0.037812553346157074, 0.027543501928448677, -0.010554878041148186, -0.017846111208200455, 0.011495514772832394, 0.00347931613214314, 0.04531685635447502, -0.03991209343075752, 0.047437187284231186, -0.0036897899117320776, 0.03569222241640091, -0.053465574979782104, -0.0033415984362363815, -0.06431667506694794, 0.005934845190495253, -0.015590662136673927, 0.010149520821869373, 0.010123536922037601, 0.02027825452387333, 0.01688988320529461, -0.0337589792907238, 0.05587693303823471, 0.015112548135221004, 0.0013875688891857862, -0.054006051272153854, 0.000011835099030577112, 0.04989011958241463, 0.0056386226788163185, -0.028312642127275467, 0.08348279446363449, -0.025152934715151787, -0.0017864300170913339, 0.032885901629924774, -0.014530496671795845, 0.014239471405744553, -0.06855733692646027, -0.028541306033730507, -0.01928045228123665, -0.0424065999686718, -0.006277840118855238, -0.038415390998125076, 0.04419432953000069, -0.06157271936535835, -0.016993820667266846, 0.025028210133314133, -0.03361346572637558, 0.012929855845868587, -0.04080595821142197, 0.010461334139108658, 0.014468134380877018, 0.016390983015298843, -0.025340022519230843, -0.005482716020196676, 0.027252476662397385, -0.012191897258162498, -0.011495514772832394, -0.02937280759215355, 0.06294470280408859, 0.040431782603263855, 0.014894278720021248, 0.05242620036005974, -0.0380827896296978, -0.00016938603948801756, -0.09088316559791565, -0.0223466157913208, -0.020610855892300606, -0.05612638220191002, 0.007613440044224262, -0.012919462285935879, -0.024030407890677452, 0.024757971987128258, 0.008039584383368492, 0.05712418630719185, 0.07695550471544266, -0.013969233259558678, -0.05201044678688049, -0.004804522264748812, -0.030495334416627884, -0.014187502674758434, -0.03500623255968094, -0.01326245628297329, 0.005326809361577034, -0.031243687495589256, 0.0331561416387558, -0.06040861830115318, 0.007680999580770731, 0.019373996183276176, -0.04153352230787277, -0.07791173458099365, -0.041117772459983826, -0.013231274671852589, -0.010778344236314297, 0.06622913479804993, -0.018396981060504913, -0.033966854214668274, 0.02280394174158573, 0.02812555432319641, -0.010289836674928665, -0.005230667069554329, 0.02088109403848648, 0.09337767213582993, -0.019166121259331703, -0.010118339210748672, -0.02334441803395748, 0.027481140568852425, -0.033031415194272995, -0.046065207570791245, 0.0013368992367759347, 0.09038426727056503, 0.01168260257691145, -0.09071686863899231, 0.06947199255228043, 0.017981229349970818, -0.0299132838845253, 0.047354038804769516, -0.08672565221786499, 0.06843261420726776, -0.026150736957788467, -0.005643819458782673, -0.030038008466362953, 0.021764563396573067, 0.034424182027578354, -0.006579259410500526, 0.024861909449100494, -0.01633901335299015, -0.020236678421497345, 0.026483338326215744, 0.036336638033390045, -0.03930925577878952, -0.011266851797699928, 0.028229491785168648, 0.038041215389966965, 0.008065569214522839, 0.030038008466362953, -0.042427387088537216, 0.0023191110230982304, 0.025236085057258606, 0.062154773622751236, 0.008995812386274338, 0.009816920384764671, -0.006745559629052877, 0.059535540640354156, -0.07275642454624176, -0.01487349160015583, 0.015019004233181477, -0.058246713131666183, -0.059992868453264236, 0.034715209156274796, 0.01703539676964283, -0.03523489460349083, -0.054463379085063934, 0.03716813772916794, 0.0013317023403942585, -0.0201847106218338, -0.036960262805223465, 0.048767589032649994, 0.05051374435424805, -0.027647441253066063, -0.03222070261836052, 0.018448950722813606, -0.009333609603345394, -0.04461007937788963, -0.05787253752350807, 0.021598264575004578, 0.015777749940752983, -0.010492515750229359, -0.026691213250160217, 0.03415394201874733, 0.015029397793114185, 0.005004602484405041, -0.012410166673362255, -0.051760997623205185, 0.035110171884298325, 0.01371978223323822, -0.04080595821142197, 0.047354038804769516, 0.014405772089958191, -0.01864643208682537, 0.004360188264399767, -0.00971298199146986, -0.025152934715151787, -0.034652844071388245, 0.021494325250387192, -0.012607648968696594, 0.004544678144156933, -0.032116763293743134, -0.037958063185214996, -0.00691705709323287, -0.019477933645248413, 0.0006213528686203063, 0.009297231212258339, -0.004908460192382336, -0.03205440193414688, -0.07866008579730988, 0.044443778693675995, -0.008309822529554367, -0.01818910613656044, -0.014239471405744553, 0.03933004289865494, -0.003232463961467147, 0.045192133635282516, 0.04440220445394516, 0.003289629705250263, -0.006210280582308769, -0.01702500320971012, -0.0025451756082475185, 0.0967036783695221, 0.018594462424516678, 0.07816118746995926, -0.004063965752720833, -0.004892869386821985, 0.025942862033843994, 0.0222842525690794, -0.033260077238082886, 0.021930864080786705, 0.023302841931581497, -0.017991624772548676, -0.0676426887512207, -0.05512858182191849, 0.011776146478950977, 0.021993227303028107, -0.022305039688944817, 0.029539108276367188, -0.008382579311728477, -0.025485536083579063, 0.0187399759888649, 0.0044251494109630585, 0.04918334260582924, -0.0695551410317421, -0.03768782690167427, 0.003011596156284213, -0.05903663858771324, -0.041824549436569214, -0.029850920662283897, -0.030121158808469772, -0.042988650500774384, -0.029996434226632118, 0.009952039457857609, 0.0188023392111063, -0.013210487551987171, 0.04594048485159874, 0.016370195895433426, 0.0598265677690506 ]
30,950
networkx.readwrite.json_graph.node_link
node_link_data
Returns data in node-link format that is suitable for JSON serialization and use in JavaScript documents. Parameters ---------- G : NetworkX graph source : string A string that provides the 'source' attribute name for storing NetworkX-internal graph data. target : string A string that provides the 'target' attribute name for storing NetworkX-internal graph data. name : string A string that provides the 'name' attribute name for storing NetworkX-internal graph data. key : string A string that provides the 'key' attribute name for storing NetworkX-internal graph data. link : string A string that provides the 'link' attribute name for storing NetworkX-internal graph data. Returns ------- data : dict A dictionary with node-link formatted data. Raises ------ NetworkXError If the values of 'source', 'target' and 'key' are not unique. Examples -------- >>> G = nx.Graph([("A", "B")]) >>> data1 = nx.node_link_data(G) >>> data1 {'directed': False, 'multigraph': False, 'graph': {}, 'nodes': [{'id': 'A'}, {'id': 'B'}], 'links': [{'source': 'A', 'target': 'B'}]} To serialize with JSON >>> import json >>> s1 = json.dumps(data1) >>> s1 '{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "links": [{"source": "A", "target": "B"}]}' A graph can also be serialized by passing `node_link_data` as an encoder function. The two methods are equivalent. >>> s1 = json.dumps(G, default=nx.node_link_data) >>> s1 '{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "links": [{"source": "A", "target": "B"}]}' The attribute names for storing NetworkX-internal graph data can be specified as keyword options. >>> H = nx.gn_graph(2) >>> data2 = nx.node_link_data(H, link="edges", source="from", target="to") >>> data2 {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'id': 0}, {'id': 1}], 'edges': [{'from': 1, 'to': 0}]} Notes ----- Graph, node, and link attributes are stored in this format. Note that attribute keys will be converted to strings in order to comply with JSON. Attribute 'key' is only used for multigraphs. To use `node_link_data` in conjunction with `node_link_graph`, the keyword names for the attributes must match. See Also -------- node_link_graph, adjacency_data, tree_data
def node_link_data( G, *, source="source", target="target", name="id", key="key", link="links", ): """Returns data in node-link format that is suitable for JSON serialization and use in JavaScript documents. Parameters ---------- G : NetworkX graph source : string A string that provides the 'source' attribute name for storing NetworkX-internal graph data. target : string A string that provides the 'target' attribute name for storing NetworkX-internal graph data. name : string A string that provides the 'name' attribute name for storing NetworkX-internal graph data. key : string A string that provides the 'key' attribute name for storing NetworkX-internal graph data. link : string A string that provides the 'link' attribute name for storing NetworkX-internal graph data. Returns ------- data : dict A dictionary with node-link formatted data. Raises ------ NetworkXError If the values of 'source', 'target' and 'key' are not unique. Examples -------- >>> G = nx.Graph([("A", "B")]) >>> data1 = nx.node_link_data(G) >>> data1 {'directed': False, 'multigraph': False, 'graph': {}, 'nodes': [{'id': 'A'}, {'id': 'B'}], 'links': [{'source': 'A', 'target': 'B'}]} To serialize with JSON >>> import json >>> s1 = json.dumps(data1) >>> s1 '{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "links": [{"source": "A", "target": "B"}]}' A graph can also be serialized by passing `node_link_data` as an encoder function. The two methods are equivalent. >>> s1 = json.dumps(G, default=nx.node_link_data) >>> s1 '{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "links": [{"source": "A", "target": "B"}]}' The attribute names for storing NetworkX-internal graph data can be specified as keyword options. >>> H = nx.gn_graph(2) >>> data2 = nx.node_link_data(H, link="edges", source="from", target="to") >>> data2 {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'id': 0}, {'id': 1}], 'edges': [{'from': 1, 'to': 0}]} Notes ----- Graph, node, and link attributes are stored in this format. Note that attribute keys will be converted to strings in order to comply with JSON. Attribute 'key' is only used for multigraphs. To use `node_link_data` in conjunction with `node_link_graph`, the keyword names for the attributes must match. See Also -------- node_link_graph, adjacency_data, tree_data """ multigraph = G.is_multigraph() # Allow 'key' to be omitted from attrs if the graph is not a multigraph. key = None if not multigraph else key if len({source, target, key}) < 3: raise nx.NetworkXError("Attribute names are not unique.") data = { "directed": G.is_directed(), "multigraph": multigraph, "graph": G.graph, "nodes": [{**G.nodes[n], name: n} for n in G], } if multigraph: data[link] = [ {**d, source: u, target: v, key: k} for u, v, k, d in G.edges(keys=True, data=True) ] else: data[link] = [{**d, source: u, target: v} for u, v, d in G.edges(data=True)] return data
(G, *, source='source', target='target', name='id', key='key', link='links')
[ -0.013870835304260254, 0.022274475544691086, -0.019424965605139732, -0.02807008847594261, -0.024129072204232216, 0.052237797528505325, -0.07391339540481567, 0.027123471722006798, 0.10107550024986267, -0.055637892335653305, 0.006264092400670052, 0.012054876424372196, 0.0487217903137207, 0.04891498014330864, -0.011987260542809963, -0.023916564881801605, -0.0029750815592706203, 0.03921698406338692, 0.0301758274435997, 0.04134204238653183, -0.013474801555275917, -0.028050769120454788, 0.010335510596632957, -0.011079281568527222, 0.0026128557510674, 0.004373273346573114, 0.036377135664224625, 0.028553055599331856, 0.011378721334040165, 0.07882034778594971, -0.021810825914144516, -0.10849388688802719, -0.016556136310100555, 0.03175996243953705, 0.02893943153321743, 0.0032576178200542927, -0.029171254485845566, 0.016594773158431053, -0.13445822894573212, -0.036686234176158905, -0.016053849831223488, -0.0072928136214613914, -0.0433511883020401, -0.00462200166657567, 0.041535232216119766, 0.017695941030979156, -0.03104517050087452, 0.03500550612807274, -0.04860587790608406, -0.08554325997829437, 0.002092458074912429, -0.04083975777029991, -0.01704876311123371, 0.059501633048057556, -0.03991245850920677, -0.006679444573819637, -0.019956229254603386, 0.061665330082178116, 0.015918618068099022, 0.041882969439029694, 0.022100606933236122, 0.0033445521257817745, 0.03857946768403053, -0.026118898764252663, -0.04597853496670723, 0.022177880629897118, -0.07039738446474075, -0.04628763347864151, -0.03264862298965454, 0.02389724738895893, -0.012112832628190517, 0.026949603110551834, 0.040028370916843414, 0.021868782117962837, 0.03067811392247677, 0.03991245850920677, -0.0023749941028654575, 0.010644610039889812, -0.0696246400475502, -0.0005231145187281072, 0.012238403782248497, -0.03510209918022156, -0.02099943906068802, -0.03942948952317238, 0.03233952447772026, -0.02254493720829487, -0.007287984248250723, 0.06846551597118378, -0.015155529603362083, -0.07851124554872513, -0.02801213227212429, -0.015628838911652565, -0.018449369817972183, 0.04794904217123985, -0.0187874473631382, -0.038791973143815994, 0.0036101844161748886, -0.03402025252580643, 0.048064954578876495, 0.04702174663543701, 0.001349895028397441, 0.014006066136062145, -0.04659673199057579, 0.04752403125166893, -0.00444088876247406, -0.0773521214723587, -0.034425944089889526, -0.0027287681587040424, -0.05088548734784126, -0.029016705229878426, -0.07429976761341095, -0.0023592975921928883, 0.05447876825928688, -0.019627811387181282, 0.075806625187397, 0.0627858117222786, 0.019598834216594696, -0.008253919892013073, -0.03119971975684166, -0.0441625751554966, -0.002348430920392275, 0.047755856066942215, -0.012769668363034725, 0.0006689103902317584, -0.007751633413136005, -0.03861810639500618, 0.02693028375506401, -0.002528336364775896, 0.011948623694479465, -0.04891498014330864, 0.035546429455280304, 0.008606486022472382, -0.019956229254603386, 0.08005674183368683, 0.05760839954018593, -0.0095772510394454, -0.05741521343588829, 0.023510873317718506, 0.036995332688093185, 0.021868782117962837, 0.021868782117962837, -0.06595408171415329, 0.014498692937195301, -0.00357879139482975, -0.012653755955398083, -0.06869734078645706, 0.02312449738383293, -0.021636957302689552, -0.030253103002905846, -0.06552907079458237, 0.06069939211010933, -0.02331768535077572, 0.040646571666002274, 0.014527671039104462, -0.01505893561989069, -0.013020811602473259, -0.07758394628763199, -0.008205623365938663, -0.03687942028045654, 0.0274905264377594, 0.010335510596632957, -0.021018758416175842, 0.005703849717974663, 0.009697993285953999, 0.00047330843517556787, -0.001877537346445024, 0.06127895414829254, -0.05977209657430649, 0.015377694740891457, 0.009693163447082043, -0.0002535581006668508, -0.04103294387459755, -0.06502678245306015, -0.00031000495073385537, 0.010857116430997849, 0.01899995282292366, 0.05015137791633606, -0.01751241274178028, 0.029306486248970032, 0.013436163775622845, -0.03434867039322853, -0.014170275069773197, 0.005872888490557671, 0.008244260214269161, -0.018410732969641685, -0.03979654610157013, 0.006017779000103474, -0.03873401880264282, 0.04393075034022331, 0.006578021217137575, 0.0013438579626381397, -0.017058422788977623, -0.045128513127565384, 0.06545179337263107, 0.013957769609987736, -0.0674223080277443, -0.00916672870516777, 0.01114689651876688, -0.04520578682422638, 0.08453868329524994, 0.005356112960726023, -0.018352776765823364, 0.008563019335269928, 0.004503674805164337, -0.00480070011690259, -0.026485953480005264, 0.0232210922986269, -0.019743723794817924, 0.0007135849446058273, -0.015000980347394943, -0.0016469202237203717, -0.018777787685394287, 0.026756417006254196, 0.03434867039322853, -0.044510312378406525, 0.0014561478747054935, -0.041419319808483124, 0.0363578163087368, -0.015677135437726974, -0.04377620294690132, 0.012141810730099678, -0.028205320239067078, 0.009635207243263721, 0.008017265237867832, 0.014508352614939213, -0.07128604501485825, 0.03655100241303444, -0.036222584545612335, 0.025404106825590134, -0.06796322762966156, 0.06436994671821594, 0.0035232501104474068, 0.019801679998636246, 0.015435650944709778, 0.028514418751001358, -0.07232926040887833, 0.0274518895894289, -0.007215538993477821, 0.02544274367392063, 0.011088940314948559, -0.0176090057939291, -0.03002127818763256, -0.018207885324954987, -0.030195146799087524, 0.018401073291897774, -0.01940564624965191, 0.05073093622922897, 0.021289220079779625, -0.013185020536184311, -0.05803341045975685, -0.021714232861995697, 0.016024870797991753, 0.01179407350718975, 0.03038833476603031, -0.028842836618423462, -0.008234601467847824, -0.0025983667001128197, -0.00005263594357529655, -0.02034260332584381, -0.04114885628223419, 0.012982174754142761, -0.051155950874090195, -0.09257526695728302, 0.05529015511274338, 0.055019691586494446, -0.034677088260650635, 0.007104456424713135, 0.028958749026060104, -0.06483359634876251, -0.012112832628190517, 0.08732058107852936, -0.0011718006571754813, 0.021153990179300308, -0.03502482548356056, 0.029576947912573814, -0.004834507592022419, -0.003977240063250065, -0.011262808926403522, 0.03181792050600052, -0.06533588469028473, -0.03695669770240784, -0.011890667490661144, -0.030098553746938705, -0.016237378120422363, -0.012016238644719124, -0.0518900603055954, -0.006838824134320021, 0.018246524035930634, -0.007548786699771881, -0.016758982092142105, 0.05355146899819374, -0.013861175626516342, -0.04891498014330864, 0.04887634143233299, -0.0030765049159526825, 0.03846355527639389, -0.01698114722967148, -0.007645380217581987, 0.0635199248790741, 0.02136649563908577, 0.0565265528857708, -0.0016734834061935544, 0.10486196726560593, -0.019135184586048126, -0.06514269858598709, -0.009045986458659172, 0.0313156321644783, -0.02362678572535515, -0.016488520428538322, 0.0073990668170154095, -0.03998973220586777, 0.005597596988081932, 0.028746243566274643, 0.01559985987842083, -0.04829677939414978, -0.04771721735596657, 0.009514465928077698, 0.0054188985377550125, 0.04957181587815285, 0.015609519556164742, -0.051155950874090195, 0.014682221226394176, -0.0426170788705349, 0.0031561944633722305, 0.023974521085619926, 0.03320886567234993, 0.05614017695188522, 0.055676527321338654, 0.06266990303993225, -0.0027601609472185373, 0.012035558000206947, 0.0005859003285877407, 0.020168734714388847, 0.04733084514737129, -0.06757685542106628, 0.0657995343208313, 0.005191904027014971, -0.030542884021997452, 0.015947597101330757, 0.007915842346847057, -0.019579514861106873, 0.007592253852635622, -0.017898786813020706, -0.017444796860218048, 0.021347176283597946, 0.008761036209762096, 0.013213998638093472, -0.015928277745842934, -0.006891950499266386, -0.015020298771560192, -0.023240409791469574, 0.09767540544271469, 0.020381242036819458, 0.024071116000413895, -0.006833994295448065, -0.05660382658243179, 0.0220426507294178, -0.07039738446474075, -0.019222117960453033, 0.046674009412527084, 0.02378133498132229, 0.05304918438196182, -0.0044746967032551765, 0.007920672185719013, 0.02183014526963234, 0.013387867249548435, 0.007572934962809086, 0.08724330365657806, 0.07561343908309937, -0.03877265378832817, 0.01495268288999796, -0.075806625187397, -0.016517499461770058, 0.020555108785629272, 0.016082827001810074, 0.00818630401045084, 0.038637425750494, -0.026331404224038124, -0.0051774149760603905, -0.032609984278678894, -0.019859636202454567, -0.008765866048634052, 0.013378208503127098, 0.036377135664224625, 0.07240653038024902, -0.011088940314948559, 0.11421222239732742, 0.028282593935728073, -0.0002506904711481184, -0.015899300575256348, -0.032938405871391296, -0.02575184404850006, 0.03309295326471329, 0.04763994365930557, -0.054865140467882156, -0.03799990564584732, 0.04910816624760628, -0.0027215236332267523, -0.05382193252444267, -0.030137190595269203, -0.0008922829874791205, 0.013339570723474026, -0.041419319808483124, -0.00004890048876404762, 0.04520578682422638, -0.010644610039889812, 0.07182697206735611, -0.0348123200237751, 0.03856014832854271, 0.043737564235925674, 0.023916564881801605, 0.017908446490764618, -0.048219505697488785, 0.013465141877532005, 0.07213607430458069, 0.04362165182828903, -0.005467195529490709, 0.03247475624084473, 0.019763043150305748, -0.009258492849767208, -0.003443560330197215, 0.01735786348581314, 0.0037647339049726725, 0.011108259670436382, 0.015715772286057472, 0.008616145700216293, -0.04292617738246918, -0.003907209727913141, -0.03487027436494827, 0.10957573354244232, 0.03732375055551529, -0.032049741595983505, 0.04752403125166893, -0.06209034100174904, 0.01688455417752266, 0.013880494982004166, 0.006437961012125015, -0.04423984885215759, 0.03409752622246742, 0.004998716525733471, -0.010857116430997849, -0.003006474580615759, -0.0020296722650527954, -0.021192627027630806, -0.0736042931675911, -0.029132617637515068, 0.00010406447108834982, 0.026138218119740486, 0.02096080221235752, -0.012035558000206947, 0.034310031682252884, 0.013040130957961082, 0.08755240589380264, -0.05830387398600578, -0.07990219444036484, -0.02955762855708599, -0.0038613276556134224, -0.0073555996641516685, -0.02795417606830597, 0.01366798859089613, 0.022158563137054443, -0.06127895414829254, -0.013687307015061378, 0.0018618408357724547, -0.02074829675257206, 0.021405132487416267, 0.004081077873706818, -0.008128347806632519, -0.06549043208360672, 0.007297643460333347, 0.021153990179300308, 0.030369015410542488, -0.05386056751012802, 0.0039796545170247555, 0.04678992182016373, 0.014247549697756767, -0.038077183067798615, -0.008601656183600426, -0.08121586591005325, -0.07356565445661545, -0.007341110613197088, -0.06081530451774597, 0.06919962912797928, 0.009640037082135677, 0.02254493720829487, 0.020246010273694992, 0.05154232308268547, 0.010354829952120781, 0.004791040439158678, 0.01899995282292366, -0.009596570394933224, 0.010074708610773087, -0.015194167383015156, 0.022776762023568153, -0.010190621018409729, 0.03850219398736954, 0.035237330943346024, -0.003441145643591881, -0.005201563239097595, -0.007669528480619192, -0.032822493463754654, -0.017898786813020706, -0.00010896960884565488, -0.00358603592030704, 0.029750816524028778, 0.01678796112537384, -0.020303966477513313, 0.053976479917764664, -0.007592253852635622, 0.026910966262221336, -0.015000980347394943, 0.035913486033678055, 0.07847260683774948, 0.0472535714507103, -0.01176509540528059, 0.0061192018911242485, -0.019028931856155396, 0.06680410355329514, -0.027374614030122757, -0.057685673236846924, 0.013436163775622845, 0.048528604209423065, 0.02239038795232773, -0.009017009288072586, -0.0557151660323143, 0.07078376412391663, 0.025577975437045097, -0.008036584593355656, -0.04536033421754837, 0.034116845577955246, -0.030600840225815773, 0.039719272404909134, -0.026891646906733513, 0.04640354588627815, -0.01555156335234642, 0.004423985257744789, 0.07202015817165375, 0.05436285585165024, 0.010857116430997849, -0.027355296537280083, 0.046828556805849075, 0.00004176916991127655, -0.01708739995956421, -0.03541119769215584, 0.027123471722006798, 0.005341623909771442, 0.0742611289024353, 0.041419319808483124, 0.03865674138069153, -0.05675837770104408, -0.042810264974832535, -0.02606094256043434, 0.0034097526222467422, 0.02807008847594261, -0.004431229550391436, -0.06440858542919159, 0.008529211394488811, -0.004276679828763008, 0.039835184812545776, -0.01889370009303093, -0.058419786393642426, 0.012692393735051155, -0.05614017695188522, -0.0026683970354497433, 0.029634904116392136, 0.01677830144762993, 0.01612146571278572, -0.012962855398654938, -0.05015137791633606, 0.008563019335269928, -0.012943536974489689, 0.039564721286296844, 0.03444526344537735, -0.023549510166049004, 0.01725161075592041, -0.0009291092865169048, -0.038289688527584076, 0.023143816739320755, 0.03228156641125679, -0.054556041955947876, 0.004578534979373217, 0.04721493273973465, 0.03033037856221199, 0.061665330082178116, 0.020767616108059883, 0.03672487288713455, -0.040955670177936554, 0.03479300066828728, 0.011427017860114574, -0.03693737834692001, -0.03772944584488869, -0.01297251507639885, -0.005317475646734238, -0.02152104489505291, 0.04196024313569069, 0.022216519340872765, 0.008630634285509586, 0.021405132487416267, 0.039159029722213745, -0.057222023606300354, -0.050074100494384766, -0.0032407138496637344, -0.004448133520781994, 0.0034097526222467422, -0.017522072419524193, -0.001355932094156742, -0.023800652474164963, -0.00810902938246727, -0.00826357863843441, -0.04593989625573158, -0.019917592406272888, 0.02018805406987667, -0.03237816318869591, -0.05977209657430649, -0.032358843833208084, -0.028630331158638, -0.009311619214713573, 0.006621488370001316, -0.02909398078918457, -0.023607466369867325, 0.0425398051738739, -0.06131759285926819, -0.008934903889894485, 0.019028931856155396, -0.019695427268743515, -0.00046757320524193347, -0.038695380091667175, 0.018661875277757645, -0.054246943444013596, -0.01565781608223915, -0.004747573286294937, -0.07627027481794357, 0.04671264439821243, 0.03444526344537735, 0.0426170788705349, -0.05756976082921028, 0.04273299127817154, 0.016971489414572716, 0.014421418309211731, 0.012054876424372196, -0.030407652258872986, 0.02847578190267086, -0.02662118524312973, -0.01812095195055008, -0.03434867039322853, 0.014846430160105228, 0.09365711361169815, -0.02640867978334427, 0.016102146357297897, -0.03301567956805229, -0.025925710797309875, 0.0019813755061477423, 0.032609984278678894, 0.009900839999318123, 0.0634426474571228, 0.05127186328172684, -0.0060805645771324635, -0.0016722760628908873, -0.005080821458250284, -0.05312645807862282, 0.013639010488986969, 0.037710126489400864, 0.021694913506507874, -0.039410173892974854, -0.004233212675899267, -0.002646663459017873, -0.00862097553908825, -0.010886094532907009, 0.027104152366518974, 0.05185142159461975, -0.04733084514737129, 0.002145584439858794, 0.014112318865954876, -0.01647886075079441, 0.030716752633452415, -0.05710611119866371, 0.036319177597761154, -0.02198469452559948, -0.016643069684505463, -0.017802193760871887, 0.0009309204178862274, 0.04377620294690132, -0.01289524044841528, 0.012653755955398083, -0.047755856066942215, 0.019627811387181282, 0.026949603110551834, -0.03774876147508621, -0.011030984111130238, 0.025925710797309875, 0.04199887812137604, -0.044510312378406525, 0.035758934915065765, -0.01669136807322502, -0.004339465871453285, -0.05513560399413109, -0.011475315317511559, 0.004445718601346016, -0.01632431149482727, -0.035855527967214584, 0.014170275069773197, 0.027934856712818146, 0.019338030368089676, 0.0007250554044730961, 0.007495660334825516, -0.041882969439029694, -0.031122444197535515, 0.031238356605172157, -0.011678161099553108, -0.025268875062465668, -0.035913486033678055, -0.014691880904138088, 0.013977088034152985, 0.0032431287690997124, 0.018062995746731758, -0.026814373210072517, -0.05467195436358452, 0.005993630271404982, -0.047176294028759, 0.035913486033678055, 0.017019785940647125, 0.01292421855032444, 0.04524442180991173, 0.057647038251161575, -0.008234601467847824, 0.009910499677062035, -0.005341623909771442, -0.053976479917764664, 0.038695380091667175, -0.032822493463754654, -0.003354211337864399, 0.11513952165842056, 0.0024112167302519083, 0.030562201514840126, -0.00687263160943985, -0.05629472807049751, -0.020671021193265915, 0.0031272165942937136, -0.00048176039126701653, 0.04292617738246918, -0.04118749499320984, 0.035082779824733734, -0.00617715809494257, -0.03432935103774071, 0.04431712627410889, -0.013812879100441933, -0.0034991016145795584, 0.024071116000413895, -0.010258235968649387, -0.029924685135483742, 0.013252636417746544, 0.009495146572589874, -0.048837702721357346, -0.05204461142420769, 0.06564498692750931, -0.0016336386324837804, -0.031644050031900406, 0.003008889500051737, 0.021714232861995697, -0.07337246835231781, -0.026891646906733513, 0.005245030391961336, 0.012190107256174088, -0.038540828973054886, -0.03579757362604141, 0.008997689932584763, 0.02260289341211319, 0.05869024619460106 ]
30,952
networkx.classes.function
nodes
Returns a NodeView over the graph nodes. This function wraps the :func:`G.nodes <networkx.Graph.nodes>` property.
def nodes(G): """Returns a NodeView over the graph nodes. This function wraps the :func:`G.nodes <networkx.Graph.nodes>` property. """ return G.nodes()
(G)
[ -0.032410748302936554, -0.04763318970799446, -0.01142117939889431, -0.0431099496781826, -0.006380376871675253, 0.08385390043258667, -0.03491592779755592, 0.012317128479480743, 0.13534924387931824, 0.015909625217318535, 0.005062548443675041, -0.02167675457894802, 0.03782124072313309, 0.03084501251578331, -0.006723969243466854, -0.019397737458348274, -0.026060817763209343, -0.0502079576253891, 0.043388303369283676, 0.011499466374516487, -0.03611632436513901, -0.04004806652665138, 0.04634580388665199, -0.053409017622470856, -0.029818585142493248, -0.01758844219148159, 0.04599786549806595, -0.0012602005153894424, 0.002848770935088396, 0.024756036698818207, -0.0775909498333931, -0.050312340259552, -0.06082016974687576, -0.036986179649829865, 0.007124101743102074, 0.05330463498830795, 0.007959161885082722, 0.034898530691862106, 0.006650031544268131, 0.006663079373538494, -0.01955431140959263, -0.01588352955877781, -0.00685879634693265, -0.037960417568683624, -0.01747536100447178, -0.015431204810738564, 0.07689506560564041, 0.009490104392170906, 0.017318787053227425, -0.051634516566991806, 0.025069184601306915, -0.03171486780047417, -0.038934651762247086, 0.012995614670217037, -0.015039770863950253, 0.013665401376783848, 0.04349268600344658, 0.048224691301584244, -0.00045422674156725407, 0.047006893903017044, -0.013752386905252934, -0.022755373269319534, 0.007615569047629833, -0.0022116031032055616, -0.017005639150738716, 0.023607829585671425, -0.021328812465071678, -0.020545944571495056, -0.011995282955467701, -0.02901832014322281, -0.027643950656056404, 0.00772430095821619, 0.04220530390739441, -0.002520401030778885, 0.02461685985326767, 0.020789504051208496, -0.02614780329167843, 0.04324912652373314, -0.025852052494883537, -0.02167675457894802, 0.006219454109668732, 0.004140503704547882, -0.01194309163838625, 0.049268513917922974, 0.09512720257043839, -0.06047223135828972, -0.012586783617734909, 0.02369481511414051, 0.015726955607533455, -0.011534260585904121, -0.030375290662050247, 0.026652317494153976, -0.02430371195077896, 0.020006636157631874, -0.030827615410089493, 0.017397074028849602, -0.020128414034843445, -0.02790490724146366, 0.012499798089265823, 0.009211750701069832, -0.012499798089265823, 0.09457049518823624, -0.05006878077983856, 0.04752880707383156, -0.04130065441131592, -0.06864885240793228, -0.08823796361684799, -0.0027422138955444098, 0.010725296102464199, -0.005480078514665365, -0.028861746191978455, 0.03635988384485245, 0.08656784147024155, 0.0024573367554694414, 0.05935881659388542, 0.008916000835597515, 0.02912270277738571, -0.012578085064888, -0.01777981035411358, 0.015587778761982918, -0.03023611567914486, 0.029488040134310722, 0.016466330736875534, 0.018371310085058212, -0.006058530882000923, 0.010638310573995113, 0.033802516758441925, 0.007624267600476742, -0.007219785824418068, -0.05935881659388542, 0.048885777592659, 0.013795879669487476, -0.0049407691694796085, 0.042727213352918625, 0.02809627540409565, 0.002022409811615944, -0.006563046481460333, 0.016701191663742065, 0.033263206481933594, 0.06513464450836182, -0.08204460144042969, -0.03872588649392128, 0.008594154380261898, 0.05765390396118164, -0.011647340841591358, -0.02179853431880474, 0.012630275450646877, 0.023973168805241585, -0.016214072704315186, -0.03938697651028633, 0.030009953305125237, 0.0026508790906518698, 0.10055509209632874, 0.014222107827663422, -0.04812030866742134, 0.01459614560008049, -0.02980118803679943, -0.05514872446656227, -0.015787845477461815, 0.01600530743598938, -0.04829427972435951, 0.006876193452626467, 0.011873503215610981, 0.021102651953697205, 0.015561683103442192, 0.00036397940129972994, 0.06113331764936447, -0.052921898663043976, -0.03959574177861214, 0.01752755232155323, 0.012717260979115963, -0.030862409621477127, -0.08301883935928345, -0.02755696512758732, 0.056575287133455276, 0.013395747169852257, 0.024843022227287292, 0.027748333290219307, -0.0071067046374082565, 0.0560881681740284, -0.028426818549633026, -0.0030183924827724695, -0.04182256758213043, -0.025156170129776, 0.007037116680294275, -0.0021278795320540667, 0.011029745452105999, -0.009272640570998192, -0.017692824825644493, -0.03775165230035782, 0.01979787088930607, 0.014665734022855759, 0.02938365750014782, 0.0406743586063385, 0.007398105692118406, -0.021955108270049095, -0.03976971283555031, 0.008450629189610481, -0.0897689014673233, 0.05977634713053703, 0.03383731096982956, 0.014091630466282368, 0.026530537754297256, 0.0005406684358604252, -0.004988611210137606, 0.02106785774230957, -0.020545944571495056, -0.030323101207613945, -0.022929344326257706, -0.03420264646410942, 0.022094285115599632, -0.009307434782385826, -0.011029745452105999, 0.046450186520814896, -0.07115403562784195, 0.005240868777036667, -0.07599042356014252, 0.007580775301903486, -0.00909866951406002, -0.05480078235268593, -0.005627953447401524, -0.026774097234010696, -0.028426818549633026, -0.05553146079182625, 0.013360952958464622, -0.05594899132847786, -0.012186650186777115, -0.06388205289840698, -0.00490162568166852, -0.0990937352180481, 0.06283823400735855, 0.0029096605721861124, -0.024895213544368744, 0.020632930099964142, 0.018788840621709824, -0.03312402963638306, 0.014056836254894733, 0.011464672163128853, 0.03152349963784218, 0.02174634300172329, -0.07341565191745758, -0.05027754604816437, 0.008137481287121773, 0.036916591227054596, 0.037160150706768036, 0.03750809282064438, -0.03980450704693794, 0.016335852444171906, 0.013169584795832634, 0.001488537178374827, -0.06179440766572952, -0.08301883935928345, 0.034046072512865067, 0.0001862030621850863, 0.0019691314082592726, 0.0032684754114598036, -0.05473119392991066, 0.02082429826259613, 0.007537282537668943, -0.01943253166973591, -0.03157569095492363, 0.023190299049019814, -0.04860742390155792, 0.052921898663043976, 0.05775828659534454, 0.008254911750555038, 0.05055589601397514, 0.027400391176342964, -0.06861405819654465, -0.009672773070633411, 0.08260130882263184, 0.06652641296386719, 0.0014059010427445173, -0.03848232701420784, 0.0548703707754612, -0.03079282119870186, -0.03510729596018791, 0.02792230434715748, 0.0006181398057378829, -0.021207032725214958, -0.03352416306734085, 0.014387380331754684, -0.0502079576253891, 0.010664406232535839, -0.050312340259552, -0.027104642242193222, 0.003064059652388096, 0.011864804662764072, -0.04109188914299011, -0.057027608156204224, 0.05250437185168266, -0.005536618642508984, 0.010029413737356663, -0.006175961345434189, 0.018110353499650955, 0.03201061487197876, -0.07024938613176346, 0.04502362757921219, -0.027591759338974953, 0.07021459192037582, 0.0751553624868393, -0.04606745392084122, -0.0017320961924269795, 0.0012971693649888039, 0.04397980496287346, 0.05511393025517464, 0.041196271777153015, 0.030149130150675774, 0.013943755067884922, 0.000390618690289557, -0.08587195724248886, -0.026478346437215805, 0.011751723475754261, -0.031123366206884384, -0.07717341929674149, -0.06457793712615967, -0.023120712488889694, 0.002787881065160036, 0.041857361793518066, 0.004077439196407795, -0.019275957718491554, 0.040291622281074524, -0.06262946873903275, 0.04631101340055466, -0.0620727613568306, 0.09951126575469971, 0.01674468442797661, 0.07863477617502213, -0.028009289875626564, 0.007154546678066254, -0.0007497051847167313, -0.015848735347390175, 0.008628948591649532, 0.029888173565268517, -0.05288710445165634, 0.0034728909377008677, 0.08545442670583725, 0.0026465298142284155, 0.012760753743350506, -0.000039687074604444206, 0.00882901530712843, 0.03155829384922981, -0.049686044454574585, 0.0346897654235363, 0.007024068851023912, 0.030984189361333847, 0.015231138095259666, -0.020754709839820862, 0.01660550758242607, -0.03583797439932823, -0.003725148504599929, 0.08942095935344696, -0.019136780872941017, -0.024408094584941864, -0.003579447977244854, 0.02600862644612789, 0.042100921273231506, 0.012143157422542572, -0.03491592779755592, 0.05504434183239937, -0.04244885966181755, 0.014831005595624447, 0.034237440675497055, -0.019693488255143166, 0.030931998044252396, -0.008385390043258667, 0.04130065441131592, 0.03060145303606987, 0.04641539230942726, -0.06955350190401077, -0.0035685747861862183, -0.021467989310622215, -0.0875420793890953, 0.034846339374780655, -0.029227085411548615, 0.013326158747076988, 0.004866831470280886, -0.03267170488834381, 0.017866795882582664, -0.0061411671340465546, 0.0179015900939703, -0.02296413853764534, 0.03879547491669655, 0.003318491857498884, 0.02705245092511177, 0.009785854257643223, 0.042657624930143356, 0.013848070986568928, -0.012934724800288677, -0.02296413853764534, -0.04317953810095787, -0.03517688438296318, -0.04147462546825409, 0.05295669287443161, -0.04780716076493263, -0.037229739129543304, 0.04196174442768097, -0.0340808667242527, -0.011716929264366627, -0.07821724563837051, 0.022703181952238083, 0.018545281141996384, -0.008354945108294487, 0.007267627865076065, -0.011629943735897541, 0.016448933631181717, 0.017562346532940865, -0.041370242834091187, 0.06047223135828972, -0.029731599614024162, 0.008533264510333538, 0.0050016590394079685, 0.0007029505213722587, -0.02600862644612789, 0.07007541507482529, 0.003714275313541293, 0.01788419298827648, 0.057375550270080566, 0.06638723611831665, 0.0002241232432425022, 0.019015002995729446, -0.03561181202530861, 0.02546931616961956, 0.039734918624162674, 0.0329674556851387, 0.020980872213840485, -0.02999255619943142, -0.01215185597538948, -0.0037686412688344717, 0.05111260339617729, 0.026861082762479782, -0.033019647002220154, 0.029714202508330345, -0.02529534511268139, 0.021485386416316032, -0.03528126701712608, 0.019571708515286446, -0.03152349963784218, -0.02797449566423893, 0.07174553722143173, 0.009116066619753838, 0.023172901943325996, 0.02002403326332569, -0.036986179649829865, 0.021607166156172752, -0.030931998044252396, -0.0048798792995512486, -0.0019038922619074583, 0.01365670282393694, -0.030740629881620407, 0.02400796301662922, 0.006001990754157305, 0.0621771439909935, -0.01459614560008049, -0.0465545691549778, 0.023468652740120888, -0.0693795308470726, -0.028009289875626564, -0.07209347188472748, 0.008133132010698318, 0.010212082415819168, -0.005980244372040033, -0.029470643028616905, -0.008381040766835213, -0.017788508906960487, -0.04558033496141434, 0.030323101207613945, -0.0538613423705101, -0.026339169591665268, 0.018058162182569504, 0.0610637292265892, -0.033611148595809937, -0.044745273888111115, -0.11809133738279343, 0.021885519847273827, 0.04679812863469124, -0.011977885849773884, 0.015126756392419338, -0.03733412176370621, -0.06391684710979462, -0.07821724563837051, -0.0417877733707428, 0.06885761767625809, 0.03604673594236374, -0.014961483888328075, 0.08608072251081467, 0.014909292571246624, -0.01887582615017891, -0.012847739271819592, -0.05977634713053703, 0.04154421389102936, -0.012630275450646877, -0.057514727115631104, -0.021537577733397484, 0.02712203934788704, 0.050416722893714905, -0.001988703152164817, -0.05434846132993698, -0.022024696692824364, 0.03931738808751106, -0.006406472530215979, 0.036499060690402985, 0.05295669287443161, 0.03150610253214836, 0.051878076046705246, -0.05490516498684883, 0.03736891597509384, 0.019832665100693703, 0.02755696512758732, -0.0009601010242477059, 0.042483653873205185, 0.0019169400911778212, 0.021207032725214958, -0.003416350344195962, 0.009672773070633411, 0.0016581586096435785, -0.06965788453817368, 0.025069184601306915, 0.022094285115599632, -0.017849398776888847, 0.018823634833097458, 0.005106041207909584, 0.04380583390593529, -0.018841031938791275, -0.011769120581448078, 0.06088975816965103, -0.00633688410744071, -0.0098641412332654, -0.018353912979364395, 0.06603929400444031, 0.029888173565268517, 0.010377354919910431, -0.041509419679641724, 0.05452243238687515, -0.03660344332456589, -0.011986584402620792, 0.03157569095492363, -0.02809627540409565, -0.016231469810009003, 0.032045409083366394, 0.004094836302101612, -0.023225093260407448, -0.004827687982469797, 0.04251844808459282, 0.001763628446497023, 0.0179015900939703, 0.06496067345142365, -0.039004240185022354, 0.00005888501982553862, -0.027504773810505867, -0.021363606676459312, -0.05354819446802139, -0.009872839786112309, -0.019206369295716286, 0.06078537553548813, 0.020719915628433228, -0.039247799664735794, -0.04074394702911377, -0.0009519461309537292, -0.03768206387758255, 0.02277277037501335, -0.04227488860487938, -0.0140220420435071, 0.0011427702847868204, -0.020128414034843445, 0.003694703569635749, 0.015039770863950253, 0.012647672556340694, 0.030566658824682236, 0.02962721697986126, 0.010046809911727905, -0.02002403326332569, 0.03131473436951637, -0.0027052450459450483, 0.013456637039780617, 0.004175297915935516, -0.005488777067512274, 0.0561925508081913, -0.005836718250066042, -0.07550330460071564, -0.05654049292206764, -0.0011014522751793265, 0.008315801620483398, 0.00633688410744071, 0.014709225855767727, 0.04759839549660683, -0.042414065450429916, 0.017388375476002693, 0.0383431501686573, -0.015370314940810204, 0.032950058579444885, -0.014274299144744873, 0.050347134470939636, 0.0005371346487663686, -0.019571708515286446, -0.013239173218607903, -0.0647171139717102, 0.041613802313804626, 0.018127750605344772, -0.034776750952005386, 0.02607821486890316, 0.04471047967672348, 0.03963053598999977, -0.006937083322554827, -0.006906638387590647, -0.01637934520840645, 0.005788876675069332, -0.01931075192987919, 0.024408094584941864, -0.036499060690402985, -0.01365670282393694, 0.004892927128821611, -0.02425152063369751, -0.05344381183385849, -0.001429822063073516, 0.029783790931105614, -0.03743850439786911, 0.0549747534096241, -0.026739303022623062, -0.008272308856248856, 0.011960488744080067, -0.015161550603806973, -0.026582729071378708, 0.006284693256020546, 0.018179941922426224, -0.006471711676567793, 0.012926026247441769, -0.03096679225564003, -0.007963511161506176, 0.01943253166973591, 0.021694151684641838, -0.059950318187475204, 0.026060817763209343, 0.027835318818688393, -0.011795216239988804, -0.07619918137788773, -0.016927354037761688, -0.0009965262142941356, -0.04488445073366165, 0.017753714695572853, -0.05069507285952568, 0.0006855534738861024, -0.019867459312081337, -0.03670782595872879, -0.02228565141558647, -0.06409081816673279, 0.015361616387963295, 0.025991229340434074, 0.0490945428609848, -0.038760680705308914, -0.007715602405369282, 0.009829347021877766, 0.024825625121593475, 0.0033554607070982456, -0.012447606772184372, 0.00882031675428152, -0.0027574363630264997, 0.008550661616027355, 0.02914009988307953, -0.052921898663043976, -0.0069936239160597324, 0.02425152063369751, 0.040709152817726135, 0.050173163414001465, 0.06102893501520157, 0.00481029087677598, 0.028966128826141357, -0.020250193774700165, -0.007528583984822035, 0.039247799664735794, -0.018249530345201492, -0.010125096887350082, 0.02626958116889, -0.014248203486204147, -0.012943423353135586, -0.014222107827663422, 0.04352748021483421, 0.052121635526418686, 0.029470643028616905, -0.02021539956331253, 0.00867679063230753, 0.04530198127031326, -0.027330802753567696, -0.03757768124341965, -0.054765988141298294, -0.01267376821488142, -0.06078537553548813, -0.009272640570998192, 0.056157756596803665, -0.009846744127571583, -0.004775496665388346, -0.049929603934288025, 0.06930994242429733, 0.055914197117090225, 0.010342560708522797, 0.05257395654916763, 0.008085289970040321, -0.00885946024209261, -0.005445284303277731, -0.010246876627206802, 0.018423501402139664, -0.005436585750430822, -0.04631101340055466, 0.007315469905734062, 0.0008589805220253766, -0.03371553122997284, 0.0011699532624334097, 0.02418193407356739, -0.046450186520814896, 0.02731340564787388, -0.002598688006401062, -0.010290369391441345, 0.01771892048418522, 0.00467111449688673, 0.05473119392991066, -0.016657698899507523, 0.028426818549633026, -0.02914009988307953, -0.03907382860779762, 0.017301389947533607, 0.021172238513827324, -0.028235452249646187, 0.028305040672421455, 0.07863477617502213, 0.013421842828392982, 0.055427078157663345, 0.0016548966523259878, -0.04237927123904228, -0.0006349931936711073, 0.005384394433349371, 0.03333279490470886, 0.04784195497632027, 0.012125760316848755, -0.031227748841047287, -0.06102893501520157, -0.023364270105957985, -0.012630275450646877, 0.03333279490470886, -0.049512073397636414, 0.017362279817461967, 0.012839040718972683, -0.019015002995729446, 0.0015635620802640915, -0.02900092303752899, 0.03987409546971321, -0.05173889920115471, 0.01630105823278427, 0.02218126878142357, -0.010029413737356663, 0.006663079373538494, 0.06750065088272095, 0.03517688438296318, 0.005554015748202801, -0.060994140803813934, 0.057862669229507446, -0.004984261933714151, -0.003960009198635817, -0.011751723475754261, -0.029227085411548615, -0.08914260566234589, -0.05807143449783325, -0.03242814540863037, -0.05424407869577408, -0.03260211646556854, -0.026113009080290794, 0.0065108551643788815, 0.04401459917426109, 0.03688179701566696 ]
30,953
networkx.classes.function
nodes_with_selfloops
Returns an iterator over nodes with self loops. A node with a self loop has an edge with both ends adjacent to that node. Returns ------- nodelist : iterator A iterator over nodes with self loops. See Also -------- selfloop_edges, number_of_selfloops Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> list(nx.nodes_with_selfloops(G)) [1]
def nodes_with_selfloops(G): """Returns an iterator over nodes with self loops. A node with a self loop has an edge with both ends adjacent to that node. Returns ------- nodelist : iterator A iterator over nodes with self loops. See Also -------- selfloop_edges, number_of_selfloops Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> list(nx.nodes_with_selfloops(G)) [1] """ return (n for n, nbrs in G._adj.items() if n in nbrs)
(G)
[ 0.020707830786705017, -0.04267943650484085, -0.053259026259183884, 0.023578403517603874, -0.058169689029455185, 0.04517087712883949, -0.039213087409734726, 0.022368790581822395, 0.13887065649032593, -0.01617630012333393, -0.010733047500252724, -0.0040192510932683945, 0.03737158700823784, 0.024914391338825226, 0.0022702787537127733, 0.011807255446910858, -0.04361823946237564, -0.025058822706341743, 0.009460247121751308, 0.05011764541268349, -0.025672655552625656, 0.008453741669654846, 0.049901001155376434, -0.006066112779080868, -0.02489633858203888, 0.03892422467470169, 0.0021393881179392338, 0.02895846776664257, -0.039393626153469086, 0.010173376649618149, -0.056761484593153, -0.060408372431993484, -0.04322105273604393, -0.03964637964963913, 0.04993710666894913, 0.06354975700378418, -0.07275724411010742, 0.02117723412811756, -0.06354975700378418, -0.008643307723104954, 0.09315816313028336, -0.02292846143245697, -0.017756016924977303, -0.004360018763691187, 0.021429987624287605, -0.021466095000505447, 0.07300999760627747, 0.010877478867769241, -0.012637735344469547, -0.05376453697681427, 0.023163162171840668, 0.018433040007948875, -0.004610516596585512, -0.018848279491066933, -0.010787209495902061, 0.0234700795263052, -0.024950500577688217, -0.03007780946791172, -0.02538379281759262, 0.031486015766859055, -0.038021527230739594, -0.028434904292225838, 0.021213341504335403, 0.0357467345893383, 0.021213341504335403, -0.02207992784678936, -0.038238175213336945, -0.027604423463344574, 0.00783088244497776, 0.002027679467573762, -0.017710883170366287, -0.004824906587600708, 0.03392329066991806, 0.03812985122203827, 0.012917570769786835, -0.012737032026052475, -0.03509679436683655, 0.05860298126935959, 0.020310645923018456, -0.015210417099297047, 0.0175393708050251, 0.05737531557679176, -0.0737682655453682, -0.05538938567042351, 0.038454823195934296, -0.04549584537744522, -0.022314628586173058, 0.03161239251494408, -0.00895022414624691, -0.0057140616700053215, -0.027207238599658012, 0.0027667612303048372, 0.007862476631999016, 0.030781911686062813, 0.027369722723960876, 0.01635684072971344, -0.023849211633205414, -0.05224800854921341, -0.01890244148671627, -0.020238429307937622, 0.018216392025351524, 0.08124258369207382, -0.03256924822926521, 0.03910476341843605, 0.018649686127901077, -0.051381420344114304, -0.07958162575960159, -0.02493244595825672, 0.029734784737229347, -0.0059803565964102745, -0.04661518707871437, 0.03181098401546478, 0.025094931945204735, -0.036938294768333435, -0.004748177714645863, 0.017575478181242943, 0.04235446825623512, 0.016257543116807938, 0.03455517813563347, -0.03359832242131233, 0.01717829331755638, 0.002809639321640134, -0.030312510207295418, 0.031070774421095848, -0.00592168141156435, 0.016311705112457275, 0.037696558982133865, -0.0018200594931840897, -0.017575478181242943, -0.07236006110906601, 0.10276284068822861, 0.027315562590956688, -0.001528940279968083, 0.0835534855723381, 0.00996575690805912, 0.006075139623135328, -0.026124004274606705, 0.013711942359805107, 0.03513290360569954, 0.007591668050736189, -0.029193168506026268, -0.07394880056381226, -0.006449758540838957, 0.07481539249420166, -0.04704848304390907, -0.0023808591067790985, -0.029554245993494987, 0.027496101334691048, 0.04437650367617607, -0.05015375465154648, 0.011382988654077053, 0.016582513228058815, 0.11431734263896942, 0.05369231849908829, -0.05055094137787819, 0.028146041557192802, -0.02820020355284214, 0.013820266351103783, 0.0038703063037246466, -0.010380996391177177, -0.04459315165877342, 0.022224359214305878, 0.008611713536083698, -0.011446177028119564, 0.003432499011978507, -0.03293032571673393, -0.02726140059530735, -0.013179352506995201, -0.003484404180198908, 0.04491811990737915, 0.02202576771378517, -0.07878725230693817, 0.007230589631944895, -0.009758137166500092, -0.034609340131282806, 0.05354788899421692, 0.017575478181242943, 0.03134158253669739, -0.0007120009395293891, 0.04459315165877342, -0.011265638284385204, -0.009369977749884129, -0.05643651261925697, -0.06611340492963791, 0.03567451983690262, 0.019371842965483665, 0.010245592333376408, 0.0035408225376158953, 0.017097050324082375, -0.024607475847005844, -0.0019046872621402144, -0.009532462805509567, 0.002344751264899969, 0.056833699345588684, 0.02310900203883648, -0.0035543630365282297, -0.011536446399986744, 0.028525173664093018, -0.038815900683403015, 0.06279148906469345, 0.010417104698717594, 0.01993151381611824, -0.016158247366547585, 0.014045939780771732, -0.0170880239456892, 0.006291786674410105, -0.022639600560069084, -0.019462112337350845, -0.02132166363298893, -0.02083420939743519, -0.029084844514727592, -0.007709018420428038, 0.022422952577471733, 0.058025259524583817, -0.0057140616700053215, 0.0250227153301239, -0.07423766702413559, 0.004712069872766733, -0.016194354742765427, -0.03343583643436432, -0.00547484727576375, -0.033760808408260345, -0.06094999238848686, -0.05751974880695343, 0.01023656502366066, -0.01711510494351387, 0.014695880934596062, -0.008936683647334576, 0.02940981462597847, -0.009803271852433681, 0.0283807422965765, 0.032154008746147156, -0.001642905524931848, -0.02605178765952587, 0.023253433406352997, 0.007280237972736359, -0.00671605346724391, 0.004231384489685297, -0.0038161445409059525, -0.02337981015443802, -0.07560976594686508, -0.05282573401927948, -0.011238557286560535, -0.012348872609436512, 0.05578657239675522, 0.02529352344572544, 0.013007840141654015, 0.04152398556470871, 0.007695477921515703, 0.06878538429737091, -0.04441261291503906, -0.05546160414814949, -0.009135277010500431, -0.013441134244203568, 0.018405959010124207, -0.05055094137787819, -0.08131479471921921, -0.04571249336004257, 0.01641100086271763, 0.05954178795218468, 0.012150279246270657, 0.020707830786705017, -0.03616197779774666, 0.05528106540441513, 0.0037168480921536684, 0.06719664484262466, 0.004459314979612827, 0.02538379281759262, -0.017647694796323776, 0.018703848123550415, 0.07582641392946243, -0.04769842326641083, 0.030908288434147835, -0.005840438883751631, 0.024878283962607384, 0.004657907877117395, -0.017674775794148445, 0.04571249336004257, -0.05282573401927948, -0.02820020355284214, -0.012096118181943893, 0.03379691392183304, -0.05037040263414383, -0.023704780265688896, -0.07167401164770126, -0.06311646103858948, 0.004540557507425547, 0.008656848222017288, -0.0050415536388754845, -0.04130734130740166, 0.06827987730503082, -0.01345016062259674, 0.05520884692668915, 0.009532462805509567, 0.06268316507339478, -0.000539078377187252, -0.01975097507238388, 0.022639600560069084, 0.011292719282209873, 0.033273350447416306, 0.09857433289289474, -0.04777063801884651, -0.06629394739866257, -0.0315040685236454, -0.01863163150846958, 0.04080183058977127, 0.012321791611611843, 0.05524495616555214, -0.018577471375465393, -0.0028028690721839666, -0.06643837690353394, -0.004048588685691357, 0.01687137596309185, -0.03347194567322731, -0.0036694565787911415, -0.07495982199907303, 0.03607170656323433, -0.011428123340010643, -0.0035927274730056524, 0.038274284452199936, -0.02020232193171978, 0.042571112513542175, -0.016122139990329742, 0.05806136503815651, -0.01790044829249382, 0.07474317401647568, 0.045604169368743896, 0.051959145814180374, -0.0077767204493284225, 0.018667740747332573, 0.020996693521738052, -0.04715680703520775, -0.03562035784125328, 0.041993387043476105, -0.041993387043476105, 0.029066789895296097, 0.06770215183496475, 0.04434039443731308, -0.02198965847492218, -0.07669299840927124, 0.005863006226718426, 0.009081115014851093, 0.003218109020963311, -0.009604678489267826, 0.013116163201630116, 0.05322291702032089, -0.023072892799973488, -0.043329376727342606, 0.03170266002416611, 0.028218256309628487, 0.03204568475484848, 0.08528665453195572, 0.0012468480272218585, -0.006810836493968964, 0.04361823946237564, 0.021032802760601044, 0.01572495326399803, 0.008882522583007812, -0.02874181978404522, 0.054017290472984314, 0.01756645180284977, 0.012041956186294556, 0.026665620505809784, -0.02704475261271, -0.018270554021000862, -0.03137769177556038, 0.009496355429291725, 0.045387521386146545, 0.023885319009423256, 0.004048588685691357, -0.05029818415641785, -0.016104085370898247, -0.05784471705555916, -0.03293032571673393, -0.03083607368171215, -0.0027193697169423103, 0.048781655728816986, -0.011996821500360966, 0.01671791821718216, 0.008801279589533806, -0.019949568435549736, -0.0388881154358387, 0.03204568475484848, -0.0008767428807914257, 0.03083607368171215, -0.03471766412258148, 0.03513290360569954, -0.007898584008216858, 0.06802712380886078, -0.0018313431646674871, -0.04899830371141434, -0.034121885895729065, 0.029283437877893448, 0.03379691392183304, -0.048203933984041214, -0.049323275685310364, 0.09279708564281464, 0.027062807232141495, 0.011680877767503262, -0.0701574832201004, -0.03256924822926521, 0.0006905619520694017, 0.0009895798284560442, 0.03838260844349861, 0.009758137166500092, 0.017223427072167397, -0.006057085935026407, -0.041090693324804306, 0.04174063354730606, 0.028543228283524513, -0.04062129184603691, -0.010380996391177177, 0.007645829580724239, -0.029175113886594772, 0.057266995310783386, -0.03262341022491455, -0.029193168506026268, 0.07026580721139908, 0.0643802359700203, 0.032244279980659485, -0.008340905420482159, -0.037913206964731216, 0.06860484927892685, 0.018162230029702187, -0.019426004961133003, -0.0018550389213487506, 0.030944397673010826, -0.007036510389298201, -0.0473734512925148, 0.04795117676258087, -0.03132352977991104, -0.047084588557481766, 0.05264519527554512, -0.037696558982133865, -0.0011509365867823362, 0.014488260261714458, -0.022549329325556755, -0.02341591753065586, 0.00040564872324466705, 0.03569257631897926, 0.01984124444425106, 0.01811709627509117, 0.010209484957158566, -0.02886819839477539, 0.06986862421035767, -0.03007780946791172, 0.001404819660820067, 0.02068977802991867, 0.029518138617277145, 0.024065857753157616, -0.014867392368614674, -0.014316748827695847, 0.013125190511345863, -0.030240295454859734, -0.06069723516702652, 0.02356034889817238, -0.06203322485089302, -0.01338697224855423, -0.04773453250527382, 0.007618749048560858, 0.000864895002450794, 0.03982691839337349, -0.008548525162041187, -0.012836327776312828, 0.004350991453975439, -0.04441261291503906, 0.04242668300867081, 0.023921426385641098, -0.038815900683403015, -0.023307593539357185, 0.004211073741316795, -0.0039041575510054827, -0.03482598811388016, -0.07893168181180954, 0.0478067472577095, 0.007821855135262012, -0.10261841118335724, -0.01178017444908619, -0.025329632684588432, -0.0835534855723381, -0.05661705136299133, -0.029391761869192123, 0.06878538429737091, -0.010444185696542263, -0.004563124850392342, -0.018758010119199753, 0.008205500431358814, -0.028091879561543465, -0.07124071568250656, -0.02583514153957367, 0.014722961001098156, -0.0344107486307621, -0.05221189931035042, 0.01058861706405878, 0.025149092078208923, 0.017674775794148445, 0.030583318322896957, -0.03637862205505371, 0.03289422020316124, 0.0013720969436690211, -0.015481225214898586, 0.028055772185325623, 0.02977089397609234, 0.015941599383950233, 0.028543228283524513, 0.039574164897203445, -0.01689845696091652, 0.019281573593616486, 0.013134217821061611, 0.03692024201154709, 0.05134531110525131, -0.009031467139720917, 0.0183247160166502, 0.01790044829249382, -0.0016485473606735468, -0.012782166711986065, -0.04564027860760689, 0.013314756564795971, -0.01063375174999237, 0.019498219713568687, -0.007754153106361628, -0.01255649235099554, 0.00235829153098166, 0.024661637842655182, -0.0315040685236454, 0.07124071568250656, -0.00311204232275486, 0.0009309045854024589, -0.014641718938946724, 0.008521444164216518, -0.016708891838788986, 0.027333615347743034, 0.0091623580083251, 0.0782095268368721, -0.06943532824516296, -0.0011249841190874577, 0.060805559158325195, 0.02605178765952587, -0.029734784737229347, 0.014027886092662811, 0.02713502198457718, 0.008534984663128853, 0.04195728152990341, 0.011419096030294895, -0.03368858993053436, 0.021610526368021965, 0.01255649235099554, 0.03047499619424343, -0.036270298063755035, -0.030095864087343216, -0.0024305072147399187, -0.025275470688939095, -0.027459992095828056, -0.016221435740590096, 0.05491998419165611, 0.02977089397609234, 0.013314756564795971, 0.01684429496526718, 0.017467156052589417, 0.044629257172346115, -0.009202979505062103, -0.015472198836505413, -0.04701237380504608, -0.03520511835813522, -0.01859552413225174, -0.028001610189676285, 0.020816154778003693, -0.01349529530853033, 0.022820139303803444, 0.08600881695747375, 0.034609340131282806, -0.015399983152747154, 0.02628648839890957, -0.06105831265449524, 0.0009574212599545717, 0.0033309459686279297, -0.03737158700823784, -0.03262341022491455, -0.015156255103647709, -0.09055840224027634, -0.06015561893582344, -0.026846159249544144, 0.011816282756626606, 0.03311086446046829, 0.016040896996855736, 0.0033783374819904566, -0.06037226691842079, 0.0020694290287792683, -0.0612388551235199, 0.02029259130358696, 0.048023391515016556, -0.04264332726597786, 0.0020017269998788834, -0.00717191444709897, -0.013197406195104122, -0.03186514601111412, 0.015968680381774902, -0.010290727019309998, 0.003660429734736681, -0.0013213203055784106, 0.029120951890945435, 0.03704661875963211, 0.036541108042001724, 0.04748177528381348, -0.0007661627023480833, 0.00015035519027151167, -0.037913206964731216, -0.02341591753065586, 0.013630700297653675, -0.03110688179731369, -0.04495422914624214, 0.028850143775343895, 0.027423884719610214, -0.011229529976844788, -0.06178047135472298, 0.022061875090003014, -0.020527292042970657, 0.0674855038523674, -0.026936430484056473, 0.0002325851091882214, 0.0015052445232868195, -0.06221376359462738, -0.0006149612017907202, 0.025889303535223007, -0.0018742212560027838, -0.024065857753157616, 0.03191930800676346, -0.060408372431993484, 0.013062002137303352, 0.0692547857761383, -0.007889557629823685, -0.011256610974669456, -0.01838790439069271, -0.03580089658498764, 0.008652335032820702, -0.056292083114385605, -0.025329632684588432, -0.01334183756262064, -0.04715680703520775, 0.004743664059787989, -0.0894029513001442, 0.07459874451160431, -0.06416358798742294, -0.029825054109096527, -0.04000745713710785, -0.05293405428528786, 0.03186514601111412, 0.0005136900581419468, 0.023036785423755646, -0.048781655728816986, 0.009424139745533466, 0.05091201886534691, 0.042173925787210464, 0.01361264567822218, -0.008115231059491634, 0.0368841327726841, 0.0004744792531710118, -0.020996693521738052, 0.0012050983496010303, -0.052897948771715164, 0.048565011471509933, 0.02217019721865654, 0.033814966678619385, 0.008516930975019932, 0.003829685039818287, 0.0034708636812865734, 0.041993387043476105, -0.037696558982133865, 0.005452279932796955, -0.0014928324380889535, -0.057808611541986465, 0.013269621878862381, -0.04769842326641083, -0.009040494449436665, -0.041415661573410034, -0.041415661573410034, -0.0031977982725948095, 0.006896592676639557, -0.02171885035932064, -0.019895406439900398, -0.030366672202944756, 0.04098236933350563, -0.07199898362159729, -0.007803801447153091, -0.020996693521738052, -0.016708891838788986, 0.018279580399394035, -0.012737032026052475, 0.056761484593153, -0.015797168016433716, -0.010299754329025745, 0.014217452146112919, 0.09258043766021729, 0.06441634148359299, -0.018703848123550415, 0.04376267269253731, 0.0038906170520931482, 0.018252499401569366, 0.011879471130669117, -0.03812985122203827, 0.028055772185325623, -0.009803271852433681, -0.012755085714161396, 0.04242668300867081, 0.027730802074074745, -0.0029540706891566515, -0.04549584537744522, -0.003908670973032713, -0.01814417727291584, 0.07589862495660782, -0.051598068326711655, -0.0058675198815763, -0.012502330355346203, -0.04618189483880997, -0.01434382889419794, -0.035999491810798645, 0.03244287148118019, -0.02989727072417736, -0.02704475261271, 0.03186514601111412, 0.028525173664093018, 0.011861417442560196, 0.01644711010158062, 0.06224987283349037, -0.05156195908784866, 0.03540371358394623, -0.010489320382475853, -0.05621986836194992, -0.020545346662402153, 0.03616197779774666, -0.007257670629769564, -0.004603746347129345, 0.004502193070948124, 0.01917324960231781, 0.011373961344361305, -0.04809560999274254, 0.018703848123550415, 0.051778607070446014, -0.048601116985082626, 0.01850525476038456, 0.022061875090003014, -0.0014217451680451632, -0.002861544257029891, 0.026033734902739525, 0.015120147727429867, -0.029572300612926483, 0.016492243856191635, 0.06470520049333572, -0.0022838192526251078, -0.053259026259183884, 0.062322087585926056, -0.01814417727291584, 0.03110688179731369, -0.04549584537744522, 0.04748177528381348, 0.048023391515016556, -0.060805559158325195, -0.028308525681495667, -0.036216139793395996, -0.020491184666752815, -0.04076572135090828, 0.009148817509412766, 0.02735166996717453, 0.005014472641050816, -0.06275538355112076, 0.0014149750350043178, 0.03585505858063698, 0.031052719801664352 ]
30,954
networkx.classes.function
non_edges
Returns the nonexistent edges in the graph. Parameters ---------- graph : NetworkX graph. Graph to find nonexistent edges. Returns ------- non_edges : iterator Iterator of edges that are not in the graph.
def non_edges(graph): """Returns the nonexistent edges in the graph. Parameters ---------- graph : NetworkX graph. Graph to find nonexistent edges. Returns ------- non_edges : iterator Iterator of edges that are not in the graph. """ if graph.is_directed(): for u in graph: for v in non_neighbors(graph, u): yield (u, v) else: nodes = set(graph) while nodes: u = nodes.pop() for v in nodes - set(graph[u]): yield (u, v)
(graph)
[ 0.03724633529782295, 0.024787694215774536, 0.00037226665881462395, 0.0009354393114335835, -0.05412936583161354, -0.0020097193773835897, -0.013939606957137585, 0.015985194593667984, 0.09418953955173492, 0.008094413205981255, 0.00014260098396334797, 0.016910798847675323, -0.022325586527585983, -0.020363304764032364, -0.023695481941103935, 0.029860008507966995, -0.025583714246749878, 0.03339581936597824, 0.05361102521419525, -0.011625595390796661, -0.04439200460910797, -0.042651865631341934, -0.015133637003600597, 0.03489529713988304, -0.010727758519351482, 0.02193683199584484, -0.028119871392846107, 0.0022816157434135675, 0.007742683403193951, 0.007085504475980997, -0.023066069930791855, -0.01774384267628193, 0.019048945978283882, -0.015216941945254803, 0.018391765654087067, 0.044614147394895554, -0.005581396631896496, 0.04824252054095268, -0.13647116720676422, 0.0027212779968976974, 0.05113040655851364, -0.02534305676817894, -0.026194613426923752, -0.008015736937522888, 0.022992022335529327, -0.03950481116771698, 0.02787921391427517, -0.02504686452448368, -0.06768021732568741, -0.016077755019068718, 0.04024529457092285, 0.029915545135736465, 0.013023258186876774, 0.02919357270002365, -0.028286481276154518, 0.049501340836286545, -0.01727178506553173, 0.0031701961997896433, -0.02678700163960457, 0.03115585632622242, -0.08678469806909561, -0.01870647259056568, 0.016022218391299248, -0.020974203944206238, 0.013874814845621586, 0.02291797287762165, -0.051685769110918045, -0.05949787423014641, -0.04516950994729996, 0.020511401817202568, -0.024454476311802864, 0.008265649899840355, 0.031655680388212204, 0.029286133125424385, 0.007867639884352684, -0.014809675514698029, -0.005951638333499432, 0.07223419100046158, -0.008052761666476727, -0.03213699534535408, 0.0016221222467720509, -0.004327202215790749, -0.0019819510634988546, 0.007997225038707256, 0.029693400487303734, 0.019437698647379875, 0.018447302281856537, 0.012995490804314613, 0.0008457713411189616, 0.020122647285461426, -0.0070345960557460785, -0.033895645290613174, -0.008936713449656963, -0.025787347927689552, -0.0017308808164671063, 0.07871342450380325, -0.010792551562190056, -0.019900502637028694, 0.001480967621318996, -0.04154114052653313, 0.02891589142382145, 0.045058440417051315, -0.02412126027047634, 0.02591693215072155, -0.011819972656667233, -0.09137570112943649, -0.04113387316465378, -0.06749510020017624, 0.06905011087656021, -0.04268889129161835, -0.025435619056224823, 0.02523198537528515, 0.05305566266179085, -0.015513135120272636, 0.019419187679886818, -0.00008388292917516083, 0.004780748393386602, -0.020474376156926155, 0.0013467548415064812, -0.03011917881667614, -0.01010760385543108, 0.049094073474407196, -0.02924910932779312, 0.022825412452220917, 0.0600162111222744, -0.02280690148472786, 0.011875508353114128, -0.00470901420339942, -0.005835937801748514, -0.00034768026671372354, 0.05357400327920914, 0.002874002791941166, 0.016725677996873856, 0.04716881737112999, -0.05524009093642235, -0.031470559537410736, -0.011847740970551968, 0.012180957943201065, 0.046724528074264526, -0.007358557544648647, -0.020141158252954483, -0.061941467225551605, 0.01836399734020233, 0.07626982778310776, -0.00998727511614561, 0.013791510835289955, -0.03857920691370964, 0.007432606071233749, 0.04302210733294487, -0.019826453179121017, 0.028804820030927658, 0.013152843341231346, -0.01923406682908535, 0.0122087262570858, -0.017031127586960793, -0.011570058763027191, -0.027268314734101295, -0.011875508353114128, -0.031118830665946007, -0.03443249687552452, -0.0019009606912732124, -0.015161405317485332, 0.029508279636502266, -0.007687147241085768, -0.003003587480634451, -0.02891589142382145, 0.040060173720121384, -0.02043735235929489, 0.01474488340318203, 0.04398473724722862, -0.012199470773339272, -0.044947367161512375, -0.09100545942783356, -0.05068611353635788, -0.020418841391801834, 0.019956037402153015, 0.025472642853856087, -0.005465696100145578, -0.00953372847288847, 0.05486984923481941, -0.017308808863162994, -0.02965637482702732, -0.04035636782646179, -0.015633463859558105, 0.05890548601746559, -0.02212195284664631, -0.009802154265344143, -0.013810022734105587, -0.005868333857506514, -0.019937526434659958, -0.003984728362411261, -0.019085969775915146, 0.030378347262740135, 0.05435150861740112, 0.05679510533809662, -0.0027976403944194317, -0.020770570263266563, 0.08959853649139404, -0.06549578905105591, 0.021159324795007706, 0.019548771902918816, -0.013856302946805954, -0.01238459162414074, 0.01711443066596985, -0.002700451761484146, 0.04220757633447647, -0.047427985817193985, -0.06605115532875061, 0.03576536849141121, -0.010598174296319485, -0.012143934145569801, -0.016151802614331245, 0.05653593689203262, 0.001395349157974124, -0.03265533596277237, 0.0676431953907013, -0.03961588442325592, 0.03637626767158508, -0.04139304533600807, -0.007427977863699198, -0.03074858896434307, -0.06364458054304123, 0.013791510835289955, -0.05205601081252098, 0.0583871454000473, -0.007821359671652317, 0.04987158253788948, -0.014818931929767132, -0.03432142361998558, -0.010616686195135117, 0.01652204431593418, 0.05498092249035835, 0.013004746288061142, -0.0006780054536648095, 0.033654987812042236, 0.03891242295503616, -0.030544957146048546, -0.015309502370655537, 0.01860465481877327, 0.0215480774641037, -0.025435619056224823, -0.003929192200303078, -0.00672451825812459, -0.01796598732471466, 0.048686809837818146, -0.025417106226086617, -0.047316912561655045, 0.05849821865558624, -0.0032789548859000206, 0.011773692443966866, -0.05431448668241501, -0.04894597828388214, -0.0020745117217302322, -0.007751939818263054, 0.057276420295238495, -0.06734699755907059, -0.04820549488067627, -0.02125188522040844, 0.08041653782129288, 0.016142547130584717, 0.00024007873435039073, 0.016438739374279976, -0.08330442756414413, 0.0651995986700058, 0.015513135120272636, -0.0003436307597439736, 0.010579662397503853, 0.012255006469786167, -0.029619351029396057, 0.020141158252954483, 0.11314592510461807, -0.022529220208525658, 0.010301981121301651, 0.02608354203402996, 0.04450307413935661, 0.02258475497364998, 0.002665741601958871, 0.02878630720078945, -0.0018084002658724785, 0.0073307896964251995, -0.02264029160141945, 0.02954530343413353, 0.0048177726566791534, 0.010033555328845978, -0.0488349050283432, -0.0016880716430023313, -0.007529794704169035, -0.05383317172527313, 0.018697215244174004, -0.02032627910375595, 0.08226774632930756, 0.013430524617433548, -0.03574685379862785, 0.004410506691783667, -0.0152076855301857, 0.02995256893336773, 0.024676622822880745, -0.034710176289081573, 0.011384937912225723, 0.0414670929312706, 0.08870995789766312, -0.0384681336581707, -0.004463728982955217, -0.02447298914194107, 0.02867523394525051, 0.022658804431557655, 0.03391415625810623, 0.04924217239022255, -0.004813144449144602, 0.001087007112801075, -0.07782484591007233, -0.022714341059327126, 0.008746964856982231, -0.031303953379392624, -0.03543214872479439, 0.01756797730922699, 0.05638784170150757, -0.042540792375802994, 0.052611373364925385, 0.013412012718617916, 0.004186047241091728, 0.08826566487550735, -0.014133984223008156, 0.04646535590291023, -0.10085389018058777, 0.07782484591007233, 0.0086960569024086, 0.03817193955183029, 0.004528521094471216, 0.047650132328271866, 0.042355671525001526, 0.011135024949908257, -0.03598751127719879, 0.03813491389155388, 0.001911373808979988, 0.03669097274541855, 0.0342288613319397, 0.001178410486318171, 0.030822638422250748, -0.019567284733057022, 0.005729493219405413, 0.040282316505908966, -0.01664237305521965, -0.06842070072889328, 0.025602227076888084, 0.040911730378866196, -0.038727302104234695, -0.006113619077950716, -0.05690617859363556, 0.09115355461835861, -0.0025500410702079535, 0.09233833104372025, -0.01589263416826725, -0.003952332306653261, 0.0210112277418375, 0.0317852683365345, -0.020826106891036034, -0.023140117526054382, -0.03235914185643196, 0.09507811814546585, -0.012967722490429878, 0.05050099268555641, 0.026916585862636566, -0.015966681763529778, 0.03528405353426933, -0.03174824267625809, 0.03435844928026199, 0.012116165831685066, -0.059349775314331055, -0.04439200460910797, -0.03093370981514454, -0.026231639087200165, -0.01318986713886261, -0.05516604334115982, 0.027083193883299828, -0.04594701901078224, 0.0020652555394917727, 0.005234294570982456, 0.028767794370651245, 0.06879094243049622, -0.02580586075782776, -0.0414670929312706, -0.004961241502314806, 0.005063057877123356, 0.06619925051927567, -0.03639477863907814, -0.00015446028555743396, 0.05172279104590416, 0.002573181176558137, 0.012921442277729511, -0.016087010502815247, -0.03298855200409889, 0.02637973427772522, 0.006719890516251326, 0.018762007355690002, -0.01813259720802307, 0.05198196321725845, -0.028638210147619247, -0.016346178948879242, -0.05098230764269829, -0.005942382384091616, 0.026250150054693222, -0.030193226411938667, 0.04790930077433586, 0.04165221378207207, 0.03232211619615555, -0.00858498364686966, 0.008024993352591991, 0.07323385030031204, -0.03148907423019409, 0.007793591823428869, 0.0010927921393886209, -0.020474376156926155, -0.024232331663370132, 0.040467437356710434, -0.019622819498181343, 0.020122647285461426, 0.0007468473049812019, 0.02891589142382145, 0.04035636782646179, 0.053536977618932724, -0.08959853649139404, 0.0540182925760746, -0.0302857868373394, 0.015170661732554436, -0.033321771770715714, -0.027286827564239502, -0.06271898001432419, -0.03511744365096092, 0.06094181537628174, -0.006937407422810793, -0.04094875231385231, 0.021955344825983047, -0.05372209846973419, -0.024695133790373802, -0.03657989948987961, -0.009570753201842308, -0.03806086629629135, -0.02545413002371788, 0.04953836649656296, -0.009857690893113613, 0.009205139242112637, 0.03880134969949722, -0.01969686895608902, 0.021233372390270233, 0.010718503035604954, 0.025065375491976738, 0.03657989948987961, 0.09781790524721146, 0.01969686895608902, -0.027453435584902763, -0.03961588442325592, 0.018743496388196945, -0.052093032747507095, -0.04087470471858978, 0.043503422290086746, -0.038097891956567764, -0.013134331442415714, -0.03582090511918068, 0.09581860154867172, 0.019160017371177673, 0.015170661732554436, -0.0905611664056778, -0.013115819543600082, 0.01980794221162796, -0.029212085530161858, 0.023991674184799194, -0.018114084377884865, 0.004961241502314806, -0.007256741169840097, -0.0002759459021035582, -0.017253272235393524, -0.02258475497364998, -0.06364458054304123, 0.012051373720169067, -0.01010760385543108, -0.04416985809803009, -0.0016880716430023313, 0.021622126922011375, -0.033432841300964355, -0.009057042188942432, 0.026916585862636566, -0.011107256636023521, -0.01709591969847679, -0.011014696210622787, -0.01531875878572464, -0.05331483110785484, -0.027397900819778442, -0.022307073697447777, -0.015864865854382515, 0.0069883158430457115, -0.09737361967563629, -0.029693400487303734, -0.06264492869377136, 0.04705774411559105, -0.008904317393898964, -0.0027305339463055134, 0.023917626589536667, 0.036080073565244675, -0.042022455483675, -0.004590999335050583, 0.02251070737838745, 0.02275136485695839, -0.004280922003090382, 0.01980794221162796, -0.026120565831661224, 0.03678353130817413, 0.005748005583882332, 0.07656602561473846, 0.0033344910480082035, 0.02251070737838745, 0.007594586815685034, 0.014309849590063095, 0.03052644431591034, 0.003616800531744957, -0.031933363527059555, -0.03532107546925545, -0.02815689519047737, 0.06897606700658798, 0.010042811743915081, 0.003126230090856552, 0.029175061732530594, 0.013523085042834282, 0.021733198314905167, -0.02730534039437771, 0.025306032970547676, -0.01802152395248413, -0.05153767019510269, -0.0022445914801210165, -0.04594701901078224, 0.011273865588009357, 0.01278260163962841, 0.021325932815670967, 0.05857226625084877, -0.032636821269989014, -0.00998727511614561, 0.08833971619606018, 0.02349184826016426, -0.0714937075972557, 0.04272591322660446, 0.02395465038716793, 0.01774384267628193, 0.03672799468040466, 0.025472642853856087, 0.00496586924418807, -0.008112925104796886, -0.02004859782755375, 0.04513248801231384, 0.015300245955586433, -0.024750670418143272, -0.034062255173921585, 0.026157589629292488, -0.03426588699221611, -0.04705774411559105, -0.005442555993795395, 0.018169621005654335, 0.02678700163960457, 0.06834665685892105, 0.040467437356710434, -0.008251766674220562, -0.029119525104761124, -0.027342364192008972, -0.062348734587430954, -0.0785653293132782, -0.0034270514734089375, -0.00043300946708768606, -0.009010761976242065, -0.02349184826016426, 0.010283468291163445, 0.06445911526679993, -0.031988900154829025, -0.021844271570444107, 0.019900502637028694, -0.023251190781593323, 0.02125188522040844, 0.020603962242603302, -0.03450654447078705, -0.02182576060295105, 0.06434804201126099, -0.07301170378923416, -0.016549812629818916, -0.04165221378207207, -0.03298855200409889, 0.005734121426939964, -0.0031655682250857353, -0.002820780500769615, -0.03311813622713089, 0.004748352337628603, 0.04779822751879692, 0.032340630888938904, 0.04539165645837784, -0.08982068300247192, 0.03724633529782295, -0.02408423461019993, -0.05035289749503136, 0.009542984887957573, 0.002917968900874257, -0.040911730378866196, -0.05257434770464897, -0.04468819499015808, -0.014457945711910725, 0.06560686230659485, 0.023917626589536667, -0.008682172745466232, 0.018873080611228943, -0.010746271349489689, -0.030711565166711807, -0.03087817318737507, 0.004873308818787336, -0.009950251318514347, -0.034691665321588516, 0.057609640061855316, -0.03300706669688225, -0.021048251539468765, -0.004766864236444235, 0.014013655483722687, -0.01836399734020233, 0.04724286496639252, -0.04198542982339859, 0.039763979613780975, -0.031581632792949677, -0.042985085397958755, -0.009371748194098473, 0.0005964365554973483, -0.012366079725325108, -0.00015142315533012152, 0.02408423461019993, 0.029415719211101532, -0.047761205583810806, 0.04668750241398811, -0.054832823574543, -0.05090826004743576, -0.025194961577653885, 0.049094073474407196, -0.04683560132980347, -0.10240890830755234, 0.041318994015455246, -0.04931621998548508, -0.015929657965898514, 0.07001274079084396, -0.09337500482797623, 0.059053581207990646, -0.029600840061903, -0.025065375491976738, -0.05931274965405464, 0.02476918324828148, 0.005498092155903578, 0.0008226312347687781, -0.011412706226110458, -0.07649197429418564, 0.05594354867935181, 0.019048945978283882, 0.06264492869377136, -0.042874012142419815, -0.0120050935074687, 0.027564508840441704, -0.032618310302495956, -0.0017285668291151524, 0.03324772045016289, -0.007626982871443033, 0.0632743388414383, 0.02419530786573887, 0.009663313627243042, 0.019160017371177673, 0.024287868291139603, 0.05653593689203262, 0.030211739242076874, -0.03197038918733597, -0.013782254420220852, -0.008538703434169292, -0.02067800983786583, 0.05201898515224457, 0.034691665321588516, -0.038727302104234695, -0.031229903921484947, 0.005701725371181965, -0.03565429523587227, 0.04613213986158371, 0.03787574544548988, -0.0005021405522711575, -0.027897726744413376, 0.026157589629292488, -0.013263915665447712, -0.02982298471033573, -0.04346639662981033, -0.0017933591734617949, -0.03402522951364517, -0.04561380296945572, 0.04113387316465378, -0.02861969918012619, -0.017753098160028458, -0.030730077996850014, 0.027675582095980644, 0.024639597162604332, 0.01837325468659401, -0.01206063013523817, 0.013624901883304119, 0.019715381786227226, 0.008746964856982231, 0.00805738940834999, 0.012819625437259674, 0.02569478750228882, 0.004979753401130438, 0.05079718679189682, -0.013726717792451382, -0.027249803766608238, -0.0006600719061680138, -0.0016105521935969591, -0.03898647055029869, 0.0152076855301857, -0.06890201568603516, -0.04191138222813606, -0.02251070737838745, -0.0342288613319397, -0.0038065495900809765, 0.0150040527805686, 0.025713300332427025, -0.016957078129053116, -0.009371748194098473, -0.013430524617433548, 0.04924217239022255, 0.026472294703125954, -0.07138263434171677, 0.06867986917495728, -0.027601532638072968, 0.024454476311802864, -0.05153767019510269, -0.04250377044081688, 0.03472869098186493, 0.01148675475269556, -0.004250839818269014, 0.0597570426762104, 0.008186973631381989, 0.04050446301698685, -0.011060976423323154, -0.02850862592458725, -0.020640986040234566, 0.03794979304075241, 0.010533382184803486, -0.00417447742074728, -0.0116626201197505, 0.01940067484974861, -0.015744537115097046, 0.046909648925065994, 0.022381123155355453, -0.03887539729475975, -0.009265303611755371, 0.05490687116980553, -0.0346546396613121, 0.03363647684454918, 0.03530256450176239, -0.014967028982937336, -0.016438739374279976, 0.0036399406380951405, 0.029101012274622917, 0.0018986467039212584, 0.04705774411559105, -0.02989703230559826, -0.028416065499186516, -0.029101012274622917, -0.03415481373667717, 0.03787574544548988, -0.039023496210575104, -0.006238576024770737, -0.07597363740205765, 0.029286133125424385, 0.019993063062429428, -0.0011367583647370338 ]
30,955
networkx.classes.function
non_neighbors
Returns the non-neighbors of the node in the graph. Parameters ---------- graph : NetworkX graph Graph to find neighbors. node : node The node whose neighbors will be returned. Returns ------- non_neighbors : set Set of nodes in the graph that are not neighbors of the node.
def non_neighbors(graph, node): """Returns the non-neighbors of the node in the graph. Parameters ---------- graph : NetworkX graph Graph to find neighbors. node : node The node whose neighbors will be returned. Returns ------- non_neighbors : set Set of nodes in the graph that are not neighbors of the node. """ return graph._adj.keys() - graph._adj[node].keys() - {node}
(graph, node)
[ 0.03179527819156647, 0.026152431964874268, 0.017552513629198074, 0.018339255824685097, -0.051219698041677475, -0.0048334975726902485, -0.021847950294613838, 0.036696597933769226, 0.08051910251379013, -0.01398956123739481, -0.03242829069495201, -0.012054353952407837, -0.017480168491601944, -0.030637772753834724, -0.022625651210546494, -0.030927149578928947, -0.058815840631723404, 0.03555717691779137, 0.029841985553503036, -0.030040932819247246, 0.004021885804831982, -0.018447773531079292, 0.0002482593117747456, 0.03921056166291237, -0.029624953866004944, 0.008925466798245907, -0.008012120611965656, 0.035358231514692307, -0.015771036967635155, 0.032120827585458755, -0.04044041410088539, -0.0028304671868681908, 0.01025479193776846, -0.04380441829562187, 0.018013708293437958, 0.049266405403614044, 0.029444092884659767, 0.0485791340470314, -0.12146592885255814, 0.0021827605087310076, -0.012895355001091957, -0.05765833333134651, -0.011719761416316032, -0.021649004891514778, 0.030095189809799194, -0.07223568856716156, 0.07538266479969025, 0.01719079166650772, -0.05400495231151581, 0.007808653172105551, 0.040729790925979614, -0.008970681577920914, -0.005602154415100813, 0.028829166665673256, -0.037438128143548965, 0.026875874027609825, 0.007257028482854366, -0.0356295220553875, -0.025392817333340645, 0.06503744423389435, -0.06753332167863846, 0.026514152064919472, 0.003587820567190647, -0.036569997668266296, 0.00813872367143631, 0.006361768580973148, -0.0031944490037858486, -0.03351345285773277, -0.043298009783029556, -0.00302715296857059, -0.02743654139339924, -0.006850092206150293, 0.038161568343639374, 0.02456085942685604, 0.00019061003695242107, -0.027490798383951187, 0.07194631546735764, 0.06731628626585007, -0.03968079760670662, -0.007487625349313021, -0.01785997673869133, -0.004342913161963224, -0.009884027764201164, 0.020907476544380188, 0.015499746426939964, 0.009404746815562248, 0.0383424311876297, 0.01758868619799614, -0.026423722505569458, 0.001695567392744124, -0.03559334948658943, -0.01607850007712841, 0.01187349297106266, 0.004153009504079819, 0.012081482447683811, 0.05628379434347153, 0.012524590827524662, -0.014975250698626041, -0.007347458507865667, -0.0365157388150692, 0.01924355886876583, 0.05642848089337349, -0.033332593739032745, 0.020600013434886932, -0.0032509679440408945, -0.09795405715703964, -0.04195963963866234, -0.03127078339457512, 0.024651288986206055, -0.023421436548233032, -0.0561029352247715, 0.01870097778737545, 0.021811779588460922, 0.011258567683398724, 0.055198632180690765, 0.025844968855381012, -0.00951326359063387, -0.024651288986206055, 0.004247961565852165, -0.01550878956913948, -0.016512565314769745, 0.06047975644469261, -0.01855628937482834, 0.0032690539956092834, 0.026731185615062714, -0.007709179539233446, 0.04601091518998146, 0.032048482447862625, -0.009793597273528576, -0.011005362495779991, 0.05107501149177551, -0.005443901754915714, -0.022788425907492638, 0.09665185958147049, -0.03190379589796066, 0.028485532850027084, 0.03445392847061157, 0.036154016852378845, 0.05870732665061951, 0.010191489942371845, -0.007998556829988956, -0.05111118406057358, 0.020220207050442696, 0.06554385274648666, 0.03418263792991638, 0.012117655016481876, -0.061456404626369476, 0.017443997785449028, 0.020202120766043663, -0.017308352515101433, -0.0009122152696363628, 0.012985785491764545, 0.0038048531860113144, -0.017941363155841827, -0.05158142000436783, 0.016530651599168777, -0.00885764416307211, -0.0303483959287405, -0.017769545316696167, -0.03606358915567398, 0.006438634358346462, -0.009495177306234837, 0.027689745649695396, -0.016756726428866386, 0.014604487456381321, -0.0411638543009758, 0.04890468344092369, -0.03888501226902008, 0.01005584467202425, 0.02656841091811657, -0.021847950294613838, -0.04134471341967583, -0.08413631469011307, -0.02112450823187828, -0.003741552121937275, 0.03331450745463371, 0.019424419850111008, -0.02362038381397724, -0.016132758930325508, 0.04423848167061806, 0.013627840206027031, -0.01701897569000721, -0.0355210043489933, -0.02367464266717434, 0.05729661136865616, -0.035683780908584595, 0.006881742738187313, 0.0029796771705150604, -0.035955071449279785, 0.011556987650692463, -0.004125880543142557, -0.026857787743210793, 0.01386295910924673, 0.050604771822690964, 0.05588589981198311, -0.009440919384360313, -0.008776256814599037, 0.05125587061047554, -0.08999619632959366, 0.03416455164551735, 0.0477471761405468, -0.00813872367143631, -0.018719064071774483, 0.017371652647852898, 0.009341445751488209, 0.015897639095783234, -0.030836718156933784, -0.02938983403146267, 0.013139517046511173, -0.025465160608291626, 0.012126698158681393, 0.0008432621834799647, 0.08970681577920914, -0.003680511610582471, -0.04561302438378334, 0.01517419796437025, -0.033477284014225006, 0.0655076801776886, -0.03523162752389908, -0.021847950294613838, -0.029769642278552055, -0.027364196255803108, 0.04152557626366615, -0.021703261882066727, 0.041200026869773865, -0.012605978175997734, 0.009404746815562248, -0.019659537822008133, -0.0168742872774601, -0.05917756259441376, 0.0034612182062119246, 0.0795062854886055, -0.02778017520904541, -0.007121383212506771, 0.023801244795322418, -0.0017294787103310227, -0.03658808395266533, -0.013501238077878952, 0.02805146761238575, 0.00016531781875528395, -0.028015295043587685, -0.013311333954334259, 0.0032826184760779142, 0.019532935693860054, 0.039644625037908554, 0.00593674648553133, -0.03946376591920853, 0.04217667505145073, 0.013582625426352024, 0.009666995145380497, -0.03946376591920853, -0.0830511525273323, -0.02362038381397724, -0.006818441674113274, 0.03902969881892204, -0.037980709224939346, -0.04828975722193718, 0.03193996846675873, 0.038233913481235504, 0.044564031064510345, -0.0015915725380182266, 0.001675220555625856, -0.05570504069328308, 0.0016153105534613132, 0.04539598897099495, 0.004901320207864046, 0.008233674801886082, 0.04695139080286026, -0.050460085272789, 0.008618003688752651, 0.047385457903146744, -0.01371827069669962, 0.019822312518954277, -0.015400273725390434, 0.02582688257098198, -0.01345602236688137, 0.012018181383609772, 0.020021259784698486, 0.026785442605614662, -0.0005657543078996241, -0.030655859038233757, -0.0017147838370874524, 0.020600013434886932, -0.0031085400842130184, -0.053570885211229324, -0.021341541782021523, 0.024868320673704147, 0.012434160336852074, 0.00838740635663271, -0.009033982641994953, 0.028232326731085777, 0.01699184626340866, -0.0032690539956092834, 0.007220856379717588, -0.020762788131833076, 0.05953928455710411, 0.006040741223841906, -0.03260915353894234, 0.0033481803257018328, 0.0684376209974289, 0.1037415936589241, -0.018447773531079292, -0.03336876630783081, -0.05205165594816208, 0.04224901646375656, 0.011656460352241993, 0.0870300829410553, 0.06637581437826157, 0.023439522832632065, 0.004584813956171274, -0.07368257641792297, -0.019279731437563896, 0.004410735797137022, -0.03143355995416641, 0.005963875446468592, -0.015861468389630318, 0.04872382432222366, -0.035159286111593246, 0.00461872573941946, 0.034273069351911545, 0.033459197729825974, 0.04384059086441994, -0.035340145230293274, 0.09983500838279724, -0.07892753183841705, 0.021431971341371536, 0.014812476933002472, 0.02750888466835022, -0.019695710390806198, 0.04897702857851982, 0.020292550325393677, 0.011023448780179024, -0.04861530661582947, 0.02023829147219658, -0.009477091021835804, 0.04412996768951416, 0.027834434062242508, 0.002423530910164118, 0.004720459692180157, 0.020835131406784058, 0.024452341720461845, 0.03371240198612213, -0.017950406298041344, -0.049013201147317886, -0.007944297976791859, 0.022896941751241684, -0.063626728951931, 0.05111118406057358, -0.024578943848609924, 0.06196281313896179, 0.010743115097284317, 0.08312349766492844, -0.020618099719285965, -0.014911949634552002, 0.033477284014225006, 0.044021449983119965, 0.0030135884881019592, -0.015138025395572186, -0.04091065004467964, 0.06547150760889053, -0.014694917015731335, 0.05537949129939079, 0.01909887045621872, -0.005258519668132067, 0.013709227554500103, 0.004462733399122953, 0.02926323190331459, 0.010426608845591545, -0.005556939635425806, -0.0598648339509964, -0.025392817333340645, -0.04546833410859108, -0.0158795528113842, -0.0449257530272007, 0.04427465423941612, 0.0007409629179164767, 0.016132758930325508, -0.006737054325640202, 0.02211924083530903, 0.027961036190390587, -0.012334687635302544, -0.09086432307958603, -0.003660164773464203, -0.005783014930784702, 0.01409807801246643, 0.005597633309662342, 0.025211956351995468, 0.03479756414890289, 0.05823708698153496, 0.0053670359775424, -0.01662108115851879, -0.04177878051996231, -0.00512739596888423, 0.026477979496121407, 0.004455951042473316, -0.013546452857553959, 0.033676229417324066, -0.04138088598847389, -0.008120637387037277, -0.08073613792657852, 0.030420739203691483, 0.01590668223798275, -0.03975314274430275, 0.030692029744386673, 0.03658808395266533, 0.06485658138990402, -0.02919088862836361, -0.018465859815478325, 0.06789503991603851, -0.06308414787054062, -0.02448851428925991, -0.0060769133269786835, -0.00862252525985241, -0.03968079760670662, 0.04423848167061806, -0.063626728951931, 0.021938381716609, 0.03718492388725281, 0.05758598819375038, -0.008920945227146149, 0.03206656873226166, -0.121393583714962, 0.019605280831456184, -0.022987371310591698, 0.04036806896328926, -0.01815839670598507, 0.0021036339458078146, -0.07617845386266708, -0.02132345549762249, 0.07241655141115189, -0.024651288986206055, -0.036352965980768204, 0.03304321691393852, -0.05353471264243126, -0.02018403448164463, -0.04930257797241211, 0.020419152453541756, -0.05353471264243126, -0.03190379589796066, 0.09679654985666275, -0.013944346457719803, -0.009260058403015137, 0.013745399191975594, -0.038848839700222015, 0.013709227554500103, 0.05642848089337349, 0.01058938354253769, 0.0017532167257741094, 0.09853281080722809, -0.0065245432779192924, -0.009287187829613686, -0.052847445011138916, 0.009820726700127125, -0.06322883814573288, -0.02837701514363289, 0.01805892214179039, -0.09701358526945114, -0.021739434450864792, -0.03260915353894234, 0.06192664057016373, 0.007686572149395943, 0.04633646458387375, -0.07936159521341324, 0.006049784366041422, 0.003759638173505664, -0.04572153836488724, 0.04405762255191803, -0.045974742621183395, 0.029444092884659767, 0.004652637057006359, 0.014658745378255844, -0.02117876708507538, -0.0119367940351367, -0.09100901335477829, 0.023385265842080116, 0.002891507465392351, -0.05899670347571373, 0.018239783123135567, 0.008590874262154102, -0.03812539950013161, -0.04825358837842941, 0.0049239275977015495, 0.002369272755458951, -0.03577421233057976, -0.017670072615146637, -0.026622667908668518, -0.07805939763784409, 0.003888501087203622, 0.011972966603934765, -0.00423665763810277, 0.023656556382775307, -0.07295913249254227, -0.01847490295767784, -0.04340652376413345, 0.02770783193409443, 0.0005160176660865545, -0.002563697984442115, -0.011701676063239574, 0.06398845463991165, 0.023421436548233032, -0.018284998834133148, 0.07259741425514221, -0.012063397094607353, 0.02671309933066368, 0.023059716448187828, -0.021015992388129234, 0.0032283603213727474, 0.016042327508330345, 0.06073296442627907, -0.017507297918200493, 0.01857437565922737, -0.010923975147306919, 0.05335385352373123, 0.033676229417324066, -0.009495177306234837, -0.0299324169754982, -0.061637263745069504, -0.006018133834004402, 0.06630346924066544, -0.008278890512883663, 0.005014358088374138, 0.03949993848800659, 0.06934192031621933, 0.012587891891598701, -0.016214145347476006, 0.04376824572682381, -0.041670262813568115, -0.06764183193445206, -0.04152557626366615, -0.01660299487411976, 0.008229153230786324, -0.003897544229403138, 0.016385963186621666, 0.05686254799365997, -0.008432622067630291, 0.03250063583254814, 0.08095316588878632, 0.0346347913146019, -0.0063210753723979, 0.033133648335933685, 0.03543057665228844, -0.050749462097883224, 0.06605026125907898, 0.033929433673620224, 0.005873445421457291, 0.020093603059649467, -0.017850933596491814, 0.033857088536024094, -0.011285696178674698, -0.018538203090429306, 0.014866734854876995, -0.017326436936855316, -0.02913662977516651, -0.07017388194799423, 0.0147310895845294, 0.0016401788452640176, -0.0035539092496037483, 0.07147607952356339, 0.038378603756427765, -0.026080086827278137, -0.059901002794504166, -0.08391927927732468, 0.010987276211380959, -0.03687746077775955, -0.040657445788383484, -0.022915028035640717, -0.009305274114012718, -0.018918011337518692, 0.0043044802732765675, 0.04561302438378334, 0.01758868619799614, 0.014251808635890484, 0.019876571372151375, -0.02031063660979271, -0.0054529448971152306, 0.03465287387371063, -0.01166550349444151, -0.017371652647852898, -0.004453690256923437, -0.051689937710762024, -0.03425498306751251, -0.01884566619992256, -0.043225664645433426, 0.041887298226356506, -0.015318886376917362, 0.05972014367580414, -0.02535664476454258, -0.015924768522381783, 0.03960845246911049, 0.05179845169186592, 0.03801688179373741, -0.06648432463407516, 0.07907222211360931, -0.018248826265335083, -0.050821807235479355, 0.04384059086441994, -0.008107072673738003, 0.012940569780766964, 0.020762788131833076, -0.0214681439101696, 0.026514152064919472, 0.028684478253126144, 0.03968079760670662, -0.013745399191975594, 0.029407920315861702, -0.007505711633712053, -0.04358738660812378, -0.004460472613573074, 0.004765674937516451, -0.03443584218621254, -0.04203198477625847, -0.0019623367115855217, -0.035068854689598083, -0.02703864686191082, -0.006185429636389017, 0.018755236640572548, 0.009947328828275204, 0.033404938876628876, -0.04789186641573906, -0.005140960216522217, -0.043298009783029556, -0.028612134978175163, 0.01951484940946102, 0.0014333196450024843, 0.0028802037704735994, -0.03222934529185295, 0.0034273068886250257, -0.00006587985990336165, -0.0477471761405468, 0.0281057246029377, -0.05103883892297745, -0.026821615174412727, -0.04666201397776604, 0.06127554550766945, -0.051762279123067856, -0.04716842249035835, 0.016955673694610596, -0.045902401208877563, -0.04098299518227577, 0.0926729291677475, -0.06015421077609062, 0.07523797452449799, -0.018013708293437958, -0.0303483959287405, -0.04517895728349686, -0.006438634358346462, 0.027942949905991554, 0.012054353952407837, -0.019695710390806198, -0.06861848384141922, 0.009377618320286274, 0.028557876124978065, 0.039861660450696945, -0.04318949207663536, -0.0005877966759726405, -0.00859539583325386, -0.02589922584593296, 0.03492416813969612, 0.03233785927295685, -0.03906587138772011, 0.06427782773971558, 0.024669375270605087, 0.01679289899766445, 0.005556939635425806, 0.022426703944802284, 0.025447074323892593, 0.040657445788383484, -0.04340652376413345, -0.0008545659366063774, 0.011737847700715065, 0.018294041976332664, 0.04004251956939697, 0.012940569780766964, -0.04517895728349686, -0.017597729340195656, 0.0047159381210803986, -0.037293437868356705, 0.03371240198612213, -0.0016198320081457496, -0.016367876902222633, -0.003359484253451228, 0.022643737494945526, -0.015327929519116879, -0.017869019880890846, -0.004537338390946388, 0.030239878222346306, -0.009603694081306458, -0.03725726902484894, -0.015418359078466892, -0.0057016280479729176, -0.0001153692282969132, -0.04546833410859108, 0.04677053168416023, 0.07972332090139389, 0.06127554550766945, 0.01931590400636196, -0.007614227943122387, 0.01419755071401596, 0.035955071449279785, 0.026387549936771393, -0.026622667908668518, 0.013618797063827515, 0.003872675821185112, 0.04828975722193718, -0.0276354867964983, -0.06283094733953476, 0.022499049082398415, -0.03559334948658943, -0.019424419850111008, 0.033477284014225006, -0.06532681733369827, -0.04633646458387375, 0.0018685152754187584, -0.022824598476290703, -0.016964716836810112, 0.03054734133183956, 0.002604391425848007, -0.060371242463588715, -0.026821615174412727, 0.00023158625117503107, -0.0010665118461474776, -0.022282015532255173, -0.008523051626980305, 0.09426449984312057, -0.0005346689140424132, 0.04365972802042961, -0.04984515905380249, -0.06453103572130203, -0.014278938062489033, -0.02495875209569931, -0.016259361058473587, 0.04420231282711029, -0.004392649978399277, -0.0003057673166040331, 0.05064094439148903, -0.005226869136095047, 0.019532935693860054, 0.027346109971404076, 0.013546452857553959, -0.011475600302219391, -0.0018425165908411145, 0.040404241532087326, -0.003895283443853259, 0.006370811723172665, 0.012244257144629955, -0.010263834148645401, -0.05490925535559654, 0.04438317194581032, -0.02501300908625126, -0.004028668161481619, 0.04311714693903923, 0.005073137581348419, -0.0022878856398165226, -0.013437937013804913, 0.05697106570005417, 0.0028689000755548477, 0.019695710390806198, -0.027002476155757904, -0.020147861912846565, -0.04897702857851982, -0.06684605032205582, 0.028829166665673256, -0.044708721339702606, -0.00011430949962232262, -0.0664481520652771, 0.0025930877309292555, 0.010987276211380959, -0.007211813237518072 ]
30,961
networkx.generators.classic
null_graph
Returns the Null graph with no nodes or edges. See empty_graph for the use of create_using.
def star_graph(n, create_using=None): """Return the star graph The star graph consists of one center node connected to n outer nodes. .. plot:: >>> nx.draw(nx.star_graph(6)) Parameters ---------- n : int or iterable If an integer, node labels are 0 to n with center 0. If an iterable of nodes, the center is the first. Warning: n is not checked for duplicates and if present the resulting graph may not be as desired. Make sure you have no duplicates. create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Notes ----- The graph has n+1 nodes for integer n. So star_graph(3) is the same as star_graph(range(4)). """ n, nodes = n if isinstance(n, numbers.Integral): nodes.append(int(n)) # there should be n+1 nodes G = empty_graph(nodes, create_using) if G.is_directed(): raise NetworkXError("Directed Graph not supported") if len(nodes) > 1: hub, *spokes = nodes G.add_edges_from((hub, node) for node in spokes) return G
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.022234423086047173, -0.006926057860255241, 0.02171940729022026, -0.050187282264232635, -0.012715532444417477, 0.0667387843132019, -0.04755893349647522, 0.007498790044337511, -0.0006165745435282588, 0.005087988916784525, 0.004202252719551325, 0.06244107708334923, 0.016977721825242043, 0.07615111768245697, 0.02699386700987816, -0.007600904908031225, 0.014855506829917431, 0.011863094754517078, -0.022891510277986526, 0.03800452500581741, -0.019836939871311188, 0.015139652416110039, 0.0342218317091465, 0.013923152349889278, -0.020920246839523315, 0.012049565091729164, 0.02225218154489994, 0.03244591876864433, -0.03736519441008568, 0.027313532307744026, 0.03315628319978714, -0.012191638350486755, 0.0011271493276581168, 0.018345173448324203, 0.020636102184653282, 0.04237326979637146, -0.021470779553055763, 0.05313529819250107, -0.1044236421585083, -0.015716824680566788, 0.04635131359100342, -0.005891588982194662, 0.014775590971112251, -0.03299644961953163, 0.01212060172110796, 0.028450114652514458, 0.08346787840127945, 0.004559654742479324, -0.06869228929281235, -0.01757265254855156, 0.042870525270700455, 0.004206692334264517, -0.043261222541332245, -0.05832096189260483, -0.0018991162069141865, 0.010104941204190254, -0.007494349963963032, -0.012298192828893661, 0.05945754423737526, -0.039886992424726486, 0.033653538674116135, 0.03210849314928055, 0.006264530587941408, -0.023495320230722427, -0.05618986487388611, -0.021843722090125084, -0.0388924814760685, -0.06144656613469124, -0.014260576106607914, -0.01891346648335457, 0.05402325466275215, 0.04152083024382591, 0.030154991894960403, -0.00960768572986126, 0.012875364162027836, 0.026354538276791573, 0.03644172102212906, 0.010850824415683746, -0.010504521429538727, -0.009083791635930538, -0.02278495579957962, -0.03628188744187355, 0.022003553807735443, -0.04802066832780838, 0.046315792948007584, 0.09824346750974655, -0.019694868475198746, 0.021009042859077454, -0.04453988000750542, -0.0239215400069952, -0.02447207272052765, -0.027793027460575104, -0.026105910539627075, 0.005523087456822395, -0.01272441167384386, 0.015983210876584053, 0.050258319824934006, -0.0925605520606041, 0.012333710677921772, -0.0009834114462137222, -0.037471748888492584, -0.03336939215660095, -0.08865354210138321, -0.021843722090125084, -0.05665160343050957, -0.03141589090228081, -0.025324510410428047, 0.056829195469617844, -0.013141751289367676, 0.028556670993566513, -0.01905553974211216, 0.01748385652899742, 0.066134974360466, -0.013630127534270287, 0.029693253338336945, 0.04269293323159218, -0.018167583271861076, 0.038679368793964386, 0.06528253853321075, -0.0230158232152462, -0.058427516371011734, 0.044255733489990234, -0.04031321033835411, 0.029817568138241768, 0.026869554072618484, -0.0003623971133492887, 0.04461091756820679, -0.0530642606317997, 0.030226027593016624, 0.021080078557133675, -0.001516185118816793, 0.01896674372255802, -0.0010239244438707829, 0.06819503009319305, -0.03530513867735863, 0.013230547308921814, -0.07885050773620605, -0.028414597734808922, -0.0012509082444012165, -0.014269455336034298, 0.03383113071322441, -0.03413303568959236, 0.038750406354665756, 0.049583472311496735, -0.06077171862125397, 0.015459316782653332, 0.018700357526540756, 0.019250890240073204, 0.013310463167726994, -0.014482565224170685, 0.023743947967886925, 0.002090026857331395, 0.09533097594976425, 0.03072328306734562, -0.02209234982728958, -0.01838069222867489, 0.027082663029432297, -0.02234097756445408, -0.012173878960311413, 0.029835326597094536, -0.007441072724759579, 0.011880853213369846, 0.039886992424726486, -0.016658058390021324, -0.07622215896844864, -0.0033764534164220095, -0.006291169207543135, -0.004319906700402498, 0.006544237025082111, -0.02706490457057953, -0.04159186780452728, -0.0009301340905949473, 0.0012919761938974261, -0.05601227656006813, -0.004493058193475008, -0.0020700478926301003, -0.03088311478495598, -0.011197127401828766, -0.017173072323203087, -0.025892801582813263, 0.02972877211868763, -0.07064579427242279, 0.02912496216595173, -0.041733939200639725, -0.012022926472127438, 0.01771472580730915, 0.00990959070622921, 0.014047466218471527, 0.029142720624804497, 0.03352922573685646, 0.046670977026224136, 0.025111399590969086, -0.012902002781629562, 0.05601227656006813, 0.02287374995648861, -0.0583919957280159, 0.06986439228057861, 0.036246370524168015, -0.07224411517381668, 0.05526639148592949, 0.0772877037525177, 0.07128512114286423, 0.02042299136519432, -0.010406846180558205, 0.048517923802137375, -0.0006260090740397573, -0.05121731013059616, -0.048127222806215286, -0.051785603165626526, 0.028645465150475502, -0.00805820245295763, 0.01967710815370083, 0.03800452500581741, 0.04457540065050125, -0.06485632061958313, 0.06975783407688141, 0.0389990359544754, 0.03171779587864876, 0.010033904574811459, -0.06112690269947052, -0.03514530509710312, -0.015690185129642487, 0.003187762573361397, 0.03420407325029373, -0.008364547044038773, -0.005802793428301811, -0.008329029195010662, -0.0168090108782053, -0.004586293362081051, -0.06268970668315887, 0.026549888774752617, -0.026567649096250534, 0.0442202165722847, -0.015308364294469357, 0.012546820566058159, -0.015210689045488834, 0.03345818817615509, -0.011685502715408802, -0.042266711592674255, 0.032357122749090195, -0.05515983700752258, -0.019481757655739784, 0.007387795485556126, -0.009367937222123146, -0.013860995881259441, 0.07977398484945297, -0.010424605570733547, 0.03146916627883911, 0.002504036296159029, -0.011587828397750854, -0.0044619799591600895, -0.019091056659817696, 0.012786569073796272, -0.03093639202415943, 0.01891346648335457, 0.030527932569384575, -0.05700678750872612, -0.007370036095380783, 0.015166291035711765, 0.042728450149297714, -0.027562160044908524, -0.008746367879211903, -0.05800129845738411, -0.028414597734808922, 0.06173071265220642, 0.018078787252306938, -0.06869228929281235, 0.05281563103199005, -0.059493064880371094, -0.028627706691622734, 0.057113341987133026, 0.0814078226685524, 0.10527608543634415, 0.004510817117989063, 0.01273329183459282, -0.0560833103954792, 0.0024596385192126036, 0.03992250934243202, -0.042870525270700455, -0.031682275235652924, -0.053774625062942505, -0.037081047892570496, -0.011756539344787598, 0.042870525270700455, 0.025271233171224594, 0.03232160583138466, 0.05000969022512436, -0.0040069022215902805, 0.025661932304501534, -0.02882305718958378, 0.019712626934051514, -0.01479334942996502, -0.03676138445734978, -0.003098967019468546, 0.030545692890882492, 0.020334195345640182, -0.02651437185704708, 0.015263966284692287, 0.0023886021226644516, 0.05260252207517624, 0.09412335604429245, -0.053099777549505234, 0.036619313061237335, 0.022465290501713753, 0.04535680264234543, 0.02699386700987816, 0.00048809839063324034, 0.010424605570733547, 0.01272441167384386, 0.014740072190761566, -0.05448498949408531, 0.014296093955636024, 0.004994753282517195, 0.009288021363317966, -0.010540039278566837, -0.05860510841012001, -0.020369714125990868, -0.02141750231385231, 0.03800452500581741, 0.038217633962631226, 0.01912657544016838, 0.005270019639283419, -0.05267355963587761, 0.021310947835445404, -0.0524604506790638, 0.05334840714931488, -0.010069423355162144, 0.05714885890483856, -0.04922828823328018, 0.020991284400224686, 0.019002262502908707, -0.01951727643609047, -0.03109622560441494, 0.03544721007347107, -0.0720665231347084, 0.03553600609302521, 0.013887634500861168, -0.03257023170590401, -0.01554811280220747, -0.051110755652189255, 0.029764290899038315, 0.010548919439315796, -0.015574751421809196, 0.007063691504299641, -0.030083954334259033, 0.03871488943696022, 0.046990640461444855, -0.09348402172327042, -0.03786244988441467, -0.02674523927271366, 0.03154020383954048, 0.07870843261480331, -0.026265744119882584, -0.029799809679389, 0.04024217277765274, 0.06649015843868256, 0.005394333507865667, 0.012289313599467278, -0.06403940171003342, -0.010602196678519249, -0.003689457895234227, 0.0035873427987098694, 0.062227968126535416, -0.009838554076850414, -0.005745076574385166, 0.021097838878631592, -0.013630127534270287, 0.08694867044687271, 0.011685502715408802, -0.006553116720169783, -0.024187926203012466, -0.0736648440361023, -0.07686148583889008, 0.05043591186404228, -0.005891588982194662, 0.054236363619565964, -0.015450437553226948, -0.0318065881729126, 0.02713594026863575, -0.0018680377397686243, -0.04194704815745354, -0.01973038539290428, 0.0425153411924839, 0.006917178630828857, 0.02644333429634571, -0.000026187770345131867, 0.041130129247903824, 0.01921537145972252, -0.04262189567089081, -0.027562160044908524, -0.05359703302383423, -0.04642234742641449, 0.06244107708334923, -0.004888198804110289, -0.02940910868346691, 0.0022043511271476746, 0.09561511874198914, 0.049050699919462204, -0.05288666859269142, 0.017377302050590515, 0.051785603165626526, -0.04567646607756615, 0.025484342128038406, 0.0026327900122851133, -0.004728366620838642, -0.037010014057159424, 0.010611075907945633, -0.009927350096404552, -0.026176948100328445, -0.02660316601395607, 0.020014531910419464, -0.07870843261480331, -0.030439136549830437, -0.000408737309044227, 0.07153374701738358, 0.0061934944242239, 0.010424605570733547, 0.0009578827302902937, 0.029480144381523132, 0.00472392700612545, 0.0239215400069952, -0.09383920580148697, -0.015139652416110039, 0.0968937799334526, 0.05313529819250107, -0.050720054656267166, 0.02797061949968338, -0.016365032643079758, -0.012022926472127438, 0.0726703330874443, 0.03407975658774376, -0.023832743987441063, 0.035944465547800064, 0.006704069208353758, 0.007365596480667591, -0.06158864125609398, 0.025413304567337036, 0.0061402167193591595, -0.0017437238711863756, 0.0013408138183876872, 0.031060706824064255, -0.00527889933437109, 0.01866483874619007, -0.02111559733748436, -0.002641669474542141, -0.015841137617826462, 0.038217633962631226, 0.03468356654047966, -0.0023220053408294916, -0.03391992673277855, -0.0067839850671589375, -0.03146916627883911, 0.052247341722249985, 0.00033159612212330103, -0.03878592699766159, -0.007787375710904598, 0.019002262502908707, -0.04574749991297722, -0.059635136276483536, 0.04709719493985176, -0.0109041016548872, 0.026869554072618484, -0.02088472992181778, 0.021896999329328537, -0.016702454537153244, -0.042479824274778366, 0.02813045121729374, -0.005842751357704401, -0.041201166808605194, -0.07053923606872559, 0.024560866877436638, 0.013132872059941292, -0.03896351531147957, -0.031078465282917023, 0.03818211331963539, -0.03475460410118103, -0.026425575837492943, -0.046528901904821396, -0.000306344882119447, -0.03088311478495598, -0.06084275618195534, 0.015326123684644699, -0.01017597783356905, 0.03956732526421547, -0.0471327118575573, -0.023726189509034157, 0.023122377693653107, -0.04755893349647522, 0.0017981112468987703, -0.03544721007347107, -0.0030878675170242786, -0.022660640999674797, -0.015219568274915218, 0.01604536734521389, -0.030581209808588028, 0.0708589032292366, -0.017439458519220352, -0.03835970535874367, -0.0019768124911934137, -0.009243623353540897, 0.01921537145972252, -0.0020966865122318268, -0.022003553807735443, 0.014873266220092773, 0.006957136560231447, 0.058107852935791016, -0.006606393959373236, -0.012902002781629562, 0.00821803417056799, 0.042799487709999084, 0.039141107350587845, 0.038608334958553314, 0.024596385657787323, 0.04201808571815491, -0.022607363760471344, 0.008004925213754177, -0.021683890372514725, -0.007720778696238995, 0.04322570562362671, -0.057361967861652374, 0.041201166808605194, 0.03818211331963539, 0.009882952086627483, 0.041876014322042465, -0.025253472849726677, -0.005913787987083197, 0.03835970535874367, -0.02667420357465744, 0.016240717843174934, -0.0005458155646920204, 0.022394254803657532, 0.06176622956991196, -0.03946077078580856, 0.01077978778630495, -0.041343238204717636, -0.08083952963352203, 0.03468356654047966, 0.046670977026224136, 0.008142557926476002, -0.020298678427934647, 0.0026949469465762377, -0.0022498590406030416, -0.011108331382274628, 0.001956833293661475, 0.0011177147971466184, 0.029711013659834862, 0.006104698404669762, -0.06748466938734055, 0.026336779817938805, -0.05967065319418907, 0.0342218317091465, -0.0038714888505637646, 0.007458831649273634, 0.006548676639795303, 0.08368098735809326, -0.00610025878995657, 0.008004925213754177, -0.0268340352922678, 0.004175613634288311, 0.03244591876864433, -0.06219245120882988, 0.006530917715281248, -0.0016937763430178165, -0.02965773642063141, 0.018647080287337303, -0.000022441705368692055, 0.00862649455666542, -0.023033583536744118, 0.024667421355843544, 0.007596464827656746, -0.005611883010715246, 0.0642169862985611, 0.08971909433603287, -0.00922586489468813, -0.016107525676488876, -0.0072945598512887955, -0.042657412588596344, -0.004799403250217438, -0.039744917303323746, -0.017936713993549347, -0.020316436886787415, -0.01967710815370083, 0.0025950518902391195, 0.0005180669249966741, -0.0026150308549404144, 0.06393284350633621, -0.09433646500110626, -0.004608492366969585, -0.017927834764122963, 0.015663547441363335, 0.04503713548183441, -0.056829195469617844, 0.06428802758455276, 0.03344042971730232, -0.04375847801566124, 0.010726510547101498, -0.02020988240838051, -0.04564094543457031, 0.026549888774752617, 0.005962625611573458, -0.04684856906533241, 0.08865354210138321, -0.020831450819969177, 0.03285437822341919, 0.062227968126535416, 0.04297707974910736, 0.03154020383954048, -0.016027608886361122, -0.01632063463330269, -0.08446238934993744, -0.006104698404669762, 0.05381014198064804, -0.020902488380670547, -0.04869551584124565, -0.05022279918193817, 0.012751050293445587, -0.028698742389678955, 0.0519631952047348, -0.06531805545091629, -0.029977399855852127, -0.0159032940864563, 0.0354294516146183, -0.015255087055265903, -0.007760737091302872, -0.029018407687544823, 0.001192081137560308, 0.01845172978937626, -0.029053926467895508, 0.001361902803182602, 0.004106797277927399, 0.010673233307898045, -0.054911207407712936, -0.022909268736839294, -0.034719087183475494, -0.0115079116076231, -0.007649742532521486, 0.009359057992696762, -0.02757991850376129, 0.0038426301907747984, 0.09625444561243057, -0.04308363422751427, 0.008302390575408936, -0.029089443385601044, -0.026354538276791573, -0.0038315309211611748, -0.03116726130247116, 0.01868259720504284, -0.03651275858283043, -0.006482080090790987, -0.028148209676146507, -0.039070069789886475, -0.0028902972117066383, 0.01771472580730915, 0.01882467046380043, 0.04269293323159218, 0.03725863993167877, -0.03484340012073517, -0.06240556016564369, 0.005474249832332134, -0.06176622956991196, 0.053774625062942505, -0.015636907890439034, 0.029799809679389, 0.06158864125609398, 0.0011798717314377427, 0.06105586513876915, -0.0037138767074793577, -0.061553120613098145, 0.006082499865442514, -0.0004645120643544942, 0.004604052752256393, 0.008120358921587467, 0.03825315088033676, -0.01688004657626152, -0.05512432008981705, -0.015077495947480202, -0.01493542268872261, 0.028183728456497192, -0.04461091756820679, -0.009882952086627483, 0.009438973851501942, -0.009128189645707607, 0.03278334066271782, -0.024418793618679047, -0.019907977432012558, -0.01783015951514244, -0.04102357476949692, -0.0519631952047348, 0.01875363476574421, 0.011108331382274628, -0.017466098070144653, 0.02820148691534996, 0.010726510547101498, 0.01630287431180477, -0.019606072455644608, 0.0148999048396945, -0.016027608886361122, 0.027171459048986435, 0.004213352221995592, -0.05082660913467407, 0.03665482997894287, -0.0013885414227843285, -0.00934129860252142, 0.037684857845306396, 0.017492735758423805, 0.02280271425843239, -0.034257348626852036, 0.012102842330932617, -0.04137875884771347, 0.03566031903028488, -0.07132063806056976, -0.023211173713207245, 0.004235550761222839, 0.02171940729022026, -0.08730384707450867, 0.0051634651608765125, 0.029693253338336945, 0.005216742400079966, -0.051856640726327896, -0.0014751171693205833, 0.033653538674116135, -0.04731030389666557, -0.025821765884757042, 0.05114627629518509, -0.035997744649648666, 0.009030514396727085, -0.03210849314928055, -0.03711656853556633, -0.04212464019656181, -0.029480144381523132, -0.02102680131793022, 0.030439136549830437, 0.01181869674474001, -0.016054246574640274, 0.018948985263705254, -0.0016793471295386553, 0.020920246839523315, 0.027562160044908524, -0.0165337435901165, -0.016666937619447708, 0.002959114033728838, -0.021524056792259216, -0.06656119227409363, -0.020902488380670547, -0.016658058390021324, -0.014500324614346027, 0.008289070799946785, -0.01843396946787834, 0.0011465733405202627, 0.029231516644358635, 0.041343238204717636, -0.0027504442259669304, 0.008963917382061481, 0.026496611535549164, -0.04475298896431923, -0.024045852944254875, 0.01531724352389574, -0.005531966686248779, -0.017865678295493126, -0.04350985214114189, -0.022820472717285156, 0.028379078954458237, 0.06403940171003342, -0.011001776903867722, -0.04510817304253578, 0.0033409351017326117, 0.04567646607756615, -0.0031344853341579437 ]
30,964
networkx.algorithms.clique
number_of_cliques
Returns the number of maximal cliques for each node. Returns a single or list depending on input nodes. Optional list of cliques can be input if already computed.
def number_of_cliques(G, nodes=None, cliques=None): """Returns the number of maximal cliques for each node. Returns a single or list depending on input nodes. Optional list of cliques can be input if already computed. """ if cliques is None: cliques = list(find_cliques(G)) if nodes is None: nodes = list(G.nodes()) # none, get entire graph if not isinstance(nodes, list): # check for a list v = nodes # assume it is a single value numcliq = len([1 for c in cliques if v in c]) else: numcliq = {} for v in nodes: numcliq[v] = len([1 for c in cliques if v in c]) return numcliq
(G, nodes=None, cliques=None)
[ -0.015538817271590233, 0.010490071028470993, -0.025508493185043335, 0.015438389964401722, -0.0438227504491806, 0.10911864787340164, -0.0027069677598774433, 0.03900224715471268, 0.07515601813793182, -0.009960546158254147, 0.001138934982009232, 0.01866118796169758, -0.026969250291585922, -0.002226515207439661, -0.00884671788662672, 0.007737454492598772, -0.02572760544717312, -0.05572793260216713, 0.07124848663806915, 0.01110176369547844, 0.006422772072255611, -0.027498776093125343, 0.0306394062936306, 0.016269195824861526, -0.025563271716237068, -0.0017974175279960036, 0.055983562022447586, 0.015027551911771297, -0.015785319730639458, 0.044151421636343, -0.06734096258878708, -0.020925363525748253, -0.05474191904067993, -0.012032996863126755, -0.012179072946310043, 0.07179627567529678, 0.01009749248623848, 0.04305585101246834, -0.08340930193662643, -0.026969250291585922, -0.007203364744782448, -0.04615996405482292, -0.015913136303424835, -0.041339460760354996, 0.04550262168049812, 0.024796372279524803, 0.045721735805273056, 0.033067915588617325, -0.06883823871612549, -0.064748115837574, 0.040170855820178986, -0.08340930193662643, -0.00496657844632864, 0.01413283683359623, -0.003980566281825304, 0.021765299141407013, 0.014872346073389053, 0.03787016123533249, 0.022806089371442795, -0.011065244674682617, -0.04312888905405998, 0.02275131084024906, -0.0012017019325867295, -0.0029877072665840387, -0.004277282860130072, 0.024522481486201286, 0.003359744092449546, -0.01751996949315071, 0.01615963876247406, -0.030328994616866112, 0.010663536377251148, 0.0007001369376666844, 0.005623919423669577, -0.030402032658457756, 0.05269685760140419, -0.05948938429355621, -0.0040901233442127705, 0.02322605811059475, -0.043676674365997314, 0.004642472602427006, 0.05364634841680527, -0.013347679749131203, -0.018916821107268333, -0.02185659669339657, 0.05978153645992279, 0.015146237798035145, 0.07022595405578613, 0.04692686349153519, -0.04239851236343384, -0.007358570117503405, -0.006258436478674412, -0.017456062138080597, 0.04265414550900459, 0.02707880735397339, -0.05722520872950554, 0.007349440362304449, -0.047219011932611465, -0.04024389386177063, 0.010973947122693062, -0.03856401890516281, -0.010407903231680393, 0.0454661026597023, -0.0851622149348259, 0.02320779860019684, -0.04126642271876335, -0.07406044751405716, -0.025837162509560585, -0.02269653230905533, -0.0036108121275901794, -0.04053604230284691, -0.03242883458733559, 0.026403207331895828, 0.055947043001651764, 0.0007823045598343015, 0.026184093207120895, 0.02707880735397339, -0.006135185249149799, -0.009070396423339844, 0.01968371868133545, -0.06105969846248627, -0.010636147111654282, 0.05390198156237602, 0.010234437882900238, -0.016543088480830193, 0.024029474705457687, 0.04663471132516861, -0.017255207523703575, 0.03622680529952049, -0.01505494024604559, 0.026184093207120895, 0.08998271077871323, -0.00924842618405819, 0.014808437786996365, 0.08399360626935959, 0.048387620598077774, -0.0012153965653851628, -0.05291597172617912, 0.011083504185080528, 0.013265511952340603, 0.010261827148497105, 0.01120219100266695, -0.027005769312381744, -0.06025628000497818, 0.00399654358625412, -0.011293487623333931, -0.007974827662110329, 0.057006094604730606, -0.04506439343094826, -0.04426097869873047, -0.013365939259529114, 0.02291564643383026, 0.0010499201016500592, 0.01212429441511631, -0.05605660006403923, 0.009650134481489658, 0.03312269598245621, -0.04122990369796753, -0.03215494379401207, -0.012142553925514221, -0.06080406531691551, -0.020432356745004654, 0.07084678113460541, -0.04024389386177063, 0.023627765476703644, -0.020103687420487404, 0.03246535360813141, 0.0094310212880373, 0.006500374525785446, -0.06956861913204193, 0.04119338467717171, 0.018460333347320557, -0.03889269009232521, -0.08077993988990784, -0.044005345553159714, 0.046707749366760254, 0.007974827662110329, -0.0219113752245903, -0.04104730859398842, 0.024686815217137337, -0.007746584247797728, -0.05558185651898384, -0.03991522267460823, 0.033907853066921234, 0.029562097042798996, 0.030402032658457756, -0.003163454821333289, 0.04532002657651901, 0.014771918766200542, -0.0037112392019480467, -0.00723988376557827, -0.06379862129688263, 0.0009837294928729534, -0.028576085343956947, 0.04696338251233101, 0.0019891420379281044, -0.0363181047141552, -0.00002079155638057273, 0.020268021151423454, -0.05539926141500473, 0.004952883813530207, -0.011594769544899464, 0.022623494267463684, 0.027005769312381744, -0.0030310736037790775, 0.04444357380270958, -0.014854086562991142, -0.01329290121793747, -0.012106034904718399, -0.027571814134716988, -0.032921839505434036, -0.01784864068031311, -0.00217059557326138, 0.02475985325872898, -0.03379829600453377, -0.000204563228180632, 0.0327027291059494, 0.030402032658457756, -0.01631484553217888, -0.04239851236343384, -0.04951970651745796, 0.030182918533682823, 0.046233002096414566, -0.03147934377193451, -0.002821089467033744, -0.01668003387749195, -0.05886856094002724, 0.021929634734988213, 0.05828425660729408, 0.04013433679938316, -0.06310476362705231, 0.0013888616813346744, 0.004971143323928118, 0.03383481502532959, 0.03911180421710014, -0.033414848148822784, -0.004658449441194534, 0.028521306812763214, 0.006550588179379702, 0.01110176369547844, -0.027352700009942055, -0.04853369668126106, -0.03827187046408653, -0.0383814238011837, 0.016077471897006035, -0.03115067258477211, 0.030365513637661934, -0.020578432828187943, -0.00010706046305131167, -0.010508330538868904, 0.05459584295749664, -0.012827284634113312, -0.08574651181697845, -0.031734976917505264, -0.061863116919994354, -0.009367113001644611, -0.018387295305728912, -0.08523525297641754, 0.03304965794086456, -0.009531448595225811, -0.044151421636343, 0.042033322155475616, 0.00366330798715353, -0.04707293584942818, 0.03819883242249489, 0.017227819189429283, 0.014269783161580563, 0.059014637023210526, 0.0031954089645296335, -0.09772473573684692, 0.006194528192281723, 0.056129638105630875, -0.0076689813286066055, 0.05003097280859947, -0.06281261146068573, -0.03262969106435776, -0.07515601813793182, 0.00045934002264402807, 0.05572793260216713, 0.05214907228946686, -0.017949068918824196, -0.029927287250757217, -0.010179659351706505, -0.031899310648441315, -0.018250349909067154, -0.021966153755784035, 0.009367113001644611, 0.009467540308833122, 0.0024947014171630144, -0.02541719563305378, -0.000550922704860568, 0.04911800101399422, -0.018241219222545624, -0.000375175237422809, 0.003327790182083845, 0.01563924364745617, 0.01871596649289131, -0.0340174101293087, -0.0009409337653778493, 0.002533502643927932, 0.05003097280859947, 0.045210469514131546, -0.08589258790016174, -0.03604421392083168, -0.07194235175848007, 0.005213081371039152, 0.0363181047141552, 0.01817731186747551, -0.012069515883922577, 0.06306824088096619, 0.0444800928235054, -0.04225243628025055, 0.03692066669464111, -0.018935080617666245, -0.0008062701090238988, -0.017465192824602127, 0.04583129286766052, 0.006956861820071936, -0.02156444452702999, -0.005336332600563765, 0.010252697393298149, 0.04663471132516861, 0.023792101070284843, -0.00816198717802763, 0.06956861913204193, -0.053317680954933167, 0.06829044967889786, -0.024449443444609642, -0.0059936740435659885, 0.060657989233732224, -0.041302941739559174, -0.02320779860019684, 0.05667742341756821, -0.023773841559886932, 0.04601388797163963, -0.02304346300661564, 0.06354298442602158, 0.04951970651745796, -0.013192473910748959, -0.07424304634332657, -0.032246239483356476, 0.005683262832462788, 0.01329290121793747, 0.0011298052268102765, -0.0074589974246919155, -0.006997945252805948, -0.0014915711944922805, -0.02592846006155014, -0.023938177153468132, -0.019574161618947983, 0.02963513508439064, -0.01584009826183319, 0.05035964399576187, 0.04659819230437279, 0.027553554624319077, -0.009458410553634167, 0.053463757038116455, 0.09012878686189651, -0.020633211359381676, 0.03098633699119091, 0.025216341018676758, -0.007454432547092438, 0.03808927536010742, 0.06146140769124031, 0.04038996994495392, -0.011512601748108864, 0.023335615172982216, 0.01933678798377514, -0.04407838359475136, 0.06080406531691551, -0.06244741752743721, 0.014288042671978474, -0.020450616255402565, -0.003498972626402974, 0.009896637871861458, -0.003247904824092984, 0.07365874201059341, -0.01972023770213127, -0.0356607623398304, 0.0004781701136380434, -0.024686815217137337, -0.04922755807638168, -0.05236818641424179, 0.0036792850587517023, -0.022660013288259506, -0.05499755218625069, -0.0269327312707901, -0.0622648261487484, 0.0041152299381792545, 0.04177768900990486, 0.014087188057601452, -0.018789004534482956, 0.007299226708710194, 0.005153737962245941, -0.03604421392083168, -0.039476994425058365, -0.0011971371714025736, 0.044516611844301224, 0.0038641623686999083, 0.01752910017967224, -0.029196906834840775, -0.023445172235369682, -0.04258110746741295, 0.022513937205076218, 0.02611105516552925, 0.0011629005894064903, 0.015164497308433056, 0.003314095549285412, -0.022513937205076218, 0.040170855820178986, -0.008591084741055965, 0.024997226893901825, 0.022093970328569412, 0.0512361004948616, -0.01668003387749195, -0.020176725462079048, -0.05558185651898384, 0.0047657242976129055, 0.041010789573192596, 0.08231373131275177, -0.00975056178867817, 0.03690240904688835, -0.011950829066336155, 0.046379078179597855, 0.0343460813164711, 0.04053604230284691, 0.00736769987270236, 0.014616712927818298, -0.04126642271876335, -0.011640418320894241, -0.007764843758195639, -0.059708498418331146, 0.0026567543391138315, 0.06529589742422104, -0.08698815852403641, -0.06306824088096619, -0.021655742079019547, -0.0025996933691203594, -0.023025203496217728, 0.020633211359381676, 0.03449215739965439, 0.05759039893746376, -0.0010984217515215278, 0.015374481678009033, -0.0007457855972461402, 0.025964979082345963, -0.0589781180024147, -0.01884378306567669, 0.007148586213588715, -0.007600508164614439, -0.012133424170315266, -0.01888030208647251, -0.03624506667256355, -0.004441618453711271, 0.000002737138856900856, 0.015739671885967255, 0.050067491829395294, -0.018916821107268333, 0.006116925738751888, -0.029215166345238686, -0.030402032658457756, 0.04999445378780365, 0.04951970651745796, 0.03503993898630142, -0.012087775394320488, -0.05729824677109718, -0.00975056178867817, -0.008896931074559689, -0.014698880724608898, 0.015904005616903305, 0.0037180865183472633, 0.05459584295749664, 0.01752910017967224, -0.08494310081005096, -0.05401153862476349, 0.07406044751405716, 0.010124881751835346, -0.015301443636417389, -0.0011275229044258595, -0.052258629351854324, 0.01152173150330782, -0.0017837228951975703, 0.029233425855636597, 0.0333600677549839, -0.0011235285783186555, -0.03410870581865311, 0.007796797901391983, -0.05068831518292427, -0.042982812970876694, -0.023481691256165504, 0.02406599372625351, 0.01137565542012453, -0.03456519544124603, -0.009777951054275036, 0.028174376115202904, 0.03834490478038788, -0.0089151905849576, 0.06547849625349045, -0.030712444335222244, -0.011731715872883797, 0.03361570090055466, -0.03403566777706146, 0.06562457233667374, -0.019738497212529182, 0.0030150965321809053, -0.014790178276598454, -0.044516611844301224, 0.0036929796915501356, 0.011393914930522442, 0.025307638570666313, 0.016634386032819748, -0.013986760750412941, -0.026804916560649872, 0.08399360626935959, 0.022678272798657417, -0.03907528519630432, -0.013603311963379383, 0.009622745215892792, 0.036281585693359375, 0.037614528089761734, 0.033907853066921234, -0.0156483743339777, 0.03600769490003586, 0.029927287250757217, 0.07175975292921066, -0.03922136127948761, 0.057480841875076294, 0.014205874875187874, -0.03142456337809563, -0.0010590498568490148, 0.07552120834589005, 0.012918581254780293, 0.048898886889219284, -0.0009489223011769354, 0.04999445378780365, -0.00815742276608944, -0.00849522277712822, 0.05634875223040581, -0.007856140844523907, 0.01984805427491665, 0.015283184126019478, 0.01734650507569313, -0.028722161427140236, 0.05116306245326996, 0.060365837067365646, 0.0024125336203724146, 0.03217320144176483, 0.060657989233732224, 0.011777363717556, -0.0007737454143352807, -0.024285107851028442, -0.022824348881840706, 0.013238122686743736, -0.04630604013800621, -0.027699630707502365, 0.028229154646396637, 0.003953177481889725, -0.003944047726690769, -0.056640904396772385, 0.003770582377910614, 0.00492549454793334, -0.026056276634335518, -0.0940728411078453, -0.029744692146778107, 0.017045224085450172, 0.01093742810189724, -0.03279402479529381, 0.05824773758649826, -0.03321399167180061, 0.01970197819173336, 0.045867811888456345, 0.03182627260684967, -0.037121523171663284, 0.03794319927692413, -0.007358570117503405, 0.02461377903819084, -0.02152792550623417, -0.07289183884859085, -0.031077634543180466, 0.013758517801761627, -0.002100981306284666, -0.027170104905962944, 0.04258110746741295, -0.0056467438116669655, 0.027170104905962944, 0.026202352717518806, 0.08129119873046875, -0.06712184846401215, -0.02320779860019684, -0.026823174208402634, 0.07161367684602737, -0.029562097042798996, -0.01095568761229515, -0.023518210276961327, 0.016269195824861526, -0.004697251133620739, 0.026695359498262405, 0.014032409526407719, 0.0038344906643033028, -0.017976457253098488, -0.0185333713889122, -0.044699206948280334, 0.022787829861044884, 0.005372851621359587, 0.020468875765800476, -0.005450454540550709, -0.02326257713139057, -0.026202352717518806, 0.03332354873418808, 0.007148586213588715, -0.04641559720039368, 0.002394274342805147, -0.024668555706739426, -0.002467312151566148, -0.010143140330910683, -0.07241709530353546, 0.010900909081101418, -0.07727411389350891, 0.017437802627682686, 0.0308037418872118, -0.031406305730342865, -0.026677099987864494, -0.0357520617544651, 0.043530598282814026, -0.012316018342971802, 0.011028725653886795, 0.04648863524198532, -0.03790668025612831, -0.010681794956326485, -0.07756626605987549, 0.05196647718548775, 0.02894127555191517, -0.025125043466687202, 0.06401773542165756, 0.017419543117284775, 0.0007263849256560206, -0.053098566830158234, 0.04477224498987198, -0.010289216414093971, -0.018898561596870422, -0.002175160450860858, -0.07493690401315689, 0.06504026800394058, -0.020779287442564964, -0.03617202863097191, -0.0028530436102300882, -0.04937363043427467, 0.030566368252038956, 0.0018978446023538709, 0.013913723640143871, -0.0011189637007191777, 0.030675925314426422, 0.008417620323598385, -0.007751149125397205, -0.03951351344585419, 0.04853369668126106, 0.04458964988589287, 0.038637056946754456, 0.023463431745767593, -0.032739248126745224, -0.06434640288352966, 0.02645798586308956, 0.013950242660939693, 0.05539926141500473, 0.00396230723708868, -0.018487723544239998, -0.01968371868133545, 0.02068798989057541, -0.05200299620628357, 0.027553554624319077, 0.022860867902636528, 0.006756007205694914, -0.006043887697160244, 0.0010270957136526704, 0.00826241448521614, -0.07690892368555069, -0.003702109446749091, -0.018624668940901756, 0.04816850647330284, -0.04608692601323128, -0.032593172043561935, 0.01003358419984579, 0.03991522267460823, -0.07574032247066498, 0.004391404800117016, 0.07121197134256363, 0.000025017627194756642, -0.002567739225924015, 0.006208222825080156, 0.033597443252801895, 0.04159509390592575, 0.0034008279908448458, 0.01095568761229515, 0.047219011932611465, 0.024978967383503914, 0.02912386879324913, -0.008714336901903152, -0.04342104122042656, 0.03819883242249489, 0.02881345897912979, -0.00399654358625412, -0.005555446725338697, 0.014881475828588009, -0.020943623036146164, 0.05536274239420891, -0.047876354306936264, -0.060037169605493546, -0.023499950766563416, -0.004829632118344307, -0.019318528473377228, 0.02813785709440708, -0.047109454870224, 0.010362254455685616, -0.00014693175035063177, 0.03671981394290924, -0.0741334855556488, 0.010745703242719173, 0.04897192493081093, 0.0016296585090458393, -0.03202712535858154, -0.014288042671978474, 0.012580781243741512, 0.0373041145503521, 0.06211875006556511, 0.0589781180024147, 0.009312334470450878, 0.0037523231003433466, 0.08925233781337738, -0.04320192709565163, 0.059525903314352036, -0.052076034247875214, 0.023116501048207283, -0.04762072116136551, -0.045685216784477234, -0.05879552289843559, 0.06697577238082886, -0.0304750707000494, 0.026531023904681206, -0.049738820642232895, -0.020742768421769142, -0.02625713124871254, 0.020980142056941986, 0.0019857182633131742, 0.013484625145792961, 0.020815806463360786, 0.01617789827287197, -0.0538654625415802, -0.012854673899710178, 0.0686921626329422, -0.00024165280046872795, -0.040791675448417664, -0.010462681762874126, 0.017711695283651352, 0.05543578043580055, -0.04126642271876335, -0.0018042648443952203, 0.011676937341690063, -0.009841859340667725, -0.06748703867197037, -0.02253219671547413, -0.005560011602938175, -0.004820502363145351, 0.023810360580682755, 0.012535132467746735, -0.0002637638826854527, 0.019647199660539627, -0.03790668025612831, -0.014224134385585785, -0.0010116893099620938 ]
30,965
networkx.classes.function
number_of_edges
Returns the number of edges in the graph. This function wraps the :func:`G.number_of_edges <networkx.Graph.number_of_edges>` function.
def number_of_edges(G): """Returns the number of edges in the graph. This function wraps the :func:`G.number_of_edges <networkx.Graph.number_of_edges>` function. """ return G.number_of_edges()
(G)
[ -0.04343518614768982, -0.04164772853255272, -0.0067833964712917805, 0.02359442226588726, -0.015121879987418652, 0.05937929451465607, -0.032102715224027634, 0.013522106222808361, 0.08122201263904572, -0.030458254739642143, 0.012306636199355125, -0.047796580940485, -0.01976926624774933, -0.02177121676504612, 0.005447272676974535, 0.032567452639341354, -0.012521130964159966, -0.03857330605387688, 0.056876856833696365, 0.02139585092663765, -0.056626614183187485, -0.02352292463183403, 0.036607105284929276, -0.11046479642391205, -0.02046637423336506, 0.033800795674324036, 0.004428423009812832, 0.03950278088450432, 0.06055901572108269, 0.02584661729633808, -0.09216124564409256, -0.07400068640708923, -0.06345469504594803, 0.033729299902915955, 0.028295431286096573, 0.07643163204193115, -0.0195190217345953, 0.04443616047501564, -0.060594767332077026, 0.02221808023750782, -0.04411441832780838, -0.02405916154384613, 0.01173465047031641, 0.028474178165197372, 0.029099786654114723, -0.02516738325357437, -0.012413883581757545, -0.034337032586336136, 0.0013093117158859968, -0.04647386074066162, 0.002556062303483486, -0.02679396979510784, 0.014755451120436192, 0.015032506547868252, -0.004955722484737635, 0.04804682359099388, 0.034176163375377655, 0.029939891770482063, -0.013575729914009571, 0.033461179584264755, -0.05037051811814308, -0.013531044125556946, 0.012422820553183556, -0.030887244269251823, -0.01062642689794302, 0.02216445654630661, -0.013727664016187191, 0.02522100694477558, -0.014353273436427116, -0.013200364075601101, 0.014433708973228931, 0.02439877763390541, 0.017427697777748108, -0.0012009472120553255, 0.016498221084475517, 0.00546514755114913, -0.02209295891225338, 0.04254145920276642, -0.01130566094070673, -0.0012970229145139456, 0.06420543044805527, -0.026990588754415512, 0.016828900203108788, 0.031226860359311104, 0.10731887072324753, -0.0397530272603035, 0.018589545041322708, 0.035981494933366776, -0.02259344607591629, -0.005429398268461227, 0.004347987473011017, 0.01216363999992609, -0.0014232620596885681, -0.034408532083034515, -0.055732883512973785, -0.028813794255256653, -0.052586961537599564, -0.026972714811563492, 0.052586961537599564, -0.07257072627544403, -0.02572149597108364, 0.06635037809610367, -0.01329867448657751, 0.016140729188919067, -0.02071661688387394, -0.06492041051387787, -0.005920948926359415, -0.057913582772016525, -0.029510902240872383, -0.029296407476067543, -0.006935330107808113, 0.03721483796834946, 0.04432891309261322, -0.004479811992496252, 0.0488690547645092, 0.02205720916390419, 0.03648198023438454, -0.028259683400392532, 0.02314755879342556, -0.00578688969835639, -0.02448815107345581, 0.05884305760264397, -0.00987569522112608, 0.008624476380646229, 0.04239846020936966, 0.04200522229075432, -0.027705570682883263, -0.008302734233438969, -0.001956147374585271, -0.0222002062946558, 0.11046479642391205, 0.015389998443424702, 0.06685086339712143, 0.03857330605387688, 0.04847581312060356, -0.015184440650045872, -0.018267802894115448, 0.02609686180949211, 0.0427917018532753, -0.0010389589006081223, -0.035034142434597015, -0.00536683714017272, -0.034068915992975235, 0.033067941665649414, -0.025328254327178, 0.012682002037763596, 0.036303237080574036, -0.006229285150766373, 0.04801107570528984, -0.04722459241747856, 0.029457278549671173, -0.02402341179549694, 0.029278533533215523, -0.003554803552106023, -0.02468477003276348, 0.05219372361898422, -0.02312968298792839, 0.0022633664775639772, -0.00311240809969604, -0.036499857902526855, -0.03961002826690674, 0.014692890457808971, -0.00627843989059329, -0.027705570682883263, 0.007266009692102671, 0.005009346175938845, 0.07936305552721024, -0.029028289020061493, -0.02279006689786911, 0.02346930094063282, 0.02727658301591873, -0.0022577806375920773, -0.07578814774751663, -0.008003335446119308, 0.03732208535075188, 0.07900556176900864, 0.016328413039445877, 0.04911929741501808, 0.0046563236974179745, 0.02493501454591751, 0.027955815196037292, -0.02733020670711994, -0.009580765850841999, 0.0008859079680405557, 0.054910656064748764, 0.01035830844193697, 0.01871466636657715, -0.009133901447057724, -0.029653899371623993, 0.007386662997305393, -0.02570362016558647, -0.034569405019283295, 0.028420554473996162, 0.04586612805724144, 0.0010311388177797198, -0.056555114686489105, -0.018732542172074318, 0.007583282887935638, -0.0397530272603035, 0.019107908010482788, 0.007560939993709326, 0.016891460865736008, -0.0184465479105711, 0.02064511924982071, 0.016078168526291847, 0.004754633642733097, 0.02200358547270298, -0.032120589166879654, -0.04146898537874222, -0.06259671598672867, -0.03900229558348656, -0.034748148173093796, 0.005188091658055782, 0.0002980024728458375, 0.007033640053123236, 0.032192084938287735, -0.000329003669321537, 0.007386662997305393, -0.05283720791339874, -0.0390380434691906, 0.01959052123129368, 0.04411441832780838, -0.01146653201431036, -0.03818006440997124, 0.029671773314476013, -0.06420543044805527, -0.0010445447405800223, 0.006524215452373028, 0.04175497591495514, -0.031995467841625214, 0.034962642937898636, 0.07217748463153839, 0.04286320134997368, 0.000417259318055585, 0.02266494557261467, -0.014540956355631351, -0.028921041637659073, -0.017222139984369278, -0.0034587278496474028, 0.007954180240631104, -0.032031215727329254, -0.06896006315946579, -0.032245710492134094, 0.017874563112854958, 0.004095509182661772, -0.015425747260451317, -0.038108568638563156, 0.032638952136039734, 0.037071842700242996, 0.031298357993364334, -0.07507316023111343, -0.0977381095290184, -0.02543550170958042, -0.02177121676504612, -0.007784371729940176, 0.02475626952946186, -0.06234647333621979, 0.06688661128282547, -0.00933052133768797, 0.0005136143881827593, 0.035230763256549835, 0.008843439631164074, -0.06971079111099243, 0.028152436017990112, 0.02268281951546669, 0.04468640685081482, 0.015988795086741447, 0.0038832486607134342, -0.05222947150468826, 0.0010361659806221724, 0.06906730681657791, -0.0444004125893116, -0.005286401603370905, -0.08193699270486832, 0.0063320635817945, -0.08608388900756836, 0.0018053307430818677, 0.037357836961746216, 0.018410800024867058, 0.00040552913560532033, -0.032513827085494995, 0.0058539193123579025, -0.06695810705423355, 0.010805172845721245, -0.053838182240724564, 0.0456516332924366, -0.0001881018397398293, -0.04196947067975998, -0.0216639693826437, -0.036964595317840576, 0.06023727357387543, -0.02509588561952114, 0.01196701917797327, 0.08422493934631348, 0.01200276892632246, -0.014987820759415627, 0.0030945336911827326, -0.02632923051714897, 0.035105641931295395, 0.06245372071862221, 0.05001302435994148, -0.04515114426612854, -0.030368881300091743, -0.015550869517028332, 0.0011104572331532836, 0.04214821755886078, 0.07006828486919403, 0.0132897375151515, 0.037286337465047836, 0.016623342409729958, -0.08243747800588608, 0.027651946991682053, -0.04186222329735756, 0.010420870035886765, 0.0019282184075564146, 0.012735625728964806, -0.034015290439128876, -0.01001869235187769, -0.04250570759177208, 0.00134170928504318, 0.04425741732120514, 0.0830809623003006, 0.017526008188724518, 0.008660225197672844, -0.04608062282204628, 0.08501141518354416, 0.02625773288309574, 0.032352957874536514, 0.08043552935123444, -0.04379267618060112, -0.031691599637269974, -0.029922017827630043, 0.007417943328619003, 0.02402341179549694, -0.04229121282696724, 0.03968152776360512, 0.07400068640708923, 0.030279507860541344, -0.06685086339712143, -0.035052016377449036, -0.0043167066760361195, 0.009991880506277084, -0.02631135657429695, 0.026579475030303, 0.0069442675448954105, -0.005675173364579678, -0.015944110229611397, -0.055983129888772964, 0.02368379570543766, 0.02010888233780861, -0.006747647188603878, 0.04818981885910034, 0.02184271439909935, -0.003311262698844075, -0.015273813158273697, 0.02139585092663765, 0.056626614183187485, 0.015086130239069462, 0.0386805534362793, 0.06316870450973511, -0.04307769611477852, 0.035945743322372437, 0.01903640851378441, 0.0028152435552328825, 0.008789815939962864, 0.018571671098470688, -0.004055291414260864, 0.04443616047501564, 0.0056215496733784676, -0.02452389895915985, -0.01153802964836359, -0.02665097266435623, -0.038537558168172836, -0.013102054595947266, 0.036857347935438156, 0.030547626316547394, -0.004528967197984457, -0.009428831748664379, 0.035981494933366776, 0.01153802964836359, -0.053123198449611664, -0.009098152630031109, 0.017034457996487617, -0.02286156453192234, 0.028313307091593742, 0.016310537233948708, -0.037286337465047836, 0.014603517018258572, 0.037357836961746216, -0.009339459240436554, -0.060380272567272186, 0.014532019384205341, -0.0215745959430933, -0.004781445488333702, -0.060058530420064926, -0.010867733508348465, 0.0402892641723156, -0.005147873889654875, 0.05026327073574066, -0.01158271636813879, -0.030225884169340134, 0.036321111023426056, 0.017651129513978958, 0.02582874335348606, 0.018643168732523918, 0.0237195435911417, 0.015693865716457367, 0.02080599032342434, 0.057734835892915726, -0.030136512592434883, -0.0034855396952480078, 0.02527463063597679, -0.053230445832014084, 0.008745129220187664, -0.0037737670354545116, -0.015416810289025307, 0.007163230795413256, 0.02087748795747757, 0.07228472828865051, -0.04665260761976242, -0.005938823334872723, 0.02733020670711994, 0.04901205003261566, 0.016650155186653137, 0.0013115459587424994, 0.016104981303215027, -0.037786826491355896, -0.0012042986927554011, -0.04393567517399788, 0.055232398211956024, -0.04704584926366806, -0.01110904011875391, 0.02309393510222435, -0.027830693870782852, -0.019054284319281578, -0.0005278581520542502, -0.003447556169703603, -0.034265536814928055, 0.033961668610572815, 0.004911036230623722, 0.010117001831531525, 0.035856373608112335, 0.019054284319281578, 0.002150533255189657, 0.0502990186214447, -0.10317197442054749, 0.003838562173768878, -0.034194037318229675, 0.07392919063568115, -0.04686710238456726, -0.05927204713225365, -0.06488466262817383, 0.030082888901233673, -0.004330112598836422, -0.10088402777910233, 0.011341409757733345, -0.02556062489748001, 0.008745129220187664, -0.034980516880750656, 0.031888220459222794, 0.0067565846256911755, 0.028849544003605843, -0.035767000168561935, 0.01271775085479021, -0.05201497673988342, -0.0442216657102108, 0.012628378346562386, -0.02125285379588604, -0.033586300909519196, 0.008526165969669819, 0.06817357987165451, 0.009294772520661354, -0.07328570634126663, -0.033210936933755875, 0.05062076076865196, 0.04196947067975998, -0.02125285379588604, -0.014067280106246471, -0.007158762309700251, -0.009035591036081314, 0.006559964269399643, 0.02484564110636711, 0.013834911398589611, -0.003974855877459049, -0.0020622776355594397, 0.030368881300091743, -0.05884305760264397, 0.01280712429434061, -0.010492367669939995, -0.030815744772553444, 0.035320136696100235, -0.03900229558348656, -0.033979542553424835, -0.04540138691663742, 0.07514466345310211, 0.004444063175469637, 0.029135536402463913, -0.011341409757733345, -0.01196701917797327, 0.013486357405781746, -0.06549239903688431, 0.013361235149204731, 0.0368930958211422, -0.008512760512530804, -0.017123831436038017, -0.008074833080172539, 0.004276488907635212, 0.034694526344537735, 0.07435818016529083, 0.01866104267537594, 0.017088081687688828, 0.03700034320354462, 0.04443616047501564, 0.06484891474246979, 0.029332157224416733, 0.00987569522112608, 0.02146734856069088, 0.0508352555334568, 0.02246832475066185, 0.0418979749083519, -0.00040664628613740206, -0.013575729914009571, 0.007341976277530193, 0.0028085405938327312, -0.037608079612255096, 0.06785184144973755, 0.02472051978111267, 0.005103187635540962, 0.035552505403757095, 0.06391943246126175, 0.0025538280606269836, 0.04668835550546646, -0.007149824872612953, 0.06248946860432625, -0.02495288848876953, -0.017963934689760208, -0.002310287207365036, -0.028331181034445763, -0.008763004094362259, 0.07357169687747955, -0.04686710238456726, -0.05169323459267616, -0.012208325788378716, 0.059844035655260086, -0.0417192280292511, -0.003963684197515249, 0.055911630392074585, 0.02227170392870903, 0.033300310373306274, -0.07621713727712631, -0.037250589579343796, 0.0258644912391901, -0.0063767503015697, -0.06835232675075531, 0.02577511966228485, 0.032066963613033295, -0.032138463109731674, -0.00922327395528555, 0.011761462315917015, -0.033103689551353455, -0.04465065523982048, -0.056841108947992325, -0.03893079608678818, -0.027777070179581642, 0.028206059709191322, 0.00025946044479496777, 0.027669822797179222, -0.02332630380988121, -0.027419578284025192, 0.05194347724318504, -0.028778044506907463, -0.01909003220498562, 0.0408255010843277, -0.03986027464270592, 0.019161531701683998, -0.02477414347231388, -0.053015951067209244, 0.015023569576442242, 0.028331181034445763, -0.0435066856443882, -0.053659435361623764, -0.016239039599895477, -0.04293469712138176, 0.05001302435994148, -0.02413065917789936, 0.035731248557567596, -0.06770884245634079, 0.02048424817621708, -0.017651129513978958, 0.04754633456468582, -0.0393955372273922, -0.04822557047009468, -0.007958648726344109, -0.018062245100736618, 0.0011752524878829718, 0.00914730690419674, -0.018089057877659798, -0.00512106204405427, -0.04661685973405838, -0.029332157224416733, -0.032853446900844574, 0.0435066856443882, 0.01269987691193819, -0.0023505049757659435, 0.003952512517571449, -0.017642192542552948, 0.010957106947898865, 0.008079302497208118, 0.013227175921201706, -0.08694186806678772, -0.02352292463183403, 0.013861723244190216, -0.01957264542579651, -0.04507964476943016, -0.06416967511177063, 0.015961984172463417, -0.007002359721809626, 0.05977253615856171, -0.02545337751507759, 0.03764382749795914, -0.029922017827630043, -0.03678584843873978, -0.008016740903258324, -0.015854736790060997, 0.01034937147051096, 0.02593599073588848, -0.011716775596141815, -0.0426129549741745, -0.04733183979988098, 0.010000817477703094, -0.031369857490062714, -0.034819647669792175, 0.014067280106246471, -0.014576705172657967, 0.053730934858322144, -0.09387720376253128, -0.01228876132518053, -0.01050130557268858, -0.00991144496947527, 0.01876829005777836, -0.04515114426612854, 0.08801434189081192, -0.06295420974493027, -0.011609528213739395, -0.005858387798070908, 0.030744247138500214, 0.0066538057290017605, 0.0027549169026315212, 0.036195989698171616, -0.04164772853255272, 0.05412417650222778, -0.0034676650539040565, 0.02205720916390419, -0.016489284113049507, -0.01207426656037569, 0.04675985500216484, 0.02164609543979168, 0.005554520059376955, -0.02564999647438526, -0.08329545706510544, 0.030565502122044563, -0.010545991361141205, 0.02078811638057232, 0.013977907598018646, -0.003150391625240445, 0.010438743978738785, 0.02590024098753929, -0.01928665302693844, 0.026561599224805832, -0.056304872035980225, 0.03825156390666962, 0.01876829005777836, 0.00997400563210249, -0.015890486538410187, -0.05272996053099632, -0.006635931320488453, 0.02037700079381466, 0.034801773726940155, 0.037036094814538956, 0.019161531701683998, -0.0486903078854084, 0.057734835892915726, -0.07303546369075775, -0.027741320431232452, 0.033604178577661514, -0.037036094814538956, -0.04372118040919304, 0.018857663497328758, 0.056733861565589905, 0.05158598721027374, -0.0481540709733963, -0.01055492926388979, 0.0417192280292511, 0.013638291507959366, 0.0190721582621336, -0.02514950931072235, -0.005246183834969997, 0.02373741939663887, 0.01334336120635271, -0.028831668198108673, 0.02422003261744976, 0.02320118248462677, -0.02275431714951992, 0.0030140981543809175, -0.02243257500231266, -0.04590187594294548, -0.02539975382387638, -0.012574754655361176, -0.04196947067975998, 0.016194352880120277, -0.07493016868829727, -0.036285363137722015, 0.028295431286096573, -0.04039651155471802, -0.02119923010468483, 0.04347093403339386, 0.03807281702756882, 0.014469457790255547, -0.06159574165940285, 0.016247976571321487, 0.0030945336911827326, 0.02354079857468605, 0.037250589579343796, 0.04722459241747856, -0.01818736642599106, -0.00041865577804856, 0.05980828404426575, 0.004260848741978407, 0.025328254327178, 0.018786165863275528, 0.028581425547599792, -0.02493501454591751, -0.015372123569250107, -0.015693865716457367, -0.04808257147669792, -0.002053340431302786, 0.009634389542043209, 0.006609119474887848, 0.013897472061216831, -0.02193208783864975, 0.07028277963399887, -0.007967585697770119, -0.009187525138258934, -0.04357818141579628, 0.0963081419467926, -0.036392610520124435, 0.0014992288779467344, 0.06223922595381737, 0.01249431911855936, -0.011082228273153305, -0.00581817002967, 0.029010415077209473, 0.031530726701021194, -0.101313017308712, -0.028259683400392532, 0.007878213189542294, 0.017248952761292458, -0.058306820690631866, -0.013200364075601101, 0.012583691626787186, 0.0024465806782245636, 0.01185083482414484, -0.02386254072189331, -0.030708497390151024, -0.0006859363056719303, 0.027455328032374382, 0.009839946404099464, 0.00975951086729765 ]
30,967
networkx.classes.function
number_of_nodes
Returns the number of nodes in the graph. This function wraps the :func:`G.number_of_nodes <networkx.Graph.number_of_nodes>` function.
def number_of_nodes(G): """Returns the number of nodes in the graph. This function wraps the :func:`G.number_of_nodes <networkx.Graph.number_of_nodes>` function. """ return G.number_of_nodes()
(G)
[ -0.04737809672951698, -0.042274218052625656, -0.012698104605078697, 0.028300141915678978, 0.01101734396070242, 0.10890626907348633, -0.046286921948194504, 0.012090918608009815, 0.09447459876537323, -0.009609376080334187, 0.017203599214553833, -0.05244677886366844, 0.009222185239195824, -0.010832548141479492, 0.008795395493507385, -0.008157409727573395, -0.0007892316207289696, -0.036395952105522156, 0.05019403249025345, 0.00013667182065546513, -0.04924365505576134, 0.013340489938855171, 0.05723387002944946, -0.08095811307430267, -0.031116075813770294, 0.003229524940252304, 0.025185013189911842, 0.03769832104444504, 0.03812071308493614, 0.010190162807703018, -0.08278847485780716, -0.04910285770893097, -0.058888230472803116, 0.005108281038701534, 0.027156168594956398, 0.08271807432174683, -0.015646036714315414, 0.04428057000041008, -0.05554430931806564, 0.0030469291377812624, -0.02333705686032772, -0.024745024740695953, -0.011008543893694878, 0.011703727766871452, 0.014581260271370411, -0.012953298166394234, 0.03259444236755371, -0.0079110162332654, -0.012768503278493881, -0.050827618688344955, 0.0035133182536810637, -0.04199262335896492, -0.01428206730633974, 0.015179647132754326, -0.025061815977096558, 0.049384452402591705, 0.050616420805454254, 0.015012450516223907, -0.005143480375409126, 0.0273673627525568, -0.018391571938991547, 0.0034011208917945623, 0.006687844172120094, -0.030816882848739624, -0.02567780204117298, 0.017520392313599586, 0.0014134671073406935, 0.014308467507362366, -0.010242961347103119, -0.021999487653374672, 0.019817138090729713, 0.03227764740586281, 0.029690509662032127, 0.00484868697822094, 0.04005666822195053, 0.019623544067144394, -0.019289150834083557, 0.036395952105522156, -0.009222185239195824, 0.0006027859635651112, 0.048328474164009094, -0.014792455360293388, 0.009582976810634136, 0.03444239869713783, 0.08687157928943634, -0.05487552285194397, 0.01911315508186817, 0.0315912663936615, -0.020169131457805634, 0.005249077919870615, -0.031468067318201065, 0.031362470239400864, 0.014466863125562668, -0.025783400982618332, -0.019412348046898842, -0.008153010159730911, -0.022773869335651398, -0.03790951892733574, 0.030324093997478485, -0.045794133096933365, -0.002336345613002777, 0.10425997525453568, -0.03139767050743103, 0.003997306805104017, -0.012310913763940334, -0.06789921969175339, -0.04473815858364105, -0.03208405524492264, -0.00804741308093071, 0.0072906301356852055, -0.04568853601813316, 0.008403804153203964, 0.04815248027443886, -0.005046682432293892, 0.06416811048984528, 0.012117317877709866, 0.028546536341309547, -0.010049366392195225, -0.0021482501178979874, -0.007044236175715923, -0.007317029871046543, 0.05029962956905365, 0.006102657876908779, -0.015478840097784996, 0.04188702628016472, 0.03695914149284363, 0.017775585874915123, 0.014466863125562668, 0.0007837317534722388, -0.03035929426550865, 0.10158483684062958, 0.022157885134220123, 0.06392171233892441, 0.03602636232972145, 0.038331907242536545, -0.0024661426432430744, -0.023425055667757988, 0.03277043625712395, 0.0187611635774374, 0.01278610248118639, -0.023671450093388557, -0.023002665489912033, -0.028141744434833527, 0.040127065032720566, -0.005284277256578207, 0.02856413461267948, 0.02178829349577427, 0.01473085768520832, 0.010630152188241482, -0.04005666822195053, 0.04406937584280968, -0.02377704717218876, 0.08651958405971527, 0.004468095954507589, -0.058184247463941574, 0.050123631954193115, 0.0058782631531357765, -0.04677971079945564, -0.004747489467263222, -0.04421016946434975, -0.03085208125412464, 0.02129550464451313, 0.006987037602812052, -0.01821557618677616, -0.012689304538071156, 0.009723774157464504, 0.043858177959918976, -0.0430837981402874, -0.039282284677028656, 0.011404534801840782, 0.037487126886844635, -0.02507941611111164, -0.042872603982686996, 0.003101927926763892, 0.05220038443803787, 0.06173936277627945, 0.0020569521002471447, 0.01251330878585577, 0.004813488107174635, 0.022721070796251297, -0.0048178876750171185, 0.0014354665763676167, -0.010022967122495174, -0.02483302168548107, 0.026751376688480377, 0.023601051419973373, 0.01985233835875988, 0.00369371403940022, -0.029514513909816742, 0.011659728363156319, -0.0006726343417540193, -0.01014616433531046, 0.023460254073143005, 0.06434410065412521, 0.008065012283623219, -0.024111438542604446, 0.010647752322256565, 0.014035673812031746, -0.06733603030443192, 0.04213342070579529, 0.014739656820893288, 0.030658487230539322, -0.0016136624617502093, 0.005869463551789522, 0.007097034715116024, -0.0021163506899029016, -0.008746996521949768, 0.012953298166394234, -0.06610406190156937, -0.062267351895570755, -0.024657025933265686, -0.03546317666769028, -0.018074778839945793, 0.04790608584880829, -0.0342664010822773, -0.010718150995671749, -0.02875773049890995, 0.006481049116700888, -0.04424536973237991, -0.07821258157491684, 0.014273268170654774, 0.04762449115514755, -0.0018006580648943782, -0.061070580035448074, 0.030271295458078384, -0.05695227533578873, -0.0033769214060157537, -0.008227808400988579, 0.018127577379345894, -0.05258757621049881, 0.06272494047880173, 0.026575380936264992, 0.02930331788957119, 0.0272089671343565, 0.035797566175460815, -0.0803949311375618, -0.0012352712219581008, -0.009714974090456963, -0.004765089135617018, -0.01044535730034113, -0.0662800595164299, -0.09743133187294006, -0.012346113100647926, 0.009820571169257164, 0.009829371236264706, 0.006155456881970167, -0.05955701321363449, 0.039986271411180496, 0.013481286354362965, 0.03590316325426102, -0.07870537042617798, -0.09010989964008331, -0.01960594393312931, -0.02189389057457447, -0.018233176320791245, 0.022421877831220627, -0.05607229471206665, 0.06261934340000153, -0.01628842018544674, 0.0017687588697299361, 0.01606842689216137, 0.009521378204226494, -0.08109891414642334, 0.016904406249523163, 0.020785115659236908, 0.02358345128595829, 0.028194544836878777, 0.03692394122481346, -0.04825807735323906, 0.0026355385780334473, 0.05807865038514137, -0.002109750872477889, 0.003810311434790492, -0.09229224920272827, 0.01939474791288376, -0.07856456935405731, -0.016385218128561974, 0.031133675947785378, 0.038437504321336746, -0.0071894326247274876, -0.02284426800906658, 0.008584200404584408, -0.05406594276428223, -0.012082118541002274, -0.07610063254833221, 0.017361996695399284, 0.020186729729175568, -0.004459296353161335, -0.05621309205889702, -0.04815248027443886, 0.016570014879107475, -0.019975535571575165, 0.006225855089724064, 0.063182532787323, 0.012002920731902122, -0.007405027747154236, -0.044350966811180115, 0.006247854791581631, 0.0018039579736068845, 0.06356971710920334, 0.05424193665385246, -0.07405907660722733, -0.06353452056646347, -0.043013397604227066, 0.016464417800307274, 0.05561470612883568, 0.0693775862455368, 0.02483302168548107, 0.021084308624267578, 0.023759447038173676, -0.08982831239700317, 0.027455361559987068, -0.01671961136162281, 0.007849417626857758, -0.003112927544862032, -0.014510862529277802, -0.028141744434833527, -0.00526227755472064, -0.004809088073670864, 0.004993883892893791, 0.043400589376688004, 0.0519539900124073, -0.002272547222673893, 0.04259100928902626, -0.06624485552310944, 0.07363668829202652, 0.03537517786026001, 0.04058465734124184, 0.03678314387798309, -0.03328082710504532, -0.01840917207300663, -0.01686040684580803, -0.005904662422835827, 0.01634122058749199, -0.05983860790729523, 0.03366801515221596, 0.08567480742931366, 0.024903420358896255, -0.05839544162154198, -0.007699820678681135, 0.00003404764356673695, 0.003552917391061783, -0.050722021609544754, 0.03542797639966011, -0.005957461427897215, -0.015003650449216366, 0.013762880116701126, -0.03412560746073723, 0.043154194951057434, -0.01955314539372921, -0.006278654094785452, 0.09250345081090927, 0.008205808699131012, -0.019993135705590248, -0.0015674635069444776, 0.03208405524492264, 0.07363668829202652, 0.02925051935017109, 0.01707160286605358, 0.06994077563285828, -0.0661744624376297, 0.003062328789383173, 0.03189045935869217, 0.015382042154669762, -0.0053414758294820786, 0.01995793543756008, 0.01909555494785309, 0.03055288828909397, 0.03055288828909397, -0.03885989636182785, -0.003803711384534836, -0.023196259513497353, -0.07983174175024033, -0.005816664546728134, 0.014607660472393036, 0.051214806735515594, 0.013217292726039886, -0.03333362564444542, 0.0034627194982022047, -0.033562418073415756, -0.04780048877000809, -0.01955314539372921, 0.02527301199734211, -0.019922737032175064, -0.010630152188241482, 0.017142001539468765, -0.025783400982618332, 0.005196278914809227, 0.018725965172052383, -0.02208748646080494, -0.05617789179086685, -0.01398287434130907, -0.026575380936264992, 0.017062803730368614, -0.0655408725142479, -0.0031459268648177385, 0.050018034875392914, -0.01939474791288376, 0.028669733554124832, -0.05786745250225067, 0.005249077919870615, 0.01283890102058649, -0.0054778726771473885, 0.023407455533742905, -0.002305546309798956, 0.02138350158929825, 0.00523587828502059, -0.014317266643047333, 0.021911490708589554, -0.0019865536596626043, -0.005147880408912897, 0.024815423414111137, -0.0301480982452631, -0.007985814474523067, 0.00930138397961855, -0.027173766866326332, -0.0061642564833164215, 0.058641836047172546, 0.08278847485780716, -0.04252060875296593, -0.01770518720149994, -0.007721820380538702, 0.043259792029857635, 0.0605073906481266, 0.026240989565849304, 0.04526614770293236, -0.00290393247269094, -0.03822631016373634, -0.03481198847293854, 0.05075721815228462, -0.04135903716087341, -0.0027873350773006678, 0.03611436113715172, -0.022914666682481766, -0.0014717658050358295, -0.020274728536605835, -0.005455872975289822, -0.03254164382815361, -0.00599706033244729, 0.02382984571158886, 0.02965530939400196, 0.042274218052625656, 0.03477679193019867, 0.022316280752420425, 0.030376892536878586, -0.05980340763926506, -0.0076822214759886265, -0.04202782362699509, 0.0343191996216774, -0.02990170381963253, -0.045547738671302795, -0.059979405254125595, 0.031186474487185478, -0.004322899505496025, -0.0748334601521492, 0.007858216762542725, -0.07687500864267349, -0.02219308353960514, -0.05705787241458893, 0.0023121461272239685, 0.010762149468064308, 0.06578727066516876, -0.004509895108640194, 0.012407711707055569, -0.043400589376688004, -0.04347098991274834, 0.010102164931595325, -0.03935268521308899, -0.011457333341240883, -0.0013529685093089938, 0.059979405254125595, 0.013402088545262814, -0.058536238968372345, -0.06972957402467728, 0.05125000700354576, 0.03248884528875351, -0.03493518754839897, 0.0007688821060582995, -0.023055464029312134, -0.03139767050743103, -0.032506443560123444, 0.005015883129090071, 0.06392171233892441, 0.026944972574710846, -0.012425310909748077, 0.045160550624132156, -0.043752580881118774, -0.005059882067143917, 0.007017836906015873, -0.040127065032720566, 0.03681834414601326, -0.026557782664895058, -0.02587139792740345, -0.043717384338378906, 0.03790951892733574, -0.00004197089947410859, 0.02293226681649685, -0.033949609845876694, -0.015734033659100533, 0.03935268521308899, -0.05554430931806564, 0.0460757277905941, 0.041323836892843246, 0.018285974860191345, 0.012856501154601574, -0.006313852965831757, 0.02537860907614231, 0.03234804794192314, 0.05487552285194397, 0.021823491901159286, 0.0214891005307436, 0.04547734186053276, 0.04234461486339569, 0.03896549344062805, 0.016103625297546387, -0.005799064878374338, 0.0005829864530824125, 0.06353452056646347, 0.024058640003204346, 0.005614269524812698, 0.00553507125005126, 0.0029589312616735697, 0.03692394122481346, -0.009714974090456963, -0.04090144857764244, 0.06804001331329346, 0.016684411093592644, -0.009450980462133884, 0.002459542825818062, 0.08736436814069748, -0.0004958134377375245, 0.01911315508186817, -0.032964032143354416, 0.057691458612680435, -0.01979953981935978, -0.014862854033708572, 0.007440227083861828, -0.04100704565644264, 0.015751633793115616, 0.04801168292760849, -0.03600876033306122, -0.07849417626857758, 0.026557782664895058, 0.061422571539878845, -0.024709824472665787, 0.02059152163565159, 0.0661744624376297, 0.017423594370484352, -0.02104911021888256, -0.059029027819633484, -0.03643115237355232, -0.029989702627062798, -0.0317496620118618, -0.05212998762726784, 0.056494686752557755, 0.049173254519701004, -0.030130498111248016, -0.04259100928902626, 0.011254938319325447, -0.024164237082004547, -0.0039621079340577126, -0.06793441623449326, -0.014510862529277802, -0.018866760656237602, 0.010788548737764359, -0.04174622893333435, -0.005042282864451408, -0.034794390201568604, 0.0005686867516487837, 0.06490729004144669, 0.010366158559918404, -0.00042596508865244687, 0.02761375717818737, -0.028247343376278877, 0.0036673147697001696, -0.03187285736203194, -0.052622776478528976, 0.046885307878255844, 0.012610106728971004, -0.06969437748193741, -0.06891999393701553, 0.0013771679950878024, -0.02592419646680355, 0.04428057000041008, -0.00037756620440632105, 0.05297476798295975, -0.09855770319700241, 0.016209222376346588, 0.0027939348947256804, 0.018831562250852585, -0.027930550277233124, -0.028194544836878777, 0.00333952228538692, -0.001238571130670607, -0.01656121388077736, 0.01278610248118639, -0.01365728210657835, 0.007572223898023367, 0.012478109449148178, -0.029391316697001457, -0.011114140972495079, 0.04899726063013077, 0.006252254359424114, 0.021717894822359085, 0.0033461221028119326, -0.027930550277233124, -0.012654105201363564, 0.011140541173517704, 0.014704457484185696, -0.0717359334230423, 0.004375698044896126, -0.004509895108640194, -0.011237338185310364, -0.058289844542741776, -0.041323836892843246, 0.01930675096809864, -0.015646036714315414, 0.027332164347171783, 0.0036673147697001696, 0.003112927544862032, -0.01644681766629219, -0.03553357347846031, -0.00496308458968997, -0.015566837973892689, 0.01647321693599224, 0.015170847065746784, -0.003161326516419649, -0.05508671700954437, -0.02214028500020504, 0.013595683500170708, -0.00902859028428793, -0.06078898534178734, 0.019517945125699043, -0.02064432017505169, 0.032260049134492874, -0.07511505484580994, -0.0272089671343565, -0.012777302414178848, -0.020855514332652092, 0.008817395195364952, -0.04406937584280968, 0.06173936277627945, -0.054453134536743164, -0.027578558772802353, 0.007814218290150166, -0.04473815858364105, 0.023354656994342804, 0.02402344159781933, 0.06395690888166428, -0.027296964079141617, 0.022157885134220123, -0.0031173275783658028, 0.03456559404730797, 0.0009212285513058305, 0.002908332273364067, 0.02118990756571293, -0.0009894269751384854, 0.02009873278439045, -0.011078942567110062, -0.09039149433374405, -0.010119764134287834, -0.0049850838258862495, 0.03660714998841286, 0.0574098639190197, 0.007994613610208035, -0.02870493195950985, 0.05139080435037613, -0.03657194972038269, -0.000013045008927292656, -0.028370540589094162, 0.01425566803663969, 0.02287946827709675, 0.038085512816905975, -0.006120257545262575, -0.027244165539741516, -0.010762149468064308, 0.00942458026111126, 0.05726906657218933, 0.031010478734970093, 0.024569028988480568, -0.010559754446148872, 0.043611783534288406, -0.05786745250225067, -0.029989702627062798, 0.012222915887832642, -0.02053872123360634, -0.0516371987760067, 0.0013903676299378276, 0.07029276341199875, 0.0628657341003418, -0.03910629078745842, 0.002708137035369873, 0.0688496008515358, 0.049032460898160934, 0.003266924060881138, -0.0157428327947855, -0.013208492659032345, 0.0400918684899807, 0.016482016071677208, -0.027455361559987068, 0.02233388088643551, 0.0026619380805641413, -0.025853797793388367, 0.0026355385780334473, -0.04417497292160988, -0.04149983450770378, -0.024393033236265182, 0.0006748343002982438, -0.05955701321363449, 0.040267862379550934, -0.022861868143081665, -0.030535290017724037, 0.028845729306340218, -0.03706473857164383, -0.021260304376482964, 0.041112642735242844, 0.029936904087662697, 0.00498948385939002, -0.04449176415801048, 0.014114871621131897, 0.006925438996404409, -0.0064326501451432705, 0.05906422436237335, 0.06944798678159714, -0.009987767785787582, 0.012425310909748077, 0.051426004618406296, -0.04403417557477951, 0.03240084648132324, 0.027842551469802856, 0.04149983450770378, 0.0014112672070041299, -0.04090144857764244, -0.05110920965671539, -0.007695421110838652, 0.00837300531566143, 0.012636505998671055, 0.016710810363292694, -0.001665361225605011, -0.013534084893763065, 0.056037094444036484, 0.02089071460068226, -0.001547663938254118, -0.06452009826898575, 0.10278160870075226, -0.03900069370865822, 0.0007067335536703467, 0.06899039447307587, 0.017749186605215073, -0.0009316783398389816, 0.01854996755719185, 0.02815934456884861, 0.002741136122494936, -0.10897666215896606, 0.023970643058419228, 0.01791638322174549, 0.015390842221677303, -0.033650416880846024, -0.0054426733404397964, -0.02140110172331333, -0.013208492659032345, -0.021753093227744102, -0.05272837355732918, -0.008724996820092201, 0.00509948143735528, 0.002826934214681387, -0.007994613610208035, 0.025994595140218735 ]
30,969
networkx.classes.function
number_of_selfloops
Returns the number of selfloop edges. A selfloop edge has the same node at both ends. Returns ------- nloops : int The number of selfloops. See Also -------- nodes_with_selfloops, selfloop_edges Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> nx.number_of_selfloops(G) 1
def number_of_selfloops(G): """Returns the number of selfloop edges. A selfloop edge has the same node at both ends. Returns ------- nloops : int The number of selfloops. See Also -------- nodes_with_selfloops, selfloop_edges Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> nx.number_of_selfloops(G) 1 """ return sum(1 for _ in nx.selfloop_edges(G))
(G)
[ -0.017464928328990936, -0.03472889959812164, -0.03313951939344406, 0.07051738351583481, -0.04987369477748871, 0.07084622234106064, -0.04640263319015503, 0.032189544290304184, 0.08009020984172821, -0.002358952770009637, -0.009554557502269745, -0.0076591745018959045, 0.027330053970217705, 0.006823379080742598, 0.02175808511674404, 0.0184423066675663, -0.02681852877140045, -0.016734177246689796, 0.01890815980732441, 0.02510126680135727, -0.005622208584100008, 0.016999075189232826, 0.07113852351903915, -0.04811989516019821, -0.010595876723527908, 0.03869321942329407, -0.011472776532173157, 0.05166403204202652, -0.016925999894738197, 0.02796946093440056, -0.07738643884658813, -0.04000857099890709, -0.0370124951004982, 0.001137229846790433, 0.050640981644392014, 0.0601772740483284, -0.05623122304677963, 0.024790698662400246, -0.11567774415016174, -0.019748521968722343, 0.036519236862659454, -0.037103839218616486, -0.005919076036661863, 0.016323130577802658, 0.048229508101940155, -0.03556926175951958, 0.016058234497904778, -0.015035184100270271, -0.023018628358840942, -0.06375794857740402, 0.0014946123119443655, -0.012322274036705494, 0.0011652038665488362, 0.0038478560745716095, -0.010942983441054821, 0.0574004203081131, 0.00391179695725441, -0.01731877774000168, -0.07088275998830795, 0.005763791501522064, -0.04757183417677879, 0.00033254839945584536, 0.019803328439593315, 0.015418827533721924, 0.001482052612118423, -0.021685009822249413, -0.021082140505313873, 0.02104560285806656, 0.01697167195379734, -0.022251341491937637, 0.0098194545134902, 0.01287947129458189, 0.02769543044269085, 0.018213946372270584, 0.016195248812437057, 0.010696355253458023, -0.032792411744594574, 0.03847399353981018, 0.02590509131550789, 0.007225291803479195, 0.030709773302078247, -0.0018428604817017913, -0.05710812285542488, -0.05597545951604843, 0.05243132263422012, -0.045964181423187256, -0.02122829109430313, 0.05075059458613396, -0.020625421777367592, -0.021885966882109642, 0.007028902880847454, 0.03023478575050831, 0.03323086351156235, 0.02135617285966873, 0.0035875262692570686, -0.008115893229842186, -0.0346192866563797, -0.05371013283729553, 0.011399702169001102, -0.05718119814991951, 0.005371013190597296, 0.04665839672088623, -0.028005998581647873, 0.016304861754179, -0.013738102279603481, -0.06313680857419968, -0.025576254352927208, -0.03492985665798187, -0.029193466529250145, -0.024735892191529274, -0.027713699266314507, 0.02890116721391678, 0.0116463303565979, -0.015391424298286438, 0.013957327231764793, 0.012550633400678635, 0.043698858469724655, 0.010449727065861225, 0.05977535992860794, -0.01843317225575447, -0.0013758654240518808, 0.03206166252493858, -0.01876200921833515, 0.010239636525511742, 0.019657177850604057, 0.024790698662400246, 0.01358281821012497, -0.010924714617431164, -0.02975979819893837, -0.039387430995702744, 0.13036581873893738, 0.028791554272174835, 0.03606251999735832, 0.06675402075052261, 0.03434525430202484, 0.02535702846944332, -0.009846857748925686, 0.025210879743099213, 0.031312644481658936, -0.000710768683347851, -0.02722044289112091, -0.0319703184068203, -0.017492331564426422, 0.06284450739622116, -0.019291803240776062, 0.03894898295402527, 0.0005534861120395362, 0.016231786459684372, 0.026325272396206856, -0.047900669276714325, 0.040629707276821136, -0.015473634004592896, 0.08228246122598648, 0.04727953299880028, -0.05027560889720917, 0.04366232082247734, -0.01717262715101242, 0.017939915880560875, -0.005457790102809668, -0.04899679496884346, -0.04687761887907982, 0.03982588276267052, 0.0011537859681993723, -0.02336573600769043, -0.009198317304253578, -0.03421737626194954, 0.0006120032048784196, 0.003882110118865967, -0.026544498279690742, 0.025539716705679893, 0.030472280457615852, -0.04541612043976784, 0.010038679465651512, -0.015172199346125126, 0.020990796387195587, 0.06109071150422096, 0.015400558710098267, -0.0025873121339827776, -0.010970385745167732, 0.019748521968722343, 0.018798546865582466, -0.03661058098077774, -0.022525371983647346, -0.026855066418647766, 0.03894898295402527, 0.018387500196695328, 0.008024550043046474, 0.016999075189232826, 0.01350974291563034, 0.018277887254953384, -0.016231786459684372, -0.010605011135339737, -0.0219042357057333, 0.04545265808701515, 0.0417989082634449, -0.0443199947476387, 0.011701135896146297, 0.006156569812446833, -0.01012088917195797, 0.014295299537479877, -0.022397492080926895, 0.02842617966234684, -0.016213517636060715, -0.0005683294730260968, 0.01898123510181904, -0.039570119231939316, -0.0024091918021440506, 0.0025690433103591204, -0.029869411140680313, -0.04698723182082176, -0.05944652110338211, -0.030600162222981453, 0.02130136638879776, 0.04282195866107941, 0.03905859217047691, -0.02069849707186222, -0.029175197705626488, -0.015400558710098267, -0.027183905243873596, -0.0351308137178421, 0.008476701565086842, 0.030454011633992195, -0.03661058098077774, -0.0312212985008955, -0.014057805761694908, -0.04399115592241287, 0.007298366632312536, 0.03507600724697113, 0.05517163500189781, -0.016396205872297287, 0.002282452303916216, 0.05838693305850029, 0.039898958057165146, -0.021922504529356956, 0.030709773302078247, -0.009572826325893402, -0.03403468802571297, -0.0300886370241642, -0.026708917692303658, -0.0230368971824646, -0.06763092428445816, -0.07113852351903915, -0.018551919609308243, -0.010449727065861225, 0.007805324625223875, -0.0009676730260252953, -0.0012114467099308968, 0.029723260551691055, 0.0328654870390892, 0.057071585208177567, -0.03986242040991783, -0.068727046251297, -0.05531778559088707, -0.0026124317664653063, -0.004585457034409046, -0.03301163762807846, -0.04804681986570358, 0.02829829789698124, 0.007366874720901251, 0.05345437303185463, 0.03463755548000336, 0.02042446658015251, -0.06693670898675919, 0.028188686817884445, -0.032609723508358, 0.06905588507652283, 0.009129809215664864, 0.015163064934313297, -0.04888718202710152, 0.02110040932893753, 0.11326626688241959, -0.07395191490650177, 0.044502682983875275, -0.05732734873890877, -0.016323130577802658, -0.059811897575855255, 0.01710868813097477, 0.046293020248413086, -0.041579682379961014, -0.02429744228720665, -0.004854921251535416, -0.00017712127009872347, -0.05466010794043541, -0.03215300664305687, -0.05886192247271538, -0.01718176156282425, -0.0033797193318605423, -0.00020823524391744286, -0.015437096357345581, -0.020661959424614906, 0.050640981644392014, -0.02203211560845375, 0.03975280746817589, 0.06225990876555443, 0.041579682379961014, 0.006914723198860884, -0.03916820511221886, -0.017400987446308136, 0.015939487144351006, 0.043114256113767624, 0.06032342091202736, -0.022909015417099, -0.08505931496620178, -0.03206166252493858, -0.01783030293881893, 0.04519689455628395, 0.022068653255701065, 0.02890116721391678, 0.03865668177604675, 0.011244417168200016, -0.06138300895690918, 0.06280796974897385, -0.004446157719939947, 0.011363164521753788, 0.04238350689411163, -0.001413544756360352, 0.007878399454057217, -0.014057805761694908, -0.049691006541252136, 0.025539716705679893, 0.054294735193252563, 0.04706030711531639, 0.0018017557449638844, 0.05506202206015587, 0.026416616514325142, 0.051152508705854416, 0.05758310854434967, 0.017337046563625336, 0.04413730651140213, -0.012797261588275433, -0.028079073876142502, -0.03355969861149788, -0.02117348462343216, 0.034984663128852844, -0.046621859073638916, 0.02362149767577648, 0.053490910679101944, 0.03609905764460564, -0.061675310134887695, -0.0820632353425026, 0.02323785424232483, 0.02150232158601284, -0.008536075241863728, -0.01625005528330803, 0.03028959222137928, 0.019547564908862114, -0.012824664823710918, -0.05597545951604843, 0.05294284597039223, 0.033906806260347366, 0.010203098878264427, 0.06430601328611374, 0.033906806260347366, -0.01241361815482378, 0.018524516373872757, 0.031257838010787964, 0.040629707276821136, 0.004019125830382109, 0.010385786183178425, 0.03763363137841225, -0.03368758037686348, 0.006736602634191513, 0.04764490947127342, -0.0032883754465729, -0.003767930204048753, 0.00432969443500042, -0.009207451716065407, 0.049362171441316605, -0.020881185308098793, 0.004864055663347244, -0.03986242040991783, -0.029668454080820084, -0.016588028520345688, -0.03169628605246544, 0.024681085720658302, 0.04731607064604759, 0.02323785424232483, -0.021739816293120384, 0.01810433343052864, -0.026252198964357376, -0.048229508101940155, -0.032609723508358, 0.014560196548700333, -0.029522305354475975, 0.013327055610716343, -0.005444088485091925, -0.03606251999735832, -0.016149578616023064, 0.0818440169095993, -0.017675017938017845, -0.03233569115400314, 0.005498894490301609, 0.018816815689206123, -0.0020232643000781536, -0.04366232082247734, -0.016003428027033806, 0.0526140071451664, 0.033724118024110794, 0.037176910787820816, -0.032390497624874115, -0.03847399353981018, -0.010011276230216026, 0.03569714352488518, 0.022799404338002205, 0.016076503321528435, 0.03788939490914345, 0.0033637341111898422, -0.013619355857372284, 0.021447516977787018, 0.008275745436549187, -0.046037256717681885, 0.00587340397760272, -0.033906806260347366, -0.024005141109228134, 0.004658531863242388, -0.04888718202710152, 0.004918861668556929, 0.02968672290444374, 0.08045558631420135, -0.016295727342367172, -0.013591952621936798, 0.021155215799808502, 0.08272091299295425, 0.03355969861149788, 0.00038478561327792704, 0.004245201591402292, 0.012422751635313034, 0.0053618792444467545, -0.025119535624980927, 0.04654878377914429, -0.06361179798841476, -0.02082637883722782, 0.04888718202710152, -0.017200030386447906, -0.003980304580181837, 0.010276173241436481, 0.0045603374019265175, -0.04804681986570358, 0.02490030974149704, 0.00020423895330168307, 0.008220938965678215, 0.008376223035156727, 0.026124317198991776, -0.0030691504944115877, 0.0465853214263916, -0.08162479102611542, 0.0011463642586022615, -0.06664440780878067, 0.014989512041211128, 0.01018483005464077, -0.044831521809101105, -0.020461004227399826, 0.0023954901844263077, -0.013317921198904514, -0.08717849105596542, -0.007960609160363674, -0.06817898899316788, 0.004265754017978907, -0.0460737943649292, -0.015190468169748783, -0.009371870197355747, 0.062223371118307114, 0.01414914894849062, 0.026581035926938057, -0.02036966010928154, -0.06138300895690918, 0.0016715909587219357, 0.00819353573024273, -0.019748521968722343, -0.029522305354475975, 0.02077157236635685, 0.020607152953743935, -0.04315079376101494, -0.020132165402173996, 0.05542739853262901, -0.011947764083743095, -0.08995533734560013, -0.029741529375314713, -0.044502682983875275, -0.04932563379406929, -0.03946050629019737, 0.0299607552587986, 0.060140736401081085, 0.01118047721683979, 0.005553700961172581, -0.03346835449337959, -0.039643194526433945, -0.025722404941916466, -0.03986242040991783, -0.01878027804195881, -0.0070700072683393955, -0.04570842161774635, -0.05173710733652115, -0.0029686724301427603, 0.016999075189232826, -0.010568473488092422, 0.05922729894518852, -0.000971098430454731, 0.006631557364016771, -0.018323559314012527, -0.05257746949791908, 0.03492985665798187, 0.025740673765540123, 0.012833799235522747, -0.00901562999933958, 0.04216428101062775, -0.003694855375215411, 0.014788555912673473, 0.0483391210436821, 0.04526996985077858, 0.017802899703383446, -0.011408836580812931, 0.04161622002720833, 0.040447019040584564, 0.01698080636560917, 0.008006281219422817, -0.0052888039499521255, 0.03412603214383125, -0.026982948184013367, 0.049435246735811234, -0.022068653255701065, -0.0318424366414547, 0.01004781387746334, 0.04698723182082176, -0.05067751929163933, 0.08593621104955673, 0.04245658218860626, -0.0098194545134902, 0.017857706174254417, 0.06927511096000671, -0.01051366701722145, 0.032591454684734344, 0.004350246861577034, 0.09068609029054642, -0.04764490947127342, -0.007289232686161995, 0.008828374557197094, -0.014715480618178844, -0.014185686595737934, 0.03430871665477753, -0.019821597263216972, -0.05396589636802673, 0.06032342091202736, 0.011317492462694645, -0.03399815037846565, 0.006531079299747944, 0.05038522183895111, 0.029851142317056656, -0.010239636525511742, -0.035167351365089417, -0.02535702846944332, -0.00763633893802762, -0.027677161619067192, -0.030454011633992195, 0.046366095542907715, 0.040447019040584564, 0.019346609711647034, -0.006471705622971058, 0.041835445910692215, 0.013957327231764793, -0.03695768862962723, -0.05886192247271538, -0.012934276834130287, -0.032792411744594574, 0.016889462247490883, -0.022196535021066666, 0.019602371379733086, -0.029504036530852318, -0.016122175380587578, 0.10668952018022537, 0.006631557364016771, -0.014103477820754051, 0.03102034330368042, -0.056560058146715164, 0.00537558039650321, -0.016542356461286545, -0.05480625852942467, -0.022525371983647346, 0.005051310174167156, -0.07482881098985672, -0.06401371210813522, -0.007394277956336737, -0.010093485936522484, 0.06529252231121063, -0.012313139624893665, 0.01314436737447977, -0.08147864043712616, -0.008024550043046474, -0.06635211408138275, 0.04958139732480049, -0.03909512981772423, -0.047425683587789536, -0.03350489214062691, 0.01268764864653349, -0.010495398193597794, -0.004841219633817673, 0.03443659842014313, -0.02776850387454033, 0.03434525430202484, -0.018853353336453438, 0.0008432171307504177, 0.018150005489587784, -0.013948192819952965, 0.062077224254608154, 0.0031856137793511152, -0.014404911547899246, -0.026142586022615433, 0.014541927725076675, 0.02084464766085148, -0.052687082439661026, -0.018999503925442696, 0.01883508451282978, 0.01461500208824873, -0.03180589899420738, -0.07738643884658813, 0.010257904417812824, -0.02689160406589508, 0.04779105633497238, 0.010796832852065563, -0.0024914012756198645, -0.005681582260876894, -0.053892821073532104, -0.014477986842393875, -0.01683465577661991, 0.0006685222033411264, 0.023548422381281853, -0.002243631286546588, -0.033851999789476395, -0.022781135514378548, 0.04899679496884346, 0.0115184485912323, -0.0030531652737408876, -0.030399205163121223, -0.06163877248764038, 0.05210248380899429, -0.053088996559381485, -0.05440434813499451, 0.008138729259371758, -0.03695768862962723, 0.027658892795443535, -0.05407550930976868, 0.10325498878955841, -0.04980061948299408, 0.004099051468074322, -0.028389642015099525, -0.04972754418849945, 0.022452296689152718, 0.0009180048364214599, 0.014624136500060558, -0.027604086324572563, 0.04095854610204697, 0.02870021015405655, 0.04278542101383209, 0.0011240992462262511, 0.0061245993711054325, 0.044575758278369904, 0.017026478424668312, -0.018150005489587784, -0.026416616514325142, -0.10603184252977371, 0.036117326468229294, 0.017400987446308136, 0.006878185551613569, -0.00768657773733139, -0.017090419307351112, -0.017428390681743622, 0.06492714583873749, -0.07658261060714722, 0.02870021015405655, -0.03993549570441246, -0.01710868813097477, 0.0244253221899271, -0.014085208997130394, -0.004153857938945293, -0.041835445910692215, -0.04267580807209015, -0.006782274693250656, 0.01571112684905529, -0.00019895813602488488, -0.00838992465287447, -0.03354142978787422, 0.053088996559381485, -0.11260859668254852, -0.02696467936038971, 0.05809463560581207, -0.031531866639852524, 0.02422436699271202, 0.018688933923840523, 0.08199016004800797, 0.028115611523389816, -0.02968672290444374, 0.03016171045601368, 0.07249040901660919, 0.0438084714114666, -0.02042446658015251, -0.012377080507576466, 0.00402597663924098, 0.038839370012283325, 0.019529296085238457, -0.056085072457790375, 0.03865668177604675, 0.006302719935774803, -0.007344038691371679, 0.019474491477012634, -0.006462571211159229, -0.006535646505653858, -0.0485948845744133, -0.008668523281812668, -0.014249627478420734, 0.04486805573105812, -0.051956333220005035, 0.0009282809915021062, 0.005521730519831181, -0.046621859073638916, -0.053088996559381485, -0.001039606286212802, 0.04092200845479965, 0.002783701289445162, -0.04954485967755318, 0.010011276230216026, -0.0005178049905225635, 0.04687761887907982, 0.01490730233490467, 0.021264828741550446, -0.049033332616090775, 0.0058916728012263775, 0.04022779315710068, -0.027275247499346733, 0.03376065567135811, 0.030198248103260994, -0.024608010426163673, -0.05498894676566124, -0.012367946095764637, -0.03376065567135811, 0.009243989363312721, -0.01604910008609295, 0.04713338240981102, 0.0011189611395820975, 0.006814244668930769, -0.009207451716065407, 0.09024763852357864, -0.005846001207828522, 0.006745737046003342, -0.006800543516874313, 0.06690017133951187, -0.022525371983647346, 0.003194748191162944, 0.09053993970155716, 0.029010780155658722, -0.049691006541252136, 0.04238350689411163, -0.017519734799861908, 0.014112611301243305, -0.07987099140882492, 0.007960609160363674, 0.05783887207508087, -0.016597162932157516, -0.04914294555783272, 0.0022938703186810017, 0.03542311117053032, -0.0062342118471860886, -0.023530153557658195, 0.030983805656433105, 0.009892529807984829, -0.03175109252333641, -0.008883181028068066, 0.0020209806971251965, 0.0035441380459815264 ]
30,970
networkx.algorithms.tree.mst
number_of_spanning_trees
Returns the number of spanning trees in `G`. A spanning tree for an undirected graph is a tree that connects all nodes in the graph. For a directed graph, the analog of a spanning tree is called a (spanning) arborescence. The arborescence includes a unique directed path from the `root` node to each other node. The graph must be weakly connected, and the root must be a node that includes all nodes as successors [3]_. Note that to avoid discussing sink-roots and reverse-arborescences, we have reversed the edge orientation from [3]_ and use the in-degree laplacian. This function (when `weight` is `None`) returns the number of spanning trees for an undirected graph and the number of arborescences from a single root node for a directed graph. When `weight` is the name of an edge attribute which holds the weight value of each edge, the function returns the sum over all trees of the multiplicative weight of each tree. That is, the weight of the tree is the product of its edge weights. Kirchoff's Tree Matrix Theorem states that any cofactor of the Laplacian matrix of a graph is the number of spanning trees in the graph. (Here we use cofactors for a diagonal entry so that the cofactor becomes the determinant of the matrix with one row and its matching column removed.) For a weighted Laplacian matrix, the cofactor is the sum across all spanning trees of the multiplicative weight of each tree. That is, the weight of each tree is the product of its edge weights. The theorem is also known as Kirchhoff's theorem [1]_ and the Matrix-Tree theorem [2]_. For directed graphs, a similar theorem (Tutte's Theorem) holds with the cofactor chosen to be the one with row and column removed that correspond to the root. The cofactor is the number of arborescences with the specified node as root. And the weighted version gives the sum of the arborescence weights with root `root`. The arborescence weight is the product of its edge weights. Parameters ---------- G : NetworkX graph root : node A node in the directed graph `G` that has all nodes as descendants. (This is ignored for undirected graphs.) weight : string or None, optional (default=None) The name of the edge attribute holding the edge weight. If `None`, then each edge is assumed to have a weight of 1. Returns ------- Number Undirected graphs: The number of spanning trees of the graph `G`. Or the sum of all spanning tree weights of the graph `G` where the weight of a tree is the product of its edge weights. Directed graphs: The number of arborescences of `G` rooted at node `root`. Or the sum of all arborescence weights of the graph `G` with specified root where the weight of an arborescence is the product of its edge weights. Raises ------ NetworkXPointlessConcept If `G` does not contain any nodes. NetworkXError If the graph `G` is directed and the root node is not specified or is not in G. Examples -------- >>> G = nx.complete_graph(5) >>> round(nx.number_of_spanning_trees(G)) 125 >>> G = nx.Graph() >>> G.add_edge(1, 2, weight=2) >>> G.add_edge(1, 3, weight=1) >>> G.add_edge(2, 3, weight=1) >>> round(nx.number_of_spanning_trees(G, weight="weight")) 5 Notes ----- Self-loops are excluded. Multi-edges are contracted in one edge equal to the sum of the weights. References ---------- .. [1] Wikipedia "Kirchhoff's theorem." https://en.wikipedia.org/wiki/Kirchhoff%27s_theorem .. [2] Kirchhoff, G. R. Über die Auflösung der Gleichungen, auf welche man bei der Untersuchung der linearen Vertheilung Galvanischer Ströme geführt wird Annalen der Physik und Chemie, vol. 72, pp. 497-508, 1847. .. [3] Margoliash, J. "Matrix-Tree Theorem for Directed Graphs" https://www.math.uchicago.edu/~may/VIGRE/VIGRE2010/REUPapers/Margoliash.pdf
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, *, root=None, weight=None, backend=None, **backend_kwargs)
[ -0.0005046416190452874, -0.029409578070044518, -0.021688226610422134, 0.0029329368844628334, 0.009710507467389107, 0.0067321197129786015, -0.048723649233579636, -0.053985290229320526, 0.07293575257062912, -0.02320683002471924, -0.025153210386633873, 0.03413650020956993, 0.011496471241116524, 0.0419006273150444, -0.05638083443045616, 0.03621121123433113, 0.030543183907866478, 0.0033500182908028364, 0.036382321268320084, 0.03219011798501015, -0.042756177484989166, -0.08226126432418823, 0.019228516146540642, 0.0596747063100338, -0.04134451970458031, -0.03345205634832382, -0.019335459917783737, -0.03770842403173447, -0.01962420903146267, 0.006518231704831123, -0.0037938354071229696, -0.05946081876754761, -0.08320236951112747, -0.037986479699611664, 0.014127291738986969, 0.00193434813991189, 0.029858741909265518, 0.050819750875234604, -0.06600578874349594, -0.05864804610610008, -0.020062679424881935, -0.03552677109837532, 0.0209182295948267, -0.025153210386633873, 0.022714888677001, 0.023121275007724762, 0.06972743570804596, 0.06532134860754013, -0.039077308028936386, -0.0051199402660131454, 0.03261789679527283, -0.02474682219326496, -0.022885998710989952, 0.02120697870850563, -0.012747715227305889, 0.006518231704831123, 0.014533679001033306, -0.006667953450232744, 0.07169520109891891, -0.04192201793193817, 0.045044779777526855, 0.006331080105155706, -0.008427180349826813, -0.00008747678657528013, -0.07901016622781754, -0.013346601277589798, -0.05672305449843407, -0.0362325981259346, -0.018191160634160042, 0.025559596717357635, 0.0015399924013763666, -0.020490454509854317, 0.04816754162311554, 0.006758855655789375, 0.01738908141851425, 0.024126548320055008, 0.005234905052930117, -0.04962197691202164, -0.020116150379180908, -0.013068546541035175, 0.07036910206079483, -0.024832377210259438, 0.03616843372583389, -0.026072926819324493, 0.04915142431855202, -0.012640771456062794, 0.029281245544552803, 0.046242550015449524, 0.018169771879911423, -0.08363014459609985, -0.025773484259843826, -0.0031896024011075497, 0.04145146161317825, 0.051247525960206985, 0.04641366004943848, 0.018383659422397614, -0.011250500567257404, -0.07058298587799072, -0.025388486683368683, -0.03464983031153679, -0.013966876082122326, 0.06814466416835785, -0.028275972232222557, 0.014533679001033306, -0.011389527469873428, -0.03439316526055336, -0.03897036239504814, 0.038606755435466766, -0.006502190139144659, -0.04962197691202164, -0.05086252838373184, 0.01849060319364071, 0.021966280415654182, 0.004734942223876715, 0.0102505749091506, 0.011197028681635857, -0.024853765964508057, 0.006972743663936853, 0.007411213591694832, 0.04356895387172699, 0.03413650020956993, 0.020533232018351555, -0.02179517038166523, 0.008149126544594765, -0.00016409208183176816, -0.03171956539154053, 0.050306420773267746, -0.00261210510507226, 0.013421461917459965, -0.013122018426656723, 0.044189225882291794, 0.029174301773309708, 0.02066156454384327, 0.0486808717250824, 0.018886296078562737, -0.009518008679151535, -0.0822184830904007, -0.001430374919436872, 0.05364307016134262, 0.030821237713098526, 0.004521054215729237, -0.10078395158052444, 0.044189225882291794, 0.01468340028077364, 0.04709810018539429, -0.01295090839266777, 0.006058373022824526, -0.006069067399948835, 0.007924544624984264, 0.0037724466528743505, 0.02474682219326496, -0.028832079842686653, 0.02547404170036316, -0.0008608985226601362, 0.007496768608689308, -0.01547478511929512, 0.01842643693089485, 0.0029275896959006786, -0.05419917777180672, 0.0028206459246575832, -0.012640771456062794, -0.0031869288068264723, 0.02179517038166523, 0.027249310165643692, -0.0023688077926635742, 0.014223541133105755, 0.023613216355443, 0.02799791842699051, -0.04329089820384979, -0.0323612280189991, -0.016105754300951958, -0.04602866247296333, -0.10206727683544159, 0.03186928853392601, 0.019356848672032356, 0.014993537217378616, 0.024853765964508057, 0.010763905011117458, -0.012993685901165009, -0.006117192097008228, 0.013988264836370945, -0.04361173138022423, 0.03204039856791496, -0.007560934871435165, -0.02165614441037178, 0.03257511928677559, 0.06010248139500618, -0.02026587352156639, 0.01948518119752407, -0.010443073697388172, -0.021688226610422134, -0.0703263208270073, 0.01696130633354187, 0.057706937193870544, 0.046199772506952286, 0.024917932227253914, 0.004721574019640684, 0.0014063125709071755, -0.04996420070528984, 0.0537286251783371, 0.0024369845632463694, -0.023762939497828484, 0.04979308694601059, 0.002136204857379198, 0.01594533771276474, -0.008363014087080956, -0.010084811598062515, -0.005603861529380083, 0.02290738746523857, -0.0021522464230656624, -0.03800787031650543, -0.03150567784905434, 0.0555252842605114, 0.05321529507637024, -0.03390122205018997, -0.02639375999569893, -0.06480801105499268, 0.012309244833886623, 0.02523876540362835, -0.04143007472157478, -0.03710953891277313, -0.0006637207116000354, 0.019570736214518547, -0.008352319709956646, 0.06232691556215286, -0.055610839277505875, 0.01273702085018158, -0.004531748592853546, 0.03621121123433113, -0.03486371785402298, 0.09282732009887695, -0.021859336644411087, 0.047782544046640396, -0.022287113592028618, -0.02547404170036316, -0.08307403326034546, -0.03969758376479149, -0.030436240136623383, 0.02297155372798443, 0.01745324768126011, -0.0320831760764122, -0.0757162943482399, -0.031142069026827812, 0.01272632647305727, 0.00008033326594159007, -0.007694615051150322, 0.011090083979070187, 0.015613812021911144, 0.036104265600442886, 0.003735016332939267, -0.08046460151672363, -0.06497912853956223, -0.006865799427032471, -0.035462602972984314, 0.006742814090102911, -0.029045969247817993, -0.00762510159984231, 0.022607944905757904, -0.020030595362186432, 0.012416188605129719, 0.0029195689130574465, -0.05133308097720146, -0.04675588011741638, 0.04036063328385353, -0.01891838014125824, -0.009191829711198807, 0.028853468596935272, 0.024126548320055008, -0.04145146161317825, -0.02142086625099182, 0.0796518325805664, 0.0099564790725708, 0.00367085007019341, -0.007411213591694832, -0.030200961977243423, -0.026671813800930977, -0.030585961416363716, 0.08546958118677139, 0.003494392614811659, -0.026735980063676834, -0.04474533721804619, 0.017592275515198708, -0.0005574451643042266, 0.03073568269610405, -0.052830297499895096, 0.038884807378053665, -0.028725136071443558, -0.046328105032444, 0.024233492091298103, -0.02476821094751358, 0.011849386617541313, -0.053086962550878525, -0.0019249905599281192, 0.020415594801306725, 0.03396539017558098, 0.017442552372813225, -0.003232379909604788, -0.04444589093327522, 0.008197251707315445, 0.05111919343471527, 0.05270196497440338, -0.017613664269447327, 0.045301444828510284, -0.015057703480124474, 0.012876047752797604, 0.067759670317173, 0.05360029265284538, -0.037280648946762085, 0.002137541538104415, 0.01515395287424326, -0.0929984301328659, 0.008646415546536446, 0.03390122205018997, 0.02148503251373768, 0.007764128502458334, -0.08649624139070511, -0.014565762132406235, -0.06053025647997856, 0.06361024081707001, 0.011485776863992214, -0.03206178545951843, 0.04979308694601059, 0.006721425335854292, 0.028981801122426987, -0.0632680207490921, 0.0105446707457304, 0.018437132239341736, 0.08084960281848907, 0.02028726227581501, -0.014383956789970398, -0.08230403810739517, 0.002740437863394618, 0.04696976765990257, 0.06194191798567772, -0.0652785673737526, 0.06254080682992935, 0.09188621491193771, -0.009213218465447426, 0.0037109539844095707, -0.05886193364858627, 0.06805910915136337, 0.05154696851968765, -0.021078646183013916, 0.027249310165643692, -0.0060851089656353, 0.013175491243600845, 0.032254286110401154, 0.013710210099816322, 0.006069067399948835, 0.023078497499227524, 0.010394948534667492, 0.0721229761838913, 0.010170366615056992, 0.013988264836370945, 0.003130783326923847, 0.002645525150001049, 0.010689044371247292, -0.02384849451482296, 0.01193494163453579, 0.02245822362601757, -0.031142069026827812, -0.0026348307728767395, 0.01997712440788746, 0.020704342052340508, 0.01606297679245472, -0.01133605558425188, -0.017677830532193184, 0.06245524808764458, 0.025837650522589684, -0.09385398030281067, 0.029773186892271042, -0.11943496763706207, -0.041643962264060974, 0.07473240792751312, -0.003232379909604788, 0.04962197691202164, -0.05638083443045616, -0.004475602880120277, 0.0030211657285690308, 0.007496768608689308, 0.020533232018351555, 0.03672454133629799, 0.0017859634244814515, 0.053086962550878525, 0.04846698418259621, -0.05432751029729843, 0.08521291613578796, -0.007314964197576046, 0.018875600770115852, -0.018266022205352783, -0.02958068810403347, -0.006053025834262371, 0.05261640623211861, 0.03005124069750309, -0.06835855543613434, 0.017014777287840843, 0.08204737305641174, 0.015335758216679096, -0.05886193364858627, 0.020372817292809486, 0.008496694266796112, -0.022522389888763428, -0.02071503736078739, 0.008288153447210789, 0.001391607685945928, -0.061770807951688766, 0.013421461917459965, 0.02040489949285984, 0.04517311230301857, -0.00996717344969511, -0.06754577904939651, -0.0003320274408906698, 0.0049996282905340195, 0.03698120638728142, -0.029174301773309708, -0.04361173138022423, 0.02795514091849327, 0.03411510959267616, 0.06823021918535233, -0.01960282027721405, 0.07195186614990234, -0.02181655913591385, 0.04080979898571968, 0.007502115797251463, 0.05312974005937576, -0.01710033230483532, -0.009619605727493763, -0.04168673977255821, -0.03569788113236427, 0.06322524696588516, -0.007614407222718, -0.07439018785953522, 0.011132861487567425, -0.020436983555555344, 0.019966429099440575, -0.01631964184343815, -0.004277756903320551, 0.006031637080013752, 0.013977570459246635, 0.007726698182523251, -0.009737243875861168, 0.021837947890162468, -0.024233492091298103, -0.04339784383773804, 0.008576902560889721, -0.04970753192901611, -0.01830879971385002, 0.03161262348294258, -0.030650127679109573, -0.04222146049141884, 0.07486074417829514, -0.019806014373898506, 0.011549943126738071, -0.00021739694057032466, -0.08007960766553879, 0.035676490515470505, 0.004919420462101698, 0.0024650574196130037, -0.07289297133684158, 0.025859039276838303, 0.05312974005937576, -0.01179591380059719, -0.0033366503193974495, 0.04709810018539429, -0.030436240136623383, -0.02222294546663761, 0.06788799911737442, -0.030799848958849907, -0.01548547949641943, -0.002196360845118761, 0.03787953779101372, -0.02404099330306053, -0.1012972816824913, -0.033152613788843155, 0.01272632647305727, 0.0028233195189386606, -0.06442301720380783, -0.03734481707215309, -0.053086962550878525, -0.04198618233203888, 0.012576605193316936, -0.019538654014468193, 0.054969172924757004, 0.013389378786087036, -0.017185887321829796, -0.019613515585660934, 0.03248956426978111, 0.012202301062643528, 0.021367395296692848, -0.04200757294893265, -0.049236979335546494, -0.05548250675201416, 0.02981596440076828, 0.018030744045972824, -0.03343066945672035, 0.050990860909223557, -0.012020496651530266, -0.03144151344895363, 0.048509761691093445, -0.053172517567873, 0.02179517038166523, 0.008887039497494698, -0.015089786611497402, 0.01700408384203911, 0.05086252838373184, 0.017228664830327034, -0.02101447992026806, 0.019303377717733383, 0.014202152378857136, 0.019399626180529594, 0.05274474248290062, -0.0040451535023748875, 0.03435038775205612, 0.054926395416259766, 0.05257362872362137, 0.0024744148831814528, 0.020255178213119507, 0.015603117644786835, 0.028361527249217033, -0.051718078553676605, 0.0007432602578774095, -0.0017779426416382194, 0.01635172590613365, 0.03580482304096222, 0.000583512766752392, 0.0448736697435379, -0.01858685351908207, 0.01514325849711895, 0.01880074106156826, -0.020907536149024963, -0.012822575867176056, 0.05043475329875946, -0.03676731884479523, 0.05869082361459732, 0.03167678788304329, -0.03512038290500641, 0.029516521841287613, -0.022351279854774475, -0.02682153508067131, -0.02177378162741661, 0.008705235086381435, 0.004157444927841425, 0.023014331236481667, 0.03571926802396774, 0.03738759458065033, 0.05591028183698654, 0.04410367086529732, -0.022351279854774475, -0.022543778643012047, -0.04684143513441086, -0.01835157722234726, 0.023912660777568817, 0.030778460204601288, 0.013442850671708584, 0.11173500865697861, -0.0724651962518692, -0.01993434689939022, 0.018597546964883804, 0.002223096787929535, 0.014170069247484207, -0.047568656504154205, -0.043932560831308365, -0.013956181704998016, -0.020180316641926765, 0.04684143513441086, -0.02337794005870819, -0.031783733516931534, -0.014170069247484207, -0.0008321573841385543, 0.011688970029354095, 0.001494541298598051, 0.03261789679527283, 0.03734481707215309, -0.017955884337425232, -0.05419917777180672, -0.014608539640903473, -0.057236384600400925, 0.009721201844513416, -0.007560934871435165, -0.034992050379514694, -0.01743185892701149, -0.0298373531550169, 0.043440621346235275, 0.028489859774708748, 0.04123757407069206, 0.04423200339078903, -0.0410022996366024, 0.05428473278880119, -0.011785219423472881, 0.03300289437174797, 0.004475602880120277, -0.0573219396173954, 0.07186631113290787, -0.0059514292515814304, -0.00852877739816904, -0.004820497240871191, -0.032895948737859726, 0.012929519638419151, 0.019025323912501335, -0.053343627601861954, 0.0029971033800393343, 0.012319939211010933, 0.03901313990354538, 0.046926990151405334, -0.02386988326907158, 0.02187003195285797, -0.0008615669212304056, -0.02632959373295307, 0.01858685351908207, -0.04314117506146431, -0.0029971033800393343, 0.004641366191208363, -0.013485628180205822, -0.062070250511169434, -0.023164052516222, 0.009138357825577259, -0.0623696930706501, 0.012245078571140766, -0.012662160210311413, -0.06733188778162003, -0.00007435944280587137, 0.012191606685519218, -0.010715780779719353, -0.01712172105908394, -0.019314071163535118, 0.013453545048832893, 0.03760148212313652, -0.025516819208860397, -0.03210456296801567, 0.019848791882395744, -0.00043412548257037997, -0.06322524696588516, 0.03640370815992355, 0.00997786782681942, 0.004932788200676441, -0.04374006390571594, 0.03974036127328873, 0.0113574443385005, -0.05672305449843407, 0.01854407601058483, -0.010255921632051468, -0.02106795273721218, -0.007347047328948975, -0.006192052736878395, -0.03882064297795296, -0.013122018426656723, -0.0005327144172042608, 0.005807054694741964, 0.001477162935771048, 0.02819041721522808, -0.01388132106512785, 0.03321678191423416, 0.019100183621048927, -0.027227921411395073, -0.00023043072724249214, 0.008988636545836926, 0.004505012650042772, -0.01179591380059719, 0.02044767700135708, -0.010143631137907505, 0.004881989676505327, 0.02752736397087574, 0.005304418504238129, 0.040724243968725204, -0.0075128101743757725, 0.005293724127113819, 0.01717519387602806, -0.041601184755563736, -0.011988413520157337, 0.027227921411395073, -0.023891272023320198, -0.048937536776065826, 0.0037777938414365053, -0.018993239849805832, -0.07640073448419571, -0.02097170241177082, 0.020319344475865364, 0.02451154589653015, -0.015613812021911144, -0.02705681137740612, 0.03991147130727768, 0.06245524808764458, 0.013688821345567703, -0.0353342704474926, 0.029687631875276566, 0.04465978220105171, -0.07610129565000534, -0.024597100913524628, 0.04168673977255821, -0.03877786546945572, 0.0022511694114655256, -0.0724651962518692, 0.021827254444360733, 0.02887485735118389, -0.003157519269734621, 0.000596880738157779, 0.0029463048558682203, 0.0043766796588897705, 0.004208242986351252, -0.05325807258486748, 0.03007262945175171, -0.028340138494968414, -0.014886593446135521, -0.020672259852290154, -0.026286814361810684, 0.01764574646949768, -0.08247514814138412, 0.0605730339884758, 0.04021091386675835, -0.02662903629243374, -0.029430966824293137, -0.02030865103006363, -0.013068546541035175, 0.005807054694741964, 0.016661861911416054, 0.019185738638043404, -0.025730706751346588, 0.024404602125287056, -0.05488361790776253, -0.012608688324689865, -0.040275078266859055, -0.001973115373402834, 0.03024373948574066, 0.016383808106184006, -0.02705681137740612, 0.024917932227253914, 0.08880622684955597, -0.08628235012292862, -0.020704342052340508, 0.0009551428956910968, 0.011122167110443115, 0.0748179629445076, 0.0188435185700655, 0.002839361084625125, 0.002874117810279131, -0.003563906066119671, -0.004625324625521898, 0.01696130633354187, -0.0009397696703672409, 0.026008760556578636, -0.01548547949641943, 0.0123947998508811, -0.08837845176458359, -0.02709958888590336, -0.023484883829951286, 0.017089638859033585, -0.0053498693741858006, 0.012811881490051746, 0.021035868674516678, -0.04125896468758583, 0.04615699499845505, 0.008443222381174564, 0.02932402305305004, -0.013913404196500778, 0.04906586930155754, 0.01948518119752407, -0.004093278665095568, -0.04594310745596886, -0.03813620284199715, -0.07413352280855179, -0.029409578070044518, -0.017185887321829796, -0.016362419351935387, 0.0022471591364592314, 0.014790344052016735, 0.03779397904872894, 0.023484883829951286, 0.059760261327028275 ]
30,979
networkx.generators.small
octahedral_graph
Returns the Platonic Octahedral graph. The octahedral graph is the 6-node 12-edge Platonic graph having the connectivity of the octahedron [1]_. If 6 couples go to a party, and each person shakes hands with every person except his or her partner, then this graph describes the set of handshakes that take place; for this reason it is also called the cocktail party graph [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Octahedral graph References ---------- .. [1] https://mathworld.wolfram.com/OctahedralGraph.html .. [2] https://en.wikipedia.org/wiki/Tur%C3%A1n_graph#Special_cases
def _raise_on_directed(func): """ A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. """ @wraps(func) def wrapper(*args, **kwargs): if kwargs.get("create_using") is not None: G = nx.empty_graph(create_using=kwargs["create_using"]) if G.is_directed(): raise NetworkXError("Directed Graph not supported") return func(*args, **kwargs) return wrapper
(create_using=None, *, backend=None, **backend_kwargs)
[ 0.02052074857056141, -0.003848758526146412, 0.0364435613155365, 0.005125714465975761, 0.0002054646611213684, 0.039073508232831955, -0.06007730960845947, -0.017837127670645714, 0.08022234588861465, -0.03692661225795746, 0.01923261024057865, 0.01080604363232851, 0.04419027641415596, -0.026782527565956116, 0.010967060923576355, 0.04515638202428818, -0.04880610480904579, 0.09396248310804367, 0.0234011672437191, 0.04737484082579613, -0.00920481700450182, -0.031863514333963394, -0.0026008752174675465, -0.01993035152554512, 0.0007502954686060548, 0.043510425835847855, -0.025208137929439545, 0.0010432573035359383, 0.006100763101130724, 0.023705311119556427, -0.034368228167295456, -0.04683811590075493, 0.0008671447285450995, 0.06558767706155777, 0.04633717238903046, 0.0627967119216919, -0.04658764600753784, 0.08108110725879669, -0.10204912722110748, -0.07349541038274765, -0.0312015563249588, 0.007684098556637764, 0.031970858573913574, 0.011396439746022224, -0.001335100969299674, -0.020019805058836937, 0.009857830591499805, 0.0001222305145347491, -0.08931087702512741, -0.042043380439281464, 0.02241717278957367, 0.00561771122738719, 0.055103667080402374, 0.06147278845310211, 0.012282034382224083, 0.04039742797613144, -0.009678922593593597, 0.029018878936767578, 0.03946710750460625, -0.016253791749477386, 0.004978115204721689, 0.05106034502387047, 0.012478833086788654, -0.024188362061977386, -0.032954853028059006, 0.0007782498141750693, -0.07821857929229736, -0.026675183326005936, -0.02193412184715271, 0.05463850498199463, 0.01161112915724516, -0.005818982608616352, 0.017219895496964455, 0.009491069242358208, 0.07231461256742477, -0.030664831399917603, 0.019840897992253304, -0.010242483578622341, 0.04830516129732132, -0.02361585572361946, -0.03596051037311554, -0.018713777884840965, -0.02241717278957367, 0.0070266118273139, 0.06204529479146004, -0.02193412184715271, -0.05127503350377083, 0.026460492983460426, 0.030181780457496643, -0.044440750032663345, -0.005666911136358976, -0.035334330052137375, -0.017345130443572998, 0.005246477201581001, -0.03216765820980072, 0.05961214751005173, 0.029501929879188538, -0.052670516073703766, 0.0640132874250412, -0.011843710206449032, 0.0018181526102125645, 0.008270022459328175, -0.019107375293970108, 0.03345579653978348, -0.016235901042819023, -0.09732595086097717, 0.00983099453151226, -0.028016993775963783, -0.019572535529732704, -0.023383276537060738, -0.08279862254858017, -0.01830228790640831, 0.04998689517378807, 0.0009694577311165631, 0.017327239736914635, -0.0011427748249843717, -0.010081466287374496, -0.018606431782245636, 0.0018326889257878065, -0.03635410591959953, -0.0217194315046072, 0.02903676964342594, -0.05649914592504501, -0.051096126437187195, 0.05649914592504501, -0.02399156428873539, -0.0005171559751033783, -0.016575826331973076, 0.042329635471105576, 0.01518928911536932, 0.018660105764865875, 0.04726749286055565, -0.029931308701634407, 0.03703395649790764, 0.00441455515101552, 0.0364435613155365, -0.0539228729903698, 0.05270629748702049, -0.014142678119242191, 0.0027909649070352316, -0.0029251459054648876, -0.018910575658082962, 0.027927540242671967, 0.04261588677763939, 0.013927987776696682, 0.0416855663061142, -0.055640388280153275, -0.02279287949204445, 0.024331487715244293, -0.028446372598409653, 0.05918276682496071, 0.005595347844064236, 0.009030381217598915, 0.016924697905778885, -0.04315261170268059, 0.034368228167295456, -0.03320532664656639, 0.02551228180527687, 0.021307943388819695, 0.014339476823806763, -0.03152358904480934, -0.022864442318677902, 0.04229385405778885, 0.023311713710427284, 0.015609723515808582, -0.022220375016331673, 0.009983066469430923, -0.01998402364552021, 0.007947987876832485, -0.00428708316758275, -0.04544263333082199, -0.022345609962940216, -0.005787673871964216, -0.03932397812604904, -0.028714735060930252, 0.030289124697446823, 0.03742755576968193, 0.04261588677763939, -0.03352735936641693, 0.016119610518217087, 0.05442381650209427, -0.04404715076088905, -0.019590426236391068, -0.02832113765180111, 0.041291967034339905, 0.018660105764865875, 0.009902558289468288, -0.02529759146273136, 0.003251652931794524, 0.0003634068707469851, 0.017559820786118507, 0.017407748848199844, 0.03250758349895477, 0.04980798810720444, 0.03803584352135658, -0.09267434477806091, -0.009365834295749664, -0.0014055459760129452, -0.01696942374110222, 0.0746404230594635, 0.052670516073703766, 0.032149769365787506, 0.03604996204376221, 0.014089005067944527, -0.004843934439122677, 0.04726749286055565, -0.02513657510280609, -0.05188332125544548, -0.05220535397529602, -0.010358773171901703, -0.038858819752931595, -0.034260883927345276, 0.03497651591897011, 0.05156128853559494, -0.03445767983794212, 0.023150695487856865, 0.021415287628769875, 0.05403021723031998, -0.01034088246524334, -0.02717612497508526, -0.012112071737647057, -0.01827545277774334, -0.008006133139133453, -0.02035973034799099, 0.06268936395645142, -0.04136352986097336, 0.008153731934726238, -0.05252739042043686, 0.025637516751885414, -0.01784607395529747, 0.04104149714112282, -0.015869140625, 0.016826298087835312, 0.022828660905361176, 0.03893038257956505, -0.047732654958963394, 0.01971566118299961, -0.045084815472364426, 0.010260374285280704, 0.013570171780884266, -0.061866387724876404, -0.0011137023102492094, 0.0043966639786958694, -0.0005512603092938662, 0.08279862254858017, 0.029591383412480354, -0.009687868878245354, 0.048877667635679245, 0.005899491254240274, -0.04161400347948074, -0.04211494326591492, -0.011405385099351406, -0.003754831850528717, -0.0236695297062397, 0.00843103975057602, -0.028732625767588615, -0.059969961643218994, -0.05882495269179344, 0.039288196712732315, 0.006955048535019159, -0.036318324506282806, 0.058252446353435516, -0.056678056716918945, 0.02041340246796608, 0.004606881178915501, -0.03345579653978348, -0.025261810049414635, 0.022113028913736343, -0.03413564711809158, 0.025047119706869125, -0.022291937842965126, 0.04093415290117264, 0.07392478734254837, -0.024170471355319023, 0.006539087742567062, 0.020055586472153664, -0.020055586472153664, 0.011593238450586796, -0.013310755603015423, 0.03497651591897011, -0.04619404673576355, -0.016629498451948166, -0.05209800973534584, 0.03640777990221977, -0.07492667436599731, 0.03180984407663345, 0.00977732241153717, 0.012711414135992527, 0.01142327580600977, -0.011906327679753304, 0.030503815039992332, 0.012004727497696877, 0.03476182371377945, 0.03209609538316727, -0.04769687354564667, 0.003358997870236635, 0.02692565508186817, -0.04200759902596474, 0.03384939581155777, 0.03231078386306763, 0.02930513024330139, -0.03753490000963211, -0.008533911779522896, 0.01830228790640831, 0.00864125695079565, 0.0038241585716605186, 0.034690260887145996, -0.02799910306930542, 0.004705280531197786, -0.01521612610667944, -0.06551611423492432, 0.03513753041625023, -0.015547105111181736, 0.019143156707286835, 0.03572792932391167, 0.02463563159108162, -0.011825819499790668, -0.03796427696943283, 0.033777832984924316, 0.06938052177429199, -0.03567425534129143, 0.10562728345394135, -0.0673767551779747, 0.0013339828001335263, -0.08308487385511398, 0.048233598470687866, 0.06107919290661812, 0.038644127547740936, 0.05639180168509483, 0.08995494246482849, 0.0021234143059700727, -0.028446372598409653, -0.007576753851026297, -0.018239671364426613, -0.08730710297822952, 0.027838084846735, 0.06938052177429199, -0.04884188622236252, 0.05538991838693619, -0.01760454848408699, 0.008663619868457317, 0.003859940217807889, -0.008860418573021889, 0.0018114435952156782, -0.006731413770467043, 0.03266860172152519, 0.008931982330977917, -0.02361585572361946, 0.023651638999581337, 0.04494168981909752, -0.010144083760678768, 0.1102788969874382, -0.02129005268216133, 0.009795213118195534, 0.0406121164560318, 0.014634674414992332, -0.02463563159108162, 0.033777832984924316, -0.02724768966436386, -0.005219641141593456, -0.03651512414216995, -0.040969934314489365, 0.057429470121860504, 0.013901151716709137, 0.061759043484926224, -0.012112071737647057, 0.03211398795247078, 0.013167629018425941, 0.04569310322403908, -0.05345771089196205, -0.03277594596147537, -0.06991724669933319, -0.0356384739279747, -0.00005196019628783688, 0.018257562071084976, 0.009902558289468288, -0.012290979735553265, -0.014312640763819218, 0.03732021152973175, 0.06887958198785782, -0.03655090555548668, 0.011673747561872005, 0.045836228877305984, -0.005094405263662338, 0.057107433676719666, -0.04279479384422302, 0.05360083654522896, 0.0844445750117302, -0.017488257959485054, -0.03735599294304848, -0.009012490510940552, -0.04036164656281471, 0.029179895296692848, 0.031756170094013214, -0.03320532664656639, -0.03345579653978348, 0.014643619768321514, 0.00011531179916346446, -0.027641287073493004, 0.003710104851052165, -0.033885177224874496, -0.00810900516808033, -0.016602663323283195, 0.028625281527638435, 0.027086671441793442, 0.022005684673786163, -0.008471294306218624, 0.015904922038316727, 0.039180852472782135, -0.00740679120644927, 0.04186447337269783, -0.01334653701633215, -0.041077278554439545, 0.007688571698963642, 0.049736425280570984, 0.029931308701634407, 0.009030381217598915, 0.03656879439949989, 0.024081017822027206, -0.03472604230046272, 0.07177788764238358, -0.04104149714112282, 0.07700200378894806, 0.038858819752931595, 0.042436979711055756, -0.0395386703312397, -0.031434137374162674, 0.007348646409809589, -0.04615826532244682, 0.029323022812604904, 0.018588541075587273, -0.049736425280570984, 0.03091530315577984, -0.05227692052721977, 0.025637516751885414, -0.013230246491730213, -0.015341361053287983, 0.014473657123744488, 0.0032203439623117447, 0.058037757873535156, 0.02209513820707798, -0.007764607202261686, -0.004893133882433176, -0.017130441963672638, -0.019805116578936577, -0.03635410591959953, 0.020878564566373825, 0.023204367607831955, 0.0011998018017038703, -0.022327719256281853, 0.06866489350795746, -0.0003561387420631945, 0.08129579573869705, 0.02334749512374401, -0.14047856628894806, -0.0108597157523036, -0.00913772638887167, -0.03016388975083828, -0.02463563159108162, 0.05567616969347, 0.01183476485311985, -0.008381839841604233, -0.10412445664405823, -0.024188362061977386, -0.032131876796483994, 0.04039742797613144, -0.010000957176089287, 0.014581002295017242, -0.024170471355319023, 0.0016716716345399618, 0.06841441988945007, -0.04157821834087372, -0.005425385199487209, -0.02853582613170147, 0.005300149787217379, -0.01343599148094654, -0.0157349593937397, -0.0025449662934988737, 0.03540589287877083, 0.01362384483218193, 0.002025014953687787, -0.017488257959485054, 0.026084786280989647, 0.011244367808103561, -0.02930513024330139, 0.004911024589091539, -0.015090890228748322, -0.013892206363379955, 0.002893836935982108, 0.06505095213651657, -0.05059518292546272, -0.0400753915309906, 0.017166223376989365, -0.06537298113107681, 0.03588894382119179, 0.028732625767588615, -0.04383246228098869, -0.018928466364741325, -0.01648637279868126, -0.07642950117588043, 0.015913866460323334, -0.023150695487856865, -0.040325865149497986, -0.004799207206815481, 0.041148841381073, -0.03173828125, -0.017300404608249664, 0.014097950421273708, 0.006785085890442133, -0.015556051395833492, 0.006776140537112951, 0.06444266438484192, 0.049199700355529785, 0.0812242329120636, 0.02594166062772274, 0.011110187508165836, -0.02778441272675991, -0.018284397199749947, 0.01643270067870617, -0.039717577397823334, 0.052348483353853226, 0.034296665340662, 0.0005319717456586659, -0.010439282283186913, -0.0040679206140339375, 0.013516499660909176, 0.04261588677763939, -0.002737292554229498, 0.031970858573913574, 0.017586655914783478, 0.010779207572340965, 0.044548094272613525, 0.016692116856575012, 0.05224113538861275, -0.01170058362185955, -0.005148077849298716, -0.005935273133218288, 0.04891344904899597, -0.08358582109212875, -0.01581546850502491, 0.011414330452680588, -0.012156798504292965, -0.04315261170268059, -0.0286431722342968, 0.018373852595686913, -0.026782527565956116, 0.017559820786118507, 0.008851473219692707, 0.003886776277795434, -0.04937860742211342, -0.03655090555548668, 0.004237883258610964, -0.0005054151406511664, -0.005045205820351839, 0.06644643098115921, 0.008721765130758286, -0.015412924811244011, 0.06179482489824295, 0.018713777884840965, 0.014679402112960815, -0.0611865371465683, 0.002871473552659154, -0.0037883769255131483, -0.03935975953936577, 0.03978914022445679, -0.017720837146043777, 0.04755374789237976, -0.0217194315046072, -0.023490620777010918, -0.009119835682213306, -0.04554997757077217, -0.04923548176884651, 0.010000957176089287, -0.025816425681114197, -0.01998402364552021, 0.02474297769367695, -0.002987763611599803, -0.034260883927345276, 0.01297083031386137, -0.06533720344305038, -0.05159706994891167, -0.020216604694724083, -0.031040538102388382, 0.018552759662270546, 0.013453882187604904, -0.024510396644473076, 0.0010018848115578294, -0.01142327580600977, -0.02712245285511017, -0.02604900486767292, -0.05453116074204445, -0.06251045316457748, 0.021898340433835983, -0.05560460686683655, 0.013543335720896721, 0.01183476485311985, 0.0009331170585937798, -0.016745788976550102, 0.049951113760471344, -0.02241717278957367, -0.07066866010427475, 0.06329765170812607, 0.018695887178182602, 0.023812655359506607, 0.05145394057035446, -0.002475639572367072, -0.029162004590034485, -0.06136544421315193, -0.017005205154418945, -0.07363853603601456, -0.068593330681324, 0.050237368792295456, -0.01792658120393753, -0.015994375571608543, 0.008346058428287506, -0.04386824369430542, -0.05356505513191223, 0.03266860172152519, 0.005559566430747509, 0.021808885037899017, 0.031541481614112854, -0.04175712913274765, -0.05020158737897873, -0.02111114375293255, -0.02014504186809063, 0.057751502841711044, 0.009786267764866352, -0.040218520909547806, -0.007773552555590868, 0.04569310322403908, -0.018874794244766235, -0.011020733043551445, 0.023758983239531517, 0.002887127920985222, -0.03206031396985054, -0.0673767551779747, 0.03404619172215462, 0.02572697028517723, 0.024295706301927567, -0.004054502584040165, -0.07199258357286453, 0.0046381899155676365, -0.038214750587940216, -0.012952939607203007, -0.008654674515128136, -0.03141624480485916, 0.02891153283417225, -0.03481549769639969, 0.04758952930569649, -0.023114914074540138, 0.013793807476758957, 0.04805469140410423, -0.0005887191509827971, -0.05170441418886185, 0.055425699800252914, 0.04798312857747078, -0.0322750024497509, -0.021200599148869514, 0.004392191302031279, -0.021862559020519257, 0.02383054606616497, -0.0027663649525493383, 0.03796427696943283, 0.0035781601909548044, 0.0004685153253376484, 0.038322094827890396, -0.016092775389552116, -0.053207240998744965, -0.02513657510280609, -0.051740195602178574, -0.0416855663061142, -0.018606431782245636, 0.011208586394786835, -0.010054630227386951, -0.017917636781930923, -0.0320066437125206, 0.021093253046274185, 0.011145968921482563, -0.03850100189447403, -0.02284655161201954, -0.03588894382119179, 0.03053959645330906, -0.0528494231402874, -0.01760454848408699, -0.03282961994409561, -0.03409986570477486, -0.018159162253141403, -0.03229289501905441, 0.027032999321818352, -0.015502378344535828, -0.006963993888348341, -0.015806522220373154, 0.036085743457078934, 0.01960831694304943, -0.02345483936369419, -0.06641065329313278, -0.06819973140954971, 0.014634674414992332, -0.0031823262106627226, -0.011521675623953342, 0.04873454198241234, 0.0172825139015913, 0.00812242366373539, 0.03488706052303314, 0.030897412449121475, -0.0712769478559494, -0.05238426476716995, 0.01901792176067829, 0.003927030600607395, 0.01640586368739605, -0.033652596175670624, -0.023687420412898064, 0.03746333718299866, 0.0016560172662138939, -0.010269319638609886, -0.052348483353853226, 0.011906327679753304, 0.014402094297111034, -0.03259703889489174, -0.030396470800042152, -0.01518928911536932, -0.013409154489636421, -0.017479311674833298, 0.0013708826154470444, -0.004656080622226, -0.03547745570540428, -0.010331937111914158, -0.028339028358459473, 0.0364435613155365, -0.017166223376989365, 0.023651638999581337, 0.03764224424958229, 0.0012098653241991997, 0.06329765170812607, -0.024707196280360222, 0.03640777990221977, -0.010645026341080666, 0.07442572712898254, -0.02821379154920578, 0.03222133219242096, -0.006413851864635944, 0.007549917791038752, -0.0645500048995018, -0.012290979735553265, 0.05696430802345276, -0.026567839086055756, 0.018445415422320366, 0.08931087702512741, -0.00046599944471381605, -0.024081017822027206, 0.04490590840578079, -0.008283440954983234, 0.025798534974455833, 0.032954853028059006, 0.02425992488861084, -0.03596051037311554, 0.04071946069598198, -0.013176574371755123, 0.011145968921482563, -0.06841441988945007, -0.015493432991206646, 0.0039807031862437725, 0.03465447947382927, -0.02479664981365204, -0.046659208834171295, 0.01960831694304943, 0.04422605782747269, 0.05696430802345276 ]
30,983
networkx.algorithms.similarity
optimal_edit_paths
Returns all minimum-cost edit paths transforming G1 to G2. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. Returns ------- edit_paths : list of tuples (node_edit_path, edge_edit_path) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric Optimal edit path cost (graph edit distance). When the cost is zero, it indicates that `G1` and `G2` are isomorphic. Examples -------- >>> G1 = nx.cycle_graph(4) >>> G2 = nx.wheel_graph(5) >>> paths, cost = nx.optimal_edit_paths(G1, G2) >>> len(paths) 40 >>> cost 5.0 Notes ----- To transform `G1` into a graph isomorphic to `G2`, apply the node and edge edits in the returned ``edit_paths``. In the case of isomorphic graphs, the cost is zero, and the paths represent different isomorphic mappings (isomorphisms). That is, the edits involve renaming nodes and edges to match the structure of `G2`. See Also -------- graph_edit_distance, optimize_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, *, backend=None, **backend_kwargs)
[ 0.04687132686376572, -0.04295044392347336, 0.0001346052304143086, 0.01932433992624283, -0.05139714106917381, -0.05668472871184349, -0.018730606883764267, -0.007539293263107538, 0.01814807578921318, -0.06452649086713791, -0.04118044674396515, 0.0081162229180336, -0.008625936694443226, 0.055654097348451614, -0.011516186408698559, -0.005438821390271187, -0.0019884465727955103, -0.06242041662335396, 0.032263245433568954, 0.0031170998699963093, -0.02773742936551571, -0.08330190926790237, 0.03208400309085846, 0.039141587913036346, -0.043891455978155136, -0.0009872217196971178, 0.04597512260079384, 0.014518460258841515, 0.029104135930538177, -0.009152455255389214, 0.00681112939491868, -0.06788724660873413, -0.06264446675777435, 0.006144579965621233, -0.03165831044316292, 0.005606858991086483, 0.041785381734371185, 0.019884465262293816, 0.014888143166899681, -0.05112828314304352, -0.04897739738225937, -0.014809725806117058, -0.013812702149152756, -0.037886906415224075, 0.04722980782389641, 0.03591526672244072, -0.044317152351140976, 0.006239801179617643, -0.01554909162223339, -0.018058454617857933, 0.015795547515153885, -0.12699171900749207, -0.045414999127388, 0.03804374486207962, 0.00941571407020092, 0.021486425772309303, 0.00953334104269743, 0.042255889624357224, 0.053503215312957764, -0.08863430470228195, 0.02511603944003582, -0.036139316856861115, -0.017991241067647934, 0.03170311823487282, -0.05784979090094566, -0.004481006413698196, -0.03163590282201767, -0.04158373922109604, 0.02234901860356331, 0.03345071151852608, -0.052651822566986084, 0.011471375823020935, 0.05108347162604332, -0.07971709966659546, -0.000028487647796282545, 0.011269730515778065, 0.013387005776166916, -0.02296515740454197, -0.005497634410858154, -0.025026420131325722, 0.010468751192092896, -0.040911588817834854, 0.04709537699818611, -0.07214420288801193, 0.0738021731376648, 0.002358129480853677, 0.030515652149915695, 0.018741808831691742, -0.04718499630689621, -0.07908976078033447, 0.00427656015381217, -0.030045146122574806, -0.017823202535510063, 0.015302636660635471, 0.03808855265378952, 0.009807802736759186, -0.024376673623919487, -0.05498194694519043, 0.015392256900668144, 0.0021648861002177, 0.064750537276268, 0.05663992092013359, -0.03201679140329361, 0.024354269728064537, 0.009191663935780525, -0.07729735970497131, -0.04153892770409584, 0.05507156625390053, 0.027378948405385017, -0.06134497746825218, -0.05753612145781517, 0.030157173052430153, 0.04144930839538574, -0.026281101629137993, -0.010334320366382599, 0.014921750873327255, -0.04259196296334267, 0.018719403073191643, -0.018820226192474365, 0.009583752602338791, 0.00993663165718317, -0.014059157110750675, -0.033540330827236176, 0.03244248405098915, 0.013902322389185429, -0.04897739738225937, 0.008502709679305553, 0.0695004090666771, 0.023973383009433746, -0.07528090476989746, 0.016792571172118187, -0.06748395413160324, 0.009998245164752007, 0.10136035829782486, -0.0012336770305410028, -0.012994918040931225, -0.037483617663383484, 0.00963976513594389, 0.0183609239757061, 0.021990537643432617, 0.031411852687597275, -0.03976893052458763, -0.007679324597120285, -0.005741289351135492, -0.01800244301557541, -0.05233815312385559, 0.011538591235876083, -0.019481174647808075, 0.007768944837152958, 0.008037804625928402, -0.02147522196173668, 0.005144755356013775, 0.0020010494627058506, -0.00961735937744379, 0.025295279920101166, -0.007276033982634544, -0.0002170487423427403, -0.010401535779237747, -0.0039068772457540035, 0.015291433781385422, -0.0045846295543015, -0.04843967780470848, 0.0020430588629096746, 0.011516186408698559, 0.05372726544737816, -0.018484150990843773, 0.045706264674663544, 0.007987393997609615, -0.07917938381433487, 0.005870118271559477, -0.032196030020713806, -0.046557653695344925, -0.07460875064134598, -0.014238397590816021, 0.018965858966112137, 0.01651250757277012, -0.009046031162142754, -0.026124266907572746, 0.007281634956598282, -0.016523711383342743, 0.02820793353021145, 0.013734283857047558, 0.049201447516679764, 0.05076980218291283, -0.0013113945024088025, 0.05977662280201912, 0.030112361535429955, -0.027423758059740067, 0.02272990345954895, -0.02244984172284603, -0.020679844543337822, -0.06309256702661514, -0.012502007186412811, 0.05054575204849243, 0.03320425748825073, 0.02854401059448719, -0.005220372229814529, 0.03900716081261635, 0.004102921579033136, 0.07904495298862457, -0.03073970228433609, -0.012277957051992416, 0.06551231443881989, 0.007466476876288652, 0.03156868740916252, -0.002639592858031392, 0.029283376410603523, -0.018472949042916298, 0.011986691504716873, 0.029283376410603523, -0.049111828207969666, 0.028051098808646202, 0.02775983326137066, -0.0017251874087378383, 0.026774011552333832, 0.038715895265340805, -0.034369319677352905, 0.040015384554862976, -0.020668640732765198, -0.03244248405098915, 0.013274980708956718, -0.019245922565460205, -0.015168205834925175, -0.011807451955974102, 0.041337281465530396, -0.0561918169260025, 0.009527739137411118, 0.028028694912791252, 0.04812600836157799, -0.04418272152543068, 0.008037804625928402, -0.07891052216291428, 0.049201447516679764, -0.016053205356001854, 0.040441080927848816, -0.02863362990319729, -0.02719970792531967, 0.025855405256152153, 0.0346829891204834, -0.0012735859490931034, -0.07272673398256302, -0.053548023104667664, -0.037438806146383286, 0.00825625378638506, -0.0043213702738285065, -0.000798879424110055, 0.041292473673820496, -0.008805177174508572, -0.011129699647426605, 0.008250652812421322, -0.01757674664258957, -0.03533273562788963, -0.009908624924719334, -0.007259230129420757, -0.040396273136138916, -0.0035932068713009357, -0.0410684235394001, 0.04214386269450188, -0.012502007186412811, -0.005186764523386955, 0.016366874799132347, 0.008833183906972408, -0.0432417094707489, 0.02140800654888153, 0.0238389540463686, 0.023144397884607315, 0.028387174010276794, 0.013028525747358799, -0.0694107860326767, -0.027401354163885117, 0.0367218479514122, 0.07554976642131805, -0.03286818042397499, 0.060807254165410995, -0.017924025654792786, 0.010715206153690815, -0.002722211414948106, 0.018495352938771248, -0.01169542595744133, -0.04722980782389641, -0.030538057908415794, -0.007651318330317736, -0.041382092982530594, 0.014596877619624138, -0.03669944033026695, -0.015392256900668144, -0.02903692051768303, -0.026930848136544228, 0.014932953752577305, 0.0012602830538526177, 0.0410684235394001, -0.01817047968506813, 0.04227829352021217, 0.03298020735383034, 0.0867970883846283, 0.03752842918038368, 0.01911149173974991, 0.00210327235981822, -0.0388055145740509, 0.0648849681019783, 0.030605273321270943, -0.04312968626618385, 0.027849454432725906, -0.05829789116978645, 0.015313838608562946, 0.014787320978939533, 0.01494415570050478, -0.01343181636184454, 0.04938068985939026, 0.051262710243463516, -0.03416767343878746, -0.028319960460066795, -0.04295044392347336, 0.03300261124968529, -0.02183370292186737, -0.002758619375526905, -0.008172235451638699, -0.015649914741516113, 0.07994115352630615, -0.007920178584754467, -0.024376673623919487, 0.029664261266589165, -0.00887239258736372, 0.02034376934170723, -0.041404496878385544, -0.04017222300171852, 0.03976893052458763, 0.038715895265340805, 0.05283106490969658, -0.004509012680500746, 0.008222646079957485, -0.014910547994077206, 0.025004014372825623, 0.01362225878983736, -0.0018778216326609254, 0.035736024379730225, 0.0454598069190979, -0.014832130633294582, -0.018316112458705902, 0.00877717137336731, 0.1039593443274498, 0.07496723532676697, -0.012748463079333305, 0.011953083798289299, 0.012815677560865879, -0.00490950234234333, 0.04839486628770828, -0.02639312669634819, -0.061255354434251785, -0.008334672078490257, -0.03253210708498955, 0.026572367176413536, -0.01454086508601904, -0.03499665856361389, 0.0032655333634465933, 0.050008028745651245, 0.02339085191488266, -0.07595305889844894, 0.04118044674396515, -0.03275615721940994, -0.009931029751896858, 0.008239449933171272, -0.005752491764724255, -0.042255889624357224, -0.025407304987311363, 0.02292034775018692, -0.033181849867105484, -0.015918774530291557, 0.053413596004247665, -0.07442951202392578, 0.03282337263226509, -0.02820793353021145, 0.06882825493812561, 0.019626807421445847, -0.02775983326137066, 0.01649010367691517, -0.05108347162604332, 0.02332363836467266, -0.03300261124968529, 0.024824773892760277, 0.0389847531914711, 0.024869585409760475, -0.014249599538743496, 0.04339854419231415, -0.005660071037709713, -0.027020467445254326, 0.059552572667598724, 0.03533273562788963, 0.03475020453333855, 0.02095990628004074, -0.02213617041707039, 0.013241373933851719, 0.05283106490969658, -0.003248729510232806, 0.0034139666240662336, 0.008726759813725948, 0.06712547689676285, 0.050052840262651443, -0.0733092650771141, -0.0345933698117733, -0.04619917646050453, 0.034414127469062805, -0.003674425184726715, 0.011751438491046429, 0.006374231539666653, -0.02896970510482788, 0.03421248123049736, 0.0367666557431221, 0.01772237941622734, 0.062106747180223465, -0.07209938764572144, 0.013588651083409786, 0.03674425184726715, 0.02419743314385414, -0.06197231635451317, -0.04032905772328377, -0.046154364943504333, 0.03374197706580162, 0.05108347162604332, -0.011628211475908756, 0.013398208655416965, 0.0002557324187364429, 0.0018820225959643722, -0.04619917646050453, -0.015773141756653786, -0.05543004721403122, -0.01362225878983736, -0.001807805965654552, -0.02225939929485321, -0.0025583745446056128, -0.02892489545047283, -0.01495535857975483, 0.045751072466373444, -0.027535783126950264, -0.041718170046806335, -0.0237269289791584, 0.04380183666944504, 0.005136353429406881, 0.08047886937856674, 0.003321545897051692, 0.011527388356626034, -0.012871690094470978, 0.016322065144777298, -0.030201982706785202, -0.03582564368844032, -0.034414127469062805, -0.01231156475841999, 0.012860488146543503, -0.03078451380133629, -0.006110972259193659, 0.04380183666944504, 0.025810595601797104, -0.01059758011251688, 0.007332046516239643, -0.04722980782389641, 0.012210741639137268, -0.013308588415384293, 0.007931381464004517, -0.08258494734764099, 0.04151652380824089, 0.0049963220953941345, 0.008984417654573917, 0.05681915953755379, 0.0368114672601223, -0.03636336699128151, 0.035243112593889236, 0.06645332276821136, -0.0057748970575630665, -0.028476795181632042, -0.01103447750210762, 0.0034195678308606148, -0.09239835292100906, -0.08392924815416336, -0.036072101444005966, 0.03537754341959953, 0.026303507387638092, -0.012871690094470978, 0.007068787235766649, -0.032196030020713806, -0.011964286677539349, 0.02298756130039692, -0.049604739993810654, 0.009779796004295349, -0.023458067327737808, 0.03239767625927925, 0.00513915391638875, 0.03817817196249962, -0.024421483278274536, -0.06291332840919495, -0.026751607656478882, -0.032688941806554794, -0.04978397861123085, 0.008962012827396393, -0.013207766227424145, 0.0008814979228191078, 0.04259196296334267, -0.01468649785965681, -0.058656372129917145, 0.017733583226799965, -0.030112361535429955, -0.010149478912353516, 0.012804475612938404, -0.040396273136138916, 0.025877811014652252, 0.03150147572159767, -0.025698570534586906, -0.02249465137720108, 0.05968700349330902, 0.0019198311492800713, 0.0037556432653218508, 0.02062383107841015, -0.039119184017181396, 0.0910092368721962, 0.04241272434592247, -0.0008317867759615183, 0.026930848136544228, 0.02017573080956936, 0.013118145987391472, 0.03168071433901787, -0.03300261124968529, -0.00836267787963152, 0.0021634858567267656, 0.02507122978568077, -0.0032123213168233633, 0.011280933395028114, 0.03591526672244072, 0.02646034210920334, -0.008217045105993748, 0.021441614255309105, -0.04619917646050453, -0.03026919811964035, 0.050859421491622925, 0.024488698691129684, 0.03188236057758331, 0.010451947338879108, 0.03882791846990585, 0.08572164922952652, -0.047319427132606506, -0.08531835675239563, -0.013129347935318947, 0.013252575881779194, 0.030963752418756485, 0.012445994652807713, 0.01789041794836521, -0.015672318637371063, 0.035310328006744385, 0.06318219006061554, -0.03488463535904884, -0.029709070920944214, -0.040889181196689606, -0.014059157110750675, 0.045683857053518295, 0.03629615157842636, 0.026505151763558388, 0.002428145380690694, 0.013308588415384293, -0.032666534185409546, -0.013689474202692509, 0.026191482320427895, 0.012681247666478157, -0.03235286474227905, -0.037013113498687744, 0.010267105884850025, -0.016142824664711952, 0.04247993975877762, 0.0080938171595335, -0.008558722212910652, 0.01403675228357315, 0.01363346166908741, 0.03244248405098915, -0.04277120530605316, 0.02053421176970005, 0.026281101629137993, -0.03421248123049736, -0.06896268576383591, -0.045639049261808395, -0.04451879858970642, 0.0002937159442808479, 0.010323118418455124, -0.06811129301786423, 0.011006471700966358, 0.03410045802593231, 0.04624398425221443, 0.0453701876103878, 0.049559928476810455, 0.040082599967718124, -0.05816346034407616, 0.05852194130420685, -0.010457548312842846, -0.024421483278274536, 0.019761238247156143, 0.010670396499335766, 0.017475923523306847, -0.01007666252553463, -0.027580592781305313, 0.025676166638731956, -0.030829323455691338, 0.08612494170665741, 0.008883594535291195, -0.023547688499093056, -0.06811129301786423, -0.051934864372015, 0.04339854419231415, -0.009174860082566738, -0.02892489545047283, 0.013106943108141422, 0.02036617323756218, -0.03775247931480408, 0.014440042898058891, -0.019391555339097977, 0.044832468032836914, 0.026482747867703438, 0.007623312063515186, -0.0388503260910511, -0.10557250678539276, -0.031344637274742126, -0.019391555339097977, 0.08195760101079941, -0.047857146710157394, -0.005164359696209431, -0.01750953122973442, 0.01925712451338768, 0.005452824290841818, -0.02984350174665451, -0.017027823254466057, 0.07855203747749329, 0.010020649991929531, 0.01966041512787342, -0.040530700236558914, 0.029619451612234116, -0.030470842495560646, -0.04254715517163277, 0.002181689953431487, 0.050456129014492035, 0.02128477953374386, -0.06891787797212601, 0.07559457421302795, -0.0020458593498915434, -0.03230805695056915, 0.05059055984020233, -0.026079457253217697, 0.021777691319584846, -0.019806047901511192, 0.0033075427636504173, -0.024376673623919487, 0.008984417654573917, 0.04118044674396515, -0.03365235775709152, 0.03380919247865677, 0.033943623304367065, 0.0016173631884157658, 0.08124064654111862, -0.020646236836910248, -0.05274144560098648, 0.014328017830848694, 0.00551723875105381, -0.057312071323394775, -0.03589285910129547, 0.0118970712646842, -0.0056824758648872375, 0.02896970510482788, 0.03291299194097519, 0.06116573512554169, -0.044361963868141174, -0.03817817196249962, -0.000304918474284932, 0.07528090476989746, 0.007824957370758057, 0.022629082202911377, 0.050411321222782135, -0.0562814399600029, -0.05525080859661102, 0.004002098925411701, 0.009040430188179016, -0.030582867562770844, -0.0455046184360981, 0.046064745634794235, 0.01050235889852047, -0.01987326331436634, -0.010603181086480618, 0.08141988515853882, 0.07111357152462006, 0.004481006413698196, -0.025833001360297203, 0.01018308661878109, 0.051934864372015, -0.04281601309776306, -0.017543138936161995, 0.056953590363264084, 0.00013241723354440182, 0.01535864919424057, -0.04073234647512436, 0.03416767343878746, -0.012199539691209793, 0.019985288381576538, 0.016624532639980316, -0.03333868831396103, 0.03367476165294647, 0.0015669518616050482, 0.006312617566436529, 0.011208117008209229, 0.014339219778776169, -0.03553437814116478, 0.009852612391114235, -0.007841761223971844, -0.0071360026486217976, -0.08271937817335129, 0.01727427914738655, -0.006402237806469202, -0.017072634771466255, -0.0033607548102736473, -0.024981610476970673, 0.012199539691209793, 0.012076311744749546, 0.028006289154291153, -0.010020649991929531, -0.0018624182557687163, -0.03215121850371361, -0.026505151763558388, 0.0014248199295252562, 0.004144930746406317, -0.01930193416774273, 0.03808855265378952, 0.016243647783994675, -0.01642288826406002, 0.04059791564941406, 0.000751268700696528, -0.08428772538900375, 0.013375803828239441, -0.015369851142168045, -0.009466125629842281, 0.08079254627227783, 0.02209136076271534, 0.0003315244393888861, -0.03840222209692001, -0.0014633286045864224, -0.007354451343417168, -0.056460678577423096, -0.01560510415583849, 0.06322699785232544, -0.019862059503793716, 0.0040273042395710945, -0.0323304608464241, 0.0033495521638542414, -0.05677434802055359, 0.06990369409322739, -0.05762574076652527, 0.0029574641957879066, -0.009695777669548988, 0.003954487852752209, 0.0518900528550148, -0.009690175764262676, 0.06331662088632584, 0.004447398707270622, 0.03625134006142616, 0.009370904415845871, -0.017868012189865112, -0.02722211368381977, -0.017240671440958977, -0.040441080927848816, 0.006043757311999798, 0.0005398212233558297, -0.04664727672934532, 0.001155959558673203, 0.005158758256584406, 0.0008527914760634303, -0.0021956930868327618, 0.0692315474152565 ]
30,984
networkx.algorithms.similarity
optimize_edit_paths
GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, *, backend=None, **backend_kwargs)
[ 0.04682719334959984, -0.0429510660469532, 0.0001777549769030884, 0.019347023218870163, -0.051442693918943405, -0.05668554827570915, -0.01874207891523838, -0.007528199348598719, 0.018137134611606598, -0.06452742218971252, -0.04120344668626785, 0.008121941238641739, -0.008598054759204388, 0.05565490201115608, -0.01150514930486679, -0.005497714038938284, -0.0019814735278487206, -0.062421318143606186, 0.03224130719900131, 0.0031787597108632326, -0.027648208662867546, -0.08321348577737808, 0.03206206113100052, 0.03914215415716171, -0.043892089277505875, -0.0009676312911324203, 0.045930977910757065, 0.014518669806420803, 0.029104556888341904, -0.009174993261694908, 0.006772018503397703, -0.06784341484308243, -0.06260056048631668, 0.006150269880890846, -0.03165876492857933, 0.005629345308989286, 0.041808392852544785, 0.01991835981607437, 0.014888358302414417, -0.051129020750522614, -0.049022916704416275, -0.01480994001030922, -0.013790495693683624, -0.037865050137043, 0.04718567803502083, 0.03589337691664696, -0.04431779310107231, 0.006262296810746193, -0.015582924708724022, -0.01806991919875145, 0.01581818051636219, -0.1269935518503189, -0.04537084326148033, 0.038021888583898544, 0.009354235604405403, 0.0214531272649765, 0.009499870240688324, 0.04227890446782112, 0.053503986448049545, -0.08854596316814423, 0.02509399689733982, -0.03611743077635765, -0.017991499975323677, 0.03165876492857933, -0.05789543688297272, -0.004441861528903246, -0.03165876492857933, -0.04158433899283409, 0.022371746599674225, 0.033496007323265076, -0.05260777473449707, 0.011437933892011642, 0.051084209233522415, -0.07971825450658798, -0.000020086050426471047, 0.011247487738728523, 0.013375996612012386, -0.02298789471387863, -0.005503315478563309, -0.02504918724298477, 0.01040168572217226, -0.04093458503484726, 0.04709605500102043, -0.0721452459692955, 0.07380323857069016, 0.0023483613040298223, 0.030516093596816063, 0.018730876967310905, -0.04723048955202103, -0.0790909007191658, 0.00420660525560379, -0.030067985877394676, -0.01783466339111328, 0.015325263142585754, 0.03813391551375389, 0.009835951030254364, -0.024309810250997543, -0.054937928915023804, 0.015392478555440903, 0.0022181300446391106, 0.06475147604942322, 0.05668554827570915, -0.03195003420114517, 0.024354619905352592, 0.009236607700586319, -0.07729847729206085, -0.04153952747583389, 0.0551171712577343, 0.027334533631801605, -0.06134586036205292, -0.057581763714551926, 0.030157607048749924, 0.041427500545978546, -0.026281481608748436, -0.010334470309317112, 0.014910764060914516, -0.04261498525738716, 0.018753282725811005, -0.018809296190738678, 0.009544680826365948, 0.009987186640501022, -0.014036954380571842, -0.033518411219120026, 0.03242054954171181, 0.013857712037861347, -0.04897810518741608, 0.008502832613885403, 0.06954622268676758, 0.0240185409784317, -0.07528199255466461, 0.016770407557487488, -0.06748493015766144, 0.010026396252214909, 0.10136182606220245, -0.0012042878661304712, -0.012983903288841248, -0.03746175393462181, 0.009679113514721394, 0.018327580764889717, 0.02202446386218071, 0.03143471106886864, -0.03979191184043884, -0.007645827252417803, -0.005780581384897232, -0.018036311492323875, -0.05233890935778618, 0.01150514930486679, -0.019470253959298134, 0.0077578541822731495, 0.008049123920500278, -0.02152034267783165, 0.005144829396158457, 0.001971671124920249, -0.009583890438079834, 0.025295644998550415, -0.007276139222085476, -0.0001935962645802647, -0.010446496307849884, -0.003918136470019817, 0.015325263142585754, -0.004615502897650003, -0.04839556664228439, 0.002002478577196598, 0.011493947356939316, 0.05372804030776024, -0.018506823107600212, 0.04570692405104637, 0.007937096990644932, -0.0791357159614563, 0.005870203021913767, -0.03224130719900131, -0.046603139489889145, -0.07456502318382263, -0.014227400533854961, 0.01897733472287655, 0.01653515174984932, -0.009034959599375725, -0.02619186043739319, 0.007276139222085476, -0.01653515174984932, 0.02820834144949913, 0.01375688798725605, 0.04920215904712677, 0.050770532339811325, -0.00129110855050385, 0.05977748706936836, 0.030090391635894775, -0.027424154803156853, 0.022685421630740166, -0.022450165823101997, -0.02061292715370655, -0.06313829123973846, -0.012524593621492386, 0.05054648220539093, 0.03313751891255379, 0.02852201648056507, -0.005189640447497368, 0.039030127227306366, 0.004122585523873568, 0.0790460929274559, -0.030740147456526756, -0.012266932055354118, 0.0655132606625557, 0.007516996469348669, 0.03163636103272438, -0.002635429846122861, 0.0292837992310524, -0.018439607694745064, 0.011897243559360504, 0.0292613934725523, -0.04911253973841667, 0.028029099106788635, 0.027715424075722694, -0.001747617730870843, 0.026751993224024773, 0.038738857954740524, -0.03439221903681755, 0.03999355807900429, -0.0206577368080616, -0.03244295343756676, 0.013286375440657139, -0.01924620009958744, -0.01511241216212511, -0.011807622388005257, 0.041427500545978546, -0.05619262903928757, 0.009567086584866047, 0.028029099106788635, 0.0481267012655735, -0.04409373924136162, 0.007981907576322556, -0.0789564698934555, 0.04915734753012657, -0.016064640134572983, 0.040396854281425476, -0.028678854927420616, -0.02713288553059101, 0.025922995060682297, 0.03470589593052864, -0.0013226161245256662, -0.07272778451442719, -0.053548797965049744, -0.03739453852176666, 0.008217164315283298, -0.004385848063975573, -0.0008079931139945984, 0.0413602851331234, -0.008844513446092606, -0.011197076179087162, 0.00825637299567461, -0.017610609531402588, -0.03533324599266052, -0.009869558736681938, -0.007276139222085476, -0.040374450385570526, -0.003601660719141364, -0.041046611964702606, 0.042122066020965576, -0.012535796500742435, -0.005203643813729286, 0.01632230170071125, 0.008794101886451244, -0.04321993142366409, 0.021408315747976303, 0.023816892877221107, 0.02309992164373398, 0.028342774137854576, 0.013039916753768921, -0.06950140744447708, -0.027356937527656555, 0.03687921538949013, 0.0755956694483757, -0.032823845744132996, 0.06080813333392143, -0.017935486510396004, 0.01072656363248825, -0.002755858702585101, 0.018462011590600014, -0.011740406043827534, -0.04723048955202103, -0.030560903251171112, -0.007668232545256615, -0.04138268902897835, 0.014597089029848576, -0.036677565425634384, -0.015459694899618626, -0.029014933854341507, -0.02686402015388012, 0.01494437176734209, 0.001274304580874741, 0.04100180044770241, -0.018137134611606598, 0.04232371598482132, 0.03298068419098854, 0.08675353229045868, 0.03748415783047676, 0.019134173169732094, 0.002044488675892353, -0.03876126557588577, 0.06484109908342361, 0.03058330900967121, -0.0430854968726635, 0.02787226065993309, -0.058298733085393906, 0.015314060263335705, 0.01479873713105917, 0.014966776594519615, -0.013398402370512486, 0.049381401389837265, 0.05126345157623291, -0.03414576128125191, -0.028320368379354477, -0.04297346994280815, 0.03298068419098854, -0.02185642346739769, -0.0026970445178449154, -0.008189157582819462, -0.01567254588007927, 0.07994230836629868, -0.007875482551753521, -0.02439943142235279, 0.02959747426211834, -0.008911729790270329, 0.02034406177699566, -0.041405096650123596, -0.04019520804286003, 0.039747100323438644, 0.038694046437740326, 0.052831828594207764, -0.004469868261367083, 0.008284379728138447, -0.014899561181664467, 0.024981969967484474, 0.013633658178150654, -0.0018498421413823962, 0.03575894609093666, 0.04550527408719063, -0.014843547716736794, -0.018327580764889717, 0.008838912472128868, 0.10396084934473038, 0.07496831566095352, -0.012748646549880505, 0.011942054145038128, 0.012804660014808178, -0.004957184661179781, 0.04839556664228439, -0.026393508538603783, -0.06125624105334282, -0.008345995098352432, -0.032577384263277054, 0.02655034512281418, -0.014518669806420803, -0.03501956909894943, 0.0032739825546741486, 0.05000875145196915, 0.02336878515779972, -0.0759093388915062, 0.041158635169267654, -0.03275663033127785, -0.009936775080859661, 0.00826757587492466, -0.0057301693595945835, -0.04223409295082092, -0.02543007768690586, 0.022965488955378532, -0.033182330429553986, -0.01588539592921734, 0.05345917493104935, -0.07443059235811234, 0.03280143812298775, -0.02825315296649933, 0.0688292533159256, 0.01962709054350853, -0.027782639488577843, 0.01649034209549427, -0.051129020750522614, 0.023279163986444473, -0.03298068419098854, 0.02478032186627388, 0.03898531571030617, 0.024869943037629128, -0.014238603413105011, 0.04337676614522934, -0.005718966946005821, -0.027110479772090912, 0.05950862169265747, 0.03535564988851547, 0.03477311134338379, 0.02099381759762764, -0.022114085033535957, 0.01326396968215704, 0.052831828594207764, -0.0032207698095589876, 0.0033748066052794456, 0.008698878809809685, 0.06712644547224045, 0.050053562968969345, -0.07335513085126877, -0.034616272896528244, -0.04619984328746796, 0.0343698151409626, -0.0036884816363453865, 0.011774013750255108, 0.006407931447029114, -0.02892531268298626, 0.034212976694107056, 0.03669997304677963, 0.01771143265068531, 0.06219726428389549, -0.0721452459692955, 0.013555239886045456, 0.03681199625134468, 0.024264998733997345, -0.062062833458185196, -0.04035204276442528, -0.04611022025346756, 0.03372005745768547, 0.051084209233522415, -0.011617176234722137, 0.01342080719769001, 0.0002499597321730107, 0.0019100564531981945, -0.04615503177046776, -0.01569495163857937, -0.05547565966844559, -0.013555239886045456, -0.0018638455076143146, -0.02223731391131878, -0.002576615894213319, -0.02894771844148636, -0.014977979473769665, 0.04568452015519142, -0.02758099138736725, -0.04169636592268944, -0.02372727170586586, 0.043847277760505676, 0.005105620250105858, 0.08048003166913986, 0.0033327965065836906, 0.01152755506336689, -0.012905484065413475, 0.016311097890138626, -0.030202418565750122, -0.03584856912493706, -0.0344146266579628, -0.012278134934604168, 0.012838268652558327, -0.030784957110881805, -0.006127864588052034, 0.043847277760505676, 0.02583337388932705, -0.010631340555846691, 0.007332152221351862, -0.04718567803502083, 0.01224452629685402, -0.013297578319907188, 0.007881083525717258, -0.0825861394405365, 0.04151712357997894, 0.004993593320250511, 0.009018155746161938, 0.05681997910141945, 0.03676718845963478, -0.03643110767006874, 0.035288434475660324, 0.06649909168481827, -0.005802987143397331, -0.028409989550709724, -0.011079448275268078, 0.0034280193503946066, -0.09239968657493591, -0.08393046259880066, -0.0360502153635025, 0.03537805378437042, 0.026303887367248535, -0.012905484065413475, 0.007085693534463644, -0.032174088060855865, -0.011986864730715752, 0.022965488955378532, -0.04956064373254776, 0.00977993756532669, -0.023458406329154968, 0.03237573802471161, 0.005156032275408506, 0.03822353482246399, -0.02437702566385269, -0.06295904517173767, -0.026729587465524673, -0.03266700729727745, -0.049739886075258255, 0.009012553840875626, -0.013219159096479416, 0.0008409009897150099, 0.04257017374038696, -0.014675507321953773, -0.0585675984621048, 0.01773383840918541, -0.030112797394394875, -0.010183233767747879, 0.01273744460195303, -0.040374450385570526, 0.025900591164827347, 0.031501930207014084, -0.025676537305116653, -0.022607002407312393, 0.059687864035367966, 0.0019338622223585844, 0.003741694148629904, 0.02061292715370655, -0.039097342640161514, 0.09092093259096146, 0.04241333529353142, -0.0008275978034362197, 0.026908831670880318, 0.02017602138221264, 0.013140740804374218, 0.03170357644557953, -0.03307030349969864, -0.00836279895156622, 0.002262940863147378, 0.025026781484484673, -0.003203965723514557, 0.011292299255728722, 0.035938188433647156, 0.02646072395145893, -0.008245171047747135, 0.0214755330234766, -0.04619984328746796, -0.03024722822010517, 0.05081534385681152, 0.02448905259370804, 0.03190522640943527, 0.01042409148067236, 0.03885088488459587, 0.08572288602590561, -0.047275297343730927, -0.08527477830648422, -0.013174348510801792, 0.01327517256140709, 0.0309866052120924, 0.012490984983742237, 0.017823459580540657, -0.01567254588007927, 0.03537805378437042, 0.06313829123973846, -0.03486273065209389, -0.029754310846328735, -0.04086736589670181, -0.014036954380571842, 0.04568452015519142, 0.036341484636068344, 0.02655034512281418, 0.0024253795854747295, 0.013230361975729465, -0.03266700729727745, -0.013723280280828476, 0.02614704892039299, 0.012681431137025356, -0.03230852261185646, -0.036991242319345474, 0.010306463576853275, -0.016087044030427933, 0.042435742914676666, 0.008088333532214165, -0.008553244173526764, 0.014059360139071941, 0.013622456230223179, 0.03244295343756676, -0.042816631495952606, 0.020556913688778877, 0.026259075850248337, -0.03414576128125191, -0.0689636841416359, -0.04563970863819122, -0.044519439339637756, 0.00024768419098109007, 0.010345672257244587, -0.06811227649450302, 0.011006630957126617, 0.03407854586839676, 0.046244651079177856, 0.04532603174448013, 0.04956064373254776, 0.04001596197485924, -0.05816430225968361, 0.0584779754281044, -0.010435294359922409, -0.02448905259370804, 0.019716711714863777, 0.010670550167560577, 0.017464974895119667, -0.01008801069110632, -0.027603397145867348, 0.025676537305116653, -0.030896984040737152, 0.0861261859536171, 0.008928533643484116, -0.023548027500510216, -0.06815709173679352, -0.05198042467236519, 0.04339917376637459, -0.009163790382444859, -0.02894771844148636, 0.013084727339446545, 0.02034406177699566, -0.0378202386200428, 0.014440251514315605, -0.019403036683797836, 0.04478830471634865, 0.026438318192958832, 0.007606618106365204, -0.03885088488459587, -0.10557403415441513, -0.03136749565601349, -0.019447848200798035, 0.08195878565311432, -0.04781302809715271, -0.0051644342020154, -0.017532190307974815, 0.019279807806015015, 0.0054641058668494225, -0.029843932017683983, -0.017095286399126053, 0.07855317741632462, 0.010071206837892532, 0.019671902060508728, -0.04053128883242607, 0.02961988002061844, -0.030448878183960915, -0.042502958327531815, 0.002198525471612811, 0.05045685917139053, 0.02128508687019348, -0.0688740611076355, 0.0756404772400856, -0.0019744718447327614, -0.03230852261185646, 0.05059128999710083, -0.026035021990537643, 0.021778004243969917, -0.01981753669679165, 0.0033075904939323664, -0.02437702566385269, 0.00897334422916174, 0.041158635169267654, -0.03369765356183052, 0.03380968049168587, 0.033899303525686264, 0.0015501704765483737, 0.08124181628227234, -0.020624129101634026, -0.05274220556020737, 0.014361832290887833, 0.005469707306474447, -0.057312898337841034, -0.035938188433647156, 0.011953257024288177, -0.005671355407685041, 0.02892531268298626, 0.032913465052843094, 0.06121142953634262, -0.04440741240978241, -0.03820113092660904, -0.00037458952283486724, 0.07528199255466461, 0.0077466513030231, 0.022562192752957344, 0.050412047654390335, -0.056237440556287766, -0.055206794291734695, 0.003999355714768171, 0.009040560573339462, -0.030560903251171112, -0.04546046629548073, 0.04602059721946716, 0.010468902066349983, -0.019851144403219223, -0.010625739581882954, 0.08151067793369293, 0.07106978446245193, 0.004506276920437813, -0.02585577964782715, 0.010188834741711617, 0.05198042467236519, -0.042816631495952606, -0.017532190307974815, 0.056954413652420044, 0.00008266350778285414, 0.015392478555440903, -0.040755338966846466, 0.03412335366010666, -0.012188512831926346, 0.019974373281002045, 0.01663597673177719, -0.03338398039340973, 0.03369765356183052, 0.0016145858680829406, 0.00635191798210144, 0.011152265593409538, 0.014384238049387932, -0.03553489223122597, 0.009869558736681938, -0.007825070060789585, -0.0071585108526051044, -0.0827653780579567, 0.017274528741836548, -0.00636312086135149, -0.017095286399126053, -0.0033103912137448788, -0.024981969967484474, 0.012222121469676495, 0.012087688781321049, 0.027984287589788437, -0.009992788545787334, -0.0018218354089185596, -0.032129280269145966, -0.02646072395145893, 0.0014010348822921515, 0.004142189864069223, -0.019347023218870163, 0.03808910399675369, 0.016255084425210953, -0.0163671113550663, 0.04062090814113617, 0.00074077706085518, -0.08428894728422165, 0.013375996612012386, -0.015381275676190853, -0.009471863508224487, 0.08083852380514145, 0.022136490792036057, 0.0002984463353641331, -0.038380373269319534, -0.0014423447428271174, -0.007376963272690773, -0.05650630593299866, -0.01562773436307907, 0.06327272206544876, -0.019907157868146896, 0.0040777744725346565, -0.03230852261185646, 0.003383208531886339, -0.05668554827570915, 0.06994951516389847, -0.057626571506261826, 0.0029659089632332325, -0.009679113514721394, 0.003962947055697441, 0.05189080163836479, -0.009679113514721394, 0.06336234509944916, 0.004483871627599001, 0.036296673119068146, 0.009343032725155354, -0.017845865339040756, -0.02720010094344616, -0.017218515276908875, -0.040464069694280624, 0.006094256415963173, 0.00055733323097229, -0.04669275879859924, 0.0011895842617377639, 0.0051756370812654495, 0.0008857116918079555, -0.002156515372917056, 0.06927735358476639 ]
30,985
networkx.algorithms.similarity
optimize_graph_edit_distance
Returns consecutive approximations of GED (graph edit distance) between graphs G1 and G2. Graph edit distance is a graph similarity measure analogous to Levenshtein distance for strings. It is defined as minimum cost of edit path (sequence of node and edge edit operations) transforming graph G1 to graph isomorphic to G2. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. Returns ------- Generator of consecutive approximations of graph edit distance. Examples -------- >>> G1 = nx.cycle_graph(6) >>> G2 = nx.wheel_graph(7) >>> for v in nx.optimize_graph_edit_distance(G1, G2): ... minv = v >>> minv 7.0 See Also -------- graph_edit_distance, optimize_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, *, backend=None, **backend_kwargs)
[ 0.04687132686376572, -0.04295044392347336, 0.0001346052304143086, 0.01932433992624283, -0.05139714106917381, -0.05668472871184349, -0.018730606883764267, -0.007539293263107538, 0.01814807578921318, -0.06452649086713791, -0.04118044674396515, 0.0081162229180336, -0.008625936694443226, 0.055654097348451614, -0.011516186408698559, -0.005438821390271187, -0.0019884465727955103, -0.06242041662335396, 0.032263245433568954, 0.0031170998699963093, -0.02773742936551571, -0.08330190926790237, 0.03208400309085846, 0.039141587913036346, -0.043891455978155136, -0.0009872217196971178, 0.04597512260079384, 0.014518460258841515, 0.029104135930538177, -0.009152455255389214, 0.00681112939491868, -0.06788724660873413, -0.06264446675777435, 0.006144579965621233, -0.03165831044316292, 0.005606858991086483, 0.041785381734371185, 0.019884465262293816, 0.014888143166899681, -0.05112828314304352, -0.04897739738225937, -0.014809725806117058, -0.013812702149152756, -0.037886906415224075, 0.04722980782389641, 0.03591526672244072, -0.044317152351140976, 0.006239801179617643, -0.01554909162223339, -0.018058454617857933, 0.015795547515153885, -0.12699171900749207, -0.045414999127388, 0.03804374486207962, 0.00941571407020092, 0.021486425772309303, 0.00953334104269743, 0.042255889624357224, 0.053503215312957764, -0.08863430470228195, 0.02511603944003582, -0.036139316856861115, -0.017991241067647934, 0.03170311823487282, -0.05784979090094566, -0.004481006413698196, -0.03163590282201767, -0.04158373922109604, 0.02234901860356331, 0.03345071151852608, -0.052651822566986084, 0.011471375823020935, 0.05108347162604332, -0.07971709966659546, -0.000028487647796282545, 0.011269730515778065, 0.013387005776166916, -0.02296515740454197, -0.005497634410858154, -0.025026420131325722, 0.010468751192092896, -0.040911588817834854, 0.04709537699818611, -0.07214420288801193, 0.0738021731376648, 0.002358129480853677, 0.030515652149915695, 0.018741808831691742, -0.04718499630689621, -0.07908976078033447, 0.00427656015381217, -0.030045146122574806, -0.017823202535510063, 0.015302636660635471, 0.03808855265378952, 0.009807802736759186, -0.024376673623919487, -0.05498194694519043, 0.015392256900668144, 0.0021648861002177, 0.064750537276268, 0.05663992092013359, -0.03201679140329361, 0.024354269728064537, 0.009191663935780525, -0.07729735970497131, -0.04153892770409584, 0.05507156625390053, 0.027378948405385017, -0.06134497746825218, -0.05753612145781517, 0.030157173052430153, 0.04144930839538574, -0.026281101629137993, -0.010334320366382599, 0.014921750873327255, -0.04259196296334267, 0.018719403073191643, -0.018820226192474365, 0.009583752602338791, 0.00993663165718317, -0.014059157110750675, -0.033540330827236176, 0.03244248405098915, 0.013902322389185429, -0.04897739738225937, 0.008502709679305553, 0.0695004090666771, 0.023973383009433746, -0.07528090476989746, 0.016792571172118187, -0.06748395413160324, 0.009998245164752007, 0.10136035829782486, -0.0012336770305410028, -0.012994918040931225, -0.037483617663383484, 0.00963976513594389, 0.0183609239757061, 0.021990537643432617, 0.031411852687597275, -0.03976893052458763, -0.007679324597120285, -0.005741289351135492, -0.01800244301557541, -0.05233815312385559, 0.011538591235876083, -0.019481174647808075, 0.007768944837152958, 0.008037804625928402, -0.02147522196173668, 0.005144755356013775, 0.0020010494627058506, -0.00961735937744379, 0.025295279920101166, -0.007276033982634544, -0.0002170487423427403, -0.010401535779237747, -0.0039068772457540035, 0.015291433781385422, -0.0045846295543015, -0.04843967780470848, 0.0020430588629096746, 0.011516186408698559, 0.05372726544737816, -0.018484150990843773, 0.045706264674663544, 0.007987393997609615, -0.07917938381433487, 0.005870118271559477, -0.032196030020713806, -0.046557653695344925, -0.07460875064134598, -0.014238397590816021, 0.018965858966112137, 0.01651250757277012, -0.009046031162142754, -0.026124266907572746, 0.007281634956598282, -0.016523711383342743, 0.02820793353021145, 0.013734283857047558, 0.049201447516679764, 0.05076980218291283, -0.0013113945024088025, 0.05977662280201912, 0.030112361535429955, -0.027423758059740067, 0.02272990345954895, -0.02244984172284603, -0.020679844543337822, -0.06309256702661514, -0.012502007186412811, 0.05054575204849243, 0.03320425748825073, 0.02854401059448719, -0.005220372229814529, 0.03900716081261635, 0.004102921579033136, 0.07904495298862457, -0.03073970228433609, -0.012277957051992416, 0.06551231443881989, 0.007466476876288652, 0.03156868740916252, -0.002639592858031392, 0.029283376410603523, -0.018472949042916298, 0.011986691504716873, 0.029283376410603523, -0.049111828207969666, 0.028051098808646202, 0.02775983326137066, -0.0017251874087378383, 0.026774011552333832, 0.038715895265340805, -0.034369319677352905, 0.040015384554862976, -0.020668640732765198, -0.03244248405098915, 0.013274980708956718, -0.019245922565460205, -0.015168205834925175, -0.011807451955974102, 0.041337281465530396, -0.0561918169260025, 0.009527739137411118, 0.028028694912791252, 0.04812600836157799, -0.04418272152543068, 0.008037804625928402, -0.07891052216291428, 0.049201447516679764, -0.016053205356001854, 0.040441080927848816, -0.02863362990319729, -0.02719970792531967, 0.025855405256152153, 0.0346829891204834, -0.0012735859490931034, -0.07272673398256302, -0.053548023104667664, -0.037438806146383286, 0.00825625378638506, -0.0043213702738285065, -0.000798879424110055, 0.041292473673820496, -0.008805177174508572, -0.011129699647426605, 0.008250652812421322, -0.01757674664258957, -0.03533273562788963, -0.009908624924719334, -0.007259230129420757, -0.040396273136138916, -0.0035932068713009357, -0.0410684235394001, 0.04214386269450188, -0.012502007186412811, -0.005186764523386955, 0.016366874799132347, 0.008833183906972408, -0.0432417094707489, 0.02140800654888153, 0.0238389540463686, 0.023144397884607315, 0.028387174010276794, 0.013028525747358799, -0.0694107860326767, -0.027401354163885117, 0.0367218479514122, 0.07554976642131805, -0.03286818042397499, 0.060807254165410995, -0.017924025654792786, 0.010715206153690815, -0.002722211414948106, 0.018495352938771248, -0.01169542595744133, -0.04722980782389641, -0.030538057908415794, -0.007651318330317736, -0.041382092982530594, 0.014596877619624138, -0.03669944033026695, -0.015392256900668144, -0.02903692051768303, -0.026930848136544228, 0.014932953752577305, 0.0012602830538526177, 0.0410684235394001, -0.01817047968506813, 0.04227829352021217, 0.03298020735383034, 0.0867970883846283, 0.03752842918038368, 0.01911149173974991, 0.00210327235981822, -0.0388055145740509, 0.0648849681019783, 0.030605273321270943, -0.04312968626618385, 0.027849454432725906, -0.05829789116978645, 0.015313838608562946, 0.014787320978939533, 0.01494415570050478, -0.01343181636184454, 0.04938068985939026, 0.051262710243463516, -0.03416767343878746, -0.028319960460066795, -0.04295044392347336, 0.03300261124968529, -0.02183370292186737, -0.002758619375526905, -0.008172235451638699, -0.015649914741516113, 0.07994115352630615, -0.007920178584754467, -0.024376673623919487, 0.029664261266589165, -0.00887239258736372, 0.02034376934170723, -0.041404496878385544, -0.04017222300171852, 0.03976893052458763, 0.038715895265340805, 0.05283106490969658, -0.004509012680500746, 0.008222646079957485, -0.014910547994077206, 0.025004014372825623, 0.01362225878983736, -0.0018778216326609254, 0.035736024379730225, 0.0454598069190979, -0.014832130633294582, -0.018316112458705902, 0.00877717137336731, 0.1039593443274498, 0.07496723532676697, -0.012748463079333305, 0.011953083798289299, 0.012815677560865879, -0.00490950234234333, 0.04839486628770828, -0.02639312669634819, -0.061255354434251785, -0.008334672078490257, -0.03253210708498955, 0.026572367176413536, -0.01454086508601904, -0.03499665856361389, 0.0032655333634465933, 0.050008028745651245, 0.02339085191488266, -0.07595305889844894, 0.04118044674396515, -0.03275615721940994, -0.009931029751896858, 0.008239449933171272, -0.005752491764724255, -0.042255889624357224, -0.025407304987311363, 0.02292034775018692, -0.033181849867105484, -0.015918774530291557, 0.053413596004247665, -0.07442951202392578, 0.03282337263226509, -0.02820793353021145, 0.06882825493812561, 0.019626807421445847, -0.02775983326137066, 0.01649010367691517, -0.05108347162604332, 0.02332363836467266, -0.03300261124968529, 0.024824773892760277, 0.0389847531914711, 0.024869585409760475, -0.014249599538743496, 0.04339854419231415, -0.005660071037709713, -0.027020467445254326, 0.059552572667598724, 0.03533273562788963, 0.03475020453333855, 0.02095990628004074, -0.02213617041707039, 0.013241373933851719, 0.05283106490969658, -0.003248729510232806, 0.0034139666240662336, 0.008726759813725948, 0.06712547689676285, 0.050052840262651443, -0.0733092650771141, -0.0345933698117733, -0.04619917646050453, 0.034414127469062805, -0.003674425184726715, 0.011751438491046429, 0.006374231539666653, -0.02896970510482788, 0.03421248123049736, 0.0367666557431221, 0.01772237941622734, 0.062106747180223465, -0.07209938764572144, 0.013588651083409786, 0.03674425184726715, 0.02419743314385414, -0.06197231635451317, -0.04032905772328377, -0.046154364943504333, 0.03374197706580162, 0.05108347162604332, -0.011628211475908756, 0.013398208655416965, 0.0002557324187364429, 0.0018820225959643722, -0.04619917646050453, -0.015773141756653786, -0.05543004721403122, -0.01362225878983736, -0.001807805965654552, -0.02225939929485321, -0.0025583745446056128, -0.02892489545047283, -0.01495535857975483, 0.045751072466373444, -0.027535783126950264, -0.041718170046806335, -0.0237269289791584, 0.04380183666944504, 0.005136353429406881, 0.08047886937856674, 0.003321545897051692, 0.011527388356626034, -0.012871690094470978, 0.016322065144777298, -0.030201982706785202, -0.03582564368844032, -0.034414127469062805, -0.01231156475841999, 0.012860488146543503, -0.03078451380133629, -0.006110972259193659, 0.04380183666944504, 0.025810595601797104, -0.01059758011251688, 0.007332046516239643, -0.04722980782389641, 0.012210741639137268, -0.013308588415384293, 0.007931381464004517, -0.08258494734764099, 0.04151652380824089, 0.0049963220953941345, 0.008984417654573917, 0.05681915953755379, 0.0368114672601223, -0.03636336699128151, 0.035243112593889236, 0.06645332276821136, -0.0057748970575630665, -0.028476795181632042, -0.01103447750210762, 0.0034195678308606148, -0.09239835292100906, -0.08392924815416336, -0.036072101444005966, 0.03537754341959953, 0.026303507387638092, -0.012871690094470978, 0.007068787235766649, -0.032196030020713806, -0.011964286677539349, 0.02298756130039692, -0.049604739993810654, 0.009779796004295349, -0.023458067327737808, 0.03239767625927925, 0.00513915391638875, 0.03817817196249962, -0.024421483278274536, -0.06291332840919495, -0.026751607656478882, -0.032688941806554794, -0.04978397861123085, 0.008962012827396393, -0.013207766227424145, 0.0008814979228191078, 0.04259196296334267, -0.01468649785965681, -0.058656372129917145, 0.017733583226799965, -0.030112361535429955, -0.010149478912353516, 0.012804475612938404, -0.040396273136138916, 0.025877811014652252, 0.03150147572159767, -0.025698570534586906, -0.02249465137720108, 0.05968700349330902, 0.0019198311492800713, 0.0037556432653218508, 0.02062383107841015, -0.039119184017181396, 0.0910092368721962, 0.04241272434592247, -0.0008317867759615183, 0.026930848136544228, 0.02017573080956936, 0.013118145987391472, 0.03168071433901787, -0.03300261124968529, -0.00836267787963152, 0.0021634858567267656, 0.02507122978568077, -0.0032123213168233633, 0.011280933395028114, 0.03591526672244072, 0.02646034210920334, -0.008217045105993748, 0.021441614255309105, -0.04619917646050453, -0.03026919811964035, 0.050859421491622925, 0.024488698691129684, 0.03188236057758331, 0.010451947338879108, 0.03882791846990585, 0.08572164922952652, -0.047319427132606506, -0.08531835675239563, -0.013129347935318947, 0.013252575881779194, 0.030963752418756485, 0.012445994652807713, 0.01789041794836521, -0.015672318637371063, 0.035310328006744385, 0.06318219006061554, -0.03488463535904884, -0.029709070920944214, -0.040889181196689606, -0.014059157110750675, 0.045683857053518295, 0.03629615157842636, 0.026505151763558388, 0.002428145380690694, 0.013308588415384293, -0.032666534185409546, -0.013689474202692509, 0.026191482320427895, 0.012681247666478157, -0.03235286474227905, -0.037013113498687744, 0.010267105884850025, -0.016142824664711952, 0.04247993975877762, 0.0080938171595335, -0.008558722212910652, 0.01403675228357315, 0.01363346166908741, 0.03244248405098915, -0.04277120530605316, 0.02053421176970005, 0.026281101629137993, -0.03421248123049736, -0.06896268576383591, -0.045639049261808395, -0.04451879858970642, 0.0002937159442808479, 0.010323118418455124, -0.06811129301786423, 0.011006471700966358, 0.03410045802593231, 0.04624398425221443, 0.0453701876103878, 0.049559928476810455, 0.040082599967718124, -0.05816346034407616, 0.05852194130420685, -0.010457548312842846, -0.024421483278274536, 0.019761238247156143, 0.010670396499335766, 0.017475923523306847, -0.01007666252553463, -0.027580592781305313, 0.025676166638731956, -0.030829323455691338, 0.08612494170665741, 0.008883594535291195, -0.023547688499093056, -0.06811129301786423, -0.051934864372015, 0.04339854419231415, -0.009174860082566738, -0.02892489545047283, 0.013106943108141422, 0.02036617323756218, -0.03775247931480408, 0.014440042898058891, -0.019391555339097977, 0.044832468032836914, 0.026482747867703438, 0.007623312063515186, -0.0388503260910511, -0.10557250678539276, -0.031344637274742126, -0.019391555339097977, 0.08195760101079941, -0.047857146710157394, -0.005164359696209431, -0.01750953122973442, 0.01925712451338768, 0.005452824290841818, -0.02984350174665451, -0.017027823254466057, 0.07855203747749329, 0.010020649991929531, 0.01966041512787342, -0.040530700236558914, 0.029619451612234116, -0.030470842495560646, -0.04254715517163277, 0.002181689953431487, 0.050456129014492035, 0.02128477953374386, -0.06891787797212601, 0.07559457421302795, -0.0020458593498915434, -0.03230805695056915, 0.05059055984020233, -0.026079457253217697, 0.021777691319584846, -0.019806047901511192, 0.0033075427636504173, -0.024376673623919487, 0.008984417654573917, 0.04118044674396515, -0.03365235775709152, 0.03380919247865677, 0.033943623304367065, 0.0016173631884157658, 0.08124064654111862, -0.020646236836910248, -0.05274144560098648, 0.014328017830848694, 0.00551723875105381, -0.057312071323394775, -0.03589285910129547, 0.0118970712646842, -0.0056824758648872375, 0.02896970510482788, 0.03291299194097519, 0.06116573512554169, -0.044361963868141174, -0.03817817196249962, -0.000304918474284932, 0.07528090476989746, 0.007824957370758057, 0.022629082202911377, 0.050411321222782135, -0.0562814399600029, -0.05525080859661102, 0.004002098925411701, 0.009040430188179016, -0.030582867562770844, -0.0455046184360981, 0.046064745634794235, 0.01050235889852047, -0.01987326331436634, -0.010603181086480618, 0.08141988515853882, 0.07111357152462006, 0.004481006413698196, -0.025833001360297203, 0.01018308661878109, 0.051934864372015, -0.04281601309776306, -0.017543138936161995, 0.056953590363264084, 0.00013241723354440182, 0.01535864919424057, -0.04073234647512436, 0.03416767343878746, -0.012199539691209793, 0.019985288381576538, 0.016624532639980316, -0.03333868831396103, 0.03367476165294647, 0.0015669518616050482, 0.006312617566436529, 0.011208117008209229, 0.014339219778776169, -0.03553437814116478, 0.009852612391114235, -0.007841761223971844, -0.0071360026486217976, -0.08271937817335129, 0.01727427914738655, -0.006402237806469202, -0.017072634771466255, -0.0033607548102736473, -0.024981610476970673, 0.012199539691209793, 0.012076311744749546, 0.028006289154291153, -0.010020649991929531, -0.0018624182557687163, -0.03215121850371361, -0.026505151763558388, 0.0014248199295252562, 0.004144930746406317, -0.01930193416774273, 0.03808855265378952, 0.016243647783994675, -0.01642288826406002, 0.04059791564941406, 0.000751268700696528, -0.08428772538900375, 0.013375803828239441, -0.015369851142168045, -0.009466125629842281, 0.08079254627227783, 0.02209136076271534, 0.0003315244393888861, -0.03840222209692001, -0.0014633286045864224, -0.007354451343417168, -0.056460678577423096, -0.01560510415583849, 0.06322699785232544, -0.019862059503793716, 0.0040273042395710945, -0.0323304608464241, 0.0033495521638542414, -0.05677434802055359, 0.06990369409322739, -0.05762574076652527, 0.0029574641957879066, -0.009695777669548988, 0.003954487852752209, 0.0518900528550148, -0.009690175764262676, 0.06331662088632584, 0.004447398707270622, 0.03625134006142616, 0.009370904415845871, -0.017868012189865112, -0.02722211368381977, -0.017240671440958977, -0.040441080927848816, 0.006043757311999798, 0.0005398212233558297, -0.04664727672934532, 0.001155959558673203, 0.005158758256584406, 0.0008527914760634303, -0.0021956930868327618, 0.0692315474152565 ]
30,993
networkx.algorithms.similarity
panther_similarity
Returns the Panther similarity of nodes in the graph `G` to node ``v``. Panther is a similarity metric that says "two objects are considered to be similar if they frequently appear on the same paths." [1]_. Parameters ---------- G : NetworkX graph A NetworkX graph source : node Source node for which to find the top `k` similar other nodes k : int (default = 5) The number of most similar nodes to return. path_length : int (default = 5) How long the randomly generated paths should be (``T`` in [1]_) c : float (default = 0.5) A universal positive constant used to scale the number of sample random paths to generate. delta : float (default = 0.1) The probability that the similarity $S$ is not an epsilon-approximation to (R, phi), where $R$ is the number of random paths and $\phi$ is the probability that an element sampled from a set $A \subseteq D$, where $D$ is the domain. eps : float or None (default = None) The error bound. Per [1]_, a good value is ``sqrt(1/|E|)``. Therefore, if no value is provided, the recommended computed value will be used. weight : string or None, optional (default="weight") The name of an edge attribute that holds the numerical value used as a weight. If None then each edge has weight 1. Returns ------- similarity : dictionary Dictionary of nodes to similarity scores (as floats). Note: the self-similarity (i.e., ``v``) will not be included in the returned dictionary. So, for ``k = 5``, a dictionary of top 4 nodes and their similarity scores will be returned. Raises ------ NetworkXUnfeasible If `source` is an isolated node. NodeNotFound If `source` is not in `G`. Notes ----- The isolated nodes in `G` are ignored. Examples -------- >>> G = nx.star_graph(10) >>> sim = nx.panther_similarity(G, 0) References ---------- .. [1] Zhang, J., Tang, J., Ma, C., Tong, H., Jing, Y., & Li, J. Panther: Fast top-k similarity search on large networks. In Proceedings of the ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (Vol. 2015-August, pp. 1445–1454). Association for Computing Machinery. https://doi.org/10.1145/2783258.2783267.
def optimize_edit_paths( G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, upper_bound=None, strictly_decreasing=True, roots=None, timeout=None, ): """GED (graph edit distance) calculation: advanced interface. Graph edit path is a sequence of node and edge edit operations transforming graph G1 to graph isomorphic to G2. Edit operations include substitutions, deletions, and insertions. Graph edit distance is defined as minimum cost of edit path. Parameters ---------- G1, G2: graphs The two graphs G1 and G2 must be of the same type. node_match : callable A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching. The function will be called like node_match(G1.nodes[n1], G2.nodes[n2]). That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs. Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered. edge_match : callable A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching. The function will be called like edge_match(G1[u1][v1], G2[u2][v2]). That is, the function will receive the edge attribute dictionaries of the edges under consideration. Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered. node_subst_cost, node_del_cost, node_ins_cost : callable Functions that return the costs of node substitution, node deletion, and node insertion, respectively. The functions will be called like node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]). That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching). If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used. edge_subst_cost, edge_del_cost, edge_ins_cost : callable Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively. The functions will be called like edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]). That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values. Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching). If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used. upper_bound : numeric Maximum edit distance to consider. strictly_decreasing : bool If True, return consecutive approximations of strictly decreasing cost. Otherwise, return all edit paths of cost less than or equal to the previous minimum cost. roots : 2-tuple Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs. timeout : numeric Maximum number of seconds to execute. After timeout is met, the current best GED is returned. Returns ------- Generator of tuples (node_edit_path, edge_edit_path, cost) node_edit_path : list of tuples (u, v) edge_edit_path : list of tuples ((u1, v1), (u2, v2)) cost : numeric See Also -------- graph_edit_distance, optimize_graph_edit_distance, optimal_edit_paths References ---------- .. [1] Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816 """ # TODO: support DiGraph import numpy as np import scipy as sp @dataclass class CostMatrix: C: ... lsa_row_ind: ... lsa_col_ind: ... ls: ... def make_CostMatrix(C, m, n): # assert(C.shape == (m + n, m + n)) lsa_row_ind, lsa_col_ind = sp.optimize.linear_sum_assignment(C) # Fixup dummy assignments: # each substitution i<->j should have dummy assignment m+j<->n+i # NOTE: fast reduce of Cv relies on it # assert len(lsa_row_ind) == len(lsa_col_ind) indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) subst_ind = [k for k, i, j in indexes if i < m and j < n] indexes = zip(range(len(lsa_row_ind)), lsa_row_ind, lsa_col_ind) dummy_ind = [k for k, i, j in indexes if i >= m and j >= n] # assert len(subst_ind) == len(dummy_ind) lsa_row_ind[dummy_ind] = lsa_col_ind[subst_ind] + m lsa_col_ind[dummy_ind] = lsa_row_ind[subst_ind] + n return CostMatrix( C, lsa_row_ind, lsa_col_ind, C[lsa_row_ind, lsa_col_ind].sum() ) def extract_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k in i or k - m in j for k in range(m + n)] col_ind = [k in j or k - n in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_C(C, i, j, m, n): # assert(C.shape == (m + n, m + n)) row_ind = [k not in i and k - m not in j for k in range(m + n)] col_ind = [k not in j and k - n not in i for k in range(m + n)] return C[row_ind, :][:, col_ind] def reduce_ind(ind, i): # assert set(ind) == set(range(len(ind))) rind = ind[[k not in i for k in ind]] for k in set(i): rind[rind >= k] -= 1 return rind def match_edges(u, v, pending_g, pending_h, Ce, matched_uv=None): """ Parameters: u, v: matched vertices, u=None or v=None for deletion/insertion pending_g, pending_h: lists of edges not yet mapped Ce: CostMatrix of pending edge mappings matched_uv: partial vertex edit path list of tuples (u, v) of previously matched vertex mappings u<->v, u=None or v=None for deletion/insertion Returns: list of (i, j): indices of edge mappings g<->h localCe: local CostMatrix of edge mappings (basically submatrix of Ce at cross of rows i, cols j) """ M = len(pending_g) N = len(pending_h) # assert Ce.C.shape == (M + N, M + N) # only attempt to match edges after one node match has been made # this will stop self-edges on the first node being automatically deleted # even when a substitution is the better option if matched_uv is None or len(matched_uv) == 0: g_ind = [] h_ind = [] else:
(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None, weight='weight', *, backend=None, **backend_kwargs)
[ 0.04682719334959984, -0.0429510660469532, 0.0001777549769030884, 0.019347023218870163, -0.051442693918943405, -0.05668554827570915, -0.01874207891523838, -0.007528199348598719, 0.018137134611606598, -0.06452742218971252, -0.04120344668626785, 0.008121941238641739, -0.008598054759204388, 0.05565490201115608, -0.01150514930486679, -0.005497714038938284, -0.0019814735278487206, -0.062421318143606186, 0.03224130719900131, 0.0031787597108632326, -0.027648208662867546, -0.08321348577737808, 0.03206206113100052, 0.03914215415716171, -0.043892089277505875, -0.0009676312911324203, 0.045930977910757065, 0.014518669806420803, 0.029104556888341904, -0.009174993261694908, 0.006772018503397703, -0.06784341484308243, -0.06260056048631668, 0.006150269880890846, -0.03165876492857933, 0.005629345308989286, 0.041808392852544785, 0.01991835981607437, 0.014888358302414417, -0.051129020750522614, -0.049022916704416275, -0.01480994001030922, -0.013790495693683624, -0.037865050137043, 0.04718567803502083, 0.03589337691664696, -0.04431779310107231, 0.006262296810746193, -0.015582924708724022, -0.01806991919875145, 0.01581818051636219, -0.1269935518503189, -0.04537084326148033, 0.038021888583898544, 0.009354235604405403, 0.0214531272649765, 0.009499870240688324, 0.04227890446782112, 0.053503986448049545, -0.08854596316814423, 0.02509399689733982, -0.03611743077635765, -0.017991499975323677, 0.03165876492857933, -0.05789543688297272, -0.004441861528903246, -0.03165876492857933, -0.04158433899283409, 0.022371746599674225, 0.033496007323265076, -0.05260777473449707, 0.011437933892011642, 0.051084209233522415, -0.07971825450658798, -0.000020086050426471047, 0.011247487738728523, 0.013375996612012386, -0.02298789471387863, -0.005503315478563309, -0.02504918724298477, 0.01040168572217226, -0.04093458503484726, 0.04709605500102043, -0.0721452459692955, 0.07380323857069016, 0.0023483613040298223, 0.030516093596816063, 0.018730876967310905, -0.04723048955202103, -0.0790909007191658, 0.00420660525560379, -0.030067985877394676, -0.01783466339111328, 0.015325263142585754, 0.03813391551375389, 0.009835951030254364, -0.024309810250997543, -0.054937928915023804, 0.015392478555440903, 0.0022181300446391106, 0.06475147604942322, 0.05668554827570915, -0.03195003420114517, 0.024354619905352592, 0.009236607700586319, -0.07729847729206085, -0.04153952747583389, 0.0551171712577343, 0.027334533631801605, -0.06134586036205292, -0.057581763714551926, 0.030157607048749924, 0.041427500545978546, -0.026281481608748436, -0.010334470309317112, 0.014910764060914516, -0.04261498525738716, 0.018753282725811005, -0.018809296190738678, 0.009544680826365948, 0.009987186640501022, -0.014036954380571842, -0.033518411219120026, 0.03242054954171181, 0.013857712037861347, -0.04897810518741608, 0.008502832613885403, 0.06954622268676758, 0.0240185409784317, -0.07528199255466461, 0.016770407557487488, -0.06748493015766144, 0.010026396252214909, 0.10136182606220245, -0.0012042878661304712, -0.012983903288841248, -0.03746175393462181, 0.009679113514721394, 0.018327580764889717, 0.02202446386218071, 0.03143471106886864, -0.03979191184043884, -0.007645827252417803, -0.005780581384897232, -0.018036311492323875, -0.05233890935778618, 0.01150514930486679, -0.019470253959298134, 0.0077578541822731495, 0.008049123920500278, -0.02152034267783165, 0.005144829396158457, 0.001971671124920249, -0.009583890438079834, 0.025295644998550415, -0.007276139222085476, -0.0001935962645802647, -0.010446496307849884, -0.003918136470019817, 0.015325263142585754, -0.004615502897650003, -0.04839556664228439, 0.002002478577196598, 0.011493947356939316, 0.05372804030776024, -0.018506823107600212, 0.04570692405104637, 0.007937096990644932, -0.0791357159614563, 0.005870203021913767, -0.03224130719900131, -0.046603139489889145, -0.07456502318382263, -0.014227400533854961, 0.01897733472287655, 0.01653515174984932, -0.009034959599375725, -0.02619186043739319, 0.007276139222085476, -0.01653515174984932, 0.02820834144949913, 0.01375688798725605, 0.04920215904712677, 0.050770532339811325, -0.00129110855050385, 0.05977748706936836, 0.030090391635894775, -0.027424154803156853, 0.022685421630740166, -0.022450165823101997, -0.02061292715370655, -0.06313829123973846, -0.012524593621492386, 0.05054648220539093, 0.03313751891255379, 0.02852201648056507, -0.005189640447497368, 0.039030127227306366, 0.004122585523873568, 0.0790460929274559, -0.030740147456526756, -0.012266932055354118, 0.0655132606625557, 0.007516996469348669, 0.03163636103272438, -0.002635429846122861, 0.0292837992310524, -0.018439607694745064, 0.011897243559360504, 0.0292613934725523, -0.04911253973841667, 0.028029099106788635, 0.027715424075722694, -0.001747617730870843, 0.026751993224024773, 0.038738857954740524, -0.03439221903681755, 0.03999355807900429, -0.0206577368080616, -0.03244295343756676, 0.013286375440657139, -0.01924620009958744, -0.01511241216212511, -0.011807622388005257, 0.041427500545978546, -0.05619262903928757, 0.009567086584866047, 0.028029099106788635, 0.0481267012655735, -0.04409373924136162, 0.007981907576322556, -0.0789564698934555, 0.04915734753012657, -0.016064640134572983, 0.040396854281425476, -0.028678854927420616, -0.02713288553059101, 0.025922995060682297, 0.03470589593052864, -0.0013226161245256662, -0.07272778451442719, -0.053548797965049744, -0.03739453852176666, 0.008217164315283298, -0.004385848063975573, -0.0008079931139945984, 0.0413602851331234, -0.008844513446092606, -0.011197076179087162, 0.00825637299567461, -0.017610609531402588, -0.03533324599266052, -0.009869558736681938, -0.007276139222085476, -0.040374450385570526, -0.003601660719141364, -0.041046611964702606, 0.042122066020965576, -0.012535796500742435, -0.005203643813729286, 0.01632230170071125, 0.008794101886451244, -0.04321993142366409, 0.021408315747976303, 0.023816892877221107, 0.02309992164373398, 0.028342774137854576, 0.013039916753768921, -0.06950140744447708, -0.027356937527656555, 0.03687921538949013, 0.0755956694483757, -0.032823845744132996, 0.06080813333392143, -0.017935486510396004, 0.01072656363248825, -0.002755858702585101, 0.018462011590600014, -0.011740406043827534, -0.04723048955202103, -0.030560903251171112, -0.007668232545256615, -0.04138268902897835, 0.014597089029848576, -0.036677565425634384, -0.015459694899618626, -0.029014933854341507, -0.02686402015388012, 0.01494437176734209, 0.001274304580874741, 0.04100180044770241, -0.018137134611606598, 0.04232371598482132, 0.03298068419098854, 0.08675353229045868, 0.03748415783047676, 0.019134173169732094, 0.002044488675892353, -0.03876126557588577, 0.06484109908342361, 0.03058330900967121, -0.0430854968726635, 0.02787226065993309, -0.058298733085393906, 0.015314060263335705, 0.01479873713105917, 0.014966776594519615, -0.013398402370512486, 0.049381401389837265, 0.05126345157623291, -0.03414576128125191, -0.028320368379354477, -0.04297346994280815, 0.03298068419098854, -0.02185642346739769, -0.0026970445178449154, -0.008189157582819462, -0.01567254588007927, 0.07994230836629868, -0.007875482551753521, -0.02439943142235279, 0.02959747426211834, -0.008911729790270329, 0.02034406177699566, -0.041405096650123596, -0.04019520804286003, 0.039747100323438644, 0.038694046437740326, 0.052831828594207764, -0.004469868261367083, 0.008284379728138447, -0.014899561181664467, 0.024981969967484474, 0.013633658178150654, -0.0018498421413823962, 0.03575894609093666, 0.04550527408719063, -0.014843547716736794, -0.018327580764889717, 0.008838912472128868, 0.10396084934473038, 0.07496831566095352, -0.012748646549880505, 0.011942054145038128, 0.012804660014808178, -0.004957184661179781, 0.04839556664228439, -0.026393508538603783, -0.06125624105334282, -0.008345995098352432, -0.032577384263277054, 0.02655034512281418, -0.014518669806420803, -0.03501956909894943, 0.0032739825546741486, 0.05000875145196915, 0.02336878515779972, -0.0759093388915062, 0.041158635169267654, -0.03275663033127785, -0.009936775080859661, 0.00826757587492466, -0.0057301693595945835, -0.04223409295082092, -0.02543007768690586, 0.022965488955378532, -0.033182330429553986, -0.01588539592921734, 0.05345917493104935, -0.07443059235811234, 0.03280143812298775, -0.02825315296649933, 0.0688292533159256, 0.01962709054350853, -0.027782639488577843, 0.01649034209549427, -0.051129020750522614, 0.023279163986444473, -0.03298068419098854, 0.02478032186627388, 0.03898531571030617, 0.024869943037629128, -0.014238603413105011, 0.04337676614522934, -0.005718966946005821, -0.027110479772090912, 0.05950862169265747, 0.03535564988851547, 0.03477311134338379, 0.02099381759762764, -0.022114085033535957, 0.01326396968215704, 0.052831828594207764, -0.0032207698095589876, 0.0033748066052794456, 0.008698878809809685, 0.06712644547224045, 0.050053562968969345, -0.07335513085126877, -0.034616272896528244, -0.04619984328746796, 0.0343698151409626, -0.0036884816363453865, 0.011774013750255108, 0.006407931447029114, -0.02892531268298626, 0.034212976694107056, 0.03669997304677963, 0.01771143265068531, 0.06219726428389549, -0.0721452459692955, 0.013555239886045456, 0.03681199625134468, 0.024264998733997345, -0.062062833458185196, -0.04035204276442528, -0.04611022025346756, 0.03372005745768547, 0.051084209233522415, -0.011617176234722137, 0.01342080719769001, 0.0002499597321730107, 0.0019100564531981945, -0.04615503177046776, -0.01569495163857937, -0.05547565966844559, -0.013555239886045456, -0.0018638455076143146, -0.02223731391131878, -0.002576615894213319, -0.02894771844148636, -0.014977979473769665, 0.04568452015519142, -0.02758099138736725, -0.04169636592268944, -0.02372727170586586, 0.043847277760505676, 0.005105620250105858, 0.08048003166913986, 0.0033327965065836906, 0.01152755506336689, -0.012905484065413475, 0.016311097890138626, -0.030202418565750122, -0.03584856912493706, -0.0344146266579628, -0.012278134934604168, 0.012838268652558327, -0.030784957110881805, -0.006127864588052034, 0.043847277760505676, 0.02583337388932705, -0.010631340555846691, 0.007332152221351862, -0.04718567803502083, 0.01224452629685402, -0.013297578319907188, 0.007881083525717258, -0.0825861394405365, 0.04151712357997894, 0.004993593320250511, 0.009018155746161938, 0.05681997910141945, 0.03676718845963478, -0.03643110767006874, 0.035288434475660324, 0.06649909168481827, -0.005802987143397331, -0.028409989550709724, -0.011079448275268078, 0.0034280193503946066, -0.09239968657493591, -0.08393046259880066, -0.0360502153635025, 0.03537805378437042, 0.026303887367248535, -0.012905484065413475, 0.007085693534463644, -0.032174088060855865, -0.011986864730715752, 0.022965488955378532, -0.04956064373254776, 0.00977993756532669, -0.023458406329154968, 0.03237573802471161, 0.005156032275408506, 0.03822353482246399, -0.02437702566385269, -0.06295904517173767, -0.026729587465524673, -0.03266700729727745, -0.049739886075258255, 0.009012553840875626, -0.013219159096479416, 0.0008409009897150099, 0.04257017374038696, -0.014675507321953773, -0.0585675984621048, 0.01773383840918541, -0.030112797394394875, -0.010183233767747879, 0.01273744460195303, -0.040374450385570526, 0.025900591164827347, 0.031501930207014084, -0.025676537305116653, -0.022607002407312393, 0.059687864035367966, 0.0019338622223585844, 0.003741694148629904, 0.02061292715370655, -0.039097342640161514, 0.09092093259096146, 0.04241333529353142, -0.0008275978034362197, 0.026908831670880318, 0.02017602138221264, 0.013140740804374218, 0.03170357644557953, -0.03307030349969864, -0.00836279895156622, 0.002262940863147378, 0.025026781484484673, -0.003203965723514557, 0.011292299255728722, 0.035938188433647156, 0.02646072395145893, -0.008245171047747135, 0.0214755330234766, -0.04619984328746796, -0.03024722822010517, 0.05081534385681152, 0.02448905259370804, 0.03190522640943527, 0.01042409148067236, 0.03885088488459587, 0.08572288602590561, -0.047275297343730927, -0.08527477830648422, -0.013174348510801792, 0.01327517256140709, 0.0309866052120924, 0.012490984983742237, 0.017823459580540657, -0.01567254588007927, 0.03537805378437042, 0.06313829123973846, -0.03486273065209389, -0.029754310846328735, -0.04086736589670181, -0.014036954380571842, 0.04568452015519142, 0.036341484636068344, 0.02655034512281418, 0.0024253795854747295, 0.013230361975729465, -0.03266700729727745, -0.013723280280828476, 0.02614704892039299, 0.012681431137025356, -0.03230852261185646, -0.036991242319345474, 0.010306463576853275, -0.016087044030427933, 0.042435742914676666, 0.008088333532214165, -0.008553244173526764, 0.014059360139071941, 0.013622456230223179, 0.03244295343756676, -0.042816631495952606, 0.020556913688778877, 0.026259075850248337, -0.03414576128125191, -0.0689636841416359, -0.04563970863819122, -0.044519439339637756, 0.00024768419098109007, 0.010345672257244587, -0.06811227649450302, 0.011006630957126617, 0.03407854586839676, 0.046244651079177856, 0.04532603174448013, 0.04956064373254776, 0.04001596197485924, -0.05816430225968361, 0.0584779754281044, -0.010435294359922409, -0.02448905259370804, 0.019716711714863777, 0.010670550167560577, 0.017464974895119667, -0.01008801069110632, -0.027603397145867348, 0.025676537305116653, -0.030896984040737152, 0.0861261859536171, 0.008928533643484116, -0.023548027500510216, -0.06815709173679352, -0.05198042467236519, 0.04339917376637459, -0.009163790382444859, -0.02894771844148636, 0.013084727339446545, 0.02034406177699566, -0.0378202386200428, 0.014440251514315605, -0.019403036683797836, 0.04478830471634865, 0.026438318192958832, 0.007606618106365204, -0.03885088488459587, -0.10557403415441513, -0.03136749565601349, -0.019447848200798035, 0.08195878565311432, -0.04781302809715271, -0.0051644342020154, -0.017532190307974815, 0.019279807806015015, 0.0054641058668494225, -0.029843932017683983, -0.017095286399126053, 0.07855317741632462, 0.010071206837892532, 0.019671902060508728, -0.04053128883242607, 0.02961988002061844, -0.030448878183960915, -0.042502958327531815, 0.002198525471612811, 0.05045685917139053, 0.02128508687019348, -0.0688740611076355, 0.0756404772400856, -0.0019744718447327614, -0.03230852261185646, 0.05059128999710083, -0.026035021990537643, 0.021778004243969917, -0.01981753669679165, 0.0033075904939323664, -0.02437702566385269, 0.00897334422916174, 0.041158635169267654, -0.03369765356183052, 0.03380968049168587, 0.033899303525686264, 0.0015501704765483737, 0.08124181628227234, -0.020624129101634026, -0.05274220556020737, 0.014361832290887833, 0.005469707306474447, -0.057312898337841034, -0.035938188433647156, 0.011953257024288177, -0.005671355407685041, 0.02892531268298626, 0.032913465052843094, 0.06121142953634262, -0.04440741240978241, -0.03820113092660904, -0.00037458952283486724, 0.07528199255466461, 0.0077466513030231, 0.022562192752957344, 0.050412047654390335, -0.056237440556287766, -0.055206794291734695, 0.003999355714768171, 0.009040560573339462, -0.030560903251171112, -0.04546046629548073, 0.04602059721946716, 0.010468902066349983, -0.019851144403219223, -0.010625739581882954, 0.08151067793369293, 0.07106978446245193, 0.004506276920437813, -0.02585577964782715, 0.010188834741711617, 0.05198042467236519, -0.042816631495952606, -0.017532190307974815, 0.056954413652420044, 0.00008266350778285414, 0.015392478555440903, -0.040755338966846466, 0.03412335366010666, -0.012188512831926346, 0.019974373281002045, 0.01663597673177719, -0.03338398039340973, 0.03369765356183052, 0.0016145858680829406, 0.00635191798210144, 0.011152265593409538, 0.014384238049387932, -0.03553489223122597, 0.009869558736681938, -0.007825070060789585, -0.0071585108526051044, -0.0827653780579567, 0.017274528741836548, -0.00636312086135149, -0.017095286399126053, -0.0033103912137448788, -0.024981969967484474, 0.012222121469676495, 0.012087688781321049, 0.027984287589788437, -0.009992788545787334, -0.0018218354089185596, -0.032129280269145966, -0.02646072395145893, 0.0014010348822921515, 0.004142189864069223, -0.019347023218870163, 0.03808910399675369, 0.016255084425210953, -0.0163671113550663, 0.04062090814113617, 0.00074077706085518, -0.08428894728422165, 0.013375996612012386, -0.015381275676190853, -0.009471863508224487, 0.08083852380514145, 0.022136490792036057, 0.0002984463353641331, -0.038380373269319534, -0.0014423447428271174, -0.007376963272690773, -0.05650630593299866, -0.01562773436307907, 0.06327272206544876, -0.019907157868146896, 0.0040777744725346565, -0.03230852261185646, 0.003383208531886339, -0.05668554827570915, 0.06994951516389847, -0.057626571506261826, 0.0029659089632332325, -0.009679113514721394, 0.003962947055697441, 0.05189080163836479, -0.009679113514721394, 0.06336234509944916, 0.004483871627599001, 0.036296673119068146, 0.009343032725155354, -0.017845865339040756, -0.02720010094344616, -0.017218515276908875, -0.040464069694280624, 0.006094256415963173, 0.00055733323097229, -0.04669275879859924, 0.0011895842617377639, 0.0051756370812654495, 0.0008857116918079555, -0.002156515372917056, 0.06927735358476639 ]
30,994
networkx.generators.small
pappus_graph
Returns the Pappus graph. The Pappus graph is a cubic symmetric distance-regular graph with 18 nodes and 27 edges. It is Hamiltonian and can be represented in LCF notation as [5,7,-7,7,-7,-5]^3 [1]_. Returns ------- G : networkx Graph Pappus graph References ---------- .. [1] https://en.wikipedia.org/wiki/Pappus_graph
def sedgewick_maze_graph(create_using=None): """ Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick """ G = empty_graph(0, create_using) G.add_nodes_from(range(8)) G.add_edges_from([[0, 2], [0, 7], [0, 5]]) G.add_edges_from([[1, 7], [2, 6]]) G.add_edges_from([[3, 4], [3, 5]]) G.add_edges_from([[4, 5], [4, 7], [4, 6]]) G.name = "Sedgewick Maze" return G
(*, backend=None, **backend_kwargs)
[ 0.08456815034151077, -0.022318517789244652, -0.013754434883594513, -0.03377189487218857, -0.06193821132183075, 0.023373888805508614, -0.06276866793632507, 0.05501773953437805, -0.00031466514337807894, -0.01584787666797638, -0.006782060954719782, 0.031557343900203705, -0.006959398277103901, 0.07737085968255997, 0.023996731266379356, -0.013451664708554745, 0.04301072284579277, -0.0033542655874043703, -0.024498464539647102, 0.052491769194602966, -0.010934343561530113, -0.039896510541439056, 0.04003491997718811, 0.0441179983317852, -0.026972534134984016, 0.02764727920293808, -0.014792505651712418, 0.05418728291988373, -0.008235359564423561, -0.03313175216317177, -0.017249273136258125, -0.04408339783549309, -0.058304961770772934, 0.018581463024020195, 0.030052142217755318, 0.0638759434223175, 0.001866364385932684, 0.04813187196850777, -0.08041586726903915, -0.0523187555372715, 0.03778576850891113, -0.005320111755281687, 0.052180346101522446, -0.004636715166270733, 0.040173329412937164, -0.012828822247684002, 0.0510384701192379, 0.02100362814962864, -0.026020968332886696, -0.031920671463012695, 0.026661112904548645, -0.023910224437713623, -0.016358261927962303, 0.035917241126298904, 0.034879170358181, -0.016877297312021255, -0.0224396251142025, -0.00800179410725832, 0.10263057798147202, -0.04757823422551155, 0.005324436817318201, -0.014169663190841675, 0.02726665325462818, 0.040969185531139374, -0.04581351578235626, -0.013962049037218094, -0.034152522683143616, -0.05491393432021141, -0.0005958092515356839, 0.004744847305119038, 0.045259878039360046, 0.03577883169054985, 0.04508686438202858, -0.010173091664910316, 0.03664389252662659, 0.029688818380236626, -0.014749252237379551, -0.035917241126298904, -0.044360216706991196, -0.0474398247897625, 0.01977524347603321, 0.016998404636979103, -0.02711094357073307, -0.05349523574113846, 0.03110751509666443, 0.032093681395053864, 0.030484672635793686, 0.04301072284579277, -0.011816702783107758, -0.09647135436534882, 0.016202552244067192, -0.013140243478119373, -0.027145545929670334, -0.011583137325942516, -0.008607335388660431, 0.004156607668846846, 0.020432688295841217, -0.06013888865709305, 0.0057439906522631645, -0.019429219886660576, -0.04173043742775917, 0.009558899328112602, -0.08484496921300888, 0.0124395452439785, -0.05269938334822655, -0.042768508195877075, -0.024481164291501045, 0.0040852404199540615, -0.017249273136258125, -0.04031173884868622, -0.041765037924051285, -0.0021637282334268093, 0.027197448536753654, 0.0044550527818500996, 0.031401634216308594, 0.036228664219379425, 0.02418704330921173, 0.016626430675387383, 0.03461965173482895, -0.06564066559076309, -0.019533026963472366, 0.009714609943330288, -0.047405220568180084, -0.03716292604804039, 0.03688610717654228, -0.029533106833696365, 0.034740760922431946, -0.013062387704849243, 0.008555431850254536, -0.012820171192288399, 0.020484592765569687, 0.006211122032254934, -0.03941207751631737, 0.032249391078948975, -0.05173051729798317, 0.00821805838495493, -0.0417996421456337, -0.043841179460287094, 0.025346223264932632, 0.02903137356042862, 0.011410125531256199, -0.028737252578139305, 0.0018815029179677367, 0.028270121663808823, -0.06314929574728012, -0.002491369377821684, -0.018581463024020195, 0.008516503497958183, 0.060900140553712845, 0.027976002544164658, 0.028425831347703934, -0.009031213819980621, 0.02121124230325222, 0.027128243818879128, -0.0214188564568758, -0.031713057309389114, -0.0013094827299937606, 0.05944684147834778, 0.015173131600022316, 0.05885859951376915, 0.01121981255710125, -0.025692246854305267, 0.01283747237175703, 0.011946462094783783, -0.036816902458667755, -0.01042395830154419, 0.008607335388660431, 0.011704245582222939, -0.012240582145750523, 0.013278652913868427, -0.0274396650493145, 0.01063157245516777, -0.05740530043840408, -0.024896392598748207, 0.06404895335435867, 0.0000034678382689889986, -0.02562304213643074, -0.005224955268204212, 0.02010396681725979, -0.04401419311761856, -0.01951572671532631, -0.012396292760968208, 0.014481084421277046, -0.005869423970580101, 0.002742236480116844, 0.003940342925488949, 0.012223280966281891, -0.0085294796153903, 0.032716523855924606, 0.016721585765480995, -0.010484512895345688, 0.005333087407052517, 0.03391030430793762, 0.07197289168834686, 0.040588557720184326, -0.023633405566215515, 0.030294358730316162, 0.024117838591337204, -0.056055810302495956, 0.07543312758207321, -0.01411775965243578, 0.0323185957968235, 0.011808052659034729, -0.026972534134984016, 0.052976202219724655, 0.035000279545784, 0.004766474012285471, -0.08110791444778442, -0.01882367953658104, 0.037889573723077774, -0.04778584837913513, -0.01601223833858967, 0.05636722967028618, 0.026816822588443756, -0.013451664708554745, -0.031401634216308594, 0.008235359564423561, 0.06121155992150307, 0.03406601399183273, -0.026038270443677902, -0.05062324181199074, 0.007041578646749258, -0.04892772436141968, -0.020000159740447998, 0.014256169088184834, -0.04328754171729088, -0.04508686438202858, -0.039100658148527145, -0.015216384083032608, -0.07425665110349655, 0.02074410952627659, -0.028944866731762886, 0.038893043994903564, -0.012595255859196186, 0.013200797140598297, -0.011756149120628834, -0.013252700679004192, -0.018910184502601624, 0.008053697645664215, -0.020865218713879585, -0.05065784230828285, -0.06373753398656845, 0.010069284588098526, -0.03408331796526909, 0.047128401696681976, 0.037993382662534714, -0.007465457543730736, 0.01833924651145935, 0.0030320310033857822, 0.008313215337693691, -0.03287223353981972, -0.014827108010649681, 0.03275112807750702, 0.00008096409874269739, -0.004528583027422428, 0.013814989477396011, -0.05799354240298271, 0.0036245964001864195, -0.016237154603004456, 0.022024396806955338, -0.021505361422896385, -0.0274396650493145, -0.023166274651885033, -0.01728387549519539, 0.04062316194176674, 0.011098704300820827, -0.05619421973824501, 0.07494869828224182, -0.08664429187774658, -0.045640502125024796, 0.03802798315882683, 0.01454163808375597, 0.014792505651712418, 0.006388459354639053, 0.017188718542456627, -0.003445096779614687, -0.025813354179263115, -0.0038365358486771584, -0.0013494917657226324, -0.03560582175850868, -0.09550248831510544, -0.03546741232275963, 0.01214542519301176, 0.0541180782020092, -0.050900060683488846, -0.0022945685777813196, 0.01610739529132843, 0.009463743306696415, 0.04141901433467865, -0.03013864904642105, -0.017465537413954735, -0.042249470949172974, 0.014178313314914703, 0.0006963723571971059, 0.04162662848830223, -0.004532908089458942, 0.022024396806955338, -0.008546780794858932, -0.028789157047867775, 0.047612834721803665, 0.08913566172122955, -0.06124616414308548, 0.007759577594697475, 0.01854686066508293, 0.023114372044801712, 0.03892764449119568, 0.001862039091065526, -0.02397942915558815, 0.04982738569378853, -0.035536617040634155, -0.08962009102106094, 0.014974167570471764, -0.004965437576174736, 0.05754370987415314, -0.027405062690377235, -0.04204185679554939, -0.0292389877140522, -0.030000239610671997, 0.05588280037045479, 0.049100738018751144, -0.007837432436645031, 0.018045127391815186, -0.015968985855579376, 0.008546780794858932, -0.06737077981233597, 0.014420529827475548, 0.018321946263313293, 0.04609033465385437, 0.012586605735123158, 0.018045127391815186, -0.02685142494738102, -0.036920711398124695, 0.015925733372569084, 0.01818353682756424, -0.05131528899073601, 0.018858281895518303, 0.013624676503241062, -0.007724975235760212, -0.022370420396327972, -0.044637035578489304, 0.09058895707130432, 0.023892924189567566, -0.013140243478119373, -0.011185210198163986, 0.06166139245033264, 0.01643611676990986, -0.007876360788941383, -0.05045022815465927, -0.012128124013543129, 0.04698999226093292, 0.03654008358716965, 0.07038118690252304, -0.01701570674777031, 0.0069161453284323215, 0.030294358730316162, 0.03391030430793762, 0.016185250133275986, 0.010164440609514713, -0.035277098417282104, 0.029065975919365883, -0.0633569061756134, 0.021834084764122963, 0.004857304971665144, -0.0016263105208054185, -0.021816782653331757, -0.025692246854305267, -0.0170589592307806, 0.032405104488134384, 0.053668249398469925, -0.05927382782101631, -0.021176639944314957, -0.05927382782101631, -0.021436156705021858, 0.03287223353981972, -0.008187782019376755, 0.06526003777980804, -0.034429341554641724, 0.009740562178194523, 0.06352991610765457, 0.004249601159244776, 0.011920509859919548, -0.00179067172575742, 0.008438648656010628, -0.00287632062099874, 0.08048506826162338, -0.028512338176369667, 0.04508686438202858, 0.035052184015512466, 0.017422284930944443, -0.05626342445611954, -0.094395212829113, -0.024308152496814728, 0.05695547163486481, 0.06806282699108124, -0.005527725908905268, 0.02531162090599537, 0.08214598149061203, 0.04650556296110153, -0.036228664219379425, 0.04657476767897606, 0.07750926911830902, -0.042872313410043716, 0.03205908089876175, 0.04387578368186951, -0.02818361483514309, -0.06550225615501404, -0.0270590391010046, 0.01079593412578106, 0.02657460607588291, 0.018633367493748665, 0.048893123865127563, -0.0487201102077961, -0.04854710027575493, 0.018045127391815186, -0.0027941400185227394, 0.010813235305249691, 0.015406697057187557, 0.026142077520489693, 0.05837416648864746, 0.006942097097635269, 0.05134988948702812, -0.012188678607344627, 0.00029682330205105245, 0.03875463455915451, 0.042457085102796555, -0.016981104388833046, -0.024429259821772575, -0.0057050627656280994, -0.05235335975885391, 0.047924257814884186, -0.010051983408629894, -0.060900140553712845, 0.057612914592027664, -0.021401554346084595, -0.01775100640952587, 0.005181702319532633, 0.033252861350774765, -0.018581463024020195, 0.02238772250711918, 0.01871987245976925, 0.03183416277170181, -0.014109108597040176, -0.029585011303424835, -0.030640382319688797, 0.020017459988594055, -0.03077879175543785, -0.007262168452143669, -0.006237073801457882, 0.01648802123963833, 0.009316683746874332, 0.03072688914835453, 0.011574487201869488, -0.03605565056204796, 0.011756149120628834, -0.06173059716820717, 0.008101276122033596, 0.02716284617781639, 0.011531233787536621, -0.03318365663290024, 0.05134988948702812, 0.03844321146607399, -0.01454163808375597, -0.020605700090527534, 0.06657492369413376, -0.038893043994903564, -0.015354793518781662, 0.02169567532837391, 0.005739665124565363, 0.0009537273435853422, -0.06792441755533218, 0.031868766993284225, -0.0296196136623621, -0.05889320373535156, -0.04588272050023079, 0.08885884284973145, -0.04515606909990311, -0.06342611461877823, -0.022422324866056442, 0.039308272302150726, -0.016998404636979103, -0.0615575835108757, -0.009558899328112602, 0.004909208510071039, 0.030847996473312378, -0.010571018792688847, 0.00038035554462112486, 0.05006960406899452, -0.08512178808450699, -0.022093601524829865, -0.04218026623129845, 0.002887133741751313, -0.03477536514401436, -0.02795870043337345, -0.000013389826563070528, -0.0064014350064098835, 0.07799369841814041, -0.030588479712605476, -0.031401634216308594, -0.004450727719813585, -0.07654040306806564, 0.028841059654951096, -0.01568351686000824, -0.03833940625190735, -0.021176639944314957, -0.02318357676267624, 0.04401419311761856, 0.023148974403738976, -0.012404942885041237, 0.01849495805799961, 0.027578074485063553, 0.056159619241952896, -0.009057166054844856, 0.0033239885233342648, 0.0766788125038147, 0.022197408601641655, 0.03003484196960926, -0.00761684263125062, 0.014948216266930103, 0.05491393432021141, -0.0592392273247242, 0.015346143394708633, 0.024308152496814728, 0.028079809620976448, 0.035917241126298904, -0.043944988399744034, 0.05996587499976158, 0.03046737052500248, 0.03375459462404251, 0.040277138352394104, 0.03764735907316208, 0.03159194812178612, 0.07141925394535065, -0.02854694053530693, 0.07937779277563095, 0.0337199904024601, -0.044360216706991196, 0.0474398247897625, 0.014342674985527992, -0.01967143639922142, -0.038581620901823044, 0.005203328561037779, -0.029654216021299362, -0.03408331796526909, -0.02295866049826145, -0.011392824351787567, 0.0017939156387001276, 0.09481044113636017, -0.029048673808574677, -0.02365070767700672, -0.09806306660175323, -0.02190328948199749, 0.032249391078948975, -0.005211979150772095, -0.005467171780765057, 0.08622906357049942, -0.04965437576174736, -0.023148974403738976, -0.029498504474759102, 0.01674753800034523, 0.012828822247684002, -0.0638759434223175, -0.011167909018695354, 0.014083157293498516, -0.009074467234313488, -0.008996611461043358, 0.022474227473139763, 0.00550177413970232, 0.02233581803739071, -0.024256248027086258, 0.025657644495368004, 0.02977532334625721, 0.043944988399744034, 0.08622906357049942, -0.025328921154141426, -0.028270121663808823, -0.00784175843000412, 0.0003398059052415192, 0.03147083893418312, 0.04955056682229042, -0.023685310035943985, -0.033996809273958206, -0.01414371095597744, 0.005653159227222204, 0.04031173884868622, -0.018944786861538887, 0.03934287279844284, -0.03657468780875206, 0.008391070179641247, -0.02190328948199749, 0.013183495961129665, 0.051176879554986954, -0.05134988948702812, 0.041280604898929596, -0.001987472642213106, -0.042560894042253494, -0.0030039167031645775, 0.02546733058989048, 0.019965557381510735, 0.023408491164445877, 0.016202552244067192, -0.05076165124773979, 0.07218050956726074, 0.0353982076048851, 0.03418712317943573, 0.03560582175850868, 0.02333928644657135, 0.01861606538295746, -0.018581463024020195, 0.0013992326566949487, -0.04397958889603615, -0.010000079870223999, 0.007543312851339579, -0.016704285517334938, -0.05394506826996803, -0.05913541838526726, 0.008140203543007374, -0.023321986198425293, 0.009039864875376225, -0.03159194812178612, -0.024446561932563782, 0.009256129153072834, -0.010882440023124218, 0.00166523817460984, -0.03287223353981972, -0.012205979786813259, 0.00400089705362916, 0.02174757793545723, 0.009991428814828396, -0.013382459990680218, 0.04072696715593338, -0.02174757793545723, -0.0453982874751091, -0.011929160915315151, -0.03321825712919235, -0.020000159740447998, -0.031003708019852638, 0.00014611384540330619, 0.00007866628584451973, 0.010787283070385456, 0.05820115655660629, -0.041661232709884644, 0.02716284617781639, 0.0274396650493145, 0.017309825867414474, -0.06761299818754196, -0.019584931433200836, 0.06356452405452728, -0.000897498510312289, -0.04273390397429466, 0.01132361963391304, -0.008196432143449783, 0.005324436817318201, 0.023218179121613503, 0.017292525619268417, 0.05498313903808594, 0.0366784930229187, -0.034879170358181, -0.06705936044454575, 0.0541180782020092, -0.04716300591826439, 0.03892764449119568, 0.00879764836281538, 0.009282081387937069, 0.02359880320727825, 0.022024396806955338, 0.04560590162873268, 0.006120291072875261, 0.02813171222805977, 0.03252620995044708, -0.027837593108415604, -0.025744149461388588, -0.04391038417816162, -0.008780347183346748, -0.05214574560523033, -0.06481020897626877, -0.045432887971401215, -0.024948295205831528, 0.02290675789117813, -0.04674777761101723, -0.03716292604804039, 0.039100658148527145, 0.05183432251214981, -0.012941279448568821, -0.04460243135690689, -0.005592605099081993, 0.03629786893725395, -0.052664779126644135, -0.021436156705021858, 0.030398165807127953, 0.007625493220984936, -0.023062467575073242, -0.040380943566560745, 0.024498464539647102, 0.050104204565286636, -0.010562367737293243, 0.007045903708785772, -0.01664373092353344, -0.018218139186501503, 0.0024437911342829466, -0.06346071511507034, 0.03259541466832161, 0.044533226639032364, 0.002415676601231098, 0.02152266353368759, 0.03996571525931358, -0.04349515587091446, -0.03986191004514694, 0.0487201102077961, -0.0027379111852496862, 0.006336555816233158, -0.020692206919193268, -0.031557343900203705, 0.04190344735980034, 0.029100578278303146, 0.00041468755807727575, -0.058997008949518204, -0.0037089395336806774, -0.000995898968540132, -0.022508829832077026, 0.0070069762878119946, 0.012205979786813259, 0.0011559348786249757, -0.01871987245976925, 0.020830616354942322, -0.0623188354074955, -0.0014543801080435514, -0.04619413986802101, -0.059689056128263474, 0.0037867948412895203, -0.056159619241952896, -0.043460555374622345, 0.008140203543007374, -0.00496976263821125, 0.052491769194602966, 0.006976699456572533, 0.0030731214210391045, 0.0003187200927641243, 0.05982746556401253, -0.01871987245976925, 0.0371975302696228, -0.03441203758120537, -0.01833924651145935, -0.08145393431186676, 0.006124616134911776, -0.00973191112279892, 0.012716364115476608, 0.030744189396500587, 0.045259878039360046, -0.046816982328891754, 0.012552003376185894, 0.059758260846138, -0.05553677678108215, 0.06692095100879669, 0.02811441197991371, -0.024913692846894264, 0.025380825623869896, -0.04020793363451958, -0.044152602553367615, -0.03619405999779701, -0.07100402563810349, -0.01823543943464756, 0.024152440950274467, 0.014550289139151573, -0.02290675789117813, -0.04467163607478142, 0.02238772250711918, 0.02285485342144966, 0.056159619241952896 ]
30,997
networkx.readwrite.gml
parse_gml
Parse GML graph from a string or iterable. Parameters ---------- lines : string or iterable of strings Data in GML format. label : string, optional If not None, the parsed nodes will be renamed according to node attributes indicated by `label`. Default value: 'label'. destringizer : callable, optional A `destringizer` that recovers values stored as strings in GML. If it cannot convert a string to a value, a `ValueError` is raised. Default value : None. Returns ------- G : NetworkX graph The parsed graph. Raises ------ NetworkXError If the input cannot be parsed. See Also -------- write_gml, read_gml Notes ----- This stores nested GML attributes as dictionaries in the NetworkX graph, node, and edge attribute structures. GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a `stringizer`/`destringizer`, the code is capable of writing `int`/`float`/`str`/`dict`/`list` data as required by the GML specification. For writing other data types, and for reading data other than `str` you need to explicitly supply a `stringizer`/`destringizer`. For additional documentation on the GML file format, please see the `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_. See the module docstring :mod:`networkx.readwrite.gml` for more details.
def generate_gml(G, stringizer=None): r"""Generate a single entry of the graph `G` in GML format. Parameters ---------- G : NetworkX graph The graph to be converted to GML. stringizer : callable, optional A `stringizer` which converts non-int/non-float/non-dict values into strings. If it cannot convert a value into a string, it should raise a `ValueError` to indicate that. Default value: None. Returns ------- lines: generator of strings Lines of GML data. Newlines are not appended. Raises ------ NetworkXError If `stringizer` cannot convert a value into a string, or the value to convert is not a string while `stringizer` is None. See Also -------- literal_stringizer Notes ----- Graph attributes named 'directed', 'multigraph', 'node' or 'edge', node attributes named 'id' or 'label', edge attributes named 'source' or 'target' (or 'key' if `G` is a multigraph) are ignored because these attribute names are used to encode the graph structure. GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a `stringizer`/`destringizer`, the code is capable of writing `int`/`float`/`str`/`dict`/`list` data as required by the GML specification. For writing other data types, and for reading data other than `str` you need to explicitly supply a `stringizer`/`destringizer`. For additional documentation on the GML file format, please see the `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_. See the module docstring :mod:`networkx.readwrite.gml` for more details. Examples -------- >>> G = nx.Graph() >>> G.add_node("1") >>> print("\n".join(nx.generate_gml(G))) graph [ node [ id 0 label "1" ] ] >>> G = nx.MultiGraph([("a", "b"), ("a", "b")]) >>> print("\n".join(nx.generate_gml(G))) graph [ multigraph 1 node [ id 0 label "a" ] node [ id 1 label "b" ] edge [ source 0 target 1 key 0 ] edge [ source 0 target 1 key 1 ] ] """ valid_keys = re.compile("^[A-Za-z][0-9A-Za-z_]*$") def stringize(key, value, ignored_keys, indent, in_list=False): if not isinstance(key, str): raise NetworkXError(f"{key!r} is not a string") if not valid_keys.match(key): raise NetworkXError(f"{key!r} is not a valid key") if not isinstance(key, str): key = str(key) if key not in ignored_keys: if isinstance(value, int | bool): if key == "label": yield indent + key + ' "' + str(value) + '"' elif value is True: # python bool is an instance of int yield indent + key + " 1" elif value is False: yield indent + key + " 0" # GML only supports signed 32-bit integers elif value < -(2**31) or value >= 2**31: yield indent + key + ' "' + str(value) + '"' else: yield indent + key + " " + str(value) elif isinstance(value, float): text = repr(value).upper() # GML matches INF to keys, so prepend + to INF. Use repr(float(*)) # instead of string literal to future proof against changes to repr. if text == repr(float("inf")).upper(): text = "+" + text else: # GML requires that a real literal contain a decimal point, but # repr may not output a decimal point when the mantissa is # integral and hence needs fixing. epos = text.rfind("E") if epos != -1 and text.find(".", 0, epos) == -1: text = text[:epos] + "." + text[epos:] if key == "label": yield indent + key + ' "' + text + '"' else: yield indent + key + " " + text elif isinstance(value, dict): yield indent + key + " [" next_indent = indent + " " for key, value in value.items(): yield from stringize(key, value, (), next_indent) yield indent + "]" elif isinstance(value, tuple) and key == "label": yield indent + key + f" \"({','.join(repr(v) for v in value)})\"" elif isinstance(value, list | tuple) and key != "label" and not in_list: if len(value) == 0: yield indent + key + " " + f'"{value!r}"' if len(value) == 1: yield indent + key + " " + f'"{LIST_START_VALUE}"' for val in value: yield from stringize(key, val, (), indent, True) else: if stringizer: try: value = stringizer(value) except ValueError as err: raise NetworkXError( f"{value!r} cannot be converted into a string" ) from err if not isinstance(value, str): raise NetworkXError(f"{value!r} is not a string") yield indent + key + ' "' + escape(value) + '"' multigraph = G.is_multigraph() yield "graph [" # Output graph attributes if G.is_directed(): yield " directed 1" if multigraph: yield " multigraph 1" ignored_keys = {"directed", "multigraph", "node", "edge"} for attr, value in G.graph.items(): yield from stringize(attr, value, ignored_keys, " ") # Output node data node_id = dict(zip(G, range(len(G)))) ignored_keys = {"id", "label"} for node, attrs in G.nodes.items(): yield " node [" yield " id " + str(node_id[node]) yield from stringize("label", node, (), " ") for attr, value in attrs.items(): yield from stringize(attr, value, ignored_keys, " ") yield " ]" # Output edge data ignored_keys = {"source", "target"} kwargs = {"data": True} if multigraph: ignored_keys.add("key") kwargs["keys"] = True for e in G.edges(**kwargs): yield " edge [" yield " source " + str(node_id[e[0]]) yield " target " + str(node_id[e[1]]) if multigraph: yield from stringize("key", e[2], (), " ") for attr, value in e[-1].items(): yield from stringize(attr, value, ignored_keys, " ") yield " ]" yield "]"
(lines, label='label', destringizer=None, *, backend=None, **backend_kwargs)
[ 0.04245934262871742, 0.02539025992155075, -0.018626635894179344, -0.03789336234331131, 0.03232457488775253, -0.0071476781740784645, -0.057693496346473694, -0.0013475239975377917, 0.11487492173910141, -0.07382377982139587, -0.011414948850870132, 0.05363959074020386, -0.030681675300002098, 0.08807646483182907, 0.009025276638567448, 0.02242450602352619, -0.02114432491362095, -0.023939387872815132, 0.05884566158056259, 0.010902876034379005, -0.01578890159726143, -0.012204393744468689, 0.035631708800792694, 0.010049422271549702, 0.030788356438279152, -0.061918094754219055, 0.01817857287824154, 0.004627321381121874, -0.04587315768003464, 0.025432931259274483, -0.01553286425769329, -0.12494567781686783, -0.007654416374862194, -0.05496244505047798, -0.0060595241375267506, -0.02656375803053379, -0.07966993749141693, 0.02204045280814171, -0.10190241783857346, -0.061875421553850174, 0.03846944496035576, -0.0176985040307045, -0.036869216710329056, -0.0358450710773468, -0.010449478402733803, 0.05457838997244835, -0.021101651713252068, 0.07023927569389343, -0.057138752192258835, -0.0452757403254509, 0.01597025990486145, -0.011863011866807938, -0.049030937254428864, 0.04856153950095177, -0.04497703164815903, -0.005803487729281187, -0.02047223038971424, 0.008913260884582996, 0.07190350443124771, 0.031172411516308784, -0.004525973927229643, 0.03106572851538658, -0.005654133390635252, -0.009329319931566715, -0.011564303189516068, 0.0013761947629973292, -0.0436541773378849, -0.06311292946338654, -0.03307134658098221, -0.007963793352246284, -0.026926476508378983, -0.002383003942668438, 0.017250441014766693, 0.01065217424184084, -0.0002967086620628834, 0.01535150595009327, -0.035034291446208954, 0.043995559215545654, 0.015330169349908829, -0.014444710686802864, -0.002320328261703253, 0.024622151628136635, 0.0009841392748057842, -0.09285580366849899, 0.028590712696313858, 0.008251834660768509, 0.04056040570139885, 0.041883260011672974, -0.0071583460085093975, 0.01489277370274067, -0.039237551391124725, 0.01180967129766941, 0.026969149708747864, 0.04335546866059303, -0.02361934259533882, -0.018882671371102333, -0.02013084851205349, -0.04437961429357529, 0.03277263790369034, -0.0014842100208625197, 0.014210010878741741, 0.010369467549026012, -0.04173390567302704, -0.0035525027196854353, -0.04437961429357529, -0.0645638033747673, -0.028697393834590912, -0.0006707615684717894, 0.04510504752397537, -0.04425159469246864, -0.08218763023614883, -0.06473449617624283, 0.06976987421512604, -0.02351265959441662, 0.060765933245420456, 0.013975311070680618, -0.016183624044060707, -0.0036671855486929417, 0.024046069011092186, -0.01656767725944519, -0.01179900299757719, -0.021955106407403946, -0.06016851216554642, 0.04391021281480789, 0.0018415938830003142, 0.014978119172155857, 0.05590124428272247, 0.007323702797293663, 0.04237399622797966, -0.025880996137857437, 0.040731098502874374, 0.025432931259274483, 0.042544685304164886, 0.045830484479665756, 0.0278012678027153, -0.038896169513463974, -0.04856153950095177, -0.005032712128013372, 0.07006858289241791, 0.07322636246681213, 0.03885349631309509, -0.08035270124673843, 0.02598767727613449, 0.01012409944087267, -0.002539025852456689, -0.04770808294415474, 0.0010101429652422667, 0.010860203765332699, -0.0040939124301075935, -0.05965644121170044, 0.04685463011264801, 0.006368901114910841, 0.03497027978301048, -0.01967211626470089, -0.007409048266708851, 0.02716117724776268, -0.05048181116580963, 0.04348348453640938, 0.007222355343401432, 0.0012601782800629735, 0.0004107247805222869, 0.0027163843624293804, 0.03462890163064003, 0.045830484479665756, 0.01565021462738514, 0.01806122250854969, 0.04647057503461838, -0.0579068623483181, 0.011222921311855316, 0.010497485287487507, -0.001212838338688016, -0.0680202916264534, -0.088247150182724, -0.010572162456810474, 0.04476366564631462, 0.007697089109569788, 0.030276283621788025, 0.10369466990232468, -0.009350656531751156, 0.059827134013175964, -0.015095469541847706, -0.0265424232929945, -0.0369972363114357, -0.007355707697570324, -0.023384641855955124, -0.017730507999658585, 0.053084846585989, -0.005584790371358395, 0.04316344112157822, -0.024878187105059624, 0.004795345012098551, -0.04149920493364334, -0.01891467720270157, 0.05752280727028847, 0.02560362219810486, -0.005152729339897633, -0.006454246584326029, -0.004766007885336876, 0.013804620131850243, 0.08265703171491623, -0.0046833292581140995, -0.028590712696313858, 0.028825411573052406, -0.036229126155376434, -0.05346889793872833, -0.014316692017018795, -0.03887483477592468, -0.01083353254944086, -0.04706799238920212, 0.0029044109396636486, -0.0012108379742130637, -0.014113997109234333, 0.012407088652253151, 0.04591583088040352, -0.016098277643322945, -0.03151379153132439, -0.0104548130184412, 0.05201802775263786, -0.08141952008008957, -0.055047787725925446, 0.010556160472333431, -0.01702640950679779, 0.019757462665438652, -0.033860791474580765, 0.04945766553282738, -0.049969736486673355, 0.05986980348825455, -0.03821340575814247, -0.007787768729031086, 0.002133635338395834, 0.10634037852287292, 0.011126907542347908, 0.05641331523656845, 0.039813634008169174, 0.02541159652173519, -0.06055256724357605, 0.026414403691887856, 0.0004193926870357245, 0.017687836661934853, 0.03104439191520214, -0.04047505930066109, -0.052658118307590485, -0.06823365390300751, -0.03130042925477028, 0.03307134658098221, 0.022744551301002502, 0.009516012854874134, 0.017079750075936317, 0.016877055168151855, 0.011190916411578655, -0.024920860305428505, 0.019288063049316406, -0.012321743182837963, -0.00874256994575262, -0.02777993120253086, -0.004392621573060751, -0.05090853571891785, -0.046086519956588745, 0.03162047266960144, -0.011596307158470154, 0.013452569954097271, -0.008219829760491848, -0.09865929186344147, 0.070794016122818, 0.07369576394557953, 0.012332411482930183, 0.023021923378109932, 0.010801528580486774, 0.014828764833509922, -0.0016789042856544256, 0.041584551334381104, 0.05841893330216408, -0.02389671467244625, -0.02564629539847374, 0.006315560545772314, -0.0035098299849778414, 0.04335546866059303, 0.01955476775765419, 0.0054887766018509865, -0.013729942962527275, -0.023491324856877327, -0.0012148385867476463, -0.023171279579401016, -0.013505911454558372, -0.023747360333800316, 0.03016960248351097, -0.037167925387620926, -0.02560362219810486, 0.01656767725944519, -0.03588774427771568, 0.061619386076927185, -0.01624763198196888, -0.03665585443377495, 0.035631708800792694, 0.04745204746723175, -0.030062921345233917, 0.012460430152714252, -0.03972828760743141, -0.005070050712674856, 0.002112298971042037, 0.08790577203035355, -0.01790119893848896, 0.0870949923992157, 0.007894450798630714, -0.01146828942000866, 0.03932289779186249, 0.019682785496115685, -0.01808255910873413, -0.02479284070432186, 0.02389671467244625, -0.04689730331301689, -0.0012041704030707479, 0.04209662228822708, 0.01280181109905243, -0.0160876102745533, 0.010881539434194565, 0.005936840083450079, -0.010796193964779377, 0.07271429151296616, -0.008721234276890755, -0.02268054336309433, 0.03213254734873772, 0.007830440998077393, 0.023662013933062553, -0.03127909451723099, 0.010945549234747887, 0.03578106313943863, 0.05035379156470299, 0.03198319301009178, -0.053212862461805344, -0.0006074192933738232, -0.024707496166229248, -0.02162439376115799, 0.06324094533920288, -0.041605886071920395, 0.05496244505047798, 0.027075830847024918, -0.0074783917516469955, -0.009382661432027817, -0.08013933897018433, 0.033242035657167435, 0.018743986263871193, -0.009622694924473763, 0.0011875013587996364, 0.023726023733615875, 0.01881866343319416, 0.011425617150962353, -0.05223139002919197, 0.018381267786026, 0.0452757403254509, -0.019608108326792717, 0.04813481122255325, 0.0162049587816, 0.021848425269126892, 0.015938255935907364, -0.028420021757483482, -0.00843319296836853, -0.046982649713754654, -0.020184189081192017, 0.05372493714094162, 0.03311401978135109, 0.0023750027175992727, -0.0023910049349069595, 0.06430776417255402, 0.0018495951080694795, -0.03076701983809471, -0.00874256994575262, 0.054706405848264694, 0.0811208114027977, 0.009969410486519337, 0.01521281898021698, -0.026030350476503372, -0.045787811279296875, -0.007862445898354053, -0.02074960246682167, 0.008011800236999989, 0.016194291412830353, 0.015618209727108479, -0.03874681517481804, -0.006662276107817888, -0.014764755964279175, 0.04702531918883324, 0.025752976536750793, 0.0519326813519001, 0.023107269778847694, -0.022211143746972084, 0.09772049635648727, 0.01955476775765419, -0.03972828760743141, -0.05060982704162598, -0.02295791544020176, 0.010998889803886414, 0.03962160646915436, 0.013708606362342834, -0.03249526396393776, -0.06426509469747543, 0.06400905549526215, -0.029038775712251663, -0.011009558103978634, -0.022829897701740265, -0.012321743182837963, -0.0013935305178165436, -0.07523197680711746, 0.0056808036752045155, 0.00679562846198678, -0.042864732444286346, 0.029294811189174652, -0.015820905566215515, 0.017933204770088196, 0.012236397713422775, 0.043739523738622665, -0.022189807146787643, -0.06622803956270218, -0.01535150595009327, 0.025454267859458923, -0.01865863986313343, -0.016396986320614815, 0.04984172061085701, -0.009585356339812279, 0.04092312231659889, 0.010129433125257492, 0.02325662411749363, 0.05069517344236374, 0.015479523688554764, -0.042181968688964844, 0.012865820899605751, -0.04329146072268486, -0.010918878018856049, -0.06883107125759125, 0.05730944126844406, -0.02504887804389, -0.048518866300582886, 0.030276283621788025, -0.005798153579235077, -0.005894167348742485, -0.03908819705247879, -0.019288063049316406, -0.019341403618454933, 0.014775424264371395, -0.018893340602517128, 0.00339248008094728, -0.03881082683801651, 0.024366114288568497, -0.009921403601765633, 0.02656375803053379, -0.0014735418371856213, -0.020376216620206833, 0.039258889853954315, 0.06720951199531555, 0.03661318123340607, -0.00863055419176817, -0.01239642035216093, 0.06533191353082657, 0.013111189007759094, -0.027950622141361237, -0.022829897701740265, 0.042822059243917465, -0.004112581722438335, -0.037701334804296494, 0.05483442544937134, -0.0036458491813391447, -0.017709173262119293, 0.029401494190096855, 0.04898826405405998, -0.018381267786026, 0.018893340602517128, 0.014508719556033611, 0.05701073259115219, -0.06823365390300751, 0.006491585168987513, -0.010881539434194565, 0.020664257928729057, -0.024110078811645508, -0.024920860305428505, -0.007281030062586069, -0.018850667402148247, -0.017794517800211906, 0.026414403691887856, -0.03422350808978081, -0.05602926015853882, 0.02656375803053379, -0.03957893326878548, 0.01817857287824154, 0.00887058861553669, 0.010790860280394554, 0.03902418911457062, 0.06533191353082657, -0.0393015593290329, -0.007115673739463091, 0.0044432953000068665, -0.05530382692813873, 0.0030297620687633753, 0.0171224232763052, -0.05483442544937134, 0.005264745093882084, 0.036869216710329056, -0.017271777614951134, -0.03247392922639847, -0.019928153604269028, -0.029316147789359093, -0.029465502128005028, 0.002294991398230195, -0.016695694997906685, 0.00025703635765239596, 0.049030937254428864, 0.018882671371102333, 0.006395571865141392, 0.044038232415914536, 0.01314319297671318, -0.037146590650081635, -0.0037578651681542397, -0.02713984064757824, 0.05701073259115219, 0.030276283621788025, -0.038064051419496536, -0.019928153604269028, 0.027609240263700485, 0.02265920676290989, -0.05287148058414459, -0.03290065377950668, 0.02952951192855835, -0.016770372167229652, -0.004947366658598185, 0.026457076892256737, -0.03014826588332653, 0.030062921345233917, 0.018210576847195625, -0.021549716591835022, -0.016258301213383675, -0.017954541370272636, 0.011414948850870132, 0.05043913796544075, 0.024622151628136635, 0.05961376801133156, -0.030297620221972466, -0.019202716648578644, 0.06904443353414536, 0.022296488285064697, -0.022552523761987686, 0.019320067018270493, 0.03857612609863281, -0.004883357789367437, -0.013388561084866524, 0.04184058681130409, 0.02927347645163536, 0.00019502759096212685, 0.06853236258029938, 0.010625503957271576, 0.024536805227398872, -0.07301300019025803, -0.06772158294916153, 0.0016975735779851675, -0.028142649680376053, -0.016034269705414772, 0.03462890163064003, -0.017869194969534874, 0.0014175339601933956, 0.06810563802719116, 0.013719274662435055, 0.0002903744170907885, -0.012353748083114624, 0.030489647760987282, -0.06311292946338654, -0.02713984064757824, 0.10463347285985947, 0.027353202924132347, -0.03851211443543434, -0.014402037486433983, -0.0027710588183254004, 0.008763906545937061, 0.008465197868645191, -0.038682807236909866, 0.062472838908433914, -0.010998889803886414, -0.030062921345233917, 0.026734448969364166, -0.06324094533920288, 0.01661035045981407, 0.0067742918618023396, -0.04243800416588783, -0.01521281898021698, 0.047622740268707275, 0.06311292946338654, 0.04979904741048813, 0.0625155121088028, 0.02008817531168461, -0.01280181109905243, 0.08696696907281876, -0.016653023660182953, 0.016951732337474823, 0.007024994120001793, -0.005590124521404505, 0.01831725798547268, -0.01624763198196888, 0.010998889803886414, -0.03915220499038696, 0.028825411573052406, -0.030212275683879852, -0.02628638595342636, -0.0420539490878582, -0.03426618129014969, 0.06464914977550507, 0.028718730434775352, 0.03872548043727875, 0.010561494156718254, 0.0214857067912817, 0.03548235446214676, -0.023192614316940308, 0.016653023660182953, -0.0402190238237381, -0.023811370134353638, 0.013388561084866524, -0.034116826951503754, -0.058077551424503326, -0.061278004199266434, -0.027950622141361237, -0.013836624100804329, 0.018349263817071915, -0.02957218512892723, -0.10719383507966995, 0.06656941771507263, -0.039237551391124725, -0.0634116381406784, -0.002209645928815007, 0.014871438033878803, 0.0052274065092206, -0.015500860288739204, -0.016034269705414772, -0.02010951191186905, -0.046427901834249496, -0.019618775695562363, -0.03014826588332653, 0.0032911323942244053, 0.007355707697570324, 0.006336896680295467, -0.012759138830006123, 0.02831333875656128, 0.04085911437869072, -0.03870414197444916, -0.027651913464069366, -0.056584008038043976, 0.0278012678027153, -0.017335785552859306, -0.023811370134353638, -0.02008817531168461, 0.03349807485938072, 0.036762535572052, -0.025176895782351494, 0.03486359864473343, -0.021336352452635765, 0.009772049263119698, 0.05662667751312256, 0.03849077969789505, -0.03900285065174103, 0.020920293405652046, 0.04060307890176773, -0.021251007914543152, -0.02596634067595005, -0.05137793719768524, -0.022147133946418762, 0.007782434578984976, -0.0018455944955348969, 0.04211796075105667, 0.0014482049737125635, -0.06827633082866669, 0.03253793716430664, -0.012663125060498714, 0.02536892332136631, 0.03669852763414383, -0.018605299293994904, -0.05645598843693733, 0.0005757481558248401, 0.05154862627387047, -0.030020248144865036, -0.040731098502874374, -0.05107922852039337, 0.050865862518548965, 0.053554244339466095, -0.01845594495534897, -0.000908795278519392, 0.01135093905031681, 0.041669897735118866, -0.014103328809142113, -0.029081448912620544, -0.021891098469495773, -0.05619995296001434, -0.02146437019109726, -0.06332629173994064, -0.003368476638570428, 0.01387929730117321, -0.016759704798460007, -0.012289739213883877, 0.02867605723440647, -0.028590712696313858, -0.00138019525911659, -0.04006966948509216, 0.018690643832087517, 0.018327927216887474, 0.003955226391553879, -0.044891685247421265, -0.012449761852622032, -0.024622151628136635, 0.002340331207960844, 0.04017635062336922, 0.026926476508378983, -0.03821340575814247, -0.031492456793785095, 0.03428751975297928, -0.007366375532001257, 0.020162852481007576, -0.00884925201535225, 0.039813634008169174, -0.029401494190096855, -0.00353916734457016, 0.0013735276879742742, -0.06533191353082657, -0.03753064572811127, 0.06371034681797028, -0.049372319132089615, 0.0016242298297584057, -0.023662013933062553, 0.029422830790281296, 0.03409549221396446, 0.020962966606020927, -0.03219655528664589, 0.028590712696313858, -0.0002618703874759376, -0.04322744905948639, -0.014508719556033611, -0.02472883276641369, 0.023341968655586243, 0.06533191353082657, -0.021869761869311333, 0.03957893326878548, 0.0010628170566633344, -0.045830484479665756, -0.06699614971876144, 0.007142344024032354, 0.029038775712251663, 0.022616533562541008, -0.027673248201608658, 0.02658509463071823, -0.022509852424263954, -0.028462694957852364, -0.02327796071767807, -0.035973090678453445, 0.03578106313943863, 0.043099433183670044, -0.04685463011264801, 0.04651324823498726, 0.04211796075105667, 0.00785711221396923, -0.03181250020861626, -0.004843351896852255, 0.045830484479665756, 0.024515468627214432, -0.010326794348657131, -0.007953125052154064, -0.02033354341983795, -0.03104439191520214, -0.030873702839016914, -0.02208312414586544, 0.03691188991069794, -0.0349276103079319, -0.014764755964279175, -0.009622694924473763, 0.010988221503794193, 0.038981515914201736 ]
30,998
networkx.readwrite.graphml
parse_graphml
Read graph in GraphML format from string. Parameters ---------- graphml_string : string String containing graphml information (e.g., contents of a graphml file). node_type: Python type (default: str) Convert node ids to this type edge_key_type: Python type (default: int) Convert graphml edge ids to this type. Multigraphs use id as edge key. Non-multigraphs add to edge attribute dict with name "id". force_multigraph : bool (default: False) If True, return a multigraph with edge keys. If False (the default) return a multigraph when multiedges are in the graph. Returns ------- graph: NetworkX graph If no parallel edges are found a Graph or DiGraph is returned. Otherwise a MultiGraph or MultiDiGraph is returned. Examples -------- >>> G = nx.path_graph(4) >>> linefeed = chr(10) # linefeed = >>> s = linefeed.join(nx.generate_graphml(G)) >>> H = nx.parse_graphml(s) Notes ----- Default node and edge attributes are not propagated to each node and edge. They can be obtained from `G.graph` and applied to node and edge attributes if desired using something like this: >>> default_color = G.graph["node_default"]["color"] # doctest: +SKIP >>> for node, data in G.nodes(data=True): # doctest: +SKIP ... if "color" not in data: ... data["color"] = default_color >>> default_color = G.graph["edge_default"]["color"] # doctest: +SKIP >>> for u, v, data in G.edges(data=True): # doctest: +SKIP ... if "color" not in data: ... data["color"] = default_color This implementation does not support mixed graphs (directed and unidirected edges together), hypergraphs, nested graphs, or ports. For multigraphs the GraphML edge "id" will be used as the edge key. If not specified then they "key" attribute will be used. If there is no "key" attribute a default NetworkX multigraph edge key will be provided.
def add_graph_element(self, G): """ Serialize graph G in GraphML to the stream. """ if G.is_directed(): default_edge_type = "directed" else: default_edge_type = "undirected" graphid = G.graph.pop("id", None) if graphid is None: graph_element = self._xml.element("graph", edgedefault=default_edge_type) else: graph_element = self._xml.element( "graph", edgedefault=default_edge_type, id=graphid ) # gather attributes types for the whole graph # to find the most general numeric format needed. # Then pass through attributes to create key_id for each. graphdata = { k: v for k, v in G.graph.items() if k not in ("node_default", "edge_default") } node_default = G.graph.get("node_default", {}) edge_default = G.graph.get("edge_default", {}) # Graph attributes for k, v in graphdata.items(): self.attribute_types[(str(k), "graph")].add(type(v)) for k, v in graphdata.items(): element_type = self.get_xml_type(self.attr_type(k, "graph", v)) self.get_key(str(k), element_type, "graph", None) # Nodes and data for node, d in G.nodes(data=True): for k, v in d.items(): self.attribute_types[(str(k), "node")].add(type(v)) for node, d in G.nodes(data=True): for k, v in d.items(): T = self.get_xml_type(self.attr_type(k, "node", v)) self.get_key(str(k), T, "node", node_default.get(k)) # Edges and data if G.is_multigraph(): for u, v, ekey, d in G.edges(keys=True, data=True): for k, v in d.items(): self.attribute_types[(str(k), "edge")].add(type(v)) for u, v, ekey, d in G.edges(keys=True, data=True): for k, v in d.items(): T = self.get_xml_type(self.attr_type(k, "edge", v)) self.get_key(str(k), T, "edge", edge_default.get(k)) else: for u, v, d in G.edges(data=True): for k, v in d.items(): self.attribute_types[(str(k), "edge")].add(type(v)) for u, v, d in G.edges(data=True): for k, v in d.items(): T = self.get_xml_type(self.attr_type(k, "edge", v)) self.get_key(str(k), T, "edge", edge_default.get(k)) # Now add attribute keys to the xml file for key in self.xml: self._xml.write(key, pretty_print=self._prettyprint) # The incremental_writer writes each node/edge as it is created incremental_writer = IncrementalElement(self._xml, self._prettyprint) with graph_element: self.add_attributes("graph", incremental_writer, graphdata, {}) self.add_nodes(G, incremental_writer) # adds attributes too self.add_edges(G, incremental_writer) # adds attributes too
(graphml_string, node_type=<class 'str'>, edge_key_type=<class 'int'>, force_multigraph=False, *, backend=None, **backend_kwargs)
[ 0.026304125785827637, -0.015990139916539192, -0.028598319739103317, 0.053676240146160126, 0.007688518147915602, -0.002388137625530362, -0.07282089442014694, 0.03328559547662735, 0.020509306341409683, -0.00871200580149889, -0.01941165328025818, -0.021972844377160072, 0.005839318037033081, 0.06443522125482559, -0.00291224243119359, 0.026759009808301926, 0.01318172924220562, 0.0014585934113711119, 0.0038121205288916826, 0.018136002123355865, 0.005597043316811323, -0.0558517687022686, -0.014150829054415226, -0.0007070470019243658, 0.044459905475378036, 0.00510260509327054, 0.01561436615884304, 0.018867772072553635, 0.020944412797689438, 0.012934509664773941, -0.061785031110048294, -0.10838090628385544, -0.03035852126777172, -0.039772629737854004, 0.04200749099254608, 0.03109028935432434, -0.036983996629714966, 0.03146606311202049, -0.06285301595926285, -0.0020136006642132998, 0.0834612101316452, 0.005097660701721907, -0.010650204494595528, -0.044776346534490585, -0.0012274434557184577, 0.04896918311715126, -0.017048237845301628, 0.07697417587041855, -0.01182696782052517, -0.04414346441626549, 0.030061857774853706, -0.020212644711136818, -0.0032187942415475845, 0.1070360392332077, -0.05233136564493179, -0.00017104479775298387, -0.027569888159632683, 0.025829464197158813, -0.006679863668978214, 0.010739203542470932, -0.0003127323288936168, -0.0018541441531851888, 0.05877884477376938, 0.031070511788129807, -0.06605697423219681, 0.027945661917328835, -0.07290000468492508, -0.03892219439148903, -0.0181854460388422, 0.027629220858216286, 0.02535480447113514, -0.01620769314467907, 0.02389126643538475, 0.028004994615912437, -0.012014854699373245, 0.04493456706404686, -0.01947098597884178, 0.016573576256632805, -0.012697179801762104, 0.0028108826372772455, 0.005117437802255154, 0.023555047810077667, -0.00005689905083272606, -0.02709522657096386, 0.05593087896704674, 0.01808655820786953, 0.00283066020347178, 0.030239855870604515, -0.0043386975303292274, -0.05684064328670502, -0.024880142882466316, 0.05063049867749214, 0.016316469758749008, 0.04801986366510391, 0.062378354370594025, -0.04869230091571808, -0.06214102357625961, -0.07214845716953278, 0.033958032727241516, 0.00786157138645649, -0.04612121731042862, 0.023001277819275856, -0.03334492817521095, -0.0572361946105957, -0.04465768113732338, -0.07638085633516312, -0.02660078927874565, -0.017829449847340584, 0.014388158917427063, -0.006289257202297449, -0.04631899297237396, -0.054309118539094925, 0.061785031110048294, 0.03467002511024475, 0.004296670202165842, 0.0030605739448219538, 0.019589651376008987, 0.026422791182994843, 0.055733103305101395, -0.012440071441233158, -0.007896182127296925, 0.013804721646010876, -0.020568639039993286, 0.049127403646707535, 0.008173068054020405, -0.017789894714951515, 0.08108790963888168, 0.008637839928269386, 0.009414108470082283, -0.02806432731449604, 0.004274420440196991, -0.012983953580260277, -0.004571083467453718, 0.015327592380344868, 0.04861319065093994, -0.080692358314991, -0.04718920588493347, 0.018205223605036736, -0.017433900386095047, 0.0949321836233139, 0.015535255894064903, -0.08354032039642334, 0.03508535400032997, 0.035520460456609726, -0.08164168149232864, -0.006744140759110451, -0.028321435675024986, -0.021854178979992867, -0.045607004314661026, -0.08148346096277237, 0.029864082112908363, -0.03172317147254944, -0.03463046997785568, -0.026838120073080063, 0.019777538254857063, -0.019283099099993706, -0.05854151397943497, 0.0813252404332161, -0.016959238797426224, -0.00862795114517212, -0.03654889017343521, -0.001302845310419798, 0.0786750465631485, -0.02782699652016163, 0.015495700761675835, 0.014239827170968056, 0.01866999641060829, 0.004640304949134588, 0.03126828745007515, 0.012054409831762314, 0.023456159979104996, -0.04378746822476387, -0.059807274490594864, 0.004704582039266825, -0.004445001948624849, 0.015406702645123005, 0.05608909949660301, 0.01752289943397045, 0.03929796814918518, 0.0747590959072113, -0.015030928887426853, -0.01957976259291172, -0.014348603785037994, 0.01164896972477436, 0.022388173267245293, -0.002796049462631345, 0.04726831614971161, -0.03943641111254692, 0.038585975766181946, -0.03882330656051636, 0.03967374190688133, 0.020944412797689438, 0.0001554390910314396, 0.05419045314192772, 0.03975285217165947, 0.01281584519892931, 0.025789909064769745, -0.03411625325679779, -0.005789874121546745, 0.11494705080986023, 0.059134840965270996, -0.007436354178935289, 0.05612865462899208, -0.006150814238935709, -0.0025438859593123198, 0.013082841411232948, 0.005265769548714161, -0.01822500117123127, -0.031841836869716644, 0.004153282847255468, 0.009280609898269176, -0.01926332153379917, 0.059886384755373, 0.01746356673538685, 0.0026996340602636337, -0.023357272148132324, -0.07820038497447968, 0.026304125785827637, -0.046239882707595825, -0.042442597448825836, -0.025789909064769745, 0.004642777144908905, -0.04200749099254608, -0.049720730632543564, 0.016751574352383614, -0.061785031110048294, 0.07483820617198944, -0.052806027233600616, -0.02507791854441166, 0.025967907160520554, 0.06819295138120651, 0.042165711522102356, 0.034274473786354065, 0.04616077244281769, 0.002033378230407834, -0.01565392129123211, -0.012163186445832253, -0.0009184194495901465, -0.00538937933743, -0.03773554414510727, 0.010511761531233788, -0.05359712988138199, -0.03969351947307587, -0.02371326833963394, 0.0035377072636038065, 0.00025463581550866365, 0.02430659532546997, -0.00453152833506465, -0.022763947024941444, -0.015841808170080185, -0.02236839570105076, -0.01836344413459301, 0.0017775062005966902, -0.006338701117783785, 0.03884308412671089, -0.046793654561042786, -0.05620776489377022, -0.023634158074855804, 0.009082834236323833, -0.01721634715795517, 0.019431430846452713, 0.032988931983709335, -0.01825466752052307, 0.05498155578970909, 0.04580477997660637, 0.0002781216171570122, 0.008267010562121868, 0.005186659283936024, -0.03401736542582512, -0.021656405180692673, 0.09010646492242813, -0.0012459849240258336, -0.03255382925271988, 0.003626706078648567, 0.020529083907604218, -0.008558729663491249, -0.010343652218580246, 0.014111273922026157, -0.019421542063355446, 0.010551316663622856, -0.02027197740972042, -0.0363115593791008, -0.012212629429996014, 0.0363115593791008, -0.0376959890127182, 0.005404212512075901, -0.029547642916440964, 0.0027663831133395433, 0.014091496355831623, -0.04283814877271652, 0.03751799091696739, 0.014220049604773521, -0.05438822880387306, 0.0306354071944952, -0.027530333027243614, -0.022091509774327278, 0.01760200969874859, -0.018630441278219223, 0.01735479012131691, 0.012647735886275768, 0.06957738101482391, -0.020291754975914955, 0.13195572793483734, -0.01840299926698208, -0.021794846281409264, -0.005957983434200287, 0.03534246236085892, 0.006576031446456909, 0.0020655165426433086, 0.01676146313548088, -0.0780421644449234, 0.03215827792882919, 0.01735479012131691, 0.03255382925271988, -0.05755263566970825, 0.036014895886182785, 0.04169104993343353, -0.03664777800440788, 0.08100879937410355, 0.055456217378377914, -0.03259338438510895, 0.025552580133080482, -0.03215827792882919, -0.02925097942352295, -0.018165668472647667, -0.00036742957308888435, 0.08710027486085892, 0.021715737879276276, 0.040464844554662704, -0.030101412907242775, -0.047386981546878815, -0.007406688295304775, -0.03724110499024391, 0.05767130106687546, -0.0585019588470459, 0.03678622096776962, 0.0008096429519355297, -0.05964905396103859, 0.01161930337548256, -0.030655184760689735, 0.02260572649538517, 0.0044425297528505325, -0.03995062783360481, 0.001886282698251307, 0.020509306341409683, -0.01135230716317892, -0.00467738788574934, -0.03467002511024475, -0.031663838773965836, 0.039733074605464935, -0.016296692192554474, 0.048534080386161804, 0.00046260899398475885, 0.044815901666879654, 0.0336020365357399, -0.01297406479716301, -0.01318172924220562, -0.02879609540104866, -0.01833377778530121, 0.05047227814793587, -0.008998779579997063, 0.04319414496421814, 0.009641549549996853, 0.028736762702465057, 0.02687767520546913, -0.008969113230705261, 0.030655184760689735, 0.022131064906716347, 0.051421597599983215, -0.02796543948352337, 0.015634143725037575, -0.06083570793271065, -0.036845553666353226, 0.00432139215990901, -0.004417807795107365, 0.041888825595378876, -0.001708284835331142, 0.06229924410581589, 0.030299188569188118, -0.06241790950298309, -0.00425217067822814, 0.019312765449285507, 0.0021495711989700794, 0.03728066012263298, 0.0031916003208607435, -0.06759962439537048, 0.11613370478153229, -0.008084069006145, 0.006135981064289808, 0.005854151211678982, 0.007297911681234837, -0.0021594599820673466, 0.014388158917427063, -0.009972823783755302, -0.011124865151941776, -0.006907305214554071, 0.049087848514318466, 0.00928555428981781, -0.0068084173835814, -0.019461097195744514, -0.020786192268133163, -0.0680742859840393, -0.016979016363620758, 0.0793079286813736, 0.024721922352910042, -0.0014437602367252111, -0.006200258154422045, -0.026422791182994843, 0.053438909351825714, 0.04469723626971245, 0.020074201747775078, -0.016642797738313675, -0.012885065749287605, -0.020687304437160492, 0.05031405761837959, 0.014892485924065113, 0.002313971985131502, 0.011302863247692585, 0.041058167815208435, 0.025473469868302345, -0.008262066170573235, 0.0921633318066597, 0.05130293592810631, 0.018027225509285927, -0.019352320581674576, -0.01652413234114647, -0.04319414496421814, 0.03247471898794174, -0.11035866290330887, 0.08116701990365982, 0.04177016019821167, -0.03842775523662567, 0.013221284374594688, -0.039278190582990646, -0.005419045686721802, 0.010145877487957478, 0.02590857446193695, -0.03929796814918518, 0.04675409942865372, 0.003391847712919116, 0.000648332410492003, -0.011668747290968895, -0.025394359603524208, -0.029547642916440964, -0.015238593332469463, -0.040286846458911896, -0.04548833891749382, 0.0592535063624382, 0.032672494649887085, 0.02737211249768734, 0.0025092752184718847, -0.01196541078388691, 0.058620624244213104, -0.030516741797327995, -0.05150070786476135, -0.0038145927246659994, 0.05818551778793335, -0.04987895116209984, 0.02796543948352337, 0.007886293344199657, 0.036014895886182785, -0.020944412797689438, -0.028894983232021332, 0.03182205930352211, -0.043035924434661865, 0.006427699699997902, 0.021517962217330933, -0.0036019841209053993, -0.03532268479466438, 0.0067787510342895985, 0.06289257109165192, -0.01752289943397045, -0.017681119963526726, -0.053953126072883606, -0.01759212091565132, -0.018165668472647667, -0.04540922865271568, -0.0006022878224030137, -0.016820795834064484, -0.032712049782276154, 0.0030333800241351128, -0.015555033460259438, 0.013784944079816341, -0.0033473484218120575, -0.001967865042388439, 0.03154517337679863, 0.04525100812315941, -0.05355757474899292, -0.040187958627939224, 0.03154517337679863, -0.045646559447050095, -0.02559213526546955, -0.0289345383644104, 0.016435135155916214, 0.041058167815208435, 0.03328559547662735, 0.007772572338581085, -0.04264037311077118, -0.047663867473602295, -0.05897662043571472, -0.018205223605036736, -0.06368367373943329, -0.04584433510899544, -0.025552580133080482, 0.035836897790431976, 0.03126828745007515, -0.02062797173857689, 0.040425289422273636, 0.02695678547024727, 0.02741166763007641, -0.014951818622648716, -0.05593087896704674, -0.00014516404189635068, 0.03593578562140465, 0.01100619975477457, -0.0437479130923748, -0.0026551345363259315, 0.009033390320837498, -0.009191610850393772, -0.05059094354510307, 0.03443269431591034, 0.02654145658016205, -0.009948101826012135, 0.014279382303357124, -0.049087848514318466, 0.054032232612371445, -0.05067005380988121, -0.037161994725465775, 0.0036019841209053993, 0.020825747400522232, 0.001605688827112317, 0.026442568749189377, -0.0012453668750822544, 0.03613356128334999, 0.029092758893966675, 0.004548833705484867, 0.076657734811306, 0.010768869891762733, -0.03099140152335167, -0.06332767754793167, -0.007441298570483923, 0.0032212664373219013, -0.02090485766530037, -0.003772565396502614, 0.03269227221608162, 0.015297926031053066, 0.034373361617326736, 0.015466035343706608, -0.002924603410065174, -0.0698542669415474, -0.029132314026355743, 0.03348337113857269, 0.02594812959432602, 0.012983953580260277, 0.026660121977329254, -0.06293212622404099, 0.01937209814786911, -0.02323860675096512, 0.03737954795360565, 0.006600753404200077, -0.007688518147915602, 0.017542677000164986, -0.04837585985660553, -0.02462303452193737, 0.04347103089094162, -0.00022496949532069266, 0.02660078927874565, -0.058304183185100555, -0.04687276482582092, 0.026126127690076828, -0.025473469868302345, 0.008820782415568829, -0.0029171868227422237, -0.06526587903499603, -0.014022274874150753, 0.0029221312142908573, -0.05063049867749214, 0.04540922865271568, 0.027154559269547462, -0.05213358998298645, -0.031663838773965836, 0.05248958617448807, 0.041611939668655396, 0.014546379446983337, 0.08741671591997147, -0.011975299566984177, 0.017473455518484116, 0.038447532802820206, -0.010313985869288445, -0.0008566146134398878, -0.05549577251076698, -0.07725106179714203, -0.002416567876935005, -0.043075479567050934, -0.015693476423621178, 0.005161937326192856, 0.05165892839431763, -0.04845497012138367, -0.030576074495911598, -0.014140940271317959, -0.04058350995182991, 0.009646493941545486, 0.003339931834489107, 0.018907327204942703, -0.013537724502384663, 0.012341183610260487, -0.032988931983709335, 0.02145862951874733, 0.003451180411502719, -0.0026353569701313972, -0.001496912445873022, 0.04208660125732422, -0.015594588592648506, -0.028182992711663246, -0.020746637135744095, -0.01822500117123127, -0.032988931983709335, 0.03112984448671341, -0.00538937933743, 0.003095184685662389, 0.025888796895742416, -0.028815872967243195, -0.04434124007821083, -0.02173551544547081, -0.03919908031821251, 0.0404055118560791, -0.01794811524450779, -0.03461069241166115, 0.012370849959552288, 0.006669974885880947, 0.0451323427259922, -0.06831161677837372, 0.047110095620155334, -0.030615629628300667, 0.021201521158218384, -0.034828245639801025, 0.04141416400671005, 0.058897510170936584, -0.01325095072388649, 0.003092712489888072, -0.0042447540909051895, 0.02966630645096302, -0.019639095291495323, -0.02938942238688469, -0.0067787510342895985, 0.03852664306759834, 0.06142903491854668, -0.041058167815208435, 0.018244778737425804, -0.01951054111123085, -0.016642797738313675, 0.013122396543622017, 0.04030662402510643, -0.04240304231643677, 0.03126828745007515, 0.020113756880164146, -0.03449202701449394, -0.001072313403710723, -0.018037114292383194, -0.03292960301041603, -0.012351072393357754, -0.010042045265436172, 0.04283814877271652, -0.02567124553024769, -0.025196583941578865, -0.004019784741103649, 0.008291732519865036, 0.004501861985772848, 0.014872708357870579, -0.03289004787802696, -0.06637341529130936, -0.00468480447307229, 0.04920651391148567, -0.007134746760129929, -0.05419045314192772, -0.030576074495911598, 0.019975313916802406, 0.014754043892025948, -0.030101412907242775, -0.0003767003072425723, 0.015772586688399315, 0.05937216803431511, -0.0080692358314991, -0.0558517687022686, -0.053715795278549194, -0.011381973512470722, -0.008351065218448639, -0.055456217378377914, -0.015119927935302258, -0.023080386221408844, -0.02618546038866043, -0.05233136564493179, 0.05735486000776291, -0.03012119047343731, 0.02998274751007557, -0.07725106179714203, 0.02430659532546997, 0.03134739771485329, 0.002017308957874775, -0.05213358998298645, -0.028459876775741577, -0.03136717528104782, -0.012558736838400364, 0.017127348110079765, 0.025295471772551537, 0.007174301892518997, -0.04086039215326309, 0.045013677328825, 0.026264570653438568, 0.04952295497059822, -0.028084104880690575, 0.01161930337548256, -0.0019011158728972077, -0.012163186445832253, 0.006536476314067841, 0.022585948929190636, -0.013072952628135681, 0.01756245456635952, -0.0825909972190857, 0.025869019329547882, -0.04200749099254608, 0.038625530898571014, 0.029646528884768486, 0.01229173969477415, -0.017780007794499397, -0.008341176435351372, 0.0075055756606161594, -0.03546112775802612, 0.00538937933743, -0.017305346205830574, -0.025414137169718742, 0.036014895886182785, -0.018491998314857483, 0.08037591725587845, -0.019312765449285507, -0.01992587000131607, -0.009053167887032032, -0.0036810943856835365, 0.00871200580149889, 0.021478407084941864, -0.017048237845301628, -0.015485811978578568, -0.08907803148031235, 0.031189177185297012, -0.01189618930220604, -0.029745416715741158, 0.06107303872704506, 0.04643765836954117, -0.05391357094049454, 0.02361438050866127, 0.04529056325554848, -0.001689743367023766, -0.03352292627096176, 0.03049696423113346, 0.044499460607767105, 0.010739203542470932, 0.06170592084527016, -0.004800997208803892, 0.01783933863043785, -0.07574797421693802, -0.014843042008578777, -0.027293002232909203, 0.005898650735616684, -0.030694739893078804, 0.03546112775802612, 0.07467998564243317, -0.0026798564940690994, 0.06360456347465515 ]
31,003
networkx.algorithms.tree.mst
partition_spanning_tree
Find a spanning tree while respecting a partition of edges. Edges can be flagged as either `INCLUDED` which are required to be in the returned tree, `EXCLUDED`, which cannot be in the returned tree and `OPEN`. This is used in the SpanningTreeIterator to create new partitions following the algorithm of Sörensen and Janssens [1]_. Parameters ---------- G : undirected graph An undirected graph. minimum : bool (default: True) Determines whether the returned tree is the minimum spanning tree of the partition of the maximum one. weight : str Data key to use for edge weights. partition : str The key for the edge attribute containing the partition data on the graph. Edges can be included, excluded or open using the `EdgePartition` enum. ignore_nan : bool (default: False) If a NaN is found as an edge weight normally an exception is raised. If `ignore_nan is True` then that edge is ignored instead. Returns ------- G : NetworkX Graph A minimum spanning tree using all of the included edges in the graph and none of the excluded edges. References ---------- .. [1] G.K. Janssens, K. Sörensen, An algorithm to generate all spanning trees in order of increasing cost, Pesquisa Operacional, 2005-08, Vol. 25 (2), p. 219-229, https://www.scielo.br/j/pope/a/XHswBwRwJyrfL88dmMwYNWp/?lang=en
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None): """ Sample a random spanning tree using the edges weights of `G`. This function supports two different methods for determining the probability of the graph. If ``multiplicative=True``, the probability is based on the product of edge weights, and if ``multiplicative=False`` it is based on the sum of the edge weight. However, since it is easier to determine the total weight of all spanning trees for the multiplicative version, that is significantly faster and should be used if possible. Additionally, setting `weight` to `None` will cause a spanning tree to be selected with uniform probability. The function uses algorithm A8 in [1]_ . Parameters ---------- G : nx.Graph An undirected version of the original graph. weight : string The edge key for the edge attribute holding edge weight. multiplicative : bool, default=True If `True`, the probability of each tree is the product of its edge weight over the sum of the product of all the spanning trees in the graph. If `False`, the probability is the sum of its edge weight over the sum of the sum of weights for all spanning trees in the graph. seed : integer, random_state, or None (default) Indicator of random number generation state. See :ref:`Randomness<randomness>`. Returns ------- nx.Graph A spanning tree using the distribution defined by the weight of the tree. References ---------- .. [1] V. Kulkarni, Generating random combinatorial objects, Journal of Algorithms, 11 (1990), pp. 185–207 """ def find_node(merged_nodes, node): """ We can think of clusters of contracted nodes as having one representative in the graph. Each node which is not in merged_nodes is still its own representative. Since a representative can be later contracted, we need to recursively search though the dict to find the final representative, but once we know it we can use path compression to speed up the access of the representative for next time. This cannot be replaced by the standard NetworkX union_find since that data structure will merge nodes with less representing nodes into the one with more representing nodes but this function requires we merge them using the order that contract_edges contracts using. Parameters ---------- merged_nodes : dict The dict storing the mapping from node to representative node The node whose representative we seek Returns ------- The representative of the `node` """ if node not in merged_nodes: return node else: rep = find_node(merged_nodes, merged_nodes[node]) merged_nodes[node] = rep return rep def prepare_graph(): """ For the graph `G`, remove all edges not in the set `V` and then contract all edges in the set `U`. Returns ------- A copy of `G` which has had all edges not in `V` removed and all edges in `U` contracted. """ # The result is a MultiGraph version of G so that parallel edges are # allowed during edge contraction result = nx.MultiGraph(incoming_graph_data=G) # Remove all edges not in V edges_to_remove = set(result.edges()).difference(V) result.remove_edges_from(edges_to_remove) # Contract all edges in U # # Imagine that you have two edges to contract and they share an # endpoint like this: # [0] ----- [1] ----- [2] # If we contract (0, 1) first, the contraction function will always # delete the second node it is passed so the resulting graph would be # [0] ----- [2] # and edge (1, 2) no longer exists but (0, 2) would need to be contracted # in its place now. That is why I use the below dict as a merge-find # data structure with path compression to track how the nodes are merged. merged_nodes = {} for u, v in U: u_rep = find_node(merged_nodes, u) v_rep = find_node(merged_nodes, v) # We cannot contract a node with itself if u_rep == v_rep: continue nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False) merged_nodes[v_rep] = u_rep return merged_nodes, result def spanning_tree_total_weight(G, weight): """ Find the sum of weights of the spanning trees of `G` using the appropriate `method`. This is easy if the chosen method is 'multiplicative', since we can use Kirchhoff's Tree Matrix Theorem directly. However, with the 'additive' method, this process is slightly more complex and less computationally efficient as we have to find the number of spanning trees which contain each possible edge in the graph. Parameters ---------- G : NetworkX Graph The graph to find the total weight of all spanning trees on. weight : string The key for the weight edge attribute of the graph. Returns ------- float The sum of either the multiplicative or additive weight for all spanning trees in the graph. """ if multiplicative: return nx.total_spanning_tree_weight(G, weight) else: # There are two cases for the total spanning tree additive weight. # 1. There is one edge in the graph. Then the only spanning tree is # that edge itself, which will have a total weight of that edge # itself. if G.number_of_edges() == 1: return G.edges(data=weight).__iter__().__next__()[2] # 2. There are no edges or two or more edges in the graph. Then, we find the # total weight of the spanning trees using the formula in the # reference paper: take the weight of each edge and multiply it by # the number of spanning trees which include that edge. This # can be accomplished by contracting the edge and finding the # multiplicative total spanning tree weight if the weight of each edge # is assumed to be 1, which is conveniently built into networkx already, # by calling total_spanning_tree_weight with weight=None. # Note that with no edges the returned value is just zero. else: total = 0 for u, v, w in G.edges(data=weight): total += w * nx.total_spanning_tree_weight( nx.contracted_edge(G, edge=(u, v), self_loops=False), None ) return total if G.number_of_nodes() < 2: # no edges in the spanning tree return nx.empty_graph(G.nodes) U = set() st_cached_value = 0 V = set(G.edges()) shuffled_edges = list(G.edges()) seed.shuffle(shuffled_edges) for u, v in shuffled_edges: e_weight = G[u][v][weight] if weight is not None else 1 node_map, prepared_G = prepare_graph() G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight) # Add the edge to U so that we can compute the total tree weight # assuming we include that edge # Now, if (u, v) cannot exist in G because it is fully contracted out # of existence, then it by definition cannot influence G_e's Kirchhoff # value. But, we also cannot pick it. rep_edge = (find_node(node_map, u), find_node(node_map, v)) # Check to see if the 'representative edge' for the current edge is # in prepared_G. If so, then we can pick it. if rep_edge in prepared_G.edges: prepared_G_e = nx.contracted_edge( prepa
(G, minimum=True, weight='weight', partition='partition', ignore_nan=False, *, backend=None, **backend_kwargs)
[ -0.00048693668213672936, -0.029452817514538765, -0.021688567474484444, 0.002916941186413169, 0.009710660204291344, 0.0067268782295286655, -0.04868163540959358, -0.053986139595508575, 0.07297967374324799, -0.023292751982808113, -0.02513221651315689, 0.03413703665137291, 0.011464567855000496, 0.04187989607453346, -0.056381721049547195, 0.036211781203746796, 0.03056505136191845, 0.0033206609077751637, 0.03638289123773575, 0.032212015241384506, -0.04273546114563942, -0.0822625532746315, 0.019218124449253082, 0.05963286757469177, -0.04134516790509224, -0.03340980410575867, -0.019314374774694443, -0.03768762946128845, -0.019613822922110558, 0.006496944930404425, -0.003812610637396574, -0.05946175381541252, -0.08333200961351395, -0.038008466362953186, 0.014127513393759727, 0.001969135832041502, 0.029859211295843124, 0.050820548087358475, -0.06600682437419891, -0.05869174376130104, -0.020084382966160774, -0.03554871678352356, 0.02093994803726673, -0.02513221651315689, 0.022672466933727264, 0.023100249469280243, 0.06964297592639923, 0.06532236933708191, -0.03914209082722664, -0.005114673171192408, 0.032618407160043716, -0.024811379611492157, -0.022864969447255135, 0.02119661681354046, -0.012747915461659431, 0.006486250553280115, 0.014523211866617203, -0.006657363381236792, 0.07169632613658905, -0.0419226735830307, 0.04504548758268356, 0.006299095693975687, -0.00839522946625948, -0.00008413611067226157, -0.07901141047477722, -0.013325421139597893, -0.0567239448428154, -0.036211781203746796, -0.018191445618867874, 0.025602776557207108, 0.0015400166157633066, -0.020501472055912018, 0.048211075365543365, 0.00673222541809082, 0.017357271164655685, 0.024126926437020302, 0.005237660836428404, -0.04957997798919678, -0.02014855109155178, -0.013079446740448475, 0.07037020474672318, -0.024832768365740776, 0.036211781203746796, -0.026073336601257324, 0.049194976687431335, -0.012640969827771187, 0.029260315001010895, 0.046243276447057724, 0.018148668110370636, -0.08363145589828491, -0.02575249969959259, -0.0032163888681679964, 0.04147350415587425, 0.05124833062291145, 0.04645716771483421, 0.018362559378147125, -0.0112720662727952, -0.07058409601449966, -0.025367496535182, -0.034650374203920364, -0.013956400565803051, 0.06818851083517075, -0.028233638033270836, 0.014491128735244274, -0.011368317529559135, -0.03441509231925011, -0.03897097706794739, 0.038607362657785416, -0.006523681338876486, -0.049622759222984314, -0.05090610310435295, 0.018533673137426376, 0.02198801562190056, 0.004737690091133118, 0.010250736027956009, 0.011186509393155575, -0.024854157119989395, 0.006935421843081713, 0.00743806641548872, 0.04359102621674538, 0.03415842354297638, 0.020608417689800262, -0.021720651537179947, 0.008106476627290249, -0.00016518081247340888, -0.03169867396354675, 0.05026443302631378, -0.0026281881146132946, 0.013400283642113209, -0.013143613934516907, 0.044232700020074844, 0.02917475998401642, 0.0206511951982975, 0.04868163540959358, 0.01885450817644596, -0.009502116590738297, -0.08221977949142456, -0.0014063345734030008, 0.05364391207695007, 0.030864499509334564, 0.004531819839030504, -0.10078553110361099, 0.044232700020074844, 0.014694325625896454, 0.04714161902666092, -0.012908333912491798, 0.006053120829164982, -0.006053120829164982, 0.007924668490886688, 0.0037564642261713743, 0.02472582273185253, -0.028832532465457916, 0.025431662797927856, -0.0008642541361041367, 0.007523622829467058, -0.015453639440238476, 0.018437420949339867, 0.0029196147806942463, -0.054200030863285065, 0.0028180165681988, -0.012683748267591, -0.0031442006584256887, 0.02175273559987545, 0.027271127328276634, -0.002356813522055745, 0.014223764650523663, 0.023613588884472847, 0.028019746765494347, -0.04331296682357788, -0.03234034776687622, -0.01609531231224537, -0.046029385179281235, -0.10206887871026993, 0.031869787722826004, 0.019335763528943062, 0.015036551281809807, 0.024854157119989395, 0.01076942216604948, -0.01297250110656023, -0.006085204426199198, 0.01396709494292736, -0.043612416833639145, 0.032040901482105255, -0.007550359237939119, -0.021624399349093437, 0.03259702026844025, 0.06010342761874199, -0.02026619017124176, 0.01947479322552681, -0.010437890887260437, -0.021699262782931328, -0.0702846497297287, 0.01700435020029545, 0.05770784616470337, 0.04615772143006325, 0.024854157119989395, 0.00471362704411149, 0.0014036609791219234, -0.04992220550775528, 0.05372946709394455, 0.002422317862510681, -0.02374192327260971, 0.04979386925697327, 0.0021536170970648527, 0.01595628261566162, -0.00838453508913517, -0.01007427554577589, -0.005668116733431816, 0.02295052632689476, -0.002172332489863038, -0.038008466362953186, -0.031484782695770264, 0.05552615597844124, 0.05317335203289986, -0.03392314538359642, -0.02635139599442482, -0.06472347676753998, 0.012298744171857834, 0.025217771530151367, -0.041430726647377014, -0.03708873316645622, -0.0005738299805670977, 0.019528266042470932, -0.008363145403563976, 0.062370672821998596, -0.05565448850393295, 0.012726525776088238, -0.004531819839030504, 0.03619039058685303, -0.034864265471696854, 0.09282878041267395, -0.02187037467956543, 0.04778329282999039, -0.022287461906671524, -0.025453051552176476, -0.08303256332874298, -0.039676815271377563, -0.030436716973781586, 0.02295052632689476, 0.01744282804429531, -0.03206229209899902, -0.0757174864411354, -0.03114255890250206, 0.012726525776088238, 0.00005969736594124697, -0.0077375140972435474, 0.01109025813639164, 0.015592668205499649, 0.03610483556985855, 0.0037217068020254374, -0.08046586811542511, -0.064980149269104, -0.006881949491798878, -0.03550593927502632, 0.006710836198180914, -0.029046423733234406, -0.007662652060389519, 0.022629689425230026, -0.020041605457663536, 0.012448467314243317, 0.0029303093906491995, -0.05133388563990593, -0.04675661399960518, 0.04038265720009804, -0.01897214911878109, -0.009208016097545624, 0.028832532465457916, 0.024084148928523064, -0.04149489104747772, -0.021410508081316948, 0.07965308427810669, 0.009940593503415585, 0.003735075006261468, -0.007389940787106752, -0.03018004819750786, -0.026693621650338173, -0.030629219487309456, 0.08551370352506638, 0.0034142383374273777, -0.02675778791308403, -0.0447460375726223, 0.017592551186680794, -0.0005323885707184672, 0.0307361651211977, -0.05287390574812889, 0.038842640817165375, -0.02874697744846344, -0.0463288314640522, 0.024233872070908546, -0.02476860024034977, 0.011860267259180546, -0.05308779329061508, -0.0018581798067316413, 0.020426608622074127, 0.03398730978369713, 0.017432132735848427, -0.0032511462923139334, -0.04448936879634857, 0.008234811015427113, 0.05111999437212944, 0.05270279198884964, -0.017592551186680794, 0.04530215635895729, -0.015068634413182735, 0.012929722666740417, 0.06771795451641083, 0.0535583570599556, -0.037281233817338943, 0.0021188596729189157, 0.015132802538573742, -0.09291433542966843, 0.008619815111160278, 0.033880364149808884, 0.021474676206707954, 0.007732166908681393, -0.08649759739637375, -0.014544601552188396, -0.06053121015429497, 0.06356846541166306, 0.01147526316344738, -0.032040901482105255, 0.0498366504907608, 0.006716183386743069, 0.02893947809934616, -0.06331179291009903, 0.01053948886692524, 0.01849089376628399, 0.08089365065097809, 0.020298274233937263, -0.014416266232728958, -0.08230533450841904, 0.0027645437512546778, 0.04697050526738167, 0.06194289028644562, -0.06523681432008743, 0.06258456408977509, 0.09188766032457352, -0.009218710474669933, 0.0036976439878344536, -0.05886285752058029, 0.06806018203496933, 0.05154777690768242, -0.021089671179652214, 0.027228349819779396, -0.006111940834671259, 0.01317569799721241, 0.032212015241384506, 0.013753203675150871, 0.0060691628605127335, 0.023014692589640617, 0.010416501201689243, 0.07208133488893509, 0.010138442739844322, 0.01397778932005167, 0.0031067696399986744, 0.0026723032351583242, 0.010673170909285545, -0.023827480152249336, 0.011956517584621906, 0.022458575665950775, -0.03116394765675068, -0.0026241776067763567, 0.01997743733227253, 0.020683279260993004, 0.01605253480374813, -0.011325539089739323, -0.01767810806632042, 0.06245622783899307, 0.025816667824983597, -0.09385545551776886, 0.0297736544162035, -0.11935129016637802, -0.0416446179151535, 0.0746908038854599, -0.003219062462449074, 0.049622759222984314, -0.056381721049547195, -0.004475673194974661, 0.0030158658046275377, 0.007534317206591368, 0.020544249564409256, 0.03674650937318802, 0.0017619287827983499, 0.053045015782117844, 0.04846774414181709, -0.05432836338877678, 0.08525703102350235, -0.0073257735930383205, 0.018907980993390083, -0.0182770024985075, -0.029645320028066635, -0.006058468017727137, 0.052617233246564865, 0.030051713809370995, -0.0683596283197403, 0.01700435020029545, 0.08204866200685501, 0.01536808256059885, -0.05886285752058029, 0.020405219867825508, 0.008523563854396343, -0.022501353174448013, -0.020704668015241623, 0.008277589455246925, 0.0013889559777453542, -0.06172899901866913, 0.013410978019237518, 0.02043730393052101, 0.04517382010817528, -0.009956635534763336, -0.06758961826562881, -0.00033971937955357134, 0.005029116757214069, 0.037024565041065216, -0.029196148738265038, -0.04359102621674538, 0.02795557864010334, 0.03409425541758537, 0.06823129206895828, -0.019603127613663673, 0.07195299863815308, -0.02179551310837269, 0.040810439735651016, 0.007518275640904903, 0.05313057452440262, -0.017089907079935074, -0.009566283784806728, -0.04166600480675697, -0.03569843992590904, 0.06322623789310455, -0.007635915651917458, -0.074348583817482, 0.011133036576211452, -0.02045869268476963, 0.019966743886470795, -0.016298510134220123, -0.004291192162781954, 0.00598895363509655, 0.013988484628498554, 0.007732166908681393, -0.009705313481390476, 0.021806208416819572, -0.024255262687802315, -0.043398525565862656, 0.008566342294216156, -0.04970831423997879, -0.018341170623898506, 0.031655896455049515, -0.030650608241558075, -0.042222123593091965, 0.07490469515323639, -0.019838407635688782, 0.011518040671944618, -0.00021389119501691312, -0.08008086681365967, 0.03567705303430557, 0.004943560343235731, 0.002489158883690834, -0.07293689996004105, 0.025838056579232216, 0.05308779329061508, -0.01176401600241661, -0.003307292703539133, 0.04709884151816368, -0.030436716973781586, -0.022244684398174286, 0.06788906455039978, -0.03077894262969494, -0.015485722571611404, -0.0021830270998179913, 0.03788013011217117, -0.024041371420025826, -0.10129886865615845, -0.03315313532948494, 0.012801388278603554, 0.0028447529766708612, -0.06438124924898148, -0.03736679255962372, -0.05308779329061508, -0.04198684170842171, 0.012608885765075684, -0.019517572596669197, 0.05497003719210625, 0.013325421139597893, -0.017186157405376434, -0.01962451823055744, 0.032490074634552, 0.012245271354913712, 0.02136773057281971, -0.042029619216918945, -0.04928053170442581, -0.055440597236156464, 0.0297736544162035, 0.018031027168035507, -0.033452581614255905, 0.05094888433814049, -0.012063463218510151, -0.03139922767877579, 0.04846774414181709, -0.05313057452440262, 0.021806208416819572, 0.00887648481875658, -0.01509002409875393, 0.01703643426299095, 0.050820548087358475, 0.01727171428501606, -0.021036198362708092, 0.019271597266197205, 0.014213070273399353, 0.019421320408582687, 0.05274556949734688, -0.00404789112508297, 0.0343509279191494, 0.05492725968360901, 0.05257445573806763, 0.0024597488809376955, 0.020255496725440025, 0.015592668205499649, 0.02838336117565632, -0.05171889066696167, 0.0007018304895609617, -0.0017686128849163651, 0.016319898888468742, 0.035826776176691055, 0.0006019031861796975, 0.04487437382340431, -0.018555061891674995, 0.01509002409875393, 0.01880103535950184, -0.020907863974571228, -0.012801388278603554, 0.050435543060302734, -0.03676789626479149, 0.05873452126979828, 0.03169867396354675, -0.03514232486486435, 0.029495596885681152, -0.022287461906671524, -0.026864733546972275, -0.02177412435412407, 0.008667941205203533, 0.00419761473312974, 0.023014692589640617, 0.03574121743440628, 0.03736679255962372, 0.05591115728020668, 0.04410436376929283, -0.02233024127781391, -0.0225441325455904, -0.046842172741889954, -0.018383948132395744, 0.023913035169243813, 0.030800333246588707, 0.01348583959043026, 0.11173675954341888, -0.07242356240749359, -0.019923964515328407, 0.018640616908669472, 0.002220457885414362, 0.014138207770884037, -0.047612179070711136, -0.04389047250151634, -0.01397778932005167, -0.020212717354297638, 0.046842172741889954, -0.02337830699980259, -0.03174145519733429, -0.014138207770884037, -0.000864922534674406, 0.011689153499901295, 0.0015159539179876447, 0.03259702026844025, 0.03732401505112648, -0.017956165596842766, -0.05415724962949753, -0.014640852808952332, -0.05728006362915039, 0.009769480675458908, -0.0075075807981193066, -0.03494982048869133, -0.017432132735848427, -0.029901988804340363, 0.043441303074359894, 0.028490306809544563, 0.041216835379600525, 0.044232700020074844, -0.0409601628780365, 0.0542428083717823, -0.011849571950733662, 0.03298202157020569, 0.004499736241996288, -0.057408396154642105, 0.0718674436211586, -0.00589804956689477, -0.008534259162843227, -0.004817899316549301, -0.03293924406170845, 0.012951112352311611, 0.019036317244172096, -0.05334446579217911, 0.0029998240061104298, 0.012309438548982143, 0.039035145193338394, 0.04692772775888443, -0.023870257660746574, 0.02189176343381405, -0.00088698003673926, -0.02635139599442482, 0.018597839400172234, -0.04314185306429863, -0.0030078450217843056, 0.004646786488592625, -0.01346445083618164, -0.06207122653722763, -0.023207195103168488, 0.009154543280601501, -0.062413450330495834, 0.01227735448628664, -0.012705137021839619, -0.06729017198085785, -0.00005944671283941716, 0.012202492915093899, -0.010705254040658474, -0.017132684588432312, -0.019314374774694443, 0.01348583959043026, 0.03758068382740021, -0.025517219677567482, -0.03210506960749626, 0.01988118700683117, -0.00038767780642956495, -0.06326901912689209, 0.03640428185462952, 0.010026149451732635, 0.004948907531797886, -0.04376213997602463, 0.0397195965051651, 0.011346927843987942, -0.0567239448428154, 0.018533673137426376, -0.010250736027956009, -0.021036198362708092, -0.0073578571900725365, -0.006144024431705475, -0.038821253925561905, -0.013154308311641216, -0.0005210255621932447, 0.005764367990195751, 0.0014825334073975682, 0.02816946990787983, -0.01389223337173462, 0.033217303454875946, 0.019111178815364838, -0.027249738574028015, -0.0002560010179877281, 0.008999472483992577, 0.004521124996244907, -0.01177471037954092, 0.02048008143901825, -0.010181221179664135, 0.004868698306381702, 0.02754918672144413, 0.005312522407621145, 0.04066071659326553, -0.007523622829467058, 0.005304501857608557, 0.017207546159625053, -0.04160183668136597, -0.01196721289306879, 0.027228349819779396, -0.02393442578613758, -0.048981085419654846, 0.0037591378204524517, -0.01897214911878109, -0.07640193402767181, -0.020918559283018112, 0.020308969542384148, 0.024469152092933655, -0.015603362582623959, -0.027057236060500145, 0.03986931964755058, 0.06245622783899307, 0.01368903648108244, -0.03533482551574707, 0.029688097536563873, 0.04466048255562782, -0.07610248774290085, -0.02455470897257328, 0.04168739542365074, -0.03879986330866814, 0.0022258053068071604, -0.07242356240749359, 0.021859681233763695, 0.028832532465457916, -0.0030800332315266132, 0.0006045768386684358, 0.0029356565792113543, 0.004379422403872013, 0.004184246528893709, -0.05325890704989433, 0.030094491317868233, -0.02834058366715908, -0.014929605647921562, -0.020683279260993004, -0.026287227869033813, 0.017635328695178032, -0.08251922577619553, 0.060573987662792206, 0.04016876593232155, -0.026629453524947166, -0.029452817514538765, -0.020308969542384148, -0.013068752363324165, 0.005801798775792122, 0.016640735790133476, 0.019250208511948586, -0.025709722191095352, 0.024447763338685036, -0.05488448217511177, -0.012619581073522568, -0.040232934057712555, -0.001965125324204564, 0.030244214460253716, 0.016373371705412865, -0.027057236060500145, 0.0249183252453804, 0.08880762755870819, -0.08628370612859726, -0.02067258395254612, 0.0009778838139027357, 0.011111647821962833, 0.07481914013624191, 0.01885450817644596, 0.0028714893851429224, 0.0028634683694690466, -0.0036040665581822395, -0.004636091645807028, 0.016940182074904442, -0.0009838994592428207, 0.026009170338511467, -0.015507112257182598, 0.012394994497299194, -0.08837984502315521, -0.027078624814748764, -0.023506643250584602, 0.01707921177148819, -0.0053446064703166485, 0.01276930421590805, 0.02107897773385048, -0.041238222271203995, 0.04607216268777847, 0.008454049937427044, 0.0293244831264019, -0.01389223337173462, 0.04906664043664932, 0.019464099779725075, -0.0041120583191514015, -0.045986607670784, -0.03811541199684143, -0.0741346925497055, -0.029410040006041527, -0.017186157405376434, -0.016319898888468742, 0.0022565522231161594, 0.014811965636909008, 0.0377945750951767, 0.02352803200483322, 0.059803977608680725 ]