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
|
---|---|---|---|---|---|---|
31,004 | networkx.generators.classic | path_graph | Returns the Path graph `P_n` of linearly connected nodes.
.. plot::
>>> nx.draw(nx.path_graph(5))
Parameters
----------
n : int or iterable
If an integer, nodes are 0 to n - 1.
If an iterable of nodes, in the order they appear in the path.
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.
| 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.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
]
|
31,005 | networkx.classes.function | path_weight | Returns total cost associated with specified path and weight
Parameters
----------
G : graph
A NetworkX graph.
path: list
A list of node labels which defines the path to traverse
weight: string
A string indicating which edge attribute to use for path cost
Returns
-------
cost: int or float
An integer or a float representing the total cost with respect to the
specified weight of the specified path
Raises
------
NetworkXNoPath
If the specified edge does not exist.
| def path_weight(G, path, weight):
"""Returns total cost associated with specified path and weight
Parameters
----------
G : graph
A NetworkX graph.
path: list
A list of node labels which defines the path to traverse
weight: string
A string indicating which edge attribute to use for path cost
Returns
-------
cost: int or float
An integer or a float representing the total cost with respect to the
specified weight of the specified path
Raises
------
NetworkXNoPath
If the specified edge does not exist.
"""
multigraph = G.is_multigraph()
cost = 0
if not nx.is_path(G, path):
raise nx.NetworkXNoPath("path does not exist")
for node, nbr in nx.utils.pairwise(path):
if multigraph:
cost += min(v[weight] for v in G._adj[node][nbr].values())
else:
cost += G._adj[node][nbr][weight]
return cost
| (G, path, weight) | [
0.04051385447382927,
0.020184773951768875,
-0.033875785768032074,
0.010931164026260376,
0.005005607381463051,
-0.04866712912917137,
0.004051836207509041,
0.007589582819491625,
0.04700761288404465,
0.013249075971543789,
0.028716852888464928,
0.0049514928832650185,
0.04119930416345596,
0.004753072280436754,
-0.05815523490309715,
0.013212999328970909,
0.035210613161325455,
-0.03501219302415848,
-0.011869152076542377,
0.004766600672155619,
0.018489180132746696,
-0.07958465069532394,
0.043291740119457245,
0.025740547105669975,
-0.010173559188842773,
-0.0007249111658893526,
0.04606962576508522,
0.0060653528198599815,
0.07547193020582199,
-0.054475437849760056,
0.01237422227859497,
-0.04801775515079498,
-0.07103452831506729,
0.01866956241428852,
0.004302116576582193,
0.0577583946287632,
0.00608790060505271,
-0.03524669259786606,
-0.05801093205809593,
-0.0407303124666214,
0.012798120267689228,
0.028410203754901886,
-0.0000210328526009107,
0.0015681982040405273,
0.017298657447099686,
0.023197157308459282,
-0.018849944695830345,
-0.01607205905020237,
0.005059721879661083,
0.010308844968676567,
0.026985183358192444,
-0.005501658655703068,
-0.001431784126907587,
-0.012356183491647243,
0.03279349207878113,
-0.006223187316209078,
0.00621867785230279,
0.024495908990502357,
0.02139333449304104,
-0.026696572080254555,
0.04397719353437424,
-0.040333472192287445,
0.03488592803478241,
0.026029158383607864,
-0.05732547864317894,
-0.04332781583070755,
-0.02622757852077484,
-0.004033797886222601,
-0.030250102281570435,
-0.03340679034590721,
0.015936771407723427,
0.009803774766623974,
0.0000162854867085116,
-0.034994155168533325,
-0.02703929878771305,
0.02458610013127327,
-0.013348286040127277,
0.003219823120161891,
0.029510535299777985,
0.013194961473345757,
0.03526473045349121,
-0.049352582544088364,
0.015422682277858257,
-0.04928043112158775,
0.03885433450341225,
-0.007954857312142849,
0.012193839997053146,
-0.024333564564585686,
-0.027382025495171547,
0.024171222001314163,
-0.036617595702409744,
0.029059579595923424,
0.020329078659415245,
0.021519601345062256,
0.065154068171978,
-0.049063969403505325,
0.0014081088593229651,
-0.04675507918000221,
-0.04080246388912201,
0.04253413528203964,
-0.02348576858639717,
0.009433991275727749,
0.01173386536538601,
-0.03593214228749275,
0.006534346845000982,
-0.03212607651948929,
-0.013375343754887581,
-0.0038669444620609283,
0.019517358392477036,
-0.015648160129785538,
-0.018182530999183655,
-0.00791878066956997,
0.024622175842523575,
-0.03539099544286728,
0.010534322820603848,
0.061871111392974854,
0.029276039451360703,
-0.012311087921261787,
-0.012725967913866043,
0.04992980509996414,
0.0233234241604805,
0.043147433549165726,
-0.0008742901845835149,
0.015729332342743874,
0.030232064425945282,
-0.0020811602007597685,
-0.0006978538003750145,
-0.043291740119457245,
0.014069815166294575,
0.028789006173610687,
0.010435112752020359,
0.008040538989007473,
0.014367446303367615,
0.040333472192287445,
-0.01659516617655754,
0.02806747704744339,
-0.05465582013130188,
0.0029018993955105543,
0.06472115218639374,
0.02822982147336006,
0.03111593797802925,
-0.015675216913223267,
0.025650355964899063,
-0.04260628670454025,
0.0969734936952591,
-0.024910788983106613,
0.00794132798910141,
0.007648207247257233,
-0.007337047718465328,
0.01652301289141178,
-0.0144395986571908,
-0.012157763354480267,
0.04606962576508522,
-0.006692181341350079,
0.04285882040858269,
0.003179237013682723,
-0.03827711194753647,
0.02806747704744339,
0.010976259596645832,
-0.048775359988212585,
0.02050946094095707,
-0.014268235303461552,
0.02296265959739685,
0.003154434496536851,
0.00017291329277213663,
0.05656787380576134,
0.002694459864869714,
0.06154642254114151,
-0.07438963651657104,
0.013312209397554398,
-0.009001074358820915,
-0.07691498845815659,
-0.05270769074559212,
-0.016532033681869507,
0.014466656371951103,
0.03124220483005047,
-0.0035512754693627357,
0.012744005769491196,
0.03910687193274498,
-0.008243468590080738,
0.037519507110118866,
-0.02193448133766651,
-0.006403569597750902,
0.05097602307796478,
0.017208466306328773,
0.021140798926353455,
0.036184679716825485,
0.01517916563898325,
0.0007305481121875346,
0.03230645880103111,
-0.00034892690018750727,
0.005506168119609356,
0.020545538514852524,
0.021465487778186798,
0.00031651448807679117,
0.008685405366122723,
0.02969091758131981,
-0.020166736096143723,
-0.06804018467664719,
0.09271647781133652,
0.034182436764240265,
-0.04971334710717201,
0.017677459865808487,
0.05169755220413208,
0.014430579729378223,
-0.001811714144423604,
0.017181409522891045,
0.022475628182291985,
-0.06403569877147675,
-0.02444179356098175,
-0.030322255566716194,
0.022854430601000786,
0.027724752202630043,
-0.013321229256689548,
-0.008302092552185059,
0.006895111408084631,
-0.043436046689748764,
0.02126706764101982,
0.027003223076462746,
-0.019300900399684906,
-0.0008607615600340068,
0.05465582013130188,
0.04278666898608208,
0.019355015829205513,
0.08066694438457489,
-0.07016869634389877,
0.016468899324536324,
0.011950324289500713,
0.005352843087166548,
-0.011589559726417065,
0.07146744430065155,
-0.012265992350876331,
0.1051989272236824,
-0.0034926512744277716,
-0.010254730470478535,
-0.007174703758209944,
-0.04653862118721008,
0.0020935614593327045,
0.01107546966522932,
-0.011679750867187977,
0.027165565639734268,
-0.036256831139326096,
-0.05754193663597107,
-0.03600429743528366,
-0.039215099066495895,
0.008910883218050003,
0.026606380939483643,
-0.06847310066223145,
0.0020755231380462646,
-0.032558996230363846,
-0.07016869634389877,
0.04123537987470627,
-0.0037902819458395243,
-0.03290172293782234,
-0.052996303886175156,
0.024928826838731766,
-0.036256831139326096,
-0.011679750867187977,
-0.09444814175367355,
0.017208466306328773,
-0.03111593797802925,
0.0053212763741612434,
-0.038998641073703766,
0.015603064559400082,
-0.006854525301605463,
0.029276039451360703,
0.017470020800828934,
-0.0063404361717402935,
-0.08239860832691193,
0.008897353895008564,
0.09978745877742767,
-0.03889041393995285,
0.029492497444152832,
0.002254778053611517,
-0.001337083405815065,
-0.039359405636787415,
-0.0032829567790031433,
0.10281787812709808,
-0.043724656105041504,
-0.03990055248141289,
-0.054619744420051575,
0.02866273932158947,
-0.044843025505542755,
0.0009622265351936221,
-0.07363203167915344,
0.04704368859529495,
0.024261411279439926,
0.01624342054128647,
-0.03131435811519623,
0.023539884015917778,
0.08896452188491821,
-0.04260628670454025,
0.034705545753240585,
0.030701057985424995,
0.03340679034590721,
0.024243373423814774,
0.016513993963599205,
-0.05241908133029938,
0.04109107702970505,
0.03176531195640564,
-0.006953735835850239,
0.014123929664492607,
0.034849848598241806,
-0.04523986577987671,
0.02258385717868805,
0.03073713555932045,
0.04275059327483177,
0.04036954790353775,
-0.018705638125538826,
0.05216654762625694,
-0.029654841870069504,
-0.038024578243494034,
-0.05534127354621887,
0.02911369502544403,
-0.023539884015917778,
-0.0039774286560714245,
0.007688793353736401,
0.036563482135534286,
-0.041451841592788696,
-0.00460200197994709,
-0.022998737171292305,
0.07871881127357483,
0.022854430601000786,
0.01810135878622532,
-0.10317864269018173,
0.028157668188214302,
0.02200663462281227,
0.03014187328517437,
0.0548001267015934,
-0.0166673194617033,
-0.014872516505420208,
0.06861740350723267,
0.02465825341641903,
-0.014529789797961712,
0.010859011672437191,
0.10491031408309937,
0.051300711929798126,
0.004640333354473114,
-0.07074591517448425,
0.019679702818393707,
0.0392511785030365,
-0.002822982147336006,
0.019012289121747017,
0.07612130790948868,
0.016441842541098595,
-0.028987426310777664,
-0.04704368859529495,
0.06140211597084999,
0.0012705674162134528,
-0.06457684189081192,
0.02213290147483349,
0.04044169932603836,
-0.039575863629579544,
-0.02458610013127327,
-0.020545538514852524,
0.0038173391949385405,
0.0006831977516412735,
-0.04992980509996414,
0.02355792187154293,
0.043291740119457245,
-0.04289489984512329,
0.025199400261044502,
0.015305433422327042,
-0.010191597044467926,
0.018705638125538826,
0.02348576858639717,
0.05371783301234245,
0.029239961877465248,
-0.011553483083844185,
-0.020274965092539787,
0.008748538792133331,
-0.03986447677016258,
-0.03124220483005047,
0.026425998657941818,
-0.008243468590080738,
0.06529837101697922,
0.028770968317985535,
-0.011291928589344025,
0.016225382685661316,
0.04873928427696228,
-0.02229524590075016,
0.0020710136741399765,
0.03052067570388317,
0.026335807517170906,
0.03979232534766197,
-0.008933430537581444,
0.05122855678200722,
-0.02451394684612751,
-0.037447355687618256,
-0.00872599147260189,
-0.036022335290908813,
0.002198408590629697,
-0.005691059865057468,
-0.021790174767374992,
-0.02280031517148018,
0.0028387655038386583,
0.07128706574440002,
0.0025636826176196337,
-0.05512481555342674,
-0.016306554898619652,
-0.018344875425100327,
-0.02835608832538128,
-0.05231085047125816,
0.0036031354684382677,
-0.02969091758131981,
0.03690620884299278,
-0.02067180536687374,
0.06684966385364532,
0.0057587032206356525,
-0.004622295033186674,
-0.041812606155872345,
0.02400887757539749,
-0.017830785363912582,
0.01195934321731329,
-0.05375390872359276,
-0.0248025581240654,
0.018371932208538055,
0.02658834308385849,
0.0129604646936059,
-0.01636067032814026,
0.023593997582793236,
0.013970605097711086,
0.024712366983294487,
-0.03176531195640564,
0.06775157153606415,
-0.05725332349538803,
0.013988642953336239,
-0.034398894757032394,
0.03549922630190849,
0.046250008046627045,
-0.0310979001224041,
-0.0336773656308651,
-0.03531884402036667,
-0.016108134761452675,
0.0062547544948756695,
0.012220896780490875,
0.027165565639734268,
-0.026714609935879707,
0.04837851971387863,
-0.04830636456608772,
-0.0030597338918596506,
0.006899620871990919,
-0.028680777177214622,
-0.01421412080526352,
-0.04094677045941353,
-0.10656983405351639,
-0.020256927236914635,
-0.014574885368347168,
-0.00180494983214885,
-0.06988008320331573,
0.011977381072938442,
-0.060391977429389954,
0.053501375019550323,
0.03163904696702957,
-0.06107742711901665,
0.0303763709962368,
-0.0038263583555817604,
-0.02139333449304104,
-0.030322255566716194,
-0.00908675603568554,
0.019679702818393707,
0.031368471682071686,
0.0711427554488182,
-0.07024084776639938,
-0.03490396589040756,
-0.031729236245155334,
0.01195934321731329,
0.0062998500652611256,
0.05393429100513458,
0.010804896242916584,
0.038926489651203156,
-0.028175706043839455,
-0.10094190388917923,
-0.02682284079492092,
0.0918506383895874,
0.009767699055373669,
-0.029997568577528,
-0.01578344590961933,
-0.014457637444138527,
-0.026985183358192444,
0.01657712832093239,
-0.011815037578344345,
0.056531794369220734,
0.029221924021840096,
0.009343800134956837,
-0.011688769795000553,
-0.025884851813316345,
-0.0006978538003750145,
0.038998641073703766,
-0.04332781583070755,
0.03331660106778145,
0.035300806164741516,
0.035878028720617294,
-0.051589321345090866,
-0.027670636773109436,
0.03190961852669716,
-0.014944668859243393,
0.02546997368335724,
0.029889337718486786,
0.04873928427696228,
-0.0129604646936059,
0.0046538617461919785,
-0.012121686711907387,
0.03126024454832077,
-0.02200663462281227,
0.02682284079492092,
-0.0042209443636238575,
0.013032617047429085,
0.05909322574734688,
0.032180193811655045,
-0.007742907851934433,
0.06353062391281128,
-0.0029244471807032824,
0.08708854764699936,
0.02045534737408161,
-0.014818402007222176,
-0.026678534224629402,
0.04404934495687485,
0.0511203296482563,
-0.01133702415972948,
0.019986353814601898,
0.011003317311406136,
-0.012220896780490875,
-0.009131851606070995,
-0.03486789017915726,
0.02317911945283413,
0.012789101339876652,
-0.08182138949632645,
0.04671900346875191,
0.04397719353437424,
0.014953688718378544,
0.0888923704624176,
-0.005235594697296619,
0.06252048909664154,
0.04390503838658333,
-0.034615352749824524,
0.0109221450984478,
-0.05043487623333931,
-0.11472310870885849,
-0.012599700130522251,
0.0006939079612493515,
-0.03522865101695061,
0.014141968451440334,
0.022349359467625618,
0.07734790444374084,
0.03961194306612015,
0.013456515967845917,
-0.04354427382349968,
-0.05530519783496857,
-0.055449504405260086,
-0.05783054977655411,
-0.017271600663661957,
-0.057289402931928635,
0.016802607104182243,
0.06410785019397736,
-0.0063404361717402935,
-0.0036053902003914118,
-0.016369689255952835,
-0.014529789797961712,
-0.001411491073668003,
-0.04422972723841667,
-0.10786858201026917,
-0.015449739061295986,
-0.008888334967195988,
0.0021070900838822126,
-0.029510535299777985,
-0.006471212953329086,
-0.017993129789829254,
-0.008838729932904243,
-0.026191502809524536,
-0.006516308523714542,
-0.0043043713085353374,
0.044987332075834274,
-0.004234473221004009,
-0.005812817718833685,
-0.006741786375641823,
-0.04228159785270691,
0.004807186778634787,
0.03522865101695061,
-0.011454273015260696,
-0.02615542523562908,
0.02628169395029545,
0.037447355687618256,
0.07720360159873962,
0.001404726761393249,
0.015413663350045681,
0.005727136507630348,
-0.0007271659560501575,
-0.08016186952590942,
0.005934576038271189,
-0.01273498684167862,
-0.08946959674358368,
0.041884757578372955,
0.06331416964530945,
-0.001877102768048644,
-0.025415858253836632,
-0.033064067363739014,
0.02756240777671337,
0.0056098876520991325,
0.03490396589040756,
-0.044337958097457886,
0.008735010400414467,
0.05591849610209465,
0.011598578654229641,
-0.019300900399684906,
0.030232064425945282,
0.005095798522233963,
-0.012897330336272717,
-0.002728281542658806,
-0.03237861394882202,
0.018353894352912903,
0.009551240131258965,
0.0005315639427863061,
0.007409201003611088,
-0.0310979001224041,
0.016559090465307236,
-0.02050946094095707,
0.020527498796582222,
-0.04495125636458397,
-0.02355792187154293,
-0.032577034085989,
-0.05530519783496857,
0.03236057609319687,
-0.0318555049598217,
0.02546997368335724,
0.07900742441415787,
0.011057431809604168,
-0.027760827913880348,
-0.031368471682071686,
0.022205054759979248,
-0.0030371861066669226,
-0.06659712642431259,
0.012013457715511322,
0.032613109797239304,
0.04080246388912201,
-0.06118565797805786,
0.013447496108710766,
-0.0384935699403286,
-0.01285223476588726,
-0.00988494697958231,
-0.05912930145859718,
0.07684283703565598,
-0.03174727410078049,
-0.03311818093061447,
-0.020906303077936172,
0.02079807221889496,
-0.03066498227417469,
-0.06302555650472641,
0.04318350926041603,
-0.004448676947504282,
-0.018182530999183655,
-0.027905134484171867,
0.005037174094468355,
-0.002746319631114602,
0.03638309985399246,
0.049208275973796844,
0.033947937190532684,
-0.05126463621854782,
-0.012040515430271626,
-0.03961194306612015,
-0.029582688584923744,
0.019156593829393387,
0.0503627248108387,
0.002757593523710966,
-0.04422972723841667,
-0.0046764095313847065,
-0.007751927245408297,
-0.07103452831506729,
0.027724752202630043,
-0.10527107864618301,
-0.014268235303461552,
0.041956909000873566,
0.010272769257426262,
0.013222018256783485,
-0.057361554354429245,
0.02363007515668869,
0.03104378469288349,
-0.043291740119457245,
-0.006831977516412735,
-0.03723089396953583,
0.022782277315855026,
0.0005566483596339822,
0.015612083487212658,
-0.011833075433969498,
0.013970605097711086,
0.01664026267826557,
-0.05674825608730316,
0.027436139062047005,
0.03737520053982735,
-0.013194961473345757,
-0.031296320259571075,
-0.07453394681215286,
0.04830636456608772,
0.022692086175084114,
0.02420729771256447,
-0.025019017979502678,
-0.008604233153164387,
0.009866909123957157,
0.0031476703006774187,
-0.0337134413421154,
-0.010453151538968086,
-0.00010710195783758536,
-0.011364081874489784,
-0.03356913477182388,
-0.010615495033562183,
-0.052851997315883636,
-0.07298265397548676,
0.0071656848303973675,
-0.015981867909431458,
0.00646219402551651,
-0.02341361530125141,
-0.044554416090250015,
-0.0012514018453657627,
-0.004748562816530466,
0.041451841592788696,
0.03762773796916008,
-0.018444085493683815,
-0.05801093205809593,
-0.0525633879005909,
-0.004753072280436754,
-0.04101892188191414,
-0.03769988939166069,
0.00008779542258707806,
0.000954898539930582,
-0.03806065395474434,
-0.013212999328970909,
0.03816888481378555,
-0.044987332075834274,
0.006714729126542807,
0.05234692990779877,
-0.04300312697887421,
-0.029799146577715874,
0.004110460635274649,
0.00362793798558414,
0.026678534224629402,
0.03488592803478241,
-0.019282862544059753,
0.0034791226498782635,
0.02770671248435974,
0.04260628670454025,
0.0034791226498782635,
0.04924435168504715,
-0.018651524558663368,
-0.03145866468548775,
-0.029420344159007072,
-0.03524669259786606,
-0.013808260671794415,
0.012202858924865723,
0.011210756376385689,
-0.0259209293872118,
0.010092386975884438,
0.025343704968690872,
0.040838539600372314,
-0.0525994636118412,
0.05844384804368019,
-0.02339557744562626,
-0.024766482412815094,
-0.09213925153017044,
-0.001848918036557734,
-0.011986400000751019,
-0.024604137986898422,
-0.032991912215948105,
-0.02473040670156479,
-0.013546707108616829,
0.01107546966522932,
-0.01962558925151825,
-0.028861159458756447,
0.06977185606956482
]
|
31,008 | networkx.algorithms.distance_measures | periphery | Returns the periphery of the graph G.
The periphery is the set of nodes with eccentricity equal to the diameter.
Parameters
----------
G : NetworkX graph
A graph
e : eccentricity dictionary, optional
A precomputed dictionary of eccentricities.
weight : string, function, or None
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.
If this is None, every edge has weight/distance/cost 1.
Weights stored as floating point values can lead to small round-off
errors in distances. Use integer weights to avoid this.
Weights should be positive, since they are distances.
Returns
-------
p : list
List of nodes in periphery
Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> nx.periphery(G)
[2, 5]
See Also
--------
barycenter
center
| 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, e=None, usebounds=False, weight=None, *, backend=None, **backend_kwargs) | [
0.05050395056605339,
-0.014621064066886902,
0.0027076045516878366,
0.0592062845826149,
0.05628017336130142,
-0.009433864615857601,
-0.03190223127603531,
-0.04947790876030922,
0.10077989101409912,
-0.008683335036039352,
0.03188323229551315,
-0.00023231365776155144,
0.015229088254272938,
-0.004503173753619194,
-0.05973830819129944,
0.04510774090886116,
-0.05692619830369949,
0.0003728893934749067,
-0.005837975535541773,
0.04632378742098808,
0.005244202446192503,
-0.10412401705980301,
-0.0036552660167217255,
0.06061233952641487,
-0.02795007824897766,
0.007453037891536951,
0.020349785685539246,
0.01344301924109459,
-0.0035460118670016527,
0.0005044101271778345,
-0.006602754816412926,
-0.05031394213438034,
-0.023332901298999786,
-0.006512501277029514,
0.022914884611964226,
0.023883922025561333,
0.00700652040541172,
0.007785550784319639,
-0.09257157146930695,
-0.05350606516003609,
-0.011561946012079716,
0.03385930880904198,
0.03209223970770836,
-0.026677029207348824,
0.033251285552978516,
0.01780368760228157,
-0.003686142386868596,
0.01883922703564167,
-0.030306169763207436,
-0.03914150968194008,
0.02584099769592285,
-0.010906420648097992,
-0.04620978236198425,
0.009163103997707367,
0.0018786975415423512,
0.03342229127883911,
0.026126008480787277,
0.05411408841609955,
0.029185127466917038,
-0.07303881645202637,
0.011115428991615772,
-0.08056311309337616,
0.02764606662094593,
0.01684414967894554,
-0.06133436784148216,
0.01502958033233881,
-0.01964675821363926,
-0.005505462642759085,
0.007999308407306671,
0.013813532888889313,
-0.029128124937415123,
-0.0022634624037891626,
0.026050005108118057,
-0.0682506337761879,
0.01872522383928299,
0.026373017579317093,
0.023902922868728638,
-0.013253011740744114,
-0.02692404016852379,
-0.014098544605076313,
0.03178822621703148,
-0.013167507946491241,
0.04620978236198425,
-0.03644340857863426,
0.02534697949886322,
-0.03729844093322754,
0.011039426550269127,
-0.016625642776489258,
0.02599300444126129,
-0.03144621476531029,
-0.0067405104637146,
0.026069005951285362,
0.03378330543637276,
0.03748844563961029,
0.07322882860898972,
0.0010450403206050396,
-0.04989592730998993,
-0.07349483668804169,
0.07072073221206665,
-0.022116854786872864,
-0.013452519662678242,
0.08641533553600311,
-0.018041197210550308,
0.0051919505931437016,
0.028672106564044952,
-0.0460197776556015,
-0.01537159364670515,
-0.034410327672958374,
0.05365807190537453,
-0.031199203804135323,
-0.05631817504763603,
0.021679837256669998,
0.01654013805091381,
-0.013728030025959015,
-0.03610139340162277,
0.04510774090886116,
-0.016872651875019073,
0.015276589430868626,
0.05932028964161873,
0.027665067464113235,
0.013186508789658546,
0.0322442464530468,
-0.01772768422961235,
-0.0009731938480399549,
0.010735414922237396,
0.021812841296195984,
0.009585870429873466,
0.0014523685676977038,
-0.011922960169613361,
0.02198384888470173,
0.04913589730858803,
0.00012105545465601608,
0.025289976969361305,
0.04848987236618996,
0.02738005667924881,
0.00989938247948885,
-0.007685796823352575,
0.03756444901227951,
0.06722459197044373,
0.0207488015294075,
-0.01041240245103836,
-0.023294899612665176,
0.02319989539682865,
0.05118797719478607,
0.03188323229551315,
0.008360322564840317,
0.01742367260158062,
0.03955952823162079,
0.03982553631067276,
-0.0027836074586957693,
0.026373017579317093,
-0.014041542075574398,
0.04389169439673424,
-0.011029926128685474,
0.009623871184885502,
0.017243165522813797,
-0.014279051683843136,
0.013870535418391228,
-0.04043355956673622,
-0.03484734520316124,
-0.07425487041473389,
-0.030724186450242996,
0.04024355486035347,
-0.021755840629339218,
0.01384203415364027,
-0.02722805179655552,
0.04947790876030922,
0.015580601990222931,
-0.06490650773048401,
0.028159087523818016,
-0.04503173753619194,
-0.05160599201917648,
-0.03410631790757179,
-0.03874249756336212,
0.030458176508545876,
0.08527529239654541,
0.026620028540492058,
-0.014564062468707561,
0.012150969356298447,
0.023560909554362297,
-0.014906075783073902,
-0.05863626301288605,
-0.0018549466039985418,
-0.021470829844474792,
0.028938116505742073,
0.04499373584985733,
0.03465733677148819,
-0.004804810509085655,
0.004643304273486137,
0.0004655179800465703,
0.008189315907657146,
-0.04145960137248039,
0.02534697949886322,
0.028957117348909378,
0.029109124094247818,
-0.014972577802836895,
0.03591138496994972,
0.01834520883858204,
-0.03473334014415741,
0.07056872546672821,
0.029014119878411293,
-0.001060478389263153,
0.037393443286418915,
0.03201623633503914,
0.005548214074224234,
0.011200932785868645,
-0.00922485627233982,
-0.029071122407913208,
-0.008236818015575409,
0.009965884499251842,
-0.066768579185009,
0.005068445578217506,
0.00555296428501606,
-0.03492334857583046,
-0.024301938712596893,
0.0299831572920084,
-0.026430020108819008,
0.008897093124687672,
0.013690028339624405,
-0.06399446725845337,
-0.05479811504483223,
-0.010051388293504715,
-0.00982337910681963,
-0.013091505505144596,
0.04461372271180153,
-0.04928790405392647,
0.02240186557173729,
0.00002389935980318114,
0.014193547889590263,
0.007020771037787199,
0.05449410527944565,
0.00319212325848639,
0.07904305309057236,
-0.05122597888112068,
0.014184047468006611,
-0.021109815686941147,
-0.05981430783867836,
0.07250680029392242,
0.052404023706912994,
0.04123159125447273,
-0.03570237755775452,
-0.06281642615795135,
-0.042827654629945755,
0.05890227481722832,
-0.03627239912748337,
-0.03705143183469772,
0.013870535418391228,
0.0018656345782801509,
0.02855810336768627,
0.00901584792882204,
-0.08793539553880692,
-0.06794662028551102,
-0.014108045026659966,
-0.02319989539682865,
0.02757006511092186,
-0.010944422334432602,
-0.08519928902387619,
0.016559138894081116,
-0.018050696700811386,
-0.02726605348289013,
0.014497559517621994,
-0.008374573662877083,
-0.07227879017591476,
-0.0045815519988536835,
-0.04822386056184769,
0.010089389979839325,
0.0004385013016872108,
0.010250896215438843,
-0.025479983538389206,
0.05076995864510536,
0.04491773247718811,
0.010431402362883091,
0.013566523790359497,
-0.009495616890490055,
-0.00493069039657712,
0.02017877995967865,
0.021185817196965218,
0.04461372271180153,
-0.00506369536742568,
0.0363864041864872,
-0.08451526612043381,
0.0016803774051368237,
-0.007638294715434313,
0.02443494275212288,
-0.05692619830369949,
0.017452172935009003,
-0.009248606860637665,
-0.05639417842030525,
0.02312389202415943,
-0.009082350879907608,
0.09249556809663773,
0.007785550784319639,
0.0035887635312974453,
0.0033607548102736473,
0.07379885017871857,
0.010393401607871056,
-0.013965539634227753,
-0.04837586730718613,
0.016369132325053215,
0.06958068907260895,
0.043131664395332336,
-0.0243209395557642,
0.004655179567635059,
-0.04936390742659569,
0.05552014335989952,
0.04081357643008232,
0.034866347908973694,
-0.00006460991426138207,
0.01723366603255272,
0.057838231325149536,
-0.09621971845626831,
0.004897438921034336,
-0.043131664395332336,
0.022876882925629616,
-0.052480027079582214,
-0.02967914566397667,
0.05012393370270729,
-0.02726605348289013,
0.020083775743842125,
0.025593988597393036,
0.015979617834091187,
0.09697974473237991,
0.014459557831287384,
0.03874249756336212,
-0.07117674499750137,
-0.0023477780632674694,
0.01983676664531231,
0.07828301936388016,
0.07934706658124924,
-0.04943990707397461,
-0.042789652943611145,
0.018411710858345032,
-0.010250896215438843,
0.004743058234453201,
-0.04145960137248039,
0.042181629687547684,
0.10952022671699524,
-0.03382130712270737,
-0.02783607505261898,
-0.02948913909494877,
0.027703069150447845,
0.004256164189428091,
-0.005305954720824957,
-0.0026197261177003384,
-0.00513019785284996,
0.019276244565844536,
0.017053158953785896,
-0.027399057522416115,
-0.03484734520316124,
-0.053202055394649506,
-0.012853995896875858,
0.003964027855545282,
-0.031997233629226685,
0.02688603848218918,
-0.016787149012088776,
0.04552575945854187,
-0.011704452335834503,
-0.048109859228134155,
0.02198384888470173,
0.023788917809724808,
-0.10359200090169907,
0.006331994663923979,
-0.028691107407212257,
-0.019390247762203217,
-0.006887766066938639,
0.012141468934714794,
-0.016511637717485428,
0.017214665189385414,
0.018326207995414734,
-0.04096558317542076,
-0.0022670249454677105,
-0.08200716972351074,
-0.07744698971509933,
0.0048095607198774815,
0.010925421491265297,
0.03748844563961029,
-0.03404931351542473,
-0.021090814843773842,
-0.01573260687291622,
-0.006398497149348259,
0.009191605262458324,
0.019323745742440224,
-0.04457572102546692,
0.01114393025636673,
0.04472772777080536,
-0.012663989327847958,
0.04909789562225342,
0.004070907365530729,
0.02416893281042576,
-0.003253875533118844,
-0.041801612824201584,
-0.02757006511092186,
0.06764261424541473,
-0.010896921157836914,
-0.043435677886009216,
0.03480934351682663,
0.061790384352207184,
0.028273090720176697,
-0.04579176753759384,
-0.014193547889590263,
-0.04609578102827072,
-0.007799800951033831,
-0.021394826471805573,
0.00854082964360714,
-0.026601027697324753,
0.015001079067587852,
0.007742798887193203,
0.043473679572343826,
0.04472772777080536,
0.014440557919442654,
-0.04962991550564766,
0.015637604519724846,
0.013452519662678242,
0.004263289738446474,
-0.01968475989997387,
-0.02017877995967865,
-0.013129507191479206,
0.0023465906269848347,
0.03701343014836311,
0.02990715391933918,
0.021318823099136353,
-0.02967914566397667,
0.07509090006351471,
-0.0059377290308475494,
0.0226298738270998,
-0.04670380428433418,
0.00012461809092201293,
-0.02002677321434021,
-0.0663885623216629,
0.05403808504343033,
-0.023845920339226723,
0.0016863150522112846,
0.018905729055404663,
-0.03127520903944969,
0.00022177418577484787,
-0.0022313985973596573,
0.01795569248497486,
0.017490174621343613,
-0.02010277658700943,
-0.03726043924689293,
0.04016755148768425,
0.012188971042633057,
0.027741070836782455,
-0.04829986393451691,
-0.0032990023028105497,
-0.06281642615795135,
-0.006906766444444656,
-0.0008485015132464468,
-0.005158699117600918,
-0.03165522217750549,
0.005514963064342737,
-0.04434771090745926,
0.02673403173685074,
0.028805112466216087,
-0.11719652265310287,
0.029128124937415123,
-0.03718443587422371,
-0.01405104249715805,
-0.06806062906980515,
0.02553698606789112,
0.016169624403119087,
0.03157921880483627,
-0.009144103154540062,
-0.02994515560567379,
-0.01957075484097004,
-0.032833267003297806,
0.007799800951033831,
-0.015618602745234966,
-0.027171049267053604,
-0.021090814843773842,
0.04909789562225342,
-0.020159779116511345,
-0.0199887715280056,
-0.043283671140670776,
0.056546181440353394,
0.012568985112011433,
-0.09120351821184158,
-0.011837457306683064,
0.006175238639116287,
-0.04415770620107651,
-0.019969770684838295,
0.02017877995967865,
0.05563414841890335,
0.023921923711895943,
0.020919807255268097,
-0.0392175130546093,
-0.0039022755809128284,
-0.0057097203098237514,
0.01995076984167099,
-0.041877616196870804,
-0.015552100725471973,
0.03163622319698334,
0.02565099112689495,
0.01212246809154749,
0.0006721509271301329,
-0.004702681675553322,
0.01229347474873066,
0.004595802631229162,
0.032757263630628586,
0.014402556233108044,
-0.026354016736149788,
-0.03144621476531029,
-0.015485597774386406,
0.04848987236618996,
0.03695642575621605,
0.03163622319698334,
-0.03859049081802368,
0.0076525453478097916,
0.08960746228694916,
0.03526536002755165,
-0.01401304081082344,
0.019152740016579628,
0.07414086163043976,
0.047463834285736084,
0.011856458149850368,
-0.026183011010289192,
-0.036557409912347794,
0.05434209853410721,
0.0652485191822052,
-0.02852010168135166,
-0.01887722872197628,
0.024225935339927673,
0.000541520887054503,
-0.0018549466039985418,
-0.016787149012088776,
0.008944595232605934,
-0.004469922743737698,
-0.07748499512672424,
-0.0021815216168761253,
-0.015305090695619583,
-0.014459557831287384,
0.01995076984167099,
-0.01944725029170513,
0.047121819108724594,
-0.00038506175042130053,
-0.007809301372617483,
-0.018630219623446465,
-0.042029622942209244,
-0.1022239476442337,
-0.011789955198764801,
-0.015476097352802753,
0.0030068662017583847,
0.014678066596388817,
0.011257934384047985,
0.08246318250894547,
0.020349785685539246,
0.001218422083184123,
0.0024000301491469145,
-0.02247786708176136,
-0.07072073221206665,
-0.04480373114347458,
0.02825409173965454,
-0.020843803882598877,
-0.03387830778956413,
0.061942391097545624,
0.03686142340302467,
-0.0501619353890419,
0.004564926028251648,
0.025403980165719986,
-0.017642181366682053,
-0.016644641757011414,
-0.08732736855745316,
-0.018126700073480606,
-0.06304443627595901,
0.006469749845564365,
-0.04043355956673622,
0.03232024610042572,
-0.024985965341329575,
-0.04491773247718811,
0.03382130712270737,
-0.03182622790336609,
0.032453253865242004,
0.07835902273654938,
0.004472297616302967,
-0.006545752752572298,
-0.013281513005495071,
0.025270976126194,
-0.06319644302129745,
0.035094354301691055,
-0.06353845447301865,
-0.012739991769194603,
-0.06106835603713989,
0.01635013148188591,
0.04119358956813812,
0.017148161306977272,
0.04161160811781883,
-0.01673964597284794,
0.05346806347370148,
-0.03860948979854584,
-0.014602064155042171,
-0.02428293786942959,
-0.057268209755420685,
0.03824847564101219,
0.0035270112566649914,
-0.0019440125906839967,
-0.03349829465150833,
-0.022078853100538254,
0.00798505824059248,
0.0460197776556015,
0.0032134989742189646,
-0.052062008529901505,
-0.009277108125388622,
0.019551753997802734,
-0.006949518341571093,
-0.04381569102406502,
0.04947790876030922,
0.005343956407159567,
-0.07041671872138977,
0.036158397793769836,
-0.053240057080984116,
0.0015663729282096028,
-0.0243209395557642,
-0.016245627775788307,
-0.000583084998652339,
-0.0033940060529857874,
0.012739991769194603,
-0.002312151715159416,
0.016511637717485428,
-0.042333632707595825,
0.017670681700110435,
-0.004811935592442751,
-0.004712182097136974,
0.03767845407128334,
-0.03277626633644104,
-0.01853521540760994,
0.05700220167636871,
0.04005354642868042,
0.005951979663223028,
-0.03323228284716606,
0.041801612824201584,
-0.0021577707957476377,
-0.042143628001213074,
-0.009889882057905197,
0.042257633060216904,
0.03171222284436226,
-0.07132875174283981,
0.04031955823302269,
-0.017480675131082535,
-0.02014077827334404,
0.041687607765197754,
-0.03572138026356697,
0.07600293308496475,
-0.057344213128089905,
-0.0006210864521563053,
-0.06399446725845337,
0.01941874995827675,
0.04898389056324959,
-0.017205163836479187,
-0.005220451392233372,
-0.005652718245983124,
-0.02010277658700943,
0.03184523060917854,
0.0333842895925045,
-0.017908191308379173,
-0.008555080741643906,
0.036006391048431396,
0.026487022638320923,
-0.02466295287013054,
0.009538368321955204,
-0.05133998394012451,
0.001156075857579708,
0.03631040081381798,
0.03336528688669205,
0.011789955198764801,
0.024035928770899773,
0.017053158953785896,
0.0330042727291584,
-0.0362153984606266,
-0.0026221012230962515,
-0.06255041807889938,
-0.019741762429475784,
-0.01229347474873066,
0.022990887984633446,
0.03127520903944969,
-0.06874465197324753,
0.023104891180992126,
-0.0032158740796148777,
0.038001466542482376,
-0.0006234615575522184,
-0.020881805568933487,
0.004716932307928801,
0.06722459197044373,
-0.02553698606789112,
-0.004377293866127729,
0.017547177150845528,
-0.021432828158140182,
-0.03070518560707569,
-0.021071814000606537,
0.02929913066327572,
-0.004873688332736492,
-0.03967353329062462,
-0.042827654629945755,
0.02067279815673828,
-0.0009179729386232793,
0.057914234697818756,
-0.04009154811501503,
-0.04989592730998993,
0.04822386056184769,
0.07034071534872055,
-0.05924428626894951,
0.07904305309057236,
0.02538497932255268,
-0.016625642776489258,
0.02681003510951996,
-0.023921923711895943,
-0.02572699263691902,
-0.07611694186925888,
-0.011210433207452297,
-0.04552575945854187,
0.03387830778956413,
-0.011970462277531624,
-0.023940924555063248,
0.018316706642508507,
-0.004070907365530729,
0.03993954136967659,
0.023769916966557503,
-0.0036243898794054985,
-0.030914193019270897,
-0.04362568259239197,
-0.006303493399173021,
-0.018250204622745514,
-0.009324610233306885,
0.012796994298696518,
0.03040117397904396,
-0.032035235315561295,
0.01212246809154749,
0.07254479825496674,
-0.04468972608447075,
0.0068830158561468124,
0.047881849110126495,
-0.027133047580718994,
0.004215787630528212,
0.015580601990222931,
0.03710843250155449,
0.02278187870979309,
0.020767802372574806,
-0.005780973006039858,
0.028273090720176697,
0.037507448345422745,
0.052100010216236115,
0.02599300444126129,
0.04153560474514961,
-0.047539833933115005,
-0.032567258924245834,
0.001257611089386046,
-0.007039771880954504,
-0.04020555317401886,
0.023294899612665176,
0.01933324709534645,
-0.02304789051413536,
0.05076995864510536,
-0.00471930718049407,
0.03175022453069687,
-0.008897093124687672,
0.057610224932432175,
-0.007799800951033831,
-0.015675604343414307,
-0.0516819953918457,
-0.0025936001911759377,
-0.005258453078567982,
-0.0038856500759720802,
-0.06657856702804565,
-0.05175799876451492,
0.014108045026659966,
-0.029185127466917038,
0.008778339251875877,
0.006583753973245621,
0.05464610829949379
]
|
31,009 | networkx.generators.small | petersen_graph |
Returns the Petersen graph.
The Peterson graph is a cubic, undirected graph with 10 nodes and 15 edges [1]_.
Julius Petersen constructed the graph as the smallest counterexample
against the claim that a connected bridgeless cubic graph
has an edge colouring with three colours [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
Petersen graph
References
----------
.. [1] https://en.wikipedia.org/wiki/Petersen_graph
.. [2] https://www.win.tue.nl/~aeb/drg/graphs/Petersen.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.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
]
|
31,011 | networkx.drawing.layout | planar_layout | Position nodes without edge intersections.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G. If G is of type
nx.PlanarEmbedding, the positions are selected accordingly.
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
Raises
------
NetworkXException
If G is not planar
Examples
--------
>>> G = nx.path_graph(4)
>>> pos = nx.planar_layout(G)
| def planar_layout(G, scale=1, center=None, dim=2):
"""Position nodes without edge intersections.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G. If G is of type
nx.PlanarEmbedding, the positions are selected accordingly.
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
Raises
------
NetworkXException
If G is not planar
Examples
--------
>>> G = nx.path_graph(4)
>>> pos = nx.planar_layout(G)
"""
import numpy as np
if dim != 2:
raise ValueError("can only handle 2 dimensions")
G, center = _process_params(G, center, dim)
if len(G) == 0:
return {}
if isinstance(G, nx.PlanarEmbedding):
embedding = G
else:
is_planar, embedding = nx.check_planarity(G)
if not is_planar:
raise nx.NetworkXException("G is not planar.")
pos = nx.combinatorial_embedding_to_pos(embedding)
node_list = list(embedding)
pos = np.vstack([pos[x] for x in node_list])
pos = pos.astype(np.float64)
pos = rescale_layout(pos, scale=scale) + center
return dict(zip(node_list, pos))
| (G, scale=1, center=None, dim=2) | [
0.07722732424736023,
0.028802599757909775,
-0.040876325219869614,
-0.005939492955803871,
0.0032757625449448824,
0.03403269127011299,
0.02130984514951706,
0.023071754723787308,
-0.008944014087319374,
-0.018629886209964752,
-0.015857195481657982,
-0.010747654363512993,
-0.018490787595510483,
0.027374526485800743,
-0.014762955717742443,
-0.042953524738550186,
0.016070479527115822,
-0.04810943081974983,
-0.027318887412548065,
-0.0022673006169497967,
0.012759941630065441,
-0.033921413123607635,
0.047849781811237335,
0.037834711372852325,
-0.017313089221715927,
0.015968473628163338,
0.0027981922030448914,
0.004933349322527647,
0.01164715550839901,
0.03774197772145271,
0.07707894593477249,
0.048331987112760544,
-0.043584100902080536,
0.03712994605302811,
-0.01784166321158409,
0.07722732424736023,
0.010849659331142902,
0.040023189038038254,
-0.024685293436050415,
-0.04577258229255676,
0.0406537689268589,
0.007664310745894909,
0.008285616524517536,
-0.04469688981771469,
0.06328041106462479,
0.041024696081876755,
0.02934044785797596,
-0.02657702937722206,
0.0022464359644800425,
0.03635099530220032,
0.04143271595239639,
-0.022533908486366272,
-0.01590356044471264,
-0.024759478867053986,
-0.045920953154563904,
-0.02828329987823963,
0.0034635451156646013,
0.0567149743437767,
0.013362700119614601,
-0.07678220421075821,
-0.004625014960765839,
-0.012240641750395298,
-0.028802599757909775,
-0.011925352737307549,
-0.03842819482088089,
-0.008624088019132614,
0.024852212518453598,
-0.05085430294275284,
0.008809552527964115,
-0.04146980866789818,
-0.011610062792897224,
-0.008693637326359749,
-0.006166686769574881,
-0.018982267007231712,
0.021254204213619232,
-0.020790543407201767,
0.0471821092069149,
0.010469458065927029,
-0.042879339307546616,
0.017888028174638748,
-0.0066488939337432384,
-0.020141419023275375,
0.0419149249792099,
0.006927090231329203,
0.04547583684325218,
-0.01824968308210373,
0.08753913640975952,
0.013223602436482906,
0.005118813831359148,
-0.06943782418966293,
0.009222210384905338,
-0.05300568789243698,
0.0627611055970192,
-0.026094822213053703,
-0.001980990171432495,
0.020122872665524483,
0.035627685487270355,
-0.041024696081876755,
-0.012565203942358494,
0.0016993163153529167,
-0.0010333837708458304,
0.03195549175143242,
-0.059496935456991196,
-0.04740466549992561,
-0.0176932904869318,
0.020122872665524483,
-0.021142926067113876,
-0.010794020257890224,
-0.036981575191020966,
0.05174453184008598,
0.04829489439725876,
0.028746960684657097,
-0.03820563852787018,
0.02537151239812374,
0.04128434509038925,
0.04154399409890175,
-0.01207372359931469,
0.032493337988853455,
-0.04402921721339226,
-0.024889305233955383,
-0.028116382658481598,
0.031936947256326675,
-0.030008118599653244,
-0.034700363874435425,
0.005332097876816988,
-0.0454387441277504,
0.04669990390539169,
0.023980529978871346,
0.018064219504594803,
0.0031783939339220524,
-0.010246900841593742,
-0.00877245981246233,
0.013121596537530422,
0.04859163612127304,
-0.022775011137127876,
-0.026762492954730988,
-0.003535412484779954,
0.012166456319391727,
-0.019789036363363266,
-0.000840384978801012,
0.030953986570239067,
-0.00792396068572998,
-0.04402921721339226,
0.014178743585944176,
-0.00752984918653965,
0.003227078355848789,
0.03531239554286003,
-0.026892319321632385,
-0.00045844449778087437,
-0.012815580703318119,
0.06420773267745972,
-0.08071404695510864,
0.08360729366540909,
0.015745915472507477,
0.030638696625828743,
-0.0008797961054369807,
0.021068740636110306,
-0.01218500267714262,
-0.02158804051578045,
0.004840617533773184,
-0.05511998012661934,
0.0020099689718335867,
-0.008758549578487873,
0.002758780959993601,
-0.020048687234520912,
-0.012008811347186565,
0.07581779360771179,
-0.013381246477365494,
-0.018435148522257805,
0.0037023304030299187,
0.005128087010234594,
-0.03182566910982132,
-0.027875280007719994,
-0.011489511467516422,
0.01214790903031826,
0.0031297095119953156,
0.015523359179496765,
-0.01853715442121029,
0.023127393797039986,
-0.0028422398027032614,
0.013130869716405869,
-0.004951896145939827,
0.052041273564100266,
0.0441775880753994,
-0.013362700119614601,
0.052671853452920914,
0.00110930809751153,
-0.020215604454278946,
-0.05968240275979042,
-0.02153240144252777,
-0.02040106989443302,
0.027393072843551636,
-0.032289329916238785,
0.05356207862496376,
-0.04632897302508354,
0.04636606574058533,
0.00023646693443879485,
0.012555930763483047,
-0.07114409655332565,
0.07006839662790298,
0.06079518795013428,
-0.00044946104753762484,
0.027300339192152023,
0.005897763650864363,
-0.004305089358240366,
0.008331982418894768,
-0.0028886059299111366,
0.014178743585944176,
0.009542136453092098,
0.027189061045646667,
-0.017034893855452538,
-0.016209576278924942,
0.014364207163453102,
-0.05645532160997391,
-0.014549671672284603,
0.0592372864484787,
-0.047775596380233765,
0.04725629463791847,
0.0015416716923937201,
0.009996524080634117,
-0.0016425178619101644,
0.004091805312782526,
-0.004532283172011375,
-0.010868205688893795,
0.024351458996534348,
-0.04725629463791847,
0.05037209391593933,
-0.04703373834490776,
-0.004933349322527647,
-0.03727831691503525,
0.014336387626826763,
-0.046996645629405975,
0.0027448711916804314,
-0.03180712088942528,
0.042582593858242035,
-0.03223368898034096,
0.02288629114627838,
0.037612155079841614,
0.020920369774103165,
0.03266025707125664,
0.016070479527115822,
-0.029025157913565636,
-0.0742969885468483,
0.004641243256628513,
-0.035831697285175323,
0.046217694878578186,
0.003159847343340516,
-0.047627225518226624,
0.005869944114238024,
-0.01804567314684391,
-0.09429003298282623,
-0.04736757278442383,
-0.01115567609667778,
0.018435148522257805,
-0.005012171808630228,
0.03195549175143242,
-0.03954098001122475,
0.018741164356470108,
0.004066303838044405,
-0.0011516171507537365,
-0.057864852249622345,
-0.06328041106462479,
-0.04751594364643097,
0.010719834826886654,
0.15067116916179657,
0.03069433569908142,
-0.0006711488240398467,
0.03445925936102867,
0.0284873116761446,
-0.0013828679220750928,
0.07752406597137451,
0.04681118205189705,
0.0010478730546310544,
0.007094008382409811,
0.08049149066209793,
0.04388084635138512,
-0.001328387763351202,
0.021365484222769737,
0.03983772546052933,
-0.0014303931966423988,
-0.03039759397506714,
-0.02535296604037285,
0.020345430821180344,
-0.0034403621684759855,
-0.009444767609238625,
-0.0030647970270365477,
0.004381593316793442,
-0.03772343322634697,
0.014382753521203995,
-0.005846761167049408,
0.03596151992678642,
0.007140374276787043,
-0.040171559900045395,
0.006838995032012463,
0.006101774517446756,
0.03714849427342415,
-0.007896141149103642,
-0.03560914099216461,
-0.02110583335161209,
-0.020345430821180344,
0.05052046477794647,
-0.06958619505167007,
0.04673699662089348,
0.041173066943883896,
0.05830996483564377,
0.0883551761507988,
-0.014800048433244228,
0.005767938680946827,
0.02344268374145031,
0.017943667247891426,
-0.029358994215726852,
-0.03531239554286003,
-0.02151385508477688,
-0.0039642988704144955,
-0.024351458996534348,
0.03039759397506714,
0.028431672602891922,
0.0015926744090393186,
0.022997569292783737,
-0.014735136181116104,
0.01718326471745968,
0.013566710986196995,
-0.07641127705574036,
0.04484526067972183,
-0.021291296929121017,
0.016459953039884567,
-0.019306831061840057,
0.020159965381026268,
0.04043120890855789,
0.0017630696529522538,
0.005693752784281969,
0.029785560443997383,
-0.03685174882411957,
0.005308914463967085,
-0.06680423021316528,
-0.0227193720638752,
0.01725745014846325,
0.028542950749397278,
-0.016645418480038643,
-0.004534601233899593,
0.01761910505592823,
-0.04759012907743454,
-0.011851166374981403,
-0.012157183140516281,
0.04402921721339226,
0.03976354002952576,
-0.015068971551954746,
-0.022348444908857346,
-0.026261739432811737,
0.003438043873757124,
0.003948070574551821,
0.02820911444723606,
-0.054378122091293335,
-0.011814073659479618,
-0.024388551712036133,
-0.0088466452434659,
0.051967088133096695,
-0.05007535219192505,
-0.04959314316511154,
0.06457865983247757,
0.06235308572649956,
0.006829721853137016,
-0.024240178987383842,
-0.021068740636110306,
-0.007223833352327347,
0.006927090231329203,
-0.04083923250436783,
0.008689001202583313,
0.11417180299758911,
0.016636144369840622,
0.060646817088127136,
-0.041877832263708115,
-0.08204939216375351,
0.05634404346346855,
-0.04161818325519562,
0.06717515736818314,
0.006009042263031006,
0.025130407884716988,
-0.04269387573003769,
-0.019585026428103447,
0.04043120890855789,
-0.024277271702885628,
0.07336966693401337,
0.022626640275120735,
-0.01960357278585434,
-0.0017595922108739614,
0.030434686690568924,
0.019492294639348984,
-0.04061667621135712,
-0.032419152557849884,
-0.06583981215953827,
-0.016033386811614037,
0.028023650869727135,
0.002661412116140127,
0.024703839793801308,
0.06172250956296921,
-0.04662571847438812,
0.03809436038136482,
-0.0481836162507534,
-0.01698852702975273,
-0.026243193075060844,
-0.02414744719862938,
-0.041173066943883896,
-0.01183262001723051,
0.026539936661720276,
-0.045364558696746826,
0.052449293434619904,
0.016089025884866714,
0.06053553521633148,
0.12782196700572968,
0.0067277164198458195,
0.006565434858202934,
0.046143509447574615,
-0.06940072774887085,
-0.0009736873907968402,
-0.02394343726336956,
-0.017146172001957893,
0.09095167368650436,
0.029006611555814743,
-0.03920714557170868,
-0.012815580703318119,
-0.02492639794945717,
0.029321901500225067,
-0.03898458927869797,
-0.008902285248041153,
-0.022200072184205055,
0.020512348040938377,
0.004393185023218393,
0.008860555477440357,
0.045216187834739685,
0.0033870411571115255,
0.0010751131922006607,
0.05256057158112526,
0.04402921721339226,
-0.00037614471511915326,
0.005716936197131872,
0.06591399759054184,
0.004975079093128443,
-0.029006611555814743,
0.047701410949230194,
0.05552799999713898,
-0.024036169052124023,
-0.015124610625207424,
-0.004731656983494759,
-0.0009389128535985947,
0.04733048006892204,
-0.038539472967386246,
-0.0237208791077137,
0.025315873324871063,
0.024425644427537918,
0.0268552266061306,
-0.03340211510658264,
0.024351458996534348,
-0.024555468931794167,
-0.016589779406785965,
-0.04106178879737854,
-0.003308218903839588,
-0.011925352737307549,
-0.13383100926876068,
0.018073493614792824,
0.016960706561803818,
-0.00505853770300746,
-0.04580967500805855,
0.009004290215671062,
0.037834711372852325,
0.03453344479203224,
0.0007586647407151759,
0.010664195753633976,
-0.042100388556718826,
-0.05100267380475998,
-0.0016344038303941488,
-0.027448711916804314,
-0.04477107524871826,
-0.0474417582154274,
-0.01104439701884985,
0.001923032570630312,
0.0004888722323812544,
0.020271243527531624,
-0.07663383334875107,
0.05055755749344826,
-0.010172715410590172,
-0.0033870411571115255,
0.021643679589033127,
0.0592372864484787,
-0.014660950750112534,
0.03177002817392349,
0.033142466098070145,
0.058940544724464417,
-0.049259308725595474,
-0.020438162609934807,
-0.023980529978871346,
-0.0031181180384010077,
0.0331239178776741,
0.03488582745194435,
-0.014048918150365353,
0.005489742383360863,
-0.03744523599743843,
-0.035052746534347534,
0.005907036829739809,
0.017220357432961464,
0.018138404935598373,
-0.06075809523463249,
0.011841893196105957,
-0.005039991345256567,
0.011535877361893654,
-0.012518838047981262,
0.030787067487835884,
0.06710097193717957,
0.03879912570118904,
0.10259883105754852,
-0.026521390303969383,
0.04469688981771469,
-0.024184539914131165,
-0.04339863732457161,
0.018147679045796394,
0.12871220707893372,
-0.014707316644489765,
0.020938916131854057,
0.012018084526062012,
-0.048331987112760544,
0.0029117888770997524,
0.016218850389122963,
0.004314362537115812,
0.047849781811237335,
-0.04666281118988991,
0.031714390963315964,
0.05526835098862648,
-0.04688536748290062,
-0.0015625364612787962,
-0.052671853452920914,
-0.016014838591217995,
0.010450911708176136,
-0.018203318119049072,
0.0021606588270515203,
0.010794020257890224,
0.050965581089258194,
0.03687029704451561,
-0.023331405594944954,
-0.013483252376317978,
0.0038414285518229008,
-0.015106064267456532,
-0.006838995032012463,
-0.020771997049450874,
-0.015217343345284462,
0.05719717964529991,
-0.004330590832978487,
0.042730968445539474,
-0.020067233592271805,
-0.02577953226864338,
-0.04759012907743454,
-0.003602643497288227,
-0.0019404198974370956,
-0.00994088500738144,
-0.015857195481657982,
0.015235889703035355,
0.020846184343099594,
-0.029581550508737564,
0.010460184887051582,
0.015087517909705639,
0.013121596537530422,
-0.011266954243183136,
-0.03253043070435524,
-0.02494494430720806,
-0.0034449987579137087,
0.009885245002806187,
-0.06313204020261765,
-0.033773042261600494,
-0.034700363874435425,
0.052746038883924484,
0.02783818729221821,
0.038539472967386246,
-0.03872494027018547,
0.04673699662089348,
-0.03560914099216461,
0.05882926657795906,
-0.03972644731402397,
-0.019566480070352554,
0.05426684394478798,
-0.008378348313272,
-0.029525911435484886,
-0.012908313423395157,
-0.015755189582705498,
0.0033012640196830034,
0.041581086814403534,
-0.043658290058374405,
0.057864852249622345,
-0.02998957224190235,
0.01676596887409687,
0.02500058338046074,
-0.0014211199013516307,
0.0013805496273562312,
-0.01041381899267435,
0.06943782418966293,
0.013613076880574226,
-0.01498551294207573,
-0.049481865018606186,
0.010497277602553368,
0.02323867194354534,
-0.008141881786286831,
-0.005183726083487272,
-0.06925235688686371,
0.01748000644147396,
0.01696998067200184,
-0.006296511739492416,
-0.015319348312914371,
-0.04577258229255676,
0.01904718019068241,
0.0023426455445587635,
0.02557552233338356,
-0.056084394454956055,
-0.010673468932509422,
-0.008494263514876366,
-0.03381013497710228,
-0.08857773244380951,
-0.013130869716405869,
-0.0537104532122612,
-0.028598589822649956,
0.05133650824427605,
-0.010061436332762241,
-0.010163442231714725,
0.009644142352044582,
0.020771997049450874,
-0.0009632550645619631,
-0.06483830511569977,
0.018629886209964752,
0.09384492039680481,
0.018704071640968323,
-0.0702909603714943,
-0.0023322131019085646,
0.016153937205672264,
-0.011220588348805904,
-0.0026220011059194803,
-0.06992002576589584,
0.02919207513332367,
-0.000980642274953425,
-0.09644141793251038,
-0.016673237085342407,
-0.016923613846302032,
0.05326533690094948,
0.028895333409309387,
0.028431672602891922,
-0.056863345205783844,
-0.005225455854088068,
-0.037519421428442,
0.049259308725595474,
-0.06194506585597992,
0.0760403499007225,
-0.050631746649742126,
0.005322824232280254,
-0.008944014087319374,
-0.017952941358089447,
-0.018268229439854622,
0.022051701322197914,
-0.0332537442445755,
0.012101543135941029,
0.06695260107517242,
-0.00484989071264863,
0.007650400977581739,
0.04354700818657875,
-0.05141069367527962,
-0.0002531297504901886,
0.023461230099201202,
-0.05983077362179756,
0.01164715550839901,
0.013631623238325119,
0.025130407884716988,
-0.016107572242617607,
-0.03076852113008499,
0.006440246477723122,
-0.028932426124811172,
-0.023183032870292664,
-0.013362700119614601,
0.026762492954730988,
-0.02123565785586834,
-0.006560798268765211,
0.03319810330867767,
0.006505159195512533,
-0.0038367919623851776,
-0.045995138585567474,
-0.02798655815422535,
0.016728876158595085,
-0.021217111498117447,
-0.0014663268812000751,
0.006927090231329203,
-0.062056344002485275,
0.03386577591300011,
-0.024815119802951813,
-0.07678220421075821,
0.036332450807094574,
0.012175729498267174,
0.06743481010198593,
-0.0038043358363211155,
0.08086241781711578,
-0.03902168199419975,
0.014596037566661835,
0.016636144369840622,
-0.0026961867697536945,
0.023201579228043556,
0.021476762369275093,
-0.015421354211866856,
0.002821375150233507,
-0.046996645629405975,
-0.04232294484972954,
0.01548626646399498,
-0.0451790951192379,
-0.021754957735538483,
-0.05419265851378441,
0.03132491558790207,
-0.005842124577611685,
0.031491830945014954,
-0.018509333953261375,
-0.006760172545909882,
0.008197520859539509,
-0.10897880047559738,
0.02429581806063652,
-0.019844677299261093,
-0.0005349484854377806,
-0.007988872937858105,
-0.0333835668861866,
0.004012983292341232,
-0.03813145309686661,
-0.02153240144252777,
-0.02770836092531681,
0.04503072425723076,
-0.017637651413679123,
-0.0056195673532783985,
-0.035516407340765,
-0.06643330305814743,
-0.007706040516495705,
-0.003192303702235222,
-0.000671728397719562,
0.08338473737239838,
-0.01268575619906187,
0.05341370776295662,
-0.03983772546052933,
0.03267880529165268,
-0.04829489439725876,
-0.008025966584682465,
-0.03714849427342415,
0.03097253292798996,
0.02770836092531681,
0.017164718359708786,
-0.026243193075060844,
-0.04937058687210083,
0.026261739432811737,
0.01395618636161089,
-0.060424257069826126,
0.030008118599653244,
-0.00795641727745533,
0.030601603910326958,
-0.018509333953261375,
0.010265447199344635,
0.0017271359683945775,
0.004560102708637714,
-0.0017143853474408388,
-0.023850705474615097,
0.003224759828299284,
0.016395041719079018,
-0.012759941630065441,
-0.06787992268800735,
-0.10185697674751282,
-0.0655059814453125,
-0.06417063623666763,
0.02073490433394909,
-0.023980529978871346,
-0.022478269413113594,
0.025130407884716988,
0.052968595176935196
]
|
31,013 | networkx.generators.community | planted_partition_graph | Returns the planted l-partition graph.
This model partitions a graph with n=l*k vertices in
l groups with k vertices each. Vertices of the same
group are linked with a probability p_in, and vertices
of different groups are linked with probability p_out.
Parameters
----------
l : int
Number of groups
k : int
Number of vertices in each group
p_in : float
probability of connecting vertices within a group
p_out : float
probability of connected vertices between groups
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
Returns
-------
G : NetworkX Graph or DiGraph
planted l-partition graph
Raises
------
NetworkXError
If `p_in`, `p_out` are not in `[0, 1]`
Examples
--------
>>> G = nx.planted_partition_graph(4, 3, 0.5, 0.1, seed=42)
See Also
--------
random_partition_model
References
----------
.. [1] A. Condon, R.M. Karp, Algorithms for graph partitioning
on the planted partition model,
Random Struct. Algor. 18 (2001) 116-140.
.. [2] Santo Fortunato 'Community Detection in Graphs' Physical Reports
Volume 486, Issue 3-5 p. 75-174. https://arxiv.org/abs/0906.0612
| 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)
| (l, k, p_in, p_out, seed=None, directed=False, *, backend=None, **backend_kwargs) | [
-0.00202886457554996,
0.025789326056838036,
-0.0388953760266304,
-0.01564270630478859,
0.00601076940074563,
0.05999740585684776,
-0.03406102582812309,
-0.04183642566204071,
0.053821202367544174,
-0.012186973355710506,
-0.01999913528561592,
0.019833700731396675,
-0.0033362528774887323,
0.05132131278514862,
-0.01010066643357277,
0.015247502364218235,
0.010826737619936466,
-0.04124821722507477,
0.02077116072177887,
0.034152936190366745,
-0.011745816096663475,
-0.0185837559401989,
-0.01171824336051941,
0.016819125041365623,
-0.036064617335796356,
0.02696574665606022,
0.022829895839095116,
0.008290083147585392,
-0.05514467507600784,
-0.0011350612621754408,
-0.0261569581925869,
-0.015596752054989338,
-0.022204922512173653,
-0.009880087338387966,
0.0026492420583963394,
0.053269755095243454,
0.03720427304506302,
0.083305224776268,
-0.013390964828431606,
-0.024410709738731384,
-0.019006531685590744,
-0.04915228858590126,
0.006401377730071545,
-0.013905649073421955,
0.01131384912878275,
0.018841097131371498,
0.012637320905923843,
0.05584317445755005,
-0.0662471354007721,
-0.05018165335059166,
0.010652112774550915,
-0.03621166944503784,
0.03455733135342598,
0.0016577867791056633,
-0.026892220601439476,
0.012334025464951992,
0.0008288933895528316,
0.03856451064348221,
0.06525453180074692,
0.005192790180444717,
-0.014604148454964161,
-0.002310332143679261,
0.017480861395597458,
-0.009751416742801666,
-0.06672506034374237,
0.0011310402769595385,
-0.06826911121606827,
-0.03915271908044815,
0.036873407661914825,
0.06345313787460327,
0.0743350237607956,
0.04367458447813988,
-0.002039204118773341,
0.012683275155723095,
0.06996021419763565,
0.04532892256975174,
-0.0000943490958889015,
0.0027939968276768923,
-0.005192790180444717,
-0.05819601193070412,
0.020421911031007767,
0.016809934750199318,
0.02080792374908924,
-0.010744021274149418,
0.06973963230848312,
-0.004243842326104641,
0.03380368649959564,
0.008363609202206135,
-0.009392976760864258,
-0.04661563038825989,
0.022774750366806984,
0.0017944995779544115,
0.04205700382590294,
-0.03617490828037262,
0.0006939038285054266,
0.05915185436606407,
-0.01810583472251892,
-0.033858831971883774,
0.03623005002737045,
-0.03481467068195343,
0.046248000115156174,
-0.006364614702761173,
-0.0628281682729721,
0.020035898312926292,
-0.020881449803709984,
-0.05536525323987007,
0.0011023191036656499,
0.0027664245571941137,
-0.00229769479483366,
-0.033307384699583054,
-0.07543791830539703,
0.045439213514328,
0.054372649639844894,
-0.004871112760156393,
0.010826737619936466,
-0.0014429523143917322,
-0.005730450619012117,
0.009549219161272049,
0.013795359991490841,
0.007292883470654488,
-0.041137926280498505,
0.031230267137289047,
-0.021800527349114418,
0.02562389150261879,
0.014337615109980106,
0.00936080887913704,
0.028270836919546127,
0.011130033992230892,
0.03220449015498161,
-0.022848276421427727,
0.02156156860291958,
-0.016120627522468567,
0.005422559566795826,
0.0204770565032959,
-0.0035039845388382673,
-0.04205700382590294,
-0.10337788611650467,
-0.036579299718141556,
0.04834349825978279,
0.006134845316410065,
-0.01267408486455679,
-0.027627483010292053,
-0.01712242141366005,
0.044078975915908813,
0.009494074620306492,
0.04157908633351326,
0.010854310356080532,
-0.020366767421364784,
0.005303079728037119,
0.008230342529714108,
0.0442260280251503,
-0.004593092016875744,
-0.012462696991860867,
-0.04529216140508652,
-0.03152437135577202,
-0.0062727066688239574,
-0.017012132331728935,
-0.029906796291470528,
-0.002094348892569542,
0.01966826803982258,
-0.024171749129891396,
0.025035683065652847,
-0.02621210180222988,
0.0512845478951931,
-0.009080490097403526,
-0.037130746990442276,
0.06069590523838997,
-0.01684669777750969,
-0.06183556094765663,
-0.02722308784723282,
-0.011166797019541264,
-0.029226677492260933,
-0.03801306337118149,
-0.058453354984521866,
0.030403098091483116,
-0.048931706696748734,
0.020054280757904053,
0.00017792773724067956,
-0.03856451064348221,
0.010624540969729424,
-0.03588080033659935,
-0.00918158795684576,
-0.015173976309597492,
-0.021230699494481087,
-0.003768219379708171,
0.052240390330553055,
0.05444617569446564,
-0.007384791038930416,
0.05510791018605232,
-0.04054971784353256,
-0.044409845024347305,
-0.04282902926206589,
-0.05102720484137535,
0.07705549150705338,
-0.001306239515542984,
0.01455819420516491,
-0.024631287902593613,
0.028546560555696487,
-0.10631893575191498,
0.028417889028787613,
0.007145830895751715,
0.022535789757966995,
0.005583398509770632,
-0.04940962791442871,
0.03554993495345116,
-0.022462263703346252,
-0.03402426466345787,
-0.030329572036862373,
0.05132131278514862,
0.03242506831884384,
0.014310043305158615,
-0.024373946711421013,
0.07837896794080734,
0.02157994918525219,
0.015164786018431187,
-0.039777692407369614,
0.017885256558656693,
0.0038003872614353895,
-0.01455819420516491,
-0.04940962791442871,
-0.001293602166697383,
-0.02996193990111351,
0.05698283016681671,
-0.031671423465013504,
0.022076250985264778,
-0.03452056646347046,
-0.015826521441340446,
-0.05106396973133087,
-0.04202024266123772,
-0.011359803378582,
0.06345313787460327,
-0.03937329724431038,
0.024171749129891396,
-0.00011919291864614934,
-0.022535789757966995,
-0.016938606277108192,
0.016534211114048958,
-0.0063462331891059875,
-0.023969551548361778,
0.0442260280251503,
-0.08646684885025024,
-0.015431318432092667,
0.023914407938718796,
0.01710404083132744,
0.03624843433499336,
0.0550711490213871,
-0.007904070429503918,
-0.002600990468636155,
-0.0204770565032959,
0.027094416320323944,
-0.021138792857527733,
-0.06661476939916611,
-0.027333376929163933,
-0.06580597907304764,
0.03944682329893112,
-0.07418797165155411,
-0.05646814778447151,
0.007283692713826895,
0.011424138210713863,
-0.02538493275642395,
-0.02884066477417946,
-0.03106483444571495,
-0.04613771289587021,
0.07874659448862076,
0.005192790180444717,
-0.033086806535720825,
0.0018829609034582973,
0.07242333889007568,
-0.0700337365269661,
0.007012564688920975,
0.040108561515808105,
0.05065957456827164,
0.04911552369594574,
-0.010422343388199806,
0.0007300925208255649,
-0.01307847909629345,
-0.01877676136791706,
0.008680691011250019,
0.01226969063282013,
0.053600624203681946,
0.011019743978977203,
0.04213053360581398,
-0.037130746990442276,
-0.0018599838949739933,
-0.0021288141142576933,
0.018804334104061127,
-0.024226894602179527,
-0.020936595275998116,
-0.007871902547776699,
-0.01271084789186716,
-0.0024286634288728237,
-0.02023809589445591,
-0.00297551485709846,
-0.0032236657571047544,
0.04257168993353844,
0.010229337029159069,
0.03490658104419708,
0.01879514381289482,
0.026653259992599487,
0.03398749977350235,
0.0469832643866539,
-0.04102763906121254,
-0.03724103793501854,
-0.004195590503513813,
0.037130746990442276,
-0.01510045025497675,
-0.0044046808034181595,
-0.04966697096824646,
0.016497448086738586,
0.03554993495345116,
-0.04025561362504959,
-0.01266489364206791,
0.046799447387456894,
0.029263440519571304,
0.029484018683433533,
0.004154232330620289,
0.016497448086738586,
-0.024998920038342476,
0.02669002301990986,
0.07146749645471573,
-0.01361154392361641,
-0.0024585335049778223,
-0.02080792374908924,
0.0033408482559025288,
-0.054666753858327866,
-0.010394771583378315,
-0.026009904220700264,
0.041652612388134,
-0.0020977952517569065,
-0.00878638494759798,
-0.05701959505677223,
-0.038711562752723694,
0.048747893422842026,
0.04661563038825989,
-0.010486679151654243,
0.036285195499658585,
0.07257039099931717,
-0.0700337365269661,
0.049299340695142746,
-0.07786428183317184,
0.02023809589445591,
-0.007334241643548012,
-0.07014402747154236,
-0.005661520175635815,
0.0010839374735951424,
-0.0074215540662407875,
0.03422646224498749,
-0.017499243840575218,
-0.043564293533563614,
-0.01887786015868187,
0.022590935230255127,
0.10161325335502625,
0.01226049941033125,
0.07253362983465195,
0.004211674444377422,
0.11028935015201569,
-0.005427155178040266,
-0.028711993247270584,
0.018023118376731873,
0.0286568496376276,
-0.05341680720448494,
-0.0060061742551624775,
0.08264348655939102,
0.027664246037602425,
-0.0388953760266304,
-0.004634450189769268,
-0.00906210858374834,
0.0051146685145795345,
0.0884520560503006,
-0.0762467011809349,
-0.004806777462363243,
-0.01593681052327156,
-0.04499805346131325,
0.030384715646505356,
-0.03904242813587189,
0.00862095132470131,
-0.11536265909671783,
0.015734614804387093,
-0.021745383739471436,
0.0006140589248389006,
-0.03406102582812309,
-0.02270122431218624,
0.03376692160964012,
0.03963064029812813,
0.004096789751201868,
-0.05341680720448494,
0.05510791018605232,
0.020421911031007767,
0.0020897535141557455,
0.025568747892975807,
-0.03104645200073719,
-0.007779994513839483,
0.018988149240612984,
0.04617447406053543,
0.007867307402193546,
0.013832123018801212,
0.07029107958078384,
-0.007876497693359852,
-0.05863717198371887,
0.033583108335733414,
0.03611976280808449,
-0.002158684190362692,
0.010734830051660538,
0.05312270298600197,
-0.03457571193575859,
-0.02295856550335884,
0.032002292573451996,
0.013758596032857895,
0.014126227237284184,
0.03801306337118149,
-0.07326889038085938,
-0.0066265519708395,
0.04690973833203316,
-0.04293932020664215,
-0.04286579415202141,
-0.064372219145298,
-0.03347281739115715,
0.028509797528386116,
0.10712771862745285,
-0.012811945751309395,
0.09595173597335815,
-0.0609164834022522,
0.055990226566791534,
0.01415379997342825,
-0.003949737176299095,
-0.034980107098817825,
0.023859262466430664,
-0.04771852493286133,
-0.04190995171666145,
-0.017205137759447098,
-0.032553739845752716,
0.004344940651208162,
0.07304831594228745,
-0.06565892696380615,
0.042534925043582916,
-0.013004952110350132,
-0.014650101773440838,
0.01684669777750969,
-0.02970459870994091,
-0.004227758385241032,
0.08904027193784714,
0.01741652563214302,
-0.004751632921397686,
-0.02755395509302616,
0.051983047276735306,
0.015183167532086372,
-0.02023809589445591,
-0.009944423101842403,
-0.015431318432092667,
0.03297651559114456,
0.047865577042102814,
-0.009953613393008709,
0.021984344348311424,
0.004358727019280195,
0.001340704970061779,
0.039520349353551865,
0.059262145310640335,
0.022296831011772156,
-0.049483153969049454,
-0.010431534610688686,
0.09543704986572266,
-0.03216772526502609,
-0.020863069221377373,
0.06628389656543732,
-0.011709053069353104,
0.04944639280438423,
-0.0028859046287834644,
-0.0049951886758208275,
0.011635526083409786,
-0.0012350109172984958,
0.03393235802650452,
0.02964945323765278,
-0.030164137482643127,
-0.07231304794549942,
-0.02832598052918911,
-0.03672635182738304,
-0.07749664783477783,
0.008809361606836319,
-0.015284265391528606,
-0.006226752884685993,
-0.015697849914431572,
-0.005215767305344343,
0.06073267012834549,
-0.009530837647616863,
-0.03922624513506889,
-0.048931706696748734,
-0.0016600844683125615,
-0.03676311671733856,
-0.011414947919547558,
0.012104256078600883,
-0.01615739054977894,
-0.09139310568571091,
0.013997556641697884,
0.00513764563947916,
0.03702045977115631,
0.009944423101842403,
0.0019116820767521858,
-0.02646944485604763,
0.03621166944503784,
-0.005427155178040266,
0.01510045025497675,
0.04676268622279167,
0.03163466230034828,
-0.03599109128117561,
0.05698283016681671,
0.015881666913628578,
0.021138792857527733,
-0.045733317732810974,
-0.05047575756907463,
0.0017508434830233455,
0.0156610868871212,
0.0004914194578304887,
-0.0010678536491468549,
-0.02270122431218624,
0.028178928419947624,
0.02051381953060627,
0.04933610185980797,
0.03202067315578461,
0.022590935230255127,
-0.00648409454151988,
0.020660871639847755,
0.047093551605939865,
-0.0232342891395092,
0.09337831288576126,
-0.01741652563214302,
0.00009966250945581123,
-0.018133407458662987,
-0.045512739568948746,
-0.02104688435792923,
0.017444098368287086,
-0.025807708501815796,
0.01095540914684534,
-0.03885861486196518,
0.05724017322063446,
0.02371221035718918,
-0.022719606757164,
-0.011258704587817192,
0.025844471529126167,
0.05227715149521828,
0.01185610517859459,
-0.022241685539484024,
-0.016543403267860413,
0.04488776624202728,
0.009990377351641655,
0.0010730234207585454,
0.031230267137289047,
0.028436271473765373,
0.020605726167559624,
0.004894089885056019,
-0.03725941851735115,
-0.04231434687972069,
0.04209376871585846,
-0.03323385864496231,
-0.012830328196287155,
0.0899961069226265,
-0.04102763906121254,
-0.039520349353551865,
-0.04992431402206421,
0.03852774575352669,
0.07076899707317352,
0.0075548202730715275,
-0.02834436297416687,
-0.06742355972528458,
-0.0053857965394854546,
0.036836642771959305,
0.011736624874174595,
-0.0163503959774971,
-0.041468795388936996,
0.00824412889778614,
0.00344654219225049,
0.017802538350224495,
-0.010165002197027206,
-0.03652415797114372,
0.0063462331891059875,
-0.00997199583798647,
-0.031193504109978676,
-0.04676268622279167,
-0.017903637140989304,
0.010762402787804604,
-0.010091475211083889,
-0.02290342189371586,
0.02213139645755291,
0.07573202252388,
-0.034998487681150436,
0.041946716606616974,
0.04588036984205246,
-0.09109900146722794,
-0.04051295295357704,
0.021249081939458847,
0.03878508880734444,
0.0280502587556839,
0.00317541416734457,
-0.02181890979409218,
-0.0104131530970335,
-0.0676441341638565,
-0.0013338117860257626,
0.011580381542444229,
-0.00803733617067337,
-0.02828921750187874,
-0.035494789481163025,
-0.05613727867603302,
0.0261569581925869,
0.003952035214751959,
0.055990226566791534,
0.02782967872917652,
-0.01361154392361641,
-0.04867436736822128,
-0.03266403079032898,
0.012379979714751244,
0.030825873836874962,
-0.0437113456428051,
0.022793132811784744,
-0.01497177965939045,
-0.06871026754379272,
-0.00303985015489161,
-0.038454219698905945,
-0.025201115757226944,
0.00689308438450098,
0.019557978957891464,
-0.05157865211367607,
0.023142382502555847,
-0.0002455661306157708,
0.006672505754977465,
-0.02132260799407959,
-0.016221724450588226,
0.024943774566054344,
-0.023032093420624733,
-0.0021357072982937098,
0.02213139645755291,
0.02998032234609127,
-0.003117971820756793,
-0.010982980951666832,
0.03911595791578293,
-0.020899832248687744,
0.02404307760298252,
-0.028436271473765373,
0.024190131574869156,
0.002520571229979396,
0.010109856724739075,
-0.00553744425997138,
-0.020164569839835167,
0.045218635350465775,
-0.017738204449415207,
-0.07661433517932892,
-0.10676009207963943,
-0.0011005958076566458,
0.03295813500881195,
0.05135807394981384,
0.0006358870305120945,
0.02049543708562851,
0.007053922861814499,
-0.0006646082038059831,
0.05477704480290413,
-0.05389472842216492,
0.01473281905055046,
-0.028546560555696487,
-0.03569698706269264,
0.028509797528386116,
0.04297608509659767,
-0.048968471586704254,
0.029759742319583893,
0.04429955407977104,
0.06054885312914848,
-0.004703381098806858,
0.008735835552215576,
0.0229769479483366,
0.018556183204054832,
-0.013299057260155678,
-0.027958350256085396,
0.03804982453584671,
-0.04532892256975174,
-0.012765992432832718,
0.06514424085617065,
-0.016672072932124138,
-0.03705722093582153,
0.04190995171666145,
-0.04121145233511925,
0.014475476928055286,
-0.03804982453584671,
0.04069676995277405,
0.02755395509302616,
0.023381343111395836,
-0.03477790951728821,
-0.00035441943327896297,
-0.0068149627186357975,
-0.005578802898526192,
-0.03485143557190895,
-0.053306519985198975,
-0.011837723664939404,
0.005822358652949333,
0.00906210858374834,
-0.01067968551069498,
-0.005119264125823975,
-0.025476839393377304,
-0.02808702178299427,
0.045218635350465775,
-0.033583108335733414,
0.000054175336117623374,
0.0053857965394854546,
0.01348287332803011,
0.05565935745835304,
0.0283075999468565,
-0.008597973734140396,
0.046284765005111694,
-0.021782146766781807,
-0.024153368547558784,
-0.03959387540817261,
0.053563859313726425,
0.02887742780148983,
0.011672289110720158,
-0.020716017112135887,
-0.008731240406632423,
0.00011036115029128268,
0.00662195635959506,
-0.03760866820812225,
-0.022554172202944756,
0.024484235793352127,
0.0991133600473404,
-0.01253622304648161,
-0.00749967573210597,
0.00986170582473278,
0.02051381953060627,
0.033877212554216385,
-0.002444747369736433,
-0.06099000945687294,
-0.02051381953060627,
0.054115306586027145,
-0.027719389647245407,
0.038233641535043716,
-0.028142165392637253,
-0.028950953856110573,
0.08117295801639557,
-0.024355564266443253,
0.042755503207445145,
-0.009466502815485,
-0.056799016892910004,
-0.018427511677145958,
0.02589961513876915,
-0.047093551605939865,
0.0032466426491737366,
-0.06668829172849655,
0.009769798256456852,
-0.04047619178891182,
0.008565805852413177,
-0.023565158247947693,
-0.027609100565314293,
0.04374811053276062,
0.009981186129152775,
-0.006134845316410065,
-0.020918212831020355,
0.007173403166234493,
-0.0022643781267106533,
0.02380411885678768,
0.007715659216046333,
-0.04643181711435318,
-0.036873407661914825,
0.003533854614943266,
-0.05429912358522415,
-0.054152071475982666,
-0.07565849274396896,
-0.006778199691325426,
0.012600557878613472,
-0.006378400605171919,
-0.002791699254885316,
-0.008014359511435032,
0.041137926280498505,
0.03996150940656662,
0.023032093420624733
]
|
31,016 | networkx.generators.random_graphs | powerlaw_cluster_graph | Holme and Kim algorithm for growing graphs with powerlaw
degree distribution and approximate average clustering.
Parameters
----------
n : int
the number of nodes
m : int
the number of random edges to add for each new node
p : float,
Probability of adding a triangle after adding a random edge
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Notes
-----
The average clustering has a hard time getting above a certain
cutoff that depends on `m`. This cutoff is often quite low. The
transitivity (fraction of triangles to possible triangles) seems to
decrease with network size.
It is essentially the Barabási–Albert (BA) growth model with an
extra step that each random edge is followed by a chance of
making an edge to one of its neighbors too (and thus a triangle).
This algorithm improves on BA in the sense that it enables a
higher average clustering to be attained if desired.
It seems possible to have a disconnected graph with this algorithm
since the initial `m` nodes may not be all linked to a new node
on the first iteration like the BA model.
Raises
------
NetworkXError
If `m` does not satisfy ``1 <= m <= n`` or `p` does not
satisfy ``0 <= p <= 1``.
References
----------
.. [1] P. Holme and B. J. Kim,
"Growing scale-free networks with tunable clustering",
Phys. Rev. E, 65, 026107, 2002.
| 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, p, seed=None, *, backend=None, **backend_kwargs) | [
0.003537906799465418,
0.0015090598026290536,
0.015320549719035625,
0.004910432733595371,
-0.02494978718459606,
-0.0408547967672348,
-0.0648464560508728,
-0.036294084042310715,
0.01211080327630043,
-0.030066218227148056,
0.006457817740738392,
0.041966233402490616,
-0.036830637603998184,
0.1071576178073883,
-0.043039340525865555,
0.013049773871898651,
0.03466525673866272,
0.04740842804312706,
-0.005897309631109238,
0.027345120906829834,
-0.0400499664247036,
0.0019869287498295307,
0.00009296886128140613,
0.0710168331861496,
-0.03455028310418129,
0.010721510276198387,
-0.039130158722400665,
0.010759835131466389,
-0.015598407946527004,
0.05928928032517433,
0.039245136082172394,
-0.12348420172929764,
0.020983116701245308,
0.0390726700425148,
-0.00014147434558253735,
0.010175374336540699,
0.02769004926085472,
0.06116722151637077,
-0.10953378677368164,
-0.036792315542697906,
0.07090185582637787,
-0.05541842430830002,
0.08339591324329376,
0.01310726162046194,
0.024700673297047615,
-0.02389584109187126,
0.030947702005505562,
0.012973123230040073,
-0.09650317579507828,
-0.009830445982515812,
0.01611579954624176,
-0.0705185979604721,
0.02621452324092388,
-0.0023833562154322863,
-0.020408237352967262,
0.018444063141942024,
-0.0031283048447221518,
0.044610679149627686,
0.017840439453721046,
0.025313878431916237,
0.06300684064626694,
-0.019545916467905045,
-0.01459236815571785,
-0.03525929898023605,
-0.02445155940949917,
0.021998737007379532,
-0.04855819046497345,
-0.026789404451847076,
-0.001455164747312665,
0.06204870343208313,
0.05035948008298874,
0.06407994776964188,
-0.008077062666416168,
0.05511182174086571,
0.054728567600250244,
0.0442657507956028,
0.048634838312864304,
0.027038518339395523,
-0.05212244391441345,
0.019718380644917488,
0.004194227978587151,
-0.02581210806965828,
0.01180420070886612,
-0.03432033210992813,
0.005490103270858526,
-0.015473851002752781,
0.006036239210516214,
0.003147467505186796,
0.0002807030687108636,
-0.10186871886253357,
-0.048596516251564026,
-0.04986124858260155,
0.05568670108914375,
0.016336170956492424,
0.03159923106431961,
-0.03328554704785347,
-0.006304516457021236,
-0.03234657645225525,
0.007516554556787014,
-0.024566534906625748,
-0.0450705848634243,
0.04369087144732475,
-0.038172025233507156,
0.0005952402134425938,
0.0065057240426540375,
0.007209951989352703,
-0.05216076970100403,
0.015138504095375538,
0.02084897831082344,
-0.03537427634000778,
-0.11712219566106796,
0.0436142235994339,
0.07979333400726318,
0.018242856487631798,
-0.022937707602977753,
-0.013279725797474384,
0.01500436570495367,
0.011622155085206032,
0.031963322311639786,
0.03221243619918823,
0.016307426616549492,
0.027096007019281387,
-0.03290229290723801,
-0.000196117878658697,
0.0007593205664306879,
-0.024068305268883705,
0.04825158789753914,
-0.008580083027482033,
-0.01290605403482914,
-0.03876606747508049,
0.010520302690565586,
0.014860645867884159,
-0.04706349968910217,
0.07017367333173752,
-0.012034152634441853,
-0.034396979957818985,
-0.04790665954351425,
0.005753589794039726,
0.06913889199495316,
0.004019368439912796,
-0.0008311805431731045,
-0.06683936715126038,
0.08899141103029251,
0.01290605403482914,
-0.03951341286301613,
-0.02150050923228264,
0.01721765287220478,
-0.05710473656654358,
0.0017976973904296756,
-0.012197035364806652,
0.0400499664247036,
-0.0012815031222999096,
0.020887304097414017,
-0.03455028310418129,
-0.039551738649606705,
0.017696719616651535,
-0.041506327688694,
-0.0003613958542700857,
-0.023205986246466637,
0.014688181690871716,
-0.030621936544775963,
-0.05465191602706909,
0.04874981567263603,
0.054306987673044205,
0.010098723694682121,
-0.03075607493519783,
0.04947799816727638,
0.0018683597445487976,
0.017438024282455444,
-0.03548925369977951,
-0.07431280612945557,
-0.001143771456554532,
-0.06607286632061005,
-0.06162712723016739,
0.05265899747610092,
-0.0021641834173351526,
-0.02602289617061615,
-0.031043514609336853,
0.02929971180856228,
0.03432033210992813,
0.03830616548657417,
-0.04729345440864563,
0.06779750436544418,
-0.05921262875199318,
-0.03064109943807125,
-0.035450927913188934,
-0.00637158565223217,
0.04300101846456528,
0.01806081086397171,
0.008541757240891457,
0.021366368979215622,
0.024815648794174194,
0.036159947514534,
0.06089894473552704,
0.025218065828084946,
0.005207453854382038,
0.02517974004149437,
0.01459236815571785,
-0.012915635481476784,
0.01111434493213892,
0.04560713842511177,
0.0021953226532787085,
0.020504049956798553,
0.02316766045987606,
0.027939163148403168,
0.0076794372871518135,
-0.03284480422735214,
-0.041966233402490616,
0.023148497566580772,
-0.02726846933364868,
0.004910432733595371,
-0.010472395457327366,
0.028571531176567078,
-0.027019355446100235,
-0.015397200360894203,
-0.06285353749990463,
0.0192105695605278,
0.017179327085614204,
-0.00008615713159088045,
-0.03493353724479675,
0.032078299671411514,
-0.058829378336668015,
0.010903555899858475,
0.02579294517636299,
0.005744008347392082,
0.043767523020505905,
-0.014582786709070206,
0.004048112779855728,
-0.01511934120208025,
0.028993109241127968,
0.03378377482295036,
-0.0008036341750994325,
0.03673482686281204,
-0.02834158018231392,
-0.03916848450899124,
-0.030200358480215073,
0.003092374885454774,
-0.03959006443619728,
-0.03579585626721382,
0.018971037119627,
-0.02937636338174343,
0.01981419324874878,
-0.020312422886490822,
-0.009011242538690567,
0.022267015650868416,
0.015560083091259003,
0.028284091502428055,
-0.05813952162861824,
-0.06852568686008453,
-0.01979503221809864,
-0.09336049854755402,
-0.01247489359229803,
0.024777323007583618,
0.03148425742983818,
0.02613787353038788,
-0.026463638991117477,
-0.02150050923228264,
0.009739424102008343,
-0.004000206012278795,
0.05859942361712456,
0.007166835945099592,
-0.02033158577978611,
-0.1112200990319252,
0.03169504553079605,
-0.0014743274077773094,
-0.005950007122009993,
-0.07074855268001556,
0.06952214241027832,
-0.013461771421134472,
-0.03131179139018059,
0.061780426651239395,
0.0006784780416637659,
0.00885315053164959,
0.00045062199933454394,
0.02698102965950966,
0.02339761145412922,
-0.012426987290382385,
0.019517172127962112,
-0.01960340514779091,
-0.04357589781284332,
-0.04127637669444084,
-0.043460920453071594,
0.024719836190342903,
0.04537718743085861,
-0.005863775033503771,
0.0041798558086156845,
-0.023320961743593216,
-0.06204870343208313,
0.02433658204972744,
-0.03351549804210663,
0.015435525216162205,
-0.028494881466031075,
0.005758380517363548,
0.05005287751555443,
-0.0017378140473738313,
-0.004840967711061239,
0.058637749403715134,
0.02349342592060566,
0.020159121602773666,
-0.008925010450184345,
0.037961237132549286,
-0.009677144698798656,
0.09113762527704239,
0.003961880691349506,
-0.01670026034116745,
-0.032059136778116226,
0.013643816113471985,
-0.025333041325211525,
-0.019871681928634644,
0.020044146105647087,
-0.09060107171535492,
0.02517974004149437,
0.05760296806693077,
0.030832724645733833,
-0.009451983496546745,
-0.06726095080375671,
0.011593411676585674,
0.0006659025675617158,
0.04047154635190964,
-0.003851695451885462,
-0.01733262836933136,
0.03748216852545738,
-0.001366537413559854,
0.0465269461274147,
-0.01757216267287731,
-0.002178555354475975,
0.04641197249293327,
0.07500266283750534,
0.0013365957420319319,
0.022286176681518555,
-0.04204288497567177,
0.01658528484404087,
-0.01064485963433981,
0.018798572942614555,
-0.08753504604101181,
0.08086644113063812,
-0.02749842219054699,
-0.02326347306370735,
0.06664774566888809,
-0.08600203692913055,
0.021653810515999794,
-0.04668024927377701,
-0.005221826024353504,
-0.010664022527635098,
0.04633532091975212,
0.044074125587940216,
0.012101221829652786,
-0.004096019547432661,
-0.05695143714547157,
0.06929218769073486,
-0.013653397560119629,
0.04192790761590004,
-0.002766609424725175,
0.02579294517636299,
-0.01916266418993473,
0.033534660935401917,
-0.0098496088758111,
0.0044936444610357285,
0.010165792889893055,
0.07028865069150925,
-0.023359287530183792,
-0.0056673577055335045,
-0.027766698971390724,
-0.013672560453414917,
0.027670886367559433,
0.006280562840402126,
0.002358205383643508,
0.043882500380277634,
0.03847862780094147,
-0.05254402384161949,
0.06975209712982178,
-0.06714597344398499,
-0.04510891065001488,
0.049248043447732925,
0.010405326262116432,
-0.028782321140170097,
-0.03771212324500084,
0.020044146105647087,
0.03211662545800209,
0.03305559605360031,
-0.012350336648523808,
-0.03959006443619728,
0.009964585304260254,
0.03959006443619728,
-0.006179959047585726,
-0.012043734081089497,
0.07258816808462143,
0.003760672640055418,
-0.00655363081023097,
-0.027019355446100235,
0.01284856628626585,
-0.029855430126190186,
0.07323969900608063,
0.007018325384706259,
-0.05499684438109398,
0.005068524274975061,
0.04116139933466911,
-0.026061221957206726,
-0.03709891811013222,
-0.003533116076141596,
0.002505518263205886,
0.016939794644713402,
-0.05055110529065132,
-0.023646727204322815,
-0.0056721484288573265,
-0.033956240862607956,
0.027843350544571877,
0.02803497575223446,
0.011296390555799007,
0.014966039918363094,
-0.015157666988670826,
0.02295687049627304,
-0.019028523936867714,
-0.011670062318444252,
0.023665890097618103,
-0.0010820917086675763,
-0.005916472524404526,
-0.020178284496068954,
0.010903555899858475,
0.014975621365010738,
0.03244239091873169,
-0.007775250822305679,
0.0065057240426540375,
-0.02487313747406006,
0.04411245137453079,
0.005815868265926838,
-0.05104933679103851,
0.019660891965031624,
-0.0815562978386879,
0.022094551473855972,
0.05396205931901932,
-0.03962838649749756,
0.033458009362220764,
-0.043039340525865555,
0.024624021723866463,
0.008556129410862923,
0.028935622423887253,
0.005365545861423016,
0.05679813399910927,
-0.02295687049627304,
0.01211080327630043,
0.02222868986427784,
0.011708387173712254,
-0.057449664920568466,
-0.029644640162587166,
-0.04568378999829292,
-0.02171129733324051,
-0.001282700803130865,
0.01606789417564869,
-0.020465724170207977,
-0.005729636177420616,
-0.00529368594288826,
0.0711701288819313,
-0.006726094987243414,
-0.04748507961630821,
0.035757530480623245,
0.05974918603897095,
-0.02801581472158432,
-0.034607771784067154,
0.10064230859279633,
0.014822320081293583,
0.00700395368039608,
0.01233117375522852,
0.0958133190870285,
0.034282006323337555,
-0.01918182522058487,
0.054192014038562775,
-0.020044146105647087,
-0.015263061039149761,
0.03803788870573044,
-0.019009362906217575,
0.0002275566221214831,
0.015560083091259003,
-0.03305559605360031,
-0.01679607480764389,
-0.038708578795194626,
-0.009442402049899101,
-0.03970503807067871,
-0.011373041197657585,
-0.011238901875913143,
0.017342209815979004,
0.004016973543912172,
0.010309512726962566,
0.032174110412597656,
0.022918544709682465,
-0.027766698971390724,
-0.035546742379665375,
0.0253713671118021,
0.012014989741146564,
0.0027091214433312416,
-0.07316304743289948,
-0.0800999328494072,
0.02232450246810913,
0.037022266536951065,
-0.05150923877954483,
-0.012647357769310474,
-0.01716974563896656,
-0.047983311116695404,
-0.007554879877716303,
-0.07634405046701431,
0.01927763968706131,
-0.011210158467292786,
-0.014659437350928783,
-0.04656527191400528,
0.0073632532730698586,
0.0004200815164949745,
-0.00216657854616642,
-0.0174284428358078,
0.0022108922712504864,
0.06342841684818268,
-0.00012800061085727066,
-0.02381919138133526,
0.03759714588522911,
0.03686896339058876,
-0.014611531049013138,
0.01627868227660656,
-0.008599244989454746,
0.0045607141219079494,
0.0513942651450634,
-0.028782321140170097,
0.034818559885025024,
0.034703582525253296,
0.03146509453654289,
-0.04595206677913666,
0.027536747977137566,
-0.008814824745059013,
0.01400790736079216,
-0.011085600592195988,
0.02150050923228264,
-0.007051859982311726,
-0.024700673297047615,
0.03640906140208244,
0.040088292211294174,
0.02012079581618309,
-0.010865230113267899,
-0.014027069322764874,
0.01006997935473919,
0.005451777949929237,
-0.05235239490866661,
-0.05170086771249771,
0.008239945396780968,
0.019268058240413666,
-0.007540508173406124,
-0.012676102109253407,
-0.006476980168372393,
-0.012973123230040073,
-0.040701497346162796,
0.0009263950050808489,
-0.012771915644407272,
-0.01922973245382309,
-0.002457611495628953,
0.015033109113574028,
-0.01850155182182789,
-0.02234366536140442,
0.00671651354059577,
-0.05652985721826553,
-0.0779920369386673,
0.048519864678382874,
0.06028573960065842,
0.024604860693216324,
-0.06714597344398499,
0.01500436570495367,
-0.02220952697098255,
0.0017905114218592644,
0.03778877109289169,
0.04307766631245613,
-0.024719836190342903,
-0.0013569560833275318,
-0.019574660807847977,
-0.010970625095069408,
0.02401081658899784,
0.0342053547501564,
0.030162032693624496,
0.01770630106329918,
-0.042924366891384125,
-0.007209951989352703,
-0.04970794916152954,
-0.05001455172896385,
-0.009830445982515812,
0.008925010450184345,
0.000021183725039009005,
0.06185707822442055,
-0.02274608239531517,
0.016336170956492424,
0.0442657507956028,
0.028475718572735786,
-0.02939552627503872,
0.0188081543892622,
0.0019474056316539645,
-0.02866734378039837,
-0.07688060402870178,
-0.022477803751826286,
0.032289087772369385,
-0.044610679149627686,
0.004730782471597195,
0.0423111617565155,
0.04767670854926109,
-0.015215154737234116,
-0.056721482425928116,
-0.07546257227659225,
0.03562339022755623,
0.032499875873327255,
0.0019701614510267973,
-0.0014994784723967314,
0.055150143802165985,
0.016786493360996246,
-0.0036193481646478176,
-0.06316013634204865,
0.02529471553862095,
0.0034684420097619295,
-0.03654319792985916,
-0.001748593058437109,
-0.027153493836522102,
-0.06381166726350784,
-0.03799956291913986,
-0.05396205931901932,
-0.045032259076833725,
0.0186452716588974,
0.023340124636888504,
0.047255128622055054,
-0.035431765019893646,
0.019833356142044067,
0.018252436071634293,
0.05108766257762909,
-0.025352204218506813,
-0.006170377600938082,
-0.025658806785941124,
-0.025735456496477127,
0.01576129160821438,
-0.0032408854458481073,
0.01668109931051731,
-0.05794789269566536,
0.0291847363114357,
-0.001885127043351531,
0.024585697799921036,
-0.02381919138133526,
0.05170086771249771,
0.00797645840793848,
0.0020252540707588196,
0.08776500076055527,
-0.06664774566888809,
0.010769416578114033,
-0.06335176527500153,
-0.003676836146041751,
-0.03782709687948227,
0.005734426900744438,
-0.020197447389364243,
0.019239313900470734,
0.010961043648421764,
-0.02600373513996601,
-0.022305339574813843,
0.0507427342236042,
0.0081058070063591,
-0.0031235141213983297,
-0.03278731554746628,
-0.0024252745788544416,
0.017811695113778114,
-0.005734426900744438,
-0.0030205147340893745,
-0.03414786607027054,
0.06591956317424774,
0.004608620423823595,
0.029012272134423256,
0.044189102947711945,
0.007818366400897503,
0.05813952162861824,
0.022631105035543442,
-0.03978168964385986,
-0.0366390123963356,
0.007842320017516613,
-0.028092464432120323,
-0.027440933510661125,
-0.006227865815162659,
-0.06511472910642624,
-0.04802163317799568,
0.0299129169434309,
-0.021328045055270195,
-0.0047738985158503056,
0.011497598141431808,
0.011986246332526207,
0.0773405134677887,
-0.002876794897019863,
-0.002946259453892708,
-0.0053415922448039055,
0.0016431984258815646,
0.050627756863832474,
-0.014774413779377937,
0.018194949254393578,
-0.05721971392631531,
-0.0022528106346726418,
0.021538833156228065,
-0.02517974004149437,
0.023455100134015083,
0.05032115429639816,
0.03865109384059906,
0.06392664462327957,
-0.02579294517636299,
-0.017294304445385933,
-0.053770434111356735,
-0.04752340540289879,
0.021193906664848328,
-0.03890020772814751,
-0.03604497015476227,
0.058177847415208817,
-0.07596080005168915,
0.03537427634000778,
-0.05112598463892937,
0.008987288922071457,
-0.03253820165991783,
0.010232862085103989,
-0.018079973757267,
-0.04530053585767746,
0.04920972138643265,
-0.00857529230415821,
0.004306808579713106,
-0.0402032695710659,
-0.005605079233646393,
0.031560905277729034,
-0.05453693866729736,
0.001576129114255309,
-0.0619337297976017,
-0.013806698843836784,
0.03612162172794342,
0.007377625443041325,
0.023838354274630547,
-0.008350130170583725,
0.03163755685091019,
-0.05373210832476616,
-0.01211080327630043,
-0.03610245883464813,
0.01422827783972025,
0.032825641334056854,
0.0013749210629612207,
0.015033109113574028,
-0.00384690472856164,
-0.03393707796931267,
0.011037694290280342,
0.0092411944642663,
0.023665890097618103,
0.00850343145430088,
0.01665235497057438,
0.0034253261983394623,
-0.052199095487594604,
0.04457235336303711,
-0.006117680110037327,
0.03600664436817169,
-0.030315333977341652,
0.00811538752168417,
0.008398037403821945,
0.0003272623580414802,
0.05453693866729736,
-0.017907509580254555,
-0.0186452716588974,
0.0549585185945034,
0.027670886367559433,
0.004982292652130127,
0.047983311116695404,
-0.029223062098026276,
-0.032078299671411514,
-0.07339300215244293,
-0.016317008063197136,
0.013653397560119629,
0.061895404011011124,
-0.04073982313275337,
-0.002276764018461108,
0.02065735124051571,
0.01592417247593403,
0.047140151262283325
]
|
31,019 | networkx.generators.trees | prefix_tree | Creates a directed prefix tree from a list of paths.
Usually the paths are described as strings or lists of integers.
A "prefix tree" represents the prefix structure of the strings.
Each node represents a prefix of some string. The root represents
the empty prefix with children for the single letter prefixes which
in turn have children for each double letter prefix starting with
the single letter corresponding to the parent node, and so on.
More generally the prefixes do not need to be strings. A prefix refers
to the start of a sequence. The root has children for each one element
prefix and they have children for each two element prefix that starts
with the one element sequence of the parent, and so on.
Note that this implementation uses integer nodes with an attribute.
Each node has an attribute "source" whose value is the original element
of the path to which this node corresponds. For example, suppose `paths`
consists of one path: "can". Then the nodes `[1, 2, 3]` which represent
this path have "source" values "c", "a" and "n".
All the descendants of a node have a common prefix in the sequence/path
associated with that node. From the returned tree, the prefix for each
node can be constructed by traversing the tree up to the root and
accumulating the "source" values along the way.
The root node is always `0` and has "source" attribute `None`.
The root is the only node with in-degree zero.
The nil node is always `-1` and has "source" attribute `"NIL"`.
The nil node is the only node with out-degree zero.
Parameters
----------
paths: iterable of paths
An iterable of paths which are themselves sequences.
Matching prefixes among these sequences are identified with
nodes of the prefix tree. One leaf of the tree is associated
with each path. (Identical paths are associated with the same
leaf of the tree.)
Returns
-------
tree: DiGraph
A directed graph representing an arborescence consisting of the
prefix tree generated by `paths`. Nodes are directed "downward",
from parent to child. A special "synthetic" root node is added
to be the parent of the first node in each path. A special
"synthetic" leaf node, the "nil" node `-1`, is added to be the child
of all nodes representing the last element in a path. (The
addition of this nil node technically makes this not an
arborescence but a directed acyclic graph; removing the nil node
makes it an arborescence.)
Notes
-----
The prefix tree is also known as a *trie*.
Examples
--------
Create a prefix tree from a list of strings with common prefixes::
>>> paths = ["ab", "abs", "ad"]
>>> T = nx.prefix_tree(paths)
>>> list(T.edges)
[(0, 1), (1, 2), (1, 4), (2, -1), (2, 3), (3, -1), (4, -1)]
The leaf nodes can be obtained as predecessors of the nil node::
>>> root, NIL = 0, -1
>>> list(T.predecessors(NIL))
[2, 3, 4]
To recover the original paths that generated the prefix tree,
traverse up the tree from the node `-1` to the node `0`::
>>> recovered = []
>>> for v in T.predecessors(NIL):
... prefix = ""
... while v != root:
... prefix = str(T.nodes[v]["source"]) + prefix
... v = next(T.predecessors(v)) # only one predecessor
... recovered.append(prefix)
>>> sorted(recovered)
['ab', 'abs', 'ad']
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (paths, *, backend=None, **backend_kwargs) | [
-0.028801551088690758,
-0.008935477584600449,
0.020405037328600883,
-0.029898392036557198,
0.03422902524471283,
0.08101499825716019,
-0.032451387494802475,
-0.009535904042422771,
0.07189986854791641,
-0.01257585734128952,
-0.010779306292533875,
0.08230095356702805,
-0.011639759875833988,
0.038881149142980576,
-0.01615004800260067,
0.002084944862872362,
-0.0005691048572771251,
0.04398713633418083,
0.023090409114956856,
-0.0017551830969750881,
-0.03328347206115723,
0.052648402750492096,
0.0058955242857337,
0.025113893672823906,
0.019289284944534302,
-0.018466653302311897,
0.00870381761342287,
-0.026588955894112587,
-0.03177058696746826,
0.007370586972683668,
-0.014400775544345379,
-0.016206782311201096,
-0.028574617579579353,
0.006907266099005938,
-0.01597984880208969,
-0.030900677666068077,
0.0172658022493124,
0.08101499825716019,
-0.04285247251391411,
-0.042814649641513824,
0.04984956607222557,
-0.05196760222315788,
0.0031746949534863234,
-0.015109940432012081,
-0.02074543759226799,
-0.003132144920527935,
0.06690734624862671,
0.03615795448422432,
-0.09727851301431656,
-0.03449378162622452,
-0.021350590512156487,
0.00456702196970582,
-0.020329393446445465,
0.011450649239122868,
-0.025265181437134743,
-0.02679697796702385,
-0.022447433322668076,
-0.03806797042489052,
0.07972904294729233,
-0.017974967136979103,
0.02991730347275734,
0.052459292113780975,
-0.04186909645795822,
-0.021823367103934288,
-0.024981515482068062,
-0.02248525433242321,
-0.10544808954000473,
0.030881768092513084,
-0.055749814957380295,
0.023184964433312416,
0.014845184981822968,
0.023109320551156998,
0.04527308791875839,
0.032167721539735794,
0.041528698056936264,
0.04485704377293587,
-0.005124898161739111,
0.013568688184022903,
0.004439372103661299,
0.03197861090302467,
-0.02910412661731243,
-0.011006238870322704,
0.03269723057746887,
-0.0021995932329446077,
-0.018854331225156784,
-0.04799627885222435,
0.02184227854013443,
0.038881149142980576,
0.03774648532271385,
-0.07473652809858322,
-0.0023981593549251556,
-0.023374075070023537,
0.004633210599422455,
-0.0189394298940897,
-0.013228288851678371,
0.0012457662960514426,
0.05102204903960228,
-0.03441813588142395,
0.011280450038611889,
-0.06078016012907028,
0.027496686205267906,
-0.02936888299882412,
-0.05295097827911377,
0.011204805225133896,
-0.045197442173957825,
0.020802170038223267,
-0.05412346497178078,
0.05295097827911377,
-0.02101019211113453,
0.016187870875000954,
-0.08638574182987213,
0.007867002859711647,
0.0731101706624031,
0.002061306033283472,
0.01974315010011196,
-0.01776694506406784,
-0.025170626118779182,
0.0008586805197410285,
-0.013786165975034237,
-0.014438597485423088,
0.030541367828845978,
0.00889765564352274,
-0.020613059401512146,
-0.007852819748222828,
0.010457818396389484,
0.03056027926504612,
0.04459228739142418,
-0.040696609765291214,
-0.024660026654601097,
-0.019516218453645706,
0.03818143904209137,
0.051059871912002563,
0.028404418379068375,
0.04534872993826866,
-0.009956675581634045,
-0.023903584107756615,
-0.07496345788240433,
-0.009720287285745144,
0.032999806106090546,
-0.030446812510490417,
0.0025482659693807364,
-0.08774733543395996,
0.06940360367298126,
0.044932689517736435,
0.039335012435913086,
0.050341252237558365,
0.02193683385848999,
-0.0188165083527565,
-0.018655763939023018,
-0.01612168177962303,
0.02891501598060131,
-0.02448982745409012,
0.031808409839868546,
-0.0008492249762639403,
-0.029955124482512474,
0.010287619195878506,
0.018977252766489983,
-0.08562929928302765,
-0.058056965470314026,
-0.0252462700009346,
-0.00738949840888381,
0.031259987503290176,
0.0247734934091568,
-0.05404781922698021,
-0.06297384202480316,
0.018589576706290245,
-0.019327107816934586,
-0.035571713000535965,
-0.019970083609223366,
0.0017469095764681697,
-0.05714923515915871,
0.002064851811155677,
-0.04848796874284744,
-0.016159504652023315,
0.0017859135987237096,
-0.024376360699534416,
-0.05956985056400299,
0.005195814650505781,
-0.04285247251391411,
0.04258771613240242,
-0.02286347560584545,
-0.06925231963396072,
-0.012036892585456371,
-0.05128680542111397,
-0.041793450713157654,
0.04818538948893547,
0.022882387042045593,
0.02112365886569023,
-0.023544274270534515,
0.010410540737211704,
0.03967541083693504,
-0.019591862335801125,
0.03759519383311272,
0.06373028457164764,
0.04436535760760307,
-0.0321488082408905,
-0.026683511212468147,
-0.003366169286891818,
-0.03426684811711311,
0.03723588585853577,
0.07140817493200302,
0.04591606184840202,
0.032905250787734985,
-0.01660391502082348,
0.006349389906972647,
-0.011630304157733917,
-0.03782212734222412,
-0.0005924481665715575,
0.04708854854106903,
0.022693276405334473,
0.017644023522734642,
-0.0026191824581474066,
0.027402130886912346,
0.08472156524658203,
-0.08230095356702805,
-0.023468630388379097,
-0.040885720402002335,
0.004916876554489136,
-0.03655508533120155,
-0.0471641942858696,
-0.0502656064927578,
0.027553420513868332,
0.02863135002553463,
-0.0036191048566251993,
-0.005881340708583593,
0.02653222344815731,
0.007777174934744835,
0.02295803092420101,
0.023014765232801437,
-0.047391127794981,
0.061801355332136154,
-0.04444099962711334,
0.050719473510980606,
-0.041982561349868774,
-0.046672504395246506,
-0.0657348558306694,
0.0635790005326271,
-0.05904034152626991,
0.0051627205684781075,
0.029595814645290375,
-0.06316295266151428,
-0.027137376368045807,
-0.008935477584600449,
-0.02615400217473507,
0.0423986054956913,
0.059796784073114395,
-0.05219453573226929,
0.010334896855056286,
-0.054010000079870224,
-0.0345316044986248,
-0.04867707937955856,
-0.033642783761024475,
0.012831157073378563,
-0.01481681875884533,
0.06804201006889343,
-0.02844223938882351,
-0.030957411974668503,
-0.0295390821993351,
0.010051230899989605,
0.055295951664447784,
-0.0056307693012058735,
-0.026362022385001183,
-0.06475148350000381,
0.07276977598667145,
-0.02460329420864582,
-0.05283751338720322,
-0.03415338322520256,
0.04432753473520279,
0.023449718952178955,
-0.03150583431124687,
0.05711141228675842,
0.03212989866733551,
0.04901747778058052,
-0.02596489153802395,
-0.0012883162125945091,
-0.009488626383244991,
0.0036403797566890717,
0.04875272139906883,
-0.006188645493239164,
0.029898392036557198,
-0.013767254538834095,
0.012982445769011974,
0.008940205909311771,
0.027194110676646233,
-0.044932689517736435,
0.042096029967069626,
-0.05261057987809181,
-0.007871730253100395,
0.007474598009139299,
-0.023544274270534515,
0.0657348558306694,
-0.04296593740582466,
-0.016263514757156372,
-0.00150933931581676,
-0.025567758828401566,
-0.04243642836809158,
-0.03129781037569046,
-0.014646618627011776,
-0.014362952671945095,
0.0316760316491127,
0.03536368906497955,
-0.03201643005013466,
0.015478705987334251,
-0.029898392036557198,
0.08910893648862839,
0.04856361076235771,
0.016424259170889854,
-0.02670242264866829,
-0.03284851834177971,
0.038408372551202774,
-0.029898392036557198,
-0.00016606277495156974,
0.07167293131351471,
-0.04856361076235771,
0.007422592490911484,
-0.11127270013093948,
-0.0005918571841903031,
-0.08139321953058243,
0.049698274582624435,
-0.015403061173856258,
-0.03829490393400192,
0.01528959535062313,
-0.019780972972512245,
0.005096531938761473,
0.00957372598350048,
0.011734315194189548,
0.03379407152533531,
0.023166052997112274,
-0.04909312352538109,
0.03818143904209137,
-0.02036721631884575,
-0.031146522611379623,
0.010769850574433804,
0.037633016705513,
-0.08994101732969284,
0.026172911748290062,
0.06270908564329147,
0.021180391311645508,
0.0009396434761583805,
-0.07284542173147202,
-0.03201643005013466,
0.0308439452201128,
-0.040053632110357285,
0.013114823028445244,
-0.015752917155623436,
0.07345057278871536,
0.05450168624520302,
0.014485875144600868,
-0.010070141404867172,
0.039977990090847015,
0.0252462700009346,
0.049963030964136124,
0.0022669637110084295,
0.01541251689195633,
0.02231505513191223,
0.05011431872844696,
-0.000036473975342232734,
0.06785289943218231,
-0.009096221998333931,
0.01523286197334528,
-0.01510048471391201,
-0.06425979733467102,
0.03160038962960243,
-0.04028056561946869,
0.031184343621134758,
-0.011356093920767307,
0.007309126202017069,
0.06399504095315933,
-0.033188916742801666,
-0.039977990090847015,
-0.03689548745751381,
-0.09198341518640518,
-0.11467669159173965,
0.05366959795355797,
0.051362451165914536,
0.0025482659693807364,
-0.040431853383779526,
-0.03341585025191307,
-0.00299503980204463,
0.038956791162490845,
-0.02377120777964592,
-0.032092075794935226,
0.05113551765680313,
0.027553420513868332,
-0.009498082101345062,
-0.037633016705513,
0.04863925650715828,
0.02212594449520111,
-0.024754581972956657,
-0.029425615444779396,
-0.01753055676817894,
-0.021634256467223167,
0.032735053449869156,
0.03110869973897934,
-0.022655455395579338,
0.04304158315062523,
0.09009230881929398,
0.006945088040083647,
-0.0440627783536911,
-0.020442860201001167,
0.03479635715484619,
0.05238364636898041,
-0.00021496560657396913,
0.00890711136162281,
0.006221740040928125,
0.003994962200522423,
-0.0018591940170153975,
-0.03201643005013466,
-0.014656074345111847,
-0.04765588045120239,
0.018305910751223564,
0.04599170759320259,
0.034058827906847,
-0.03948630020022392,
0.07031133770942688,
-0.017918232828378677,
0.02074543759226799,
0.07068955898284912,
0.04671032726764679,
-0.02450873889029026,
0.03194078803062439,
-0.05714923515915871,
0.03103305585682392,
0.08154451102018356,
0.07087866961956024,
0.022712187841534615,
0.04599170759320259,
-0.03065483458340168,
0.00834923516958952,
0.0743204802274704,
-0.01233946904540062,
-0.03842728212475777,
-0.010656384751200676,
0.03141127899289131,
0.04099918529391289,
-0.046029530465602875,
-0.03615795448422432,
-0.019185274839401245,
-0.06713427603244781,
0.01889215223491192,
0.004600116517394781,
0.06512970477342606,
0.059985894709825516,
-0.00438736705109477,
0.05268622562289238,
0.014069831930100918,
0.008174307644367218,
0.052459292113780975,
0.02119930274784565,
-0.05041689798235893,
0.013559232465922832,
-0.04856361076235771,
0.017086146399378777,
0.013701065443456173,
-0.043268512934446335,
0.03101414442062378,
-0.03829490393400192,
0.05609021708369255,
-0.059607673436403275,
0.025851424783468246,
0.03462615981698036,
0.029141949489712715,
-0.01991335116326809,
0.028290951624512672,
0.036309242248535156,
-0.06917667388916016,
0.03723588585853577,
-0.022806743159890175,
0.002467893762513995,
-0.041793450713157654,
0.04092354327440262,
0.020215926691889763,
-0.015781283378601074,
0.01615004800260067,
0.023449718952178955,
-0.008472156710922718,
-0.029425615444779396,
-0.02598380111157894,
-0.03975105658173561,
-0.06006154045462608,
0.005328192375600338,
0.00925223808735609,
0.05983460694551468,
-0.02458438277244568,
-0.0659617930650711,
-0.05385870859026909,
-0.00106729322578758,
0.020953459665179253,
0.037500638514757156,
-0.04175562784075737,
-0.04534872993826866,
-0.06857151538133621,
-0.008008835837244987,
-0.019346019253134727,
-0.04848796874284744,
0.025567758828401566,
-0.015989305451512337,
-0.020140282809734344,
0.03865421563386917,
-0.0041037010960280895,
0.0295390821993351,
0.003351986175402999,
0.012651502154767513,
0.021501880139112473,
0.022258322685956955,
0.044554468244314194,
0.028782639652490616,
-0.011460104957222939,
0.024206161499023438,
0.01724689081311226,
0.0378788597881794,
0.004897965583950281,
0.0455000214278698,
0.014041464775800705,
0.04792063683271408,
0.0455000214278698,
0.01463716384023428,
-0.02203138917684555,
0.03417229279875755,
0.02743995375931263,
0.013644332997500896,
0.04205820709466934,
0.02341189794242382,
0.02121821418404579,
0.012424568645656109,
-0.00902530550956726,
0.017426544800400734,
0.02460329420864582,
0.02248525433242321,
0.024830227717757225,
0.02350645326077938,
-0.018835419788956642,
-0.02167207933962345,
0.04935787618160248,
0.005384925287216902,
-0.02212594449520111,
-0.03636597469449043,
0.0030139507725834846,
0.011809959076344967,
-0.029236504808068275,
-0.008027746342122555,
-0.01600821502506733,
0.001375779858790338,
0.009417709894478321,
0.0123867467045784,
-0.013417399488389492,
0.03846510499715805,
-0.024073785170912743,
0.011441193521022797,
-0.01612168177962303,
0.03460724651813507,
-0.00029947442817501724,
0.028801551088690758,
-0.021615346893668175,
0.08487285673618317,
-0.06966836005449295,
-0.00635884515941143,
-0.02789381891489029,
-0.01137500535696745,
0.0038625847082585096,
-0.020688703283667564,
0.03922154754400253,
0.04489486664533615,
-0.043003760278224945,
0.0655079260468483,
0.025170626118779182,
-0.054199110716581345,
0.017067234963178635,
-0.006023173686116934,
-0.04202038422226906,
-0.027023909613490105,
0.023014765232801437,
0.03627141937613487,
-0.03203534334897995,
-0.03074938990175724,
0.0022043208591639996,
-0.05056818574666977,
-0.025643402710556984,
-0.010977872647345066,
-0.02329843118786812,
0.0031605116091668606,
0.0009591455454938114,
0.026475489139556885,
-0.003928773570805788,
0.028026197105646133,
0.05219453573226929,
-0.026645688340067863,
0.04130176454782486,
0.001412420067936182,
0.01729416847229004,
0.005626041442155838,
-0.0232227873057127,
0.0678907185792923,
0.019346019253134727,
0.0023745205253362656,
-0.004278628155589104,
-0.013767254538834095,
-0.015667816624045372,
-0.011053516529500484,
-0.027213020250201225,
0.04981174319982529,
0.0609692707657814,
-0.018542299047112465,
0.057489633560180664,
0.012320558540523052,
0.001398236840032041,
0.0059711686335504055,
-0.06395722180604935,
0.007890641689300537,
0.009053671732544899,
0.005285642575472593,
0.011261538602411747,
-0.010599651373922825,
-0.05745181068778038,
0.01541251689195633,
0.0031746949534863234,
-0.03163820877671242,
0.015809649601578712,
-0.008651811629533768,
-0.05003867670893669,
-0.0012256733607500792,
-0.000694390619173646,
-0.010977872647345066,
-0.010249796323478222,
-0.01710505783557892,
-0.05170284956693649,
-0.0031486921943724155,
-0.018060065805912018,
-0.052156712859869,
0.02762906439602375,
0.02672133408486843,
-0.03056027926504612,
-0.011762681417167187,
-0.038408372551202774,
-0.0359688438475132,
-0.012859523296356201,
0.03649835288524628,
-0.013464677147567272,
-0.017974967136979103,
0.057224880903959274,
-0.0235820971429348,
-0.020858904346823692,
-0.024376360699534416,
-0.033264562487602234,
-0.0006506587960757315,
-0.07269413024187088,
-0.040053632110357285,
-0.003782212734222412,
-0.0015743460971862078,
-0.025719046592712402,
-0.02284456603229046,
0.009748653508722782,
0.042549893260002136,
-0.0017729122191667557,
0.0018391009652987123,
-0.007058554794639349,
-0.02276892028748989,
-0.003477271879091859,
0.006604689173400402,
-0.006699244491755962,
-0.00218186411075294,
0.018835419788956642,
0.010051230899989605,
0.06342770904302597,
-0.017379267141222954,
0.022504165768623352,
0.019762061536312103,
-0.026210734620690346,
-0.02201247774064541,
0.04194473847746849,
-0.028139663860201836,
-0.04973609745502472,
0.04682379588484764,
-0.028763728216290474,
-0.0248869601637125,
0.003337802831083536,
-0.033529315143823624,
0.056392792612314224,
0.010524007491767406,
-0.021445145830512047,
0.04935787618160248,
0.022693276405334473,
-0.022882387042045593,
-0.02157752402126789,
-0.008150668814778328,
0.032073166221380234,
-0.044554468244314194,
-0.005143809597939253,
0.01912854053080082,
0.011828870512545109,
-0.009720287285745144,
0.0011701220646500587,
0.045840419828891754,
0.0702735111117363,
-0.052724044770002365,
0.017738578841090202,
-0.012887890450656414,
0.014079286716878414,
-0.04754241555929184,
-0.0012587676756083965,
0.06482712924480438,
-0.0392971895635128,
-0.037954505532979965,
0.006926177069544792,
-0.05060600861907005,
0.039788879454135895,
-0.04553784057497978,
0.047769349068403244,
-0.029123038053512573,
0.03903243690729141,
-0.02715628780424595,
0.0006731156609021127,
-0.018665220588445663,
-0.018466653302311897,
-0.0416799858212471,
-0.03056027926504612,
0.02469784952700138,
0.05975896120071411,
-0.08631009608507156,
-0.013445766642689705,
0.005195814650505781,
-0.022163767367601395,
-0.00010135148477274925,
0.03891896829009056,
0.004897965583950281,
0.009460260160267353,
0.06815547496080399,
-0.07534167915582657,
-0.018154621124267578,
-0.0006435671239160001,
0.018740864470601082,
0.05204324796795845,
0.016821391880512238,
-0.057413991540670395,
-0.018608486279845238,
-0.02579469047486782,
0.015213950537145138,
0.02908521704375744,
-0.03056027926504612,
-0.03634706512093544,
-0.004314086399972439,
0.015299051068723202,
-0.05351831018924713,
0.005347103346139193,
0.019383840262889862,
-0.025113893672823906,
0.040242742747068405,
0.012651502154767513,
0.04958480969071388,
-0.013776710256934166,
0.037141330540180206,
0.028328774496912956,
-0.009460260160267353,
0.00442518899217248,
0.025000426918268204,
0.020083550363779068,
-0.0023130595218390226,
-0.01765347830951214,
0.000963873288128525,
-0.04285247251391411,
-0.011639759875833988,
-0.02779926359653473,
-0.059153806418180466,
-0.0018781049875542521,
0.00028987115365453064,
0.01175322663038969,
0.02761015295982361,
0.005195814650505781
]
|
31,020 | networkx.generators.trees | prefix_tree_recursive | Recursively creates a directed prefix tree from a list of paths.
The original recursive version of prefix_tree for comparison. It is
the same algorithm but the recursion is unrolled onto a stack.
Usually the paths are described as strings or lists of integers.
A "prefix tree" represents the prefix structure of the strings.
Each node represents a prefix of some string. The root represents
the empty prefix with children for the single letter prefixes which
in turn have children for each double letter prefix starting with
the single letter corresponding to the parent node, and so on.
More generally the prefixes do not need to be strings. A prefix refers
to the start of a sequence. The root has children for each one element
prefix and they have children for each two element prefix that starts
with the one element sequence of the parent, and so on.
Note that this implementation uses integer nodes with an attribute.
Each node has an attribute "source" whose value is the original element
of the path to which this node corresponds. For example, suppose `paths`
consists of one path: "can". Then the nodes `[1, 2, 3]` which represent
this path have "source" values "c", "a" and "n".
All the descendants of a node have a common prefix in the sequence/path
associated with that node. From the returned tree, ehe prefix for each
node can be constructed by traversing the tree up to the root and
accumulating the "source" values along the way.
The root node is always `0` and has "source" attribute `None`.
The root is the only node with in-degree zero.
The nil node is always `-1` and has "source" attribute `"NIL"`.
The nil node is the only node with out-degree zero.
Parameters
----------
paths: iterable of paths
An iterable of paths which are themselves sequences.
Matching prefixes among these sequences are identified with
nodes of the prefix tree. One leaf of the tree is associated
with each path. (Identical paths are associated with the same
leaf of the tree.)
Returns
-------
tree: DiGraph
A directed graph representing an arborescence consisting of the
prefix tree generated by `paths`. Nodes are directed "downward",
from parent to child. A special "synthetic" root node is added
to be the parent of the first node in each path. A special
"synthetic" leaf node, the "nil" node `-1`, is added to be the child
of all nodes representing the last element in a path. (The
addition of this nil node technically makes this not an
arborescence but a directed acyclic graph; removing the nil node
makes it an arborescence.)
Notes
-----
The prefix tree is also known as a *trie*.
Examples
--------
Create a prefix tree from a list of strings with common prefixes::
>>> paths = ["ab", "abs", "ad"]
>>> T = nx.prefix_tree(paths)
>>> list(T.edges)
[(0, 1), (1, 2), (1, 4), (2, -1), (2, 3), (3, -1), (4, -1)]
The leaf nodes can be obtained as predecessors of the nil node.
>>> root, NIL = 0, -1
>>> list(T.predecessors(NIL))
[2, 3, 4]
To recover the original paths that generated the prefix tree,
traverse up the tree from the node `-1` to the node `0`::
>>> recovered = []
>>> for v in T.predecessors(NIL):
... prefix = ""
... while v != root:
... prefix = str(T.nodes[v]["source"]) + prefix
... v = next(T.predecessors(v)) # only one predecessor
... recovered.append(prefix)
>>> sorted(recovered)
['ab', 'abs', 'ad']
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (paths, *, backend=None, **backend_kwargs) | [
-0.028801551088690758,
-0.008935477584600449,
0.020405037328600883,
-0.029898392036557198,
0.03422902524471283,
0.08101499825716019,
-0.032451387494802475,
-0.009535904042422771,
0.07189986854791641,
-0.01257585734128952,
-0.010779306292533875,
0.08230095356702805,
-0.011639759875833988,
0.038881149142980576,
-0.01615004800260067,
0.002084944862872362,
-0.0005691048572771251,
0.04398713633418083,
0.023090409114956856,
-0.0017551830969750881,
-0.03328347206115723,
0.052648402750492096,
0.0058955242857337,
0.025113893672823906,
0.019289284944534302,
-0.018466653302311897,
0.00870381761342287,
-0.026588955894112587,
-0.03177058696746826,
0.007370586972683668,
-0.014400775544345379,
-0.016206782311201096,
-0.028574617579579353,
0.006907266099005938,
-0.01597984880208969,
-0.030900677666068077,
0.0172658022493124,
0.08101499825716019,
-0.04285247251391411,
-0.042814649641513824,
0.04984956607222557,
-0.05196760222315788,
0.0031746949534863234,
-0.015109940432012081,
-0.02074543759226799,
-0.003132144920527935,
0.06690734624862671,
0.03615795448422432,
-0.09727851301431656,
-0.03449378162622452,
-0.021350590512156487,
0.00456702196970582,
-0.020329393446445465,
0.011450649239122868,
-0.025265181437134743,
-0.02679697796702385,
-0.022447433322668076,
-0.03806797042489052,
0.07972904294729233,
-0.017974967136979103,
0.02991730347275734,
0.052459292113780975,
-0.04186909645795822,
-0.021823367103934288,
-0.024981515482068062,
-0.02248525433242321,
-0.10544808954000473,
0.030881768092513084,
-0.055749814957380295,
0.023184964433312416,
0.014845184981822968,
0.023109320551156998,
0.04527308791875839,
0.032167721539735794,
0.041528698056936264,
0.04485704377293587,
-0.005124898161739111,
0.013568688184022903,
0.004439372103661299,
0.03197861090302467,
-0.02910412661731243,
-0.011006238870322704,
0.03269723057746887,
-0.0021995932329446077,
-0.018854331225156784,
-0.04799627885222435,
0.02184227854013443,
0.038881149142980576,
0.03774648532271385,
-0.07473652809858322,
-0.0023981593549251556,
-0.023374075070023537,
0.004633210599422455,
-0.0189394298940897,
-0.013228288851678371,
0.0012457662960514426,
0.05102204903960228,
-0.03441813588142395,
0.011280450038611889,
-0.06078016012907028,
0.027496686205267906,
-0.02936888299882412,
-0.05295097827911377,
0.011204805225133896,
-0.045197442173957825,
0.020802170038223267,
-0.05412346497178078,
0.05295097827911377,
-0.02101019211113453,
0.016187870875000954,
-0.08638574182987213,
0.007867002859711647,
0.0731101706624031,
0.002061306033283472,
0.01974315010011196,
-0.01776694506406784,
-0.025170626118779182,
0.0008586805197410285,
-0.013786165975034237,
-0.014438597485423088,
0.030541367828845978,
0.00889765564352274,
-0.020613059401512146,
-0.007852819748222828,
0.010457818396389484,
0.03056027926504612,
0.04459228739142418,
-0.040696609765291214,
-0.024660026654601097,
-0.019516218453645706,
0.03818143904209137,
0.051059871912002563,
0.028404418379068375,
0.04534872993826866,
-0.009956675581634045,
-0.023903584107756615,
-0.07496345788240433,
-0.009720287285745144,
0.032999806106090546,
-0.030446812510490417,
0.0025482659693807364,
-0.08774733543395996,
0.06940360367298126,
0.044932689517736435,
0.039335012435913086,
0.050341252237558365,
0.02193683385848999,
-0.0188165083527565,
-0.018655763939023018,
-0.01612168177962303,
0.02891501598060131,
-0.02448982745409012,
0.031808409839868546,
-0.0008492249762639403,
-0.029955124482512474,
0.010287619195878506,
0.018977252766489983,
-0.08562929928302765,
-0.058056965470314026,
-0.0252462700009346,
-0.00738949840888381,
0.031259987503290176,
0.0247734934091568,
-0.05404781922698021,
-0.06297384202480316,
0.018589576706290245,
-0.019327107816934586,
-0.035571713000535965,
-0.019970083609223366,
0.0017469095764681697,
-0.05714923515915871,
0.002064851811155677,
-0.04848796874284744,
-0.016159504652023315,
0.0017859135987237096,
-0.024376360699534416,
-0.05956985056400299,
0.005195814650505781,
-0.04285247251391411,
0.04258771613240242,
-0.02286347560584545,
-0.06925231963396072,
-0.012036892585456371,
-0.05128680542111397,
-0.041793450713157654,
0.04818538948893547,
0.022882387042045593,
0.02112365886569023,
-0.023544274270534515,
0.010410540737211704,
0.03967541083693504,
-0.019591862335801125,
0.03759519383311272,
0.06373028457164764,
0.04436535760760307,
-0.0321488082408905,
-0.026683511212468147,
-0.003366169286891818,
-0.03426684811711311,
0.03723588585853577,
0.07140817493200302,
0.04591606184840202,
0.032905250787734985,
-0.01660391502082348,
0.006349389906972647,
-0.011630304157733917,
-0.03782212734222412,
-0.0005924481665715575,
0.04708854854106903,
0.022693276405334473,
0.017644023522734642,
-0.0026191824581474066,
0.027402130886912346,
0.08472156524658203,
-0.08230095356702805,
-0.023468630388379097,
-0.040885720402002335,
0.004916876554489136,
-0.03655508533120155,
-0.0471641942858696,
-0.0502656064927578,
0.027553420513868332,
0.02863135002553463,
-0.0036191048566251993,
-0.005881340708583593,
0.02653222344815731,
0.007777174934744835,
0.02295803092420101,
0.023014765232801437,
-0.047391127794981,
0.061801355332136154,
-0.04444099962711334,
0.050719473510980606,
-0.041982561349868774,
-0.046672504395246506,
-0.0657348558306694,
0.0635790005326271,
-0.05904034152626991,
0.0051627205684781075,
0.029595814645290375,
-0.06316295266151428,
-0.027137376368045807,
-0.008935477584600449,
-0.02615400217473507,
0.0423986054956913,
0.059796784073114395,
-0.05219453573226929,
0.010334896855056286,
-0.054010000079870224,
-0.0345316044986248,
-0.04867707937955856,
-0.033642783761024475,
0.012831157073378563,
-0.01481681875884533,
0.06804201006889343,
-0.02844223938882351,
-0.030957411974668503,
-0.0295390821993351,
0.010051230899989605,
0.055295951664447784,
-0.0056307693012058735,
-0.026362022385001183,
-0.06475148350000381,
0.07276977598667145,
-0.02460329420864582,
-0.05283751338720322,
-0.03415338322520256,
0.04432753473520279,
0.023449718952178955,
-0.03150583431124687,
0.05711141228675842,
0.03212989866733551,
0.04901747778058052,
-0.02596489153802395,
-0.0012883162125945091,
-0.009488626383244991,
0.0036403797566890717,
0.04875272139906883,
-0.006188645493239164,
0.029898392036557198,
-0.013767254538834095,
0.012982445769011974,
0.008940205909311771,
0.027194110676646233,
-0.044932689517736435,
0.042096029967069626,
-0.05261057987809181,
-0.007871730253100395,
0.007474598009139299,
-0.023544274270534515,
0.0657348558306694,
-0.04296593740582466,
-0.016263514757156372,
-0.00150933931581676,
-0.025567758828401566,
-0.04243642836809158,
-0.03129781037569046,
-0.014646618627011776,
-0.014362952671945095,
0.0316760316491127,
0.03536368906497955,
-0.03201643005013466,
0.015478705987334251,
-0.029898392036557198,
0.08910893648862839,
0.04856361076235771,
0.016424259170889854,
-0.02670242264866829,
-0.03284851834177971,
0.038408372551202774,
-0.029898392036557198,
-0.00016606277495156974,
0.07167293131351471,
-0.04856361076235771,
0.007422592490911484,
-0.11127270013093948,
-0.0005918571841903031,
-0.08139321953058243,
0.049698274582624435,
-0.015403061173856258,
-0.03829490393400192,
0.01528959535062313,
-0.019780972972512245,
0.005096531938761473,
0.00957372598350048,
0.011734315194189548,
0.03379407152533531,
0.023166052997112274,
-0.04909312352538109,
0.03818143904209137,
-0.02036721631884575,
-0.031146522611379623,
0.010769850574433804,
0.037633016705513,
-0.08994101732969284,
0.026172911748290062,
0.06270908564329147,
0.021180391311645508,
0.0009396434761583805,
-0.07284542173147202,
-0.03201643005013466,
0.0308439452201128,
-0.040053632110357285,
0.013114823028445244,
-0.015752917155623436,
0.07345057278871536,
0.05450168624520302,
0.014485875144600868,
-0.010070141404867172,
0.039977990090847015,
0.0252462700009346,
0.049963030964136124,
0.0022669637110084295,
0.01541251689195633,
0.02231505513191223,
0.05011431872844696,
-0.000036473975342232734,
0.06785289943218231,
-0.009096221998333931,
0.01523286197334528,
-0.01510048471391201,
-0.06425979733467102,
0.03160038962960243,
-0.04028056561946869,
0.031184343621134758,
-0.011356093920767307,
0.007309126202017069,
0.06399504095315933,
-0.033188916742801666,
-0.039977990090847015,
-0.03689548745751381,
-0.09198341518640518,
-0.11467669159173965,
0.05366959795355797,
0.051362451165914536,
0.0025482659693807364,
-0.040431853383779526,
-0.03341585025191307,
-0.00299503980204463,
0.038956791162490845,
-0.02377120777964592,
-0.032092075794935226,
0.05113551765680313,
0.027553420513868332,
-0.009498082101345062,
-0.037633016705513,
0.04863925650715828,
0.02212594449520111,
-0.024754581972956657,
-0.029425615444779396,
-0.01753055676817894,
-0.021634256467223167,
0.032735053449869156,
0.03110869973897934,
-0.022655455395579338,
0.04304158315062523,
0.09009230881929398,
0.006945088040083647,
-0.0440627783536911,
-0.020442860201001167,
0.03479635715484619,
0.05238364636898041,
-0.00021496560657396913,
0.00890711136162281,
0.006221740040928125,
0.003994962200522423,
-0.0018591940170153975,
-0.03201643005013466,
-0.014656074345111847,
-0.04765588045120239,
0.018305910751223564,
0.04599170759320259,
0.034058827906847,
-0.03948630020022392,
0.07031133770942688,
-0.017918232828378677,
0.02074543759226799,
0.07068955898284912,
0.04671032726764679,
-0.02450873889029026,
0.03194078803062439,
-0.05714923515915871,
0.03103305585682392,
0.08154451102018356,
0.07087866961956024,
0.022712187841534615,
0.04599170759320259,
-0.03065483458340168,
0.00834923516958952,
0.0743204802274704,
-0.01233946904540062,
-0.03842728212475777,
-0.010656384751200676,
0.03141127899289131,
0.04099918529391289,
-0.046029530465602875,
-0.03615795448422432,
-0.019185274839401245,
-0.06713427603244781,
0.01889215223491192,
0.004600116517394781,
0.06512970477342606,
0.059985894709825516,
-0.00438736705109477,
0.05268622562289238,
0.014069831930100918,
0.008174307644367218,
0.052459292113780975,
0.02119930274784565,
-0.05041689798235893,
0.013559232465922832,
-0.04856361076235771,
0.017086146399378777,
0.013701065443456173,
-0.043268512934446335,
0.03101414442062378,
-0.03829490393400192,
0.05609021708369255,
-0.059607673436403275,
0.025851424783468246,
0.03462615981698036,
0.029141949489712715,
-0.01991335116326809,
0.028290951624512672,
0.036309242248535156,
-0.06917667388916016,
0.03723588585853577,
-0.022806743159890175,
0.002467893762513995,
-0.041793450713157654,
0.04092354327440262,
0.020215926691889763,
-0.015781283378601074,
0.01615004800260067,
0.023449718952178955,
-0.008472156710922718,
-0.029425615444779396,
-0.02598380111157894,
-0.03975105658173561,
-0.06006154045462608,
0.005328192375600338,
0.00925223808735609,
0.05983460694551468,
-0.02458438277244568,
-0.0659617930650711,
-0.05385870859026909,
-0.00106729322578758,
0.020953459665179253,
0.037500638514757156,
-0.04175562784075737,
-0.04534872993826866,
-0.06857151538133621,
-0.008008835837244987,
-0.019346019253134727,
-0.04848796874284744,
0.025567758828401566,
-0.015989305451512337,
-0.020140282809734344,
0.03865421563386917,
-0.0041037010960280895,
0.0295390821993351,
0.003351986175402999,
0.012651502154767513,
0.021501880139112473,
0.022258322685956955,
0.044554468244314194,
0.028782639652490616,
-0.011460104957222939,
0.024206161499023438,
0.01724689081311226,
0.0378788597881794,
0.004897965583950281,
0.0455000214278698,
0.014041464775800705,
0.04792063683271408,
0.0455000214278698,
0.01463716384023428,
-0.02203138917684555,
0.03417229279875755,
0.02743995375931263,
0.013644332997500896,
0.04205820709466934,
0.02341189794242382,
0.02121821418404579,
0.012424568645656109,
-0.00902530550956726,
0.017426544800400734,
0.02460329420864582,
0.02248525433242321,
0.024830227717757225,
0.02350645326077938,
-0.018835419788956642,
-0.02167207933962345,
0.04935787618160248,
0.005384925287216902,
-0.02212594449520111,
-0.03636597469449043,
0.0030139507725834846,
0.011809959076344967,
-0.029236504808068275,
-0.008027746342122555,
-0.01600821502506733,
0.001375779858790338,
0.009417709894478321,
0.0123867467045784,
-0.013417399488389492,
0.03846510499715805,
-0.024073785170912743,
0.011441193521022797,
-0.01612168177962303,
0.03460724651813507,
-0.00029947442817501724,
0.028801551088690758,
-0.021615346893668175,
0.08487285673618317,
-0.06966836005449295,
-0.00635884515941143,
-0.02789381891489029,
-0.01137500535696745,
0.0038625847082585096,
-0.020688703283667564,
0.03922154754400253,
0.04489486664533615,
-0.043003760278224945,
0.0655079260468483,
0.025170626118779182,
-0.054199110716581345,
0.017067234963178635,
-0.006023173686116934,
-0.04202038422226906,
-0.027023909613490105,
0.023014765232801437,
0.03627141937613487,
-0.03203534334897995,
-0.03074938990175724,
0.0022043208591639996,
-0.05056818574666977,
-0.025643402710556984,
-0.010977872647345066,
-0.02329843118786812,
0.0031605116091668606,
0.0009591455454938114,
0.026475489139556885,
-0.003928773570805788,
0.028026197105646133,
0.05219453573226929,
-0.026645688340067863,
0.04130176454782486,
0.001412420067936182,
0.01729416847229004,
0.005626041442155838,
-0.0232227873057127,
0.0678907185792923,
0.019346019253134727,
0.0023745205253362656,
-0.004278628155589104,
-0.013767254538834095,
-0.015667816624045372,
-0.011053516529500484,
-0.027213020250201225,
0.04981174319982529,
0.0609692707657814,
-0.018542299047112465,
0.057489633560180664,
0.012320558540523052,
0.001398236840032041,
0.0059711686335504055,
-0.06395722180604935,
0.007890641689300537,
0.009053671732544899,
0.005285642575472593,
0.011261538602411747,
-0.010599651373922825,
-0.05745181068778038,
0.01541251689195633,
0.0031746949534863234,
-0.03163820877671242,
0.015809649601578712,
-0.008651811629533768,
-0.05003867670893669,
-0.0012256733607500792,
-0.000694390619173646,
-0.010977872647345066,
-0.010249796323478222,
-0.01710505783557892,
-0.05170284956693649,
-0.0031486921943724155,
-0.018060065805912018,
-0.052156712859869,
0.02762906439602375,
0.02672133408486843,
-0.03056027926504612,
-0.011762681417167187,
-0.038408372551202774,
-0.0359688438475132,
-0.012859523296356201,
0.03649835288524628,
-0.013464677147567272,
-0.017974967136979103,
0.057224880903959274,
-0.0235820971429348,
-0.020858904346823692,
-0.024376360699534416,
-0.033264562487602234,
-0.0006506587960757315,
-0.07269413024187088,
-0.040053632110357285,
-0.003782212734222412,
-0.0015743460971862078,
-0.025719046592712402,
-0.02284456603229046,
0.009748653508722782,
0.042549893260002136,
-0.0017729122191667557,
0.0018391009652987123,
-0.007058554794639349,
-0.02276892028748989,
-0.003477271879091859,
0.006604689173400402,
-0.006699244491755962,
-0.00218186411075294,
0.018835419788956642,
0.010051230899989605,
0.06342770904302597,
-0.017379267141222954,
0.022504165768623352,
0.019762061536312103,
-0.026210734620690346,
-0.02201247774064541,
0.04194473847746849,
-0.028139663860201836,
-0.04973609745502472,
0.04682379588484764,
-0.028763728216290474,
-0.0248869601637125,
0.003337802831083536,
-0.033529315143823624,
0.056392792612314224,
0.010524007491767406,
-0.021445145830512047,
0.04935787618160248,
0.022693276405334473,
-0.022882387042045593,
-0.02157752402126789,
-0.008150668814778328,
0.032073166221380234,
-0.044554468244314194,
-0.005143809597939253,
0.01912854053080082,
0.011828870512545109,
-0.009720287285745144,
0.0011701220646500587,
0.045840419828891754,
0.0702735111117363,
-0.052724044770002365,
0.017738578841090202,
-0.012887890450656414,
0.014079286716878414,
-0.04754241555929184,
-0.0012587676756083965,
0.06482712924480438,
-0.0392971895635128,
-0.037954505532979965,
0.006926177069544792,
-0.05060600861907005,
0.039788879454135895,
-0.04553784057497978,
0.047769349068403244,
-0.029123038053512573,
0.03903243690729141,
-0.02715628780424595,
0.0006731156609021127,
-0.018665220588445663,
-0.018466653302311897,
-0.0416799858212471,
-0.03056027926504612,
0.02469784952700138,
0.05975896120071411,
-0.08631009608507156,
-0.013445766642689705,
0.005195814650505781,
-0.022163767367601395,
-0.00010135148477274925,
0.03891896829009056,
0.004897965583950281,
0.009460260160267353,
0.06815547496080399,
-0.07534167915582657,
-0.018154621124267578,
-0.0006435671239160001,
0.018740864470601082,
0.05204324796795845,
0.016821391880512238,
-0.057413991540670395,
-0.018608486279845238,
-0.02579469047486782,
0.015213950537145138,
0.02908521704375744,
-0.03056027926504612,
-0.03634706512093544,
-0.004314086399972439,
0.015299051068723202,
-0.05351831018924713,
0.005347103346139193,
0.019383840262889862,
-0.025113893672823906,
0.040242742747068405,
0.012651502154767513,
0.04958480969071388,
-0.013776710256934166,
0.037141330540180206,
0.028328774496912956,
-0.009460260160267353,
0.00442518899217248,
0.025000426918268204,
0.020083550363779068,
-0.0023130595218390226,
-0.01765347830951214,
0.000963873288128525,
-0.04285247251391411,
-0.011639759875833988,
-0.02779926359653473,
-0.059153806418180466,
-0.0018781049875542521,
0.00028987115365453064,
0.01175322663038969,
0.02761015295982361,
0.005195814650505781
]
|
31,026 | networkx.algorithms.distance_measures | radius | Returns the radius of the graph G.
The radius is the minimum eccentricity.
Parameters
----------
G : NetworkX graph
A graph
e : eccentricity dictionary, optional
A precomputed dictionary of eccentricities.
weight : string, function, or None
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.
If this is None, every edge has weight/distance/cost 1.
Weights stored as floating point values can lead to small round-off
errors in distances. Use integer weights to avoid this.
Weights should be positive, since they are distances.
Returns
-------
r : integer
Radius of graph
Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> nx.radius(G)
2
| 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, e=None, usebounds=False, weight=None, *, backend=None, **backend_kwargs) | [
0.05050395056605339,
-0.014621064066886902,
0.0027076045516878366,
0.0592062845826149,
0.05628017336130142,
-0.009433864615857601,
-0.03190223127603531,
-0.04947790876030922,
0.10077989101409912,
-0.008683335036039352,
0.03188323229551315,
-0.00023231365776155144,
0.015229088254272938,
-0.004503173753619194,
-0.05973830819129944,
0.04510774090886116,
-0.05692619830369949,
0.0003728893934749067,
-0.005837975535541773,
0.04632378742098808,
0.005244202446192503,
-0.10412401705980301,
-0.0036552660167217255,
0.06061233952641487,
-0.02795007824897766,
0.007453037891536951,
0.020349785685539246,
0.01344301924109459,
-0.0035460118670016527,
0.0005044101271778345,
-0.006602754816412926,
-0.05031394213438034,
-0.023332901298999786,
-0.006512501277029514,
0.022914884611964226,
0.023883922025561333,
0.00700652040541172,
0.007785550784319639,
-0.09257157146930695,
-0.05350606516003609,
-0.011561946012079716,
0.03385930880904198,
0.03209223970770836,
-0.026677029207348824,
0.033251285552978516,
0.01780368760228157,
-0.003686142386868596,
0.01883922703564167,
-0.030306169763207436,
-0.03914150968194008,
0.02584099769592285,
-0.010906420648097992,
-0.04620978236198425,
0.009163103997707367,
0.0018786975415423512,
0.03342229127883911,
0.026126008480787277,
0.05411408841609955,
0.029185127466917038,
-0.07303881645202637,
0.011115428991615772,
-0.08056311309337616,
0.02764606662094593,
0.01684414967894554,
-0.06133436784148216,
0.01502958033233881,
-0.01964675821363926,
-0.005505462642759085,
0.007999308407306671,
0.013813532888889313,
-0.029128124937415123,
-0.0022634624037891626,
0.026050005108118057,
-0.0682506337761879,
0.01872522383928299,
0.026373017579317093,
0.023902922868728638,
-0.013253011740744114,
-0.02692404016852379,
-0.014098544605076313,
0.03178822621703148,
-0.013167507946491241,
0.04620978236198425,
-0.03644340857863426,
0.02534697949886322,
-0.03729844093322754,
0.011039426550269127,
-0.016625642776489258,
0.02599300444126129,
-0.03144621476531029,
-0.0067405104637146,
0.026069005951285362,
0.03378330543637276,
0.03748844563961029,
0.07322882860898972,
0.0010450403206050396,
-0.04989592730998993,
-0.07349483668804169,
0.07072073221206665,
-0.022116854786872864,
-0.013452519662678242,
0.08641533553600311,
-0.018041197210550308,
0.0051919505931437016,
0.028672106564044952,
-0.0460197776556015,
-0.01537159364670515,
-0.034410327672958374,
0.05365807190537453,
-0.031199203804135323,
-0.05631817504763603,
0.021679837256669998,
0.01654013805091381,
-0.013728030025959015,
-0.03610139340162277,
0.04510774090886116,
-0.016872651875019073,
0.015276589430868626,
0.05932028964161873,
0.027665067464113235,
0.013186508789658546,
0.0322442464530468,
-0.01772768422961235,
-0.0009731938480399549,
0.010735414922237396,
0.021812841296195984,
0.009585870429873466,
0.0014523685676977038,
-0.011922960169613361,
0.02198384888470173,
0.04913589730858803,
0.00012105545465601608,
0.025289976969361305,
0.04848987236618996,
0.02738005667924881,
0.00989938247948885,
-0.007685796823352575,
0.03756444901227951,
0.06722459197044373,
0.0207488015294075,
-0.01041240245103836,
-0.023294899612665176,
0.02319989539682865,
0.05118797719478607,
0.03188323229551315,
0.008360322564840317,
0.01742367260158062,
0.03955952823162079,
0.03982553631067276,
-0.0027836074586957693,
0.026373017579317093,
-0.014041542075574398,
0.04389169439673424,
-0.011029926128685474,
0.009623871184885502,
0.017243165522813797,
-0.014279051683843136,
0.013870535418391228,
-0.04043355956673622,
-0.03484734520316124,
-0.07425487041473389,
-0.030724186450242996,
0.04024355486035347,
-0.021755840629339218,
0.01384203415364027,
-0.02722805179655552,
0.04947790876030922,
0.015580601990222931,
-0.06490650773048401,
0.028159087523818016,
-0.04503173753619194,
-0.05160599201917648,
-0.03410631790757179,
-0.03874249756336212,
0.030458176508545876,
0.08527529239654541,
0.026620028540492058,
-0.014564062468707561,
0.012150969356298447,
0.023560909554362297,
-0.014906075783073902,
-0.05863626301288605,
-0.0018549466039985418,
-0.021470829844474792,
0.028938116505742073,
0.04499373584985733,
0.03465733677148819,
-0.004804810509085655,
0.004643304273486137,
0.0004655179800465703,
0.008189315907657146,
-0.04145960137248039,
0.02534697949886322,
0.028957117348909378,
0.029109124094247818,
-0.014972577802836895,
0.03591138496994972,
0.01834520883858204,
-0.03473334014415741,
0.07056872546672821,
0.029014119878411293,
-0.001060478389263153,
0.037393443286418915,
0.03201623633503914,
0.005548214074224234,
0.011200932785868645,
-0.00922485627233982,
-0.029071122407913208,
-0.008236818015575409,
0.009965884499251842,
-0.066768579185009,
0.005068445578217506,
0.00555296428501606,
-0.03492334857583046,
-0.024301938712596893,
0.0299831572920084,
-0.026430020108819008,
0.008897093124687672,
0.013690028339624405,
-0.06399446725845337,
-0.05479811504483223,
-0.010051388293504715,
-0.00982337910681963,
-0.013091505505144596,
0.04461372271180153,
-0.04928790405392647,
0.02240186557173729,
0.00002389935980318114,
0.014193547889590263,
0.007020771037787199,
0.05449410527944565,
0.00319212325848639,
0.07904305309057236,
-0.05122597888112068,
0.014184047468006611,
-0.021109815686941147,
-0.05981430783867836,
0.07250680029392242,
0.052404023706912994,
0.04123159125447273,
-0.03570237755775452,
-0.06281642615795135,
-0.042827654629945755,
0.05890227481722832,
-0.03627239912748337,
-0.03705143183469772,
0.013870535418391228,
0.0018656345782801509,
0.02855810336768627,
0.00901584792882204,
-0.08793539553880692,
-0.06794662028551102,
-0.014108045026659966,
-0.02319989539682865,
0.02757006511092186,
-0.010944422334432602,
-0.08519928902387619,
0.016559138894081116,
-0.018050696700811386,
-0.02726605348289013,
0.014497559517621994,
-0.008374573662877083,
-0.07227879017591476,
-0.0045815519988536835,
-0.04822386056184769,
0.010089389979839325,
0.0004385013016872108,
0.010250896215438843,
-0.025479983538389206,
0.05076995864510536,
0.04491773247718811,
0.010431402362883091,
0.013566523790359497,
-0.009495616890490055,
-0.00493069039657712,
0.02017877995967865,
0.021185817196965218,
0.04461372271180153,
-0.00506369536742568,
0.0363864041864872,
-0.08451526612043381,
0.0016803774051368237,
-0.007638294715434313,
0.02443494275212288,
-0.05692619830369949,
0.017452172935009003,
-0.009248606860637665,
-0.05639417842030525,
0.02312389202415943,
-0.009082350879907608,
0.09249556809663773,
0.007785550784319639,
0.0035887635312974453,
0.0033607548102736473,
0.07379885017871857,
0.010393401607871056,
-0.013965539634227753,
-0.04837586730718613,
0.016369132325053215,
0.06958068907260895,
0.043131664395332336,
-0.0243209395557642,
0.004655179567635059,
-0.04936390742659569,
0.05552014335989952,
0.04081357643008232,
0.034866347908973694,
-0.00006460991426138207,
0.01723366603255272,
0.057838231325149536,
-0.09621971845626831,
0.004897438921034336,
-0.043131664395332336,
0.022876882925629616,
-0.052480027079582214,
-0.02967914566397667,
0.05012393370270729,
-0.02726605348289013,
0.020083775743842125,
0.025593988597393036,
0.015979617834091187,
0.09697974473237991,
0.014459557831287384,
0.03874249756336212,
-0.07117674499750137,
-0.0023477780632674694,
0.01983676664531231,
0.07828301936388016,
0.07934706658124924,
-0.04943990707397461,
-0.042789652943611145,
0.018411710858345032,
-0.010250896215438843,
0.004743058234453201,
-0.04145960137248039,
0.042181629687547684,
0.10952022671699524,
-0.03382130712270737,
-0.02783607505261898,
-0.02948913909494877,
0.027703069150447845,
0.004256164189428091,
-0.005305954720824957,
-0.0026197261177003384,
-0.00513019785284996,
0.019276244565844536,
0.017053158953785896,
-0.027399057522416115,
-0.03484734520316124,
-0.053202055394649506,
-0.012853995896875858,
0.003964027855545282,
-0.031997233629226685,
0.02688603848218918,
-0.016787149012088776,
0.04552575945854187,
-0.011704452335834503,
-0.048109859228134155,
0.02198384888470173,
0.023788917809724808,
-0.10359200090169907,
0.006331994663923979,
-0.028691107407212257,
-0.019390247762203217,
-0.006887766066938639,
0.012141468934714794,
-0.016511637717485428,
0.017214665189385414,
0.018326207995414734,
-0.04096558317542076,
-0.0022670249454677105,
-0.08200716972351074,
-0.07744698971509933,
0.0048095607198774815,
0.010925421491265297,
0.03748844563961029,
-0.03404931351542473,
-0.021090814843773842,
-0.01573260687291622,
-0.006398497149348259,
0.009191605262458324,
0.019323745742440224,
-0.04457572102546692,
0.01114393025636673,
0.04472772777080536,
-0.012663989327847958,
0.04909789562225342,
0.004070907365530729,
0.02416893281042576,
-0.003253875533118844,
-0.041801612824201584,
-0.02757006511092186,
0.06764261424541473,
-0.010896921157836914,
-0.043435677886009216,
0.03480934351682663,
0.061790384352207184,
0.028273090720176697,
-0.04579176753759384,
-0.014193547889590263,
-0.04609578102827072,
-0.007799800951033831,
-0.021394826471805573,
0.00854082964360714,
-0.026601027697324753,
0.015001079067587852,
0.007742798887193203,
0.043473679572343826,
0.04472772777080536,
0.014440557919442654,
-0.04962991550564766,
0.015637604519724846,
0.013452519662678242,
0.004263289738446474,
-0.01968475989997387,
-0.02017877995967865,
-0.013129507191479206,
0.0023465906269848347,
0.03701343014836311,
0.02990715391933918,
0.021318823099136353,
-0.02967914566397667,
0.07509090006351471,
-0.0059377290308475494,
0.0226298738270998,
-0.04670380428433418,
0.00012461809092201293,
-0.02002677321434021,
-0.0663885623216629,
0.05403808504343033,
-0.023845920339226723,
0.0016863150522112846,
0.018905729055404663,
-0.03127520903944969,
0.00022177418577484787,
-0.0022313985973596573,
0.01795569248497486,
0.017490174621343613,
-0.02010277658700943,
-0.03726043924689293,
0.04016755148768425,
0.012188971042633057,
0.027741070836782455,
-0.04829986393451691,
-0.0032990023028105497,
-0.06281642615795135,
-0.006906766444444656,
-0.0008485015132464468,
-0.005158699117600918,
-0.03165522217750549,
0.005514963064342737,
-0.04434771090745926,
0.02673403173685074,
0.028805112466216087,
-0.11719652265310287,
0.029128124937415123,
-0.03718443587422371,
-0.01405104249715805,
-0.06806062906980515,
0.02553698606789112,
0.016169624403119087,
0.03157921880483627,
-0.009144103154540062,
-0.02994515560567379,
-0.01957075484097004,
-0.032833267003297806,
0.007799800951033831,
-0.015618602745234966,
-0.027171049267053604,
-0.021090814843773842,
0.04909789562225342,
-0.020159779116511345,
-0.0199887715280056,
-0.043283671140670776,
0.056546181440353394,
0.012568985112011433,
-0.09120351821184158,
-0.011837457306683064,
0.006175238639116287,
-0.04415770620107651,
-0.019969770684838295,
0.02017877995967865,
0.05563414841890335,
0.023921923711895943,
0.020919807255268097,
-0.0392175130546093,
-0.0039022755809128284,
-0.0057097203098237514,
0.01995076984167099,
-0.041877616196870804,
-0.015552100725471973,
0.03163622319698334,
0.02565099112689495,
0.01212246809154749,
0.0006721509271301329,
-0.004702681675553322,
0.01229347474873066,
0.004595802631229162,
0.032757263630628586,
0.014402556233108044,
-0.026354016736149788,
-0.03144621476531029,
-0.015485597774386406,
0.04848987236618996,
0.03695642575621605,
0.03163622319698334,
-0.03859049081802368,
0.0076525453478097916,
0.08960746228694916,
0.03526536002755165,
-0.01401304081082344,
0.019152740016579628,
0.07414086163043976,
0.047463834285736084,
0.011856458149850368,
-0.026183011010289192,
-0.036557409912347794,
0.05434209853410721,
0.0652485191822052,
-0.02852010168135166,
-0.01887722872197628,
0.024225935339927673,
0.000541520887054503,
-0.0018549466039985418,
-0.016787149012088776,
0.008944595232605934,
-0.004469922743737698,
-0.07748499512672424,
-0.0021815216168761253,
-0.015305090695619583,
-0.014459557831287384,
0.01995076984167099,
-0.01944725029170513,
0.047121819108724594,
-0.00038506175042130053,
-0.007809301372617483,
-0.018630219623446465,
-0.042029622942209244,
-0.1022239476442337,
-0.011789955198764801,
-0.015476097352802753,
0.0030068662017583847,
0.014678066596388817,
0.011257934384047985,
0.08246318250894547,
0.020349785685539246,
0.001218422083184123,
0.0024000301491469145,
-0.02247786708176136,
-0.07072073221206665,
-0.04480373114347458,
0.02825409173965454,
-0.020843803882598877,
-0.03387830778956413,
0.061942391097545624,
0.03686142340302467,
-0.0501619353890419,
0.004564926028251648,
0.025403980165719986,
-0.017642181366682053,
-0.016644641757011414,
-0.08732736855745316,
-0.018126700073480606,
-0.06304443627595901,
0.006469749845564365,
-0.04043355956673622,
0.03232024610042572,
-0.024985965341329575,
-0.04491773247718811,
0.03382130712270737,
-0.03182622790336609,
0.032453253865242004,
0.07835902273654938,
0.004472297616302967,
-0.006545752752572298,
-0.013281513005495071,
0.025270976126194,
-0.06319644302129745,
0.035094354301691055,
-0.06353845447301865,
-0.012739991769194603,
-0.06106835603713989,
0.01635013148188591,
0.04119358956813812,
0.017148161306977272,
0.04161160811781883,
-0.01673964597284794,
0.05346806347370148,
-0.03860948979854584,
-0.014602064155042171,
-0.02428293786942959,
-0.057268209755420685,
0.03824847564101219,
0.0035270112566649914,
-0.0019440125906839967,
-0.03349829465150833,
-0.022078853100538254,
0.00798505824059248,
0.0460197776556015,
0.0032134989742189646,
-0.052062008529901505,
-0.009277108125388622,
0.019551753997802734,
-0.006949518341571093,
-0.04381569102406502,
0.04947790876030922,
0.005343956407159567,
-0.07041671872138977,
0.036158397793769836,
-0.053240057080984116,
0.0015663729282096028,
-0.0243209395557642,
-0.016245627775788307,
-0.000583084998652339,
-0.0033940060529857874,
0.012739991769194603,
-0.002312151715159416,
0.016511637717485428,
-0.042333632707595825,
0.017670681700110435,
-0.004811935592442751,
-0.004712182097136974,
0.03767845407128334,
-0.03277626633644104,
-0.01853521540760994,
0.05700220167636871,
0.04005354642868042,
0.005951979663223028,
-0.03323228284716606,
0.041801612824201584,
-0.0021577707957476377,
-0.042143628001213074,
-0.009889882057905197,
0.042257633060216904,
0.03171222284436226,
-0.07132875174283981,
0.04031955823302269,
-0.017480675131082535,
-0.02014077827334404,
0.041687607765197754,
-0.03572138026356697,
0.07600293308496475,
-0.057344213128089905,
-0.0006210864521563053,
-0.06399446725845337,
0.01941874995827675,
0.04898389056324959,
-0.017205163836479187,
-0.005220451392233372,
-0.005652718245983124,
-0.02010277658700943,
0.03184523060917854,
0.0333842895925045,
-0.017908191308379173,
-0.008555080741643906,
0.036006391048431396,
0.026487022638320923,
-0.02466295287013054,
0.009538368321955204,
-0.05133998394012451,
0.001156075857579708,
0.03631040081381798,
0.03336528688669205,
0.011789955198764801,
0.024035928770899773,
0.017053158953785896,
0.0330042727291584,
-0.0362153984606266,
-0.0026221012230962515,
-0.06255041807889938,
-0.019741762429475784,
-0.01229347474873066,
0.022990887984633446,
0.03127520903944969,
-0.06874465197324753,
0.023104891180992126,
-0.0032158740796148777,
0.038001466542482376,
-0.0006234615575522184,
-0.020881805568933487,
0.004716932307928801,
0.06722459197044373,
-0.02553698606789112,
-0.004377293866127729,
0.017547177150845528,
-0.021432828158140182,
-0.03070518560707569,
-0.021071814000606537,
0.02929913066327572,
-0.004873688332736492,
-0.03967353329062462,
-0.042827654629945755,
0.02067279815673828,
-0.0009179729386232793,
0.057914234697818756,
-0.04009154811501503,
-0.04989592730998993,
0.04822386056184769,
0.07034071534872055,
-0.05924428626894951,
0.07904305309057236,
0.02538497932255268,
-0.016625642776489258,
0.02681003510951996,
-0.023921923711895943,
-0.02572699263691902,
-0.07611694186925888,
-0.011210433207452297,
-0.04552575945854187,
0.03387830778956413,
-0.011970462277531624,
-0.023940924555063248,
0.018316706642508507,
-0.004070907365530729,
0.03993954136967659,
0.023769916966557503,
-0.0036243898794054985,
-0.030914193019270897,
-0.04362568259239197,
-0.006303493399173021,
-0.018250204622745514,
-0.009324610233306885,
0.012796994298696518,
0.03040117397904396,
-0.032035235315561295,
0.01212246809154749,
0.07254479825496674,
-0.04468972608447075,
0.0068830158561468124,
0.047881849110126495,
-0.027133047580718994,
0.004215787630528212,
0.015580601990222931,
0.03710843250155449,
0.02278187870979309,
0.020767802372574806,
-0.005780973006039858,
0.028273090720176697,
0.037507448345422745,
0.052100010216236115,
0.02599300444126129,
0.04153560474514961,
-0.047539833933115005,
-0.032567258924245834,
0.001257611089386046,
-0.007039771880954504,
-0.04020555317401886,
0.023294899612665176,
0.01933324709534645,
-0.02304789051413536,
0.05076995864510536,
-0.00471930718049407,
0.03175022453069687,
-0.008897093124687672,
0.057610224932432175,
-0.007799800951033831,
-0.015675604343414307,
-0.0516819953918457,
-0.0025936001911759377,
-0.005258453078567982,
-0.0038856500759720802,
-0.06657856702804565,
-0.05175799876451492,
0.014108045026659966,
-0.029185127466917038,
0.008778339251875877,
0.006583753973245621,
0.05464610829949379
]
|
31,030 | networkx.generators.degree_seq | random_degree_sequence_graph | Returns a simple random graph with the given degree sequence.
If the maximum degree $d_m$ in the sequence is $O(m^{1/4})$ then the
algorithm produces almost uniform random graphs in $O(m d_m)$ time
where $m$ is the number of edges.
Parameters
----------
sequence : list of integers
Sequence of degrees
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
tries : int, optional
Maximum number of tries to create a graph
Returns
-------
G : Graph
A graph with the specified degree sequence.
Nodes are labeled starting at 0 with an index
corresponding to the position in the sequence.
Raises
------
NetworkXUnfeasible
If the degree sequence is not graphical.
NetworkXError
If a graph is not produced in specified number of tries
See Also
--------
is_graphical, configuration_model
Notes
-----
The generator algorithm [1]_ is not guaranteed to produce a graph.
References
----------
.. [1] Moshen Bayati, Jeong Han Kim, and Amin Saberi,
A sequential algorithm for generating random graphs.
Algorithmica, Volume 58, Number 4, 860-910,
DOI: 10.1007/s00453-009-9340-1
Examples
--------
>>> sequence = [1, 2, 2, 3]
>>> G = nx.random_degree_sequence_graph(sequence, seed=42)
>>> sorted(d for n, d in G.degree())
[1, 2, 2, 3]
| 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
| (sequence, seed=None, tries=10, *, backend=None, **backend_kwargs) | [
-0.022486142814159393,
0.0036777034401893616,
-0.030360806733369827,
-0.021203801035881042,
-0.015993155539035797,
0.04858451709151268,
-0.07159443199634552,
-0.03926495835185051,
0.03422589600086212,
-0.03135417029261589,
0.03240171819925308,
0.08040827512741089,
-0.03397303819656372,
0.04024026170372963,
-0.013699389062821865,
0.005079701077193022,
0.023967158049345016,
0.013645205646753311,
-0.014385713264346123,
0.0017270982498303056,
-0.019199011847376823,
-0.015487443655729294,
-0.0069806380197405815,
0.03346732631325722,
-0.03397303819656372,
-0.004966818727552891,
-0.016760755330324173,
0.01341944094747305,
-0.028933975845575333,
-0.01814243383705616,
-0.0585542768239975,
0.0013162068789824843,
-0.027236226946115494,
0.004384346306324005,
0.013482654467225075,
0.046417176723480225,
-0.018729422241449356,
0.026802759617567062,
-0.051835525780916214,
0.029511932283639908,
0.09695229679346085,
-0.02927713841199875,
-0.035833340138196945,
0.015568718314170837,
-0.024003280326724052,
-0.030902642756700516,
0.039734549820423126,
0.037603333592414856,
-0.0005443746340461075,
-0.07845767587423325,
0.021276045590639114,
-0.018061159178614616,
0.009455016814172268,
0.015442290343344212,
0.010764450766146183,
0.015117189846932888,
-0.010845725424587727,
0.01692330650985241,
0.08337030559778214,
0.0214385949075222,
-0.020896760746836662,
-0.012760208919644356,
0.00038464623503386974,
-0.0006643119850195944,
-0.029421627521514893,
0.020987065508961678,
-0.04887349531054497,
-0.02441868558526039,
0.009545322507619858,
0.05667591467499733,
0.05096859112381935,
-0.012859544716775417,
0.05132981389760971,
-0.0021300879307091236,
0.05349715054035187,
-0.019650541245937347,
0.00955435261130333,
-0.027651634067296982,
0.02051747590303421,
-0.03001764602959156,
-0.03189600631594658,
-0.0034496812149882317,
-0.021041249856352806,
-0.0015329408925026655,
0.05317205190658569,
0.038506388664245605,
0.002792706713080406,
-0.042154744267463684,
-0.03803680092096329,
-0.05064348876476288,
-0.01912676729261875,
-0.027236226946115494,
-0.004817814100533724,
0.01266087219119072,
0.03828965499997139,
-0.01704070344567299,
-0.0382535345852375,
-0.05198001489043236,
0.03962618112564087,
-0.02300991676747799,
-0.017320651561021805,
0.02539398893713951,
-0.14376682043075562,
0.03408140689134598,
0.022359713912010193,
-0.06570649147033691,
-0.004136005416512489,
-0.04497228562831879,
0.035652726888656616,
-0.010231646709144115,
-0.04992104321718216,
0.04692288860678673,
0.07199177891016006,
0.04016801714897156,
-0.010683175176382065,
0.020788393914699554,
-0.0010170689783990383,
-0.020788393914699554,
0.025845518335700035,
0.02100512757897377,
-0.033647939562797546,
0.023533688858151436,
-0.018675237894058228,
0.0570010170340538,
0.003104261588305235,
0.022684814408421516,
0.015559688210487366,
-0.03050529770553112,
0.06902974843978882,
-0.05230511352419853,
0.05497816577553749,
0.005463500507175922,
0.025971945375204086,
-0.00788821093738079,
-0.06613996624946594,
-0.012706025503575802,
-0.016950396820902824,
-0.04201025515794754,
0.022486142814159393,
0.051474303007125854,
-0.012706025503575802,
-0.03959006071090698,
0.009879454039037228,
0.04793431609869003,
0.010186493396759033,
0.04432208463549614,
-0.007269616238772869,
0.008971880190074444,
-0.015758361667394638,
-0.03471354767680168,
0.028590813279151917,
-0.01019552443176508,
0.009233767166733742,
-0.002783676143735647,
-0.0068948473781347275,
0.023912973701953888,
-0.002160566160455346,
0.033033858984708786,
-0.050932466983795166,
-0.002224908908829093,
-0.0374949648976326,
0.0027904489543288946,
0.008863513357937336,
0.01740192621946335,
0.0017180676804855466,
-0.029746728017926216,
0.09659107774496078,
-0.05678428336977959,
-0.02557460032403469,
-0.00840295385569334,
-0.038434144109487534,
-0.042588211596012115,
-0.04461106285452843,
-0.02501470409333706,
-0.03379242867231369,
0.007210917770862579,
0.020300742238759995,
0.006583292502909899,
-0.004456590861082077,
0.05114920064806938,
0.0038447692058980465,
-0.03404528275132179,
-0.03731435537338257,
-0.029800912365317345,
0.03915659338235855,
-0.01418703980743885,
0.06281670928001404,
0.005553806200623512,
0.054942045360803604,
-0.05060736462473869,
-0.03991515934467316,
0.007445712573826313,
0.05273858457803726,
0.0857543796300888,
0.0801192969083786,
-0.017374834045767784,
0.02897009812295437,
0.06570649147033691,
-0.06765709817409515,
0.051113080233335495,
0.032365597784519196,
-0.010448380373418331,
0.024147769436240196,
-0.038145165890455246,
-0.02508694864809513,
0.02064390480518341,
-0.029385505244135857,
-0.009355680085718632,
0.011766844429075718,
0.03373824432492256,
-0.01525264885276556,
-0.0025082433130592108,
0.07101647555828094,
0.009825270622968674,
-0.053786128759384155,
0.0012236435431987047,
0.02033686451613903,
0.013988367281854153,
0.013780663721263409,
-0.04121556505560875,
-0.046597789973020554,
0.0032848732080310583,
-0.006560715846717358,
-0.07701277732849121,
-0.012733116745948792,
-0.032600391656160355,
-0.034117527306079865,
-0.04399698227643967,
-0.1055494099855423,
0.0010204555001109838,
0.06913811713457108,
-0.03417171165347099,
-0.03599588945508003,
-0.012335771694779396,
0.02441868558526039,
0.029927339404821396,
-0.017799271270632744,
-0.005395771004259586,
-0.013374287635087967,
0.03202243521809578,
-0.043310657143592834,
-0.05678428336977959,
0.009319557808339596,
0.033702120184898376,
0.04692288860678673,
0.06473119556903839,
0.021583084017038345,
-0.03628486767411232,
0.007129642181098461,
0.036989253014326096,
-0.04840390384197235,
-0.051654912531375885,
-0.026513781398534775,
-0.02210685797035694,
0.006411711219698191,
-0.05270246043801308,
-0.022269409149885178,
-0.03901210427284241,
0.035454053431749344,
0.013256890699267387,
0.02123992331326008,
0.051618792116642,
-0.08662131428718567,
0.026260925456881523,
0.03471354767680168,
-0.0026391868013888597,
-0.003910240717232227,
0.0147017827257514,
-0.05320817232131958,
-0.007937879301607609,
0.010628991760313511,
0.05277470499277115,
0.01644468493759632,
-0.009725933894515038,
0.03621262311935425,
-0.018043097108602524,
0.01205582357943058,
0.04851227253675461,
-0.04280494526028633,
0.021962368860840797,
-0.04616432264447212,
0.01165847759693861,
-0.0012010670034214854,
-0.0006993054994381964,
-0.06585098057985306,
0.04825941473245621,
0.009870423004031181,
-0.03839802369475365,
0.029439687728881836,
-0.061227329075336456,
0.001274440553970635,
0.008195250295102596,
-0.014503110200166702,
0.04013189300894737,
0.09435149282217026,
-0.01415994856506586,
-0.0038267080672085285,
-0.004867482464760542,
0.001097779837436974,
0.06397262215614319,
0.06245548650622368,
-0.020860638469457626,
0.0017914411146193743,
-0.0353095643222332,
-0.0029213924426585436,
-0.005933090578764677,
0.025845518335700035,
0.0012078399304300547,
0.0446833074092865,
0.011414652690291405,
-0.06303344666957855,
-0.014114795252680779,
0.09290660172700882,
0.020300742238759995,
0.02105931006371975,
-0.043563514947891235,
-0.013545868918299675,
-0.04414147138595581,
0.06729587912559509,
0.05486980080604553,
0.0018343364354223013,
0.05302756279706955,
-0.06451445817947388,
0.014015459455549717,
-0.08691029250621796,
0.04742860421538353,
0.037783943116664886,
0.03706149756908417,
-0.0017248406074941158,
-0.04753696918487549,
-0.056170202791690826,
-0.0014290892286226153,
-0.016092492267489433,
0.03117355890572071,
-0.07014954090118408,
0.020535537973046303,
0.09102823585271835,
-0.048548392951488495,
0.003709310432896018,
-0.01601121760904789,
0.09868617355823517,
0.007256070617586374,
-0.050860222429037094,
0.029548054561018944,
0.0067639038898050785,
-0.009166037663817406,
0.03032468445599079,
-0.041974131017923355,
-0.022179102525115013,
0.010908939875662327,
-0.02039104886353016,
0.09153395146131516,
-0.006136278621852398,
0.06512853503227234,
0.04728411138057709,
0.0444304496049881,
0.011685569770634174,
0.009653689339756966,
-0.050860222429037094,
0.030126012861728668,
-0.010791542008519173,
0.016462745144963264,
-0.029511932283639908,
0.048006560653448105,
-0.01123404037207365,
-0.04793431609869003,
0.04204637557268143,
0.058951620012521744,
0.033936917781829834,
-0.021944306790828705,
0.0018354651983827353,
-0.04273270070552826,
-0.04334678128361702,
0.022865427657961845,
-0.011134704574942589,
0.025971945375204086,
0.007960455492138863,
0.004368542693555355,
0.06787383556365967,
-0.035941705107688904,
-0.02618868090212345,
-0.004881028085947037,
-0.004212765023112297,
0.024797970429062843,
0.0167517252266407,
-0.0329977385699749,
0.06646506488323212,
0.006276252679526806,
0.06014365702867508,
-0.015993155539035797,
0.0008641135646030307,
-0.035941705107688904,
0.025845518335700035,
-0.015532596036791801,
0.023154405876994133,
0.030848458409309387,
0.0693187266588211,
0.02270287647843361,
-0.04049311578273773,
-0.008542927913367748,
-0.017988914623856544,
-0.06567037105560303,
0.00873708538711071,
0.05552000179886818,
-0.007603747770190239,
-0.08214215189218521,
0.07802420854568481,
0.03919271379709244,
0.05974631384015083,
-0.03727823123335838,
-0.028590813279151917,
0.011649447493255138,
-0.008791268803179264,
0.002285865368321538,
0.034117527306079865,
-0.05317205190658569,
0.013780663721263409,
-0.01892809383571148,
0.06082998216152191,
0.016399532556533813,
0.06003529205918312,
0.03657384589314461,
0.06538139283657074,
0.010340013541281223,
0.01266087219119072,
0.027055615559220314,
-0.02118573896586895,
0.013618113473057747,
-0.050860222429037094,
0.07246136665344238,
-0.010945062153041363,
-0.01491851732134819,
0.00986139290034771,
-0.050498999655246735,
0.01232674065977335,
-0.024075524881482124,
0.016038307920098305,
-0.018160495907068253,
-0.021294105798006058,
0.005490592215210199,
0.03574303165078163,
0.002880754880607128,
0.024093585088849068,
-0.019740846008062363,
0.036736395210027695,
-0.011017306707799435,
-0.020318804308772087,
-0.01527974009513855,
-0.027687756344676018,
0.026152556762099266,
0.016652388498187065,
0.007183826062828302,
0.03140835464000702,
-0.02064390480518341,
-0.03767557814717293,
0.08206990361213684,
0.01434055995196104,
-0.0403125062584877,
-0.055122654885053635,
0.005273858085274696,
0.055989593267440796,
0.022450020536780357,
-0.03532762452960014,
0.06433384865522385,
-0.033322837203741074,
-0.014476018957793713,
-0.0007884824299253523,
0.006827117875218391,
-0.04247984662652016,
0.0034948342945426702,
0.004704931750893593,
0.0009640143252909184,
-0.019271256402134895,
-0.08965559303760529,
-0.00861517246812582,
-0.04150454327464104,
-0.025357866659760475,
-0.019144827499985695,
0.008231372572481632,
-0.05454469844698906,
-0.04421371594071388,
-0.007779844105243683,
0.0034406506456434727,
0.03456905856728554,
-0.03883149102330208,
0.04024026170372963,
-0.01753738522529602,
-0.02673051506280899,
-0.0355624221265316,
-0.044538818299770355,
-0.06082998216152191,
-0.08163643628358841,
-0.032600391656160355,
0.01385290827602148,
0.014223162084817886,
0.04421371594071388,
-0.009789148345589638,
-0.0355624221265316,
-0.00217749853618443,
-0.023912973701953888,
-0.0016853318084031343,
0.0017598341219127178,
0.0068948473781347275,
0.022504203021526337,
0.017248407006263733,
0.006908392999321222,
-0.030649786815047264,
-0.03756720945239067,
0.011026337742805481,
0.0398067943751812,
0.034858036786317825,
0.007296707946807146,
-0.0013760345755144954,
0.047825947403907776,
0.0035738516598939896,
0.010023943148553371,
0.007319284602999687,
0.0003663028765004128,
-0.024797970429062843,
-0.009445985779166222,
0.010908939875662327,
0.027723878622055054,
0.0066690826788544655,
0.031805701553821564,
-0.005039063282310963,
0.03763945400714874,
-0.043744124472141266,
-0.07025790959596634,
0.014060611836612225,
-0.01087281759828329,
0.03915659338235855,
0.004235341679304838,
0.0054002865217626095,
0.09225639700889587,
-0.016399532556533813,
-0.06332242488861084,
0.06328629702329636,
-0.04482779651880264,
-0.06588710844516754,
-0.05060736462473869,
-0.002109769033268094,
0.007558594923466444,
-0.00946404691785574,
-0.02015625312924385,
0.0010486759711056948,
0.00934664998203516,
0.08373153209686279,
-0.01612861454486847,
0.034984465688467026,
-0.03001764602959156,
-0.030089890584349632,
0.04583922028541565,
-0.017591567710042,
-0.050932466983795166,
0.12447750568389893,
-0.013636174611747265,
-0.021817879751324654,
0.0036144894547760487,
0.028699180111289024,
0.01941574551165104,
0.004736538976430893,
-0.038687001913785934,
-0.06390038132667542,
-0.026802759617567062,
-0.0038018738850951195,
-0.006506532430648804,
-0.014078672975301743,
-0.006176916416734457,
0.0037838127464056015,
0.04778982698917389,
0.008759661577641964,
-0.03431620076298714,
0.01120694912970066,
-0.019578296691179276,
0.006483955774456263,
-0.03977067023515701,
-0.009400833398103714,
0.022612569853663445,
0.017988914623856544,
-0.025592662394046783,
0.003752205753698945,
0.004517547320574522,
-0.014232193119823933,
-0.01449408009648323,
0.004187931306660175,
0.024508992210030556,
-0.045947588980197906,
0.023479506373405457,
0.08163643628358841,
0.002004788490012288,
-0.003919271286576986,
-0.043924737721681595,
0.00205558561719954,
-0.002445029327645898,
-0.07433973252773285,
0.04692288860678673,
-0.030884580686688423,
-0.0051654912531375885,
-0.044358205050230026,
-0.016724633052945137,
-0.05046287551522255,
0.07860216498374939,
0.017880547791719437,
0.09095599502325058,
-0.020770331844687462,
0.0426243357360363,
-0.016471777111291885,
0.010385165922343731,
-0.01735677383840084,
-0.018061159178614616,
0.0005226447829045355,
-0.004903604742139578,
-0.0013839362654834986,
-0.0403125062584877,
-0.040709853172302246,
-0.04323841258883476,
-0.014060611836612225,
0.007391529157757759,
-0.03688088431954384,
-0.0037296293303370476,
-0.02105931006371975,
-0.012985972687602043,
-0.06408099085092545,
0.006935484707355499,
-0.004650748334825039,
0.022486142814159393,
0.05541163310408592,
-0.007192856632173061,
0.024870214983820915,
0.024201951920986176,
0.00952726136893034,
-0.059059988707304,
-0.07506217807531357,
-0.019704723730683327,
-0.000032259627914754674,
-0.015306832268834114,
0.015686117112636566,
0.0273445937782526,
0.02539398893713951,
-0.027254289016127586,
-0.07535115629434586,
0.04038475081324577,
-0.05255797132849693,
-0.047464724630117416,
-0.057506728917360306,
-0.02459929883480072,
0.015135250985622406,
0.03397303819656372,
-0.0178444255143404,
-0.02337113954126835,
-0.018729422241449356,
0.009870423004031181,
0.06241936236619949,
-0.02788642980158329,
0.014900456182658672,
-0.007635354995727539,
0.01503591425716877,
0.006953545846045017,
0.04016801714897156,
-0.04049311578273773,
0.006371073890477419,
0.02665827050805092,
0.08770498633384705,
-0.0059376060962677,
0.018160495907068253,
0.040204137563705444,
0.0449361614882946,
-0.03146253898739815,
-0.04219086468219757,
-0.013726480305194855,
-0.027922552078962326,
-0.04233535751700401,
0.06769322603940964,
0.013004033826291561,
-0.056531425565481186,
0.01657111383974552,
-0.011848120018839836,
0.004980364348739386,
0.03623068332672119,
0.03050529770553112,
0.01723034493625164,
0.032365597784519196,
-0.0224680807441473,
-0.07285871356725693,
-0.00997878983616829,
-0.012398985214531422,
-0.042588211596012115,
-0.03839802369475365,
0.0039847432635724545,
-0.002180884825065732,
-0.029566116631031036,
0.002258773660287261,
0.057434484362602234,
0.006068549118936062,
0.009581444784998894,
0.02105931006371975,
-0.031751517206430435,
-0.017013611271977425,
0.024942459538578987,
-0.030089890584349632,
0.037169866263866425,
-0.018584933131933212,
-0.014466987922787666,
0.030216317623853683,
-0.006438802927732468,
-0.008700963109731674,
0.011261132545769215,
0.006145309191197157,
-0.03532762452960014,
0.017329681664705276,
-0.014548263512551785,
0.002314085839316249,
-0.00692645413801074,
0.04815104976296425,
-0.011830058880150318,
-0.005860846024006605,
0.0033209954854100943,
0.07657930999994278,
-0.030306624248623848,
-0.024707665666937828,
-0.001871587592177093,
0.01649886928498745,
-0.013103370554745197,
0.04598370939493179,
-0.025538478046655655,
0.044358205050230026,
0.0006445575854741037,
-0.046308811753988266,
-0.01844947412610054,
-0.019831152632832527,
-0.026333170011639595,
0.04078209772706032,
0.003734144615009427,
-0.02898816019296646,
0.0037476904690265656,
-0.008082368411123753,
0.020102068781852722,
0.05837366357445717,
-0.02203461341559887,
0.0331241637468338,
-0.017880547791719437,
0.008303618058562279,
-0.02544817328453064,
0.03727823123335838,
0.007671477273106575,
-0.010421288199722767,
0.031877946108579636,
0.01728452928364277,
0.0033119649160653353,
0.010421288199722767,
0.028843671083450317,
-0.003609974170103669,
0.03155284374952316,
0.025538478046655655,
-0.044719427824020386,
-0.02300991676747799,
-0.012769239023327827,
-0.025249499827623367,
-0.027127860113978386,
-0.08611560612916946,
-0.03288936987519264,
-0.03269069641828537,
0.04450269415974617,
0.011893273331224918,
-0.01223643496632576,
0.0403125062584877,
0.06942709535360336,
-0.004718477837741375
]
|
31,031 | networkx.generators.geometric | random_geometric_graph | Returns a random geometric graph in the unit cube of dimensions `dim`.
The random geometric graph model places `n` nodes uniformly at
random in the unit cube. Two nodes are joined by an edge if the
distance between the nodes is at most `radius`.
Edges are determined using a KDTree when SciPy is available.
This reduces the time complexity from $O(n^2)$ to $O(n)$.
Parameters
----------
n : int or iterable
Number of nodes or iterable of nodes
radius: float
Distance threshold value
dim : int, optional
Dimension of graph
pos : dict, optional
A dictionary keyed by node with node positions as values.
p : float, optional
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.
Returns
-------
Graph
A random geometric 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.
Examples
--------
Create a random geometric graph on twenty nodes where nodes are joined by
an edge if their distance is at most 0.1::
>>> G = nx.random_geometric_graph(20, 0.1)
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::
>>> import random
>>> n = 20
>>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)}
>>> G = nx.random_geometric_graph(n, 0.2, pos=pos)
References
----------
.. [1] Penrose, Mathew, *Random Geometric Graphs*,
Oxford Studies in Probability, 5, 2003.
| 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, radius, dim=2, pos=None, p=2, seed=None, *, pos_name='pos', backend=None, **backend_kwargs) | [
0.02176002599298954,
-0.039479728788137436,
0.009754493832588196,
-0.024934563785791397,
0.018248792737722397,
0.00954766757786274,
-0.06264424324035645,
-0.016940496861934662,
0.023453112691640854,
-0.02476140856742859,
0.02289516292512417,
0.08065254241228104,
0.016219010576605797,
0.02560795098543167,
-0.0601046122610569,
-0.02903260663151741,
-0.011822754517197609,
0.009860311634838581,
-0.010187385603785515,
-0.05506382882595062,
-0.026973966509103775,
-0.0012698158388957381,
0.04806060343980789,
0.05787281692028046,
0.005444816313683987,
-0.03295749053359032,
-0.05133134126663208,
0.0426735058426857,
-0.02747419662773609,
0.02791670709848404,
-0.041365209966897964,
-0.06395254284143448,
0.016459506005048752,
0.01478565763682127,
0.012784736230969429,
0.004778644070029259,
0.05506382882595062,
0.04313525930047035,
-0.06953203678131104,
-0.038479264825582504,
-0.010177765972912312,
-0.014420105144381523,
-0.024953804910182953,
-0.02139447256922722,
0.007258151657879353,
0.00951399840414524,
0.06756959110498428,
0.046983182430267334,
-0.04463594779372215,
-0.03276509419083595,
0.014477823860943317,
-0.0003595406305976212,
-0.0063923681154847145,
-0.013563941232860088,
-0.029051845893263817,
-0.007883439771831036,
0.0016558109782636166,
-0.031476039439439774,
0.05187005177140236,
-0.03276509419083595,
0.03736336901783943,
0.012496141716837883,
0.04736797511577606,
-0.020509449765086174,
-0.0396721251308918,
-0.015555243007838726,
-0.050869591534137726,
-0.02774355188012123,
0.00009582238999428228,
0.003263522870838642,
0.029821431264281273,
0.01817183382809162,
0.063721664249897,
0.025377076119184494,
0.0014850591542199254,
0.01609395258128643,
0.06245185062289238,
-0.015891937538981438,
-0.016815438866615295,
-0.0057670800015330315,
0.007056135684251785,
0.0003697616921272129,
0.023491591215133667,
-0.06152834743261337,
0.009850692003965378,
-0.0243381354957819,
0.01414113026112318,
0.04752189293503761,
0.05614124983549118,
-0.06710784137248993,
-0.018643204122781754,
0.014833756722509861,
0.021298274397850037,
0.0033404813148081303,
0.054679036140441895,
0.020413251593708992,
0.05514078959822655,
-0.003843116806820035,
0.04621359705924988,
0.008109505288302898,
-0.00124336127191782,
0.010504839941859245,
-0.0715329572558403,
0.04652143269777298,
-0.013554321601986885,
-0.03620899096131325,
-0.03828686848282814,
0.012592339888215065,
0.011168607510626316,
-0.0017544140573590994,
-0.04513617977499962,
-0.024665210396051407,
0.05063871294260025,
0.002833036007359624,
0.04886866733431816,
-0.0017808685079216957,
-0.05475599691271782,
0.021644586697220802,
0.00759484525769949,
-0.010225865058600903,
0.023664748296141624,
0.0038767859805375338,
-0.009571717120707035,
0.018364230170845985,
-0.0074697877280414104,
0.02127903513610363,
0.04240415245294571,
-0.028744012117385864,
-0.01684429869055748,
-0.018595105037093163,
0.016536464914679527,
0.012178687378764153,
0.05394793301820755,
0.07137903571128845,
-0.033880993723869324,
0.0035689519718289375,
-0.05340922251343727,
0.010629897005856037,
0.06953203678131104,
-0.023241477087140083,
0.029398160055279732,
-0.09996913373470306,
0.009268693625926971,
0.019739864394068718,
0.03668998181819916,
0.009860311634838581,
-0.007763192057609558,
-0.03524700924754143,
0.02978295274078846,
-0.038517747074365616,
0.035150811076164246,
-0.05995069816708565,
0.05848848447203636,
-0.020971199497580528,
-0.0038984306156635284,
-0.01822955161333084,
0.028859449550509453,
-0.04844539612531662,
-0.05983525887131691,
-0.02812834456562996,
0.017883239313960075,
0.006084533873945475,
0.018268031999468803,
0.016700001433491707,
-0.03624746948480606,
0.004009058699011803,
0.0712251216173172,
-0.06903180480003357,
0.009826642461121082,
-0.0025853256229311228,
-0.05575645714998245,
-0.044943783432245255,
-0.011284044943749905,
0.0009337234660051763,
-0.04282742366194725,
0.03316912800073624,
-0.006604004185646772,
-0.012159448117017746,
-0.06256728619337082,
-0.026069702580571175,
-0.004374611657112837,
-0.03447742387652397,
-0.0008934404468163848,
0.010389401577413082,
-0.018152594566345215,
0.0736493170261383,
0.04579032585024834,
-0.016911637037992477,
-0.030437098816037178,
0.005642022471874952,
-0.05995069816708565,
-0.020028458908200264,
0.030167745426297188,
0.04209631681442261,
0.06133595108985901,
0.0007581617683172226,
0.03264965862035751,
0.03343848139047623,
-0.11474516987800598,
0.08580876141786575,
0.06833917647600174,
0.00650780601426959,
0.018056396394968033,
-0.03853698447346687,
-0.010620277374982834,
-0.023914864286780357,
-0.024992283433675766,
-0.005180271342396736,
0.03971060365438461,
0.01754654571413994,
0.016940496861934662,
-0.0019492153078317642,
0.01540132611989975,
0.04513617977499962,
-0.028570855036377907,
-0.0002341824147151783,
-0.018373848870396614,
0.012813596054911613,
-0.04786820709705353,
-0.04352005198597908,
-0.03461210057139397,
0.014602881856262684,
-0.016440266743302345,
-0.011322524398565292,
0.05448663979768753,
0.015362846665084362,
0.007291820831596851,
-0.03640138730406761,
0.03620899096131325,
-0.05752650275826454,
0.09127281606197357,
-0.05036935955286026,
0.061143554747104645,
-0.02818606235086918,
-0.02218329720199108,
-0.04525161534547806,
0.014218089170753956,
0.0007431308040395379,
-0.0022233801428228617,
0.020778803154826164,
-0.0046896603889763355,
-0.04648295417428017,
-0.053447701036930084,
0.030186984688043594,
0.04967673122882843,
-0.013054091483354568,
-0.005136982072144747,
-0.0205864068120718,
0.08442351222038269,
-0.0011363407829776406,
-0.057603463530540466,
-0.05225484445691109,
-0.012977132573723793,
-0.013217628002166748,
0.023087559267878532,
-0.029128804802894592,
-0.0040499428287148476,
-0.030995048582553864,
0.020971199497580528,
0.020778803154826164,
-0.02368398755788803,
0.0023291981779038906,
-0.03503537178039551,
0.04609816148877144,
0.03480449691414833,
-0.016940496861934662,
-0.05367857590317726,
0.04709862172603607,
-0.021663827821612358,
-0.041095856577157974,
-0.05133134126663208,
0.011053169146180153,
0.06410645693540573,
-0.0021656611934304237,
0.04375092685222626,
-0.0386139452457428,
0.010620277374982834,
0.04663687199354172,
0.0330536887049675,
0.012399943545460701,
-0.0471755787730217,
0.01361204031854868,
0.02218329720199108,
-0.008907950483262539,
-0.05575645714998245,
0.06680000573396683,
-0.08065254241228104,
0.013236867263913155,
0.012765496969223022,
-0.051254384219646454,
-0.04421267658472061,
-0.0160843338817358,
-0.027570394799113274,
0.007869009859859943,
0.022548850625753403,
0.016344068571925163,
0.02716636285185814,
-0.012236407026648521,
0.012775116600096226,
-0.03188007324934006,
0.13221475481987,
-0.019932260736823082,
0.04444355145096779,
-0.050023045390844345,
0.053332261741161346,
0.05063871294260025,
0.012371083721518517,
-0.019076095893979073,
-0.04759885370731354,
0.02506924234330654,
-0.0371132530272007,
-0.01807563565671444,
0.041942398995161057,
0.012265265919268131,
0.025684909895062447,
-0.10743410885334015,
0.023760946467518806,
-0.06576106697320938,
0.023491591215133667,
-0.0074216886423528194,
-0.007089804857969284,
0.002960498444736004,
-0.04732949659228325,
0.035054612904787064,
-0.06949355453252792,
-0.042211756110191345,
0.021894702687859535,
0.039864521473646164,
-0.004179810173809528,
-0.0024145739153027534,
-0.025319356471300125,
0.05298595130443573,
0.01747920736670494,
-0.010956970974802971,
-0.05294746905565262,
0.07811290770769119,
0.05571797862648964,
0.02993686869740486,
-0.015410945750772953,
-0.05821913108229637,
0.005579493474215269,
-0.03074493445456028,
0.01657494343817234,
0.058411527425050735,
-0.0160843338817358,
-0.015035773627460003,
0.0023664748296141624,
-0.02310679852962494,
-0.0012866504257544875,
-0.05213940516114235,
0.07591959089040756,
0.037459567189216614,
-0.03268813714385033,
0.01441048551350832,
0.026935486122965813,
-0.0018097279826179147,
0.01540132611989975,
0.032534219324588776,
-0.003934504929929972,
0.07057097554206848,
-0.014179609715938568,
-0.006517425645142794,
0.04305829852819443,
0.016334448009729385,
0.02224101684987545,
0.03921037167310715,
0.021355992183089256,
0.06302903592586517,
-0.004987874999642372,
-0.021105878055095673,
0.010312443599104881,
-0.08373088389635086,
-0.11597651243209839,
0.01743110828101635,
0.02668537199497223,
-0.018633585423231125,
-0.0330536887049675,
-0.012409563176333904,
-0.0025131769943982363,
0.036593783646821976,
-0.014949195086956024,
0.005969095975160599,
0.03203399106860161,
0.009975749999284744,
-0.01489147637039423,
-0.011611118912696838,
0.03701705485582352,
0.05460207909345627,
0.013342685997486115,
-0.026762329041957855,
-0.055371664464473724,
-0.04340461269021034,
0.05067719519138336,
0.055102311074733734,
0.00681564025580883,
0.04744493588805199,
0.06487604230642319,
0.03634366765618324,
-0.07345692068338394,
-0.0029340439941734076,
0.01470869965851307,
-0.02512696012854576,
-0.01769084297120571,
-0.05202396959066391,
-0.0199899785220623,
-0.005752650089561939,
-0.015391706489026546,
-0.012611579149961472,
0.05502535030245781,
0.010870392434298992,
0.027935948222875595,
0.014237328432500362,
0.011139747686684132,
0.0008693909039720893,
0.025088481605052948,
-0.0348622165620327,
-0.004439545329660177,
0.05244724079966545,
0.004439545329660177,
-0.026377536356449127,
0.04067258536815643,
-0.08072949945926666,
0.02678157016634941,
0.008710743859410286,
0.004013868514448404,
0.020817283540964127,
0.008734793402254581,
-0.03543940559029579,
-0.00697917677462101,
0.05156221613287926,
-0.020355531945824623,
0.00580074917525053,
0.0022606567945331335,
0.02608894184231758,
0.03853698447346687,
-0.04228871315717697,
-0.01791209913790226,
-0.015795739367604256,
-0.04944585636258125,
-0.020836522802710533,
0.029879150912165642,
0.009672725573182106,
0.029205763712525368,
-0.041673045605421066,
0.006084533873945475,
-0.003910455387085676,
0.003934504929929972,
0.010322063229978085,
0.00834038108587265,
-0.007258151657879353,
0.05864240229129791,
0.006483756471425295,
0.07684309780597687,
0.04771428927779198,
-0.04625207930803299,
0.06287512183189392,
-0.03426578640937805,
0.01363128051161766,
-0.03132212162017822,
0.004696875344961882,
0.035150811076164246,
0.007960398681461811,
-0.06476060301065445,
-0.018470047041773796,
0.006320219486951828,
-0.020605647936463356,
-0.0005372066516429186,
-0.0017652363749220967,
0.006753111258149147,
-0.0011615928960964084,
0.08350000530481339,
-0.011264805682003498,
-0.036593783646821976,
-0.04471290856599808,
0.019114576280117035,
0.015603342093527317,
-0.0784207433462143,
0.04806060343980789,
0.005295709241181612,
-0.030821891501545906,
0.022164057940244675,
-0.007219672203063965,
0.030667975544929504,
-0.0008459426462650299,
-0.03391947224736214,
-0.04190392047166824,
-0.007537126075476408,
0.008147984743118286,
0.02822454273700714,
-0.06187466159462929,
-0.03128364309668541,
-0.004617511760443449,
0.049869127571582794,
0.007998877204954624,
-0.0231452789157629,
0.028378458693623543,
-0.014304667711257935,
-0.025319356471300125,
0.03832535073161125,
-0.010379781946539879,
-0.020971199497580528,
0.028590094298124313,
0.0006673747557215393,
0.02133675292134285,
0.06495299935340881,
-0.04313525930047035,
0.07203318923711777,
0.012178687378764153,
0.029475117102265358,
0.04517465829849243,
0.053178347647190094,
0.058257609605789185,
0.05571797862648964,
0.013640900142490864,
0.007181193213909864,
0.0008693909039720893,
-0.01813335344195366,
0.02337615378201008,
-0.013284966349601746,
-0.04844539612531662,
0.048522353172302246,
0.06818526238203049,
0.005920996889472008,
0.019913019612431526,
0.01358318142592907,
-0.015228169970214367,
0.0408649817109108,
-0.044289637356996536,
0.011216706596314907,
0.03736336901783943,
0.03324608504772186,
0.009672725573182106,
-0.060874197632074356,
0.014939575456082821,
-0.011880473233759403,
0.02891716919839382,
-0.021798504516482353,
0.0035593321081250906,
-0.02860933542251587,
-0.038036756217479706,
0.008220133371651173,
-0.005420766770839691,
0.013939114287495613,
0.02025933377444744,
0.030610255897045135,
0.047291018068790436,
0.030225463211536407,
-0.0220870990306139,
-0.04902258515357971,
-0.03921037167310715,
0.0718407928943634,
-0.0016269515035673976,
-0.08934886008501053,
-0.05918111279606819,
0.09696774929761887,
-0.024261176586151123,
0.0080758361145854,
-0.03495841473340988,
-0.00009770126052899286,
0.04190392047166824,
-0.0456748902797699,
-0.06768503040075302,
-0.01662304252386093,
-0.004162975586950779,
-0.032322581857442856,
-0.016344068571925163,
-0.04355853050947189,
0.041403692215681076,
-0.03074493445456028,
0.009475518949329853,
0.0393642894923687,
0.03153375908732414,
0.020240094512701035,
-0.026589173823595047,
0.01537246722728014,
-0.006300979759544134,
-0.042057838290929794,
0.006459706928580999,
-0.01791209913790226,
-0.01967252418398857,
-0.01526664849370718,
0.00021358998492360115,
0.032322581857442856,
0.00850391760468483,
-0.02331843599677086,
0.0411728136241436,
-0.05818064883351326,
0.031302884221076965,
0.007003226317465305,
0.03126440569758415,
0.0534861795604229,
0.000044040723878424615,
0.04552097246050835,
-0.019124194979667664,
-0.03041785955429077,
0.015353227034211159,
0.007489026989787817,
0.01409303117543459,
-0.0005693729035556316,
-0.030937330797314644,
-0.026704611256718636,
0.030456339940428734,
-0.02843617834150791,
0.0036483153235167265,
-0.04305829852819443,
0.007474597543478012,
0.015006913803517818,
-0.030918089672923088,
0.029609795659780502,
-0.055794935673475266,
-0.029186522588133812,
-0.002505962271243334,
-0.033342283219099045,
-0.02699320577085018,
-0.011563019827008247,
0.0003018217394128442,
-0.0694165974855423,
0.06518387794494629,
0.018643204122781754,
-0.025954265147447586,
-0.028089864179491997,
-0.010389401577413082,
0.06048940494656563,
-0.007157143671065569,
0.026877768337726593,
-0.04340461269021034,
-0.014391245320439339,
-0.04255807027220726,
-0.04848387464880943,
0.04309677705168724,
-0.0333615243434906,
-0.047675810754299164,
-0.011457201093435287,
-0.027878228574991226,
-0.07464977353811264,
-0.02491532452404499,
0.014660600572824478,
-0.030033066868782043,
-0.0037998275365680456,
0.01609395258128643,
-0.04775276780128479,
0.027724310755729675,
-0.04217327758669853,
-0.04983064904808998,
-0.01157263945788145,
-0.020894242450594902,
0.028089864179491997,
0.02406878024339676,
0.009412990882992744,
-0.06803134083747864,
-0.040133874863386154,
0.018152594566345215,
0.013073330745100975,
-0.017623504623770714,
0.02818606235086918,
0.017979437485337257,
-0.02229873463511467,
-0.008114315569400787,
0.02010541595518589,
-0.02181774377822876,
0.014516303315758705,
0.051831573247909546,
0.047560371458530426,
0.057295627892017365,
-0.021721545606851578,
0.03107200749218464,
0.028474656865000725,
-0.03432350605726242,
0.03784435987472534,
0.00032286508940160275,
-0.018537387251853943,
-0.013746717944741249,
0.043443091213703156,
0.0001227278116857633,
-0.008628975600004196,
0.019970739260315895,
-0.00807102583348751,
0.028474656865000725,
-0.06476060301065445,
-0.023876383900642395,
0.10566406697034836,
0.02962903492152691,
-0.03368859738111496,
-0.01914343424141407,
0.052908990532159805,
0.05475599691271782,
-0.03813295438885689,
-0.05294746905565262,
0.03207246959209442,
0.05845000594854355,
-0.012438423000276089,
0.03107200749218464,
0.06395254284143448,
0.03722868859767914,
0.03747880458831787,
-0.004391446243971586,
-0.0426735058426857,
0.007253341842442751,
0.035150811076164246,
-0.037036292254924774,
0.036978576332330704,
-0.012880934402346611,
-0.0456748902797699,
0.05968134105205536,
-0.02458825148642063,
-0.02266428805887699,
-0.021355992183089256,
0.02395334281027317,
0.020817283540964127,
-0.010062328539788723,
-0.07137903571128845,
-0.013910254463553429,
0.030494818463921547,
-0.04009539633989334,
-0.04956129565834999,
0.031937792897224426,
0.014525922946631908,
-0.0030206223018467426,
-0.05460207909345627,
-0.05987373739480972,
0.0018638394540175796,
0.0016582158859819174,
-0.043981801718473434,
0.034669820219278336,
-0.017498446628451347,
0.0037926125805824995,
0.0356125608086586,
-0.11651521921157837,
-0.003650720464065671,
-0.01363128051161766,
0.014881855808198452,
0.040133874863386154,
-0.011332144029438496,
0.016873158514499664,
0.007176383398473263,
0.012678918428719044,
-0.014593261294066906,
0.037074774503707886,
-0.046329036355018616,
0.04775276780128479,
-0.017132893204689026,
0.027820508927106857,
-0.03776739910244942,
-0.04059562459588051,
0.009966130368411541,
-0.01941278949379921,
0.003691604593768716,
-0.009206164628267288,
0.005112932529300451,
0.025569472461938858,
0.02555023320019245,
0.024530531838536263,
0.031937792897224426,
-0.003205803921446204,
-0.018729783594608307,
0.06041244789958,
-0.03089885041117668,
-0.04532857611775398,
-0.025377076119184494,
-0.036439865827560425,
-0.042365673929452896,
-0.01526664849370718,
-0.0172771904617548,
0.0020021244417876005,
-0.03297673165798187,
0.03326532617211342,
0.005550634115934372,
0.05094654858112335
]
|
31,035 | networkx.generators.random_graphs | random_kernel_graph | Returns an random graph based on the specified kernel.
The algorithm chooses each of the $[n(n-1)]/2$ possible edges with
probability specified by a kernel $\kappa(x,y)$ [1]_. The kernel
$\kappa(x,y)$ must be a symmetric (in $x,y$), non-negative,
bounded function.
Parameters
----------
n : int
The number of nodes
kernel_integral : function
Function that returns the definite integral of the kernel $\kappa(x,y)$,
$F(y,a,b) := \int_a^b \kappa(x,y)dx$
kernel_root: function (optional)
Function that returns the root $b$ of the equation $F(y,a,b) = r$.
If None, the root is found using :func:`scipy.optimize.brentq`
(this requires SciPy).
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Notes
-----
The kernel is specified through its definite integral which must be
provided as one of the arguments. If the integral and root of the
kernel integral can be found in $O(1)$ time then this algorithm runs in
time $O(n+m)$ where m is the expected number of edges [2]_.
The nodes are set to integers from $0$ to $n-1$.
Examples
--------
Generate an Erdős–Rényi random graph $G(n,c/n)$, with kernel
$\kappa(x,y)=c$ where $c$ is the mean expected degree.
>>> def integral(u, w, z):
... return c * (z - w)
>>> def root(u, w, r):
... return r / c + w
>>> c = 1
>>> graph = nx.random_kernel_graph(1000, integral, root)
See Also
--------
gnp_random_graph
expected_degree_graph
References
----------
.. [1] Bollobás, Béla, Janson, S. and Riordan, O.
"The phase transition in inhomogeneous random graphs",
*Random Structures Algorithms*, 31, 3--122, 2007.
.. [2] Hagberg A, Lemons N (2015),
"Fast Generation of Sparse Random Kernel Graphs".
PLoS ONE 10(9): e0135177, 2015. doi:10.1371/journal.pone.0135177
| 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, kernel_integral, kernel_root=None, seed=None, *, backend=None, **backend_kwargs) | [
0.003537906799465418,
0.0015090598026290536,
0.015320549719035625,
0.004910432733595371,
-0.02494978718459606,
-0.0408547967672348,
-0.0648464560508728,
-0.036294084042310715,
0.01211080327630043,
-0.030066218227148056,
0.006457817740738392,
0.041966233402490616,
-0.036830637603998184,
0.1071576178073883,
-0.043039340525865555,
0.013049773871898651,
0.03466525673866272,
0.04740842804312706,
-0.005897309631109238,
0.027345120906829834,
-0.0400499664247036,
0.0019869287498295307,
0.00009296886128140613,
0.0710168331861496,
-0.03455028310418129,
0.010721510276198387,
-0.039130158722400665,
0.010759835131466389,
-0.015598407946527004,
0.05928928032517433,
0.039245136082172394,
-0.12348420172929764,
0.020983116701245308,
0.0390726700425148,
-0.00014147434558253735,
0.010175374336540699,
0.02769004926085472,
0.06116722151637077,
-0.10953378677368164,
-0.036792315542697906,
0.07090185582637787,
-0.05541842430830002,
0.08339591324329376,
0.01310726162046194,
0.024700673297047615,
-0.02389584109187126,
0.030947702005505562,
0.012973123230040073,
-0.09650317579507828,
-0.009830445982515812,
0.01611579954624176,
-0.0705185979604721,
0.02621452324092388,
-0.0023833562154322863,
-0.020408237352967262,
0.018444063141942024,
-0.0031283048447221518,
0.044610679149627686,
0.017840439453721046,
0.025313878431916237,
0.06300684064626694,
-0.019545916467905045,
-0.01459236815571785,
-0.03525929898023605,
-0.02445155940949917,
0.021998737007379532,
-0.04855819046497345,
-0.026789404451847076,
-0.001455164747312665,
0.06204870343208313,
0.05035948008298874,
0.06407994776964188,
-0.008077062666416168,
0.05511182174086571,
0.054728567600250244,
0.0442657507956028,
0.048634838312864304,
0.027038518339395523,
-0.05212244391441345,
0.019718380644917488,
0.004194227978587151,
-0.02581210806965828,
0.01180420070886612,
-0.03432033210992813,
0.005490103270858526,
-0.015473851002752781,
0.006036239210516214,
0.003147467505186796,
0.0002807030687108636,
-0.10186871886253357,
-0.048596516251564026,
-0.04986124858260155,
0.05568670108914375,
0.016336170956492424,
0.03159923106431961,
-0.03328554704785347,
-0.006304516457021236,
-0.03234657645225525,
0.007516554556787014,
-0.024566534906625748,
-0.0450705848634243,
0.04369087144732475,
-0.038172025233507156,
0.0005952402134425938,
0.0065057240426540375,
0.007209951989352703,
-0.05216076970100403,
0.015138504095375538,
0.02084897831082344,
-0.03537427634000778,
-0.11712219566106796,
0.0436142235994339,
0.07979333400726318,
0.018242856487631798,
-0.022937707602977753,
-0.013279725797474384,
0.01500436570495367,
0.011622155085206032,
0.031963322311639786,
0.03221243619918823,
0.016307426616549492,
0.027096007019281387,
-0.03290229290723801,
-0.000196117878658697,
0.0007593205664306879,
-0.024068305268883705,
0.04825158789753914,
-0.008580083027482033,
-0.01290605403482914,
-0.03876606747508049,
0.010520302690565586,
0.014860645867884159,
-0.04706349968910217,
0.07017367333173752,
-0.012034152634441853,
-0.034396979957818985,
-0.04790665954351425,
0.005753589794039726,
0.06913889199495316,
0.004019368439912796,
-0.0008311805431731045,
-0.06683936715126038,
0.08899141103029251,
0.01290605403482914,
-0.03951341286301613,
-0.02150050923228264,
0.01721765287220478,
-0.05710473656654358,
0.0017976973904296756,
-0.012197035364806652,
0.0400499664247036,
-0.0012815031222999096,
0.020887304097414017,
-0.03455028310418129,
-0.039551738649606705,
0.017696719616651535,
-0.041506327688694,
-0.0003613958542700857,
-0.023205986246466637,
0.014688181690871716,
-0.030621936544775963,
-0.05465191602706909,
0.04874981567263603,
0.054306987673044205,
0.010098723694682121,
-0.03075607493519783,
0.04947799816727638,
0.0018683597445487976,
0.017438024282455444,
-0.03548925369977951,
-0.07431280612945557,
-0.001143771456554532,
-0.06607286632061005,
-0.06162712723016739,
0.05265899747610092,
-0.0021641834173351526,
-0.02602289617061615,
-0.031043514609336853,
0.02929971180856228,
0.03432033210992813,
0.03830616548657417,
-0.04729345440864563,
0.06779750436544418,
-0.05921262875199318,
-0.03064109943807125,
-0.035450927913188934,
-0.00637158565223217,
0.04300101846456528,
0.01806081086397171,
0.008541757240891457,
0.021366368979215622,
0.024815648794174194,
0.036159947514534,
0.06089894473552704,
0.025218065828084946,
0.005207453854382038,
0.02517974004149437,
0.01459236815571785,
-0.012915635481476784,
0.01111434493213892,
0.04560713842511177,
0.0021953226532787085,
0.020504049956798553,
0.02316766045987606,
0.027939163148403168,
0.0076794372871518135,
-0.03284480422735214,
-0.041966233402490616,
0.023148497566580772,
-0.02726846933364868,
0.004910432733595371,
-0.010472395457327366,
0.028571531176567078,
-0.027019355446100235,
-0.015397200360894203,
-0.06285353749990463,
0.0192105695605278,
0.017179327085614204,
-0.00008615713159088045,
-0.03493353724479675,
0.032078299671411514,
-0.058829378336668015,
0.010903555899858475,
0.02579294517636299,
0.005744008347392082,
0.043767523020505905,
-0.014582786709070206,
0.004048112779855728,
-0.01511934120208025,
0.028993109241127968,
0.03378377482295036,
-0.0008036341750994325,
0.03673482686281204,
-0.02834158018231392,
-0.03916848450899124,
-0.030200358480215073,
0.003092374885454774,
-0.03959006443619728,
-0.03579585626721382,
0.018971037119627,
-0.02937636338174343,
0.01981419324874878,
-0.020312422886490822,
-0.009011242538690567,
0.022267015650868416,
0.015560083091259003,
0.028284091502428055,
-0.05813952162861824,
-0.06852568686008453,
-0.01979503221809864,
-0.09336049854755402,
-0.01247489359229803,
0.024777323007583618,
0.03148425742983818,
0.02613787353038788,
-0.026463638991117477,
-0.02150050923228264,
0.009739424102008343,
-0.004000206012278795,
0.05859942361712456,
0.007166835945099592,
-0.02033158577978611,
-0.1112200990319252,
0.03169504553079605,
-0.0014743274077773094,
-0.005950007122009993,
-0.07074855268001556,
0.06952214241027832,
-0.013461771421134472,
-0.03131179139018059,
0.061780426651239395,
0.0006784780416637659,
0.00885315053164959,
0.00045062199933454394,
0.02698102965950966,
0.02339761145412922,
-0.012426987290382385,
0.019517172127962112,
-0.01960340514779091,
-0.04357589781284332,
-0.04127637669444084,
-0.043460920453071594,
0.024719836190342903,
0.04537718743085861,
-0.005863775033503771,
0.0041798558086156845,
-0.023320961743593216,
-0.06204870343208313,
0.02433658204972744,
-0.03351549804210663,
0.015435525216162205,
-0.028494881466031075,
0.005758380517363548,
0.05005287751555443,
-0.0017378140473738313,
-0.004840967711061239,
0.058637749403715134,
0.02349342592060566,
0.020159121602773666,
-0.008925010450184345,
0.037961237132549286,
-0.009677144698798656,
0.09113762527704239,
0.003961880691349506,
-0.01670026034116745,
-0.032059136778116226,
0.013643816113471985,
-0.025333041325211525,
-0.019871681928634644,
0.020044146105647087,
-0.09060107171535492,
0.02517974004149437,
0.05760296806693077,
0.030832724645733833,
-0.009451983496546745,
-0.06726095080375671,
0.011593411676585674,
0.0006659025675617158,
0.04047154635190964,
-0.003851695451885462,
-0.01733262836933136,
0.03748216852545738,
-0.001366537413559854,
0.0465269461274147,
-0.01757216267287731,
-0.002178555354475975,
0.04641197249293327,
0.07500266283750534,
0.0013365957420319319,
0.022286176681518555,
-0.04204288497567177,
0.01658528484404087,
-0.01064485963433981,
0.018798572942614555,
-0.08753504604101181,
0.08086644113063812,
-0.02749842219054699,
-0.02326347306370735,
0.06664774566888809,
-0.08600203692913055,
0.021653810515999794,
-0.04668024927377701,
-0.005221826024353504,
-0.010664022527635098,
0.04633532091975212,
0.044074125587940216,
0.012101221829652786,
-0.004096019547432661,
-0.05695143714547157,
0.06929218769073486,
-0.013653397560119629,
0.04192790761590004,
-0.002766609424725175,
0.02579294517636299,
-0.01916266418993473,
0.033534660935401917,
-0.0098496088758111,
0.0044936444610357285,
0.010165792889893055,
0.07028865069150925,
-0.023359287530183792,
-0.0056673577055335045,
-0.027766698971390724,
-0.013672560453414917,
0.027670886367559433,
0.006280562840402126,
0.002358205383643508,
0.043882500380277634,
0.03847862780094147,
-0.05254402384161949,
0.06975209712982178,
-0.06714597344398499,
-0.04510891065001488,
0.049248043447732925,
0.010405326262116432,
-0.028782321140170097,
-0.03771212324500084,
0.020044146105647087,
0.03211662545800209,
0.03305559605360031,
-0.012350336648523808,
-0.03959006443619728,
0.009964585304260254,
0.03959006443619728,
-0.006179959047585726,
-0.012043734081089497,
0.07258816808462143,
0.003760672640055418,
-0.00655363081023097,
-0.027019355446100235,
0.01284856628626585,
-0.029855430126190186,
0.07323969900608063,
0.007018325384706259,
-0.05499684438109398,
0.005068524274975061,
0.04116139933466911,
-0.026061221957206726,
-0.03709891811013222,
-0.003533116076141596,
0.002505518263205886,
0.016939794644713402,
-0.05055110529065132,
-0.023646727204322815,
-0.0056721484288573265,
-0.033956240862607956,
0.027843350544571877,
0.02803497575223446,
0.011296390555799007,
0.014966039918363094,
-0.015157666988670826,
0.02295687049627304,
-0.019028523936867714,
-0.011670062318444252,
0.023665890097618103,
-0.0010820917086675763,
-0.005916472524404526,
-0.020178284496068954,
0.010903555899858475,
0.014975621365010738,
0.03244239091873169,
-0.007775250822305679,
0.0065057240426540375,
-0.02487313747406006,
0.04411245137453079,
0.005815868265926838,
-0.05104933679103851,
0.019660891965031624,
-0.0815562978386879,
0.022094551473855972,
0.05396205931901932,
-0.03962838649749756,
0.033458009362220764,
-0.043039340525865555,
0.024624021723866463,
0.008556129410862923,
0.028935622423887253,
0.005365545861423016,
0.05679813399910927,
-0.02295687049627304,
0.01211080327630043,
0.02222868986427784,
0.011708387173712254,
-0.057449664920568466,
-0.029644640162587166,
-0.04568378999829292,
-0.02171129733324051,
-0.001282700803130865,
0.01606789417564869,
-0.020465724170207977,
-0.005729636177420616,
-0.00529368594288826,
0.0711701288819313,
-0.006726094987243414,
-0.04748507961630821,
0.035757530480623245,
0.05974918603897095,
-0.02801581472158432,
-0.034607771784067154,
0.10064230859279633,
0.014822320081293583,
0.00700395368039608,
0.01233117375522852,
0.0958133190870285,
0.034282006323337555,
-0.01918182522058487,
0.054192014038562775,
-0.020044146105647087,
-0.015263061039149761,
0.03803788870573044,
-0.019009362906217575,
0.0002275566221214831,
0.015560083091259003,
-0.03305559605360031,
-0.01679607480764389,
-0.038708578795194626,
-0.009442402049899101,
-0.03970503807067871,
-0.011373041197657585,
-0.011238901875913143,
0.017342209815979004,
0.004016973543912172,
0.010309512726962566,
0.032174110412597656,
0.022918544709682465,
-0.027766698971390724,
-0.035546742379665375,
0.0253713671118021,
0.012014989741146564,
0.0027091214433312416,
-0.07316304743289948,
-0.0800999328494072,
0.02232450246810913,
0.037022266536951065,
-0.05150923877954483,
-0.012647357769310474,
-0.01716974563896656,
-0.047983311116695404,
-0.007554879877716303,
-0.07634405046701431,
0.01927763968706131,
-0.011210158467292786,
-0.014659437350928783,
-0.04656527191400528,
0.0073632532730698586,
0.0004200815164949745,
-0.00216657854616642,
-0.0174284428358078,
0.0022108922712504864,
0.06342841684818268,
-0.00012800061085727066,
-0.02381919138133526,
0.03759714588522911,
0.03686896339058876,
-0.014611531049013138,
0.01627868227660656,
-0.008599244989454746,
0.0045607141219079494,
0.0513942651450634,
-0.028782321140170097,
0.034818559885025024,
0.034703582525253296,
0.03146509453654289,
-0.04595206677913666,
0.027536747977137566,
-0.008814824745059013,
0.01400790736079216,
-0.011085600592195988,
0.02150050923228264,
-0.007051859982311726,
-0.024700673297047615,
0.03640906140208244,
0.040088292211294174,
0.02012079581618309,
-0.010865230113267899,
-0.014027069322764874,
0.01006997935473919,
0.005451777949929237,
-0.05235239490866661,
-0.05170086771249771,
0.008239945396780968,
0.019268058240413666,
-0.007540508173406124,
-0.012676102109253407,
-0.006476980168372393,
-0.012973123230040073,
-0.040701497346162796,
0.0009263950050808489,
-0.012771915644407272,
-0.01922973245382309,
-0.002457611495628953,
0.015033109113574028,
-0.01850155182182789,
-0.02234366536140442,
0.00671651354059577,
-0.05652985721826553,
-0.0779920369386673,
0.048519864678382874,
0.06028573960065842,
0.024604860693216324,
-0.06714597344398499,
0.01500436570495367,
-0.02220952697098255,
0.0017905114218592644,
0.03778877109289169,
0.04307766631245613,
-0.024719836190342903,
-0.0013569560833275318,
-0.019574660807847977,
-0.010970625095069408,
0.02401081658899784,
0.0342053547501564,
0.030162032693624496,
0.01770630106329918,
-0.042924366891384125,
-0.007209951989352703,
-0.04970794916152954,
-0.05001455172896385,
-0.009830445982515812,
0.008925010450184345,
0.000021183725039009005,
0.06185707822442055,
-0.02274608239531517,
0.016336170956492424,
0.0442657507956028,
0.028475718572735786,
-0.02939552627503872,
0.0188081543892622,
0.0019474056316539645,
-0.02866734378039837,
-0.07688060402870178,
-0.022477803751826286,
0.032289087772369385,
-0.044610679149627686,
0.004730782471597195,
0.0423111617565155,
0.04767670854926109,
-0.015215154737234116,
-0.056721482425928116,
-0.07546257227659225,
0.03562339022755623,
0.032499875873327255,
0.0019701614510267973,
-0.0014994784723967314,
0.055150143802165985,
0.016786493360996246,
-0.0036193481646478176,
-0.06316013634204865,
0.02529471553862095,
0.0034684420097619295,
-0.03654319792985916,
-0.001748593058437109,
-0.027153493836522102,
-0.06381166726350784,
-0.03799956291913986,
-0.05396205931901932,
-0.045032259076833725,
0.0186452716588974,
0.023340124636888504,
0.047255128622055054,
-0.035431765019893646,
0.019833356142044067,
0.018252436071634293,
0.05108766257762909,
-0.025352204218506813,
-0.006170377600938082,
-0.025658806785941124,
-0.025735456496477127,
0.01576129160821438,
-0.0032408854458481073,
0.01668109931051731,
-0.05794789269566536,
0.0291847363114357,
-0.001885127043351531,
0.024585697799921036,
-0.02381919138133526,
0.05170086771249771,
0.00797645840793848,
0.0020252540707588196,
0.08776500076055527,
-0.06664774566888809,
0.010769416578114033,
-0.06335176527500153,
-0.003676836146041751,
-0.03782709687948227,
0.005734426900744438,
-0.020197447389364243,
0.019239313900470734,
0.010961043648421764,
-0.02600373513996601,
-0.022305339574813843,
0.0507427342236042,
0.0081058070063591,
-0.0031235141213983297,
-0.03278731554746628,
-0.0024252745788544416,
0.017811695113778114,
-0.005734426900744438,
-0.0030205147340893745,
-0.03414786607027054,
0.06591956317424774,
0.004608620423823595,
0.029012272134423256,
0.044189102947711945,
0.007818366400897503,
0.05813952162861824,
0.022631105035543442,
-0.03978168964385986,
-0.0366390123963356,
0.007842320017516613,
-0.028092464432120323,
-0.027440933510661125,
-0.006227865815162659,
-0.06511472910642624,
-0.04802163317799568,
0.0299129169434309,
-0.021328045055270195,
-0.0047738985158503056,
0.011497598141431808,
0.011986246332526207,
0.0773405134677887,
-0.002876794897019863,
-0.002946259453892708,
-0.0053415922448039055,
0.0016431984258815646,
0.050627756863832474,
-0.014774413779377937,
0.018194949254393578,
-0.05721971392631531,
-0.0022528106346726418,
0.021538833156228065,
-0.02517974004149437,
0.023455100134015083,
0.05032115429639816,
0.03865109384059906,
0.06392664462327957,
-0.02579294517636299,
-0.017294304445385933,
-0.053770434111356735,
-0.04752340540289879,
0.021193906664848328,
-0.03890020772814751,
-0.03604497015476227,
0.058177847415208817,
-0.07596080005168915,
0.03537427634000778,
-0.05112598463892937,
0.008987288922071457,
-0.03253820165991783,
0.010232862085103989,
-0.018079973757267,
-0.04530053585767746,
0.04920972138643265,
-0.00857529230415821,
0.004306808579713106,
-0.0402032695710659,
-0.005605079233646393,
0.031560905277729034,
-0.05453693866729736,
0.001576129114255309,
-0.0619337297976017,
-0.013806698843836784,
0.03612162172794342,
0.007377625443041325,
0.023838354274630547,
-0.008350130170583725,
0.03163755685091019,
-0.05373210832476616,
-0.01211080327630043,
-0.03610245883464813,
0.01422827783972025,
0.032825641334056854,
0.0013749210629612207,
0.015033109113574028,
-0.00384690472856164,
-0.03393707796931267,
0.011037694290280342,
0.0092411944642663,
0.023665890097618103,
0.00850343145430088,
0.01665235497057438,
0.0034253261983394623,
-0.052199095487594604,
0.04457235336303711,
-0.006117680110037327,
0.03600664436817169,
-0.030315333977341652,
0.00811538752168417,
0.008398037403821945,
0.0003272623580414802,
0.05453693866729736,
-0.017907509580254555,
-0.0186452716588974,
0.0549585185945034,
0.027670886367559433,
0.004982292652130127,
0.047983311116695404,
-0.029223062098026276,
-0.032078299671411514,
-0.07339300215244293,
-0.016317008063197136,
0.013653397560119629,
0.061895404011011124,
-0.04073982313275337,
-0.002276764018461108,
0.02065735124051571,
0.01592417247593403,
0.047140151262283325
]
|
31,036 | networkx.generators.trees | random_labeled_rooted_forest | Returns a labeled rooted forest with `n` nodes.
The returned forest is chosen uniformly at random using a
generalization of Prüfer sequences [1]_ in the form described in [2]_.
Parameters
----------
n : int
The number of nodes.
seed : random_state
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph`
A `networkx.Graph` with integer nodes 0 <= node <= `n` - 1.
The "roots" graph attribute is a set of integers containing the roots.
References
----------
.. [1] Knuth, Donald E. "Another Enumeration of Trees."
Canadian Journal of Mathematics, 20 (1968): 1077-1086.
https://doi.org/10.4153/CJM-1968-104-8
.. [2] Rubey, Martin. "Counting Spanning Trees". Diplomarbeit
zur Erlangung des akademischen Grades Magister der
Naturwissenschaften an der Formal- und Naturwissenschaftlichen
Fakultät der Universität Wien. Wien, May 2000.
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,037 | networkx.generators.trees | random_labeled_rooted_tree | Returns a labeled rooted tree with `n` nodes.
The returned tree is chosen uniformly at random from all labeled rooted trees.
Parameters
----------
n : int
The number of nodes
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph`
A `networkx.Graph` with integer nodes 0 <= node <= `n` - 1.
The root of the tree is selected uniformly from the nodes.
The "root" graph attribute identifies the root of the tree.
Notes
-----
This function returns the result of :func:`random_labeled_tree`
with a randomly selected root.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,038 | networkx.generators.trees | random_labeled_tree | Returns a labeled tree on `n` nodes chosen uniformly at random.
Generating uniformly distributed random Prüfer sequences and
converting them into the corresponding trees is a straightforward
method of generating uniformly distributed random labeled trees.
This function implements this method.
Parameters
----------
n : int
The number of nodes, greater than zero.
seed : random_state
Indicator of random number generation state.
See :ref:`Randomness<randomness>`
Returns
-------
:class:`networkx.Graph`
A `networkx.Graph` with nodes in the set {0, …, *n* - 1}.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,039 | networkx.drawing.layout | random_layout | Position nodes uniformly at random in the unit square.
For every node, a position is generated by choosing each of dim
coordinates uniformly at random on the interval [0.0, 1.0).
NumPy (http://scipy.org) is required for this function.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G.
center : array-like or None
Coordinate pair around which to center the layout.
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.lollipop_graph(4, 3)
>>> pos = nx.random_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, center=None, dim=2, seed=None) | [
0.0714673325419426,
-0.011959406547248363,
0.0032693222165107727,
0.00313199614174664,
0.010986078530550003,
0.02943112701177597,
-0.0009082789183594286,
-0.02168305031955242,
0.03212946280837059,
0.02530652843415737,
-0.04028229042887688,
-0.04444543644785881,
0.024073004722595215,
0.01662367209792137,
-0.016748951748013496,
0.024689767509698868,
-0.0028669810853898525,
-0.0587080642580986,
-0.04745215177536011,
-0.020892823114991188,
0.0030211717821657658,
-0.08125843852758408,
0.04402140900492668,
0.0711975023150444,
-0.021721597760915756,
-0.00003911230669473298,
-0.0069433944299817085,
-0.0001617194211576134,
0.006533825770020485,
0.012373793870210648,
0.03658171370625496,
-0.031917449086904526,
-0.0029031194280833006,
0.013761509209871292,
0.013183294795453548,
0.04687393829226494,
0.04459962621331215,
-0.02530652843415737,
-0.021548133343458176,
-0.019553292542696,
0.04857003316283226,
0.009289982728660107,
0.046180080622434616,
-0.027773577719926834,
0.04814600944519043,
0.08287743479013443,
0.014956486411392689,
-0.02571127936244011,
-0.038239262998104095,
0.03382555767893791,
0.0019032899290323257,
-0.024073004722595215,
-0.03989681228995323,
-0.031570520251989365,
-0.03155124932527542,
-0.021644502878189087,
0.022993670776486397,
0.030452638864517212,
0.033016059547662735,
-0.07902267575263977,
0.0313585102558136,
-0.05666503682732582,
-0.020507346838712692,
0.010648787021636963,
-0.08210648596286774,
-0.01702842302620411,
0.017731916159391403,
-0.014551736414432526,
0.02463194541633129,
-0.054506368935108185,
0.013183294795453548,
-0.02016041800379753,
0.0006998807075433433,
-0.023456241935491562,
0.03662026301026344,
0.0057387808337807655,
0.02116265706717968,
0.02100846730172634,
-0.03463505953550339,
0.011997954919934273,
-0.0009697141940705478,
0.010648787021636963,
0.0014539690455421805,
0.0355987511575222,
0.036388978362083435,
0.008114279247820377,
0.0612136609852314,
0.04325045645236969,
0.021817967295646667,
-0.017384987324476242,
0.00336087285540998,
-0.0042908345349133015,
0.05200077220797539,
0.032919690012931824,
0.022531097754836082,
0.020507346838712692,
0.008114279247820377,
-0.04429124295711517,
0.07381874322891235,
0.0008420250960625708,
-0.015920177102088928,
0.006716927047818899,
0.011622115038335323,
0.0013636229559779167,
-0.03854764625430107,
0.0041486904956400394,
-0.02842888794839382,
0.0054641286842525005,
0.00994529202580452,
0.024670492857694626,
0.036292608827352524,
0.056626491248607635,
-0.016585124656558037,
0.015968361869454384,
-0.008335928432643414,
0.04602588713169098,
0.049032606184482574,
0.04367448017001152,
-0.010484959930181503,
-0.013819330371916294,
-0.04517783969640732,
0.0036788908764719963,
-0.0662248507142067,
-0.010456048883497715,
-0.0022743111476302147,
-0.017481356859207153,
0.018011387437582016,
-0.019591839984059334,
0.006688016466796398,
0.012007591314613819,
0.01584308221936226,
-0.011747394688427448,
0.0003174157754983753,
0.008254014886915684,
0.0209891926497221,
-0.03255348652601242,
-0.009993476793169975,
-0.01720188744366169,
0.004996738396584988,
0.042363863438367844,
-0.01938946545124054,
-0.0073433262296020985,
-0.020179692655801773,
0.06476004421710968,
-0.013173657469451427,
0.02630876749753952,
0.05076725035905838,
-0.03619623929262161,
0.023205682635307312,
0.028216876089572906,
0.012200329452753067,
-0.040166646242141724,
0.09775682538747787,
0.009140610694885254,
0.034191761165857315,
-0.0602114200592041,
0.007203591056168079,
0.01929309591650963,
-0.004842547699809074,
0.0012696631019935012,
-0.04155436158180237,
-0.05338848754763603,
-0.01433008722960949,
-0.00035987840965390205,
-0.05651084706187248,
-0.0035704756155610085,
0.03513617813587189,
0.04814600944519043,
-0.031050128862261772,
-0.01702842302620411,
-0.03085738979279995,
-0.04255659878253937,
-0.07509081065654755,
-0.03168616443872452,
0.010060935281217098,
0.04055212438106537,
0.03490489348769188,
0.0030862209387123585,
-0.006900028325617313,
-0.014975760132074356,
0.019553292542696,
-0.006856662221252918,
0.04367448017001152,
0.031666889786720276,
-0.02800486423075199,
0.07431986182928085,
0.016141826286911964,
-0.012826728634536266,
-0.022222718223929405,
0.010321131907403469,
-0.02353333681821823,
-0.003960770554840565,
-0.014108438044786453,
0.05069015175104141,
0.0009480311418883502,
0.06051980331540108,
0.019090721383690834,
0.004606443457305431,
-0.08711767941713333,
0.036292608827352524,
0.07408857345581055,
-0.0514611080288887,
0.002621239982545376,
-0.022107074037194252,
0.006548281293362379,
-0.004466708283871412,
0.0001257315743714571,
-0.008075731806457043,
-0.007762532215565443,
0.03324734419584274,
-0.014387908391654491,
-0.006312177050858736,
0.051653843373060226,
-0.057474538683891296,
0.024998147040605545,
-0.0030067162588238716,
-0.0404750257730484,
0.04244095832109451,
-0.0044691176153719425,
-0.06194606423377991,
-0.033594273030757904,
-0.005305119790136814,
-0.02251182496547699,
0.023995909839868546,
-0.04332755133509636,
-0.012065413407981396,
0.05839968100190163,
-0.054429274052381516,
0.001983999041840434,
0.008957508951425552,
0.049032606184482574,
-0.042787887156009674,
0.024304289370775223,
-0.03870183601975441,
-0.028216876089572906,
-0.024342838674783707,
-0.03725630044937134,
0.09128082543611526,
0.04806891456246376,
0.03193672373890877,
0.017731916159391403,
-0.05520022660493851,
-0.06317958980798721,
0.06144494563341141,
-0.02141321636736393,
-0.006567555014044046,
0.03201381862163544,
-0.043211910873651505,
-0.007540883030742407,
-0.010822251439094543,
-0.07574612647294998,
-0.021856514737010002,
0.03212946280837059,
0.011188453994691372,
0.02840961515903473,
0.0010829479433596134,
-0.06672597676515579,
0.05878515914082527,
-0.008740678429603577,
-0.0701952651143074,
-0.04078340902924538,
-0.010215125977993011,
-0.017230797559022903,
0.0065820105373859406,
0.05913208797574043,
0.039106585085392,
0.016970600932836533,
0.03085738979279995,
-0.008080550469458103,
0.04240240901708603,
-0.007174680475145578,
0.038412727415561676,
0.022029979154467583,
0.008152826689183712,
0.06163768470287323,
0.040012456476688385,
-0.019350918009877205,
0.023803170770406723,
0.0477219857275486,
0.04845438897609711,
-0.03490489348769188,
-0.011169180274009705,
-0.019109994173049927,
0.03552165627479553,
-0.0022478096652776003,
0.042363863438367844,
-0.009993476793169975,
-0.03278477117419243,
0.047606341540813446,
-0.03970407322049141,
0.09690877795219421,
-0.03588785603642464,
-0.014204807579517365,
-0.006480822805315256,
-0.012393067590892315,
0.022627467289566994,
-0.01904253661632538,
0.0022803342435508966,
0.01273036003112793,
-0.02278165891766548,
0.06240863725543022,
-0.06129075586795807,
0.09983839839696884,
0.03367136791348457,
0.05909353867173195,
0.050034843385219574,
-0.02285875380039215,
-0.028737269341945648,
0.00015946076018735766,
-0.012682175263762474,
-0.09528978168964386,
0.022492550313472748,
-0.034596510231494904,
0.007087948266416788,
-0.04887841269373894,
0.03615768998861313,
0.02251182496547699,
-0.03515545278787613,
0.029874425381422043,
0.04089905321598053,
0.031821079552173615,
0.044137053191661835,
-0.07139024138450623,
0.04602588713169098,
0.0015021535800769925,
0.020121870562434196,
0.020372429862618446,
0.041284527629613876,
0.07617014646530151,
-0.010966804809868336,
-0.022319085896015167,
0.005401488859206438,
-0.02823615074157715,
0.016710404306650162,
-0.057204704731702805,
-0.02596183866262436,
0.03282332047820091,
-0.018339041620492935,
-0.03324734419584274,
-0.06102092191576958,
-0.004153508692979813,
-0.05874660983681679,
-0.025865469127893448,
-0.010138031095266342,
0.04502364993095398,
0.015621433034539223,
0.017346439883112907,
-0.04656555503606796,
-0.05905499309301376,
-0.027773577719926834,
0.0389716699719429,
0.03130068629980087,
-0.07667126506567001,
0.020642263814806938,
-0.012788181193172932,
0.037410490214824677,
-0.006919302511960268,
-0.0657237321138382,
-0.013212205842137337,
0.04637281596660614,
0.006572373677045107,
0.02800486423075199,
-0.03197527304291725,
-0.040513575077056885,
0.02413082681596279,
0.01938946545124054,
-0.007902267388999462,
0.00649045966565609,
0.08727186918258667,
-0.014387908391654491,
0.029662413522601128,
-0.09074115753173828,
-0.10138030350208282,
0.056780681014060974,
-0.005541224032640457,
0.03263058140873909,
-0.01547687966376543,
-0.00005842377504450269,
-0.04533202946186066,
-0.025904018431901932,
0.01041750144213438,
0.016247833147644997,
0.05913208797574043,
0.011988317593932152,
0.04494655504822731,
-0.0202375128865242,
0.06726563721895218,
0.05917063355445862,
-0.059324827045202255,
-0.02193360961973667,
-0.05200077220797539,
-0.0008414228213950992,
0.03928004950284958,
0.021991431713104248,
0.006249536760151386,
0.039588432759046555,
-0.018358316272497177,
0.03667808324098587,
-0.037815239280462265,
0.009039422497153282,
-0.03818144276738167,
-0.04891696199774742,
-0.07073492556810379,
0.006688016466796398,
-0.030221354216337204,
-0.04941808059811592,
-0.018512506037950516,
0.005338849034160376,
0.02378389798104763,
0.036485347896814346,
0.02039170451462269,
0.02216489613056183,
0.019456923007965088,
-0.0637192577123642,
0.037988703697919846,
-0.002893482567742467,
-0.021721597760915756,
0.07104331254959106,
0.028814364224672318,
-0.010880072601139545,
0.007984180934727192,
-0.024265741929411888,
0.08534448593854904,
0.0035150633193552494,
0.06105947121977806,
0.01626710593700409,
-0.0394727885723114,
-0.03224510699510574,
-0.028467435389757156,
0.043481744825839996,
-0.01888834685087204,
0.02883363887667656,
0.03239929676055908,
0.02241545543074608,
-0.030471913516521454,
-0.00994529202580452,
0.020295334979891777,
0.013086925260722637,
-0.04062921926379204,
-0.026713518425822258,
0.04544767364859581,
-0.003503017360344529,
-0.03584931045770645,
-0.02875654399394989,
0.006957849953323603,
-0.009728461503982544,
-0.0306068304926157,
0.008856321685016155,
0.021702324971556664,
0.010590965859591961,
0.05388960614800453,
-0.07748076319694519,
0.06468294560909271,
-0.01484084315598011,
-0.04826165363192558,
0.009261071681976318,
0.023591158911585808,
-0.03278477117419243,
-0.062370091676712036,
0.0038812661077827215,
0.012518348172307014,
-0.02241545543074608,
-0.052656084299087524,
-0.03345935419201851,
0.024593397974967957,
0.02318640798330307,
0.002821205882355571,
0.0018093300750479102,
-0.05944046750664711,
-0.03002861514687538,
0.041862741112709045,
-0.016218921169638634,
-0.004524529911577702,
-0.04089905321598053,
0.028043411672115326,
-0.00889968778938055,
-0.05955611169338226,
-0.007984180934727192,
-0.062177352607250214,
-0.01344349142163992,
-0.02690625563263893,
0.006225444842129946,
0.004784726537764072,
0.027792852371931076,
0.0177993755787611,
0.028178328648209572,
0.029970794916152954,
0.03388338163495064,
-0.01643093302845955,
-0.03870183601975441,
-0.029720233753323555,
0.03845127671957016,
0.03492416813969612,
0.05007339268922806,
0.03025990165770054,
0.010937894694507122,
0.003038036171346903,
-0.047760531306266785,
0.007425240240991116,
0.025441445410251617,
0.004307699389755726,
-0.07748076319694519,
0.0549689419567585,
-0.002498369198292494,
0.017809012904763222,
-0.015255230478942394,
-0.003796942997723818,
0.044483982026576996,
0.06853771209716797,
0.07609305530786514,
-0.006437456700950861,
0.03396047651767731,
-0.0033777374774217606,
-0.036813002079725266,
-0.009246616624295712,
0.06036561354994774,
-0.041785646229982376,
0.04533202946186066,
0.03727557137608528,
-0.019871311262249947,
0.01538051012903452,
0.010060935281217098,
-0.026019660755991936,
0.04899405688047409,
-0.025075243785977364,
0.019418375566601753,
0.019418375566601753,
-0.06973268836736679,
-0.007998635992407799,
0.0011088470928370953,
-0.021181931719183922,
0.045833151787519455,
-0.010359679348766804,
0.05978739634156227,
0.035791490226984024,
0.014436093159019947,
0.04614153131842613,
-0.0010721064172685146,
-0.0022911757696419954,
-0.036813002079725266,
-0.01459028385579586,
0.01794392801821232,
-0.026462959125638008,
0.007242138963192701,
0.06911592930555344,
0.03405684605240822,
0.009429717436432838,
-0.031840354204177856,
-0.03787306323647499,
-0.08041039109230042,
0.005541224032640457,
0.03355572372674942,
-0.02528725564479828,
-0.026462959125638008,
0.03145487979054451,
0.014792658388614655,
-0.02158668078482151,
-0.026578601449728012,
-0.01421444397419691,
-0.013674777001142502,
-0.028717996552586555,
-0.055354420095682144,
-0.0389716699719429,
-0.016411660239100456,
0.04124598205089569,
-0.04587169736623764,
0.00915506575256586,
-0.05338848754763603,
-0.0003000994329340756,
-0.010928257368505001,
0.01566961780190468,
0.00592188211157918,
0.050959985703229904,
0.0044980281963944435,
0.03565657138824463,
-0.0035584294237196445,
0.018261946737766266,
0.00826846994459629,
0.018078844994306564,
-0.06726563721895218,
0.021104834973812103,
-0.04814600944519043,
0.01601654663681984,
0.0632181391119957,
-0.005449673160910606,
0.0467197448015213,
-0.01932200789451599,
0.008547940291464329,
-0.048531483858823776,
-0.017847560346126556,
-0.009752553887665272,
-0.044561076909303665,
0.06691870838403702,
0.0027272459119558334,
-0.029835877940058708,
-0.04537057876586914,
0.012585805729031563,
0.023995909839868546,
0.028814364224672318,
0.013578408397734165,
-0.08580705523490906,
0.02216489613056183,
0.009053878486156464,
0.0006122449995018542,
-0.03928004950284958,
-0.051037080585956573,
0.04575605317950249,
0.0121810557320714,
0.018107756972312927,
-0.04290352761745453,
-0.00923697929829359,
-0.004883504938334227,
-0.018175214529037476,
-0.025595637038350105,
0.022646741941571236,
-0.04614153131842613,
0.018445048481225967,
0.05230915546417236,
0.03365209326148033,
0.003551201894879341,
0.012026865035295486,
-0.02091209776699543,
0.006316995248198509,
-0.032592035830020905,
-0.023090040311217308,
0.08334001153707504,
0.01872451789677143,
-0.015428694896399975,
0.006904846988618374,
-0.013674777001142502,
0.01932200789451599,
-0.03272695094347,
-0.025769101455807686,
0.014252991415560246,
0.01822339929640293,
-0.08565286546945572,
0.020680811256170273,
-0.04533202946186066,
0.022280538454651833,
0.06441311538219452,
0.0409761480987072,
-0.02783139981329441,
-0.003151270095258951,
-0.026597876101732254,
0.014387908391654491,
0.03974262252449989,
0.09690877795219421,
-0.03180180862545967,
-0.006288084667176008,
0.018165577203035355,
-0.00400172732770443,
-0.043134815990924835,
-0.03311242535710335,
-0.018078844994306564,
-0.002592329168692231,
0.04544767364859581,
0.023340599611401558,
-0.0032235467806458473,
0.009121336974203587,
-0.05651084706187248,
-0.006076072342693806,
0.02158668078482151,
0.0075890677981078625,
-0.0042619239538908005,
0.04564041271805763,
0.012335246428847313,
0.001704528694972396,
-0.013231479562819004,
0.025942565873265266,
-0.06156058982014656,
-0.03370991721749306,
-0.024477753788232803,
0.019505107775330544,
0.01762591116130352,
-0.0592091828584671,
0.032341472804546356,
-0.0017503040144219995,
-0.013202568516135216,
-0.02918056771159172,
-0.04644991084933281,
0.0101187564432621,
0.04787617549300194,
0.001122700166888535,
-0.013588044792413712,
-0.038219988346099854,
-0.011178816668689251,
0.0010865617077797651,
-0.06375780701637268,
0.05466056242585182,
-0.01888834685087204,
0.020198965445160866,
-0.040012456476688385,
0.04849293828010559,
-0.007116858847439289,
0.02218416891992092,
-0.007907086052000523,
-0.007256594020873308,
0.009468265809118748,
0.05284882336854935,
-0.021143384277820587,
0.06287121027708054,
0.004278788808733225,
-0.07027235627174377,
0.05863096937537193,
-0.01441681943833828,
-0.032669130712747574,
-0.056048277765512466,
0.04012809693813324,
0.012036502361297607,
0.07166007161140442,
-0.03584931045770645,
-0.04664264991879463,
0.02621239796280861,
-0.08118133991956711,
0.03565657138824463,
-0.002197215799242258,
-0.0027079719584435225,
-0.011072810739278793,
-0.04024374112486839,
0.015698527917265892,
-0.021702324971556664,
-0.025653457269072533,
0.0298551507294178,
0.005565316416323185,
-0.03282332047820091,
-0.03274622559547424,
0.03263058140873909,
-0.025094516575336456,
-0.02039170451462269,
0.03087666444480419,
-0.03850909695029259,
0.03313170000910759,
0.00889005046337843,
0.11864965409040451,
-0.02900710329413414,
0.04332755133509636,
-0.07239247858524323,
-0.022743111476302147,
-0.02638586238026619,
0.0328618660569191,
0.01854141801595688,
0.022126348689198494,
-0.058476779609918594,
-0.028621627017855644,
-0.03864401578903198,
-0.006109801586717367,
-0.007829990237951279,
0.008658764883875847,
0.01887870952486992,
-0.0070494008250534534,
-0.0008528666221536696,
0.011593203991651535,
-0.0012552076950669289,
-0.0026621967554092407,
-0.046257175505161285,
-0.05338848754763603,
0.03299678489565849,
-0.04301917180418968,
0.0004173987254034728,
-0.06348796933889389,
-0.050304677337408066,
-0.08010200411081314,
-0.04575605317950249,
0.03353645280003548,
-0.07277795672416687,
0.01696096360683441,
0.014869754202663898,
0.05928627774119377
]
|
31,040 | networkx.generators.random_graphs | random_lobster | Returns a random lobster graph.
A lobster is a tree that reduces to a caterpillar when pruning all
leaf nodes. A caterpillar is a tree that reduces to a path graph
when pruning all leaf nodes; setting `p2` to zero produces a caterpillar.
This implementation iterates on the probabilities `p1` and `p2` to add
edges at levels 1 and 2, respectively. Graphs are therefore constructed
iteratively with uniform randomness at each level rather than being selected
uniformly at random from the set of all possible lobsters.
Parameters
----------
n : int
The expected number of nodes in the backbone
p1 : float
Probability of adding an edge to the backbone
p2 : float
Probability of adding an edge one level beyond backbone
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Raises
------
NetworkXError
If `p1` or `p2` parameters are >= 1 because the while loops would never finish.
| 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, p1, p2, seed=None, *, backend=None, **backend_kwargs) | [
0.0035043188836425543,
0.001513827359303832,
0.015291573479771614,
0.004915148485451937,
-0.02493024617433548,
-0.04081585258245468,
-0.06480714678764343,
-0.03633185848593712,
0.012139363214373589,
-0.030046598985791206,
0.0064960443414747715,
0.04200391843914986,
-0.036830078810453415,
0.10715598613023758,
-0.043038688600063324,
0.013068737462162971,
0.034683894366025925,
0.04744603484869003,
-0.005882848519831896,
0.027344705536961555,
-0.039972707629203796,
0.0019928866531699896,
0.00007114779145922512,
0.07097742706537247,
-0.03453059494495392,
0.01072134729474783,
-0.03912956267595291,
0.010750090703368187,
-0.015646077692508698,
0.059288378804922104,
0.039206214249134064,
-0.12348232418298721,
0.021021122112870216,
0.03901458904147148,
-0.00013338807912077755,
0.010165638290345669,
0.027670465409755707,
0.061204615980386734,
-0.10968542098999023,
-0.03681091591715813,
0.07090077549219131,
-0.055417582392692566,
0.08339464664459229,
0.013107062317430973,
0.02470029704272747,
-0.023933803662657738,
0.030966393649578094,
0.012972925789654255,
-0.09650170803070068,
-0.009878203272819519,
0.016125136986374855,
-0.07047920674085617,
0.026233287528157234,
-0.0023737389128655195,
-0.02042708918452263,
0.01844378374516964,
-0.003142629051581025,
0.04464832693338394,
0.01788807474076748,
0.025332655757665634,
0.06300587952136993,
-0.01955520175397396,
-0.014592146500945091,
-0.03525876626372337,
-0.024508673697710037,
0.022017566487193108,
-0.04859577491879463,
-0.026808159425854683,
-0.0014994556549936533,
0.06204776093363762,
0.050358712673187256,
0.0640406459569931,
-0.008081730455160141,
0.05511098355054855,
0.054766058921813965,
0.04430340602993965,
0.04863410070538521,
0.027018945664167404,
-0.0520833283662796,
0.019698917865753174,
0.0042037456296384335,
-0.02583087794482708,
0.011823183856904507,
-0.034319810569286346,
0.005509181879460812,
-0.015521521680057049,
0.006074471864849329,
0.0031066995579749346,
0.00029297469882294536,
-0.10179052501916885,
-0.04859577491879463,
-0.04982216656208038,
0.055647529661655426,
0.016335923224687576,
0.031637076288461685,
-0.0332467146217823,
-0.00631879223510623,
-0.032307758927345276,
0.007482906337827444,
-0.024546999484300613,
-0.04503157362341881,
0.0437285341322422,
-0.03820976987481117,
0.0006491253734566271,
0.006534368731081486,
0.007185889407992363,
-0.052159976214170456,
0.015147855505347252,
0.02086782269179821,
-0.035354577004909515,
-0.1171204224228859,
0.04361356049776077,
0.07979211956262589,
0.01823299750685692,
-0.02287987247109413,
-0.01329868659377098,
0.015013718977570534,
0.011641141027212143,
0.0319436751306057,
0.032211948186159134,
0.016355084255337715,
0.02707643248140812,
-0.0329209566116333,
-0.0001762040046742186,
0.000751524290535599,
-0.024048777297139168,
0.048212528228759766,
-0.008579952642321587,
-0.012896277010440826,
-0.0388229675590992,
0.01054888591170311,
0.014841257594525814,
-0.04702446237206459,
0.07021093368530273,
-0.011995645239949226,
-0.03441562131047249,
-0.047982580959796906,
0.005777455400675535,
0.06913784146308899,
0.004014517180621624,
-0.0008605102775618434,
-0.06687667965888977,
0.08906670659780502,
0.012896277010440826,
-0.039512813091278076,
-0.021519344300031662,
0.017236553132534027,
-0.05706554651260376,
0.0018371924525126815,
-0.012196850031614304,
0.04001103341579437,
-0.0013245990267023444,
0.02086782269179821,
-0.03460724279284477,
-0.039551135152578354,
0.017696451395750046,
-0.041544023901224136,
-0.0003574980073608458,
-0.02322479523718357,
0.014678376726806164,
-0.030640633776783943,
-0.054651085287332535,
0.04874907433986664,
0.054306164383888245,
0.010108151473104954,
-0.030755607411265373,
0.04947724565863609,
0.0018455759854987264,
0.017437757924199104,
-0.035488713532686234,
-0.07435000687837601,
-0.0011371669825166464,
-0.06603353470563889,
-0.06166451424360275,
0.05269652232527733,
-0.002188103273510933,
-0.025984177365899086,
-0.03100471757352352,
0.029280105605721474,
0.03437729552388191,
0.03826725855469704,
-0.0473310612142086,
0.06779647618532181,
-0.059250056743621826,
-0.030621470883488655,
-0.03543122485280037,
-0.006342745386064053,
0.04300036281347275,
0.018012629821896553,
0.008532046340405941,
0.02132772095501423,
0.024776946753263474,
0.036140233278274536,
0.0609363429248333,
0.025217682123184204,
0.005240908823907375,
0.025121869519352913,
0.014601727947592735,
-0.012886695563793182,
0.011133338324725628,
0.04560644552111626,
0.0022288234904408455,
0.02052289992570877,
0.023205632343888283,
0.027900414541363716,
0.007703273557126522,
-0.03282514214515686,
-0.04196559637784958,
0.023167308419942856,
-0.027229731902480125,
0.004886405076831579,
-0.01048181764781475,
0.028609421104192734,
-0.02707643248140812,
-0.015406547114253044,
-0.06285258382558823,
0.019239021465182304,
0.017207810655236244,
-0.00011108187754871324,
-0.03493300452828407,
0.03205864876508713,
-0.05890513211488724,
0.010960876941680908,
0.02581171505153179,
0.005810989532619715,
0.0437285341322422,
-0.014563403092324734,
0.004024098161607981,
-0.015186180360615253,
0.029011832550168037,
0.03384074941277504,
-0.0007826631190255284,
0.03673426806926727,
-0.028341148048639297,
-0.039187051355838776,
-0.030199898406863213,
0.0030659795738756657,
-0.039627786725759506,
-0.035795312374830246,
0.01893242448568344,
-0.029414242133498192,
0.019833054393529892,
-0.020331276580691338,
-0.008939246647059917,
0.02234332635998726,
0.01555984653532505,
0.028283661231398582,
-0.05817696079611778,
-0.06848631799221039,
-0.019794730469584465,
-0.09335907548666,
-0.01246512308716774,
0.024757785722613335,
0.03146461397409439,
0.02615663781762123,
-0.026444073766469955,
-0.021519344300031662,
0.009715322405099869,
-0.003995354752987623,
0.058598533272743225,
0.007176308427006006,
-0.020388763397932053,
-0.1112184077501297,
0.03167540207505226,
-0.001459933235310018,
-0.00600740360096097,
-0.0707474797964096,
0.06948275864124298,
-0.013528634794056416,
-0.03133047744631767,
0.06193278729915619,
0.0006862524314783514,
0.008824272081255913,
0.0004092963063158095,
0.027018945664167404,
0.023397255688905716,
-0.01239805482327938,
0.019516875967383385,
-0.019603107124567032,
-0.04349858686327934,
-0.0412757508456707,
-0.04342193529009819,
0.02470029704272747,
0.04541482403874397,
-0.005854104645550251,
0.004242070019245148,
-0.023339768871665,
-0.06204776093363762,
0.024336213245987892,
-0.03353415057063103,
0.015473615378141403,
-0.028513610363006592,
0.005767873954027891,
0.050013791769742966,
-0.0017425782280042768,
-0.004898381419479847,
0.0586368590593338,
0.023493068292737007,
0.02017797715961933,
-0.008934455923736095,
0.038056470453739166,
-0.009686578996479511,
0.09113623946905136,
0.003959425259381533,
-0.016700007021427155,
-0.03203948587179184,
0.013605284504592419,
-0.025351818650960922,
-0.01985221728682518,
0.020024679601192474,
-0.09059969335794449,
0.0251410324126482,
0.057563766837120056,
0.030832257121801376,
-0.009427887387573719,
-0.06733657419681549,
0.011545329354703426,
0.0006045129848644137,
0.04050925374031067,
-0.0038444509264081717,
-0.017303621396422386,
0.03748159855604172,
-0.0013222036650404334,
0.04656456410884857,
-0.01759105734527111,
-0.002216846914961934,
0.046411264687776566,
0.07500152289867401,
0.0013545402325689793,
0.022247513756155968,
-0.04208057001233101,
0.01657545194029808,
-0.01065427903085947,
0.018846193328499794,
-0.08753371983766556,
0.08086521178483963,
-0.027459679171442986,
-0.023282282054424286,
0.06664673238992691,
-0.0860007256269455,
0.021634317934513092,
-0.046756189316511154,
-0.005255280528217554,
-0.010635117068886757,
0.04637294262647629,
0.04407345503568649,
0.012110618874430656,
-0.004072003997862339,
-0.05695056915283203,
0.0692911371588707,
-0.013681934215128422,
0.04196559637784958,
-0.002694708527997136,
0.025754228234291077,
-0.0191623717546463,
0.03353415057063103,
-0.009839878417551517,
0.004469623323529959,
0.010146476328372955,
0.07032590359449387,
-0.023320607841014862,
-0.005672062281519175,
-0.027766278013586998,
-0.013691514730453491,
0.027670465409755707,
0.006304420530796051,
0.0023773317225277424,
0.04388183355331421,
0.038516368716955185,
-0.052504900842905045,
0.06971271336078644,
-0.06718327850103378,
-0.04510822519659996,
0.04920897260308266,
0.010424330830574036,
-0.028781883418560028,
-0.037711549550294876,
0.020024679601192474,
0.03211613744497299,
0.03307425603270531,
-0.012388473376631737,
-0.03958946093916893,
0.009993176907300949,
0.03958946093916893,
-0.006170284003019333,
-0.012053132057189941,
0.07266371697187424,
0.003758220234885812,
-0.006524787750095129,
-0.026999782770872116,
0.01284837070852518,
-0.029854975640773773,
0.07327691465616226,
0.007018218748271465,
-0.05499600991606712,
0.005044494289904833,
0.04119909927248955,
-0.02606082707643509,
-0.037060029804706573,
-0.0035546200815588236,
0.002515061292797327,
0.016958698630332947,
-0.05055033788084984,
-0.023627204820513725,
-0.005691224709153175,
-0.033917397260665894,
0.02786208875477314,
0.028053712099790573,
0.01134412456303835,
0.014994556084275246,
-0.015234085731208324,
0.023033171892166138,
-0.018989911302924156,
-0.011660303920507431,
0.02370385453104973,
-0.0010964469984173775,
-0.005945126060396433,
-0.020158816128969193,
0.010903390124440193,
0.014965812675654888,
0.032441895455121994,
-0.007827828638255596,
0.006515206769108772,
-0.024853596463799477,
0.04411178082227707,
0.005777455400675535,
-0.051048558205366135,
0.01962227001786232,
-0.08155505359172821,
0.022190026938915253,
0.05399956554174423,
-0.039627786725759506,
0.0334191769361496,
-0.043038688600063324,
0.024642810225486755,
0.008546417579054832,
0.028896857053041458,
0.0053702546283602715,
0.05672062188386917,
-0.022975685074925423,
0.012091456912457943,
0.022247513756155968,
0.011708209291100502,
-0.05741046741604805,
-0.02956753969192505,
-0.04564477130770683,
-0.021730130538344383,
-0.0012395658995956182,
0.01608681119978428,
-0.02052289992570877,
-0.0056672715581953526,
-0.005307977087795734,
0.07116904854774475,
-0.006764317397028208,
-0.04748435690999031,
0.03577614948153496,
0.05974827706813812,
-0.027996225282549858,
-0.03464556857943535,
0.10064078122377396,
0.014841257594525814,
0.00699426606297493,
0.012340568006038666,
0.09573521465063095,
0.034223996102809906,
-0.019200697541236877,
0.05415286496281624,
-0.0200630035251379,
-0.015301153995096684,
0.03801814839243889,
-0.018970748409628868,
0.00022650523169431835,
0.015550265088677406,
-0.03303593024611473,
-0.01680540107190609,
-0.03870799019932747,
-0.009451840072870255,
-0.03970443457365036,
-0.01138244941830635,
-0.011238731443881989,
0.01736111007630825,
0.003992959391325712,
0.010366843082010746,
0.03215445950627327,
0.02287987247109413,
-0.027727952226996422,
-0.035584524273872375,
0.025409305468201637,
0.01200522668659687,
0.0026923133991658688,
-0.07316193729639053,
-0.08002206683158875,
0.02232416346669197,
0.03696421533823013,
-0.05150845646858215,
-0.012647165916860104,
-0.017140742391347885,
-0.04790592938661575,
-0.007516440469771624,
-0.07634288817644119,
0.019258184358477592,
-0.0112195685505867,
-0.014640052802860737,
-0.04660288989543915,
0.007406257092952728,
0.0004742687160614878,
-0.0021916963160037994,
-0.017418596893548965,
0.0022611599415540695,
0.06346577405929565,
-0.0000900481827557087,
-0.02379966713488102,
0.03757741302251816,
0.03688756749033928,
-0.014563403092324734,
0.01624969206750393,
-0.008642230182886124,
0.004589388146996498,
0.05139348283410072,
-0.028801046311855316,
0.03485635668039322,
0.03474137932062149,
0.0314454510807991,
-0.045951370149850845,
0.02753632888197899,
-0.0088434349745512,
0.013969369232654572,
-0.011066270060837269,
0.021461857482790947,
-0.007070915307849646,
-0.024642810225486755,
0.036370184272527695,
0.040087681263685226,
0.020139653235673904,
-0.010855483822524548,
-0.014026856049895287,
0.01009857002645731,
0.005470857489854097,
-0.05231327563524246,
-0.05166175588965416,
0.008297307416796684,
0.019267765805125237,
-0.007540393620729446,
-0.012656746432185173,
-0.006462510209530592,
-0.012982507236301899,
-0.04070087894797325,
0.0009629091946408153,
-0.012752559036016464,
-0.01922944001853466,
-0.002474341308698058,
0.015052043832838535,
-0.018549175933003426,
-0.022362489253282547,
0.006740364246070385,
-0.05652899667620659,
-0.07799085229635239,
0.0484808012843132,
0.060284823179244995,
0.02460448630154133,
-0.0671449527144432,
0.014994556084275246,
-0.022190026938915253,
0.0018180300248786807,
0.037749871611595154,
0.0430770143866539,
-0.02470029704272747,
-0.0013880743645131588,
-0.019612688571214676,
-0.01099920179694891,
0.024048777297139168,
0.03420483320951462,
0.03012324869632721,
0.0176868699491024,
-0.04284706339240074,
-0.007195470854640007,
-0.04970719292759895,
-0.050013791769742966,
-0.009768019430339336,
0.008924874477088451,
0.00006104263593442738,
0.06177948787808418,
-0.0227648988366127,
0.01634550280869007,
0.044265080243349075,
0.028475284576416016,
-0.029395079240202904,
0.01878870651125908,
0.001980910310521722,
-0.02864774689078331,
-0.07687943428754807,
-0.022496625781059265,
0.032326921820640564,
-0.04457167908549309,
0.004740291740745306,
0.04227219149470329,
0.04767598211765289,
-0.015243667177855968,
-0.05672062188386917,
-0.07549974322319031,
0.035584524273872375,
0.03249938413500786,
0.0019437831360846758,
-0.0014874791959300637,
0.05511098355054855,
0.016747914254665375,
-0.003648036625236273,
-0.06319750100374222,
0.02527516894042492,
0.0034612035378813744,
-0.03656180575489998,
-0.0017545546870678663,
-0.02719140611588955,
-0.06377237290143967,
-0.0379989854991436,
-0.05392291396856308,
-0.04499325156211853,
0.01865456998348236,
0.023320607841014862,
0.0471777617931366,
-0.03541206568479538,
0.019794730469584465,
0.018252160400152206,
0.05108688399195671,
-0.025351818650960922,
-0.006165493279695511,
-0.025639254599809647,
-0.02571590431034565,
0.01569398306310177,
-0.0032839516643434763,
0.0167095884680748,
-0.057908687740564346,
0.029184293001890182,
-0.0018623430514708161,
0.024546999484300613,
-0.023876314982771873,
0.051700081676244736,
0.00792843196541071,
0.0020360019989311695,
0.08776366710662842,
-0.06664673238992691,
0.010769253596663475,
-0.0633891299366951,
-0.003698337823152542,
-0.03786484897136688,
0.00578224565833807,
-0.020158816128969193,
0.019267765805125237,
0.010980038903653622,
-0.026022501289844513,
-0.022285839542746544,
0.05074196308851242,
0.008139217272400856,
-0.0031282573472708464,
-0.03271016851067543,
-0.0024276331532746553,
0.017801843583583832,
-0.005691224709153175,
-0.002991725457832217,
-0.03414734825491905,
0.06588023900985718,
0.004620526917278767,
0.029030993580818176,
0.04418842867016792,
0.007799085695296526,
0.058138638734817505,
0.022592436522245407,
-0.03978108614683151,
-0.03665761649608612,
0.007861362770199776,
-0.028111200779676437,
-0.02742135524749756,
-0.006218189839273691,
-0.06511373817920685,
-0.04802090674638748,
0.02989330142736435,
-0.021270234137773514,
-0.00481933681294322,
0.011487842537462711,
0.011986063793301582,
0.07733933627605438,
-0.002879146486520767,
-0.0029462147504091263,
-0.005355882924050093,
0.0016311969375237823,
0.05062698572874069,
-0.014755026437342167,
0.018175510689616203,
-0.057257167994976044,
-0.002225230447947979,
0.021519344300031662,
-0.025198519229888916,
0.02345474436879158,
0.050358712673187256,
0.03866966813802719,
0.0638873502612114,
-0.025773391127586365,
-0.017236553132534027,
-0.053731292486190796,
-0.04756100848317146,
0.02119358442723751,
-0.038957104086875916,
-0.03606358543038368,
0.05821528658270836,
-0.07595964521169662,
0.035354577004909515,
-0.05112520977854729,
0.009006314910948277,
-0.032518547028303146,
0.010232706554234028,
-0.018089279532432556,
-0.045299846678972244,
0.04924729838967323,
-0.008608696050941944,
0.004361834842711687,
-0.04016433283686638,
-0.005614574998617172,
0.03159875050187111,
-0.05457443743944168,
0.0015856863465160131,
-0.06193278729915619,
-0.01375858299434185,
0.036140233278274536,
0.007391884922981262,
0.023761341348290443,
-0.008330841548740864,
0.031637076288461685,
-0.05376961827278137,
-0.012139363214373589,
-0.03608274832367897,
0.014189736917614937,
0.032863467931747437,
0.0013916672905907035,
0.01500413753092289,
-0.0038899616338312626,
-0.03395572304725647,
0.01099920179694891,
0.009241053834557533,
0.02356971800327301,
0.008522464893758297,
0.01662335731089115,
0.0034683893900364637,
-0.05219830200076103,
0.04457167908549309,
-0.006127168424427509,
0.03594861179590225,
-0.030295711010694504,
0.008091311901807785,
0.008407491259276867,
0.00029581913258880377,
0.05457443743944168,
-0.017926398664712906,
-0.018664151430130005,
0.05491935834288597,
0.02774711512029171,
0.004953473340719938,
0.04790592938661575,
-0.029241779819130898,
-0.03203948587179184,
-0.0733918845653534,
-0.01636466570198536,
0.013662771321833134,
0.06189446151256561,
-0.04073920473456383,
-0.0022803223691880703,
0.020676199346780777,
0.015933511778712273,
0.04713943600654602
]
|
31,041 | networkx.generators.community | random_partition_graph | Returns the random partition graph with a partition of sizes.
A partition graph is a graph of communities with sizes defined by
s in sizes. Nodes in the same group are connected with probability
p_in and nodes of different groups are connected with probability
p_out.
Parameters
----------
sizes : list of ints
Sizes of groups
p_in : float
probability of edges with in groups
p_out : float
probability of edges between groups
directed : boolean optional, default=False
Whether to create a directed graph
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
G : NetworkX Graph or DiGraph
random partition graph of size sum(gs)
Raises
------
NetworkXError
If p_in or p_out is not in [0,1]
Examples
--------
>>> G = nx.random_partition_graph([10, 10, 10], 0.25, 0.01)
>>> len(G)
30
>>> partition = G.graph["partition"]
>>> len(partition)
3
Notes
-----
This is a generalization of the planted-l-partition described in
[1]_. It allows for the creation of groups of any size.
The partition is store as a graph attribute 'partition'.
References
----------
.. [1] Santo Fortunato 'Community Detection in Graphs' Physical Reports
Volume 486, Issue 3-5 p. 75-174. https://arxiv.org/abs/0906.0612
| 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)
| (sizes, p_in, p_out, seed=None, directed=False, *, backend=None, **backend_kwargs) | [
-0.0020576873794198036,
0.02577221766114235,
-0.03886053338646889,
-0.01566186174750328,
0.005983492825180292,
0.06000037118792534,
-0.03411785885691643,
-0.041801728308200836,
0.0538606271147728,
-0.012205957435071468,
-0.020000124350190163,
0.01988982781767845,
-0.003311141859740019,
0.051360610872507095,
-0.010119548067450523,
0.01528502069413662,
0.010891611687839031,
-0.04125025495886803,
0.020753804594278336,
0.03413623943924904,
-0.011801543645560741,
-0.018520334735512733,
-0.011626910418272018,
0.01685672253370285,
-0.0360296331346035,
0.02704060822725296,
0.0228310227394104,
0.008239940740168095,
-0.05507386848330498,
-0.0011500531109049916,
-0.026103101670742035,
-0.01560671441257,
-0.02216925472021103,
-0.009880575351417065,
0.0026792443823069334,
0.05327238887548447,
0.03722449392080307,
0.08330933749675751,
-0.01348353922367096,
-0.024375149980187416,
-0.018970705568790436,
-0.0492282435297966,
0.0064522456377744675,
-0.013943100348114967,
0.011332790367305279,
0.018878793343901634,
0.012674710713326931,
0.05577240139245987,
-0.06632393598556519,
-0.050294429063797,
0.010634256526827812,
-0.03617669269442558,
0.034595802426338196,
0.0016360394656658173,
-0.0269303135573864,
0.01228867843747139,
0.0007944672252051532,
0.03856641426682472,
0.06514745950698853,
0.005142495036125183,
-0.014586486853659153,
-0.0023253820836544037,
0.017490915954113007,
-0.009687559679150581,
-0.06665482372045517,
0.001163265435025096,
-0.06834600865840912,
-0.03915465250611305,
0.03687522932887077,
0.06345627456903458,
0.07433869689702988,
0.04371350631117821,
-0.002022071275860071,
0.012693093158304691,
0.0699269026517868,
0.045294396579265594,
-0.00010763795580714941,
0.0027734546456485987,
-0.005183855537325144,
-0.05823565274477005,
0.02045968547463417,
0.016847530379891396,
0.020827334374189377,
-0.01078131701797247,
0.06977984309196472,
-0.004200393799692392,
0.03375020995736122,
0.008382405154407024,
-0.009411823004484177,
-0.046617936342954636,
0.02275749295949936,
0.001817566342651844,
0.04202231764793396,
-0.03615831211209297,
0.0006767045706510544,
0.059154778718948364,
-0.01808834634721279,
-0.03386050462722778,
0.036250222474336624,
-0.03474286198616028,
0.04621351882815361,
-0.006318972911685705,
-0.06275773793458939,
0.019981741905212402,
-0.020882481709122658,
-0.05536798760294914,
0.001038034912198782,
0.0028263041749596596,
-0.002265638904646039,
-0.033327411860227585,
-0.07536811381578445,
0.0454782210290432,
0.05444886535406113,
-0.0049494788981974125,
0.010882420465350151,
-0.0014579594135284424,
-0.005739924963563681,
0.00957726500928402,
0.013750084675848484,
0.007325412705540657,
-0.041139960289001465,
0.03117666393518448,
-0.021801605820655823,
0.025606775656342506,
0.01440266240388155,
0.009237189777195454,
0.02823546901345253,
0.011176539584994316,
0.032187700271606445,
-0.02290455251932144,
0.02154425159096718,
-0.01613980531692505,
0.005422827787697315,
0.02045968547463417,
-0.003511051181703806,
-0.04202231764793396,
-0.10338298976421356,
-0.0365627259016037,
0.048272356390953064,
0.0061213611625134945,
-0.01263794582337141,
-0.02761046402156353,
-0.017095694318413734,
0.044081155210733414,
0.009466970339417458,
0.04158113896846771,
0.01085484679788351,
-0.02047806791961193,
0.005372275598347187,
0.008267514407634735,
0.044228214770555496,
-0.004620892461389303,
-0.012435738928616047,
-0.045257631689310074,
-0.03159945830702782,
-0.006323568522930145,
-0.016976207494735718,
-0.029871508479118347,
-0.0020530917681753635,
0.019614091143012047,
-0.024209707975387573,
0.025036919862031937,
-0.026195013895630836,
0.05125031620264053,
-0.009103916585445404,
-0.037022288888692856,
0.06062537431716919,
-0.016847530379891396,
-0.06180185079574585,
-0.027261197566986084,
-0.011185730807483196,
-0.029191356152296066,
-0.03790464624762535,
-0.058529771864414215,
0.030349452048540115,
-0.048934124410152435,
0.020018506795167923,
0.00021240365458652377,
-0.03856641426682472,
0.010615874081850052,
-0.0358458086848259,
-0.009172851219773293,
-0.015165534801781178,
-0.021250130608677864,
-0.0037867880892008543,
0.05220620334148407,
0.05444886535406113,
-0.007380560506135225,
0.05514739826321602,
-0.040514957159757614,
-0.04448556900024414,
-0.042831145226955414,
-0.05099296197295189,
0.0770592987537384,
-0.0013200908433645964,
0.014568104408681393,
-0.0246141217648983,
0.028547970578074455,
-0.10632418841123581,
0.028400911018252373,
0.007155375089496374,
0.022536903619766235,
0.005583674181252718,
-0.049412067979574203,
0.03558845445513725,
-0.022481756284832954,
-0.034062709659338,
-0.030312687158584595,
0.051287081092596054,
0.03242667019367218,
0.014301558956503868,
-0.024411914870142937,
0.07838283479213715,
0.02163616381585598,
0.015165534801781178,
-0.0397796556353569,
0.017886139452457428,
0.003832744201645255,
-0.014549721963703632,
-0.04937530308961868,
-0.0012212850851938128,
-0.03000018559396267,
0.05691211670637131,
-0.03165460750460625,
0.022022195160388947,
-0.034503888338804245,
-0.015882451087236404,
-0.05099296197295189,
-0.04194878786802292,
-0.0113695552572608,
0.06341950595378876,
-0.039375241845846176,
0.024209707975387573,
-0.00006591837882297114,
-0.022500138729810715,
-0.016994589939713478,
0.01655341126024723,
-0.006273016799241304,
-0.023915588855743408,
0.04426497966051102,
-0.08647112548351288,
-0.015413697808980942,
0.02393397130072117,
0.01708650216460228,
0.036268606781959534,
0.05507386848330498,
-0.007913651876151562,
-0.0026172036305069923,
-0.02045968547463417,
0.02709575556218624,
-0.021158218383789062,
-0.06654452532529831,
-0.027353109791874886,
-0.06584599614143372,
0.03948553651571274,
-0.0741916373372078,
-0.05639740824699402,
0.007274860981851816,
0.01138793770223856,
-0.0253310389816761,
-0.02882370725274086,
-0.031047984957695007,
-0.04613998904824257,
0.07875048369169235,
0.005101134534925222,
-0.03305167332291603,
0.0018405443988740444,
0.07242691516876221,
-0.07007396221160889,
0.007017506752163172,
0.040037013590335846,
0.050698842853307724,
0.04911794885993004,
-0.010422858409583569,
0.0007588511798530817,
-0.013060742057859898,
-0.018823646008968353,
0.00868571549654007,
0.012187574990093708,
0.05356650799512863,
0.011066244915127754,
0.042095847427845,
-0.03715096414089203,
-0.0019037341699004173,
-0.0021013456862419844,
0.01873173378407955,
-0.024228090420365334,
-0.02091924659907818,
-0.00784012209624052,
-0.012729858048260212,
-0.002394316252321005,
-0.020257478579878807,
-0.002991746412590146,
-0.003246803069487214,
0.04257379099726677,
0.010229842737317085,
0.03490830212831497,
0.018768498674035072,
0.026691341772675514,
0.033952414989471436,
0.04698558524250984,
-0.041066430509090424,
-0.03718772903084755,
-0.004147544037550688,
0.03715096414089203,
-0.015064431354403496,
-0.004400303121656179,
-0.049632661044597626,
0.01644311659038067,
0.03555168956518173,
-0.04025760293006897,
-0.012729858048260212,
0.04680176079273224,
0.029191356152296066,
0.02948547527194023,
0.004138352815061808,
0.016415541991591454,
-0.025018537417054176,
0.026654576882719994,
0.07139749825000763,
-0.013603025116026402,
-0.002405805280432105,
-0.020717039704322815,
0.00338696944527328,
-0.05463268980383873,
-0.010413667187094688,
-0.026011189445853233,
0.041654668748378754,
-0.0021059412974864244,
-0.00872248038649559,
-0.05705917626619339,
-0.038676708936691284,
0.04871353507041931,
0.04669146612286568,
-0.010441240854561329,
0.036360517144203186,
0.07253721356391907,
-0.07007396221160889,
0.04930177330970764,
-0.07786812633275986,
0.020312625914812088,
-0.007330008316785097,
-0.07014749199151993,
-0.005638821516185999,
0.0011012246832251549,
-0.007385156117379665,
0.03432006388902664,
-0.01744496077299118,
-0.043566446751356125,
-0.018805263563990593,
0.022647198289632797,
0.10169180482625961,
0.01227948721498251,
0.07250044494867325,
0.004239456262439489,
0.11029479652643204,
-0.005473379511386156,
-0.02878694236278534,
0.018106728792190552,
0.028713412582874298,
-0.05338268354535103,
-0.0060616182163357735,
0.08264756947755814,
0.02761046402156353,
-0.03897082805633545,
-0.004609403666108847,
-0.009007408283650875,
0.005124112591147423,
0.08838289976119995,
-0.07617694139480591,
-0.00480241933837533,
-0.01591002382338047,
-0.04500027745962143,
0.030367834493517876,
-0.03904435783624649,
0.008644354529678822,
-0.11529482901096344,
0.015726199373602867,
-0.021801605820655823,
0.0006198337650857866,
-0.034062709659338,
-0.022683963179588318,
0.03380535542964935,
0.0395958311855793,
0.004122267942875624,
-0.05341944843530655,
0.0551106333732605,
0.02047806791961193,
0.0019761151634156704,
0.025570010766386986,
-0.031029602512717247,
-0.007775783538818359,
0.018989088013768196,
0.04610322415828705,
0.007872290909290314,
0.013777658343315125,
0.07036808133125305,
-0.007803357206285,
-0.05864006653428078,
0.03360315039753914,
0.03604801744222641,
-0.0020990478806197643,
0.010744551196694374,
0.05308856442570686,
-0.034577418118715286,
-0.022978082299232483,
0.03200387582182884,
0.013713319785892963,
0.014117734506726265,
0.03801494091749191,
-0.07327251136302948,
-0.006659048609435558,
0.04683852568268776,
-0.042904675006866455,
-0.042831145226955414,
-0.06437540054321289,
-0.03354800119996071,
0.028529588133096695,
0.10705948621034622,
-0.012803387828171253,
0.09603000432252884,
-0.060882728546857834,
0.05606652423739433,
0.014145308174192905,
-0.0039246566593647,
-0.03494506701827049,
0.023860441520810127,
-0.047684118151664734,
-0.0419120229780674,
-0.017251944169402122,
-0.03255534917116165,
0.00428081676363945,
0.07305192202329636,
-0.06562540680170059,
0.04257379099726677,
-0.012987212277948856,
-0.014632442966103554,
0.01678319275379181,
-0.029687684029340744,
-0.0043037948198616505,
0.08904466778039932,
0.01740819588303566,
-0.004761058837175369,
-0.02751855179667473,
0.051912084221839905,
0.015193108469247818,
-0.020239096134901047,
-0.00996329728513956,
-0.015404506586492062,
0.03295976296067238,
0.047757647931575775,
-0.009917340241372585,
0.021967047825455666,
0.004352048970758915,
0.0013511113356798887,
0.03948553651571274,
0.05930183827877045,
0.02231631428003311,
-0.049559131264686584,
-0.01045962329953909,
0.09544176608324051,
-0.032169315963983536,
-0.020845716819167137,
0.06621364504098892,
-0.01174639631062746,
0.049522366374731064,
-0.00284698442555964,
-0.0049908398650586605,
0.011654484085738659,
-0.0012029026402160525,
0.033897269517183304,
0.029632536694407463,
-0.030165627598762512,
-0.07227985560894012,
-0.02821708656847477,
-0.03672816976904869,
-0.07750047743320465,
0.008768436498939991,
-0.01532178558409214,
-0.006171912886202335,
-0.015735391527414322,
-0.005197642371058464,
0.06073566898703575,
-0.009531308896839619,
-0.039264947175979614,
-0.04900765419006348,
-0.0016383372712880373,
-0.03680169954895973,
-0.01142470259219408,
0.012123236432671547,
-0.01615818776190281,
-0.09139762073755264,
0.014016631059348583,
0.005087347701191902,
0.037003904581069946,
0.009954105131328106,
0.0019669239409267902,
-0.02647075243294239,
0.03619507700204849,
-0.005491761956363916,
0.015128769911825657,
0.04680176079273224,
0.03163622319698334,
-0.03597448766231537,
0.05691211670637131,
0.01585487648844719,
0.021213365718722343,
-0.04573557525873184,
-0.0504782535135746,
0.0017830992583185434,
0.015735391527414322,
0.00048253973363898695,
-0.0010483750374987721,
-0.022665580734610558,
0.02816193923354149,
0.02047806791961193,
0.04930177330970764,
0.03198549151420593,
0.022647198289632797,
-0.006475223693996668,
0.020661892369389534,
0.047095879912376404,
-0.023198673501610756,
0.09338293224573135,
-0.01746334321796894,
0.00011323886428726837,
-0.01805158145725727,
-0.0454782210290432,
-0.02106630615890026,
0.01751849055290222,
-0.02584574744105339,
0.011001906357705593,
-0.03893406316637993,
0.05724300071597099,
0.023676617071032524,
-0.02272072806954384,
-0.011277643032371998,
0.02590089477598667,
0.05231649801135063,
0.011875073425471783,
-0.02224278450012207,
-0.016525836661458015,
0.04485321789979935,
0.009944913908839226,
0.0010311414953321218,
0.03123181127011776,
0.028437675908207893,
0.020625127479434013,
0.004871353507041931,
-0.03724287822842598,
-0.042279671877622604,
0.04202231764793396,
-0.033235497772693634,
-0.012830961495637894,
0.09000055491924286,
-0.04099290072917938,
-0.03955906629562378,
-0.04992678016424179,
0.03845611959695816,
0.07084602862596512,
0.007541406899690628,
-0.02832738123834133,
-0.06746365129947662,
-0.0054366146214306355,
0.03687522932887077,
0.0117280138656497,
-0.016369586810469627,
-0.04147084429860115,
0.008244535885751247,
0.0034099475014954805,
0.017775844782590866,
-0.010091974399983883,
-0.03652596101164818,
0.0063373553566634655,
-0.010018444620072842,
-0.03123181127011776,
-0.04680176079273224,
-0.017913714051246643,
0.01083646435290575,
-0.010082783177495003,
-0.02286778762936592,
0.022095724940299988,
0.0758092924952507,
-0.03498183190822601,
0.04202231764793396,
0.045919399708509445,
-0.09117703139781952,
-0.040514957159757614,
0.021194983273744583,
0.038787003606557846,
0.028051644563674927,
0.003242207458242774,
-0.021819988265633583,
-0.010358519852161407,
-0.06757394969463348,
-0.001300559495575726,
0.011626910418272018,
-0.008033137768507004,
-0.02829061634838581,
-0.03557007387280464,
-0.056140054017305374,
0.026213396340608597,
0.003926954232156277,
0.05591946467757225,
0.027831053361296654,
-0.013639790005981922,
-0.04867677018046379,
-0.032684024423360825,
0.012371400371193886,
0.030809013172984123,
-0.04371350631117821,
0.02277587540447712,
-0.014981710352003574,
-0.06871365755796432,
-0.0030285113025456667,
-0.0385296493768692,
-0.02520236186683178,
0.006861255504190922,
0.019577326253056526,
-0.05161796510219574,
0.023198673501610756,
-0.00024284962273668498,
0.006663644220679998,
-0.021342042833566666,
-0.016204144805669785,
0.024981772527098656,
-0.023106759414076805,
-0.0021254727616906166,
0.02218763716518879,
0.03001856803894043,
-0.0030905522871762514,
-0.011029480025172234,
0.03919141739606857,
-0.02091924659907818,
0.02406264841556549,
-0.028437675908207893,
0.024228090420365334,
0.0024885262828320265,
0.010128739289939404,
-0.005579078570008278,
-0.020128801465034485,
0.04522086679935455,
-0.017757462337613106,
-0.0766916498541832,
-0.10676536709070206,
-0.0011322450591251254,
0.03292299807071686,
0.051397375762462616,
0.0006548753590323031,
0.02049645036458969,
0.007127801422029734,
-0.0006364929140545428,
0.05474298447370529,
-0.05389739200472832,
0.01475192978978157,
-0.028547970578074455,
-0.035735514014959335,
0.028529588133096695,
0.04301496967673302,
-0.048970889300107956,
0.029724448919296265,
0.04433850944042206,
0.06051507964730263,
-0.0047151027247309685,
0.008648950606584549,
0.022941317409276962,
0.01860305666923523,
-0.013354862108826637,
-0.027978114783763885,
0.038088470697402954,
-0.045331161469221115,
-0.012748240493237972,
0.0651106983423233,
-0.016700470820069313,
-0.03711419925093651,
0.04187525808811188,
-0.04128701984882355,
0.01444861851632595,
-0.038051705807447433,
0.0406620167195797,
0.02759208157658577,
0.02334573306143284,
-0.03483477234840393,
-0.00033662893110886216,
-0.0067831301130354404,
-0.005533122457563877,
-0.03479800745844841,
-0.05330915376543999,
-0.011865882202982903,
0.005822646431624889,
0.009103916585445404,
-0.010615874081850052,
-0.005036795977503061,
-0.025459716096520424,
-0.028070027008652687,
0.045257631689310074,
-0.03356638550758362,
0.00003218726851628162,
0.005353893153369427,
0.01349273044615984,
0.05562534183263779,
0.028364146128296852,
-0.008658141829073429,
0.04628705233335495,
-0.021875135600566864,
-0.02409941330552101,
-0.0395958311855793,
0.05360327288508415,
0.028934001922607422,
0.0116820577532053,
-0.020680274814367294,
-0.00871328916400671,
0.00015955406706780195,
0.006603901274502277,
-0.03764729201793671,
-0.022555286064743996,
0.02457735687494278,
0.09919179230928421,
-0.012527651153504848,
-0.007467877119779587,
0.009816236793994904,
0.02051483280956745,
0.033842120319604874,
-0.002529887016862631,
-0.061029788106679916,
-0.02051483280956745,
0.05411798134446144,
-0.02768399380147457,
0.03830906003713608,
-0.028070027008652687,
-0.028989149257540703,
0.08117697387933731,
-0.024356767535209656,
0.04272085055708885,
-0.009476161561906338,
-0.05691211670637131,
-0.018382467329502106,
0.02580898255109787,
-0.047132644802331924,
0.003182464512065053,
-0.06669158488512039,
0.009779471904039383,
-0.04044142737984657,
0.00855244230479002,
-0.023566322401165962,
-0.02757369913160801,
0.04375027120113373,
0.009935722686350346,
-0.006075405050069094,
-0.02093762904405594,
0.007192139979451895,
-0.0023024040274322033,
0.023768529295921326,
0.00764710595831275,
-0.04643411189317703,
-0.03687522932887077,
0.0035294336266815662,
-0.054265040904283524,
-0.05415474623441696,
-0.07566223293542862,
-0.006865851115435362,
0.01260118093341589,
-0.006369524635374546,
-0.002794134896248579,
-0.00797339528799057,
0.041139960289001465,
0.039963483810424805,
0.023033229634165764
]
|
31,042 | networkx.generators.random_graphs | random_powerlaw_tree | Returns a tree with a power law degree distribution.
Parameters
----------
n : int
The number of nodes.
gamma : float
Exponent of the power law.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
tries : int
Number of attempts to adjust the sequence to make it a tree.
Raises
------
NetworkXError
If no valid sequence is found within the maximum number of
attempts.
Notes
-----
A trial power law degree sequence is chosen and then elements are
swapped with new elements from a powerlaw distribution until the
sequence makes a tree (by checking, for example, that the number of
edges is one smaller than the number of nodes).
| 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, gamma=3, seed=None, tries=100, *, 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
]
|
31,043 | networkx.generators.random_graphs | random_powerlaw_tree_sequence | Returns a degree sequence for a tree with a power law distribution.
Parameters
----------
n : int,
The number of nodes.
gamma : float
Exponent of the power law.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
tries : int
Number of attempts to adjust the sequence to make it a tree.
Raises
------
NetworkXError
If no valid sequence is found within the maximum number of
attempts.
Notes
-----
A trial power law degree sequence is chosen and then elements are
swapped with new elements from a power law distribution until
the sequence makes a tree (by checking, for example, that the number of
edges is one smaller than the number of nodes).
| 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, gamma=3, seed=None, tries=100, *, backend=None, **backend_kwargs) | [
0.0035043188836425543,
0.001513827359303832,
0.015291573479771614,
0.004915148485451937,
-0.02493024617433548,
-0.04081585258245468,
-0.06480714678764343,
-0.03633185848593712,
0.012139363214373589,
-0.030046598985791206,
0.0064960443414747715,
0.04200391843914986,
-0.036830078810453415,
0.10715598613023758,
-0.043038688600063324,
0.013068737462162971,
0.034683894366025925,
0.04744603484869003,
-0.005882848519831896,
0.027344705536961555,
-0.039972707629203796,
0.0019928866531699896,
0.00007114779145922512,
0.07097742706537247,
-0.03453059494495392,
0.01072134729474783,
-0.03912956267595291,
0.010750090703368187,
-0.015646077692508698,
0.059288378804922104,
0.039206214249134064,
-0.12348232418298721,
0.021021122112870216,
0.03901458904147148,
-0.00013338807912077755,
0.010165638290345669,
0.027670465409755707,
0.061204615980386734,
-0.10968542098999023,
-0.03681091591715813,
0.07090077549219131,
-0.055417582392692566,
0.08339464664459229,
0.013107062317430973,
0.02470029704272747,
-0.023933803662657738,
0.030966393649578094,
0.012972925789654255,
-0.09650170803070068,
-0.009878203272819519,
0.016125136986374855,
-0.07047920674085617,
0.026233287528157234,
-0.0023737389128655195,
-0.02042708918452263,
0.01844378374516964,
-0.003142629051581025,
0.04464832693338394,
0.01788807474076748,
0.025332655757665634,
0.06300587952136993,
-0.01955520175397396,
-0.014592146500945091,
-0.03525876626372337,
-0.024508673697710037,
0.022017566487193108,
-0.04859577491879463,
-0.026808159425854683,
-0.0014994556549936533,
0.06204776093363762,
0.050358712673187256,
0.0640406459569931,
-0.008081730455160141,
0.05511098355054855,
0.054766058921813965,
0.04430340602993965,
0.04863410070538521,
0.027018945664167404,
-0.0520833283662796,
0.019698917865753174,
0.0042037456296384335,
-0.02583087794482708,
0.011823183856904507,
-0.034319810569286346,
0.005509181879460812,
-0.015521521680057049,
0.006074471864849329,
0.0031066995579749346,
0.00029297469882294536,
-0.10179052501916885,
-0.04859577491879463,
-0.04982216656208038,
0.055647529661655426,
0.016335923224687576,
0.031637076288461685,
-0.0332467146217823,
-0.00631879223510623,
-0.032307758927345276,
0.007482906337827444,
-0.024546999484300613,
-0.04503157362341881,
0.0437285341322422,
-0.03820976987481117,
0.0006491253734566271,
0.006534368731081486,
0.007185889407992363,
-0.052159976214170456,
0.015147855505347252,
0.02086782269179821,
-0.035354577004909515,
-0.1171204224228859,
0.04361356049776077,
0.07979211956262589,
0.01823299750685692,
-0.02287987247109413,
-0.01329868659377098,
0.015013718977570534,
0.011641141027212143,
0.0319436751306057,
0.032211948186159134,
0.016355084255337715,
0.02707643248140812,
-0.0329209566116333,
-0.0001762040046742186,
0.000751524290535599,
-0.024048777297139168,
0.048212528228759766,
-0.008579952642321587,
-0.012896277010440826,
-0.0388229675590992,
0.01054888591170311,
0.014841257594525814,
-0.04702446237206459,
0.07021093368530273,
-0.011995645239949226,
-0.03441562131047249,
-0.047982580959796906,
0.005777455400675535,
0.06913784146308899,
0.004014517180621624,
-0.0008605102775618434,
-0.06687667965888977,
0.08906670659780502,
0.012896277010440826,
-0.039512813091278076,
-0.021519344300031662,
0.017236553132534027,
-0.05706554651260376,
0.0018371924525126815,
-0.012196850031614304,
0.04001103341579437,
-0.0013245990267023444,
0.02086782269179821,
-0.03460724279284477,
-0.039551135152578354,
0.017696451395750046,
-0.041544023901224136,
-0.0003574980073608458,
-0.02322479523718357,
0.014678376726806164,
-0.030640633776783943,
-0.054651085287332535,
0.04874907433986664,
0.054306164383888245,
0.010108151473104954,
-0.030755607411265373,
0.04947724565863609,
0.0018455759854987264,
0.017437757924199104,
-0.035488713532686234,
-0.07435000687837601,
-0.0011371669825166464,
-0.06603353470563889,
-0.06166451424360275,
0.05269652232527733,
-0.002188103273510933,
-0.025984177365899086,
-0.03100471757352352,
0.029280105605721474,
0.03437729552388191,
0.03826725855469704,
-0.0473310612142086,
0.06779647618532181,
-0.059250056743621826,
-0.030621470883488655,
-0.03543122485280037,
-0.006342745386064053,
0.04300036281347275,
0.018012629821896553,
0.008532046340405941,
0.02132772095501423,
0.024776946753263474,
0.036140233278274536,
0.0609363429248333,
0.025217682123184204,
0.005240908823907375,
0.025121869519352913,
0.014601727947592735,
-0.012886695563793182,
0.011133338324725628,
0.04560644552111626,
0.0022288234904408455,
0.02052289992570877,
0.023205632343888283,
0.027900414541363716,
0.007703273557126522,
-0.03282514214515686,
-0.04196559637784958,
0.023167308419942856,
-0.027229731902480125,
0.004886405076831579,
-0.01048181764781475,
0.028609421104192734,
-0.02707643248140812,
-0.015406547114253044,
-0.06285258382558823,
0.019239021465182304,
0.017207810655236244,
-0.00011108187754871324,
-0.03493300452828407,
0.03205864876508713,
-0.05890513211488724,
0.010960876941680908,
0.02581171505153179,
0.005810989532619715,
0.0437285341322422,
-0.014563403092324734,
0.004024098161607981,
-0.015186180360615253,
0.029011832550168037,
0.03384074941277504,
-0.0007826631190255284,
0.03673426806926727,
-0.028341148048639297,
-0.039187051355838776,
-0.030199898406863213,
0.0030659795738756657,
-0.039627786725759506,
-0.035795312374830246,
0.01893242448568344,
-0.029414242133498192,
0.019833054393529892,
-0.020331276580691338,
-0.008939246647059917,
0.02234332635998726,
0.01555984653532505,
0.028283661231398582,
-0.05817696079611778,
-0.06848631799221039,
-0.019794730469584465,
-0.09335907548666,
-0.01246512308716774,
0.024757785722613335,
0.03146461397409439,
0.02615663781762123,
-0.026444073766469955,
-0.021519344300031662,
0.009715322405099869,
-0.003995354752987623,
0.058598533272743225,
0.007176308427006006,
-0.020388763397932053,
-0.1112184077501297,
0.03167540207505226,
-0.001459933235310018,
-0.00600740360096097,
-0.0707474797964096,
0.06948275864124298,
-0.013528634794056416,
-0.03133047744631767,
0.06193278729915619,
0.0006862524314783514,
0.008824272081255913,
0.0004092963063158095,
0.027018945664167404,
0.023397255688905716,
-0.01239805482327938,
0.019516875967383385,
-0.019603107124567032,
-0.04349858686327934,
-0.0412757508456707,
-0.04342193529009819,
0.02470029704272747,
0.04541482403874397,
-0.005854104645550251,
0.004242070019245148,
-0.023339768871665,
-0.06204776093363762,
0.024336213245987892,
-0.03353415057063103,
0.015473615378141403,
-0.028513610363006592,
0.005767873954027891,
0.050013791769742966,
-0.0017425782280042768,
-0.004898381419479847,
0.0586368590593338,
0.023493068292737007,
0.02017797715961933,
-0.008934455923736095,
0.038056470453739166,
-0.009686578996479511,
0.09113623946905136,
0.003959425259381533,
-0.016700007021427155,
-0.03203948587179184,
0.013605284504592419,
-0.025351818650960922,
-0.01985221728682518,
0.020024679601192474,
-0.09059969335794449,
0.0251410324126482,
0.057563766837120056,
0.030832257121801376,
-0.009427887387573719,
-0.06733657419681549,
0.011545329354703426,
0.0006045129848644137,
0.04050925374031067,
-0.0038444509264081717,
-0.017303621396422386,
0.03748159855604172,
-0.0013222036650404334,
0.04656456410884857,
-0.01759105734527111,
-0.002216846914961934,
0.046411264687776566,
0.07500152289867401,
0.0013545402325689793,
0.022247513756155968,
-0.04208057001233101,
0.01657545194029808,
-0.01065427903085947,
0.018846193328499794,
-0.08753371983766556,
0.08086521178483963,
-0.027459679171442986,
-0.023282282054424286,
0.06664673238992691,
-0.0860007256269455,
0.021634317934513092,
-0.046756189316511154,
-0.005255280528217554,
-0.010635117068886757,
0.04637294262647629,
0.04407345503568649,
0.012110618874430656,
-0.004072003997862339,
-0.05695056915283203,
0.0692911371588707,
-0.013681934215128422,
0.04196559637784958,
-0.002694708527997136,
0.025754228234291077,
-0.0191623717546463,
0.03353415057063103,
-0.009839878417551517,
0.004469623323529959,
0.010146476328372955,
0.07032590359449387,
-0.023320607841014862,
-0.005672062281519175,
-0.027766278013586998,
-0.013691514730453491,
0.027670465409755707,
0.006304420530796051,
0.0023773317225277424,
0.04388183355331421,
0.038516368716955185,
-0.052504900842905045,
0.06971271336078644,
-0.06718327850103378,
-0.04510822519659996,
0.04920897260308266,
0.010424330830574036,
-0.028781883418560028,
-0.037711549550294876,
0.020024679601192474,
0.03211613744497299,
0.03307425603270531,
-0.012388473376631737,
-0.03958946093916893,
0.009993176907300949,
0.03958946093916893,
-0.006170284003019333,
-0.012053132057189941,
0.07266371697187424,
0.003758220234885812,
-0.006524787750095129,
-0.026999782770872116,
0.01284837070852518,
-0.029854975640773773,
0.07327691465616226,
0.007018218748271465,
-0.05499600991606712,
0.005044494289904833,
0.04119909927248955,
-0.02606082707643509,
-0.037060029804706573,
-0.0035546200815588236,
0.002515061292797327,
0.016958698630332947,
-0.05055033788084984,
-0.023627204820513725,
-0.005691224709153175,
-0.033917397260665894,
0.02786208875477314,
0.028053712099790573,
0.01134412456303835,
0.014994556084275246,
-0.015234085731208324,
0.023033171892166138,
-0.018989911302924156,
-0.011660303920507431,
0.02370385453104973,
-0.0010964469984173775,
-0.005945126060396433,
-0.020158816128969193,
0.010903390124440193,
0.014965812675654888,
0.032441895455121994,
-0.007827828638255596,
0.006515206769108772,
-0.024853596463799477,
0.04411178082227707,
0.005777455400675535,
-0.051048558205366135,
0.01962227001786232,
-0.08155505359172821,
0.022190026938915253,
0.05399956554174423,
-0.039627786725759506,
0.0334191769361496,
-0.043038688600063324,
0.024642810225486755,
0.008546417579054832,
0.028896857053041458,
0.0053702546283602715,
0.05672062188386917,
-0.022975685074925423,
0.012091456912457943,
0.022247513756155968,
0.011708209291100502,
-0.05741046741604805,
-0.02956753969192505,
-0.04564477130770683,
-0.021730130538344383,
-0.0012395658995956182,
0.01608681119978428,
-0.02052289992570877,
-0.0056672715581953526,
-0.005307977087795734,
0.07116904854774475,
-0.006764317397028208,
-0.04748435690999031,
0.03577614948153496,
0.05974827706813812,
-0.027996225282549858,
-0.03464556857943535,
0.10064078122377396,
0.014841257594525814,
0.00699426606297493,
0.012340568006038666,
0.09573521465063095,
0.034223996102809906,
-0.019200697541236877,
0.05415286496281624,
-0.0200630035251379,
-0.015301153995096684,
0.03801814839243889,
-0.018970748409628868,
0.00022650523169431835,
0.015550265088677406,
-0.03303593024611473,
-0.01680540107190609,
-0.03870799019932747,
-0.009451840072870255,
-0.03970443457365036,
-0.01138244941830635,
-0.011238731443881989,
0.01736111007630825,
0.003992959391325712,
0.010366843082010746,
0.03215445950627327,
0.02287987247109413,
-0.027727952226996422,
-0.035584524273872375,
0.025409305468201637,
0.01200522668659687,
0.0026923133991658688,
-0.07316193729639053,
-0.08002206683158875,
0.02232416346669197,
0.03696421533823013,
-0.05150845646858215,
-0.012647165916860104,
-0.017140742391347885,
-0.04790592938661575,
-0.007516440469771624,
-0.07634288817644119,
0.019258184358477592,
-0.0112195685505867,
-0.014640052802860737,
-0.04660288989543915,
0.007406257092952728,
0.0004742687160614878,
-0.0021916963160037994,
-0.017418596893548965,
0.0022611599415540695,
0.06346577405929565,
-0.0000900481827557087,
-0.02379966713488102,
0.03757741302251816,
0.03688756749033928,
-0.014563403092324734,
0.01624969206750393,
-0.008642230182886124,
0.004589388146996498,
0.05139348283410072,
-0.028801046311855316,
0.03485635668039322,
0.03474137932062149,
0.0314454510807991,
-0.045951370149850845,
0.02753632888197899,
-0.0088434349745512,
0.013969369232654572,
-0.011066270060837269,
0.021461857482790947,
-0.007070915307849646,
-0.024642810225486755,
0.036370184272527695,
0.040087681263685226,
0.020139653235673904,
-0.010855483822524548,
-0.014026856049895287,
0.01009857002645731,
0.005470857489854097,
-0.05231327563524246,
-0.05166175588965416,
0.008297307416796684,
0.019267765805125237,
-0.007540393620729446,
-0.012656746432185173,
-0.006462510209530592,
-0.012982507236301899,
-0.04070087894797325,
0.0009629091946408153,
-0.012752559036016464,
-0.01922944001853466,
-0.002474341308698058,
0.015052043832838535,
-0.018549175933003426,
-0.022362489253282547,
0.006740364246070385,
-0.05652899667620659,
-0.07799085229635239,
0.0484808012843132,
0.060284823179244995,
0.02460448630154133,
-0.0671449527144432,
0.014994556084275246,
-0.022190026938915253,
0.0018180300248786807,
0.037749871611595154,
0.0430770143866539,
-0.02470029704272747,
-0.0013880743645131588,
-0.019612688571214676,
-0.01099920179694891,
0.024048777297139168,
0.03420483320951462,
0.03012324869632721,
0.0176868699491024,
-0.04284706339240074,
-0.007195470854640007,
-0.04970719292759895,
-0.050013791769742966,
-0.009768019430339336,
0.008924874477088451,
0.00006104263593442738,
0.06177948787808418,
-0.0227648988366127,
0.01634550280869007,
0.044265080243349075,
0.028475284576416016,
-0.029395079240202904,
0.01878870651125908,
0.001980910310521722,
-0.02864774689078331,
-0.07687943428754807,
-0.022496625781059265,
0.032326921820640564,
-0.04457167908549309,
0.004740291740745306,
0.04227219149470329,
0.04767598211765289,
-0.015243667177855968,
-0.05672062188386917,
-0.07549974322319031,
0.035584524273872375,
0.03249938413500786,
0.0019437831360846758,
-0.0014874791959300637,
0.05511098355054855,
0.016747914254665375,
-0.003648036625236273,
-0.06319750100374222,
0.02527516894042492,
0.0034612035378813744,
-0.03656180575489998,
-0.0017545546870678663,
-0.02719140611588955,
-0.06377237290143967,
-0.0379989854991436,
-0.05392291396856308,
-0.04499325156211853,
0.01865456998348236,
0.023320607841014862,
0.0471777617931366,
-0.03541206568479538,
0.019794730469584465,
0.018252160400152206,
0.05108688399195671,
-0.025351818650960922,
-0.006165493279695511,
-0.025639254599809647,
-0.02571590431034565,
0.01569398306310177,
-0.0032839516643434763,
0.0167095884680748,
-0.057908687740564346,
0.029184293001890182,
-0.0018623430514708161,
0.024546999484300613,
-0.023876314982771873,
0.051700081676244736,
0.00792843196541071,
0.0020360019989311695,
0.08776366710662842,
-0.06664673238992691,
0.010769253596663475,
-0.0633891299366951,
-0.003698337823152542,
-0.03786484897136688,
0.00578224565833807,
-0.020158816128969193,
0.019267765805125237,
0.010980038903653622,
-0.026022501289844513,
-0.022285839542746544,
0.05074196308851242,
0.008139217272400856,
-0.0031282573472708464,
-0.03271016851067543,
-0.0024276331532746553,
0.017801843583583832,
-0.005691224709153175,
-0.002991725457832217,
-0.03414734825491905,
0.06588023900985718,
0.004620526917278767,
0.029030993580818176,
0.04418842867016792,
0.007799085695296526,
0.058138638734817505,
0.022592436522245407,
-0.03978108614683151,
-0.03665761649608612,
0.007861362770199776,
-0.028111200779676437,
-0.02742135524749756,
-0.006218189839273691,
-0.06511373817920685,
-0.04802090674638748,
0.02989330142736435,
-0.021270234137773514,
-0.00481933681294322,
0.011487842537462711,
0.011986063793301582,
0.07733933627605438,
-0.002879146486520767,
-0.0029462147504091263,
-0.005355882924050093,
0.0016311969375237823,
0.05062698572874069,
-0.014755026437342167,
0.018175510689616203,
-0.057257167994976044,
-0.002225230447947979,
0.021519344300031662,
-0.025198519229888916,
0.02345474436879158,
0.050358712673187256,
0.03866966813802719,
0.0638873502612114,
-0.025773391127586365,
-0.017236553132534027,
-0.053731292486190796,
-0.04756100848317146,
0.02119358442723751,
-0.038957104086875916,
-0.03606358543038368,
0.05821528658270836,
-0.07595964521169662,
0.035354577004909515,
-0.05112520977854729,
0.009006314910948277,
-0.032518547028303146,
0.010232706554234028,
-0.018089279532432556,
-0.045299846678972244,
0.04924729838967323,
-0.008608696050941944,
0.004361834842711687,
-0.04016433283686638,
-0.005614574998617172,
0.03159875050187111,
-0.05457443743944168,
0.0015856863465160131,
-0.06193278729915619,
-0.01375858299434185,
0.036140233278274536,
0.007391884922981262,
0.023761341348290443,
-0.008330841548740864,
0.031637076288461685,
-0.05376961827278137,
-0.012139363214373589,
-0.03608274832367897,
0.014189736917614937,
0.032863467931747437,
0.0013916672905907035,
0.01500413753092289,
-0.0038899616338312626,
-0.03395572304725647,
0.01099920179694891,
0.009241053834557533,
0.02356971800327301,
0.008522464893758297,
0.01662335731089115,
0.0034683893900364637,
-0.05219830200076103,
0.04457167908549309,
-0.006127168424427509,
0.03594861179590225,
-0.030295711010694504,
0.008091311901807785,
0.008407491259276867,
0.00029581913258880377,
0.05457443743944168,
-0.017926398664712906,
-0.018664151430130005,
0.05491935834288597,
0.02774711512029171,
0.004953473340719938,
0.04790592938661575,
-0.029241779819130898,
-0.03203948587179184,
-0.0733918845653534,
-0.01636466570198536,
0.013662771321833134,
0.06189446151256561,
-0.04073920473456383,
-0.0022803223691880703,
0.020676199346780777,
0.015933511778712273,
0.04713943600654602
]
|
31,046 | networkx.generators.random_graphs | random_regular_graph | Returns a random $d$-regular graph on $n$ nodes.
A regular graph is a graph where each node has the same number of neighbors.
The resulting graph has no self-loops or parallel edges.
Parameters
----------
d : int
The degree of each node.
n : integer
The number of nodes. The value of $n \times d$ must be even.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Notes
-----
The nodes are numbered from $0$ to $n - 1$.
Kim and Vu's paper [2]_ shows that this algorithm samples in an
asymptotically uniform way from the space of random graphs when
$d = O(n^{1 / 3 - \epsilon})$.
Raises
------
NetworkXError
If $n \times d$ is odd or $d$ is greater than or equal to $n$.
References
----------
.. [1] A. Steger and N. Wormald,
Generating random regular graphs quickly,
Probability and Computing 8 (1999), 377-396, 1999.
https://doi.org/10.1017/S0963548399003867
.. [2] Jeong Han Kim and Van H. Vu,
Generating random regular graphs,
Proceedings of the thirty-fifth ACM symposium on Theory of computing,
San Diego, CA, USA, pp 213--222, 2003.
http://portal.acm.org/citation.cfm?id=780542.780576
| 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
| (d, n, 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
]
|
31,047 | networkx.generators.random_graphs | random_shell_graph | Returns a random shell graph for the constructor given.
Parameters
----------
constructor : list of three-tuples
Represents the parameters for a shell, starting at the center
shell. Each element of the list must be of the form `(n, m,
d)`, where `n` is the number of nodes in the shell, `m` is
the number of edges in the shell, and `d` is the ratio of
inter-shell (next) edges to intra-shell edges. If `d` is zero,
there will be no intra-shell edges, and if `d` is one there
will be all possible intra-shell edges.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Examples
--------
>>> constructor = [(10, 20, 0.8), (20, 40, 0.8)]
>>> G = nx.random_shell_graph(constructor)
| 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
| (constructor, seed=None, *, backend=None, **backend_kwargs) | [
0.0035043188836425543,
0.001513827359303832,
0.015291573479771614,
0.004915148485451937,
-0.02493024617433548,
-0.04081585258245468,
-0.06480714678764343,
-0.03633185848593712,
0.012139363214373589,
-0.030046598985791206,
0.0064960443414747715,
0.04200391843914986,
-0.036830078810453415,
0.10715598613023758,
-0.043038688600063324,
0.013068737462162971,
0.034683894366025925,
0.04744603484869003,
-0.005882848519831896,
0.027344705536961555,
-0.039972707629203796,
0.0019928866531699896,
0.00007114779145922512,
0.07097742706537247,
-0.03453059494495392,
0.01072134729474783,
-0.03912956267595291,
0.010750090703368187,
-0.015646077692508698,
0.059288378804922104,
0.039206214249134064,
-0.12348232418298721,
0.021021122112870216,
0.03901458904147148,
-0.00013338807912077755,
0.010165638290345669,
0.027670465409755707,
0.061204615980386734,
-0.10968542098999023,
-0.03681091591715813,
0.07090077549219131,
-0.055417582392692566,
0.08339464664459229,
0.013107062317430973,
0.02470029704272747,
-0.023933803662657738,
0.030966393649578094,
0.012972925789654255,
-0.09650170803070068,
-0.009878203272819519,
0.016125136986374855,
-0.07047920674085617,
0.026233287528157234,
-0.0023737389128655195,
-0.02042708918452263,
0.01844378374516964,
-0.003142629051581025,
0.04464832693338394,
0.01788807474076748,
0.025332655757665634,
0.06300587952136993,
-0.01955520175397396,
-0.014592146500945091,
-0.03525876626372337,
-0.024508673697710037,
0.022017566487193108,
-0.04859577491879463,
-0.026808159425854683,
-0.0014994556549936533,
0.06204776093363762,
0.050358712673187256,
0.0640406459569931,
-0.008081730455160141,
0.05511098355054855,
0.054766058921813965,
0.04430340602993965,
0.04863410070538521,
0.027018945664167404,
-0.0520833283662796,
0.019698917865753174,
0.0042037456296384335,
-0.02583087794482708,
0.011823183856904507,
-0.034319810569286346,
0.005509181879460812,
-0.015521521680057049,
0.006074471864849329,
0.0031066995579749346,
0.00029297469882294536,
-0.10179052501916885,
-0.04859577491879463,
-0.04982216656208038,
0.055647529661655426,
0.016335923224687576,
0.031637076288461685,
-0.0332467146217823,
-0.00631879223510623,
-0.032307758927345276,
0.007482906337827444,
-0.024546999484300613,
-0.04503157362341881,
0.0437285341322422,
-0.03820976987481117,
0.0006491253734566271,
0.006534368731081486,
0.007185889407992363,
-0.052159976214170456,
0.015147855505347252,
0.02086782269179821,
-0.035354577004909515,
-0.1171204224228859,
0.04361356049776077,
0.07979211956262589,
0.01823299750685692,
-0.02287987247109413,
-0.01329868659377098,
0.015013718977570534,
0.011641141027212143,
0.0319436751306057,
0.032211948186159134,
0.016355084255337715,
0.02707643248140812,
-0.0329209566116333,
-0.0001762040046742186,
0.000751524290535599,
-0.024048777297139168,
0.048212528228759766,
-0.008579952642321587,
-0.012896277010440826,
-0.0388229675590992,
0.01054888591170311,
0.014841257594525814,
-0.04702446237206459,
0.07021093368530273,
-0.011995645239949226,
-0.03441562131047249,
-0.047982580959796906,
0.005777455400675535,
0.06913784146308899,
0.004014517180621624,
-0.0008605102775618434,
-0.06687667965888977,
0.08906670659780502,
0.012896277010440826,
-0.039512813091278076,
-0.021519344300031662,
0.017236553132534027,
-0.05706554651260376,
0.0018371924525126815,
-0.012196850031614304,
0.04001103341579437,
-0.0013245990267023444,
0.02086782269179821,
-0.03460724279284477,
-0.039551135152578354,
0.017696451395750046,
-0.041544023901224136,
-0.0003574980073608458,
-0.02322479523718357,
0.014678376726806164,
-0.030640633776783943,
-0.054651085287332535,
0.04874907433986664,
0.054306164383888245,
0.010108151473104954,
-0.030755607411265373,
0.04947724565863609,
0.0018455759854987264,
0.017437757924199104,
-0.035488713532686234,
-0.07435000687837601,
-0.0011371669825166464,
-0.06603353470563889,
-0.06166451424360275,
0.05269652232527733,
-0.002188103273510933,
-0.025984177365899086,
-0.03100471757352352,
0.029280105605721474,
0.03437729552388191,
0.03826725855469704,
-0.0473310612142086,
0.06779647618532181,
-0.059250056743621826,
-0.030621470883488655,
-0.03543122485280037,
-0.006342745386064053,
0.04300036281347275,
0.018012629821896553,
0.008532046340405941,
0.02132772095501423,
0.024776946753263474,
0.036140233278274536,
0.0609363429248333,
0.025217682123184204,
0.005240908823907375,
0.025121869519352913,
0.014601727947592735,
-0.012886695563793182,
0.011133338324725628,
0.04560644552111626,
0.0022288234904408455,
0.02052289992570877,
0.023205632343888283,
0.027900414541363716,
0.007703273557126522,
-0.03282514214515686,
-0.04196559637784958,
0.023167308419942856,
-0.027229731902480125,
0.004886405076831579,
-0.01048181764781475,
0.028609421104192734,
-0.02707643248140812,
-0.015406547114253044,
-0.06285258382558823,
0.019239021465182304,
0.017207810655236244,
-0.00011108187754871324,
-0.03493300452828407,
0.03205864876508713,
-0.05890513211488724,
0.010960876941680908,
0.02581171505153179,
0.005810989532619715,
0.0437285341322422,
-0.014563403092324734,
0.004024098161607981,
-0.015186180360615253,
0.029011832550168037,
0.03384074941277504,
-0.0007826631190255284,
0.03673426806926727,
-0.028341148048639297,
-0.039187051355838776,
-0.030199898406863213,
0.0030659795738756657,
-0.039627786725759506,
-0.035795312374830246,
0.01893242448568344,
-0.029414242133498192,
0.019833054393529892,
-0.020331276580691338,
-0.008939246647059917,
0.02234332635998726,
0.01555984653532505,
0.028283661231398582,
-0.05817696079611778,
-0.06848631799221039,
-0.019794730469584465,
-0.09335907548666,
-0.01246512308716774,
0.024757785722613335,
0.03146461397409439,
0.02615663781762123,
-0.026444073766469955,
-0.021519344300031662,
0.009715322405099869,
-0.003995354752987623,
0.058598533272743225,
0.007176308427006006,
-0.020388763397932053,
-0.1112184077501297,
0.03167540207505226,
-0.001459933235310018,
-0.00600740360096097,
-0.0707474797964096,
0.06948275864124298,
-0.013528634794056416,
-0.03133047744631767,
0.06193278729915619,
0.0006862524314783514,
0.008824272081255913,
0.0004092963063158095,
0.027018945664167404,
0.023397255688905716,
-0.01239805482327938,
0.019516875967383385,
-0.019603107124567032,
-0.04349858686327934,
-0.0412757508456707,
-0.04342193529009819,
0.02470029704272747,
0.04541482403874397,
-0.005854104645550251,
0.004242070019245148,
-0.023339768871665,
-0.06204776093363762,
0.024336213245987892,
-0.03353415057063103,
0.015473615378141403,
-0.028513610363006592,
0.005767873954027891,
0.050013791769742966,
-0.0017425782280042768,
-0.004898381419479847,
0.0586368590593338,
0.023493068292737007,
0.02017797715961933,
-0.008934455923736095,
0.038056470453739166,
-0.009686578996479511,
0.09113623946905136,
0.003959425259381533,
-0.016700007021427155,
-0.03203948587179184,
0.013605284504592419,
-0.025351818650960922,
-0.01985221728682518,
0.020024679601192474,
-0.09059969335794449,
0.0251410324126482,
0.057563766837120056,
0.030832257121801376,
-0.009427887387573719,
-0.06733657419681549,
0.011545329354703426,
0.0006045129848644137,
0.04050925374031067,
-0.0038444509264081717,
-0.017303621396422386,
0.03748159855604172,
-0.0013222036650404334,
0.04656456410884857,
-0.01759105734527111,
-0.002216846914961934,
0.046411264687776566,
0.07500152289867401,
0.0013545402325689793,
0.022247513756155968,
-0.04208057001233101,
0.01657545194029808,
-0.01065427903085947,
0.018846193328499794,
-0.08753371983766556,
0.08086521178483963,
-0.027459679171442986,
-0.023282282054424286,
0.06664673238992691,
-0.0860007256269455,
0.021634317934513092,
-0.046756189316511154,
-0.005255280528217554,
-0.010635117068886757,
0.04637294262647629,
0.04407345503568649,
0.012110618874430656,
-0.004072003997862339,
-0.05695056915283203,
0.0692911371588707,
-0.013681934215128422,
0.04196559637784958,
-0.002694708527997136,
0.025754228234291077,
-0.0191623717546463,
0.03353415057063103,
-0.009839878417551517,
0.004469623323529959,
0.010146476328372955,
0.07032590359449387,
-0.023320607841014862,
-0.005672062281519175,
-0.027766278013586998,
-0.013691514730453491,
0.027670465409755707,
0.006304420530796051,
0.0023773317225277424,
0.04388183355331421,
0.038516368716955185,
-0.052504900842905045,
0.06971271336078644,
-0.06718327850103378,
-0.04510822519659996,
0.04920897260308266,
0.010424330830574036,
-0.028781883418560028,
-0.037711549550294876,
0.020024679601192474,
0.03211613744497299,
0.03307425603270531,
-0.012388473376631737,
-0.03958946093916893,
0.009993176907300949,
0.03958946093916893,
-0.006170284003019333,
-0.012053132057189941,
0.07266371697187424,
0.003758220234885812,
-0.006524787750095129,
-0.026999782770872116,
0.01284837070852518,
-0.029854975640773773,
0.07327691465616226,
0.007018218748271465,
-0.05499600991606712,
0.005044494289904833,
0.04119909927248955,
-0.02606082707643509,
-0.037060029804706573,
-0.0035546200815588236,
0.002515061292797327,
0.016958698630332947,
-0.05055033788084984,
-0.023627204820513725,
-0.005691224709153175,
-0.033917397260665894,
0.02786208875477314,
0.028053712099790573,
0.01134412456303835,
0.014994556084275246,
-0.015234085731208324,
0.023033171892166138,
-0.018989911302924156,
-0.011660303920507431,
0.02370385453104973,
-0.0010964469984173775,
-0.005945126060396433,
-0.020158816128969193,
0.010903390124440193,
0.014965812675654888,
0.032441895455121994,
-0.007827828638255596,
0.006515206769108772,
-0.024853596463799477,
0.04411178082227707,
0.005777455400675535,
-0.051048558205366135,
0.01962227001786232,
-0.08155505359172821,
0.022190026938915253,
0.05399956554174423,
-0.039627786725759506,
0.0334191769361496,
-0.043038688600063324,
0.024642810225486755,
0.008546417579054832,
0.028896857053041458,
0.0053702546283602715,
0.05672062188386917,
-0.022975685074925423,
0.012091456912457943,
0.022247513756155968,
0.011708209291100502,
-0.05741046741604805,
-0.02956753969192505,
-0.04564477130770683,
-0.021730130538344383,
-0.0012395658995956182,
0.01608681119978428,
-0.02052289992570877,
-0.0056672715581953526,
-0.005307977087795734,
0.07116904854774475,
-0.006764317397028208,
-0.04748435690999031,
0.03577614948153496,
0.05974827706813812,
-0.027996225282549858,
-0.03464556857943535,
0.10064078122377396,
0.014841257594525814,
0.00699426606297493,
0.012340568006038666,
0.09573521465063095,
0.034223996102809906,
-0.019200697541236877,
0.05415286496281624,
-0.0200630035251379,
-0.015301153995096684,
0.03801814839243889,
-0.018970748409628868,
0.00022650523169431835,
0.015550265088677406,
-0.03303593024611473,
-0.01680540107190609,
-0.03870799019932747,
-0.009451840072870255,
-0.03970443457365036,
-0.01138244941830635,
-0.011238731443881989,
0.01736111007630825,
0.003992959391325712,
0.010366843082010746,
0.03215445950627327,
0.02287987247109413,
-0.027727952226996422,
-0.035584524273872375,
0.025409305468201637,
0.01200522668659687,
0.0026923133991658688,
-0.07316193729639053,
-0.08002206683158875,
0.02232416346669197,
0.03696421533823013,
-0.05150845646858215,
-0.012647165916860104,
-0.017140742391347885,
-0.04790592938661575,
-0.007516440469771624,
-0.07634288817644119,
0.019258184358477592,
-0.0112195685505867,
-0.014640052802860737,
-0.04660288989543915,
0.007406257092952728,
0.0004742687160614878,
-0.0021916963160037994,
-0.017418596893548965,
0.0022611599415540695,
0.06346577405929565,
-0.0000900481827557087,
-0.02379966713488102,
0.03757741302251816,
0.03688756749033928,
-0.014563403092324734,
0.01624969206750393,
-0.008642230182886124,
0.004589388146996498,
0.05139348283410072,
-0.028801046311855316,
0.03485635668039322,
0.03474137932062149,
0.0314454510807991,
-0.045951370149850845,
0.02753632888197899,
-0.0088434349745512,
0.013969369232654572,
-0.011066270060837269,
0.021461857482790947,
-0.007070915307849646,
-0.024642810225486755,
0.036370184272527695,
0.040087681263685226,
0.020139653235673904,
-0.010855483822524548,
-0.014026856049895287,
0.01009857002645731,
0.005470857489854097,
-0.05231327563524246,
-0.05166175588965416,
0.008297307416796684,
0.019267765805125237,
-0.007540393620729446,
-0.012656746432185173,
-0.006462510209530592,
-0.012982507236301899,
-0.04070087894797325,
0.0009629091946408153,
-0.012752559036016464,
-0.01922944001853466,
-0.002474341308698058,
0.015052043832838535,
-0.018549175933003426,
-0.022362489253282547,
0.006740364246070385,
-0.05652899667620659,
-0.07799085229635239,
0.0484808012843132,
0.060284823179244995,
0.02460448630154133,
-0.0671449527144432,
0.014994556084275246,
-0.022190026938915253,
0.0018180300248786807,
0.037749871611595154,
0.0430770143866539,
-0.02470029704272747,
-0.0013880743645131588,
-0.019612688571214676,
-0.01099920179694891,
0.024048777297139168,
0.03420483320951462,
0.03012324869632721,
0.0176868699491024,
-0.04284706339240074,
-0.007195470854640007,
-0.04970719292759895,
-0.050013791769742966,
-0.009768019430339336,
0.008924874477088451,
0.00006104263593442738,
0.06177948787808418,
-0.0227648988366127,
0.01634550280869007,
0.044265080243349075,
0.028475284576416016,
-0.029395079240202904,
0.01878870651125908,
0.001980910310521722,
-0.02864774689078331,
-0.07687943428754807,
-0.022496625781059265,
0.032326921820640564,
-0.04457167908549309,
0.004740291740745306,
0.04227219149470329,
0.04767598211765289,
-0.015243667177855968,
-0.05672062188386917,
-0.07549974322319031,
0.035584524273872375,
0.03249938413500786,
0.0019437831360846758,
-0.0014874791959300637,
0.05511098355054855,
0.016747914254665375,
-0.003648036625236273,
-0.06319750100374222,
0.02527516894042492,
0.0034612035378813744,
-0.03656180575489998,
-0.0017545546870678663,
-0.02719140611588955,
-0.06377237290143967,
-0.0379989854991436,
-0.05392291396856308,
-0.04499325156211853,
0.01865456998348236,
0.023320607841014862,
0.0471777617931366,
-0.03541206568479538,
0.019794730469584465,
0.018252160400152206,
0.05108688399195671,
-0.025351818650960922,
-0.006165493279695511,
-0.025639254599809647,
-0.02571590431034565,
0.01569398306310177,
-0.0032839516643434763,
0.0167095884680748,
-0.057908687740564346,
0.029184293001890182,
-0.0018623430514708161,
0.024546999484300613,
-0.023876314982771873,
0.051700081676244736,
0.00792843196541071,
0.0020360019989311695,
0.08776366710662842,
-0.06664673238992691,
0.010769253596663475,
-0.0633891299366951,
-0.003698337823152542,
-0.03786484897136688,
0.00578224565833807,
-0.020158816128969193,
0.019267765805125237,
0.010980038903653622,
-0.026022501289844513,
-0.022285839542746544,
0.05074196308851242,
0.008139217272400856,
-0.0031282573472708464,
-0.03271016851067543,
-0.0024276331532746553,
0.017801843583583832,
-0.005691224709153175,
-0.002991725457832217,
-0.03414734825491905,
0.06588023900985718,
0.004620526917278767,
0.029030993580818176,
0.04418842867016792,
0.007799085695296526,
0.058138638734817505,
0.022592436522245407,
-0.03978108614683151,
-0.03665761649608612,
0.007861362770199776,
-0.028111200779676437,
-0.02742135524749756,
-0.006218189839273691,
-0.06511373817920685,
-0.04802090674638748,
0.02989330142736435,
-0.021270234137773514,
-0.00481933681294322,
0.011487842537462711,
0.011986063793301582,
0.07733933627605438,
-0.002879146486520767,
-0.0029462147504091263,
-0.005355882924050093,
0.0016311969375237823,
0.05062698572874069,
-0.014755026437342167,
0.018175510689616203,
-0.057257167994976044,
-0.002225230447947979,
0.021519344300031662,
-0.025198519229888916,
0.02345474436879158,
0.050358712673187256,
0.03866966813802719,
0.0638873502612114,
-0.025773391127586365,
-0.017236553132534027,
-0.053731292486190796,
-0.04756100848317146,
0.02119358442723751,
-0.038957104086875916,
-0.03606358543038368,
0.05821528658270836,
-0.07595964521169662,
0.035354577004909515,
-0.05112520977854729,
0.009006314910948277,
-0.032518547028303146,
0.010232706554234028,
-0.018089279532432556,
-0.045299846678972244,
0.04924729838967323,
-0.008608696050941944,
0.004361834842711687,
-0.04016433283686638,
-0.005614574998617172,
0.03159875050187111,
-0.05457443743944168,
0.0015856863465160131,
-0.06193278729915619,
-0.01375858299434185,
0.036140233278274536,
0.007391884922981262,
0.023761341348290443,
-0.008330841548740864,
0.031637076288461685,
-0.05376961827278137,
-0.012139363214373589,
-0.03608274832367897,
0.014189736917614937,
0.032863467931747437,
0.0013916672905907035,
0.01500413753092289,
-0.0038899616338312626,
-0.03395572304725647,
0.01099920179694891,
0.009241053834557533,
0.02356971800327301,
0.008522464893758297,
0.01662335731089115,
0.0034683893900364637,
-0.05219830200076103,
0.04457167908549309,
-0.006127168424427509,
0.03594861179590225,
-0.030295711010694504,
0.008091311901807785,
0.008407491259276867,
0.00029581913258880377,
0.05457443743944168,
-0.017926398664712906,
-0.018664151430130005,
0.05491935834288597,
0.02774711512029171,
0.004953473340719938,
0.04790592938661575,
-0.029241779819130898,
-0.03203948587179184,
-0.0733918845653534,
-0.01636466570198536,
0.013662771321833134,
0.06189446151256561,
-0.04073920473456383,
-0.0022803223691880703,
0.020676199346780777,
0.015933511778712273,
0.04713943600654602
]
|
31,048 | networkx.algorithms.tree.mst | random_spanning_tree |
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 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=None, *, multiplicative=True, seed=None, 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
]
|
31,049 | networkx.generators.trees | random_tree | Returns a uniformly random tree on `n` nodes.
.. deprecated:: 3.2
``random_tree`` is deprecated and will be removed in NX v3.4
Use ``random_labeled_tree`` instead.
Parameters
----------
n : int
A positive integer representing the number of nodes in the tree.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated.
Returns
-------
NetworkX graph
A tree, given as an undirected graph, whose nodes are numbers in
the set {0, …, *n* - 1}.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
Notes
-----
The current implementation of this function generates a uniformly
random Prüfer sequence then converts that to a tree via the
:func:`~networkx.from_prufer_sequence` function. Since there is a
bijection between Prüfer sequences of length *n* - 2 and trees on
*n* nodes, the tree is chosen uniformly at random from the set of
all trees on *n* nodes.
Examples
--------
>>> tree = nx.random_tree(n=10, seed=0)
>>> nx.write_network_text(tree, sources=[0])
╙── 0
├── 3
└── 4
├── 6
│ ├── 1
│ ├── 2
│ └── 7
│ └── 8
│ └── 5
└── 9
>>> tree = nx.random_tree(n=10, seed=0, create_using=nx.DiGraph)
>>> nx.write_network_text(tree)
╙── 0
├─╼ 3
└─╼ 4
├─╼ 6
│ ├─╼ 1
│ ├─╼ 2
│ └─╼ 7
│ └─╼ 8
│ └─╼ 5
└─╼ 9
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, seed=None, create_using=None, *, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,051 | networkx.generators.trees | random_unlabeled_rooted_forest | Returns a forest or list of forests selected at random.
Returns one or more (depending on `number_of_forests`)
unlabeled rooted forests with `n` nodes, and with no more than
`q` nodes per tree, drawn uniformly at random.
The "roots" graph attribute identifies the roots of the forest.
Parameters
----------
n : int
The number of nodes
q : int or None (default)
The maximum number of nodes per tree.
number_of_forests : int or None (default)
If not None, this number of forests is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_forests`
is specified) with nodes in the set {0, …, *n* - 1}.
The "roots" graph attribute is a set containing the roots
of the trees in the forest.
Notes
-----
This function implements the algorithm "Forest" of [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_forests` optional argument
to reuse the counting functions.
Raises
------
ValueError
If `n` is non-zero but `q` is zero.
References
----------
.. [1] Wilf, Herbert S. "The uniform selection of free trees."
Journal of Algorithms 2.2 (1981): 204-207.
https://doi.org/10.1016/0196-6774(81)90021-3
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, q=None, number_of_forests=None, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,052 | networkx.generators.trees | random_unlabeled_rooted_tree | Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, number_of_trees=None, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,053 | networkx.generators.trees | random_unlabeled_tree | Returns a tree or list of trees chosen randomly.
Returns one or more (depending on `number_of_trees`)
unlabeled trees with `n` nodes drawn uniformly at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if
`number_of_trees` is specified) with nodes in the set {0, …, *n* - 1}.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
Notes
-----
This function generates an unlabeled tree uniformly at random using
Wilf's algorithm "Free" of [1]_. The algorithm needs to
compute some counting functions that are relatively expensive:
in case several trees are needed, it is advisable to use the
`number_of_trees` optional argument to reuse the counting
functions.
References
----------
.. [1] Wilf, Herbert S. "The uniform selection of free trees."
Journal of Algorithms 2.2 (1981): 204-207.
https://doi.org/10.1016/0196-6774(81)90021-3
| def random_unlabeled_rooted_tree(n, *, number_of_trees=None, seed=None):
"""Returns a number of unlabeled rooted trees uniformly at random
Returns one or more (depending on `number_of_trees`)
unlabeled rooted trees with `n` nodes drawn uniformly
at random.
Parameters
----------
n : int
The number of nodes
number_of_trees : int or None (default)
If not None, this number of trees is generated and returned.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
:class:`networkx.Graph` or list of :class:`networkx.Graph`
A single `networkx.Graph` (or a list thereof, if `number_of_trees`
is specified) with nodes in the set {0, …, *n* - 1}.
The "root" graph attribute identifies the root of the tree.
Notes
-----
The trees are generated using the "RANRUT" algorithm from [1]_.
The algorithm needs to compute some counting functions
that are relatively expensive: in case several trees are needed,
it is advisable to use the `number_of_trees` optional argument
to reuse the counting functions.
Raises
------
NetworkXPointlessConcept
If `n` is zero (because the null graph is not a tree).
References
----------
.. [1] Nijenhuis, Albert, and Wilf, Herbert S.
"Combinatorial algorithms: for computers and calculators."
Academic Press, 1978.
https://doi.org/10.1016/C2013-0-11243-3
"""
if n == 0:
raise nx.NetworkXPointlessConcept("the null graph is not a tree")
cache_trees = [0, 1] # initial cache of number of rooted trees
if number_of_trees is None:
return _to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
return [
_to_nx(*_random_unlabeled_rooted_tree(n, cache_trees, seed), root=0)
for i in range(number_of_trees)
]
| (n, *, number_of_trees=None, seed=None, backend=None, **backend_kwargs) | [
-0.028837542980909348,
-0.008953820914030075,
0.02034701406955719,
-0.02989649586379528,
0.034207943826913834,
0.08100985735654831,
-0.03246823698282242,
-0.009535298682749271,
0.0718953013420105,
-0.012575059197843075,
-0.01075971219688654,
0.0822957307100296,
-0.011620111763477325,
0.03891649842262268,
-0.016167933121323586,
0.0021190866827964783,
-0.00043404047028161585,
0.04402216523885727,
0.023221313953399658,
-0.0017219794681295753,
-0.03335700184106827,
0.052645061165094376,
0.00600860919803381,
0.02516902983188629,
0.01925024203956127,
-0.01849384792149067,
0.008670172654092312,
-0.02656835876405239,
-0.031768571585416794,
0.007450486533343792,
-0.01446604635566473,
-0.016243573278188705,
-0.02855389565229416,
0.006878463085740805,
-0.015941014513373375,
-0.030898718163371086,
0.01730252616107464,
0.08100985735654831,
-0.04284975305199623,
-0.04284975305199623,
0.04988422244787216,
-0.05200212448835373,
0.003167402232065797,
-0.015184620395302773,
-0.020744120702147484,
-0.0030775803606957197,
0.06697873771190643,
0.03611784055829048,
-0.0972723439335823,
-0.03449159115552902,
-0.02131141722202301,
0.004621097818017006,
-0.020309194922447205,
0.011449922807514668,
-0.025263577699661255,
-0.026757458224892616,
-0.02242709882557392,
-0.03802773728966713,
0.07972398400306702,
-0.01798328012228012,
0.02995322458446026,
0.05253160372376442,
-0.0419042594730854,
-0.02182198315858841,
-0.025036659091711044,
-0.0224838275462389,
-0.10551704466342926,
0.030879808589816093,
-0.05578409880399704,
0.023183492943644524,
0.014853698201477528,
0.02308894321322441,
0.04527021571993828,
0.032146770507097244,
0.04156387969851494,
0.04489201679825783,
-0.005138755775988102,
0.013530007563531399,
0.0044367266818881035,
0.031938761472702026,
-0.028988821431994438,
-0.011005541309714317,
0.032732974737882614,
-0.0021982716862112284,
-0.01879640482366085,
-0.04795541614294052,
0.02182198315858841,
0.03899214044213295,
0.03774408996105194,
-0.07476960122585297,
-0.002413371345028281,
-0.023334771394729614,
0.00467310007661581,
-0.018919318914413452,
-0.0132747245952487,
0.0012078675208613276,
0.0510566346347332,
-0.03434031456708908,
0.011270279064774513,
-0.06073848158121109,
0.02751385234296322,
-0.029461568221449852,
-0.053023260086774826,
0.011194639839231968,
-0.04527021571993828,
0.02080085128545761,
-0.054120030254125595,
0.05298544093966484,
-0.0209521297365427,
0.016073385253548622,
-0.0863802582025528,
0.007852321490645409,
0.07310553640127182,
0.002102540573105216,
0.01968516781926155,
-0.01780363731086254,
-0.025187939405441284,
0.0008491710759699345,
-0.013775835745036602,
-0.014456590637564659,
0.030501611530780792,
0.008920728228986263,
-0.020611751824617386,
-0.0077908639796078205,
0.010428790003061295,
0.03048270009458065,
0.0447029173374176,
-0.040656208992004395,
-0.02463955245912075,
-0.019571708515286446,
0.03825465589761734,
0.051018811762332916,
0.028364796191453934,
0.04534585401415825,
-0.009852039627730846,
-0.023864248767495155,
-0.07499652355909348,
-0.00972912460565567,
0.03297880291938782,
-0.03048270009458065,
0.0025977424811571836,
-0.08781740814447403,
0.06939920037984848,
0.04492983594536781,
0.0393703356385231,
0.0503002367913723,
0.021954352036118507,
-0.018834223970770836,
-0.018682945519685745,
-0.016167933121323586,
0.028969911858439445,
-0.02448827400803566,
0.03182530030608177,
-0.000884627050254494,
-0.030009955167770386,
0.0102869663387537,
0.019013868644833565,
-0.08562386780977249,
-0.05801546201109886,
-0.025282489135861397,
-0.007346482016146183,
0.03129582479596138,
0.024828651919960976,
-0.053968753665685654,
-0.0630076676607132,
0.018607305362820625,
-0.019344791769981384,
-0.03553163632750511,
-0.01996881701052189,
0.0017184339230880141,
-0.05710779130458832,
0.0020588114857673645,
-0.04848489165306091,
-0.016177387908101082,
0.0017243432812392712,
-0.02441263385117054,
-0.05956607311964035,
0.005195484962314367,
-0.042887572199106216,
0.042660653591156006,
-0.02286202646791935,
-0.06928574293851852,
-0.012026673182845116,
-0.051321372389793396,
-0.041752979159355164,
0.04810669273138046,
0.022918755188584328,
0.021103408187627792,
-0.02352387085556984,
0.010428790003061295,
0.0396350733935833,
-0.019647348672151566,
0.0375928096473217,
0.0637640580534935,
0.044362541288137436,
-0.032071128487586975,
-0.02664399892091751,
-0.003415594110265374,
-0.03424576297402382,
0.03727134317159653,
0.07129018753767014,
0.045837510377168655,
0.03290316462516785,
-0.016659589484333992,
0.006301712244749069,
-0.01165793091058731,
-0.037838637828826904,
-0.0006334804347716272,
0.04712338000535965,
0.022672927007079124,
0.01770908758044243,
-0.002637926023453474,
0.02738148346543312,
0.08479183167219162,
-0.08222009241580963,
-0.023353682830929756,
-0.040883127599954605,
0.004940201994031668,
-0.03649603947997093,
-0.047161199152469635,
-0.050262417644262314,
0.02760840207338333,
0.028667353093624115,
-0.0036306940019130707,
-0.005866785533726215,
0.02649272046983242,
0.007762499153614044,
0.02293766476213932,
0.023032214492559433,
-0.047388117760419846,
0.06183525547385216,
-0.04443817958235741,
0.050791893154382706,
-0.0419042594730854,
-0.04670736566185951,
-0.06576851010322571,
0.06353714317083359,
-0.059074416756629944,
0.005157665349543095,
0.02966957725584507,
-0.06315894424915314,
-0.027097834274172783,
-0.00890181865543127,
-0.026209071278572083,
0.04239591583609581,
0.05979299172759056,
-0.052191223949193954,
0.010296421125531197,
-0.05400657281279564,
-0.03452941030263901,
-0.04863617196679115,
-0.033640649169683456,
0.012849252671003342,
-0.014834788627922535,
0.06803768873214722,
-0.02847825549542904,
-0.03084198758006096,
-0.029537208378314972,
0.010031682439148426,
0.05529244244098663,
-0.005663504358381033,
-0.026379261165857315,
-0.06474737823009491,
0.07280297577381134,
-0.02463955245912075,
-0.0528341606259346,
-0.03413230553269386,
0.044286902993917465,
0.02344823069870472,
-0.03159838169813156,
0.0571456104516983,
0.03212785720825195,
0.049014367163181305,
-0.02588760480284691,
-0.0012941438471898437,
-0.009516389109194279,
0.0036117839626967907,
0.04874962940812111,
-0.006140978541225195,
0.029858674854040146,
-0.013738016597926617,
0.013000531122088432,
0.00896800309419632,
0.027192384004592896,
-0.04489201679825783,
0.042055536061525345,
-0.05260724201798439,
-0.00793741550296545,
0.007478851359337568,
-0.023618420585989952,
0.06573069095611572,
-0.04296321049332619,
-0.01628139242529869,
-0.001478514983318746,
-0.02560395561158657,
-0.04247155413031578,
-0.03129582479596138,
-0.014645690098404884,
-0.014295857399702072,
0.031711842864751816,
0.0353047177195549,
-0.031995490193367004,
0.015468268655240536,
-0.02987758442759514,
0.08902764320373535,
0.0485227108001709,
0.01641376130282879,
-0.02671963721513748,
-0.03292207419872284,
0.038368113338947296,
-0.02989649586379528,
-0.0001672341168159619,
0.07181966304779053,
-0.048560529947280884,
0.007459941320121288,
-0.1112656369805336,
-0.0005513407522812486,
-0.08146369457244873,
0.04965730383992195,
-0.01539262942969799,
-0.038292475044727325,
0.015269715338945389,
-0.01981753669679165,
0.005048933904618025,
0.009497479535639286,
0.01172411534935236,
0.03373519703745842,
0.023221313953399658,
-0.049090005457401276,
0.03817901387810707,
-0.020460473373532295,
-0.031163455918431282,
0.0107975322753191,
0.03766844794154167,
-0.0899353101849556,
0.026209071278572083,
0.06266728788614273,
0.021216867491602898,
0.0009762217523530126,
-0.07280297577381134,
-0.031938761472702026,
0.03084198758006096,
-0.040051091462373734,
0.013161265291273594,
-0.015761371701955795,
0.07344590872526169,
0.05453604832291603,
0.014484955929219723,
-0.010050592944025993,
0.03989981487393379,
0.025206848978996277,
0.04999767988920212,
0.0022230909671634436,
0.015383174642920494,
0.022256910800933838,
0.05007331818342209,
-0.0000492321269121021,
0.06784859299659729,
-0.009053097106516361,
0.015279170125722885,
-0.015090071596205235,
-0.0642557144165039,
0.031617291271686554,
-0.04020237177610397,
0.031163455918431282,
-0.011449922807514668,
0.007337027229368687,
0.064028799533844,
-0.03313008323311806,
-0.040051091462373734,
-0.03685532510280609,
-0.09197758138179779,
-0.11466941237449646,
0.05374183505773544,
0.051321372389793396,
0.002562286565080285,
-0.040429290384054184,
-0.03343264013528824,
-0.0029877584893256426,
0.03891649842262268,
-0.023883158341050148,
-0.031995490193367004,
0.051170092076063156,
0.027570581063628197,
-0.009525843895971775,
-0.037630628794431686,
0.04859834909439087,
0.022105630487203598,
-0.02479083091020584,
-0.029385928064584732,
-0.017519989982247353,
-0.021576154977083206,
0.032732974737882614,
0.031106727197766304,
-0.022616198286414146,
0.04300102964043617,
0.09008659422397614,
0.006916282698512077,
-0.04402216523885727,
-0.020441563799977303,
0.034813061356544495,
0.052342504262924194,
-0.00024095302796922624,
0.008892363868653774,
0.006226072553545237,
0.0039805262349545956,
-0.001863803481683135,
-0.032014399766922,
-0.014588960446417332,
-0.04772849753499031,
0.01828583888709545,
0.045913148671388626,
0.033999934792518616,
-0.03952161595225334,
0.07030687481164932,
-0.01793600618839264,
0.020819760859012604,
0.0706094354391098,
0.0467451848089695,
-0.024507183581590652,
0.031938761472702026,
-0.05710779130458832,
0.031031087040901184,
0.08138805627822876,
0.07091198861598969,
0.022824205458164215,
0.04587532952427864,
-0.030671799555420876,
0.008377069607377052,
0.07435358315706253,
-0.012357596307992935,
-0.03850048407912254,
-0.010513884015381336,
0.03139037266373634,
0.041034404188394547,
-0.045988790690898895,
-0.03611784055829048,
-0.019165147095918655,
-0.06713001430034637,
0.018834223970770836,
0.004576187115162611,
0.06504993140697479,
0.05998208746314049,
-0.00436817854642868,
0.052645061165094376,
0.014050029218196869,
0.00819269847124815,
0.052418142557144165,
0.021122317761182785,
-0.05037587881088257,
0.013567827641963959,
-0.048560529947280884,
0.017075607553124428,
0.013662376441061497,
-0.04330359026789665,
0.0309932678937912,
-0.038216836750507355,
0.056124474853277206,
-0.05956607311964035,
0.025868693366646767,
0.03460505232214928,
0.029064461588859558,
-0.019874267280101776,
0.028383705765008926,
0.036288030445575714,
-0.06917228549718857,
0.03723352402448654,
-0.022805295884609222,
0.002481919713318348,
-0.04179079830646515,
0.040958765894174576,
0.020233554765582085,
-0.015761371701955795,
0.016177387908101082,
0.023334771394729614,
-0.00848580151796341,
-0.029404839500784874,
-0.02596324309706688,
-0.03978635370731354,
-0.06001991033554077,
0.005313671659678221,
0.009237468242645264,
0.05986863002181053,
-0.024620642885565758,
-0.06595760583877563,
-0.0538552924990654,
-0.0010624979622662067,
0.020914308726787567,
0.03751717135310173,
-0.04171516001224518,
-0.045383673161268234,
-0.0686049833893776,
-0.007946870289742947,
-0.019344791769981384,
-0.04844707250595093,
0.025547226890921593,
-0.01593155972659588,
-0.020139005035161972,
0.038651760667562485,
-0.004153078887611628,
0.029556117951869965,
0.003339954651892185,
0.012660154141485691,
0.021481605246663094,
0.02227582037448883,
0.044513821601867676,
0.028818633407354355,
-0.011421557515859604,
0.024223536252975464,
0.017255250364542007,
0.037914276123046875,
0.004826742690056562,
0.04549713432788849,
0.013955479487776756,
0.04795541614294052,
0.04549713432788849,
0.014626779593527317,
-0.022029992192983627,
0.034151215106248856,
0.027419302612543106,
0.013596192002296448,
0.042055536061525345,
0.023429321125149727,
0.021216867491602898,
0.012423780746757984,
-0.009015277959406376,
0.017482168972492218,
0.024696283042430878,
0.022446008399128914,
0.024828651919960976,
0.02352387085556984,
-0.018815314397215843,
-0.02168961428105831,
0.04935474693775177,
0.005370401311665773,
-0.022143451496958733,
-0.03634475916624069,
0.0029877584893256426,
0.011894304305315018,
-0.029272468760609627,
-0.008008327335119247,
-0.015997745096683502,
0.001395784318447113,
0.009398202411830425,
0.012338686734437943,
-0.013407093472778797,
0.03846266493201256,
-0.02403443679213524,
0.011431013233959675,
-0.016111204400658607,
0.03460505232214928,
-0.0002885231515392661,
0.028875362128019333,
-0.0215950645506382,
0.08486746996641159,
-0.06973958015441895,
-0.006429353728890419,
-0.027873139828443527,
-0.011355373077094555,
0.003871794557198882,
-0.02064957097172737,
0.03921905905008316,
0.04489201679825783,
-0.04296321049332619,
0.06550376862287521,
0.02515011839568615,
-0.05430912971496582,
0.017009422183036804,
-0.005980244372040033,
-0.04201771691441536,
-0.026984376832842827,
0.02301330491900444,
0.03626912087202072,
-0.03203330934047699,
-0.030747439712285995,
0.002167543163523078,
-0.050564978271722794,
-0.025566136464476585,
-0.010939355939626694,
-0.02329695224761963,
0.0031414011027663946,
0.0010624979622662067,
0.026454899460077286,
-0.003968707751482725,
0.028081148862838745,
0.052191223949193954,
-0.02662508934736252,
0.04133696109056473,
0.0013615102507174015,
0.017283616587519646,
0.005620956886559725,
-0.023202402517199516,
0.06788641214370728,
0.019288061186671257,
0.0023519142996519804,
-0.004299630410969257,
-0.013775835745036602,
-0.01567627675831318,
-0.011033905670046806,
-0.027305843308568,
0.04980858042836189,
0.0609654001891613,
-0.01859785057604313,
0.05748598650097847,
0.012348141521215439,
0.0013556008925661445,
0.005904605146497488,
-0.06399098038673401,
0.007823956198990345,
0.009124009869992733,
0.005356219131499529,
0.01127973385155201,
-0.010636798106133938,
-0.05748598650097847,
0.015383174642920494,
0.003179220948368311,
-0.03167402371764183,
0.015780281275510788,
-0.00865126308053732,
-0.0500354990363121,
-0.0011759571498259902,
-0.0007108927238732576,
-0.010977176018059254,
-0.010192416608333588,
-0.017132336273789406,
-0.05169956758618355,
-0.0031366737093776464,
-0.018040010705590248,
-0.052191223949193954,
0.027627311646938324,
0.026681818068027496,
-0.030596159398555756,
-0.011714660562574863,
-0.03840593248605728,
-0.035985469818115234,
-0.012849252671003342,
0.036514949053525925,
-0.013492188416421413,
-0.01798328012228012,
0.05718342959880829,
-0.02352387085556984,
-0.02093322016298771,
-0.02433699555695057,
-0.033281359821558,
-0.000662436184938997,
-0.07268951833248138,
-0.040051091462373734,
-0.003711060853675008,
-0.0016156114870682359,
-0.025660686194896698,
-0.022824205458164215,
0.009672395884990692,
0.042509373277425766,
-0.0017586173489689827,
0.0017467987490817904,
-0.007020287215709686,
-0.02278638631105423,
-0.0034368678461760283,
0.006604270078241825,
-0.006665727123618126,
-0.002179361879825592,
0.01885313354432583,
0.010041138157248497,
0.06346150487661362,
-0.017340345308184624,
0.02255946770310402,
0.01976080797612667,
-0.026171252131462097,
-0.022067811340093613,
0.04194207862019539,
-0.02819460816681385,
-0.04977076128125191,
0.04682082310318947,
-0.028837542980909348,
-0.024904290214180946,
0.003269042819738388,
-0.0335271880030632,
0.0563892163336277,
0.01047606486827135,
-0.021424876525998116,
0.049392566084861755,
0.022691836580634117,
-0.022918755188584328,
-0.02153833582997322,
-0.008117059245705605,
0.03212785720825195,
-0.044513821601867676,
-0.005148210562765598,
0.019184056669473648,
0.011847029440104961,
-0.009691305458545685,
0.0011824574321508408,
0.04587532952427864,
0.07023123651742935,
-0.052871979773044586,
0.017737451940774918,
-0.012887072749435902,
0.014059484004974365,
-0.0475015789270401,
-0.0013674194924533367,
0.06486083567142487,
-0.039256878197193146,
-0.03795209899544716,
0.006883190479129553,
-0.05060279741883278,
0.03986199200153351,
-0.04557277262210846,
0.04780413582921028,
-0.02908337116241455,
0.03899214044213295,
-0.027173474431037903,
0.0006695273914374411,
-0.018682945519685745,
-0.01846548169851303,
-0.04171516001224518,
-0.030615070834755898,
0.024696283042430878,
0.05979299172759056,
-0.08630461990833282,
-0.013454368337988853,
0.005181302782148123,
-0.022162361070513725,
-0.00010703278530854732,
0.03876522183418274,
0.004817287903279066,
0.009459659457206726,
0.06815115362405777,
-0.07541253417730331,
-0.01811564899981022,
-0.0005977289984002709,
0.01869240030646324,
0.052077766507864,
0.016810869798064232,
-0.057296887040138245,
-0.018626216799020767,
-0.02581196464598179,
0.015212985686957836,
0.02900773100554943,
-0.03055834025144577,
-0.03634475916624069,
-0.00435636006295681,
0.015288624912500381,
-0.05355273559689522,
0.005370401311665773,
0.019344791769981384,
-0.02507448010146618,
0.040278010070323944,
0.012631788849830627,
0.0495438426733017,
-0.013709651306271553,
0.03719570115208626,
0.02832697704434395,
-0.009459659457206726,
0.004394179675728083,
0.024961020797491074,
0.020082276314496994,
-0.002246728166937828,
-0.017699632793664932,
0.0009644030942581594,
-0.042887572199106216,
-0.01165793091058731,
-0.027797499671578407,
-0.059225693345069885,
-0.0019016232108697295,
0.00029517116490751505,
0.011780845001339912,
0.02760840207338333,
0.0051718479953706264
]
|
31,057 | networkx.readwrite.gexf | read_gexf | Read graph in GEXF format from path.
"GEXF (Graph Exchange XML Format) is a language for describing
complex networks structures, their associated data and dynamics" [1]_.
Parameters
----------
path : file or string
File or file name to read.
File names ending in .gz or .bz2 will be decompressed.
node_type: Python type (default: None)
Convert node ids to this type if not None.
relabel : bool (default: False)
If True relabel the nodes to use the GEXF node "label" attribute
instead of the node "id" attribute as the NetworkX node label.
version : string (default: 1.2draft)
Version of GEFX File Format (see http://gexf.net/schema.html)
Supported values: "1.1draft", "1.2draft"
Returns
-------
graph: NetworkX graph
If no parallel edges are found a Graph or DiGraph is returned.
Otherwise a MultiGraph or MultiDiGraph is returned.
Notes
-----
This implementation does not support mixed graphs (directed and undirected
edges together).
References
----------
.. [1] GEXF File Format, http://gexf.net/
| def add_node(self, G, node_xml, node_attr, node_pid=None):
# add a single node with attributes to the graph
# get attributes and subattributues for node
data = self.decode_attr_elements(node_attr, node_xml)
data = self.add_parents(data, node_xml) # add any parents
if self.VERSION == "1.1":
data = self.add_slices(data, node_xml) # add slices
else:
data = self.add_spells(data, node_xml) # add spells
data = self.add_viz(data, node_xml) # add viz
data = self.add_start_end(data, node_xml) # add start/end
# find the node id and cast it to the appropriate type
node_id = node_xml.get("id")
if self.node_type is not None:
node_id = self.node_type(node_id)
# every node should have a label
node_label = node_xml.get("label")
data["label"] = node_label
# parent node id
node_pid = node_xml.get("pid", node_pid)
if node_pid is not None:
data["pid"] = node_pid
# check for subnodes, recursive
subnodes = node_xml.find(f"{{{self.NS_GEXF}}}nodes")
if subnodes is not None:
for node_xml in subnodes.findall(f"{{{self.NS_GEXF}}}node"):
self.add_node(G, node_xml, node_attr, node_pid=node_id)
G.add_node(node_id, **data)
| (path, node_type=None, relabel=False, version='1.2draft', *, backend=None, **backend_kwargs) | [
0.013808805495500565,
0.03107464127242565,
0.0026386405806988478,
0.03458961099386215,
0.006329840514808893,
0.02161126397550106,
-0.027057534083724022,
0.0726555585861206,
0.06836806982755661,
-0.0656256228685379,
0.021649889647960663,
0.009419922716915607,
0.06682302802801132,
0.05090910568833351,
-0.018328052014112473,
-0.014079187996685505,
-0.02489447593688965,
-0.020066222175955772,
-0.044535811990499496,
0.014079187996685505,
-0.01702442206442356,
0.019023319706320763,
0.0030924964230507612,
0.0006536248256452382,
0.04530833289027214,
0.008251485414803028,
-0.0035173827782273293,
0.03553594648838043,
0.01977652683854103,
-0.010158645920455456,
0.018279768526554108,
-0.09586980938911438,
-0.06342393904924393,
-0.021031873300671577,
-0.004565113689750433,
0.05809354782104492,
-0.03793076053261757,
-0.026729213073849678,
-0.04341565817594528,
0.007570701651275158,
0.055891864001750946,
-0.02518417127430439,
0.0027762458194047213,
-0.013248728588223457,
-0.018714310601353645,
-0.0050068991258740425,
0.038239769637584686,
0.07806320488452911,
-0.0674796774983406,
-0.06276729702949524,
-0.004463720601052046,
-0.03107464127242565,
0.00026781720225699246,
0.050484221428632736,
-0.035072434693574905,
-0.005084151402115822,
-0.019815152511000633,
0.03345014154911041,
-0.009463377296924591,
0.05836392939090729,
0.04302939772605896,
0.027598299086093903,
-0.02126362919807434,
-0.025068294256925583,
-0.04071183502674103,
0.03341151401400566,
-0.030669067054986954,
-0.06825219839811325,
-0.01321010198444128,
0.028911583125591278,
0.022576915100216866,
-0.011220861226320267,
0.042759016156196594,
0.03242655098438263,
0.07551389187574387,
0.02477859891951084,
0.0036501598078757524,
0.02066492661833763,
0.01219616923481226,
0.03814320266246796,
-0.009434407576918602,
0.005702167749404907,
-0.022982487455010414,
0.006793352775275707,
0.029954485595226288,
0.04229550436139107,
-0.05987034738063812,
0.0017804185627028346,
0.012176855467259884,
-0.02607257105410099,
-0.03391365334391594,
0.020549047738313675,
0.010332463309168816,
0.02489447593688965,
0.07640228420495987,
-0.036462973803281784,
0.015141403302550316,
-0.02721203863620758,
0.04762589558959007,
0.05542835220694542,
-0.04851429536938667,
0.03852946311235428,
-0.06887020915746689,
-0.0389157235622406,
-0.009463377296924591,
-0.08659955859184265,
-0.044690318405628204,
0.034821365028619766,
-0.01856946386396885,
0.03341151401400566,
-0.038741908967494965,
-0.049209561198949814,
0.0620720311999321,
0.007208582945168018,
-0.03426128998398781,
0.02562837116420269,
-0.0013772593811154366,
0.025802187621593475,
-0.0004743759345728904,
-0.020838743075728416,
0.012128573842346668,
-0.023368747904896736,
0.005509037524461746,
0.00817906204611063,
-0.032986629754304886,
-0.012988002970814705,
0.017700377851724625,
0.011858191341161728,
-0.013895714655518532,
-0.04376329109072685,
0.03959168121218681,
0.021128438413143158,
-0.023079052567481995,
0.01194509956985712,
0.01442682184278965,
-0.045037951320409775,
-0.0008823633543215692,
0.023021113127470016,
0.008401161059737206,
0.03126776963472366,
0.0057504503056406975,
-0.07972412556409836,
0.05863431468605995,
0.012669337913393974,
-0.06307630985975266,
0.0010060874046757817,
-0.09502003341913223,
-0.000006219205715751741,
-0.046428486704826355,
-0.029066087678074837,
-0.024373024702072144,
-0.03008967638015747,
0.01496758684515953,
-0.03372052311897278,
-0.005528350360691547,
0.026188448071479797,
-0.0419478677213192,
0.0033942623995244503,
-0.007686580065637827,
0.004215065389871597,
-0.06272867321968079,
-0.02107049897313118,
0.08157817274332047,
0.008980551734566689,
0.030823571607470512,
-0.015025525353848934,
-0.0013482898939400911,
-0.054462701082229614,
-0.024469589814543724,
0.02587944082915783,
0.022615540772676468,
-0.07269418984651566,
-0.010235898196697235,
0.00871499814093113,
-0.019911717623472214,
-0.026265699416399002,
0.05314941704273224,
-0.03217548131942749,
0.004367155488580465,
0.03733205795288086,
0.0029307499062269926,
0.013403232209384441,
0.040132444351911545,
0.03337289020419121,
-0.00424644909799099,
-0.018376333639025688,
0.016618849709630013,
0.02319493144750595,
0.01724652200937271,
0.01180025190114975,
0.02676783874630928,
0.004849981050938368,
-0.014706861227750778,
0.03063044138252735,
0.047123756259679794,
0.02062629908323288,
0.02369706891477108,
-0.007213410921394825,
-0.016416063532233238,
0.09579255431890488,
0.06832944601774216,
0.024566154927015305,
0.015131747350096703,
0.015991175547242165,
0.00028577225748449564,
-0.00890812836587429,
-0.021649889647960663,
0.02429577335715294,
-0.05318804457783699,
-0.056780263781547546,
0.027482420206069946,
0.025415927171707153,
0.043647412210702896,
0.02616913616657257,
-0.04020969569683075,
-0.009579255245625973,
-0.11325152218341827,
0.041020844131708145,
-0.07617053389549255,
-0.013673614710569382,
0.01325838454067707,
-0.009598568081855774,
-0.0366947278380394,
-0.06323081254959106,
0.009820668026804924,
-0.03370121121406555,
0.04353153705596924,
-0.012852811254560947,
-0.0013410474639385939,
0.012814185582101345,
0.0005655091954395175,
0.06153126433491707,
0.03182784840464592,
-0.011269143782556057,
0.007440338842570782,
0.0006904402980580926,
0.050136588513851166,
0.04812803491950035,
-0.011858191341161728,
-0.0046254671178758144,
-0.01085391454398632,
-0.016309840604662895,
-0.07389159500598907,
-0.019988970831036568,
0.04237275570631027,
0.01348048448562622,
0.046119481325149536,
0.052376896142959595,
-0.026845090091228485,
0.018260454759001732,
-0.03748656064271927,
-0.021340882405638695,
-0.011317426338791847,
0.04264313727617264,
0.018965380266308784,
0.021051187068223953,
-0.059715840965509415,
-0.04743276536464691,
0.011433305218815804,
0.0028052153065800667,
0.028583262115716934,
0.034879304468631744,
0.01474548690021038,
0.02869914099574089,
0.03327632322907448,
-0.0022873852867633104,
0.033643271774053574,
-0.015025525353848934,
-0.04561734199523926,
-0.00542695727199316,
0.08876261860132217,
0.017391370609402657,
0.03686854615807533,
-0.010824944823980331,
0.041716113686561584,
-0.05573736131191254,
-0.021476073190569878,
0.03300594165921211,
0.0015486624324694276,
-0.01581735908985138,
-0.06110638007521629,
-0.032387927174568176,
0.01635812409222126,
0.06558699905872345,
-0.08258245140314102,
-0.08312321454286575,
-0.0011479173554107547,
0.10212722420692444,
-0.02161126397550106,
-0.048012156039476395,
-0.05040697008371353,
0.03679129481315613,
-0.06431233882904053,
0.05280178412795067,
0.006542284041643143,
0.008154920302331448,
0.0038022499065846205,
0.050484221428632736,
-0.04357016086578369,
0.02651676908135414,
0.07277143746614456,
-0.000032138064852915704,
0.022171340882778168,
-0.06701616197824478,
-0.028679827228188515,
0.036018773913383484,
0.025705622509121895,
-0.00597254978492856,
-0.015247625298798084,
0.0009149540564976633,
-0.0787971019744873,
0.02616913616657257,
0.001703166519291699,
0.043454281985759735,
-0.032387927174568176,
0.03261968120932579,
0.04878467693924904,
-0.05932958051562309,
0.04217962548136711,
0.009748244658112526,
-0.035671137273311615,
-0.04214099794626236,
-0.03793076053261757,
0.031943727284669876,
-0.007976274937391281,
0.014349570497870445,
0.03881916031241417,
0.061647143214941025,
0.024469589814543724,
0.03628915548324585,
-0.03509174659848213,
0.02562837116420269,
-0.01724652200937271,
0.04237275570631027,
-0.08837635815143585,
0.004318872932344675,
0.0007266522152349353,
-0.05662576109170914,
-0.0025034495629370213,
0.00682715093716979,
-0.0032059603836387396,
0.023175617679953575,
-0.062187906354665756,
0.013045941479504108,
0.046428486704826355,
-0.02354256436228752,
0.018212173134088516,
-0.05303353816270828,
-0.021553324535489082,
0.01841495931148529,
-0.04063458368182182,
0.025995317846536636,
-0.03397159278392792,
-0.008019729517400265,
0.01939992420375347,
-0.019158510491251945,
0.022538287565112114,
-0.02591806650161743,
-0.05338117480278015,
0.028776392340660095,
-0.036559537053108215,
-0.003966410644352436,
0.013026628643274307,
0.021051187068223953,
-0.0742778554558754,
-0.021591950207948685,
0.049248188734054565,
0.04859154671430588,
0.0323299877345562,
-0.009888263419270515,
0.053419798612594604,
-0.06628226488828659,
-0.0381045788526535,
0.021997524425387383,
-0.02334943413734436,
0.03093945048749447,
0.027057534083724022,
0.010293836705386639,
0.009115743450820446,
-0.06531661748886108,
-0.02572493627667427,
-0.031209832057356834,
-0.027250664308667183,
0.0077783167362213135,
-0.020297978073358536,
-0.0524541474878788,
0.1172686293721199,
0.02676783874630928,
0.021147752180695534,
-0.0018600847106426954,
-0.012524490244686604,
0.026342952623963356,
0.01209960412234068,
0.007058906834572554,
-0.056432630866765976,
-0.059908971190452576,
0.05813217535614967,
-0.04051870480179787,
-0.06438959389925003,
-0.032387927174568176,
0.0022246178705245256,
-0.014117813669145107,
-0.019477175548672676,
0.04163885861635208,
0.03265830874443054,
-0.012485864572227001,
-0.049402691423892975,
-0.0463898628950119,
0.02499104104936123,
0.031847160309553146,
0.03520762547850609,
0.00831908080726862,
-0.007894194684922695,
-0.0038915725890547037,
0.031750597059726715,
0.011249830946326256,
0.031345024704933167,
0.026709899306297302,
-0.015402129851281643,
-0.04384054243564606,
-0.039939314126968384,
0.026632647961378098,
0.034531671553850174,
0.04526970535516739,
0.006209134124219418,
-0.002247552154585719,
0.016087740659713745,
0.0315188392996788,
-0.06195615231990814,
0.04704650491476059,
0.010892540216445923,
0.02856394834816456,
0.03389434143900871,
-0.02419920824468136,
0.03211754560470581,
-0.03738999739289284,
0.007174785248935223,
-0.07400747388601303,
0.009699962101876736,
0.029181964695453644,
0.01569182425737381,
-0.013972966000437737,
0.011568496003746986,
-0.0001231959176948294,
-0.0515657514333725,
-0.007445167284458876,
-0.06442821770906448,
-0.04492207244038582,
0.06411921232938766,
-0.030360059812664986,
0.0725783109664917,
0.03781488165259361,
0.04496069997549057,
0.023021113127470016,
-0.04561734199523926,
-0.036211904138326645,
-0.08428199589252472,
-0.07906748354434967,
0.0032494147308170795,
-0.0183859895914793,
-0.07389159500598907,
0.03959168121218681,
-0.030842885375022888,
-0.015431098639965057,
-0.022731417790055275,
0.004504760727286339,
0.041175346821546555,
-0.02835150621831417,
-0.041368477046489716,
-0.028641201555728912,
0.0032445865217596292,
-0.02122500352561474,
-0.009352327324450016,
-0.08791284263134003,
0.031943727284669876,
-0.011259487830102444,
-0.02439233846962452,
-0.034280601888895035,
-0.035439383238554,
-0.04565596580505371,
0.0055573200806975365,
-0.007087876554578543,
0.03623121604323387,
0.059908971190452576,
-0.026883717626333237,
0.03441579267382622,
0.03540075570344925,
0.011269143782556057,
-0.02939440868794918,
0.011694030836224556,
-0.013663957826793194,
-0.07107189297676086,
-0.03468617424368858,
0.055003467947244644,
0.007005796302109957,
0.013316323980689049,
0.02236447110772133,
-0.0778314471244812,
-0.026632647961378098,
-0.024508215487003326,
-0.02914333902299404,
-0.002364637330174446,
0.007725206203758717,
0.011442961171269417,
-0.0019168166909366846,
0.018202517181634903,
-0.05932958051562309,
0.06717066466808319,
-0.0067595550790429115,
0.02489447593688965,
0.0010006555821746588,
-0.018839845433831215,
0.05631675198674202,
0.00831908080726862,
0.016589879989624023,
0.014533043839037418,
-0.008203202858567238,
0.04217962548136711,
-0.02300180122256279,
-0.01983446627855301,
0.024527529254555702,
0.011742313392460346,
0.056432630866765976,
-0.008565322495996952,
-0.006914059165865183,
0.060604240745306015,
-0.029819294810295105,
-0.03607671335339546,
-0.0690247118473053,
0.026787152513861656,
-0.00936681218445301,
0.009115743450820446,
0.027057534083724022,
-0.009603396989405155,
-0.023426687344908714,
0.026613334193825722,
0.06002485007047653,
0.052724529057741165,
0.0029693760443478823,
-0.06153126433491707,
0.027115473523736,
-0.03404884412884712,
0.014320600777864456,
0.01452338695526123,
-0.0033266667742282152,
-0.015585603192448616,
0.07153540849685669,
-0.044188179075717926,
0.03306388109922409,
-0.03702304884791374,
0.013760522939264774,
-0.03225273638963699,
-0.03059181571006775,
0.05542835220694542,
0.07284869253635406,
0.019506145268678665,
0.02483653649687767,
-0.04132985323667526,
0.018656373023986816,
-0.02572493627667427,
-0.039784811437129974,
-0.038297709077596664,
-0.005904954392462969,
0.0035825641825795174,
0.017854882404208183,
0.013074911199510098,
-0.00028697933885268867,
-0.0039060572162270546,
0.035265564918518066,
-0.00048765362589620054,
0.018849503248929977,
0.025609057396650314,
-0.03401022031903267,
-0.06021798029541969,
-0.02866051346063614,
-0.043454281985759735,
-0.015546976588666439,
0.030108990147709846,
-0.02939440868794918,
-0.046621616929769516,
-0.07466411590576172,
0.020587673410773277,
0.004903091583400965,
0.04422680288553238,
-0.012901093810796738,
0.04132985323667526,
-0.004907920025289059,
0.04245000705122948,
0.05129536613821983,
-0.025705622509121895,
-0.0020966692827641964,
-0.06454409658908844,
0.07910610735416412,
-0.022731417790055275,
-0.021534010767936707,
0.016725070774555206,
0.01316181942820549,
-0.02271210588514805,
-0.02076149173080921,
-0.020104847848415375,
-0.01898469403386116,
-0.017961103469133377,
0.04805077984929085,
0.0076914080418646336,
-0.04546283558011055,
0.03615396469831467,
-0.015827015042304993,
0.005142090376466513,
-0.061840273439884186,
-0.015556633472442627,
0.0240447036921978,
-0.028332192450761795,
-0.026053257286548615,
0.01645468920469284,
-0.025551117956638336,
-0.04797352850437164,
-0.03970756009221077,
0.021649889647960663,
0.05670301243662834,
0.0008292525890283287,
-0.02300180122256279,
-0.018965380266308784,
-0.019245419651269913,
0.028641201555728912,
-0.00370568479411304,
-0.020433170720934868,
0.03128708526492119,
-0.04163885861635208,
-0.028872957453131676,
-0.008072840049862862,
-0.006286386400461197,
-0.0035753219854086637,
-0.0042681763879954815,
-0.046621616929769516,
0.011423648335039616,
-0.017854882404208183,
0.04163885861635208,
0.03441579267382622,
0.012350672855973244,
0.02993517369031906,
-0.022267905995249748,
0.01301697175949812,
-0.0297420434653759,
-0.02786868065595627,
0.01601048931479454,
0.006996139883995056,
0.05121811479330063,
0.01170368678867817,
-0.007319632451981306,
-0.03731274604797363,
0.017227210104465485,
-0.013306667096912861,
-0.02002759650349617,
-0.002749690553173423,
0.04237275570631027,
0.03754450008273125,
-0.05909782648086548,
0.0076672667637467384,
-0.027694864198565483,
0.0004414834547787905,
0.01224445179104805,
-0.008927441202104092,
0.05106361210346222,
-0.0028848815709352493,
-0.008579806424677372,
-0.015431098639965057,
0.03881916031241417,
-0.037699006497859955,
0.011491243727505207,
0.014291631057858467,
-0.053806059062480927,
-0.03733205795288086,
-0.015015869401395321,
0.012186512351036072,
0.0009161611669696867,
-0.05496484041213989,
0.03229136019945145,
0.023117678239941597,
0.0030755975749343634,
0.054501328617334366,
-0.012485864572227001,
0.05229964479804039,
0.025319362059235573,
-0.08204168826341629,
0.025589745491743088,
0.07304181903600693,
0.009077116847038269,
-0.042102374136447906,
0.023272182792425156,
0.0026531254407018423,
0.012736933305859566,
-0.03252311795949936,
0.03837496042251587,
0.008628088980913162,
0.03990069031715393,
-0.047316886484622955,
0.024160582572221756,
0.01578838936984539,
0.0088598458096385,
-0.00003408068005228415,
-0.010293836705386639,
-0.005658713169395924,
-0.03895435109734535,
0.0366947278380394,
0.015363503247499466,
-0.030456624925136566,
-0.04967307299375534,
0.05716652423143387,
-0.012823841534554958,
0.019728245213627815,
-0.018105952069163322,
0.034628234803676605,
0.01720789633691311,
0.03345014154911041,
-0.012775558978319168,
0.012794872745871544,
0.016213275492191315,
-0.00298627489246428,
-0.054501328617334366,
-0.026883717626333237,
-0.021244317293167114,
0.009844809770584106,
0.04132985323667526,
0.04654436558485031,
0.043454281985759735,
-0.03261968120932579,
0.011385022662580013,
-0.08335497230291367,
-0.011829221621155739,
-0.02920127846300602,
0.002043558284640312,
0.04040282592177391,
0.01901366375386715,
0.002880053361877799,
0.01487102173268795,
-0.029471660032868385,
-0.04812803491950035,
0.0420251190662384,
-0.00457235611975193,
-0.028216315433382988,
-0.027791429311037064,
0.015373160131275654,
0.00011874486517626792,
-0.03466686233878136,
0.007932821288704872,
0.014262661337852478,
0.024469589814543724,
0.0489005520939827,
-0.04357016086578369,
0.05106361210346222,
0.04063458368182182,
0.022596227005124092,
0.011375365778803825,
0.108461894094944,
0.05144987255334854,
0.01911022886633873,
0.02309836633503437,
0.014233691617846489,
0.0205297339707613,
-0.07875847816467285,
-0.014021248556673527,
-0.02081942930817604,
-0.003452201373875141,
-0.02205546386539936,
0.023716382682323456,
0.03416472300887108,
0.012862468138337135,
0.0909256711602211
]
|
31,058 | networkx.readwrite.gml | read_gml | Read graph in GML format from `path`.
Parameters
----------
path : filename or filehandle
The filename or filehandle to read from.
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, parse_gml
literal_destringizer
Notes
-----
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.path_graph(4)
>>> nx.write_gml(G, "test.gml")
GML values are interpreted as strings by default:
>>> H = nx.read_gml("test.gml")
>>> H.nodes
NodeView(('0', '1', '2', '3'))
When a `destringizer` is provided, GML values are converted to the provided type.
For example, integer nodes can be recovered as shown below:
>>> J = nx.read_gml("test.gml", destringizer=int)
>>> J.nodes
NodeView((0, 1, 2, 3))
| 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 "]"
| (path, label='label', destringizer=None, *, backend=None, **backend_kwargs) | [
0.042373087257146835,
0.025368379428982735,
-0.01866890862584114,
-0.037871215492486954,
0.03228120878338814,
-0.007163526955991983,
-0.057692259550094604,
-0.0013088238192722201,
0.11487246304750443,
-0.07390753924846649,
-0.011393368244171143,
0.05363843962550163,
-0.03070235438644886,
0.08807457983493805,
0.009009081870317459,
0.02244536206126213,
-0.021143872290849686,
-0.023896202445030212,
0.058887071907520294,
0.010886640287935734,
-0.015831233933568,
-0.012214800342917442,
0.0356522798538208,
0.010118548758327961,
0.030809033662080765,
-0.0619167685508728,
0.018188850954174995,
0.004637890495359898,
-0.045914847403764725,
0.025411050766706467,
-0.015553867444396019,
-0.12494300305843353,
-0.007622248493134975,
-0.054918594658374786,
-0.006038058549165726,
-0.026563189923763275,
-0.07971090823411942,
0.022061316296458244,
-0.10198558121919632,
-0.06187409535050392,
0.03848995640873909,
-0.01770879328250885,
-0.03688976168632507,
-0.03584430366754532,
-0.010427919216454029,
0.05457722023129463,
-0.0211118683218956,
0.07023777067661285,
-0.05713752657175064,
-0.045232098549604416,
0.016076596453785896,
-0.011841421946883202,
-0.04907255992293358,
0.0485604964196682,
-0.044976066797971725,
-0.005728688091039658,
-0.020493127405643463,
0.008929071947932243,
0.07190196961164474,
0.031235750764608383,
-0.004528543911874294,
0.031065063551068306,
-0.005632676184177399,
-0.009339787997305393,
-0.01156405545771122,
0.0013935007154941559,
-0.04369591549038887,
-0.06311158090829849,
-0.03302796557545662,
-0.007984958589076996,
-0.02692589908838272,
-0.0023669509682804346,
0.017292743548750877,
0.010678615421056747,
-0.000306370115140453,
0.01534050889313221,
-0.035054877400398254,
0.04399461671710014,
0.015308504924178123,
-0.01450840849429369,
-0.00227493979036808,
0.024621622636914253,
0.0010281234281137586,
-0.09293916076421738,
0.02852609194815159,
0.008294329047203064,
0.04055953770875931,
0.041882362216711044,
-0.007163526955991983,
0.014849782921373844,
-0.03923671320080757,
0.011777414008975029,
0.026968572288751602,
0.0433972105383873,
-0.02361883595585823,
-0.018914271146059036,
-0.02015175297856331,
-0.04437866061925888,
0.03266525641083717,
-0.0015095146372914314,
0.014209706336259842,
0.010353242978453636,
-0.04179701954126358,
-0.0035417587496340275,
-0.0443359911441803,
-0.06460509449243546,
-0.028675442561507225,
-0.0007094184984453022,
0.04514675587415695,
-0.044250648468732834,
-0.08218587189912796,
-0.0647331103682518,
0.06981104612350464,
-0.023533493280410767,
0.060807302594184875,
0.01392167154699564,
-0.01616194099187851,
-0.0036297691985964775,
0.02406688965857029,
-0.016588658094406128,
-0.011756078340113163,
-0.0219333004206419,
-0.06016722694039345,
0.04395194351673126,
0.0019095626194030046,
0.015020470134913921,
0.05590004473924637,
0.007350216154009104,
0.042373087257146835,
-0.025859104469418526,
0.040730223059654236,
0.025453723967075348,
0.04256511107087135,
0.04582950472831726,
0.027822008356451988,
-0.03889533877372742,
-0.0485604964196682,
-0.004987265449017286,
0.07006707787513733,
0.07322479039430618,
0.03887400031089783,
-0.08026564121246338,
0.02598712034523487,
0.010075876489281654,
-0.002481631236150861,
-0.04770706221461296,
0.0010174554772675037,
0.01087063830345869,
-0.004096491727977991,
-0.05965516343712807,
0.046853628009557724,
0.006379432510584593,
0.03490552306175232,
-0.01960768736898899,
-0.007382219657301903,
0.02713925950229168,
-0.050438057631254196,
0.04348255321383476,
0.007222200743854046,
0.0012068116338923573,
0.0004230508056934923,
0.0027136593125760555,
0.034606821835041046,
0.0457441583275795,
0.015703219920396805,
0.01803950034081936,
0.04651225358247757,
-0.05790562182664871,
0.011158673092722893,
0.010523930191993713,
-0.0012194797163829207,
-0.06810417771339417,
-0.08824526518583298,
-0.01052926480770111,
0.0448053814470768,
0.007707592099905014,
0.030296972021460533,
0.1036924496293068,
-0.0093824602663517,
0.059868521988391876,
-0.01510581374168396,
-0.026477845385670662,
-0.03699644282460213,
-0.007382219657301903,
-0.023298798128962517,
-0.017751464620232582,
0.053041037172079086,
-0.00554733257740736,
0.0431625172495842,
-0.024877654388546944,
0.004837914370000362,
-0.04147697985172272,
-0.018892934545874596,
0.05743623152375221,
0.025624411180615425,
-0.0051579526625573635,
-0.006432772614061832,
-0.0047765737399458885,
0.013761652633547783,
0.08269792795181274,
-0.004667227156460285,
-0.028654107823967934,
0.028846129775047302,
-0.036228351294994354,
-0.053467754274606705,
-0.01428438164293766,
-0.03887400031089783,
-0.010801296681165695,
-0.04702431336045265,
0.002877678954973817,
-0.0011834754841402173,
-0.01414569839835167,
0.012438827194273472,
0.045872174203395844,
-0.01608726568520069,
-0.031491782516241074,
-0.010454588569700718,
0.052059583365917206,
-0.08141777664422989,
-0.05504661053419113,
0.010561267845332623,
-0.016994040459394455,
0.019789043813943863,
-0.033902738243341446,
0.0494992770254612,
-0.05005401000380516,
0.05991119518876076,
-0.03821258991956711,
-0.007792935706675053,
0.0021749278530478477,
0.10633810609579086,
0.011126669123768806,
0.05641210824251175,
0.039812780916690826,
0.025411050766706467,
-0.060508597642183304,
0.02641383931040764,
0.00035737623693421483,
0.017666121944785118,
0.0309583842754364,
-0.040474195033311844,
-0.05265698954463005,
-0.06823219358921051,
-0.031299758702516556,
0.03304930031299591,
0.022701391950249672,
0.009553147479891777,
0.017111388966441154,
0.016823353245854378,
0.011233349330723286,
-0.024920325726270676,
0.019266312941908836,
-0.012396154925227165,
-0.00874771736562252,
-0.027800671756267548,
-0.004451201297342777,
-0.050864774733781815,
-0.04608553275465965,
0.03161979839205742,
-0.011585391126573086,
0.013430946506559849,
-0.008203651756048203,
-0.09865718334913254,
0.0708351731300354,
0.07369418442249298,
0.012332147918641567,
0.023042766377329826,
0.010763959027826786,
0.014764439314603806,
-0.0017055381322279572,
0.04156232252717018,
0.058417681604623795,
-0.023917539045214653,
-0.025603074580430984,
0.006272753234952688,
-0.0035364245995879173,
0.043333202600479126,
0.019543679431080818,
0.005477990955114365,
-0.013761652633547783,
-0.023469485342502594,
-0.0012228135019540787,
-0.023192118853330612,
-0.013484286144375801,
-0.023746851831674576,
0.030168956145644188,
-0.037145793437957764,
-0.025624411180615425,
0.01655665412545204,
-0.03586563840508461,
0.06157539412379265,
-0.01625795289874077,
-0.03663373365998268,
0.03560961037874222,
0.04749370366334915,
-0.030083613470196724,
0.012481498531997204,
-0.039770107716321945,
-0.005037938244640827,
0.002110920147970319,
0.08781854808330536,
-0.017879480496048927,
0.08713579922914505,
0.007888947613537312,
-0.011489379219710827,
0.03925804793834686,
0.01968236267566681,
-0.018103506416082382,
-0.0247496385127306,
0.023896202445030212,
-0.04689629748463631,
-0.0011794749880209565,
0.042095720767974854,
0.012833541259169579,
-0.016055261716246605,
0.01095598191022873,
0.005920710973441601,
-0.010806631296873093,
0.07267005741596222,
-0.008678375743329525,
-0.022744065150618553,
0.03206785023212433,
0.007846275344491005,
0.023554828017950058,
-0.031299758702516556,
0.010923978872597218,
0.035758960992097855,
0.05031004175543785,
0.031982507556676865,
-0.053211722522974014,
-0.0006050726515240967,
-0.024642959237098694,
-0.0215812586247921,
0.06323959678411484,
-0.04160499572753906,
0.054918594658374786,
0.02713925950229168,
-0.007488899398595095,
-0.00943046621978283,
-0.08013762533664703,
0.03328399732708931,
0.01872224733233452,
-0.009595818817615509,
0.0012141457991674542,
0.023746851831674576,
0.01880759187042713,
0.011382699944078922,
-0.05223027244210243,
0.01845555007457733,
0.045232098549604416,
-0.019575683400034904,
0.048091109842061996,
0.01620461232960224,
0.02183728851377964,
0.01596991717815399,
-0.028376741334795952,
-0.008390340954065323,
-0.04693897068500519,
-0.020183756947517395,
0.053723786026239395,
0.03311330825090408,
0.0023616168182343245,
-0.002374951960518956,
0.06430638581514359,
0.001888226717710495,
-0.030745025724172592,
-0.008699711412191391,
0.054662562906742096,
0.08111907541751862,
0.009937193244695663,
0.015212493017315865,
-0.02600845694541931,
-0.0457441583275795,
-0.007915616966784,
-0.020770493894815445,
0.008043632842600346,
0.016151273623108864,
0.015585871413350105,
-0.03874598443508148,
-0.006672801449894905,
-0.01473243534564972,
0.04706698656082153,
0.02577376179397106,
0.05197424069046974,
0.023106774315238,
-0.022274674847722054,
0.09771840274333954,
0.019597020000219345,
-0.03972743824124336,
-0.05056607350707054,
-0.022978758439421654,
0.011030658148229122,
0.0396420918405056,
0.013718980364501476,
-0.03249456733465195,
-0.064263716340065,
0.06400768458843231,
-0.02903815358877182,
-0.01097731851041317,
-0.022829407826066017,
-0.012321479618549347,
-0.0014761772472411394,
-0.07518769800662994,
0.005707351956516504,
0.006800816860049963,
-0.042821142822504044,
0.02929418534040451,
-0.01578856259584427,
0.01792215183377266,
0.01227880734950304,
0.04373858496546745,
-0.02223200350999832,
-0.06622661650180817,
-0.015383180230855942,
0.025389716029167175,
-0.018658241257071495,
-0.01643930748105049,
0.04984065145254135,
-0.00956914946436882,
0.040964920073747635,
0.010129216127097607,
0.023277461528778076,
0.050651416182518005,
0.015511196106672287,
-0.042159728705883026,
0.012865545228123665,
-0.04324785992503166,
-0.010913310572504997,
-0.06878692656755447,
0.05730821564793587,
-0.02498433366417885,
-0.048517826944589615,
0.030296972021460533,
-0.005846035201102495,
-0.005904708988964558,
-0.039108697324991226,
-0.019298316910862923,
-0.019340990111231804,
0.014817778952419758,
-0.018850263208150864,
0.0034270782489329576,
-0.038809992372989655,
0.02434425614774227,
-0.009937193244695663,
0.026584526523947716,
-0.0015428519109264016,
-0.020354444161057472,
0.039322055876255035,
0.06720807403326035,
0.03661239519715309,
-0.008651705458760262,
-0.012310811318457127,
0.06533051282167435,
0.013078903779387474,
-0.027907351031899452,
-0.022829407826066017,
0.042863812297582626,
-0.0041444976814091206,
-0.03772186487913132,
0.05479057878255844,
-0.003672441001981497,
-0.017644785344600677,
0.029400864616036415,
0.0490298867225647,
-0.018348870798945427,
0.018924938514828682,
0.014561749063432217,
0.05692416802048683,
-0.06823219358921051,
0.006523449905216694,
-0.010891974903643131,
0.020599806681275368,
-0.02410956099629402,
-0.024962997063994408,
-0.007280874531716108,
-0.01886093243956566,
-0.01780480518937111,
0.02645651064813137,
-0.03422277793288231,
-0.056070733815431595,
0.026584526523947716,
-0.03951407968997955,
0.018167514353990555,
0.008886400610208511,
0.010774627327919006,
0.039087358862161636,
0.06533051282167435,
-0.03925804793834686,
-0.007104853168129921,
0.0044938731007277966,
-0.05521729588508606,
0.0030163621995598078,
0.017090052366256714,
-0.054875921458005905,
0.005285968072712421,
0.03688976168632507,
-0.01723940297961235,
-0.03238788992166519,
-0.01998106576502323,
-0.02929418534040451,
-0.02946487069129944,
0.0022909417748451233,
-0.016738010570406914,
0.00016335294640157372,
0.04907255992293358,
0.018818259239196777,
0.00636876467615366,
0.044037289917469025,
0.01311090774834156,
-0.037167128175497055,
-0.0037577846087515354,
-0.02713925950229168,
0.05692416802048683,
0.030254298821091652,
-0.03802056610584259,
-0.019927727058529854,
0.02760864794254303,
0.02265872061252594,
-0.05291302129626274,
-0.032899949699640274,
0.02950754389166832,
-0.016780681908130646,
-0.004917923826724291,
0.02641383931040764,
-0.030147619545459747,
0.030083613470196724,
0.018188850954174995,
-0.021538587287068367,
-0.01618327759206295,
-0.0179434884339571,
0.011457376182079315,
0.050438057631254196,
0.024642959237098694,
0.059612490236759186,
-0.030296972021460533,
-0.019170302897691727,
0.06904295831918716,
0.022253338247537613,
-0.022594712674617767,
0.019308986142277718,
0.038575299084186554,
-0.004845915362238884,
-0.013356270268559456,
0.04183969274163246,
0.02929418534040451,
0.00027219936600886285,
0.06853089481592178,
0.010651946067810059,
0.02455761469900608,
-0.07301143556833267,
-0.06776280701160431,
0.001709538628347218,
-0.028142046183347702,
-0.01602325774729252,
0.034606821835041046,
-0.017890147864818573,
0.001380165689624846,
0.06810417771339417,
0.013729648664593697,
0.0002900348335970193,
-0.012342815287411213,
0.0304889939725399,
-0.06311158090829849,
-0.02716059423983097,
0.10454588383436203,
0.027331281453371048,
-0.03853262588381767,
-0.014380393549799919,
-0.00277900043874979,
0.008806390687823296,
0.008443680591881275,
-0.03876732289791107,
0.062471501529216766,
-0.011030658148229122,
-0.030062276870012283,
0.026712540537118912,
-0.06328226625919342,
0.01660999469459057,
0.006768812891095877,
-0.0424584336578846,
-0.015223161317408085,
0.0476217195391655,
0.06311158090829849,
0.04984065145254135,
0.06251417100429535,
0.020023737102746964,
-0.012780201621353626,
0.08705045282840729,
-0.016684670001268387,
0.016994040459394455,
0.007014175411313772,
-0.00555266672745347,
0.018348870798945427,
-0.016247283667325974,
0.010998654179275036,
-0.03923671320080757,
0.02882479503750801,
-0.030254298821091652,
-0.026285823434591293,
-0.0419890433549881,
-0.0342441126704216,
0.06464776396751404,
0.028718115761876106,
0.03874598443508148,
0.010539932176470757,
0.021517250686883926,
0.03546025976538658,
-0.02314944565296173,
0.016641998663544655,
-0.04019682854413986,
-0.02381085976958275,
0.013398942537605762,
-0.034094762057065964,
-0.05803363397717476,
-0.061234019696712494,
-0.027971358969807625,
-0.013889667578041553,
0.018306197598576546,
-0.02955021522939205,
-0.1071915403008461,
0.06656799465417862,
-0.03921537473797798,
-0.06336761265993118,
-0.002217599656432867,
0.014839115552604198,
0.005200624465942383,
-0.0154791921377182,
-0.01606592908501625,
-0.02015175297856331,
-0.04651225358247757,
-0.019671695306897163,
-0.03021162748336792,
0.003315064823254943,
0.0073288800194859505,
0.00637409882619977,
-0.012801537290215492,
0.02831273339688778,
0.04087957739830017,
-0.03872464969754219,
-0.027672655880451202,
-0.05662546679377556,
0.027822008356451988,
-0.017399422824382782,
-0.02381085976958275,
-0.020087745040655136,
0.03349735587835312,
0.036719076335430145,
-0.025176357477903366,
0.034841518849134445,
-0.021335896104574203,
0.009766506031155586,
0.05662546679377556,
0.03853262588381767,
-0.039023350924253464,
0.020962517708539963,
0.04062354564666748,
-0.021218547597527504,
-0.0259231124073267,
-0.051334165036678314,
-0.02218933030962944,
0.0077769337221980095,
-0.0018615568988025188,
0.042159728705883026,
0.0014281715266406536,
-0.06831753998994827,
0.03249456733465195,
-0.012662854045629501,
0.025389716029167175,
0.03674041107296944,
-0.018636904656887054,
-0.05645477771759033,
0.0005994053208269179,
0.05146218091249466,
-0.030062276870012283,
-0.04079423099756241,
-0.051078133285045624,
0.050864774733781815,
0.053467754274606705,
-0.018423546105623245,
-0.0009481138549745083,
0.011382699944078922,
0.041690338402986526,
-0.01414569839835167,
-0.029080824926495552,
-0.021847957745194435,
-0.05619874969124794,
-0.02148524671792984,
-0.063324935734272,
-0.0033203987404704094,
0.013825660571455956,
-0.016780681908130646,
-0.01228947564959526,
0.028675442561507225,
-0.02856876328587532,
-0.0013374938862398267,
-0.04004747420549393,
0.01869024522602558,
0.01831686682999134,
0.003955141641199589,
-0.044976066797971725,
-0.012492166832089424,
-0.024664295837283134,
0.0023496155627071857,
0.04019682854413986,
0.02694723568856716,
-0.03825525939464569,
-0.03144910931587219,
0.03428678214550018,
-0.007350216154009104,
0.020119749009609222,
-0.008870398625731468,
0.03983411565423012,
-0.029422199353575706,
-0.003507087705656886,
0.0013201584806665778,
-0.06537318229675293,
-0.03757251054048538,
0.06375165283679962,
-0.04932859167456627,
0.0015975252026692033,
-0.02364017255604267,
0.02946487069129944,
0.034116096794605255,
0.02101585641503334,
-0.032195866107940674,
0.02859009988605976,
-0.0003032030654139817,
-0.04318385198712349,
-0.014476405456662178,
-0.0247496385127306,
0.023320132866501808,
0.06533051282167435,
-0.021869292482733727,
0.039578087627887726,
0.0010614608181640506,
-0.04578683152794838,
-0.06699471175670624,
0.00714752497151494,
0.02901681698858738,
0.02265872061252594,
-0.02765132114291191,
0.02664853259921074,
-0.02246669866144657,
-0.028462084010243416,
-0.023234790191054344,
-0.035972319543361664,
0.035801634192466736,
0.043098509311676025,
-0.046853628009557724,
0.04651225358247757,
0.04218106344342232,
0.007888947613537312,
-0.03185449168086052,
-0.004851249046623707,
0.045872174203395844,
0.024472272023558617,
-0.010305237025022507,
-0.00796362292021513,
-0.020375780761241913,
-0.031022392213344574,
-0.03093704767525196,
-0.022082651033997536,
0.036953769624233246,
-0.03492686152458191,
-0.014721767976880074,
-0.009617154486477375,
0.01096665021032095,
0.03895934671163559
]
|
31,060 | networkx.readwrite.graphml | read_graphml | Read graph in GraphML format from path.
Parameters
----------
path : file or string
File or filename to write.
Filenames ending in .gz or .bz2 will be compressed.
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 parallel edges are present or `force_multigraph=True` then
a MultiGraph or MultiDiGraph is returned. Otherwise a Graph/DiGraph.
The returned graph is directed if the file indicates it should be.
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.
Files with the yEd "yfiles" extension can be read. The type of the node's
shape is preserved in the `shape_type` node attribute.
yEd compressed files ("file.graphmlz" extension) can be read by renaming
the file to "file.graphml.gz".
| 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
| (path, 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,069 | networkx.algorithms.cycles | recursive_simple_cycles | 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
| 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.021086322143673897,
-0.03180520236492157,
-0.04123547300696373,
0.029052266851067543,
-0.03897064924240112,
-0.001070789759978652,
-0.038599684834480286,
-0.01454565767198801,
0.07555932551622391,
-0.05908074975013733,
-0.02504977025091648,
0.039107318967580795,
0.00017465162090957165,
0.0024515290278941393,
-0.02993086352944374,
-0.028349388390779495,
0.0031702700071036816,
0.0030067532788962126,
-0.03619818761944771,
0.03885350003838539,
-0.01598069816827774,
-0.042133595794439316,
0.04107927903532982,
0.04760042205452919,
-0.01886054314672947,
0.05911979824304581,
-0.0024466479662805796,
0.024229746311903,
-0.09793425351381302,
-0.020637262612581253,
0.0129446592181921,
0.00201833201572299,
-0.07954229414463043,
-0.04998239502310753,
0.024327367544174194,
0.06614857167005539,
0.015082578174769878,
0.05236436799168587,
-0.0783708319067955,
0.009078833274543285,
0.03196139633655548,
-0.009981835260987282,
0.011255800724029541,
-0.05033383145928383,
0.04326600953936577,
-0.014662804082036018,
0.02975514344871044,
0.0859072357416153,
-0.014340651221573353,
-0.05439490079879761,
0.051583390682935715,
-0.005749927833676338,
-0.04143071919679642,
0.0011824448592960835,
0.04459366574883461,
0.011148416437208652,
0.010250295512378216,
0.04353934898972511,
0.07263066619634628,
-0.024991197511553764,
-0.013930640183389187,
-0.021808724850416183,
0.024503087624907494,
0.0521300733089447,
-0.05869026482105255,
-0.01497519388794899,
-0.013413243927061558,
-0.047366127371788025,
-0.008380836807191372,
0.0022831312380731106,
0.0037120713386684656,
-0.004837163258343935,
0.017718367278575897,
-0.04779566451907158,
-0.014799474738538265,
-0.05216912180185318,
-0.008512626402080059,
-0.008044041693210602,
-0.005130028817802668,
-0.022257784381508827,
0.024483563378453255,
-0.011226514354348183,
0.002457630354911089,
-0.04728803038597107,
0.029071791097521782,
-0.00035326910438016057,
0.015355918556451797,
0.03651057556271553,
-0.04022020846605301,
-0.023761160671710968,
-0.007253304589539766,
-0.024678807705640793,
0.0066187623888254166,
0.09004640579223633,
0.02745126746594906,
0.003360632574185729,
-0.03563198074698448,
-0.05533207207918167,
0.030750887468457222,
0.0015204604715108871,
0.0071068718098104,
0.003926839213818312,
-0.11691194027662277,
-0.013354671187698841,
-0.02424927055835724,
-0.02626028098165989,
-0.033581919968128204,
0.02339019812643528,
0.008253928273916245,
-0.08653201907873154,
-0.05185673385858536,
0.056464485824108124,
0.01598069816827774,
-0.03467528522014618,
-0.01085555087774992,
0.05939314141869545,
0.028310339897871017,
-0.027216974645853043,
0.007189850322902203,
-0.014243029989302158,
-0.014487084001302719,
-0.021574432030320168,
-0.04154786467552185,
0.04455461725592613,
0.020793456584215164,
-0.001655910862609744,
0.009049546904861927,
0.02134013921022415,
0.008722512982785702,
-0.008244166150689125,
0.061853211373090744,
0.038111574947834015,
0.023468295112252235,
0.0703267902135849,
-0.0006504056509584188,
-0.022784942761063576,
-0.05181768536567688,
-0.01970985345542431,
-0.019114360213279724,
0.01650785654783249,
-0.016117369756102562,
-0.1049630269408226,
0.012271068058907986,
0.06642191857099533,
0.03955638036131859,
-0.015463302843272686,
0.035729601979255676,
-0.02456166036427021,
0.002818831242620945,
0.030243253335356712,
0.014408987015485764,
0.002413700567558408,
0.025694074109196663,
0.0019683009013533592,
0.021945394575595856,
-0.00334598938934505,
-0.040493547916412354,
0.04545274004340172,
-0.046194665133953094,
0.0244054663926363,
-0.031922347843647,
-0.006374707445502281,
-0.024620233103632927,
0.0068823411129415035,
-0.027997950091958046,
0.019094835966825485,
0.023507345467805862,
-0.008610248565673828,
-0.052208174020051956,
0.025440257042646408,
0.007272828835994005,
0.00648209173232317,
-0.07169349491596222,
0.011177703738212585,
0.003719392931088805,
0.03565150499343872,
0.013198476284742355,
0.03721345588564873,
0.010689593851566315,
-0.01884101890027523,
-0.021633004769682884,
-0.009361936710774899,
-0.026318853721022606,
-0.015414492227137089,
0.014399224892258644,
0.028720352798700333,
0.06829625368118286,
-0.05115385726094246,
0.05818263068795204,
0.009215503931045532,
-0.06318087130784988,
0.010289344005286694,
0.044984154403209686,
0.057635948061943054,
0.0699753537774086,
-0.03783823549747467,
-0.02034439705312252,
0.029813716188073158,
-0.058651216328144073,
0.08145568519830704,
0.01414540782570839,
0.030692312866449356,
0.05369202420115471,
-0.002242862246930599,
0.045179396867752075,
0.03268380090594292,
0.014701852574944496,
-0.0055107539519667625,
0.016390711069107056,
0.013637774623930454,
-0.05619114264845848,
-0.05103670805692673,
0.031922347843647,
-0.016556667163968086,
-0.041274525225162506,
0.026279805228114128,
-0.0032752135302871466,
0.0193291287869215,
0.017776941880583763,
-0.06872579455375671,
-0.03317191079258919,
0.010230771265923977,
-0.008898233063519001,
-0.022765418514609337,
-0.009981835260987282,
-0.025127867236733437,
0.039087794721126556,
0.01253464724868536,
0.026846012100577354,
-0.021672053262591362,
0.027861280366778374,
0.004685849417001009,
0.04357840120792389,
-0.011372947134077549,
0.01043577678501606,
-0.05345773324370384,
-0.036764394491910934,
0.00466388463973999,
0.020266298204660416,
-0.0023892950266599655,
-0.04877188429236412,
-0.06966295838356018,
-0.0008127019973471761,
-0.012817750684916973,
0.014506609179079533,
-0.015717118978500366,
0.040493547916412354,
-0.00018349858873989433,
-0.013872066512703896,
-0.0013398600276559591,
-0.08098709583282471,
-0.05181768536567688,
-0.0007169105811044574,
-0.06544569879770279,
0.00850286427885294,
-0.04025925695896149,
-0.04529654607176781,
-0.02694363333284855,
-0.0005180059815756977,
0.011460806243121624,
0.011421757750213146,
0.016781197860836983,
-0.04728803038597107,
0.021906346082687378,
-0.0024198018945753574,
0.008600486442446709,
0.011187465861439705,
0.01733764261007309,
-0.03360144421458244,
0.026963157579302788,
0.07602790743112564,
-0.05869026482105255,
0.01135342288762331,
0.008629772812128067,
-0.04728803038597107,
0.027041256427764893,
-0.005588851869106293,
0.031219471246004105,
-0.02272637002170086,
-0.052598658949136734,
-0.0787222683429718,
0.02741221897304058,
0.0006882341112941504,
-0.004527213983237743,
-0.04693659022450447,
-0.014701852574944496,
0.004783471114933491,
-0.042485035955905914,
0.0006006795447319746,
-0.0056279003620147705,
0.07442691177129745,
-0.03371858969330788,
0.05127100273966789,
0.028525108471512794,
0.044671762734651566,
0.006394232157617807,
-0.020949652418494225,
-0.07844892889261246,
0.0022953341249376535,
0.026338377967476845,
0.010875075124204159,
-0.05013858899474144,
0.0018450531642884016,
-0.02622123248875141,
0.007365569472312927,
-0.04471081495285034,
0.009318007156252861,
-0.023683063685894012,
-0.00005620883894152939,
-0.01169509906321764,
-0.04900617524981499,
0.0240540262311697,
0.011480331420898438,
0.02202349156141281,
-0.004720016848295927,
-0.060174115002155304,
-0.028349388390779495,
-0.021652529016137123,
0.06794481724500656,
0.05236436799168587,
0.01563902199268341,
0.04353934898972511,
-0.04310981556773186,
0.040805939584970474,
-0.059471238404512405,
0.044827960431575775,
0.06380564719438553,
0.052598658949136734,
0.0369986854493618,
0.005403370130807161,
-0.0056279003620147705,
0.022823991253972054,
-0.014096597209572792,
0.04307076707482338,
0.003694987390190363,
0.011421757750213146,
0.06267323344945908,
-0.05466824397444725,
-0.022082066163420677,
-0.07993277907371521,
0.07618410140275955,
0.054082512855529785,
-0.013920878060162067,
-0.018762921914458275,
0.002618706552311778,
-0.009166693314909935,
0.049357615411281586,
0.011714623309671879,
-0.020617736503481865,
0.026006463915109634,
0.032918091863393784,
0.06817910820245743,
-0.036061517894268036,
0.019475562497973442,
-0.025030246004462242,
0.029833240434527397,
0.010660307481884956,
-0.005369202233850956,
-0.010621258988976479,
-0.005247175227850676,
0.026182183995842934,
0.03690106421709061,
-0.008107495494186878,
-0.013920878060162067,
0.04849854111671448,
-0.006042793393135071,
-0.017630508169531822,
0.04346125200390816,
0.0019829440861940384,
-0.05501968041062355,
-0.03418717533349991,
-0.00016473689174745232,
0.006130652967840433,
-0.0032044376712292433,
0.0021928311325609684,
0.03518291935324669,
0.02491309866309166,
-0.016254039481282234,
0.052754852920770645,
0.027002207934856415,
-0.0010683492291718721,
-0.006779838353395462,
0.0010903141228482127,
0.011558428406715393,
0.030184680595993996,
-0.0027626988012343645,
0.04463271424174309,
0.026982683688402176,
0.08278334140777588,
-0.011382709257304668,
-0.04611656814813614,
-0.05076336860656738,
0.023819735273718834,
0.009078833274543285,
-0.04580417647957802,
-0.012583457864820957,
0.14377747476100922,
0.03551483526825905,
-0.00798546802252531,
-0.013959926553070545,
-0.0002118699485436082,
0.013764682225883007,
0.030243253335356712,
0.02891559526324272,
0.00551563547924161,
-0.028310339897871017,
0.04795185849070549,
0.00019448105012997985,
0.0027090066578239202,
-0.007482715882360935,
-0.03125851973891258,
0.009786591865122318,
0.004688289947807789,
-0.01697644218802452,
0.01328633539378643,
-0.05587875470519066,
-0.03787728399038315,
-0.0009310684981755912,
0.07345069199800491,
0.024678807705640793,
0.04287552088499069,
-0.00841500423848629,
0.04572607949376106,
-0.008224641904234886,
0.009635278023779392,
0.02089107781648636,
0.02692410908639431,
0.03346477448940277,
-0.04642895609140396,
0.06825720518827438,
-0.003192235017195344,
-0.0291303638368845,
-0.0289546437561512,
-0.0491623692214489,
-0.019748901948332787,
-0.024639757350087166,
0.043656498193740845,
-0.020559163764119148,
0.05740165710449219,
0.026318853721022606,
-0.021652529016137123,
0.06478186696767807,
-0.009371698834002018,
-0.035592932254076004,
0.05162244290113449,
-0.018450532108545303,
0.0041391667909920216,
0.03315238282084465,
0.011948916129767895,
-0.017025252804160118,
0.021301090717315674,
-0.028817974030971527,
0.03096565417945385,
-0.05150529369711876,
-0.12292545288801193,
0.03133661672472954,
0.018030758947134018,
0.01865553855895996,
-0.050411928445100784,
0.02524501457810402,
0.06681240350008011,
0.02221873588860035,
0.016927631571888924,
0.01378420740365982,
-0.05349678173661232,
-0.04287552088499069,
0.011411995626986027,
0.014936145395040512,
-0.02184777334332466,
0.004026901908218861,
0.03449956700205803,
-0.022784942761063576,
-0.08051851391792297,
-0.03268380090594292,
0.030399447306990623,
-0.021144894883036613,
-0.07161539793014526,
-0.013149664737284184,
-0.0017742773052304983,
-0.08122138679027557,
-0.07544217258691788,
-0.014662804082036018,
0.02217968739569187,
-0.017620746046304703,
-0.0037755256053060293,
-0.030887557193636894,
0.03914636746048927,
-0.005461943335831165,
-0.02286303974688053,
-0.05974458158016205,
-0.052247222512960434,
-0.02050059102475643,
-0.021593956276774406,
0.01018196064978838,
0.025498829782009125,
0.0689210370182991,
-0.04424222931265831,
-0.018460294231772423,
0.08871874958276749,
-0.024424990639090538,
0.01246631145477295,
-0.004495486617088318,
-0.0007285031606443226,
0.008668821305036545,
0.04537464305758476,
0.03112185001373291,
0.01529734581708908,
-0.0072386609390378,
0.025440257042646408,
0.006735908333212137,
0.02811509557068348,
-0.006111128721386194,
0.019299842417240143,
0.044984154403209686,
0.010962935164570808,
0.0017425502883270383,
-0.013813493773341179,
-0.004183096811175346,
0.0363934300839901,
-0.02708030492067337,
0.0129446592181921,
0.020246773958206177,
0.004917701240628958,
0.0535358302295208,
-0.008478458970785141,
0.01982700079679489,
-0.0006375928060151637,
-0.050568126142024994,
-0.0267679151147604,
-0.008385717868804932,
0.006125771906226873,
0.020324870944023132,
-0.025674549862742424,
0.09605991095304489,
0.010211247019469738,
-0.01685929484665394,
0.047170884907245636,
0.018470056354999542,
-0.05869026482105255,
0.0009005616884678602,
0.022960662841796875,
0.039087794721126556,
0.0706782266497612,
0.009191098622977734,
0.006740789394825697,
0.02050059102475643,
0.056464485824108124,
0.016790959984064102,
-0.03299618884921074,
-0.036744870245456696,
-0.00404154509305954,
0.006701740901917219,
-0.00743878586217761,
-0.027997950091958046,
0.06275133043527603,
-0.08512626588344574,
-0.02069583535194397,
0.014516371302306652,
0.0028993692249059677,
0.024522611871361732,
-0.03303523734211922,
0.0035021842923015356,
-0.06564094126224518,
-0.08254905045032501,
0.04107927903532982,
-0.022316357120871544,
0.07532502710819244,
-0.029540374875068665,
0.018577439710497856,
0.03330858051776886,
0.0129446592181921,
-0.002120835008099675,
0.03293761610984802,
-0.02672886662185192,
-0.0010567567078396678,
0.037115830928087234,
-0.020481066778302193,
-0.02153538353741169,
0.000979879405349493,
-0.06946771591901779,
-0.007565694395452738,
-0.04435937479138374,
-0.00711175287142396,
0.01245654933154583,
0.05935409292578697,
-0.008117257617413998,
-0.02255064994096756,
0.0041464888490736485,
-0.03043849766254425,
-0.007287472020834684,
0.030087057501077652,
-0.05923694744706154,
0.030692312866449356,
-0.005710878875106573,
-0.02053963951766491,
0.032215215265750885,
-0.002799306996166706,
0.027353646233677864,
-0.0034436113201081753,
-0.01412588357925415,
-0.03200044482946396,
0.015765931457281113,
0.040454499423503876,
0.04998239502310753,
-0.03461671248078346,
0.023487819358706474,
0.019807476550340652,
-0.06310277432203293,
0.04412508383393288,
-0.018811732530593872,
0.0019805035553872585,
0.05263770744204521,
-0.00334354885853827,
0.006506497040390968,
-0.06692954897880554,
0.011841531842947006,
-0.0433831550180912,
0.015189961530268192,
-0.02421022206544876,
-0.008039160631597042,
0.006921390071511269,
0.0013154546031728387,
0.013257049024105072,
-0.028056522831320763,
-0.07095157355070114,
0.02559645287692547,
0.02340972237288952,
0.009508369490504265,
0.029364656656980515,
0.0699753537774086,
0.013667060993611813,
-0.0048103174194693565,
-0.012280830182135105,
0.05822167918086052,
0.007248423527926207,
-0.06942866742610931,
0.001962199341505766,
-0.002667517401278019,
-0.013188713230192661,
0.0874691903591156,
-0.06646096706390381,
-0.015551162883639336,
-0.0524815134704113,
0.018235763534903526,
-0.07833178341388702,
-0.045530837029218674,
0.03112185001373291,
-0.04474986344575882,
0.019104598090052605,
0.041274525225162506,
-0.03098517842590809,
0.023292576894164085,
0.029891815036535263,
-0.014506609179079533,
-0.005876836366951466,
0.053418684750795364,
0.039771147072315216,
-0.031883299350738525,
0.017718367278575897,
-0.040454499423503876,
0.056464485824108124,
0.005291104782372713,
0.015346156433224678,
-0.012915372848510742,
-0.02102774940431118,
-0.0030384804122149944,
0.07348974049091339,
-0.021281566470861435,
-0.034597188234329224,
0.015375443734228611,
-0.02223826013505459,
-0.0678667202591896,
0.0022867920342832804,
-0.024132125079631805,
-0.07770700007677078,
-0.004058628808706999,
-0.03803347796201706,
0.040766891092061996,
-0.007516883313655853,
-0.017191210761666298,
0.016703100875020027,
0.012271068058907986,
-0.02977466769516468,
-0.03344525024294853,
-0.0005985440220683813,
-0.0025235251523554325,
-0.0021452405489981174,
-0.053418684750795364,
0.03748679533600807,
-0.07860512286424637,
0.0018279693322256207,
0.013188713230192661,
0.03364049270749092,
0.018255287781357765,
-0.014506609179079533,
0.02473738044500351,
0.01662500388920307,
0.010035527870059013,
0.04439842328429222,
-0.0531843900680542,
0.054238706827163696,
-0.013139902614057064,
0.02053963951766491,
0.028857022523880005,
-0.0025845388881862164,
0.0001378908782498911,
-0.05146624520421028,
0.004986036568880081,
0.030028484761714935,
0.043812692165374756,
-0.0015924565959721804,
0.009518131613731384,
-0.003389919176697731,
-0.0037852877285331488,
0.017796466127038002,
-0.06743717938661575,
-0.014594468288123608,
-0.023761160671710968,
-0.04611656814813614,
0.029306083917617798,
-0.005203245207667351,
0.009176455438137054,
-0.026787439361214638,
0.0307899359613657,
-0.02253112569451332,
0.09020259976387024,
0.05111480876803398,
-0.02319495379924774,
0.015004480257630348,
-0.020637262612581253,
-0.04123547300696373,
0.06282942742109299,
-0.011011745780706406,
0.031238995492458344,
0.025323111563920975,
-0.04439842328429222,
-0.02067631110548973,
0.0033386677969247103,
-0.01010386273264885,
0.02977466769516468,
-0.006096485536545515,
-0.035944368690252304,
-0.06282942742109299,
0.029677046462893486,
-0.018304098397493362,
-0.021925870329141617,
0.010962935164570808,
0.062165603041648865,
0.018050283193588257,
-0.09746566414833069,
-0.005657186731696129,
-0.03176615387201309,
-0.02791985310614109,
-0.03951733186841011,
-0.008766443468630314,
0.010113624855875969,
-0.05974458158016205,
-0.009991597384214401,
-0.051427196711301804,
-0.053574878722429276,
-0.013940402306616306,
0.007795105688273907,
0.022082066163420677,
0.02339019812643528,
-0.034265272319316864,
0.029345132410526276,
0.0002654094423633069,
0.05599590018391609
]
|
31,072 | networkx.readwrite.gexf | relabel_gexf_graph | Relabel graph using "label" node keyword for node label.
Parameters
----------
G : graph
A NetworkX graph read from GEXF data
Returns
-------
H : graph
A NetworkX graph with relabeled nodes
Raises
------
NetworkXError
If node labels are missing or not unique while relabel=True.
Notes
-----
This function relabels the nodes in a NetworkX graph with the
"label" attribute. It also handles relabeling the specific GEXF
node attributes "parents", and "pid".
| def relabel_gexf_graph(G):
"""Relabel graph using "label" node keyword for node label.
Parameters
----------
G : graph
A NetworkX graph read from GEXF data
Returns
-------
H : graph
A NetworkX graph with relabeled nodes
Raises
------
NetworkXError
If node labels are missing or not unique while relabel=True.
Notes
-----
This function relabels the nodes in a NetworkX graph with the
"label" attribute. It also handles relabeling the specific GEXF
node attributes "parents", and "pid".
"""
# build mapping of node labels, do some error checking
try:
mapping = [(u, G.nodes[u]["label"]) for u in G]
except KeyError as err:
raise nx.NetworkXError(
"Failed to relabel nodes: missing node labels found. Use relabel=False."
) from err
x, y = zip(*mapping)
if len(set(y)) != len(G):
raise nx.NetworkXError(
"Failed to relabel nodes: "
"duplicate node labels found. "
"Use relabel=False."
)
mapping = dict(mapping)
H = nx.relabel_nodes(G, mapping)
# relabel attributes
for n in G:
m = mapping[n]
H.nodes[m]["id"] = n
H.nodes[m].pop("label")
if "pid" in H.nodes[m]:
H.nodes[m]["pid"] = mapping[G.nodes[n]["pid"]]
if "parents" in H.nodes[m]:
H.nodes[m]["parents"] = [mapping[p] for p in G.nodes[n]["parents"]]
return H
| (G) | [
0.08150695264339447,
-0.034383416175842285,
0.008274557068943977,
0.026262523606419563,
-0.0494331456720829,
-0.008973028510808945,
-0.004828765522688627,
0.004034836310893297,
0.15869268774986267,
-0.07673872262239456,
0.004055790603160858,
-0.06537692248821259,
0.02473519928753376,
0.05412687361240387,
-0.0003911439562216401,
-0.06247127801179886,
-0.029708314687013626,
0.028944652527570724,
0.007175629027187824,
0.0024469781201332808,
0.015766827389597893,
-0.05394061654806137,
0.015301179140806198,
0.030956251546740532,
0.010579513385891914,
-0.03227869048714638,
0.009061502292752266,
0.038779132068157196,
0.04000844061374664,
0.019594449549913406,
0.0032339224126189947,
-0.09089440852403641,
-0.07048041373491287,
-0.02007872425019741,
-0.0005049366154707968,
0.005238535348325968,
-0.052785810083150864,
0.014472326263785362,
-0.03455105051398277,
-0.051854513585567474,
0.03695379197597504,
-0.08515762537717819,
-0.033526625484228134,
-0.02758496254682541,
0.03658127412199974,
0.043472856283187866,
-0.009201196022331715,
0.0047728875651955605,
0.010849588550627232,
-0.0053596035577356815,
-0.032502200454473495,
-0.048948872834444046,
-0.037959590554237366,
0.05211527645587921,
-0.010821649804711342,
0.014667898416519165,
-0.016744686290621758,
0.04585697501897812,
0.038853634148836136,
-0.007664558943361044,
0.008353717625141144,
-0.021326659247279167,
-0.06954912096261978,
0.007324636448174715,
-0.0031431212555617094,
-0.005904411431401968,
-0.026784049347043037,
-0.07513689249753952,
-0.043510109186172485,
-0.054573897272348404,
-0.057405032217502594,
-0.009583027102053165,
0.02944755367934704,
-0.027957480400800705,
0.03389914333820343,
0.02274222858250141,
-0.025964509695768356,
0.020395364612340927,
-0.014351258054375648,
0.012600423768162727,
-0.0006751889595761895,
-0.007236163131892681,
-0.009075471200048923,
-0.035296086221933365,
0.0014516563387587667,
-0.011706380173563957,
0.06623370945453644,
0.04332385212182999,
0.02030223421752453,
-0.06936286389827728,
-0.018868040293455124,
0.006323494017124176,
0.025852752849459648,
-0.0019522274378687143,
0.00943867675960064,
-0.041684772819280624,
-0.02095414139330387,
-0.0067006684839725494,
0.02738007716834545,
0.011538746766746044,
0.01470515038818121,
0.007999825291335583,
-0.08255000412464142,
0.02670954540371895,
-0.015478125773370266,
-0.0328933447599411,
-0.04310033842921257,
-0.006244333926588297,
0.012619049288332462,
-0.045409951359033585,
-0.06053418666124344,
-0.02767809107899666,
0.05110947787761688,
-0.026020387187600136,
0.039784930646419525,
-0.004551704972982407,
0.047980327159166336,
0.00546670239418745,
-0.008418908342719078,
-0.049954671412706375,
0.03512845188379288,
0.03218556195497513,
-0.07617994397878647,
0.005289756692945957,
-0.013382711447775364,
0.006947461981326342,
0.07435460388660431,
0.03944966197013855,
0.019519945606589317,
-0.048278339207172394,
0.020581623539328575,
0.02916816435754299,
-0.05759129300713539,
0.037084173411130905,
0.061800748109817505,
-0.05706976726651192,
-0.024399932473897934,
0.03406677767634392,
0.029019156470894814,
-0.005937006790190935,
0.005899754818528891,
-0.018868040293455124,
0.03833210840821266,
0.03781058266758919,
0.01699613593518734,
-0.045298196375370026,
0.015496751293540001,
0.013643474318087101,
0.01667018234729767,
-0.024120545014739037,
0.026132142171263695,
0.003473730990663171,
0.03682341054081917,
-0.042541563510894775,
-0.035221584141254425,
0.02738007716834545,
-0.06466913223266602,
0.014872783794999123,
-0.006016166880726814,
0.031515028327703476,
-0.01570163667201996,
-0.023487264290452003,
-0.010616764426231384,
-0.017098579555749893,
-0.008065016008913517,
-0.017238274216651917,
0.021457040682435036,
-0.013364085927605629,
-0.01610209234058857,
0.04224354773759842,
-0.017731860280036926,
-0.07733474671840668,
-0.04604323208332062,
-0.027882976457476616,
0.009890354238450527,
0.059975408017635345,
0.03514707833528519,
-0.013177826069295406,
0.01705201342701912,
0.07606818526983261,
0.013885610736906528,
0.007068530190736055,
-0.025349853560328484,
-0.003888157196342945,
0.00797654315829277,
0.03488631546497345,
0.0031547623220831156,
0.04108874127268791,
0.019929716363549232,
-0.007417765911668539,
0.035407841205596924,
-0.02760358899831772,
-0.012693553231656551,
0.07904833555221558,
0.024027414619922638,
-0.006309524644166231,
-0.015813391655683517,
0.009815851226449013,
-0.02555473893880844,
0.11115939170122147,
0.01564575918018818,
0.0002002284600166604,
0.0332658626139164,
0.038052719086408615,
-0.053568098694086075,
0.008065016008913517,
0.06288105249404907,
-0.006919522769749165,
-0.06481814384460449,
-0.05591496080160141,
0.04187102988362312,
-0.0054480768740177155,
-0.018532773479819298,
0.010234933346509933,
-0.02743595466017723,
0.042504310607910156,
-0.05103497579693794,
0.05766579508781433,
-0.01639079488813877,
-0.014900722540915012,
-0.07558391243219376,
0.002754305489361286,
-0.03546372056007385,
-0.031515028327703476,
0.013857671990990639,
-0.044404152780771255,
0.042690571397542953,
0.028795646503567696,
0.06306730955839157,
-0.05192901939153671,
0.05118397995829582,
0.009815851226449013,
0.07513689249753952,
-0.027137940749526024,
0.07606818526983261,
-0.02479107677936554,
0.03272571042180061,
0.021699177101254463,
0.039039891213178635,
0.05803831294178963,
0.0054992977529764175,
-0.05420137941837311,
-0.03723318129777908,
-0.03268846124410629,
0.04496293142437935,
-0.02212757244706154,
0.046378497034311295,
0.025033213198184967,
-0.008265244774520397,
-0.012442103587090969,
-0.04298858344554901,
-0.0018125332426279783,
0.017703920602798462,
0.016530489549040794,
0.009294325485825539,
-0.0075621167197823524,
-0.0657866895198822,
-0.011184854432940483,
-0.0025773593224585056,
0.01587858237326145,
-0.02555473893880844,
0.02182955853641033,
-0.0568462572991848,
-0.021755054593086243,
0.050885967910289764,
0.038779132068157196,
0.020432615652680397,
0.05010367929935455,
-0.02203444391489029,
-0.022500090301036835,
0.10147392004728317,
0.017610792070627213,
-0.00572280865162611,
0.025983134284615517,
0.03781058266758919,
-0.016297664493322372,
0.0031640753149986267,
0.007650589570403099,
0.05535618215799332,
-0.028031984344124794,
-0.029913200065493584,
-0.03322860971093178,
0.014854157343506813,
0.04302583634853363,
-0.05744228512048721,
-0.016679495573043823,
-0.0219599399715662,
0.06399860233068466,
-0.006328150629997253,
-0.056436486542224884,
0.03373150900006294,
-0.005625022575259209,
0.0001263068988919258,
0.05047619715332985,
-0.04406888782978058,
-0.0008352553704753518,
-0.014639959670603275,
-0.01562713272869587,
-0.028926027938723564,
0.03272571042180061,
0.05241329222917557,
-0.02745458111166954,
-0.017154457047581673,
-0.017824988812208176,
0.020823759958148003,
-0.011101038195192814,
0.04939589649438858,
0.03386189043521881,
-0.00595563231036067,
0.040790729224681854,
-0.04555895924568176,
0.01505904272198677,
-0.033657006919384,
-0.029075033962726593,
-0.07200773805379868,
-0.010560886934399605,
0.06701599806547165,
0.008046390488743782,
0.05591496080160141,
-0.03952416777610779,
-0.02829274721443653,
0.02764084003865719,
-0.03725180774927139,
0.08620067685842514,
-0.050066426396369934,
0.046192239969968796,
0.02767809107899666,
0.0528603121638298,
0.02022773027420044,
-0.040790729224681854,
-0.0008655224228277802,
-0.02460481785237789,
-0.005229222122579813,
-0.0035459063947200775,
-0.08143244683742523,
0.02190406247973442,
0.06042242795228958,
-0.011156915687024593,
-0.008414251729846,
-0.02738007716834545,
-0.04395713284611702,
0.01604621484875679,
-0.08091092109680176,
-0.01802056096494198,
0.02287260815501213,
0.038052719086408615,
-0.03911439701914787,
-0.011250045150518417,
-0.002458619186654687,
0.0328933447599411,
-0.02026498317718506,
0.03941241279244423,
-0.006025479640811682,
-0.025182221084833145,
0.01367141306400299,
-0.02117765136063099,
-0.01741521991789341,
-0.01467721164226532,
-0.017079953104257584,
0.08150695264339447,
-0.03600386902689934,
-0.06280654668807983,
-0.011631876230239868,
-0.033526625484228134,
-0.009177913889288902,
-0.004395713098347187,
-0.027808472514152527,
0.07867581397294998,
0.013876297511160374,
-0.02747320756316185,
0.02190406247973442,
-0.04120049625635147,
-0.051780011504888535,
0.008828678168356419,
-0.019063612446188927,
0.05576595291495323,
-0.022406961768865585,
-0.04682552069425583,
-0.05300932005047798,
-0.006067387759685516,
0.03866737335920334,
-0.03293059766292572,
-0.03589211404323578,
0.03198067471385002,
0.012134775519371033,
-0.01701476238667965,
0.0958116427063942,
0.016679495573043823,
0.05926762521266937,
0.010411879979074001,
-0.005601740442216396,
-0.008237306028604507,
0.04228080064058304,
0.017629416659474373,
-0.020674752071499825,
-0.03568723052740097,
0.017787737771868706,
0.007138377521187067,
0.00037571939174085855,
-0.027137940749526024,
-0.034383416175842285,
0.04492567852139473,
-0.01911017671227455,
0.016986822709441185,
0.042429808527231216,
0.057218775153160095,
0.028870150446891785,
-0.004672773648053408,
0.018542086705565453,
0.024511689320206642,
0.006649447605013847,
0.055616945028305054,
0.020600248128175735,
-0.026113515719771385,
0.009219822473824024,
0.051705505698919296,
0.01092409249395132,
0.01599033735692501,
0.06168898940086365,
-0.0246234443038702,
-0.01146424375474453,
0.020451242104172707,
0.015329117886722088,
-0.02192268706858158,
-0.009126692079007626,
-0.016530489549040794,
-0.020823759958148003,
0.020488493144512177,
-0.0568462572991848,
0.09551363438367844,
-0.05766579508781433,
-0.024493062868714333,
0.02287260815501213,
0.0036297228652983904,
0.004025523085147142,
-0.05237603932619095,
0.021624673157930374,
-0.023580392822623253,
-0.059863653033971786,
0.022239327430725098,
0.023189248517155647,
0.006328150629997253,
0.04604323208332062,
-0.05982640013098717,
-0.005555175710469484,
-0.0037088829558342695,
-0.0477195642888546,
0.020618874579668045,
0.019687579944729805,
-0.007999825291335583,
0.006835706532001495,
-0.013187139295041561,
0.05535618215799332,
0.028050610795617104,
-0.05103497579693794,
-0.008335091173648834,
-0.01514285895973444,
-0.038928136229515076,
-0.037158675491809845,
0.018104378134012222,
-0.05047619715332985,
-0.004744948819279671,
0.03866737335920334,
0.04660201072692871,
-0.009583027102053165,
-0.01825338415801525,
0.05438763648271561,
-0.013941488228738308,
-0.023133371025323868,
-0.002289821859449148,
0.030434725806117058,
-0.07550941407680511,
-0.003275830764323473,
-0.04317484423518181,
0.0011722678318619728,
0.007692498154938221,
-0.038779132068157196,
0.03397364541888237,
0.02192268706858158,
-0.05654824152588844,
0.03779195621609688,
-0.0014958928804844618,
0.060981206595897675,
0.012330347672104836,
0.027715343981981277,
-0.020544370636343956,
0.06496714800596237,
-0.01912880316376686,
-0.06466913223266602,
0.0010104551911354065,
-0.027231071144342422,
-0.00687761465087533,
-0.01013249158859253,
0.05468565225601196,
0.013187139295041561,
-0.0038369360845535994,
-0.0047333077527582645,
-0.0010669149924069643,
0.00018844175792764872,
-0.03676753118634224,
-0.014882097020745277,
-0.05490916222333908,
0.0016181253595277667,
0.020320860669016838,
0.03741943836212158,
0.012060272507369518,
-0.03373150900006294,
0.05677175149321556,
0.05155650153756142,
0.015841331332921982,
-0.045223694294691086,
0.0010023064678534865,
0.05300932005047798,
0.06418485939502716,
-0.015422247350215912,
0.021214904263615608,
-0.005159375257790089,
0.035351965576410294,
0.025126343593001366,
0.031515028327703476,
0.030900374054908752,
-0.0012036990374326706,
0.006309524644166231,
-0.04332385212182999,
-0.028628012165427208,
0.042578812688589096,
0.06664348393678665,
-0.020712004974484444,
-0.01878422312438488,
-0.001945242751389742,
-0.060049910098314285,
-0.00040278516826219857,
0.01732208952307701,
-0.006402654107660055,
-0.017256898805499077,
-0.015459499321877956,
0.043435607105493546,
0.009545775130391121,
0.0010360658634454012,
-0.015506064519286156,
0.011687754653394222,
-0.015794765204191208,
-0.024940084666013718,
0.04608048498630524,
0.02764084003865719,
-0.0014691180549561977,
0.04667651280760765,
-0.0096482178196311,
0.0038346077781170607,
-0.051780011504888535,
-0.05949113517999649,
-0.015841331332921982,
-0.022276580333709717,
-0.035351965576410294,
-0.009075471200048923,
0.007278071716427803,
-0.02287260815501213,
0.07942084968090057,
0.009666843339800835,
-0.014230189844965935,
-0.02926129288971424,
-0.02743595466017723,
0.08724372833967209,
-0.05472290515899658,
0.03691653907299042,
-0.02114040032029152,
-0.03654402121901512,
-0.0007648261380381882,
-0.00403017969802022,
0.025927256792783737,
0.007357231806963682,
-0.004693727474659681,
0.043510109186172485,
-0.0015901864971965551,
-0.009983483701944351,
-0.017629416659474373,
0.023096119984984398,
-0.026374278590083122,
0.046266742050647736,
-0.051705505698919296,
-0.03937515988945961,
0.019445443525910378,
0.04749605432152748,
0.03276296332478523,
0.028944652527570724,
0.07200773805379868,
0.001933601568453014,
0.06861782819032669,
-0.00733860582113266,
-0.02829274721443653,
-0.04138675704598427,
0.009038219228386879,
0.07785627245903015,
0.003678615903481841,
0.004025523085147142,
-0.028218243271112442,
0.004346820060163736,
0.01568301022052765,
-0.0006821737042628229,
-0.014584082178771496,
-0.00002495579974493012,
0.02391565963625908,
0.04056721553206444,
-0.028944652527570724,
-0.022555967792868614,
-0.019687579944729805,
-0.0038974701892584562,
-0.01380179449915886,
0.0020989065524190664,
-0.028143739327788353,
0.02372940070927143,
0.020842386409640312,
-0.011296610347926617,
-0.03790371119976044,
-0.07383307814598083,
-0.008856616914272308,
-0.023990163579583168,
-0.008949746377766132,
-0.05524442717432976,
-0.04656475782394409,
-0.03844386339187622,
-0.05569145083427429,
0.007580742705613375,
0.001137344166636467,
-0.00808829814195633,
0.030043581500649452,
-0.007385170552879572,
0.0017671325476840138,
-0.029689690098166466,
0.035165704786777496,
-0.02829274721443653,
-0.04954490065574646,
-0.015096294693648815,
-0.010644703172147274,
0.045372698456048965,
-0.06299280375242233,
0.025890005752444267,
0.005755404010415077,
-0.050736960023641586,
0.042727820575237274,
-0.0785268098115921,
-0.014015992172062397,
-0.02486558072268963,
-0.022369708865880966,
-0.03399227187037468,
0.011454930528998375,
0.03915164992213249,
-0.07390758395195007,
0.03218556195497513,
-0.03302372619509697,
0.03399227187037468,
0.016586367040872574,
0.013894923962652683,
-0.005531893111765385,
0.026132142171263695,
0.06623370945453644,
-0.04459041357040405,
0.005736778024584055,
-0.013252330012619495,
-0.03829485550522804,
-0.005573801696300507,
-0.0009877549018710852,
0.05949113517999649,
0.028590761125087738,
-0.0027496488764882088,
0.04157301411032677,
0.00641196733340621,
-0.03734493628144264,
0.02371077425777912,
-0.02017185278236866,
-0.050811462104320526,
-0.046229492872953415,
-0.009289668872952461,
-0.0024632757995277643,
-0.025275349617004395,
-0.0762544497847557,
0.03116113506257534,
0.048054829239845276,
-0.011166228912770748,
0.015105606988072395,
0.02572237141430378,
0.03730768337845802,
0.012637674808502197,
-0.016707435250282288,
0.02203444391489029,
-0.010793711058795452,
-0.006537692155689001,
0.009494554251432419,
0.02667229250073433,
0.021606046706438065,
0.006709981709718704,
0.0007467822870239615,
0.05755404010415077,
0.023543141782283783,
-0.028106488287448883,
0.02205306850373745,
-0.017536288127303123,
0.010654016397893429,
-0.004195484798401594,
-0.04190828278660774,
-0.01377385575324297,
0.008339747786521912,
-0.03220418468117714,
0.018774909898638725,
0.02667229250073433,
-0.00023980850528459996,
-0.1064656600356102,
0.035333339124917984,
-0.09827026724815369,
0.02298436500132084,
-0.028963278979063034,
-0.014993852004408836,
0.026281150057911873,
0.019557198509573936,
0.07081568241119385,
-0.027882976457476616,
0.005094184540212154,
-0.049023378640413284,
-0.08307152986526489,
0.019929716363549232,
0.017098579555749893,
0.05852258577942848,
0.03695379197597504,
0.07334880530834198,
-0.041647519916296005,
0.018188195303082466,
0.015468812547624111,
-0.061987005174160004,
-0.030453352257609367,
0.02397153712809086,
0.04205729067325592,
0.08396556973457336,
-0.06399860233068466,
-0.014164999127388,
-0.00201508984901011,
-0.0330796055495739,
-0.014248816296458244,
0.029913200065493584,
-0.00479617016389966,
0.035091202706098557,
0.02570374682545662,
0.0038578901439905167,
-0.048129335045814514,
0.03024846687912941,
-0.035221584141254425,
0.020823759958148003,
0.008400281891226768,
0.030825870111584663,
-0.015813391655683517,
-0.00242602382786572,
0.04585697501897812,
0.03125426545739174,
0.006938148755580187,
-0.0385928712785244,
0.05617572367191315,
-0.02209032140672207,
-0.01559919398277998,
-0.0015540987951681018,
-0.023654896765947342,
-0.024325428530573845,
-0.018113691359758377,
-0.03123563900589943,
-0.048948872834444046,
-0.021680550649762154,
0.009927606210112572,
-0.0030057551339268684,
0.0008701789192855358,
0.0583735816180706
]
|
31,074 | networkx.generators.community | relaxed_caveman_graph | Returns a relaxed caveman graph.
A relaxed caveman graph starts with `l` cliques of size `k`. Edges are
then randomly rewired with probability `p` to link different cliques.
Parameters
----------
l : int
Number of groups
k : int
Size of cliques
p : float
Probability of rewiring each edge.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
G : NetworkX Graph
Relaxed Caveman Graph
Raises
------
NetworkXError
If p is not in [0,1]
Examples
--------
>>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)
References
----------
.. [1] Santo Fortunato, Community Detection in Graphs,
Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
https://arxiv.org/abs/0906.0612
| 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)
| (l, k, p, seed=None, *, backend=None, **backend_kwargs) | [
-0.0020576873794198036,
0.02577221766114235,
-0.03886053338646889,
-0.01566186174750328,
0.005983492825180292,
0.06000037118792534,
-0.03411785885691643,
-0.041801728308200836,
0.0538606271147728,
-0.012205957435071468,
-0.020000124350190163,
0.01988982781767845,
-0.003311141859740019,
0.051360610872507095,
-0.010119548067450523,
0.01528502069413662,
0.010891611687839031,
-0.04125025495886803,
0.020753804594278336,
0.03413623943924904,
-0.011801543645560741,
-0.018520334735512733,
-0.011626910418272018,
0.01685672253370285,
-0.0360296331346035,
0.02704060822725296,
0.0228310227394104,
0.008239940740168095,
-0.05507386848330498,
-0.0011500531109049916,
-0.026103101670742035,
-0.01560671441257,
-0.02216925472021103,
-0.009880575351417065,
0.0026792443823069334,
0.05327238887548447,
0.03722449392080307,
0.08330933749675751,
-0.01348353922367096,
-0.024375149980187416,
-0.018970705568790436,
-0.0492282435297966,
0.0064522456377744675,
-0.013943100348114967,
0.011332790367305279,
0.018878793343901634,
0.012674710713326931,
0.05577240139245987,
-0.06632393598556519,
-0.050294429063797,
0.010634256526827812,
-0.03617669269442558,
0.034595802426338196,
0.0016360394656658173,
-0.0269303135573864,
0.01228867843747139,
0.0007944672252051532,
0.03856641426682472,
0.06514745950698853,
0.005142495036125183,
-0.014586486853659153,
-0.0023253820836544037,
0.017490915954113007,
-0.009687559679150581,
-0.06665482372045517,
0.001163265435025096,
-0.06834600865840912,
-0.03915465250611305,
0.03687522932887077,
0.06345627456903458,
0.07433869689702988,
0.04371350631117821,
-0.002022071275860071,
0.012693093158304691,
0.0699269026517868,
0.045294396579265594,
-0.00010763795580714941,
0.0027734546456485987,
-0.005183855537325144,
-0.05823565274477005,
0.02045968547463417,
0.016847530379891396,
0.020827334374189377,
-0.01078131701797247,
0.06977984309196472,
-0.004200393799692392,
0.03375020995736122,
0.008382405154407024,
-0.009411823004484177,
-0.046617936342954636,
0.02275749295949936,
0.001817566342651844,
0.04202231764793396,
-0.03615831211209297,
0.0006767045706510544,
0.059154778718948364,
-0.01808834634721279,
-0.03386050462722778,
0.036250222474336624,
-0.03474286198616028,
0.04621351882815361,
-0.006318972911685705,
-0.06275773793458939,
0.019981741905212402,
-0.020882481709122658,
-0.05536798760294914,
0.001038034912198782,
0.0028263041749596596,
-0.002265638904646039,
-0.033327411860227585,
-0.07536811381578445,
0.0454782210290432,
0.05444886535406113,
-0.0049494788981974125,
0.010882420465350151,
-0.0014579594135284424,
-0.005739924963563681,
0.00957726500928402,
0.013750084675848484,
0.007325412705540657,
-0.041139960289001465,
0.03117666393518448,
-0.021801605820655823,
0.025606775656342506,
0.01440266240388155,
0.009237189777195454,
0.02823546901345253,
0.011176539584994316,
0.032187700271606445,
-0.02290455251932144,
0.02154425159096718,
-0.01613980531692505,
0.005422827787697315,
0.02045968547463417,
-0.003511051181703806,
-0.04202231764793396,
-0.10338298976421356,
-0.0365627259016037,
0.048272356390953064,
0.0061213611625134945,
-0.01263794582337141,
-0.02761046402156353,
-0.017095694318413734,
0.044081155210733414,
0.009466970339417458,
0.04158113896846771,
0.01085484679788351,
-0.02047806791961193,
0.005372275598347187,
0.008267514407634735,
0.044228214770555496,
-0.004620892461389303,
-0.012435738928616047,
-0.045257631689310074,
-0.03159945830702782,
-0.006323568522930145,
-0.016976207494735718,
-0.029871508479118347,
-0.0020530917681753635,
0.019614091143012047,
-0.024209707975387573,
0.025036919862031937,
-0.026195013895630836,
0.05125031620264053,
-0.009103916585445404,
-0.037022288888692856,
0.06062537431716919,
-0.016847530379891396,
-0.06180185079574585,
-0.027261197566986084,
-0.011185730807483196,
-0.029191356152296066,
-0.03790464624762535,
-0.058529771864414215,
0.030349452048540115,
-0.048934124410152435,
0.020018506795167923,
0.00021240365458652377,
-0.03856641426682472,
0.010615874081850052,
-0.0358458086848259,
-0.009172851219773293,
-0.015165534801781178,
-0.021250130608677864,
-0.0037867880892008543,
0.05220620334148407,
0.05444886535406113,
-0.007380560506135225,
0.05514739826321602,
-0.040514957159757614,
-0.04448556900024414,
-0.042831145226955414,
-0.05099296197295189,
0.0770592987537384,
-0.0013200908433645964,
0.014568104408681393,
-0.0246141217648983,
0.028547970578074455,
-0.10632418841123581,
0.028400911018252373,
0.007155375089496374,
0.022536903619766235,
0.005583674181252718,
-0.049412067979574203,
0.03558845445513725,
-0.022481756284832954,
-0.034062709659338,
-0.030312687158584595,
0.051287081092596054,
0.03242667019367218,
0.014301558956503868,
-0.024411914870142937,
0.07838283479213715,
0.02163616381585598,
0.015165534801781178,
-0.0397796556353569,
0.017886139452457428,
0.003832744201645255,
-0.014549721963703632,
-0.04937530308961868,
-0.0012212850851938128,
-0.03000018559396267,
0.05691211670637131,
-0.03165460750460625,
0.022022195160388947,
-0.034503888338804245,
-0.015882451087236404,
-0.05099296197295189,
-0.04194878786802292,
-0.0113695552572608,
0.06341950595378876,
-0.039375241845846176,
0.024209707975387573,
-0.00006591837882297114,
-0.022500138729810715,
-0.016994589939713478,
0.01655341126024723,
-0.006273016799241304,
-0.023915588855743408,
0.04426497966051102,
-0.08647112548351288,
-0.015413697808980942,
0.02393397130072117,
0.01708650216460228,
0.036268606781959534,
0.05507386848330498,
-0.007913651876151562,
-0.0026172036305069923,
-0.02045968547463417,
0.02709575556218624,
-0.021158218383789062,
-0.06654452532529831,
-0.027353109791874886,
-0.06584599614143372,
0.03948553651571274,
-0.0741916373372078,
-0.05639740824699402,
0.007274860981851816,
0.01138793770223856,
-0.0253310389816761,
-0.02882370725274086,
-0.031047984957695007,
-0.04613998904824257,
0.07875048369169235,
0.005101134534925222,
-0.03305167332291603,
0.0018405443988740444,
0.07242691516876221,
-0.07007396221160889,
0.007017506752163172,
0.040037013590335846,
0.050698842853307724,
0.04911794885993004,
-0.010422858409583569,
0.0007588511798530817,
-0.013060742057859898,
-0.018823646008968353,
0.00868571549654007,
0.012187574990093708,
0.05356650799512863,
0.011066244915127754,
0.042095847427845,
-0.03715096414089203,
-0.0019037341699004173,
-0.0021013456862419844,
0.01873173378407955,
-0.024228090420365334,
-0.02091924659907818,
-0.00784012209624052,
-0.012729858048260212,
-0.002394316252321005,
-0.020257478579878807,
-0.002991746412590146,
-0.003246803069487214,
0.04257379099726677,
0.010229842737317085,
0.03490830212831497,
0.018768498674035072,
0.026691341772675514,
0.033952414989471436,
0.04698558524250984,
-0.041066430509090424,
-0.03718772903084755,
-0.004147544037550688,
0.03715096414089203,
-0.015064431354403496,
-0.004400303121656179,
-0.049632661044597626,
0.01644311659038067,
0.03555168956518173,
-0.04025760293006897,
-0.012729858048260212,
0.04680176079273224,
0.029191356152296066,
0.02948547527194023,
0.004138352815061808,
0.016415541991591454,
-0.025018537417054176,
0.026654576882719994,
0.07139749825000763,
-0.013603025116026402,
-0.002405805280432105,
-0.020717039704322815,
0.00338696944527328,
-0.05463268980383873,
-0.010413667187094688,
-0.026011189445853233,
0.041654668748378754,
-0.0021059412974864244,
-0.00872248038649559,
-0.05705917626619339,
-0.038676708936691284,
0.04871353507041931,
0.04669146612286568,
-0.010441240854561329,
0.036360517144203186,
0.07253721356391907,
-0.07007396221160889,
0.04930177330970764,
-0.07786812633275986,
0.020312625914812088,
-0.007330008316785097,
-0.07014749199151993,
-0.005638821516185999,
0.0011012246832251549,
-0.007385156117379665,
0.03432006388902664,
-0.01744496077299118,
-0.043566446751356125,
-0.018805263563990593,
0.022647198289632797,
0.10169180482625961,
0.01227948721498251,
0.07250044494867325,
0.004239456262439489,
0.11029479652643204,
-0.005473379511386156,
-0.02878694236278534,
0.018106728792190552,
0.028713412582874298,
-0.05338268354535103,
-0.0060616182163357735,
0.08264756947755814,
0.02761046402156353,
-0.03897082805633545,
-0.004609403666108847,
-0.009007408283650875,
0.005124112591147423,
0.08838289976119995,
-0.07617694139480591,
-0.00480241933837533,
-0.01591002382338047,
-0.04500027745962143,
0.030367834493517876,
-0.03904435783624649,
0.008644354529678822,
-0.11529482901096344,
0.015726199373602867,
-0.021801605820655823,
0.0006198337650857866,
-0.034062709659338,
-0.022683963179588318,
0.03380535542964935,
0.0395958311855793,
0.004122267942875624,
-0.05341944843530655,
0.0551106333732605,
0.02047806791961193,
0.0019761151634156704,
0.025570010766386986,
-0.031029602512717247,
-0.007775783538818359,
0.018989088013768196,
0.04610322415828705,
0.007872290909290314,
0.013777658343315125,
0.07036808133125305,
-0.007803357206285,
-0.05864006653428078,
0.03360315039753914,
0.03604801744222641,
-0.0020990478806197643,
0.010744551196694374,
0.05308856442570686,
-0.034577418118715286,
-0.022978082299232483,
0.03200387582182884,
0.013713319785892963,
0.014117734506726265,
0.03801494091749191,
-0.07327251136302948,
-0.006659048609435558,
0.04683852568268776,
-0.042904675006866455,
-0.042831145226955414,
-0.06437540054321289,
-0.03354800119996071,
0.028529588133096695,
0.10705948621034622,
-0.012803387828171253,
0.09603000432252884,
-0.060882728546857834,
0.05606652423739433,
0.014145308174192905,
-0.0039246566593647,
-0.03494506701827049,
0.023860441520810127,
-0.047684118151664734,
-0.0419120229780674,
-0.017251944169402122,
-0.03255534917116165,
0.00428081676363945,
0.07305192202329636,
-0.06562540680170059,
0.04257379099726677,
-0.012987212277948856,
-0.014632442966103554,
0.01678319275379181,
-0.029687684029340744,
-0.0043037948198616505,
0.08904466778039932,
0.01740819588303566,
-0.004761058837175369,
-0.02751855179667473,
0.051912084221839905,
0.015193108469247818,
-0.020239096134901047,
-0.00996329728513956,
-0.015404506586492062,
0.03295976296067238,
0.047757647931575775,
-0.009917340241372585,
0.021967047825455666,
0.004352048970758915,
0.0013511113356798887,
0.03948553651571274,
0.05930183827877045,
0.02231631428003311,
-0.049559131264686584,
-0.01045962329953909,
0.09544176608324051,
-0.032169315963983536,
-0.020845716819167137,
0.06621364504098892,
-0.01174639631062746,
0.049522366374731064,
-0.00284698442555964,
-0.0049908398650586605,
0.011654484085738659,
-0.0012029026402160525,
0.033897269517183304,
0.029632536694407463,
-0.030165627598762512,
-0.07227985560894012,
-0.02821708656847477,
-0.03672816976904869,
-0.07750047743320465,
0.008768436498939991,
-0.01532178558409214,
-0.006171912886202335,
-0.015735391527414322,
-0.005197642371058464,
0.06073566898703575,
-0.009531308896839619,
-0.039264947175979614,
-0.04900765419006348,
-0.0016383372712880373,
-0.03680169954895973,
-0.01142470259219408,
0.012123236432671547,
-0.01615818776190281,
-0.09139762073755264,
0.014016631059348583,
0.005087347701191902,
0.037003904581069946,
0.009954105131328106,
0.0019669239409267902,
-0.02647075243294239,
0.03619507700204849,
-0.005491761956363916,
0.015128769911825657,
0.04680176079273224,
0.03163622319698334,
-0.03597448766231537,
0.05691211670637131,
0.01585487648844719,
0.021213365718722343,
-0.04573557525873184,
-0.0504782535135746,
0.0017830992583185434,
0.015735391527414322,
0.00048253973363898695,
-0.0010483750374987721,
-0.022665580734610558,
0.02816193923354149,
0.02047806791961193,
0.04930177330970764,
0.03198549151420593,
0.022647198289632797,
-0.006475223693996668,
0.020661892369389534,
0.047095879912376404,
-0.023198673501610756,
0.09338293224573135,
-0.01746334321796894,
0.00011323886428726837,
-0.01805158145725727,
-0.0454782210290432,
-0.02106630615890026,
0.01751849055290222,
-0.02584574744105339,
0.011001906357705593,
-0.03893406316637993,
0.05724300071597099,
0.023676617071032524,
-0.02272072806954384,
-0.011277643032371998,
0.02590089477598667,
0.05231649801135063,
0.011875073425471783,
-0.02224278450012207,
-0.016525836661458015,
0.04485321789979935,
0.009944913908839226,
0.0010311414953321218,
0.03123181127011776,
0.028437675908207893,
0.020625127479434013,
0.004871353507041931,
-0.03724287822842598,
-0.042279671877622604,
0.04202231764793396,
-0.033235497772693634,
-0.012830961495637894,
0.09000055491924286,
-0.04099290072917938,
-0.03955906629562378,
-0.04992678016424179,
0.03845611959695816,
0.07084602862596512,
0.007541406899690628,
-0.02832738123834133,
-0.06746365129947662,
-0.0054366146214306355,
0.03687522932887077,
0.0117280138656497,
-0.016369586810469627,
-0.04147084429860115,
0.008244535885751247,
0.0034099475014954805,
0.017775844782590866,
-0.010091974399983883,
-0.03652596101164818,
0.0063373553566634655,
-0.010018444620072842,
-0.03123181127011776,
-0.04680176079273224,
-0.017913714051246643,
0.01083646435290575,
-0.010082783177495003,
-0.02286778762936592,
0.022095724940299988,
0.0758092924952507,
-0.03498183190822601,
0.04202231764793396,
0.045919399708509445,
-0.09117703139781952,
-0.040514957159757614,
0.021194983273744583,
0.038787003606557846,
0.028051644563674927,
0.003242207458242774,
-0.021819988265633583,
-0.010358519852161407,
-0.06757394969463348,
-0.001300559495575726,
0.011626910418272018,
-0.008033137768507004,
-0.02829061634838581,
-0.03557007387280464,
-0.056140054017305374,
0.026213396340608597,
0.003926954232156277,
0.05591946467757225,
0.027831053361296654,
-0.013639790005981922,
-0.04867677018046379,
-0.032684024423360825,
0.012371400371193886,
0.030809013172984123,
-0.04371350631117821,
0.02277587540447712,
-0.014981710352003574,
-0.06871365755796432,
-0.0030285113025456667,
-0.0385296493768692,
-0.02520236186683178,
0.006861255504190922,
0.019577326253056526,
-0.05161796510219574,
0.023198673501610756,
-0.00024284962273668498,
0.006663644220679998,
-0.021342042833566666,
-0.016204144805669785,
0.024981772527098656,
-0.023106759414076805,
-0.0021254727616906166,
0.02218763716518879,
0.03001856803894043,
-0.0030905522871762514,
-0.011029480025172234,
0.03919141739606857,
-0.02091924659907818,
0.02406264841556549,
-0.028437675908207893,
0.024228090420365334,
0.0024885262828320265,
0.010128739289939404,
-0.005579078570008278,
-0.020128801465034485,
0.04522086679935455,
-0.017757462337613106,
-0.0766916498541832,
-0.10676536709070206,
-0.0011322450591251254,
0.03292299807071686,
0.051397375762462616,
0.0006548753590323031,
0.02049645036458969,
0.007127801422029734,
-0.0006364929140545428,
0.05474298447370529,
-0.05389739200472832,
0.01475192978978157,
-0.028547970578074455,
-0.035735514014959335,
0.028529588133096695,
0.04301496967673302,
-0.048970889300107956,
0.029724448919296265,
0.04433850944042206,
0.06051507964730263,
-0.0047151027247309685,
0.008648950606584549,
0.022941317409276962,
0.01860305666923523,
-0.013354862108826637,
-0.027978114783763885,
0.038088470697402954,
-0.045331161469221115,
-0.012748240493237972,
0.0651106983423233,
-0.016700470820069313,
-0.03711419925093651,
0.04187525808811188,
-0.04128701984882355,
0.01444861851632595,
-0.038051705807447433,
0.0406620167195797,
0.02759208157658577,
0.02334573306143284,
-0.03483477234840393,
-0.00033662893110886216,
-0.0067831301130354404,
-0.005533122457563877,
-0.03479800745844841,
-0.05330915376543999,
-0.011865882202982903,
0.005822646431624889,
0.009103916585445404,
-0.010615874081850052,
-0.005036795977503061,
-0.025459716096520424,
-0.028070027008652687,
0.045257631689310074,
-0.03356638550758362,
0.00003218726851628162,
0.005353893153369427,
0.01349273044615984,
0.05562534183263779,
0.028364146128296852,
-0.008658141829073429,
0.04628705233335495,
-0.021875135600566864,
-0.02409941330552101,
-0.0395958311855793,
0.05360327288508415,
0.028934001922607422,
0.0116820577532053,
-0.020680274814367294,
-0.00871328916400671,
0.00015955406706780195,
0.006603901274502277,
-0.03764729201793671,
-0.022555286064743996,
0.02457735687494278,
0.09919179230928421,
-0.012527651153504848,
-0.007467877119779587,
0.009816236793994904,
0.02051483280956745,
0.033842120319604874,
-0.002529887016862631,
-0.061029788106679916,
-0.02051483280956745,
0.05411798134446144,
-0.02768399380147457,
0.03830906003713608,
-0.028070027008652687,
-0.028989149257540703,
0.08117697387933731,
-0.024356767535209656,
0.04272085055708885,
-0.009476161561906338,
-0.05691211670637131,
-0.018382467329502106,
0.02580898255109787,
-0.047132644802331924,
0.003182464512065053,
-0.06669158488512039,
0.009779471904039383,
-0.04044142737984657,
0.00855244230479002,
-0.023566322401165962,
-0.02757369913160801,
0.04375027120113373,
0.009935722686350346,
-0.006075405050069094,
-0.02093762904405594,
0.007192139979451895,
-0.0023024040274322033,
0.023768529295921326,
0.00764710595831275,
-0.04643411189317703,
-0.03687522932887077,
0.0035294336266815662,
-0.054265040904283524,
-0.05415474623441696,
-0.07566223293542862,
-0.006865851115435362,
0.01260118093341589,
-0.006369524635374546,
-0.002794134896248579,
-0.00797339528799057,
0.041139960289001465,
0.039963483810424805,
0.023033229634165764
]
|
31,076 | networkx.drawing.layout | rescale_layout | Returns scaled position array to (-scale, scale) in all axes.
The function acts on NumPy arrays which hold position information.
Each position is one row of the array. The dimension of the space
equals the number of columns. Each coordinate in one column.
To rescale, the mean (center) is subtracted from each axis separately.
Then all values are scaled so that the largest magnitude value
from all axes equals `scale` (thus, the aspect ratio is preserved).
The resulting NumPy Array is returned (order of rows unchanged).
Parameters
----------
pos : numpy array
positions to be scaled. Each row is a position.
scale : number (default: 1)
The size of the resulting extent in all directions.
Returns
-------
pos : numpy array
scaled positions. Each row is a position.
See Also
--------
rescale_layout_dict
| def rescale_layout(pos, scale=1):
"""Returns scaled position array to (-scale, scale) in all axes.
The function acts on NumPy arrays which hold position information.
Each position is one row of the array. The dimension of the space
equals the number of columns. Each coordinate in one column.
To rescale, the mean (center) is subtracted from each axis separately.
Then all values are scaled so that the largest magnitude value
from all axes equals `scale` (thus, the aspect ratio is preserved).
The resulting NumPy Array is returned (order of rows unchanged).
Parameters
----------
pos : numpy array
positions to be scaled. Each row is a position.
scale : number (default: 1)
The size of the resulting extent in all directions.
Returns
-------
pos : numpy array
scaled positions. Each row is a position.
See Also
--------
rescale_layout_dict
"""
import numpy as np
# Find max length over all dimensions
pos -= pos.mean(axis=0)
lim = np.abs(pos).max() # max coordinate for all axes
# rescale to (-scale, scale) in all directions, preserves aspect
if lim > 0:
pos *= scale / lim
return pos
| (pos, scale=1) | [
0.05194149166345596,
-0.03870292007923126,
-0.004973506089299917,
-0.006510771811008453,
-0.005412078928202391,
0.011402892880141735,
0.02776120789349079,
-0.04362216964364052,
-0.030455943197011948,
0.01567106507718563,
0.0001392440462950617,
-0.02707395888864994,
0.03794332966208458,
0.02595265954732895,
-0.019640827551484108,
0.0092281149700284,
0.062033187597990036,
0.008956832811236382,
-0.022914299741387367,
0.02539200894534588,
0.07190785557031631,
-0.024270709604024887,
0.06528857350349426,
0.016123203560709953,
-0.010598089545965195,
0.04944569244980812,
0.008667465299367905,
-0.032174061983823776,
0.042681727558374405,
-0.040511470288038254,
0.02707395888864994,
0.07342703640460968,
0.05309896171092987,
0.025229239836335182,
-0.018808895722031593,
0.02132277749478817,
-0.01542691234499216,
0.008920661173760891,
-0.026440966874361038,
-0.001241115853190422,
0.007831011898815632,
0.007840054109692574,
0.03190278261899948,
-0.020472759380936623,
0.08109527826309204,
0.07093124091625214,
-0.005280959419906139,
0.0033638987224549055,
-0.029009105637669563,
0.03300599381327629,
0.05165212228894234,
0.02157597430050373,
0.006180711556226015,
-0.012596534565091133,
-0.023836659267544746,
0.030871909111738205,
-0.026061171665787697,
0.07783989608287811,
0.05660754442214966,
-0.07064187526702881,
0.04915632680058479,
0.009404447861015797,
-0.04890312999486923,
-0.02385474368929863,
0.011972585693001747,
-0.039209313690662384,
0.005403036251664162,
-0.0325719453394413,
-0.003908723592758179,
-0.00481977965682745,
-0.05129041150212288,
-0.0028032490517944098,
-0.01174651738256216,
-0.02626011334359646,
0.022950470447540283,
0.04047529771924019,
0.04315194860100746,
0.03306025266647339,
0.006940301973372698,
0.011167782358825207,
-0.016177458688616753,
0.005859694443643093,
0.08543579280376434,
0.03740076720714569,
0.04344131425023079,
-0.0037776040844619274,
0.0414157435297966,
0.05866928771138191,
0.023945171386003494,
-0.0030180139001458883,
0.04405622184276581,
-0.016376400366425514,
0.07407811284065247,
0.021340863779187202,
-0.04474347084760666,
0.024614334106445312,
0.009323063306510448,
0.02354729175567627,
-0.008414268493652344,
-0.03164958581328392,
-0.028882507234811783,
0.03121553361415863,
-0.048541419208049774,
-0.05024145543575287,
-0.06608433276414871,
0.09324871748685837,
0.04702224209904671,
-0.005412078928202391,
-0.019116349518299103,
0.05313513055443764,
0.03490497171878815,
0.060116127133369446,
-0.020291905850172043,
0.02477710321545601,
-0.05877780169248581,
-0.062322553247213364,
-0.056824568659067154,
-0.01597851887345314,
-0.0014129278715699911,
-0.010136909782886505,
-0.0563543476164341,
0.0034249371383339167,
0.014007202349603176,
-0.015336484648287296,
-0.0020470500458031893,
-0.002927586669102311,
0.001663863891735673,
0.01545403990894556,
0.01458593737334013,
-0.01592426188290119,
-0.06782054156064987,
-0.05906716734170914,
-0.03870292007923126,
0.013464638032019138,
0.036677345633506775,
-0.05906716734170914,
0.023203667253255844,
0.02108766697347164,
-0.035682644695043564,
0.0008805366815067828,
0.0020527015440165997,
0.06601198762655258,
-0.001372235594317317,
0.015634894371032715,
-0.02508455701172352,
-0.01325665507465601,
0.10410000383853912,
0.012515150010585785,
-0.016367357224225998,
-0.03627946600317955,
0.030817652121186256,
-0.03146873041987419,
0.01022733747959137,
-0.036568835377693176,
0.07501856237649918,
-0.038919948041439056,
-0.005118189845234156,
-0.057077765464782715,
-0.02620585635304451,
0.0341634675860405,
-0.03924548625946045,
0.003865770762786269,
-0.024614334106445312,
-0.047311607748270035,
-0.030510200187563896,
0.03137830272316933,
0.0009037086856551468,
-0.012867816723883152,
-0.019803596660494804,
0.04315194860100746,
0.00619879737496376,
0.03769013285636902,
-0.013564107939600945,
-0.0384497232735157,
0.07538026571273804,
0.01523701474070549,
-0.014115714468061924,
-0.009160294197499752,
-0.009377320297062397,
0.0029886250849813223,
0.013564107939600945,
-0.0077451057732105255,
0.07270361483097076,
0.029877208173274994,
0.0077541484497487545,
0.039715707302093506,
-0.027309071272611618,
0.0339464396238327,
-0.022136623039841652,
-0.056028809398412704,
-0.03331344947218895,
0.024759018793702126,
-0.01298537291586399,
-0.049915917217731476,
-0.04503283649682999,
0.03714757040143013,
-0.07595900446176529,
0.0032825141679495573,
0.03910079970955849,
-0.026422882452607155,
-0.017732810229063034,
-0.005181489046663046,
0.06420344114303589,
0.016674809157848358,
0.001582479220815003,
0.013880603946745396,
0.042609382420778275,
-0.016502996906638145,
0.0053985146805644035,
-0.009657644666731358,
-0.0370752289891243,
0.031486816704273224,
-0.017877494916319847,
-0.0695929154753685,
0.037111397832632065,
0.02786972001194954,
-0.01718120276927948,
-0.017597168684005737,
0.008043515495955944,
0.06901417672634125,
-0.01649395562708378,
0.022606845945119858,
-0.007758669555187225,
-0.0015700454823672771,
-0.010335850529372692,
-0.01542691234499216,
0.06102040037512779,
-0.05592029541730881,
0.03184852376580238,
-0.00852730218321085,
0.007699891924858093,
-0.1140831857919693,
0.009603388607501984,
-0.051579780876636505,
0.05067550763487816,
-0.003348073922097683,
0.007103071082383394,
0.004369903355836868,
0.05396706238389015,
0.02768886461853981,
-0.0018774985801428556,
0.034507088363170624,
-0.07624837011098862,
0.03599010035395622,
-0.016674809157848358,
0.033837929368019104,
0.03714757040143013,
-0.0038273390382528305,
-0.024759018793702126,
-0.04264555498957634,
-0.017660468816757202,
-0.02947932668030262,
0.00022790527145843953,
0.01646682620048523,
0.05056699365377426,
0.01649395562708378,
-0.045466888695955276,
0.05407557636499405,
-0.0008488870807923377,
-0.0059365578927099705,
-0.029226131737232208,
-0.03808801621198654,
-0.0035786638036370277,
-0.07422279566526413,
0.03608052805066109,
-0.004489719867706299,
0.02311323955655098,
0.019803596660494804,
0.009820413775742054,
0.033476218581199646,
0.0678928792476654,
0.05125424265861511,
-0.004770044703036547,
0.026350539177656174,
0.013726877048611641,
0.055775612592697144,
0.004661531653255224,
-0.015255100093781948,
0.09086143970489502,
0.0041506169363856316,
-0.03121553361415863,
-0.056643713265657425,
0.012053970247507095,
0.02781546302139759,
0.06713329255580902,
-0.07190785557031631,
0.013048672117292881,
-0.006361566483974457,
-0.01050766184926033,
0.062141697853803635,
-0.01618650183081627,
0.0034430227242410183,
-0.0413072295486927,
-0.04622647911310196,
-0.0782739445567131,
-0.021539803594350815,
0.011276294477283955,
-0.05946504697203636,
-0.020165307447314262,
-0.009802328422665596,
-0.0035741424653679132,
-0.022570675238966942,
-0.006451993715018034,
0.04043912515044212,
0.0782739445567131,
0.02768886461853981,
-0.02861122414469719,
-0.049662720412015915,
0.0011868594447150826,
0.003662309143692255,
-0.05729478970170021,
-0.012831646017730236,
-0.07697179168462753,
0.010598089545965195,
0.00027877066168002784,
0.03360281512141228,
0.05982675775885582,
0.005728574935346842,
0.049228668212890625,
0.01917060650885105,
-0.04814353957772255,
0.03743693605065346,
-0.062394894659519196,
0.017542913556098938,
0.017913665622472763,
0.0018921929877251387,
-0.03635180741548538,
0.006940301973372698,
0.0593203641474247,
0.0005109147168695927,
0.0037866467610001564,
0.01728067360818386,
-0.03765396401286125,
-0.02040041796863079,
-0.06774819642305374,
-0.11039375513792038,
0.014676365070044994,
0.045141350477933884,
-0.010335850529372692,
-0.035628389567136765,
-0.036677345633506775,
-0.008961353451013565,
-0.027471840381622314,
-0.02181108482182026,
0.0383412130177021,
-0.002927586669102311,
-0.001316848793067038,
0.0016039557522162795,
-0.01825728826224804,
0.002947932807728648,
0.014766791835427284,
-0.019062092527747154,
-0.059175681322813034,
-0.05150743946433067,
-0.0296059250831604,
-0.002004096983000636,
0.03369324281811714,
-0.0503137968480587,
0.017597168684005737,
-0.03320493549108505,
0.07190785557031631,
-0.03660500422120094,
-0.028231428936123848,
-0.05082019045948982,
-0.01756099797785282,
0.012343337759375572,
-0.02244407683610916,
-0.08037185668945312,
0.0816740170121193,
0.03584541380405426,
0.021594058722257614,
-0.01976742595434189,
-0.03184852376580238,
0.015155630186200142,
-0.0355922169983387,
0.04148808494210243,
-0.07762286812067032,
-0.00793952401727438,
-0.02720055729150772,
0.015526382252573967,
0.047926515340805054,
-0.03747310861945152,
0.05208617448806763,
-0.002633697586134076,
0.06604816019535065,
0.005864216014742851,
0.028972934931516647,
0.020002538338303566,
-0.07588665932416916,
-0.014495509676635265,
-0.0444902740418911,
0.03939016908407211,
-0.010372021235525608,
-0.006329916883260012,
-0.03398261219263077,
0.02182917110621929,
-0.0682184174656868,
0.07205253839492798,
-0.0473477803170681,
0.021051494404673576,
-0.03047402948141098,
0.031360216438770294,
0.017398228868842125,
-0.011348636820912361,
-0.04246469959616661,
-0.02935273014008999,
-0.014115714468061924,
0.046624358743429184,
0.010923627763986588,
0.11198527365922928,
0.03168575465679169,
0.03676777333021164,
0.02193768322467804,
-0.06601198762655258,
0.005570326931774616,
-0.007898831740021706,
-0.017172159627079964,
0.017542913556098938,
-0.019080178812146187,
-0.027797378599643707,
-0.07776755094528198,
0.04673287272453308,
-0.0005171315860934556,
0.04061998054385185,
0.006741361692547798,
-0.06601198762655258,
0.002418932504951954,
-0.04109020531177521,
-0.009531046263873577,
0.05353301391005516,
-0.008997525088489056,
-0.021557888016104698,
-0.011836945079267025,
0.007008122280240059,
0.023221751675009727,
-0.05964590236544609,
0.03769013285636902,
0.0663013607263565,
-0.08290382474660873,
0.032047465443611145,
0.017172159627079964,
0.01976742595434189,
-0.0029411506839096546,
0.009006567299365997,
0.055667098611593246,
-0.008599644526839256,
-0.03651457652449608,
-0.00845043919980526,
-0.035429447889328,
-0.022950470447540283,
0.04604562371969223,
0.006917695049196482,
0.06901417672634125,
-0.009775199927389622,
0.005674318410456181,
-0.07368023693561554,
-0.012913030572235584,
-0.04018592834472656,
-0.021395118907094002,
-0.013102928176522255,
0.04105403274297714,
0.0000634404641459696,
-0.07335469126701355,
-0.020599357783794403,
0.054111748933792114,
0.04930100962519646,
0.03157724440097809,
0.03826886788010597,
0.023203667253255844,
-0.009323063306510448,
0.07302915304899216,
-0.05450962856411934,
-0.0031016592402011156,
-0.04412856325507164,
-0.008215327747166157,
0.000544824986718595,
-0.01393486000597477,
0.005059412214905024,
-0.0053487797267735004,
0.0637693926692009,
-0.010344892740249634,
-0.02108766697347164,
-0.0043947710655629635,
0.0695929154753685,
-0.030871909111738205,
-0.029153788462281227,
-0.009974140673875809,
0.017579084262251854,
-0.024740932509303093,
0.05649903044104576,
-0.0005713880527764559,
-0.004055668134242296,
0.00871719978749752,
0.08087825030088425,
-0.03714757040143013,
-0.054654311388731,
-0.013654535636305809,
-0.009757114574313164,
-0.012072055600583553,
-0.02490370161831379,
0.03873909264802933,
-0.02114192210137844,
0.03794332966208458,
-0.0011834683828055859,
-0.028828250244259834,
-0.0016661245608702302,
-0.0207621268928051,
0.08398895710706711,
-0.002934368560090661,
0.03953485190868378,
-0.05700542405247688,
0.019116349518299103,
-0.03403686732053757,
-0.027471840381622314,
0.004575625527650118,
0.055160705000162125,
-0.05765650048851967,
0.03870292007923126,
0.034959226846694946,
-0.003651005681604147,
0.01764238253235817,
0.011547576636075974,
-0.027670780196785927,
0.0354837067425251,
-0.04203064739704132,
0.0005270221154205501,
0.03635180741548538,
-0.023583462461829185,
0.013527937233448029,
0.04937335103750229,
0.0006358175305649638,
0.0025545735843479633,
0.035754989832639694,
-0.018682297319173813,
0.06138210743665695,
0.024017512798309326,
-0.007966652512550354,
-0.04673287272453308,
0.009947012178599834,
0.02638671174645424,
0.0008890142198652029,
0.035194337368011475,
-0.005850651767104864,
-0.02094298228621483,
-0.014269441366195679,
0.037364594638347626,
0.003045142162591219,
-0.027471840381622314,
0.019387630745768547,
-0.05284576490521431,
-0.0022799004800617695,
0.006234968081116676,
-0.015273185446858406,
0.023872829973697662,
0.019731255248188972,
0.0244153942912817,
-0.02837611362338066,
-0.03579115867614746,
-0.029624011367559433,
-0.03349430486559868,
0.010489576496183872,
-0.008360011503100395,
0.057511817663908005,
0.02065361477434635,
-0.02824951522052288,
0.01690087839961052,
-0.047745659947395325,
0.054473455995321274,
0.05946504697203636,
0.01746152900159359,
-0.013464638032019138,
-0.014233270660042763,
0.03608052805066109,
-0.019676998257637024,
0.021250436082482338,
-0.031993210315704346,
0.05711393803358078,
-0.07321000844240189,
-0.0036555270198732615,
0.004107663873583078,
0.02287812903523445,
-0.058560773730278015,
-0.06713329255580902,
-0.015101373195648193,
0.0002192864048993215,
0.03085382468998432,
-0.01504711713641882,
0.04333280399441719,
0.013238568790256977,
0.0251026414334774,
-0.011773645877838135,
0.034199636429548264,
0.02620585635304451,
0.004824301227927208,
0.00970285851508379,
-0.06416727602481842,
0.0035967491567134857,
0.002834898419678211,
-0.016367357224225998,
0.018863152712583542,
-0.03906463086605072,
0.03620712459087372,
0.02924421615898609,
0.005959164816886187,
-0.03608052805066109,
-0.08102294057607651,
0.02712821587920189,
-0.0398242212831974,
0.005204095970839262,
0.0415242537856102,
-0.02347494848072529,
-0.005299044772982597,
-0.033403877168893814,
-0.004978027660399675,
-0.042247675359249115,
-0.019188690930604935,
-0.05060316622257233,
-0.007803883403539658,
0.01789557933807373,
-0.017217373475432396,
0.004345035646110773,
-0.007378874812275171,
-0.000316213263431564,
-0.040945518761873245,
0.0007347225327976048,
0.027598438784480095,
0.00040946650551632047,
0.023167496547102928,
-0.05414791777729988,
-0.012343337759375572,
0.015897134318947792,
0.03139638900756836,
0.0251026414334774,
-0.04109020531177521,
-0.04380302503705025,
-0.013102928176522255,
-0.034706030040979385,
-0.021033409982919693,
0.027670780196785927,
0.05259256809949875,
0.08934225887060165,
-0.05696925148367882,
0.0415242537856102,
-0.017298758029937744,
-0.0030089712236076593,
-0.019803596660494804,
-0.0006725536659359932,
-0.041379570960998535,
-0.02935273014008999,
0.031251706182956696,
0.022082367911934853,
0.01282260287553072,
-0.006650933995842934,
-0.02119617909193039,
0.07950375974178314,
0.07697179168462753,
-0.022661102935671806,
-0.0030948773492127657,
-0.01273217611014843,
-0.06449281424283981,
-0.011900244280695915,
-0.010019354522228241,
0.004399292171001434,
0.015417869202792645,
0.02750801108777523,
0.012994415126740932,
-0.04474347084760666,
0.029624011367559433,
-0.016765236854553223,
-0.0680013969540596,
0.03949868306517601,
0.027453754097223282,
-0.05827140808105469,
-0.007012643851339817,
0.015101373195648193,
0.0009455313556827605,
0.0024144111666828394,
-0.021033409982919693,
-0.042247675359249115,
-0.007921438664197922,
0.00029728002846241,
-0.01022733747959137,
0.010001269169151783,
0.05678839609026909,
0.0059862928465008736,
0.008396183140575886,
0.060116127133369446,
-0.011258209124207497,
-0.007098549511283636,
-0.016195544973015785,
0.07360789179801941,
0.00320565071888268,
-0.012497064657509327,
-0.0031129627022892237,
0.02193768322467804,
0.020382333546876907,
-0.005543198902159929,
0.025572864338755608,
-0.0040827966295182705,
0.021214265376329422,
0.010589046403765678,
-0.010091695934534073,
-0.04789034277200699,
0.02477710321545601,
-0.00435859989374876,
-0.01607798971235752,
-0.05208617448806763,
-0.0013880603946745396,
0.005601976532489061,
0.06427578628063202,
0.015969475731253624,
0.040149759501218796,
0.05241171270608902,
-0.06774819642305374,
-0.013184312731027603,
-0.059609733521938324,
-0.011185867711901665,
0.01412475761026144,
-0.022914299741387367,
0.019676998257637024,
-0.0069222161546349525,
0.007740584202110767,
0.002199646085500717,
-0.0489393025636673,
-0.007161848712712526,
-0.04105403274297714,
-0.021232349798083305,
-0.02275153063237667,
-0.018401972949504852,
-0.010245422832667828,
-0.06952057033777237,
-0.021123837679624557,
-0.0038996809162199497,
0.01530031394213438,
0.0074783447198569775,
0.055341560393571854,
-0.02546435222029686,
-0.07223339378833771,
-0.048686105757951736,
0.00621236115694046,
0.03479645773768425,
-0.031251706182956696,
0.01174651738256216,
0.002158953808248043,
-0.001232073176652193,
-0.00784909725189209,
0.019640827551484108,
0.002418932504951954,
-0.003904202254489064,
-0.02106958068907261,
0.025554779917001724,
-0.011855030432343483,
-0.01471253577619791,
-0.010697559453547001,
-0.04640733450651169,
-0.05606497824192047,
0.08232509344816208,
0.00919194333255291,
-0.006415823008865118,
-0.02372814528644085,
-0.026115428656339645,
-0.027019701898097992,
-0.06655455380678177,
0.07053335756063461,
0.018772725015878677,
-0.03725608438253403,
0.015019988641142845,
0.012289081700146198
]
|
31,077 | networkx.drawing.layout | rescale_layout_dict | Return a dictionary of scaled positions keyed by node
Parameters
----------
pos : A dictionary of positions keyed by node
scale : number (default: 1)
The size of the resulting extent in all directions.
Returns
-------
pos : A dictionary of positions keyed by node
Examples
--------
>>> import numpy as np
>>> pos = {0: np.array((0, 0)), 1: np.array((1, 1)), 2: np.array((0.5, 0.5))}
>>> nx.rescale_layout_dict(pos)
{0: array([-1., -1.]), 1: array([1., 1.]), 2: array([0., 0.])}
>>> pos = {0: np.array((0, 0)), 1: np.array((-1, 1)), 2: np.array((-0.5, 0.5))}
>>> nx.rescale_layout_dict(pos, scale=2)
{0: array([ 2., -2.]), 1: array([-2., 2.]), 2: array([0., 0.])}
See Also
--------
rescale_layout
| def rescale_layout_dict(pos, scale=1):
"""Return a dictionary of scaled positions keyed by node
Parameters
----------
pos : A dictionary of positions keyed by node
scale : number (default: 1)
The size of the resulting extent in all directions.
Returns
-------
pos : A dictionary of positions keyed by node
Examples
--------
>>> import numpy as np
>>> pos = {0: np.array((0, 0)), 1: np.array((1, 1)), 2: np.array((0.5, 0.5))}
>>> nx.rescale_layout_dict(pos)
{0: array([-1., -1.]), 1: array([1., 1.]), 2: array([0., 0.])}
>>> pos = {0: np.array((0, 0)), 1: np.array((-1, 1)), 2: np.array((-0.5, 0.5))}
>>> nx.rescale_layout_dict(pos, scale=2)
{0: array([ 2., -2.]), 1: array([-2., 2.]), 2: array([0., 0.])}
See Also
--------
rescale_layout
"""
import numpy as np
if not pos: # empty_graph
return {}
pos_v = np.array(list(pos.values()))
pos_v = rescale_layout(pos_v, scale=scale)
return dict(zip(pos, pos_v))
| (pos, scale=1) | [
0.06880049407482147,
-0.020331406965851784,
-0.012305851094424725,
-0.0152792539447546,
-0.010332354344427586,
0.044557180255651474,
-0.012042718008160591,
-0.028506070375442505,
0.03004978410899639,
-0.0030106795020401478,
-0.005648587364703417,
-0.00916579831391573,
0.027120236307382584,
0.05136355385184288,
-0.015551157295703888,
-0.027611417695879936,
0.05160914361476898,
0.003672897582873702,
-0.030663760378956795,
0.021962830796837807,
0.056029777973890305,
-0.019805140793323517,
0.07585246115922928,
0.019577091559767723,
-0.033838897943496704,
0.011779584921896458,
0.008350085467100143,
-0.012946140952408314,
0.0673971176147461,
-0.01068319845944643,
-0.009341220371425152,
0.0332249216735363,
0.024892376735806465,
0.03410203009843826,
0.004414055496454239,
-0.0010750077199190855,
0.0028221008833497763,
0.0018517981516197324,
-0.04382040724158287,
-0.035926420241594315,
0.0017355810850858688,
0.001372676924802363,
-0.015559928491711617,
-0.026804476976394653,
0.0945875272154808,
0.08504457026720047,
-0.0007614410133101046,
-0.015498531050980091,
-0.018419306725263596,
0.00020721720647998154,
0.031874172389507294,
-0.04859188571572304,
0.02626066841185093,
0.013717997819185257,
-0.009262279607355595,
-0.02066470868885517,
-0.02017352730035782,
0.04297838360071182,
0.01755973882973194,
-0.05774891376495361,
0.02917267382144928,
0.012533899396657944,
-0.06606391072273254,
-0.05224066227674484,
-0.03350559622049332,
-0.052345916628837585,
0.007486132439225912,
-0.06434477865695953,
-0.025664234533905983,
-0.020699791610240936,
0.0012334357015788555,
-0.024629244580864906,
-0.01738431677222252,
-0.03150578588247299,
0.009735919535160065,
0.008639532141387463,
0.05497724562883377,
0.02429594285786152,
-0.007380879484117031,
0.02313815802335739,
-0.030716387555003166,
-0.04178551211953163,
0.03645268455147743,
0.0001306071353610605,
0.0206120815128088,
0.006183624267578125,
0.08651811629533768,
0.06406410038471222,
0.045820217579603195,
-0.011165608651936054,
0.004370199982076883,
0.0006962059414945543,
0.03568083047866821,
0.008902665227651596,
-0.00595996156334877,
0.017612366005778313,
0.03950502723455429,
-0.011016500182449818,
0.007902760058641434,
-0.032996874302625656,
-0.03126019611954689,
0.007863289676606655,
-0.08665845543146133,
-0.016138821840286255,
-0.077115498483181,
0.002480028197169304,
0.032067134976387024,
-0.011691873893141747,
-0.03978570178151131,
0.031295280903577805,
0.011069126427173615,
0.05094254016876221,
-0.024523992091417313,
0.050767119973897934,
-0.012919828295707703,
-0.01591077260673046,
-0.03532998636364937,
-0.0036136924754828215,
0.009920112788677216,
0.0011248934315517545,
-0.060871422290802,
0.045574627816677094,
-0.0037540302146226168,
0.023050446063280106,
-0.039926040917634964,
-0.011525223031640053,
0.02941826358437538,
0.053679123520851135,
0.017805330455303192,
0.03254077583551407,
-0.03445287421345711,
-0.07269486784934998,
-0.02345391735434532,
0.06746728718280792,
0.06781813502311707,
-0.049749672412872314,
-0.013112792745232582,
0.03708420321345329,
-0.01058671623468399,
0.037189457565546036,
0.012121657840907574,
0.012200597673654556,
-0.06406410038471222,
-0.010727053508162498,
-0.012104116380214691,
-0.015393277630209923,
0.03824198991060257,
-0.013612745329737663,
-0.03606675565242767,
-0.01833159662783146,
0.02112080529332161,
0.008069410920143127,
0.006525697186589241,
-0.028874456882476807,
0.028172768652439117,
-0.05613503232598305,
0.008306230418384075,
-0.04578513279557228,
-0.012867201119661331,
0.03606675565242767,
-0.026172958314418793,
0.01712995581328869,
0.008867580443620682,
-0.07325621694326401,
-0.008573749102652073,
0.019927935674786568,
0.004102681297808886,
-0.058380432426929474,
0.001518496428616345,
0.016665088012814522,
-0.03362839296460152,
-0.0007565072737634182,
-0.0008069410687312484,
-0.03222501650452614,
0.077115498483181,
-0.009279821999371052,
0.0003574222500901669,
-0.027611417695879936,
-0.025278305634856224,
0.034084487706422806,
0.03024274855852127,
-0.02543618530035019,
0.046206146478652954,
0.07599280029535294,
-0.03538260981440544,
0.05062678083777428,
-0.004898658487945795,
0.04406600072979927,
-0.02612033113837242,
-0.0164896659553051,
-0.003074269974604249,
0.033330176025629044,
-0.03908401355147362,
-0.009428930468857288,
-0.02264697663486004,
0.018050920218229294,
-0.05774891376495361,
-0.03227764368057251,
-0.01611250825226307,
0.045434288680553436,
0.01661246083676815,
-0.027821924537420273,
0.029646312817931175,
0.03343542665243149,
-0.023225868120789528,
-0.003304511308670044,
0.01922624744474888,
-0.008249218575656414,
0.00030095831607468426,
0.032944247126579285,
-0.06543239206075668,
0.002151111839339137,
0.027664044871926308,
-0.06392376869916916,
0.005144249182194471,
-0.006600251421332359,
-0.03901384770870209,
0.043785322457551956,
-0.02822539582848549,
-0.010569173842668533,
0.03038308583199978,
0.03390906751155853,
0.04399583116173744,
-0.014253035187721252,
-0.013016310520470142,
-0.04083823412656784,
0.013717997819185257,
-0.04673241451382637,
0.009779774583876133,
-0.0076790968887507915,
0.012858430854976177,
-0.07206334173679352,
0.015051204711198807,
-0.023892471566796303,
0.030295373871922493,
-0.010051678866147995,
0.015024892054498196,
-0.007157216314226389,
0.0814659595489502,
0.025787029415369034,
0.004534658044576645,
0.0019351235823705792,
-0.055328089743852615,
0.013998673297464848,
-0.03385644033551216,
0.023506544530391693,
0.07034420967102051,
-0.012665466405451298,
-0.04399583116173744,
-0.029084961861371994,
-0.02264697663486004,
-0.0392945222556591,
-0.023734591901302338,
0.03645268455147743,
0.014261806383728981,
0.024453822523355484,
-0.08799166232347488,
0.04452209547162056,
-0.03429499641060829,
-0.036382514983415604,
0.005157405976206064,
-0.021857578307390213,
-0.052345916628837585,
-0.0492234043776989,
0.09128959476947784,
0.010428836569190025,
0.009227195754647255,
0.05315285548567772,
-0.020085815340280533,
0.019577091559767723,
0.014893325045704842,
0.011288403533399105,
0.022980278357863426,
0.020313864573836327,
0.046451736241579056,
0.02403281070291996,
-0.0005169466021470726,
-0.01113052386790514,
0.0979556292295456,
0.013191732577979565,
-0.02822539582848549,
-0.044872939586639404,
-0.02220842055976391,
-0.013340841047465801,
0.053819458931684494,
-0.025892281904816628,
-0.010051678866147995,
0.02987436205148697,
0.03531244397163391,
0.011805898509919643,
-0.020313864573836327,
-0.00600820267572999,
-0.076133131980896,
-0.024945003911852837,
-0.06350275129079819,
-0.0014044721610844135,
0.02054191194474697,
-0.04838138073682785,
0.00799485668540001,
0.06476578861474991,
0.0407329797744751,
-0.032119762152433395,
-0.03157595545053482,
0.027874551713466644,
0.09325432032346725,
0.06332733482122421,
0.0110954400151968,
-0.004696923308074474,
0.00001783342486305628,
0.0012531706597656012,
-0.06504646688699722,
0.002982173580676317,
-0.05434572696685791,
0.03729471191763878,
-0.023190785199403763,
-0.0033220534678548574,
0.020331406965851784,
-0.014761758968234062,
0.03775080665946007,
0.05195998772978783,
-0.031119856983423233,
0.042522285133600235,
-0.09241229295730591,
0.03722454234957695,
0.022225962951779366,
0.01185852475464344,
0.037189457565546036,
0.011376114562153816,
0.08062393963336945,
0.04020671546459198,
-0.005990660283714533,
0.0048548029735684395,
-0.009858714416623116,
-0.02073487639427185,
-0.08216764777898788,
-0.04838138073682785,
0.0324881486594677,
0.0531177744269371,
-0.05417030304670334,
-0.030277831479907036,
0.006302034482359886,
-0.011709416285157204,
-0.025962451472878456,
-0.03803148493170738,
0.038838423788547516,
-0.01793689653277397,
0.004539043642580509,
-0.01623530313372612,
-0.028260478749871254,
-0.002515112515538931,
-0.042206525802612305,
0.024190690368413925,
-0.04827612638473511,
0.005731912795454264,
-0.024559075012803078,
0.006727432366460562,
0.04697800427675247,
-0.1149364784359932,
0.025839656591415405,
-0.009209653362631798,
0.050065431743860245,
0.004262753762304783,
-0.020243695005774498,
-0.057924333959817886,
0.026348380371928215,
0.0005462749977596104,
-0.02017352730035782,
-0.024366112425923347,
0.11998862773180008,
0.020085815340280533,
0.0443817600607872,
-0.02231367491185665,
-0.06483595818281174,
0.0463114008307457,
-0.03813673555850983,
0.024015268310904503,
-0.07136166095733643,
-0.006977408658713102,
-0.022541722282767296,
-0.03050588071346283,
0.04234686493873596,
-0.04010146111249924,
0.05680163577198982,
0.037961315363645554,
0.030909352004528046,
-0.03131282329559326,
0.08483406156301498,
0.01675279811024666,
-0.02936563827097416,
-0.02124360017478466,
-0.05360895395278931,
0.051784563809633255,
0.02168215624988079,
0.024067893624305725,
-0.030155036598443985,
0.003940416034311056,
0.0122444536536932,
0.01750711351633072,
-0.06041532754898071,
-0.0017476413631811738,
-0.00019310122297611088,
-0.007990471087396145,
-0.029014794155955315,
-0.007661554496735334,
0.02441873773932457,
-0.047469183802604675,
-0.007205457426607609,
0.02917267382144928,
0.05087237060070038,
0.10497250407934189,
0.0013079900527372956,
0.011139295063912868,
0.03676844388246536,
-0.048732224851846695,
-0.013709226623177528,
-0.04031196981668472,
0.0037474518176168203,
0.01706855744123459,
0.011753272265195847,
-0.047083258628845215,
-0.024260858073830605,
0.022559264674782753,
0.012025175616145134,
0.021226057782769203,
0.022787313908338547,
-0.06041532754898071,
-0.003984271548688412,
-0.02645363286137581,
0.00556526193395257,
0.09564005583524704,
-0.021910203620791435,
-0.0390489287674427,
0.044171251356601715,
-0.02383984625339508,
0.05318794026970863,
-0.04399583116173744,
0.05694197118282318,
0.030663760378956795,
-0.07192301005125046,
0.039855871349573135,
0.029084961861371994,
0.028576238080859184,
0.03841741010546684,
-0.025716861709952354,
0.02480466663837433,
0.010700739920139313,
-0.03147070109844208,
-0.03587379306554794,
0.006266949698328972,
-0.019296417012810707,
0.0521354079246521,
-0.024331027641892433,
0.07283519953489304,
-0.02613787353038788,
0.01781410165131092,
-0.030102409422397614,
-0.033330176025629044,
-0.006394130643457174,
-0.016717713326215744,
-0.0064467573538422585,
0.0419609360396862,
-0.03676844388246536,
-0.08209748566150665,
0.004205741919577122,
0.020506829023361206,
0.044241420924663544,
0.026786934584379196,
0.046451736241579056,
0.011490139178931713,
-0.02017352730035782,
0.046381570398807526,
-0.009920112788677216,
-0.012288308702409267,
-0.07690498977899551,
-0.026365922763943672,
0.007942229509353638,
-0.023506544530391693,
0.031611040234565735,
-0.03768064081668854,
0.04876730591058731,
0.025208137929439545,
-0.045434288680553436,
0.03680352866649628,
0.04883747547864914,
-0.02231367491185665,
-0.011762043461203575,
-0.002087521366775036,
0.023892471566796303,
-0.05599469318985939,
0.07241418957710266,
-0.03648776933550835,
-0.03669827803969383,
0.0358913354575634,
0.04711833968758583,
-0.009376304224133492,
-0.037189457565546036,
0.004181621130555868,
-0.009271050803363323,
-0.015586242079734802,
-0.038066565990448,
-0.00041169344331137836,
-0.028207853436470032,
0.04767969250679016,
0.04522378370165825,
-0.027857009321451187,
0.01572657935321331,
-0.029523517936468124,
0.08602693676948547,
0.02548881247639656,
0.0175772812217474,
-0.035610660910606384,
0.018156174570322037,
0.02745353803038597,
-0.00524950260296464,
0.015480988658964634,
0.06487104296684265,
-0.05939787998795509,
0.04575004801154137,
0.021857578307390213,
-0.044732604175806046,
0.03375118598341942,
0.019875308498740196,
0.04101365804672241,
0.027488622814416885,
-0.018086005002260208,
0.016594918444752693,
0.047784943133592606,
-0.030997062101960182,
0.019384127110242844,
0.03247060626745224,
-0.008512350730597973,
0.013621515594422817,
0.02441873773932457,
-0.014007444493472576,
0.05080220103263855,
0.02461170218884945,
0.04711833968758583,
-0.03525981679558754,
-0.03894367814064026,
0.03620709478855133,
0.017866726964712143,
-0.0034930899273604155,
0.022594349458813667,
-0.019892850890755653,
0.06687085330486298,
0.060660917311906815,
0.060660917311906815,
-0.041259247809648514,
-0.01470913179218769,
-0.0686250776052475,
-0.011183151043951511,
-0.0024098593275994062,
-0.018980657681822777,
-0.030207663774490356,
-0.01799829490482807,
0.0006326154689304531,
-0.034470416605472565,
-0.045820217579603195,
-0.010042907670140266,
-0.01017447467893362,
-0.002896655350923538,
-0.018559643998742104,
0.0635378360748291,
0.01984022557735443,
-0.03476863354444504,
0.004229862242937088,
-0.06830931454896927,
0.030348001047968864,
0.026611512526869774,
0.03582116588950157,
0.0220680832862854,
-0.00916579831391573,
0.059643469750881195,
-0.007152830716222525,
0.018594728782773018,
-0.05087237060070038,
0.02548881247639656,
-0.03466338291764259,
-0.01781410165131092,
-0.0011018692748621106,
0.003769379574805498,
0.029084961861371994,
-0.003146631643176079,
0.05024085193872452,
0.014156552962958813,
0.06757254153490067,
-0.016849279403686523,
0.04673241451382637,
0.0014680626336485147,
0.016208989545702934,
-0.03431253880262375,
-0.006964252330362797,
0.01509506069123745,
0.015103831887245178,
-0.01692822016775608,
-0.07634364068508148,
0.04139958322048187,
0.02866395004093647,
-0.015349422581493855,
-0.008358856663107872,
-0.06729187071323395,
-0.013261901214718819,
0.010674427263438702,
0.024260858073830605,
-0.049749672412872314,
-0.0678883045911789,
0.07690498977899551,
-0.018735066056251526,
0.030646217986941338,
-0.00025422481121495366,
-0.018945572897791862,
-0.045890387147665024,
0.013726769015192986,
-0.012095345184206963,
-0.0005484677385538816,
-0.05048644170165062,
-0.02250663936138153,
-0.003157595405355096,
0.001725713605992496,
-0.020945383235812187,
-0.024015268310904503,
-0.01604233868420124,
-0.017550967633724213,
-0.04227669537067413,
0.02403281070291996,
0.05125829949975014,
0.016665088012814522,
0.025418642908334732,
-0.04185568168759346,
-0.023296037688851357,
0.0070300353690981865,
0.03792623057961464,
0.02054191194474697,
-0.05652095749974251,
-0.0286113228648901,
-0.02645363286137581,
-0.023927556350827217,
-0.007367722690105438,
-0.0025480040349066257,
0.07206334173679352,
0.06599374860525131,
-0.020962925627827644,
0.018945572897791862,
-0.04420633614063263,
-0.0016577376518398523,
-0.021155890077352524,
0.05715247616171837,
-0.05588943883776665,
-0.020576996728777885,
0.02048928663134575,
0.03418974205851555,
0.0018134246347472072,
-0.007152830716222525,
-0.03220747411251068,
0.05816992372274399,
0.06350275129079819,
-0.012314622290432453,
-0.050767119973897934,
-0.01669139973819256,
-0.04915323480963707,
-0.022243505343794823,
0.007635241374373436,
-0.026278210803866386,
-0.0221908800303936,
0.029839277267456055,
0.010674427263438702,
-0.05118812993168831,
0.027506165206432343,
0.01850701868534088,
-0.08153612911701202,
0.02441873773932457,
0.00925350934267044,
-0.03778589144349098,
0.0001811780093703419,
-0.000028780166758224368,
0.01769130490720272,
0.012788261286914349,
0.0072449273429811,
-0.040873318910598755,
-0.024243315681815147,
0.01195500697940588,
0.04101365804672241,
-0.028365733101963997,
0.045890387147665024,
0.002662028418853879,
-0.01020955853164196,
0.040171630680561066,
-0.05231083184480667,
-0.007012493442744017,
0.051889818161726,
0.11121752858161926,
-0.017524654045701027,
0.012297079898416996,
-0.02657642774283886,
-0.025032715871930122,
0.010218329727649689,
-0.01845439150929451,
0.036943867802619934,
0.02587474137544632,
-0.028014888986945152,
0.004569742362946272,
-0.020384032279253006,
-0.009595581330358982,
0.03596150502562523,
-0.003416342893615365,
-0.05624028295278549,
-0.08237815648317337,
0.006236250977963209,
0.03869808837771416,
0.05224066227674484,
-0.01385833602398634,
0.021401479840278625,
0.03845249488949776,
-0.05371420830488205,
-0.045890387147665024,
-0.0044272118248045444,
0.00344923441298306,
-0.0006254889885894954,
-0.04890764504671097,
0.01090247556567192,
-0.03778589144349098,
0.012121657840907574,
-0.0029383180662989616,
0.009823630563914776,
-0.032944247126579285,
-0.043469563126564026,
0.01150768157094717,
-0.04368007183074951,
-0.026734307408332825,
-0.03038308583199978,
-0.060660917311906815,
0.004552199970930815,
-0.03145315870642662,
-0.008209748193621635,
-0.03610184043645859,
0.02352408692240715,
-0.023734591901302338,
-0.03845249488949776,
-0.04743409901857376,
0.03652285411953926,
0.04845154657959938,
0.0043066092766821384,
-0.035277359187603,
0.03338279947638512,
0.014814385212957859,
-0.015331880189478397,
0.026278210803866386,
0.05848568305373192,
0.0005646394565701485,
-0.009648208506405354,
0.030295373871922493,
0.025383559986948967,
-0.01833159662783146,
-0.012551441788673401,
-0.026593970134854317,
-0.07479992508888245,
0.025471270084381104,
-0.00877986941486597,
0.00840709824115038,
-0.0152178555727005,
-0.03918926790356636,
-0.037189457565546036,
-0.072273850440979,
0.04427650570869446,
-0.003306704107671976,
-0.013753082603216171,
0.03792623057961464,
0.02162952907383442
]
|
31,078 | networkx.algorithms.distance_measures | resistance_distance | Returns the resistance distance between pairs of nodes in graph G.
The resistance distance between two nodes of a graph is akin to treating
the graph as a grid of resistors with a resistance equal to the provided
weight [1]_, [2]_.
If weight is not provided, then a weight of 1 is used for all edges.
If two nodes are the same, the resistance distance is zero.
Parameters
----------
G : NetworkX graph
A graph
nodeA : node or None, optional (default=None)
A node within graph G.
If None, compute resistance distance using all nodes as source nodes.
nodeB : node or None, optional (default=None)
A node within graph G.
If None, compute resistance distance using all nodes as target nodes.
weight : string or None, optional (default=None)
The edge data key used to compute the resistance distance.
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
-------
rd : dict or float
If `nodeA` and `nodeB` are given, resistance distance between `nodeA`
and `nodeB`. If `nodeA` or `nodeB` is unspecified (the default), a
dictionary of nodes with resistance distances as the value.
Raises
------
NetworkXNotImplemented
If `G` is a directed graph.
NetworkXError
If `G` is not connected, or contains no nodes,
or `nodeA` is not in `G` or `nodeB` is not in `G`.
Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> round(nx.resistance_distance(G, 1, 3), 10)
0.625
Notes
-----
The implementation is based on Theorem A 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] Wikipedia
"Resistance distance."
https://en.wikipedia.org/wiki/Resistance_distance
.. [2] D. J. Klein and M. Randic.
Resistance distance.
J. of Math. Chem. 12:81-95, 1993.
| 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, nodeA=None, nodeB=None, weight=None, invert_weight=True, *, backend=None, **backend_kwargs) | [
0.05050395056605339,
-0.014621064066886902,
0.0027076045516878366,
0.0592062845826149,
0.05628017336130142,
-0.009433864615857601,
-0.03190223127603531,
-0.04947790876030922,
0.10077989101409912,
-0.008683335036039352,
0.03188323229551315,
-0.00023231365776155144,
0.015229088254272938,
-0.004503173753619194,
-0.05973830819129944,
0.04510774090886116,
-0.05692619830369949,
0.0003728893934749067,
-0.005837975535541773,
0.04632378742098808,
0.005244202446192503,
-0.10412401705980301,
-0.0036552660167217255,
0.06061233952641487,
-0.02795007824897766,
0.007453037891536951,
0.020349785685539246,
0.01344301924109459,
-0.0035460118670016527,
0.0005044101271778345,
-0.006602754816412926,
-0.05031394213438034,
-0.023332901298999786,
-0.006512501277029514,
0.022914884611964226,
0.023883922025561333,
0.00700652040541172,
0.007785550784319639,
-0.09257157146930695,
-0.05350606516003609,
-0.011561946012079716,
0.03385930880904198,
0.03209223970770836,
-0.026677029207348824,
0.033251285552978516,
0.01780368760228157,
-0.003686142386868596,
0.01883922703564167,
-0.030306169763207436,
-0.03914150968194008,
0.02584099769592285,
-0.010906420648097992,
-0.04620978236198425,
0.009163103997707367,
0.0018786975415423512,
0.03342229127883911,
0.026126008480787277,
0.05411408841609955,
0.029185127466917038,
-0.07303881645202637,
0.011115428991615772,
-0.08056311309337616,
0.02764606662094593,
0.01684414967894554,
-0.06133436784148216,
0.01502958033233881,
-0.01964675821363926,
-0.005505462642759085,
0.007999308407306671,
0.013813532888889313,
-0.029128124937415123,
-0.0022634624037891626,
0.026050005108118057,
-0.0682506337761879,
0.01872522383928299,
0.026373017579317093,
0.023902922868728638,
-0.013253011740744114,
-0.02692404016852379,
-0.014098544605076313,
0.03178822621703148,
-0.013167507946491241,
0.04620978236198425,
-0.03644340857863426,
0.02534697949886322,
-0.03729844093322754,
0.011039426550269127,
-0.016625642776489258,
0.02599300444126129,
-0.03144621476531029,
-0.0067405104637146,
0.026069005951285362,
0.03378330543637276,
0.03748844563961029,
0.07322882860898972,
0.0010450403206050396,
-0.04989592730998993,
-0.07349483668804169,
0.07072073221206665,
-0.022116854786872864,
-0.013452519662678242,
0.08641533553600311,
-0.018041197210550308,
0.0051919505931437016,
0.028672106564044952,
-0.0460197776556015,
-0.01537159364670515,
-0.034410327672958374,
0.05365807190537453,
-0.031199203804135323,
-0.05631817504763603,
0.021679837256669998,
0.01654013805091381,
-0.013728030025959015,
-0.03610139340162277,
0.04510774090886116,
-0.016872651875019073,
0.015276589430868626,
0.05932028964161873,
0.027665067464113235,
0.013186508789658546,
0.0322442464530468,
-0.01772768422961235,
-0.0009731938480399549,
0.010735414922237396,
0.021812841296195984,
0.009585870429873466,
0.0014523685676977038,
-0.011922960169613361,
0.02198384888470173,
0.04913589730858803,
0.00012105545465601608,
0.025289976969361305,
0.04848987236618996,
0.02738005667924881,
0.00989938247948885,
-0.007685796823352575,
0.03756444901227951,
0.06722459197044373,
0.0207488015294075,
-0.01041240245103836,
-0.023294899612665176,
0.02319989539682865,
0.05118797719478607,
0.03188323229551315,
0.008360322564840317,
0.01742367260158062,
0.03955952823162079,
0.03982553631067276,
-0.0027836074586957693,
0.026373017579317093,
-0.014041542075574398,
0.04389169439673424,
-0.011029926128685474,
0.009623871184885502,
0.017243165522813797,
-0.014279051683843136,
0.013870535418391228,
-0.04043355956673622,
-0.03484734520316124,
-0.07425487041473389,
-0.030724186450242996,
0.04024355486035347,
-0.021755840629339218,
0.01384203415364027,
-0.02722805179655552,
0.04947790876030922,
0.015580601990222931,
-0.06490650773048401,
0.028159087523818016,
-0.04503173753619194,
-0.05160599201917648,
-0.03410631790757179,
-0.03874249756336212,
0.030458176508545876,
0.08527529239654541,
0.026620028540492058,
-0.014564062468707561,
0.012150969356298447,
0.023560909554362297,
-0.014906075783073902,
-0.05863626301288605,
-0.0018549466039985418,
-0.021470829844474792,
0.028938116505742073,
0.04499373584985733,
0.03465733677148819,
-0.004804810509085655,
0.004643304273486137,
0.0004655179800465703,
0.008189315907657146,
-0.04145960137248039,
0.02534697949886322,
0.028957117348909378,
0.029109124094247818,
-0.014972577802836895,
0.03591138496994972,
0.01834520883858204,
-0.03473334014415741,
0.07056872546672821,
0.029014119878411293,
-0.001060478389263153,
0.037393443286418915,
0.03201623633503914,
0.005548214074224234,
0.011200932785868645,
-0.00922485627233982,
-0.029071122407913208,
-0.008236818015575409,
0.009965884499251842,
-0.066768579185009,
0.005068445578217506,
0.00555296428501606,
-0.03492334857583046,
-0.024301938712596893,
0.0299831572920084,
-0.026430020108819008,
0.008897093124687672,
0.013690028339624405,
-0.06399446725845337,
-0.05479811504483223,
-0.010051388293504715,
-0.00982337910681963,
-0.013091505505144596,
0.04461372271180153,
-0.04928790405392647,
0.02240186557173729,
0.00002389935980318114,
0.014193547889590263,
0.007020771037787199,
0.05449410527944565,
0.00319212325848639,
0.07904305309057236,
-0.05122597888112068,
0.014184047468006611,
-0.021109815686941147,
-0.05981430783867836,
0.07250680029392242,
0.052404023706912994,
0.04123159125447273,
-0.03570237755775452,
-0.06281642615795135,
-0.042827654629945755,
0.05890227481722832,
-0.03627239912748337,
-0.03705143183469772,
0.013870535418391228,
0.0018656345782801509,
0.02855810336768627,
0.00901584792882204,
-0.08793539553880692,
-0.06794662028551102,
-0.014108045026659966,
-0.02319989539682865,
0.02757006511092186,
-0.010944422334432602,
-0.08519928902387619,
0.016559138894081116,
-0.018050696700811386,
-0.02726605348289013,
0.014497559517621994,
-0.008374573662877083,
-0.07227879017591476,
-0.0045815519988536835,
-0.04822386056184769,
0.010089389979839325,
0.0004385013016872108,
0.010250896215438843,
-0.025479983538389206,
0.05076995864510536,
0.04491773247718811,
0.010431402362883091,
0.013566523790359497,
-0.009495616890490055,
-0.00493069039657712,
0.02017877995967865,
0.021185817196965218,
0.04461372271180153,
-0.00506369536742568,
0.0363864041864872,
-0.08451526612043381,
0.0016803774051368237,
-0.007638294715434313,
0.02443494275212288,
-0.05692619830369949,
0.017452172935009003,
-0.009248606860637665,
-0.05639417842030525,
0.02312389202415943,
-0.009082350879907608,
0.09249556809663773,
0.007785550784319639,
0.0035887635312974453,
0.0033607548102736473,
0.07379885017871857,
0.010393401607871056,
-0.013965539634227753,
-0.04837586730718613,
0.016369132325053215,
0.06958068907260895,
0.043131664395332336,
-0.0243209395557642,
0.004655179567635059,
-0.04936390742659569,
0.05552014335989952,
0.04081357643008232,
0.034866347908973694,
-0.00006460991426138207,
0.01723366603255272,
0.057838231325149536,
-0.09621971845626831,
0.004897438921034336,
-0.043131664395332336,
0.022876882925629616,
-0.052480027079582214,
-0.02967914566397667,
0.05012393370270729,
-0.02726605348289013,
0.020083775743842125,
0.025593988597393036,
0.015979617834091187,
0.09697974473237991,
0.014459557831287384,
0.03874249756336212,
-0.07117674499750137,
-0.0023477780632674694,
0.01983676664531231,
0.07828301936388016,
0.07934706658124924,
-0.04943990707397461,
-0.042789652943611145,
0.018411710858345032,
-0.010250896215438843,
0.004743058234453201,
-0.04145960137248039,
0.042181629687547684,
0.10952022671699524,
-0.03382130712270737,
-0.02783607505261898,
-0.02948913909494877,
0.027703069150447845,
0.004256164189428091,
-0.005305954720824957,
-0.0026197261177003384,
-0.00513019785284996,
0.019276244565844536,
0.017053158953785896,
-0.027399057522416115,
-0.03484734520316124,
-0.053202055394649506,
-0.012853995896875858,
0.003964027855545282,
-0.031997233629226685,
0.02688603848218918,
-0.016787149012088776,
0.04552575945854187,
-0.011704452335834503,
-0.048109859228134155,
0.02198384888470173,
0.023788917809724808,
-0.10359200090169907,
0.006331994663923979,
-0.028691107407212257,
-0.019390247762203217,
-0.006887766066938639,
0.012141468934714794,
-0.016511637717485428,
0.017214665189385414,
0.018326207995414734,
-0.04096558317542076,
-0.0022670249454677105,
-0.08200716972351074,
-0.07744698971509933,
0.0048095607198774815,
0.010925421491265297,
0.03748844563961029,
-0.03404931351542473,
-0.021090814843773842,
-0.01573260687291622,
-0.006398497149348259,
0.009191605262458324,
0.019323745742440224,
-0.04457572102546692,
0.01114393025636673,
0.04472772777080536,
-0.012663989327847958,
0.04909789562225342,
0.004070907365530729,
0.02416893281042576,
-0.003253875533118844,
-0.041801612824201584,
-0.02757006511092186,
0.06764261424541473,
-0.010896921157836914,
-0.043435677886009216,
0.03480934351682663,
0.061790384352207184,
0.028273090720176697,
-0.04579176753759384,
-0.014193547889590263,
-0.04609578102827072,
-0.007799800951033831,
-0.021394826471805573,
0.00854082964360714,
-0.026601027697324753,
0.015001079067587852,
0.007742798887193203,
0.043473679572343826,
0.04472772777080536,
0.014440557919442654,
-0.04962991550564766,
0.015637604519724846,
0.013452519662678242,
0.004263289738446474,
-0.01968475989997387,
-0.02017877995967865,
-0.013129507191479206,
0.0023465906269848347,
0.03701343014836311,
0.02990715391933918,
0.021318823099136353,
-0.02967914566397667,
0.07509090006351471,
-0.0059377290308475494,
0.0226298738270998,
-0.04670380428433418,
0.00012461809092201293,
-0.02002677321434021,
-0.0663885623216629,
0.05403808504343033,
-0.023845920339226723,
0.0016863150522112846,
0.018905729055404663,
-0.03127520903944969,
0.00022177418577484787,
-0.0022313985973596573,
0.01795569248497486,
0.017490174621343613,
-0.02010277658700943,
-0.03726043924689293,
0.04016755148768425,
0.012188971042633057,
0.027741070836782455,
-0.04829986393451691,
-0.0032990023028105497,
-0.06281642615795135,
-0.006906766444444656,
-0.0008485015132464468,
-0.005158699117600918,
-0.03165522217750549,
0.005514963064342737,
-0.04434771090745926,
0.02673403173685074,
0.028805112466216087,
-0.11719652265310287,
0.029128124937415123,
-0.03718443587422371,
-0.01405104249715805,
-0.06806062906980515,
0.02553698606789112,
0.016169624403119087,
0.03157921880483627,
-0.009144103154540062,
-0.02994515560567379,
-0.01957075484097004,
-0.032833267003297806,
0.007799800951033831,
-0.015618602745234966,
-0.027171049267053604,
-0.021090814843773842,
0.04909789562225342,
-0.020159779116511345,
-0.0199887715280056,
-0.043283671140670776,
0.056546181440353394,
0.012568985112011433,
-0.09120351821184158,
-0.011837457306683064,
0.006175238639116287,
-0.04415770620107651,
-0.019969770684838295,
0.02017877995967865,
0.05563414841890335,
0.023921923711895943,
0.020919807255268097,
-0.0392175130546093,
-0.0039022755809128284,
-0.0057097203098237514,
0.01995076984167099,
-0.041877616196870804,
-0.015552100725471973,
0.03163622319698334,
0.02565099112689495,
0.01212246809154749,
0.0006721509271301329,
-0.004702681675553322,
0.01229347474873066,
0.004595802631229162,
0.032757263630628586,
0.014402556233108044,
-0.026354016736149788,
-0.03144621476531029,
-0.015485597774386406,
0.04848987236618996,
0.03695642575621605,
0.03163622319698334,
-0.03859049081802368,
0.0076525453478097916,
0.08960746228694916,
0.03526536002755165,
-0.01401304081082344,
0.019152740016579628,
0.07414086163043976,
0.047463834285736084,
0.011856458149850368,
-0.026183011010289192,
-0.036557409912347794,
0.05434209853410721,
0.0652485191822052,
-0.02852010168135166,
-0.01887722872197628,
0.024225935339927673,
0.000541520887054503,
-0.0018549466039985418,
-0.016787149012088776,
0.008944595232605934,
-0.004469922743737698,
-0.07748499512672424,
-0.0021815216168761253,
-0.015305090695619583,
-0.014459557831287384,
0.01995076984167099,
-0.01944725029170513,
0.047121819108724594,
-0.00038506175042130053,
-0.007809301372617483,
-0.018630219623446465,
-0.042029622942209244,
-0.1022239476442337,
-0.011789955198764801,
-0.015476097352802753,
0.0030068662017583847,
0.014678066596388817,
0.011257934384047985,
0.08246318250894547,
0.020349785685539246,
0.001218422083184123,
0.0024000301491469145,
-0.02247786708176136,
-0.07072073221206665,
-0.04480373114347458,
0.02825409173965454,
-0.020843803882598877,
-0.03387830778956413,
0.061942391097545624,
0.03686142340302467,
-0.0501619353890419,
0.004564926028251648,
0.025403980165719986,
-0.017642181366682053,
-0.016644641757011414,
-0.08732736855745316,
-0.018126700073480606,
-0.06304443627595901,
0.006469749845564365,
-0.04043355956673622,
0.03232024610042572,
-0.024985965341329575,
-0.04491773247718811,
0.03382130712270737,
-0.03182622790336609,
0.032453253865242004,
0.07835902273654938,
0.004472297616302967,
-0.006545752752572298,
-0.013281513005495071,
0.025270976126194,
-0.06319644302129745,
0.035094354301691055,
-0.06353845447301865,
-0.012739991769194603,
-0.06106835603713989,
0.01635013148188591,
0.04119358956813812,
0.017148161306977272,
0.04161160811781883,
-0.01673964597284794,
0.05346806347370148,
-0.03860948979854584,
-0.014602064155042171,
-0.02428293786942959,
-0.057268209755420685,
0.03824847564101219,
0.0035270112566649914,
-0.0019440125906839967,
-0.03349829465150833,
-0.022078853100538254,
0.00798505824059248,
0.0460197776556015,
0.0032134989742189646,
-0.052062008529901505,
-0.009277108125388622,
0.019551753997802734,
-0.006949518341571093,
-0.04381569102406502,
0.04947790876030922,
0.005343956407159567,
-0.07041671872138977,
0.036158397793769836,
-0.053240057080984116,
0.0015663729282096028,
-0.0243209395557642,
-0.016245627775788307,
-0.000583084998652339,
-0.0033940060529857874,
0.012739991769194603,
-0.002312151715159416,
0.016511637717485428,
-0.042333632707595825,
0.017670681700110435,
-0.004811935592442751,
-0.004712182097136974,
0.03767845407128334,
-0.03277626633644104,
-0.01853521540760994,
0.05700220167636871,
0.04005354642868042,
0.005951979663223028,
-0.03323228284716606,
0.041801612824201584,
-0.0021577707957476377,
-0.042143628001213074,
-0.009889882057905197,
0.042257633060216904,
0.03171222284436226,
-0.07132875174283981,
0.04031955823302269,
-0.017480675131082535,
-0.02014077827334404,
0.041687607765197754,
-0.03572138026356697,
0.07600293308496475,
-0.057344213128089905,
-0.0006210864521563053,
-0.06399446725845337,
0.01941874995827675,
0.04898389056324959,
-0.017205163836479187,
-0.005220451392233372,
-0.005652718245983124,
-0.02010277658700943,
0.03184523060917854,
0.0333842895925045,
-0.017908191308379173,
-0.008555080741643906,
0.036006391048431396,
0.026487022638320923,
-0.02466295287013054,
0.009538368321955204,
-0.05133998394012451,
0.001156075857579708,
0.03631040081381798,
0.03336528688669205,
0.011789955198764801,
0.024035928770899773,
0.017053158953785896,
0.0330042727291584,
-0.0362153984606266,
-0.0026221012230962515,
-0.06255041807889938,
-0.019741762429475784,
-0.01229347474873066,
0.022990887984633446,
0.03127520903944969,
-0.06874465197324753,
0.023104891180992126,
-0.0032158740796148777,
0.038001466542482376,
-0.0006234615575522184,
-0.020881805568933487,
0.004716932307928801,
0.06722459197044373,
-0.02553698606789112,
-0.004377293866127729,
0.017547177150845528,
-0.021432828158140182,
-0.03070518560707569,
-0.021071814000606537,
0.02929913066327572,
-0.004873688332736492,
-0.03967353329062462,
-0.042827654629945755,
0.02067279815673828,
-0.0009179729386232793,
0.057914234697818756,
-0.04009154811501503,
-0.04989592730998993,
0.04822386056184769,
0.07034071534872055,
-0.05924428626894951,
0.07904305309057236,
0.02538497932255268,
-0.016625642776489258,
0.02681003510951996,
-0.023921923711895943,
-0.02572699263691902,
-0.07611694186925888,
-0.011210433207452297,
-0.04552575945854187,
0.03387830778956413,
-0.011970462277531624,
-0.023940924555063248,
0.018316706642508507,
-0.004070907365530729,
0.03993954136967659,
0.023769916966557503,
-0.0036243898794054985,
-0.030914193019270897,
-0.04362568259239197,
-0.006303493399173021,
-0.018250204622745514,
-0.009324610233306885,
0.012796994298696518,
0.03040117397904396,
-0.032035235315561295,
0.01212246809154749,
0.07254479825496674,
-0.04468972608447075,
0.0068830158561468124,
0.047881849110126495,
-0.027133047580718994,
0.004215787630528212,
0.015580601990222931,
0.03710843250155449,
0.02278187870979309,
0.020767802372574806,
-0.005780973006039858,
0.028273090720176697,
0.037507448345422745,
0.052100010216236115,
0.02599300444126129,
0.04153560474514961,
-0.047539833933115005,
-0.032567258924245834,
0.001257611089386046,
-0.007039771880954504,
-0.04020555317401886,
0.023294899612665176,
0.01933324709534645,
-0.02304789051413536,
0.05076995864510536,
-0.00471930718049407,
0.03175022453069687,
-0.008897093124687672,
0.057610224932432175,
-0.007799800951033831,
-0.015675604343414307,
-0.0516819953918457,
-0.0025936001911759377,
-0.005258453078567982,
-0.0038856500759720802,
-0.06657856702804565,
-0.05175799876451492,
0.014108045026659966,
-0.029185127466917038,
0.008778339251875877,
0.006583753973245621,
0.05464610829949379
]
|
31,080 | networkx.classes.function | restricted_view | Returns a view of `G` with hidden nodes and edges.
The resulting subgraph filters out node `nodes` and edges `edges`.
Filtered out nodes also filter out any of their edges.
Parameters
----------
G : NetworkX Graph
nodes : iterable
An iterable of nodes. Nodes not present in `G` are ignored.
edges : iterable
An iterable of edges. Edges not present in `G` are ignored.
Returns
-------
subgraph : SubGraph View
A read-only restricted view of `G` filtering out nodes and edges.
Changes to `G` are 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)`
If you create a subgraph of a subgraph recursively you may end up
with a chain of subgraph views. Such chains can get quite slow
for lengths near 15. To avoid long chains, try to make your subgraph
based on the original graph. We do not rule out chains programmatically
so that odd cases like an `edge_subgraph` of a `restricted_view`
can be created.
Examples
--------
>>> G = nx.path_graph(5)
>>> H = nx.restricted_view(G, [0], [(1, 2), (3, 4)])
>>> list(H.nodes)
[1, 2, 3, 4]
>>> list(H.edges)
[(2, 3)]
| def restricted_view(G, nodes, edges):
"""Returns a view of `G` with hidden nodes and edges.
The resulting subgraph filters out node `nodes` and edges `edges`.
Filtered out nodes also filter out any of their edges.
Parameters
----------
G : NetworkX Graph
nodes : iterable
An iterable of nodes. Nodes not present in `G` are ignored.
edges : iterable
An iterable of edges. Edges not present in `G` are ignored.
Returns
-------
subgraph : SubGraph View
A read-only restricted view of `G` filtering out nodes and edges.
Changes to `G` are 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)`
If you create a subgraph of a subgraph recursively you may end up
with a chain of subgraph views. Such chains can get quite slow
for lengths near 15. To avoid long chains, try to make your subgraph
based on the original graph. We do not rule out chains programmatically
so that odd cases like an `edge_subgraph` of a `restricted_view`
can be created.
Examples
--------
>>> G = nx.path_graph(5)
>>> H = nx.restricted_view(G, [0], [(1, 2), (3, 4)])
>>> list(H.nodes)
[1, 2, 3, 4]
>>> list(H.edges)
[(2, 3)]
"""
nxf = nx.filters
hide_nodes = nxf.hide_nodes(nodes)
if G.is_multigraph():
if G.is_directed():
hide_edges = nxf.hide_multidiedges(edges)
else:
hide_edges = nxf.hide_multiedges(edges)
else:
if G.is_directed():
hide_edges = nxf.hide_diedges(edges)
else:
hide_edges = nxf.hide_edges(edges)
return nx.subgraph_view(G, filter_node=hide_nodes, filter_edge=hide_edges)
| (G, nodes, edges) | [
0.042750608175992966,
-0.028122559189796448,
0.011785205453634262,
0.02643124759197235,
-0.06534941494464874,
0.00022757929400540888,
-0.009239241480827332,
-0.026323290541768074,
0.08255041390657425,
-0.024488037452101707,
0.021735157817602158,
0.04239075630903244,
-0.002079279161989689,
0.014538086019456387,
-0.04023163393139839,
0.015545675531029701,
-0.024739935994148254,
-0.004138316493481398,
0.09456952661275864,
0.03774864226579666,
-0.020097823813557625,
-0.08312617987394333,
0.03900812938809395,
0.04386615380644798,
-0.044046081602573395,
0.015644636005163193,
-0.0024942352902144194,
0.015239800326526165,
0.025423657149076462,
-0.009329204447567463,
-0.016976093873381615,
-0.043758198618888855,
-0.020817531272768974,
0.004642111714929342,
-0.001402304507791996,
0.05387008562684059,
0.00638740137219429,
0.0650615319609642,
-0.045089658349752426,
0.009167270734906197,
-0.0365971103310585,
-0.035337623208761215,
0.023912271484732628,
-0.04922797158360481,
0.004619620740413666,
-0.02729489654302597,
0.055921249091625214,
0.045233599841594696,
-0.03350237011909485,
0.006131005939096212,
0.03683101758360863,
0.024272125214338303,
-0.039547912776470184,
0.018460489809513092,
-0.0012572385603561997,
-0.005784646607935429,
0.024434059858322144,
0.05448183789849281,
0.08578909933567047,
-0.008033731952309608,
-0.03582342714071274,
-0.04105929657816887,
0.01559965405613184,
0.004853525664657354,
-0.011641263961791992,
-0.0009266230626963079,
-0.04372221231460571,
-0.02700701355934143,
-0.05689285695552826,
0.02540566399693489,
-0.05588526651263237,
-0.002752880100160837,
0.014745001681149006,
0.01932413876056671,
0.013080678880214691,
-0.03713689371943474,
-0.030299672856926918,
0.02713296189904213,
-0.029202120378613472,
-0.04311046376824379,
0.06905590742826462,
-0.041167251765728,
-0.00865897722542286,
0.0014776488533243537,
0.050127606838941574,
0.0031622136011719704,
0.013674437068402767,
-0.017632827162742615,
0.029975805431604385,
-0.02526172250509262,
-0.011128473095595837,
0.012378963641822338,
-0.02411019243299961,
0.0011942641576752067,
-0.01661624014377594,
0.0397278368473053,
-0.026809094473719597,
-0.023552417755126953,
-0.019234174862504005,
-0.029256097972393036,
0.041850972920656204,
0.022400887683033943,
-0.06491759419441223,
0.03130726516246796,
-0.0005965697928331792,
-0.048688191920518875,
-0.024182163178920746,
0.018496476113796234,
-0.017057061195373535,
-0.04800447076559067,
-0.012037103064358234,
0.055489424616098404,
0.015077865682542324,
0.03289061784744263,
0.014475110918283463,
0.05818832665681839,
-0.010408765636384487,
-0.04908403381705284,
0.009455153718590736,
-0.032746680080890656,
-0.01147033367305994,
0.03020971082150936,
-0.05660497397184372,
0.017983684316277504,
-0.006931680254638195,
0.04890410602092743,
-0.00046190584544092417,
0.0004366036446299404,
0.03918805718421936,
-0.03990776464343071,
-0.009428164921700954,
-0.016940109431743622,
-0.02015180140733719,
0.05127913877367973,
0.021951070055365562,
-0.006068031303584576,
-0.036633096635341644,
0.031577154994010925,
0.03979980945587158,
0.03702893480658531,
-0.07981552928686142,
-0.04652906954288483,
0.02598142996430397,
0.10759622603654861,
-0.00500196497887373,
-0.03612930327653885,
0.04105929657816887,
0.012972722761332989,
0.07006349414587021,
-0.011866172775626183,
-0.006436881609261036,
0.013827375136315823,
0.019378116354346275,
-0.011380370706319809,
-0.006688778754323721,
0.030515585094690323,
-0.03774864226579666,
0.025927452370524406,
0.006207474507391453,
0.021267348900437355,
-0.0464211143553257,
-0.020259758457541466,
-0.02450603060424328,
0.006783240474760532,
0.00414281478151679,
-0.0600595660507679,
0.0990317091345787,
-0.03641718626022339,
-0.014574071392416954,
0.056245118379592896,
-0.001412425423040986,
-0.026377269998192787,
-0.06866006553173065,
-0.029220113530755043,
0.013827375136315823,
0.053618188947439194,
0.04059148579835892,
0.00732751889154315,
-0.039547912776470184,
0.02932806871831417,
0.01306268572807312,
-0.03450996056199074,
-0.030155731365084648,
0.029364055022597313,
0.05343826115131378,
0.005240368191152811,
-0.00936518982052803,
-0.03542758896946907,
-0.0019814439583569765,
-0.015500694513320923,
-0.01524879690259695,
0.001954454928636551,
0.028626354411244392,
0.020403699949383736,
-0.013017703779041767,
-0.03958389535546303,
-0.04678096994757652,
0.001743040862493217,
-0.05009162053465843,
0.044801775366067886,
0.01885632984340191,
0.014924928545951843,
0.03380824625492096,
-0.005528251174837351,
-0.019935889169573784,
0.06193080544471741,
0.003607532475143671,
-0.021573223173618317,
-0.026305299252271652,
0.024308111518621445,
-0.013710422441363335,
-0.00950013566762209,
0.09154675900936127,
-0.011587286368012428,
-0.02394825778901577,
0.022670777514576912,
-0.043326374143362045,
0.03438401222229004,
-0.011794202029705048,
0.0022130997385829687,
-0.0027348874136805534,
-0.03406014293432236,
-0.04804045706987381,
0.0163283571600914,
0.035031747072935104,
-0.06254255771636963,
0.04109528288245201,
-0.05293446406722069,
0.013710422441363335,
-0.0842057466506958,
0.05775650218129158,
-0.02193307690322399,
0.023696359246969223,
-0.04699688032269478,
-0.024128183722496033,
0.04915600270032883,
0.001685689203441143,
-0.043470315635204315,
0.053474247455596924,
0.02612537145614624,
-0.053618188947439194,
-0.07600108534097672,
-0.024703949689865112,
0.0307494904845953,
0.02538767270743847,
0.006477364804595709,
-0.045197613537311554,
0.027096977457404137,
0.02614336460828781,
0.009680061601102352,
-0.048688191920518875,
-0.029094163328409195,
-0.03267470747232437,
0.012181044556200504,
0.02785266935825348,
0.05185490474104881,
-0.07967159152030945,
-0.04019564762711525,
-0.011461337096989155,
-0.011497322469949722,
-0.03218890354037285,
-0.005168397445231676,
-0.0770086720585823,
0.011497322469949722,
0.06822824478149414,
-0.011461337096989155,
0.014016297645866871,
-0.0003587290702853352,
-0.04584534838795662,
-0.015572665259242058,
0.0545538067817688,
0.08434968441724777,
0.04706885293126106,
0.0005864489357918501,
0.0002034016215475276,
-0.002017429331317544,
0.0031667116563767195,
0.0191442109644413,
-0.00037053675623610616,
0.0023412974551320076,
-0.02468595653772354,
0.031109344214200974,
-0.055201541632413864,
0.03742477670311928,
0.005910595413297415,
-0.04771658778190613,
0.028770295903086662,
-0.03047960065305233,
-0.02193307690322399,
-0.002761876443400979,
0.05649701505899429,
-0.031559161841869354,
0.08665274828672409,
-0.001249366789124906,
-0.005937584675848484,
0.030731497332453728,
-0.028338471427559853,
-0.047392718493938446,
-0.008578009903430939,
0.03479784354567528,
0.08974748849868774,
-0.01801067218184471,
0.026665152981877327,
-0.0006865332252345979,
0.09701653569936752,
-0.026215335354208946,
-0.0016969346906989813,
-0.0008507164311595261,
0.032278869301080704,
0.02959795854985714,
-0.048688191920518875,
-0.03893616050481796,
-0.01161427516490221,
-0.022904682904481888,
-0.03567948564887047,
-0.007062126882374287,
-0.005429291166365147,
-0.011560297571122646,
0.02450603060424328,
0.044801775366067886,
0.019234174862504005,
0.037964556366205215,
-0.05764854699373245,
0.051890891045331955,
-0.03573346138000488,
0.009689058177173138,
0.007844808511435986,
0.056245118379592896,
-0.022113004699349403,
0.021897092461586,
-0.027456829324364662,
0.02729489654302597,
-0.01022883877158165,
0.0062974379397928715,
-0.036920979619026184,
0.04102331027388573,
0.04408206790685654,
0.004799547605216503,
0.002406521001830697,
-0.02421814762055874,
0.04408206790685654,
0.0009159398614428937,
-0.012558890506625175,
0.0012549894163385034,
0.013161645270884037,
0.04865220934152603,
0.006990156136453152,
0.007610903587192297,
-0.011704238131642342,
-0.03391620144248009,
0.04102331027388573,
0.05383409932255745,
-0.01523080375045538,
-0.032278869301080704,
-0.03479784354567528,
-0.0033016568049788475,
0.0013618209632113576,
0.01487994659692049,
-0.048832133412361145,
0.0004045541863888502,
0.02438008226454258,
0.034887805581092834,
-0.007385995239019394,
-0.05656898766756058,
0.042606666684150696,
-0.0188923142850399,
0.0062254671938717365,
0.026035407558083534,
-0.003920155111700296,
-0.07412984222173691,
-0.026485225185751915,
-0.06405394524335861,
-0.0184245053678751,
0.02655719593167305,
0.03233284503221512,
0.012963726185262203,
-0.04652906954288483,
-0.014097264967858791,
0.021285340189933777,
0.10730834305286407,
-0.012172047980129719,
-0.0073365154676139355,
0.03600335493683815,
0.002872081706300378,
0.05271855369210243,
-0.021393297240138054,
0.00359178869985044,
0.03181105852127075,
0.04778856039047241,
-0.014924928545951843,
-0.02002585306763649,
-0.036363206803798676,
0.021267348900437355,
0.04652906954288483,
-0.020511655136942863,
-0.006841716822236776,
0.03611131012439728,
0.022454865276813507,
0.010381776839494705,
-0.030533578246831894,
-0.02481190674006939,
0.03632722049951553,
-0.04789651557803154,
0.00859600305557251,
0.04408206790685654,
0.01312565989792347,
0.018910307437181473,
0.02815854549407959,
0.03657912090420723,
-0.044945716857910156,
0.04249871149659157,
-0.02610737830400467,
0.007718859706073999,
0.041850972920656204,
0.0729423239827156,
0.021807128563523293,
-0.004028111230581999,
0.04598928987979889,
0.027744712308049202,
0.0009091926040127873,
0.055525410920381546,
-0.02614336460828781,
0.04393812641501427,
-0.05066738650202751,
0.010993527248501778,
-0.055345483124256134,
-0.043470315635204315,
-0.01651727966964245,
0.015140840783715248,
0.06833620369434357,
0.0010435754666104913,
-0.07006349414587021,
0.006113013252615929,
-0.03616528585553169,
-0.015473704785108566,
-0.02018778771162033,
0.00873994454741478,
-0.016508284956216812,
-0.013539492152631283,
0.06657291948795319,
0.02450603060424328,
0.024901868775486946,
-0.0010171487228944898,
-0.07171882688999176,
0.031703103333711624,
-0.03299857676029205,
-0.01684114895761013,
0.10442951321601868,
0.03204496204853058,
-0.06261453032493591,
0.05908796191215515,
0.018838336691260338,
0.019504064694046974,
-0.03654313459992409,
-0.078448086977005,
0.028194529935717583,
-0.012684839777648449,
0.022418878972530365,
-0.0660691186785698,
0.10039915889501572,
0.015572665259242058,
-0.014484107494354248,
-0.07628896832466125,
-0.013845367357134819,
0.012675843201577663,
-0.00504244863986969,
0.02396625094115734,
-0.020277751609683037,
-0.05937584489583969,
-0.010273820720613003,
0.035337623208761215,
-0.05448183789849281,
-0.03699295222759247,
-0.03961988165974617,
0.050163593143224716,
0.03742477670311928,
-0.04239075630903244,
-0.0076918709091842175,
-0.02279672585427761,
-0.022526836022734642,
-0.04005170613527298,
-0.008069717325270176,
-0.00994095578789711,
0.011020516976714134,
-0.03314251825213432,
0.014412136748433113,
0.00455439742654562,
0.04660104215145111,
-0.01444812212139368,
0.0034905800130218267,
0.030155731365084648,
-0.022418878972530365,
-0.08298224210739136,
-0.002602191409096122,
0.008281131274998188,
0.03060554899275303,
-0.03495977818965912,
0.010759622789919376,
0.06139102578163147,
-0.032278869301080704,
-0.01743490807712078,
-0.030083760619163513,
0.04300250485539436,
0.005465276539325714,
0.03800054267048836,
-0.00279561267234385,
0.00004013211218989454,
0.024613985791802406,
0.04051951691508293,
-0.026791101321578026,
0.020403699949383736,
0.0029957813676446676,
0.01204609964042902,
0.047248777002096176,
0.019648006185889244,
-0.014538086019456387,
-0.01961202174425125,
0.03328645974397659,
0.04829235374927521,
-0.05315037816762924,
0.03675904497504234,
0.02468595653772354,
0.004221532493829727,
0.0037402284797281027,
0.02132132649421692,
-0.002280572196468711,
-0.02016979455947876,
-0.010327798314392567,
-0.023570410907268524,
-0.0028226017020642757,
-0.008132691495120525,
0.05153103545308113,
-0.023696359246969223,
0.0698835700750351,
-0.0011594033567234874,
-0.0368490107357502,
-0.014601060189306736,
-0.022544829174876213,
-0.041419148445129395,
0.02556759864091873,
0.028392449021339417,
0.0478605292737484,
0.03587740287184715,
0.04732074961066246,
0.005420295055955648,
-0.013899345882236958,
0.0204576775431633,
0.007026141509413719,
0.03307054564356804,
-0.04059148579835892,
-0.02686307206749916,
0.015986496582627296,
0.020691582933068275,
-0.05631709098815918,
0.058404240757226944,
0.00021549046505242586,
-0.011137468740344048,
0.043902140110731125,
-0.028212523087859154,
0.007493951357901096,
-0.002604440553113818,
-0.021861106157302856,
0.019090233370661736,
-0.04293053597211838,
0.007075621746480465,
-0.011506319046020508,
0.04343432933092117,
0.0176418237388134,
0.0009873483795672655,
0.007363504264503717,
-0.04372221231460571,
0.005744163412600756,
0.006144500337541103,
0.04015966132283211,
-0.017902716994285583,
0.020367713645100594,
0.039116088300943375,
0.060887228697538376,
-0.006913687568157911,
-0.03510371968150139,
-0.02117738500237465,
-0.03019171766936779,
-0.010408765636384487,
0.024775920435786247,
0.005204382818192244,
0.020637603476643562,
-0.0030385139398276806,
0.013989308848977089,
-0.005114419385790825,
0.020259758457541466,
0.08816413581371307,
-0.0204576775431633,
0.06704072654247284,
0.002948550507426262,
0.0005229122471064329,
0.01138936635106802,
-0.041850972920656204,
0.009608090855181217,
0.0068192258477211,
0.014834964647889137,
-0.08240647614002228,
-0.015725603327155113,
0.07484955340623856,
-0.02016979455947876,
-0.03501375764608383,
-0.005280851852148771,
0.016994087025523186,
-0.04422600939869881,
0.008222654461860657,
-0.06426985561847687,
-0.04901206120848656,
0.07096312940120697,
-0.012675843201577663,
-0.02511778101325035,
0.0009204380330629647,
-0.00779982702806592,
-0.06696875393390656,
0.035481564700603485,
-0.03800054267048836,
-0.043326374143362045,
-0.04512564092874527,
0.00751194404438138,
-0.0466730110347271,
-0.006351415999233723,
-0.02321055717766285,
0.014996899291872978,
0.02612537145614624,
0.017371932044625282,
-0.04469381645321846,
0.05343826115131378,
-0.0004014616715721786,
-0.08398982882499695,
-0.03614729642868042,
0.09125887602567673,
0.004115825518965721,
-0.10637272894382477,
-0.020655596628785133,
0.00907730683684349,
-0.02049366384744644,
0.07448969781398773,
-0.053618188947439194,
-0.00700365100055933,
-0.04915600270032883,
-0.01961202174425125,
-0.06401795893907547,
-0.029220113530755043,
-0.0324048176407814,
-0.011137468740344048,
0.044190023094415665,
-0.029669929295778275,
-0.022292930632829666,
0.058152344077825546,
0.06052737683057785,
-0.031595148146152496,
-0.026485225185751915,
0.043794184923172,
0.027510808780789375,
-0.020655596628785133,
0.04314644634723663,
-0.026053400710225105,
0.04962381348013878,
-0.02396625094115734,
0.037964556366205215,
-0.007345511578023434,
0.0466730110347271,
0.002161370823159814,
-0.0021445024758577347,
-0.03818046674132347,
0.04307447746396065,
0.00416530529037118,
-0.00047455693129450083,
-0.07189875096082687,
-0.01575259119272232,
0.004727576859295368,
-0.04947987198829651,
-0.04937191307544708,
0.018766365945339203,
-0.01370142586529255,
-0.055921249091625214,
-0.026161357760429382,
-0.00765588553622365,
0.017875727266073227,
-0.01661624014377594,
-0.040267620235681534,
-0.03742477670311928,
0.015212811529636383,
-0.06520547717809677,
-0.03326846659183502,
0.025477634742856026,
0.007089116144925356,
0.013449528254568577,
-0.06761649250984192,
0.05037950351834297,
0.04436995089054108,
0.008681468665599823,
0.017731785774230957,
0.002723641926422715,
0.009895973838865757,
0.01900027133524418,
0.010210846550762653,
0.02306661568582058,
0.016175419092178345,
-0.018676402047276497,
0.0397278368473053,
-0.03400616720318794,
-0.058116357773542404,
-0.059447817504405975,
0.015446715988218784,
0.00022968780831433833,
-0.038684263825416565,
-0.03699295222759247,
-0.026449240744113922,
0.06211073324084282,
0.015932518988847733,
0.021267348900437355,
-0.05466176196932793,
-0.02857237681746483,
-0.016256386414170265,
-0.010462743230164051,
-0.00198931572958827,
0.0368490107357502,
-0.004052851349115372,
-0.018496476113796234,
0.08298224210739136,
-0.03020971082150936,
0.08291026949882507,
-0.018019668757915497,
-0.06901992112398148,
0.030947409570217133,
-0.049551840871572495,
0.017758775502443314,
0.06254255771636963,
0.0009401175193488598,
0.004772558342665434,
-0.019378116354346275,
-0.0177677720785141,
-0.06722065061330795,
0.005505760200321674,
-0.041419148445129395,
-0.006846214644610882,
0.02308460883796215,
0.005577730946242809,
-0.01731795445084572,
-0.006081526167690754,
-0.06628503650426865,
0.009018830955028534,
-0.0006651668809354305,
0.04253469780087471,
-0.004048353061079979,
-0.0037379793357104063,
0.01928815245628357,
0.030677519738674164,
-0.027744712308049202,
-0.018910307437181473,
0.0665009468793869,
0.0324048176407814,
-0.018478482961654663,
-0.04102331027388573,
-0.04588133469223976,
-0.07664881646633148,
-0.045521482825279236,
0.03204496204853058,
-0.007984251715242863,
-0.0007719984278082848,
-0.013440532609820366,
0.03477985039353371,
0.027528800070285797,
0.033592335879802704
]
|
31,085 | networkx.generators.community | ring_of_cliques | Defines a "ring of cliques" graph.
A ring of cliques graph is consisting of cliques, connected through single
links. Each clique is a complete graph.
Parameters
----------
num_cliques : int
Number of cliques
clique_size : int
Size of cliques
Returns
-------
G : NetworkX Graph
ring of cliques graph
Raises
------
NetworkXError
If the number of cliques is lower than 2 or
if the size of cliques is smaller than 2.
Examples
--------
>>> G = nx.ring_of_cliques(8, 4)
See Also
--------
connected_caveman_graph
Notes
-----
The `connected_caveman_graph` graph removes a link from each clique to
connect it with the next clique. Instead, the `ring_of_cliques` graph
simply adds the link without removing any link from the cliques.
| 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)
| (num_cliques, clique_size, *, backend=None, **backend_kwargs) | [
-0.0020874955225735903,
0.025789817795157433,
-0.038896117359399796,
-0.015624621883034706,
0.005974119994789362,
0.05996178463101387,
-0.034135203808546066,
-0.04176369681954384,
0.05385899171233177,
-0.012196396477520466,
-0.020017897710204124,
0.01990760676562786,
-0.003315636655315757,
0.05139581486582756,
-0.010156004689633846,
0.015238601714372635,
0.010872898623347282,
-0.04113870859146118,
0.020698027685284615,
0.034098438918590546,
-0.0118195666000247,
-0.018565727397799492,
-0.011700084432959557,
0.01693892851471901,
-0.03606530278921127,
0.02705816924571991,
0.022830329835414886,
0.00822590384632349,
-0.05510896071791649,
-0.0011270407121628523,
-0.02608392760157585,
-0.015624621883034706,
-0.022131817415356636,
-0.009898657910525799,
0.0026492925826460123,
0.05319724231958389,
0.037223365157842636,
0.0833803340792656,
-0.01354746613651514,
-0.02437441051006317,
-0.018933365121483803,
-0.049189984798431396,
0.006484217941761017,
-0.013924295082688332,
0.011350828222930431,
0.01889660209417343,
0.01270189881324768,
0.05584423616528511,
-0.0662851631641388,
-0.05025613680481911,
0.010661507025361061,
-0.03623073920607567,
0.03463151305913925,
0.0016716048121452332,
-0.026874350383877754,
0.012352642603218555,
0.0007823799387551844,
0.038565244525671005,
0.0652557760477066,
0.005165316164493561,
-0.01455847080796957,
-0.002312673721462488,
0.01742604933679104,
-0.009714838117361069,
-0.06672632694244385,
0.0011672511463984847,
-0.06834393739700317,
-0.03915346413850784,
0.036855727434158325,
0.06345434486865997,
0.07433643937110901,
0.043712176382541656,
-0.0019749063067138195,
0.012711089104413986,
0.06992477923631668,
0.04529302194714546,
-0.00011036325304303318,
0.002791752340272069,
-0.005188293755054474,
-0.05819712206721306,
0.020440680906176567,
0.016810255125164986,
0.02082670107483864,
-0.010725843720138073,
0.06970419734716415,
-0.004230136517435312,
0.0338410921394825,
0.008377554826438427,
-0.009457491338253021,
-0.04669004678726196,
0.022701656445860863,
0.0018117667641490698,
0.042021043598651886,
-0.036102067679166794,
0.0007031079730950296,
0.05915297940373421,
-0.018096989020705223,
-0.03389623761177063,
0.036193978041410446,
-0.034796953201293945,
0.04621211811900139,
-0.006332567427307367,
-0.06282936036586761,
0.020054662600159645,
-0.02090022899210453,
-0.055329542607069016,
0.0010092816082760692,
0.002803240902721882,
-0.0022896963637322187,
-0.03327125310897827,
-0.07543934881687164,
0.045440077781677246,
0.05441044643521309,
-0.004921755753457546,
0.01079937070608139,
-0.0014820413198322058,
-0.005762728396803141,
0.00956778321415186,
0.013731284998357296,
0.007348167710006237,
-0.04102841764688492,
0.03113895282149315,
-0.02189285308122635,
0.025624379515647888,
0.014383843168616295,
0.009264481253921986,
0.028308138251304626,
0.011157818138599396,
0.03222348541021347,
-0.022867092862725258,
0.02154359593987465,
-0.0161393154412508,
0.005413471721112728,
0.020495828241109848,
-0.003531624097377062,
-0.04209456965327263,
-0.10337985306978226,
-0.03657999634742737,
0.04834441840648651,
0.006102793384343386,
-0.012619179673492908,
-0.027572862803936005,
-0.017049219459295273,
0.04407981410622597,
0.009494255296885967,
0.04150635004043579,
0.010836134664714336,
-0.020367154851555824,
0.005303180310875177,
0.00828564539551735,
0.04422686994075775,
-0.004554117564111948,
-0.012407788075506687,
-0.04529302194714546,
-0.03156173601746559,
-0.006282017100602388,
-0.01695731095969677,
-0.029907364398241043,
-0.002117366064339876,
0.01957673206925392,
-0.024135446175932884,
0.0250361580401659,
-0.026175837963819504,
0.0512855239212513,
-0.009076067246496677,
-0.03705792501568794,
0.06066029518842697,
-0.01681944541633129,
-0.061836738139390945,
-0.027241988107562065,
-0.011212963610887527,
-0.029245615005493164,
-0.03797702118754387,
-0.05849123001098633,
0.030311767011880875,
-0.04889587685465813,
0.020017897710204124,
0.0001517943455837667,
-0.038528479635715485,
0.010670697316527367,
-0.035844720900058746,
-0.00918635819107294,
-0.015146692283451557,
-0.0212862491607666,
-0.0037705888971686363,
0.052241381257772446,
0.05444721132516861,
-0.00736195407807827,
0.05514572560787201,
-0.0404769629240036,
-0.0444842167198658,
-0.04282984510064125,
-0.05099141225218773,
0.07705695927143097,
-0.0012844358570873737,
0.014631998725235462,
-0.02465013787150383,
0.028602249920368195,
-0.10632095485925674,
0.02838166616857052,
0.0071459668688476086,
0.022462692111730576,
0.005597291048616171,
-0.04941057041287422,
0.0355873741209507,
-0.022462692111730576,
-0.034080058336257935,
-0.030293384566903114,
0.0512855239212513,
0.032425686717033386,
0.014347079209983349,
-0.024429555982351303,
0.07838045805692673,
0.02159874141216278,
0.015192647464573383,
-0.03985197842121124,
0.017876405268907547,
0.0038211392238736153,
-0.014540089294314384,
-0.0493738055229187,
-0.0012626072857528925,
-0.029962509870529175,
0.057020679116249084,
-0.031690411269664764,
0.022076671943068504,
-0.03450284153223038,
-0.015817631036043167,
-0.05099141225218773,
-0.041984278708696365,
-0.011396783404052258,
0.06345434486865997,
-0.03933728486299515,
0.024245737120509148,
-0.00009284299449063838,
-0.022499455139040947,
-0.017003264278173447,
0.016516145318746567,
-0.00634175818413496,
-0.02393324486911297,
0.04422686994075775,
-0.08646849542856216,
-0.015394847840070724,
0.02395162545144558,
0.017085984349250793,
0.03623073920607567,
0.05514572560787201,
-0.007816906087100506,
-0.0026010400615632534,
-0.02051420882344246,
0.02711331471800804,
-0.021157575771212578,
-0.06657927483320236,
-0.027333896607160568,
-0.0657704696059227,
0.03948433697223663,
-0.07418937981128693,
-0.056358929723501205,
0.007247067056596279,
0.011424356140196323,
-0.02536703273653984,
-0.02882283180952072,
-0.031047042459249496,
-0.04621211811900139,
0.0786745697259903,
0.005146934185177088,
-0.033087436109781265,
0.0018301487434655428,
0.07246147841215134,
-0.07007183134555817,
0.006998911499977112,
0.04010932520031929,
0.05062377452850342,
0.04904293268918991,
-0.010394969023764133,
0.0007364252232946455,
-0.013069536536931992,
-0.018767928704619408,
0.008699238300323486,
0.012233159504830837,
0.053564880043268204,
0.011010763235390186,
0.04209456965327263,
-0.037131454795598984,
-0.0018473818199709058,
-0.002162171993404627,
0.018767928704619408,
-0.024264119565486908,
-0.020973756909370422,
-0.007812310941517353,
-0.012812189757823944,
-0.0023896479979157448,
-0.02025686204433441,
-0.0029847624246031046,
-0.0031984520610421896,
0.04253573715686798,
0.010247914120554924,
0.03485209867358208,
0.018749546259641647,
0.026617003604769707,
0.03400652855634689,
0.04694739356637001,
-0.04106518253684044,
-0.037223365157842636,
-0.0041566090658307076,
0.03711307421326637,
-0.015119119547307491,
-0.004363405518233776,
-0.04963115230202675,
0.016460997983813286,
0.03553222864866257,
-0.040256377309560776,
-0.012665134854614735,
0.046800337731838226,
0.029245615005493164,
0.0294845812022686,
0.004076187964528799,
0.01643342524766922,
-0.02496263198554516,
0.0266905315220356,
0.07146885991096497,
-0.013639375567436218,
-0.0024241141509264708,
-0.020789938047528267,
0.003437416860833764,
-0.054631032049655914,
-0.01043173298239708,
-0.025955254212021828,
0.04165340214967728,
-0.0021368968300521374,
-0.008740597404539585,
-0.05709420517086983,
-0.03871230036020279,
0.04871205613017082,
0.04669004678726196,
-0.010523642413318157,
0.03634103387594223,
0.0725717768073082,
-0.07007183134555817,
0.04933704063296318,
-0.07786576449871063,
0.020275244489312172,
-0.007288426626473665,
-0.07018212229013443,
-0.00563865015283227,
0.0010776394046843052,
-0.007417100016027689,
0.03426387533545494,
-0.017453622072935104,
-0.04356512054800987,
-0.01885983720421791,
0.02262812852859497,
0.10168871283531189,
0.01230668742209673,
0.0725717768073082,
0.004301366396248341,
0.11029145121574402,
-0.005500786006450653,
-0.02873092330992222,
0.018078606575727463,
0.028675775974988937,
-0.0533810630440712,
-0.006052243057638407,
0.08257152885198593,
0.02770153619349003,
-0.038859352469444275,
-0.0046230498701334,
-0.009057684801518917,
0.005174506921321154,
0.0884537398815155,
-0.0762481540441513,
-0.004770105239003897,
-0.01596468687057495,
-0.04496214911341667,
0.0304404404014349,
-0.03904317319393158,
0.008639496751129627,
-0.11536485701799393,
0.015799250453710556,
-0.021819325163960457,
0.0006743862759321928,
-0.034080058336257935,
-0.02264651097357273,
0.033767566084861755,
0.03963139280676842,
0.004076187964528799,
-0.0533810630440712,
0.05514572560787201,
0.020422300323843956,
0.002096686279401183,
0.025550851598381996,
-0.030973514541983604,
-0.007766356226056814,
0.018970130011439323,
0.046101827174425125,
0.007826097309589386,
0.013823195360600948,
0.07032918184995651,
-0.007816906087100506,
-0.05863828584551811,
0.03354698047041893,
0.03606530278921127,
-0.0020691135432571173,
0.010670697316527367,
0.05312371626496315,
-0.03459475189447403,
-0.02297738566994667,
0.032021284103393555,
0.013777240179479122,
0.014163260348141193,
0.03801378607749939,
-0.07330705225467682,
-0.006649655289947987,
0.04687386751174927,
-0.042940136045217514,
-0.04279308393597603,
-0.06441020965576172,
-0.033455073833465576,
0.028491957113146782,
0.10705623030662537,
-0.01285814493894577,
0.09602709114551544,
-0.0608808808028698,
0.056028056889772415,
0.014154069125652313,
-0.0039429194293916225,
-0.03498077020049095,
0.023859716951847076,
-0.04768266901373863,
-0.041984278708696365,
-0.017177892848849297,
-0.03259112313389778,
0.004230136517435312,
0.07301294058561325,
-0.06566017866134644,
0.0425724983215332,
-0.013041963800787926,
-0.014631998725235462,
0.016810255125164986,
-0.029650017619132996,
-0.004230136517435312,
0.0889684334397316,
0.017407666891813278,
-0.004696577321738005,
-0.027572862803936005,
0.051910508424043655,
0.015155883505940437,
-0.02025686204433441,
-0.00995380338281393,
-0.015413230285048485,
0.0329771414399147,
0.04786648973822594,
-0.00993542093783617,
0.021984761580824852,
0.004324343986809254,
0.0013499213382601738,
0.03948433697223663,
0.05930003523826599,
0.02227887324988842,
-0.049520861357450485,
-0.010450114496052265,
0.0954388678073883,
-0.03213157504796982,
-0.02086346596479416,
0.0662851631641388,
-0.011690893210470676,
0.049447331577539444,
-0.00287447078153491,
-0.004999878816306591,
0.011700084432959557,
-0.0011649534571915865,
0.03385947644710541,
0.029631635174155235,
-0.03018309362232685,
-0.07231442630290985,
-0.028234610334038734,
-0.03674543276429176,
-0.07749812304973602,
0.008763574995100498,
-0.015321320854127407,
-0.006277421489357948,
-0.015707340091466904,
-0.005303180310875177,
0.06073382496833801,
-0.009494255296885967,
-0.03930051997303963,
-0.04900616779923439,
-0.0016141613014042377,
-0.036782197654247284,
-0.011405973695218563,
0.012104486115276814,
-0.016194460913538933,
-0.09146837145090103,
0.01404377818107605,
0.005133147817105055,
0.03696601837873459,
0.00993542093783617,
0.0019186116987839341,
-0.026469947770237923,
0.03626750409603119,
-0.00548240402713418,
0.015100737102329731,
0.046800337731838226,
0.0315801165997982,
-0.03599177673459053,
0.05694715306162834,
0.01596468687057495,
0.021084047853946686,
-0.045734185725450516,
-0.050513483583927155,
0.0017692586407065392,
0.01571653224527836,
0.00045035674702376127,
-0.0010822347830981016,
-0.022701656445860863,
0.028216229751706123,
0.020495828241109848,
0.04930027574300766,
0.032021284103393555,
0.02257298305630684,
-0.00650259992107749,
0.020679647102952003,
0.047094449400901794,
-0.023179586976766586,
0.09330656379461288,
-0.017361711710691452,
0.00011065047146985307,
-0.01814294420182705,
-0.04555036872625351,
-0.021028902381658554,
0.017490385100245476,
-0.025881726294755936,
0.01098319049924612,
-0.03882259130477905,
0.05720449984073639,
0.02365751564502716,
-0.022720038890838623,
-0.011249727569520473,
0.025771435350179672,
0.052278146147727966,
0.011856330558657646,
-0.022205345332622528,
-0.016552908346056938,
0.04492538422346115,
0.009917039424180984,
0.0010213447967544198,
0.031304389238357544,
0.02840004861354828,
0.02060611918568611,
0.0048298463225364685,
-0.037186600267887115,
-0.042315151542425156,
0.042021043598651886,
-0.03319772705435753,
-0.012830572202801704,
0.08999782055616379,
-0.04113870859146118,
-0.039557866752147675,
-0.04992526397109032,
0.038528479635715485,
0.07080710679292679,
0.007476841099560261,
-0.02838166616857052,
-0.06742484122514725,
-0.005404280964285135,
0.036855727434158325,
0.011801185086369514,
-0.016359897330403328,
-0.04150635004043579,
0.008267262950539589,
0.003407546319067478,
0.017784496769309044,
-0.0101192407310009,
-0.036524850875139236,
0.006323376204818487,
-0.010064094327390194,
-0.03121248073875904,
-0.046726811677217484,
-0.017959123477339745,
0.010790180414915085,
-0.010146813467144966,
-0.022885475307703018,
0.022150199860334396,
0.07580699026584625,
-0.03499915450811386,
0.041984278708696365,
0.04591800644993782,
-0.09117426723241806,
-0.04044019803404808,
0.02124948613345623,
0.03882259130477905,
0.02803240902721882,
0.0031938564497977495,
-0.021800942718982697,
-0.010450114496052265,
-0.06764542311429977,
-0.001372898812405765,
0.011617366224527359,
-0.008019107393920422,
-0.028252992779016495,
-0.035513848066329956,
-0.05610158294439316,
0.026157455518841743,
0.003970492165535688,
0.055954527109861374,
0.027811827138066292,
-0.013593421317636967,
-0.04871205613017082,
-0.032719794660806656,
0.012343451380729675,
0.03078969568014145,
-0.043712176382541656,
0.022738419473171234,
-0.014953682199120522,
-0.06871157139539719,
-0.0030330149456858635,
-0.038491714745759964,
-0.025183213874697685,
0.006870238110423088,
0.01955834962427616,
-0.051579635590314865,
0.023124439641833305,
-0.00020550399494823068,
0.0066634416580200195,
-0.0212862491607666,
-0.016222033649683,
0.024944249540567398,
-0.02299576625227928,
-0.002151832217350602,
0.022150199860334396,
0.029980892315506935,
-0.0031662837136536837,
-0.011047527194023132,
0.03915346413850784,
-0.02088184840977192,
0.024135446175932884,
-0.02840004861354828,
0.024264119565486908,
0.0025022372137755156,
0.010128431022167206,
-0.005514572374522686,
-0.020073043182492256,
0.04514596611261368,
-0.017766114324331284,
-0.07668931782245636,
-0.1067621260881424,
-0.0011115310480818152,
0.03295876085758209,
0.05135904997587204,
0.0006749606691300869,
0.02053259126842022,
0.007077034562826157,
-0.000628431502263993,
0.05470455810427666,
-0.05385899171233177,
0.014806627295911312,
-0.028547102585434914,
-0.03571604564785957,
0.028547102585434914,
0.042940136045217514,
-0.04900616779923439,
0.029741927981376648,
0.044337160885334015,
0.060476478189229965,
-0.004728745669126511,
0.00866247434169054,
0.02295900322496891,
0.018565727397799492,
-0.013354456052184105,
-0.028014028444886208,
0.03808731213212013,
-0.04532978683710098,
-0.012830572202801704,
0.0650719553232193,
-0.016718344762921333,
-0.03707630932331085,
0.0418739877641201,
-0.041249003261327744,
0.014466561377048492,
-0.03805055096745491,
0.04069754481315613,
0.027609625831246376,
0.02334502339363098,
-0.034760188311338425,
-0.00042536883847787976,
-0.006787519436329603,
-0.00548240402713418,
-0.03483371436595917,
-0.053270768374204636,
-0.011856330558657646,
0.0058086831122636795,
0.009043898433446884,
-0.010689079761505127,
-0.005082597490400076,
-0.025458943098783493,
-0.02812431938946247,
0.04525625705718994,
-0.03360212966799736,
0.00006415716779883951,
0.005408876575529575,
0.013427983969449997,
0.055623654276132584,
0.028289755806326866,
-0.008598137646913528,
0.04624887928366661,
-0.021856088191270828,
-0.024117063730955124,
-0.03963139280676842,
0.053601644933223724,
0.028877977281808853,
0.01167251169681549,
-0.020679647102952003,
-0.008690047077834606,
0.00012946320930495858,
0.006654250901192427,
-0.03762776777148247,
-0.022517837584018707,
0.024503083899617195,
0.09911524504423141,
-0.012591606937348843,
-0.007430886384099722,
0.00978836603462696,
0.020495828241109848,
0.03391462191939354,
-0.0024907486513257027,
-0.06102793663740158,
-0.02051420882344246,
0.05415309965610504,
-0.02775668166577816,
0.038234367966651917,
-0.02812431938946247,
-0.028933122754096985,
0.08117450773715973,
-0.02433764562010765,
0.04279308393597603,
-0.009439109824597836,
-0.05683685839176178,
-0.018391098827123642,
0.025808198377490044,
-0.04702091962099075,
0.0032581931445747614,
-0.06668956577777863,
0.009751602075994015,
-0.04044019803404808,
0.008565968833863735,
-0.02360237017273903,
-0.027536097913980484,
0.04374894127249718,
0.009990567341446877,
-0.00607981625944376,
-0.020992139354348183,
0.00720111234113574,
-0.002293142955750227,
0.023749426007270813,
0.007734187878668308,
-0.046432700008153915,
-0.03689248859882355,
0.003621235955506563,
-0.054300155490636826,
-0.05415309965610504,
-0.07565993070602417,
-0.006824283394962549,
0.012582415714859962,
-0.006355544552206993,
-0.002771072555333376,
-0.00796396192163229,
0.04113870859146118,
0.04003579542040825,
0.023087676614522934
]
|
31,092 | networkx.generators.small | sedgewick_maze_graph |
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
| 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.0845726802945137,
-0.022371619939804077,
-0.013746521435678005,
-0.033756405115127563,
-0.061906926333904266,
0.023340538144111633,
-0.06273742765188217,
0.055020689964294434,
-0.0002573687816038728,
-0.01574491336941719,
-0.0067694480530917645,
0.03145522251725197,
-0.006881911773234606,
0.07730580121278763,
0.02403262071311474,
-0.013391828164458275,
0.04294382035732269,
-0.0033912123180925846,
-0.024465173482894897,
0.05252918601036072,
-0.010900325141847134,
-0.039898648858070374,
0.040037065744400024,
0.044120363891124725,
-0.026991281658411026,
0.027666063979268074,
-0.014775996096432209,
0.05422479286789894,
-0.008248778060078621,
-0.03309892490506172,
-0.017293451353907585,
-0.044120363891124725,
-0.058308087289333344,
0.018495948985219002,
0.030088357627391815,
0.06394857168197632,
0.0018934989348053932,
0.048169054090976715,
-0.080489382147789,
-0.052356164902448654,
0.03768398240208626,
-0.005277141463011503,
0.05218314379453659,
-0.004593708552420139,
0.04010627418756485,
-0.012829509563744068,
0.051075808703899384,
0.021004753187298775,
-0.025953155010938644,
-0.031905077397823334,
0.02667984366416931,
-0.0239288080483675,
-0.01641104556620121,
0.03595377132296562,
0.034846436232328415,
-0.016878202557563782,
-0.022475432604551315,
-0.00799357146024704,
0.10263607650995255,
-0.04761538654565811,
0.005329047795385122,
-0.01415312010794878,
0.02725081332027912,
0.04097137972712517,
-0.045781366527080536,
-0.013928193598985672,
-0.03418895602226257,
-0.05488227307796478,
-0.0005807018605992198,
0.004801333881914616,
0.04519309476017952,
0.035746145993471146,
0.04508928209543228,
-0.010139032267034054,
0.03668045997619629,
0.029621200636029243,
-0.01472408976405859,
-0.03591916710138321,
-0.0443279892206192,
-0.047407761216163635,
0.01979360543191433,
0.016999317333102226,
-0.027129698544740677,
-0.053498104214668274,
0.03116108849644661,
0.03206079825758934,
0.03048630617558956,
0.04301302880048752,
-0.011782732792198658,
-0.09647652506828308,
0.01617746613919735,
-0.013089041225612164,
-0.027147000655531883,
-0.011505899019539356,
-0.008633749559521675,
0.0041914344765245914,
0.020399179309606552,
-0.06007290259003639,
0.005826483480632305,
-0.019378354772925377,
-0.04176727682352066,
0.009611318819224834,
-0.08471109718084335,
0.012492118403315544,
-0.05266760289669037,
-0.04287461191415787,
-0.02444787137210369,
0.004031389951705933,
-0.017137734219431877,
-0.040313899517059326,
-0.04176727682352066,
-0.00213464698754251,
0.02721620909869671,
0.004476919304579496,
0.03131680563092232,
0.036265209317207336,
0.024136433377861977,
0.016592716798186302,
0.03456960245966911,
-0.06557497382164001,
-0.019620584324002266,
0.009810292162001133,
-0.047407761216163635,
-0.037130314856767654,
0.03692268952727318,
-0.029621200636029243,
0.03477722778916359,
-0.013071739114820957,
0.008568867109715939,
-0.012820858508348465,
0.02055489830672741,
0.0062201060354709625,
-0.039414189755916595,
0.03216461092233658,
-0.05169868469238281,
0.008205522783100605,
-0.04180188104510307,
-0.043843530118465424,
0.02531297691166401,
0.02911943942308426,
0.01132422685623169,
-0.02873879298567772,
0.0018459181301295757,
0.028237031772732735,
-0.06311807036399841,
-0.0024395964574068785,
-0.018617063760757446,
0.00851696077734232,
0.06083419546484947,
0.02792559564113617,
0.028479261323809624,
-0.009057651273906231,
0.021229680627584457,
0.027077792212367058,
-0.021471910178661346,
-0.03176666051149368,
-0.0013073901645839214,
0.059484630823135376,
0.015182595700025558,
0.05879254639148712,
0.011289622634649277,
-0.02569362334907055,
0.01289006695151329,
0.011981706134974957,
-0.03685348108410835,
-0.010441819205880165,
0.008625098504126072,
0.011748128570616245,
-0.012215284630656242,
0.01327071338891983,
-0.02744113653898239,
0.010580236092209816,
-0.057442981749773026,
-0.02493233047425747,
0.06387936323881149,
0.00006974910502322018,
-0.025555206462740898,
-0.005255513824522495,
0.02012234553694725,
-0.043981947004795074,
-0.01949946954846382,
-0.012379654683172703,
0.014516464434564114,
-0.005882715340703726,
0.002740220632404089,
0.0038735084235668182,
0.01218068040907383,
-0.008547239005565643,
0.032666370272636414,
0.016670577228069305,
-0.010519678704440594,
0.005359326489269733,
0.03387751802802086,
0.07197675108909607,
0.04059073328971863,
-0.02360006980597973,
0.030330587178468704,
0.02411913126707077,
-0.05612802132964134,
0.07536796480417252,
-0.014118515886366367,
0.03225111961364746,
0.011765430681407452,
-0.02697397954761982,
0.05297904089093208,
0.03496754914522171,
0.0047710551880300045,
-0.08111225813627243,
-0.01884199120104313,
0.037891607731580734,
-0.04775380343198776,
-0.01603039912879467,
0.05626643821597099,
0.02687016688287258,
-0.013426432386040688,
-0.031368713825941086,
0.008227149955928326,
0.06121484190225601,
0.03406784310936928,
-0.026005061343312263,
-0.05066055804491043,
0.007024653721600771,
-0.04896495118737221,
-0.020018532872200012,
0.014274234883487225,
-0.04328986257314682,
-0.04505467787384987,
-0.03920656442642212,
-0.015147991478443146,
-0.07426062971353531,
0.02074522152543068,
-0.028911814093589783,
0.03886052221059799,
-0.012552675791084766,
0.013236109167337418,
-0.011748128570616245,
-0.013288015499711037,
-0.018893897533416748,
0.00799357146024704,
-0.020900940522551537,
-0.05062595382332802,
-0.06377555429935455,
0.010052521713078022,
-0.03406784310936928,
0.04709632694721222,
0.03799542039632797,
-0.007491810712963343,
0.018340229988098145,
0.003068960504606366,
0.008361241780221462,
-0.03287399560213089,
-0.01486250665038824,
0.03278748691082001,
0.00009083604527404532,
-0.00456775538623333,
0.013763823546469212,
-0.058065857738256454,
0.0036096512340009212,
-0.01626397669315338,
0.022042879834771156,
-0.02150651440024376,
-0.027371928095817566,
-0.023150214925408363,
-0.01721559278666973,
0.04062533751130104,
0.011073346249759197,
-0.05623183399438858,
0.07495271414518356,
-0.08664893358945847,
-0.045642949640750885,
0.038030024617910385,
0.014516464434564114,
0.014767345041036606,
0.006367173977196217,
0.017206942662596703,
-0.0034431186504662037,
-0.02588394656777382,
-0.0037783468142151833,
-0.0013939007185399532,
-0.03557312488555908,
-0.09550760686397552,
-0.035469312220811844,
0.012137425132095814,
0.05408637598156929,
-0.050971996039152145,
-0.0022233203053474426,
0.01612555980682373,
0.009403693489730358,
0.04142123460769653,
-0.03015756607055664,
-0.01746647246181965,
-0.04218252748250961,
0.01415312010794878,
0.0007018165779300034,
0.0415942557156086,
-0.004472593776881695,
0.022060181945562363,
-0.008555890060961246,
-0.028704188764095306,
0.047649990767240524,
0.08914043754339218,
-0.06121484190225601,
0.007790272124111652,
0.018444042652845383,
0.023098308593034744,
0.03892973065376282,
0.0019032313721254468,
-0.02398071438074112,
0.049830056726932526,
-0.03553852066397667,
-0.08969410508871078,
0.015000923536717892,
-0.004922448191791773,
0.05751219019293785,
-0.027458438649773598,
-0.04204411059617996,
-0.029188647866249084,
-0.030036451295018196,
0.05588579550385475,
0.04903415963053703,
-0.007855154573917389,
0.018115302547812462,
-0.016013097018003464,
0.008529936894774437,
-0.0674436017870903,
0.014464558102190495,
0.018340229988098145,
0.046162012964487076,
0.012656488455832005,
0.018063396215438843,
-0.02683556266129017,
-0.03692268952727318,
0.015900632366538048,
0.018149906769394875,
-0.05131803825497627,
0.01887659542262554,
0.013685964047908783,
-0.007721063680946827,
-0.022285109385848045,
-0.044639427214860916,
0.09052460640668869,
0.023911505937576294,
-0.013166900724172592,
-0.01110795047134161,
0.06169930100440979,
0.01641104556620121,
-0.007859480567276478,
-0.050452932715415955,
-0.012146076187491417,
0.04695791006088257,
0.03647283464670181,
0.07038495689630508,
-0.01703392155468464,
0.006899213884025812,
0.030313285067677498,
0.03391212224960327,
0.016142861917614937,
0.010164985433220863,
-0.03524438291788101,
0.029102137312293053,
-0.0633603036403656,
0.02183525450527668,
0.004861890804022551,
-0.0016069328412413597,
-0.02183525450527668,
-0.025624414905905724,
-0.017059873789548874,
0.032372236251831055,
0.053774937987327576,
-0.059346213936805725,
-0.02117777429521084,
-0.05924240127205849,
-0.021420003846287727,
0.0329085998237133,
-0.008227149955928326,
0.06536734849214554,
-0.03437928110361099,
0.009767036885023117,
0.06349872052669525,
0.004284433554857969,
0.011895195581018925,
-0.0017983373254537582,
0.008452077396214008,
-0.002917567268013954,
0.08055859059095383,
-0.02849656343460083,
0.045123886317014694,
0.035036757588386536,
0.017388613894581795,
-0.056301042437553406,
-0.09433107078075409,
-0.02430945448577404,
0.056923918426036835,
0.06813568621873856,
-0.005515045486390591,
0.025243768468499184,
0.08215038478374481,
0.04647345095872879,
-0.036230605095624924,
0.046542659401893616,
0.07751341909170151,
-0.04287461191415787,
0.03206079825758934,
0.043878134340047836,
-0.028202427551150322,
-0.06550576537847519,
-0.027095094323158264,
0.010787861421704292,
0.02659333311021328,
0.01865166798233986,
0.04889574274420738,
-0.04875732585787773,
-0.048549700528383255,
0.01808069832623005,
-0.002759685507044196,
0.010796512477099895,
0.01551133580505848,
0.026143478229641914,
0.058446504175662994,
0.006942469161003828,
0.051352642476558685,
-0.012172029353678226,
0.00032711788662709296,
0.038756709545850754,
0.04252856969833374,
-0.016956061124801636,
-0.024482475593686104,
-0.005722670815885067,
-0.052356164902448654,
0.04789222031831741,
-0.010095776990056038,
-0.0609034039080143,
0.05761600285768509,
-0.021437305957078934,
-0.01775195822119713,
0.005207933019846678,
0.03328924626111984,
-0.018582459539175034,
0.022371619939804077,
0.01868627220392227,
0.03187047317624092,
-0.014144469052553177,
-0.02958659641444683,
-0.03067662939429283,
0.0199839286506176,
-0.03083234839141369,
-0.007275534328073263,
-0.006233082618564367,
0.01645429991185665,
0.009334485046565533,
0.030711233615875244,
0.011601060628890991,
-0.03605758398771286,
0.011748128570616245,
-0.06169930100440979,
0.008093059062957764,
0.027147000655531883,
0.011479945853352547,
-0.03315082937479019,
0.05131803825497627,
0.03844527527689934,
-0.014525115489959717,
-0.020589502528309822,
0.06657849252223969,
-0.03882591798901558,
-0.015338314697146416,
0.021748743951320648,
0.005714019760489464,
0.0010235275840386748,
-0.06792806088924408,
0.03187047317624092,
-0.029655804857611656,
-0.05889635905623436,
-0.04591978341341019,
0.08886360377073288,
-0.04515849053859711,
-0.06342951208353043,
-0.02235431782901287,
0.03931037709116936,
-0.01698201522231102,
-0.06156088411808014,
-0.009594016708433628,
0.004948401357978582,
0.030797744169831276,
-0.010528329759836197,
0.00042768637649714947,
0.05000307783484459,
-0.08519555628299713,
-0.022146692499518394,
-0.0421479232609272,
0.0028829630464315414,
-0.03474262356758118,
-0.027960199862718582,
-0.00008745672676013783,
-0.0063888016156852245,
0.07806708663702011,
-0.030520910397171974,
-0.031420618295669556,
-0.004420687444508076,
-0.07647529989480972,
0.028842605650424957,
-0.015684356912970543,
-0.03844527527689934,
-0.02117777429521084,
-0.02316751703619957,
0.04394734278321266,
0.02316751703619957,
-0.012388305738568306,
0.018478646874427795,
0.027614157646894455,
0.056162625551223755,
-0.009057651273906231,
0.0033284921664744616,
0.0766829252243042,
0.022181296721100807,
0.03001914918422699,
-0.007638878654688597,
0.014992272481322289,
0.05498608574271202,
-0.0592770054936409,
0.015329663641750813,
0.024292152374982834,
0.028133219107985497,
0.03591916710138321,
-0.043981947004795074,
0.059969089925289154,
0.030417097732424736,
0.03368719667196274,
0.040313899517059326,
0.03768398240208626,
0.03155903518199921,
0.07142308354377747,
-0.028583073988556862,
0.0793820470571518,
0.033756405115127563,
-0.0443279892206192,
0.04744236543774605,
0.014334792271256447,
-0.019759001210331917,
-0.03858369216322899,
0.005181979853659868,
-0.029655804857611656,
-0.03406784310936928,
-0.022959891706705093,
-0.011376133188605309,
0.0018026628531515598,
0.09481552243232727,
-0.028981022536754608,
-0.023669278249144554,
-0.09813752770423889,
-0.0218871608376503,
0.03225111961364746,
-0.005225235130637884,
-0.005419883877038956,
0.08630289137363434,
-0.04965703561902046,
-0.023150214925408363,
-0.029465481638908386,
0.01674843579530716,
0.012820858508348465,
-0.06394857168197632,
-0.011229065246880054,
0.014032005332410336,
-0.009074953384697437,
-0.009074953384697437,
0.02240622416138649,
0.005441511515527964,
0.022319713607430458,
-0.024205641821026802,
0.025676321238279343,
0.029811523854732513,
0.04391273856163025,
0.08616447448730469,
-0.02539948746562004,
-0.028271635994315147,
-0.007816225290298462,
0.0003444199974182993,
0.031472526490688324,
0.04951861873269081,
-0.023669278249144554,
-0.03399863466620445,
-0.014135817997157574,
0.0056967176496982574,
0.04034850373864174,
-0.018945803865790367,
0.03934498131275177,
-0.03657664731144905,
0.008343939669430256,
-0.021904462948441505,
0.013236109167337418,
0.051214225590229034,
-0.051352642476558685,
0.04128281772136688,
-0.0019919045735150576,
-0.04256317391991615,
-0.0029802871868014336,
0.025485998019576073,
0.019949324429035187,
0.023478955030441284,
0.01617746613919735,
-0.050729766488075256,
0.07218437641859055,
0.03540010377764702,
0.03415435180068016,
0.035607729107141495,
0.023340538144111633,
0.018582459539175034,
-0.018582459539175034,
0.001390656572766602,
-0.04394734278321266,
-0.010026568546891212,
0.007552368100732565,
-0.0166532751172781,
-0.05394795909523964,
-0.059103984385728836,
0.008179569616913795,
-0.0232540275901556,
0.008997093886137009,
-0.03155903518199921,
-0.024430569261312485,
0.00932583399116993,
-0.01089167408645153,
0.0016491067362949252,
-0.032943204045295715,
-0.012189331464469433,
0.0040075997821986675,
0.021714139729738235,
0.009922755882143974,
-0.013409130275249481,
0.04072915017604828,
-0.021766046062111855,
-0.04543532431125641,
-0.011921148747205734,
-0.03322003781795502,
-0.019966626539826393,
-0.031005369499325752,
0.00018383485439699143,
0.00007583187107229605,
0.01075325720012188,
0.05810046195983887,
-0.04166346415877342,
0.027181604877114296,
0.027458438649773598,
0.01726749911904335,
-0.06761661916971207,
-0.019568677991628647,
0.06353332102298737,
-0.0008726748637855053,
-0.042701590806245804,
0.01132422685623169,
-0.008205522783100605,
0.005272815935313702,
0.02321942336857319,
0.017284801229834557,
0.055020689964294434,
0.03668045997619629,
-0.034898340702056885,
-0.06699374318122864,
0.054155584424734116,
-0.04713093116879463,
0.03886052221059799,
0.008837048895657063,
0.009317182935774326,
0.02363467402756214,
0.02197367139160633,
0.04553913697600365,
0.006081689149141312,
0.028081312775611877,
0.032510653138160706,
-0.02787368930876255,
-0.025797436013817787,
-0.043878134340047836,
-0.00875053834170103,
-0.05214853957295418,
-0.06481368094682693,
-0.04543532431125641,
-0.024949632585048676,
0.022890683263540268,
-0.04668107628822327,
-0.03716491907835007,
0.03910275176167488,
0.05183710157871246,
-0.012967926450073719,
-0.044639427214860916,
-0.005618858151137829,
0.03633441776037216,
-0.05270220711827278,
-0.021437305957078934,
0.030417097732424736,
0.0076302275992929935,
-0.02306370437145233,
-0.040417712181806564,
0.024534381926059723,
0.05014149472117424,
-0.010580236092209816,
0.007111164275556803,
-0.016705181449651718,
-0.018184510990977287,
0.0024482475128024817,
-0.06342951208353043,
0.03259716182947159,
0.04457021877169609,
0.00240715523250401,
0.021523816511034966,
0.039933253079652786,
-0.04353209212422371,
-0.039898648858070374,
0.04875732585787773,
-0.0027640110347419977,
0.006328244227916002,
-0.020658710971474648,
-0.03155903518199921,
0.04190569370985031,
0.029050230979919434,
0.0004406629304867238,
-0.058965567499399185,
-0.003758881939575076,
-0.001005144091323018,
-0.022510036826133728,
0.0069900499656796455,
0.012172029353678226,
0.0010976021876558661,
-0.018668970093131065,
0.0207971278578043,
-0.06232217699289322,
-0.0014804111560806632,
-0.046162012964487076,
-0.05976146459579468,
0.003910275176167488,
-0.056162625551223755,
-0.043462883681058884,
0.008149290457367897,
-0.004965703468769789,
0.05259839445352554,
0.006972747854888439,
0.003060309449210763,
0.000317655794788152,
0.0598306730389595,
-0.01873817853629589,
0.03716491907835007,
-0.03437928110361099,
-0.018322927877306938,
-0.08145830035209656,
0.0061681997030973434,
-0.009732432663440704,
0.01269974373281002,
0.030745837837457657,
0.04529690742492676,
-0.04688870161771774,
0.012587280012667179,
0.05969225615262985,
-0.055539753288030624,
0.06699374318122864,
0.028150521218776703,
-0.024915028363466263,
0.025382185354828835,
-0.040175482630729675,
-0.04415496811270714,
-0.0361613966524601,
-0.07100783288478851,
-0.0182191152125597,
0.02411913126707077,
0.014481860212981701,
-0.02292528748512268,
-0.04467403143644333,
0.022388922050595284,
0.02283877693116665,
0.056162625551223755
]
|
31,093 | networkx.classes.function | selfloop_edges | Returns an iterator over selfloop edges.
A selfloop edge has the same node at both ends.
Parameters
----------
G : graph
A NetworkX graph.
data : string or bool, optional (default=False)
Return selfloop edges as two tuples (u, v) (data=False)
or three-tuples (u, v, datadict) (data=True)
or three-tuples (u, v, datavalue) (data='attrname')
keys : bool, optional (default=False)
If True, return edge keys with each edge.
default : value, optional (default=None)
Value used for edges that don't have the requested attribute.
Only relevant if data is not True or False.
Returns
-------
edgeiter : iterator over edge tuples
An iterator over all selfloop edges.
See Also
--------
nodes_with_selfloops, number_of_selfloops
Examples
--------
>>> G = nx.MultiGraph() # or Graph, DiGraph, MultiDiGraph, etc
>>> ekey = G.add_edge(1, 1)
>>> ekey = G.add_edge(1, 2)
>>> list(nx.selfloop_edges(G))
[(1, 1)]
>>> list(nx.selfloop_edges(G, data=True))
[(1, 1, {})]
>>> list(nx.selfloop_edges(G, keys=True))
[(1, 1, 0)]
>>> list(nx.selfloop_edges(G, keys=True, data=True))
[(1, 1, 0, {})]
| def selfloop_edges(G, data=False, keys=False, default=None):
"""Returns an iterator over selfloop edges.
A selfloop edge has the same node at both ends.
Parameters
----------
G : graph
A NetworkX graph.
data : string or bool, optional (default=False)
Return selfloop edges as two tuples (u, v) (data=False)
or three-tuples (u, v, datadict) (data=True)
or three-tuples (u, v, datavalue) (data='attrname')
keys : bool, optional (default=False)
If True, return edge keys with each edge.
default : value, optional (default=None)
Value used for edges that don't have the requested attribute.
Only relevant if data is not True or False.
Returns
-------
edgeiter : iterator over edge tuples
An iterator over all selfloop edges.
See Also
--------
nodes_with_selfloops, number_of_selfloops
Examples
--------
>>> G = nx.MultiGraph() # or Graph, DiGraph, MultiDiGraph, etc
>>> ekey = G.add_edge(1, 1)
>>> ekey = G.add_edge(1, 2)
>>> list(nx.selfloop_edges(G))
[(1, 1)]
>>> list(nx.selfloop_edges(G, data=True))
[(1, 1, {})]
>>> list(nx.selfloop_edges(G, keys=True))
[(1, 1, 0)]
>>> list(nx.selfloop_edges(G, keys=True, data=True))
[(1, 1, 0, {})]
"""
if data is True:
if G.is_multigraph():
if keys is True:
return (
(n, n, k, d)
for n, nbrs in G._adj.items()
if n in nbrs
for k, d in nbrs[n].items()
)
else:
return (
(n, n, d)
for n, nbrs in G._adj.items()
if n in nbrs
for d in nbrs[n].values()
)
else:
return ((n, n, nbrs[n]) for n, nbrs in G._adj.items() if n in nbrs)
elif data is not False:
if G.is_multigraph():
if keys is True:
return (
(n, n, k, d.get(data, default))
for n, nbrs in G._adj.items()
if n in nbrs
for k, d in nbrs[n].items()
)
else:
return (
(n, n, d.get(data, default))
for n, nbrs in G._adj.items()
if n in nbrs
for d in nbrs[n].values()
)
else:
return (
(n, n, nbrs[n].get(data, default))
for n, nbrs in G._adj.items()
if n in nbrs
)
else:
if G.is_multigraph():
if keys is True:
return (
(n, n, k)
for n, nbrs in G._adj.items()
if n in nbrs
for k in nbrs[n]
)
else:
return (
(n, n)
for n, nbrs in G._adj.items()
if n in nbrs
for i in range(len(nbrs[n])) # for easy edge removal (#4068)
)
else:
return ((n, n) for n, nbrs in G._adj.items() if n in nbrs)
| (G, data=False, keys=False, default=None) | [
0.052644189447164536,
-0.028060726821422577,
-0.05826442316174507,
-0.0031487452797591686,
-0.031821027398109436,
0.0035707680508494377,
0.005655611399561167,
0.02990044467151165,
0.15073543787002563,
-0.04294019192457199,
-0.018467921763658524,
0.03509612753987312,
0.008172585628926754,
0.028262894600629807,
0.004200011491775513,
0.009142985567450523,
-0.03297337517142296,
-0.006595686078071594,
0.011665014550089836,
0.07136482000350952,
0.008258506655693054,
-0.027171194553375244,
0.011614472605288029,
0.01709318906068802,
0.0003060929011553526,
0.044436223804950714,
-0.00874876044690609,
0.03406507521867752,
0.00767727755010128,
0.03465136140584946,
-0.04997558891773224,
-0.06707888841629028,
-0.040615275502204895,
-0.028262894600629807,
0.03190189227461815,
0.04241455718874931,
-0.05066295713186264,
0.04071635752916336,
-0.0705561488866806,
-0.01665852963924408,
0.06319728493690491,
-0.06695758551359177,
-0.008106881752610207,
-0.02177334576845169,
0.018002938479185104,
-0.00007190340693341568,
0.008197857066988945,
0.011958155781030655,
-0.03297337517142296,
-0.0591135211288929,
0.05664708837866783,
-0.02478562854230404,
0.0029491055756807327,
0.011867181397974491,
-0.008566810749471188,
0.01058342307806015,
-0.04039289057254791,
0.005493877921253443,
-0.03667302429676056,
0.004197484347969294,
-0.012635414488613605,
-0.015101847238838673,
0.04049397632479668,
0.03374160826206207,
-0.043304089456796646,
-0.014950222335755825,
-0.04528532549738884,
-0.06679585576057434,
-0.03277121111750603,
0.01676972210407257,
-0.02012568712234497,
0.021267928183078766,
0.001431592390872538,
0.018922796472907066,
-0.0026989243924617767,
-0.004285932518541813,
-0.028323544189333916,
0.0490456223487854,
0.04819652438163757,
0.013383430428802967,
-0.006115540396422148,
-0.005928536411374807,
-0.0644507184624672,
-0.07629768550395966,
0.05769835412502289,
0.004652359522879124,
0.0009944071061909199,
0.08369698375463486,
-0.0019142652163282037,
-0.05268462374806404,
-0.012200755998492241,
-0.035904791206121445,
0.005342253018170595,
0.04884345829486847,
0.013757439330220222,
-0.026827510446310043,
-0.052158989012241364,
-0.044112756848335266,
0.027049895375967026,
-0.015576938167214394,
0.0062722195871174335,
0.02130836248397827,
-0.035581327974796295,
-0.006358140613883734,
-0.0021593922283500433,
-0.08114968240261078,
-0.05482758954167366,
0.0027772639878094196,
0.02270331233739853,
-0.08490998297929764,
-0.07294172048568726,
0.0005025736172683537,
0.020843379199504852,
0.013009422458708286,
-0.014363938942551613,
0.017487412318587303,
0.013524947687983513,
0.011169706471264362,
0.006696769502013922,
-0.02747444435954094,
-0.008258506655693054,
-0.010654181241989136,
-0.04734742268919945,
0.03509612753987312,
-0.01844770461320877,
-0.021409446373581886,
0.07678288221359253,
-0.014899680390954018,
-0.01114948932081461,
-0.012069347314536572,
0.09461398422718048,
0.03163907676935196,
-0.0061003779992461205,
0.08183705061674118,
-0.0014833976747468114,
0.007586302701383829,
-0.0006576732848770916,
0.04225282371044159,
0.015445530414581299,
0.009739377535879612,
0.015000763349235058,
-0.08046231418848038,
0.003338276408612728,
0.09291578084230423,
-0.012039022520184517,
-0.022117028012871742,
0.017083080485463142,
0.01902388036251068,
0.03638999164104462,
-0.010633964091539383,
0.011857072822749615,
0.03044629469513893,
0.04657918959856033,
0.037380609661340714,
-0.0018232902511954308,
-0.01567802205681801,
-0.06133735552430153,
0.012039022520184517,
-0.03655172511935234,
-0.021146629005670547,
-0.03634956106543541,
0.011412305757403374,
0.012382705695927143,
-0.017891746014356613,
0.04698352515697479,
0.002065890235826373,
-0.007106157019734383,
-0.02539212815463543,
0.04071635752916336,
0.03137626126408577,
0.031153876334428787,
-0.039806608110666275,
-0.02533147856593132,
-0.026827510446310043,
-0.053857188671827316,
0.04225282371044159,
-0.0031158931087702513,
0.009264285676181316,
0.017831096425652504,
0.007252727635204792,
0.003310478525236249,
-0.02715097740292549,
-0.013302563689649105,
-0.05207812413573265,
0.023208728060126305,
0.05616188794374466,
0.06186298653483391,
-0.03552067652344704,
0.022460712119936943,
-0.01836683787405491,
-0.047185689210891724,
-0.053371988236904144,
-0.019802220165729523,
0.07755111902952194,
0.02715097740292549,
0.0027140870224684477,
0.011857072822749615,
0.052239857614040375,
-0.01148306392133236,
0.09881904721260071,
0.005574744660407305,
-0.029010910540819168,
0.008202910423278809,
0.03632934391498566,
-0.015182713977992535,
-0.0010841184994205832,
-0.005428174044936895,
-0.01737622171640396,
0.023896094411611557,
0.007020235992968082,
-0.032629694789648056,
-0.004379434511065483,
0.02955676056444645,
0.04617485776543617,
0.004877269733697176,
0.03212427720427513,
-0.03141669183969498,
0.00851626880466938,
-0.035439807921648026,
-0.02686794474720955,
0.0010702195577323437,
-0.032811641693115234,
-0.0067624738439917564,
0.0021303307730704546,
0.0477113239467144,
-0.05749619007110596,
0.013807980343699455,
0.013464297167956829,
0.0231885127723217,
0.022541578859090805,
0.04334452375769615,
0.008167531341314316,
0.019397888332605362,
-0.012241189368069172,
0.032407309859991074,
-0.008157423697412014,
-0.0002471802872605622,
-0.028909826651215553,
0.007702548522502184,
0.021348794922232628,
-0.05474672093987465,
-0.023431111127138138,
-0.030587811022996902,
-0.013524947687983513,
0.03418637812137604,
-0.027110544964671135,
0.05126945674419403,
0.010735047981142998,
-0.007975473068654537,
0.05288678780198097,
-0.044921424239873886,
-0.03331705927848816,
0.00025681479019112885,
-0.010295335203409195,
0.026018844917416573,
-0.04803479090332985,
-0.08539517968893051,
-0.01790185458958149,
0.01819499582052231,
0.012524222023785114,
0.05066295713186264,
0.023269379511475563,
-0.060286086052656174,
0.0678066834807396,
0.023228945210576057,
0.04116112366318703,
0.019165396690368652,
-0.011462847702205181,
-0.035985659807920456,
0.020631104707717896,
0.05474672093987465,
-0.030688893049955368,
0.03871490806341171,
0.002848022384569049,
-0.007601465098559856,
0.0007353810942731798,
0.011351656168699265,
0.022480929270386696,
-0.04132285714149475,
-0.0570918545126915,
-0.035641975700855255,
0.020024605095386505,
-0.06311642378568649,
-0.016870804131031036,
-0.06032652035355568,
-0.018700413405895233,
-0.038532957434654236,
-0.04540662467479706,
0.055474523454904556,
-0.015607263892889023,
0.08717425167560577,
-0.021591395139694214,
0.009769702330231667,
0.03103257715702057,
0.06339945644140244,
0.027332928031682968,
-0.0034368326887488365,
0.01125057227909565,
0.04071635752916336,
0.015132172033190727,
0.07896628230810165,
-0.04742829129099846,
0.03855317458510399,
-0.025513427332043648,
-0.0008124571177177131,
0.029536543413996696,
0.047873057425022125,
0.02163182944059372,
0.0009116451255977154,
-0.007020235992968082,
-0.05288678780198097,
-0.024826060980558395,
0.03774451091885567,
0.015132172033190727,
-0.021611612290143967,
-0.0799771174788475,
0.036592159420251846,
-0.00335091189481318,
0.0245228111743927,
0.03612717613577843,
-0.03426724299788475,
0.04067592695355415,
-0.022400062531232834,
0.031821027398109436,
-0.01827586255967617,
0.07112222164869308,
0.020944463089108467,
0.021146629005670547,
0.03606652468442917,
0.026928594335913658,
-0.015000763349235058,
-0.024138694629073143,
-0.05414022132754326,
0.08026015013456345,
-0.04374885931611061,
0.04354669153690338,
0.04884345829486847,
0.03909902647137642,
-0.007535760756582022,
-0.05725358799099922,
0.010512664914131165,
-0.003906870260834694,
0.012696064077317715,
-0.03687519207596779,
0.05155248939990997,
0.014737946912646294,
0.01418198924511671,
-0.02808094397187233,
0.024098262190818787,
0.06558285653591156,
0.0056808823719620705,
0.04932865500450134,
-0.003785570152103901,
0.0019926046952605247,
0.04160588979721069,
-0.025210177525877953,
-0.008950927294790745,
-0.036106958985328674,
0.025169745087623596,
0.03687519207596779,
0.0436679907143116,
0.013898955658078194,
0.022622445598244667,
0.02599862776696682,
0.0005749113624915481,
-0.04265715926885605,
-0.054665856063365936,
0.07265868782997131,
0.025371911004185677,
-0.0010853820713236928,
-0.006105432286858559,
-0.012584872543811798,
-0.03230622783303261,
0.00574153196066618,
-0.00856175646185875,
0.03552067652344704,
0.01868019625544548,
0.01945853792130947,
0.017770446836948395,
-0.015101847238838673,
-0.014778380282223225,
-0.04851999133825302,
0.02735314518213272,
0.05155248939990997,
0.03796689212322235,
-0.0245228111743927,
0.0718500167131424,
0.016607988625764847,
0.0691814199090004,
0.0018207632238045335,
-0.07168828696012497,
-0.0073538110591471195,
0.0598008893430233,
0.015627481043338776,
-0.02533147856593132,
-0.03311489149928093,
0.11394111067056656,
-0.00006621746433665976,
-0.019397888332605362,
-0.06910055130720139,
-0.03440875932574272,
0.009436127729713917,
-0.037987109273672104,
0.010472231544554234,
0.012554547749459743,
0.010512664914131165,
0.03139647841453552,
-0.014778380282223225,
0.04597268998622894,
0.005200736224651337,
-0.038856424391269684,
0.0208231620490551,
0.01673939637839794,
-0.006706877611577511,
0.04985428974032402,
-0.0016906184609979391,
-0.002377985045313835,
0.08313091844320297,
0.060771286487579346,
0.040069423615932465,
0.007500381674617529,
-0.024401511996984482,
0.06081172078847885,
-0.030668677762150764,
-0.03762320801615715,
-0.009516993537545204,
-0.00670182378962636,
0.0010310497600585222,
-0.05769835412502289,
0.05543408915400505,
-0.024300428107380867,
-0.058466587215662,
0.05781965330243111,
-0.04089830815792084,
-0.0050592198967933655,
0.00415705144405365,
-0.01680004596710205,
0.00767727755010128,
0.027575528249144554,
-0.006590631790459156,
-0.010482339188456535,
0.0012673320015892386,
-0.01569823920726776,
-0.047792188823223114,
0.03446941077709198,
-0.03861382603645325,
-0.008101827464997768,
0.01317115593701601,
0.04953082278370857,
0.015101847238838673,
0.013009422458708286,
-0.009233960881829262,
0.03216471150517464,
0.003373655490577221,
-0.059962622821331024,
0.008693165145814419,
-0.03924054279923439,
0.025715595111250877,
-0.026888161897659302,
-0.0009754539933055639,
0.03311489149928093,
-0.021550962701439857,
-0.010694614611566067,
0.011432522907853127,
-0.014434697106480598,
-0.03426724299788475,
0.04374885931611061,
0.01299931388348341,
-0.06631065160036087,
-0.053776323795318604,
-0.0001811602560337633,
-0.017214488238096237,
-0.021005112677812576,
-0.03083041124045849,
0.03238709270954132,
-0.015809429809451103,
-0.04916692525148392,
-0.05033949017524719,
-0.04589182510972023,
-0.10860390961170197,
-0.0025422454345971346,
-0.03713800758123398,
0.052158989012241364,
-0.037461474537849426,
-0.01009316835552454,
-0.047792188823223114,
0.0005069960025139153,
-0.0006399837438948452,
-0.09582698345184326,
-0.015192821621894836,
-0.012372597120702267,
-0.02177334576845169,
-0.025028228759765625,
0.005256332457065582,
0.053048521280288696,
0.03206362575292587,
0.018953120335936546,
-0.044436223804950714,
0.045042723417282104,
-0.03653150796890259,
0.017770446836948395,
-0.014485239051282406,
0.04589182510972023,
-0.024644112214446068,
0.014323505572974682,
0.029374809935688972,
-0.011604364030063152,
0.03533872589468956,
0.012574763968586922,
0.011857072822749615,
0.003669324330985546,
0.0005840720259584486,
0.014586322009563446,
0.022480929270386696,
0.0031740160193294287,
-0.01323180552572012,
0.018781280145049095,
0.012311947531998158,
-0.024623895063996315,
-0.026989243924617767,
0.008672947995364666,
0.00490254070609808,
-0.014626755379140377,
0.08252441883087158,
-0.07197131961584091,
0.09097497910261154,
0.0024019922129809856,
-0.03062824346125126,
-0.009436127729713917,
-0.017588496208190918,
-0.02990044467151165,
0.03149756044149399,
0.015597155317664146,
0.07654028385877609,
-0.05749619007110596,
-0.0362686924636364,
0.06311642378568649,
0.058345288038253784,
-0.03703692555427551,
0.007601465098559856,
0.07132438570261002,
0.03736039251089096,
-0.02110619656741619,
-0.017244813963770866,
-0.007106157019734383,
0.002992066089063883,
0.03050694428384304,
0.035581327974796295,
-0.016375496983528137,
-0.060286086052656174,
-0.03734017536044121,
0.00010708513582358137,
0.007500381674617529,
0.009466452524065971,
-0.00429351394996047,
0.016274413093924522,
-0.006504711229354143,
0.006555252708494663,
0.039139457046985626,
0.013686680234968662,
-0.03780515864491463,
-0.02157117985188961,
-0.0725373849272728,
-0.04516402259469032,
0.04395102337002754,
-0.01584986411035061,
0.015405097045004368,
-0.004174740985035896,
0.012857797555625439,
0.05664708837866783,
-0.028768310323357582,
-0.005549473688006401,
0.02935459464788437,
-0.0665128231048584,
0.008076556958258152,
-0.006636119447648525,
-0.08021971583366394,
-0.06999008357524872,
0.0011959419352933764,
-0.08305004984140396,
-0.03305424377322197,
-0.0053574154153466225,
0.05769835412502289,
0.039462924003601074,
0.034085292369127274,
0.0019218465313315392,
-0.04120155796408653,
0.029233293607831,
-0.03353944420814514,
0.01732568070292473,
0.014828922227025032,
-0.04322322458028793,
0.0017083080019801855,
0.0008200383745133877,
0.013787764124572277,
-0.016213763505220413,
0.048479557037353516,
0.015111954882740974,
0.00028508654213510454,
-0.042091090232133865,
-0.023410895839333534,
0.033276624977588654,
0.028869394212961197,
0.0564449205994606,
-0.02545277774333954,
0.006898935884237289,
-0.009542264975607395,
-0.020782729610800743,
0.02816181071102619,
-0.024017395451664925,
-0.013322780840098858,
0.024239778518676758,
0.01844770461320877,
0.01350473053753376,
-0.06283338367938995,
0.00870327278971672,
-0.034085292369127274,
0.06558285653591156,
-0.07358865439891815,
-0.004508315585553646,
-0.021550962701439857,
-0.06339945644140244,
-0.014525672420859337,
0.007328540086746216,
-0.026827510446310043,
0.023673711344599724,
0.01766936294734478,
-0.04488098993897438,
0.0109169976785779,
0.039604440331459045,
-0.0005591170629486442,
-0.013241914100944996,
0.025958195328712463,
-0.0056909904815256596,
0.010593531653285027,
-0.038997940719127655,
0.028303327038884163,
0.0008206701604649425,
-0.035500459372997284,
0.006373303011059761,
-0.042495425790548325,
0.058749619871377945,
-0.03010261058807373,
-0.017153838649392128,
-0.026524260640144348,
-0.019418103620409966,
0.06643195450305939,
-0.03677411004900932,
0.011533605866134167,
-0.011857072822749615,
0.0026711265090852976,
0.037522125989198685,
0.01026501040905714,
-0.011432522907853127,
-0.009259231388568878,
0.06133735552430153,
0.0056909904815256596,
-0.049692556262016296,
-0.03944271057844162,
-0.03171994537115097,
0.011412305757403374,
0.007449840195477009,
0.013049855828285217,
-0.026888161897659302,
-0.017861422151327133,
0.03568241000175476,
0.007793523371219635,
-0.008450564928352833,
0.05494888871908188,
-0.015111954882740974,
-0.033357493579387665,
0.0043086763471364975,
-0.015546613372862339,
-0.020176229998469353,
-0.03368096053600311,
-0.03861382603645325,
0.0127668222412467,
0.013090289197862148,
-0.02059067040681839,
-0.023208728060126305,
0.012119889259338379,
0.06877708435058594,
-0.05316982418298721,
0.006085215602070093,
-0.023835444822907448,
-0.03857339173555374,
0.06339945644140244,
-0.023754578083753586,
0.01552639715373516,
-0.057010989636182785,
0.0228448286652565,
-0.010765372775495052,
0.07031355053186417,
0.003123474307358265,
-0.05268462374806404,
-0.051229022443294525,
-0.023673711344599724,
0.04678135737776756,
0.003416616003960371,
-0.052644189447164536,
0.003694595070555806,
-0.017244813963770866,
0.011402198113501072,
0.0065198736265301704,
0.01642603799700737,
-0.0015907986089587212,
-0.05179508775472641,
-0.006358140613883734,
-0.001597116352058947,
0.05207812413573265,
-0.07067745178937912,
0.030587811022996902,
-0.033155325800180435,
-0.05595972388982773,
-0.007384135853499174,
-0.031153876334428787,
0.010593531653285027,
0.009365368634462357,
-0.07112222164869308,
0.03632934391498566,
-0.01844770461320877,
0.02660512737929821,
0.029071560129523277,
0.044234056025743484,
-0.058426156640052795,
0.014879463240504265,
0.03643042594194412,
-0.06966661661863327,
-0.03426724299788475,
0.024826060980558395,
0.013262130320072174,
0.023592844605445862,
0.032912727445364,
0.04916692525148392,
0.008996414951980114,
-0.05757705494761467,
0.022056378424167633,
-0.008339373394846916,
-0.029475893825292587,
0.07989624887704849,
-0.031073009595274925,
0.015870079398155212,
-0.03246796131134033,
0.051309891045093536,
-0.034631144255399704,
-0.058426156640052795,
0.016527121886610985,
0.07237565517425537,
-0.0129386642947793,
-0.052239857614040375,
0.04548748955130577,
-0.028101161122322083,
0.014454913325607777,
-0.042697589844465256,
0.0021556017454713583,
0.016274413093924522,
-0.031740158796310425,
-0.0463770255446434,
-0.019963953644037247,
-0.02747444435954094,
-0.014909788966178894,
0.01407079678028822,
0.017153838649392128,
0.03857339173555374,
-0.08288832008838654,
-0.006848394405096769,
0.04017050936818123,
0.05430195480585098
]
|
31,095 | networkx.classes.function | set_edge_attributes | 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}
| 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, values, name=None) | [
0.06644006818532944,
0.0003522563783917576,
0.005212217103689909,
0.002716004615649581,
-0.07711569219827652,
-0.026668129488825798,
-0.04295369237661362,
0.0252656452357769,
0.07824604958295822,
-0.023151453584432602,
-0.0218745656311512,
0.0142550989985466,
0.07912521809339523,
0.07899962365627289,
0.009613296017050743,
0.0403580479323864,
0.015699448063969612,
0.03615059703588486,
0.020618608221411705,
0.02882418781518936,
0.029263772070407867,
-0.06824027001857758,
-0.03022667206823826,
-0.0148202795535326,
0.038348518311977386,
-0.02534937672317028,
-0.008885887451469898,
0.050824347883462906,
0.054466620087623596,
0.03506210073828697,
-0.0245539378374815,
-0.08561432361602783,
-0.0638025552034378,
-0.02599828690290451,
0.07343155145645142,
-0.02867765910923481,
-0.031168637797236443,
0.018588146194815636,
-0.06581208854913712,
-0.004686285275965929,
0.009027183055877686,
-0.03615059703588486,
-0.028007816523313522,
-0.0020343868527561426,
0.06430494040250778,
0.06108132004737854,
-0.017353123053908348,
0.01684027537703514,
0.024763263761997223,
-0.05526205897331238,
0.002264645416289568,
-0.025391241535544395,
0.0448794886469841,
0.055596981197595596,
-0.013051474466919899,
0.03962540626525879,
-0.023884093388915062,
0.05094994232058525,
-0.037783339619636536,
-0.019331254065036774,
0.011198939755558968,
-0.019090529531240463,
0.000744415505323559,
-0.035941269248723984,
-0.08285122364759445,
0.022795598953962326,
-0.03520863130688667,
-0.011167541146278381,
-0.03054066002368927,
0.004987191408872604,
-0.024281812831759453,
-0.018169494345784187,
0.006075686775147915,
-0.04123721644282341,
-0.025537770241498947,
0.06840772926807404,
-0.02842646837234497,
0.08038117736577988,
-0.0008091757190413773,
-0.017635714262723923,
0.0010407426161691546,
0.03278044983744621,
0.011041945777833462,
-0.03336656093597412,
0.002473971340805292,
0.046847153455019,
-0.04016965627670288,
0.04818683862686157,
0.042325712740421295,
-0.059657905250787735,
-0.024574870243668556,
0.006049520801752806,
-0.019006798043847084,
0.013627121224999428,
0.012046709656715393,
0.011282670311629772,
0.030519727617502213,
-0.07657144218683243,
-0.0024517304264009,
0.018284624442458153,
-0.01332359854131937,
-0.0604114793241024,
0.006363509688526392,
0.003202687483280897,
-0.035271428525447845,
-0.09101493656635284,
-0.030498795211315155,
-0.05526205897331238,
0.006735063157975674,
-0.09252208471298218,
-0.03983473405241966,
-0.007640398107469082,
0.08707960695028305,
-0.031084908172488213,
-0.010822152718901634,
0.03246646001935005,
-0.002888698596507311,
-0.05882060155272484,
0.002543310634791851,
0.018692810088396072,
0.0022070808336138725,
0.046135444194078445,
0.02066047489643097,
0.06648193299770355,
0.021811766549944878,
0.007834024727344513,
0.022481610998511314,
0.039332352578639984,
0.021916430443525314,
-0.06677498668432236,
-0.018493950366973877,
-0.03192221000790596,
0.01199437864124775,
0.03912302479147911,
0.036736708134412766,
-0.03493650630116463,
-0.063509501516819,
0.0139725087210536,
0.06313271820545197,
-0.02325611561536789,
0.0017688045045360923,
-0.012779351323843002,
0.03520863130688667,
-0.0218745656311512,
-0.026144815608859062,
-0.028531130403280258,
-0.00793345458805561,
-0.03968820720911026,
-0.026772793382406235,
0.02162337303161621,
-0.008844022639095783,
-0.008519567549228668,
0.008393972180783749,
0.005662267562001944,
-0.011366400867700577,
-0.009388269856572151,
-0.06283965706825256,
0.022314149886369705,
0.004322581458836794,
0.028405535966157913,
-0.05145232751965523,
-0.020796535536646843,
0.01668328046798706,
-0.021434979513287544,
0.023842228576540947,
0.004890378098934889,
0.034538786858320236,
-0.022021092474460602,
0.007844490930438042,
0.02574709616601467,
0.02706584893167019,
-0.05668547376990318,
0.005782630294561386,
-0.005343045573681593,
-0.004581622313708067,
0.004584238864481449,
0.07849724590778351,
-0.0460098497569561,
0.004144654609262943,
0.04843803122639656,
0.004673202522099018,
-0.0013409946113824844,
0.013700385577976704,
0.0416349358856678,
0.03432945907115936,
-0.02357010543346405,
-0.0008484243880957365,
0.013501525856554508,
0.035941269248723984,
0.00830500852316618,
0.046135444194078445,
-0.027484500780701637,
-0.024177150800824165,
0.04090229794383049,
0.02430274710059166,
-0.011544328182935715,
0.013135205022990704,
-0.036987900733947754,
0.013093340210616589,
0.07414326071739197,
0.03240366280078888,
-0.05157792195677757,
0.04109068959951401,
0.02382129617035389,
0.06288152188062668,
-0.014747015200555325,
0.07301290333271027,
-0.06091386079788208,
-0.022544408217072487,
-0.017949702218174934,
-0.01765664666891098,
-0.01651581935584545,
0.02769382670521736,
0.013459660112857819,
0.00849863514304161,
0.007891589775681496,
-0.007336875423789024,
0.03945794701576233,
-0.017698511481285095,
-0.016149498522281647,
-0.027986884117126465,
-0.0042414674535393715,
0.033240966498851776,
-0.0031948378309607506,
0.030017346143722534,
-0.0505312904715538,
0.008791690692305565,
-0.03441319242119789,
0.03799266368150711,
0.02599828690290451,
0.04843803122639656,
0.01547965593636036,
0.0406511053442955,
-0.003911779262125492,
0.0006626475369557738,
0.005275014787912369,
0.036401789635419846,
-0.011272204108536243,
0.0035009770654141903,
0.04130001738667488,
0.011785052716732025,
-0.047768186777830124,
-0.058611273765563965,
0.030435997992753983,
0.0066670323722064495,
-0.021016327664256096,
0.02340264432132244,
0.00907951407134533,
-0.024177150800824165,
0.0018381437985226512,
-0.0527920126914978,
0.01927892304956913,
-0.022942127659916878,
0.030645323917269707,
-0.03784613683819771,
0.003529759356752038,
0.008676561526954174,
-0.02560056746006012,
0.013993442058563232,
-0.013239867985248566,
0.005369211547076702,
-0.03845318406820297,
-0.05094994232058525,
0.03296884149312973,
0.03489464148879051,
0.005772164091467857,
0.03474811092019081,
0.002368000103160739,
-0.12124160677194595,
-0.010434900410473347,
0.07523175328969955,
-0.03319910168647766,
-0.00570936594158411,
0.0043539805337786674,
0.011722254566848278,
0.021979227662086487,
0.0013619271339848638,
-0.03548075258731842,
-0.02000109665095806,
-0.04894041270017624,
0.015605251304805279,
-0.033157236874103546,
-0.04196985810995102,
0.0567273385822773,
0.003809732850641012,
0.009419669397175312,
-0.014736548997461796,
0.025809893384575844,
0.014213234186172485,
-0.014883076772093773,
0.09721098840236664,
0.022900262847542763,
-0.03556448221206665,
0.015668049454689026,
0.03906022757291794,
0.022481610998511314,
-0.021288452669978142,
-0.006635633762925863,
0.0392276868224144,
0.04789378494024277,
0.07971133291721344,
0.006452473346143961,
0.06367696076631546,
0.02972428873181343,
0.008184646256268024,
-0.024930724874138832,
0.06639820337295532,
0.03520863130688667,
-0.0100895119830966,
0.060955725610256195,
-0.0279450174421072,
0.040295250713825226,
-0.05840194970369339,
0.02009529434144497,
0.04567492753267288,
0.02989174984395504,
0.02882418781518936,
-0.022481610998511314,
0.0228583961725235,
0.0009812155039981008,
-0.027986884117126465,
0.0013776265550404787,
-0.04554933309555054,
-0.021414047107100487,
-0.006159416865557432,
0.025495903566479683,
0.05882060155272484,
0.06727737188339233,
0.030729053542017937,
-0.023549173027276993,
-0.04226291552186012,
-0.01519706565886736,
0.03449692204594612,
0.021079126745462418,
-0.0005805524997413158,
0.08398158103227615,
-0.005641335155814886,
0.02049301378428936,
0.026751860976219177,
-0.01724846102297306,
0.010314537212252617,
0.05467594414949417,
-0.04793564975261688,
-0.021288452669978142,
0.003974576946347952,
0.010031947866082191,
0.0002732685243245214,
-0.0020500863902270794,
-0.004437710624188185,
0.020932598039507866,
-0.05735531821846962,
0.07108709961175919,
-0.002716004615649581,
0.013794582337141037,
-0.045256275683641434,
0.003511443268507719,
-0.025307510048151016,
-0.0838141217827797,
0.014150436036288738,
-0.02972428873181343,
-0.022795598953962326,
0.01078028790652752,
0.03460158407688141,
-0.025391241535544395,
0.018190426751971245,
0.00123960233759135,
-0.02325611561536789,
0.0383903831243515,
0.02882418781518936,
-0.046302907168865204,
0.06162557005882263,
-0.05241522565484047,
-0.0027971183881163597,
0.048647359013557434,
0.01076982170343399,
0.018839338794350624,
-0.04471202939748764,
0.012371165677905083,
0.018588146194815636,
0.02681465819478035,
-0.022900262847542763,
-0.036652978509664536,
0.009168477728962898,
0.04764259234070778,
0.06648193299770355,
-0.02892884984612465,
0.13329878449440002,
-0.018776539713144302,
0.016798410564661026,
-0.01596110500395298,
-0.005036906339228153,
-0.01564711704850197,
0.016662348061800003,
-0.008974851109087467,
-0.03493650630116463,
-0.02405155450105667,
0.028405535966157913,
-0.0012173614231869578,
-0.04617731273174286,
-0.0643468052148819,
-0.07108709961175919,
-0.018326489254832268,
0.043958455324172974,
0.02373756654560566,
0.04058830812573433,
-0.015385459177196026,
0.0513685941696167,
0.052205897867679596,
0.05337812379002571,
0.0311895702034235,
0.013721317984163761,
-0.011638524010777473,
-0.054969001561403275,
-0.014977273531258106,
0.022649070248007774,
0.009267907589673996,
0.02777755819261074,
-0.04146747663617134,
0.0547596774995327,
-0.0011427890276536345,
0.05086621269583702,
0.0021141923498362303,
0.009330705739557743,
-0.016829809173941612,
0.021246585994958878,
-0.04328861087560654,
0.0010904575465247035,
0.0006201282376423478,
-0.03497837111353874,
0.04203265532851219,
-0.019414983689785004,
-0.01652628555893898,
0.01579364575445652,
0.015029605478048325,
0.03399454057216644,
0.0024635051377117634,
0.014286498539149761,
-0.049442797899246216,
-0.004092323128134012,
-0.0424722395837307,
-0.05300133675336838,
-0.036987900733947754,
-0.026040151715278625,
-0.08691214770078659,
-0.05764837563037872,
-0.07230119407176971,
-0.015825044363737106,
0.013061940670013428,
0.07242678850889206,
-0.03855784609913826,
-0.003911779262125492,
0.02008482813835144,
0.04086042940616608,
0.0109372828155756,
-0.03395267203450203,
0.045340005308389664,
-0.00339108076877892,
-0.02156057581305504,
0.01978130452334881,
0.03661111369729042,
-0.01937311887741089,
-0.05044756084680557,
-0.06141624227166176,
0.00238893274217844,
-0.014213234186172485,
0.03481091186404228,
0.06597954779863358,
-0.004681052174419165,
-0.017049601301550865,
-0.004442943725734949,
0.03822292387485504,
-0.08138594031333923,
0.011596659198403358,
-0.006599001586437225,
0.0010250431951135397,
-0.01984410360455513,
-0.028070613741874695,
-0.006159416865557432,
-0.06359323114156723,
-0.05467594414949417,
0.044837623834609985,
-0.02430274710059166,
0.03005921095609665,
0.011366400867700577,
0.0748131051659584,
0.014213234186172485,
0.013354997150599957,
-0.03307350352406502,
-0.023151453584432602,
0.05949044227600098,
-0.013156137429177761,
-0.07946014404296875,
-0.005955324042588472,
0.007697962690144777,
0.02147684618830681,
0.03294790908694267,
-0.0311895702034235,
-0.0168612077832222,
0.00032870718860067427,
-0.05379677563905716,
-0.0427652969956398,
-0.04031618312001228,
-0.002891315147280693,
-0.023611970245838165,
0.02331891469657421,
0.020513946190476418,
-0.025642432272434235,
-0.01004241406917572,
0.04697275161743164,
-0.011355934664607048,
0.035669147968292236,
0.005923925433307886,
0.037385620176792145,
0.024888858199119568,
0.01564711704850197,
0.0038542146794497967,
0.00733164232224226,
0.025370309129357338,
0.028803255409002304,
-0.0592811182141304,
0.009309773333370686,
-0.006128018256276846,
-0.008017185144126415,
0.016170432791113853,
-0.04739140346646309,
-0.009184177033603191,
0.025391241535544395,
-0.04165586829185486,
0.029263772070407867,
-0.017970634624361992,
0.01861954666674137,
0.08000438660383224,
-0.013867845758795738,
0.05086621269583702,
0.02825900726020336,
0.0016301260329782963,
0.08138594031333923,
0.008200345560908318,
-0.007389206904917955,
0.01349105965346098,
0.015165667049586773,
0.0448794886469841,
-0.021497778594493866,
0.02156057581305504,
-0.027149580419063568,
-0.034706246107816696,
-0.009581896476447582,
-0.04086042940616608,
0.04948466271162033,
-0.08992644399404526,
-0.038181059062480927,
0.005494806915521622,
-0.002039619954302907,
-0.0169344712048769,
-0.016735611483454704,
-0.0674448311328888,
0.03801359608769417,
-0.013428261503577232,
-0.015029605478048325,
0.023067722097039223,
-0.04814497381448746,
-0.02292119525372982,
0.017269393429160118,
-0.016955403611063957,
0.03271764889359474,
0.0007790851523168385,
-0.01937311887741089,
0.0036710542626678944,
-0.016463488340377808,
0.01264328882098198,
-0.04835430160164833,
0.05693666636943817,
0.026061084121465683,
0.006520504131913185,
0.010099978186190128,
0.005667500663548708,
0.009498165920376778,
-0.0029462631791830063,
-0.01024650689214468,
-0.019080063328146935,
-0.017436854541301727,
0.03533422574400902,
-0.034057337790727615,
0.015364526771008968,
0.05806702747941017,
0.0269611869007349,
-0.004272866528481245,
0.10123004019260406,
-0.043790996074676514,
0.019896434620022774,
-0.035941269248723984,
-0.01878700591623783,
0.019791770726442337,
-0.016494886949658394,
-0.044837623834609985,
-0.010314537212252617,
-0.013302666135132313,
-0.01830555684864521,
-0.018022967502474785,
0.037385620176792145,
-0.06196048855781555,
-0.008043350651860237,
0.016620483249425888,
0.02704491652548313,
-0.0403580479323864,
-0.012413030490279198,
0.02647973597049713,
-0.028070613741874695,
-0.027798490598797798,
-0.033910807222127914,
0.0239887572824955,
0.04894041270017624,
0.005008124280720949,
-0.015427324920892715,
0.017436854541301727,
-0.048563625663518906,
-0.030812785029411316,
0.08992644399404526,
-0.05061502009630203,
-0.010021481662988663,
-0.05630868673324585,
-0.0821395143866539,
-0.06388629227876663,
-0.03215247020125389,
0.015207532793283463,
0.020597675815224648,
-0.025495903566479683,
-0.014276031404733658,
-0.0674448311328888,
-0.018368354067206383,
0.002925330540165305,
-0.07334782183170319,
-0.016787944361567497,
-0.033261898905038834,
0.033408425748348236,
-0.08900540322065353,
0.030477862805128098,
0.015699448063969612,
-0.006096619181334972,
0.03841131553053856,
0.006007655523717403,
0.04349793866276741,
-0.008519567549228668,
-0.002507986966520548,
-0.04529814049601555,
0.054801542311906815,
0.012549092061817646,
-0.08758199214935303,
0.013867845758795738,
0.014600487425923347,
0.04096509516239166,
0.01198391243815422,
-0.025307510048151016,
0.0060599870048463345,
0.026312274858355522,
0.035606350749731064,
-0.043790996074676514,
-0.03654831647872925,
-0.0002629657683428377,
-0.016139032319188118,
-0.012779351323843002,
-0.0001273944799322635,
0.04213732108473778,
0.0012363315327093005,
0.003343982622027397,
0.028949782252311707,
-0.02972428873181343,
0.0067559960298240185,
0.052540820091962814,
0.010916349478065968,
-0.05007077381014824,
-0.01861954666674137,
0.01469468418508768,
0.009738891385495663,
-0.03667391091585159,
-0.029305636882781982,
0.019624311476945877,
-0.0019938298501074314,
0.0581507571041584,
0.04923347011208534,
-0.014579554088413715,
0.057062260806560516,
0.014987739734351635,
-0.013417795300483704,
-0.003652738407254219,
-0.007514802739024162,
0.005547138396650553,
0.005745998118072748,
-0.00026541881379671395,
0.02049301378428936,
0.0007679646951146424,
-0.06974741816520691,
0.005772164091467857,
0.004814497660845518,
-0.02947309799492359,
-0.04190706089138985,
0.00346172833815217,
-0.012297901324927807,
0.02585175819694996,
0.021748969331383705,
0.008535266853868961,
0.04270249977707863,
-0.0581507571041584,
0.0010597127256914973,
0.008477701805531979,
-0.04207452014088631,
-0.09252208471298218,
0.02275373414158821,
0.003066625678911805,
-0.023716634139418602,
-0.04496322199702263,
0.01032500434666872,
0.013595722615718842,
-0.017698511481285095,
0.04157213866710663,
-0.008388739079236984,
-0.005489573813974857,
-0.060871995985507965,
-0.06229541078209877,
0.05283387750387192,
-0.03380614519119263,
0.04412591829895973,
0.03255018964409828,
-0.015751779079437256,
-0.05769024044275284,
-0.043874725699424744,
-0.008519567549228668,
0.011533861048519611,
0.031315166503190994,
-0.0330316387116909,
-0.02673092670738697,
0.0660632774233818,
-0.004139421042054892,
0.04513068124651909,
-0.06614700704813004,
-0.05986722931265831,
-0.03144076094031334,
-0.004445560276508331,
0.007226979359984398,
0.08138594031333923,
-0.01815902814269066,
-0.011282670311629772,
-0.045800525695085526,
-0.020199956372380257,
-0.04793564975261688,
-0.01830555684864521,
-0.04165586829185486,
0.06254660338163376,
-0.00269507197663188,
-0.0009288840228691697,
0.02065000869333744,
0.028740456327795982,
-0.031084908172488213,
0.019226592034101486,
0.08318614214658737,
-0.06116504967212677,
0.033659618347883224,
-0.019540579989552498,
0.02892884984612465,
-0.030729053542017937,
-0.0290753785520792,
0.03857877850532532,
0.0041106389835476875,
-0.03012200817465782,
-0.032215267419815063,
0.05170351639389992,
0.017028668895363808,
0.042158253490924835
]
|
31,096 | networkx.classes.function | set_node_attributes | Sets node 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 node 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 node in `G`. This means that if
you provide a mutable object, like a list, updates to that object
will be reflected in the node attribute for every node.
The attribute name will be `name`.
If `values` is a dict or a dict of dict, it should be keyed
by node to either an attribute value or a dict of attribute key/value
pairs used to update the node's attributes.
name : string (optional, default=None)
Name of the node attribute to set if values is a scalar.
Examples
--------
After computing some property of the nodes of a graph, you may want
to assign a node attribute to store the value of that property for
each node::
>>> G = nx.path_graph(3)
>>> bb = nx.betweenness_centrality(G)
>>> isinstance(bb, dict)
True
>>> nx.set_node_attributes(G, bb, "betweenness")
>>> G.nodes[1]["betweenness"]
1.0
If you provide a list as the second argument, updates to the list
will be reflected in the node attribute for each node::
>>> G = nx.path_graph(3)
>>> labels = []
>>> nx.set_node_attributes(G, labels, "labels")
>>> labels.append("foo")
>>> G.nodes[0]["labels"]
['foo']
>>> G.nodes[1]["labels"]
['foo']
>>> G.nodes[2]["labels"]
['foo']
If you provide a dictionary of dictionaries as the second argument,
the outer dictionary is assumed to be keyed by node to an inner
dictionary of node attributes for that node::
>>> G = nx.path_graph(3)
>>> attrs = {0: {"attr1": 20, "attr2": "nothing"}, 1: {"attr2": 3}}
>>> nx.set_node_attributes(G, attrs)
>>> G.nodes[0]["attr1"]
20
>>> G.nodes[0]["attr2"]
'nothing'
>>> G.nodes[1]["attr2"]
3
>>> G.nodes[2]
{}
Note that if the dictionary contains nodes that are not in `G`, the
values are silently ignored::
>>> G = nx.Graph()
>>> G.add_node(0)
>>> nx.set_node_attributes(G, {0: "red", 1: "blue"}, name="color")
>>> G.nodes[0]["color"]
'red'
>>> 1 in G.nodes
False
| def set_node_attributes(G, values, name=None):
"""Sets node 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 node 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 node in `G`. This means that if
you provide a mutable object, like a list, updates to that object
will be reflected in the node attribute for every node.
The attribute name will be `name`.
If `values` is a dict or a dict of dict, it should be keyed
by node to either an attribute value or a dict of attribute key/value
pairs used to update the node's attributes.
name : string (optional, default=None)
Name of the node attribute to set if values is a scalar.
Examples
--------
After computing some property of the nodes of a graph, you may want
to assign a node attribute to store the value of that property for
each node::
>>> G = nx.path_graph(3)
>>> bb = nx.betweenness_centrality(G)
>>> isinstance(bb, dict)
True
>>> nx.set_node_attributes(G, bb, "betweenness")
>>> G.nodes[1]["betweenness"]
1.0
If you provide a list as the second argument, updates to the list
will be reflected in the node attribute for each node::
>>> G = nx.path_graph(3)
>>> labels = []
>>> nx.set_node_attributes(G, labels, "labels")
>>> labels.append("foo")
>>> G.nodes[0]["labels"]
['foo']
>>> G.nodes[1]["labels"]
['foo']
>>> G.nodes[2]["labels"]
['foo']
If you provide a dictionary of dictionaries as the second argument,
the outer dictionary is assumed to be keyed by node to an inner
dictionary of node attributes for that node::
>>> G = nx.path_graph(3)
>>> attrs = {0: {"attr1": 20, "attr2": "nothing"}, 1: {"attr2": 3}}
>>> nx.set_node_attributes(G, attrs)
>>> G.nodes[0]["attr1"]
20
>>> G.nodes[0]["attr2"]
'nothing'
>>> G.nodes[1]["attr2"]
3
>>> G.nodes[2]
{}
Note that if the dictionary contains nodes that are not in `G`, the
values are silently ignored::
>>> G = nx.Graph()
>>> G.add_node(0)
>>> nx.set_node_attributes(G, {0: "red", 1: "blue"}, name="color")
>>> G.nodes[0]["color"]
'red'
>>> 1 in G.nodes
False
"""
# Set node attributes based on type of `values`
if name is not None: # `values` must not be a dict of dict
try: # `values` is a dict
for n, v in values.items():
try:
G.nodes[n][name] = values[n]
except KeyError:
pass
except AttributeError: # `values` is a constant
for n in G:
G.nodes[n][name] = values
else: # `values` must be dict of dict
for n, d in values.items():
try:
G.nodes[n].update(d)
except KeyError:
pass
nx._clear_cache(G)
| (G, values, name=None) | [
0.03507662191987038,
0.0091753164306283,
0.004673294723033905,
-0.015179643407464027,
-0.04815205931663513,
0.027051279321312904,
-0.0675303265452385,
0.04944394528865814,
0.10374224185943604,
-0.010286141186952591,
-0.010550390928983688,
0.03257115185260773,
0.0815061703324318,
0.07696500420570374,
0.006302830763161182,
0.001968411263078451,
0.021805444732308388,
0.051910270005464554,
0.014934968203306198,
0.0038732069078832865,
0.033432405441999435,
-0.028852088376879692,
-0.01237077359110117,
0.026816392317414284,
0.024937286972999573,
-0.059583280235528946,
0.0022326603066176176,
0.0386195182800293,
0.018507225438952446,
0.04576403275132179,
-0.015228578820824623,
-0.05351533740758896,
-0.05245834216475487,
-0.02687511406838894,
0.06800010800361633,
-0.04220156371593475,
-0.032610297203063965,
0.04059649258852005,
-0.09051021188497543,
-0.03100522980093956,
-0.0004859859182033688,
-0.021825019270181656,
-0.0532413013279438,
-0.02225564792752266,
0.046703584492206573,
0.055903367698192596,
0.011137611232697964,
0.03989182785153389,
0.012507791630923748,
-0.051910270005464554,
0.006968346890062094,
-0.03625106438994408,
0.030946508049964905,
0.04259304329752922,
-0.028617199510335922,
0.0380910187959671,
-0.020082931965589523,
0.05731269717216492,
-0.0312596932053566,
-0.005837948061525822,
0.0076876915991306305,
0.007599608972668648,
-0.017450228333473206,
-0.033784739673137665,
-0.07332423329353333,
0.027892962098121643,
-0.026698946952819824,
-0.021002911031246185,
-0.03137713670730591,
0.0029018467757850885,
-0.04137945547699928,
-0.03609447181224823,
0.01727406308054924,
-0.024761119857430458,
0.015806011855602264,
0.0750076025724411,
-0.04012671858072281,
0.0800185427069664,
-0.010090401396155357,
0.0007713382947258651,
-0.012292477302253246,
0.03630978614091873,
0.016256213188171387,
-0.0260334312915802,
-0.00793725997209549,
0.03836505487561226,
-0.0423581525683403,
0.03844335302710533,
0.05872202664613724,
-0.03975481167435646,
-0.05809565633535385,
0.0003982087364420295,
0.014807737432420254,
0.009919128380715847,
0.007447910029441118,
0.03844335302710533,
0.05054008960723877,
-0.06819584220647812,
0.0030486518517136574,
0.031161820515990257,
0.02333221770823002,
-0.03149458020925522,
-0.0029776960145682096,
0.004264687187969685,
-0.02497643418610096,
-0.07974451035261154,
-0.05848713591694832,
-0.03783655911684036,
-0.0009389407350681722,
-0.057821620255708694,
-0.05586421862244606,
-0.02366497553884983,
0.11783552914857864,
-0.035448528826236725,
0.000366400956409052,
0.02615087479352951,
-0.021257372573018074,
-0.06843073666095734,
-0.014670719392597675,
0.008744688704609871,
-0.0024381873663514853,
0.03873696178197861,
0.03560512140393257,
0.06518144905567169,
0.026366189122200012,
0.0287542175501585,
0.02403688244521618,
0.05124475434422493,
0.012086950242519379,
-0.04709506407380104,
-0.01437710877507925,
-0.02757977694272995,
0.01965230517089367,
0.04188837856054306,
0.06584696471691132,
-0.01713704504072666,
-0.07786540687084198,
0.012008653953671455,
0.07007495313882828,
0.0033226879313588142,
0.016872795298695564,
-0.043728332966566086,
0.034371957182884216,
-0.03535065799951553,
-0.009023617953062057,
-0.03243413195014,
-0.020141655579209328,
-0.022333944216370583,
-0.02628789283335209,
0.037092745304107666,
-0.01679449900984764,
0.00953743513673544,
0.053202155977487564,
0.018644243478775024,
-0.05183197557926178,
-0.007286424748599529,
-0.03304092586040497,
-0.03053545393049717,
0.0036897005047649145,
0.014788162894546986,
-0.037210188806056976,
-0.003723955014720559,
0.012282690033316612,
-0.01859530806541443,
0.025152601301670074,
-0.011959719471633434,
0.03127926588058472,
-0.021022485569119453,
-0.003026630962267518,
0.02262755297124386,
0.02769722230732441,
-0.06349807977676392,
0.02329307049512863,
0.016755351796746254,
-0.00458765821531415,
-0.02947845682501793,
0.06854818016290665,
-0.062206197530031204,
-0.007198341656476259,
0.052497491240501404,
-0.026111727580428123,
0.015238365158438683,
-0.013065651059150696,
0.03693615272641182,
0.012096737511456013,
-0.016011537984013557,
-0.018977001309394836,
0.02356710657477379,
0.018761686980724335,
0.025230897590517998,
0.05386767163872719,
-0.00775130745023489,
-0.025172173976898193,
0.046194661408662796,
0.04525510594248772,
0.0022852655965834856,
0.013672444969415665,
-0.03458727151155472,
0.0023868056014180183,
0.08455971628427505,
0.05104901269078255,
-0.045489996671676636,
0.04087052866816521,
0.024898137897253036,
0.05895691365003586,
-0.02143353968858719,
0.057939063757658005,
-0.018419142812490463,
-0.03163159638643265,
-0.03468514233827591,
-0.012155459262430668,
-0.025485359132289886,
0.010012105107307434,
0.025955135002732277,
-0.03719061613082886,
0.007447910029441118,
-0.014944755472242832,
0.021962037310004234,
-0.029165271669626236,
-0.04697762057185173,
0.01764596812427044,
0.011695469729602337,
0.039128441363573074,
-0.03292348235845566,
0.027266593649983406,
-0.043610889464616776,
0.00508924201130867,
-0.04494192451238632,
0.025504933670163155,
0.002038143575191498,
0.047643136233091354,
0.02746233344078064,
0.02605300582945347,
0.01543410588055849,
0.0036701266653835773,
-0.06792180985212326,
0.06972261518239975,
-0.01775362528860569,
0.018311485648155212,
0.03597702831029892,
-0.02258840575814247,
-0.04701676964759827,
-0.0497179813683033,
0.015590697526931763,
0.008358101360499859,
-0.01331032533198595,
0.0015145388897508383,
0.013633296824991703,
-0.02119865082204342,
0.010511242784559727,
-0.06095346063375473,
0.0011646534549072385,
-0.010638473555445671,
0.036642543971538544,
-0.036877430975437164,
0.03300177678465843,
0.020983336493372917,
-0.014484765939414501,
0.022862441837787628,
-0.019084658473730087,
-0.0015867180190980434,
-0.03255157545208931,
-0.07050558179616928,
0.0376603938639164,
0.03895227611064911,
-0.021727148443460464,
0.041731785982847214,
0.016833648085594177,
-0.10538645833730698,
-0.0014643805334344506,
0.005490509327501059,
0.0032786463852971792,
-0.004367450717836618,
-0.021237799897789955,
0.030750766396522522,
0.005162644665688276,
0.016246426850557327,
-0.034371957182884216,
-0.016725990921258926,
-0.03090735897421837,
0.01753831095993519,
-0.04533340409398079,
-0.04087052866816521,
0.047525692731142044,
-0.0003563081263564527,
-0.02190331555902958,
-0.020219950005412102,
0.049992017447948456,
-0.005588379222899675,
-0.021609704941511154,
0.08377675712108612,
0.023880289867520332,
-0.05316300690174103,
0.01532644871622324,
0.01100059226155281,
0.022882016375660896,
-0.07614289224147797,
-0.0010857457527890801,
0.030750766396522522,
0.031161820515990257,
0.06815669685602188,
-0.02270584926009178,
0.04227985814213753,
0.027051279321312904,
0.045724883675575256,
-0.014572849497199059,
0.06244108825922012,
0.03223839029669762,
-0.029791640117764473,
0.09309398382902145,
-0.03245370462536812,
0.023410513997077942,
-0.02415432594716549,
-0.005842841695994139,
0.0598573163151741,
0.014112859964370728,
0.042788781225681305,
-0.03139670938253403,
0.022157777100801468,
0.019701238721609116,
-0.029263142496347427,
-0.01892806589603424,
-0.06576866656541824,
-0.005329023580998182,
-0.027051279321312904,
0.020513560622930527,
0.07802199572324753,
0.08910088986158371,
0.021727148443460464,
-0.0002711306151468307,
-0.05245834216475487,
-0.012165246531367302,
0.03288433328270912,
0.01646174117922783,
0.004962011240422726,
0.052732378244400024,
-0.01177376601845026,
0.0215509831905365,
0.03597702831029892,
-0.016285575926303864,
-0.001608738792128861,
0.04067479074001312,
-0.06428104639053345,
-0.029615474864840508,
0.011157184839248657,
0.01965230517089367,
0.02509387955069542,
0.01006104052066803,
0.014093286357820034,
0.01821361482143402,
-0.04826950654387474,
0.09458161145448685,
-0.0051479642279446125,
0.01977953501045704,
-0.04224070906639099,
0.01752852462232113,
0.00712983263656497,
-0.057234399020671844,
-0.007535993121564388,
-0.03836505487561226,
-0.022314369678497314,
0.023116903379559517,
0.054963815957307816,
-0.03644680231809616,
0.031905632466077805,
-0.0027550416998565197,
0.0027892962098121643,
0.030476730316877365,
0.04388492554426193,
-0.05836969241499901,
0.06349807977676392,
-0.0594266913831234,
-0.03730805963277817,
0.02757977694272995,
-0.0013775208499282598,
0.02756020426750183,
-0.03814974054694176,
-0.010403585620224476,
-0.009557009674608707,
0.006464316044002771,
-0.021825019270181656,
-0.043258558958768845,
0.030692044645547867,
0.04251474514603615,
0.0386195182800293,
-0.03131841495633125,
0.10429031401872635,
-0.016608545556664467,
0.002370901871472597,
-0.018742112442851067,
-0.01646174117922783,
-0.022099055349826813,
0.005436680745333433,
0.00010972149175358936,
-0.06459422409534454,
-0.023058181628584862,
0.035565972328186035,
-0.0038585264701396227,
-0.05570762977004051,
-0.08675200492143631,
-0.05171452835202217,
-0.03198393061757088,
0.02793210931122303,
0.028617199510335922,
0.045489996671676636,
-0.006116877775639296,
0.06173642352223396,
0.03695572912693024,
0.0532413013279438,
0.04498106986284256,
0.01741108112037182,
-0.020396117120981216,
-0.025230897590517998,
-0.021844593808054924,
0.030320139601826668,
-0.011617174372076988,
0.022510109469294548,
-0.008592989295721054,
0.04795632138848305,
-0.029165271669626236,
0.02936101332306862,
-0.025015583261847496,
0.0281669981777668,
0.03433281183242798,
0.059113506227731705,
-0.011969505809247494,
0.03930461034178734,
-0.03576171398162842,
-0.030437583103775978,
0.05453318729996681,
-0.03255157545208931,
-0.002569088712334633,
0.007878538221120834,
0.019016148522496223,
0.06772606819868088,
-0.012341412715613842,
0.009038298390805721,
-0.05833054333925247,
-0.027364464476704597,
-0.009625518694519997,
-0.065298892557621,
-0.025524506345391273,
-0.0016955984756350517,
-0.07418549060821533,
-0.07473356276750565,
-0.0378757044672966,
-0.022314369678497314,
-0.002600896405056119,
0.04674273356795311,
-0.04748654365539551,
-0.008764262311160564,
0.015424318611621857,
0.03636850789189339,
-0.00441149203106761,
-0.018644243478775024,
0.044198110699653625,
-0.07763051986694336,
-0.02178587205708027,
0.03679913654923439,
0.013026502914726734,
-0.013515852391719818,
-0.04772143065929413,
-0.02297988533973694,
0.009160635992884636,
-0.010188271291553974,
0.03358899801969528,
0.04498106986284256,
-0.024076029658317566,
0.0028724856674671173,
-0.01219460740685463,
0.027247019112110138,
-0.05335874855518341,
0.010638473555445671,
-0.015903882682323456,
-0.013985629193484783,
-0.013721379451453686,
-0.044550444930791855,
-0.0034915136639028788,
-0.09920107573270798,
-0.06181471794843674,
0.0017946918960660696,
-0.011979293078184128,
0.06706055253744125,
0.03711232170462608,
0.056373145431280136,
-0.005270301830023527,
0.016833648085594177,
-0.023038607090711594,
0.009121487848460674,
0.045529142022132874,
-0.002955675357952714,
-0.09802663326263428,
-0.0051430705934762955,
-0.007829603739082813,
-0.011098463088274002,
-0.0019586242269724607,
-0.04627295583486557,
-0.04181008040904999,
-0.01319288183003664,
-0.030829062685370445,
-0.05836969241499901,
-0.008196615613996983,
0.032590724527835846,
0.005451361183077097,
0.057077810168266296,
0.02258840575814247,
-0.009615731425583363,
-0.0076142894104123116,
0.03337368369102478,
-0.017949365079402924,
0.023958586156368256,
0.024780694395303726,
0.021825019270181656,
0.012449068948626518,
0.021590130403637886,
0.009087233804166317,
-0.008441290818154812,
0.039343755692243576,
-0.0017041621031239629,
-0.08299379795789719,
-0.0032566257286816835,
-0.011215906590223312,
0.02746233344078064,
0.007668117992579937,
-0.02613130211830139,
0.012860123068094254,
0.03149458020925522,
-0.0454508475959301,
0.011832487769424915,
-0.006273469887673855,
0.010511242784559727,
0.05339789390563965,
-0.03625106438994408,
0.027521055191755295,
0.020513560622930527,
0.014895820058882236,
0.08996213972568512,
0.019681666046380997,
0.01882040873169899,
0.035468101501464844,
0.0378757044672966,
0.0258181169629097,
0.03337368369102478,
0.025720246136188507,
-0.03582043573260307,
-0.03300177678465843,
-0.005299662705510855,
-0.03623148798942566,
0.04055734723806381,
-0.07226724177598953,
-0.020865892991423607,
-0.051792826503515244,
-0.005201792810112238,
-0.0076093957759439945,
-0.019936127588152885,
-0.05848713591694832,
0.021042058244347572,
-0.024428362026810646,
-0.003723955014720559,
0.025270044803619385,
-0.046703584492206573,
-0.0297133456915617,
0.02756020426750183,
-0.0006107702502049506,
0.007017281837761402,
-0.005192005541175604,
-0.04944394528865814,
-0.021727148443460464,
0.008270018734037876,
0.029909085482358932,
-0.013124372810125351,
0.08643881976604462,
0.03174903988838196,
0.016021326184272766,
0.01177376601845026,
-0.0004633534699678421,
0.02912612445652485,
0.022040333598852158,
-0.02391943894326687,
-0.033197518438100815,
-0.02699255757033825,
0.03689700737595558,
-0.014200943522155285,
0.009341695345938206,
0.05292811989784241,
0.02072887495160103,
-0.02830401621758938,
0.09818322956562042,
-0.02247096225619316,
0.028225719928741455,
-0.0316903181374073,
0.0068117547780275345,
0.018977001309394836,
-0.015806011855602264,
-0.035565972328186035,
-0.011891210451722145,
-0.026894686743617058,
-0.024193475022912025,
-0.004007778130471706,
0.020768022164702415,
-0.06670822203159332,
-0.020885467529296875,
-0.003229711437597871,
0.03879568353295326,
-0.04995286837220192,
-0.03427409008145332,
0.020180802792310715,
-0.005813480354845524,
-0.016011537984013557,
-0.04321940988302231,
0.0367012657225132,
0.01906508393585682,
0.013789888471364975,
0.0037215084303170443,
0.0477997288107872,
-0.03936333209276199,
-0.01472944114357233,
0.05786076933145523,
-0.012635022401809692,
-0.045724883675575256,
-0.04732995107769966,
-0.07911814004182816,
-0.05147964134812355,
-0.03180776536464691,
0.025270044803619385,
-0.001693151774816215,
-0.023136477917432785,
-0.02519174851477146,
-0.06533803790807724,
-0.02225564792752266,
0.00792747363448143,
-0.07571226358413696,
-0.03877611085772514,
-0.052732378244400024,
0.007770881522446871,
-0.05382852256298065,
0.020787596702575684,
0.004367450717836618,
-0.010804852470755577,
0.03611404448747635,
0.014651144854724407,
-0.0028186573181301355,
0.005015839822590351,
0.0007077227346599102,
-0.03476344048976898,
0.004470214247703552,
0.031161820515990257,
-0.04721250757575035,
0.034371957182884216,
0.01857573352754116,
0.013701805844902992,
0.013506066054105759,
-0.006831328850239515,
0.014592423103749752,
0.03869781643152237,
0.023704124614596367,
-0.03452854976058006,
-0.013877972029149532,
0.014054138213396072,
-0.02983078919351101,
-0.019554434344172478,
-0.0072668506763875484,
0.04036160558462143,
0.039696089923381805,
0.02830401621758938,
0.002569088712334633,
-0.016755351796746254,
-0.001964741153642535,
0.022059908136725426,
0.022784145548939705,
-0.0485435426235199,
-0.03599660098552704,
0.024898137897253036,
-0.003941716160625219,
-0.023116903379559517,
-0.03599660098552704,
0.013143946416676044,
0.01820382848381996,
0.06302830576896667,
0.03519406542181969,
-0.027873387560248375,
0.04435470327734947,
0.0014435831690207124,
-0.0006361552514135838,
-0.020298246294260025,
0.019613156095147133,
-0.0044481935910880566,
-0.010256780311465263,
0.0030926933977752924,
0.04584232717752457,
-0.008783835917711258,
-0.06267597526311874,
0.01479795016348362,
0.01290905848145485,
-0.02769722230732441,
-0.02450665831565857,
-0.0035257681738585234,
0.010971231386065483,
0.051205605268478394,
0.023939011618494987,
0.021864166483283043,
0.02804955467581749,
-0.07242383062839508,
0.011695469729602337,
-0.001509645371697843,
-0.05292811989784241,
-0.06811755150556564,
0.02722744643688202,
0.011010379530489445,
-0.015287300571799278,
-0.04016586393117905,
0.02436964027583599,
0.027188297361135483,
-0.0006954889977350831,
0.012047802098095417,
-0.0013090118300169706,
-0.0058575221337378025,
-0.06095346063375473,
-0.0386195182800293,
0.047643136233091354,
-0.02200118452310562,
0.01966209150850773,
0.03151415288448334,
0.009424884803593159,
-0.026679374277591705,
-0.04271048679947853,
-0.0002806117699947208,
-0.014572849497199059,
0.03529193624854088,
-0.03239498287439346,
-0.0028137636836618185,
0.08675200492143631,
-0.005896669812500477,
0.00121297687292099,
-0.05187112092971802,
-0.06940943747758865,
-0.02272542379796505,
-0.004037139005959034,
-0.010628686286509037,
0.07261957228183746,
-0.006914518307894468,
0.0027697221376001835,
-0.02462410181760788,
-0.04517681151628494,
-0.010462307371199131,
-0.03300177678465843,
-0.0388348326086998,
0.05872202664613724,
0.009752749465405941,
0.016295362263917923,
0.040067996829748154,
0.018272336572408676,
-0.050109460949897766,
0.0040175653994083405,
0.12182863056659698,
-0.0586828775703907,
0.02804955467581749,
-0.012987354770302773,
0.02319519966840744,
-0.03452854976058006,
-0.016667267307639122,
0.01597239077091217,
-0.0042720274068415165,
-0.02333221770823002,
-0.011538878083229065,
0.036055322736501694,
0.02356710657477379,
0.04529425501823425
]
|
31,097 | networkx.drawing.layout | shell_layout | Position nodes in concentric circles.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G.
nlist : list of lists
List of node lists for each shell.
rotate : angle in radians (default=pi/len(nlist))
Angle by which to rotate the starting position of each shell
relative to the starting position of the previous shell.
To recreate behavior before v2.5 use rotate=0.
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, currently only dim=2 is supported.
Other dimension values result in a ValueError.
Returns
-------
pos : dict
A dictionary of positions keyed by node
Raises
------
ValueError
If dim != 2
Examples
--------
>>> G = nx.path_graph(4)
>>> shells = [[0], [1, 2, 3]]
>>> pos = nx.shell_layout(G, shells)
Notes
-----
This algorithm currently only works in two dimensions and does not
try to minimize edge crossings.
| def shell_layout(G, nlist=None, rotate=None, scale=1, center=None, dim=2):
"""Position nodes in concentric circles.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G.
nlist : list of lists
List of node lists for each shell.
rotate : angle in radians (default=pi/len(nlist))
Angle by which to rotate the starting position of each shell
relative to the starting position of the previous shell.
To recreate behavior before v2.5 use rotate=0.
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, currently only dim=2 is supported.
Other dimension values result in a ValueError.
Returns
-------
pos : dict
A dictionary of positions keyed by node
Raises
------
ValueError
If dim != 2
Examples
--------
>>> G = nx.path_graph(4)
>>> shells = [[0], [1, 2, 3]]
>>> pos = nx.shell_layout(G, shells)
Notes
-----
This algorithm currently only works in two dimensions and does not
try to minimize edge crossings.
"""
import numpy as np
if dim != 2:
raise ValueError("can only handle 2 dimensions")
G, center = _process_params(G, center, dim)
if len(G) == 0:
return {}
if len(G) == 1:
return {nx.utils.arbitrary_element(G): center}
if nlist is None:
# draw the whole graph in one shell
nlist = [list(G)]
radius_bump = scale / len(nlist)
if len(nlist[0]) == 1:
# single node at center
radius = 0.0
else:
# else start at r=1
radius = radius_bump
if rotate is None:
rotate = np.pi / len(nlist)
first_theta = rotate
npos = {}
for nodes in nlist:
# Discard the last angle (endpoint=False) since 2*pi matches 0 radians
theta = (
np.linspace(0, 2 * np.pi, len(nodes), endpoint=False, dtype=np.float32)
+ first_theta
)
pos = radius * np.column_stack([np.cos(theta), np.sin(theta)]) + center
npos.update(zip(nodes, pos))
radius += radius_bump
first_theta += rotate
return npos
| (G, nlist=None, rotate=None, scale=1, center=None, dim=2) | [
0.032115623354911804,
-0.001392651116475463,
-0.02391510084271431,
-0.048386797308921814,
0.011725635267794132,
0.09068813920021057,
0.0033743667881935835,
0.017885303124785423,
0.03996363654732704,
-0.027495872229337692,
-0.009401843883097172,
0.03231970965862274,
0.009063247591257095,
0.017440026625990868,
-0.01912836916744709,
-0.05918477103114128,
0.03426779806613922,
-0.026957828551530838,
0.012773891910910606,
-0.001675587729550898,
0.03059425950050354,
-0.054138295352458954,
0.05053897202014923,
-0.011113379150629044,
-0.03050149418413639,
-0.04085418954491615,
0.026271359995007515,
0.03278353810310364,
0.00226813112385571,
0.015464108437299728,
0.031076643615961075,
0.017588453367352486,
-0.014100447297096252,
0.010130058042705059,
0.010686654597520828,
0.04293214902281761,
0.040446020662784576,
0.03068702481687069,
-0.032059963792562485,
0.011131932027637959,
0.011298910714685917,
-0.015491938218474388,
0.020260116085410118,
-0.02280190773308277,
0.034008052200078964,
0.06820163875818253,
0.021651607006788254,
0.004443496000021696,
-0.026549657806754112,
0.028497746214270592,
0.012968700379133224,
-0.0664205253124237,
-0.041522108018398285,
-0.06122562661767006,
-0.04519564285874367,
-0.02879459783434868,
0.02005603164434433,
0.0011160920839756727,
-0.0007595224305987358,
-0.03614167124032974,
0.025417910888791084,
0.036642611026763916,
-0.005004731006920338,
-0.013747936114668846,
-0.05662442743778229,
-0.0231173112988472,
0.051021356135606766,
-0.033006180077791214,
0.007745969109237194,
-0.042486872524023056,
-0.017811091616749763,
0.02291322685778141,
0.04716228321194649,
-0.04760756343603134,
0.03254234790802002,
-0.00456409202888608,
0.04389691725373268,
0.030353067442774773,
-0.004879496991634369,
0.03226405009627342,
-0.027922596782445908,
0.001255821087397635,
0.021169224753975868,
0.031132303178310394,
0.028200894594192505,
0.039592571556568146,
0.03847937658429146,
0.09484405815601349,
-0.027514426037669182,
-0.05454646795988083,
0.015482662245631218,
-0.009619844146072865,
0.026549657806754112,
-0.039778102189302444,
0.006048349663615227,
0.024620123207569122,
0.012671848759055138,
-0.0474962443113327,
-0.006025158334523439,
-0.010779420845210552,
-0.028145235031843185,
0.04100261628627777,
-0.03940704092383385,
-0.05447225272655487,
-0.040520232170820236,
-0.012439933605492115,
-0.042412661015987396,
0.03829384595155716,
-0.06033506989479065,
0.02565910294651985,
-0.0003936761349905282,
0.04671700671315193,
0.048461008816957474,
-0.001788066583685577,
0.07232045382261276,
0.031262174248695374,
-0.005185625050216913,
0.014629214070737362,
0.009647673927247524,
-0.03549230843782425,
-0.06055770814418793,
0.005329412408173084,
0.003072876948863268,
-0.006368392612785101,
0.014258149079978466,
0.05562255159020424,
0.02788548916578293,
0.011169038712978363,
-0.0015526725910604,
0.031243622303009033,
0.037774354219436646,
-0.013033636845648289,
0.022430842742323875,
0.017532791942358017,
0.02782982960343361,
-0.04103972390294075,
-0.05651310831308365,
-0.017857473343610764,
-0.01487040612846613,
-0.007588266860693693,
0.03955546393990517,
-0.0664205253124237,
-0.03317315876483917,
0.044527728110551834,
-0.05903634428977966,
0.032857753336429596,
0.03224549442529678,
-0.03703222796320915,
0.03699512034654617,
0.00249772728420794,
0.032041411846876144,
-0.013330488465726376,
0.11206144839525223,
-0.0018472049850970507,
0.003919367678463459,
-0.018803687766194344,
-0.004206942394375801,
-0.04077997803688049,
-0.03601180016994476,
0.05840553715825081,
-0.053025104105472565,
-0.011623592115938663,
0.004026048816740513,
0.03552941605448723,
-0.021299095824360847,
-0.03539954498410225,
0.029926342889666557,
-0.04886918142437935,
-0.021484628319740295,
-0.020761054009199142,
0.0034161116927862167,
-0.03326592221856117,
-0.03629009798169136,
-0.02860906533896923,
0.018627433106303215,
0.002885025693103671,
0.0004475964233279228,
0.013497467152774334,
-0.06456520408391953,
-0.02959238551557064,
-0.016521641984581947,
-0.03933282569050789,
0.06122562661767006,
0.027477318421006203,
-0.04322900250554085,
0.061485372483730316,
0.06534443795681,
-0.013070743530988693,
0.02100224420428276,
0.002831685123965144,
-0.05710681155323982,
0.02578897587954998,
-0.029481066390872,
0.06337779760360718,
0.00004330292358645238,
0.026345571503043175,
-0.018488284200429916,
0.009740440174937248,
-0.07933356612920761,
0.019851945340633392,
0.002961557824164629,
0.026141487061977386,
0.027495872229337692,
-0.015621811151504517,
0.02191135287284851,
-0.04590066522359848,
-0.029406853020191193,
0.03719920665025711,
0.032022856175899506,
0.0030264940578490496,
-0.02000037021934986,
0.0006093573174439371,
0.011224698275327682,
-0.021707266569137573,
-0.02771851047873497,
0.007931501604616642,
-0.023395610973238945,
0.008720013312995434,
-0.010009462013840675,
-0.06089166924357414,
-0.01001873891800642,
0.03851648420095444,
0.010352696292102337,
-0.02107645757496357,
-0.027421658858656883,
-0.046345941722393036,
0.03790422901511192,
-0.06872112303972244,
0.020723946392536163,
-0.01482402253895998,
0.05065029114484787,
-0.07027959823608398,
-0.0012592998100444674,
0.01332121156156063,
-0.004005176480859518,
-0.07621663063764572,
-0.004387836437672377,
0.0025325145106762648,
-0.013441807590425014,
0.06222749873995781,
-0.052134547382593155,
-0.042561087757349014,
-0.029035789892077446,
0.01914692297577858,
0.029017236083745956,
0.0711701512336731,
0.027365999296307564,
-0.029332641512155533,
-0.0460490919649601,
-0.022597821429371834,
-0.07554870843887329,
-0.023395610973238945,
-0.007161542773246765,
-0.02588174119591713,
-0.012356444261968136,
0.03918439894914627,
-0.0853448137640953,
0.01830275170505047,
0.006604946218430996,
-0.025046847760677338,
-0.02586318925023079,
-0.04515853896737099,
-0.03361843526363373,
0.006303456611931324,
0.11361991614103317,
0.02478710189461708,
0.00865507684648037,
0.031058089807629585,
-0.05929609015583992,
0.004130410496145487,
-0.012644018977880478,
0.06382307410240173,
0.01054750569164753,
0.013933468610048294,
0.07547450065612793,
0.03252379596233368,
0.009499249048531055,
0.009888865984976292,
0.03955546393990517,
-0.017644112929701805,
-0.010742314159870148,
0.0010610122699290514,
-0.044416408985853195,
-0.019332455471158028,
-0.01916547678411007,
0.01100205909460783,
0.005055752582848072,
-0.04571513459086418,
0.01918402872979641,
-0.015482662245631218,
0.04200448840856552,
-0.024100633338093758,
-0.030779791995882988,
-0.02473144233226776,
-0.01437874510884285,
0.0304829403758049,
-0.03519545868039131,
-0.004392474889755249,
-0.03933282569050789,
0.001011730288155377,
0.06942614912986755,
-0.050056587904691696,
0.031020984053611755,
0.011252528056502342,
0.03452754393219948,
0.03261655941605568,
0.012690402567386627,
0.000768799043726176,
0.009304439648985863,
-0.01918402872979641,
-0.031206516548991203,
-0.0015967364888638258,
0.03426779806613922,
0.004689326509833336,
-0.0172916017472744,
0.0304829403758049,
0.011883337050676346,
-0.01386853214353323,
0.03165179491043091,
0.04193027690052986,
-0.0003125057846773416,
-0.014248873107135296,
-0.0595187284052372,
0.11235830187797546,
0.026549657806754112,
0.03265366703271866,
-0.0036804950796067715,
0.07491790503263474,
0.03374830633401871,
0.06668027490377426,
-0.029054341837763786,
0.03374830633401871,
-0.02782982960343361,
0.004888773430138826,
-0.04304347187280655,
-0.014443681575357914,
0.050205014646053314,
0.03330302983522415,
-0.04886918142437935,
-0.05269114300608635,
0.06022375077009201,
-0.002131301211193204,
0.007889756932854652,
-0.01705040968954563,
-0.00024452563957311213,
0.0382196344435215,
0.056772854179143906,
0.004842390306293964,
-0.019740626215934753,
-0.05458357185125351,
0.020482754334807396,
0.11324885487556458,
-0.06014953926205635,
-0.015918662771582603,
-0.023469822481274605,
0.043488748371601105,
0.00907252449542284,
-0.04033470153808594,
-0.02482420764863491,
0.007254309020936489,
0.059852685779333115,
-0.02868327870965004,
0.0007270543137565255,
0.007810905575752258,
-0.05250561237335205,
0.00043107246165163815,
-0.01426742598414421,
0.03313605114817619,
0.10330432653427124,
0.002917493926361203,
0.019870499148964882,
-0.023636803030967712,
-0.050056587904691696,
0.014276702888309956,
-0.015055937692523003,
0.05766340717673302,
-0.017681218683719635,
-0.04300636425614357,
-0.014332362450659275,
-0.02196701243519783,
0.007875842042267323,
-0.04764466732740402,
0.05473199859261513,
0.023395610973238945,
-0.03907307982444763,
-0.013497467152774334,
0.025974508374929428,
0.0536930188536644,
-0.029462512582540512,
-0.03176311403512955,
-0.06968589127063751,
-0.008205161429941654,
0.059964004904031754,
0.021410414949059486,
-0.0022762480657547712,
0.046457260847091675,
0.013571680523455143,
0.047422029078006744,
-0.08178259432315826,
-0.007806267123669386,
0.005811796057969332,
-0.0275700856000185,
0.029128555208444595,
-0.01715245097875595,
0.006850776262581348,
-0.08155995607376099,
0.0343976691365242,
0.0052551995031535625,
0.030297407880425453,
0.011874061077833176,
-0.012198742479085922,
-0.0515037402510643,
0.06055770814418793,
-0.005732945166528225,
0.030241748318076134,
-0.02671663649380207,
-0.07562292367219925,
0.08593851327896118,
0.028386427089571953,
-0.09076235443353653,
-0.029110001400113106,
-0.017004026100039482,
0.02115067094564438,
0.024249058216810226,
0.001933013554662466,
0.03131783381104469,
0.019443774595856667,
0.0010140493977814913,
-0.02497263438999653,
0.05087292939424515,
0.001476140576414764,
0.026327019557356834,
0.027347445487976074,
0.00017451622989028692,
0.0028479192405939102,
-0.018933560699224472,
0.07105883210897446,
-0.026549657806754112,
-0.015696024522185326,
0.04118814691901207,
0.013914914801716805,
0.03636430948972702,
-0.010695931501686573,
0.007861927151679993,
0.010807250626385212,
0.07176385819911957,
-0.033043283969163895,
-0.03259800747036934,
0.010788697749376297,
0.0009201237699016929,
0.04686543345451355,
-0.03836805745959282,
0.03055715374648571,
-0.03606745973229408,
-0.014582830481231213,
-0.009457503445446491,
-0.044490620493888855,
0.012913040816783905,
-0.10456594824790955,
0.033841073513031006,
0.05228297412395477,
-0.02489842101931572,
-0.046308837831020355,
0.016874153167009354,
-0.02578897587954998,
-0.01332121156156063,
-0.01379431877285242,
0.040446020662784576,
-0.04560381546616554,
0.0014367150142788887,
0.005213454831391573,
-0.02482420764863491,
-0.057700514793395996,
-0.005283029284328222,
-0.025306591764092445,
-0.011178314685821533,
0.03851648420095444,
-0.04901760816574097,
-0.0973673015832901,
-0.01152154989540577,
-0.0613369457423687,
0.00083721405826509,
-0.004805284086614847,
0.03738473728299141,
-0.046197518706321716,
0.025399358943104744,
0.051206886768341064,
-0.009814653545618057,
-0.0012442253064364195,
-0.027904042974114418,
-0.029388301074504852,
0.0064101372845470905,
-0.015028107911348343,
0.023525482043623924,
0.032802093774080276,
-0.0004209261678624898,
-0.04296925663948059,
-0.07250598073005676,
-0.005788604728877544,
-0.020835265517234802,
-0.0019248966127634048,
-0.0037639844231307507,
0.09439878165721893,
0.015473385341465473,
0.03836805745959282,
0.0034346648026257753,
-0.005167071707546711,
0.009160652756690979,
0.003137813415378332,
0.03660550341010094,
0.035974692553281784,
0.02671663649380207,
0.01912836916744709,
-0.03404515981674194,
-0.030872557312250137,
0.03562218323349953,
0.023655354976654053,
0.07465815544128418,
0.0017474814085289836,
-0.007648564875125885,
0.018850071355700493,
0.006813670042902231,
-0.03892465680837631,
0.03452754393219948,
-0.06044638901948929,
0.029926342889666557,
0.07124436646699905,
-0.05057607591152191,
-0.027495872229337692,
-0.02673519030213356,
-0.03410081937909126,
0.04293214902281761,
-0.057923153042793274,
0.013052190653979778,
0.012161635793745518,
0.038776230067014694,
0.02102079801261425,
0.015055937692523003,
0.03925861418247223,
-0.005245923064649105,
-0.014276702888309956,
0.0035668564960360527,
-0.004179112613201141,
0.01091856975108385,
0.062487244606018066,
0.03471307456493378,
0.09707044810056686,
-0.07476947456598282,
-0.02974081225693226,
-0.009740440174937248,
0.005426816642284393,
-0.019406668841838837,
-0.016911260783672333,
-0.019313901662826538,
0.0023724930360913277,
0.003986623138189316,
0.011818401515483856,
-0.05154084414243698,
0.021410414949059486,
-0.002108109649270773,
0.012783168815076351,
-0.0013485872186720371,
-0.04475036635994911,
-0.024156292900443077,
0.09113341569900513,
-0.01644742861390114,
-0.0040677934885025024,
-0.023284291848540306,
0.014527170918881893,
0.03365553915500641,
0.01824709214270115,
0.028349319472908974,
0.04230134189128876,
-0.01812649518251419,
0.07142989337444305,
-0.05239429324865341,
0.015863003209233284,
0.04901760816574097,
-0.022263864055275917,
-0.049166031181812286,
0.013673722743988037,
-0.03836805745959282,
-0.03235681727528572,
0.02014879696071148,
0.02098369225859642,
0.09306295216083527,
-0.027291785925626755,
0.045418281108140945,
-0.006818308494985104,
-0.02760719135403633,
0.009870313107967377,
-0.018905730918049812,
0.07673611491918564,
0.04849811643362045,
-0.03155902773141861,
-0.060706134885549545,
0.01909126341342926,
-0.0017474814085289836,
-0.025195272639393806,
0.013673722743988037,
-0.06783057004213333,
0.02497263438999653,
0.009712610393762589,
0.04519564285874367,
-0.013117126189172268,
-0.014044787734746933,
0.03528822585940361,
-0.03183732554316521,
-0.02207833155989647,
-0.04174474626779556,
-0.005658732261508703,
-0.015983598306775093,
-0.02189279906451702,
-0.053025104105472565,
-0.03148481249809265,
-0.021466074511408806,
-0.00007345190533669665,
0.028497746214270592,
0.0018437262624502182,
-0.002199716167524457,
0.035900481045246124,
0.008010352961719036,
-0.03510269150137901,
-0.041485000401735306,
0.011150484904646873,
0.07380470633506775,
0.010835080407559872,
0.02666097693145275,
0.009861036203801632,
-0.018432624638080597,
0.05257982388138771,
-0.010278483852744102,
-0.004649900831282139,
0.002488450612872839,
-0.008399969898164272,
-0.040520232170820236,
-0.028367873281240463,
-0.02868327870965004,
0.0066003077663481236,
0.03558507561683655,
0.04564091935753822,
-0.046383049339056015,
-0.004856305196881294,
-0.004668454173952341,
0.018599603325128555,
-0.06193064898252487,
0.07168964296579361,
0.009466780349612236,
0.012653295882046223,
0.018386241048574448,
-0.02487986721098423,
0.047422029078006744,
0.001972439233213663,
0.009160652756690979,
-0.009336908347904682,
0.030148983001708984,
-0.024082079529762268,
-0.0515037402510643,
0.005579880904406309,
-0.049203138798475266,
0.028256554156541824,
0.03191153705120087,
-0.03836805745959282,
0.03577060624957085,
0.00813094899058342,
-0.03317315876483917,
-0.010825803503394127,
-0.010306313633918762,
0.009777546860277653,
0.0021684076637029648,
0.0034671330358833075,
-0.07380470633506775,
0.0324866883456707,
0.014119000174105167,
-0.0033766860142350197,
-0.03139204904437065,
0.045566707849502563,
0.05447225272655487,
-0.007588266860693693,
-0.002130141481757164,
-0.026475444436073303,
-0.01641959883272648,
-0.0046777306124567986,
0.004925880115479231,
-0.06000111252069473,
0.014675596728920937,
0.01641032285988331,
-0.06426835060119629,
0.002237982116639614,
0.045529600232839584,
0.04293214902281761,
0.0366797149181366,
0.05157795175909996,
-0.009063247591257095,
0.003492643591016531,
-0.0010760867735370994,
-0.000007641426236659754,
0.02196701243519783,
0.02395220659673214,
-0.02688361518085003,
0.04779309406876564,
-0.050205014646053314,
-0.04029759392142296,
0.028367873281240463,
-0.01724521815776825,
-0.05050186440348625,
-0.0609658807516098,
0.030334513634443283,
0.015584704466164112,
0.04467615485191345,
-0.02671663649380207,
-0.017773984000086784,
0.04667990282177925,
-0.022542161867022514,
-0.011271080933511257,
-0.021707266569137573,
0.01722666434943676,
0.04382270574569702,
-0.03528822585940361,
-0.05135531350970268,
-0.022375183179974556,
-0.006507541984319687,
0.04285793751478195,
0.06705133616924286,
0.01297797728329897,
-0.0182934757322073,
0.029295533895492554,
-0.03532532975077629,
-0.0647878423333168,
0.0025904932990670204,
-0.04326611012220383,
0.0573294498026371,
-0.008566949516534805,
0.031039535999298096,
0.008455630391836166,
0.023506930097937584,
-0.003494962817057967,
-0.04219002276659012,
-0.10345275700092316,
0.014814745634794235,
0.07465815544128418,
-0.04578934609889984,
-0.06976010650396347,
-0.06864691525697708,
0.0343976691365242,
-0.024044973775744438,
-0.025529230013489723,
-0.015454832464456558,
0.014944618567824364,
0.02872038446366787,
0.0014332362916320562,
0.017569899559020996,
-0.017486410215497017,
-0.004791369196027517,
-0.011076272465288639,
-0.019907604902982712,
-0.0199261587113142,
0.020389989018440247,
-0.00811703409999609,
-0.05447225272655487,
-0.055028852075338364,
-0.04397113248705864,
-0.0593331977725029,
0.013914914801716805,
0.006284903269261122,
-0.0070223938673734665,
0.03165179491043091,
0.012300784699618816
]
|
31,101 | networkx.algorithms.simple_paths | shortest_simple_paths | Generate all simple paths in the graph G from source to target,
starting from shortest ones.
A simple path is a path with no repeated nodes.
If a weighted shortest path search is to be used, no negative weights
are allowed.
Parameters
----------
G : NetworkX graph
source : node
Starting node for path
target : node
Ending node for path
weight : string or function
If it is a string, it is the name of the edge attribute to be
used as a weight.
If it 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.
If None all edges are considered to have unit weight. Default
value None.
Returns
-------
path_generator: generator
A generator that produces lists of simple paths, in order from
shortest to longest.
Raises
------
NetworkXNoPath
If no path exists between source and target.
NetworkXError
If source or target nodes are not in the input graph.
NetworkXNotImplemented
If the input graph is a Multi[Di]Graph.
Examples
--------
>>> G = nx.cycle_graph(7)
>>> paths = list(nx.shortest_simple_paths(G, 0, 3))
>>> print(paths)
[[0, 1, 2, 3], [0, 6, 5, 4, 3]]
You can use this function to efficiently compute the k shortest/best
paths between two nodes.
>>> from itertools import islice
>>> def k_shortest_paths(G, source, target, k, weight=None):
... return list(
... islice(nx.shortest_simple_paths(G, source, target, weight=weight), k)
... )
>>> for path in k_shortest_paths(G, 0, 3, 2):
... print(path)
[0, 1, 2, 3]
[0, 6, 5, 4, 3]
Notes
-----
This procedure is based on algorithm by Jin Y. Yen [1]_. Finding
the first $K$ paths requires $O(KN^3)$ operations.
See Also
--------
all_shortest_paths
shortest_path
all_simple_paths
References
----------
.. [1] Jin Y. Yen, "Finding the K Shortest Loopless Paths in a
Network", Management Science, Vol. 17, No. 11, Theory Series
(Jul., 1971), pp. 712-716.
| 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, source, target, weight=None, *, backend=None, **backend_kwargs) | [
-0.006668563466519117,
-0.017880544066429138,
-0.034567657858133316,
-0.035844836384058,
-0.026611441746354103,
-0.030777985230088234,
-0.018037574365735054,
0.045811042189598083,
0.07177342474460602,
-0.05305538326501846,
-0.02979392744600773,
0.0296892412006855,
0.021104903891682625,
0.016844142228364944,
-0.02832830883562565,
0.041497938334941864,
0.006610985845327377,
0.025648321956396103,
0.007076843176037073,
0.03368828445672989,
-0.014541028067469597,
-0.04970540106296539,
0.03431640565395355,
0.06737656891345978,
-0.03404422104358673,
-0.0254389476031065,
0.007490356918424368,
-0.00941659789532423,
-0.021712088957428932,
-0.019408974796533585,
0.0398857556283474,
-0.028160810470581055,
0.002021768130362034,
-0.02474801242351532,
0.02336614392697811,
0.04710916057229042,
0.005140133202075958,
0.015137744136154652,
-0.04861665517091751,
-0.06787906587123871,
-0.057494115084409714,
-0.05083601921796799,
0.006668563466519117,
-0.025124887004494667,
0.03728951886296272,
0.049244776368141174,
0.00006113558629294857,
0.030359238386154175,
0.00515583623200655,
0.004538182634860277,
0.01864475943148136,
-0.0018765149870887399,
-0.01386056188493967,
0.038608577102422714,
0.01227978803217411,
0.029940489679574966,
-0.019147256389260292,
0.04208418354392052,
0.057117242366075516,
-0.040388256311416626,
0.03507015481591225,
0.009374722838401794,
0.07064280658960342,
0.03440015763044357,
-0.05284601077437401,
-0.003923146519809961,
-0.0427960567176342,
-0.03580296412110329,
-0.0543535053730011,
0.02612988092005253,
0.006050910335034132,
-0.021000217646360397,
-0.010018547996878624,
0.0018280971562489867,
-0.015472742728888988,
0.014164154417812824,
0.013180096633732319,
-0.0177339818328619,
0.009500348009169102,
-0.05891785770654678,
0.044429175555706024,
-0.03607514873147011,
-0.002884127665311098,
-0.07964588701725006,
0.03973919525742531,
0.018403979018330574,
0.018362104892730713,
0.017022110521793365,
-0.011463229544460773,
-0.03285078704357147,
-0.0724852979183197,
0.036096084862947464,
0.01736757718026638,
0.042733244597911835,
0.053599756211042404,
0.02328239381313324,
0.0033526020124554634,
-0.0666646957397461,
0.04756978526711464,
0.0042345901019871235,
0.011923852376639843,
0.05401850491762161,
-0.06737656891345978,
0.03446296975016594,
0.0023175091482698917,
-0.051673516631126404,
-0.0203406885266304,
0.001146322931163013,
-0.006522001698613167,
-0.05439537763595581,
-0.05728474259376526,
0.004559120163321495,
0.02154459059238434,
-0.01530524343252182,
0.009489879012107849,
0.02617175690829754,
-0.006176534574478865,
0.019000696018338203,
0.012981191277503967,
-0.004399472381919622,
0.015818210318684578,
0.022612398490309715,
-0.09044959396123886,
-0.01966022327542305,
0.04160262271761894,
-0.023931454867124557,
0.03477703034877777,
0.008463946171104908,
0.046397291123867035,
0.019869597628712654,
0.019231006503105164,
0.031636420637369156,
-0.020466312766075134,
0.10644576698541641,
0.0003150425327476114,
0.009610269218683243,
-0.06875843554735184,
0.029500804841518402,
0.05477225035429001,
0.016791798174381256,
0.03601233661174774,
-0.10234203934669495,
0.061974719166755676,
0.012709004804491997,
0.01713726669549942,
-0.0043261912651360035,
0.0016946212854236364,
0.006302158813923597,
0.04911915212869644,
0.03877607360482216,
0.028516745194792747,
-0.01947178691625595,
0.01006042305380106,
-0.003776584519073367,
-0.0002924693690147251,
-0.03927857056260109,
-0.0466485396027565,
0.03530046343803406,
-0.0030463924631476402,
-0.005642630625516176,
0.009557925164699554,
-0.07621215283870697,
0.02883080765604973,
-0.0019563387613743544,
-0.04405229911208153,
0.015263368375599384,
0.04966352507472038,
0.02594144456088543,
-0.022738022729754448,
0.03377203643321991,
0.002155244117602706,
-0.044471047818660736,
-0.07407654076814651,
-0.021753964945673943,
-0.04576916620135307,
0.03634733706712723,
0.024182703346014023,
-0.00734379468485713,
0.007783480454236269,
-0.014457277953624725,
0.008914100006222725,
-0.05736849084496498,
0.013661656528711319,
-0.04706728830933571,
0.05330663546919823,
0.04861665517091751,
0.03061048686504364,
-0.032055165618658066,
0.003499163780361414,
0.03766639158129692,
-0.04216793552041054,
-0.06452908366918564,
0.017283828929066658,
0.06318908929824829,
0.01264619268476963,
0.008233634755015373,
-0.00530501501634717,
0.01113869994878769,
-0.05230163782835007,
0.05288788676261902,
-0.005182007793337107,
-0.017618825659155846,
0.05117101967334747,
-0.012593849562108517,
0.005621693097054958,
-0.0027218626346439123,
-0.019691629335284233,
0.004724001977592707,
0.020916467532515526,
0.012813691981136799,
-0.03423265740275383,
-0.03249485418200493,
0.012918379157781601,
-0.050668518990278244,
-0.031196733936667442,
0.010714717209339142,
-0.026067068800330162,
0.06071847677230835,
0.044429175555706024,
-0.04208418354392052,
-0.005061617586761713,
0.0030280721839517355,
-0.0199428778141737,
-0.010374484583735466,
0.056112244725227356,
-0.06163972243666649,
0.034525781869888306,
0.009960970841348171,
0.043507929891347885,
-0.06926093995571136,
0.06369158625602722,
-0.029291430488228798,
0.07202467322349548,
-0.010897919535636902,
0.074411541223526,
-0.042188871651887894,
-0.020403500646352768,
0.005956691689789295,
0.028516745194792747,
-0.0025268830358982086,
-0.033792972564697266,
-0.04648103937506676,
-0.03157360851764679,
-0.02759549953043461,
0.017723513767123222,
0.0043261912651360035,
0.04476417228579521,
-0.01672898605465889,
0.0408698134124279,
0.006940749939531088,
-0.03971825912594795,
-0.003051626728847623,
-0.029542678967118263,
-0.06607845425605774,
0.0049490793608129025,
-0.034169845283031464,
-0.032746102660894394,
-0.03605421259999275,
-0.05699161812663078,
-0.019042570143938065,
-0.021712088957428932,
-0.02162833884358406,
-0.043507929891347885,
0.06138847395777702,
0.007448481861501932,
0.03659858554601669,
0.0203406885266304,
-0.027888623997569084,
-0.04622979089617729,
-0.005103492643684149,
0.021094435825943947,
0.010918856598436832,
-0.036096084862947464,
0.0352795273065567,
-0.03239016607403755,
0.011369011364877224,
-0.025459885597229004,
0.05326475948095322,
-0.009725424461066723,
-0.003724240930750966,
-0.0913708359003067,
0.007631684187799692,
-0.004959547892212868,
0.003554124617949128,
-0.02818174660205841,
0.043424177914857864,
0.007040202617645264,
-0.05875035747885704,
0.013274314813315868,
-0.020236002281308174,
0.07730089873075485,
-0.0016043286304920912,
0.029249554499983788,
-0.01271947380155325,
0.0790596455335617,
0.04602041840553284,
0.005069469101727009,
-0.07889214158058167,
0.019649755209684372,
0.027197688817977905,
0.01970209926366806,
-0.042963556945323944,
0.015263368375599384,
-0.04811415821313858,
-0.0007491665310226381,
0.006050910335034132,
0.027155814692378044,
-0.014279310591518879,
0.0029992833733558655,
-0.017796793952584267,
-0.05648912116885185,
-0.035677339881658554,
0.008280743844807148,
-0.00976206548511982,
0.023952390998601913,
-0.0755421593785286,
-0.024873636662960052,
0.009720190428197384,
-0.007589809596538544,
0.04040919244289398,
-0.038294512778520584,
0.08927709609270096,
-0.06880031526088715,
0.03308109939098358,
-0.07219216972589493,
0.03463046997785568,
0.036137960851192474,
0.05841536074876785,
0.025376135483384132,
-0.020518656820058823,
0.035677339881658554,
0.020413970574736595,
-0.01381868775933981,
0.008950741030275822,
-0.048867903649806976,
0.061890970915555954,
0.07508153468370438,
0.023680204525589943,
-0.003012369154021144,
-0.011609790846705437,
0.07298779487609863,
0.03385578468441963,
-0.005857239011675119,
0.050207898020744324,
0.02991955168545246,
-0.022717084735631943,
0.019325224682688713,
-0.044889796525239944,
-0.004443964455276728,
-0.01948225498199463,
0.03370922431349754,
0.05925285816192627,
-0.017995700240135193,
-0.0015860084677115083,
0.04744416102766991,
0.0032557665836066008,
-0.017451327294111252,
-0.010897919535636902,
0.010322140529751778,
0.023638330399990082,
-0.022068025544285774,
0.022989271208643913,
-0.03362547233700752,
0.016624299809336662,
-0.017514139413833618,
0.00017976725939661264,
-0.002105517778545618,
0.0014446809655055404,
-0.0298776775598526,
-0.03243204206228256,
-0.020633812993764877,
-0.0755421593785286,
-0.019953347742557526,
0.035488903522491455,
0.0002168984356103465,
0.052804134786129,
0.017817731946706772,
0.0006791570922359824,
0.016027582809329033,
0.05870848521590233,
-0.014237435534596443,
0.052720386534929276,
0.004124668892472982,
0.040388256311416626,
0.01765023171901703,
-0.028998306021094322,
0.0906170904636383,
0.0005613841931335628,
0.04334042966365814,
-0.011442291550338268,
-0.052678510546684265,
-0.04468042403459549,
0.038378264755010605,
0.023659268394112587,
0.006537704728543758,
-0.014164154417812824,
0.0921245813369751,
0.05062664672732353,
-0.02625550702214241,
-0.019220538437366486,
0.021837713196873665,
-0.016760392114520073,
-0.05054289475083351,
0.054227881133556366,
0.009332848712801933,
-0.02122006006538868,
0.07449528574943542,
0.03632639721035957,
0.04313105344772339,
0.03446296975016594,
-0.039111074060201645,
0.0030280721839517355,
-0.01736757718026638,
0.012510099448263645,
-0.02652769163250923,
-0.04614604264497757,
-0.042733244597911835,
0.05699161812663078,
0.05225976184010506,
-0.005590287037193775,
0.024413013830780983,
-0.014677121303975582,
0.06427783519029617,
-0.05682411789894104,
0.0354679636657238,
-0.013808218762278557,
-0.0038106078281998634,
-0.023156769573688507,
-0.0017325702356174588,
0.08044151216745377,
-0.00010746777843451127,
-0.03303922712802887,
0.021345684304833412,
-0.05004039779305458,
-0.009981907904148102,
0.01663476787507534,
0.02259146049618721,
-0.02809799835085869,
0.06892593950033188,
-0.011515572667121887,
-0.038106076419353485,
-0.004271230660378933,
-0.022570522502064705,
-0.010918856598436832,
0.011902915313839912,
-0.0724852979183197,
-0.016153208911418915,
0.00429740222170949,
0.03473515436053276,
-0.03684983402490616,
0.01966022327542305,
-0.05766161531209946,
0.01837257295846939,
0.0036169367376714945,
-0.08186525106430054,
0.022905521094799042,
-0.021984275430440903,
0.024119891226291656,
-0.1075345128774643,
0.025166761130094528,
0.05766161531209946,
-0.007851527072489262,
0.024643326178193092,
-0.013661656528711319,
-0.03607514873147011,
0.04463854804635048,
0.012112288735806942,
-0.02401520311832428,
-0.03469328209757805,
-0.031280484050512314,
0.04468042403459549,
-0.046941664069890976,
-0.07114530354738235,
-0.02945892885327339,
0.07152217626571655,
-0.012729942798614502,
-0.06113722175359726,
0.0076421527191996574,
0.017493201419711113,
-0.053181007504463196,
-0.006909343879669905,
-0.030442986637353897,
0.03959263488650322,
0.02259146049618721,
0.0038812714628875256,
-0.039069198071956635,
0.007485122419893742,
-0.01069901417940855,
0.019283350557088852,
-0.020466312766075134,
0.015074932016432285,
-0.016624299809336662,
0.031636420637369156,
-0.033290475606918335,
-0.0034127971157431602,
0.0647803321480751,
-0.017262890934944153,
-0.031406108289957047,
0.07730089873075485,
-0.01947178691625595,
0.005789192393422127,
-0.03280891478061676,
-0.04468042403459549,
0.039843883365392685,
0.02277989685535431,
0.04187481105327606,
-0.019995221868157387,
0.02818174660205841,
-0.030819861218333244,
0.03333234786987305,
0.024685200303792953,
0.02130381017923355,
0.04957977682352066,
0.06586907804012299,
0.019053038209676743,
0.005401850678026676,
-0.021879589185118675,
0.03643108531832695,
0.022193649783730507,
-0.05108726769685745,
0.012342600151896477,
0.05263663828372955,
0.006652860436588526,
0.007464184891432524,
-0.04505729675292969,
0.0223611481487751,
0.0206233449280262,
-0.04719291254878044,
0.030547674745321274,
-0.0006327021983452141,
0.007406607270240784,
0.041456062346696854,
0.016666173934936523,
0.04409417510032654,
0.04853290691971779,
0.03056861087679863,
0.05891785770654678,
-0.019785847514867783,
-0.021879589185118675,
-0.02652769163250923,
0.03111298382282257,
-0.011452760547399521,
-0.05200851336121559,
-0.014289778657257557,
0.03419078141450882,
0.020591938868165016,
0.02837018482387066,
0.010897919535636902,
-0.03243204206228256,
-0.0505010224878788,
-0.04756978526711464,
-0.013399939052760601,
0.027888623997569084,
0.04141418635845184,
0.07474653422832489,
-0.05200851336121559,
0.02208896167576313,
0.026108944788575172,
0.011023543775081635,
0.0786408931016922,
-0.04920290410518646,
-0.059420354664325714,
-0.0406813770532608,
-0.03927857056260109,
-0.010541983880102634,
-0.0012994277058169246,
0.0217749010771513,
0.01301259733736515,
0.0296892412006855,
0.008228400722146034,
-0.005260522942990065,
0.0319923534989357,
-0.011840102262794971,
-0.004300019703805447,
-0.03486077859997749,
-0.015922896564006805,
-0.01778632588684559,
-0.03775013983249664,
0.020152252167463303,
-0.06716719269752502,
0.004990953952074051,
0.0022062789648771286,
0.036682333797216415,
0.04966352507472038,
0.008631445467472076,
-0.0056478651240468025,
-0.031406108289957047,
0.04063950479030609,
-0.034211721271276474,
-0.0068779378198087215,
0.013284783810377121,
-0.06381721049547195,
0.04459667205810547,
-0.0034651404712349176,
0.0036483427975326777,
-0.04141418635845184,
-0.010191282257437706,
0.016708049923181534,
0.05008227378129959,
-0.026339255273342133,
-0.04455479979515076,
0.003742561209946871,
0.03473515436053276,
0.024078015238046646,
0.003970255609601736,
0.009887689724564552,
0.0016527464613318443,
-0.08274462819099426,
-0.015483210794627666,
-0.04622979089617729,
0.023198645561933517,
0.03167829290032387,
0.030317362397909164,
-0.030945485457777977,
-0.07520715892314911,
0.00481036864221096,
-0.011170106008648872,
0.01143182348459959,
-0.05720099061727524,
-0.01850866712629795,
0.005600756034255028,
-0.04648103937506676,
0.03404422104358673,
-0.009840580634772778,
-0.01645680144429207,
0.03213891759514809,
0.034902654588222504,
0.015441336669027805,
-0.04141418635845184,
0.028349246829748154,
-0.02991955168545246,
-0.08144650608301163,
0.016718517988920212,
0.058582860976457596,
-0.03536327928304672,
-0.0223611481487751,
0.0670834481716156,
-0.0027061596047133207,
-0.029123930260539055,
0.020885061472654343,
-0.052217889577150345,
0.02717675268650055,
-0.02960549108684063,
-0.022612398490309715,
-0.034525781869888306,
-0.024182703346014023,
0.018718039616942406,
-0.012855567038059235,
-0.018634291365742683,
0.00987198669463396,
-0.005600756034255028,
0.015598366968333721,
-0.010578623972833157,
-0.02455957606434822,
0.011023543775081635,
0.07277841866016388,
0.003276703879237175,
-0.017514139413833618,
0.02282177098095417,
0.002013916615396738,
0.04329855367541313,
0.050291646271944046,
0.06059285253286362,
-0.042314495891332626,
-0.021984275430440903,
0.015912428498268127,
0.013483689166605473,
-0.03871326148509979,
0.01539946161210537,
-0.025124887004494667,
-0.041853874921798706,
-0.018131792545318604,
0.0047449395060539246,
0.015263368375599384,
-0.05297163501381874,
-0.044429175555706024,
0.003925763536244631,
0.008898396976292133,
-0.018121324479579926,
-0.07072655856609344,
0.027888623997569084,
0.02204708755016327,
0.021481778472661972,
-0.04421979933977127,
0.007092546205967665,
0.037603579461574554,
-0.06272846460342407,
-0.06348221004009247,
0.04202137142419815,
-0.009353785775601864,
0.002169638639315963,
-0.04794665798544884,
0.039655447006225586,
0.02945892885327339,
-0.0034442031756043434,
-0.057619739323854446,
-0.015263368375599384,
-0.013274314813315868,
0.03276703879237175,
-0.06574345380067825,
0.054227881133556366,
0.029668303206562996,
-0.0025753008667379618,
-0.04170731082558632,
0.010212219320237637,
-0.010568154975771904,
-0.06503158062696457,
0.023952390998601913,
-0.02529238536953926,
0.029584553092718124,
-0.004786814097315073,
-0.03666139766573906,
-0.023763954639434814,
0.004624549299478531,
0.02328239381313324,
-0.0045434171333909035,
-0.01896928995847702,
-0.04622979089617729,
-0.021366622298955917,
0.01227978803217411,
-0.01731523498892784,
-0.03800139203667641,
-0.025271447375416756,
0.04606229066848755,
-0.07918526977300644,
0.018068980425596237,
0.004373300354927778,
-0.07143842428922653,
-0.027051128447055817,
-0.025145823135972023,
-0.03530046343803406,
0.0751652866601944,
0.016708049923181534,
0.06071847677230835,
0.01837257295846939,
-0.00047632597852498293,
0.006270752754062414,
0.015650710090994835,
0.00432880874723196,
0.06352408975362778,
-0.002619792940095067,
0.021366622298955917,
-0.06059285253286362,
0.006485361140221357,
-0.0052422028966248035,
0.005553646944463253,
0.010897919535636902,
0.019189132377505302,
-0.015064463019371033,
-0.030045175924897194,
0.04417792335152626,
-0.007579340599477291,
0.043507929891347885,
-0.0264020673930645,
0.027009252458810806,
0.008877459913492203,
-0.03515390306711197,
-0.019764911383390427,
-0.0352795273065567,
-0.05715911462903023,
-0.04421979933977127,
-0.02071756310760975,
-0.03213891759514809,
0.03643108531832695,
-0.009081599302589893,
0.05058477073907852,
0.029521740972995758,
0.08961209654808044
]
|
31,104 | networkx.algorithms.cycles | simple_cycles | Find simple cycles (elementary circuits) of a graph.
A `simple cycle`, or `elementary circuit`, is a closed path where
no node appears twice. In a directed graph, two simple cycles are distinct
if they are not cyclic permutations of each other. In an undirected graph,
two simple cycles are distinct if they are not cyclic permutations of each
other nor of the other's reversal.
Optionally, the cycles are bounded in length. In the unbounded case, we use
a nonrecursive, iterator/generator version of Johnson's algorithm [1]_. In
the bounded case, we use a version of the algorithm of Gupta and
Suzumura[2]_. There may be better algorithms for some cases [3]_ [4]_ [5]_.
The algorithms of Johnson, and Gupta and Suzumura, are enhanced by some
well-known preprocessing techniques. When G is directed, we restrict our
attention to strongly connected components of G, generate all simple cycles
containing a certain node, remove that node, and further decompose the
remainder into strongly connected components. When G is undirected, we
restrict our attention to biconnected components, generate all simple cycles
containing a particular edge, remove that edge, and further decompose the
remainder into biconnected components.
Note that multigraphs are supported by this function -- and in undirected
multigraphs, a pair of parallel edges is considered a cycle of length 2.
Likewise, self-loops are considered to be cycles of length 1. We define
cycles as sequences of nodes; so the presence of loops and parallel edges
does not change the number of simple cycles in a graph.
Parameters
----------
G : NetworkX DiGraph
A directed graph
length_bound : int or None, optional (default=None)
If length_bound is an int, generate all simple cycles of G with length at
most length_bound. Otherwise, generate all simple cycles of G.
Yields
------
list of nodes
Each cycle is represented by a list of nodes along the cycle.
Examples
--------
>>> edges = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)]
>>> G = nx.DiGraph(edges)
>>> sorted(nx.simple_cycles(G))
[[0], [0, 1, 2], [0, 2], [1, 2], [2]]
To filter the cycles so that they don't include certain nodes or edges,
copy your graph and eliminate those nodes or edges before calling.
For example, to exclude self-loops from the above example:
>>> H = G.copy()
>>> H.remove_edges_from(nx.selfloop_edges(G))
>>> sorted(nx.simple_cycles(H))
[[0, 1, 2], [0, 2], [1, 2]]
Notes
-----
When length_bound is None, the time complexity is $O((n+e)(c+1))$ for $n$
nodes, $e$ edges and $c$ simple circuits. Otherwise, when length_bound > 1,
the time complexity is $O((c+n)(k-1)d^k)$ where $d$ is the average degree of
the nodes of G and $k$ = length_bound.
Raises
------
ValueError
when length_bound < 0.
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
.. [2] Finding All Bounded-Length Simple Cycles in a Directed Graph
A. Gupta and T. Suzumura https://arxiv.org/abs/2105.10094
.. [3] Enumerating the cycles of a digraph: a new preprocessing strategy.
G. Loizou and P. Thanish, Information Sciences, v. 27, 163-182, 1982.
.. [4] A search strategy for the elementary cycles of a directed graph.
J.L. Szwarcfiter and P.E. Lauer, BIT NUMERICAL MATHEMATICS,
v. 16, no. 2, 192-204, 1976.
.. [5] Optimal Listing of Cycles and st-Paths in Undirected Graphs
R. Ferreira and R. Grossi and A. Marino and N. Pisanti and R. Rizzi and
G. Sacomoto https://arxiv.org/abs/1205.2766
See Also
--------
cycle_basis
chordless_cycles
| 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, length_bound=None, *, 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
]
|
31,106 | networkx.algorithms.similarity | simrank_similarity | Returns the SimRank similarity of nodes in the graph ``G``.
SimRank is a similarity metric that says "two objects are considered
to be similar if they are referenced by similar objects." [1]_.
The pseudo-code definition from the paper is::
def simrank(G, u, v):
in_neighbors_u = G.predecessors(u)
in_neighbors_v = G.predecessors(v)
scale = C / (len(in_neighbors_u) * len(in_neighbors_v))
return scale * sum(
simrank(G, w, x) for w, x in product(in_neighbors_u, in_neighbors_v)
)
where ``G`` is the graph, ``u`` is the source, ``v`` is the target,
and ``C`` is a float decay or importance factor between 0 and 1.
The SimRank algorithm for determining node similarity is defined in
[2]_.
Parameters
----------
G : NetworkX graph
A NetworkX graph
source : node
If this is specified, the returned dictionary maps each node
``v`` in the graph to the similarity between ``source`` and
``v``.
target : node
If both ``source`` and ``target`` are specified, the similarity
value between ``source`` and ``target`` is returned. If
``target`` is specified but ``source`` is not, this argument is
ignored.
importance_factor : float
The relative importance of indirect neighbors with respect to
direct neighbors.
max_iterations : integer
Maximum number of iterations.
tolerance : float
Error tolerance used to check convergence. When an iteration of
the algorithm finds that no similarity value changes more than
this amount, the algorithm halts.
Returns
-------
similarity : dictionary or float
If ``source`` and ``target`` are both ``None``, this returns a
dictionary of dictionaries, where keys are node pairs and value
are similarity of the pair of nodes.
If ``source`` is not ``None`` but ``target`` is, this returns a
dictionary mapping node to the similarity of ``source`` and that
node.
If neither ``source`` nor ``target`` is ``None``, this returns
the similarity value for the given pair of nodes.
Raises
------
ExceededMaxIterations
If the algorithm does not converge within ``max_iterations``.
NodeNotFound
If either ``source`` or ``target`` is not in `G`.
Examples
--------
>>> G = nx.cycle_graph(2)
>>> nx.simrank_similarity(G)
{0: {0: 1.0, 1: 0.0}, 1: {0: 0.0, 1: 1.0}}
>>> nx.simrank_similarity(G, source=0)
{0: 1.0, 1: 0.0}
>>> nx.simrank_similarity(G, source=0, target=0)
1.0
The result of this function can be converted to a numpy array
representing the SimRank matrix by using the node order of the
graph to determine which row and column represent each node.
Other ordering of nodes is also possible.
>>> import numpy as np
>>> sim = nx.simrank_similarity(G)
>>> np.array([[sim[u][v] for v in G] for u in G])
array([[1., 0.],
[0., 1.]])
>>> sim_1d = nx.simrank_similarity(G, source=0)
>>> np.array([sim[0][v] for v in G])
array([1., 0.])
References
----------
.. [1] https://en.wikipedia.org/wiki/SimRank
.. [2] G. Jeh and J. Widom.
"SimRank: a measure of structural-context similarity",
In KDD'02: Proceedings of the Eighth ACM SIGKDD
International Conference on Knowledge Discovery and Data Mining,
pp. 538--543. ACM Press, 2002.
| 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=None, target=None, importance_factor=0.9, max_iterations=1000, tolerance=0.0001, *, 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
]
|
31,108 | networkx.algorithms.shortest_paths.weighted | single_source_bellman_ford | Compute shortest paths and lengths in a weighted graph G.
Uses Bellman-Ford algorithm for shortest paths.
Parameters
----------
G : NetworkX graph
source : node label
Starting node for path
target : node label, optional
Ending 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
-------
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.
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> length, path = nx.single_source_bellman_ford(G, 0)
>>> length[4]
4
>>> for node in [0, 1, 2, 3, 4]:
... print(f"{node}: {length[node]}")
0: 0
1: 1
2: 2
3: 3
4: 4
>>> path[4]
[0, 1, 2, 3, 4]
>>> length, path = nx.single_source_bellman_ford(G, 0, 1)
>>> length
1
>>> path
[0, 1]
Notes
-----
Edge weight attributes must be numerical.
Distances are calculated as sums of weighted edges traversed.
See Also
--------
single_source_dijkstra
single_source_bellman_ford_path
single_source_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, source, target=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
]
|
31,109 | networkx.algorithms.shortest_paths.weighted | single_source_bellman_ford_path | Compute shortest path between source and all other reachable
nodes for a weighted graph.
Parameters
----------
G : NetworkX graph
source : node
Starting node for path.
weight : string or function (default="weight")
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
-------
paths : dictionary
Dictionary of shortest path lengths keyed by target.
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> path = nx.single_source_bellman_ford_path(G, 0)
>>> path[4]
[0, 1, 2, 3, 4]
Notes
-----
Edge weight attributes must be numerical.
Distances are calculated as sums of weighted edges traversed.
See Also
--------
single_source_dijkstra, single_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, source, 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
]
|
31,110 | networkx.algorithms.shortest_paths.weighted | single_source_bellman_ford_path_length | Compute the shortest path length between source and all other
reachable nodes for a weighted graph.
Parameters
----------
G : NetworkX graph
source : node label
Starting node for path
weight : string or function (default="weight")
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
-------
length : dictionary
Dictionary of shortest path length keyed by target
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> length = nx.single_source_bellman_ford_path_length(G, 0)
>>> length[4]
4
>>> for node in [0, 1, 2, 3, 4]:
... print(f"{node}: {length[node]}")
0: 0
1: 1
2: 2
3: 3
4: 4
Notes
-----
Edge weight attributes must be numerical.
Distances are calculated as sums of weighted edges traversed.
See Also
--------
single_source_dijkstra, single_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, 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
]
|
31,111 | networkx.algorithms.shortest_paths.weighted | single_source_dijkstra | Find shortest weighted paths and lengths from a source node.
Compute the shortest path length between source and all other
reachable nodes for a weighted graph.
Uses Dijkstra's algorithm to compute shortest paths and lengths
between a source and all other reachable nodes in a weighted graph.
Parameters
----------
G : NetworkX graph
source : node label
Starting node for path
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, paths and lengths to all nodes are computed.
The return value is a tuple of two dictionaries keyed by target nodes.
The first dictionary stores distance to each target node.
The second stores the path to each target node.
If target is not None, returns a tuple (distance, path), where
distance is the distance from source to target and path is a list
representing the path from source to target.
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> length, path = nx.single_source_dijkstra(G, 0)
>>> length[4]
4
>>> for node in [0, 1, 2, 3, 4]:
... print(f"{node}: {length[node]}")
0: 0
1: 1
2: 2
3: 3
4: 4
>>> path[4]
[0, 1, 2, 3, 4]
>>> length, path = nx.single_source_dijkstra(G, 0, 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).
See Also
--------
single_source_dijkstra_path
single_source_dijkstra_path_length
single_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, source, target=None, cutoff=None, 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
]
|
31,112 | networkx.algorithms.shortest_paths.weighted | single_source_dijkstra_path | Find shortest weighted paths in G from a source node.
Compute shortest path between source and all other reachable
nodes for a weighted graph.
Parameters
----------
G : NetworkX graph
source : node
Starting 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
-------
paths : dictionary
Dictionary of shortest path lengths keyed by target.
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> path = nx.single_source_dijkstra_path(G, 0)
>>> path[4]
[0, 1, 2, 3, 4]
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.
See Also
--------
single_source_dijkstra, single_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, source, cutoff=None, 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
]
|
31,113 | networkx.algorithms.shortest_paths.weighted | single_source_dijkstra_path_length | Find shortest weighted path lengths in G from a source node.
Compute the shortest path length between source and all other
reachable nodes for a weighted graph.
Parameters
----------
G : NetworkX graph
source : node label
Starting 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
-------
length : dict
Dict keyed by node to shortest path length from source.
Raises
------
NodeNotFound
If `source` is not in `G`.
Examples
--------
>>> G = nx.path_graph(5)
>>> length = nx.single_source_dijkstra_path_length(G, 0)
>>> length[4]
4
>>> for node in [0, 1, 2, 3, 4]:
... print(f"{node}: {length[node]}")
0: 0
1: 1
2: 2
3: 3
4: 4
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.
See Also
--------
single_source_dijkstra, single_source_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, source, cutoff=None, 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
]
|
31,123 | networkx.generators.geometric | soft_random_geometric_graph | Returns a soft random geometric graph in the unit cube.
The soft random geometric graph [1] model places `n` nodes uniformly at
random in the unit cube in dimension `dim`. Two nodes of distance, `dist`,
computed by the `p`-Minkowski distance metric are joined by an edge with
probability `p_dist` if the computed distance metric value of the nodes
is at most `radius`, otherwise they are not joined.
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
dim : int, optional
Dimension of graph
pos : dict, optional
A dictionary keyed by node with node positions as values.
p : float, optional
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.
p_dist : function, optional
A probability density function computing the probability of
connecting two nodes that are of distance, dist, computed by the
Minkowski distance metric. The probability density function, `p_dist`,
must be any function that takes the metric value as input
and outputs a single probability value between 0-1. The scipy.stats
package has many probability distribution functions implemented and
tools for custom probability distribution definitions [2], and passing
the .pdf method of scipy.stats distributions can be used here. If the
probability function, `p_dist`, is not supplied, the default function
is an exponential distribution with rate parameter :math:`\lambda=1`.
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.
Returns
-------
Graph
A soft random geometric 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.
Examples
--------
Default Graph:
G = nx.soft_random_geometric_graph(50, 0.2)
Custom Graph:
Create a soft random geometric graph on 100 uniformly distributed nodes
where nodes are joined by an edge with probability computed from an
exponential distribution with rate parameter :math:`\lambda=1` if 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
The scipy.stats package can be used to define the probability distribution
with the .pdf method used as `p_dist`.
::
>>> import random
>>> import math
>>> n = 100
>>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)}
>>> p_dist = lambda dist: math.exp(-dist)
>>> G = nx.soft_random_geometric_graph(n, 0.2, pos=pos, p_dist=p_dist)
References
----------
.. [1] Penrose, Mathew D. "Connectivity of soft random geometric graphs."
The Annals of Applied Probability 26.2 (2016): 986-1028.
.. [2] scipy.stats -
https://docs.scipy.org/doc/scipy/reference/tutorial/stats.html
| 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, radius, dim=2, pos=None, p=2, p_dist=None, seed=None, *, 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
]
|
31,129 | networkx.drawing.layout | spectral_layout | 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).
| 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, weight='weight', scale=1, center=None, dim=2) | [
0.07145671546459198,
-0.01197690051048994,
0.003237521043047309,
0.003196570323780179,
0.011032624170184135,
0.02933039888739586,
-0.0008244356722570956,
-0.02162201516330242,
0.03224031254649162,
0.025206413120031357,
-0.040314845740795135,
-0.044477373361587524,
0.023973071947693825,
0.016534483060240746,
-0.016746463254094124,
0.02466682717204094,
-0.002958092140033841,
-0.05873788148164749,
-0.047368016093969345,
-0.020851176232099533,
0.0030231315176934004,
-0.08132344484329224,
0.04405341297388077,
0.07118692249059677,
-0.02166055701673031,
-0.0000461825511592906,
-0.00693272752687335,
-0.00012209959095343947,
0.006590667646378279,
0.012323778122663498,
0.03655700758099556,
-0.03189343586564064,
-0.0030279492493718863,
0.013759464025497437,
0.013171699829399586,
0.04694405570626259,
0.044592998921871185,
-0.025264225900173187,
-0.02150638960301876,
-0.019531115889549255,
0.048601359128952026,
0.009225971065461636,
0.046134673058986664,
-0.02784653566777706,
0.048138853162527084,
0.08294220268726349,
0.014915721490979195,
-0.025649646297097206,
-0.03827212378382683,
0.03383980318903923,
0.0019427535589784384,
-0.024127239361405373,
-0.03989088535308838,
-0.031585101038217545,
-0.0315658301115036,
-0.021602744236588478,
0.02304806560277939,
0.03050592727959156,
0.032972611486911774,
-0.07916510105133057,
0.031315308064222336,
-0.05657953396439552,
-0.02050429955124855,
0.010685746558010578,
-0.08209428191184998,
-0.01706443354487419,
0.01777745969593525,
-0.01455920934677124,
0.024705369025468826,
-0.05449827015399933,
0.013094616122543812,
-0.020195964723825455,
0.0007033899892121553,
-0.023472027853131294,
0.03655700758099556,
0.005718656815588474,
0.021159512922167778,
0.021043887361884117,
-0.034591369330883026,
0.012005806900560856,
-0.001008111983537674,
0.010656840167939663,
0.0014790460700169206,
0.03561273217201233,
0.0364413820207119,
0.00803117174655199,
0.061204563826322556,
0.04332111403346062,
0.02189180813729763,
-0.01739203929901123,
0.0034880435559898615,
-0.0043166945688426495,
0.05195450410246849,
0.032876256853342056,
0.02250847965478897,
0.020485028624534607,
0.008098619990050793,
-0.04432320594787598,
0.07380776852369308,
0.0008918840321712196,
-0.01594671793282032,
0.0067496532574296,
0.011601117439568043,
0.001368238008581102,
-0.03859972953796387,
0.004070989787578583,
-0.028424663469195366,
0.005472952034324408,
0.009914908558130264,
0.024570472538471222,
0.03638356924057007,
0.05657953396439552,
-0.01655375398695469,
0.015956353396177292,
-0.008296147920191288,
0.046019047498703,
0.04906386137008667,
0.043590907007455826,
-0.010483401827514172,
-0.013855819590389729,
-0.04517112672328949,
0.003673526458442211,
-0.06617647409439087,
-0.010502672754228115,
-0.002343830419704318,
-0.017478760331869125,
0.018027981743216515,
-0.019588928669691086,
0.006634027697145939,
0.011870910413563251,
0.015956353396177292,
-0.011736013926565647,
0.0002904193534050137,
0.00830578338354826,
0.020928261801600456,
-0.032702818512916565,
-0.010011263191699982,
-0.017131881788372993,
0.004911685362458229,
0.04239610955119133,
-0.019348042085766792,
-0.007356688380241394,
-0.020215235650539398,
0.06475041806697845,
-0.013219877146184444,
0.026304857805371284,
0.05079824849963188,
-0.03615231812000275,
0.023182963952422142,
0.0281741414219141,
0.012188881635665894,
-0.04023776203393936,
0.09774230420589447,
0.009095892310142517,
0.0342252217233181,
-0.06016393378376961,
0.007125436794012785,
0.01927095837891102,
-0.004767153412103653,
0.001257430063560605,
-0.04162526875734329,
-0.053419098258018494,
-0.014318321831524372,
-0.0002953876683022827,
-0.05646390840411186,
-0.003500087885186076,
0.035150229930877686,
0.04806176945567131,
-0.03100697323679924,
-0.01699698530137539,
-0.03077572025358677,
-0.04255027696490288,
-0.07515674084424973,
-0.031700726598501205,
0.010078711435198784,
0.040584638714790344,
0.03495752066373825,
0.003054447006434202,
-0.006793012842535973,
-0.014954264275729656,
0.019482938572764397,
-0.006817101500928402,
0.04370653256773949,
0.03168145567178726,
-0.02800070308148861,
0.07430881261825562,
0.016197239980101585,
-0.012853729538619518,
-0.02227722853422165,
0.010271420702338219,
-0.023587653413414955,
-0.003912004642188549,
-0.014096706174314022,
0.050759706646203995,
0.0010087141999974847,
0.06062643602490425,
0.019039707258343697,
0.004651527851819992,
-0.0870276466012001,
0.03632575646042824,
0.07415464520454407,
-0.05149200186133385,
0.0027123873587697744,
-0.022045977413654327,
0.0065232194028794765,
-0.004415458533912897,
0.0001418974861735478,
-0.008064895868301392,
-0.0077710142359137535,
0.03322313353419304,
-0.014385771006345749,
-0.006306421011686325,
0.051530543714761734,
-0.05750454217195511,
0.02499443292617798,
-0.0029171414207667112,
-0.04035338759422302,
0.04239610955119133,
-0.004564808215945959,
-0.061859775334596634,
-0.033589281141757965,
-0.005222429987043142,
-0.022643376141786575,
0.023915259167551994,
-0.043205488473176956,
-0.012140704318881035,
0.05854517221450806,
-0.05438264459371567,
0.00199333974160254,
0.008989902213215828,
0.04902531951665878,
-0.04282006993889809,
0.0243392214179039,
-0.038638271391391754,
-0.028077786788344383,
-0.024300679564476013,
-0.037250764667987823,
0.09119017422199249,
0.04794614389538765,
0.03193197771906853,
0.017710011452436447,
-0.055192023515701294,
-0.06320874392986298,
0.06143581494688988,
-0.02144857682287693,
-0.0065617612563073635,
0.03198979049921036,
-0.04324403032660484,
-0.007457860745489597,
-0.010849549435079098,
-0.0758119523525238,
-0.021814724430441856,
0.03206687420606613,
0.011148249730467796,
0.02828976698219776,
0.001095433603040874,
-0.0666775181889534,
0.05877642333507538,
-0.008782739751040936,
-0.07018483430147171,
-0.04077734798192978,
-0.010232878848910332,
-0.017266778275370598,
0.006537672597914934,
0.05916184186935425,
0.039139315485954285,
0.017045162618160248,
0.030756449326872826,
-0.008035989478230476,
0.04239610955119133,
-0.007159160915762186,
0.03846483305096626,
0.021988164633512497,
0.00819979328662157,
0.061705607920885086,
0.04000651091337204,
-0.01933840662240982,
0.02383817546069622,
0.04767635092139244,
0.048370104283094406,
-0.03489970415830612,
-0.011148249730467796,
-0.0191071555018425,
0.03551637753844261,
-0.002314923796802759,
0.042319025844335556,
-0.010011263191699982,
-0.03274136036634445,
0.04759926721453667,
-0.03977525979280472,
0.09697146713733673,
-0.03588252514600754,
-0.014173789881169796,
-0.006441317964345217,
-0.012420132756233215,
0.02260483428835869,
-0.019087884575128555,
0.0023052883334457874,
0.012661019340157509,
-0.02283608540892601,
0.06236082315444946,
-0.061320189386606216,
0.09974648058414459,
0.03366636484861374,
0.05916184186935425,
0.05006594955921173,
-0.022874627262353897,
-0.02879081293940544,
0.00018804239516612142,
-0.01267065480351448,
-0.09527561813592911,
0.022527750581502914,
-0.03462991118431091,
0.0070290821604430676,
-0.04890969395637512,
0.03628721460700035,
0.0225662924349308,
-0.03513095900416374,
0.029927799478173256,
0.040815889835357666,
0.03179708123207092,
0.0442461222410202,
-0.07145671546459198,
0.046019047498703,
0.001412802143022418,
0.020253777503967285,
0.020311590284109116,
0.0413169339299202,
0.07615882903337479,
-0.010984445922076702,
-0.022315770387649536,
0.0054392279125750065,
-0.02828976698219776,
0.016736827790737152,
-0.057196203619241714,
-0.025977252051234245,
0.032876256853342056,
-0.018423035740852356,
-0.03322313353419304,
-0.06105039641261101,
-0.004114349838346243,
-0.05877642333507538,
-0.025861626490950584,
-0.01016543060541153,
0.045094043016433716,
0.015657654032111168,
0.017295684665441513,
-0.04655863717198372,
-0.0590076744556427,
-0.027692368254065514,
0.038927335292100906,
0.03121895343065262,
-0.07665987312793732,
0.020523570477962494,
-0.012786281295120716,
0.03740493208169937,
-0.006923092063516378,
-0.06567542999982834,
-0.013200606219470501,
0.046481553465127945,
0.006614756304770708,
0.027923619374632835,
-0.03195124864578247,
-0.04050755500793457,
0.024146510288119316,
0.019299864768981934,
-0.007886639796197414,
0.006426864769309759,
0.0873359814286232,
-0.014347228221595287,
0.029696546494960785,
-0.09080475568771362,
-0.10144232213497162,
0.056695159524679184,
-0.005511494353413582,
0.03266427293419838,
-0.015484214760363102,
-0.000011272757546976209,
-0.04532529413700104,
-0.025919439271092415,
0.010483401827514172,
0.016255052760243416,
0.059084758162498474,
0.012005806900560856,
0.044862791895866394,
-0.02027304843068123,
0.06721710413694382,
0.05923892557621002,
-0.05923892557621002,
-0.021930349990725517,
-0.05199304595589638,
-0.0007931204163469374,
0.03933202475309372,
0.021930349990725517,
0.0063786874525249004,
0.03958255052566528,
-0.0184423066675663,
0.036749716848134995,
-0.03771326690912247,
0.009052532725036144,
-0.03823358193039894,
-0.048986777663230896,
-0.07064733654260635,
0.006691840477287769,
-0.030197592452168465,
-0.049487821757793427,
-0.018471213057637215,
0.005415139254182577,
0.02383817546069622,
0.0365762785077095,
0.02044648677110672,
0.022296499460935593,
0.0195503868162632,
-0.0637483298778534,
0.03800233080983162,
-0.002787062432616949,
-0.02171836979687214,
0.07118692249059677,
0.02884862571954727,
-0.010849549435079098,
0.007978176698088646,
-0.024185052141547203,
0.08533180505037308,
0.003466363763436675,
0.060973312705755234,
0.016197239980101585,
-0.03950546681880951,
-0.03216322883963585,
-0.02855955995619297,
0.04351382330060005,
-0.018875904381275177,
0.02884862571954727,
0.032413750886917114,
0.02245066687464714,
-0.030544469133019447,
-0.009924544021487236,
0.020292319357395172,
0.013056074269115925,
-0.040584638714790344,
-0.02672882005572319,
0.045479461550712585,
-0.0036566643975675106,
-0.03582471236586571,
-0.028713727369904518,
0.007038717623800039,
-0.009760740213096142,
-0.03062155283987522,
0.008864641189575195,
0.02162201516330242,
0.010541214607656002,
0.05384305864572525,
-0.07739216834306717,
0.0646347925066948,
-0.014829002320766449,
-0.048370104283094406,
0.009259695187211037,
0.02372254990041256,
-0.032818444073200226,
-0.06243790686130524,
0.0039674085564911366,
0.012439403682947159,
-0.022412125021219254,
-0.05260971561074257,
-0.03339657187461853,
0.024589743465185165,
0.02310587838292122,
0.002789471298456192,
0.0017946079606190324,
-0.05954726040363312,
-0.030024154111742973,
0.04177943989634514,
-0.016312865540385246,
-0.004576852545142174,
-0.04089297354221344,
0.02800070308148861,
-0.008922453969717026,
-0.05950871855020523,
-0.007992629893124104,
-0.06216811388731003,
-0.013364410027861595,
-0.026882987469434738,
0.006296785548329353,
0.004841828253120184,
0.027807993814349174,
0.017738917842507362,
0.028251225128769875,
0.029966341331601143,
0.033916886895895004,
-0.01655375398695469,
-0.03873462602496147,
-0.02967727556824684,
0.03854191675782204,
0.03495752066373825,
0.05006594955921173,
0.030255405232310295,
0.010965174995362759,
0.0029845896642655134,
-0.04783051833510399,
0.007366323843598366,
0.02545693702995777,
0.004323921166360378,
-0.07746925204992294,
0.05496077239513397,
-0.002519677858799696,
0.017825637012720108,
-0.015378224663436413,
-0.003815649775788188,
0.0445544570684433,
0.06860461086034775,
0.07600466161966324,
-0.006465406622737646,
0.033859074115753174,
-0.0032832894939929247,
-0.036807529628276825,
-0.00922115333378315,
0.0604722686111927,
-0.04174089804291725,
0.04528675228357315,
0.03727003559470177,
-0.01979127526283264,
0.015330047346651554,
0.009991992264986038,
-0.026035064831376076,
0.048986777663230896,
-0.025148600339889526,
0.019463667646050453,
0.019463667646050453,
-0.06972232460975647,
-0.00794927030801773,
0.0010430406546220183,
-0.021198054775595665,
0.04582633823156357,
-0.01028105616569519,
0.05977851524949074,
0.035747628659009933,
0.014472490176558495,
0.046134673058986664,
-0.0010851958068087697,
-0.0023317860905081034,
-0.03678825870156288,
-0.014607386663556099,
0.017989439889788628,
-0.026536110788583755,
0.007245880551636219,
0.06910565495491028,
0.03399397060275078,
0.009500582702457905,
-0.03179708123207092,
-0.0379059761762619,
-0.08039844036102295,
0.0054777697660028934,
0.03355073928833008,
-0.025148600339889526,
-0.02643975429236889,
0.031527288258075714,
0.014809731394052505,
-0.02156420238316059,
-0.02649756893515587,
-0.014212331734597683,
-0.013740193098783493,
-0.02879081293940544,
-0.05534619465470314,
-0.03904296085238457,
-0.016303230077028275,
0.04123985022306442,
-0.04594196379184723,
0.009119980968534946,
-0.05338055640459061,
-0.0003562116180546582,
-0.010897726751863956,
0.015763644129037857,
0.005781287793070078,
0.05091387405991554,
0.004422685131430626,
0.03561273217201233,
-0.00359885161742568,
0.018211055546998978,
0.008276876993477345,
0.018124336376786232,
-0.06721710413694382,
0.021101700142025948,
-0.048138853162527084,
0.015956353396177292,
0.06320874392986298,
-0.005453681107610464,
0.04671280458569527,
-0.01923241652548313,
0.008565940894186497,
-0.04852427542209625,
-0.017921991646289825,
-0.009784828871488571,
-0.04451591521501541,
0.06694731116294861,
0.002693116432055831,
-0.029850713908672333,
-0.04532529413700104,
0.012622477486729622,
0.023915259167551994,
0.02884862571954727,
0.013518577441573143,
-0.08579430729150772,
0.022257957607507706,
0.009018808603286743,
0.0006238973001018167,
-0.039197128266096115,
-0.051145125180482864,
0.04563362896442413,
0.012150339782238007,
0.018124336376786232,
-0.04289715364575386,
-0.009168158285319805,
-0.004870734643191099,
-0.018211055546998978,
-0.02566891722381115,
0.022489208728075027,
-0.046134673058986664,
0.01833631657063961,
0.05230138078331947,
0.033647093921899796,
0.003538629738613963,
0.01197690051048994,
-0.020851176232099533,
0.00633532740175724,
-0.032529376447200775,
-0.023067336529493332,
0.08340470492839813,
0.018750643357634544,
-0.015513122081756592,
0.006947180721908808,
-0.013653473928570747,
0.019348042085766792,
-0.03274136036634445,
-0.02572673000395298,
0.014347228221595287,
0.018259232863783836,
-0.08579430729150772,
0.0206584669649601,
-0.04528675228357315,
0.022315770387649536,
0.0643264576792717,
0.040970057249069214,
-0.027865806594491005,
-0.003129121847450733,
-0.026536110788583755,
0.014482125639915466,
0.039698176085948944,
0.09697146713733673,
-0.03189343586564064,
-0.006238972768187523,
0.018143607303500175,
-0.003998723812401295,
-0.04312840476632118,
-0.03312677890062332,
-0.018095429986715317,
-0.0026353036519140005,
0.0454409196972847,
0.02333713136613369,
-0.003194161457940936,
0.009105527773499489,
-0.056540992110967636,
-0.0060558984987437725,
0.02166055701673031,
0.007616846356540918,
-0.004256472922861576,
0.04563362896442413,
0.0123912263661623,
0.0017644971376284957,
-0.01319097075611353,
0.026015793904662132,
-0.06151289865374565,
-0.03382053226232529,
-0.024474117904901505,
0.0195503868162632,
0.01761365681886673,
-0.05916184186935425,
0.03218249976634979,
-0.0016259871190413833,
-0.013181335292756557,
-0.029137689620256424,
-0.04640446975827217,
0.01011725328862667,
0.047869060188531876,
0.0010924225207418203,
-0.013634203001856804,
-0.03823358193039894,
-0.011206062510609627,
0.0010906157549470663,
-0.06378687173128128,
0.054652437567710876,
-0.01888553984463215,
0.02017669379711151,
-0.04000651091337204,
0.04863990098237991,
-0.007149525452405214,
0.022200144827365875,
-0.007925181649625301,
-0.007216974161565304,
0.009486129507422447,
0.05272534117102623,
-0.02117878384888172,
0.062861867249012,
0.00419384241104126,
-0.07026191800832748,
0.05862225592136383,
-0.01439540646970272,
-0.032702818512916565,
-0.05619411543011665,
0.0401221364736557,
0.012034713290631771,
0.0716879665851593,
-0.03588252514600754,
-0.046597179025411606,
0.026247045025229454,
-0.08124636113643646,
0.035747628659009933,
-0.002130645327270031,
-0.0027437026146799326,
-0.011022988706827164,
-0.04027630388736725,
0.015696195885539055,
-0.021699098870158195,
-0.025630375370383263,
0.029850713908672333,
0.005550036206841469,
-0.032876256853342056,
-0.03262573108077049,
0.03260646015405655,
-0.025206413120031357,
-0.020485028624534607,
0.030872074887156487,
-0.03844556212425232,
0.033146049827337265,
0.008922453969717026,
0.11863201856613159,
-0.028964251279830933,
0.04324403032660484,
-0.0723046362400055,
-0.022701188921928406,
-0.026362670585513115,
0.032876256853342056,
0.018519390374422073,
0.022045977413654327,
-0.05846808850765228,
-0.028598101809620857,
-0.03859972953796387,
-0.00613780040293932,
-0.007848097942769527,
0.008662295527756214,
0.01872173696756363,
-0.00701462896540761,
-0.0008533421205356717,
0.011620388366281986,
-0.0011815506732091308,
-0.002726840553805232,
-0.04625030234456062,
-0.05338055640459061,
0.033030424267053604,
-0.04301277920603752,
0.00041071229497902095,
-0.06351707875728607,
-0.05037428438663483,
-0.08009010553359985,
-0.04571071267127991,
0.033531468361616135,
-0.07269005477428436,
0.0168909952044487,
0.014877179637551308,
0.059316009283065796
]
|
31,132 | networkx.drawing.layout | spiral_layout | Position nodes in a spiral layout.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G.
scale : number (default: 1)
Scale factor for positions.
center : array-like or None
Coordinate pair around which to center the layout.
dim : int, default=2
Dimension of layout, currently only dim=2 is supported.
Other dimension values result in a ValueError.
resolution : float, default=0.35
The compactness of the spiral layout returned.
Lower values result in more compressed spiral layouts.
equidistant : bool, default=False
If True, nodes will be positioned equidistant from each other
by decreasing angle further from center.
If False, nodes will be positioned at equal angles
from each other by increasing separation further from center.
Returns
-------
pos : dict
A dictionary of positions keyed by node
Raises
------
ValueError
If dim != 2
Examples
--------
>>> G = nx.path_graph(4)
>>> pos = nx.spiral_layout(G)
>>> nx.draw(G, pos=pos)
Notes
-----
This algorithm currently only works in two dimensions.
| def spiral_layout(G, scale=1, center=None, dim=2, resolution=0.35, equidistant=False):
"""Position nodes in a spiral layout.
Parameters
----------
G : NetworkX graph or list of nodes
A position will be assigned to every node in G.
scale : number (default: 1)
Scale factor for positions.
center : array-like or None
Coordinate pair around which to center the layout.
dim : int, default=2
Dimension of layout, currently only dim=2 is supported.
Other dimension values result in a ValueError.
resolution : float, default=0.35
The compactness of the spiral layout returned.
Lower values result in more compressed spiral layouts.
equidistant : bool, default=False
If True, nodes will be positioned equidistant from each other
by decreasing angle further from center.
If False, nodes will be positioned at equal angles
from each other by increasing separation further from center.
Returns
-------
pos : dict
A dictionary of positions keyed by node
Raises
------
ValueError
If dim != 2
Examples
--------
>>> G = nx.path_graph(4)
>>> pos = nx.spiral_layout(G)
>>> nx.draw(G, pos=pos)
Notes
-----
This algorithm currently only works in two dimensions.
"""
import numpy as np
if dim != 2:
raise ValueError("can only handle 2 dimensions")
G, center = _process_params(G, center, dim)
if len(G) == 0:
return {}
if len(G) == 1:
return {nx.utils.arbitrary_element(G): center}
pos = []
if equidistant:
chord = 1
step = 0.5
theta = resolution
theta += chord / (step * theta)
for _ in range(len(G)):
r = step * theta
theta += chord / r
pos.append([np.cos(theta) * r, np.sin(theta) * r])
else:
dist = np.arange(len(G), dtype=float)
angle = resolution * dist
pos = np.transpose(dist * np.array([np.cos(angle), np.sin(angle)]))
pos = rescale_layout(np.array(pos), scale=scale) + center
pos = dict(zip(G, pos))
return pos
| (G, scale=1, center=None, dim=2, resolution=0.35, equidistant=False) | [
0.03372453525662422,
0.014048752374947071,
-0.024766454473137856,
0.004295549355447292,
0.01617535576224327,
0.043096642941236496,
0.0028793825767934322,
-0.001856072572991252,
0.022207003086805344,
-0.0026723681949079037,
0.010623604990541935,
-0.006666806060820818,
0.03443967550992966,
0.05137721821665764,
-0.008379380218684673,
-0.011733954772353172,
0.050398606806993484,
-0.04392470046877861,
-0.03302821144461632,
0.0040720682591199875,
0.036001693457365036,
-0.02536867745220661,
0.05660903826355934,
0.0456184558570385,
-0.04862957447767258,
0.008181774988770485,
0.010021381080150604,
0.01857484132051468,
-0.007316078525036573,
0.010237804614007473,
0.04923179745674133,
0.00951795931905508,
-0.04294608533382416,
0.013964064419269562,
0.00438258983194828,
0.06466378271579742,
-0.00599871389567852,
0.02534985914826393,
-0.014698024839162827,
-0.008327626623213291,
0.0299606341868639,
0.03801537677645683,
0.05574334040284157,
-0.06413683295249939,
0.04866721108555794,
0.06876643002033234,
0.030393483117222786,
-0.013540626503527164,
-0.026177916675806046,
0.007396061439067125,
0.04979638010263443,
-0.014029933139681816,
-0.05438833683729172,
-0.0285115335136652,
0.0015914235264062881,
-0.03570058196783066,
0.023787841200828552,
0.03573821857571602,
0.047274570912122726,
-0.08679550886154175,
0.027739934623241425,
-0.02693069539964199,
-0.017991436645388603,
0.005857567768543959,
-0.061539746820926666,
0.027438823133707047,
0.027739934623241425,
-0.06575531512498856,
-0.0035168929025530815,
-0.053372085094451904,
0.00669033033773303,
0.013804099522531033,
-0.021021375432610512,
-0.03306585177779198,
0.03504189848899841,
-0.01499913726001978,
0.04283316805958748,
0.020268594846129417,
-0.02999827452003956,
-0.023693744093179703,
-0.005866977386176586,
0.00712317880243063,
0.02967834286391735,
0.013267743401229382,
0.018377237021923065,
0.01686226762831211,
0.07373477518558502,
0.008125316351652145,
-0.036246344447135925,
-0.03594523295760155,
0.004326131194829941,
-0.03581349924206734,
0.04821554571390152,
0.003366336924955249,
0.015460214577615261,
0.02113429270684719,
0.0004737219715025276,
-0.058905016630887985,
-0.0032863542437553406,
0.000649860652629286,
-0.018471334129571915,
0.0068926396779716015,
-0.0647766962647438,
-0.030732234939932823,
-0.05442597717046738,
-0.0010027261450886726,
-0.013277153484523296,
0.007631305139511824,
-0.0058058141730725765,
0.022301100194454193,
0.021021375432610512,
0.0819777175784111,
-0.025048747658729553,
0.010350721888244152,
0.017615046352148056,
0.0597330741584301,
-0.004008552059531212,
0.014735664241015911,
-0.0062339575961232185,
-0.015262610279023647,
-0.044790394604206085,
0.01905473880469799,
-0.03513599559664726,
0.02111547254025936,
0.01283489540219307,
-0.01979810744524002,
0.009447386488318443,
0.06078696623444557,
-0.003107568947598338,
0.015130873769521713,
-0.0052459342405200005,
-0.014340454712510109,
0.060372937470674515,
0.0512266643345356,
0.035662941634655,
-0.0009121573530137539,
0.0011832757154479623,
-0.005777584854513407,
-0.0425320565700531,
0.0508502721786499,
-0.000938034150749445,
-0.03447731211781502,
-0.036058150231838226,
0.04151580482721329,
0.007349012419581413,
0.03306585177779198,
0.04392470046877861,
0.007113768719136715,
0.009179208427667618,
-0.005274163093417883,
0.044903311878442764,
-0.06368517130613327,
0.10922834277153015,
0.012354997918009758,
0.020870819687843323,
-0.0133900698274374,
-0.010153117589652538,
0.056006815284490585,
-0.022207003086805344,
0.011715135537087917,
-0.06703504174947739,
-0.036095790565013885,
-0.022414017468690872,
-0.005457653198391199,
-0.021698877215385437,
-0.012430275790393353,
0.02856799215078354,
-0.02252693474292755,
-0.02819160185754299,
0.005095378030091524,
-0.02000512182712555,
-0.034853704273700714,
-0.02403249405324459,
-0.034816063940525055,
-0.0017219837754964828,
-0.0008709896937943995,
0.011178779415786266,
0.03850468620657921,
0.0001362943003186956,
-0.030412303283810616,
-0.0010127240093424916,
-0.03137209638953209,
0.06869115680456161,
0.013211284764111042,
-0.05517875775694847,
0.08732245117425919,
0.009946102276444435,
-0.04012316092848778,
-0.014472191222012043,
-0.006022238172590733,
-0.01918647438287735,
0.04166635870933533,
-0.023110339418053627,
0.04144052788615227,
0.00055194046581164,
0.03647217899560928,
-0.010360131971538067,
0.013841737993061543,
-0.07000851631164551,
0.05416250601410866,
0.07301963865756989,
0.055818621069192886,
0.03560648486018181,
-0.007621895056217909,
-0.0005187123315408826,
0.011884510517120361,
0.011376384645700455,
0.005707011558115482,
-0.0020866114646196365,
0.07106240838766098,
-0.027476461604237556,
-0.009343879297375679,
0.012298539280891418,
-0.07753631472587585,
-0.04128997027873993,
0.08476300537586212,
-0.01571427844464779,
0.06793837249279022,
0.011263467371463776,
-0.03404446691274643,
0.039106909185647964,
0.013851148076355457,
-0.019609913229942322,
-0.01424635760486126,
0.014848580583930016,
-0.05216763913631439,
0.050473883748054504,
-0.07941826432943344,
-0.01359708420932293,
-0.03952093794941902,
0.03568176180124283,
-0.034872524440288544,
0.02408895269036293,
-0.032124876976013184,
0.01640118844807148,
-0.040198441594839096,
0.017859699204564095,
0.04087594151496887,
0.023411450907588005,
0.0568348728120327,
-0.02284686639904976,
-0.007377241738140583,
-0.08664495497941971,
0.02002394199371338,
-0.043209560215473175,
0.03438321501016617,
0.0015831899363547564,
-0.021999988704919815,
-0.0037192024756222963,
-0.013804099522531033,
-0.07143879681825638,
-0.050248049199581146,
-0.023562006652355194,
-0.021021375432610512,
0.0032251907978206873,
0.05837807059288025,
-0.08860217779874802,
0.029076118022203445,
-0.0032981163822114468,
-0.026121458038687706,
-0.003914454951882362,
-0.036321625113487244,
-0.054727088660001755,
0.004281435161828995,
0.1020769402384758,
0.04509150981903076,
0.000058406592870596796,
0.03387508913874626,
0.007052605506032705,
-0.0044790394604206085,
0.000599871389567852,
0.06869115680456161,
-0.006544479168951511,
-0.005467063281685114,
0.07358422130346298,
0.07798798382282257,
-0.012166802771389484,
0.04674762487411499,
0.013578264974057674,
0.015977751463651657,
-0.036020513623952866,
-0.00040550128323957324,
0.02691187709569931,
0.00862873811274767,
-0.004846019670367241,
0.019289981573820114,
0.0005481177940964699,
-0.0010827090591192245,
0.02826688066124916,
0.017059871926903725,
0.07411117106676102,
0.01341829914599657,
-0.040650106966495514,
-0.0007286673062480986,
0.016429418697953224,
0.02570742927491665,
-0.0429084487259388,
-0.012769026681780815,
0.0007610133034177125,
-0.013098368421196938,
0.08114966005086899,
-0.06266891956329346,
0.03391272947192192,
0.00029199622804298997,
0.08227882534265518,
0.04441400617361069,
0.00018275492766406387,
-0.02405131421983242,
0.016768168658018112,
0.01127287745475769,
-0.06485197693109512,
-0.0002714123984333128,
-0.01196919847279787,
-0.0182737298309803,
-0.019007688388228416,
-0.00499187083914876,
-0.007174932397902012,
-0.023129157721996307,
0.04068774729967117,
0.01353121642023325,
0.01911119557917118,
0.011169370263814926,
-0.06270655244588852,
0.029245493933558464,
-0.028078684583306313,
0.050549160689115524,
-0.020964916795492172,
0.08303160965442657,
0.01417107880115509,
-0.008050038479268551,
-0.006878525018692017,
0.006130450405180454,
-0.06402391940355301,
-0.001416166895069182,
-0.05258166790008545,
-0.038730520755052567,
0.01785029098391533,
0.020419150590896606,
-0.004375532269477844,
-0.02824806049466133,
0.03722495958209038,
-0.10034554451704025,
-0.00917450338602066,
0.004582546651363373,
0.04915652051568031,
0.02550041489303112,
0.03417620062828064,
-0.04268261417746544,
-0.019440537318587303,
0.005048329476267099,
0.03118390217423439,
0.0214542243629694,
-0.054802365601062775,
-0.02107783406972885,
-0.03524891287088394,
0.03176730498671532,
0.012957221828401089,
-0.046258315443992615,
-0.02149186283349991,
0.03216251730918884,
0.03786482289433479,
-0.008788703940808773,
-0.002761760726571083,
0.01287253387272358,
-0.013465347699820995,
0.011771593242883682,
-0.05536695197224617,
0.03876815736293793,
0.11239001899957657,
0.007325488142669201,
0.06327114254236221,
-0.03536183014512062,
-0.08973135054111481,
0.05559278652071953,
-0.05205472186207771,
0.08664495497941971,
0.015206151641905308,
-0.00983318593353033,
-0.05363555997610092,
-0.047500401735305786,
0.0036886208690702915,
-0.020626164972782135,
0.0742240846157074,
0.058867376297712326,
-0.00015026189794298261,
-0.013615904375910759,
0.06413683295249939,
0.018828904256224632,
-0.043360114097595215,
-0.029264314100146294,
-0.06865351647138596,
-0.03952093794941902,
0.06473906338214874,
0.016749350354075432,
-0.05958252027630806,
0.026441389694809914,
-0.0037638989742845297,
0.05284513905644417,
-0.02247047610580921,
0.007588961161673069,
-0.01723865605890751,
-0.03794009983539581,
-0.0032110761385411024,
-0.015479033812880516,
0.023166798055171967,
-0.03850468620657921,
0.0336492545902729,
0.016109487041831017,
0.0514148585498333,
0.09462441504001617,
0.020701443776488304,
-0.0047378079034388065,
0.04802734777331352,
-0.05706070736050606,
0.04087594151496887,
-0.0427202507853508,
-0.058792099356651306,
0.09530191868543625,
0.0514148585498333,
0.004161460790783167,
-0.02286568470299244,
-0.012364408001303673,
0.013653542846441269,
0.004568432457745075,
0.0036227526143193245,
0.013578264974057674,
0.008826342411339283,
0.007269029505550861,
-0.026403751224279404,
0.076369509100914,
-0.001978399232029915,
0.0214542243629694,
0.04004788398742676,
0.012016247026622295,
-0.01196919847279787,
-0.01762445643544197,
0.03937038034200668,
-0.009207437746226788,
-0.027702296152710915,
-0.003843881655484438,
0.024841733276844025,
0.019459357485175133,
-0.02815396338701248,
-0.04396233707666397,
0.033291686326265335,
0.007706583011895418,
-0.05800168216228485,
0.019609913229942322,
0.03854232281446457,
0.009710859507322311,
0.0155166732147336,
-0.02286568470299244,
0.03690502792596817,
-0.0030322910752147436,
-0.046258315443992615,
-0.020419150590896606,
0.006149269640445709,
-0.009597942233085632,
-0.10298027098178864,
0.025782708078622818,
-0.0019007689552381635,
-0.017313934862613678,
-0.04351067170500755,
-0.02000512182712555,
0.034928981214761734,
0.012966631911695004,
0.0037638989742845297,
0.029433688148856163,
-0.07524033635854721,
-0.0682394877076149,
0.01143284235149622,
-0.030958067625761032,
-0.036378081887960434,
-0.03839176893234253,
0.0001447483809897676,
-0.03579467907547951,
-0.008595803752541542,
0.02826688066124916,
-0.07516506314277649,
0.021905891597270966,
-0.019384078681468964,
-0.014679205603897572,
0.013051318936049938,
0.045994844287633896,
0.010124888271093369,
0.018433693796396255,
0.027420002967119217,
0.030694594606757164,
-0.05939432233572006,
-0.004366122651845217,
-0.010463639162480831,
-0.0178314708173275,
-0.0010991761228069663,
0.023863118141889572,
0.011216418817639351,
0.025180483236908913,
-0.013757050037384033,
-0.07087421417236328,
-0.009386222809553146,
0.006930278614163399,
0.015855424106121063,
-0.0827304944396019,
0.04091358184814453,
0.009852005168795586,
0.02973480150103569,
0.00888750609010458,
-0.00285585829988122,
0.05288277938961983,
0.0458066500723362,
0.04648414999246597,
-0.002210114384070039,
0.050511524081230164,
-0.020814361050724983,
-0.049194157123565674,
0.004841315094381571,
0.05133958160877228,
-0.03850468620657921,
0.032049600034952164,
0.00988964457064867,
-0.04550553858280182,
0.0016561155207455158,
-0.006930278614163399,
0.006600937806069851,
0.08860217779874802,
-0.034627869725227356,
0.011715135537087917,
0.047349847853183746,
-0.034533772617578506,
-0.019609913229942322,
-0.031993139535188675,
-0.007316078525036573,
0.044677481055259705,
-0.01706928201019764,
0.026027360931038857,
0.029396049678325653,
0.05995890870690346,
0.051904164254665375,
-0.02565097063779831,
0.01065183337777853,
-0.02433360554277897,
-0.01424635760486126,
0.0365474596619606,
-0.05100082978606224,
-0.002481820760294795,
0.044677481055259705,
-0.012759617529809475,
0.04219330474734306,
-0.057662930339574814,
0.011385793797671795,
-0.07444991916418076,
-0.031729668378829956,
0.009216846898198128,
-0.004763684701174498,
-0.03801537677645683,
0.03985968977212906,
-0.023091519251465797,
-0.030224107205867767,
0.006817361805588007,
-0.005471767857670784,
0.024898190051317215,
-0.02566979080438614,
-0.023467909544706345,
-0.043171919882297516,
-0.031786125153303146,
0.04287080839276314,
-0.055893898010253906,
-0.009616761468350887,
-0.03515481576323509,
0.05672195553779602,
0.0039662085473537445,
0.03993496671319008,
-0.0006769137107767165,
0.07685881108045578,
-0.02006158046424389,
0.03861760348081589,
-0.03142855688929558,
0.01651410572230816,
0.0352865532040596,
-0.018490152433514595,
-0.03647217899560928,
0.002359494101256132,
0.004488449543714523,
-0.01070829201489687,
0.034665510058403015,
-0.021755335852503777,
0.0421556681394577,
-0.04697345942258835,
0.05239347368478775,
-0.004333188757300377,
0.004662529565393925,
0.00787595845758915,
-0.05288277938961983,
0.06364753097295761,
0.013832327909767628,
-0.014472191222012043,
-0.03263300284743309,
0.019459357485175133,
-0.009908463805913925,
-0.020682623609900475,
-0.016410598531365395,
-0.10531388968229294,
0.03833530843257904,
0.010266033932566643,
0.004702521022409201,
-0.03419502079486847,
-0.03176730498671532,
0.03125917911529541,
-0.004396704491227865,
-0.003665096592158079,
-0.0073678321205079556,
-0.010115478187799454,
0.0019513462902978063,
0.010840028524398804,
-0.04396233707666397,
0.02439006417989731,
-0.06616934388875961,
-0.020682623609900475,
0.06360989063978195,
0.0032651822548359632,
-0.028850285336375237,
0.01714455895125866,
0.012552603147923946,
-0.014538059011101723,
-0.07452519983053207,
-0.02583916485309601,
0.076369509100914,
0.034684326499700546,
-0.028963202610611916,
-0.0016972831217572093,
-0.02841743640601635,
-0.005448243580758572,
-0.027946949005126953,
-0.05118902400135994,
0.015940111130475998,
0.01796320639550686,
-0.0730949193239212,
-0.01689990609884262,
-0.001999571220949292,
0.03293411433696747,
0.026347292587161064,
0.029283132404088974,
-0.046183038502931595,
-0.03363043814897537,
-0.02280922792851925,
-0.0001533494796603918,
-0.06127627193927765,
0.078891322016716,
-0.034740786999464035,
-0.0005692897248081863,
0.02254575490951538,
-0.037469614297151566,
-0.0015831899363547564,
0.0007051429129205644,
-0.031710848212242126,
0.014058162458240986,
0.046371232718229294,
-0.0020125096198171377,
-0.009946102276444435,
0.02418304979801178,
-0.05950723960995674,
-0.007932417094707489,
0.013051318936049938,
-0.0003581584896892309,
0.01833018660545349,
0.002884087385609746,
-0.0007345483754761517,
-0.00880281813442707,
0.0019454652210697532,
0.019478175789117813,
-0.05860390514135361,
-0.006845591124147177,
-0.023242074996232986,
0.037375517189502716,
0.0037991853896528482,
-0.025105206295847893,
0.02124720998108387,
0.025970902293920517,
-0.00931564997881651,
-0.029132576659321785,
-0.012100934982299805,
-0.023185616359114647,
-0.010943535715341568,
-0.014453371986746788,
0.007118473760783672,
-0.048930685967206955,
-0.012326768599450588,
0.04384942352771759,
-0.0939469188451767,
0.0310333464294672,
0.040537189692258835,
0.0624430812895298,
-0.012957221828401089,
0.061577387154102325,
-0.020306235179305077,
0.03573821857571602,
-0.02008040063083172,
-0.026102637872099876,
0.03854232281446457,
0.0396338552236557,
-0.032200153917074203,
0.04358594864606857,
-0.037582531571388245,
0.0035921710077673197,
0.025970902293920517,
-0.041929833590984344,
-0.02267749048769474,
-0.06872878968715668,
0.027909310534596443,
0.006144565064460039,
0.06673392653465271,
-0.009635580703616142,
-0.025782708078622818,
0.024954648688435555,
-0.06575531512498856,
-0.0022242290433496237,
-0.07143879681825638,
-0.00034227955620735884,
0.011846872046589851,
-0.0423438623547554,
0.004916592966765165,
-0.03154147416353226,
-0.03152265399694443,
-0.016739940270781517,
0.014142850413918495,
-0.03560648486018181,
0.0022042333148419857,
0.024427704513072968,
-0.02149186283349991,
-0.029170216992497444,
-0.02297860197722912,
-0.05977071449160576,
0.05096318945288658,
0.009644990786910057,
0.0651530921459198,
-0.05540459230542183,
-0.0016102429945021868,
-0.07219158113002777,
-0.00167963991407305,
-0.03385626897215843,
0.015017956495285034,
0.012260900810360909,
0.0022724538575857878,
-0.04565609246492386,
-0.04979638010263443,
-0.011555169709026814,
-0.014641566202044487,
-0.03391272947192192,
-0.009334469214081764,
0.01413344033062458,
0.014876809902489185,
0.01968519017100334,
0.03395036607980728,
-0.02134130708873272,
-0.00888750609010458,
-0.01825490966439247,
-0.03662273660302162,
-0.013305382803082466,
0.002813514322042465,
-0.015337888151407242,
-0.04012316092848778,
-0.05224291607737541,
-0.055818621069192886,
-0.036133430898189545,
0.014641566202044487,
-0.011376384645700455,
0.01206329558044672,
0.032200153917074203,
0.054538894444704056
]
|
31,135 | networkx.generators.classic | star_graph | 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)).
| 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.02225247211754322,
-0.006895069498568773,
0.02168417163193226,
-0.0502234548330307,
-0.012653540819883347,
0.06673965603113174,
-0.047559551894664764,
0.007436729967594147,
-0.0006354519282467663,
0.0049814991652965546,
0.004182328004390001,
0.06244189292192459,
0.016960183158516884,
0.07608107477426529,
0.02701197937130928,
-0.007583244703710079,
0.014793542213737965,
0.011836609803140163,
-0.02283853106200695,
0.03800502046942711,
-0.019801679998636246,
0.015130970627069473,
0.03425779566168785,
0.013941093347966671,
-0.020849483087658882,
0.012058601714670658,
0.022216953337192535,
0.03244633972644806,
-0.03736568242311478,
0.027260608971118927,
0.03315671533346176,
-0.01215627882629633,
0.0011676775757223368,
0.018363172188401222,
0.020671889185905457,
0.04237382113933563,
-0.02145330049097538,
0.05313599109649658,
-0.1044960469007492,
-0.01573478803038597,
0.046387434005737305,
-0.005953823681920767,
0.014837941154837608,
-0.03299688175320625,
0.012174038216471672,
0.028450487181544304,
0.0834689661860466,
0.004541954956948757,
-0.06876422464847565,
-0.017555123195052147,
0.04290660098195076,
0.004220066592097282,
-0.04329730570316315,
-0.058321721851825714,
-0.0019435393624007702,
0.010087313130497932,
-0.007561045233160257,
-0.01233387179672718,
0.059493839740753174,
-0.03995854780077934,
0.03365397825837135,
0.032108914107084274,
0.006206894759088755,
-0.023548904806375504,
-0.05622611939907074,
-0.02180848829448223,
-0.03885746747255325,
-0.06141185015439987,
-0.014305160380899906,
-0.018931472674012184,
0.0540594756603241,
0.041485853493213654,
0.030190903693437576,
-0.009634450078010559,
0.012893292121589184,
0.026337122544646263,
0.0364777147769928,
0.01084208581596613,
-0.01046913955360651,
-0.009052830748260021,
-0.02283853106200695,
-0.036211322993040085,
0.022003840655088425,
-0.048056814819574356,
0.046316396445035934,
0.09824474900960922,
-0.019677365198731422,
0.021027076989412308,
-0.04457598179578781,
-0.023992888629436493,
-0.024401353672146797,
-0.027793390676379204,
-0.026106251403689384,
0.0055098398588597775,
-0.0127068180590868,
0.01596565917134285,
0.050330013036727905,
-0.09249071776866913,
0.012351631186902523,
-0.0009695497574284673,
-0.03754327446222305,
-0.03336982801556587,
-0.08865469694137573,
-0.021844007074832916,
-0.05665234103798866,
-0.031434059143066406,
-0.02534259855747223,
0.05682993680238724,
-0.013115284033119678,
0.028539283201098442,
-0.019055787473917007,
0.01742192730307579,
0.06613583862781525,
-0.01362142525613308,
0.029782438650727272,
0.04269348829984665,
-0.018185580149292946,
0.03864435479044914,
0.06521235406398773,
-0.023051641881465912,
-0.058463796973228455,
0.044185273349285126,
-0.040384773164987564,
0.029746919870376587,
0.02686990424990654,
-0.0003812711511272937,
0.04457598179578781,
-0.05313599109649658,
0.030208662152290344,
0.021062595769762993,
-0.0015495037660002708,
0.01896699145436287,
-0.0010544616961851716,
0.06819592416286469,
-0.03530559688806534,
0.01322183944284916,
-0.07885153591632843,
-0.02834393084049225,
-0.0012775636278092861,
-0.014287400990724564,
0.03392036631703377,
-0.03413347899913788,
0.03875091299414635,
0.0495130829513073,
-0.06070147454738617,
0.015477278269827366,
0.01873612031340599,
0.019144585356116295,
0.01331951655447483,
-0.014482754282653332,
0.023690979927778244,
0.002009026939049363,
0.09533222019672394,
0.030723683536052704,
-0.02211039699614048,
-0.018398690968751907,
0.02710077539086342,
-0.02234126813709736,
-0.012147398665547371,
0.029853476211428642,
-0.007463369052857161,
0.011845489963889122,
0.03988751024007797,
-0.016596117988228798,
-0.07615211606025696,
-0.0033232192508876324,
-0.006291251629590988,
-0.004397660028189421,
0.0065665217116475105,
-0.02717181295156479,
-0.04166344553232193,
-0.0009062821045517921,
0.0012575843138620257,
-0.05601300671696663,
-0.004568594042211771,
-0.0020434358157217503,
-0.030865758657455444,
-0.01119727361947298,
-0.017191056162118912,
-0.02591089904308319,
0.029675882309675217,
-0.07064671069383621,
0.029107581824064255,
-0.041770003736019135,
-0.01208524126559496,
0.017697196453809738,
0.00995411816984415,
0.014109807088971138,
0.029125342145562172,
0.03354742005467415,
0.04670710489153862,
0.025093968957662582,
-0.012884411960840225,
0.05601300671696663,
0.022891808301210403,
-0.05842827633023262,
0.06986530125141144,
0.036211322993040085,
-0.0722450539469719,
0.05526711419224739,
0.07743078470230103,
0.07132156938314438,
0.020458776503801346,
-0.010362583212554455,
0.04848304018378258,
-0.0005799539503641427,
-0.051217980682849884,
-0.048127852380275726,
-0.05182179808616638,
0.028716877102851868,
-0.008044987916946411,
0.019677365198731422,
0.037969499826431274,
0.04454046115279198,
-0.06485716253519058,
0.06968770921230316,
0.038999542593955994,
0.03177148476243019,
0.01002515573054552,
-0.061092179268598557,
-0.035181280225515366,
-0.015672631561756134,
0.0032344225328415632,
0.034222278743982315,
-0.008373536169528961,
-0.005767350550740957,
-0.008373536169528961,
-0.016826989129185677,
-0.004586353432387114,
-0.06269052624702454,
0.026550235226750374,
-0.02656799554824829,
0.04422079399228096,
-0.015273044817149639,
0.012609141878783703,
-0.01522864680737257,
0.03345862403512001,
-0.011694535613059998,
-0.04237382113933563,
0.032322026789188385,
-0.05512503907084465,
-0.019499771296977997,
0.007396771106868982,
-0.009394698776304722,
-0.01383453793823719,
0.07970398664474487,
-0.01039810199290514,
0.031434059143066406,
0.0024907495826482773,
-0.011694535613059998,
-0.0044820173643529415,
-0.019055787473917007,
0.01284889318048954,
-0.030919037759304047,
0.0188959538936615,
0.030546089634299278,
-0.05697201192378998,
-0.0074678086675703526,
0.015166489407420158,
0.04269348829984665,
-0.02759803831577301,
-0.008773121051490307,
-0.0580020546913147,
-0.02834393084049225,
0.06176703795790672,
0.01807902380824089,
-0.06869318336248398,
0.05288735777139664,
-0.05952935665845871,
-0.028663598001003265,
0.05704304948449135,
0.08140888065099716,
0.10527745634317398,
0.004477577283978462,
0.012760096229612827,
-0.056119561195373535,
0.0025018490850925446,
0.039851993322372437,
-0.04290660098195076,
-0.03162940964102745,
-0.053917400538921356,
-0.03711705282330513,
-0.01175669301301241,
0.04283556342124939,
0.02532484009861946,
0.032322026789188385,
0.049974825233221054,
-0.004082431551069021,
0.025680027902126312,
-0.028805673122406006,
0.019677365198731422,
-0.014837941154837608,
-0.03683290258049965,
-0.0030990075320005417,
0.030475053936243057,
0.020245663821697235,
-0.026479197666049004,
0.015273044817149639,
0.002346454653888941,
0.052532173693180084,
0.09412457793951035,
-0.05310047045350075,
0.036655306816101074,
0.0224833432585001,
0.045357391238212585,
0.02701197937130928,
0.0004706229083240032,
0.01039810199290514,
0.012760096229612827,
0.014695866033434868,
-0.05448570102453232,
0.014349558390676975,
0.005061415955424309,
0.009323661215603352,
-0.010513538494706154,
-0.05864138901233673,
-0.020441018044948578,
-0.02145330049097538,
0.038040537387132645,
0.038253650069236755,
0.019144585356116295,
0.005256769247353077,
-0.052603207528591156,
0.02129346691071987,
-0.052461136132478714,
0.05334910377860069,
-0.01003403589129448,
0.057149603962898254,
-0.04912237450480461,
0.02100931666791439,
0.019002510234713554,
-0.0195530503988266,
-0.031132148578763008,
0.035394392907619476,
-0.07213850319385529,
0.03551870957016945,
0.013905574567615986,
-0.032552897930145264,
-0.01548615749925375,
-0.051075905561447144,
0.029782438650727272,
0.010531297884881496,
-0.015548314899206161,
0.007050463929772377,
-0.03010210581123829,
0.03864435479044914,
0.04695573449134827,
-0.09348524361848831,
-0.03786294534802437,
-0.0267278291285038,
0.03155837208032608,
0.07870946079492569,
-0.02628384530544281,
-0.029782438650727272,
0.040242698043584824,
0.06641998887062073,
0.005345565732568502,
0.012360511347651482,
-0.06404023617506027,
-0.01058457512408495,
-0.003749443916603923,
0.0035385515075176954,
0.062193259596824646,
-0.009856441989541054,
-0.005758470855653286,
0.02108035422861576,
-0.013568147085607052,
0.08702083677053452,
0.011667896062135696,
-0.006539882626384497,
-0.024152722209692,
-0.0736658051609993,
-0.07679145038127899,
0.05043656751513481,
-0.0057851099409163,
0.05423707142472267,
-0.01544175948947668,
-0.031807005405426025,
0.02717181295156479,
-0.0018902613082900643,
-0.041912078857421875,
-0.019730642437934875,
0.04251589626073837,
0.006917268969118595,
0.02644367888569832,
-0.00003877921699313447,
0.0411306656897068,
0.019304418936371803,
-0.04269348829984665,
-0.027562519535422325,
-0.053633250296115875,
-0.046458471566438675,
0.06240637227892876,
-0.004857183434069157,
-0.029338454827666283,
0.002228799043223262,
0.09561637043952942,
0.049015820026397705,
-0.05288735777139664,
0.017359768971800804,
0.05178627744317055,
-0.04571257904171944,
0.025537952780723572,
0.002623944776132703,
-0.0047195483930408955,
-0.03697497770190239,
0.010593455284833908,
-0.009936358779668808,
-0.02614177018404007,
-0.026603514328598976,
0.01997927390038967,
-0.07870946079492569,
-0.03038625605404377,
-0.0004234496154822409,
0.07153467833995819,
0.006215773988515139,
0.010406982153654099,
0.0009756545769050717,
0.02949828840792179,
0.004621872212737799,
0.023904092609882355,
-0.09384042769670486,
-0.015122090466320515,
0.09682400524616241,
0.05310047045350075,
-0.05072071775794029,
0.027988743036985397,
-0.0163208469748497,
-0.01200532354414463,
0.07267127931118011,
0.03413347899913788,
-0.023850813508033752,
0.035980451852083206,
0.006730795372277498,
0.007356812711805105,
-0.06155392527580261,
0.025378117337822914,
0.006158056203275919,
-0.0017437466885894537,
0.0013275117380544543,
0.031025592237710953,
-0.005301167257130146,
0.01868284121155739,
-0.021062595769762993,
-0.0026461437810212374,
-0.015770306810736656,
0.03814709559082985,
0.03475505858659744,
-0.002339794998988509,
-0.0339558869600296,
-0.006695276591926813,
-0.031434059143066406,
0.05221250280737877,
0.00030412894557230175,
-0.03878642991185188,
-0.007751958444714546,
0.019020268693566322,
-0.04578361660242081,
-0.059706952422857285,
0.04713332653045654,
-0.010930882766842842,
0.026852143928408623,
-0.020831722766160965,
0.02189728431403637,
-0.01672043278813362,
-0.042444858700037,
0.028095299378037453,
-0.005829508416354656,
-0.04116618633270264,
-0.0705401599407196,
0.024472391232848167,
0.013124163262546062,
-0.038999542593955994,
-0.031007833778858185,
0.038182612508535385,
-0.03477281704545021,
-0.026408160105347633,
-0.04656502977013588,
-0.000288034527329728,
-0.03088351897895336,
-0.060736995190382004,
0.015335203148424625,
-0.010176110081374645,
0.039567843079566956,
-0.04716884717345238,
-0.023708738386631012,
0.023175958544015884,
-0.047559551894664764,
0.0018491927767172456,
-0.03542991355061531,
-0.0031189867295324802,
-0.022607658058404922,
-0.015237526968121529,
0.01596565917134285,
-0.030634887516498566,
0.07089534401893616,
-0.01746632531285286,
-0.038395725190639496,
-0.0020012573804706335,
-0.009297022596001625,
0.019304418936371803,
-0.002124462742358446,
-0.022021600976586342,
0.014873459935188293,
0.006979426369071007,
0.05803757160902023,
-0.006655318196862936,
-0.012884411960840225,
0.00828917883336544,
0.042800046503543854,
0.0391061007976532,
0.03857331722974777,
0.024632224813103676,
0.041983116418123245,
-0.022643176838755608,
0.008013908751308918,
-0.021719690412282944,
-0.0076942406594753265,
0.04329730570316315,
-0.057362716645002365,
0.04123722389340401,
0.03821813315153122,
0.00988308060914278,
0.041841041296720505,
-0.025271562859416008,
-0.005936064291745424,
0.03843124583363533,
-0.02665679156780243,
0.016214290633797646,
-0.0005477651138789952,
0.022359028458595276,
0.06169600039720535,
-0.03946128487586975,
0.010779928416013718,
-0.04134377837181091,
-0.0808405801653862,
0.03471953794360161,
0.046742621809244156,
0.008151544257998466,
-0.020316701382398605,
0.002672782866284251,
-0.0022709774784743786,
-0.011099596507847309,
0.0019113505259156227,
0.0011987565085291862,
0.02964036352932453,
0.006140296813100576,
-0.06748554855585098,
0.026337122544646263,
-0.059635914862155914,
0.034222278743982315,
-0.0038981784600764513,
0.007436729967594147,
0.006588720716536045,
0.08368208259344101,
-0.006118097808212042,
0.007996149361133575,
-0.026834385469555855,
0.004186768084764481,
0.03242858126759529,
-0.062193259596824646,
0.006584280636161566,
-0.0017615059623494744,
-0.029604844748973846,
0.01866508275270462,
-0.0000034859672268794384,
0.008679884485900402,
-0.023016123101115227,
0.02466774359345436,
0.007569924928247929,
-0.005603076424449682,
0.06421782821416855,
0.08972026407718658,
-0.009279263205826283,
-0.016054457053542137,
-0.0072591365315020084,
-0.04269348829984665,
-0.004741747863590717,
-0.039709918200969696,
-0.01793694868683815,
-0.020334461703896523,
-0.019641846418380737,
0.002570666605606675,
0.0005610845983028412,
-0.002583986148238182,
0.06393367797136307,
-0.09433769434690475,
-0.004639631602913141,
-0.01786591112613678,
0.015610473230481148,
0.04503772407770157,
-0.05690097436308861,
0.06435990333557129,
0.03354742005467415,
-0.04372353106737137,
0.01072665024548769,
-0.020174626260995865,
-0.045641541481018066,
0.02651471644639969,
0.005931624677032232,
-0.046813659369945526,
0.08865469694137573,
-0.02086724154651165,
0.032908085733652115,
0.062264297157526016,
0.042942121624946594,
0.03155837208032608,
-0.016045577824115753,
-0.016303088515996933,
-0.08453452587127686,
-0.0060692597180604935,
0.05373980849981308,
-0.02093827910721302,
-0.04869615286588669,
-0.050187937915325165,
0.012724577449262142,
-0.028716877102851868,
0.05189283564686775,
-0.06531890481710434,
-0.029995551332831383,
-0.015832465142011642,
0.03542991355061531,
-0.01522864680737257,
-0.007743078749626875,
-0.02900102734565735,
0.0012187357060611248,
0.018469728529453278,
-0.029107581824064255,
0.0012997627491131425,
0.004060232546180487,
0.010673372074961662,
-0.05491192638874054,
-0.022962845861911774,
-0.03463074192404747,
-0.0115702198818326,
-0.007547725923359394,
0.009439096786081791,
-0.027544759213924408,
0.0038826388772577047,
0.09625570476055145,
-0.0430486761033535,
0.008329137228429317,
-0.029089823365211487,
-0.026301603764295578,
-0.0038182612042874098,
-0.031149908900260925,
0.018700601533055305,
-0.03654875233769417,
-0.006531002931296825,
-0.028130818158388138,
-0.0391061007976532,
-0.002901434665545821,
0.01772383600473404,
0.01880715601146221,
0.04276452586054802,
0.037294644862413406,
-0.034808333963155746,
-0.06240637227892876,
0.0054476819932460785,
-0.06173151731491089,
0.05381084606051445,
-0.015610473230481148,
0.029817957431077957,
0.06162496283650398,
0.0011965365847572684,
0.06105666235089302,
-0.003685066243633628,
-0.06148288771510124,
0.006033740937709808,
-0.0004462038050405681,
0.0046485112980008125,
0.008098266087472439,
0.038253650069236755,
-0.016942424699664116,
-0.055089518427848816,
-0.01501553412526846,
-0.014882339164614677,
0.028166336938738823,
-0.04461149871349335,
-0.009856441989541054,
0.009483495727181435,
-0.0091194286942482,
0.03281928971409798,
-0.024436872452497482,
-0.0199082363396883,
-0.01786591112613678,
-0.04098859056830406,
-0.05199939012527466,
0.018718359991908073,
0.011117355898022652,
-0.01749296486377716,
0.028219614177942276,
0.010771049186587334,
0.016303088515996933,
-0.0195530503988266,
0.014873459935188293,
-0.01599229872226715,
0.027189573273062706,
0.004233386367559433,
-0.05079175531864166,
0.03669082745909691,
-0.0014362878864631057,
-0.009341420605778694,
0.03768534958362579,
0.01746632531285286,
0.022820770740509033,
-0.03420451655983925,
0.012111879885196686,
-0.04141481593251228,
0.035696301609277725,
-0.07132156938314438,
-0.023193717002868652,
0.0042555853724479675,
0.02175520919263363,
-0.08716291189193726,
0.0052123707719147205,
0.029693640768527985,
0.005265648942440748,
-0.05192835256457329,
-0.0014917858643457294,
0.03361845761537552,
-0.04727540165185928,
-0.025822101160883904,
0.05111142247915268,
-0.035980451852083206,
0.009070590138435364,
-0.032108914107084274,
-0.037152569741010666,
-0.042196229100227356,
-0.029480529949069023,
-0.021027076989412308,
0.030439535155892372,
0.011792211793363094,
-0.016054457053542137,
0.018931472674012184,
-0.0016316407127305865,
0.020973797887563705,
0.02759803831577301,
-0.016560599207878113,
-0.016640515998005867,
0.002959152450785041,
-0.02145330049097538,
-0.06656206399202347,
-0.020902760326862335,
-0.016658274456858635,
-0.014473874121904373,
0.008329137228429317,
-0.01845197007060051,
0.0011621278245002031,
0.02928517572581768,
0.04134377837181091,
-0.00279265851713717,
0.008964034728705883,
0.02649695798754692,
-0.04471805691719055,
-0.024063926190137863,
0.015281924977898598,
-0.0055142794735729694,
-0.01786591112613678,
-0.04354593902826309,
-0.02283853106200695,
0.02834393084049225,
0.06404023617506027,
-0.010966401547193527,
-0.045144278556108475,
0.003292140318080783,
0.0456770621240139,
-0.003096787491813302
]
|
31,137 | networkx.generators.community | stochastic_block_model | Returns a stochastic block model graph.
This model partitions the nodes in blocks of arbitrary sizes, and places
edges between pairs of nodes independently, with a probability that depends
on the blocks.
Parameters
----------
sizes : list of ints
Sizes of blocks
p : list of list of floats
Element (r,s) gives the density of edges going from the nodes
of group r to nodes of group s.
p must match the number of groups (len(sizes) == len(p)),
and it must be symmetric if the graph is undirected.
nodelist : list, optional
The block tags are assigned according to the node identifiers
in nodelist. If nodelist is None, then the ordering is the
range [0,sum(sizes)-1].
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
directed : boolean optional, default=False
Whether to create a directed graph or not.
selfloops : boolean optional, default=False
Whether to include self-loops or not.
sparse: boolean optional, default=True
Use the sparse heuristic to speed up the generator.
Returns
-------
g : NetworkX Graph or DiGraph
Stochastic block model graph of size sum(sizes)
Raises
------
NetworkXError
If probabilities are not in [0,1].
If the probability matrix is not square (directed case).
If the probability matrix is not symmetric (undirected case).
If the sizes list does not match nodelist or the probability matrix.
If nodelist contains duplicate.
Examples
--------
>>> sizes = [75, 75, 300]
>>> probs = [[0.25, 0.05, 0.02], [0.05, 0.35, 0.07], [0.02, 0.07, 0.40]]
>>> g = nx.stochastic_block_model(sizes, probs, seed=0)
>>> len(g)
450
>>> H = nx.quotient_graph(g, g.graph["partition"], relabel=True)
>>> for v in H.nodes(data=True):
... print(round(v[1]["density"], 3))
0.245
0.348
0.405
>>> for v in H.edges(data=True):
... print(round(1.0 * v[2]["weight"] / (sizes[v[0]] * sizes[v[1]]), 3))
0.051
0.022
0.07
See Also
--------
random_partition_graph
planted_partition_graph
gaussian_random_partition_graph
gnp_random_graph
References
----------
.. [1] Holland, P. W., Laskey, K. B., & Leinhardt, S.,
"Stochastic blockmodels: First steps",
Social networks, 5(2), 109-137, 1983.
| 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)
| (sizes, p, nodelist=None, seed=None, directed=False, selfloops=False, sparse=True, *, backend=None, **backend_kwargs) | [
-0.0020266559440642595,
0.025790462270379066,
-0.038897089660167694,
-0.01563420332968235,
0.005978865083307028,
0.05996328219771385,
-0.034080907702445984,
-0.04183826968073845,
0.053786806762218475,
-0.012159936130046844,
-0.019981633871793747,
0.019871339201927185,
-0.003292741486802697,
0.05128680542111397,
-0.010128684341907501,
0.015183835290372372,
0.010808832012116909,
-0.04128679633140564,
0.020772075280547142,
0.034117672592401505,
-0.011746332980692387,
-0.018538618460297585,
-0.011718759313225746,
0.016847439110279083,
-0.03610296919941902,
0.02696693316102028,
0.02281251735985279,
0.008322617039084435,
-0.05518386885523796,
-0.0011218988802284002,
-0.026139726862311363,
-0.015661777928471565,
-0.022205900400877,
-0.009880522266030312,
0.002688421169295907,
0.053272102028131485,
0.03718752786517143,
0.08338242024183273,
-0.013455892913043499,
-0.02441178448498249,
-0.01904413290321827,
-0.04915444925427437,
0.0064614019356667995,
-0.013933834619820118,
0.011351112276315689,
0.018897073343396187,
0.01271140668541193,
0.05577210336923599,
-0.06632357835769653,
-0.05022062733769417,
0.010670964606106281,
-0.036231644451618195,
0.03457723185420036,
0.0016337329288944602,
-0.026911785826086998,
0.012297803536057472,
0.0008323765941895545,
0.03856620565056801,
0.06525740772485733,
0.005165445152670145,
-0.014549643732607365,
-0.0023288161028176546,
0.017398910596966743,
-0.009770228527486324,
-0.06672799587249756,
0.0011333877919241786,
-0.06830887496471405,
-0.03915444388985634,
0.036893412470817566,
0.06345593184232712,
0.07430152595043182,
0.043713271617889404,
-0.0020312515553086996,
0.012656260281801224,
0.06996329128742218,
0.045330919325351715,
-0.00002805824260576628,
0.002823991235345602,
-0.005202210042625666,
-0.05816181004047394,
0.020422810688614845,
0.016847439110279083,
0.020845605060458183,
-0.010735302232205868,
0.06970594078302383,
-0.004283091519027948,
0.03382355719804764,
0.008345594629645348,
-0.009430154226720333,
-0.04661768302321434,
0.02272060699760914,
0.0018037698464468122,
0.042058855295181274,
-0.03612135350704193,
0.0007341458112932742,
0.0591544583439827,
-0.018115822225809097,
-0.03382355719804764,
0.036231644451618195,
-0.03485297039151192,
0.04621327295899391,
-0.0063832770101726055,
-0.06279416382312775,
0.020036781206727028,
-0.020900752395391464,
-0.055367689579725266,
0.0011052398476749659,
0.0027941197622567415,
-0.002265626797452569,
-0.03329046815633774,
-0.07544123381376266,
0.045404449105262756,
0.05437504127621651,
-0.0049218786880373955,
0.01086397934705019,
-0.0014464625855907798,
-0.005767467897385359,
0.009549640119075775,
0.01377758476883173,
0.007320777978748083,
-0.041102971881628036,
0.0311764944344759,
-0.0217647235840559,
0.025643402710556984,
0.014338246546685696,
0.009315264411270618,
0.028290463611483574,
0.011194861494004726,
0.03220590949058533,
-0.022904429584741592,
0.021507369354367256,
-0.016121337190270424,
0.005409011617302895,
0.020477958023548126,
-0.0035133298952132463,
-0.042058855295181274,
-0.10330890864133835,
-0.03654414787888527,
0.04834562540054321,
0.0060937548987567425,
-0.012628686614334583,
-0.027628697454929352,
-0.017104793339967728,
0.04408091679215431,
0.009485301561653614,
0.041580915451049805,
0.01082721445709467,
-0.020404428243637085,
0.00528033496811986,
0.008249087259173393,
0.044191211462020874,
-0.004641547799110413,
-0.012444863095879555,
-0.045330919325351715,
-0.031562525779008865,
-0.0062270271591842175,
-0.01702207140624523,
-0.029871346428990364,
-0.002095589879900217,
0.01965075172483921,
-0.024154430255293846,
0.025036783888936043,
-0.026213256642222404,
0.05125004053115845,
-0.009071698412299156,
-0.03711399808526039,
0.060698576271533966,
-0.01689339615404606,
-0.06183828413486481,
-0.027242667973041534,
-0.0111489063128829,
-0.029246347025036812,
-0.03797797113656998,
-0.0584559291601181,
0.030386053025722504,
-0.04893386363983154,
0.02011030912399292,
0.00019473821157589555,
-0.03856620565056801,
0.010689347051084042,
-0.03586399927735329,
-0.009136036969721317,
-0.015119497664272785,
-0.02125001698732376,
-0.0037477051373571157,
0.052242688834667206,
0.05448533594608307,
-0.007375924848020077,
0.05511033907532692,
-0.040514737367630005,
-0.04437503591179848,
-0.04279415309429169,
-0.0509926863014698,
0.07713241130113602,
-0.0012925101909786463,
0.014558834955096245,
-0.024632371962070465,
0.02854781597852707,
-0.10632361471652985,
0.028419140726327896,
0.007182910107076168,
0.022518400102853775,
0.005583643913269043,
-0.04937503859400749,
0.03555149957537651,
-0.022481635212898254,
-0.03404414281249046,
-0.030275758355855942,
0.05128680542111397,
0.03242649510502815,
0.014310672879219055,
-0.02433825470507145,
0.07838241755962372,
0.021580899134278297,
0.015119497664272785,
-0.03981620818376541,
0.01792280748486519,
0.00384421250782907,
-0.014586408622562885,
-0.04937503859400749,
-0.0013039992190897465,
-0.029963258653879166,
0.0570221021771431,
-0.03165443614125252,
0.022095605731010437,
-0.03450370207428932,
-0.015836410224437714,
-0.051102980971336365,
-0.04198532551527023,
-0.01136949472129345,
0.0634191706776619,
-0.039411794394254684,
0.024172812700271606,
-0.00006523586489493027,
-0.022518400102853775,
-0.0169669259339571,
0.016525749117136,
-0.006318938918411732,
-0.02391546033322811,
0.044227976351976395,
-0.08639712631702423,
-0.015431997366249561,
0.02389707788825035,
0.017187513411045074,
0.036250028759241104,
0.0550735741853714,
-0.00790441781282425,
-0.0025735313538461924,
-0.020477958023548126,
0.02705884538590908,
-0.02112133987247944,
-0.06658093631267548,
-0.027352962642908096,
-0.06580887734889984,
0.039448559284210205,
-0.07415447384119034,
-0.056433867663145065,
0.007270226255059242,
0.011452214792370796,
-0.02536766789853573,
-0.028805170208215714,
-0.031084584072232246,
-0.04610297828912735,
0.07867652922868729,
0.005248165689408779,
-0.033125028014183044,
0.0018520235316827893,
0.07242652773857117,
-0.0700000524520874,
0.006985299754887819,
0.040036797523498535,
0.050661806017160416,
0.04911768436431885,
-0.010395228862762451,
0.0007324224570766091,
-0.013079054653644562,
-0.018786778673529625,
0.008694860152900219,
0.012270229868590832,
0.05363974720239639,
0.011029420420527458,
0.042169149965047836,
-0.03711399808526039,
-0.0018899372080340981,
-0.0021093767136335373,
0.01879597082734108,
-0.024246342480182648,
-0.020955899730324745,
-0.007881440222263336,
-0.01274817157536745,
-0.002433365909382701,
-0.02018383890390396,
-0.0029756457079201937,
-0.0032284033950418234,
0.042610328644514084,
0.010229787789285183,
0.03490811586380005,
0.01877758838236332,
0.026691198348999023,
0.03398899734020233,
0.04702209681272507,
-0.041029445827007294,
-0.03724267706274986,
-0.004195775371044874,
0.03707723692059517,
-0.015119497664272785,
-0.004379598889499903,
-0.049632392823696136,
0.016498174518346786,
0.03556988015770912,
-0.04025738313794136,
-0.012683833949267864,
0.04676474258303642,
0.029246347025036812,
0.029485316947102547,
0.004106161184608936,
0.016525749117136,
-0.025000018998980522,
0.026691198348999023,
0.07143387943506241,
-0.013593760319054127,
-0.0024954064283519983,
-0.020827222615480423,
0.003382355673238635,
-0.05463239550590515,
-0.010450376197695732,
-0.02599266730248928,
0.041654445230960846,
-0.0021128233056515455,
-0.008818941190838814,
-0.0570221021771431,
-0.03867650032043457,
0.04878680408000946,
0.04669121280312538,
-0.010477949865162373,
0.036305174231529236,
0.07257358729839325,
-0.0700000524520874,
0.04930150881409645,
-0.07786770910024643,
0.020257368683815002,
-0.007279417477548122,
-0.07011035084724426,
-0.005647982470691204,
0.0010552627500146627,
-0.007398902904242277,
0.034191202372312546,
-0.017472440376877785,
-0.04356621205806732,
-0.018933838233351707,
0.022628694772720337,
0.1016177237033844,
0.012205892242491245,
0.07253681868314743,
0.004223349038511515,
0.11029420793056488,
-0.005468754097819328,
-0.028750022873282433,
0.01805148459970951,
0.02867649309337139,
-0.053308866918087006,
-0.006024820730090141,
0.08264712244272232,
0.027665462344884872,
-0.038897089660167694,
-0.004648440983146429,
-0.009053315967321396,
0.005147062707692385,
0.08845595270395279,
-0.07625006139278412,
-0.004733459558337927,
-0.01593751274049282,
-0.04492650553584099,
0.030367670580744743,
-0.039007384330034256,
0.008662690408527851,
-0.1152942106127739,
0.01572611555457115,
-0.02178310602903366,
0.0006054692203179002,
-0.03404414281249046,
-0.022665459662675858,
0.0337500274181366,
0.03959561884403229,
0.00409007677808404,
-0.05338239669799805,
0.05514710396528244,
0.020441193133592606,
0.00204733619466424,
0.025533108040690422,
-0.031029436737298965,
-0.007771146018058062,
0.018970603123307228,
0.04617650806903839,
0.007876844145357609,
0.01377758476883173,
0.07029417157173157,
-0.007835484109818935,
-0.05867651849985123,
0.033602967858314514,
0.0360662043094635,
-0.0021243123337626457,
0.010726111009716988,
0.05305151268839836,
-0.034613996744155884,
-0.022959576919674873,
0.032003700733184814,
0.01377758476883173,
0.014154423028230667,
0.03797797113656998,
-0.07327211648225784,
-0.0066498215310275555,
0.046838272362947464,
-0.04294120892882347,
-0.04286767914891243,
-0.06441181898117065,
-0.03345590829849243,
0.02854781597852707,
0.10705890506505966,
-0.012886039912700653,
0.09595596045255661,
-0.06091916561126709,
0.055955927819013596,
0.014136040583252907,
-0.003952208906412125,
-0.03496326133608818,
0.02384193055331707,
-0.04768386110663414,
-0.04194856435060501,
-0.01719670556485653,
-0.032573554664850235,
0.004329047631472349,
0.07308829575777054,
-0.06569857895374298,
0.04257356375455856,
-0.01302390731871128,
-0.014641555957496166,
0.016847439110279083,
-0.02972428873181343,
-0.004264709074050188,
0.08904419094324112,
0.017362145707011223,
-0.004774820059537888,
-0.02757355198264122,
0.05194856971502304,
0.015183835290372372,
-0.020294133573770523,
-0.009917287155985832,
-0.0153676588088274,
0.03301473334431648,
0.04783092066645622,
-0.009944860823452473,
0.022003693506121635,
0.004308367148041725,
0.0013338705757632852,
0.039522089064121246,
0.0593382827937603,
0.0222978126257658,
-0.04944856837391853,
-0.010468758642673492,
0.09544125199317932,
-0.0321507602930069,
-0.020827222615480423,
0.06628681719303131,
-0.011691185645759106,
0.04944856837391853,
-0.002872244920581579,
-0.004990812856703997,
0.011645229533314705,
-0.0011891094036400318,
0.0339338518679142,
0.02963237650692463,
-0.03014708310365677,
-0.07227946817874908,
-0.028290463611483574,
-0.03674635291099548,
-0.07750006020069122,
0.008795962668955326,
-0.015312512405216694,
-0.006222431547939777,
-0.01570773310959339,
-0.005197614431381226,
0.060698576271533966,
-0.009512875229120255,
-0.03922797366976738,
-0.04893386363983154,
-0.0016957734478637576,
-0.036819882690906525,
-0.011443023569881916,
0.012132362462580204,
-0.01616729237139225,
-0.09139712899923325,
0.014025745913386345,
0.005174636375159025,
0.03704047203063965,
0.009926478378474712,
0.0019312974764034152,
-0.02648899145424366,
0.036231644451618195,
-0.005431989673525095,
0.015110306441783905,
0.04676474258303642,
0.03165443614125252,
-0.03604782372713089,
0.056948576122522354,
0.015909938141703606,
0.02121325209736824,
-0.045735329389572144,
-0.05051474645733833,
0.0017670050729066133,
0.01567096821963787,
0.00048512217472307384,
-0.0010851341066882014,
-0.022683842107653618,
0.02816178649663925,
0.020514722913503647,
0.04933827370405197,
0.032003700733184814,
0.022610312327742577,
-0.0064430199563503265,
0.02071692794561386,
0.04709562659263611,
-0.02321692928671837,
0.09330889582633972,
-0.017389720305800438,
0.000041611649066908285,
-0.018170969560742378,
-0.04551474004983902,
-0.02110295742750168,
0.01742648519575596,
-0.025772079825401306,
0.010974273085594177,
-0.03886032477021217,
0.0572059266269207,
0.023713253438472748,
-0.022702224552631378,
-0.011277582496404648,
0.025845607742667198,
0.05231621861457825,
0.011847435496747494,
-0.02224266529083252,
-0.016525749117136,
0.04485297575592995,
0.010027581825852394,
0.0010437738383188844,
0.03121325932443142,
0.028455905616283417,
0.02058825083076954,
0.004875923041254282,
-0.03722429275512695,
-0.0422794446349144,
0.042058855295181274,
-0.03330884873867035,
-0.012840083800256252,
0.08992654085159302,
-0.041066210716962814,
-0.03955885395407677,
-0.04988974705338478,
0.03852944076061249,
0.07080888003110886,
0.007564343977719545,
-0.028400758281350136,
-0.06746328622102737,
-0.005381437949836254,
0.036838263273239136,
0.011718759313225746,
-0.016369497403502464,
-0.04143385589122772,
0.008221513591706753,
0.0033984400797635317,
0.01782170496881008,
-0.010128684341907501,
-0.03654414787888527,
0.006328130140900612,
-0.009990816935896873,
-0.03121325932443142,
-0.04676474258303642,
-0.01795957237482071,
0.010753684677183628,
-0.01010111067444086,
-0.022867664694786072,
0.022132370620965958,
0.07573535293340683,
-0.03501841053366661,
0.04194856435060501,
0.045882388949394226,
-0.09117653965950012,
-0.040477972477674484,
0.021231634542346,
0.03875003010034561,
0.02806987427175045,
0.0031847450882196426,
-0.02178310602903366,
-0.010422802530229092,
-0.0676838755607605,
-0.0013051481219008565,
0.011626847088336945,
-0.008014712482690811,
-0.028272081166505814,
-0.03551473468542099,
-0.05610298365354538,
0.026213256642222404,
0.003984378185123205,
0.055992692708969116,
0.027830904349684715,
-0.013612142764031887,
-0.04863974452018738,
-0.03272061422467232,
0.012334568426012993,
0.03080884739756584,
-0.043750032782554626,
0.02279413491487503,
-0.014990820549428463,
-0.06871329247951508,
-0.003044579643756151,
-0.03845591098070145,
-0.025220608338713646,
0.006930152419954538,
0.019503692165017128,
-0.051617689430713654,
0.023198546841740608,
-0.00020536550437100232,
0.006631439086049795,
-0.02128678187727928,
-0.016231629997491837,
0.025000018998980522,
-0.023051489144563675,
-0.0021185679361224174,
0.02218751795589924,
0.029981641098856926,
-0.003173256292939186,
-0.011001846753060818,
0.03911767899990082,
-0.020863987505435944,
0.024080900475382805,
-0.028437523171305656,
0.024209577590227127,
0.0025298732798546553,
0.010156258009374142,
-0.005510114599019289,
-0.0201654564589262,
0.045257389545440674,
-0.01772979274392128,
-0.07669124007225037,
-0.10661773383617401,
-0.0010948997223749757,
0.03299634903669357,
0.05136033520102501,
0.0006353405769914389,
0.020477958023548126,
0.007054233457893133,
-0.0006175326416268945,
0.054779455065727234,
-0.05389710143208504,
0.014751849696040154,
-0.02856619842350483,
-0.035735324025154114,
0.02854781597852707,
0.04297797381877899,
-0.048970628529787064,
0.02976105362176895,
0.04433827102184296,
0.060588281601667404,
-0.004659930244088173,
0.008704051375389099,
0.022996341809630394,
0.01858457364141941,
-0.013318025507032871,
-0.027959581464529037,
0.03805150091648102,
-0.045367684215307236,
-0.012775745242834091,
0.06514710932970047,
-0.01668199896812439,
-0.03704047203063965,
0.04191179946064949,
-0.04125003144145012,
0.014494496397674084,
-0.03812503069639206,
0.04073532670736313,
0.02750002220273018,
0.02338237129151821,
-0.034779440611600876,
-0.0003578817122615874,
-0.006842836271971464,
-0.005588239524513483,
-0.034816205501556396,
-0.053308866918087006,
-0.011865817941725254,
0.005831805989146233,
0.009076293557882309,
-0.010680155828595161,
-0.005133276339620352,
-0.02545957826077938,
-0.02808825671672821,
0.045294154435396194,
-0.033621348440647125,
0.000044268475903663784,
0.005450372118502855,
0.0135478051379323,
0.05569857358932495,
0.028308846056461334,
-0.008639712817966938,
0.046323567628860474,
-0.02181987091898918,
-0.024154430255293846,
-0.03955885395407677,
0.05360298231244087,
0.028915464878082275,
0.011636038310825825,
-0.02073531039059162,
-0.008736220188438892,
0.00009823077562032267,
0.006631439086049795,
-0.03762870654463768,
-0.022610312327742577,
0.02444854937493801,
0.09919125586748123,
-0.012545965611934662,
-0.007481623440980911,
0.009825375862419605,
0.020459575578570366,
0.03391546756029129,
-0.002433365909382701,
-0.06099269539117813,
-0.020496340468525887,
0.05415445566177368,
-0.027702227234840393,
0.03830885514616966,
-0.02816178649663925,
-0.028970610350370407,
0.08117653429508209,
-0.02435663715004921,
0.04279415309429169,
-0.009439345449209213,
-0.05680151656270027,
-0.018446706235408783,
0.02586399018764496,
-0.04702209681272507,
0.0032238077837973833,
-0.06665446609258652,
0.009788610972464085,
-0.040514737367630005,
0.008469675667583942,
-0.023584578186273575,
-0.0275367870926857,
0.043750032782554626,
0.009963243268430233,
-0.006121328566223383,
-0.020937517285346985,
0.007136953994631767,
-0.002277115825563669,
0.02380516566336155,
0.007711403071880341,
-0.04647062346339226,
-0.036856647580862045,
0.003556988202035427,
-0.05422798544168472,
-0.05415445566177368,
-0.07573535293340683,
-0.006810666993260384,
0.012573539279401302,
-0.0063832770101726055,
-0.002851564669981599,
-0.008042286150157452,
0.04117650166153908,
0.040000032633543015,
0.023033106699585915
]
|
31,145 | networkx.classes.function | subgraph | Returns the subgraph induced on nodes in nbunch.
Parameters
----------
G : graph
A NetworkX graph
nbunch : list, iterable
A container of nodes that will be iterated through once (thus
it should be an iterator or be iterable). Each element of the
container should be a valid node type: any hashable type except
None. If nbunch is None, return all edges data in the graph.
Nodes in nbunch that are not in the graph will be (quietly)
ignored.
Notes
-----
subgraph(G) calls G.subgraph()
| def subgraph(G, nbunch):
"""Returns the subgraph induced on nodes in nbunch.
Parameters
----------
G : graph
A NetworkX graph
nbunch : list, iterable
A container of nodes that will be iterated through once (thus
it should be an iterator or be iterable). Each element of the
container should be a valid node type: any hashable type except
None. If nbunch is None, return all edges data in the graph.
Nodes in nbunch that are not in the graph will be (quietly)
ignored.
Notes
-----
subgraph(G) calls G.subgraph()
"""
return G.subgraph(nbunch)
| (G, nbunch) | [
0.004074414260685444,
-0.039609938859939575,
-0.02781420201063156,
-0.0008948225295171142,
-0.1043468788266182,
0.0026632011868059635,
0.0026741069741547108,
0.01825197972357273,
0.09687858074903488,
-0.03427044674754143,
0.004063508473336697,
0.015992293134331703,
-0.030518846586346626,
0.006233766674995422,
-0.034008707851171494,
-0.009902484714984894,
0.023731064051389694,
-0.03671335056424141,
0.020572738721966743,
0.06103769317269325,
-0.03268256038427353,
-0.0270638819783926,
0.031391311436891556,
0.024603528901934624,
-0.050882190465927124,
0.031391311436891556,
0.014020522125065327,
-0.0025737734977155924,
-0.004898894112557173,
0.015259423293173313,
0.005483446177095175,
-0.065609410405159,
-0.035387203097343445,
-0.024900168180465698,
0.04055219888687134,
0.05761762708425522,
-0.021043868735432625,
0.04097098484635353,
-0.08438487350940704,
0.0565008707344532,
-0.01968282274901867,
-0.06543491780757904,
0.028390029445290565,
-0.009056192822754383,
0.0418783463537693,
0.029541684314608574,
0.07894068211317062,
0.023539120331406593,
-0.045263513922691345,
-0.01940363459289074,
0.02552834339439869,
-0.0030863469000905752,
-0.0588739775121212,
-0.006626375950872898,
-0.040168315172195435,
0.0034506013616919518,
-0.00001903406337078195,
0.0335724763572216,
0.04606618359684944,
0.050009727478027344,
-0.02540619671344757,
-0.06351549178361893,
0.0041921972297132015,
0.01032999251037836,
-0.002595585072413087,
-0.015486263670027256,
-0.07210055738687515,
-0.027011534199118614,
-0.05800151079893112,
-0.019962012767791748,
-0.03730662912130356,
0.05370898172259331,
-0.03118192031979561,
0.006111621391028166,
-0.006207592319697142,
-0.017711050808429718,
-0.0141252176836133,
0.03369462117552757,
-0.029367191717028618,
-0.00893404707312584,
0.02453373186290264,
-0.0008904601563699543,
-0.04215753823518753,
0.012249416671693325,
0.05587269365787506,
0.017536558210849762,
0.055663302540779114,
0.01398562267422676,
-0.041913244873285294,
0.011769560165703297,
-0.0028442377224564552,
-0.012554779648780823,
0.0009177247411571443,
0.012537330389022827,
-0.008702844381332397,
-0.003731971373781562,
-0.07136768102645874,
-0.01454400084912777,
-0.0391213558614254,
-0.06431816518306732,
-0.0038541166577488184,
-0.0185660682618618,
-0.05318550020456314,
-0.006949188187718391,
0.009509874507784843,
-0.038074396550655365,
-0.02387065812945366,
-0.003555297153070569,
0.0066176513209939,
-0.023957904428243637,
-0.034357693046331406,
0.0671449527144432,
-0.0026086720172315836,
-0.029332293197512627,
0.009344106540083885,
0.03224632889032364,
0.03006516396999359,
-0.038702573627233505,
-0.00394136318936944,
-0.016367454081773758,
-0.03224632889032364,
0.03503821790218353,
-0.000539565400686115,
0.06512083113193512,
-0.01185680739581585,
0.010146774351596832,
0.019962012767791748,
0.024271992966532707,
0.03824888914823532,
-0.09876310080289841,
0.126472607254982,
-0.018391573801636696,
-0.04603128507733345,
-0.003247753018513322,
-0.0005332945729605854,
-0.008240437135100365,
0.0015780720859766006,
-0.022195523604750633,
0.021706944331526756,
0.02868666872382164,
-0.058071307837963104,
-0.04540310800075531,
0.007415957283228636,
0.08766534179449081,
-0.03734152764081955,
-0.04400716349482536,
-0.014954060316085815,
-0.013305099681019783,
0.004373233765363693,
0.006255578249692917,
-0.06651677191257477,
0.039575036615133286,
0.035073116421699524,
-0.06121218577027321,
-0.026767244562506676,
-0.02900075539946556,
-0.041668955236673355,
0.043448787182569504,
0.028320232406258583,
-0.018949951976537704,
-0.01632383093237877,
0.02868666872382164,
-0.03250806778669357,
0.008092118427157402,
-0.06721474975347519,
-0.0016707716276869178,
0.06536512076854706,
0.003570565255358815,
-0.018391573801636696,
0.029855770990252495,
0.004183472599834204,
0.0008299328619614244,
-0.05559350550174713,
0.018478820100426674,
-0.01580907590687275,
0.04212263599038124,
0.031792644411325455,
0.03529995679855347,
0.031147021800279617,
0.03573618829250336,
-0.023975353688001633,
-0.03449728712439537,
0.001186553156003356,
-0.015198349952697754,
0.019490880891680717,
-0.00002976947871502489,
-0.0003364445292390883,
-0.009440077468752861,
0.04816009849309921,
-0.058071307837963104,
-0.01940363459289074,
-0.014186290092766285,
-0.0006581661873497069,
0.02912290021777153,
0.054825738072395325,
-0.01655939593911171,
-0.05559350550174713,
0.051545266062021255,
-0.07203076034784317,
0.08452446758747101,
-0.027482666075229645,
-0.02615651860833168,
0.028163189068436623,
-0.027168577536940575,
0.02402770146727562,
0.044600438326597214,
0.009981006383895874,
-0.016227860003709793,
-0.03006516396999359,
-0.010844746604561806,
-0.00932665728032589,
-0.019630474969744682,
0.09227196127176285,
0.009937383234500885,
-0.021008970215916634,
-0.004562994930893183,
-0.06808721274137497,
-0.026139069348573685,
-0.005343851633369923,
-0.03446238860487938,
-0.0006690720329061151,
-0.06801741570234299,
0.04002872109413147,
-0.003601101692765951,
-0.028861161321401596,
-0.021584797650575638,
0.018758010119199753,
-0.03156580403447151,
0.024114947766065598,
-0.034444939345121384,
0.013776231557130814,
-0.010940718464553356,
0.057163942605257034,
-0.04159915819764137,
-0.035108014941215515,
0.06156117096543312,
-0.052452631294727325,
0.006011287681758404,
0.10804613679647446,
0.04362327978014946,
-0.06662146747112274,
-0.026889389380812645,
-0.04829969257116318,
-0.008567611686885357,
0.004006797913461924,
0.014657421968877316,
-0.005404924042522907,
0.006957912817597389,
-0.01952577941119671,
0.03608517721295357,
-0.040761590003967285,
0.0002903674612753093,
0.008968946523964405,
-0.007952523417770863,
-0.0017242101021111012,
0.040447503328323364,
-0.07122808694839478,
-0.05384857580065727,
0.0006139976321719587,
0.0335724763572216,
0.04292530566453934,
-0.0022258777171373367,
-0.03030945360660553,
0.05461634323000908,
-0.012223242782056332,
0.014866813085973263,
-0.020642535760998726,
0.007852190174162388,
-0.06358528882265091,
0.010111875832080841,
0.04086628928780556,
0.0009090000530704856,
0.02940209023654461,
-0.0008348404662683606,
0.032298676669597626,
0.0060810851864516735,
-0.023661267012357712,
0.050044625997543335,
0.0031321514397859573,
-0.07258913666009903,
-0.019508330151438713,
0.04205283895134926,
-0.014753392897546291,
0.0012585315853357315,
-0.019578127190470695,
-0.04690374806523323,
0.05105668678879738,
0.015259423293173313,
0.0141252176836133,
-0.025947125628590584,
0.06128198280930519,
-0.03796970099210739,
-0.004222733434289694,
0.0335724763572216,
-0.015276872552931309,
0.05765252560377121,
-0.015189625322818756,
-0.0051170107908546925,
0.015573510900139809,
0.05234793573617935,
0.09876310080289841,
-0.07461325824260712,
-0.025859879329800606,
0.01682986132800579,
0.007895813323557377,
0.004399407655000687,
0.03552679717540741,
0.016070816665887833,
-0.021515000611543655,
-0.004006797913461924,
-0.09597121179103851,
-0.046135980635881424,
-0.036573756486177444,
-0.014509102329611778,
-0.08473385870456696,
-0.05583779513835907,
-0.0013163323746994138,
-0.032106734812259674,
0.01667281799018383,
-0.00628175213932991,
-0.02777930349111557,
0.032542966306209564,
0.003352449042722583,
0.06033971905708313,
-0.001999036641791463,
0.07059991359710693,
-0.03529995679855347,
0.09345851093530655,
-0.01872311159968376,
0.03090273030102253,
-0.036329466849565506,
0.021706944331526756,
0.0031866806093603373,
0.0810346007347107,
-0.0185660682618618,
0.06264302879571915,
0.05964174494147301,
0.03828378766775131,
-0.03486372530460358,
-0.06609798967838287,
0.011376950889825821,
0.05964174494147301,
-0.0030143684707581997,
-0.00160751782823354,
0.10420728474855423,
0.023137787356972694,
-0.02893095836043358,
-0.006643825210630894,
0.015521162189543247,
0.015128552913665771,
-0.04578699171543121,
0.06658656895160675,
-0.025109559297561646,
-0.04159915819764137,
-0.0009466251358389854,
0.0335724763572216,
0.0011031236499547958,
-0.05377877876162529,
-0.014081594534218311,
0.004080957733094692,
0.03863277658820152,
0.04655476287007332,
-0.006822680588811636,
-0.031234268099069595,
0.03343288227915764,
-0.0023054901976138353,
-0.04993993043899536,
0.06149137392640114,
-0.03181009367108345,
-0.044600438326597214,
-0.014753392897546291,
-0.021410305052995682,
-0.011106486432254314,
-0.0005016677314415574,
-0.013593013398349285,
0.007053884211927652,
0.01379368081688881,
-0.011019240133464336,
-0.001120027736760676,
0.02667999640107155,
-0.015407742001116276,
0.002172439359128475,
-0.0003607099934015423,
0.021951233968138695,
0.04271591454744339,
-0.006648187525570393,
-0.045507803559303284,
0.017353340983390808,
0.05116138234734535,
-0.03308389335870743,
-0.02212572656571865,
-0.013034635223448277,
0.0320194847881794,
0.040168315172195435,
-0.039609938859939575,
-0.07136768102645874,
0.07552061975002289,
-0.02137540653347969,
-0.023818310350179672,
-0.0030972526874393225,
-0.007904537953436375,
0.023225033655762672,
-0.023975353688001633,
0.05053320527076721,
0.022910945117473602,
-0.0454380065202713,
0.02303309179842472,
-0.02840747870504856,
0.05021911859512329,
-0.07852189987897873,
0.04121527448296547,
-0.023818310350179672,
-0.08745595067739487,
0.04638027027249336,
0.046135980635881424,
0.02181163989007473,
0.005710287019610405,
0.07684677094221115,
-0.0022193342447280884,
0.018286878243088722,
0.04927685484290123,
0.0156084094196558,
0.05349959060549736,
0.009893759153783321,
0.030483946204185486,
0.02006670832633972,
-0.044042062014341354,
-0.02299819327890873,
-0.01968282274901867,
0.02355656959116459,
-0.04097098484635353,
-0.05011442303657532,
0.006770332809537649,
0.012362836860120296,
0.010984341613948345,
-0.04365817829966545,
-0.00020543838036246598,
-0.018129834905266762,
-0.019264040514826775,
0.06536512076854706,
0.009797788225114346,
0.0061247083358466625,
-0.007036434952169657,
-0.03263021260499954,
0.04145956411957741,
-0.03835358843207359,
0.0021560804452747107,
0.012319213710725307,
0.04812519997358322,
-0.02477802149951458,
0.018740560859441757,
-0.06131688132882118,
-0.01129842922091484,
-0.02018885314464569,
-0.06421346962451935,
-0.006377723533660173,
0.005479083862155676,
0.030518846586346626,
-0.03971463441848755,
0.04247162491083145,
0.003149600699543953,
0.014509102329611778,
0.01900229975581169,
0.0068575795739889145,
-0.013741333037614822,
-0.022143175825476646,
0.10406769067049026,
0.001377405016683042,
-0.03228122740983963,
-0.019962012767791748,
0.031356412917375565,
-0.029053103178739548,
-0.0501842200756073,
-0.060863196849823,
0.10008925199508667,
0.023923005908727646,
-0.05667536333203316,
-0.012502431869506836,
0.00978033896535635,
-0.058699484914541245,
-0.003738515079021454,
0.014290985651314259,
0.01742313802242279,
0.008214263245463371,
-0.01900229975581169,
-0.001599883777089417,
-0.015748003497719765,
0.0071367681957781315,
-0.07321731001138687,
-0.02425454370677471,
0.027918897569179535,
-0.00865485891699791,
-0.06697046011686325,
-0.01655939593911171,
0.0418783463537693,
0.04714803770184517,
-0.00016004290955606848,
-0.012197068892419338,
0.04152936115860939,
-0.01395072415471077,
-0.002447265898808837,
0.03418320044875145,
0.05220834165811539,
-0.00590659212321043,
-0.013113157823681831,
0.018025139346718788,
0.009762889705598354,
0.06431816518306732,
0.04023811221122742,
-0.002545418217778206,
0.02418474480509758,
0.012842693366110325,
-0.00873338058590889,
0.031635601073503494,
0.04491452872753143,
-0.005404924042522907,
-0.014099043793976307,
0.006412622053176165,
0.04152936115860939,
-0.010408514179289341,
0.05862968787550926,
0.0011898248922079802,
0.03667845204472542,
0.060793399810791016,
0.025947125628590584,
-0.005858606193214655,
0.026522953063249588,
0.030379250645637512,
-0.01743186265230179,
0.007197841070592403,
-0.010434688068926334,
0.07845210283994675,
0.015590960159897804,
0.08187217265367508,
0.013113157823681831,
-0.039295848459005356,
0.004301255103200674,
0.012467533349990845,
0.03374696895480156,
0.02339952625334263,
-0.013392346911132336,
0.02762226015329361,
0.05576799809932709,
0.06738924235105515,
-0.057163942605257034,
0.021881436929106712,
0.018321776762604713,
0.059606846421957016,
0.012214518152177334,
-0.024167295545339584,
-0.016856035217642784,
0.0027417230885475874,
0.02212572656571865,
0.009789063595235348,
0.005976389162242413,
-0.034706681966781616,
-0.052452631294727325,
0.04540310800075531,
-0.012589678168296814,
-0.0075293779373168945,
-0.04697354510426521,
-0.011272255331277847,
0.014666146598756313,
0.016890933737158775,
0.042262233793735504,
-0.0006314469501376152,
-0.02924504689872265,
0.008070306852459908,
0.01632383093237877,
0.012083647772669792,
0.0042794435285031796,
0.0018572610570117831,
0.01928148977458477,
-0.006975362077355385,
-0.015617134049534798,
0.022300219163298607,
-0.017021803185343742,
0.05580289661884308,
0.013680260628461838,
-0.028913509100675583,
-0.006421346683055162,
-0.031042324379086494,
0.028773915022611618,
0.04896276816725731,
-0.0012432634830474854,
0.05130097642540932,
-0.03814419358968735,
0.0006968818488530815,
-0.04774131625890732,
-0.009213236160576344,
0.061665866523981094,
0.0073854210786521435,
0.060235023498535156,
-0.008960221894085407,
-0.005243517924100161,
-0.019804969429969788,
-0.024394137784838676,
-0.024690775200724602,
-0.034357693046331406,
-0.0450541228055954,
-0.02387065812945366,
0.04920705780386925,
0.09513364732265472,
-0.00468077789992094,
-0.016890933737158775,
-0.00970181729644537,
0.0048683579079806805,
-0.02556324191391468,
0.038039498031139374,
-0.051510367542505264,
0.018670763820409775,
0.06707515567541122,
-0.05028891563415527,
-0.025388747453689575,
-0.07684677094221115,
-0.012057473883032799,
-0.024882718920707703,
0.012144721113145351,
-0.04805540293455124,
-0.02018885314464569,
0.0075075663626194,
-0.004434306174516678,
-0.01556478627026081,
0.0026588388718664646,
-0.04707824066281319,
0.0036512683145701885,
0.014360783621668816,
-0.014099043793976307,
0.004329610615968704,
-0.010460861958563328,
0.00932665728032589,
-0.04205283895134926,
0.007817291654646397,
0.01714394800364971,
0.002962020691484213,
-0.12828734517097473,
-0.009806512854993343,
-0.012223242782056332,
-0.03371207043528557,
0.05472104251384735,
-0.01479701604694128,
-0.013540665619075298,
-0.024586079642176628,
-0.010678978636860847,
-0.03339798375964165,
-0.01999691128730774,
0.0011614698451012373,
-0.019822418689727783,
0.0018441741121932864,
-0.013182954862713814,
0.020241200923919678,
0.037481121718883514,
0.03863277658820152,
0.02758736163377762,
-0.05161506310105324,
0.06651677191257477,
0.06791272014379501,
-0.012720547616481781,
-0.002122272504493594,
0.0237136147916317,
0.06173566356301308,
-0.0072109280154109,
-0.00003888606443069875,
0.023696165531873703,
0.053953271359205246,
0.05077749490737915,
0.012729272246360779,
-0.0513707734644413,
-0.005780084524303675,
-0.01021657232195139,
-0.03919115290045738,
-0.006447520572692156,
-0.02896585687994957,
-0.03158325329422951,
-0.07789372652769089,
-0.020834477618336678,
-0.021392855793237686,
-0.012659475207328796,
-0.003995892126113176,
-0.01868821308016777,
0.013296375051140785,
0.017335891723632812,
-0.01053065899759531,
-0.04501922428607941,
-0.04243672639131546,
0.044670239090919495,
-0.04145956411957741,
-0.04051730036735535,
0.009012569673359394,
-0.02699408493936062,
0.02146265283226967,
-0.023975353688001633,
0.01037361565977335,
0.0533599928021431,
-0.0017841920489445329,
0.05681495741009712,
-0.0020590187050402164,
0.01357556413859129,
-0.016856035217642784,
0.0034396955743432045,
0.00903001893311739,
0.026016922667622566,
-0.009989731013774872,
0.03362482413649559,
0.011150109581649303,
0.0007312351954169571,
-0.04658966138958931,
0.010774949565529823,
0.006861941888928413,
0.03915625438094139,
-0.03222887963056564,
-0.002693737391382456,
0.009134714491665363,
0.027918897569179535,
0.009038743562996387,
-0.022457264363765717,
-0.0026719258166849613,
0.002169167622923851,
-0.09471486508846283,
0.047915808856487274,
-0.01238901074975729,
-0.022387467324733734,
0.04802050441503525,
0.03353757783770561,
0.0071934787556529045,
0.06738924235105515,
0.0762883871793747,
-0.03727173060178757,
-0.01015549898147583,
0.018356675282120705,
-0.0276571586728096,
0.04180854931473732,
0.03449728712439537,
0.031635601073503494,
0.016367454081773758,
-0.030518846586346626,
-0.03943544253706932,
0.008768279105424881,
0.00657839048653841,
-0.027552463114261627,
-0.0026348461396992207,
-0.029367191717028618,
-0.01726609282195568,
0.03486372530460358,
-0.06225914508104324,
-0.04299510270357132,
-0.008480365388095379,
0.011952778324484825,
0.004434306174516678,
0.013514491729438305,
0.009256859309971333,
0.03386911377310753,
0.02006670832633972,
-0.03413085266947746,
0.017405688762664795,
0.012589678168296814,
-0.03528250753879547,
-0.03615497425198555,
-0.03461943566799164,
-0.05639617517590523,
-0.01611443981528282,
0.045507803559303284,
0.004351422190666199,
-0.010042078793048859,
-0.04634537175297737,
0.015058755874633789,
0.027831651270389557,
-0.006076722871512175
]
|
31,155 | networkx.generators.classic | tadpole_graph | Returns the (m,n)-tadpole graph; ``C_m`` connected to ``P_n``.
This graph on m+n nodes connects a cycle of size `m` to a path of length `n`.
It looks like a tadpole. It is also called a kite graph or a dragon graph.
.. plot::
>>> nx.draw(nx.tadpole_graph(3, 5))
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.
The nodes for `m` appear in the cycle graph $C_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 cycle of size `m` connected to a path of length `n`.
Raises
------
NetworkXError
If ``m < 2``. The tadpole graph is undefined for ``m<2``.
Notes
-----
The 2 subgraphs are joined via an edge ``(m-1, m)``.
If ``n=0``, this is a cycle graph.
`m` and/or `n` can be a container of nodes instead of an integer.
| 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.02225247211754322,
-0.006895069498568773,
0.02168417163193226,
-0.0502234548330307,
-0.012653540819883347,
0.06673965603113174,
-0.047559551894664764,
0.007436729967594147,
-0.0006354519282467663,
0.0049814991652965546,
0.004182328004390001,
0.06244189292192459,
0.016960183158516884,
0.07608107477426529,
0.02701197937130928,
-0.007583244703710079,
0.014793542213737965,
0.011836609803140163,
-0.02283853106200695,
0.03800502046942711,
-0.019801679998636246,
0.015130970627069473,
0.03425779566168785,
0.013941093347966671,
-0.020849483087658882,
0.012058601714670658,
0.022216953337192535,
0.03244633972644806,
-0.03736568242311478,
0.027260608971118927,
0.03315671533346176,
-0.01215627882629633,
0.0011676775757223368,
0.018363172188401222,
0.020671889185905457,
0.04237382113933563,
-0.02145330049097538,
0.05313599109649658,
-0.1044960469007492,
-0.01573478803038597,
0.046387434005737305,
-0.005953823681920767,
0.014837941154837608,
-0.03299688175320625,
0.012174038216471672,
0.028450487181544304,
0.0834689661860466,
0.004541954956948757,
-0.06876422464847565,
-0.017555123195052147,
0.04290660098195076,
0.004220066592097282,
-0.04329730570316315,
-0.058321721851825714,
-0.0019435393624007702,
0.010087313130497932,
-0.007561045233160257,
-0.01233387179672718,
0.059493839740753174,
-0.03995854780077934,
0.03365397825837135,
0.032108914107084274,
0.006206894759088755,
-0.023548904806375504,
-0.05622611939907074,
-0.02180848829448223,
-0.03885746747255325,
-0.06141185015439987,
-0.014305160380899906,
-0.018931472674012184,
0.0540594756603241,
0.041485853493213654,
0.030190903693437576,
-0.009634450078010559,
0.012893292121589184,
0.026337122544646263,
0.0364777147769928,
0.01084208581596613,
-0.01046913955360651,
-0.009052830748260021,
-0.02283853106200695,
-0.036211322993040085,
0.022003840655088425,
-0.048056814819574356,
0.046316396445035934,
0.09824474900960922,
-0.019677365198731422,
0.021027076989412308,
-0.04457598179578781,
-0.023992888629436493,
-0.024401353672146797,
-0.027793390676379204,
-0.026106251403689384,
0.0055098398588597775,
-0.0127068180590868,
0.01596565917134285,
0.050330013036727905,
-0.09249071776866913,
0.012351631186902523,
-0.0009695497574284673,
-0.03754327446222305,
-0.03336982801556587,
-0.08865469694137573,
-0.021844007074832916,
-0.05665234103798866,
-0.031434059143066406,
-0.02534259855747223,
0.05682993680238724,
-0.013115284033119678,
0.028539283201098442,
-0.019055787473917007,
0.01742192730307579,
0.06613583862781525,
-0.01362142525613308,
0.029782438650727272,
0.04269348829984665,
-0.018185580149292946,
0.03864435479044914,
0.06521235406398773,
-0.023051641881465912,
-0.058463796973228455,
0.044185273349285126,
-0.040384773164987564,
0.029746919870376587,
0.02686990424990654,
-0.0003812711511272937,
0.04457598179578781,
-0.05313599109649658,
0.030208662152290344,
0.021062595769762993,
-0.0015495037660002708,
0.01896699145436287,
-0.0010544616961851716,
0.06819592416286469,
-0.03530559688806534,
0.01322183944284916,
-0.07885153591632843,
-0.02834393084049225,
-0.0012775636278092861,
-0.014287400990724564,
0.03392036631703377,
-0.03413347899913788,
0.03875091299414635,
0.0495130829513073,
-0.06070147454738617,
0.015477278269827366,
0.01873612031340599,
0.019144585356116295,
0.01331951655447483,
-0.014482754282653332,
0.023690979927778244,
0.002009026939049363,
0.09533222019672394,
0.030723683536052704,
-0.02211039699614048,
-0.018398690968751907,
0.02710077539086342,
-0.02234126813709736,
-0.012147398665547371,
0.029853476211428642,
-0.007463369052857161,
0.011845489963889122,
0.03988751024007797,
-0.016596117988228798,
-0.07615211606025696,
-0.0033232192508876324,
-0.006291251629590988,
-0.004397660028189421,
0.0065665217116475105,
-0.02717181295156479,
-0.04166344553232193,
-0.0009062821045517921,
0.0012575843138620257,
-0.05601300671696663,
-0.004568594042211771,
-0.0020434358157217503,
-0.030865758657455444,
-0.01119727361947298,
-0.017191056162118912,
-0.02591089904308319,
0.029675882309675217,
-0.07064671069383621,
0.029107581824064255,
-0.041770003736019135,
-0.01208524126559496,
0.017697196453809738,
0.00995411816984415,
0.014109807088971138,
0.029125342145562172,
0.03354742005467415,
0.04670710489153862,
0.025093968957662582,
-0.012884411960840225,
0.05601300671696663,
0.022891808301210403,
-0.05842827633023262,
0.06986530125141144,
0.036211322993040085,
-0.0722450539469719,
0.05526711419224739,
0.07743078470230103,
0.07132156938314438,
0.020458776503801346,
-0.010362583212554455,
0.04848304018378258,
-0.0005799539503641427,
-0.051217980682849884,
-0.048127852380275726,
-0.05182179808616638,
0.028716877102851868,
-0.008044987916946411,
0.019677365198731422,
0.037969499826431274,
0.04454046115279198,
-0.06485716253519058,
0.06968770921230316,
0.038999542593955994,
0.03177148476243019,
0.01002515573054552,
-0.061092179268598557,
-0.035181280225515366,
-0.015672631561756134,
0.0032344225328415632,
0.034222278743982315,
-0.008373536169528961,
-0.005767350550740957,
-0.008373536169528961,
-0.016826989129185677,
-0.004586353432387114,
-0.06269052624702454,
0.026550235226750374,
-0.02656799554824829,
0.04422079399228096,
-0.015273044817149639,
0.012609141878783703,
-0.01522864680737257,
0.03345862403512001,
-0.011694535613059998,
-0.04237382113933563,
0.032322026789188385,
-0.05512503907084465,
-0.019499771296977997,
0.007396771106868982,
-0.009394698776304722,
-0.01383453793823719,
0.07970398664474487,
-0.01039810199290514,
0.031434059143066406,
0.0024907495826482773,
-0.011694535613059998,
-0.0044820173643529415,
-0.019055787473917007,
0.01284889318048954,
-0.030919037759304047,
0.0188959538936615,
0.030546089634299278,
-0.05697201192378998,
-0.0074678086675703526,
0.015166489407420158,
0.04269348829984665,
-0.02759803831577301,
-0.008773121051490307,
-0.0580020546913147,
-0.02834393084049225,
0.06176703795790672,
0.01807902380824089,
-0.06869318336248398,
0.05288735777139664,
-0.05952935665845871,
-0.028663598001003265,
0.05704304948449135,
0.08140888065099716,
0.10527745634317398,
0.004477577283978462,
0.012760096229612827,
-0.056119561195373535,
0.0025018490850925446,
0.039851993322372437,
-0.04290660098195076,
-0.03162940964102745,
-0.053917400538921356,
-0.03711705282330513,
-0.01175669301301241,
0.04283556342124939,
0.02532484009861946,
0.032322026789188385,
0.049974825233221054,
-0.004082431551069021,
0.025680027902126312,
-0.028805673122406006,
0.019677365198731422,
-0.014837941154837608,
-0.03683290258049965,
-0.0030990075320005417,
0.030475053936243057,
0.020245663821697235,
-0.026479197666049004,
0.015273044817149639,
0.002346454653888941,
0.052532173693180084,
0.09412457793951035,
-0.05310047045350075,
0.036655306816101074,
0.0224833432585001,
0.045357391238212585,
0.02701197937130928,
0.0004706229083240032,
0.01039810199290514,
0.012760096229612827,
0.014695866033434868,
-0.05448570102453232,
0.014349558390676975,
0.005061415955424309,
0.009323661215603352,
-0.010513538494706154,
-0.05864138901233673,
-0.020441018044948578,
-0.02145330049097538,
0.038040537387132645,
0.038253650069236755,
0.019144585356116295,
0.005256769247353077,
-0.052603207528591156,
0.02129346691071987,
-0.052461136132478714,
0.05334910377860069,
-0.01003403589129448,
0.057149603962898254,
-0.04912237450480461,
0.02100931666791439,
0.019002510234713554,
-0.0195530503988266,
-0.031132148578763008,
0.035394392907619476,
-0.07213850319385529,
0.03551870957016945,
0.013905574567615986,
-0.032552897930145264,
-0.01548615749925375,
-0.051075905561447144,
0.029782438650727272,
0.010531297884881496,
-0.015548314899206161,
0.007050463929772377,
-0.03010210581123829,
0.03864435479044914,
0.04695573449134827,
-0.09348524361848831,
-0.03786294534802437,
-0.0267278291285038,
0.03155837208032608,
0.07870946079492569,
-0.02628384530544281,
-0.029782438650727272,
0.040242698043584824,
0.06641998887062073,
0.005345565732568502,
0.012360511347651482,
-0.06404023617506027,
-0.01058457512408495,
-0.003749443916603923,
0.0035385515075176954,
0.062193259596824646,
-0.009856441989541054,
-0.005758470855653286,
0.02108035422861576,
-0.013568147085607052,
0.08702083677053452,
0.011667896062135696,
-0.006539882626384497,
-0.024152722209692,
-0.0736658051609993,
-0.07679145038127899,
0.05043656751513481,
-0.0057851099409163,
0.05423707142472267,
-0.01544175948947668,
-0.031807005405426025,
0.02717181295156479,
-0.0018902613082900643,
-0.041912078857421875,
-0.019730642437934875,
0.04251589626073837,
0.006917268969118595,
0.02644367888569832,
-0.00003877921699313447,
0.0411306656897068,
0.019304418936371803,
-0.04269348829984665,
-0.027562519535422325,
-0.053633250296115875,
-0.046458471566438675,
0.06240637227892876,
-0.004857183434069157,
-0.029338454827666283,
0.002228799043223262,
0.09561637043952942,
0.049015820026397705,
-0.05288735777139664,
0.017359768971800804,
0.05178627744317055,
-0.04571257904171944,
0.025537952780723572,
0.002623944776132703,
-0.0047195483930408955,
-0.03697497770190239,
0.010593455284833908,
-0.009936358779668808,
-0.02614177018404007,
-0.026603514328598976,
0.01997927390038967,
-0.07870946079492569,
-0.03038625605404377,
-0.0004234496154822409,
0.07153467833995819,
0.006215773988515139,
0.010406982153654099,
0.0009756545769050717,
0.02949828840792179,
0.004621872212737799,
0.023904092609882355,
-0.09384042769670486,
-0.015122090466320515,
0.09682400524616241,
0.05310047045350075,
-0.05072071775794029,
0.027988743036985397,
-0.0163208469748497,
-0.01200532354414463,
0.07267127931118011,
0.03413347899913788,
-0.023850813508033752,
0.035980451852083206,
0.006730795372277498,
0.007356812711805105,
-0.06155392527580261,
0.025378117337822914,
0.006158056203275919,
-0.0017437466885894537,
0.0013275117380544543,
0.031025592237710953,
-0.005301167257130146,
0.01868284121155739,
-0.021062595769762993,
-0.0026461437810212374,
-0.015770306810736656,
0.03814709559082985,
0.03475505858659744,
-0.002339794998988509,
-0.0339558869600296,
-0.006695276591926813,
-0.031434059143066406,
0.05221250280737877,
0.00030412894557230175,
-0.03878642991185188,
-0.007751958444714546,
0.019020268693566322,
-0.04578361660242081,
-0.059706952422857285,
0.04713332653045654,
-0.010930882766842842,
0.026852143928408623,
-0.020831722766160965,
0.02189728431403637,
-0.01672043278813362,
-0.042444858700037,
0.028095299378037453,
-0.005829508416354656,
-0.04116618633270264,
-0.0705401599407196,
0.024472391232848167,
0.013124163262546062,
-0.038999542593955994,
-0.031007833778858185,
0.038182612508535385,
-0.03477281704545021,
-0.026408160105347633,
-0.04656502977013588,
-0.000288034527329728,
-0.03088351897895336,
-0.060736995190382004,
0.015335203148424625,
-0.010176110081374645,
0.039567843079566956,
-0.04716884717345238,
-0.023708738386631012,
0.023175958544015884,
-0.047559551894664764,
0.0018491927767172456,
-0.03542991355061531,
-0.0031189867295324802,
-0.022607658058404922,
-0.015237526968121529,
0.01596565917134285,
-0.030634887516498566,
0.07089534401893616,
-0.01746632531285286,
-0.038395725190639496,
-0.0020012573804706335,
-0.009297022596001625,
0.019304418936371803,
-0.002124462742358446,
-0.022021600976586342,
0.014873459935188293,
0.006979426369071007,
0.05803757160902023,
-0.006655318196862936,
-0.012884411960840225,
0.00828917883336544,
0.042800046503543854,
0.0391061007976532,
0.03857331722974777,
0.024632224813103676,
0.041983116418123245,
-0.022643176838755608,
0.008013908751308918,
-0.021719690412282944,
-0.0076942406594753265,
0.04329730570316315,
-0.057362716645002365,
0.04123722389340401,
0.03821813315153122,
0.00988308060914278,
0.041841041296720505,
-0.025271562859416008,
-0.005936064291745424,
0.03843124583363533,
-0.02665679156780243,
0.016214290633797646,
-0.0005477651138789952,
0.022359028458595276,
0.06169600039720535,
-0.03946128487586975,
0.010779928416013718,
-0.04134377837181091,
-0.0808405801653862,
0.03471953794360161,
0.046742621809244156,
0.008151544257998466,
-0.020316701382398605,
0.002672782866284251,
-0.0022709774784743786,
-0.011099596507847309,
0.0019113505259156227,
0.0011987565085291862,
0.02964036352932453,
0.006140296813100576,
-0.06748554855585098,
0.026337122544646263,
-0.059635914862155914,
0.034222278743982315,
-0.0038981784600764513,
0.007436729967594147,
0.006588720716536045,
0.08368208259344101,
-0.006118097808212042,
0.007996149361133575,
-0.026834385469555855,
0.004186768084764481,
0.03242858126759529,
-0.062193259596824646,
0.006584280636161566,
-0.0017615059623494744,
-0.029604844748973846,
0.01866508275270462,
-0.0000034859672268794384,
0.008679884485900402,
-0.023016123101115227,
0.02466774359345436,
0.007569924928247929,
-0.005603076424449682,
0.06421782821416855,
0.08972026407718658,
-0.009279263205826283,
-0.016054457053542137,
-0.0072591365315020084,
-0.04269348829984665,
-0.004741747863590717,
-0.039709918200969696,
-0.01793694868683815,
-0.020334461703896523,
-0.019641846418380737,
0.002570666605606675,
0.0005610845983028412,
-0.002583986148238182,
0.06393367797136307,
-0.09433769434690475,
-0.004639631602913141,
-0.01786591112613678,
0.015610473230481148,
0.04503772407770157,
-0.05690097436308861,
0.06435990333557129,
0.03354742005467415,
-0.04372353106737137,
0.01072665024548769,
-0.020174626260995865,
-0.045641541481018066,
0.02651471644639969,
0.005931624677032232,
-0.046813659369945526,
0.08865469694137573,
-0.02086724154651165,
0.032908085733652115,
0.062264297157526016,
0.042942121624946594,
0.03155837208032608,
-0.016045577824115753,
-0.016303088515996933,
-0.08453452587127686,
-0.0060692597180604935,
0.05373980849981308,
-0.02093827910721302,
-0.04869615286588669,
-0.050187937915325165,
0.012724577449262142,
-0.028716877102851868,
0.05189283564686775,
-0.06531890481710434,
-0.029995551332831383,
-0.015832465142011642,
0.03542991355061531,
-0.01522864680737257,
-0.007743078749626875,
-0.02900102734565735,
0.0012187357060611248,
0.018469728529453278,
-0.029107581824064255,
0.0012997627491131425,
0.004060232546180487,
0.010673372074961662,
-0.05491192638874054,
-0.022962845861911774,
-0.03463074192404747,
-0.0115702198818326,
-0.007547725923359394,
0.009439096786081791,
-0.027544759213924408,
0.0038826388772577047,
0.09625570476055145,
-0.0430486761033535,
0.008329137228429317,
-0.029089823365211487,
-0.026301603764295578,
-0.0038182612042874098,
-0.031149908900260925,
0.018700601533055305,
-0.03654875233769417,
-0.006531002931296825,
-0.028130818158388138,
-0.0391061007976532,
-0.002901434665545821,
0.01772383600473404,
0.01880715601146221,
0.04276452586054802,
0.037294644862413406,
-0.034808333963155746,
-0.06240637227892876,
0.0054476819932460785,
-0.06173151731491089,
0.05381084606051445,
-0.015610473230481148,
0.029817957431077957,
0.06162496283650398,
0.0011965365847572684,
0.06105666235089302,
-0.003685066243633628,
-0.06148288771510124,
0.006033740937709808,
-0.0004462038050405681,
0.0046485112980008125,
0.008098266087472439,
0.038253650069236755,
-0.016942424699664116,
-0.055089518427848816,
-0.01501553412526846,
-0.014882339164614677,
0.028166336938738823,
-0.04461149871349335,
-0.009856441989541054,
0.009483495727181435,
-0.0091194286942482,
0.03281928971409798,
-0.024436872452497482,
-0.0199082363396883,
-0.01786591112613678,
-0.04098859056830406,
-0.05199939012527466,
0.018718359991908073,
0.011117355898022652,
-0.01749296486377716,
0.028219614177942276,
0.010771049186587334,
0.016303088515996933,
-0.0195530503988266,
0.014873459935188293,
-0.01599229872226715,
0.027189573273062706,
0.004233386367559433,
-0.05079175531864166,
0.03669082745909691,
-0.0014362878864631057,
-0.009341420605778694,
0.03768534958362579,
0.01746632531285286,
0.022820770740509033,
-0.03420451655983925,
0.012111879885196686,
-0.04141481593251228,
0.035696301609277725,
-0.07132156938314438,
-0.023193717002868652,
0.0042555853724479675,
0.02175520919263363,
-0.08716291189193726,
0.0052123707719147205,
0.029693640768527985,
0.005265648942440748,
-0.05192835256457329,
-0.0014917858643457294,
0.03361845761537552,
-0.04727540165185928,
-0.025822101160883904,
0.05111142247915268,
-0.035980451852083206,
0.009070590138435364,
-0.032108914107084274,
-0.037152569741010666,
-0.042196229100227356,
-0.029480529949069023,
-0.021027076989412308,
0.030439535155892372,
0.011792211793363094,
-0.016054457053542137,
0.018931472674012184,
-0.0016316407127305865,
0.020973797887563705,
0.02759803831577301,
-0.016560599207878113,
-0.016640515998005867,
0.002959152450785041,
-0.02145330049097538,
-0.06656206399202347,
-0.020902760326862335,
-0.016658274456858635,
-0.014473874121904373,
0.008329137228429317,
-0.01845197007060051,
0.0011621278245002031,
0.02928517572581768,
0.04134377837181091,
-0.00279265851713717,
0.008964034728705883,
0.02649695798754692,
-0.04471805691719055,
-0.024063926190137863,
0.015281924977898598,
-0.0055142794735729694,
-0.01786591112613678,
-0.04354593902826309,
-0.02283853106200695,
0.02834393084049225,
0.06404023617506027,
-0.010966401547193527,
-0.045144278556108475,
0.003292140318080783,
0.0456770621240139,
-0.003096787491813302
]
|
31,157 | networkx.generators.small | tetrahedral_graph |
Returns the 3-regular Platonic Tetrahedral graph.
Tetrahedral graph has 4 nodes and 6 edges. It is a
special case of the complete graph, K4, and wheel graph, W4.
It is one of the 5 platonic graphs [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
Tetrahedral Graph
References
----------
.. [1] https://en.wikipedia.org/wiki/Tetrahedron#Tetrahedral_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.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
]
|
31,159 | networkx.generators.geometric | thresholded_random_geometric_graph | 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
| 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, radius, theta, dim=2, pos=None, weight=None, p=2, seed=None, *, pos_name='pos', weight_name='weight', backend=None, **backend_kwargs) | [
0.02176172472536564,
-0.039482809603214264,
0.009755255654454231,
-0.024917270988225937,
0.018182873725891113,
0.009538793005049229,
-0.0625721737742424,
-0.016941819339990616,
0.023454943671822548,
-0.02476334199309349,
0.022877709940075874,
0.08058187365531921,
0.016220277175307274,
0.025552228093147278,
-0.060147788375616074,
-0.028996391221880913,
-0.011842918582260609,
0.009870702400803566,
-0.010111216455698013,
-0.055068131536245346,
-0.02691834792494774,
-0.0012795354705303907,
0.04806435853242874,
0.0579158179461956,
0.0054548620246350765,
-0.032960064709186554,
-0.05141231417655945,
0.04267683997750282,
-0.027476342394948006,
0.02791888825595379,
-0.04136843979358673,
-0.0639190524816513,
0.016431929543614388,
0.014767571352422237,
0.012776114046573639,
0.004815094172954559,
0.05510661378502846,
0.04313862696290016,
-0.06961442530155182,
-0.038520753383636475,
-0.010207422077655792,
-0.014450092799961567,
-0.025013476610183716,
-0.021415384486317635,
0.007297200616449118,
0.009524362161755562,
0.0675748661160469,
0.04698685184121132,
-0.04456247016787529,
-0.032767653465270996,
0.0144789544865489,
-0.0003538565069902688,
-0.006364005617797375,
-0.013536138460040092,
-0.029034873470664024,
-0.007855193689465523,
0.0016391042154282331,
-0.03147849813103676,
0.05187410116195679,
-0.032767653465270996,
0.03738552704453468,
0.012525979429483414,
0.04733319208025932,
-0.020453326404094696,
-0.03967522084712982,
-0.015489114448428154,
-0.05095052719116211,
-0.02772647701203823,
0.00006460060831159353,
0.0032036490738391876,
0.029804518446326256,
0.018134770914912224,
0.06368815898895264,
0.02539829909801483,
0.0014984034933149815,
0.016085589304566383,
0.062456727027893066,
-0.015999004244804382,
-0.016797510907053947,
-0.005733858328312635,
0.007095168810337782,
0.00037760729901492596,
0.023474184796214104,
-0.06149467080831528,
0.009928425773978233,
-0.02435927838087082,
0.014142234809696674,
0.04748712107539177,
0.05618411675095558,
-0.06711307913064957,
-0.018663901835680008,
0.014902259223163128,
0.02126145549118519,
0.003396060550585389,
0.05468330904841423,
0.020414844155311584,
0.05510661378502846,
-0.003814555238932371,
0.046178724616765976,
0.008129379712045193,
-0.0011767157120630145,
0.010524901561439037,
-0.07146158069372177,
0.04652506485581398,
-0.013478415086865425,
-0.03617333620786667,
-0.038289859890937805,
0.01263180561363697,
0.011179099790751934,
-0.001705245696939528,
-0.04506273940205574,
-0.024705618619918823,
0.050565704703330994,
0.0028549034614115953,
0.048872485756874084,
-0.0017641716403886676,
-0.05472179129719734,
0.021684760227799416,
0.007624300196766853,
-0.010245904326438904,
0.02366659604012966,
0.0038073398172855377,
-0.009630188345909119,
0.01837528496980667,
-0.007431888487190008,
0.021280696615576744,
0.04240746423602104,
-0.028765497729182243,
-0.016845613718032837,
-0.018644660711288452,
0.016528135165572166,
0.012170018628239632,
0.05395214259624481,
0.07134613394737244,
-0.03388363867998123,
0.0034682147670537233,
-0.05337490886449814,
0.010688451118767262,
0.0695374608039856,
-0.023339496925473213,
0.029342731460928917,
-0.09989997744560242,
0.00925498642027378,
0.019722163677215576,
0.036692846566438675,
0.009837030433118343,
-0.007758988067507744,
-0.03524976223707199,
0.029862241819500923,
-0.03844378888607025,
0.03515355661511421,
-0.059955377131700516,
0.058454569429159164,
-0.020953597500920296,
-0.003905950579792261,
-0.018221355974674225,
0.028842462226748466,
-0.048410698771476746,
-0.05987841263413429,
-0.028149781748652458,
0.017913497984409332,
0.006056147627532482,
0.018298320472240448,
0.016624340787529945,
-0.03621181845664978,
0.004006966482847929,
0.0712306872010231,
-0.06903719156980515,
0.009837030433118343,
-0.00254223495721817,
-0.055799294263124466,
-0.044947292655706406,
-0.011284925974905491,
0.0008899025269784033,
-0.04279228672385216,
0.03321019932627678,
-0.006599709391593933,
-0.012198880314826965,
-0.0625721737742424,
-0.026071738451719284,
-0.004358117002993822,
-0.034422390162944794,
-0.0009103462216444314,
0.010399834252893925,
-0.018134770914912224,
0.07350113987922668,
0.04575541988015175,
-0.016941819339990616,
-0.030458718538284302,
0.005685755517333746,
-0.059955377131700516,
-0.02003002166748047,
0.030208582058548927,
0.04209960624575615,
0.06134074181318283,
0.0007690441561862826,
0.032632965594530106,
0.03340261057019234,
-0.11475413292646408,
0.08581546694040298,
0.06834451109170914,
0.006484262645244598,
0.018086668103933334,
-0.03857847675681114,
-0.010592245496809483,
-0.023916730657219887,
-0.02499423548579216,
-0.005166244693100452,
0.03967522084712982,
0.017576778307557106,
0.016912957653403282,
-0.001969811273738742,
0.01546025276184082,
0.04510122165083885,
-0.028534604236483574,
-0.00019075782620348036,
-0.018442628905177116,
0.01281459629535675,
-0.047910429537296295,
-0.043446484953165054,
-0.03467252478003502,
0.014584780670702457,
-0.01650889404118061,
-0.011256064288318157,
0.054529380053281784,
0.01537366770207882,
0.007273149210959673,
-0.03644271194934845,
0.03634650632739067,
-0.05753099545836449,
0.0912029817700386,
-0.0502578467130661,
0.06110984832048416,
-0.028245987370610237,
-0.02216578833758831,
-0.04529363289475441,
0.014199958182871342,
0.0007437901222147048,
-0.002189881633967161,
0.02070346102118492,
-0.004634708631783724,
-0.04648658260703087,
-0.05341339111328125,
0.030208582058548927,
0.04971909523010254,
-0.013026248663663864,
-0.005204727407544851,
-0.02066497877240181,
0.08458403497934341,
-0.0011274103308096528,
-0.05764644220471382,
-0.05218195915222168,
-0.012968525290489197,
-0.013160936534404755,
0.0231278445571661,
-0.02915032021701336,
-0.003992535639554262,
-0.030997470021247864,
0.020953597500920296,
0.020780427381396294,
-0.023685837164521217,
0.002384698251262307,
-0.03503810614347458,
0.04610176011919975,
0.03474948927760124,
-0.016912957653403282,
-0.05368276685476303,
0.047102298587560654,
-0.02166551910340786,
-0.04113754630088806,
-0.051335349678993225,
0.011034791357815266,
0.06411146372556686,
-0.0021754507906734943,
0.043677378445863724,
-0.03857847675681114,
0.010573004372417927,
0.046640511602163315,
0.03305627033114433,
0.012439394369721413,
-0.047102298587560654,
0.013651586137712002,
0.02216578833758831,
-0.008908646181225777,
-0.055760812014341354,
0.06680522114038467,
-0.08065883815288544,
0.0132282804697752,
0.012747252359986305,
-0.051296867430210114,
-0.0442546121776104,
-0.016124071553349495,
-0.02755330689251423,
0.007884055376052856,
0.022569851949810982,
0.016364585608243942,
0.027168484404683113,
-0.01226622425019741,
0.012756872922182083,
-0.03197876736521721,
0.13222508132457733,
-0.019953057169914246,
0.04448550567030907,
-0.04998847097158432,
0.05333642661571503,
0.05064266920089722,
0.012381670996546745,
-0.019096827134490013,
-0.04756408557295799,
0.025071199983358383,
-0.03707766905426979,
-0.01810590922832489,
0.041984159499406815,
0.012246983125805855,
0.025648433715105057,
-0.10744249820709229,
0.02376280166208744,
-0.06576620042324066,
0.023474184796214104,
-0.007475181017071009,
-0.007071117404848337,
0.0029270576778799295,
-0.0472562275826931,
0.035057347267866135,
-0.06934504956007004,
-0.042253535240888596,
0.021915653720498085,
0.03986763209104538,
-0.004194567445665598,
-0.002438813913613558,
-0.025340575724840164,
0.053028568625450134,
0.017499811947345734,
-0.010957826860249043,
-0.0529131218791008,
0.07811900973320007,
0.05564536526799202,
0.02988148294389248,
-0.015441011637449265,
-0.05818519368767738,
0.005555877927690744,
-0.030805058777332306,
0.0165569968521595,
0.058454569429159164,
-0.01610483042895794,
-0.01502732653170824,
0.002408749656751752,
-0.023108603432774544,
-0.001239850651472807,
-0.05218195915222168,
0.07592552155256271,
0.037424009293317795,
-0.03269068896770477,
0.014430851675570011,
0.02691834792494774,
-0.001837528427131474,
0.01541214995086193,
0.03251751884818077,
-0.003901140298694372,
0.0705764889717102,
-0.014151855371892452,
-0.006503503769636154,
0.04306166246533394,
0.016316482797265053,
0.022185029461979866,
0.039251916110515594,
0.02133841998875141,
0.06307244300842285,
-0.005055608227849007,
-0.021107526496052742,
0.010332489386200905,
-0.08373742550611496,
-0.11590860038995743,
0.017451709136366844,
0.026706695556640625,
-0.018683142960071564,
-0.03307551145553589,
-0.012391291558742523,
-0.002501347567886114,
0.036692846566438675,
-0.014998464845120907,
0.005955131258815527,
0.0319402851164341,
0.009918805211782455,
-0.014873397536575794,
-0.011583163402974606,
0.03703918680548668,
0.054529380053281784,
0.013382209464907646,
-0.02668745443224907,
-0.055299025028944016,
-0.043446484953165054,
0.05071963369846344,
0.05514509603381157,
0.006825793068856001,
0.04748712107539177,
0.06484262645244598,
0.03634650632739067,
-0.07330872863531113,
-0.0029559193644672632,
0.014690606854856014,
-0.025109682232141495,
-0.01769222505390644,
-0.052066512405872345,
-0.019991539418697357,
-0.005753099452704191,
-0.015392908826470375,
-0.012641426175832748,
0.055068131536245346,
0.010861621238291264,
0.027938129380345345,
0.014238440431654453,
0.011188720352947712,
0.0008490151376463473,
0.02509044110774994,
-0.03486493602395058,
-0.0044711590744555,
0.05245133489370346,
0.0043941945768892765,
-0.026418078690767288,
0.040714241564273834,
-0.08073580265045166,
0.026783660054206848,
0.008653700351715088,
0.003946837969124317,
0.02079966850578785,
0.00868737231940031,
-0.03542293235659599,
-0.007008583750575781,
0.051566243171691895,
-0.020376361906528473,
0.00575790973380208,
0.002293302910402417,
0.026071738451719284,
0.038520753383636475,
-0.04217657074332237,
-0.017913497984409332,
-0.015806593000888824,
-0.049411237239837646,
-0.020876633003354073,
0.02988148294389248,
0.009683101437985897,
0.029169561341404915,
-0.04167630150914192,
0.006085009314119816,
-0.003939622547477484,
0.0039179762825369835,
0.010322868824005127,
0.008365083485841751,
-0.007263528648763895,
0.05860849842429161,
0.006440970115363598,
0.07684909552335739,
0.04775649681687355,
-0.0462556891143322,
0.0629185140132904,
-0.03426846116781235,
0.01366120669990778,
-0.03132456913590431,
0.0047092679888010025,
0.035134315490722656,
0.007951399311423302,
-0.06468869745731354,
-0.018490731716156006,
0.006335143931210041,
-0.020626496523618698,
-0.0005507775349542499,
-0.0018098693108186126,
0.0067488281056284904,
-0.0011725067161023617,
0.08350653201341629,
-0.01124644372612238,
-0.036596640944480896,
-0.044716399163007736,
0.01916417106986046,
0.015604561194777489,
-0.07842686772346497,
0.04806435853242874,
0.005267261061817408,
-0.030805058777332306,
0.022204270586371422,
-0.00723947724327445,
0.03068961203098297,
-0.0008947128080762923,
-0.0339413620531559,
-0.0419456772506237,
-0.007566576357930899,
0.008129379712045193,
0.02818826399743557,
-0.061917975544929504,
-0.031266845762729645,
-0.004678001161664724,
0.049873024225234985,
0.008009122684597969,
-0.0231278445571661,
0.028399916365742683,
-0.014305784367024899,
-0.025282852351665497,
0.03834758326411247,
-0.010390213690698147,
-0.02097283862531185,
0.02859232760965824,
0.0005853514303453267,
0.02133841998875141,
0.06495807319879532,
-0.04313862696290016,
0.07203881442546844,
0.012208500877022743,
0.029535142704844475,
0.04529363289475441,
0.05318249762058258,
0.05830064043402672,
0.05564536526799202,
0.013670827262103558,
0.007152892183512449,
0.0008995230891741812,
-0.018134770914912224,
0.023377979174256325,
-0.013237901031970978,
-0.04844918102025986,
0.04848766326904297,
0.06826754659414291,
0.005955131258815527,
0.019914574921131134,
0.013632345013320446,
-0.015210118144750595,
0.04086817055940628,
-0.04429309442639351,
0.011207961477339268,
0.037424009293317795,
0.03324868157505989,
0.009721583686769009,
-0.06087895482778549,
0.014959982596337795,
-0.011842918582260609,
0.028938667848706245,
-0.021819448098540306,
0.003501886734738946,
-0.02859232760965824,
-0.03813593089580536,
0.008220775052905083,
-0.005353846121579409,
0.013949823565781116,
0.020280156284570694,
0.030593406409025192,
0.0472562275826931,
0.030170099809765816,
-0.022088823840022087,
-0.04906489700078964,
-0.03921343386173248,
0.07184640318155289,
-0.0015789757017046213,
-0.08927886933088303,
-0.059185732156038284,
0.09697532653808594,
-0.024243831634521484,
0.008110138587653637,
-0.0349419005215168,
-0.00003494972042972222,
0.04190719500184059,
-0.045678455382585526,
-0.06776727735996246,
-0.01660509966313839,
-0.004151274915784597,
-0.03238283097743988,
-0.016393447294831276,
-0.0436004139482975,
0.041483890265226364,
-0.03074733540415764,
0.009452207945287228,
0.03936736285686493,
0.03147849813103676,
0.020260915160179138,
-0.02659124881029129,
0.015335185453295708,
-0.006306282244622707,
-0.042022641748189926,
0.006460211239755154,
-0.017884636297822,
-0.01965481974184513,
-0.015315944328904152,
0.00020143063738942146,
0.03230586647987366,
0.008485340513288975,
-0.023320255801081657,
0.04113754630088806,
-0.05814671143889427,
0.0312860868871212,
0.006998963188380003,
0.0312860868871212,
0.05349035561084747,
0.00007613777415826917,
0.04548604413866997,
-0.019125688821077347,
-0.03038175404071808,
0.01537366770207882,
0.00747037073597312,
0.014132614247500896,
-0.0005652083782479167,
-0.03092050552368164,
-0.026745177805423737,
0.030439477413892746,
-0.02845763973891735,
0.003638979746028781,
-0.04310014471411705,
0.00747037073597312,
0.014931120909750462,
-0.030939746648073196,
0.02968907169997692,
-0.05583777651190758,
-0.029227284714579582,
-0.002444826764985919,
-0.03330640494823456,
-0.026995312422513962,
-0.011583163402974606,
0.0003021459560841322,
-0.06942201405763626,
0.06518896669149399,
0.018663901835680008,
-0.025975532829761505,
-0.02809205837547779,
-0.010399834252893925,
0.06049412861466408,
-0.007143271621316671,
0.026899106800556183,
-0.04333103820681572,
-0.014440472237765789,
-0.0425998754799366,
-0.04856462776660919,
0.04310014471411705,
-0.03340261057019234,
-0.04771801456809044,
-0.01146771665662527,
-0.02782268263399601,
-0.07465560734272003,
-0.024840306490659714,
0.014690606854856014,
-0.030035411939024925,
-0.0037688573356717825,
0.016047107055783272,
-0.04775649681687355,
0.02772647701203823,
-0.04217657074332237,
-0.049834541976451874,
-0.011592783965170383,
-0.020915115252137184,
0.028015093877911568,
0.024070661514997482,
0.009404105134308338,
-0.06803665310144424,
-0.040213972330093384,
0.018125150352716446,
0.013074351474642754,
-0.017624881118535995,
0.028207505121827126,
0.017961600795388222,
-0.022281235083937645,
-0.008071656338870525,
0.020106986165046692,
-0.021819448098540306,
0.014507816173136234,
0.05187410116195679,
0.047602567821741104,
0.057261619716882706,
-0.02170400135219097,
0.03101671114563942,
0.028476880863308907,
-0.03438390791416168,
0.03784731402993202,
0.0003643789968919009,
-0.01850997284054756,
-0.01374779175966978,
0.043446484953165054,
0.0001758760045049712,
-0.00859597697854042,
0.019953057169914246,
-0.008129379712045193,
0.028476880863308907,
-0.06476566195487976,
-0.02389748953282833,
0.10567231476306915,
0.029592866078019142,
-0.033691227436065674,
-0.019125688821077347,
0.0529131218791008,
0.054798755794763565,
-0.03813593089580536,
-0.0529131218791008,
0.03205573186278343,
0.058454569429159164,
-0.01244901493191719,
0.03105519339442253,
0.06399601697921753,
0.03727008029818535,
0.037424009293317795,
-0.0043677375651896,
-0.04267683997750282,
0.007234666962176561,
0.035192038863897324,
-0.03703918680548668,
0.03698146343231201,
-0.01281459629535675,
-0.045678455382585526,
0.05964751914143562,
-0.024647895246744156,
-0.02266605757176876,
-0.02139614336192608,
0.023935973644256592,
0.02083815075457096,
-0.01008235476911068,
-0.07134613394737244,
-0.013872859068214893,
0.030497200787067413,
-0.04006004333496094,
-0.04956516623497009,
0.0319402851164341,
0.0144789544865489,
-0.0030400995165109634,
-0.05460634455084801,
-0.05987841263413429,
0.0018567695515230298,
0.0017473356565460563,
-0.04402371868491173,
0.03467252478003502,
-0.017528673633933067,
0.003828986082226038,
0.03567306697368622,
-0.11652431637048721,
-0.0036510054487735033,
-0.013641965575516224,
0.01489263866096735,
0.04013700783252716,
-0.011323408223688602,
0.016845613718032837,
0.007191374432295561,
0.012699149549007416,
-0.014652124606072903,
0.03707766905426979,
-0.04633265361189842,
0.04775649681687355,
-0.017182333394885063,
0.027803441509604454,
-0.0377703495323658,
-0.04056031256914139,
0.009918805211782455,
-0.01943354681134224,
0.00366543629206717,
-0.009197263047099113,
0.005098900757730007,
0.025648433715105057,
0.025513745844364166,
0.024513207376003265,
0.03192104399204254,
-0.0032589673064649105,
-0.018779348582029343,
0.060417164117097855,
-0.030939746648073196,
-0.04529363289475441,
-0.025340575724840164,
-0.03640422970056534,
-0.04236898198723793,
-0.015296703204512596,
-0.017230436205863953,
0.002026332076638937,
-0.03292158246040344,
0.03326792269945145,
0.005502964835613966,
0.05095052719116211
]
|
31,162 | networkx.convert | to_dict_of_dicts | Returns adjacency representation of graph as a dictionary of dictionaries.
Parameters
----------
G : graph
A NetworkX graph
nodelist : list
Use only nodes specified in nodelist
edge_data : scalar, optional
If provided, the value of the dictionary will be set to `edge_data` for
all edges. Usual values could be `1` or `True`. If `edge_data` is
`None` (the default), the edgedata in `G` is used, resulting in a
dict-of-dict-of-dicts. If `G` is a MultiGraph, the result will be a
dict-of-dict-of-dict-of-dicts. See Notes for an approach to customize
handling edge data. `edge_data` should *not* be a container.
Returns
-------
dod : dict
A nested dictionary representation of `G`. Note that the level of
nesting depends on the type of `G` and the value of `edge_data`
(see Examples).
See Also
--------
from_dict_of_dicts, to_dict_of_lists
Notes
-----
For a more custom approach to handling edge data, try::
dod = {
n: {nbr: custom(n, nbr, dd) for nbr, dd in nbrdict.items()}
for n, nbrdict in G.adj.items()
}
where `custom` returns the desired edge data for each edge between `n` and
`nbr`, given existing edge data `dd`.
Examples
--------
>>> G = nx.path_graph(3)
>>> nx.to_dict_of_dicts(G)
{0: {1: {}}, 1: {0: {}, 2: {}}, 2: {1: {}}}
Edge data is preserved by default (``edge_data=None``), resulting
in dict-of-dict-of-dicts where the innermost dictionary contains the
edge data:
>>> G = nx.Graph()
>>> G.add_edges_from(
... [
... (0, 1, {"weight": 1.0}),
... (1, 2, {"weight": 2.0}),
... (2, 0, {"weight": 1.0}),
... ]
... )
>>> d = nx.to_dict_of_dicts(G)
>>> d # doctest: +SKIP
{0: {1: {'weight': 1.0}, 2: {'weight': 1.0}},
1: {0: {'weight': 1.0}, 2: {'weight': 2.0}},
2: {1: {'weight': 2.0}, 0: {'weight': 1.0}}}
>>> d[1][2]["weight"]
2.0
If `edge_data` is not `None`, edge data in the original graph (if any) is
replaced:
>>> d = nx.to_dict_of_dicts(G, edge_data=1)
>>> d
{0: {1: 1, 2: 1}, 1: {0: 1, 2: 1}, 2: {1: 1, 0: 1}}
>>> d[1][2]
1
This also applies to MultiGraphs: edge data is preserved by default:
>>> G = nx.MultiGraph()
>>> G.add_edge(0, 1, key="a", weight=1.0)
'a'
>>> G.add_edge(0, 1, key="b", weight=5.0)
'b'
>>> d = nx.to_dict_of_dicts(G)
>>> d # doctest: +SKIP
{0: {1: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}},
1: {0: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}}}
>>> d[0][1]["b"]["weight"]
5.0
But multi edge data is lost if `edge_data` is not `None`:
>>> d = nx.to_dict_of_dicts(G, edge_data=10)
>>> d
{0: {1: 10}, 1: {0: 10}}
| def to_dict_of_dicts(G, nodelist=None, edge_data=None):
"""Returns adjacency representation of graph as a dictionary of dictionaries.
Parameters
----------
G : graph
A NetworkX graph
nodelist : list
Use only nodes specified in nodelist
edge_data : scalar, optional
If provided, the value of the dictionary will be set to `edge_data` for
all edges. Usual values could be `1` or `True`. If `edge_data` is
`None` (the default), the edgedata in `G` is used, resulting in a
dict-of-dict-of-dicts. If `G` is a MultiGraph, the result will be a
dict-of-dict-of-dict-of-dicts. See Notes for an approach to customize
handling edge data. `edge_data` should *not* be a container.
Returns
-------
dod : dict
A nested dictionary representation of `G`. Note that the level of
nesting depends on the type of `G` and the value of `edge_data`
(see Examples).
See Also
--------
from_dict_of_dicts, to_dict_of_lists
Notes
-----
For a more custom approach to handling edge data, try::
dod = {
n: {nbr: custom(n, nbr, dd) for nbr, dd in nbrdict.items()}
for n, nbrdict in G.adj.items()
}
where `custom` returns the desired edge data for each edge between `n` and
`nbr`, given existing edge data `dd`.
Examples
--------
>>> G = nx.path_graph(3)
>>> nx.to_dict_of_dicts(G)
{0: {1: {}}, 1: {0: {}, 2: {}}, 2: {1: {}}}
Edge data is preserved by default (``edge_data=None``), resulting
in dict-of-dict-of-dicts where the innermost dictionary contains the
edge data:
>>> G = nx.Graph()
>>> G.add_edges_from(
... [
... (0, 1, {"weight": 1.0}),
... (1, 2, {"weight": 2.0}),
... (2, 0, {"weight": 1.0}),
... ]
... )
>>> d = nx.to_dict_of_dicts(G)
>>> d # doctest: +SKIP
{0: {1: {'weight': 1.0}, 2: {'weight': 1.0}},
1: {0: {'weight': 1.0}, 2: {'weight': 2.0}},
2: {1: {'weight': 2.0}, 0: {'weight': 1.0}}}
>>> d[1][2]["weight"]
2.0
If `edge_data` is not `None`, edge data in the original graph (if any) is
replaced:
>>> d = nx.to_dict_of_dicts(G, edge_data=1)
>>> d
{0: {1: 1, 2: 1}, 1: {0: 1, 2: 1}, 2: {1: 1, 0: 1}}
>>> d[1][2]
1
This also applies to MultiGraphs: edge data is preserved by default:
>>> G = nx.MultiGraph()
>>> G.add_edge(0, 1, key="a", weight=1.0)
'a'
>>> G.add_edge(0, 1, key="b", weight=5.0)
'b'
>>> d = nx.to_dict_of_dicts(G)
>>> d # doctest: +SKIP
{0: {1: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}},
1: {0: {'a': {'weight': 1.0}, 'b': {'weight': 5.0}}}}
>>> d[0][1]["b"]["weight"]
5.0
But multi edge data is lost if `edge_data` is not `None`:
>>> d = nx.to_dict_of_dicts(G, edge_data=10)
>>> d
{0: {1: 10}, 1: {0: 10}}
"""
dod = {}
if nodelist is None:
if edge_data is None:
for u, nbrdict in G.adjacency():
dod[u] = nbrdict.copy()
else: # edge_data is not None
for u, nbrdict in G.adjacency():
dod[u] = dod.fromkeys(nbrdict, edge_data)
else: # nodelist is not None
if edge_data is None:
for u in nodelist:
dod[u] = {}
for v, data in ((v, data) for v, data in G[u].items() if v in nodelist):
dod[u][v] = data
else: # nodelist and edge_data are not None
for u in nodelist:
dod[u] = {}
for v in (v for v in G[u] if v in nodelist):
dod[u][v] = edge_data
return dod
| (G, nodelist=None, edge_data=None) | [
-0.0011693969136103988,
0.0238039493560791,
-0.02147022821009159,
-0.021652866154909134,
-0.005367557052522898,
-0.005600929260253906,
-0.0025201644748449326,
-0.010364762507379055,
0.07536902278661728,
-0.06481654942035675,
-0.0009861236903816462,
-0.00014982104767113924,
-0.01406320184469223,
0.014570532366633415,
0.002823294373229146,
-0.031231267377734184,
-0.007011307869106531,
0.016488242894411087,
0.014570532366633415,
0.02899901382625103,
0.02349955029785633,
-0.07106686383485794,
0.034701406955718994,
0.022687820717692375,
-0.03155595809221268,
-0.03478258103132248,
-0.016051938757300377,
0.03350410982966423,
0.009695086628198624,
0.06883460283279419,
-0.001553699723444879,
-0.07910297811031342,
-0.032550327479839325,
0.03666985034942627,
0.03614222630858421,
0.03662926331162453,
-0.010420569218695164,
-0.009010190144181252,
-0.11226209998130798,
-0.009958898648619652,
-0.005403070244938135,
-0.04149963706731796,
-0.05958089604973793,
-0.0016488241963088512,
0.03900356963276863,
0.006534417159855366,
0.011039512231945992,
-0.0030135433189570904,
0.014986543916165829,
-0.06380188465118408,
0.013799390755593777,
-0.06453244388103485,
0.00510374503210187,
0.04395511746406555,
0.01828419230878353,
-0.0388818122446537,
-0.012713703326880932,
-0.004119523800909519,
0.012845609337091446,
-0.0008890967583283782,
0.0002663485356606543,
0.0019709791522473097,
-0.019217681139707565,
-0.0310080423951149,
-0.036466918885707855,
0.016478095203638077,
-0.04667440801858902,
-0.06879401952028275,
-0.05726746842265129,
0.004677587654441595,
-0.030703643336892128,
-0.023012513294816017,
0.0021548864897340536,
-0.014570532366633415,
0.02684793248772621,
0.03390997275710106,
0.03610163927078247,
0.017076745629310608,
-0.030358659103512764,
0.0530058927834034,
0.01770583540201187,
-0.03332147002220154,
-0.04249400645494461,
0.025691218674182892,
0.0597432442009449,
-0.001906294492073357,
0.042088139802217484,
0.09464758634567261,
0.0074222455732524395,
-0.05231592431664467,
-0.02244430221617222,
-0.016275163739919662,
0.011830948293209076,
0.04724261909723282,
0.032672084867954254,
-0.054994627833366394,
-0.014154521748423576,
-0.025691218674182892,
0.042696937918663025,
0.03259091451764107,
-0.06721115112304688,
0.015534460544586182,
-0.06794170290231705,
-0.005890107247978449,
-0.014174815267324448,
-0.10041085630655289,
-0.030216606333851814,
-0.008157874457538128,
-0.03234739601612091,
-0.08141640573740005,
-0.11648309230804443,
0.009553033858537674,
0.013576164841651917,
0.019958382472395897,
0.03886151686310768,
0.031819771975278854,
0.023418378084897995,
0.013779097236692905,
-0.0018809279426932335,
-0.028004644438624382,
-0.05641515552997589,
0.08807258307933807,
-0.025589751079678535,
0.015027130022644997,
-0.0024986029602587223,
-0.010303882881999016,
0.018598737195134163,
-0.023296618834137917,
0.01370807085186243,
0.013829830102622509,
0.06396423280239105,
0.01035461574792862,
-0.03218504786491394,
0.020688939839601517,
0.06863167136907578,
-0.01797979325056076,
-0.056009288877248764,
0.02843080274760723,
0.04188520833849907,
0.018639324232935905,
0.012825315818190575,
-0.07228445261716843,
0.026766758412122726,
0.029932500794529915,
0.005687175318598747,
0.012531064450740814,
0.028369924053549767,
-0.024128640070557594,
-0.03666985034942627,
-0.022992219775915146,
0.039774712175130844,
0.006803302560001612,
0.010491595603525639,
-0.008335440419614315,
-0.03346352279186249,
-0.030764523893594742,
-0.03462023660540581,
-0.04460449889302254,
-0.04829786717891693,
0.003944494761526585,
-0.0192988533526659,
-0.010045144706964493,
0.015483727678656578,
-0.027639366686344147,
0.0017566320020705462,
0.014844491146504879,
0.03216475620865822,
-0.0527217872440815,
0.04160110279917717,
-0.02437215857207775,
-0.02782200649380684,
0.007173653692007065,
-0.03445788845419884,
-0.01842624507844448,
0.012947075068950653,
0.031819771975278854,
0.05434524640440941,
-0.0030084699392318726,
-0.01972501166164875,
0.032692380249500275,
0.047892000526189804,
-0.024575090035796165,
-0.0027725612744688988,
0.05304647982120514,
0.023134272545576096,
-0.008847844786942005,
0.018304485827684402,
0.017939208075404167,
0.01565621979534626,
0.010542328469455242,
0.02203843742609024,
-0.009669720195233822,
0.009395761415362358,
0.06863167136907578,
0.024453330785036087,
-0.027456728741526604,
-0.012429597787559032,
-0.010491595603525639,
0.00008323391375597566,
0.11177506297826767,
0.002879100851714611,
-0.031231267377734184,
0.022870460525155067,
0.0004185476864222437,
-0.042696937918663025,
-0.005803861189633608,
0.030196312814950943,
-0.016011351719498634,
-0.01739129051566124,
0.022079024463891983,
-0.021632574498653412,
-0.025447700172662735,
0.034701406955718994,
-0.024006880819797516,
-0.0245142113417387,
-0.01651868224143982,
0.026908811181783676,
0.05479169636964798,
-0.05816037207841873,
-0.05438583344221115,
-0.05069246515631676,
0.01122215110808611,
-0.042981043457984924,
0.00790928304195404,
0.005824154708534479,
-0.061975497752428055,
-0.0026989984326064587,
0.008944237604737282,
0.04785141721367836,
-0.008533299900591373,
0.04137787967920303,
0.009492154233157635,
-0.004890666343271732,
-0.015889592468738556,
0.08121347427368164,
-0.019938088953495026,
-0.0208614319562912,
-0.04149963706731796,
0.015260502696037292,
0.005702394992113113,
-0.0012309106532484293,
-0.05584694445133209,
-0.02418951876461506,
-0.014012468978762627,
0.029242532327771187,
-0.041073478758335114,
0.05166654288768768,
-0.0030236898455768824,
0.003467604285106063,
-0.02203843742609024,
-0.03437671810388565,
-0.0005288920947350562,
0.03141390532255173,
0.007934649474918842,
-0.02216019667685032,
0.057632748037576675,
-0.03330117464065552,
-0.01064379420131445,
-0.04927194118499756,
-0.035147860646247864,
0.07037688791751862,
0.009816845878958702,
-0.052965305745601654,
0.006727202795445919,
0.03953119367361069,
0.02839021570980549,
0.02623913437128067,
-0.0036756095942109823,
-0.036608971655368805,
0.009476934559643269,
0.06899695098400116,
-0.03579724207520485,
0.04927194118499756,
-0.03115009516477585,
0.02636089362204075,
-0.00026825102395378053,
0.018740789964795113,
0.0018238532356917858,
0.03727864846587181,
0.018507417291402817,
-0.03372733294963837,
-0.0009474397520534694,
-0.06384247541427612,
-0.01000455766916275,
-0.020942604169249535,
0.05483228340744972,
-0.02954692952334881,
0.038475945591926575,
0.04387394338846207,
-0.012186079286038876,
0.07581547647714615,
-0.016265016049146652,
-0.00666632317006588,
0.03997764736413956,
-0.03421436995267868,
0.03955148905515671,
-0.007615031208842993,
-0.029262825846672058,
0.058525651693344116,
0.07122920453548431,
0.07695189118385315,
-0.0022652307525277138,
0.06327426433563232,
0.02711174264550209,
0.02147022821009159,
0.020059850066900253,
0.0623001903295517,
0.015717100352048874,
-0.04813551902770996,
0.005803861189633608,
-0.055887531489133835,
0.014458919875323772,
0.03149507939815521,
0.08579973876476288,
-0.04894724860787392,
-0.0518694743514061,
-0.0030008601024746895,
-0.03190094232559204,
0.041093774139881134,
0.012987661175429821,
-0.04379277303814888,
0.07784479856491089,
0.008817404508590698,
0.02058747224509716,
0.010836579836905003,
-0.0048779831267893314,
0.10308956354856491,
0.09773215651512146,
0.10909635573625565,
0.0000019272615645604674,
-0.02609708160161972,
-0.04184462130069733,
0.00855359248816967,
0.04898783564567566,
-0.05828212946653366,
0.04764848202466965,
0.07459788024425507,
-0.0005780397332273424,
-0.0385977067053318,
-0.006108259782195091,
-0.008568813093006611,
0.025873856619000435,
0.005063158459961414,
-0.014763318002223969,
0.005869814194738865,
-0.0015207232208922505,
0.007863623090088367,
-0.022079024463891983,
-0.005874887574464083,
-0.0034447743091732264,
-0.02755819447338581,
0.09229356795549393,
-0.011800508014857769,
0.04354925453662872,
-0.03202270343899727,
-0.05004308372735977,
0.025975322350859642,
-0.0608796626329422,
0.014996690675616264,
0.014408187009394169,
-0.01448936015367508,
0.051260676234960556,
0.004005374386906624,
-0.004601487889885902,
0.04184462130069733,
0.014225548133254051,
-0.027761125937104225,
0.05706453695893288,
0.05564401298761368,
-0.027659660205245018,
0.013312352821230888,
-0.0620160847902298,
-0.03439700976014137,
0.02463597059249878,
0.019958382472395897,
0.042088139802217484,
-0.005864740815013647,
0.025894150137901306,
-0.000335155229549855,
0.030399246141314507,
-0.022647235542535782,
-0.02477802336215973,
-0.011039512231945992,
0.002676168456673622,
0.06510065495967865,
-0.017726128920912743,
0.13117538392543793,
0.028613442555069923,
-0.0030896428506821394,
-0.059377964586019516,
-0.05462935194373131,
0.00790928304195404,
0.048338454216718674,
0.03800920397043228,
-0.024148933589458466,
-0.002176448004320264,
0.020617913454771042,
-0.019359733909368515,
-0.009659573435783386,
-0.02770024724304676,
-0.008335440419614315,
-0.010243003256618977,
-0.008381100371479988,
0.006158992648124695,
0.04085025563836098,
-0.027314675971865654,
-0.007239606697112322,
-0.02278928831219673,
0.07143213599920273,
0.008863064460456371,
0.02727408893406391,
0.053411759436130524,
0.00005370569124352187,
0.05337117239832878,
0.06522241234779358,
0.06148846074938774,
0.030115140601992607,
0.03293589875102043,
0.06311191618442535,
0.017898621037602425,
0.0513012632727623,
0.00038018080522306263,
0.059662070125341415,
0.0084876399487257,
0.026178255677223206,
-0.00862969271838665,
-0.048176106065511703,
0.02321544475853443,
-0.0159301795065403,
0.051544781774282455,
0.009512447752058506,
-0.06177256628870964,
0.02333720400929451,
-0.06339602172374725,
-0.01610267162322998,
0.011891827918589115,
0.02796405926346779,
0.005397996865212917,
-0.003325551515445113,
0.02843080274760723,
-0.010684381239116192,
0.04040380194783211,
0.012429597787559032,
-0.04018057882785797,
0.02216019667685032,
-0.012936928309500217,
0.008360806852579117,
0.008893503807485104,
0.03624369204044342,
0.004558364860713482,
0.028735201805830002,
-0.03192123770713806,
0.061569634824991226,
-0.03380850702524185,
-0.101466104388237,
0.014093642123043537,
0.01267311628907919,
0.03614222630858421,
-0.015463434159755707,
0.010344469919800758,
0.00878189131617546,
-0.03322000429034233,
-0.030054260045289993,
0.001781998435035348,
0.0022855240385979414,
0.02177462726831436,
0.00765054440125823,
0.014773464761674404,
-0.0527217872440815,
0.0035056539345532656,
0.035574015229940414,
0.014854637905955315,
-0.017168065533041954,
-0.057348642498254776,
0.04220990091562271,
0.010978632606565952,
-0.004431532230228186,
-0.00713306711986661,
0.0001582237018737942,
-0.04448274150490761,
0.04011970013380051,
-0.008660132065415382,
0.05276237428188324,
-0.047039687633514404,
0.010532181710004807,
-0.005524829495698214,
-0.02767995372414589,
-0.008599252440035343,
-0.06083907559514046,
0.02954692952334881,
-0.06745466589927673,
-0.06104201078414917,
-0.022728407755494118,
-0.018162433058023453,
0.02333720400929451,
0.050083670765161514,
-0.013200740329921246,
-0.01108009833842516,
0.0075389314442873,
-0.045740921050310135,
-0.020617913454771042,
-0.04036321863532066,
-0.007478051818907261,
0.043265148997306824,
-0.03583782911300659,
0.0002630191738717258,
-0.05069246515631676,
0.054142314940690994,
0.05462935194373131,
-0.0002470065373927355,
-0.018213165923953056,
0.022809579968452454,
0.046755582094192505,
0.046755582094192505,
0.0012886195909231901,
0.01943075843155384,
-0.014753172174096107,
0.0265029463917017,
0.009684939868748188,
-0.052559442818164825,
0.018233459442853928,
0.04561915993690491,
0.030399246141314507,
0.051260676234960556,
-0.042696937918663025,
0.062259603291749954,
0.024392452090978622,
-0.03319970890879631,
0.017330411821603775,
-0.0011814460158348083,
0.012876048684120178,
0.059053272008895874,
-0.005085988435894251,
0.035310205072164536,
0.004517778288573027,
-0.03232710063457489,
0.050367776304483414,
0.0008960725390352309,
-0.037765685468912125,
-0.01840595155954361,
0.06392364948987961,
0.0003887420170940459,
0.015879444777965546,
0.0017934134230017662,
0.06830698251724243,
0.012419451028108597,
0.06587179750204086,
-0.010273443534970284,
-0.009898019023239613,
-0.03563489764928818,
-0.054304659366607666,
-0.030845696106553078,
0.027598781511187553,
-0.007721570786088705,
0.0007362634059973061,
-0.061691392213106155,
-0.003987617790699005,
-0.02853226847946644,
0.03934855759143829,
-0.030683349817991257,
-0.045010365545749664,
-0.00971537921577692,
-0.03535079210996628,
-0.03608134761452675,
0.03512756526470184,
-0.012723850086331367,
-0.00405864417552948,
0.038191843777894974,
-0.07715483009815216,
0.007462832145392895,
-0.02940487675368786,
0.002345135435461998,
0.04036321863532066,
-0.0348028726875782,
-0.006798229180276394,
0.0022563524544239044,
-0.06449186056852341,
-0.025325940921902657,
0.016183843836188316,
-0.05880975350737572,
-0.022667527198791504,
0.006975794676691294,
0.009588547050952911,
0.05840389057993889,
0.020090289413928986,
0.009781332686543465,
-0.03504639118909836,
0.04436098039150238,
0.0007869965047575533,
-0.011648309417068958,
0.010785846970975399,
-0.013119567185640335,
0.05012425780296326,
-0.0031403759494423866,
0.03305765613913536,
-0.030236899852752686,
0.0011966659221798182,
0.04395511746406555,
0.010978632606565952,
-0.07642427086830139,
-0.05377703532576561,
0.046146783977746964,
0.005636441987007856,
0.028735201805830002,
-0.0003919128212146461,
0.016853520646691322,
0.04011970013380051,
-0.019339440390467644,
0.02954692952334881,
-0.061244942247867584,
-0.034559354186058044,
0.006985941436141729,
0.0062553854659199715,
-0.07313676923513412,
-0.009405908174812794,
-0.04582209512591362,
-0.02696969173848629,
-0.008563739247620106,
-0.05288413539528847,
-0.04103289172053337,
0.039652954787015915,
-0.07086392492055893,
0.0009334881906397641,
-0.0003107399388682097,
-0.03046012483537197,
0.05146360769867897,
-0.006899695377796888,
0.04610619693994522,
-0.03699454292654991,
-0.0007172385230660439,
-0.009319662116467953,
-0.041682276874780655,
0.02260664850473404,
0.050083670765161514,
-0.004601487889885902,
-0.051950644701719284,
-0.010755407623946667,
0.00492617953568697,
-0.007589664775878191,
0.0388818122446537,
-0.0036553165409713984,
0.016315748915076256,
-0.02987162210047245,
-0.031961824744939804,
-0.03713659569621086,
-0.025285353884100914,
0.052275337278842926,
-0.03829330950975418,
0.018446538597345352,
-0.03577695041894913,
0.022809579968452454,
-0.023134272545576096,
-0.006067673210054636,
-0.002655875403434038,
-0.02640148065984249,
0.03261120617389679,
0.020354101434350014,
-0.04537564143538475,
-0.05377703532576561,
-0.011617869138717651,
-0.005121501628309488,
0.0005682102055288851,
-0.003269745269790292,
-0.02767995372414589,
0.04403629153966904,
0.03652779757976532,
-0.04032263159751892,
0.031840063631534576,
0.06773877143859863,
-0.059215620160102844,
-0.019938088953495026,
0.015625780448317528,
0.02100348472595215,
0.025265060365200043,
-0.03666985034942627,
-0.019369879737496376,
0.022221077233552933,
0.04289986938238144,
0.001306376070715487,
-0.04695851355791092,
0.02291104756295681,
0.0840139389038086,
-0.034721702337265015,
-0.01595047116279602,
-0.02770024724304676,
-0.032387979328632355,
-0.014956103637814522,
-0.035310205072164536,
-0.026482652872800827,
-0.003698439570143819,
0.0042844065465033054,
-0.03744099289178848,
0.03843536227941513,
0.0026330454275012016,
-0.026178255677223206,
-0.038922399282455444,
-0.017299970611929893,
0.01064379420131445,
-0.022687820717692375,
-0.04679616913199425,
-0.02970927581191063,
-0.012206372804939747,
0.023743068799376488,
0.04423922300338745,
0.030054260045289993,
-0.06546593457460403,
-0.09716394543647766,
0.015047423541545868,
0.01122215110808611,
-0.0153619684278965,
-0.0935923382639885,
0.005555269308388233,
0.0008719743345864117,
-0.007741863839328289,
0.022951632738113403,
-0.0035081906244158745,
0.008137581869959831,
0.0016767274355515838,
-0.06891577690839767,
-0.022119611501693726,
-0.027294382452964783,
0.01623457670211792,
0.042981043457984924,
0.07439494878053665,
-0.03729894012212753,
-0.00964435376226902,
0.022971926257014275,
-0.07504433393478394,
-0.045294471085071564,
0.0026888519059866667,
-0.004548218101263046,
0.02072952501475811,
-0.005494389683008194,
0.009547960944473743,
-0.038638293743133545,
-0.04683675616979599,
-0.04496977850794792,
0.013383379206061363,
-0.012662970460951328,
0.02230224944651127,
-0.0010577841894701123,
-0.017015865072607994,
-0.0608796626329422,
0.04249400645494461,
-0.0055451225489377975,
-0.04825728014111519,
0.04781083017587662,
0.020841138437390327,
0.015575047582387924,
-0.03236768767237663,
0.028775786980986595,
-0.0011484695132821798,
-0.04440156742930412,
-0.04797317460179329,
0.007807816844433546,
-0.0123991584405303,
-0.03955148905515671,
-0.021409347653388977,
0.01883210986852646,
-0.030074553564190865,
-0.0007464100490324199,
-0.009466787800192833,
0.014235694892704487,
-0.01058291457593441,
-0.05929679051041603,
0.011404789984226227,
0.043711598962545395,
0.01370807085186243
]
|
31,164 | networkx.classes.function | to_directed | Returns a directed view of the graph `graph`.
Identical to graph.to_directed(as_view=True)
Note that graph.to_directed defaults to `as_view=False`
while this function always provides a view.
| def to_directed(graph):
"""Returns a directed view of the graph `graph`.
Identical to graph.to_directed(as_view=True)
Note that graph.to_directed defaults to `as_view=False`
while this function always provides a view.
"""
return graph.to_directed(as_view=True)
| (graph) | [
0.017421403899788857,
0.027673229575157166,
0.025344790890812874,
-0.004707129206508398,
-0.0012469285866245627,
-0.006440893746912479,
-0.02551230415701866,
-0.006005358882248402,
0.0740409642457962,
0.03624992072582245,
-0.011742696166038513,
-0.04509463161230087,
-0.008333796635270119,
0.02055390551686287,
0.033737216144800186,
0.023401634767651558,
-0.04489361494779587,
0.02082192711532116,
0.008987098932266235,
0.06948459893465042,
0.030755477026104927,
-0.08516386151313782,
-0.004141771234571934,
-0.03688647225499153,
-0.013828238472342491,
0.010126190260052681,
0.0028330718632787466,
-0.01573789305984974,
-0.012546760961413383,
0.0435200072824955,
0.015143219381570816,
-0.07987043261528015,
0.039499681442976,
0.054207365959882736,
0.01511809229850769,
0.07866434007883072,
-0.01961583085358143,
0.053939346224069595,
-0.08208160847425461,
-0.05434137582778931,
-0.027388455346226692,
0.01337595283985138,
0.000001578618366693263,
0.024205699563026428,
-0.0015725329285487533,
0.007831255905330181,
0.02760622277855873,
-0.029331613332033157,
-0.013710979372262955,
-0.04643474146723747,
0.012060971930623055,
-0.015134843997657299,
-0.029499126598238945,
0.039399173110723495,
-0.007529731374233961,
-0.02135797031223774,
-0.0030550272203981876,
0.017555413767695427,
-0.005192918237298727,
0.010595228523015976,
-0.00814115535467863,
-0.04800936579704285,
-0.008635320700705051,
-0.022848840802907944,
-0.030554460361599922,
0.04268243908882141,
-0.048679422587156296,
-0.01502596028149128,
0.01770617626607418,
-0.018007701262831688,
-0.05256573483347893,
0.006449269596487284,
0.017990948632359505,
0.017739679664373398,
0.012597015127539635,
0.015101341530680656,
0.03661844879388809,
0.028829071670770645,
-0.006935058627277613,
-0.03909764811396599,
-0.019029533490538597,
-0.047473322600126266,
-0.011700817383825779,
-0.0009616321185603738,
0.0062650046311318874,
-0.026701651513576508,
-0.025612812489271164,
0.008074150420725346,
-0.007973642088472843,
-0.08663798123598099,
0.03356970474123955,
-0.012002341449260712,
-0.022899094969034195,
0.0344407744705677,
-0.023033104836940765,
0.017588917165994644,
0.0030550272203981876,
-0.03233010321855545,
0.006193811539560556,
0.026818910613656044,
-0.03090623952448368,
0.05454239249229431,
-0.10251826047897339,
-0.013895244337618351,
-0.04137583449482918,
-0.07879834622144699,
-0.026098601520061493,
-0.00006667822162853554,
0.006156120914965868,
-0.007056505884975195,
-0.05846220999956131,
0.038461096584796906,
0.05873022973537445,
0.010335582308471203,
0.011064265854656696,
0.006260816939175129,
0.04224690422415733,
-0.029013337567448616,
-0.031107256188988686,
0.018828516826033592,
-0.048176880925893784,
0.05266624316573143,
-0.012496506795287132,
-0.020319387316703796,
0.010126190260052681,
-0.009950301609933376,
0.009774412028491497,
-0.02532804012298584,
-0.009162988513708115,
0.03594839572906494,
0.006394827738404274,
-0.016382819041609764,
-0.026835661381483078,
0.09796188771724701,
0.04010273143649101,
-0.00014945345174055547,
-0.05856271833181381,
0.018041202798485756,
0.003346082055941224,
0.06355462223291397,
-0.0447596050798893,
-0.05739012360572815,
0.0660003200173378,
0.06529676169157028,
0.015252103097736835,
-0.020319387316703796,
-0.02127421274781227,
0.017203636467456818,
-0.047205302864313126,
-0.018124960362911224,
0.08335471153259277,
0.043989043682813644,
0.06928358227014542,
-0.009397506713867188,
-0.007818692363798618,
-0.0016384914051741362,
-0.06730692088603973,
0.0012354119680821896,
0.015687638893723488,
0.011675690300762653,
-0.037120990455150604,
-0.05149364843964577,
0.03450778126716614,
0.04901444911956787,
-0.004418168216943741,
-0.042347412556409836,
0.05594950541853905,
-0.006281755864620209,
-0.00992517452687025,
0.009807915426790714,
-0.047238804399967194,
-0.019063035026192665,
-0.10472943633794785,
-0.03221284598112106,
-0.015201849862933159,
0.012421125546097755,
0.02100619114935398,
0.05970180779695511,
0.016123173758387566,
0.01175107154995203,
0.0012982295593246818,
-0.029549380764365196,
-0.03276563808321953,
0.0030801543034613132,
0.02176000364124775,
-0.03889663144946098,
-0.03460828587412834,
-0.005067283287644386,
0.0009694843320176005,
0.013786360621452332,
0.037087488919496536,
0.03537885099649429,
0.029231104999780655,
-0.018309224396944046,
0.005075658671557903,
-0.10908478498458862,
-0.04636773467063904,
0.0003656505432445556,
-0.053168781101703644,
0.061879485845565796,
0.047741346061229706,
-0.007923387922346592,
0.04408955201506615,
0.03321792557835579,
-0.0005533180083148181,
0.07189679145812988,
-0.022949349135160446,
-0.04676976799964905,
0.012546760961413383,
0.011742696166038513,
0.00960689876228571,
-0.0030864360742270947,
0.017773181200027466,
-0.003300015814602375,
-0.020922435447573662,
-0.007843819446861744,
-0.024406716227531433,
0.02666814811527729,
0.014573673717677593,
0.008861463516950607,
-0.015704389661550522,
-0.05159415677189827,
-0.03425651043653488,
0.007441787049174309,
-0.0036936725955456495,
-0.06881454586982727,
-0.013777985237538815,
-0.06325309723615646,
-0.012915289960801601,
-0.07504604756832123,
0.03933217003941536,
-0.010804620571434498,
0.009012226015329361,
-0.00036408010055311024,
0.05400634929537773,
-0.01511809229850769,
-0.04053826630115509,
-0.032480865716934204,
-0.010327206924557686,
0.029331613332033157,
-0.02261432074010372,
0.0013641880359500647,
0.0000750538965803571,
0.026550889015197754,
0.020453397184610367,
0.022195538505911827,
-0.030336692929267883,
-0.012086098082363605,
0.0382600836455822,
-0.03759002685546875,
-0.05698809027671814,
-0.05698809027671814,
-0.015888655558228493,
0.01395387388765812,
0.008551564067602158,
-0.01948181912302971,
-0.04117481783032417,
-0.014305652119219303,
-0.02283209003508091,
0.010595228523015976,
-0.04201238229870796,
0.04757383093237877,
-0.09481263905763626,
0.012060971930623055,
0.026835661381483078,
-0.010017306543886662,
-0.05765814334154129,
0.011558431200683117,
0.0009134720312431455,
-0.0007349654333665967,
0.05497792735695839,
0.0005842032842338085,
0.014615552499890327,
-0.003833965165540576,
0.038059066981077194,
0.004418168216943741,
0.0007579985540360212,
0.0553799606859684,
-0.02162599191069603,
0.007776814047247171,
-0.056519053876399994,
-0.013066052459180355,
-0.04221339896321297,
-0.011960463598370552,
-0.06653635948896408,
0.03889663144946098,
0.007219831459224224,
-0.00896197184920311,
0.030269687995314598,
-0.014833319932222366,
0.1239599883556366,
0.013384328223764896,
0.016801603138446808,
0.01168406568467617,
-0.010704112239181995,
0.04298396408557892,
-0.003182756481692195,
-0.03591489419341087,
0.031157510355114937,
0.060036834329366684,
0.06539727002382278,
-0.02621586248278618,
0.05015353858470917,
0.04382152855396271,
0.017061248421669006,
0.012672395445406437,
-0.02377016469836235,
-0.01364397443830967,
0.0211402028799057,
-0.010109439492225647,
-0.08791108429431915,
-0.011776198633015156,
-0.00692249508574605,
0.05926627293229103,
-0.03554636240005493,
-0.009397506713867188,
-0.03330168128013611,
-0.025160526856780052,
0.05437488108873367,
0.019096538424491882,
-0.031509287655353546,
0.07665417343378067,
-0.042481422424316406,
-0.009188114665448666,
-0.03107375279068947,
0.032129086554050446,
0.033954985439777374,
0.029046839103102684,
0.0738399475812912,
0.07256684452295303,
0.045195139944553375,
0.007085820659995079,
0.007353842258453369,
0.022145284339785576,
-0.07966941595077515,
0.04874642565846443,
0.04821038246154785,
-0.005377183202654123,
-0.005163603462278843,
-0.012035844847559929,
0.033201172947883606,
0.007035566493868828,
0.0027116246055811644,
-0.006667037028819323,
0.02011837065219879,
0.059065256267786026,
-0.014958955347537994,
-0.011792950332164764,
0.0014667899813503027,
-0.0204701479524374,
-0.04727230593562126,
0.0568205751478672,
-0.028343282639980316,
0.014942203648388386,
-0.03963369131088257,
0.06301857531070709,
0.021692996844649315,
0.014598800800740719,
-0.05035455524921417,
-0.01784018613398075,
-0.04650174453854561,
0.011843203566968441,
0.035110827535390854,
-0.008920093066990376,
0.05725611373782158,
0.036584947258234024,
-0.012881787493824959,
0.006273380480706692,
0.04928246885538101,
-0.018610749393701553,
-0.021692996844649315,
-0.026869164779782295,
0.02211178094148636,
0.029365114867687225,
0.0074962289072573185,
0.020754922181367874,
-0.009179739281535149,
0.013920371420681477,
0.031509287655353546,
0.046803269535303116,
-0.01545311976224184,
0.014883574098348618,
0.04944998398423195,
0.050991106778383255,
0.06546427309513092,
0.007387345191091299,
0.049114957451820374,
0.031459033489227295,
-0.04643474146723747,
-0.04643474146723747,
-0.031107256188988686,
-0.020084867253899574,
0.012739401310682297,
0.01894577592611313,
-0.01650008000433445,
0.0068136113695800304,
-0.00556144816800952,
0.02626611664891243,
-0.02733820118010044,
-0.0031869441736489534,
0.018811766058206558,
0.007952703163027763,
-0.03588138893246651,
-0.008413365110754967,
-0.01784018613398075,
0.06693839281797409,
0.021776754409074783,
0.004397229291498661,
0.01757216453552246,
-0.03748951852321625,
0.06901556253433228,
0.009648777544498444,
-0.052465226501226425,
-0.012630517594516277,
0.08965322375297546,
0.0191300418227911,
0.03211233764886856,
0.034943316131830215,
0.06536376476287842,
0.03316767141222954,
0.047339312732219696,
0.011441171169281006,
-0.003833965165540576,
0.003741832682862878,
0.03946617990732193,
-0.04010273143649101,
-0.01757216453552246,
0.06975261867046356,
-0.041543345898389816,
0.03464179113507271,
0.06378913670778275,
-0.07357192784547806,
0.05303477123379707,
-0.031861066818237305,
0.02301635406911373,
0.024272704496979713,
0.05970180779695511,
-0.004101986531168222,
-0.0050547197461128235,
0.05782565847039223,
0.03268188238143921,
-0.023837169632315636,
-0.015252103097736835,
-0.061075419187545776,
-0.019917353987693787,
-0.039968717843294144,
0.007207267917692661,
0.048679422587156296,
0.0568205751478672,
-0.056083519011735916,
0.06141044571995735,
0.0022739956621080637,
0.034675292670726776,
0.007818692363798618,
-0.11223404109477997,
0.03147578611969948,
0.003517783246934414,
-0.038327086716890335,
-0.00769305694848299,
0.07759225368499756,
0.02790774777531624,
-0.044391077011823654,
-0.04124182090163231,
0.017957447096705437,
0.010628730989992619,
-0.014414535835385323,
-0.024339711293578148,
-0.023971181362867355,
-0.013535089790821075,
-0.012622141279280186,
0.07444299757480621,
-0.03085598535835743,
0.0012751964386552572,
-0.06161146238446236,
0.0015379833057522774,
0.026383375748991966,
-0.010921879671514034,
-0.01840973272919655,
-0.032480865716934204,
0.01239599846303463,
-0.07203080505132675,
-0.04794236272573471,
-0.020084867253899574,
0.02573007345199585,
-0.003928191494196653,
0.018258970230817795,
-0.029750395566225052,
0.01623205840587616,
0.0013516244944185019,
0.02645038068294525,
0.02728794887661934,
-0.024188948795199394,
-0.021776754409074783,
-0.05239821970462799,
0.015863528475165367,
0.08389075845479965,
-0.061343442648649216,
-0.028695061802864075,
-0.04589869827032089,
0.004150146618485451,
-0.011516552418470383,
-0.0606398843228817,
-0.040504761040210724,
0.014464790001511574,
0.002839353634044528,
0.0017944882856681943,
0.03477580100297928,
0.010670609772205353,
0.0004630177572835237,
0.04710479453206062,
0.035512860864400864,
0.04067227616906166,
0.014020879752933979,
0.03906414657831192,
0.027271196246147156,
0.025127023458480835,
-0.06640234589576721,
-0.0022551503498107195,
0.0356803722679615,
-0.041275326162576675,
0.0056033264845609665,
0.03246411681175232,
-0.009305374696850777,
0.009020601399242878,
-0.028309781104326248,
0.018543744459748268,
-0.00187824503518641,
0.0039260974153876305,
0.034675292670726776,
0.017203636467456818,
0.003909346181899309,
0.05075658857822418,
0.030839234590530396,
0.08824610710144043,
0.007211456075310707,
-0.0003666974953375757,
0.016165051609277725,
0.018392981961369514,
-0.07564909011125565,
-0.015469871461391449,
-0.041040804237127304,
-0.0082249129191041,
-0.04700428619980812,
0.002054134150967002,
0.05749063193798065,
0.01438103336840868,
0.015528501011431217,
-0.056787073612213135,
0.007831255905330181,
-0.04824388772249222,
-0.0740409642457962,
0.016516830772161484,
-0.016977492719888687,
0.015051087364554405,
0.02693616971373558,
0.0065665291622281075,
-0.0037648656871169806,
0.059601299464702606,
0.0502205453813076,
-0.03517783433198929,
-0.03728850185871124,
-0.02671840228140354,
0.003346082055941224,
-0.015528501011431217,
0.050589073449373245,
-0.0025629564188420773,
0.01819196529686451,
0.013777985237538815,
0.0204701479524374,
-0.031777311116456985,
-0.01658383570611477,
-0.071360744535923,
0.03775754198431969,
-0.0024163820780813694,
0.015905406326055527,
0.04298396408557892,
0.002366128144785762,
0.03335193544626236,
0.02970014326274395,
-0.03162654861807823,
-0.05752413347363472,
0.031325023621320724,
-0.005515381693840027,
0.051125116646289825,
-0.006172872148454189,
-0.0012762434780597687,
0.023083359003067017,
-0.010310455225408077,
0.03050420619547367,
-0.03527834266424179,
-0.008379862643778324,
-0.060036834329366684,
0.022262543439865112,
0.01939806342124939,
-0.004581494256854057,
-0.04713829606771469,
-0.021961018443107605,
0.024641234427690506,
0.04365401715040207,
-0.01228711474686861,
-0.01335920114070177,
0.026902666315436363,
0.008509685285389423,
-0.012856660410761833,
0.03264838084578514,
0.02578032575547695,
-0.011901834048330784,
-0.06214750558137894,
0.04254842549562454,
-0.03308391571044922,
-0.023803668096661568,
0.0435200072824955,
-0.033921483904123306,
-0.06194648891687393,
0.03484280779957771,
-0.024272704496979713,
-0.02256406843662262,
0.010218323208391666,
-0.07390695065259933,
0.03537885099649429,
0.06301857531070709,
-0.00960689876228571,
-0.024490471929311752,
-0.022865591570734978,
-0.04110781103372574,
0.03241386264562607,
0.013225190341472626,
-0.023485392332077026,
-0.019548824056982994,
-0.007831255905330181,
-0.0030864360742270947,
-0.05444188416004181,
-0.004849515855312347,
0.041811369359493256,
-0.031944822520017624,
-0.08389075845479965,
0.002707436913624406,
0.01507621444761753,
0.029448872432112694,
0.042112890630960464,
-0.05846220999956131,
0.03430676460266113,
-0.03269863501191139,
-0.052331216633319855,
-0.029984915629029274,
-0.03651794046163559,
0.015813274309039116,
-0.02876206673681736,
-0.00905410386621952,
-0.029398618265986443,
-0.029750395566225052,
0.06948459893465042,
0.040069226175546646,
-0.012312241829931736,
0.04837789759039879,
0.04030374810099602,
0.012630517594516277,
0.0009684374090284109,
-0.005142664071172476,
-0.025261035189032555,
0.018560495227575302,
0.025160526856780052,
0.0449606217443943,
-0.03728850185871124,
0.03722149878740311,
0.09347252547740936,
-0.044659096747636795,
-0.012496506795287132,
-0.014481541700661182,
-0.04633423313498497,
-0.04894744232296944,
0.010360709391534328,
0.02377016469836235,
-0.009556644596159458,
0.006478584371507168,
-0.019917353987693787,
0.05873022973537445,
0.026333121582865715,
0.021994521841406822,
-0.07216481119394302,
-0.019465068355202675,
0.010201571509242058,
-0.007843819446861744,
-0.05360431596636772,
-0.09796188771724701,
-0.033603206276893616,
-0.022145284339785576,
-0.03497681766748428,
0.036852966994047165,
-0.035646870732307434,
-0.001702355919405818,
-0.0474398210644722,
0.005431625060737133,
-0.011583558283746243,
0.05119212344288826,
0.012714274227619171,
-0.03809256851673126,
0.027405207976698875,
-0.01814171113073826,
-0.011416045017540455,
0.03571387752890587,
-0.0063361977227032185,
0.03484280779957771,
0.024691488593816757,
0.03254787251353264,
-0.056787073612213135,
-0.013392703607678413,
0.03251436725258827,
-0.04067227616906166,
-0.03608240559697151,
0.0016322096344083548,
0.0077433111146092415,
0.020101619884371758,
0.031057002022862434,
0.05715560540556908,
-0.05343680456280708,
-0.012714274227619171,
-0.0011066360166296363,
-0.06422467529773712,
0.005285050719976425,
0.004811825230717659,
-0.0447596050798893,
-0.012806406244635582,
0.02412194386124611,
0.023669656366109848,
-0.017019370570778847,
-0.022681327536702156,
0.01518509816378355,
0.02336813136935234,
-0.03624992072582245,
-0.041576847434043884,
0.022631073370575905,
0.034038741141557693,
-0.004003572277724743,
-0.06710590422153473,
0.04502762854099274,
0.0009323172853328288,
0.03608240559697151,
-0.006960185710340738,
0.028393536806106567,
-0.0033963359892368317,
0.028477294370532036,
-0.04757383093237877,
-0.016843480989336967,
0.014925451949238777,
-0.05916576460003853,
0.015009208582341671,
-0.003789992770180106,
-0.04274944216012955,
-0.02862805686891079,
0.05383883789181709,
0.015252103097736835,
0.019364560022950172,
-0.03588138893246651,
0.020905684679746628,
0.0011820170329883695,
0.05249872803688049,
-0.018158461898565292,
0.01330894697457552,
-0.07048967480659485,
-0.04445808008313179,
-0.041811369359493256,
-0.009456136263906956,
-0.05574848875403404,
-0.06345411390066147,
-0.0015777676599100232,
0.031057002022862434,
0.025529056787490845
]
|
31,167 | networkx.drawing.nx_latex | to_latex | Return latex code to draw the graph(s) in `Gbunch`
The TikZ drawing utility in LaTeX is used to draw the graph(s).
If `Gbunch` is a graph, it is drawn in a figure environment.
If `Gbunch` is an iterable of graphs, each is drawn in a subfigure environment
within a single figure environment.
If `as_document` is True, the figure is wrapped inside a document environment
so that the resulting string is ready to be compiled by LaTeX. Otherwise,
the string is ready for inclusion in a larger tex document using ``\include``
or ``\input`` statements.
Parameters
==========
Gbunch : NetworkX graph or iterable of NetworkX graphs
The NetworkX graph to be drawn or an iterable of graphs
to be drawn inside subfigures of a single figure.
pos : string or list of strings
The name of the node attribute on `G` that holds the position of each node.
Positions can be sequences of length 2 with numbers for (x,y) coordinates.
They can also be strings to denote positions in TikZ style, such as (x, y)
or (angle:radius).
If a dict, it should be keyed by node to a position.
If an empty dict, a circular layout is computed by TikZ.
If you are drawing many graphs in subfigures, use a list of position dicts.
tikz_options : string
The tikzpicture options description defining the options for the picture.
Often large scale options like `[scale=2]`.
default_node_options : string
The draw options for a path of nodes. Individual node options override these.
node_options : string or dict
The name of the node attribute on `G` that holds the options for each node.
Or a dict keyed by node to a string holding the options for that node.
node_label : string or dict
The name of the node attribute on `G` that holds the node label (text)
displayed for each node. If the attribute is "" or not present, the node
itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
Or a dict keyed by node to a string holding the label for that node.
default_edge_options : string
The options for the scope drawing all edges. The default is "[-]" for
undirected graphs and "[->]" for directed graphs.
edge_options : string or dict
The name of the edge attribute on `G` that holds the options for each edge.
If the edge is a self-loop and ``"loop" not in edge_options`` the option
"loop," is added to the options for the self-loop edge. Hence you can
use "[loop above]" explicitly, but the default is "[loop]".
Or a dict keyed by edge to a string holding the options for that edge.
edge_label : string or dict
The name of the edge attribute on `G` that holds the edge label (text)
displayed for each edge. If the attribute is "" or not present, no edge
label is drawn.
Or a dict keyed by edge to a string holding the label for that edge.
edge_label_options : string or dict
The name of the edge attribute on `G` that holds the label options for
each edge. For example, "[sloped,above,blue]". The default is no options.
Or a dict keyed by edge to a string holding the label options for that edge.
caption : string
The caption string for the figure environment
latex_label : string
The latex label used for the figure for easy referral from the main text
sub_captions : list of strings
The sub_caption string for each subfigure in the figure
sub_latex_labels : list of strings
The latex label for each subfigure in the figure
n_rows : int
The number of rows of subfigures to arrange for multiple graphs
as_document : bool
Whether to wrap the latex code in a document environment for compiling
document_wrapper : formatted text string with variable ``content``.
This text is called to evaluate the content embedded in a document
environment with a preamble setting up TikZ.
figure_wrapper : formatted text string
This text is evaluated with variables ``content``, ``caption`` and ``label``.
It wraps the content and if a caption is provided, adds the latex code for
that caption, and if a label is provided, adds the latex code for a label.
subfigure_wrapper : formatted text string
This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
It wraps the content and if a caption is provided, adds the latex code for
that caption, and if a label is provided, adds the latex code for a label.
The size is the vertical size of each row of subfigures as a fraction.
Returns
=======
latex_code : string
The text string which draws the desired graph(s) when compiled by LaTeX.
See Also
========
write_latex
to_latex_raw
| def to_latex(
Gbunch,
pos="pos",
tikz_options="",
default_node_options="",
node_options="node_options",
node_label="node_label",
default_edge_options="",
edge_options="edge_options",
edge_label="edge_label",
edge_label_options="edge_label_options",
caption="",
latex_label="",
sub_captions=None,
sub_labels=None,
n_rows=1,
as_document=True,
document_wrapper=_DOC_WRAPPER_TIKZ,
figure_wrapper=_FIG_WRAPPER,
subfigure_wrapper=_SUBFIG_WRAPPER,
):
"""Return latex code to draw the graph(s) in `Gbunch`
The TikZ drawing utility in LaTeX is used to draw the graph(s).
If `Gbunch` is a graph, it is drawn in a figure environment.
If `Gbunch` is an iterable of graphs, each is drawn in a subfigure environment
within a single figure environment.
If `as_document` is True, the figure is wrapped inside a document environment
so that the resulting string is ready to be compiled by LaTeX. Otherwise,
the string is ready for inclusion in a larger tex document using ``\\include``
or ``\\input`` statements.
Parameters
==========
Gbunch : NetworkX graph or iterable of NetworkX graphs
The NetworkX graph to be drawn or an iterable of graphs
to be drawn inside subfigures of a single figure.
pos : string or list of strings
The name of the node attribute on `G` that holds the position of each node.
Positions can be sequences of length 2 with numbers for (x,y) coordinates.
They can also be strings to denote positions in TikZ style, such as (x, y)
or (angle:radius).
If a dict, it should be keyed by node to a position.
If an empty dict, a circular layout is computed by TikZ.
If you are drawing many graphs in subfigures, use a list of position dicts.
tikz_options : string
The tikzpicture options description defining the options for the picture.
Often large scale options like `[scale=2]`.
default_node_options : string
The draw options for a path of nodes. Individual node options override these.
node_options : string or dict
The name of the node attribute on `G` that holds the options for each node.
Or a dict keyed by node to a string holding the options for that node.
node_label : string or dict
The name of the node attribute on `G` that holds the node label (text)
displayed for each node. If the attribute is "" or not present, the node
itself is drawn as a string. LaTeX processing such as ``"$A_1$"`` is allowed.
Or a dict keyed by node to a string holding the label for that node.
default_edge_options : string
The options for the scope drawing all edges. The default is "[-]" for
undirected graphs and "[->]" for directed graphs.
edge_options : string or dict
The name of the edge attribute on `G` that holds the options for each edge.
If the edge is a self-loop and ``"loop" not in edge_options`` the option
"loop," is added to the options for the self-loop edge. Hence you can
use "[loop above]" explicitly, but the default is "[loop]".
Or a dict keyed by edge to a string holding the options for that edge.
edge_label : string or dict
The name of the edge attribute on `G` that holds the edge label (text)
displayed for each edge. If the attribute is "" or not present, no edge
label is drawn.
Or a dict keyed by edge to a string holding the label for that edge.
edge_label_options : string or dict
The name of the edge attribute on `G` that holds the label options for
each edge. For example, "[sloped,above,blue]". The default is no options.
Or a dict keyed by edge to a string holding the label options for that edge.
caption : string
The caption string for the figure environment
latex_label : string
The latex label used for the figure for easy referral from the main text
sub_captions : list of strings
The sub_caption string for each subfigure in the figure
sub_latex_labels : list of strings
The latex label for each subfigure in the figure
n_rows : int
The number of rows of subfigures to arrange for multiple graphs
as_document : bool
Whether to wrap the latex code in a document environment for compiling
document_wrapper : formatted text string with variable ``content``.
This text is called to evaluate the content embedded in a document
environment with a preamble setting up TikZ.
figure_wrapper : formatted text string
This text is evaluated with variables ``content``, ``caption`` and ``label``.
It wraps the content and if a caption is provided, adds the latex code for
that caption, and if a label is provided, adds the latex code for a label.
subfigure_wrapper : formatted text string
This text evaluate variables ``size``, ``content``, ``caption`` and ``label``.
It wraps the content and if a caption is provided, adds the latex code for
that caption, and if a label is provided, adds the latex code for a label.
The size is the vertical size of each row of subfigures as a fraction.
Returns
=======
latex_code : string
The text string which draws the desired graph(s) when compiled by LaTeX.
See Also
========
write_latex
to_latex_raw
"""
if hasattr(Gbunch, "adj"):
raw = to_latex_raw(
Gbunch,
pos,
tikz_options,
default_node_options,
node_options,
node_label,
default_edge_options,
edge_options,
edge_label,
edge_label_options,
)
else: # iterator of graphs
sbf = subfigure_wrapper
size = 1 / n_rows
N = len(Gbunch)
if isinstance(pos, str | dict):
pos = [pos] * N
if sub_captions is None:
sub_captions = [""] * N
if sub_labels is None:
sub_labels = [""] * N
if not (len(Gbunch) == len(pos) == len(sub_captions) == len(sub_labels)):
raise nx.NetworkXError(
"length of Gbunch, sub_captions and sub_figures must agree"
)
raw = ""
for G, pos, subcap, sublbl in zip(Gbunch, pos, sub_captions, sub_labels):
subraw = to_latex_raw(
G,
pos,
tikz_options,
default_node_options,
node_options,
node_label,
default_edge_options,
edge_options,
edge_label,
edge_label_options,
)
cap = f" \\caption{{{subcap}}}" if subcap else ""
lbl = f"\\label{{{sublbl}}}" if sublbl else ""
raw += sbf.format(size=size, content=subraw, caption=cap, label=lbl)
raw += "\n"
# put raw latex code into a figure environment and optionally into a document
raw = raw[:-1]
cap = f"\n \\caption{{{caption}}}" if caption else ""
lbl = f"\\label{{{latex_label}}}" if latex_label else ""
fig = figure_wrapper.format(content=raw, caption=cap, label=lbl)
if as_document:
return document_wrapper.format(content=fig)
return fig
| (Gbunch, pos='pos', tikz_options='', default_node_options='', node_options='node_options', node_label='node_label', default_edge_options='', edge_options='edge_options', edge_label='edge_label', edge_label_options='edge_label_options', caption='', latex_label='', sub_captions=None, sub_labels=None, n_rows=1, as_document=True, document_wrapper='\\documentclass{{report}}\n\\usepackage{{tikz}}\n\\usepackage{{subcaption}}\n\n\\begin{{document}}\n{content}\n\\end{{document}}', figure_wrapper='\\begin{{figure}}\n{content}{caption}{label}\n\\end{{figure}}', subfigure_wrapper=' \\begin{{subfigure}}{{{size}\\textwidth}}\n{content}{caption}{label}\n \\end{{subfigure}}') | [
0.054183486849069595,
-0.04538169875741005,
0.039204295724630356,
0.023659853264689445,
-0.04824833571910858,
-0.012829212471842766,
-0.06778991967439651,
-0.009402369149029255,
0.053820110857486725,
-0.02242841012775898,
0.02267066203057766,
0.007010139990597963,
0.01674560457468033,
0.03526771813631058,
-0.039688799530267715,
0.0033990852534770966,
0.036236722022295,
-0.05834212899208069,
0.014464407227933407,
0.03696347400546074,
-0.019016709178686142,
-0.064277283847332,
0.05850363150238991,
0.037871915847063065,
0.006656857207417488,
-0.02436641976237297,
-0.020611528307199478,
0.03347102180123329,
-0.019279146566987038,
-0.009609292261302471,
-0.006202636752277613,
-0.06649791449308395,
-0.055959995836019516,
-0.025032609701156616,
0.027253244072198868,
0.03643859550356865,
-0.011840020306408405,
0.006586200557649136,
-0.0150599405169487,
-0.015231535769999027,
0.0297161303460598,
-0.008690756745636463,
0.012637430801987648,
-0.04590657725930214,
0.007842877879738808,
0.037589289247989655,
0.006949577480554581,
0.03137151151895523,
-0.03544940426945686,
-0.055031366646289825,
0.05878625810146332,
-0.05668674781918526,
-0.033087458461523056,
0.03020063228905201,
-0.04120286926627159,
0.006702279206365347,
-0.01856248825788498,
0.0847071185708046,
0.08729112893342972,
-0.025597862899303436,
0.030987948179244995,
0.03989067301154137,
-0.03789210319519043,
0.012011615559458733,
-0.004022377077490091,
0.03974936157464981,
0.01678597927093506,
-0.08131560683250427,
-0.02882787585258484,
-0.0712621882557869,
-0.020995091646909714,
0.041223056614398956,
0.024951858446002007,
-0.02331666462123394,
0.004188924562186003,
-0.020167401060461998,
-0.03813435509800911,
-0.03789210319519043,
-0.026910055428743362,
0.0065660132095217705,
0.011900583282113075,
0.004855114966630936,
0.007232203613966703,
-0.014514876529574394,
0.10279519855976105,
-0.017371419817209244,
0.07275606691837311,
0.07630908489227295,
-0.014585532248020172,
-0.030463071539998055,
0.0047895051538944244,
-0.011103173717856407,
0.05075159668922424,
0.039870485663414,
-0.04574507474899292,
-0.027737746015191078,
-0.010699422098696232,
-0.06702279299497604,
0.0018459026468917727,
-0.02404341846704483,
-0.00877655390650034,
-0.00033404151326976717,
-0.03649916127324104,
-0.01876436360180378,
-0.029897818341851234,
-0.005652524530887604,
-0.03678178787231445,
0.03141188621520996,
0.04897508770227432,
-0.06314677745103836,
-0.05696937441825867,
0.009437697939574718,
0.04106155410408974,
-0.04166718199849129,
0.04055686667561531,
-0.037185538560152054,
-0.007449219934642315,
-0.027091743424534798,
-0.013111839070916176,
-0.012233678251504898,
-0.04408969357609749,
-0.019935242831707,
-0.0244067944586277,
0.04538169875741005,
-0.054223861545324326,
0.023982854560017586,
0.04251506179571152,
0.04970184341073036,
0.03298651799559593,
-0.10804397612810135,
0.11474625021219254,
-0.028000185266137123,
-0.01566556841135025,
0.001992262667044997,
0.032037701457738876,
-0.010618671774864197,
0.019723273813724518,
-0.02017749473452568,
-0.027333995327353477,
0.031553201377391815,
0.012183209881186485,
-0.07901421934366226,
-0.020712465047836304,
0.03510621562600136,
-0.03024100698530674,
-0.018007328733801842,
0.018451455980539322,
-0.0586247555911541,
-0.03355177119374275,
-0.028484687209129333,
0.037185538560152054,
-0.0076813772320747375,
0.01662447862327099,
-0.038598667830228806,
0.0008630193769931793,
-0.028242435306310654,
-0.03236070275306702,
0.05676749721169472,
0.020752841606736183,
0.08260761201381683,
0.02085377834737301,
-0.01735123246908188,
0.002529757097363472,
0.01752282679080963,
-0.01210245955735445,
-0.012677805498242378,
0.022004472091794014,
-0.019713180139660835,
-0.015544443391263485,
0.052205104380846024,
0.021277718245983124,
-0.024023231118917465,
-0.08922914415597916,
0.04756195843219757,
0.026364989578723907,
0.04554320126771927,
0.02271103672683239,
0.08583762496709824,
-0.011123361065983772,
0.023054225370287895,
-0.002245869254693389,
-0.004600246902555227,
-0.004368089605122805,
0.037225913256406784,
0.007868112996220589,
-0.017785266041755676,
0.052810732275247574,
0.02097490429878235,
0.05898813158273697,
-0.03242126852273941,
0.00736846961081028,
-0.012829212471842766,
-0.006041135638952255,
0.02384154126048088,
0.062662273645401,
0.000394919712562114,
0.004880349617451429,
-0.011870302259922028,
-0.04299956187605858,
0.05155910179018974,
0.01264752447605133,
-0.01650335267186165,
0.06213739886879921,
-0.0658922865986824,
-0.00515540549531579,
0.012011615559458733,
0.010219966992735863,
0.010487452149391174,
-0.027495495975017548,
-0.018138548359274864,
-0.005157928913831711,
-0.020631715655326843,
0.0038003134541213512,
0.00797409750521183,
-0.0007135050836950541,
-0.010770078748464584,
-0.04776383563876152,
0.06048201397061348,
-0.05773650109767914,
-0.010548015125095844,
-0.03484377637505531,
0.007484548259526491,
0.008867397904396057,
-0.004105650819838047,
0.00704546831548214,
-0.041788309812545776,
0.08099260181188583,
0.004080416169017553,
0.04522019624710083,
-0.057130876928567886,
0.06120876967906952,
-0.03104851022362709,
0.040577054023742676,
0.014272624626755714,
-0.026910055428743362,
-0.02380116656422615,
-0.02154015749692917,
0.052083976566791534,
0.056282997131347656,
0.040940430015325546,
-0.02162090688943863,
0.0008371540461666882,
-0.009932293556630611,
-0.02553729899227619,
0.012506211176514626,
0.03829585388302803,
0.04893471300601959,
-0.0027783168479800224,
-0.053295232355594635,
-0.0001700173452263698,
-0.03506584092974663,
-0.0242049191147089,
-0.007247344125062227,
-0.019188303500413895,
-0.0032073031179606915,
0.007232203613966703,
-0.017694421112537384,
-0.0410817414522171,
0.03052363358438015,
0.030584195628762245,
0.033410459756851196,
0.011284861713647842,
-0.07251381874084473,
0.014262530952692032,
0.0602397620677948,
-0.008090175688266754,
-0.055475492030382156,
0.005556633695960045,
-0.08357661962509155,
-0.009018804877996445,
-0.020561058074235916,
0.05785762891173363,
0.015594911761581898,
0.01759348250925541,
0.027556058019399643,
-0.006808264181017876,
-0.03516677767038345,
0.01419187430292368,
0.01836061105132103,
-0.020278433337807655,
-0.04259581118822098,
-0.026930242776870728,
-0.004310050047934055,
0.0009090723469853401,
-0.026243865489959717,
-0.024467356503009796,
-0.022125596180558205,
0.027293618768453598,
0.016664855182170868,
-0.03108888678252697,
0.003739750711247325,
0.0024780265521258116,
0.016664855182170868,
-0.001960719469934702,
-0.016806166619062424,
-0.038437169045209885,
0.01969299279153347,
0.0054708365350961685,
-0.03363252058625221,
0.012415367178618908,
0.06847629696130753,
-0.04667370393872261,
0.11878377199172974,
0.027838684618473053,
-0.014565344899892807,
0.02882787585258484,
0.03801322728395462,
-0.03401608765125275,
0.03157338872551918,
-0.02878750115633011,
-0.06088576838374138,
0.005430461373180151,
0.027717558667063713,
0.05979563668370247,
-0.04299956187605858,
0.004130885470658541,
0.02145940624177456,
-0.054990991950035095,
0.07380582392215729,
0.007151453290134668,
-0.0484098382294178,
0.0017992188222706318,
0.0019279146799817681,
0.01590782031416893,
0.03575221821665764,
0.0027833636850118637,
0.0009671116713434458,
0.05906888470053673,
0.0459873266518116,
-0.006762842182070017,
-0.011628051288425922,
0.009397322311997414,
0.006682091858237982,
0.0028338327538222075,
-0.07146406173706055,
0.013889061287045479,
0.028141498565673828,
0.0021802594419568777,
-0.06040126457810402,
-0.0838996171951294,
0.04949996620416641,
0.009412462823092937,
-0.0023594244848936796,
0.02053077705204487,
0.03458134084939957,
0.008312239311635494,
-0.014676377177238464,
-0.0463910773396492,
0.0007822690531611443,
0.03526771813631058,
-0.037670038640499115,
0.08575687557458878,
-0.015150785446166992,
-0.005773650482296944,
-0.016210634261369705,
-0.013333901762962341,
0.031472451984882355,
-0.05119572579860687,
-0.03621653467416763,
0.006348996423184872,
0.024628857150673866,
0.01683644950389862,
-0.027475308626890182,
0.04845021292567253,
0.0010119028156623244,
-0.020873965695500374,
-0.017250293865799904,
0.039123546332120895,
0.05119572579860687,
0.012445648200809956,
0.055758118629455566,
-0.024871109053492546,
-0.022287096828222275,
-0.022408222779631615,
-0.002560038585215807,
0.02210540883243084,
-0.052972231060266495,
-0.010982047766447067,
-0.026829304173588753,
-0.052689604461193085,
0.03137151151895523,
-0.006419653072953224,
-0.019016709178686142,
0.0313311368227005,
0.019339710474014282,
-0.03643859550356865,
0.0195314921438694,
0.03869960829615593,
0.016160164028406143,
-0.053012605756521225,
-0.013364183716475964,
0.009462932124733925,
0.10037268698215485,
0.02858562581241131,
-0.04092024266719818,
-0.07198894023895264,
0.038881294429302216,
0.030099693685770035,
-0.025234485045075417,
0.015251723118126392,
0.007888300344347954,
-0.006727513857185841,
0.006495356559753418,
0.001490096328780055,
0.023700227960944176,
-0.017896296456456184,
0.03108888678252697,
0.00016008126840461046,
0.02234766073524952,
0.04727933183312416,
0.016735510900616646,
0.004572488833218813,
-0.10529845952987671,
0.02013712003827095,
-0.04425119236111641,
0.003757414873689413,
-0.031956952065229416,
0.032320328056812286,
0.008276911452412605,
-0.0077722216956317425,
-0.01695757359266281,
0.05636374652385712,
0.06795142590999603,
0.04344369098544121,
0.03286539390683174,
0.03716535121202469,
-0.03480340167880058,
-0.01784582808613777,
-0.07029318064451218,
0.06536740809679031,
-0.03435927629470825,
-0.040334802120923996,
0.02363966591656208,
0.03526771813631058,
0.02428566850721836,
-0.031674325466156006,
0.0007097198977135122,
-0.01419187430292368,
-0.029009563848376274,
-0.0003722086548805237,
0.06455990672111511,
-0.03597428277134895,
-0.016099601984024048,
-0.05026709660887718,
0.039729174226522446,
0.027576245367527008,
-0.05046897009015083,
-0.012708086520433426,
-0.021439218893647194,
0.027091743424534798,
0.03355177119374275,
0.051478348672389984,
0.038719795644283295,
0.007898394018411636,
-0.07146406173706055,
-0.015382942743599415,
0.052245479077100754,
-0.04425119236111641,
-0.0345611497759819,
0.026405366137623787,
-0.01453506387770176,
-0.0183202363550663,
0.04622957855463028,
0.06217777356505394,
0.02549692429602146,
-0.03589353337883949,
0.053497109562158585,
0.026788929477334023,
-0.07832784205675125,
-0.03068513423204422,
0.030584195628762245,
-0.06706316769123077,
-0.056605998426675797,
-0.03306727111339569,
0.04392819106578827,
-0.0037548914551734924,
-0.05050934478640556,
-0.0021260054782032967,
-0.010023137554526329,
-0.07162556052207947,
0.009780886583030224,
-0.016291383653879166,
0.013364183716475964,
0.0035555390641093254,
0.011163736693561077,
0.033329710364341736,
0.06573078781366348,
-0.03205788880586624,
-0.04158643260598183,
-0.055435117334127426,
-0.06274302303791046,
0.05022671818733215,
-0.0077116587199270725,
-0.015382942743599415,
0.03989067301154137,
0.056040745228528976,
-0.006389371585100889,
-0.028323186561465263,
-0.036579910665750504,
-0.09068264812231064,
0.019965525716543198,
0.008564583957195282,
-0.017532920464873314,
-0.007635955233126879,
0.04909621551632881,
-0.0011323975631967187,
0.022125596180558205,
0.06153177097439766,
0.03052363358438015,
-0.02097490429878235,
-0.04102117940783501,
-0.015191160142421722,
0.019713180139660835,
0.004819786641746759,
-0.014807595871388912,
0.014514876529574394,
-0.006253105588257313,
0.010800359770655632,
0.00926105584949255,
-0.010618671774864197,
0.04096061736345291,
0.008438412100076675,
-0.04865208640694618,
0.04348406568169594,
0.0029322472400963306,
0.056848250329494476,
0.04945959150791168,
0.03954748436808586,
0.012062083929777145,
0.021277718245983124,
0.007646048907190561,
0.008009425364434719,
0.04348406568169594,
0.06205664575099945,
0.006051229778677225,
-0.0029524348210543394,
-0.01635194756090641,
0.032804831862449646,
0.0407385528087616,
-0.039365798234939575,
0.015958288684487343,
0.05692899972200394,
-0.004474074114114046,
0.02363966591656208,
0.004484168253839016,
0.03403627499938011,
0.09124790132045746,
0.023861728608608246,
0.06560966372489929,
-0.03530809283256531,
-0.016967667266726494,
0.012798931449651718,
0.03100813552737236,
0.03611559420824051,
0.009003664366900921,
0.01787610910832882,
0.0063590905629098415,
0.04215168580412865,
0.026284240186214447,
-0.02214578539133072,
-0.0342179611325264,
0.0003371958155184984,
0.014363469555974007,
-0.04622957855463028,
0.056323371827602386,
0.019824212417006493,
-0.010961860418319702,
-0.004373136442154646,
0.006041135638952255,
-0.0329461432993412,
0.018976332619786263,
-0.0010775125119835138,
0.07122181355953217,
0.0047516534104943275,
-0.02995838038623333,
-0.01107289269566536,
-0.031876202672719955,
0.06040126457810402,
0.01068932842463255,
-0.016705229878425598,
-0.023982854560017586,
-0.018067890778183937,
0.028525061905384064,
0.06407540291547775,
0.055717743933200836,
0.0036287191323935986,
0.027858871966600418,
0.020894154906272888,
-0.01380831003189087,
-0.016402415931224823,
-0.013798216357827187,
0.001235228031873703,
0.04461457207798958,
0.010931579396128654,
0.011062798090279102,
0.0048727793619036674,
0.04081930220127106,
0.00928124412894249,
-0.008175973780453205,
-0.019258959218859673,
-0.05951301008462906,
0.05818063020706177,
0.013303620740771294,
0.01034613884985447,
-0.06807254999876022,
0.01674560457468033,
0.06778991967439651,
0.009215634316205978,
0.0022912912536412477,
-0.055435117334127426,
0.013747747987508774,
0.06904155015945435,
-0.052649229764938354,
-0.03813435509800911,
-0.10699421912431717,
-0.07412882149219513,
-0.04360518977046013,
0.040132924914360046,
-0.016765791922807693,
-0.020288527011871338,
0.0011342901270836592,
0.0028388795908540487,
-0.022973475977778435,
0.0007071964791975915,
-0.04138455539941788,
0.03740760311484337,
0.0346217155456543,
-0.002156286733224988,
-0.0006800693809054792,
0.020318808034062386,
0.028101123869419098,
-0.04667370393872261,
0.010608578100800514,
0.0024717177730053663,
0.0034798355773091316,
-0.0524473562836647,
-0.01678597927093506,
0.01618035137653351,
-0.014403844252228737,
-0.004186401143670082,
0.005450648721307516,
-0.03966861218214035,
0.0008030874887481332,
0.007408844772726297,
0.01435337495058775,
0.010290623642504215,
0.04211131110787392,
-0.05612149462103844,
0.009165165014564991,
0.02594105154275894,
0.012829212471842766,
0.03100813552737236,
0.005112506914883852,
-0.052568480372428894,
-0.025597862899303436,
0.11256599426269531,
-0.002428819192573428,
-0.0431610643863678,
0.004143502563238144,
-0.019925149157643318,
0.017058512195944786,
-0.03625690937042236,
-0.011032517068088055,
0.02234766073524952,
-0.004426128696650267,
-0.0063288090750575066,
0.005188210401684046,
0.010598483495414257,
0.015049846842885017,
-0.03649916127324104,
-0.010436982847750187,
0.002054087119176984,
-0.054062362760305405,
-0.08462636917829514,
-0.04372631758451462,
-0.028161685913801193,
0.04039536416530609,
-0.014434125274419785,
0.008160832338035107,
-0.04364556446671486,
0.0018446409376338124,
0.05818063020706177,
-0.05107459798455238,
-0.0017563202418386936,
-0.021116217598319054,
-0.025517111644148827,
-0.002165118930861354,
-0.04998447000980377,
0.0019493639701977372,
-0.03829585388302803,
-0.0338142104446888,
0.08276911079883575,
0.006081510800868273,
-0.026526492089033127,
0.020752841606736183,
-0.03589353337883949,
0.00019809071091003716,
-0.021681470796465874,
0.027111930772662163,
-0.04542207345366478,
0.0317348875105381,
-0.02481054700911045,
-0.008095222525298595,
0.04223243519663811,
-0.003621148644015193,
-0.020389463752508163,
-0.03036213293671608,
0.025577673688530922,
-0.010709515772759914,
0.016664855182170868,
-0.01718973182141781,
0.055435117334127426,
0.03157338872551918,
0.0005444340058602393,
-0.021802594885230064,
-0.04077892750501633,
-0.018047703430056572,
0.05745387822389603,
-0.08264798671007156,
-0.012253866530954838,
-0.027778122574090958,
0.03044288419187069,
0.04816758632659912,
0.005491023883223534,
0.018976332619786263,
0.03532828018069267,
-0.017704514786601067,
-0.07384619861841202,
0.005920010153204203,
-0.012274053879082203,
-0.015433411113917828,
0.04186905920505524,
-0.01735123246908188,
-0.014686470851302147,
-0.0467948317527771,
-0.02911050245165825,
-0.04493757337331772,
-0.0213786568492651,
-0.04120286926627159,
0.010961860418319702,
-0.03500527888536453,
-0.04497794806957245,
-0.06900117546319962,
0.0011816048063337803,
0.002199185313656926,
-0.037871915847063065,
0.02081340365111828,
0.06217777356505394,
0.011628051288425922,
0.05668674781918526,
0.03712497651576996,
0.010739796794950962,
-0.030786072835326195,
-0.012597055174410343,
0.010325951501727104,
0.01619044505059719,
0.027152307331562042,
-0.01623082160949707,
0.005001475103199482,
-0.051720600575208664,
-0.01052782777696848,
-0.015635287389159203,
-0.006656857207417488,
-0.009361994452774525,
0.000297293794574216,
-0.030059318989515305,
-0.031512826681137085,
0.03326914459466934
]
|
31,170 | networkx.convert | to_networkx_graph | Make a NetworkX graph from a known data structure.
The preferred way to call this is automatically
from the class constructor
>>> d = {0: {1: {"weight": 1}}} # dict-of-dicts single edge (0,1)
>>> G = nx.Graph(d)
instead of the equivalent
>>> G = nx.from_dict_of_dicts(d)
Parameters
----------
data : object to be converted
Current known types are:
any NetworkX graph
dict-of-dicts
dict-of-lists
container (e.g. set, list, tuple) of edges
iterator (e.g. itertools.chain) that produces edges
generator of edges
Pandas DataFrame (row per edge)
2D numpy array
scipy sparse array
pygraphviz agraph
create_using : NetworkX graph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated.
multigraph_input : bool (default False)
If True and data is a dict_of_dicts,
try to create a multigraph assuming dict_of_dict_of_lists.
If data and create_using are both multigraphs then create
a multigraph from a multigraph.
| def to_networkx_graph(data, create_using=None, multigraph_input=False):
"""Make a NetworkX graph from a known data structure.
The preferred way to call this is automatically
from the class constructor
>>> d = {0: {1: {"weight": 1}}} # dict-of-dicts single edge (0,1)
>>> G = nx.Graph(d)
instead of the equivalent
>>> G = nx.from_dict_of_dicts(d)
Parameters
----------
data : object to be converted
Current known types are:
any NetworkX graph
dict-of-dicts
dict-of-lists
container (e.g. set, list, tuple) of edges
iterator (e.g. itertools.chain) that produces edges
generator of edges
Pandas DataFrame (row per edge)
2D numpy array
scipy sparse array
pygraphviz agraph
create_using : NetworkX graph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated.
multigraph_input : bool (default False)
If True and data is a dict_of_dicts,
try to create a multigraph assuming dict_of_dict_of_lists.
If data and create_using are both multigraphs then create
a multigraph from a multigraph.
"""
# NX graph
if hasattr(data, "adj"):
try:
result = from_dict_of_dicts(
data.adj,
create_using=create_using,
multigraph_input=data.is_multigraph(),
)
# data.graph should be dict-like
result.graph.update(data.graph)
# data.nodes should be dict-like
# result.add_node_from(data.nodes.items()) possible but
# for custom node_attr_dict_factory which may be hashable
# will be unexpected behavior
for n, dd in data.nodes.items():
result._node[n].update(dd)
return result
except Exception as err:
raise nx.NetworkXError("Input is not a correct NetworkX graph.") from err
# pygraphviz agraph
if hasattr(data, "is_strict"):
try:
return nx.nx_agraph.from_agraph(data, create_using=create_using)
except Exception as err:
raise nx.NetworkXError("Input is not a correct pygraphviz graph.") from err
# dict of dicts/lists
if isinstance(data, dict):
try:
return from_dict_of_dicts(
data, create_using=create_using, multigraph_input=multigraph_input
)
except Exception as err1:
if multigraph_input is True:
raise nx.NetworkXError(
f"converting multigraph_input raised:\n{type(err1)}: {err1}"
)
try:
return from_dict_of_lists(data, create_using=create_using)
except Exception as err2:
raise TypeError("Input is not known type.") from err2
# Pandas DataFrame
try:
import pandas as pd
if isinstance(data, pd.DataFrame):
if data.shape[0] == data.shape[1]:
try:
return nx.from_pandas_adjacency(data, create_using=create_using)
except Exception as err:
msg = "Input is not a correct Pandas DataFrame adjacency matrix."
raise nx.NetworkXError(msg) from err
else:
try:
return nx.from_pandas_edgelist(
data, edge_attr=True, create_using=create_using
)
except Exception as err:
msg = "Input is not a correct Pandas DataFrame edge-list."
raise nx.NetworkXError(msg) from err
except ImportError:
warnings.warn("pandas not found, skipping conversion test.", ImportWarning)
# numpy array
try:
import numpy as np
if isinstance(data, np.ndarray):
try:
return nx.from_numpy_array(data, create_using=create_using)
except Exception as err:
raise nx.NetworkXError(
f"Failed to interpret array as an adjacency matrix."
) from err
except ImportError:
warnings.warn("numpy not found, skipping conversion test.", ImportWarning)
# scipy sparse array - any format
try:
import scipy
if hasattr(data, "format"):
try:
return nx.from_scipy_sparse_array(data, create_using=create_using)
except Exception as err:
raise nx.NetworkXError(
"Input is not a correct scipy sparse array type."
) from err
except ImportError:
warnings.warn("scipy not found, skipping conversion test.", ImportWarning)
# Note: most general check - should remain last in order of execution
# Includes containers (e.g. list, set, dict, etc.), generators, and
# iterators (e.g. itertools.chain) of edges
if isinstance(data, Collection | Generator | Iterator):
try:
return from_edgelist(data, create_using=create_using)
except Exception as err:
raise nx.NetworkXError("Input is not a valid edge list") from err
raise nx.NetworkXError("Input is not a known data type for conversion.")
| (data, create_using=None, multigraph_input=False) | [
0.015805616974830627,
0.009644446894526482,
0.00946323573589325,
-0.025913158431649208,
0.0032819306943565607,
0.011768640950322151,
-0.04993366822600365,
0.007500117644667625,
0.09962572902441025,
-0.0523095466196537,
-0.01093305740505457,
0.03579922020435333,
0.0009872218361124396,
0.011949852108955383,
-0.016590865328907967,
0.029013877734541893,
-0.03501397371292114,
0.0376918688416481,
0.03779254108667374,
0.06535673141479492,
-0.008567248471081257,
-0.04280604049563408,
-0.024362798780202866,
0.0506182461977005,
0.03052396886050701,
0.008089053444564342,
-0.0033926707692444324,
0.03249715641140938,
-0.04045030102133751,
0.01738617941737175,
-0.01918822154402733,
-0.032074328511953354,
-0.021966787055134773,
0.010369290597736835,
0.042564425617456436,
0.042242273688316345,
-0.017426447942852974,
-0.008612551726400852,
-0.07288704812526703,
-0.03269850090146065,
0.0007292480440810323,
-0.03978585824370384,
-0.015584137290716171,
0.007666227873414755,
0.018443241715431213,
0.046551067382097244,
-0.011214940808713436,
0.04187985137104988,
-0.06124928221106529,
-0.07425619661808014,
0.009654514491558075,
-0.06237681955099106,
0.010802183300256729,
0.08198786526918411,
-0.004905278328806162,
0.010973326861858368,
-0.022792303934693336,
0.061289552599191666,
0.04659133404493332,
-0.013319001533091068,
0.03424885869026184,
0.05186658725142479,
-0.023718493059277534,
-0.0340072438120842,
-0.036242179572582245,
0.0023507080040872097,
-0.0356985479593277,
-0.08114221692085266,
-0.07083332538604736,
-0.016721738502383232,
-0.034148186445236206,
0.02087952196598053,
0.01944996975362301,
-0.006130968686193228,
0.06326273828744888,
0.0653970018029213,
0.026476925238966942,
0.024886297062039375,
-0.02786620892584324,
0.02263122797012329,
0.02700042352080345,
-0.011547161266207695,
-0.0393831692636013,
-0.019359365105628967,
0.04828263819217682,
0.0316917710006237,
0.020406359806656837,
0.1220153421163559,
-0.00549673056229949,
-0.03334280475974083,
-0.0338461697101593,
-0.031409889459609985,
-0.003473208984360099,
0.046349722892045975,
0.011949852108955383,
-0.019037211313843727,
0.0049379970878362656,
-0.07558508217334747,
0.03451060876250267,
0.01428545918315649,
-0.02889307029545307,
0.005944724194705486,
-0.051302820444107056,
0.021745307371020317,
-0.08843091875314713,
-0.09012222290039062,
-0.015855953097343445,
0.014688150025904179,
-0.006453121546655893,
-0.05327600613236427,
-0.10743793100118637,
-0.01648012548685074,
0.038134828209877014,
0.00770146306604147,
0.05005447566509247,
0.007671261206269264,
0.00696655223146081,
-0.013399539515376091,
-0.03968518599867821,
-0.004610810428857803,
-0.04900748282670975,
0.06382650882005692,
0.005904455203562975,
0.04187985137104988,
0.005106623750180006,
-0.023275533691048622,
0.07075279206037521,
-0.05810829624533653,
0.0393831692636013,
-0.015483465045690536,
0.017668062821030617,
-0.015654608607292175,
-0.0566183403134346,
0.057906948029994965,
0.030221950262784958,
-0.010711577720940113,
-0.038336172699928284,
-0.009181352332234383,
-0.0004162187979090959,
-0.015221715904772282,
0.04828263819217682,
-0.038336172699928284,
0.00975518673658371,
0.02047683112323284,
-0.008466576226055622,
-0.0292353592813015,
0.009775320999324322,
-0.03638312220573425,
-0.04220200330018997,
-0.019117750227451324,
-0.02224867232143879,
-0.018483512103557587,
0.012221668846905231,
-0.015423061326146126,
-0.01689288206398487,
-0.03497370332479477,
-0.06918229162693024,
-0.06898094713687897,
0.03267836570739746,
0.04105433449149132,
-0.03640325739979744,
-0.007726631592959166,
-0.01651032641530037,
0.007766900584101677,
-0.005184645298868418,
-0.021181540563702583,
0.0005518123507499695,
-0.07067225128412247,
0.0036670039407908916,
-0.011889448389410973,
0.00690111517906189,
-0.0057182107120752335,
-0.05553107336163521,
-0.02321512997150421,
0.00570814311504364,
-0.01817142590880394,
0.028067555278539658,
0.010580702684819698,
0.022731900215148926,
0.018392905592918396,
-0.018674788996577263,
-0.010892788879573345,
-0.03410791978240013,
0.0078474385663867,
-0.029456838965415955,
0.0012231735745444894,
0.006438020616769791,
0.031107870861887932,
0.0507793202996254,
0.016329115256667137,
0.019037211313843727,
-0.02798701636493206,
0.023778896778821945,
0.07598777115345001,
0.04755779355764389,
-0.058953944593667984,
-0.01930902898311615,
0.04401411488652229,
-0.04022882133722305,
0.09696796536445618,
0.03080585226416588,
-0.039826128631830215,
0.07949118316173553,
-0.014758621342480183,
-0.062336549162864685,
-0.01677207462489605,
-0.025651410222053528,
-0.02641652151942253,
-0.009604177437722683,
-0.02245001681149006,
-0.020839253440499306,
-0.038658324629068375,
0.04208119958639145,
0.01755732297897339,
-0.03992680087685585,
-0.001033782958984375,
0.038195230066776276,
0.000646822212729603,
-0.007223267573863268,
-0.06543727219104767,
0.023054054006934166,
-0.013661288656294346,
-0.04377250000834465,
-0.004444700665771961,
0.04840344563126564,
-0.05468542128801346,
-0.0025847721844911575,
0.039886534214019775,
0.050658512860536575,
-0.03517504781484604,
0.0790884867310524,
-0.027684997767210007,
0.00901524256914854,
0.004749235697090626,
0.050135016441345215,
-0.03318173065781593,
0.0061813052743673325,
-0.0036896553356200457,
0.024644682183861732,
0.029980337247252464,
-0.019067414104938507,
-0.03779254108667374,
-0.012745166197419167,
-0.03509451076388359,
0.02786620892584324,
-0.005884320475161076,
0.0412355475127697,
0.01784927397966385,
-0.025087641552090645,
-0.039302632212638855,
-0.02335607074201107,
0.014990168623626232,
0.01744658313691616,
-0.0152317825704813,
-0.03211459890007973,
-0.02178557775914669,
-0.009679682552814484,
-0.04208119958639145,
0.02460441365838051,
-0.04304765537381172,
0.006810509599745274,
0.031671639531850815,
-0.013621019199490547,
0.051826316863298416,
0.0244634710252285,
-0.022530555725097656,
-0.009095780551433563,
0.029315896332263947,
-0.01752712018787861,
-0.012120995670557022,
0.009181352332234383,
0.020305687561631203,
0.08448454737663269,
0.00015502025780733675,
0.01636938378214836,
-0.027121230959892273,
0.0021644635125994682,
-0.03712809830904007,
0.012110928073525429,
0.04421545937657356,
-0.06382650882005692,
-0.01601703092455864,
-0.0507793202996254,
-0.02577221766114235,
-0.0013615986099466681,
0.003611633786931634,
-0.04105433449149132,
-0.03418845683336258,
0.006478289607912302,
-0.029436703771352768,
0.032315943390131,
-0.04598730057477951,
-0.01677207462489605,
0.021161405369639397,
-0.044859763234853745,
0.02432253025472164,
-0.01750698685646057,
-0.019500305876135826,
0.036765679717063904,
0.032577693462371826,
0.05859152227640152,
0.004706449806690216,
0.09777335077524185,
0.015121042728424072,
0.009060544893145561,
0.016580797731876373,
0.014980101026594639,
-0.010963259264826775,
-0.0507793202996254,
0.017053959891200066,
-0.03279917314648628,
0.05899421498179436,
0.005501764360815287,
0.013449875637888908,
-0.000017529244360048324,
-0.02158423140645027,
0.01723516918718815,
-0.016228443011641502,
0.06777287274599075,
0.037933479994535446,
-0.03320186212658882,
0.04117514193058014,
-0.015896223485469818,
-0.009241756051778793,
-0.031007198616862297,
0.02694001980125904,
0.09439074248075485,
0.03652406483888626,
0.06745072454214096,
0.0036267347168177366,
0.00037846650229766965,
-0.007238368503749371,
0.0283091701567173,
0.05218873918056488,
-0.039886534214019775,
0.01814122498035431,
0.005793715361505747,
-0.01040955912321806,
0.023114457726478577,
-0.015070706605911255,
-0.02172517403960228,
0.04840344563126564,
0.012030390091240406,
-0.04973232373595238,
-0.002301630098372698,
-0.018221762031316757,
-0.01666133478283882,
-0.052873313426971436,
-0.01170823723077774,
0.04920882731676102,
-0.06491377204656601,
0.06853798776865005,
-0.014104248024523258,
0.05363842472434044,
-0.022329209372401237,
-0.04179931432008743,
0.000639586360193789,
-0.05726264417171478,
0.025429928675293922,
0.008773627690970898,
0.038920074701309204,
0.03668513894081116,
0.031812578439712524,
-0.023960107937455177,
0.015906289219856262,
-0.012251870706677437,
-0.02236947789788246,
0.036826081573963165,
0.04069191589951515,
-0.01915801875293255,
0.022913111373782158,
-0.06608157604932785,
-0.036826081573963165,
0.016087500378489494,
0.00902530923485756,
0.05589349567890167,
-0.02289297617971897,
0.01790967769920826,
0.0018838383257389069,
0.039503976702690125,
0.016178106889128685,
-0.016751941293478012,
-0.0017089194152504206,
0.0019027144880965352,
0.08633692562580109,
-0.024946700781583786,
0.057826410979032516,
0.04715510457754135,
-0.0063021122477948666,
-0.05335654318332672,
-0.06189358979463577,
-0.006740038748830557,
0.05851098522543907,
0.02621517702937126,
-0.014698217622935772,
-0.022349344566464424,
0.07268570363521576,
0.016349250450730324,
-0.02079898491501808,
-0.0189264714717865,
-0.0356985479593277,
-0.027564190328121185,
0.008657854050397873,
0.015151244588196278,
0.0012829479528591037,
0.011980053968727589,
0.03086625598371029,
0.00003865675171255134,
0.016641201451420784,
0.021302348002791405,
0.1029277890920639,
0.034087784588336945,
-0.021825846284627914,
0.0035688478965312243,
0.008109187707304955,
0.0541619248688221,
0.01787947490811348,
0.021302348002791405,
0.03066491149365902,
0.032195135951042175,
0.06249762699007988,
-0.012110928073525429,
0.014990168623626232,
0.02949710749089718,
0.001399350818246603,
-0.0024652231950312853,
-0.04912828654050827,
-0.01790967769920826,
-0.013983441516757011,
0.07449781149625778,
0.0004652967327274382,
-0.0746186226606369,
0.05355788767337799,
-0.061490897089242935,
0.015996895730495453,
-0.007122594863176346,
-0.0044396668672561646,
0.02218826860189438,
0.005672907922416925,
0.015896223485469818,
0.0057182107120752335,
-0.03320186212658882,
0.031349483877420425,
-0.057504259049892426,
-0.04574568569660187,
-0.0076813288033008575,
-0.029134685173630714,
0.029396435245871544,
-0.008698123507201672,
-0.002549536759033799,
0.0340072438120842,
-0.025812486186623573,
0.0670882984995842,
-0.009110881015658379,
-0.09197460114955902,
0.01399350818246603,
0.00886926706880331,
0.02245001681149006,
-0.006186338607221842,
0.052551161497831345,
0.019651316106319427,
-0.06451108306646347,
-0.04989340156316757,
0.009337394498288631,
-0.04345034807920456,
0.03501397371292114,
0.008209860883653164,
0.009619278833270073,
-0.03700729086995125,
-0.019751988351345062,
0.03211459890007973,
-0.000030005190637893975,
-0.0015767865115776658,
-0.022288940846920013,
0.03491330146789551,
0.014376064762473106,
0.007651126943528652,
-0.0058390176855027676,
-0.019379498437047005,
-0.046671874821186066,
0.03287971019744873,
-0.023658089339733124,
0.06241708621382713,
0.013792162761092186,
0.012725031934678555,
0.0043364777229726315,
0.0498531311750412,
-0.03221527114510536,
-0.027483653277158737,
0.001862445380538702,
-0.06720910966396332,
-0.009251822717487812,
-0.0027861176058650017,
0.019067414104938507,
0.04594703018665314,
0.044457074254751205,
-0.02851051464676857,
-0.038134828209877014,
0.010892788879573345,
-0.09253836423158646,
0.02804742008447647,
0.01732577569782734,
-0.044255729764699936,
0.010042103938758373,
0.01930902898311615,
0.028429975733160973,
0.013731759041547775,
0.056336455047130585,
0.03497370332479477,
-0.02210772968828678,
-0.050658512860536575,
0.014627746306359768,
0.07192059606313705,
0.028329303488135338,
0.0003359951952006668,
0.024020511656999588,
-0.006402784958481789,
0.014778755605220795,
-0.04155769944190979,
-0.042564425617456436,
0.018805664032697678,
0.034732088446617126,
0.02355741709470749,
0.021543962880969048,
-0.03080585226416588,
0.06008148193359375,
0.01921842247247696,
-0.023537281900644302,
0.011667968705296516,
-0.0027861176058650017,
-0.0024778074584901333,
0.012181399390101433,
0.011104200966656208,
0.038920074701309204,
0.01695328578352928,
-0.055490802973508835,
0.0686185285449028,
0.019208354875445366,
-0.03686635196208954,
-0.012735099531710148,
0.04075231775641441,
0.022268805652856827,
-0.04578595235943794,
0.0015616855816915631,
0.029195088893175125,
-0.01540292613208294,
0.041195277124643326,
0.011929717846214771,
-0.01960097812116146,
-0.03163136914372444,
-0.06495404243469238,
0.013590817339718342,
0.021624499931931496,
0.04808129370212555,
0.03483276069164276,
-0.05536999553442001,
0.0032693466637283564,
-0.00039923025178723037,
0.051504164934158325,
-0.031872984021902084,
-0.0515444353222847,
0.005056287627667189,
-0.025953426957130432,
-0.038859669119119644,
0.016359318047761917,
-0.02108086831867695,
-0.02615477330982685,
0.024886297062039375,
-0.03410791978240013,
-0.012020323425531387,
0.018533848226070404,
0.0022928211838006973,
0.02067817747592926,
0.0062568094581365585,
-0.019530508667230606,
-0.010600837878882885,
-0.05017528310418129,
-0.0072081671096384525,
0.010439760982990265,
-0.04131608456373215,
-0.01944996975362301,
0.025127911940217018,
-0.002725713886320591,
0.006604130379855633,
0.03934289887547493,
-0.017305640503764153,
-0.041396621614694595,
0.03424885869026184,
-0.0003473208926152438,
-0.0344703383743763,
0.00001339025857305387,
-0.011124336160719395,
0.04069191589951515,
0.024966834113001823,
0.002652726136147976,
0.007671261206269264,
0.03916168957948685,
0.0010753105161711574,
0.03658446669578552,
-0.05484649911522865,
-0.0523095466196537,
0.08392078429460526,
-0.007746765855699778,
0.023013783618807793,
0.0356985479593277,
-0.019208354875445366,
0.0052651832811534405,
-0.010812249965965748,
0.053799502551555634,
-0.0626184344291687,
0.024161452427506447,
0.053074657917022705,
-0.022490285336971283,
-0.034027379006147385,
-0.00593465706333518,
-0.04228254407644272,
-0.064631886780262,
0.026638003066182137,
-0.0376918688416481,
-0.034732088446617126,
0.04397384449839592,
-0.07067225128412247,
-0.01834256947040558,
0.0184633769094944,
-0.02075871452689171,
0.03386630490422249,
0.00564270606264472,
-0.002559603890404105,
-0.019117750227451324,
-0.031933385878801346,
0.03364482522010803,
-0.06197412684559822,
0.04026908800005913,
0.04105433449149132,
-0.044457074254751205,
-0.03153069689869881,
0.013610951602458954,
0.04638998955488205,
-0.012493484653532505,
0.043410077691078186,
-0.03541666269302368,
-0.03610123693943024,
-0.0030025639571249485,
-0.0014119349652901292,
0.007479983381927013,
-0.04016841575503349,
0.05210820212960243,
-0.06567888706922531,
0.028953474014997482,
0.028651457279920578,
0.022651363164186478,
0.0026602766010910273,
-0.007968246005475521,
0.015322388149797916,
0.05239008367061615,
0.06853798776865005,
-0.01510090846568346,
-0.03014141321182251,
-0.01939963363111019,
-0.010510232299566269,
0.027121230959892273,
0.00835583545267582,
0.03579922020435333,
0.0304635651409626,
0.05206793174147606,
0.052470624446868896,
0.00837093684822321,
0.017255304381251335,
0.03575894981622696,
0.017396247014403343,
-0.04860479012131691,
0.009619278833270073,
0.016429787501692772,
0.008109187707304955,
0.003858281997963786,
-0.03998720645904541,
0.009644446894526482,
0.011265277862548828,
-0.015090840868651867,
-0.03547706827521324,
0.0009689749567769468,
0.08090060204267502,
-0.03489316627383232,
-0.01974192075431347,
-0.04336980730295181,
-0.07896768301725388,
0.006115867756307125,
-0.05669887736439705,
-0.0035663312301039696,
-0.03881940245628357,
0.002614974044263363,
0.004686315078288317,
0.012775368057191372,
-0.02067817747592926,
-0.07377296686172485,
-0.05259142816066742,
-0.039886534214019775,
-0.0007506409892812371,
-0.007273604162037373,
-0.04405438154935837,
0.028913205489516258,
-0.00008124603482428938,
0.007031989749521017,
0.06716883927583694,
0.05106120556592941,
-0.03235621377825737,
-0.08311539888381958,
0.026718540117144585,
0.040410030633211136,
-0.026899751275777817,
-0.05794721841812134,
-0.00931726023554802,
0.020718446001410484,
-0.00824006274342537,
0.023919839411973953,
0.0037374747917056084,
0.003697205800563097,
0.04542353376746178,
-0.06777287274599075,
-0.002334348624572158,
0.011768640950322151,
0.04300738498568535,
0.025852754712104797,
0.040993932634592056,
-0.03509451076388359,
-0.010610904544591904,
0.010751846246421337,
-0.06902121752500534,
0.0030906526371836662,
-0.035718683153390884,
0.016751941293478012,
0.04598730057477951,
-0.01552373357117176,
0.03157096728682518,
-0.029698453843593597,
-0.044134922325611115,
-0.04703429713845253,
0.05778614059090614,
0.012443148531019688,
0.07558508217334747,
-0.03555760532617569,
-0.028852801769971848,
-0.08408185839653015,
-0.0074044787324965,
-0.027765536680817604,
-0.054886769503355026,
0.06624265015125275,
0.007339041214436293,
-0.009362563490867615,
-0.013198194094002247,
0.04924909397959709,
-0.025933293625712395,
-0.06132982298731804,
-0.012785435654222965,
0.03968518599867821,
0.015191514045000076,
-0.03964491933584213,
0.010600837878882885,
-0.014235123060643673,
-0.10655201226472855,
0.005101589951664209,
0.014396199025213718,
0.052027661353349686,
-0.034812625497579575,
-0.06398758292198181,
-0.01575528085231781,
0.058027755469083786,
0.04401411488652229
]
|
31,171 | networkx.convert_matrix | to_numpy_array | 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.]])
| 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] | (G, nodelist=None, dtype=None, order=None, multigraph_weight=<built-in function sum>, weight='weight', nonedge=0.0, *, 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
]
|
31,172 | networkx.convert_matrix | to_pandas_adjacency | Returns the graph adjacency matrix as a Pandas DataFrame.
Parameters
----------
G : graph
The NetworkX graph used to construct the Pandas DataFrame.
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().
multigraph_weight : {sum, min, max}, optional
An operator that determines how weights in multigraphs are handled.
The default is to sum the weights of the multiple edges.
weight : string or None, optional
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.
nonedge : float, optional
The matrix values corresponding to nonedges are typically set to zero.
However, this could be undesirable if there are matrix 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
-------
df : Pandas DataFrame
Graph adjacency matrix
Notes
-----
For directed graphs, entry i,j corresponds to an edge from i to j.
The DataFrame entries are assigned to 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 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 matrix 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 Pandas DataFrame can be modified as follows::
>>> import pandas as pd
>>> G = nx.Graph([(1, 1), (2, 2)])
>>> df = nx.to_pandas_adjacency(G)
>>> df
1 2
1 1.0 0.0
2 0.0 1.0
>>> diag_idx = list(range(len(df)))
>>> df.iloc[diag_idx, diag_idx] *= 2
>>> df
1 2
1 2.0 0.0
2 0.0 2.0
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_pandas_adjacency(G, nodelist=[0, 1, 2], dtype=int)
0 1 2
0 0 2 0
1 1 0 0
2 0 0 4
| 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] | (G, nodelist=None, dtype=None, order=None, multigraph_weight=<built-in function sum>, weight='weight', nonedge=0.0, *, 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
]
|
31,173 | networkx.convert_matrix | to_pandas_edgelist | Returns the graph edge list as a Pandas DataFrame.
Parameters
----------
G : graph
The NetworkX graph used to construct the Pandas DataFrame.
source : str or int, optional
A valid column name (string or integer) for the source nodes (for the
directed case).
target : str or int, optional
A valid column name (string or integer) for the target nodes (for the
directed case).
nodelist : list, optional
Use only nodes specified in nodelist
dtype : dtype, default None
Use to create the DataFrame. Data type to force.
Only a single dtype is allowed. If None, infer.
edge_key : str or int or None, optional (default=None)
A valid column name (string or integer) for the edge keys (for the
multigraph case). If None, edge keys are not stored in the DataFrame.
Returns
-------
df : Pandas DataFrame
Graph edge list
Examples
--------
>>> G = nx.Graph(
... [
... ("A", "B", {"cost": 1, "weight": 7}),
... ("C", "E", {"cost": 9, "weight": 10}),
... ]
... )
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"])
>>> df[["source", "target", "cost", "weight"]]
source target cost weight
0 A B 1 7
1 C E 9 10
>>> G = nx.MultiGraph([("A", "B", {"cost": 1}), ("A", "B", {"cost": 9})])
>>> df = nx.to_pandas_edgelist(G, nodelist=["A", "C"], edge_key="ekey")
>>> df[["source", "target", "cost", "ekey"]]
source target cost ekey
0 A B 1 0
1 A B 9 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] | (G, source='source', target='target', nodelist=None, dtype=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
]
|
31,175 | networkx.convert_matrix | to_scipy_sparse_array | Returns the graph adjacency matrix as a SciPy sparse array.
Parameters
----------
G : graph
The NetworkX graph used to construct the sparse matrix.
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 valid NumPy dtype used to initialize the array. If None, then the
NumPy default is used.
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.
format : str in {'bsr', 'csr', 'csc', 'coo', 'lil', 'dia', 'dok'}
The type of the matrix to be returned (default 'csr'). For
some algorithms different implementations of sparse matrices
can perform better. See [1]_ for details.
Returns
-------
A : SciPy sparse array
Graph adjacency matrix.
Notes
-----
For directed graphs, matrix entry i,j corresponds to an edge from i to j.
The matrix entries are populated using the edge attribute held in
parameter weight. When an edge does not have that attribute, the
value of the entry is 1.
For multiple edges the matrix values are the sums of the edge weights.
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 matrix 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 SciPy sparse array can be modified as follows:
>>> G = nx.Graph([(1, 1)])
>>> A = nx.to_scipy_sparse_array(G)
>>> print(A.todense())
[[1]]
>>> A.setdiag(A.diagonal() * 2)
>>> print(A.toarray())
[[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
>>> S = nx.to_scipy_sparse_array(G, nodelist=[0, 1, 2])
>>> print(S.toarray())
[[0 2 0]
[1 0 0]
[0 0 4]]
References
----------
.. [1] Scipy Dev. References, "Sparse Matrices",
https://docs.scipy.org/doc/scipy/reference/sparse.html
| 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] | (G, nodelist=None, dtype=None, weight='weight', format='csr', *, 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
]
|
31,176 | networkx.readwrite.sparse6 | to_sparse6_bytes | Convert an undirected graph to bytes in sparse6 format.
Parameters
----------
G : Graph (undirected)
nodes: list or iterable
Nodes are labeled 0...n-1 in the order provided. If None the ordering
given by ``G.nodes()`` is used.
header: bool
If True add '>>sparse6<<' bytes to head of data.
Raises
------
NetworkXNotImplemented
If the graph is directed.
ValueError
If the graph has at least ``2 ** 36`` nodes; the sparse6 format
is only defined for graphs of order less than ``2 ** 36``.
Examples
--------
>>> nx.to_sparse6_bytes(nx.path_graph(2))
b'>>sparse6<<:An\n'
See Also
--------
to_sparse6_bytes, read_sparse6, write_sparse6_bytes
Notes
-----
The returned bytes end with a newline character.
The format does not support edge or node labels.
References
----------
.. [1] Graph6 specification
<https://users.cecs.anu.edu.au/~bdm/data/formats.html>
| def to_sparse6_bytes(G, nodes=None, header=True):
"""Convert an undirected graph to bytes in sparse6 format.
Parameters
----------
G : Graph (undirected)
nodes: list or iterable
Nodes are labeled 0...n-1 in the order provided. If None the ordering
given by ``G.nodes()`` is used.
header: bool
If True add '>>sparse6<<' bytes to head of data.
Raises
------
NetworkXNotImplemented
If the graph is directed.
ValueError
If the graph has at least ``2 ** 36`` nodes; the sparse6 format
is only defined for graphs of order less than ``2 ** 36``.
Examples
--------
>>> nx.to_sparse6_bytes(nx.path_graph(2))
b'>>sparse6<<:An\\n'
See Also
--------
to_sparse6_bytes, read_sparse6, write_sparse6_bytes
Notes
-----
The returned bytes end with a newline character.
The format does not support edge or node labels.
References
----------
.. [1] Graph6 specification
<https://users.cecs.anu.edu.au/~bdm/data/formats.html>
"""
if nodes is not None:
G = G.subgraph(nodes)
G = nx.convert_node_labels_to_integers(G, ordering="sorted")
return b"".join(_generate_sparse6_bytes(G, nodes, header))
| (G, nodes=None, header=True) | [
0.018457701429724693,
0.02643642947077751,
-0.012602345086634159,
-0.055961400270462036,
-0.033256955444812775,
-0.05239487066864967,
-0.04507797211408615,
0.03156561031937599,
0.06302092224359512,
-0.01021240372210741,
0.0736837387084961,
0.005441713146865368,
-0.016012609004974365,
0.028973445296287537,
-0.0011047734878957272,
-0.007491547614336014,
-0.008649749681353569,
-0.029046980664134026,
0.07041135430335999,
0.03241128474473953,
-0.004458160139620304,
0.004357047379016876,
-0.01489117369055748,
0.03241128474473953,
-0.03535275161266327,
-0.012841339223086834,
0.07765471190214157,
0.038386136293411255,
-0.020222581923007965,
-0.0006532123661600053,
-0.00296904263086617,
-0.01915629953145981,
-0.01950559951364994,
-0.013365288265049458,
-0.011030498892068863,
0.013549129478633404,
0.014468338340520859,
0.005726667586714029,
0.007794886361807585,
-0.024984080344438553,
0.0016787040513008833,
0.006875677965581417,
-0.047247305512428284,
-0.05529956892132759,
0.03358786925673485,
0.041621752083301544,
0.008213126100599766,
0.03572043403983116,
-0.029911037534475327,
0.02643642947077751,
0.013438824564218521,
-0.07478678226470947,
0.0014132827054709196,
0.02739240601658821,
-0.06791111081838608,
0.003959489520639181,
-0.020259350538253784,
-0.04893864691257477,
-0.015902303159236908,
0.029855884611606598,
-0.007542103994637728,
-0.013383672572672367,
0.08589082211256027,
0.045298583805561066,
-0.0120600126683712,
0.01443156972527504,
-0.05335084721446037,
-0.027796858921647072,
-0.003796330187469721,
-0.023917799815535545,
-0.02132563106715679,
0.05916024371981621,
-0.036510951817035675,
-0.006314960774034262,
-0.019450446590781212,
0.03768754005432129,
-0.0530199334025383,
-0.021141789853572845,
-0.05842487886548042,
-0.03437839075922966,
0.05478481203317642,
-0.024083256721496582,
0.03801845386624336,
0.0033551102969795465,
0.09368570894002914,
-0.012372543103992939,
0.07133056223392487,
0.05147566273808479,
-0.019707825034856796,
-0.03162076324224472,
0.005892124958336353,
0.001105922507122159,
0.01187617052346468,
-0.015157744288444519,
0.025682678446173668,
-0.017464956268668175,
0.01021240372210741,
-0.008668133988976479,
-0.03298119455575943,
-0.04151144623756409,
0.04165852069854736,
0.006466630380600691,
-0.05636585131287575,
0.025259843096137047,
-0.029046980664134026,
-0.02967204339802265,
-0.032778967171907425,
0.007569679990410805,
0.040702540427446365,
-0.06000591441988945,
0.010865041986107826,
0.034212931990623474,
0.051769811660051346,
-0.03572043403983116,
0.05776304751634598,
-0.027613015845417976,
0.05298316478729248,
0.004986704792827368,
-0.015047439374029636,
-0.009104757569730282,
0.017602838575839996,
0.023035358637571335,
-0.022079382091760635,
0.04915925860404968,
0.0612560398876667,
-0.019634287804365158,
-0.007624832447618246,
0.024745086207985878,
0.0744558721780777,
-0.026877649128437042,
0.03588588908314705,
-0.02792554721236229,
0.03638226166367531,
0.052321333438158035,
-0.01728111505508423,
-0.023053742945194244,
-0.04493090137839317,
-0.03246643766760826,
0.03384524956345558,
-0.020792491734027863,
-0.005303831771016121,
-0.0886116772890091,
-0.026859264820814133,
0.046254560351371765,
0.06269000470638275,
-0.007312302011996508,
0.025737831369042397,
-0.027208564803004265,
-0.024046488106250763,
-0.03285250440239906,
0.02509438619017601,
-0.0063241529278457165,
0.003474607365205884,
0.005267063621431589,
-0.03224582597613335,
-0.018044058233499527,
-0.017253538593649864,
-0.002295722719281912,
0.0017120253760367632,
0.013080333359539509,
0.009155314415693283,
-0.002165884478017688,
-0.03893766179680824,
0.0501520037651062,
-0.02369718998670578,
-0.04379108175635338,
0.018264668062329292,
0.015314009971916676,
-0.055630482733249664,
0.006705624517053366,
-0.009398904629051685,
-0.038349367678165436,
-0.048644501715898514,
-0.016279177740216255,
0.04180559143424034,
-0.007964939810335636,
-0.018457701429724693,
-0.005110797937959433,
0.01692262478172779,
0.014918750151991844,
-0.0438278503715992,
0.011021306738257408,
0.004607531242072582,
0.021086636930704117,
-0.011076459661126137,
0.053277309983968735,
0.01089261844754219,
-0.003982469905167818,
0.014762484468519688,
-0.03114277683198452,
0.020259350538253784,
0.03535275161266327,
-0.02320081740617752,
0.08978826552629471,
0.03191491216421127,
-0.0016660649562254548,
0.005110797937959433,
0.019266605377197266,
-0.08390533179044724,
0.04360723868012428,
0.008157973177731037,
0.002918486250564456,
0.057836584746837616,
-0.042540960013866425,
-0.0047431145794689655,
-0.006383901461958885,
0.022888286039233208,
-0.025958441197872162,
-0.04835035651922226,
-0.0029874269384890795,
-0.01467975601553917,
0.04125406593084335,
-0.013190638273954391,
0.008392371237277985,
-0.043938156217336655,
0.0007284725434146821,
0.008874955587089062,
0.03669479489326477,
-0.038827355951070786,
-0.055152494460344315,
-0.040187787264585495,
-0.022630907595157623,
-0.03801845386624336,
-0.0008370540454052389,
-0.009449461475014687,
-0.020792491734027863,
0.01902761124074459,
-0.030002957209944725,
-0.007270937319844961,
-0.056990914046764374,
0.06857293844223022,
0.002819671295583248,
0.02279636450111866,
0.06831555813550949,
-0.005873740650713444,
0.03871705383062363,
0.020204197615385056,
-0.026252588257193565,
0.04463675245642662,
0.02051672898232937,
-0.038753822445869446,
-0.0825081318616867,
-0.023586884140968323,
0.03062801994383335,
0.0736837387084961,
0.016545748338103294,
-0.038349367678165436,
-0.030922167003154755,
-0.04099668934941292,
0.016361907124519348,
-0.06493287533521652,
-0.04757821932435036,
0.028238078579306602,
-0.05485834926366806,
-0.006310364697128534,
0.030389025807380676,
-0.0557040199637413,
-0.01992843486368656,
-0.03577558696269989,
-0.0028081813361495733,
-0.006126523017883301,
0.01001937035471201,
-0.0771399587392807,
0.010782312601804733,
0.05993238091468811,
0.00637470930814743,
0.0001946136326296255,
0.05754243955016136,
-0.053314078599214554,
-0.014946326613426208,
0.09214143455028534,
0.005037261173129082,
-0.03801845386624336,
0.02505761757493019,
0.038386136293411255,
-0.04647517204284668,
-0.04875480756163597,
0.03498506546020508,
0.04404846206307411,
0.0025232266634702682,
-0.004092774819582701,
0.005818588193506002,
-0.01467975601553917,
0.03588588908314705,
-0.006972194649279118,
0.0350218340754509,
-0.05357145890593529,
-0.030094878748059273,
-0.0130159892141819,
-0.03356948494911194,
0.06342536956071854,
-0.016895048320293427,
-0.0065263789147138596,
0.04040839523077011,
0.03246643766760826,
0.023035358637571335,
-0.00858540553599596,
0.007509931456297636,
0.036529336124658585,
0.03901119902729988,
0.06982306391000748,
0.010166443884372711,
0.008479696698486805,
-0.0003984193317592144,
0.02559075877070427,
-0.036106500774621964,
-0.04566626623272896,
0.02099471725523472,
0.04588687792420387,
0.055593717843294144,
-0.03362463787198067,
-0.09000887721776962,
0.06728604435920715,
-0.00021759382798336446,
-0.060630977153778076,
-0.012427696026861668,
0.012666690163314342,
-0.011545255780220032,
0.048570964485406876,
-0.0007652408676221967,
-0.013071141205728054,
0.025737831369042397,
-0.016876664012670517,
0.042982179671525955,
-0.0694921463727951,
-0.017143234610557556,
0.014192575588822365,
-0.016849087551236153,
-0.014312072657048702,
-0.05085060000419617,
0.02921243943274021,
-0.02371557429432869,
0.03711763024330139,
0.03241128474473953,
-0.011269493028521538,
0.0648961067199707,
0.04735761135816574,
-0.023072127252817154,
-0.06633006781339645,
-0.06735958158969879,
0.021270480006933212,
0.030370641499757767,
-0.004370835144072771,
0.02145432122051716,
0.017538493499159813,
-0.029469817876815796,
-0.04548242688179016,
-0.02086602710187435,
-0.08993533998727798,
0.03062801994383335,
0.01751091703772545,
0.01902761124074459,
0.024046488106250763,
-0.02656511962413788,
0.049048952758312225,
-0.0026174455415457487,
0.03246643766760826,
-0.06331506371498108,
0.03288927301764488,
0.032834120094776154,
0.03993040695786476,
0.06235909089446068,
-0.00650799460709095,
-0.027171796187758446,
0.018099211156368256,
0.01228981465101242,
-0.040776077657938004,
0.04327632486820221,
0.03456223011016846,
-0.028568992391228676,
0.0063241529278457165,
-0.018457701429724693,
-0.03439677506685257,
0.022998591884970665,
0.0012110569514334202,
0.019266605377197266,
-0.03761400282382965,
0.020259350538253784,
-0.05820426717400551,
-0.014017926529049873,
0.011251109652221203,
-0.021472705528140068,
-0.030977318063378334,
0.05037261173129082,
0.060630977153778076,
-0.005749647971242666,
0.017060505226254463,
0.0008623322355560958,
0.023494962602853775,
-0.0012363351415842772,
-0.02983750030398369,
0.0260319784283638,
0.011508487164974213,
-0.012694266624748707,
-0.009872296825051308,
0.015911495313048363,
0.0557040199637413,
0.031822990626096725,
-0.018044058233499527,
-0.01952398382127285,
-0.010570894926786423,
0.009761991910636425,
-0.02366042137145996,
0.00879682321101427,
-0.011490103788673878,
-0.016371099278330803,
0.050519686192274094,
-0.04088638350367546,
0.007390434388071299,
0.024009719491004944,
0.03390040248632431,
0.04801943898200989,
-0.031804606318473816,
0.019450446590781212,
-0.0019050590926781297,
-0.022649291902780533,
-0.013549129478633404,
0.018016481772065163,
0.05346115306019783,
0.03816552832722664,
-0.04103345796465874,
0.03070155717432499,
-0.002449690131470561,
-0.023090511560440063,
0.01413742359727621,
-0.0048809959553182125,
-0.05658646300435066,
-0.006007025949656963,
-0.0250760018825531,
0.028660913929343224,
-0.02980073168873787,
-0.002686386229470372,
0.017409805208444595,
0.045298583805561066,
0.00008186698687495664,
-0.01372377946972847,
0.021656546741724014,
-0.05805719271302223,
-0.06360921263694763,
0.03945241868495941,
0.018099211156368256,
-0.028660913929343224,
-0.007004367187619209,
0.0065769352950155735,
-0.0030931357759982347,
-0.02888152375817299,
-0.03937888145446777,
-0.01671120710670948,
0.02829323150217533,
0.03434162214398384,
-0.017060505226254463,
-0.07706642150878906,
-0.013732971623539925,
-0.0023968354798853397,
-0.01911953277885914,
-0.039820101112127304,
0.06750665605068207,
0.015883918851614,
-0.028440304100513458,
0.0011030499590560794,
0.021086636930704117,
0.0013328519416972995,
-0.01786021701991558,
0.018154364079236984,
0.02702472358942032,
-0.027061492204666138,
0.015075015835464,
0.0139719657599926,
0.0250760018825531,
-0.019413677975535393,
0.022502219304442406,
-0.0012765504652634263,
-0.022961823269724846,
-0.028440304100513458,
0.040665775537490845,
-0.005892124958336353,
-0.04640163481235504,
0.013677818700671196,
-0.09045009315013885,
-0.00778569420799613,
0.019376911222934723,
-0.040776077657938004,
0.02049834467470646,
-0.009431077167391777,
0.04360723868012428,
-0.0219139251857996,
0.05066676065325737,
-0.015883918851614,
-0.029855884611606598,
0.010285940952599049,
0.05537310615181923,
-0.0171340424567461,
-0.07544861733913422,
-0.004674173891544342,
0.0709996446967125,
0.022428682073950768,
-0.04643840342760086,
0.015350778587162495,
-0.021031485870480537,
0.030444178730249405,
-0.05842487886548042,
0.025333380326628685,
-0.007592660374939442,
-0.05026230961084366,
0.03108762390911579,
-0.02829323150217533,
0.06405043601989746,
0.011490103788673878,
0.030389025807380676,
-0.024837007746100426,
-0.037944916635751724,
0.029524968937039375,
-0.00858540553599596,
0.026381276547908783,
0.02237352915108204,
0.029194055125117302,
-0.009936640970408916,
-0.028440304100513458,
0.038864124566316605,
0.022575754672288895,
0.003754965728148818,
0.08228752762079239,
0.017961328849196434,
0.012151933275163174,
-0.03244805335998535,
0.015350778587162495,
0.056512925773859024,
-0.009431077167391777,
0.01230819895863533,
0.035610128194093704,
-0.025259843096137047,
0.054674506187438965,
-0.021141789853572845,
0.06644037365913391,
0.019818130880594254,
-0.018880538642406464,
0.018080826848745346,
0.009927449747920036,
-0.006434457842260599,
-0.04044516384601593,
-0.03715439885854721,
-0.001852204673923552,
-0.003589508356526494,
0.01954236812889576,
-0.027245333418250084,
0.042026203125715256,
0.05640261992812157,
0.05114474892616272,
0.01644463650882244,
-0.07041135430335999,
-0.13288074731826782,
0.0171340424567461,
-0.03219067305326462,
-0.017428189516067505,
0.03691540285944939,
-0.014220152050256729,
-0.034157779067754745,
0.05673353374004364,
0.020388038828969002,
-0.0007508782437071204,
-0.042982179671525955,
-0.04890187829732895,
-0.013043565675616264,
-0.017308691516518593,
-0.005469289142638445,
-0.01996520347893238,
-0.024965696036815643,
-0.06566824018955231,
0.01391681283712387,
0.041621752083301544,
-0.020204197615385056,
0.020240966230630875,
-0.010377861559391022,
0.02788877859711647,
0.015516235493123531,
-0.028091004118323326,
-0.06265323609113693,
0.052836090326309204,
0.05294639617204666,
-0.05195365101099014,
0.012161125428974628,
0.03114277683198452,
0.019266605377197266,
0.06394013017416,
0.07508093118667603,
0.0005546847241930664,
-0.010865041986107826,
-0.013567513786256313,
-0.04754145070910454,
-0.014578643254935741,
0.04945340380072594,
-0.04890187829732895,
0.05158596858382225,
0.03434162214398384,
0.009660879150032997,
-0.02184038795530796,
-0.0007594958296976984,
0.04404846206307411,
-0.013356096111238003,
0.01818194054067135,
-0.03432323783636093,
0.04272479936480522,
0.05956469476222992,
0.002794393105432391,
0.07169824838638306,
0.021546242758631706,
-0.01911953277885914,
0.007206592708826065,
0.036051347851753235,
-0.023384658619761467,
-0.022097766399383545,
0.09442107379436493,
-0.030113263055682182,
0.019450446590781212,
-0.04636486619710922,
-0.011572832241654396,
-0.007261745166033506,
-0.04926956444978714,
-0.08397886902093887,
-0.05485834926366806,
-0.015957456082105637,
-0.009587341919541359,
-0.05662322789430618,
-0.03621680662035942,
-0.004667279776185751,
0.07357343286275864,
-0.05960146337747574,
0.04960047826170921,
-0.03498506546020508,
0.030039725825190544,
0.02840353548526764,
-0.07324251532554626,
0.03290765732526779,
0.06265323609113693,
0.008502676151692867,
-0.0825081318616867,
-0.03504021838307381,
0.03250320628285408,
0.0055795940570533276,
0.04243065416812897,
-0.05055645480751991,
0.05901316925883293,
-0.011958899907767773,
-0.06324152648448944,
-0.05022554099559784,
-0.07133056223392487,
0.01902761124074459,
-0.04588687792420387,
-0.012014051899313927,
-0.021619778126478195,
-0.018292244523763657,
0.04732084274291992,
0.07640459388494492,
-0.016224026679992676,
0.042504191398620605,
0.02932274341583252,
0.023127280175685883,
-0.015185320749878883,
-0.0019395294366404414,
-0.07883130013942719,
0.008033880032598972,
0.0008066052687354386,
0.014091462828218937,
0.011986475437879562,
-0.00744558684527874,
0.04125406593084335,
0.013631858862936497,
0.009467844851315022,
-0.006200059782713652,
-0.08199337869882584,
-0.05607170611619949,
0.005285447463393211,
0.022410297766327858,
-0.05860871821641922,
-0.048644501715898514,
0.0059059131890535355,
0.01651817187666893,
0.023366274312138557,
0.016867471858859062,
-0.020149044692516327,
0.05154919996857643,
0.024984080344438553,
-0.0190459955483675,
-0.010543318465352058,
-0.06184433400630951,
-0.002893208060413599,
-0.05449066683650017,
-0.0009220807696692646,
-0.024837007746100426,
-0.015075015835464,
0.025811368599534035,
-0.02005712501704693,
0.06287384778261185,
0.025296611711382866,
0.05169627442955971,
0.03831259906291962,
-0.0030770497396588326,
0.07419849187135696,
-0.004471948370337486,
-0.018420934677124023,
0.015295625664293766,
-0.003548143897205591,
0.004926956258714199,
0.010138867422938347,
-0.003125308081507683,
-0.018843770027160645,
-0.03070155717432499,
0.011278685182332993,
-0.07511769980192184,
0.04890187829732895,
0.027539480477571487,
0.005216506775468588,
-0.011977284215390682,
0.03121631219983101,
-0.018843770027160645,
-0.014247728511691093,
-0.03755884990096092,
-0.02143593691289425,
-0.0744558721780777,
0.040776077657938004,
0.003982469905167818,
-0.008392371237277985,
0.02645481377840042,
0.05382883548736572,
-0.09236204624176025,
0.030480945482850075,
-0.0031207120046019554,
-0.03167591616511345,
0.09773022681474686,
-0.007151440251618624,
0.02606874704360962,
0.01749253273010254,
-0.008907128125429153,
0.04507797211408615,
-0.010653624311089516,
0.010138867422938347,
-0.04695316031575203,
-0.003325236029922962,
-0.008392371237277985,
0.043864618986845016,
-0.025314996019005775,
0.02932274341583252,
0.024910544976592064,
0.0031528843101114035,
-0.04423230141401291,
-0.04846065863966942,
0.003738879691809416,
0.05629231408238411,
-0.029414664953947067,
0.022208072245121002,
-0.00605298625305295,
0.02693280205130577,
-0.03108762390911579,
-0.04805620759725571,
0.07405141741037369,
0.019707825034856796,
-0.05621877685189247,
-0.0409599207341671,
-0.005979449953883886,
-0.07452940940856934,
-0.01644463650882244,
-0.022980207577347755,
-0.031804606318473816,
-0.008406159467995167,
-0.029377896338701248,
-0.0017441976815462112,
0.0029046982526779175,
0.030793476849794388
]
|
31,177 | networkx.classes.function | to_undirected | Returns an undirected view of the graph `graph`.
Identical to graph.to_undirected(as_view=True)
Note that graph.to_undirected defaults to `as_view=False`
while this function always provides a view.
| def to_undirected(graph):
"""Returns an undirected view of the graph `graph`.
Identical to graph.to_undirected(as_view=True)
Note that graph.to_undirected defaults to `as_view=False`
while this function always provides a view.
"""
return graph.to_undirected(as_view=True)
| (graph) | [
-0.022642308846116066,
0.043751802295446396,
0.017843937501311302,
0.021476037800312042,
-0.026990830898284912,
-0.00681435177102685,
-0.03167257457971573,
0.002599117113277316,
0.08023940771818161,
0.019743293523788452,
-0.021342748776078224,
-0.04338525980710983,
-0.0447847843170166,
0.01607787236571312,
0.0044609843753278255,
0.06151243671774864,
-0.0333886556327343,
0.025907864794135094,
0.0341050811111927,
0.0038924277760088444,
0.04355186969041824,
-0.06134582683444023,
-0.006006292998790741,
0.002984402934089303,
-0.04135261848568916,
-0.04865013808012009,
-0.04521797224879265,
-0.02315879985690117,
-0.032055776566267014,
-0.016161177307367325,
0.033521946519613266,
-0.023708611726760864,
0.06924314051866531,
-0.00421106955036521,
0.04428495466709137,
0.04315200820565224,
-0.00010614883649395779,
0.03090616688132286,
-0.05138254538178444,
-0.06587762385606766,
0.007934804074466228,
-0.03692078962922096,
-0.018077192828059196,
0.013303813524544239,
0.06117921695113182,
0.029539965093135834,
0.05991297960281372,
-0.04635092243552208,
-0.03407175838947296,
-0.0048775095492601395,
0.02760728821158409,
0.027623949572443962,
-0.027240745723247528,
0.04061953350901604,
-0.03835363686084747,
-0.029256727546453476,
-0.028806880116462708,
0.001331839244812727,
-0.02617444097995758,
0.03363857418298721,
-0.05204898491501808,
-0.03058960847556591,
-0.000266055460087955,
-0.025574645027518272,
0.031289368867874146,
0.028723575174808502,
-0.01779395528137684,
-0.0000053285934882296715,
-0.0025574646424502134,
-0.007076762616634369,
-0.10263179987668991,
0.027623949572443962,
0.0017421165248379111,
0.02079293690621853,
0.033488623797893524,
-0.022592324763536453,
0.06684395670890808,
0.0682101622223854,
-0.029073456302285194,
-0.015469744801521301,
-0.013520406559109688,
-0.03155594691634178,
-0.008763689547777176,
0.06877663731575012,
0.02272561378777027,
-0.003925749566406012,
0.01622782088816166,
-0.010688035748898983,
-0.051149290055036545,
-0.06347843259572983,
0.02034308947622776,
-0.010104900225996971,
-0.0333886556327343,
-0.0021471872460097075,
0.021792596206068993,
0.015561380423605442,
-0.016452744603157043,
0.014628363773226738,
-0.016261141747236252,
-0.025008171796798706,
0.01370367780327797,
0.026607627049088478,
-0.10796332359313965,
-0.02600783109664917,
0.0008929258328862488,
-0.07584090530872345,
-0.007984787225723267,
-0.040452923625707626,
-0.0036320993676781654,
0.0076598976738750935,
-0.0064644706435501575,
0.01701088808476925,
0.05544783174991608,
0.014045228250324726,
0.015694668516516685,
-0.0282070841640234,
0.03722069039940834,
-0.02507481537759304,
-0.000949156703427434,
0.01412020344287157,
-0.038220349699258804,
0.030056456103920937,
-0.028506983071565628,
-0.036954112350940704,
0.00960507057607174,
-0.017927242442965508,
-0.004165251739323139,
-0.007226711604744196,
0.014053558930754662,
0.04178580641746521,
0.006772699300199747,
-0.03815370425581932,
-0.03708739951252937,
0.028956830501556396,
-0.023725273087620735,
-0.009496773593127728,
-0.03230569139122963,
-0.0017264968482777476,
0.04648420959711075,
0.0637783333659172,
-0.03988644853234291,
-0.0315726064145565,
0.04568447917699814,
0.11835978925228119,
0.020409733057022095,
0.00969670619815588,
-0.019443394616246223,
0.046450886875391006,
-0.004727560561150312,
-0.00775986397638917,
0.02634105086326599,
0.03888678923249245,
0.05268210172653198,
0.00032436897163279355,
-0.003698743414133787,
-0.030339693650603294,
-0.044684819877147675,
-0.014686677604913712,
-0.008963621221482754,
0.009921629913151264,
-0.01952669955790043,
-0.04805034399032593,
0.025924526154994965,
0.016019558534026146,
-0.029706574976444244,
-0.08137235790491104,
0.11795992404222488,
-0.0104047991335392,
0.009496773593127728,
0.024341730400919914,
-0.03392180800437927,
-0.030539624392986298,
-0.05611427128314972,
-0.012270831502974033,
-0.03155594691634178,
0.0086054103448987,
0.010163214057683945,
0.0378204844892025,
0.0013526654802262783,
0.03400511294603348,
0.02067630924284458,
-0.016744311898946762,
-0.02302551083266735,
-0.03263891115784645,
0.03092282824218273,
-0.03622102737426758,
-0.046284276992082596,
-0.017227480188012123,
0.0076598976738750935,
-0.005139920394867659,
0.011254509910941124,
0.010621392168104649,
0.06707721203565598,
0.014761651866137981,
0.062178876250982285,
-0.044384922832250595,
-0.06407823413610458,
0.04301872104406357,
-0.01829378493130207,
0.012262500822544098,
0.044051703065633774,
-0.022125815972685814,
0.06054610013961792,
0.021559342741966248,
-0.02304217219352722,
0.04934990033507347,
-0.05738050863146782,
-0.03027305006980896,
0.028956830501556396,
0.01253740768879652,
0.04071950167417526,
-0.009055256843566895,
0.031022794544696808,
-0.02745733968913555,
-0.04698403924703598,
-0.02744067832827568,
-0.06451141834259033,
0.027240745723247528,
0.010288171470165253,
0.0060354494489729404,
-0.04991637542843819,
-0.03672085702419281,
-0.02004319056868553,
-0.05248217284679413,
-0.0113544762134552,
-0.046750783920288086,
-0.03280552104115486,
-0.037120722234249115,
-0.006422818172723055,
-0.03925333172082901,
0.060012947767972946,
-0.025158120319247246,
-0.014528397470712662,
0.008013944141566753,
0.061412472277879715,
-0.03363857418298721,
-0.0688432827591896,
-0.0322057269513607,
0.06704389303922653,
0.033788520842790604,
-0.026241086423397064,
-0.038553569465875626,
0.016785964369773865,
0.024991510435938835,
0.04538458213210106,
0.042185667902231216,
-0.053215254098176956,
0.003286383580416441,
0.03532133251428604,
-0.008397147059440613,
-0.06004626676440239,
-0.04445156455039978,
-0.03183918446302414,
0.015003236941993237,
0.0384536050260067,
0.0064394790679216385,
-0.054281558841466904,
-0.02019314095377922,
-0.041852448135614395,
0.02729072980582714,
-0.018543699756264687,
0.05281539261341095,
-0.06774365156888962,
0.049549832940101624,
0.028506983071565628,
-0.03605441749095917,
-0.04068617895245552,
-0.0018837350653484464,
0.0027948839124292135,
0.017910582944750786,
0.0028261232655495405,
-0.0214427150785923,
0.0015859195264056325,
-0.006597758736461401,
0.03535465523600578,
0.02224244363605976,
0.02332540974020958,
0.03788712993264198,
-0.005048285238444805,
0.03278886154294014,
-0.036820825189352036,
-0.015852948650717735,
-0.046450886875391006,
0.004006972070783377,
-0.05801362544298172,
0.029873184859752655,
0.013836965896189213,
-0.06474467366933823,
0.02330874837934971,
-0.03172255679965019,
0.14768315851688385,
0.028506983071565628,
0.03605441749095917,
0.014553389512002468,
-0.03548794612288475,
0.026990830898284912,
-0.012604051269590855,
-0.039486587047576904,
0.012254170142114162,
0.04991637542843819,
0.07517446577548981,
-0.002035766839981079,
0.015461414121091366,
0.032522283494472504,
0.04148590564727783,
0.0037799659185111523,
-0.032722216099500656,
0.028640270233154297,
-0.00851793959736824,
-0.0005544991581700742,
-0.10663044452667236,
-0.04528461769223213,
-0.007468296214938164,
0.029756557196378708,
-0.05628088116645813,
-0.0041860779747366905,
-0.015811296179890633,
-0.03210575878620148,
0.04661749675869942,
0.0359211303293705,
-0.007293355651199818,
0.055414509028196335,
-0.03898675739765167,
0.029423337429761887,
-0.051315899938344955,
0.006260373163968325,
0.019326766952872276,
0.023542001843452454,
0.018477056175470352,
0.05061613768339157,
0.016744311898946762,
0.015328126028180122,
-0.032255709171295166,
0.01671098917722702,
-0.06917650252580643,
0.04241892322897911,
0.04085278883576393,
0.012745670042932034,
0.005827187094837427,
-0.026407696306705475,
0.0007075721514411271,
0.05638084560632706,
-0.02317546121776104,
-0.030656252056360245,
0.03152262419462204,
0.06374501436948776,
-0.04118600860238075,
0.009530095383524895,
0.01907685212790966,
-0.024375053122639656,
-0.015069880522787571,
0.06851006299257278,
-0.04268549755215645,
0.013520406559109688,
-0.013062229380011559,
0.07037609070539474,
0.023708611726760864,
0.014553389512002468,
-0.023125477135181427,
-0.005773038603365421,
-0.012928941287100315,
0.0067143854685127735,
-0.012895619496703148,
-0.03055628575384617,
0.05488135665655136,
0.015827955678105354,
0.0016359025612473488,
-0.02330874837934971,
-0.054148271679878235,
0.01892690360546112,
-0.033788520842790604,
-0.06547775864601135,
0.04088611155748367,
0.032722216099500656,
0.01497824490070343,
0.03405509889125824,
-0.01126284059137106,
0.010313163511455059,
0.04551786929368973,
0.05268210172653198,
-0.004419331904500723,
0.022808918729424477,
0.0416191965341568,
0.032572269439697266,
0.07757364958524704,
0.009996604174375534,
0.003105195239186287,
0.0315726064145565,
-0.020209800451993942,
-0.04188577085733414,
-0.020109836012125015,
-0.024841561913490295,
0.017927242442965508,
0.00756826251745224,
0.016269473358988762,
0.0026803393848240376,
-0.003677917178720236,
0.035854484885931015,
0.035054758191108704,
-0.022009190171957016,
0.012070898897945881,
0.033488623797893524,
-0.050516173243522644,
0.021842580288648605,
-0.020243123173713684,
0.04555119201540947,
-0.0065019577741622925,
0.030239727348089218,
0.027240745723247528,
-0.053015321493148804,
0.0669439285993576,
0.011171204969286919,
-0.0595797598361969,
0.0032738877926021814,
0.12542405724525452,
-0.005714725237339735,
0.02474159561097622,
0.02552466280758381,
0.030506303533911705,
0.009988273493945599,
0.036654215306043625,
0.031306032091379166,
0.01889358088374138,
-0.008451296016573906,
0.03772052004933357,
-0.025474678725004196,
-0.03415506333112717,
0.016269473358988762,
-0.04781708866357803,
0.09116902947425842,
0.024241764098405838,
-0.07617412507534027,
0.04871678352355957,
-0.03628767281770706,
0.011962602846324444,
0.03312208130955696,
0.06241213157773018,
0.002463746350258589,
-0.008730367757380009,
0.0845046266913414,
-0.007863995619118214,
-0.001392235397361219,
0.00610625883564353,
-0.0328388437628746,
0.006293695420026779,
-0.01891024224460125,
-0.01133781485259533,
0.021825918927788734,
0.05104932561516762,
-0.02427508682012558,
0.022658968344330788,
-0.026607627049088478,
0.020409733057022095,
-0.025308068841695786,
-0.08470455557107925,
-0.00607710238546133,
-0.03385516628623009,
-0.013378788717091084,
-0.033788520842790604,
0.09356821328401566,
0.02192588523030281,
-0.04395173490047455,
-0.03390514850616455,
0.008772020228207111,
0.01766066625714302,
-0.030972812324762344,
-0.00421106955036521,
-0.03832031413912773,
-0.03968651965260506,
-0.0061479113064706326,
0.036954112350940704,
-0.01957668364048004,
0.016802625730633736,
-0.0416191965341568,
-0.0018556196009740233,
-0.011296162381768227,
-0.027340712025761604,
-0.025258086621761322,
-0.01222917903214693,
-0.03135601431131363,
-0.06524450331926346,
-0.028790218755602837,
-0.031289368867874146,
0.026141120120882988,
-0.022658968344330788,
0.03415506333112717,
-0.026374373584985733,
0.005014962982386351,
0.02934003248810768,
-0.0055731069296598434,
0.035254690796136856,
-0.03532133251428604,
-0.02157600410282612,
-0.03575452044606209,
0.012245839461684227,
0.0352880135178566,
-0.08083920180797577,
-0.02757396548986435,
-0.003877849318087101,
0.0012454102979972959,
-0.011762671172618866,
-0.04275214299559593,
-0.015061549842357635,
0.005260712932795286,
0.03425503149628639,
0.015827955678105354,
0.05108264833688736,
0.03028970956802368,
0.019743293523788452,
0.02319212071597576,
0.0479503758251667,
0.04055289179086685,
-0.00430270517244935,
0.03468821570277214,
0.04195241630077362,
0.006681063678115606,
-0.0481836311519146,
-0.017377430573105812,
0.04555119201540947,
-0.032538946717977524,
0.007980622351169586,
0.026107797399163246,
-0.01797722652554512,
0.003557124873623252,
-0.023092154413461685,
0.026374373584985733,
-0.03028970956802368,
0.00480253528803587,
0.01671098917722702,
0.014070220291614532,
0.00889697764068842,
0.026391034945845604,
0.027657270431518555,
0.07530774921178818,
0.009480113163590431,
0.016294464468955994,
-0.0007731748628430068,
-0.012629043310880661,
-0.06814351677894592,
-0.0010308998171240091,
-0.025258086621761322,
-0.01000493485480547,
0.0044609843753278255,
0.03875350207090378,
0.03133935481309891,
0.015403100289404392,
-0.022658968344330788,
-0.016177836805582047,
-0.025574645027518272,
-0.025258086621761322,
-0.1102958619594574,
0.023841900750994682,
-0.01000493485480547,
0.02602449245750904,
0.01797722652554512,
0.029223404824733734,
-0.018210479989647865,
0.10509762912988663,
0.02930671162903309,
-0.02285890094935894,
-0.024708272889256477,
-0.03218906372785568,
-0.017527379095554352,
-0.03218906372785568,
-0.004681742750108242,
0.00835549458861351,
-0.005027459003031254,
-0.0026803393848240376,
0.016602693125605583,
0.0032176568638533354,
-0.014786643907427788,
-0.06534446775913239,
-0.006006292998790741,
-0.014869948849081993,
0.002430424327030778,
0.02745733968913555,
0.041685838252305984,
0.0479503758251667,
0.052282240241765976,
-0.04568447917699814,
-0.01642775349318981,
0.002753231441602111,
-0.028007151558995247,
0.02272561378777027,
-0.007114249747246504,
-0.017743973061442375,
0.026757577434182167,
0.023875223472714424,
0.05094935745000839,
-0.08343832194805145,
0.016952574253082275,
-0.053648442029953,
0.053815051913261414,
0.04081946611404419,
-0.011945941485464573,
-0.048483528196811676,
-0.019610004499554634,
0.02934003248810768,
0.047717124223709106,
-0.004794204607605934,
0.022192461416125298,
0.04998302087187767,
0.024175120517611504,
0.008871986530721188,
0.021975867450237274,
0.0008481493568979204,
-0.012079229578375816,
-0.06791026145219803,
0.012179195880889893,
-0.03405509889125824,
0.015086541883647442,
0.02649100124835968,
-0.04241892322897911,
0.0010314204264432192,
0.03295547142624855,
-0.004660916514694691,
-0.027823880314826965,
-0.02917342260479927,
-0.06794358789920807,
0.03832031413912773,
0.040419600903987885,
-0.0481836311519146,
-0.03862021490931511,
-0.018160497769713402,
-0.03922000899910927,
0.021242784336209297,
0.03495479375123978,
0.023392053321003914,
-0.016636015847325325,
0.042152345180511475,
0.003732065437361598,
-0.07704049348831177,
-0.022125815972685814,
0.06241213157773018,
-0.05434820428490639,
-0.06454473733901978,
-0.00733500812202692,
-0.00756826251745224,
0.04031963646411896,
0.07130911201238632,
-0.03027305006980896,
0.023691952228546143,
-0.03118940442800522,
-0.058546777814626694,
-0.00516074663028121,
-0.03692078962922096,
0.0015130277024582028,
-0.016519388183951378,
-0.06271202862262726,
-0.015069880522787571,
-0.01253740768879652,
0.048783428966999054,
0.07950632274150848,
-0.01970997080206871,
-0.006706055253744125,
0.041685838252305984,
0.012928941287100315,
-0.004196491092443466,
0.032538946717977524,
0.006726881489157677,
-0.0010704697342589498,
0.014470084570348263,
0.02130942791700363,
0.010804662480950356,
0.03462157025933266,
0.1157606765627861,
-0.01348708476871252,
-0.02430840954184532,
-0.019793275743722916,
-0.06054610013961792,
-0.032522283494472504,
0.012029246427118778,
0.007130910642445087,
-0.02047637663781643,
-0.0012589473044499755,
-0.036487605422735214,
0.04978308826684952,
0.04008638113737106,
0.010671374388039112,
-0.055414509028196335,
-0.017127515748143196,
0.01112122181802988,
-0.02000986970961094,
-0.06597758829593658,
-0.09696705639362335,
-0.0268242210149765,
-0.0337052159011364,
-0.037587232887744904,
0.03155594691634178,
-0.04135261848568916,
-0.0052565475925803185,
-0.032089099287986755,
0.008905308321118355,
0.01623615063726902,
0.03092282824218273,
-0.01857702247798443,
-0.007676559034734964,
0.0328388437628746,
0.0333886556327343,
0.021725952625274658,
0.05184905230998993,
-0.016127854585647583,
0.027340712025761604,
0.01112122181802988,
0.014561720192432404,
-0.0022575664333999157,
0.03495479375123978,
0.003996558953076601,
-0.038087062537670135,
-0.003517555072903633,
0.011912619695067406,
-0.024241764098405838,
0.015328126028180122,
0.014719999395310879,
0.09190211445093155,
-0.008093084208667278,
-0.04465149715542793,
0.001805636566132307,
-0.059046607464551926,
-0.022575663402676582,
0.016002897173166275,
-0.0020899150986224413,
-0.046884071081876755,
0.027024153620004654,
0.017294125631451607,
-0.0009559252648614347,
-0.049549832940101624,
-0.013170525431632996,
0.010962942615151405,
-0.01625281199812889,
-0.020276445895433426,
0.013062229380011559,
0.033521946519613266,
0.02157600410282612,
-0.02867359295487404,
0.06067938730120659,
0.00953842606395483,
0.03772052004933357,
-0.020859580487012863,
0.003517555072903633,
-0.025308068841695786,
0.011071238666772842,
-0.036987435072660446,
0.003677917178720236,
0.018510378897190094,
-0.0494498685002327,
0.01332047488540411,
-0.024808239191770554,
-0.04095275327563286,
0.0086637232452631,
0.0777735784649849,
0.00646030530333519,
-0.024008510634303093,
-0.04875010624527931,
0.029706574976444244,
0.02362530678510666,
0.03888678923249245,
-0.005718890577554703,
-0.012387458235025406,
-0.08903641998767853,
-0.06111257150769234,
-0.025657949969172478,
-0.038720179349184036,
-0.02002652920782566,
-0.02489154413342476,
0.024008510634303093,
0.041685838252305984,
0.026857541874051094
]
|
31,178 | networkx.algorithms.dag | topological_generations | Stratifies a DAG into generations.
A topological generation is node collection in which ancestors of a node in each
generation are guaranteed to be in a previous generation, and any descendants of
a node are guaranteed to be in a following generation. Nodes are guaranteed to
be in the earliest possible generation that they can belong to.
Parameters
----------
G : NetworkX digraph
A directed acyclic graph (DAG)
Yields
------
sets of nodes
Yields sets of nodes representing each generation.
Raises
------
NetworkXError
Generations are 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 generations
exist 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.
Examples
--------
>>> DG = nx.DiGraph([(2, 1), (3, 1)])
>>> [sorted(generation) for generation in nx.topological_generations(DG)]
[[2, 3], [1]]
Notes
-----
The generation in which a node resides can also be determined by taking the
max-path-distance from the node to the farthest leaf node. That value can
be obtained with this function using `enumerate(topological_generations(G))`.
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.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
]
|
31,179 | networkx.algorithms.dag | topological_sort | Returns a generator of nodes in topologically sorted order.
A topological sort is a nonunique permutation of the nodes of a
directed graph such that an edge from u to v implies that u
appears before v in the topological sort order. This ordering is
valid only if the graph has no directed cycles.
Parameters
----------
G : NetworkX digraph
A directed acyclic graph (DAG)
Yields
------
nodes
Yields the nodes in topological sorted 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.
Examples
--------
To get the reverse order of the topological sort:
>>> DG = nx.DiGraph([(1, 2), (2, 3)])
>>> list(reversed(list(nx.topological_sort(DG))))
[3, 2, 1]
If your DiGraph naturally has the edges representing tasks/inputs
and nodes representing people/processes that initiate tasks, then
topological_sort is not quite what you need. You will have to change
the tasks to nodes with dependence reflected by edges. The result is
a kind of topological sort of the edges. This can be done
with :func:`networkx.line_graph` as follows:
>>> list(nx.topological_sort(nx.line_graph(DG)))
[(1, 2), (2, 3)]
Notes
-----
This algorithm is based on a description and proof in
"Introduction to Algorithms: A Creative Approach" [1]_ .
See also
--------
is_directed_acyclic_graph, lexicographical_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, *, 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
]
|
31,182 | networkx.algorithms.dag | transitive_closure | Returns transitive closure of a graph
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 path from v to w in G.
Handling of paths from v to v has some flexibility within this definition.
A reflexive transitive closure creates a self-loop for the path
from v to v of length 0. The usual transitive closure creates a
self-loop only if a cycle exists (a path from v to v with length > 0).
We also allow an option for no self-loops.
Parameters
----------
G : NetworkX Graph
A directed/undirected graph/multigraph.
reflexive : Bool or None, optional (default: False)
Determines when cycles create self-loops in the Transitive Closure.
If True, trivial cycles (length 0) create self-loops. The result
is a reflexive transitive closure of G.
If False (the default) non-trivial cycles create self-loops.
If None, self-loops are not created.
Returns
-------
NetworkX graph
The transitive closure of `G`
Raises
------
NetworkXError
If `reflexive` not in `{None, True, False}`
Examples
--------
The treatment of trivial (i.e. length 0) cycles is controlled by the
`reflexive` parameter.
Trivial (i.e. length 0) cycles do not create self-loops when
``reflexive=False`` (the default)::
>>> DG = nx.DiGraph([(1, 2), (2, 3)])
>>> TC = nx.transitive_closure(DG, reflexive=False)
>>> TC.edges()
OutEdgeView([(1, 2), (1, 3), (2, 3)])
However, nontrivial (i.e. length greater than 0) cycles create self-loops
when ``reflexive=False`` (the default)::
>>> DG = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
>>> TC = nx.transitive_closure(DG, reflexive=False)
>>> TC.edges()
OutEdgeView([(1, 2), (1, 3), (1, 1), (2, 3), (2, 1), (2, 2), (3, 1), (3, 2), (3, 3)])
Trivial cycles (length 0) create self-loops when ``reflexive=True``::
>>> DG = nx.DiGraph([(1, 2), (2, 3)])
>>> TC = nx.transitive_closure(DG, reflexive=True)
>>> TC.edges()
OutEdgeView([(1, 2), (1, 1), (1, 3), (2, 3), (2, 2), (3, 3)])
And the third option is not to create self-loops at all when ``reflexive=None``::
>>> DG = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
>>> TC = nx.transitive_closure(DG, reflexive=None)
>>> TC.edges()
OutEdgeView([(1, 2), (1, 3), (2, 3), (2, 1), (3, 1), (3, 2)])
References
----------
.. [1] https://www.ics.uci.edu/~eppstein/PADS/PartialOrder.py
| 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, reflexive=False, *, 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
]
|
31,183 | networkx.algorithms.dag | transitive_closure_dag | 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.
| 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, topo_order=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
]
|
31,184 | networkx.algorithms.dag | transitive_reduction | Returns transitive reduction of a directed graph
The transitive reduction 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 (v,w) is
in E and there is no path from v to w in G with length greater than 1.
Parameters
----------
G : NetworkX DiGraph
A directed acyclic graph (DAG)
Returns
-------
NetworkX DiGraph
The transitive reduction of `G`
Raises
------
NetworkXError
If `G` is not a directed acyclic graph (DAG) transitive reduction is
not uniquely defined and a :exc:`NetworkXError` exception is raised.
Examples
--------
To perform transitive reduction on a DiGraph:
>>> DG = nx.DiGraph([(1, 2), (2, 3), (1, 3)])
>>> TR = nx.transitive_reduction(DG)
>>> list(TR.edges)
[(1, 2), (2, 3)]
To avoid unnecessary data copies, this implementation does not return a
DiGraph with node/edge data.
To perform transitive reduction on a DiGraph and transfer node/edge data:
>>> DG = nx.DiGraph()
>>> DG.add_edges_from([(1, 2), (2, 3), (1, 3)], color="red")
>>> TR = nx.transitive_reduction(DG)
>>> TR.add_nodes_from(DG.nodes(data=True))
>>> TR.add_edges_from((u, v, DG.edges[u, v]) for u, v in TR.edges)
>>> list(TR.edges(data=True))
[(1, 2, {'color': 'red'}), (2, 3, {'color': 'red'})]
References
----------
https://en.wikipedia.org/wiki/Transitive_reduction
| 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.032685063779354095,
0.021145019680261612,
-0.024768874049186707,
0.007955769076943398,
-0.036273736506700516,
-0.030996276065707207,
-0.018928486853837967,
-0.012683493085205555,
0.09302400797605515,
-0.07761383056640625,
0.012164543382823467,
0.028251996263861656,
0.0004922879743389785,
-0.011768733151257038,
-0.03161197900772095,
0.02234124206006527,
-0.014002857729792595,
-0.017301268875598907,
0.003228045767173171,
0.02946581318974495,
0.0008916706428863108,
-0.06413871794939041,
0.013457519933581352,
-0.023889297619462013,
-0.01571803167462349,
0.016518445685505867,
-0.047004569321870804,
0.032122135162353516,
-0.06055004522204399,
-0.03136569634079933,
0.03115459904074669,
-0.04538614675402641,
-0.09056119620800018,
0.013466316275298595,
0.052669040858745575,
0.08092103898525238,
-0.00040652925963513553,
0.018101684749126434,
-0.01716933399438858,
-0.06037412956357002,
0.01223490945994854,
-0.018453514203429222,
-0.011522452346980572,
-0.03245637193322182,
0.045878708362579346,
0.01338715385645628,
-0.009130003862082958,
0.038138438016176224,
-0.0373644083738327,
-0.04950256645679474,
0.08640959113836288,
-0.03725885972380638,
-0.005761226173490286,
-0.010616488754749298,
0.015304630622267723,
0.03912356123328209,
0.01952659897506237,
0.05942418798804283,
0.06814958900213242,
-0.017776241526007652,
-0.00996560137718916,
-0.05523740500211716,
-0.009042046032845974,
0.035499706864356995,
-0.050980255007743835,
0.02126815915107727,
-0.03680147975683212,
-0.06016303226351738,
-0.021180201321840286,
0.007296087220311165,
-0.013721393421292305,
0.02014230191707611,
0.0056512788869440556,
-0.0760657787322998,
-0.027319645509123802,
-0.07641760259866714,
0.027917757630348206,
-0.045210231095552444,
-0.028533460572361946,
-0.03518306091427803,
-0.034373849630355835,
-0.06843104958534241,
0.023449508473277092,
-0.008311998099088669,
0.061359256505966187,
-0.02795294113457203,
0.0336877815425396,
-0.0014688927913084626,
-0.06762184202671051,
-0.040777165442705154,
0.00782823096960783,
-0.03439144045114517,
-0.031242556869983673,
0.03272024542093277,
0.03743477538228035,
-0.00883534550666809,
-0.0009345500147901475,
-0.04858780652284622,
0.010027172043919563,
0.00999198853969574,
0.038982830941677094,
0.0075203790329396725,
-0.08542446792125702,
-0.006280176341533661,
0.023168044164776802,
-0.04538614675402641,
-0.017468389123678207,
0.016799911856651306,
-0.0173452477902174,
-0.08753545582294464,
-0.0024716099724173546,
-0.001261092838831246,
0.09773854166269302,
-0.03887728229165077,
0.0315416119992733,
0.01310568954795599,
0.007806241512298584,
0.0006888183415867388,
-0.0004054298042319715,
-0.005704053677618504,
0.014134794473648071,
0.022200509905815125,
0.001091774320229888,
0.012727471999824047,
-0.007287291344255209,
0.008070114068686962,
0.009332306683063507,
0.02767147682607174,
0.034373849630355835,
-0.010845177806913853,
0.06100742518901825,
-0.013747780583798885,
0.033247992396354675,
0.0816950649023056,
0.05168391391634941,
0.0038195608649402857,
-0.03236841410398483,
0.015366201288998127,
-0.020335808396339417,
0.02272825688123703,
-0.010150312446057796,
-0.06139443814754486,
-0.021584806963801384,
0.049361832439899445,
0.04985439404845238,
0.003936104942113161,
-0.0057700215838849545,
-0.013246421702206135,
0.011944648809731007,
0.019262725487351418,
0.008487912826240063,
0.003883330151438713,
-0.014812068082392216,
0.032632287591695786,
0.00014732906129211187,
-0.007837026380002499,
-0.043626993894577026,
0.07240673899650574,
-0.05365416780114174,
0.012102972716093063,
-0.03133051469922066,
0.04725084826350212,
-0.04007350653409958,
0.024768874049186707,
0.016703156754374504,
-0.0019020842155441642,
0.11406347900629044,
0.006262584589421749,
-0.031506430357694626,
0.031400881707668304,
-0.0567854568362236,
-0.030767586082220078,
-0.0073576574213802814,
-0.0048376708291471004,
-0.006174627225846052,
0.02990560047328472,
0.0038151631597429514,
0.030556486919522285,
-0.016069862991571426,
0.021743131801486015,
-0.016527242958545685,
0.0005750231212005019,
-0.04573797807097435,
0.021232977509498596,
0.03242119029164314,
0.031049050390720367,
0.04119936376810074,
-0.04014386981725693,
0.07698053121566772,
-0.021004287526011467,
-0.05499112233519554,
0.012709880247712135,
0.03789215534925461,
0.023326369002461433,
0.07536211609840393,
-0.05590588226914406,
-0.030011149123311043,
0.037188492715358734,
-0.04770822823047638,
0.0715271607041359,
0.06396280229091644,
0.015049553476274014,
0.0719141736626625,
0.03331835940480232,
0.023695791140198708,
0.08155433088541031,
0.03433866798877716,
-0.0330193005502224,
-0.02374856546521187,
0.008602257817983627,
-0.012982549145817757,
-0.02547253482043743,
0.010642875917255878,
-0.03989759087562561,
-0.051719099283218384,
0.03228045627474785,
-0.038243986666202545,
0.013545477762818336,
0.048130426555871964,
0.0019031836418434978,
-0.026334520429372787,
0.03708294406533241,
0.025683633983135223,
-0.016905460506677628,
0.07043648511171341,
-0.0775434672832489,
-0.00041230148053728044,
0.011293762363493443,
0.02026544325053692,
-0.05949455499649048,
0.011012298054993153,
-0.007203731685876846,
0.03279061242938042,
-0.01970251277089119,
0.06195736676454544,
-0.04429547116160393,
-0.03514787554740906,
0.003166475333273411,
0.01885811984539032,
0.017925769090652466,
-0.05073397234082222,
-0.006042690481990576,
-0.0246457327157259,
0.010572509840130806,
-0.01701100915670395,
-0.0051851035095751286,
0.026580801233649254,
0.006029496900737286,
0.03249155730009079,
0.026404885575175285,
-0.05122653394937515,
-0.03567562252283096,
-0.04865817353129387,
-0.029659319669008255,
-0.031066641211509705,
-0.01248998660594225,
-0.00406804122030735,
-0.0567854568362236,
-0.005330233369022608,
0.01728367805480957,
0.0003889377403538674,
0.017204515635967255,
-0.05762985348701477,
0.0692402645945549,
0.008874926716089249,
-0.029483404010534286,
0.03428589180111885,
-0.0818357989192009,
-0.06688299775123596,
-0.0055193426087498665,
-0.016623996198177338,
0.003927309066057205,
0.04401400685310364,
0.005404997617006302,
0.003740399144589901,
-0.04095308110117912,
0.01548934169113636,
0.016078658401966095,
-0.003052130341529846,
-0.029958374798297882,
-0.041832659393548965,
0.029272304847836494,
-0.03126014769077301,
-0.02311526983976364,
-0.06280176341533661,
-0.00643849978223443,
-0.011302557773888111,
-0.026897449046373367,
0.02211255393922329,
0.018541472032666206,
0.07648797333240509,
0.00267391256056726,
0.07296966761350632,
0.02480405755341053,
0.06304804235696793,
0.035376567393541336,
0.026404885575175285,
-0.025384576991200447,
-0.0024738088250160217,
0.033036891371011734,
0.07360295951366425,
0.009490630589425564,
-0.016316143795847893,
-0.051824647933244705,
0.0018350164173170924,
0.004556206054985523,
0.00987764447927475,
-0.00797336082905531,
-0.029395446181297302,
0.04014386981725693,
-0.05168391391634941,
-0.049924761056900024,
-0.07036612182855606,
0.04506950080394745,
-0.06931062787771225,
-0.03412756696343422,
-0.03266746923327446,
-0.04932665079832077,
0.05442819371819496,
0.011768733151257038,
0.002366060856729746,
0.01565646193921566,
-0.008492311462759972,
-0.006530855316668749,
-0.07648797333240509,
0.046828653663396835,
0.00968413706868887,
0.05780576542019844,
0.058509428054094315,
0.010255862027406693,
-0.00573923671618104,
0.03866618126630783,
0.005264265462756157,
0.057102106511592865,
-0.0030741197988390923,
0.07078831642866135,
0.09661268442869186,
-0.029923193156719208,
0.015225469134747982,
-0.028251996263861656,
0.04563242942094803,
0.041903022676706314,
-0.028832517564296722,
0.00971052423119545,
-0.012402028776705265,
0.010009580291807652,
0.00301694730296731,
-0.0014095213264226913,
0.03704776242375374,
-0.022763440385460854,
0.04309924691915512,
0.03806807100772858,
-0.018136868253350258,
0.02726687118411064,
-0.03915874660015106,
0.06572195887565613,
0.0491507351398468,
-0.008699011988937855,
0.014935208484530449,
0.027847392484545708,
0.0034435419365763664,
-0.022147735580801964,
0.019438641145825386,
-0.03623855113983154,
0.05523740500211716,
0.0031818679999560118,
-0.009015658870339394,
0.037469957023859024,
-0.020898737013339996,
-0.04450657218694687,
0.017019804567098618,
-0.011346536688506603,
0.04067161679267883,
0.009305919520556927,
-0.051332082599401474,
0.03052130527794361,
0.047778595238924026,
-0.054076362401247025,
0.05298568680882454,
0.036062635481357574,
-0.019948795437812805,
0.017591530457139015,
-0.008021737448871136,
0.03131292387843132,
0.020441357046365738,
0.01518149022012949,
0.043626993894577026,
0.008650634437799454,
0.0235726498067379,
-0.027812208980321884,
-0.005598504561930895,
-0.027055773884058,
0.04545651376247406,
-0.003916314337402582,
0.0003812414361163974,
-0.03430348262190819,
0.06614415347576141,
0.04461212083697319,
0.025771591812372208,
0.0029487803112715483,
-0.014574582688510418,
0.007639121729880571,
0.02198941260576248,
0.008954089134931564,
0.02367819845676422,
-0.03344149887561798,
0.012164543382823467,
0.036836665123701096,
0.06178145483136177,
0.04883408546447754,
-0.0036458445247262716,
0.006302165798842907,
0.03208694979548454,
-0.017098966985940933,
-0.020159892737865448,
-0.019667331129312515,
-0.07110496610403061,
0.003052130341529846,
0.05868534371256828,
0.002328678732737899,
0.04897481948137283,
0.02900843322277069,
0.0283927284181118,
-0.038982830941677094,
0.004657357465475798,
-0.03410997614264488,
0.031400881707668304,
0.03915874660015106,
-0.010352615267038345,
0.09196852147579193,
0.010730832815170288,
-0.03205176815390587,
0.013184851966798306,
-0.03331835940480232,
0.00006802974530728534,
0.02098669484257698,
0.014152386225759983,
0.008237234316766262,
0.040038321167230606,
0.06617933511734009,
-0.0076831006444990635,
0.04024942219257355,
-0.025279028341174126,
-0.06090187653899193,
-0.011927057057619095,
-0.029430629685521126,
0.008998067118227482,
0.03294893726706505,
0.04911554977297783,
-0.02227087691426277,
0.046265725046396255,
0.04651200398802757,
-0.006750749424099922,
-0.011575226671993732,
-0.08507263660430908,
0.050030309706926346,
0.024663325399160385,
-0.0053566209971904755,
-0.11863727867603302,
0.01023827027529478,
0.008602257817983627,
-0.03215731680393219,
0.0596001036465168,
-0.04528059810400009,
-0.01633373461663723,
-0.02227087691426277,
0.0026519231032580137,
0.0009862250881269574,
-0.04091789945960045,
-0.03261469677090645,
0.05136726796627045,
-0.032755427062511444,
-0.05924827232956886,
-0.04394363984465599,
0.04496395215392113,
0.015172694809734821,
-0.05309123545885086,
0.03326558321714401,
0.05731320381164551,
-0.033423908054828644,
0.020740414038300514,
-0.029606545343995094,
0.003546892199665308,
0.011179417371749878,
0.0026123421266674995,
0.000982376979663968,
0.015295835211873055,
-0.020406175404787064,
0.011161825619637966,
-0.0004549059667624533,
0.001628316007554531,
-0.02295694686472416,
-0.005989916156977415,
-0.0114520862698555,
0.006214207969605923,
0.038982830941677094,
-0.015858763828873634,
-0.0360274538397789,
0.009437855333089828,
0.006139443721622229,
-0.0015810386976227164,
0.042114123702049255,
-0.01811927556991577,
0.021057061851024628,
-0.0009345500147901475,
-0.03623855113983154,
0.009578588418662548,
0.026299336925148964,
0.012709880247712135,
0.013932491652667522,
0.041058629751205444,
0.022816214710474014,
0.00875618401914835,
0.0340220183134079,
0.010141517035663128,
0.014741702005267143,
-0.023273594677448273,
0.004894843325018883,
0.024329086765646935,
-0.029553771018981934,
0.0041581979021430016,
0.013149668462574482,
0.020670047029852867,
0.08056920766830444,
-0.011320149526000023,
-0.012938570231199265,
0.02137370966374874,
-0.034145157784223557,
-0.006957449950277805,
-0.00301694730296731,
0.00044281178270466626,
0.03236841410398483,
-0.013879717327654362,
0.057278022170066833,
-0.0036744307726621628,
-0.05280977115035057,
-0.00797336082905531,
-0.02441704273223877,
-0.11610409617424011,
0.0006140543264336884,
0.01409081555902958,
0.04827115684747696,
0.015893947333097458,
0.013255218043923378,
0.03915874660015106,
-0.010766016319394112,
0.046265725046396255,
-0.04091789945960045,
-0.028093673288822174,
-0.010871565900743008,
-0.07895078510046005,
0.03115459904074669,
-0.012665901333093643,
0.025331802666187286,
0.036273736506700516,
-0.03430348262190819,
-0.027020590379834175,
0.04971366375684738,
-0.021461665630340576,
0.01041418593376875,
-0.057278022170066833,
-0.009657749906182289,
-0.0658978745341301,
-0.05302087217569351,
0.014627357013523579,
0.006917869206517935,
0.05122653394937515,
-0.009059637784957886,
0.03215731680393219,
-0.022886579856276512,
0.01391489990055561,
-0.08148396760225296,
0.012076585553586483,
-0.0020769000984728336,
-0.020951511338353157,
0.05066360533237457,
-0.01248998660594225,
0.011847895570099354,
0.03722367808222771,
-0.0617462694644928,
-0.019843244925141335,
-0.035781171172857285,
0.018260007724165916,
0.038912463933229446,
0.007612734567373991,
-0.011355332098901272,
-0.0006899178260937333,
0.03433866798877716,
0.0021824492141604424,
-0.039369843900203705,
0.018260007724165916,
-0.04039015248417854,
0.019561780616641045,
0.006873890291899443,
-0.0017921371618285775,
-0.015674052760004997,
-0.010862769559025764,
0.06741074472665787,
-0.01728367805480957,
-0.023484691977500916,
-0.03866618126630783,
0.005448976531624794,
0.028216814622282982,
0.01683509349822998,
-0.06941618025302887,
0.001983444904908538,
0.008008544333279133,
-0.03732922673225403,
0.06941618025302887,
-0.03986240550875664,
-0.0021956427954137325,
0.017433205619454384,
-0.03659038245677948,
-0.0443306565284729,
-0.04911554977297783,
-0.010581305250525475,
-0.07508064806461334,
0.028990840539336205,
-0.0791618824005127,
0.00432311836630106,
0.0183479655534029,
-0.02570122480392456,
0.01484725158661604,
-0.03395165130496025,
-0.03912356123328209,
0.08078030496835709,
0.0336877815425396,
-0.04696938395500183,
0.002129674656316638,
0.05319678783416748,
-0.03233323246240616,
-0.020863555371761322,
-0.006275778170675039,
0.03592190518975258,
0.01582358032464981,
-0.07958408445119858,
0.0013600451638922095,
0.02434667758643627,
-0.0183479655534029,
-0.027847392484545708,
-0.10695650428533554,
0.04496395215392113,
-0.03944021090865135,
0.000808660639449954,
-0.05083952099084854,
-0.020793188363313675,
0.009789686650037766,
-0.046441640704870224,
-0.005154318176209927,
-0.042852967977523804,
-0.013026528060436249,
0.018893303349614143,
0.03708294406533241,
0.00423735985532403,
0.013369563035666943,
0.06695336103439331,
0.04176229238510132,
-0.04478803649544716,
0.03458494693040848,
0.011513656005263329,
0.07824712246656418,
0.013659822754561901,
0.018488697707653046,
-0.01991361193358898,
-0.0019603560212999582,
0.02575399912893772,
0.05010067671537399,
-0.0664256140589714,
-0.004833272658288479,
-0.04253631830215454,
-0.02446981891989708,
0.02311526983976364,
0.012648309580981731,
-0.027812208980321884,
-0.022517157718539238,
-0.005097145680338144,
0.037118129432201385,
0.02918434888124466,
0.012331662699580193,
-0.029923193156719208,
0.027372419834136963,
0.06452573090791702,
0.007089386694133282,
-0.04573797807097435,
-0.015031962655484676,
-0.014583378098905087,
-0.014046836644411087,
-0.039088379591703415,
0.0638924390077591,
-0.0533023364841938,
0.03849026560783386,
-0.0023044904228299856,
0.0073268720880150795,
-0.016430489718914032,
0.05787613242864609,
0.0056292894296348095,
-0.001704179449006915,
0.01459217444062233,
0.01592913083732128,
-0.019051626324653625,
-0.005176307633519173,
0.0021780512761324644,
0.0340220183134079,
0.03694221377372742,
-0.025683633983135223,
-0.005607299972325563,
-0.03428589180111885,
-0.03143606334924698,
0.002090093679726124,
0.017081376165151596,
-0.03456735610961914,
-0.03243878111243248,
-0.006104260683059692,
0.01599949598312378,
0.017758648842573166,
-0.04904518648982048,
-0.041269730776548386,
0.0065044681541621685,
-0.04429547116160393,
-0.002172553911805153,
0.01903403550386429,
0.03243878111243248,
-0.05734838917851448,
0.0214968491345644,
0.024205945432186127,
0.05207092687487602,
0.022868989035487175,
-0.03599226847290993,
-0.031453654170036316,
-0.029254714027047157,
-0.011944648809731007,
0.048622988164424896,
0.02177831344306469,
0.007951371371746063,
-0.020019160583615303,
-0.0038393514696508646,
-0.047778595238924026,
0.033652596175670624,
-0.04137527942657471,
0.032755427062511444,
-0.03514787554740906,
0.015445363707840443,
-0.05495594069361687,
0.02177831344306469,
-0.010229474864900112,
-0.018031317740678787,
-0.025613266974687576,
-0.0008663828484714031,
0.015269448049366474,
-0.01880534552037716,
0.004608980845659971,
0.006469285115599632,
0.004802487790584564,
-0.08394677937030792,
-0.018506288528442383,
-0.010247066617012024,
-0.05713728815317154,
-0.020511724054813385,
-0.06230919808149338,
-0.06104261055588722,
-0.04422510787844658,
-0.012938570231199265,
0.015418975614011288,
-0.026281746104359627,
0.05618734657764435,
0.01433709729462862,
0.034197933971881866,
0.04957292973995209
]
|
31,191 | networkx.readwrite.json_graph.tree | tree_data | Returns data in tree format that is suitable for JSON serialization
and use in JavaScript documents.
Parameters
----------
G : NetworkX graph
G must be an oriented tree
root : node
The root of the tree
ident : string
Attribute name for storing NetworkX-internal graph data. `ident` must
have a different value than `children`. The default is 'id'.
children : string
Attribute name for storing NetworkX-internal graph data. `children`
must have a different value than `ident`. The default is 'children'.
Returns
-------
data : dict
A dictionary with node-link formatted data.
Raises
------
NetworkXError
If `children` and `ident` attributes are identical.
Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1, 2)])
>>> data = json_graph.tree_data(G, root=1)
To serialize with json
>>> import json
>>> s = json.dumps(data)
Notes
-----
Node attributes are stored in this format but keys
for attributes must be strings if you want to serialize with JSON.
Graph and edge attributes are not stored.
See Also
--------
tree_graph, node_link_data, adjacency_data
| def tree_data(G, root, ident="id", children="children"):
"""Returns data in tree format that is suitable for JSON serialization
and use in JavaScript documents.
Parameters
----------
G : NetworkX graph
G must be an oriented tree
root : node
The root of the tree
ident : string
Attribute name for storing NetworkX-internal graph data. `ident` must
have a different value than `children`. The default is 'id'.
children : string
Attribute name for storing NetworkX-internal graph data. `children`
must have a different value than `ident`. The default is 'children'.
Returns
-------
data : dict
A dictionary with node-link formatted data.
Raises
------
NetworkXError
If `children` and `ident` attributes are identical.
Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1, 2)])
>>> data = json_graph.tree_data(G, root=1)
To serialize with json
>>> import json
>>> s = json.dumps(data)
Notes
-----
Node attributes are stored in this format but keys
for attributes must be strings if you want to serialize with JSON.
Graph and edge attributes are not stored.
See Also
--------
tree_graph, node_link_data, adjacency_data
"""
if G.number_of_nodes() != G.number_of_edges() + 1:
raise TypeError("G is not a tree.")
if not G.is_directed():
raise TypeError("G is not directed.")
if not nx.is_weakly_connected(G):
raise TypeError("G is not weakly connected.")
if ident == children:
raise nx.NetworkXError("The values for `id` and `children` must be different.")
def add_children(n, G):
nbrs = G[n]
if len(nbrs) == 0:
return []
children_ = []
for child in nbrs:
d = {**G.nodes[child], ident: child}
c = add_children(child, G)
if c:
d[children] = c
children_.append(d)
return children_
return {**G.nodes[root], ident: root, children: add_children(root, G)}
| (G, root, ident='id', children='children') | [
-0.008505553938448429,
0.020497146993875504,
0.038251183927059174,
-0.03958464041352272,
0.014858527109026909,
0.06690146774053574,
-0.04655671864748001,
0.03842262551188469,
0.09966642409563065,
-0.056805290281772614,
0.02857409045100212,
0.012391630560159683,
0.004174198489636183,
0.02171630784869194,
-0.0393560454249382,
-0.04929983243346214,
-0.0011024835985153913,
0.033203091472387314,
0.02148771658539772,
0.022630680352449417,
-0.021659160032868385,
-0.02356410026550293,
0.008981789462268353,
0.015287138521671295,
-0.0425182469189167,
-0.014906150288879871,
0.02013520896434784,
0.024611815810203552,
0.03377457335591316,
0.01944943144917488,
-0.0035193755757063627,
-0.0766928568482399,
-0.0397370345890522,
-0.012544025667011738,
-0.021354369819164276,
0.009096085093915462,
-0.041146691888570786,
0.04789017513394356,
-0.07265438884496689,
-0.00574815459549427,
-0.01979232020676136,
-0.0006107711815275252,
-0.05002370849251747,
-0.030002795159816742,
0.008362683467566967,
0.01786833070218563,
0.010753382928669453,
0.03392697125673294,
-0.016230084002017975,
-0.06937789171934128,
0.022573530673980713,
-0.03042188100516796,
-0.023430753499269485,
0.03023138828575611,
-0.0034884202759712934,
-0.004517087247222662,
0.025830978527665138,
0.037908293306827545,
0.04312782734632492,
0.014506112784147263,
0.0318886861205101,
0.015410959720611572,
0.012696420773863792,
-0.01085815392434597,
-0.06861591339111328,
0.012315432541072369,
-0.052423931658267975,
-0.04979511350393295,
-0.052042942494153976,
-0.004138480871915817,
-0.04316592589020729,
-0.020630493760108948,
0.045680444687604904,
0.02552618831396103,
0.05330020189285278,
0.015858620405197144,
-0.006324398797005415,
-0.007024463731795549,
-0.029736103489995003,
0.07097803801298141,
-0.03497468680143356,
-0.0707494467496872,
0.003781304694712162,
0.038708366453647614,
-0.01681108959019184,
-0.01877317763864994,
-0.0071101863868534565,
0.04602333530783653,
0.008172189816832542,
-0.036631982773542404,
-0.04308972880244255,
0.004843308124691248,
0.005876738112419844,
0.03585095703601837,
-0.03261256217956543,
-0.03192678466439247,
-0.0021263884846121073,
0.02510710060596466,
0.027507323771715164,
0.04316592589020729,
0.0016668218886479735,
0.06225341930985451,
-0.03352693095803261,
-0.012620223686099052,
-0.01817312091588974,
-0.06659667938947678,
-0.024421323090791702,
0.0063863093964755535,
-0.01282024197280407,
-0.01975422166287899,
-0.07673095911741257,
0.007253056392073631,
0.02051619626581669,
-0.014020353555679321,
0.09204667061567307,
0.018030250445008278,
0.019097017124295235,
-0.03846072405576706,
-0.015630027279257774,
-0.06484413892030716,
0.0022287790197879076,
0.04084189981222153,
0.009648517705500126,
0.03634624183177948,
-0.005714817903935909,
0.011648704297840595,
0.04971891641616821,
-0.004614715464413166,
-0.0334126353263855,
-0.03642243891954422,
0.052500128746032715,
0.048880744725465775,
0.003964655101299286,
0.06198672577738762,
0.09837106615304947,
-0.009577082470059395,
-0.001238210592418909,
0.006781584117561579,
0.04259444400668144,
0.009753289632499218,
-0.02051619626581669,
-0.0701017677783966,
-0.012182087637484074,
0.0163253303617239,
-0.00035360438050702214,
-0.04339451715350151,
-0.002571668243035674,
-0.04408029839396477,
-0.05493845045566559,
-0.0271453857421875,
0.032136328518390656,
0.00010410195682197809,
0.045489951968193054,
-0.0006339876563288271,
0.0028074043802917004,
-0.004952842369675636,
-0.059434108436107635,
-0.051890548318624496,
-0.02036380209028721,
0.02179250679910183,
0.019049393013119698,
0.01794452965259552,
0.00929134152829647,
0.00020135803788434714,
0.0090484619140625,
0.034479402005672455,
0.04766158387064934,
-0.06552991271018982,
-0.03823213279247284,
0.02228778973221779,
0.00574815459549427,
-0.016220558434724808,
-0.048804547637701035,
0.03943224623799324,
0.033679328858852386,
-0.011658228933811188,
0.06126284971833229,
0.01715397834777832,
0.011039123870432377,
0.03166009113192558,
-0.0024859458208084106,
0.00503380224108696,
0.0029359878972172737,
0.05741487070918083,
0.02055429480969906,
-0.048956941813230515,
0.01948752999305725,
-0.008867492899298668,
0.056576699018478394,
-0.026211965829133987,
-0.042289651930332184,
-0.028002608567476273,
-0.007848350331187248,
0.055852822959423065,
0.04651862010359764,
-0.03796544298529625,
0.005557660479098558,
-0.0196780227124691,
-0.012601173482835293,
0.0763118714094162,
-0.02752637304365635,
-0.014306094497442245,
0.03118385747075081,
-0.038517873734235764,
-0.0005018324591219425,
-0.009091323241591454,
-0.013629840686917305,
-0.02752637304365635,
-0.04015612229704857,
-0.04030851647257805,
0.025621434673666954,
0.001632294966839254,
0.026516756042838097,
0.041413381695747375,
-0.05135716497898102,
-0.020763838663697243,
-0.0063863093964755535,
0.021963950246572495,
-0.026269113644957542,
-0.0680825337767601,
-0.023926038295030594,
0.029240818694233894,
-0.019963763654232025,
-0.002819310175254941,
-0.008438881486654282,
-0.07627376914024353,
0.05093807727098465,
-0.025659533217549324,
0.03238397091627121,
-0.038746464997529984,
0.0370129719376564,
0.01994471438229084,
0.004367073532193899,
-0.014963299036026001,
0.0016251513734459877,
-0.05490035191178322,
0.01480137836188078,
-0.03514613211154938,
0.04994751140475273,
0.02653580531477928,
-0.000910203845705837,
-0.04674721136689186,
-0.004074188880622387,
-0.023164061829447746,
0.01745876856148243,
-0.018373139202594757,
0.04373740777373314,
0.023697445169091225,
0.01568717509508133,
-0.03369837626814842,
-0.05909121781587601,
-0.01990661583840847,
0.03158389404416084,
0.019849468022584915,
-0.016039589419960976,
0.0005187983042560518,
-0.004643289837986231,
0.05711008235812187,
-0.0044623203575611115,
-0.022802123799920082,
0.009053224697709084,
-0.04648052155971527,
-0.052271537482738495,
0.09097990393638611,
0.030059942975640297,
-0.03689867630600929,
0.021392468363046646,
-0.016982534900307655,
-0.0641583576798439,
-0.02522139623761177,
0.07139712572097778,
0.0020001863595098257,
0.041375283151865005,
-0.0578339584171772,
0.02352600172162056,
-0.024611815810203552,
0.0012917870189994574,
0.005519561935216188,
0.008191239088773727,
-0.052157238125801086,
-0.045451853424310684,
-0.029621807858347893,
-0.0075387973338365555,
-0.019258936867117882,
-0.030479028820991516,
-0.04400409758090973,
-0.010591463185846806,
0.03291735053062439,
0.00999140739440918,
-0.03026948682963848,
0.031088611111044884,
-0.023926038295030594,
-0.08838918805122375,
0.02314501255750656,
0.014963299036026001,
-0.007876924239099026,
-0.06667287647724152,
-0.04994751140475273,
0.041375283151865005,
0.03453655168414116,
0.003983704373240471,
-0.011439160443842411,
0.11170564591884613,
-0.02137341909110546,
-0.04232775419950485,
0.03268875926733017,
-0.0015310950111597776,
-0.024573717266321182,
-0.037641603499650955,
0.0033788862638175488,
-0.01941133290529251,
0.016582496464252472,
0.04415649548172951,
0.00853889063000679,
-0.05413837730884552,
-0.033050697296857834,
0.02186870388686657,
-0.06274870038032532,
0.06537751853466034,
0.016458675265312195,
-0.041222888976335526,
0.0053481170907616615,
-0.011143894866108894,
-0.0028574089519679546,
0.04312782734632492,
0.028440745547413826,
0.08450310677289963,
0.07174001634120941,
0.04731869325041771,
0.004243252333253622,
-0.042289651930332184,
-0.006976840551942587,
0.008010270074009895,
0.03465084731578827,
-0.030479028820991516,
0.052462030202150345,
0.029050325974822044,
-0.04377550631761551,
0.001562050310894847,
0.0002528509357944131,
-0.02464991621673107,
-0.018011201173067093,
-0.005657670088112354,
-0.009172283113002777,
-0.005852926056832075,
0.013372674584388733,
0.03686057776212692,
0.017963578924536705,
0.028174053877592087,
-0.0012251141015440226,
-0.05017610266804695,
0.06892070919275284,
-0.02575477957725525,
-0.006019608583301306,
-0.05006180703639984,
-0.0496046207845211,
0.0704827532172203,
-0.06118665263056755,
-0.048194967210292816,
0.0511285737156868,
0.04301353171467781,
0.035812858492136,
0.006972078233957291,
0.0014167986810207367,
-0.012067791074514389,
-0.019582776352763176,
0.0075721340253949165,
0.056195709854364395,
0.07193051278591156,
-0.060157984495162964,
0.018449338153004646,
-0.021049579605460167,
-0.025278545916080475,
0.03223157301545143,
0.014410866424441338,
0.03268875926733017,
0.018916048109531403,
-0.03442225605249405,
-0.01357269287109375,
-0.011134370230138302,
-0.052576325833797455,
-0.041413381695747375,
0.03754635527729988,
0.0015239515341818333,
0.04248014837503433,
-0.02171630784869194,
0.1309836357831955,
-0.004483751021325588,
-0.02228778973221779,
0.009057986550033092,
-0.07566419243812561,
-0.014125125482678413,
0.01952562853693962,
0.05703388527035713,
-0.08076942712068558,
-0.03343168646097183,
0.041680071502923965,
-0.023011667653918266,
-0.04762348532676697,
-0.0008887732983566821,
-0.013420297764241695,
-0.009577082470059395,
-0.029945647343993187,
-0.0053100185468792915,
0.06427265703678131,
-0.014953774400055408,
0.05025229975581169,
-0.06225341930985451,
0.048804547637701035,
-0.002702632686123252,
0.018858900293707848,
0.005252870265394449,
0.008248387835919857,
0.04027041792869568,
0.1219923198223114,
-0.0018251700093969703,
0.022497333586215973,
0.03977513313293457,
0.019125591963529587,
-0.012410679832100868,
0.017011107876896858,
0.014315619133412838,
0.013629840686917305,
0.020687641575932503,
0.025240447372198105,
0.04282303526997566,
-0.023240260779857635,
-0.013029784895479679,
-0.04305163025856018,
0.09791388362646103,
0.002262115478515625,
-0.025507137179374695,
0.04099429398775101,
-0.06838732212781906,
0.026345310732722282,
0.02122102491557598,
0.007334016729146242,
-0.034174613654613495,
0.008419832214713097,
0.07970266044139862,
-0.0031074322760105133,
0.0637773722410202,
-0.009467548690736294,
-0.0472043976187706,
-0.01330600120127201,
-0.02352600172162056,
0.026592953130602837,
0.03920365124940872,
0.056500501930713654,
-0.012229710817337036,
0.04956652224063873,
0.027126336470246315,
0.05848163738846779,
-0.056081414222717285,
-0.06987317651510239,
-0.023697445169091225,
0.015220465138554573,
-0.01670631766319275,
-0.03927984833717346,
0.04648052155971527,
-0.00863413792103529,
-0.035755712538957596,
0.022363988682627678,
0.015658602118492126,
-0.03276495635509491,
-0.02706918865442276,
0.007834062911570072,
-0.018858900293707848,
-0.04305163025856018,
0.011229617521166801,
0.03703201934695244,
0.049223631620407104,
-0.04602333530783653,
-0.008724622428417206,
0.033679328858852386,
0.018268369138240814,
-0.048652149736881256,
-0.04068950563669205,
-0.09760909527540207,
-0.06217722222208977,
-0.0012429729104042053,
-0.016201509162783623,
0.0727686807513237,
-0.02024950459599495,
-0.0036003354471176863,
-0.005914836656302214,
0.03476514294743538,
0.012601173482835293,
0.02310691401362419,
-0.027850212529301643,
-0.03541282191872597,
0.002678820863366127,
-0.014115600846707821,
0.019773270934820175,
0.022687828168272972,
0.0720067098736763,
0.01763973757624626,
-0.023773644119501114,
-0.02748827449977398,
-0.02299261838197708,
-0.01760163903236389,
-0.02476421184837818,
0.03322214260697365,
-0.006057707127183676,
-0.01459183543920517,
0.025983372703194618,
-0.017096830531954765,
0.056652896106243134,
0.02002091333270073,
0.023354556411504745,
-0.015963392332196236,
-0.008586513809859753,
0.04293733462691307,
0.017392097041010857,
-0.020801937207579613,
0.020497146993875504,
-0.02314501255750656,
0.06259630620479584,
-0.021925851702690125,
-0.059776995331048965,
-0.01944943144917488,
-0.006281537469476461,
0.03792734444141388,
-0.008596038445830345,
-0.025983372703194618,
0.05402408167719841,
0.004440889693796635,
-0.00946278590708971,
-0.022821173071861267,
0.03491753712296486,
-0.04598523676395416,
0.02684059552848339,
0.012972637079656124,
0.04651862010359764,
-0.05147146061062813,
-0.01983041875064373,
0.0735306590795517,
-0.0015787185402587056,
0.01944943144917488,
-0.023316457867622375,
0.04659481719136238,
0.014868051744997501,
0.015144268050789833,
-0.01723017729818821,
0.030155189335346222,
0.009191332384943962,
0.05867213383316994,
-0.002890745410695672,
0.03804164007306099,
-0.02028760500252247,
-0.004436127375811338,
-0.021392468363046646,
0.008043606765568256,
-0.028307398781180382,
0.008415069431066513,
-0.041680071502923965,
0.005871975794434547,
-0.02032570354640484,
0.019277986139059067,
-0.005095712840557098,
-0.02876458503305912,
0.04747108742594719,
-0.04933793097734451,
-0.04312782734632492,
0.02684059552848339,
0.0049385554157197475,
0.020420949906110764,
0.0350508838891983,
-0.05863403528928757,
-0.03520327806472778,
0.019773270934820175,
0.052347734570503235,
0.08556987345218658,
-0.02028760500252247,
-0.018839851021766663,
0.011515358462929726,
-0.06533942371606827,
0.010115227662026882,
0.03716536611318588,
-0.04362311214208603,
-0.004038471262902021,
0.026707250624895096,
-0.03474609553813934,
0.034631796181201935,
0.03720346465706825,
0.045718543231487274,
-0.010458117350935936,
0.07634996622800827,
0.014125125482678413,
-0.04663291573524475,
-0.011991593055427074,
-0.0070578004233539104,
0.044842272996902466,
-0.015010922215878963,
0.05688149109482765,
0.004259920679032803,
-0.05813875049352646,
0.01462993398308754,
0.01824931986629963,
-0.08381733298301697,
-0.032212525606155396,
0.003174105193465948,
-0.0236021988093853,
-0.016182459890842438,
-0.0049766539596021175,
-0.011867771856486797,
0.00041581253753975034,
-0.001700158347375691,
-0.028250250965356827,
-0.04373740777373314,
-0.01480137836188078,
0.010715283453464508,
0.0237926933914423,
-0.045185159891843796,
-0.001558478455990553,
-0.0053290678188204765,
-0.033679328858852386,
-0.018125498667359352,
-0.04274683818221092,
-0.060005590319633484,
0.013391723856329918,
-0.024630865082144737,
0.015087119303643703,
-0.004971891641616821,
-0.02464991621673107,
-0.04343261569738388,
-0.022078247740864754,
-0.013277427293360233,
-0.08107421547174454,
-0.05699578672647476,
-0.017134929075837135,
-0.0637773722410202,
0.015315712429583073,
0.011886822059750557,
-0.0006863734452053905,
-0.059815097600221634,
0.006762534845620394,
-0.001564431469887495,
0.016153885051608086,
0.02137341909110546,
-0.05436696857213974,
-0.022078247740864754,
-0.049223631620407104,
-0.013715563341975212,
-0.03446035459637642,
-0.01643962599337101,
0.03977513313293457,
0.00046343603753484786,
-0.019811369478702545,
-0.06240581348538399,
-0.013486970216035843,
-0.003240778110921383,
0.01839219033718109,
0.02160201221704483,
0.03476514294743538,
0.059472206979990005,
0.006119617726653814,
0.008015031926333904,
0.006114855408668518,
-0.021811556071043015,
0.024707064032554626,
0.0002964561863336712,
-0.02756447345018387,
0.016430102288722992,
0.056462403386831284,
0.0007655475055798888,
-0.04030851647257805,
-0.007562609389424324,
0.05547183379530907,
-0.005181435029953718,
-0.011886822059750557,
0.02895507775247097,
0.03167914226651192,
-0.012715470045804977,
0.004757585935294628,
-0.06572040915489197,
0.02194490097463131,
0.03916555270552635,
0.024268927052617073,
0.004024184308946133,
-0.023354556411504745,
0.07471172511577606,
0.029774202033877373,
0.002514519961550832,
-0.016992058604955673,
0.044842272996902466,
0.003821784630417824,
-0.022668778896331787,
0.0036503400187939405,
-0.007348303683102131,
0.04655671864748001,
-0.024611815810203552,
0.041565775871276855,
0.025240447372198105,
0.0013346481136977673,
-0.002931225346401334,
0.014096551574766636,
0.017096830531954765,
-0.009396113455295563,
-0.03206012770533562,
0.0034479403402656317,
-0.014810903929173946,
0.018001677468419075,
0.02853599190711975,
0.027354929596185684,
-0.05920551344752312,
-0.013544118963181973,
0.04004182666540146,
0.011277240701019764,
-0.02884078212082386,
-0.06408216059207916,
0.041908666491508484,
0.021049579605460167,
0.024421323090791702,
0.015372860245406628,
-0.01438229251652956,
-0.002476421184837818,
0.014306094497442245,
-0.03729871287941933,
0.01563955284655094,
0.0011965400772169232,
0.0028788396157324314,
0.08244577795267105,
0.0763118714094162,
-0.002681202255189419,
0.026897743344306946,
0.08046463876962662,
-0.059967491775751114,
0.012534501031041145,
-0.06293919682502747,
-0.02175440825521946,
0.09547556191682816,
0.008772245608270168,
-0.02929796651005745,
-0.014429915696382523,
-0.07551179826259613,
-0.03699392080307007,
-0.03522232919931412,
-0.04369930922985077,
0.04343261569738388,
-0.017239701002836227,
0.021163877099752426,
-0.030707621946930885,
0.005009990651160479,
-0.0017430195584893227,
-0.02468801476061344,
0.014753755182027817,
0.04625192657113075,
0.008572227321565151,
-0.012286858633160591,
0.029126523062586784,
0.04705200344324112,
-0.0636630728840828,
-0.020782887935638428,
0.07779772579669952,
0.0436612106859684,
-0.002816929016262293,
-0.006462506949901581,
0.008686523884534836,
-0.03996562957763672,
-0.06278680264949799,
-0.01854458451271057,
0.0045670922845602036,
-0.036574836820364,
-0.030326634645462036,
-0.000980448443442583,
0.011601081117987633,
0.06259630620479584
]
|
31,201 | networkx.generators.classic | trivial_graph | Return the Trivial graph with one node (with label 0) and no edges.
.. plot::
>>> nx.draw(nx.trivial_graph(), with_labels=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
| (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
]
|
31,206 | networkx.generators.small | truncated_cube_graph |
Returns the skeleton of the truncated cube.
The truncated cube is an Archimedean solid with 14 regular
faces (6 octagonal and 8 triangular), 36 edges and 24 nodes [1]_.
The truncated cube is created by truncating (cutting off) the tips
of the cube one third of the way into each edge [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
Skeleton of the truncated cube
References
----------
.. [1] https://en.wikipedia.org/wiki/Truncated_cube
.. [2] https://www.coolmath.com/reference/polyhedra-truncated-cube
| 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
]
|
31,207 | networkx.generators.small | truncated_tetrahedron_graph |
Returns the skeleton of the truncated Platonic tetrahedron.
The truncated tetrahedron is an Archimedean solid with 4 regular hexagonal faces,
4 equilateral triangle faces, 12 nodes and 18 edges. It can be constructed by truncating
all 4 vertices of a regular tetrahedron at one third of the original edge length [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
Skeleton of the truncated tetrahedron
References
----------
.. [1] https://en.wikipedia.org/wiki/Truncated_tetrahedron
| 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
]
|
31,208 | networkx.generators.classic | turan_graph | Return the Turan Graph
The Turan Graph is a complete multipartite graph on $n$ nodes
with $r$ disjoint subsets. That is, edges connect each node to
every node not in its subset.
Given $n$ and $r$, we create a complete multipartite graph with
$r-(n \mod r)$ partitions of size $n/r$, rounded down, and
$n \mod r$ partitions of size $n/r+1$, rounded down.
.. plot::
>>> nx.draw(nx.turan_graph(6, 2))
Parameters
----------
n : int
The number of nodes.
r : int
The number of partitions.
Must be less than or equal to n.
Notes
-----
Must satisfy $1 <= r <= n$.
The graph has $(r-1)(n^2)/(2r)$ edges, rounded down.
| 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, r, *, backend=None, **backend_kwargs) | [
0.022164342924952507,
-0.0068553173914551735,
0.021755864843726158,
-0.05026048794388771,
-0.012653921730816364,
0.06674166768789291,
-0.04756098613142967,
0.007428073789924383,
-0.0007431404083035886,
0.005110408179461956,
0.004138054326176643,
0.06251481175422668,
0.016916295513510704,
0.07608336955308914,
0.027012791484594345,
-0.007667832542210817,
0.014838388189673424,
0.011819206178188324,
-0.02289249747991562,
0.03793512284755707,
-0.019802276045084,
0.015158065594732761,
0.03429434821009636,
0.013897113502025604,
-0.020885629579424858,
0.011970165185630322,
0.02228866145014763,
0.032447319477796555,
-0.03736680746078491,
0.027350230142474174,
0.033193234354257584,
-0.01208560448139906,
0.0011654928093776107,
0.018399246037006378,
0.020708031952381134,
0.042375095188617706,
-0.02147170715034008,
0.05310206860303879,
-0.10449919104576111,
-0.015717502683401108,
0.046353310346603394,
-0.005860763601958752,
0.014829508028924465,
-0.032980114221572876,
0.012138884514570236,
0.02845134399831295,
0.08347148448228836,
0.004497691988945007,
-0.06883732974529266,
-0.017591170966625214,
0.04280133545398712,
0.0043023331090807915,
-0.04322757199406624,
-0.05839451774954796,
-0.0018692284356802702,
0.010078737512230873,
-0.007525753229856491,
-0.012307603843510151,
0.05953114852309227,
-0.039959751069545746,
0.033583950251340866,
0.032109878957271576,
0.006247041281312704,
-0.023531854152679443,
-0.05622781068086624,
-0.021791385486721992,
-0.03885863721370697,
-0.061378177255392075,
-0.014287831261754036,
-0.018967561423778534,
0.05402558296918869,
0.04148710146546364,
0.03012077324092388,
-0.00959034077823162,
0.01288480032235384,
0.026426715776324272,
0.036478813737630844,
0.010815773159265518,
-0.010504974983632565,
-0.009048664011061192,
-0.022785939276218414,
-0.03631897270679474,
0.0219512227922678,
-0.048093780875205994,
0.04624675214290619,
0.09831874817609787,
-0.019677957519888878,
0.02100994996726513,
-0.044648364186286926,
-0.023922571912407875,
-0.02443760819733143,
-0.027811987325549126,
-0.026124797761440277,
0.005501125939190388,
-0.012724961154162884,
0.01598390005528927,
0.05026048794388771,
-0.09249350428581238,
0.012396402657032013,
-0.0009440491558052599,
-0.03747336566448212,
-0.033317554742097855,
-0.08858633041381836,
-0.021897943690419197,
-0.05665404722094536,
-0.03138172626495361,
-0.025343362241983414,
0.056867167353630066,
-0.01316007785499096,
0.028540141880512238,
-0.019091881811618805,
0.017466850578784943,
0.06613782793283463,
-0.013719514943659306,
0.02973005548119545,
0.04265925660729408,
-0.01818612776696682,
0.03871655836701393,
0.06532087177038193,
-0.02301681786775589,
-0.05850107595324516,
0.044186607003211975,
-0.04031495004892349,
0.029765574261546135,
0.02683519385755062,
-0.00038960756501182914,
0.04454180225729942,
-0.05317310988903046,
0.030209572985768318,
0.021098749712109566,
-0.001577300252392888,
0.018967561423778534,
-0.0009540390456095338,
0.06826901435852051,
-0.035324420779943466,
0.013204477727413177,
-0.07892494648694992,
-0.028433583676815033,
-0.001253182184882462,
-0.014332231134176254,
0.033868107944726944,
-0.03417002782225609,
0.038752079010009766,
0.04958561062812805,
-0.060703303664922714,
0.015495503321290016,
0.018772203475236893,
0.01919844001531601,
0.013302157633006573,
-0.014483190141618252,
0.023656172677874565,
0.002056817291304469,
0.09533508867025375,
0.030706848949193954,
-0.02207554318010807,
-0.018399246037006378,
0.027066072449088097,
-0.022324182093143463,
-0.012112244963645935,
0.029836613684892654,
-0.007499113213270903,
0.01190800592303276,
0.03985319286584854,
-0.016605496406555176,
-0.07622544467449188,
-0.003383259056136012,
-0.006295880768448114,
-0.004331192933022976,
0.006548959296196699,
-0.027030551806092262,
-0.04166470095515251,
-0.000902979401871562,
0.0012576221488416195,
-0.056014690548181534,
-0.0045598517172038555,
-0.002096777083352208,
-0.03081340901553631,
-0.011135450564324856,
-0.017235971987247467,
-0.025876158848404884,
0.02973005548119545,
-0.07064884155988693,
0.029090698808431625,
-0.041771259158849716,
-0.012032325379550457,
0.01767997071146965,
0.009936658665537834,
0.014083592221140862,
0.029143979772925377,
0.0336194708943367,
0.046672988682985306,
0.02504144422709942,
-0.012902559712529182,
0.055943652987480164,
0.0228747371584177,
-0.05839451774954796,
0.06986740231513977,
0.036194656044244766,
-0.07231827080249786,
0.0551622174680233,
0.07743311673402786,
0.07132371515035629,
0.020441632717847824,
-0.010433935560286045,
0.048484500497579575,
-0.000602171232458204,
-0.05132608115673065,
-0.04816482216119766,
-0.05175231769680977,
0.028699981048703194,
-0.008014149963855743,
0.019713478162884712,
0.03793512284755707,
0.04450628161430359,
-0.06485911458730698,
0.0696898102760315,
0.039036236703395844,
0.03175468370318413,
0.010087617672979832,
-0.06112954020500183,
-0.035200100392103195,
-0.015708621591329575,
0.003199000144377351,
0.034258827567100525,
-0.008471467532217503,
-0.005723124369978905,
-0.008404867723584175,
-0.016774216666817665,
-0.004626451060175896,
-0.06269241124391556,
0.02649775519967079,
-0.02658655494451523,
0.044257644563913345,
-0.015291265211999416,
0.01252072211354971,
-0.015246865339577198,
0.03349515050649643,
-0.011623847298324108,
-0.042304057627916336,
0.03239404037594795,
-0.055126696825027466,
-0.019429318606853485,
0.007388113997876644,
-0.009315062314271927,
-0.013808313757181168,
0.07970638573169708,
-0.010425055399537086,
0.03141724318265915,
0.002481944626197219,
-0.011623847298324108,
-0.004442192614078522,
-0.019091881811618805,
0.012831520289182663,
-0.03093772754073143,
0.01891428232192993,
0.030547009781003,
-0.05697372555732727,
-0.007325954269617796,
0.01513142604380846,
0.04269477352499962,
-0.027598869055509567,
-0.008817785419523716,
-0.05800379812717438,
-0.028362544253468513,
0.06173337623476982,
0.018097328022122383,
-0.06869525462388992,
0.05281791090965271,
-0.05953114852309227,
-0.028611181303858757,
0.05711580440402031,
0.08141133189201355,
0.10535166412591934,
0.004497691988945007,
0.012769361026585102,
-0.05605021119117737,
0.0025108044501394033,
0.03981767222285271,
-0.042907893657684326,
-0.03163036331534386,
-0.05388350412249565,
-0.037153687328100204,
-0.011721527203917503,
0.04280133545398712,
0.02536112256348133,
0.03239404037594795,
0.05001185089349747,
-0.0039981952868402,
0.02562751993536949,
-0.02878878079354763,
0.019748996943235397,
-0.014758468605577946,
-0.036798492074012756,
-0.0030902207363396883,
0.03052924945950508,
0.020228514447808266,
-0.026551034301519394,
0.015282385051250458,
0.002319885650649667,
0.0524982325732708,
0.09412741661071777,
-0.05310206860303879,
0.03662089258432388,
0.022519540041685104,
0.04535875841975212,
0.02697727270424366,
0.00039182757609523833,
0.010442814789712429,
0.012778240256011486,
0.014705188572406769,
-0.054451823234558105,
0.014323350973427296,
0.004968329332768917,
0.009359462186694145,
-0.010504974983632565,
-0.0586431547999382,
-0.02047715336084366,
-0.021453946828842163,
0.0379706434905529,
0.038219284266233444,
0.019162921234965324,
0.005279127042740583,
-0.0526047945022583,
0.021294107660651207,
-0.05242719501256943,
0.053386230021715164,
-0.010043217800557613,
0.05711580440402031,
-0.04919489473104477,
0.021027708426117897,
0.01905636116862297,
-0.019482599571347237,
-0.031062046065926552,
0.03543097898364067,
-0.07199859619140625,
0.03551977872848511,
0.013897113502025604,
-0.03255387768149376,
-0.015539903193712234,
-0.051112961024045944,
0.02973005548119545,
0.010593773797154427,
-0.015531023032963276,
0.00697963684797287,
-0.03012077324092388,
0.03864552080631256,
0.046957146376371384,
-0.09348805993795395,
-0.0378640852868557,
-0.02678191289305687,
0.03159484267234802,
0.07871183007955551,
-0.026266876608133316,
-0.029818855226039886,
0.04020839184522629,
0.0664219856262207,
0.005363486707210541,
0.012352002784609795,
-0.06411319971084595,
-0.010655933991074562,
-0.003676297143101692,
0.003603037679567933,
0.06219513341784477,
-0.009838978759944439,
-0.005780844017863274,
0.02106322906911373,
-0.013612955808639526,
0.0868813768029213,
0.011659367941319942,
-0.006486799567937851,
-0.02415345050394535,
-0.07359698414802551,
-0.0768648013472557,
0.05033152550458908,
-0.005860763601958752,
0.05413214489817619,
-0.015388944186270237,
-0.03180796280503273,
0.0271726306527853,
-0.001798188779503107,
-0.04194885864853859,
-0.019766757264733315,
0.042517174035310745,
0.006877517327666283,
0.026426715776324272,
-0.00005019249874749221,
0.041167423129081726,
0.019358279183506966,
-0.04269477352499962,
-0.027563348412513733,
-0.05363486707210541,
-0.0464598722755909,
0.06230169162154198,
-0.0048795295879244804,
-0.0293215773999691,
0.0021911263465881348,
0.09561924636363983,
0.0491238534450531,
-0.05288895219564438,
0.017404692247509956,
0.0517878383398056,
-0.045607395470142365,
0.025556480512022972,
0.002586283953860402,
-0.004764090292155743,
-0.037011608481407166,
0.010620414279401302,
-0.009989937767386436,
-0.02617807686328888,
-0.026622073724865913,
0.020050914958119392,
-0.07871183007955551,
-0.030422691255807877,
-0.00042984483297914267,
0.0715368390083313,
0.006202641408890486,
0.010345135815441608,
0.0009568140376359224,
0.029410377144813538,
0.004666410852223635,
0.02388705126941204,
-0.0938432589173317,
-0.015193585306406021,
0.09682691842317581,
0.05310206860303879,
-0.05068672448396683,
0.028007345274090767,
-0.016321338713169098,
-0.012005685828626156,
0.07263794541358948,
0.03420554846525192,
-0.023780493065714836,
0.035999298095703125,
0.006708798464387655,
0.0073348344303667545,
-0.06159129738807678,
0.025378882884979248,
0.006144921761006117,
-0.0017426891718059778,
0.0013453116407617927,
0.030955487862229347,
-0.005301326978951693,
0.018612364307045937,
-0.021027708426117897,
-0.002612923737615347,
-0.01579742133617401,
0.03825480118393898,
0.034720584750175476,
-0.002313225530087948,
-0.03395690768957138,
-0.006695478223264217,
-0.03147052600979805,
0.052249595522880554,
0.0003196780162397772,
-0.038752079010009766,
-0.007707791868597269,
0.019020842388272285,
-0.04571395739912987,
-0.05967322736978531,
0.04713474586606026,
-0.010851292870938778,
0.02685295231640339,
-0.020885629579424858,
0.021862424910068512,
-0.016747575253248215,
-0.042375095188617706,
0.02806062623858452,
-0.005807484034448862,
-0.041167423129081726,
-0.07054228335618973,
0.024455368518829346,
0.013115678913891315,
-0.03896519914269447,
-0.030991006642580032,
0.03811272233724594,
-0.03480938449501991,
-0.02637343667447567,
-0.04663747176527977,
-0.00031218555523082614,
-0.030848927795886993,
-0.06073882430791855,
0.015388944186270237,
-0.01022969651967287,
0.03953351452946663,
-0.04713474586606026,
-0.023780493065714836,
0.023194415494799614,
-0.04752546548843384,
0.001880328287370503,
-0.03543097898364067,
-0.0030880006961524487,
-0.022626100108027458,
-0.01522910501807928,
0.0159927811473608,
-0.030618049204349518,
0.07086195796728134,
-0.017466850578784943,
-0.03839688003063202,
-0.0019324979512020946,
-0.009235142730176449,
0.019233960658311844,
-0.002114536939188838,
-0.02200450375676155,
0.014900547452270985,
0.0069352369755506516,
0.05811036005616188,
-0.0065933591686189175,
-0.012875920161604881,
0.008227269165217876,
0.04280133545398712,
0.03914279490709305,
0.03857447952032089,
0.02456192672252655,
0.04201989993453026,
-0.022626100108027458,
0.008005269803106785,
-0.021720344200730324,
-0.007801031693816185,
0.043192051351070404,
-0.05732892453670502,
0.041238464415073395,
0.03818376362323761,
0.009785698726773262,
0.041913338005542755,
-0.02530784346163273,
-0.00595400296151638,
0.03846792131662369,
-0.02663983404636383,
0.016241418197751045,
-0.0006193761364556849,
0.022448500618338585,
0.06173337623476982,
-0.039426956325769424,
0.0107713732868433,
-0.041380543261766434,
-0.0808430165052414,
0.03468506410717964,
0.046744029968976974,
0.008160669356584549,
-0.020352832973003387,
0.0026950633618980646,
-0.0022577259223908186,
-0.011126570403575897,
0.0019402679754421115,
0.001155502861365676,
0.02965901605784893,
0.006087202113121748,
-0.06748758256435394,
0.026337916031479836,
-0.05963771045207977,
0.034258827567100525,
-0.0038916359189897776,
0.007436953950673342,
0.00652675935998559,
0.08368460088968277,
-0.006087202113121748,
0.008023030124604702,
-0.026870712637901306,
0.004140274133533239,
0.032447319477796555,
-0.06219513341784477,
0.0064557199366390705,
-0.0017116093076765537,
-0.02958797663450241,
0.018683403730392456,
0.00002983106423926074,
0.008724546059966087,
-0.023070096969604492,
0.02470400556921959,
0.007539073005318642,
-0.0056609646417200565,
0.06429079920053482,
0.089651919901371,
-0.009235142730176449,
-0.016054939478635788,
-0.007206075359135866,
-0.04269477352499962,
-0.0047818501479923725,
-0.03967559337615967,
-0.017955249175429344,
-0.020299553871154785,
-0.019677957519888878,
0.0025929438415914774,
0.0005849663866683841,
-0.002644003601744771,
0.063864566385746,
-0.09434053301811218,
-0.004617571365088224,
-0.017910849303007126,
0.01567310281097889,
0.04507460072636604,
-0.056867167353630066,
0.06429079920053482,
0.03349515050649643,
-0.04376036673784256,
0.010726973414421082,
-0.020121954381465912,
-0.0456429161131382,
0.026462236419320107,
0.005945123266428709,
-0.046815067529678345,
0.08858633041381836,
-0.020885629579424858,
0.03282027691602707,
0.06219513341784477,
0.042907893657684326,
0.03166588395833969,
-0.016028299927711487,
-0.01630357839167118,
-0.084537073969841,
-0.006087202113121748,
0.05381246656179428,
-0.020992189645767212,
-0.048697616904973984,
-0.050224967300891876,
0.012778240256011486,
-0.02866446226835251,
0.05200095847249031,
-0.0653919130563736,
-0.029978694394230843,
-0.015859581530094147,
0.035324420779943466,
-0.015193585306406021,
-0.007778831757605076,
-0.028966380283236504,
0.001204342464916408,
0.018470285460352898,
-0.02898414060473442,
0.0013497516047209501,
0.00411807419732213,
0.010682573541998863,
-0.05487805977463722,
-0.022999057546257973,
-0.034596264362335205,
-0.011535048484802246,
-0.007543513085693121,
0.009377221576869488,
-0.027563348412513733,
0.003856115974485874,
0.09632964432239532,
-0.04301445186138153,
0.008329388685524464,
-0.029090698808431625,
-0.02630239725112915,
-0.0038117163348942995,
-0.03115084581077099,
0.018683403730392456,
-0.036478813737630844,
-0.006548959296196699,
-0.02818494476377964,
-0.03914279490709305,
-0.0029170617926865816,
0.01767997071146965,
0.018843242898583412,
0.04269477352499962,
0.03736680746078491,
-0.03477386385202408,
-0.06240825355052948,
0.005390126723796129,
-0.06169785559177399,
0.05388350412249565,
-0.015610942617058754,
0.02980109490454197,
0.06155577674508095,
0.0011943526333197951,
0.061094019562006,
-0.003642997471615672,
-0.06155577674508095,
0.005980642978101969,
-0.00041485991096124053,
0.0046575311571359634,
0.008111829869449139,
0.038290321826934814,
-0.016916295513510704,
-0.05509117618203163,
-0.01506038662046194,
-0.014900547452270985,
0.028167184442281723,
-0.04468388110399246,
-0.009785698726773262,
0.009466021321713924,
-0.009172982536256313,
0.03287355601787567,
-0.02436656877398491,
-0.01992659643292427,
-0.01784868910908699,
-0.04095430672168732,
-0.05200095847249031,
0.018701164051890373,
0.011170970275998116,
-0.017546771094202995,
0.028238223865628242,
0.010753612965345383,
0.01627693884074688,
-0.019482599571347237,
0.014838388189673424,
-0.015948381274938583,
0.0271726306527853,
0.004233513493090868,
-0.05072224512696266,
0.03669193014502525,
-0.0014108011964708567,
-0.009341701865196228,
0.03775752708315849,
0.01751125045120716,
0.022803697735071182,
-0.034134507179260254,
0.012183284386992455,
-0.0413450226187706,
0.035732898861169815,
-0.07128819823265076,
-0.02322993613779545,
0.004249053541570902,
0.021791385486721992,
-0.08730761706829071,
0.0051814476028084755,
0.029818855226039886,
0.005225847475230694,
-0.05189439654350281,
-0.0014674108242616057,
0.0336194708943367,
-0.0473833866417408,
-0.0258939191699028,
0.051112961024045944,
-0.035999298095703125,
0.009048664011061192,
-0.03214539960026741,
-0.037082649767398834,
-0.04212645813822746,
-0.02951693721115589,
-0.02106322906911373,
0.030387170612812042,
0.01190800592303276,
-0.016090460121631622,
0.01891428232192993,
-0.0016660996479913592,
0.020903389900922775,
0.02758110873401165,
-0.016605496406555176,
-0.016703175380825996,
0.0029881014488637447,
-0.02147170715034008,
-0.06649302691221237,
-0.020903389900922775,
-0.016703175380825996,
-0.014500949531793594,
0.008302748203277588,
-0.018470285460352898,
0.0011743727372959256,
0.029215019196271896,
0.041309501975774765,
-0.0027372429613023996,
0.008933224715292454,
0.026533275842666626,
-0.044790443032979965,
-0.02401137165725231,
0.0152735048905015,
-0.005549965426325798,
-0.01784868910908699,
-0.043511729687452316,
-0.022768178954720497,
0.028344783931970596,
0.0639711245894432,
-0.011028891429305077,
-0.04514563828706741,
0.0033188792876899242,
0.0457494743168354,
-0.0030902207363396883
]
|
31,209 | networkx.generators.small | tutte_graph |
Returns the Tutte graph.
The Tutte graph is a cubic polyhedral, non-Hamiltonian graph. It has
46 nodes and 69 edges.
It is a counterexample to Tait's conjecture that every 3-regular polyhedron
has a Hamiltonian cycle.
It can be realized geometrically from a tetrahedron by multiply truncating
three of its vertices [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
Tutte graph
References
----------
.. [1] https://en.wikipedia.org/wiki/Tutte_graph
| 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
]
|
31,217 | networkx.algorithms.isomorphism.vf2pp | vf2pp_all_isomorphisms | Yields all the possible mappings between G1 and G2.
Parameters
----------
G1, G2 : NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism.
node_label : str, optional
The name of the node attribute to be used when comparing nodes.
The default is `None`, meaning node attributes are not considered
in the comparison. Any node that doesn't have the `node_label`
attribute uses `default_label` instead.
default_label : scalar
Default value to use when a node doesn't have an attribute
named `node_label`. Default is `None`.
Yields
------
dict
Isomorphic mapping between the nodes in `G1` and `G2`.
| def _consistent_PT(u, v, graph_params, state_params):
"""Checks the consistency of extending the mapping using the current node pair.
Parameters
----------
u, v: Graph node
The two candidate nodes being examined.
graph_params: namedtuple
Contains all the Graph-related parameters:
G1,G2: NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism or monomorphism
G1_labels,G2_labels: dict
The label of every node in G1 and G2 respectively
state_params: namedtuple
Contains all the State-related parameters:
mapping: dict
The mapping as extended so far. Maps nodes of G1 to nodes of G2
reverse_mapping: dict
The reverse mapping as extended so far. Maps nodes from G2 to nodes of G1. It's basically "mapping" reversed
T1, T2: set
Ti contains uncovered neighbors of covered nodes from Gi, i.e. nodes that are not in the mapping, but are
neighbors of nodes that are.
T1_out, T2_out: set
Ti_out contains all the nodes from Gi, that are neither in the mapping nor in Ti
Returns
-------
True if the pair passes all the consistency checks successfully. False otherwise.
"""
G1, G2 = graph_params.G1, graph_params.G2
mapping, reverse_mapping = state_params.mapping, state_params.reverse_mapping
for neighbor in G1[u]:
if neighbor in mapping:
if G1.number_of_edges(u, neighbor) != G2.number_of_edges(
v, mapping[neighbor]
):
return False
for neighbor in G2[v]:
if neighbor in reverse_mapping:
if G1.number_of_edges(u, reverse_mapping[neighbor]) != G2.number_of_edges(
v, neighbor
):
return False
if not G1.is_directed():
return True
for predecessor in G1.pred[u]:
if predecessor in mapping:
if G1.number_of_edges(predecessor, u) != G2.number_of_edges(
mapping[predecessor], v
):
return False
for predecessor in G2.pred[v]:
if predecessor in reverse_mapping:
if G1.number_of_edges(
reverse_mapping[predecessor], u
) != G2.number_of_edges(predecessor, v):
return False
return True
| (G1, G2, node_label=None, default_label=None, *, backend=None, **backend_kwargs) | [
0.04594627022743225,
-0.00400518486276269,
-0.05663935840129852,
0.10670416802167892,
-0.02091386541724205,
-0.019024627283215523,
-0.04968696087598801,
-0.04122317582368851,
0.0166819728910923,
-0.04500165209174156,
-0.026524903252720833,
0.0016459986800327897,
0.024503417313098907,
0.01913798227906227,
-0.02427670918405056,
0.004302739631384611,
-0.014093716628849506,
0.004210639279335737,
0.030737904831767082,
0.015510644763708115,
-0.032287079840898514,
-0.011958877556025982,
0.034856442362070084,
0.07269788533449173,
-0.048137787729501724,
-0.05917093902826309,
-0.013640299439430237,
-0.015680676326155663,
0.0011719180038198829,
0.02185848541557789,
-0.03663232550024986,
-0.06117352843284607,
0.027847370132803917,
0.04337690770626068,
0.05244525149464607,
0.016285233199596405,
0.021121682599186897,
0.03234375640749931,
-0.045530639588832855,
-0.04658861085772514,
-0.026468226686120033,
-0.03172030672430992,
-0.014736057259142399,
-0.014225962571799755,
0.06820149719715118,
0.028678635135293007,
0.004413732327520847,
0.05338986963033676,
-0.018854595720767975,
0.005889699794352055,
0.02336987480521202,
-0.07473825663328171,
-0.01759825274348259,
0.02926429733633995,
-0.035706598311662674,
0.011070935055613518,
0.01917576603591442,
0.02335098385810852,
0.0019140343647450209,
-0.0032919973600655794,
0.005389051511883736,
-0.022765319794416428,
0.009332836605608463,
0.0007509721326641738,
-0.0015231982106342912,
0.006744579877704382,
-0.034761980175971985,
-0.07088421285152435,
-0.015463413670659065,
0.031304676085710526,
-0.0029023420065641403,
-0.03151249140501022,
0.0005086183082312346,
-0.010674195364117622,
-0.003561213845387101,
0.016511941328644753,
0.02423892542719841,
0.027960723266005516,
-0.004076031036674976,
-0.03835153207182884,
-0.02170734666287899,
-0.04658861085772514,
0.02189626917243004,
-0.07065750658512115,
0.021915161982178688,
0.06623668968677521,
0.010608072392642498,
0.033061668276786804,
0.004963973071426153,
-0.03859713301062584,
-0.034667517989873886,
0.021971838548779488,
0.044812727719545364,
0.01165659911930561,
0.07643857598304749,
0.04262121021747589,
-0.015142243355512619,
-0.05490126088261604,
-0.09733355045318604,
-0.017040926963090897,
0.04923354461789131,
0.008610202930867672,
-0.04503943771123886,
0.009417852386832237,
0.03676457330584526,
-0.051387276500463486,
-0.035442106425762177,
-0.008954988792538643,
-0.024503417313098907,
-0.05611037090420723,
-0.09068343043327332,
-0.00752389058470726,
-0.0018845150480046868,
0.015680676326155663,
-0.012308386154472828,
0.03502647578716278,
0.022387471050024033,
-0.0040547773241996765,
-0.04681532084941864,
0.00004413142232806422,
0.03855935111641884,
0.03540432080626488,
-0.013772545382380486,
-0.012204478494822979,
0.010079084895551205,
-0.08085939288139343,
0.06192922592163086,
0.08085939288139343,
-0.014811626635491848,
-0.007925353944301605,
0.005266251042485237,
0.0018455494428053498,
-0.015368952415883541,
0.07866787165403366,
0.03179587796330452,
-0.02168845385313034,
-0.0671813040971756,
0.005119835026562214,
0.006532040890306234,
0.03510204330086708,
0.01842951774597168,
-0.035649921745061874,
0.014339317567646503,
-0.005072604399174452,
0.033930715173482895,
-0.0336851142346859,
-0.0504804402589798,
-0.0005827118875458837,
0.031191321089863777,
0.03164473921060562,
-0.002060450380668044,
-0.009460359811782837,
0.024843480437994003,
-0.028225217014551163,
-0.07352914661169052,
-0.028036292642354965,
0.021159466356039047,
-0.026317086070775986,
-0.005587421823292971,
-0.01578458398580551,
-0.017749391496181488,
-0.04439709708094597,
-0.004805749282240868,
0.032362647354602814,
0.008251246996223927,
-0.009512313641607761,
-0.0023544630967080593,
0.01851453259587288,
0.020214848220348358,
-0.01177939958870411,
-0.02588256262242794,
-0.01929856650531292,
-0.031134644523262978,
-0.0251268669962883,
0.04375475272536278,
-0.012383955530822277,
0.005899146199226379,
-0.03750137612223625,
0.0020828850101679564,
-0.003967400174587965,
0.004007546231150627,
-0.03194701671600342,
-0.013952023349702358,
-0.03406296297907829,
-0.019761430099606514,
0.09060785919427872,
0.02261417917907238,
-0.004378309473395348,
-0.0009517036960460246,
0.02418224699795246,
-0.041449885815382004,
-0.026090377941727638,
0.010286901146173477,
0.08305090665817261,
0.06174030154943466,
0.012327278964221478,
0.038767166435718536,
0.04915797710418701,
-0.038049254566431046,
0.03510204330086708,
0.016086863353848457,
-0.07919686287641525,
0.021329497918486595,
0.03234375640749931,
-0.008799126371741295,
0.009795699268579483,
0.0012232817243784666,
0.004085477441549301,
0.08554469794034958,
-0.023861076682806015,
-0.03096461296081543,
-0.039825137704610825,
-0.021253928542137146,
0.016521386802196503,
-0.008482678793370724,
-0.007169658783823252,
-0.00650842534378171,
0.03937172144651413,
-0.029056482017040253,
-0.013640299439430237,
0.054712336510419846,
-0.06582105904817581,
0.01915687508881092,
0.00003285872298874892,
0.04345247521996498,
0.02263307198882103,
-0.005913315340876579,
0.057432837784290314,
0.01921355165541172,
0.0023650899529457092,
0.04284792020916939,
-0.021140573546290398,
0.038842733949422836,
0.020630480721592903,
0.06559434533119202,
-0.038767166435718536,
-0.02592034637928009,
0.004170493222773075,
0.04836449399590492,
0.050140380859375,
-0.015350059606134892,
-0.013564729131758213,
-0.05191626399755478,
0.0034950904082506895,
0.001687325770035386,
-0.04794886335730553,
0.028244109824299812,
-0.014490456320345402,
0.04005184769630432,
0.02601480856537819,
-0.07235781848430634,
-0.03952286019921303,
-0.01853342540562153,
0.008274862542748451,
0.023218736052513123,
-0.04594627022743225,
-0.02257639542222023,
-0.012440633028745651,
0.028848666697740555,
0.024597879499197006,
0.004510555882006884,
0.04942246899008751,
-0.03612223267555237,
0.05463676527142525,
0.005908592138439417,
-0.015217812731862068,
0.047230951488018036,
0.033760685473680496,
-0.03680235892534256,
-0.041336528956890106,
0.04775993898510933,
0.00007748827920295298,
-0.04443487897515297,
0.042092226445674896,
-0.010626964271068573,
0.003473836462944746,
0.0416010245680809,
-0.027809584513306618,
-0.011694383807480335,
-0.0019943269435316324,
-0.03629226237535477,
0.002500878879800439,
-0.0021277545019984245,
0.01744711399078369,
-0.04530392959713936,
-0.012846819125115871,
-0.038181502372026443,
-0.04020298644900322,
0.03614112362265587,
-0.05085828900337219,
-0.013356913812458515,
-0.038011468946933746,
0.028111863881349564,
0.02505129761993885,
0.013149097561836243,
0.03098350577056408,
0.025504713878035545,
-0.01595461554825306,
0.006328947842121124,
-0.011864415369927883,
0.03706685081124306,
-0.022973135113716125,
0.019666967913508415,
-0.0249946191906929,
0.06899497658014297,
0.03151249140501022,
0.028962019830942154,
-0.013054635375738144,
0.03419521078467369,
0.013989808037877083,
-0.05996441841125488,
-0.0030227808747440577,
0.013649744912981987,
0.039862923324108124,
0.030719012022018433,
-0.026373764500021935,
-0.04012741893529892,
-0.035498782992362976,
0.05611037090420723,
0.0208760816603899,
-0.027148351073265076,
0.07719426602125168,
0.024031108245253563,
0.0293776523321867,
-0.07182883471250534,
-0.07167769223451614,
0.047306522727012634,
0.013564729131758213,
0.04001406207680702,
-0.0001815439754864201,
-0.01842951774597168,
-0.045681778341531754,
0.0586797371506691,
0.03421410173177719,
-0.07432262599468231,
0.022122977301478386,
0.034591950476169586,
0.027129458263516426,
0.06003998592495918,
0.006130577530711889,
0.11327871680259705,
0.038993872702121735,
-0.051500629633665085,
-0.03655675798654556,
0.038011468946933746,
0.029887747019529343,
-0.0503670871257782,
0.0051859584636986256,
-0.016984250396490097,
0.025618068873882294,
-0.06922168284654617,
0.056563787162303925,
0.00794424582272768,
0.009469806216657162,
0.029755499213933945,
0.030530087649822235,
0.04923354461789131,
-0.05456119775772095,
0.020384879782795906,
0.05758397653698921,
0.02669493481516838,
-0.042356718331575394,
-0.007410536520183086,
-0.023766614496707916,
0.029623253270983696,
0.02023373916745186,
0.02331319823861122,
-0.014821073040366173,
-0.024012215435504913,
-0.01381033007055521,
-0.0008867611177265644,
-0.09015443921089172,
0.033930715173482895,
0.01208167802542448,
-0.019931461662054062,
0.05422113463282585,
-0.06279827654361725,
0.014821073040366173,
0.007410536520183086,
-0.004739626310765743,
0.04462380334734917,
0.028773095458745956,
0.00964928325265646,
0.08153951913118362,
0.020498232915997505,
-0.03493201360106468,
0.050140380859375,
0.010409701615571976,
0.0337228998541832,
0.021934054791927338,
-0.007665583398193121,
0.03444081172347069,
0.01177939958870411,
-0.015529537573456764,
-0.03780365362763405,
0.03411963954567909,
0.026184840127825737,
0.034686412662267685,
-0.013054635375738144,
-0.07897014915943146,
0.01206278521567583,
-0.029849961400032043,
-0.023917755112051964,
-0.0034880058374255896,
-0.011429890058934689,
-0.027809584513306618,
-0.0021997815929353237,
0.053276512771844864,
0.0017062181141227484,
0.04265899583697319,
-0.03173920139670372,
0.004257870372384787,
0.026940535753965378,
-0.012166693806648254,
-0.053881071507930756,
-0.04530392959713936,
-0.03566881641745567,
-0.005492959637194872,
0.04080754145979881,
-0.00878967996686697,
0.0754183828830719,
-0.013470267876982689,
0.02265196479856968,
-0.011004812084138393,
-0.0011890392052009702,
-0.0918169692158699,
-0.03523429110646248,
0.010201885364949703,
-0.0002352691808482632,
0.03574438393115997,
0.00920058973133564,
-0.03608444705605507,
0.05244525149464607,
-0.04239450395107269,
0.014499902725219727,
0.01209112349897623,
0.017286527901887894,
0.001209112349897623,
0.031418029218912125,
0.0065225944854319096,
0.037161312997341156,
0.03449748829007149,
-0.0030629271641373634,
-0.03519650548696518,
0.05769733339548111,
-0.009852376766502857,
-0.08267305791378021,
-0.007368028629571199,
-0.0010987099958583713,
0.008440171368420124,
-0.030416732653975487,
-0.017295975238084793,
-0.005422113463282585,
-0.05263417214155197,
-0.03519650548696518,
0.03151249140501022,
-0.0502537339925766,
-0.03251378610730171,
-0.06245821341872215,
0.06408295780420303,
-0.002290701260790229,
-0.05369214713573456,
-0.027053888887166977,
0.061664730310440063,
-0.030681226402521133,
-0.003591913962736726,
0.0020002308301627636,
-0.003955592401325703,
-0.021575098857283592,
0.01674809493124485,
-0.02080051228404045,
-0.06344061344861984,
-0.03940950706601143,
-0.013980361633002758,
-0.008945542387664318,
0.016341909766197205,
-0.02010149322450161,
0.028924236074090004,
0.00039733038283884525,
0.010711980052292347,
-0.048969052731990814,
0.024824589490890503,
0.025466930121183395,
0.0502537339925766,
0.030511194840073586,
-0.04938468337059021,
-0.0010957580525428057,
0.01919465884566307,
-0.033798471093177795,
-0.03937172144651413,
-0.027941832318902016,
-0.1085934042930603,
0.019421366974711418,
0.07651413977146149,
-0.005455174949020147,
0.007967861369252205,
-0.005280420649796724,
-0.04099646583199501,
0.03087015077471733,
-0.06026669591665268,
0.03659454360604286,
0.050593797117471695,
0.007434152066707611,
0.026392655447125435,
0.05943543091416359,
0.007580568082630634,
-0.02682718075811863,
0.001271693385206163,
-0.0015503560425713658,
0.0416010245680809,
-0.017173174768686295,
-0.022954242303967476,
0.0915902629494667,
0.0500648096203804,
0.02684607356786728,
0.008709387853741646,
0.012912942096590996,
-0.07394477725028992,
0.0037926454097032547,
-0.0499892383813858,
0.008629094809293747,
-0.009285605512559414,
0.046550825238227844,
-0.018986843526363373,
-0.022821996361017227,
0.02748841419816017,
-0.0028645573183894157,
-0.015623998828232288,
-0.030416732653975487,
-0.09400849044322968,
-0.044926080852746964,
-0.006484809797257185,
0.02435227856040001,
-0.0005564396851696074,
-0.04024077206850052,
0.011514905840158463,
0.04080754145979881,
-0.026940535753965378,
-0.08705609291791916,
0.0017558106919750571,
0.06200479343533516,
-0.012601218186318874,
0.03536653891205788,
0.010815887711942196,
0.033855147659778595,
0.0669168159365654,
-0.002149008447304368,
-0.061551377177238464,
-0.016946466639637947,
0.006239208858460188,
-0.033987391740083694,
0.023785507306456566,
0.03767140954732895,
0.018004439771175385,
0.014424333348870277,
-0.02769623138010502,
-0.022784210741519928,
0.019723646342754364,
0.042923491448163986,
0.010201885364949703,
-0.029491007328033447,
-0.015265043824911118,
0.024673448875546455,
-0.016398586332798004,
-0.0332316979765892,
-0.021367283537983894,
-0.009691791608929634,
-0.024503417313098907,
0.030586764216423035,
0.06903275847434998,
0.029679929837584496,
0.03094572015106678,
-0.010863118804991245,
-0.03328837454319,
-0.0145849185064435,
-0.0421300083398819,
-0.0019612652249634266,
0.00027069239877164364,
-0.00519540486857295,
-0.06959953159093857,
-0.04020298644900322,
0.0669923797249794,
0.039711784571409225,
0.040694188326597214,
0.0584908127784729,
0.016559172421693802,
-0.06922168284654617,
0.05119835212826729,
0.03925836831331253,
-0.01006019301712513,
-0.05667714402079582,
-0.014122054912149906,
0.02085718885064125,
-0.03455416485667229,
0.005403221119195223,
0.012421740218997002,
0.03770919144153595,
0.042205579578876495,
0.036254480481147766,
-0.03170141577720642,
0.005516575183719397,
0.013319128192961216,
0.0037926454097032547,
-0.04617298021912575,
-0.02578810043632984,
-0.0416388064622879,
0.0028362188022583723,
0.0291887279599905,
0.020290417596697807,
0.0008956169476732612,
0.05372993275523186,
0.004345247521996498,
0.025693638250231743,
-0.08599811792373657,
0.002772456966340542,
-0.019912568852305412,
-0.05920872092247009,
0.05573252588510513,
-0.013895345851778984,
-0.013026297092437744,
-0.0026921643875539303,
-0.01751323789358139,
-0.004527086857706308,
0.01996924728155136,
-0.038767166435718536,
0.011401551775634289,
0.03523429110646248,
-0.012724018655717373,
0.016511941328644753,
-0.056563787162303925,
-0.017210958525538445,
-0.04587070271372795,
0.024673448875546455,
0.014055931940674782,
0.04598405584692955,
-0.06510314345359802,
0.029056482017040253,
-0.014027592726051807,
-0.028036292642354965,
0.067030169069767,
-0.08229520916938782,
0.009002219885587692,
-0.0035871907602995634,
0.023691045120358467,
0.014858857728540897,
0.009880715049803257,
0.032098155468702316,
0.02607148513197899,
0.06861712783575058,
0.04129874333739281,
0.013149097561836243,
0.08637596666812897,
0.03279717266559601,
-0.03784143924713135,
0.0025811714585870504,
0.04545506834983826,
-0.000827132083941251,
-0.02845192514359951,
-0.0167103111743927,
-0.02251971885561943,
-0.019836999475955963,
0.010560841299593449,
-0.03614112362265587,
-0.01332857459783554,
0.028130754828453064,
0.033099450170993805,
0.03092682734131813,
0.02000703103840351,
-0.0030629271641373634,
0.03489422798156738,
-0.003771391464397311,
-0.0335150845348835,
0.03240043297410011,
-0.013139651156961918,
-0.01919465884566307,
-0.06850377470254898,
0.02590145356953144,
0.004902572836726904,
-0.04677753522992134,
-0.014244855381548405,
0.04080754145979881,
0.018873488530516624,
-0.019818108528852463,
-0.021235035732388496,
0.005280420649796724,
0.024484526365995407,
-0.017163727432489395,
-0.030700119212269783,
0.016511941328644753,
-0.007051581051200628,
-0.010504163801670074,
-0.08048154413700104,
0.013479714281857014,
0.0417899452149868,
-0.005337097682058811,
-0.011108719743788242,
-0.04420817270874977,
0.015614553354680538,
0.02182069979608059,
-0.04590848460793495,
0.010400256142020226,
-0.07394477725028992,
-0.03598998486995697,
0.0336095467209816,
0.017220405861735344,
0.056488219648599625,
-0.054939042776823044,
-0.012365063652396202,
0.00035541292163543403,
-0.008090661838650703,
-0.04095868021249771,
-0.027431737631559372,
0.058188535273075104,
-0.07628743350505829,
0.017173174768686295,
-0.027337275445461273,
0.006215593311935663,
-0.005875530652701855,
0.011118166148662567,
-0.012809034436941147,
-0.0750027522444725,
0.008232355117797852,
0.001063286792486906,
-0.0035753832198679447,
-0.010778103023767471,
0.050556011497974396,
0.005554359871894121,
-0.07904572039842606,
-0.03795479238033295,
-0.01135432068258524,
-0.0014003977412357926,
0.05543024465441704,
-0.05682828277349472,
0.014386547729372978,
-0.037199098616838455,
0.017277082428336143,
-0.02661936543881893,
0.019629184156656265,
-0.022274117916822433,
0.067559152841568,
0.013980361633002758,
-0.007755322381854057,
-0.013149097561836243,
-0.018703456968069077,
-0.04424595460295677,
0.03617890924215317,
-0.039749570190906525,
-0.014868304133415222,
-0.034591950476169586,
-0.02593923918902874,
0.08229520916938782,
0.009299774654209614,
-0.01471716444939375,
-0.03151249140501022,
0.06446080654859543,
0.030567873269319534,
0.0025740868877619505,
-0.03258935734629631,
-0.04405703395605087,
-0.08169065415859222,
-0.03952286019921303,
0.005918038543313742,
-0.002552832942456007,
0.03604666143655777,
-0.008662156760692596,
0.04367918521165848,
-0.003228235524147749,
0.08221964538097382
]
|
31,218 | networkx.algorithms.isomorphism.vf2pp | vf2pp_is_isomorphic | Examines whether G1 and G2 are isomorphic.
Parameters
----------
G1, G2 : NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism.
node_label : str, optional
The name of the node attribute to be used when comparing nodes.
The default is `None`, meaning node attributes are not considered
in the comparison. Any node that doesn't have the `node_label`
attribute uses `default_label` instead.
default_label : scalar
Default value to use when a node doesn't have an attribute
named `node_label`. Default is `None`.
Returns
-------
bool
True if the two graphs are isomorphic, False otherwise.
| def _consistent_PT(u, v, graph_params, state_params):
"""Checks the consistency of extending the mapping using the current node pair.
Parameters
----------
u, v: Graph node
The two candidate nodes being examined.
graph_params: namedtuple
Contains all the Graph-related parameters:
G1,G2: NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism or monomorphism
G1_labels,G2_labels: dict
The label of every node in G1 and G2 respectively
state_params: namedtuple
Contains all the State-related parameters:
mapping: dict
The mapping as extended so far. Maps nodes of G1 to nodes of G2
reverse_mapping: dict
The reverse mapping as extended so far. Maps nodes from G2 to nodes of G1. It's basically "mapping" reversed
T1, T2: set
Ti contains uncovered neighbors of covered nodes from Gi, i.e. nodes that are not in the mapping, but are
neighbors of nodes that are.
T1_out, T2_out: set
Ti_out contains all the nodes from Gi, that are neither in the mapping nor in Ti
Returns
-------
True if the pair passes all the consistency checks successfully. False otherwise.
"""
G1, G2 = graph_params.G1, graph_params.G2
mapping, reverse_mapping = state_params.mapping, state_params.reverse_mapping
for neighbor in G1[u]:
if neighbor in mapping:
if G1.number_of_edges(u, neighbor) != G2.number_of_edges(
v, mapping[neighbor]
):
return False
for neighbor in G2[v]:
if neighbor in reverse_mapping:
if G1.number_of_edges(u, reverse_mapping[neighbor]) != G2.number_of_edges(
v, neighbor
):
return False
if not G1.is_directed():
return True
for predecessor in G1.pred[u]:
if predecessor in mapping:
if G1.number_of_edges(predecessor, u) != G2.number_of_edges(
mapping[predecessor], v
):
return False
for predecessor in G2.pred[v]:
if predecessor in reverse_mapping:
if G1.number_of_edges(
reverse_mapping[predecessor], u
) != G2.number_of_edges(predecessor, v):
return False
return True
| (G1, G2, node_label=None, default_label=None, *, backend=None, **backend_kwargs) | [
0.04582758992910385,
-0.003964577801525593,
-0.05663277581334114,
0.10669177025556564,
-0.020892545580863953,
-0.018984636291861534,
-0.04968118667602539,
-0.041218385100364685,
0.01668003387749195,
-0.04503420367836952,
-0.026559600606560707,
0.0016930329147726297,
0.024481680244207382,
0.01915464736521244,
-0.024273887276649475,
0.004283349495381117,
-0.014054297469556332,
0.004198343493044376,
0.030734332278370857,
0.015565512701869011,
-0.03228332847356796,
-0.011929151602089405,
0.034852392971515656,
0.07268943637609482,
-0.048132192343473434,
-0.059239622205495834,
-0.013638713397085667,
-0.015707189217209816,
0.0012113330885767937,
0.02189372479915619,
-0.03659028932452202,
-0.0611286386847496,
0.027825243771076202,
0.043409645557403564,
0.05240137502551079,
0.016236115247011185,
0.021213678643107414,
0.032377779483795166,
-0.04548756778240204,
-0.04665875807404518,
-0.026465149596333504,
-0.031735509634017944,
-0.014677673578262329,
-0.014243199490010738,
0.06819356977939606,
0.028713081032037735,
0.004434471018612385,
0.053421445190906525,
-0.01887129433453083,
0.0058559575118124485,
0.023404939100146294,
-0.07472957670688629,
-0.017577316612005234,
0.029242007061839104,
-0.03560800105333328,
0.011012977920472622,
0.019211318343877792,
0.02329159900546074,
0.0019645793363451958,
-0.0033199500758200884,
0.005383702926337719,
-0.02272489294409752,
0.009393144398927689,
0.0007845330401323736,
-0.0015242018271237612,
0.006729628425091505,
-0.03472016006708145,
-0.07087597250938416,
-0.015452171675860882,
0.03135770931839943,
-0.0029350626282393932,
-0.031546611338853836,
0.0005250881076790392,
-0.01070129033178091,
-0.003494684351608157,
0.016510022804141045,
0.024273887276649475,
0.02797636389732361,
-0.004101531580090523,
-0.03834707662463188,
-0.021704822778701782,
-0.04658319801092148,
0.02189372479915619,
-0.07064929604530334,
0.021799273788928986,
0.06626676768064499,
0.010616283863782883,
0.03307671472430229,
0.004949228372424841,
-0.03861153870820999,
-0.03475794196128845,
0.02193150483071804,
0.044807519763708115,
0.011711915023624897,
0.07642968744039536,
0.04269181936979294,
-0.015216044150292873,
-0.05489487946033478,
-0.09732223302125931,
-0.017038946971297264,
0.04919004440307617,
0.008628091774880886,
-0.04499642178416252,
0.009487595409154892,
0.03672252222895622,
-0.051456864923238754,
-0.035400208085775375,
-0.008958670310676098,
-0.024519460275769234,
-0.05610385164618492,
-0.09074845165014267,
-0.00748051330447197,
-0.001848876941949129,
0.015688298270106316,
-0.012335291132330894,
0.03500351309776306,
0.022384868934750557,
-0.0040519447065889835,
-0.04680987820029259,
0.00003528996603563428,
0.03851708769798279,
0.03532464802265167,
-0.013723719865083694,
-0.01220306009054184,
0.010030688717961311,
-0.08084999024868011,
0.06192202866077423,
0.08092555403709412,
-0.014819350093603134,
-0.00790082011371851,
0.005232581403106451,
0.0017922063125297427,
-0.015367166139185429,
0.07865872979164124,
0.031773291528224945,
-0.021704822778701782,
-0.06713572144508362,
0.005109795369207859,
0.006578506901860237,
0.035135746002197266,
0.018465155735611916,
-0.03560800105333328,
0.014280980452895164,
-0.005076737143099308,
0.034002333879470825,
-0.03362452983856201,
-0.05047457665205002,
-0.0006133407005108893,
0.031206585466861725,
0.03164106234908104,
-0.0020791010465472937,
-0.009402589872479439,
0.024878373369574547,
-0.028203045949339867,
-0.07359616458415985,
-0.027957474812865257,
0.021175898611545563,
-0.0263895895332098,
-0.005596217233687639,
-0.015707189217209816,
-0.01776621863245964,
-0.0443541556596756,
-0.0047603268176317215,
0.032377779483795166,
0.008288068696856499,
-0.009487595409154892,
-0.0023612731602042913,
0.018531272187829018,
0.02021249756217003,
-0.011759140528738499,
-0.025955114513635635,
-0.019258543848991394,
-0.031206585466861725,
-0.025123946368694305,
0.04363632947206497,
-0.012458077631890774,
0.00590318301692605,
-0.03749701753258705,
0.0020720171742141247,
-0.004025970585644245,
0.00403069332242012,
-0.03199997544288635,
-0.013931511901319027,
-0.03405900299549103,
-0.019796913489699364,
0.09067288786172867,
0.022611550986766815,
-0.0044132196344435215,
-0.0009315222851000726,
0.02414165623486042,
-0.04140728712081909,
-0.02608734555542469,
0.010266815312206745,
0.08304125815629959,
0.061770904809236526,
0.01235418114811182,
0.038724880665540695,
0.04911448061466217,
-0.03800705447793007,
0.035060182213783264,
0.016169998794794083,
-0.07926321774721146,
0.021270349621772766,
0.032358888536691666,
-0.008774491026997566,
0.009719000197947025,
0.0012656424660235643,
0.004042499698698521,
0.08568587899208069,
-0.023801634088158607,
-0.030904343351721764,
-0.039820510894060135,
-0.021308129653334618,
0.016528911888599396,
-0.008495860733091831,
-0.007154657505452633,
-0.00646044360473752,
0.03936714679002762,
-0.028996434062719345,
-0.013629268854856491,
0.05474375560879707,
-0.06581340730190277,
0.019258543848991394,
0.00004276118124835193,
0.04337186738848686,
0.022668221965432167,
-0.005931518040597439,
0.05742616206407547,
0.019220763817429543,
0.0023825245443731546,
0.042842939496040344,
-0.021175898611545563,
0.0388004407286644,
0.020609192550182343,
0.06551115959882736,
-0.0388382226228714,
-0.025917334482073784,
0.004212511237710714,
0.04832109436392784,
0.05017233267426491,
-0.015376610681414604,
-0.013563153333961964,
-0.05187245085835457,
0.0034781554713845253,
0.001713103731162846,
-0.04798107221722603,
0.02831638790667057,
-0.014535997994244099,
0.04004719480872154,
0.02603067457675934,
-0.07242497056722641,
-0.039518266916275024,
-0.01855016127228737,
0.008236120454967022,
0.023253818973898888,
-0.04601649194955826,
-0.022592661902308464,
-0.012401406653225422,
0.02886420302093029,
0.024576131254434586,
0.004531283397227526,
0.04937894642353058,
-0.036080252379179,
0.05466819554567337,
0.0058559575118124485,
-0.0152349341660738,
0.0471876822412014,
0.03377564996480942,
-0.03672252222895622,
-0.04129394516348839,
0.047603268176317215,
0.00006748075975337997,
-0.0444674976170063,
0.04208733141422272,
-0.01069184485822916,
0.003442736342549324,
0.0416339673101902,
-0.027806352823972702,
-0.011702469550073147,
-0.00192561827134341,
-0.03628804534673691,
0.0024958658032119274,
-0.002127507235854864,
0.01744508557021618,
-0.045336443930864334,
-0.012779210694134235,
-0.03821484372019768,
-0.04027387499809265,
0.036174703389406204,
-0.050890158861875534,
-0.013317580334842205,
-0.03800705447793007,
0.02805192582309246,
0.02499171532690525,
0.013175904750823975,
0.030961014330387115,
0.025445079430937767,
-0.015962205827236176,
0.006365992594510317,
-0.011825256049633026,
0.03698698431253433,
-0.022951574996113777,
0.019645793363451958,
-0.02501060627400875,
0.06902473419904709,
0.031471047550439835,
0.029015325009822845,
-0.013109788298606873,
0.03417234495282173,
0.013997627422213554,
-0.05991966649889946,
-0.003012984525412321,
0.013685938902199268,
0.03989607095718384,
0.03075322136282921,
-0.02633291855454445,
-0.04016053304076195,
-0.03553243726491928,
0.05606606975197792,
0.0208547655493021,
-0.02716408669948578,
0.07710973918437958,
0.023971645161509514,
0.02939312905073166,
-0.07182048261165619,
-0.07166936248540878,
0.0472254641354084,
0.013506482355296612,
0.03997163102030754,
-0.00015126906509976834,
-0.018427375704050064,
-0.045676469802856445,
0.058672916144132614,
0.034247905015945435,
-0.07427620887756348,
0.022063735872507095,
0.03466349095106125,
0.027126306667923927,
0.06014635041356087,
0.006129865068942308,
0.11326555162668228,
0.038989342749118805,
-0.051494646817445755,
-0.036514729261398315,
0.037912603467702866,
0.029884273186326027,
-0.05039901286363602,
0.005204245913773775,
-0.017010612413287163,
0.025633981451392174,
-0.0692136362195015,
0.05659499391913414,
0.007886652834713459,
0.009520653635263443,
0.029752042144536972,
0.0305643193423748,
0.04915226250886917,
-0.05459263548254967,
0.020401399582624435,
0.05761506408452988,
0.02667294256389141,
-0.04238957539200783,
-0.0073813400231301785,
-0.023763854056596756,
0.02965759113430977,
0.020193608477711678,
0.023253818973898888,
-0.014819350093603134,
-0.024009425193071365,
-0.01385595090687275,
-0.0008937419042922556,
-0.09014396369457245,
0.03388899192214012,
0.012118053622543812,
-0.01994803547859192,
0.054252613335847855,
-0.06279097497463226,
0.014800460077822208,
0.007409675046801567,
-0.004819358699023724,
0.04461861774325371,
0.028769752010703087,
0.00970955565571785,
0.08153004199266434,
0.020476961508393288,
-0.03500351309776306,
0.05013455078005791,
0.010446272790431976,
0.03377564996480942,
0.02195039577782154,
-0.007683583069592714,
0.03439902886748314,
0.0118063660338521,
-0.015537177212536335,
-0.03779926151037216,
0.03411567583680153,
0.026238467544317245,
0.03468238189816475,
-0.013043672777712345,
-0.07903653383255005,
0.012033048085868359,
-0.029789822176098824,
-0.023971645161509514,
-0.003527742112055421,
-0.011466342955827713,
-0.0277874618768692,
-0.00218890025280416,
0.05330810323357582,
0.0016942134825512767,
0.04265403747558594,
-0.031773291528224945,
0.004318768624216318,
0.02695629373192787,
-0.012155834585428238,
-0.05383702740073204,
-0.04529866576194763,
-0.035664670169353485,
-0.005468708463013172,
0.04080279916524887,
-0.008765045553445816,
0.07548517733812332,
-0.013487592339515686,
0.022687112912535667,
-0.010994087904691696,
-0.0011623366735875607,
-0.09188186377286911,
-0.03515463322401047,
0.010238480754196644,
-0.00022874833666719496,
0.03574023023247719,
0.009157017804682255,
-0.0360424742102623,
0.05240137502551079,
-0.042351797223091125,
0.01445099152624607,
0.01208971906453371,
0.017275074496865273,
0.0012443909654393792,
0.03145216032862663,
0.006578506901860237,
0.03713810443878174,
0.03449347987771034,
-0.003105074167251587,
-0.03523019701242447,
0.05765284597873688,
-0.00987012218683958,
-0.08273901045322418,
-0.007376617286354303,
-0.0010631632758304477,
0.008505306206643581,
-0.030394308269023895,
-0.017303409054875374,
-0.0054545411840081215,
-0.0526658371090889,
-0.03519241511821747,
0.03156549856066704,
-0.05028567463159561,
-0.03249111771583557,
-0.06245095282793045,
0.0639999508857727,
-0.002295157639309764,
-0.053685907274484634,
-0.027012964710593224,
0.061695344746112823,
-0.030734332278370857,
-0.0036528895143419504,
0.00200944347307086,
-0.00395749369636178,
-0.021572591736912727,
0.01668003387749195,
-0.0208169836550951,
-0.06343324482440948,
-0.03940492495894432,
-0.013940956443548203,
-0.008968115784227848,
0.016292784363031387,
-0.020155828446149826,
0.02886420302093029,
0.00033441532286815345,
0.010635174810886383,
-0.048963360488414764,
0.024840593338012695,
0.025463970378041267,
0.05024789273738861,
0.03052653931081295,
-0.04937894642353058,
-0.0010838244343176484,
0.01919242925941944,
-0.033737871795892715,
-0.03944270685315132,
-0.027957474812865257,
-0.10865634679794312,
0.01943800039589405,
0.07642968744039536,
-0.005435650702565908,
0.008004715666174889,
-0.005331754684448242,
-0.04102948307991028,
0.03080989234149456,
-0.06025969237089157,
0.03662807121872902,
0.05055013671517372,
0.007471068296581507,
0.0263895895332098,
0.05942852422595024,
0.007584409322589636,
-0.02686184272170067,
0.0011806365801021457,
-0.0015360082034021616,
0.0415584072470665,
-0.01717117801308632,
-0.02300824597477913,
0.0916551798582077,
0.050058990716934204,
0.026842953637242317,
0.008689485490322113,
0.012892551720142365,
-0.07397396862506866,
0.00371428276412189,
-0.0499456487596035,
0.00858558900654316,
-0.009308138862252235,
0.046469856053590775,
-0.01889018528163433,
-0.022819343954324722,
0.02748521976172924,
-0.002814637729898095,
-0.015650518238544464,
-0.030375417321920395,
-0.09407312422990799,
-0.04495863988995552,
-0.006455720867961645,
0.024330558255314827,
-0.0005324670928530395,
-0.04031165689229965,
0.01151356752961874,
0.04080279916524887,
-0.02688073366880417,
-0.08697041124105453,
0.0017390777356922626,
0.062035370618104935,
-0.012543083168566227,
0.035362426191568375,
0.010795741342008114,
0.03387010097503662,
0.06687125563621521,
-0.00215230043977499,
-0.06154422461986542,
-0.01694449596107006,
0.006247928831726313,
-0.034002333879470825,
0.023782743141055107,
0.03766702860593796,
0.017955120652914047,
0.01442265696823597,
-0.02774968184530735,
-0.02276267297565937,
0.019759133458137512,
0.04295628145337105,
0.010200699791312218,
-0.029506469145417213,
-0.015263269655406475,
0.02467058226466179,
-0.01639668084681034,
-0.033190056681632996,
-0.021308129653334618,
-0.009610381908714771,
-0.024595022201538086,
0.030620990321040154,
0.06902473419904709,
0.02969537116587162,
0.030923234298825264,
-0.010909082368016243,
-0.033208947628736496,
-0.014602113515138626,
-0.04212511330842972,
-0.0019208957673981786,
0.0002626916393637657,
-0.005223136395215988,
-0.06959144026041031,
-0.040122754871845245,
0.06706015765666962,
0.039820510894060135,
0.040689460933208466,
0.05848401412367821,
0.016576137393712997,
-0.0692514181137085,
0.05123018100857735,
0.039253804832696915,
-0.010059023275971413,
-0.056708335876464844,
-0.014186529442667961,
0.0208169836550951,
-0.034587930887937546,
0.005412037950009108,
0.012448632158339024,
0.03766702860593796,
0.04212511330842972,
0.03630693629384041,
-0.03171662241220474,
0.005553714465349913,
0.013327025808393955,
0.003768591908738017,
-0.04612983390688896,
-0.02582288347184658,
-0.0416717492043972,
0.0028382502496242523,
0.029185336083173752,
0.02026916854083538,
0.0009657607297413051,
0.05372368544340134,
0.004332936368882656,
0.025709541514515877,
-0.0859881266951561,
0.00280991499312222,
-0.019910255447030067,
-0.05916406214237213,
0.05580160766839981,
-0.013931511901319027,
-0.013062562793493271,
-0.0026753225829452276,
-0.017548982053995132,
-0.004488780163228512,
0.01996692642569542,
-0.0388004407286644,
0.01136244647204876,
0.03523019701242447,
-0.012694204226136208,
0.016538357362151146,
-0.05655721575021744,
-0.01723729446530342,
-0.045903149992227554,
0.02468947321176529,
0.014035407453775406,
0.04605427011847496,
-0.06509558111429214,
0.02909088507294655,
-0.013988181948661804,
-0.02805192582309246,
0.06706015765666962,
-0.08221008628606796,
0.00902006309479475,
-0.00353482598438859,
0.023726072162389755,
0.01485713105648756,
0.009907902218401432,
0.03211331367492676,
0.026144016534090042,
0.06864693015813828,
0.04129394516348839,
0.013128679245710373,
0.08636593073606491,
0.03277447074651718,
-0.037837039679288864,
0.0025312849320471287,
0.04541200399398804,
-0.0008388423011638224,
-0.028486398980021477,
-0.016708368435502052,
-0.022535990923643112,
-0.019891364499926567,
0.010587949305772781,
-0.036118034273386,
-0.013317580334842205,
0.02805192582309246,
0.03305782377719879,
0.030942123383283615,
0.02000470645725727,
-0.0031286869198083878,
0.03489017114043236,
-0.003740256652235985,
-0.033473409712314606,
0.03245333954691887,
-0.013072008267045021,
-0.01919242925941944,
-0.06849581003189087,
0.025936225429177284,
0.0049020033329725266,
-0.04680987820029259,
-0.014280980452895164,
0.04080279916524887,
0.018918519839644432,
-0.019853584468364716,
-0.021308129653334618,
0.0052845291793346405,
0.02436833828687668,
-0.017123952507972717,
-0.030639881268143654,
0.016491131857037544,
-0.0071027097292244434,
-0.01052183285355568,
-0.0804721862077713,
0.013497037813067436,
0.041785091161727905,
-0.005402592942118645,
-0.011050758883357048,
-0.044240813702344894,
0.015612738206982613,
0.021818164736032486,
-0.04586537182331085,
0.010446272790431976,
-0.07386062294244766,
-0.035948023200035095,
0.03362452983856201,
0.017256183549761772,
0.05651943385601044,
-0.05489487946033478,
-0.012401406653225422,
0.00036186512443237007,
-0.008108612149953842,
-0.040953923016786575,
-0.02744743973016739,
0.058143991976976395,
-0.07624078541994095,
0.01718062348663807,
-0.027371877804398537,
0.006290431600064039,
-0.0058417897671461105,
0.011116874404251575,
-0.012816990725696087,
-0.0750695988535881,
0.00816528219729662,
0.0010371892713010311,
-0.003655250882729888,
-0.010824075900018215,
0.050587914884090424,
0.005605662707239389,
-0.07896097749471664,
-0.03795038163661957,
-0.01135300099849701,
-0.0013872479321435094,
0.055423803627491,
-0.05678389593958855,
0.014432101510465145,
-0.03719477355480194,
0.017284519970417023,
-0.026578491553664207,
0.019608013331890106,
-0.02223374880850315,
0.06758908182382584,
0.013997627422213554,
-0.007749698590487242,
-0.013119233772158623,
-0.018720174208283424,
-0.044278595596551895,
0.036212485283613205,
-0.039858292788267136,
-0.01485713105648756,
-0.034550148993730545,
-0.025955114513635635,
0.08228565007448196,
0.009275080636143684,
-0.014677673578262329,
-0.031546611338853836,
0.06445331126451492,
0.0305643193423748,
0.0025808715727180243,
-0.032604459673166275,
-0.04405191168189049,
-0.08175672590732574,
-0.03948048874735832,
0.005922073032706976,
-0.0025312849320471287,
0.036080252379179,
-0.008623369969427586,
0.043674107640981674,
-0.003239666810259223,
0.08221008628606796
]
|
31,219 | networkx.algorithms.isomorphism.vf2pp | vf2pp_isomorphism | Return an isomorphic mapping between `G1` and `G2` if it exists.
Parameters
----------
G1, G2 : NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism.
node_label : str, optional
The name of the node attribute to be used when comparing nodes.
The default is `None`, meaning node attributes are not considered
in the comparison. Any node that doesn't have the `node_label`
attribute uses `default_label` instead.
default_label : scalar
Default value to use when a node doesn't have an attribute
named `node_label`. Default is `None`.
Returns
-------
dict or None
Node mapping if the two graphs are isomorphic. None otherwise.
| def _consistent_PT(u, v, graph_params, state_params):
"""Checks the consistency of extending the mapping using the current node pair.
Parameters
----------
u, v: Graph node
The two candidate nodes being examined.
graph_params: namedtuple
Contains all the Graph-related parameters:
G1,G2: NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism or monomorphism
G1_labels,G2_labels: dict
The label of every node in G1 and G2 respectively
state_params: namedtuple
Contains all the State-related parameters:
mapping: dict
The mapping as extended so far. Maps nodes of G1 to nodes of G2
reverse_mapping: dict
The reverse mapping as extended so far. Maps nodes from G2 to nodes of G1. It's basically "mapping" reversed
T1, T2: set
Ti contains uncovered neighbors of covered nodes from Gi, i.e. nodes that are not in the mapping, but are
neighbors of nodes that are.
T1_out, T2_out: set
Ti_out contains all the nodes from Gi, that are neither in the mapping nor in Ti
Returns
-------
True if the pair passes all the consistency checks successfully. False otherwise.
"""
G1, G2 = graph_params.G1, graph_params.G2
mapping, reverse_mapping = state_params.mapping, state_params.reverse_mapping
for neighbor in G1[u]:
if neighbor in mapping:
if G1.number_of_edges(u, neighbor) != G2.number_of_edges(
v, mapping[neighbor]
):
return False
for neighbor in G2[v]:
if neighbor in reverse_mapping:
if G1.number_of_edges(u, reverse_mapping[neighbor]) != G2.number_of_edges(
v, neighbor
):
return False
if not G1.is_directed():
return True
for predecessor in G1.pred[u]:
if predecessor in mapping:
if G1.number_of_edges(predecessor, u) != G2.number_of_edges(
mapping[predecessor], v
):
return False
for predecessor in G2.pred[v]:
if predecessor in reverse_mapping:
if G1.number_of_edges(
reverse_mapping[predecessor], u
) != G2.number_of_edges(predecessor, v):
return False
return True
| (G1, G2, node_label=None, default_label=None, *, backend=None, **backend_kwargs) | [
0.04582758992910385,
-0.003964577801525593,
-0.05663277581334114,
0.10669177025556564,
-0.020892545580863953,
-0.018984636291861534,
-0.04968118667602539,
-0.041218385100364685,
0.01668003387749195,
-0.04503420367836952,
-0.026559600606560707,
0.0016930329147726297,
0.024481680244207382,
0.01915464736521244,
-0.024273887276649475,
0.004283349495381117,
-0.014054297469556332,
0.004198343493044376,
0.030734332278370857,
0.015565512701869011,
-0.03228332847356796,
-0.011929151602089405,
0.034852392971515656,
0.07268943637609482,
-0.048132192343473434,
-0.059239622205495834,
-0.013638713397085667,
-0.015707189217209816,
0.0012113330885767937,
0.02189372479915619,
-0.03659028932452202,
-0.0611286386847496,
0.027825243771076202,
0.043409645557403564,
0.05240137502551079,
0.016236115247011185,
0.021213678643107414,
0.032377779483795166,
-0.04548756778240204,
-0.04665875807404518,
-0.026465149596333504,
-0.031735509634017944,
-0.014677673578262329,
-0.014243199490010738,
0.06819356977939606,
0.028713081032037735,
0.004434471018612385,
0.053421445190906525,
-0.01887129433453083,
0.0058559575118124485,
0.023404939100146294,
-0.07472957670688629,
-0.017577316612005234,
0.029242007061839104,
-0.03560800105333328,
0.011012977920472622,
0.019211318343877792,
0.02329159900546074,
0.0019645793363451958,
-0.0033199500758200884,
0.005383702926337719,
-0.02272489294409752,
0.009393144398927689,
0.0007845330401323736,
-0.0015242018271237612,
0.006729628425091505,
-0.03472016006708145,
-0.07087597250938416,
-0.015452171675860882,
0.03135770931839943,
-0.0029350626282393932,
-0.031546611338853836,
0.0005250881076790392,
-0.01070129033178091,
-0.003494684351608157,
0.016510022804141045,
0.024273887276649475,
0.02797636389732361,
-0.004101531580090523,
-0.03834707662463188,
-0.021704822778701782,
-0.04658319801092148,
0.02189372479915619,
-0.07064929604530334,
0.021799273788928986,
0.06626676768064499,
0.010616283863782883,
0.03307671472430229,
0.004949228372424841,
-0.03861153870820999,
-0.03475794196128845,
0.02193150483071804,
0.044807519763708115,
0.011711915023624897,
0.07642968744039536,
0.04269181936979294,
-0.015216044150292873,
-0.05489487946033478,
-0.09732223302125931,
-0.017038946971297264,
0.04919004440307617,
0.008628091774880886,
-0.04499642178416252,
0.009487595409154892,
0.03672252222895622,
-0.051456864923238754,
-0.035400208085775375,
-0.008958670310676098,
-0.024519460275769234,
-0.05610385164618492,
-0.09074845165014267,
-0.00748051330447197,
-0.001848876941949129,
0.015688298270106316,
-0.012335291132330894,
0.03500351309776306,
0.022384868934750557,
-0.0040519447065889835,
-0.04680987820029259,
0.00003528996603563428,
0.03851708769798279,
0.03532464802265167,
-0.013723719865083694,
-0.01220306009054184,
0.010030688717961311,
-0.08084999024868011,
0.06192202866077423,
0.08092555403709412,
-0.014819350093603134,
-0.00790082011371851,
0.005232581403106451,
0.0017922063125297427,
-0.015367166139185429,
0.07865872979164124,
0.031773291528224945,
-0.021704822778701782,
-0.06713572144508362,
0.005109795369207859,
0.006578506901860237,
0.035135746002197266,
0.018465155735611916,
-0.03560800105333328,
0.014280980452895164,
-0.005076737143099308,
0.034002333879470825,
-0.03362452983856201,
-0.05047457665205002,
-0.0006133407005108893,
0.031206585466861725,
0.03164106234908104,
-0.0020791010465472937,
-0.009402589872479439,
0.024878373369574547,
-0.028203045949339867,
-0.07359616458415985,
-0.027957474812865257,
0.021175898611545563,
-0.0263895895332098,
-0.005596217233687639,
-0.015707189217209816,
-0.01776621863245964,
-0.0443541556596756,
-0.0047603268176317215,
0.032377779483795166,
0.008288068696856499,
-0.009487595409154892,
-0.0023612731602042913,
0.018531272187829018,
0.02021249756217003,
-0.011759140528738499,
-0.025955114513635635,
-0.019258543848991394,
-0.031206585466861725,
-0.025123946368694305,
0.04363632947206497,
-0.012458077631890774,
0.00590318301692605,
-0.03749701753258705,
0.0020720171742141247,
-0.004025970585644245,
0.00403069332242012,
-0.03199997544288635,
-0.013931511901319027,
-0.03405900299549103,
-0.019796913489699364,
0.09067288786172867,
0.022611550986766815,
-0.0044132196344435215,
-0.0009315222851000726,
0.02414165623486042,
-0.04140728712081909,
-0.02608734555542469,
0.010266815312206745,
0.08304125815629959,
0.061770904809236526,
0.01235418114811182,
0.038724880665540695,
0.04911448061466217,
-0.03800705447793007,
0.035060182213783264,
0.016169998794794083,
-0.07926321774721146,
0.021270349621772766,
0.032358888536691666,
-0.008774491026997566,
0.009719000197947025,
0.0012656424660235643,
0.004042499698698521,
0.08568587899208069,
-0.023801634088158607,
-0.030904343351721764,
-0.039820510894060135,
-0.021308129653334618,
0.016528911888599396,
-0.008495860733091831,
-0.007154657505452633,
-0.00646044360473752,
0.03936714679002762,
-0.028996434062719345,
-0.013629268854856491,
0.05474375560879707,
-0.06581340730190277,
0.019258543848991394,
0.00004276118124835193,
0.04337186738848686,
0.022668221965432167,
-0.005931518040597439,
0.05742616206407547,
0.019220763817429543,
0.0023825245443731546,
0.042842939496040344,
-0.021175898611545563,
0.0388004407286644,
0.020609192550182343,
0.06551115959882736,
-0.0388382226228714,
-0.025917334482073784,
0.004212511237710714,
0.04832109436392784,
0.05017233267426491,
-0.015376610681414604,
-0.013563153333961964,
-0.05187245085835457,
0.0034781554713845253,
0.001713103731162846,
-0.04798107221722603,
0.02831638790667057,
-0.014535997994244099,
0.04004719480872154,
0.02603067457675934,
-0.07242497056722641,
-0.039518266916275024,
-0.01855016127228737,
0.008236120454967022,
0.023253818973898888,
-0.04601649194955826,
-0.022592661902308464,
-0.012401406653225422,
0.02886420302093029,
0.024576131254434586,
0.004531283397227526,
0.04937894642353058,
-0.036080252379179,
0.05466819554567337,
0.0058559575118124485,
-0.0152349341660738,
0.0471876822412014,
0.03377564996480942,
-0.03672252222895622,
-0.04129394516348839,
0.047603268176317215,
0.00006748075975337997,
-0.0444674976170063,
0.04208733141422272,
-0.01069184485822916,
0.003442736342549324,
0.0416339673101902,
-0.027806352823972702,
-0.011702469550073147,
-0.00192561827134341,
-0.03628804534673691,
0.0024958658032119274,
-0.002127507235854864,
0.01744508557021618,
-0.045336443930864334,
-0.012779210694134235,
-0.03821484372019768,
-0.04027387499809265,
0.036174703389406204,
-0.050890158861875534,
-0.013317580334842205,
-0.03800705447793007,
0.02805192582309246,
0.02499171532690525,
0.013175904750823975,
0.030961014330387115,
0.025445079430937767,
-0.015962205827236176,
0.006365992594510317,
-0.011825256049633026,
0.03698698431253433,
-0.022951574996113777,
0.019645793363451958,
-0.02501060627400875,
0.06902473419904709,
0.031471047550439835,
0.029015325009822845,
-0.013109788298606873,
0.03417234495282173,
0.013997627422213554,
-0.05991966649889946,
-0.003012984525412321,
0.013685938902199268,
0.03989607095718384,
0.03075322136282921,
-0.02633291855454445,
-0.04016053304076195,
-0.03553243726491928,
0.05606606975197792,
0.0208547655493021,
-0.02716408669948578,
0.07710973918437958,
0.023971645161509514,
0.02939312905073166,
-0.07182048261165619,
-0.07166936248540878,
0.0472254641354084,
0.013506482355296612,
0.03997163102030754,
-0.00015126906509976834,
-0.018427375704050064,
-0.045676469802856445,
0.058672916144132614,
0.034247905015945435,
-0.07427620887756348,
0.022063735872507095,
0.03466349095106125,
0.027126306667923927,
0.06014635041356087,
0.006129865068942308,
0.11326555162668228,
0.038989342749118805,
-0.051494646817445755,
-0.036514729261398315,
0.037912603467702866,
0.029884273186326027,
-0.05039901286363602,
0.005204245913773775,
-0.017010612413287163,
0.025633981451392174,
-0.0692136362195015,
0.05659499391913414,
0.007886652834713459,
0.009520653635263443,
0.029752042144536972,
0.0305643193423748,
0.04915226250886917,
-0.05459263548254967,
0.020401399582624435,
0.05761506408452988,
0.02667294256389141,
-0.04238957539200783,
-0.0073813400231301785,
-0.023763854056596756,
0.02965759113430977,
0.020193608477711678,
0.023253818973898888,
-0.014819350093603134,
-0.024009425193071365,
-0.01385595090687275,
-0.0008937419042922556,
-0.09014396369457245,
0.03388899192214012,
0.012118053622543812,
-0.01994803547859192,
0.054252613335847855,
-0.06279097497463226,
0.014800460077822208,
0.007409675046801567,
-0.004819358699023724,
0.04461861774325371,
0.028769752010703087,
0.00970955565571785,
0.08153004199266434,
0.020476961508393288,
-0.03500351309776306,
0.05013455078005791,
0.010446272790431976,
0.03377564996480942,
0.02195039577782154,
-0.007683583069592714,
0.03439902886748314,
0.0118063660338521,
-0.015537177212536335,
-0.03779926151037216,
0.03411567583680153,
0.026238467544317245,
0.03468238189816475,
-0.013043672777712345,
-0.07903653383255005,
0.012033048085868359,
-0.029789822176098824,
-0.023971645161509514,
-0.003527742112055421,
-0.011466342955827713,
-0.0277874618768692,
-0.00218890025280416,
0.05330810323357582,
0.0016942134825512767,
0.04265403747558594,
-0.031773291528224945,
0.004318768624216318,
0.02695629373192787,
-0.012155834585428238,
-0.05383702740073204,
-0.04529866576194763,
-0.035664670169353485,
-0.005468708463013172,
0.04080279916524887,
-0.008765045553445816,
0.07548517733812332,
-0.013487592339515686,
0.022687112912535667,
-0.010994087904691696,
-0.0011623366735875607,
-0.09188186377286911,
-0.03515463322401047,
0.010238480754196644,
-0.00022874833666719496,
0.03574023023247719,
0.009157017804682255,
-0.0360424742102623,
0.05240137502551079,
-0.042351797223091125,
0.01445099152624607,
0.01208971906453371,
0.017275074496865273,
0.0012443909654393792,
0.03145216032862663,
0.006578506901860237,
0.03713810443878174,
0.03449347987771034,
-0.003105074167251587,
-0.03523019701242447,
0.05765284597873688,
-0.00987012218683958,
-0.08273901045322418,
-0.007376617286354303,
-0.0010631632758304477,
0.008505306206643581,
-0.030394308269023895,
-0.017303409054875374,
-0.0054545411840081215,
-0.0526658371090889,
-0.03519241511821747,
0.03156549856066704,
-0.05028567463159561,
-0.03249111771583557,
-0.06245095282793045,
0.0639999508857727,
-0.002295157639309764,
-0.053685907274484634,
-0.027012964710593224,
0.061695344746112823,
-0.030734332278370857,
-0.0036528895143419504,
0.00200944347307086,
-0.00395749369636178,
-0.021572591736912727,
0.01668003387749195,
-0.0208169836550951,
-0.06343324482440948,
-0.03940492495894432,
-0.013940956443548203,
-0.008968115784227848,
0.016292784363031387,
-0.020155828446149826,
0.02886420302093029,
0.00033441532286815345,
0.010635174810886383,
-0.048963360488414764,
0.024840593338012695,
0.025463970378041267,
0.05024789273738861,
0.03052653931081295,
-0.04937894642353058,
-0.0010838244343176484,
0.01919242925941944,
-0.033737871795892715,
-0.03944270685315132,
-0.027957474812865257,
-0.10865634679794312,
0.01943800039589405,
0.07642968744039536,
-0.005435650702565908,
0.008004715666174889,
-0.005331754684448242,
-0.04102948307991028,
0.03080989234149456,
-0.06025969237089157,
0.03662807121872902,
0.05055013671517372,
0.007471068296581507,
0.0263895895332098,
0.05942852422595024,
0.007584409322589636,
-0.02686184272170067,
0.0011806365801021457,
-0.0015360082034021616,
0.0415584072470665,
-0.01717117801308632,
-0.02300824597477913,
0.0916551798582077,
0.050058990716934204,
0.026842953637242317,
0.008689485490322113,
0.012892551720142365,
-0.07397396862506866,
0.00371428276412189,
-0.0499456487596035,
0.00858558900654316,
-0.009308138862252235,
0.046469856053590775,
-0.01889018528163433,
-0.022819343954324722,
0.02748521976172924,
-0.002814637729898095,
-0.015650518238544464,
-0.030375417321920395,
-0.09407312422990799,
-0.04495863988995552,
-0.006455720867961645,
0.024330558255314827,
-0.0005324670928530395,
-0.04031165689229965,
0.01151356752961874,
0.04080279916524887,
-0.02688073366880417,
-0.08697041124105453,
0.0017390777356922626,
0.062035370618104935,
-0.012543083168566227,
0.035362426191568375,
0.010795741342008114,
0.03387010097503662,
0.06687125563621521,
-0.00215230043977499,
-0.06154422461986542,
-0.01694449596107006,
0.006247928831726313,
-0.034002333879470825,
0.023782743141055107,
0.03766702860593796,
0.017955120652914047,
0.01442265696823597,
-0.02774968184530735,
-0.02276267297565937,
0.019759133458137512,
0.04295628145337105,
0.010200699791312218,
-0.029506469145417213,
-0.015263269655406475,
0.02467058226466179,
-0.01639668084681034,
-0.033190056681632996,
-0.021308129653334618,
-0.009610381908714771,
-0.024595022201538086,
0.030620990321040154,
0.06902473419904709,
0.02969537116587162,
0.030923234298825264,
-0.010909082368016243,
-0.033208947628736496,
-0.014602113515138626,
-0.04212511330842972,
-0.0019208957673981786,
0.0002626916393637657,
-0.005223136395215988,
-0.06959144026041031,
-0.040122754871845245,
0.06706015765666962,
0.039820510894060135,
0.040689460933208466,
0.05848401412367821,
0.016576137393712997,
-0.0692514181137085,
0.05123018100857735,
0.039253804832696915,
-0.010059023275971413,
-0.056708335876464844,
-0.014186529442667961,
0.0208169836550951,
-0.034587930887937546,
0.005412037950009108,
0.012448632158339024,
0.03766702860593796,
0.04212511330842972,
0.03630693629384041,
-0.03171662241220474,
0.005553714465349913,
0.013327025808393955,
0.003768591908738017,
-0.04612983390688896,
-0.02582288347184658,
-0.0416717492043972,
0.0028382502496242523,
0.029185336083173752,
0.02026916854083538,
0.0009657607297413051,
0.05372368544340134,
0.004332936368882656,
0.025709541514515877,
-0.0859881266951561,
0.00280991499312222,
-0.019910255447030067,
-0.05916406214237213,
0.05580160766839981,
-0.013931511901319027,
-0.013062562793493271,
-0.0026753225829452276,
-0.017548982053995132,
-0.004488780163228512,
0.01996692642569542,
-0.0388004407286644,
0.01136244647204876,
0.03523019701242447,
-0.012694204226136208,
0.016538357362151146,
-0.05655721575021744,
-0.01723729446530342,
-0.045903149992227554,
0.02468947321176529,
0.014035407453775406,
0.04605427011847496,
-0.06509558111429214,
0.02909088507294655,
-0.013988181948661804,
-0.02805192582309246,
0.06706015765666962,
-0.08221008628606796,
0.00902006309479475,
-0.00353482598438859,
0.023726072162389755,
0.01485713105648756,
0.009907902218401432,
0.03211331367492676,
0.026144016534090042,
0.06864693015813828,
0.04129394516348839,
0.013128679245710373,
0.08636593073606491,
0.03277447074651718,
-0.037837039679288864,
0.0025312849320471287,
0.04541200399398804,
-0.0008388423011638224,
-0.028486398980021477,
-0.016708368435502052,
-0.022535990923643112,
-0.019891364499926567,
0.010587949305772781,
-0.036118034273386,
-0.013317580334842205,
0.02805192582309246,
0.03305782377719879,
0.030942123383283615,
0.02000470645725727,
-0.0031286869198083878,
0.03489017114043236,
-0.003740256652235985,
-0.033473409712314606,
0.03245333954691887,
-0.013072008267045021,
-0.01919242925941944,
-0.06849581003189087,
0.025936225429177284,
0.0049020033329725266,
-0.04680987820029259,
-0.014280980452895164,
0.04080279916524887,
0.018918519839644432,
-0.019853584468364716,
-0.021308129653334618,
0.0052845291793346405,
0.02436833828687668,
-0.017123952507972717,
-0.030639881268143654,
0.016491131857037544,
-0.0071027097292244434,
-0.01052183285355568,
-0.0804721862077713,
0.013497037813067436,
0.041785091161727905,
-0.005402592942118645,
-0.011050758883357048,
-0.044240813702344894,
0.015612738206982613,
0.021818164736032486,
-0.04586537182331085,
0.010446272790431976,
-0.07386062294244766,
-0.035948023200035095,
0.03362452983856201,
0.017256183549761772,
0.05651943385601044,
-0.05489487946033478,
-0.012401406653225422,
0.00036186512443237007,
-0.008108612149953842,
-0.040953923016786575,
-0.02744743973016739,
0.058143991976976395,
-0.07624078541994095,
0.01718062348663807,
-0.027371877804398537,
0.006290431600064039,
-0.0058417897671461105,
0.011116874404251575,
-0.012816990725696087,
-0.0750695988535881,
0.00816528219729662,
0.0010371892713010311,
-0.003655250882729888,
-0.010824075900018215,
0.050587914884090424,
0.005605662707239389,
-0.07896097749471664,
-0.03795038163661957,
-0.01135300099849701,
-0.0013872479321435094,
0.055423803627491,
-0.05678389593958855,
0.014432101510465145,
-0.03719477355480194,
0.017284519970417023,
-0.026578491553664207,
0.019608013331890106,
-0.02223374880850315,
0.06758908182382584,
0.013997627422213554,
-0.007749698590487242,
-0.013119233772158623,
-0.018720174208283424,
-0.044278595596551895,
0.036212485283613205,
-0.039858292788267136,
-0.01485713105648756,
-0.034550148993730545,
-0.025955114513635635,
0.08228565007448196,
0.009275080636143684,
-0.014677673578262329,
-0.031546611338853836,
0.06445331126451492,
0.0305643193423748,
0.0025808715727180243,
-0.032604459673166275,
-0.04405191168189049,
-0.08175672590732574,
-0.03948048874735832,
0.005922073032706976,
-0.0025312849320471287,
0.036080252379179,
-0.008623369969427586,
0.043674107640981674,
-0.003239666810259223,
0.08221008628606796
]
|
31,228 | networkx.generators.random_graphs | watts_strogatz_graph | Returns a 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 rewiring each edge
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
See Also
--------
newman_watts_strogatz_graph
connected_watts_strogatz_graph
Notes
-----
First create a ring over $n$ nodes [1]_. Then each node in the ring is joined
to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
Then shortcuts are created by replacing some edges as follows: for each
edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
with probability $p$ replace it with a new edge $(u, w)$ with uniformly
random choice of existing node $w$.
In contrast with :func:`newman_watts_strogatz_graph`, the random rewiring
does not increase the number of edges. The rewired graph is not guaranteed
to be connected as in :func:`connected_watts_strogatz_graph`.
References
----------
.. [1] Duncan J. Watts and Steven H. Strogatz,
Collective dynamics of small-world networks,
Nature, 393, pp. 440--442, 1998.
| 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.00351903703995049,
0.0014900211244821548,
0.015369735658168793,
0.004886886104941368,
-0.02499019354581833,
-0.04081987217068672,
-0.0648135244846344,
-0.03633543476462364,
0.01210222952067852,
-0.029972899705171585,
0.006487101782113314,
0.04196972772479057,
-0.03679537773132324,
0.10724318772554398,
-0.0430045947432518,
0.01303169596940279,
0.03464898094534874,
0.047374047338962555,
-0.005864263046532869,
0.027328232303261757,
-0.04001497104763985,
0.0020266203209757805,
0.00006490395753644407,
0.07094608247280121,
-0.034533992409706116,
0.010741567239165306,
-0.03915258124470711,
0.010760731063783169,
-0.015580542385578156,
0.05933254584670067,
0.03921007364988327,
-0.12357114255428314,
0.021004026755690575,
0.03907592222094536,
-0.00011977661779383197,
0.01016663946211338,
0.027673188596963882,
0.061210643500089645,
-0.10961955785751343,
-0.03675704821944237,
0.07090775668621063,
-0.055423036217689514,
0.0834028571844101,
0.013089188374578953,
0.02466440014541149,
-0.02389783039689064,
0.030911948531866074,
0.012945456430315971,
-0.09651120752096176,
-0.00986001081764698,
0.016107559204101562,
-0.0704861432313919,
0.026235871016979218,
-0.002351214876398444,
-0.02042909897863865,
0.01844559982419014,
-0.0031117964535951614,
0.04461439326405525,
0.01783234253525734,
0.02537347935140133,
0.06301208585500717,
-0.01961461827158928,
-0.014564836397767067,
-0.03526223450899124,
-0.024472758173942566,
0.022019732743501663,
-0.04863888770341873,
-0.026791634038090706,
-0.0014972076751291752,
0.06209219619631767,
0.05036367103457451,
0.0640469491481781,
-0.008092108182609081,
0.055116407573223114,
0.05477144941687584,
0.04434609413146973,
0.04863888770341873,
0.027021605521440506,
-0.052088454365730286,
0.019605036824941635,
0.004206554964184761,
-0.025814255699515343,
0.011786019429564476,
-0.03432318568229675,
0.0055145155638456345,
-0.015484721399843693,
0.006027159281075001,
0.0031117964535951614,
0.0003054303815588355,
-0.10187719762325287,
-0.04863888770341873,
-0.04986540228128433,
0.055576350539922714,
0.01632794924080372,
0.031601861119270325,
-0.03326915204524994,
-0.006290667690336704,
-0.03238759562373161,
0.007512389216572046,
-0.024549415335059166,
-0.04503600671887398,
0.04369451105594635,
-0.03813687339425087,
0.0006198440096341074,
0.006544594187289476,
0.007119521964341402,
-0.052165113389492035,
0.015178092755377293,
0.02081238478422165,
-0.035319726914167404,
-0.11705528944730759,
0.0436178520321846,
0.07979997247457504,
0.018273120746016502,
-0.02288212440907955,
-0.013280831277370453,
0.015034360811114311,
0.011680616065859795,
0.031985148787498474,
0.03223428130149841,
0.016318365931510925,
0.02713659033179283,
-0.03296252340078354,
-0.00018774984346237034,
0.0007252474315464497,
-0.02405114471912384,
0.048217274248600006,
-0.008590378798544407,
-0.012887964025139809,
-0.03880762308835983,
0.010511595755815506,
0.014823554083704948,
-0.04710574820637703,
0.07021784037351608,
-0.011996826156973839,
-0.0343998447060585,
-0.04794897511601448,
0.005816352553665638,
0.06922130286693573,
0.0040316809900105,
-0.0008905391441658139,
-0.06684493273496628,
0.0890754759311676,
0.012935874983668327,
-0.03955502808094025,
-0.021444804966449738,
0.017180757597088814,
-0.057032834738492966,
0.0018469553906470537,
-0.012159721925854683,
0.039938315749168396,
-0.0012732254108414054,
0.020927369594573975,
-0.03459148854017258,
-0.03959335759282112,
0.017669446766376495,
-0.04154811426997185,
-0.00037340359995141625,
-0.023227080702781677,
0.014679822139441967,
-0.030605321750044823,
-0.054656464606523514,
0.04875387251377106,
0.05427318066358566,
0.010080399923026562,
-0.030796963721513748,
0.04952044412493706,
0.0018146157963201404,
0.017439475283026695,
-0.035473041236400604,
-0.07439564913511276,
-0.0012091449461877346,
-0.06600170582532883,
-0.06167058274149895,
0.052701711654663086,
-0.0021679566707462072,
-0.02598673477768898,
-0.03100777044892311,
0.029263822361826897,
0.03441900759935379,
0.038309354335069656,
-0.047297392040491104,
0.06780314445495605,
-0.05921756103634834,
-0.030605321750044823,
-0.035453878343105316,
-0.006405653432011604,
0.0430045947432518,
0.018052732571959496,
0.008547259494662285,
0.021406477317214012,
0.02476022206246853,
0.036067135632038116,
0.06086568534374237,
0.025239327922463417,
0.005231842398643494,
0.02514350786805153,
0.014612747356295586,
-0.012887964025139809,
0.011153598316013813,
0.04564926400780678,
0.0022422182373702526,
0.020467428490519524,
0.023227080702781677,
0.027903160080313683,
0.007641748059540987,
-0.03279004618525505,
-0.04196972772479057,
0.023150423541665077,
-0.02723241224884987,
0.00489167682826519,
-0.010434938594698906,
0.02861223742365837,
-0.02705993317067623,
-0.015379318036139011,
-0.06285876780748367,
0.019202586263418198,
0.017190340906381607,
-0.00014388165436685085,
-0.034917280077934265,
0.03208097070455551,
-0.05891093239188194,
0.010885299183428288,
0.02583342045545578,
0.005782815162092447,
0.043732836842536926,
-0.014631911180913448,
0.00398137466982007,
-0.015149346552789211,
0.028957195580005646,
0.033844079822301865,
-0.0007947178673930466,
0.036776211112737656,
-0.028343938291072845,
-0.03915258124470711,
-0.030126214027404785,
0.0030423260759562254,
-0.03959335759282112,
-0.03579883649945259,
0.019010944291949272,
-0.02945546619594097,
0.01987333595752716,
-0.02035244181752205,
-0.00900720153003931,
0.02236468903720379,
0.015561377629637718,
0.02830561064183712,
-0.05814436078071594,
-0.0684930607676506,
-0.019777514040470123,
-0.09329161047935486,
-0.012495096772909164,
0.024779386818408966,
0.031486876308918,
0.02614004909992218,
-0.026408348232507706,
-0.021521462127566338,
0.009725861251354218,
-0.004041262902319431,
0.05860430374741554,
0.007196179125458002,
-0.02035244181752205,
-0.11122936010360718,
0.03169768303632736,
-0.001528349588625133,
-0.005960084497928619,
-0.0707927718758583,
0.0695662572979927,
-0.013529966585338116,
-0.03131439909338951,
0.06186222657561302,
0.000664760242216289,
0.008920961990952492,
0.0004054438613820821,
0.027021605521440506,
0.023322902619838715,
-0.012475932016968727,
0.019509214907884598,
-0.019605036824941635,
-0.04354119673371315,
-0.04120315611362457,
-0.0434645377099514,
0.024721894413232803,
0.04538096487522125,
-0.005825934465974569,
0.004218532238155603,
-0.023303737863898277,
-0.06201554089784622,
0.02430027909576893,
-0.033518288284540176,
0.015484721399843693,
-0.028478087857365608,
0.005773232784122229,
0.05005704239010811,
-0.0017355631571263075,
-0.004838975146412849,
0.05864263325929642,
0.023533709347248077,
0.020199129357933998,
-0.008901798166334629,
0.038021888583898544,
-0.009634830988943577,
0.0910685583949089,
0.003959815017879009,
-0.016672905534505844,
-0.0321001335978508,
0.013635369949042797,
-0.02527765743434429,
-0.019815843552350998,
0.02002665027976036,
-0.090608611702919,
0.025162670761346817,
0.05753110349178314,
0.03085445612668991,
-0.009471935220062733,
-0.06734320521354675,
0.011546465568244457,
0.0006372116040438414,
0.04047491401433945,
-0.003832851769402623,
-0.017305325716733932,
0.037561945617198944,
-0.001395397586748004,
0.046530820429325104,
-0.017564043402671814,
-0.0021943075116723776,
0.046377506107091904,
0.07500890642404556,
0.0012899941066280007,
0.0223455261439085,
-0.0420847125351429,
0.01653875596821308,
-0.010597835294902325,
0.01882888376712799,
-0.08746567368507385,
0.08087316900491714,
-0.02744321897625923,
-0.023303737863898277,
0.0666532889008522,
-0.08593253791332245,
0.0215789545327425,
-0.04672246426343918,
-0.005279753357172012,
-0.010674492456018925,
0.046377506107091904,
0.0440777949988842,
0.012159721925854683,
-0.004132293164730072,
-0.056956175714731216,
0.0692596286535263,
-0.013654534704983234,
0.04196972772479057,
-0.002742884447798133,
0.025699270889163017,
-0.019125930964946747,
0.033537451177835464,
-0.009927085600793362,
0.004424548242241144,
0.01020496804267168,
0.07025617361068726,
-0.023457052186131477,
-0.0055959634482860565,
-0.02776901051402092,
-0.013664116151630878,
0.027634860947728157,
0.006338578648865223,
0.002315281890332699,
0.043886151164770126,
0.038481831550598145,
-0.052471742033958435,
0.06964291632175446,
-0.06718988716602325,
-0.04511266574263573,
0.04925214499235153,
0.010415774770081043,
-0.028823044151067734,
-0.03777275234460831,
0.020045815035700798,
0.03217678889632225,
0.033058345317840576,
-0.012399275787174702,
-0.03959335759282112,
0.009984578937292099,
0.03959335759282112,
-0.0061373538337647915,
-0.012073483318090439,
0.07263254374265671,
0.003772963536903262,
-0.006506265606731176,
-0.027021605521440506,
0.012849635444581509,
-0.029819587245583534,
0.07324579358100891,
0.007023700978606939,
-0.054963093250989914,
0.0050354087725281715,
0.0411648266017437,
-0.026044227182865143,
-0.03712116926908493,
-0.0035549700260162354,
0.0025344733148813248,
0.016998697072267532,
-0.05055531486868858,
-0.023629531264305115,
-0.005643874406814575,
-0.033920738846063614,
0.027883997187018394,
0.028037309646606445,
0.011335658840835094,
0.014976868405938148,
-0.015206838957965374,
0.023016273975372314,
-0.019039690494537354,
-0.011642287485301495,
0.023725351318717003,
-0.0011133236112073064,
-0.005912174005061388,
-0.02010330744087696,
0.010952373966574669,
0.015024778433144093,
0.032445091754198074,
-0.007775898091495037,
0.006520639173686504,
-0.024875206872820854,
0.04415445029735565,
0.005778023973107338,
-0.051015257835388184,
0.019662529230117798,
-0.0815630853176117,
0.0221922118216753,
0.05396655201911926,
-0.03955502808094025,
0.03349912539124489,
-0.0430045947432518,
0.02468356490135193,
0.008494557812809944,
0.028976358473300934,
0.005303708370774984,
0.056726206094026566,
-0.02297794632613659,
0.012130975723266602,
0.022211376577615738,
0.011671033687889576,
-0.05745444819331169,
-0.02962794341146946,
-0.04568759351968765,
-0.021674776449799538,
-0.0012432812945917249,
0.016136305406689644,
-0.020524920895695686,
-0.005706158000975847,
-0.005294126458466053,
0.07121438533067703,
-0.0067170727998018265,
-0.04748903214931488,
0.03574134409427643,
0.05971582978963852,
-0.028018146753311157,
-0.03466814383864403,
0.10057403147220612,
0.01481397170573473,
0.00694225262850523,
0.012245961464941502,
0.09574463963508606,
0.0342465303838253,
-0.019154677167534828,
0.054196521639823914,
-0.020064977928996086,
-0.015321824699640274,
0.03796439617872238,
-0.018963033333420753,
0.0001838571042753756,
0.015561377629637718,
-0.03309667482972145,
-0.016797471791505814,
-0.03869263827800751,
-0.009481516666710377,
-0.03967001661658287,
-0.011335658840835094,
-0.011278166435658932,
0.017334071919322014,
0.003957419190555811,
0.010319952853024006,
0.03219595551490784,
0.02288212440907955,
-0.02776901051402092,
-0.035607192665338516,
0.025411807000637054,
0.01198724377900362,
0.002682996215298772,
-0.07313080877065659,
-0.08010660111904144,
0.022307196632027626,
0.037006184458732605,
-0.05151352658867836,
-0.012638828717172146,
-0.01714242994785309,
-0.04794897511601448,
-0.007517180405557156,
-0.07627374678850174,
0.019279243424534798,
-0.01121109165251255,
-0.014612747356295586,
-0.04656914994120598,
0.007373448461294174,
0.00045185728231444955,
-0.0021871209610253572,
-0.017391564324498177,
0.0022050875704735518,
0.06347202509641647,
-0.000020698897060356103,
-0.023782845586538315,
0.037561945617198944,
0.03694869205355644,
-0.014536090195178986,
0.01623212732374668,
-0.008604751899838448,
0.004628168419003487,
0.051475197076797485,
-0.028823044151067734,
0.03480229526758194,
0.034687306731939316,
0.031448546797037125,
-0.0459175631403923,
0.02753903903067112,
-0.008844305761158466,
0.013932416215538979,
-0.01105777733027935,
0.0215022973716259,
-0.007052447181195021,
-0.024645237252116203,
0.03643125668168068,
0.04005330055952072,
0.020141635090112686,
-0.010914045386016369,
-0.014047401957213879,
0.010080399923026562,
0.0055336798541247845,
-0.05235675349831581,
-0.051705170422792435,
0.008293332532048225,
0.01928882673382759,
-0.007579464465379715,
-0.012657992541790009,
-0.006487101782113314,
-0.012974203564226627,
-0.0407048836350441,
0.0009749816381372511,
-0.01272506732493639,
-0.01928882673382759,
-0.00247458484955132,
0.015034360811114311,
-0.01855100318789482,
-0.022383853793144226,
0.006712281610816717,
-0.05653456225991249,
-0.07799853384494781,
0.04848557338118553,
0.060290757566690445,
0.02460690774023533,
-0.06718988716602325,
0.014986449852585793,
-0.022153882309794426,
0.0018074291292577982,
0.03779191896319389,
0.04308125376701355,
-0.024702729657292366,
-0.001395397586748004,
-0.01959545537829399,
-0.01101944874972105,
0.02397448755800724,
0.03420820087194443,
0.030145378783345222,
0.017698192968964577,
-0.042889609932899475,
-0.007177014835178852,
-0.04967375844717026,
-0.04998038709163666,
-0.00982168223708868,
0.00887784268707037,
0.000018350152458879165,
0.061747241765260696,
-0.02272881008684635,
0.016337530687451363,
0.0442311093211174,
0.028439760208129883,
-0.02945546619594097,
0.018780972808599472,
0.001969127682968974,
-0.02863140217959881,
-0.07688700407743454,
-0.022479675710201263,
0.03227261081337929,
-0.044576067477464676,
0.004707220941781998,
0.0423913411796093,
0.04771900549530983,
-0.015187675133347511,
-0.05668787658214569,
-0.07546885311603546,
0.03556886315345764,
0.03250258415937424,
0.0020086539443582296,
-0.0015582938212901354,
0.055116407573223114,
0.016749562695622444,
-0.0036196494475007057,
-0.0632803812623024,
0.02529682219028473,
0.0034447754733264446,
-0.03650791198015213,
-0.0017487385775893927,
-0.02715575508773327,
-0.06385531276464462,
-0.03796439617872238,
-0.05388989672064781,
-0.04495935142040253,
0.018637241795659065,
0.023322902619838715,
0.04718240350484848,
-0.035453878343105316,
0.019854171201586723,
0.018311448395252228,
0.051015257835388184,
-0.025335149839520454,
-0.006132562644779682,
-0.025699270889163017,
-0.02575676329433918,
0.015724273398518562,
-0.003260319586843252,
0.016682486981153488,
-0.05802937597036362,
0.029187165200710297,
-0.001860130811110139,
0.02460690774023533,
-0.023878665640950203,
0.05166684091091156,
0.0079100476577878,
0.0020110493060201406,
0.08777230232954025,
-0.0666532889008522,
0.010846970602869987,
-0.0634336993098259,
-0.003696306375786662,
-0.03790690377354622,
0.005768442060798407,
-0.020160799846053123,
0.019250497221946716,
0.01094279158860445,
-0.02606339193880558,
-0.022326361387968063,
0.05070862919092178,
0.008120854385197163,
-0.0031117964535951614,
-0.03277088329195976,
-0.002449431922286749,
0.017813177779316902,
-0.005730113480240107,
-0.0029417136684060097,
-0.03411237895488739,
0.0658867210149765,
0.004642541520297527,
0.02909134514629841,
0.04415445029735565,
0.007852555252611637,
0.05814436078071594,
0.022632990032434464,
-0.03982333093881607,
-0.036622896790504456,
0.0078717190772295,
-0.028133131563663483,
-0.02738572470843792,
-0.006185264326632023,
-0.06508181989192963,
-0.047987304627895355,
0.029877079650759697,
-0.021310655400156975,
-0.004889281466603279,
0.011479390785098076,
0.011996826156973839,
0.07730861753225327,
-0.0028578699566423893,
-0.002956087002530694,
-0.005370783619582653,
0.0016373463440686464,
0.050631970167160034,
-0.014746896922588348,
0.018225209787487984,
-0.057186149060726166,
-0.002164363395422697,
0.0215022973716259,
-0.025181835517287254,
0.023418724536895752,
0.05036367103457451,
0.03867347538471222,
0.06385531276464462,
-0.025737598538398743,
-0.017334071919322014,
-0.05377490818500519,
-0.047527361661195755,
0.021176505833864212,
-0.03888428211212158,
-0.036067135632038116,
0.05822101607918739,
-0.07596711814403534,
0.035377223044633865,
-0.051091913133859634,
0.00900720153003931,
-0.03254090994596481,
0.010195385664701462,
-0.018119806423783302,
-0.04534263536334038,
0.04925214499235153,
-0.008561632595956326,
0.004309562500566244,
-0.04012995585799217,
-0.005562426056712866,
0.03154436871409416,
-0.05457980930805206,
0.0015906334156170487,
-0.06193888559937477,
-0.013817430473864079,
0.03614379093050957,
0.007349492982029915,
0.023802008479833603,
-0.008322079665958881,
0.031601861119270325,
-0.05373658239841461,
-0.012169304303824902,
-0.03604796901345253,
0.014248626306653023,
0.0328667052090168,
0.0014540881384164095,
0.015024778433144093,
-0.0038687847554683685,
-0.03397823125123978,
0.011038612574338913,
0.009294665418565273,
0.023629531264305115,
0.008532886393368244,
0.016596248373389244,
0.0035070593003183603,
-0.052165113389492035,
0.044576067477464676,
-0.0060990252532064915,
0.03595215082168579,
-0.030298693105578423,
0.008092108182609081,
0.008413109928369522,
0.0002739890187513083,
0.05454147979617119,
-0.017918581143021584,
-0.01864682324230671,
0.05492476373910904,
0.027673188596963882,
0.004944378510117531,
0.047910645604133606,
-0.029282987117767334,
-0.03208097070455551,
-0.07343743741512299,
-0.016289619728922844,
0.013721609488129616,
0.061900556087493896,
-0.0407048836350441,
-0.002320073079317808,
0.02073572762310505,
0.015954244881868362,
0.04710574820637703
]
|
31,229 | networkx.generators.geometric | waxman_graph | Returns a Waxman random graph.
The Waxman random graph model places `n` nodes uniformly at random
in a rectangular domain. Each pair of nodes at distance `d` is
joined by an edge with probability
.. math::
p = \beta \exp(-d / \alpha L).
This function implements both Waxman models, using the `L` keyword
argument.
* Waxman-1: if `L` is not specified, it is set to be the maximum distance
between any pair of nodes.
* Waxman-2: if `L` is specified, the distance between a pair of nodes is
chosen uniformly at random from the interval `[0, L]`.
Parameters
----------
n : int or iterable
Number of nodes or iterable of nodes
beta: float
Model parameter
alpha: float
Model parameter
L : float, optional
Maximum distance between nodes. If not specified, the actual distance
is calculated.
domain : four-tuple of numbers, optional
Domain size, given as a tuple of the form `(x_min, y_min, x_max,
y_max)`.
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
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.
Returns
-------
Graph
A random Waxman graph, undirected and without self-loops. Each
node has a node attribute ``'pos'`` that stores the position of
that node in Euclidean space as generated by this function.
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.waxman_graph(10, 0.5, 0.1, metric=dist)
.. _taxicab metric: https://en.wikipedia.org/wiki/Taxicab_geometry
.. _Euclidean metric: https://en.wikipedia.org/wiki/Euclidean_distance
Notes
-----
Starting in NetworkX 2.0 the parameters alpha and beta align with their
usual roles in the probability distribution. In earlier versions their
positions in the expression were reversed. Their position in the calling
sequence reversed as well to minimize backward incompatibility.
References
----------
.. [1] B. M. Waxman, *Routing of multipoint connections*.
IEEE J. Select. Areas Commun. 6(9),(1988) 1617--1622.
| 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, beta=0.4, alpha=0.1, L=None, domain=(0, 0, 1, 1), metric=None, seed=None, *, pos_name='pos', backend=None, **backend_kwargs) | [
0.021800145506858826,
-0.03952118381857872,
0.009755228646099567,
-0.024917202070355415,
0.018221305683255196,
0.00953395664691925,
-0.06257200241088867,
-0.016941772773861885,
0.023416396230459213,
-0.02480175532400608,
0.0228776466101408,
0.08050468564033508,
0.01619137078523636,
0.02553291618824005,
-0.06014762446284294,
-0.02901555225253105,
-0.011842885985970497,
0.009870675392448902,
-0.010140050202608109,
-0.05506797879934311,
-0.026937514543533325,
-0.0013071909779682755,
0.048064224421978,
0.05787717550992966,
0.005459656938910484,
-0.03297921642661095,
-0.051373690366744995,
0.042715203016996384,
-0.02751474827528,
0.027899568900465965,
-0.04136832803487778,
-0.06395735591650009,
0.016393402591347694,
0.014729048125445843,
0.012756837531924248,
0.004798244684934616,
0.05510645732283592,
0.04317699000239372,
-0.06953726708889008,
-0.03852064535021782,
-0.010217014700174332,
-0.014401949942111969,
-0.024955684319138527,
-0.021376842632889748,
0.00726831890642643,
0.00953395664691925,
0.0676516443490982,
0.04698672145605087,
-0.04460082948207855,
-0.03276756405830383,
0.014507776126265526,
-0.00039504346204921603,
-0.00639765989035368,
-0.013536101207137108,
-0.029054034501314163,
-0.007879222743213177,
0.0016787843778729439,
-0.03145916759967804,
0.05187395587563515,
-0.03276756405830383,
0.03742390498518944,
0.0125163234770298,
0.04737154394388199,
-0.020472511649131775,
-0.039675112813711166,
-0.015508311800658703,
-0.050873421132564545,
-0.027726398780941963,
0.00006753169145667925,
0.0031819939613342285,
0.029785195365548134,
0.01815396174788475,
0.06368798017501831,
0.02539822831749916,
0.0014767530374228954,
0.01609516516327858,
0.06245655193924904,
-0.015989338979125023,
-0.01677822321653366,
-0.005733842495828867,
0.007104769349098206,
0.0003183797816745937,
0.023531842976808548,
-0.06149449944496155,
0.009918778203427792,
-0.024339968338608742,
0.014161436818540096,
0.047563955187797546,
0.056183960288763046,
-0.06711289286613464,
-0.018644608557224274,
0.014882977120578289,
0.021242154762148857,
0.0033768098801374435,
0.05468315631151199,
0.02035706490278244,
0.055144939571619034,
-0.0038025188259780407,
0.04617859795689583,
0.008129357360303402,
-0.0012212074361741543,
0.010457527823746204,
-0.07153834402561188,
0.04652493819594383,
-0.013536101207137108,
-0.03621171787381172,
-0.03823202848434448,
0.012641390785574913,
0.01118868961930275,
-0.0017268870724365115,
-0.04506261274218559,
-0.024724790826439857,
0.05056556314229965,
0.0028861623723059893,
0.04887234792113304,
-0.0017268870724365115,
-0.054721638560295105,
0.02168469876050949,
0.007619468495249748,
-0.010207394137978554,
0.023628048598766327,
0.003860242199152708,
-0.009620540775358677,
0.018375232815742493,
-0.007489591371268034,
0.02131911925971508,
0.04240734502673149,
-0.028765417635440826,
-0.01682632602751255,
-0.018634987995028496,
0.016576191410422325,
0.012208466418087482,
0.05391351133584976,
0.07134593278169632,
-0.03384506329894066,
0.0035283335018903017,
-0.05345172435045242,
0.010698041878640652,
0.06953726708889008,
-0.023320190608501434,
0.02930416725575924,
-0.09997666627168655,
0.009211667813360691,
0.019741350784897804,
0.03669274225831032,
0.009803331457078457,
-0.007773397024720907,
-0.03524966165423393,
0.0298429187387228,
-0.038443680852651596,
0.0351342149078846,
-0.05995521321892738,
0.05845440924167633,
-0.02095353789627552,
-0.003865052480250597,
-0.01820206455886364,
0.02884238213300705,
-0.048449043184518814,
-0.05980128422379494,
-0.028130462393164635,
0.017894206568598747,
0.006051320116966963,
0.018269406631588936,
0.016672397032380104,
-0.03625020012259483,
0.0039780936203897,
0.0712689682841301,
-0.068960040807724,
0.00978890061378479,
-0.0025157714262604713,
-0.05579913780093193,
-0.04494716599583626,
-0.01130413543432951,
0.0009458194253966212,
-0.04279216751456261,
0.033171623945236206,
-0.006585260387510061,
-0.012169984169304371,
-0.06257200241088867,
-0.02612938918173313,
-0.004355699755251408,
-0.034460779279470444,
-0.0008808808051981032,
0.010370943695306778,
-0.01815396174788475,
0.07350093126296997,
0.045832257717847824,
-0.01696101389825344,
-0.03043939173221588,
0.005652067717164755,
-0.05995521321892738,
-0.020049206912517548,
0.030208498239517212,
0.0420994870364666,
0.06137905269861221,
0.0007594214403070509,
0.03261363506317139,
0.033402517437934875,
-0.11475381255149841,
0.08581522852182388,
0.06834432482719421,
0.006484244484454393,
0.018086617812514305,
-0.0386168509721756,
-0.010621077381074429,
-0.023897424340248108,
-0.024955684319138527,
-0.005161420442163944,
0.039675112813711166,
0.017547866329550743,
0.01687442883849144,
-0.001955375075340271,
0.015392865985631943,
0.045139577239751816,
-0.02857300639152527,
-0.00017587550973985344,
-0.018442576751112938,
0.012824181467294693,
-0.04787181317806244,
-0.04348484426736832,
-0.03461470827460289,
0.014613602310419083,
-0.01650884933769703,
-0.011284894309937954,
0.054490745067596436,
0.01531590148806572,
0.007229836657643318,
-0.03644261136651039,
0.0363079234957695,
-0.05753083527088165,
0.09127969294786453,
-0.05029618740081787,
0.06107119470834732,
-0.02824590913951397,
-0.022204209119081497,
-0.04529350623488426,
0.01419029850512743,
0.0007630291511304677,
-0.0021417730022221804,
0.02076112851500511,
-0.00462988531216979,
-0.04648645594716072,
-0.05345172435045242,
0.030189257115125656,
0.049718957394361496,
-0.0130935562774539,
-0.005166230723261833,
-0.020664922893047333,
0.08450683206319809,
-0.0011039570672437549,
-0.0576847642660141,
-0.05225877836346626,
-0.012968488968908787,
-0.013218623585999012,
0.023127781227231026,
-0.029092516750097275,
-0.004035816993564367,
-0.03099738247692585,
0.020895814523100853,
0.020780367776751518,
-0.02366653084754944,
0.0024231737479567528,
-0.034961044788360596,
0.04614011570811272,
0.03474939614534378,
-0.016893669962882996,
-0.05364413559436798,
0.047025203704833984,
-0.021626975387334824,
-0.04113743454217911,
-0.051335208117961884,
0.011044381186366081,
0.06407280266284943,
-0.0022031038533896208,
0.043715737760066986,
-0.0386168509721756,
0.010582595132291317,
0.04664038121700287,
0.03311390057206154,
0.012429739348590374,
-0.04717913269996643,
0.013584204018115997,
0.02218496799468994,
-0.00891824159771204,
-0.05572217330336571,
0.06688199937343597,
-0.08065861463546753,
0.013218623585999012,
0.012737596407532692,
-0.05129672586917877,
-0.044216006994247437,
-0.01613364741206169,
-0.027533989399671555,
0.007859981618821621,
0.022492824122309685,
0.016345299780368805,
0.02718764916062355,
-0.012237328104674816,
0.012785699218511581,
-0.031940195709466934,
0.13222472369670868,
-0.019933760166168213,
0.044446900486946106,
-0.05002681165933609,
0.053297799080610275,
0.050604045391082764,
0.012391257099807262,
-0.01912563480436802,
-0.04760243743658066,
0.025071129202842712,
-0.037077564746141434,
-0.018086617812514305,
0.041984040290117264,
0.012179604731500149,
0.025667604058980942,
-0.10736523568630219,
0.023781977593898773,
-0.06576602160930634,
0.023493360728025436,
-0.007479970809072256,
-0.007042236160486937,
0.0029318598099052906,
-0.047294579446315765,
0.035057250410318375,
-0.06942182779312134,
-0.042291898280382156,
0.021934833377599716,
0.03990600258111954,
-0.004187340382486582,
-0.002444820012897253,
-0.025340504944324493,
0.053028423339128494,
0.017547866329550743,
-0.010967416688799858,
-0.05287449434399605,
0.07811879366636276,
0.05572217330336571,
0.029919883236289024,
-0.015421727672219276,
-0.05818503350019455,
0.005575103685259819,
-0.03080497309565544,
0.016576191410422325,
0.05845440924167633,
-0.016114406287670135,
-0.01501766499131918,
0.0023967172019183636,
-0.023127781227231026,
-0.0012163971550762653,
-0.05214333161711693,
0.075925312936306,
0.03746238723397255,
-0.03269059956073761,
0.01444043219089508,
0.026879791170358658,
-0.0018675875617191195,
0.015440968796610832,
0.03249818831682205,
-0.0039059396367520094,
0.07049932330846786,
-0.01419029850512743,
-0.006489054765552282,
0.04306154325604439,
0.016306817531585693,
0.02218496799468994,
0.03925180807709694,
0.02131911925971508,
0.06303378194570541,
-0.005055594258010387,
-0.021068984642624855,
0.01031322032213211,
-0.08373718708753586,
-0.11590828001499176,
0.01747090183198452,
0.02668738178908825,
-0.018596505746245384,
-0.03305618092417717,
-0.01240087766200304,
-0.002479694550856948,
0.03659653663635254,
-0.014940700493752956,
0.006003217771649361,
0.0319979190826416,
0.009947639890015125,
-0.014844494871795177,
-0.01162161398679018,
0.037019841372966766,
0.05452922731637955,
0.013372551649808884,
-0.026706621050834656,
-0.05529886856675148,
-0.043446362018585205,
0.0507194921374321,
0.055183421820402145,
0.006782481446862221,
0.04744850844144821,
0.06484244763851166,
0.03636564686894417,
-0.07330852001905441,
-0.0029222392477095127,
0.014729048125445843,
-0.025109611451625824,
-0.017711415886878967,
-0.052066367119550705,
-0.020029965788125992,
-0.005733842495828867,
-0.015373624861240387,
-0.012631770223379135,
0.05506797879934311,
0.01087121106684208,
0.02797653339803219,
0.014248020946979523,
0.011159827932715416,
0.0009277809294871986,
0.025071129202842712,
-0.03486483916640282,
-0.00445912079885602,
0.05245118960738182,
0.004427853971719742,
-0.026418006047606468,
0.04067564755678177,
-0.08073557913303375,
0.02678358554840088,
0.00869215838611126,
0.0039756884798407555,
0.02081885002553463,
0.008644056506454945,
-0.0354805551469326,
-0.006974892225116491,
0.051604583859443665,
-0.020395547151565552,
0.005743463058024645,
0.002313740085810423,
0.026033183559775352,
0.03852064535021782,
-0.042253416031599045,
-0.017894206568598747,
-0.015787307173013687,
-0.0494110994040966,
-0.02085733227431774,
0.029881400987505913,
0.0096975052729249,
0.029188722372055054,
-0.04171466454863548,
0.0060753715224564075,
-0.003954042214900255,
0.0039083450101315975,
0.010322840884327888,
0.00838911160826683,
-0.007263508625328541,
0.05860833451151848,
0.00639765989035368,
0.07684887945652008,
0.04771788418292999,
-0.04629404470324516,
0.06291833519935608,
-0.034268368035554886,
0.013690030202269554,
-0.03130524232983589,
0.004718875512480736,
0.035153456032276154,
0.007869602181017399,
-0.06468851864337921,
-0.01847143843770027,
0.006234110798686743,
-0.020645681768655777,
-0.0005168034113012254,
-0.0018267002888023853,
0.00669589638710022,
-0.001219403580762446,
0.08350629359483719,
-0.01125603262335062,
-0.03659653663635254,
-0.044639311730861664,
0.01911601424217224,
0.015643000602722168,
-0.07834968715906143,
0.04810270667076111,
0.005267246160656214,
-0.030824214220046997,
0.02218496799468994,
-0.007234646938741207,
0.03063180297613144,
-0.0008935077348724008,
-0.03394126892089844,
-0.04190707579255104,
-0.007571365684270859,
0.008129357360303402,
0.028188185766339302,
-0.06191780045628548,
-0.031286001205444336,
-0.004615454468876123,
0.04987288638949394,
0.008018720895051956,
-0.023089298978447914,
0.028419077396392822,
-0.014286503195762634,
-0.025340504944324493,
0.03832823410630226,
-0.010390183888375759,
-0.020972779020667076,
0.028630729764699936,
0.0005832453025504947,
0.021338360384106636,
0.0649963766336441,
-0.04317699000239372,
0.07203861325979233,
0.01221808698028326,
0.029496578499674797,
0.04525502398610115,
0.05310538783669472,
0.05826199799776077,
0.055683691054582596,
0.013699650764465332,
0.007152872160077095,
0.0008694563875906169,
-0.018086617812514305,
0.023416396230459213,
-0.013266726396977901,
-0.048487525433301926,
0.048487525433301926,
0.06819039583206177,
0.005983976647257805,
0.01995300129055977,
0.013593824580311775,
-0.015238936990499496,
0.04090654104948044,
-0.04425448924303055,
0.011217551305890083,
0.03736618161201477,
0.033267829567193985,
0.009721556678414345,
-0.06087878346443176,
0.0149214593693614,
-0.011842885985970497,
0.028919346630573273,
-0.021800145506858826,
0.0035379540640860796,
-0.02864997088909149,
-0.03809734433889389,
0.008215942420065403,
-0.0053826929070055485,
0.013911302201449871,
0.020299341529607773,
0.030612561851739883,
0.047256097197532654,
0.030227739363908768,
-0.02205028012394905,
-0.04902627691626549,
-0.03925180807709694,
0.07184620201587677,
-0.0015561225591227412,
-0.08927862346172333,
-0.05918556824326515,
0.09697505086660385,
-0.024243762716650963,
0.008100495673716068,
-0.03494180366396904,
-0.00003402890433790162,
0.04194555804133415,
-0.045639846473932266,
-0.06769012659788132,
-0.016624294221401215,
-0.004110376350581646,
-0.03232501819729805,
-0.016393402591347694,
-0.04356180876493454,
0.04140681028366089,
-0.030747249722480774,
0.009500284679234028,
0.039405737072229385,
0.03153613209724426,
0.02031858265399933,
-0.02659117616713047,
0.015354383736848831,
-0.006296643987298012,
-0.042022522538900375,
0.006503485608845949,
-0.017942309379577637,
-0.019654765725135803,
-0.015306280925869942,
0.00019631916075013578,
0.03228653594851494,
0.00848531723022461,
-0.023320190608501434,
0.04113743454217911,
-0.05818503350019455,
0.031286001205444336,
0.006994133349508047,
0.03132448345422745,
0.053528688848018646,
0.000047313518734881654,
0.04552439972758293,
-0.0190679132938385,
-0.03040090948343277,
0.015373624861240387,
0.007455919403582811,
0.014161436818540096,
-0.0005119931884109974,
-0.030920419842004776,
-0.02678358554840088,
0.03040090948343277,
-0.028457559645175934,
0.0036485902965068817,
-0.04313850775361061,
0.0074607296846807,
0.014988803304731846,
-0.030920419842004776,
0.0296697486191988,
-0.05583762004971504,
-0.029227204620838165,
-0.0024676688481122255,
-0.0333063118159771,
-0.026975996792316437,
-0.011640855111181736,
0.00032018363708630204,
-0.06934486329555511,
0.06518878787755966,
0.018634987995028496,
-0.02595621906220913,
-0.02811122126877308,
-0.010380564257502556,
0.06053244322538376,
-0.0071961646899580956,
0.02691827341914177,
-0.04336939752101898,
-0.014430811628699303,
-0.04259975627064705,
-0.04852600768208504,
0.04306154325604439,
-0.03344099968671799,
-0.04767940193414688,
-0.0114388233050704,
-0.027861086651682854,
-0.07473236322402954,
-0.024878719821572304,
0.014700186438858509,
-0.030016088858246803,
-0.00382897537201643,
0.01604706235229969,
-0.047794848680496216,
0.027707157656550407,
-0.04221493378281593,
-0.04983440414071083,
-0.011563890613615513,
-0.020895814523100853,
0.028034256771206856,
0.02407059445977211,
0.009389648213982582,
-0.0679595023393631,
-0.04017537832260132,
0.018173202872276306,
0.013016591779887676,
-0.017644071951508522,
0.028207426890730858,
0.017990412190556526,
-0.022300414741039276,
-0.008129357360303402,
0.02008768916130066,
-0.02178090438246727,
0.014517396688461304,
0.051796991378068924,
0.047563955187797546,
0.05726145952939987,
-0.02168469876050949,
0.03103586472570896,
0.0285152830183506,
-0.03432609140872955,
0.037847209721803665,
0.00031266757287085056,
-0.018509920686483383,
-0.013766994699835777,
0.043446362018585205,
0.00011469488526927307,
-0.008595953695476055,
0.019933760166168213,
-0.00809087511152029,
0.028496041893959045,
-0.06476548314094543,
-0.02393590658903122,
0.10567202419042587,
0.029650507494807243,
-0.03369113430380821,
-0.019096773117780685,
0.05291297659277916,
0.05479860305786133,
-0.03815506398677826,
-0.05291297659277916,
0.032074883580207825,
0.05845440924167633,
-0.01240087766200304,
0.031151311472058296,
0.06395735591650009,
0.03726997599005699,
0.037385422736406326,
-0.004358104895800352,
-0.04267672076821327,
0.007210595533251762,
0.0351342149078846,
-0.037077564746141434,
0.036981359124183655,
-0.012853043153882027,
-0.04567832872271538,
0.059724319726228714,
-0.02462858520448208,
-0.02264675311744213,
-0.021338360384106636,
0.02397438883781433,
0.020876573398709297,
-0.01004384458065033,
-0.07138441503047943,
-0.013911302201449871,
0.030516356229782104,
-0.040059931576251984,
-0.04960351064801216,
0.03195943683385849,
0.014498155564069748,
-0.003032875480130315,
-0.05460619181394577,
-0.05987824872136116,
0.0018639798508957028,
0.0017557487590238452,
-0.04402359575033188,
0.034653190523386,
-0.017528625205159187,
0.00382897537201643,
0.035692207515239716,
-0.11652399599552155,
-0.0036774517502635717,
-0.013641927391290665,
0.014892597682774067,
0.040098413825035095,
-0.011332997120916843,
0.01691291108727455,
0.00717692356556654,
0.012708734720945358,
-0.01462322287261486,
0.03703908249735832,
-0.04629404470324516,
0.047756366431713104,
-0.01714380457997322,
0.02778412215411663,
-0.03777024522423744,
-0.040598683059215546,
0.009938019327819347,
-0.019462354481220245,
0.0037015031557530165,
-0.009182806126773357,
0.005098886787891388,
0.025609880685806274,
0.025513675063848495,
0.0245323795825243,
0.031940195709466934,
-0.0032469325233250856,
-0.018740814179182053,
0.060416996479034424,
-0.030939660966396332,
-0.045331988483667374,
-0.025417469441890717,
-0.03646184876561165,
-0.04233038052916527,
-0.015258178114891052,
-0.017240010201931,
0.0019758185371756554,
-0.03292149305343628,
0.033267829567193985,
0.005502949468791485,
0.05095038563013077
]
|
31,235 | networkx.generators.classic | wheel_graph | Return the wheel graph
The wheel graph consists of a hub node connected to a cycle of (n-1) nodes.
.. plot::
>>> nx.draw(nx.wheel_graph(5))
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.
Node labels are the integers 0 to n - 1.
| 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.022164342924952507,
-0.0068553173914551735,
0.021755864843726158,
-0.05026048794388771,
-0.012653921730816364,
0.06674166768789291,
-0.04756098613142967,
0.007428073789924383,
-0.0007431404083035886,
0.005110408179461956,
0.004138054326176643,
0.06251481175422668,
0.016916295513510704,
0.07608336955308914,
0.027012791484594345,
-0.007667832542210817,
0.014838388189673424,
0.011819206178188324,
-0.02289249747991562,
0.03793512284755707,
-0.019802276045084,
0.015158065594732761,
0.03429434821009636,
0.013897113502025604,
-0.020885629579424858,
0.011970165185630322,
0.02228866145014763,
0.032447319477796555,
-0.03736680746078491,
0.027350230142474174,
0.033193234354257584,
-0.01208560448139906,
0.0011654928093776107,
0.018399246037006378,
0.020708031952381134,
0.042375095188617706,
-0.02147170715034008,
0.05310206860303879,
-0.10449919104576111,
-0.015717502683401108,
0.046353310346603394,
-0.005860763601958752,
0.014829508028924465,
-0.032980114221572876,
0.012138884514570236,
0.02845134399831295,
0.08347148448228836,
0.004497691988945007,
-0.06883732974529266,
-0.017591170966625214,
0.04280133545398712,
0.0043023331090807915,
-0.04322757199406624,
-0.05839451774954796,
-0.0018692284356802702,
0.010078737512230873,
-0.007525753229856491,
-0.012307603843510151,
0.05953114852309227,
-0.039959751069545746,
0.033583950251340866,
0.032109878957271576,
0.006247041281312704,
-0.023531854152679443,
-0.05622781068086624,
-0.021791385486721992,
-0.03885863721370697,
-0.061378177255392075,
-0.014287831261754036,
-0.018967561423778534,
0.05402558296918869,
0.04148710146546364,
0.03012077324092388,
-0.00959034077823162,
0.01288480032235384,
0.026426715776324272,
0.036478813737630844,
0.010815773159265518,
-0.010504974983632565,
-0.009048664011061192,
-0.022785939276218414,
-0.03631897270679474,
0.0219512227922678,
-0.048093780875205994,
0.04624675214290619,
0.09831874817609787,
-0.019677957519888878,
0.02100994996726513,
-0.044648364186286926,
-0.023922571912407875,
-0.02443760819733143,
-0.027811987325549126,
-0.026124797761440277,
0.005501125939190388,
-0.012724961154162884,
0.01598390005528927,
0.05026048794388771,
-0.09249350428581238,
0.012396402657032013,
-0.0009440491558052599,
-0.03747336566448212,
-0.033317554742097855,
-0.08858633041381836,
-0.021897943690419197,
-0.05665404722094536,
-0.03138172626495361,
-0.025343362241983414,
0.056867167353630066,
-0.01316007785499096,
0.028540141880512238,
-0.019091881811618805,
0.017466850578784943,
0.06613782793283463,
-0.013719514943659306,
0.02973005548119545,
0.04265925660729408,
-0.01818612776696682,
0.03871655836701393,
0.06532087177038193,
-0.02301681786775589,
-0.05850107595324516,
0.044186607003211975,
-0.04031495004892349,
0.029765574261546135,
0.02683519385755062,
-0.00038960756501182914,
0.04454180225729942,
-0.05317310988903046,
0.030209572985768318,
0.021098749712109566,
-0.001577300252392888,
0.018967561423778534,
-0.0009540390456095338,
0.06826901435852051,
-0.035324420779943466,
0.013204477727413177,
-0.07892494648694992,
-0.028433583676815033,
-0.001253182184882462,
-0.014332231134176254,
0.033868107944726944,
-0.03417002782225609,
0.038752079010009766,
0.04958561062812805,
-0.060703303664922714,
0.015495503321290016,
0.018772203475236893,
0.01919844001531601,
0.013302157633006573,
-0.014483190141618252,
0.023656172677874565,
0.002056817291304469,
0.09533508867025375,
0.030706848949193954,
-0.02207554318010807,
-0.018399246037006378,
0.027066072449088097,
-0.022324182093143463,
-0.012112244963645935,
0.029836613684892654,
-0.007499113213270903,
0.01190800592303276,
0.03985319286584854,
-0.016605496406555176,
-0.07622544467449188,
-0.003383259056136012,
-0.006295880768448114,
-0.004331192933022976,
0.006548959296196699,
-0.027030551806092262,
-0.04166470095515251,
-0.000902979401871562,
0.0012576221488416195,
-0.056014690548181534,
-0.0045598517172038555,
-0.002096777083352208,
-0.03081340901553631,
-0.011135450564324856,
-0.017235971987247467,
-0.025876158848404884,
0.02973005548119545,
-0.07064884155988693,
0.029090698808431625,
-0.041771259158849716,
-0.012032325379550457,
0.01767997071146965,
0.009936658665537834,
0.014083592221140862,
0.029143979772925377,
0.0336194708943367,
0.046672988682985306,
0.02504144422709942,
-0.012902559712529182,
0.055943652987480164,
0.0228747371584177,
-0.05839451774954796,
0.06986740231513977,
0.036194656044244766,
-0.07231827080249786,
0.0551622174680233,
0.07743311673402786,
0.07132371515035629,
0.020441632717847824,
-0.010433935560286045,
0.048484500497579575,
-0.000602171232458204,
-0.05132608115673065,
-0.04816482216119766,
-0.05175231769680977,
0.028699981048703194,
-0.008014149963855743,
0.019713478162884712,
0.03793512284755707,
0.04450628161430359,
-0.06485911458730698,
0.0696898102760315,
0.039036236703395844,
0.03175468370318413,
0.010087617672979832,
-0.06112954020500183,
-0.035200100392103195,
-0.015708621591329575,
0.003199000144377351,
0.034258827567100525,
-0.008471467532217503,
-0.005723124369978905,
-0.008404867723584175,
-0.016774216666817665,
-0.004626451060175896,
-0.06269241124391556,
0.02649775519967079,
-0.02658655494451523,
0.044257644563913345,
-0.015291265211999416,
0.01252072211354971,
-0.015246865339577198,
0.03349515050649643,
-0.011623847298324108,
-0.042304057627916336,
0.03239404037594795,
-0.055126696825027466,
-0.019429318606853485,
0.007388113997876644,
-0.009315062314271927,
-0.013808313757181168,
0.07970638573169708,
-0.010425055399537086,
0.03141724318265915,
0.002481944626197219,
-0.011623847298324108,
-0.004442192614078522,
-0.019091881811618805,
0.012831520289182663,
-0.03093772754073143,
0.01891428232192993,
0.030547009781003,
-0.05697372555732727,
-0.007325954269617796,
0.01513142604380846,
0.04269477352499962,
-0.027598869055509567,
-0.008817785419523716,
-0.05800379812717438,
-0.028362544253468513,
0.06173337623476982,
0.018097328022122383,
-0.06869525462388992,
0.05281791090965271,
-0.05953114852309227,
-0.028611181303858757,
0.05711580440402031,
0.08141133189201355,
0.10535166412591934,
0.004497691988945007,
0.012769361026585102,
-0.05605021119117737,
0.0025108044501394033,
0.03981767222285271,
-0.042907893657684326,
-0.03163036331534386,
-0.05388350412249565,
-0.037153687328100204,
-0.011721527203917503,
0.04280133545398712,
0.02536112256348133,
0.03239404037594795,
0.05001185089349747,
-0.0039981952868402,
0.02562751993536949,
-0.02878878079354763,
0.019748996943235397,
-0.014758468605577946,
-0.036798492074012756,
-0.0030902207363396883,
0.03052924945950508,
0.020228514447808266,
-0.026551034301519394,
0.015282385051250458,
0.002319885650649667,
0.0524982325732708,
0.09412741661071777,
-0.05310206860303879,
0.03662089258432388,
0.022519540041685104,
0.04535875841975212,
0.02697727270424366,
0.00039182757609523833,
0.010442814789712429,
0.012778240256011486,
0.014705188572406769,
-0.054451823234558105,
0.014323350973427296,
0.004968329332768917,
0.009359462186694145,
-0.010504974983632565,
-0.0586431547999382,
-0.02047715336084366,
-0.021453946828842163,
0.0379706434905529,
0.038219284266233444,
0.019162921234965324,
0.005279127042740583,
-0.0526047945022583,
0.021294107660651207,
-0.05242719501256943,
0.053386230021715164,
-0.010043217800557613,
0.05711580440402031,
-0.04919489473104477,
0.021027708426117897,
0.01905636116862297,
-0.019482599571347237,
-0.031062046065926552,
0.03543097898364067,
-0.07199859619140625,
0.03551977872848511,
0.013897113502025604,
-0.03255387768149376,
-0.015539903193712234,
-0.051112961024045944,
0.02973005548119545,
0.010593773797154427,
-0.015531023032963276,
0.00697963684797287,
-0.03012077324092388,
0.03864552080631256,
0.046957146376371384,
-0.09348805993795395,
-0.0378640852868557,
-0.02678191289305687,
0.03159484267234802,
0.07871183007955551,
-0.026266876608133316,
-0.029818855226039886,
0.04020839184522629,
0.0664219856262207,
0.005363486707210541,
0.012352002784609795,
-0.06411319971084595,
-0.010655933991074562,
-0.003676297143101692,
0.003603037679567933,
0.06219513341784477,
-0.009838978759944439,
-0.005780844017863274,
0.02106322906911373,
-0.013612955808639526,
0.0868813768029213,
0.011659367941319942,
-0.006486799567937851,
-0.02415345050394535,
-0.07359698414802551,
-0.0768648013472557,
0.05033152550458908,
-0.005860763601958752,
0.05413214489817619,
-0.015388944186270237,
-0.03180796280503273,
0.0271726306527853,
-0.001798188779503107,
-0.04194885864853859,
-0.019766757264733315,
0.042517174035310745,
0.006877517327666283,
0.026426715776324272,
-0.00005019249874749221,
0.041167423129081726,
0.019358279183506966,
-0.04269477352499962,
-0.027563348412513733,
-0.05363486707210541,
-0.0464598722755909,
0.06230169162154198,
-0.0048795295879244804,
-0.0293215773999691,
0.0021911263465881348,
0.09561924636363983,
0.0491238534450531,
-0.05288895219564438,
0.017404692247509956,
0.0517878383398056,
-0.045607395470142365,
0.025556480512022972,
0.002586283953860402,
-0.004764090292155743,
-0.037011608481407166,
0.010620414279401302,
-0.009989937767386436,
-0.02617807686328888,
-0.026622073724865913,
0.020050914958119392,
-0.07871183007955551,
-0.030422691255807877,
-0.00042984483297914267,
0.0715368390083313,
0.006202641408890486,
0.010345135815441608,
0.0009568140376359224,
0.029410377144813538,
0.004666410852223635,
0.02388705126941204,
-0.0938432589173317,
-0.015193585306406021,
0.09682691842317581,
0.05310206860303879,
-0.05068672448396683,
0.028007345274090767,
-0.016321338713169098,
-0.012005685828626156,
0.07263794541358948,
0.03420554846525192,
-0.023780493065714836,
0.035999298095703125,
0.006708798464387655,
0.0073348344303667545,
-0.06159129738807678,
0.025378882884979248,
0.006144921761006117,
-0.0017426891718059778,
0.0013453116407617927,
0.030955487862229347,
-0.005301326978951693,
0.018612364307045937,
-0.021027708426117897,
-0.002612923737615347,
-0.01579742133617401,
0.03825480118393898,
0.034720584750175476,
-0.002313225530087948,
-0.03395690768957138,
-0.006695478223264217,
-0.03147052600979805,
0.052249595522880554,
0.0003196780162397772,
-0.038752079010009766,
-0.007707791868597269,
0.019020842388272285,
-0.04571395739912987,
-0.05967322736978531,
0.04713474586606026,
-0.010851292870938778,
0.02685295231640339,
-0.020885629579424858,
0.021862424910068512,
-0.016747575253248215,
-0.042375095188617706,
0.02806062623858452,
-0.005807484034448862,
-0.041167423129081726,
-0.07054228335618973,
0.024455368518829346,
0.013115678913891315,
-0.03896519914269447,
-0.030991006642580032,
0.03811272233724594,
-0.03480938449501991,
-0.02637343667447567,
-0.04663747176527977,
-0.00031218555523082614,
-0.030848927795886993,
-0.06073882430791855,
0.015388944186270237,
-0.01022969651967287,
0.03953351452946663,
-0.04713474586606026,
-0.023780493065714836,
0.023194415494799614,
-0.04752546548843384,
0.001880328287370503,
-0.03543097898364067,
-0.0030880006961524487,
-0.022626100108027458,
-0.01522910501807928,
0.0159927811473608,
-0.030618049204349518,
0.07086195796728134,
-0.017466850578784943,
-0.03839688003063202,
-0.0019324979512020946,
-0.009235142730176449,
0.019233960658311844,
-0.002114536939188838,
-0.02200450375676155,
0.014900547452270985,
0.0069352369755506516,
0.05811036005616188,
-0.0065933591686189175,
-0.012875920161604881,
0.008227269165217876,
0.04280133545398712,
0.03914279490709305,
0.03857447952032089,
0.02456192672252655,
0.04201989993453026,
-0.022626100108027458,
0.008005269803106785,
-0.021720344200730324,
-0.007801031693816185,
0.043192051351070404,
-0.05732892453670502,
0.041238464415073395,
0.03818376362323761,
0.009785698726773262,
0.041913338005542755,
-0.02530784346163273,
-0.00595400296151638,
0.03846792131662369,
-0.02663983404636383,
0.016241418197751045,
-0.0006193761364556849,
0.022448500618338585,
0.06173337623476982,
-0.039426956325769424,
0.0107713732868433,
-0.041380543261766434,
-0.0808430165052414,
0.03468506410717964,
0.046744029968976974,
0.008160669356584549,
-0.020352832973003387,
0.0026950633618980646,
-0.0022577259223908186,
-0.011126570403575897,
0.0019402679754421115,
0.001155502861365676,
0.02965901605784893,
0.006087202113121748,
-0.06748758256435394,
0.026337916031479836,
-0.05963771045207977,
0.034258827567100525,
-0.0038916359189897776,
0.007436953950673342,
0.00652675935998559,
0.08368460088968277,
-0.006087202113121748,
0.008023030124604702,
-0.026870712637901306,
0.004140274133533239,
0.032447319477796555,
-0.06219513341784477,
0.0064557199366390705,
-0.0017116093076765537,
-0.02958797663450241,
0.018683403730392456,
0.00002983106423926074,
0.008724546059966087,
-0.023070096969604492,
0.02470400556921959,
0.007539073005318642,
-0.0056609646417200565,
0.06429079920053482,
0.089651919901371,
-0.009235142730176449,
-0.016054939478635788,
-0.007206075359135866,
-0.04269477352499962,
-0.0047818501479923725,
-0.03967559337615967,
-0.017955249175429344,
-0.020299553871154785,
-0.019677957519888878,
0.0025929438415914774,
0.0005849663866683841,
-0.002644003601744771,
0.063864566385746,
-0.09434053301811218,
-0.004617571365088224,
-0.017910849303007126,
0.01567310281097889,
0.04507460072636604,
-0.056867167353630066,
0.06429079920053482,
0.03349515050649643,
-0.04376036673784256,
0.010726973414421082,
-0.020121954381465912,
-0.0456429161131382,
0.026462236419320107,
0.005945123266428709,
-0.046815067529678345,
0.08858633041381836,
-0.020885629579424858,
0.03282027691602707,
0.06219513341784477,
0.042907893657684326,
0.03166588395833969,
-0.016028299927711487,
-0.01630357839167118,
-0.084537073969841,
-0.006087202113121748,
0.05381246656179428,
-0.020992189645767212,
-0.048697616904973984,
-0.050224967300891876,
0.012778240256011486,
-0.02866446226835251,
0.05200095847249031,
-0.0653919130563736,
-0.029978694394230843,
-0.015859581530094147,
0.035324420779943466,
-0.015193585306406021,
-0.007778831757605076,
-0.028966380283236504,
0.001204342464916408,
0.018470285460352898,
-0.02898414060473442,
0.0013497516047209501,
0.00411807419732213,
0.010682573541998863,
-0.05487805977463722,
-0.022999057546257973,
-0.034596264362335205,
-0.011535048484802246,
-0.007543513085693121,
0.009377221576869488,
-0.027563348412513733,
0.003856115974485874,
0.09632964432239532,
-0.04301445186138153,
0.008329388685524464,
-0.029090698808431625,
-0.02630239725112915,
-0.0038117163348942995,
-0.03115084581077099,
0.018683403730392456,
-0.036478813737630844,
-0.006548959296196699,
-0.02818494476377964,
-0.03914279490709305,
-0.0029170617926865816,
0.01767997071146965,
0.018843242898583412,
0.04269477352499962,
0.03736680746078491,
-0.03477386385202408,
-0.06240825355052948,
0.005390126723796129,
-0.06169785559177399,
0.05388350412249565,
-0.015610942617058754,
0.02980109490454197,
0.06155577674508095,
0.0011943526333197951,
0.061094019562006,
-0.003642997471615672,
-0.06155577674508095,
0.005980642978101969,
-0.00041485991096124053,
0.0046575311571359634,
0.008111829869449139,
0.038290321826934814,
-0.016916295513510704,
-0.05509117618203163,
-0.01506038662046194,
-0.014900547452270985,
0.028167184442281723,
-0.04468388110399246,
-0.009785698726773262,
0.009466021321713924,
-0.009172982536256313,
0.03287355601787567,
-0.02436656877398491,
-0.01992659643292427,
-0.01784868910908699,
-0.04095430672168732,
-0.05200095847249031,
0.018701164051890373,
0.011170970275998116,
-0.017546771094202995,
0.028238223865628242,
0.010753612965345383,
0.01627693884074688,
-0.019482599571347237,
0.014838388189673424,
-0.015948381274938583,
0.0271726306527853,
0.004233513493090868,
-0.05072224512696266,
0.03669193014502525,
-0.0014108011964708567,
-0.009341701865196228,
0.03775752708315849,
0.01751125045120716,
0.022803697735071182,
-0.034134507179260254,
0.012183284386992455,
-0.0413450226187706,
0.035732898861169815,
-0.07128819823265076,
-0.02322993613779545,
0.004249053541570902,
0.021791385486721992,
-0.08730761706829071,
0.0051814476028084755,
0.029818855226039886,
0.005225847475230694,
-0.05189439654350281,
-0.0014674108242616057,
0.0336194708943367,
-0.0473833866417408,
-0.0258939191699028,
0.051112961024045944,
-0.035999298095703125,
0.009048664011061192,
-0.03214539960026741,
-0.037082649767398834,
-0.04212645813822746,
-0.02951693721115589,
-0.02106322906911373,
0.030387170612812042,
0.01190800592303276,
-0.016090460121631622,
0.01891428232192993,
-0.0016660996479913592,
0.020903389900922775,
0.02758110873401165,
-0.016605496406555176,
-0.016703175380825996,
0.0029881014488637447,
-0.02147170715034008,
-0.06649302691221237,
-0.020903389900922775,
-0.016703175380825996,
-0.014500949531793594,
0.008302748203277588,
-0.018470285460352898,
0.0011743727372959256,
0.029215019196271896,
0.041309501975774765,
-0.0027372429613023996,
0.008933224715292454,
0.026533275842666626,
-0.044790443032979965,
-0.02401137165725231,
0.0152735048905015,
-0.005549965426325798,
-0.01784868910908699,
-0.043511729687452316,
-0.022768178954720497,
0.028344783931970596,
0.0639711245894432,
-0.011028891429305077,
-0.04514563828706741,
0.0033188792876899242,
0.0457494743168354,
-0.0030902207363396883
]
|
31,238 | networkx.generators.community | windmill_graph | Generate a windmill graph.
A windmill graph is a graph of `n` cliques each of size `k` that are all
joined at one node.
It can be thought of as taking a disjoint union of `n` cliques of size `k`,
selecting one point from each, and contracting all of the selected points.
Alternatively, one could generate `n` cliques of size `k-1` and one node
that is connected to all other nodes in the graph.
Parameters
----------
n : int
Number of cliques
k : int
Size of cliques
Returns
-------
G : NetworkX Graph
windmill graph with n cliques of size k
Raises
------
NetworkXError
If the number of cliques is less than two
If the size of the cliques are less than two
Examples
--------
>>> G = nx.windmill_graph(4, 5)
Notes
-----
The node labeled `0` will be the node connected to all other nodes.
Note that windmill graphs are usually denoted `Wd(k,n)`, so the parameters
are in the opposite order as the parameters of this method.
| 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, k, *, backend=None, **backend_kwargs) | [
-0.002044924534857273,
0.02575226128101349,
-0.03889492154121399,
-0.015614951029419899,
0.006033675745129585,
0.05999670550227165,
-0.03407901152968407,
-0.04183593764901161,
0.053820572793483734,
-0.012196021154522896,
-0.019998900592327118,
0.01985185034573078,
-0.0033499998971819878,
0.05128394812345505,
-0.010137311182916164,
0.015256514772772789,
0.010844992473721504,
-0.04124773293733597,
0.020807679742574692,
0.03411577269434929,
-0.011791631579399109,
-0.018565157428383827,
-0.01169053465127945,
0.016892453655600548,
-0.03604581579566002,
0.02698381245136261,
0.022848010063171387,
0.008285390213131905,
-0.05514403060078621,
-0.001177554833702743,
-0.026156650856137276,
-0.015578188002109528,
-0.022167900577187538,
-0.009852400049567223,
0.0026744853239506483,
0.05326913297176361,
0.03722222149372101,
0.08337777107954025,
-0.013464333489537239,
-0.02439204230904579,
-0.018987927585840225,
-0.049151711165905,
0.006424279417842627,
-0.013923867605626583,
0.011341288685798645,
0.01887764036655426,
0.012683127075433731,
0.05587928369641304,
-0.06635665148496628,
-0.05021782964468002,
0.01061522588133812,
-0.036192864179611206,
0.03455692529678345,
0.0016692557837814093,
-0.026873523369431496,
0.01228792779147625,
0.0008438185323029757,
0.038527294993400574,
0.06521700322628021,
0.005174348130822182,
-0.014594786800444126,
-0.002314900513738394,
0.01746227592229843,
-0.009732921607792377,
-0.06668751686811447,
0.0011551525676622987,
-0.06837859749794006,
-0.03915226086974144,
0.03685459494590759,
0.0634891614317894,
0.07433415204286575,
0.04371083527803421,
-0.002020798856392503,
0.012664745561778545,
0.06992262601852417,
0.04536515474319458,
-0.00006523222691612318,
0.002787071280181408,
-0.005174348130822182,
-0.05823209509253502,
0.020421672612428665,
0.01680973917245865,
0.020844442769885063,
-0.010799039155244827,
0.06970205157995224,
-0.004202434793114662,
0.033803291618824005,
0.008358916267752647,
-0.00942962896078825,
-0.04661508649587631,
0.022774484008550644,
0.0018220506608486176,
0.04205651208758354,
-0.03613772243261337,
0.0007128514698706567,
0.05915116146206856,
-0.01812400482594967,
-0.03387681394815445,
0.03624800965189934,
-0.03477749973535538,
0.0462474599480629,
-0.0063369679264724255,
-0.06279066950082779,
0.020017283037304878,
-0.020862825214862823,
-0.05536460503935814,
0.0010925410315394402,
0.0027824759017676115,
-0.002276988932862878,
-0.03323346748948097,
-0.075437031686306,
0.045475441962480545,
0.05437201261520386,
-0.0049216048792004585,
0.01085418276488781,
-0.001440637744963169,
-0.005748765077441931,
0.009595060721039772,
0.013758435845375061,
0.007329560816287994,
-0.04106391966342926,
0.031174758449196815,
-0.021781891584396362,
0.025641974061727524,
0.014346638694405556,
0.009310150519013405,
0.028270505368709564,
0.011157475411891937,
0.03222249448299408,
-0.022866390645503998,
0.021542934700846672,
-0.016083674505352974,
0.005422496236860752,
0.020421672612428665,
-0.00351772946305573,
-0.04201975092291832,
-0.10330314934253693,
-0.036634016782045364,
0.04826940596103668,
0.006070438772439957,
-0.012600410729646683,
-0.027590395882725716,
-0.017076266929507256,
0.044078461825847626,
0.009503154084086418,
0.04157859832048416,
0.010872564278542995,
-0.020366529002785683,
0.005348970647901297,
0.008308366872370243,
0.04418874904513359,
-0.00459074042737484,
-0.012471741065382957,
-0.04529162868857384,
-0.0315791480243206,
-0.006258847191929817,
-0.0169843602925539,
-0.029924826696515083,
-0.002105812542140484,
0.01959451101720333,
-0.0241530854254961,
0.025017008185386658,
-0.026211796328425407,
0.05124718323349953,
-0.009048216044902802,
-0.037093549966812134,
0.06065843254327774,
-0.016855692490935326,
-0.06187160313129425,
-0.02718600630760193,
-0.011120712384581566,
-0.029281480237841606,
-0.03801261633634567,
-0.05845267325639725,
0.030384359881281853,
-0.04889437183737755,
0.02005404606461525,
0.0001685913885012269,
-0.038527294993400574,
0.01060603465884924,
-0.0358436182141304,
-0.009149313904345036,
-0.015164608135819435,
-0.02128559537231922,
-0.0037520916666835546,
0.05223977565765381,
0.05448229983448982,
-0.007384704425930977,
0.05510726571083069,
-0.04051247984170914,
-0.04448284953832626,
-0.042828530073165894,
-0.050953082740306854,
0.07705458998680115,
-0.0013223078567534685,
0.01454883348196745,
-0.024630999192595482,
0.028601370751857758,
-0.10631769150495529,
0.02843593806028366,
0.007131961174309254,
0.02248038351535797,
0.005601714365184307,
-0.04944581165909767,
0.03554951772093773,
-0.02246200107038021,
-0.03406062722206116,
-0.03031083568930626,
0.05135747417807579,
0.0324246883392334,
0.01431906595826149,
-0.02439204230904579,
0.07837804406881332,
0.021598078310489655,
0.01517379842698574,
-0.03981398791074753,
0.01794019155204296,
0.0038141286931931973,
-0.014558023773133755,
-0.04937228932976723,
-0.0012775033246725798,
-0.029961589723825455,
0.05698216333985329,
-0.031671054661273956,
0.022057611495256424,
-0.034520164132118225,
-0.015835527330636978,
-0.0510266087949276,
-0.04201975092291832,
-0.011387242004275322,
0.06341563165187836,
-0.03940960019826889,
0.024189848452806473,
-0.00006893003592267632,
-0.022517144680023193,
-0.0169843602925539,
0.016543209552764893,
-0.006300205364823341,
-0.023969272151589394,
0.044262275099754333,
-0.08646583557128906,
-0.015412756241858006,
0.023932509124279022,
0.017113029956817627,
0.03622962906956673,
0.05510726571083069,
-0.00786721520125866,
-0.002568792784586549,
-0.020476816222071648,
0.027112482115626335,
-0.021120162680745125,
-0.06657722592353821,
-0.027351438999176025,
-0.06584197282791138,
0.03944636136293411,
-0.07422386109828949,
-0.05639396235346794,
0.007292797788977623,
0.011424005031585693,
-0.025366254150867462,
-0.028840327635407448,
-0.03100932575762272,
-0.04613717272877693,
0.07874567806720734,
0.005165157373994589,
-0.033086419105529785,
0.0018875341629609466,
0.07238572835922241,
-0.07003291696310043,
0.007021673023700714,
0.039997801184654236,
0.050695743411779404,
0.04911495000123978,
-0.010403839871287346,
0.0007140003144741058,
-0.013105898164212704,
-0.018804114311933517,
0.008675994351506233,
0.012241974472999573,
0.053599998354911804,
0.011065568774938583,
0.042130038142204285,
-0.037130314856767654,
-0.0018783435225486755,
-0.0021494682878255844,
0.01877654157578945,
-0.024244992062449455,
-0.02100987546145916,
-0.007862619124352932,
-0.012747461907565594,
-0.0024125513155013323,
-0.02025623992085457,
-0.002936419565230608,
-0.0032580930273979902,
0.042607951909303665,
0.010238408111035824,
0.034942932426929474,
0.018748970702290535,
0.026616185903549194,
0.0339687205851078,
0.04698271304368973,
-0.04102715849876404,
-0.03718545660376549,
-0.0041817557066679,
0.037111930549144745,
-0.015127845108509064,
-0.0043632714077830315,
-0.0496663898229599,
0.016497256234288216,
0.03553113713860512,
-0.040218379348516464,
-0.012692317366600037,
0.04679889976978302,
0.029226336628198624,
0.029465293511748314,
0.004085253458470106,
0.016515636816620827,
-0.024998627603054047,
0.026708092540502548,
0.07142990082502365,
-0.01361138466745615,
-0.002474588342010975,
-0.02075253613293171,
0.0033821670804172754,
-0.05462935194373131,
-0.010431412607431412,
-0.025954456999897957,
0.041615359485149384,
-0.0021483195014297962,
-0.008800067938864231,
-0.05705568939447403,
-0.03871110826730728,
0.04871055856347084,
0.046688612550497055,
-0.010458984412252903,
0.03628477081656456,
0.07256954163312912,
-0.07003291696310043,
0.049298763275146484,
-0.07786337286233902,
0.02029300294816494,
-0.0073157744482159615,
-0.0701432079076767,
-0.005643072538077831,
0.0010402691550552845,
-0.00739389518275857,
0.03424444422125816,
-0.017489848658442497,
-0.043563783168792725,
-0.01889602094888687,
0.02264581434428692,
0.10161206871271133,
0.012260355986654758,
0.07256954163312912,
0.00427595991641283,
0.11028806120157242,
-0.005463854409754276,
-0.028711657971143723,
0.018068861216306686,
0.02867489494383335,
-0.053379420191049576,
-0.006010699085891247,
0.08264251798391342,
0.02766392193734646,
-0.03893168643116951,
-0.004627502989023924,
-0.00907119270414114,
0.005073250737041235,
0.08845102041959763,
-0.07624581456184387,
-0.004797530360519886,
-0.015945814549922943,
-0.044997528195381165,
0.03034759685397148,
-0.039005208760499954,
0.008648421615362167,
-0.11536131054162979,
0.01575281098484993,
-0.021781891584396362,
0.0006433470407500863,
-0.034042246639728546,
-0.02266419678926468,
0.033784907311201096,
0.03963017463684082,
0.004048490896821022,
-0.053379420191049576,
0.055070504546165466,
0.020421672612428665,
0.0020828358829021454,
0.02556844800710678,
-0.03102770820260048,
-0.007775308098644018,
0.019006308168172836,
0.046173933893442154,
0.007881000638008118,
0.013813579455018044,
0.0703270211815834,
-0.00783504731953144,
-0.05867324769496918,
0.03358271345496178,
0.03610095754265785,
-0.002118449890986085,
0.010716322809457779,
0.0530853196978569,
-0.03461207076907158,
-0.022995060309767723,
0.03203868120908737,
0.013795197941362858,
0.014098490588366985,
0.03804938122630119,
-0.07330479472875595,
-0.006686213426291943,
0.046945951879024506,
-0.042902056127786636,
-0.042865291237831116,
-0.06437146663665771,
-0.033527571707963943,
0.028527844697237015,
0.10712646692991257,
-0.012830177322030067,
0.09595061093568802,
-0.06087900698184967,
0.056026335805654526,
0.014126062393188477,
-0.003963476978242397,
-0.034961313009262085,
0.023822220042347908,
-0.04768120497465134,
-0.04194622486829758,
-0.01720493659377098,
-0.03253497928380966,
0.004310424905270338,
0.0730474591255188,
-0.06565815955400467,
0.04253442957997322,
-0.013013990595936775,
-0.014640740118920803,
0.016837310045957565,
-0.029667487367987633,
-0.004271364770829678,
0.08903922885656357,
0.017397942021489143,
-0.004701028577983379,
-0.027535252273082733,
0.051982440054416656,
0.015228942967951298,
-0.02025623992085457,
-0.009916734881699085,
-0.015412756241858006,
0.03299451246857643,
0.0477914921939373,
-0.009935116395354271,
0.02196570485830307,
0.0043173180893063545,
0.0013590705348178744,
0.039519887417554855,
0.05926145240664482,
0.022314950823783875,
-0.049519337713718414,
-0.010449793189764023,
0.09543593227863312,
-0.03216734901070595,
-0.020826062187552452,
0.06624636054039001,
-0.01171810645610094,
0.04944581165909767,
-0.002899657003581524,
-0.004976748488843441,
0.011653771623969078,
-0.001194787328131497,
0.03387681394815445,
0.02964910678565502,
-0.030163783580064774,
-0.07231220602989197,
-0.028270505368709564,
-0.03670754283666611,
-0.07742221653461456,
0.008781686425209045,
-0.015311659313738346,
-0.006231275387108326,
-0.01577119156718254,
-0.005169752985239029,
0.06073195859789848,
-0.009558298625051975,
-0.03922578692436218,
-0.04896789789199829,
-0.0016543208621442318,
-0.03679944947361946,
-0.011405623517930508,
0.012058161199092865,
-0.016166390851140022,
-0.09139204025268555,
0.014024964533746243,
0.005123799201101065,
0.03700164332985878,
0.009962688200175762,
0.0019415293354541063,
-0.026432370766997337,
0.03626639023423195,
-0.005399519577622414,
0.015091083012521267,
0.0467621386051178,
0.031615909188985825,
-0.0360090509057045,
0.056945402175188065,
0.015863100066781044,
0.021156925708055496,
-0.04569602012634277,
-0.050511930137872696,
0.001778394915163517,
0.01567009463906288,
0.000527027586940676,
-0.0011069015599787235,
-0.02266419678926468,
0.02817859873175621,
0.02051357924938202,
0.04933552443981171,
0.03196515515446663,
0.022590670734643936,
-0.006461041979491711,
0.020660629495978355,
0.04712976515293121,
-0.02319725602865219,
0.09337722510099411,
-0.01740713231265545,
0.00014396326150745153,
-0.01816076785326004,
-0.045512206852436066,
-0.021083401516079903,
0.017471466213464737,
-0.02580740675330162,
0.010946090333163738,
-0.03889492154121399,
0.05723950266838074,
0.023693552240729332,
-0.0227009579539299,
-0.011286145076155663,
0.025844167917966843,
0.05227654054760933,
0.011855966411530972,
-0.02222304418683052,
-0.016534017398953438,
0.0448872409760952,
0.009953496977686882,
0.0010465877130627632,
0.03124828264117241,
0.028454318642616272,
0.020568722859025,
0.004866460803896189,
-0.03725898265838623,
-0.04227709025144577,
0.04205651208758354,
-0.03321508690714836,
-0.012839368544518948,
0.08999505639076233,
-0.04102715849876404,
-0.0395934134721756,
-0.04992372915148735,
0.038527294993400574,
0.07076817005872726,
0.00758689921349287,
-0.028344031423330307,
-0.0674227699637413,
-0.005436282139271498,
0.03685459494590759,
0.01171810645610094,
-0.016396157443523407,
-0.041468311101198196,
0.008239436894655228,
0.0033959532156586647,
0.01776556856930256,
-0.01014650147408247,
-0.03656049072742462,
0.006313991267234087,
-0.009990260004997253,
-0.031211521476507187,
-0.0467621386051178,
-0.017930999398231506,
0.010780657641589642,
-0.010137311182916164,
-0.022884773090481758,
0.022075993940234184,
0.07580465823411942,
-0.03503483906388283,
0.041909463703632355,
0.04587983340024948,
-0.09117146581411362,
-0.04051247984170914,
0.02124883234500885,
0.038784634321928024,
0.028068311512470245,
0.0032443071249872446,
-0.021781891584396362,
-0.01039464958012104,
-0.06764334440231323,
-0.0013280520215630531,
0.011607818305492401,
-0.007968312129378319,
-0.028270505368709564,
-0.03553113713860512,
-0.05613662302494049,
0.026175033301115036,
0.003951988648623228,
0.05595280975103378,
0.027829352766275406,
-0.013593003153800964,
-0.04871055856347084,
-0.03268202766776085,
0.012379834428429604,
0.03082551248371601,
-0.04374759644269943,
0.022811247035861015,
-0.014989985153079033,
-0.06870946288108826,
-0.0030444099102169275,
-0.03845376893877983,
-0.025200821459293365,
0.006934361532330513,
0.019520986825227737,
-0.05157804861664772,
0.02316049300134182,
-0.00017907448636833578,
0.006686213426291943,
-0.021303975954651833,
-0.016258297488093376,
0.024961864575743675,
-0.023031823337078094,
-0.0021414265502244234,
0.022149518132209778,
0.029979970306158066,
-0.0031478051096200943,
-0.011019615456461906,
0.03911549970507622,
-0.020881205797195435,
0.024061178788542747,
-0.02843593806028366,
0.024189848452806473,
0.002511350903660059,
0.010091357864439487,
-0.005564951803535223,
-0.020145952701568604,
0.045218102633953094,
-0.01776556856930256,
-0.07661344110965729,
-0.10675884038209915,
-0.0011407921556383371,
0.03295774757862091,
0.051430996507406235,
0.0006416237447410822,
0.02053195983171463,
0.007058435585349798,
-0.0006485167541541159,
0.054776404052972794,
-0.05389409884810448,
0.014751028269529343,
-0.028546225279569626,
-0.035696569830179214,
0.028564607724547386,
0.0430123433470726,
-0.04896789789199829,
0.029741013422608376,
0.044299036264419556,
0.060511380434036255,
-0.004728600382804871,
0.008666803129017353,
0.02295829728245735,
0.018611110746860504,
-0.013308092951774597,
-0.02797640487551689,
0.038086142390966415,
-0.04532839357852936,
-0.012802605517208576,
0.06510671973228455,
-0.01669025979936123,
-0.03707516938447952,
0.041872698813676834,
-0.04128449782729149,
0.014502880163490772,
-0.03804938122630119,
0.04065953195095062,
0.027572015300393105,
0.02336268685758114,
-0.03477749973535538,
-0.0003420653229113668,
-0.006824073847383261,
-0.005560356192290783,
-0.0348142646253109,
-0.05330589413642883,
-0.011837584897875786,
0.0058039091527462006,
0.009029834531247616,
-0.010670369490981102,
-0.005082441493868828,
-0.025458160787820816,
-0.028123455122113228,
0.045254867523908615,
-0.03360109403729439,
0.000040316892409464344,
0.005394924432039261,
0.013491906225681305,
0.05562194436788559,
0.028325648978352547,
-0.008634636178612709,
0.04632098600268364,
-0.021837035194039345,
-0.02407955937087536,
-0.0395934134721756,
0.05352647230029106,
0.02889547124505043,
0.011617008596658707,
-0.020715773105621338,
-0.008731137961149216,
0.000129459222080186,
0.006594306789338589,
-0.037626609206199646,
-0.022553907707333565,
0.024520711973309517,
0.09911220520734787,
-0.012526885606348515,
-0.007439848501235247,
0.009797255508601665,
0.02051357924938202,
0.03387681394815445,
-0.0024493138771504164,
-0.060989297926425934,
-0.020476816222071648,
0.05415143817663193,
-0.027737446129322052,
0.03826995566487312,
-0.02814183570444584,
-0.028950614854693413,
0.08117201179265976,
-0.02437366172671318,
0.04279176518321037,
-0.00943882018327713,
-0.0568351149559021,
-0.01841810531914234,
0.025862550362944603,
-0.04709300026297569,
0.003239711746573448,
-0.0667242780327797,
0.00978806521743536,
-0.04051247984170914,
0.008538133464753628,
-0.023583263158798218,
-0.027535252273082733,
0.04378436133265495,
0.009971878491342068,
-0.006116392090916634,
-0.020936349406838417,
0.007159532979130745,
-0.0023378771729767323,
0.023748695850372314,
0.007733950391411781,
-0.04646803438663483,
-0.036872975528240204,
0.0035039435606449842,
-0.054298486560583115,
-0.05411467328667641,
-0.07565760612487793,
-0.006810287479311228,
0.012563647702336311,
-0.006410493515431881,
-0.002784773474559188,
-0.007982098497450352,
0.04113744571805,
0.039997801184654236,
0.023050203919410706
]
|
31,242 | networkx.readwrite.gexf | write_gexf | Write G in GEXF format to path.
"GEXF (Graph Exchange XML Format) is a language for describing
complex networks structures, their associated data and dynamics" [1]_.
Node attributes are checked according to the version of the GEXF
schemas used for parameters which are not user defined,
e.g. visualization 'viz' [2]_. See example for usage.
Parameters
----------
G : graph
A NetworkX graph
path : file or string
File or file name to write.
File names ending in .gz or .bz2 will be compressed.
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 (optional, default: '1.2draft')
The version of GEXF to be used for nodes attributes checking
Examples
--------
>>> G = nx.path_graph(4)
>>> nx.write_gexf(G, "test.gexf")
# visualization data
>>> G.nodes[0]["viz"] = {"size": 54}
>>> G.nodes[0]["viz"]["position"] = {"x": 0, "y": 1}
>>> G.nodes[0]["viz"]["color"] = {"r": 0, "g": 0, "b": 256}
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, http://gexf.net/
.. [2] GEXF schema, http://gexf.net/schema.html
| def add_node(self, G, node_xml, node_attr, node_pid=None):
# add a single node with attributes to the graph
# get attributes and subattributues for node
data = self.decode_attr_elements(node_attr, node_xml)
data = self.add_parents(data, node_xml) # add any parents
if self.VERSION == "1.1":
data = self.add_slices(data, node_xml) # add slices
else:
data = self.add_spells(data, node_xml) # add spells
data = self.add_viz(data, node_xml) # add viz
data = self.add_start_end(data, node_xml) # add start/end
# find the node id and cast it to the appropriate type
node_id = node_xml.get("id")
if self.node_type is not None:
node_id = self.node_type(node_id)
# every node should have a label
node_label = node_xml.get("label")
data["label"] = node_label
# parent node id
node_pid = node_xml.get("pid", node_pid)
if node_pid is not None:
data["pid"] = node_pid
# check for subnodes, recursive
subnodes = node_xml.find(f"{{{self.NS_GEXF}}}nodes")
if subnodes is not None:
for node_xml in subnodes.findall(f"{{{self.NS_GEXF}}}node"):
self.add_node(G, node_xml, node_attr, node_pid=node_id)
G.add_node(node_id, **data)
| (G, path, encoding='utf-8', prettyprint=True, version='1.2draft') | [
0.013720755465328693,
0.031091365963220596,
0.0026601464487612247,
0.034451551735401154,
0.0062520685605704784,
0.02168671041727066,
-0.02699734829366207,
0.07268813997507095,
0.06843963265419006,
-0.06562016159296036,
0.021648088470101357,
0.009535008110105991,
0.06674022972583771,
0.05090487003326416,
-0.018297558650374413,
-0.014106983318924904,
-0.024873092770576477,
-0.02006455324590206,
-0.04457072913646698,
0.014116639271378517,
-0.01700369454920292,
0.019098982214927673,
0.0030801696702837944,
0.0006541739567182958,
0.04522731900215149,
0.008183209225535393,
-0.0035822661593556404,
0.0354943685233593,
0.01974591426551342,
-0.010099866427481174,
0.018297558650374413,
-0.09578458219766617,
-0.06349591165781021,
-0.021068746224045753,
-0.004540594760328531,
0.05808871611952782,
-0.03792760521173477,
-0.0267656110227108,
-0.043334800750017166,
0.007555588148534298,
0.05573272332549095,
-0.025240009650588036,
0.002766359131783247,
-0.01319934707134962,
-0.018712753430008888,
-0.004996826872229576,
0.03837176784873009,
0.07801809161901474,
-0.06747405976057053,
-0.06280069798231125,
-0.004448865540325642,
-0.031033432111144066,
0.00031501732883043587,
0.05048001930117607,
-0.03512744978070259,
-0.00506441667675972,
-0.019794194027781487,
0.03340873494744301,
-0.009597769938409328,
0.058397699147462845,
0.04290995001792908,
0.027692558243870735,
-0.021319793537259102,
-0.02502758428454399,
-0.04074707254767418,
0.03340873494744301,
-0.03058926947414875,
-0.0682465136051178,
-0.013209003023803234,
0.02890917845070362,
0.022555723786354065,
-0.011297173798084259,
0.042639587074518204,
0.03244316577911377,
0.07562347501516342,
0.02473791316151619,
0.00367399537935853,
0.02068251743912697,
0.012204810045659542,
0.03821727633476257,
-0.00937568861991167,
0.005696865264326334,
-0.022980576381087303,
0.0068169268779456615,
0.030009927228093147,
0.04236922785639763,
-0.05986536294221878,
0.0019178641960024834,
0.012166187167167664,
-0.026070401072502136,
-0.03394945710897446,
0.020470092073082924,
0.010389537550508976,
0.024931028485298157,
0.0763959288597107,
-0.036402005702257156,
0.015111176297068596,
-0.027209773659706116,
0.04762193188071251,
0.055346496403217316,
-0.04851025715470314,
0.038564883172512054,
-0.06886447966098785,
-0.03883524239063263,
-0.009481901302933693,
-0.08659235388040543,
-0.04468659684062004,
0.03481847047805786,
-0.018596885725855827,
0.03340873494744301,
-0.038680750876665115,
-0.04916684329509735,
0.06206686422228813,
0.007241778075695038,
-0.03427774831652641,
0.025645550340414047,
-0.001368695986457169,
0.025780729949474335,
-0.0004076517652720213,
-0.020779075101017952,
0.01209859736263752,
-0.02330886945128441,
0.005469956435263157,
0.008134930394589901,
-0.03298388421535492,
-0.013064167462289333,
0.017708560451865196,
0.011953761801123619,
-0.01398145966231823,
-0.0437210276722908,
0.03958838805556297,
0.021165303885936737,
-0.02311575599014759,
0.012002039700746536,
0.014415966346859932,
-0.04499557986855507,
-0.000826166186016053,
0.023019198328256607,
0.008453568443655968,
0.031284481287002563,
0.005749971605837345,
-0.0797947347164154,
0.058590810745954514,
0.01266828365623951,
-0.06307105720043182,
0.0011104060104116797,
-0.0950121283531189,
0.00001028747374220984,
-0.04642462357878685,
-0.029063668102025986,
-0.02437099628150463,
-0.030087172985076904,
0.015004963614046574,
-0.03364047408103943,
-0.005445817019790411,
0.02622489258646965,
-0.04194437712430954,
0.0032684558536857367,
-0.007724563125520945,
0.004255751613527536,
-0.06268483400344849,
-0.021184613928198814,
0.08172588050365448,
0.008950837887823582,
0.030859630554914474,
-0.014956685714423656,
-0.001298692193813622,
-0.054458171129226685,
-0.024467553943395615,
0.02587728761136532,
0.022594347596168518,
-0.07268813997507095,
-0.010196423158049583,
0.008690133690834045,
-0.01983281597495079,
-0.026244202628731728,
0.05318361893296242,
-0.03221143037080765,
0.004272649064660072,
0.03732895106077194,
0.003007751889526844,
0.013431084342300892,
0.040167730301618576,
0.03344735875725746,
-0.004243682138621807,
-0.018365148454904556,
0.0166657455265522,
0.023135066032409668,
0.017216119915246964,
0.01182823721319437,
0.0267656110227108,
0.004936478566378355,
-0.014734604395925999,
0.03064720518887043,
0.04708121344447136,
0.020643895491957664,
0.023791654035449028,
-0.007207983173429966,
-0.016395386308431625,
0.09570733457803726,
0.06843963265419006,
0.02462204545736313,
0.015111176297068596,
0.016086403280496597,
0.00028997287154197693,
-0.008946009911596775,
-0.021725334227085114,
0.024332374334335327,
-0.05318361893296242,
-0.0567755401134491,
0.027441510930657387,
0.02533656731247902,
0.043643783777952194,
0.026128334924578667,
-0.04020635038614273,
-0.009549491107463837,
-0.11324209719896317,
0.04109467566013336,
-0.07616419345140457,
-0.013633853755891323,
0.013266936875879765,
-0.009646047838032246,
-0.03674960881471634,
-0.06310968101024628,
0.00970398262143135,
-0.03367909416556358,
0.043527912348508835,
-0.012861398048698902,
-0.0012697250349447131,
0.012842086143791676,
0.0004438606556504965,
0.06152614578604698,
0.03180588781833649,
-0.01125855091959238,
0.0074976542964577675,
0.0007718528504483402,
0.050209660083055496,
0.048124030232429504,
-0.011847549118101597,
-0.004661290906369686,
-0.010891634039580822,
-0.016366418451070786,
-0.07376957684755325,
-0.019967995584011078,
0.04240785166621208,
0.013575919903814793,
0.04623151198029518,
0.05233391746878624,
-0.026842856779694557,
0.01825893670320511,
-0.03757999837398529,
-0.021300483494997025,
-0.011335796676576138,
0.04260096698999405,
0.019041048362851143,
0.021049434319138527,
-0.05967225134372711,
-0.04739019647240639,
0.011384074576199055,
0.002831535181030631,
0.028600195422768593,
0.03481847047805786,
0.014831161126494408,
0.02867744117975235,
0.0333314910531044,
-0.002281160093843937,
0.03369840607047081,
-0.015014619566500187,
-0.04565216973423958,
-0.005469956435263157,
0.08867798745632172,
0.017331989482045174,
0.0368654765188694,
-0.010804732330143452,
0.041674017906188965,
-0.05573272332549095,
-0.021551530808210373,
0.03308044373989105,
0.0015437057008966804,
-0.01580638810992241,
-0.061139918863773346,
-0.032346609979867935,
0.01640504039824009,
0.0655815452337265,
-0.08257558196783066,
-0.08311630040407181,
-0.0011146303731948137,
0.10219597071409225,
-0.021551530808210373,
-0.0480467826128006,
-0.05048001930117607,
0.0368654765188694,
-0.06434561312198639,
0.052836012095212936,
0.006536911707371473,
0.008255627006292343,
0.003823658684268594,
0.05040277540683746,
-0.04356653615832329,
0.026514563709497452,
0.07268813997507095,
-0.000014926738003850915,
0.022246742621064186,
-0.06701058894395828,
-0.028600195422768593,
0.036054398864507675,
0.025722796097397804,
-0.005981708411127329,
-0.01520773395895958,
0.000826166186016053,
-0.07879054546356201,
0.026128334924578667,
0.0016740576829761267,
0.04345066845417023,
-0.03238523006439209,
0.032655589282512665,
0.048780616372823715,
-0.05932464450597763,
0.042098868638277054,
0.009713638573884964,
-0.035706792026758194,
-0.04217611625790596,
-0.03792760521173477,
0.031921759247779846,
-0.007946643978357315,
0.01436768751591444,
0.03883524239063263,
0.06160338968038559,
0.024525487795472145,
0.036305446177721024,
-0.03503089398145676,
0.025606926530599594,
-0.017254743725061417,
0.04236922785639763,
-0.08836900442838669,
0.004188161808997393,
0.0007537484052591026,
-0.05662104859948158,
-0.002510483143851161,
0.006884517148137093,
-0.0031187923159450293,
0.023212311789393425,
-0.06218273192644119,
0.01308347936719656,
0.046501871198415756,
-0.023559918627142906,
0.01822996884584427,
-0.05299050360918045,
-0.02151290886104107,
0.018471362069249153,
-0.040592581033706665,
0.026031777262687683,
-0.033910833299160004,
-0.007975611835718155,
0.019465899094939232,
-0.01914726011455059,
0.022497789934277534,
-0.025954531505703926,
-0.053376730531454086,
0.028773998841643333,
-0.03655649349093437,
-0.003975735977292061,
0.013035200536251068,
0.021107368171215057,
-0.0742330551147461,
-0.021532220765948296,
0.04924409091472626,
0.0486261248588562,
0.03238523006439209,
-0.009882613085210323,
0.05341535434126854,
-0.06627675145864487,
-0.03812072053551674,
0.02191844768822193,
-0.023405427113175392,
0.03089825250208378,
0.0270552821457386,
0.010302635841071606,
0.00906187854707241,
-0.06527256220579147,
-0.025722796097397804,
-0.031207235530018806,
-0.027267707511782646,
0.007734219077974558,
-0.020334912464022636,
-0.052488405257463455,
0.11733611673116684,
0.026804234832525253,
0.02120392583310604,
-0.0018575160065665841,
-0.012552415020763874,
0.026360072195529938,
0.012137220241129398,
0.006990729831159115,
-0.05646655708551407,
-0.059903986752033234,
0.058050092309713364,
-0.040476709604263306,
-0.06438423693180084,
-0.03242385387420654,
0.0022292607463896275,
-0.014106983318924904,
-0.019417621195316315,
0.04163539409637451,
0.032713524997234344,
-0.012494481168687344,
-0.04939858242869377,
-0.046386003494262695,
0.025066208094358444,
0.03188313543796539,
0.03514676168560982,
0.008255627006292343,
-0.007811464369297028,
-0.0038864207454025745,
0.03178657591342926,
0.011268206872045994,
0.03126516938209534,
0.026688365265727043,
-0.015342913568019867,
-0.04379827156662941,
-0.03997461497783661,
0.02659180946648121,
0.03450948745012283,
0.0453045628964901,
0.0062134456820786,
-0.002248571952804923,
0.016076747328042984,
0.03153552860021591,
-0.06183512881398201,
0.0469653457403183,
0.010939912870526314,
0.02873537503182888,
0.033910833299160004,
-0.024235816672444344,
0.03209555894136429,
-0.037425506860017776,
0.0071693602949380875,
-0.07400131225585938,
0.009723293595016003,
0.029198849573731422,
0.015680862590670586,
-0.013971803709864616,
0.011509599164128304,
-0.00008614698163000867,
-0.05148421227931976,
-0.0074300640262663364,
-0.0644228607416153,
-0.04487971216440201,
0.06411387771368027,
-0.03035753406584263,
0.07261089235544205,
0.03783104941248894,
0.04491833597421646,
0.023019198328256607,
-0.045613545924425125,
-0.036228202283382416,
-0.08435223251581192,
-0.07906090468168259,
0.003212935524061322,
-0.018423082306981087,
-0.07388544827699661,
0.03966563194990158,
-0.030801694840192795,
-0.015400847420096397,
-0.0226909052580595,
0.004605770576745272,
0.041249167174100876,
-0.028465015813708305,
-0.04136503487825394,
-0.02856157161295414,
0.0032153495121747255,
-0.02126185968518257,
-0.0092887869104743,
-0.08798277378082275,
0.031941067427396774,
-0.011229583993554115,
-0.02437099628150463,
-0.03435499593615532,
-0.03541712090373039,
-0.04553629830479622,
0.005547201726585627,
-0.007130737416446209,
0.03624751418828964,
0.060019854456186295,
-0.026958726346492767,
0.03443223983049393,
0.03535918891429901,
0.011287517845630646,
-0.029411274939775467,
0.011760647408664227,
-0.013633853755891323,
-0.07114322483539581,
-0.03476053476333618,
0.05496026575565338,
0.007072803098708391,
0.013353838585317135,
0.022362610325217247,
-0.07790222018957138,
-0.026688365265727043,
-0.024525487795472145,
-0.029179537668824196,
-0.002392200753092766,
0.0077487025409936905,
0.011470976285636425,
-0.0018925180193036795,
0.018201002851128578,
-0.05944051221013069,
0.0671650767326355,
-0.00685554975643754,
0.02491171658039093,
0.0010162628022953868,
-0.018789999186992645,
0.056427933275699615,
0.00831838883459568,
0.016530565917491913,
0.01460907980799675,
-0.008265282958745956,
0.04213749244809151,
-0.02294195257127285,
-0.01983281597495079,
0.024602733552455902,
0.011799270287156105,
0.05650518089532852,
-0.008569437079131603,
-0.006913484074175358,
0.06056057661771774,
-0.029778191819787025,
-0.0360737107694149,
-0.06901897490024567,
0.026784922927618027,
-0.009394999593496323,
0.009052222594618797,
0.027035972103476524,
-0.009646047838032246,
-0.02342473715543747,
0.026611119508743286,
0.06005847826600075,
0.052720144391059875,
0.003058444242924452,
-0.06160338968038559,
0.027113215997815132,
-0.03404601290822029,
0.014261474832892418,
0.014502867124974728,
-0.003316734218969941,
-0.015458782203495502,
0.07152945548295975,
-0.0442231260240078,
0.03308044373989105,
-0.037019968032836914,
0.013788345269858837,
-0.03232729807496071,
-0.030550647526979446,
0.05542374029755592,
0.07280401140451431,
0.019465899094939232,
0.02479584701359272,
-0.04132641479372978,
0.01869344338774681,
-0.025780729949474335,
-0.03985874727368355,
-0.03831383213400841,
-0.005962397437542677,
0.0035074343904852867,
0.017814774066209793,
0.013035200536251068,
-0.0003403635637369007,
-0.003884006990119815,
0.03526262938976288,
-0.0005102435825392604,
0.01883827894926071,
0.025587616488337517,
-0.03398807719349861,
-0.06017434597015381,
-0.02867744117975235,
-0.043412044644355774,
-0.015516716055572033,
0.030009927228093147,
-0.02944989688694477,
-0.04661773890256882,
-0.07473514974117279,
0.020643895491957664,
0.004873716738075018,
0.044184502214193344,
-0.01290002092719078,
0.04132641479372978,
-0.004963031969964504,
0.04240785166621208,
0.051291100680828094,
-0.025722796097397804,
-0.002145980251953006,
-0.06453872472047806,
0.07917677611112595,
-0.022787461057305336,
-0.021493596956133842,
0.016704367473721504,
0.013131757266819477,
-0.022671593353152275,
-0.0207404512912035,
-0.020103175193071365,
-0.018954146653413773,
-0.017959609627723694,
0.048124030232429504,
0.007642489857971668,
-0.04542043060064316,
0.0360737107694149,
-0.015816044062376022,
0.005093384068459272,
-0.06183512881398201,
-0.015564994886517525,
0.024004079401493073,
-0.028291212394833565,
-0.026031777262687683,
0.01646297611296177,
-0.025548992678523064,
-0.04796953871846199,
-0.03974287584424019,
0.02162877656519413,
0.05669829249382019,
0.0008738412288948894,
-0.023077132180333138,
-0.019012080505490303,
-0.019195539876818657,
0.028580883517861366,
-0.0036981345620006323,
-0.020508715882897377,
0.031284481287002563,
-0.041674017906188965,
-0.028928488492965698,
-0.008096307516098022,
-0.006218273192644119,
-0.00359192187897861,
-0.004243682138621807,
-0.04677223041653633,
0.011519255116581917,
-0.017766496166586876,
0.04159677401185036,
0.0344129279255867,
0.012368956580758095,
0.030029239133000374,
-0.02222743071615696,
0.01290002092719078,
-0.029681634157896042,
-0.027943607419729233,
0.01600915752351284,
0.006923139560967684,
0.05121385306119919,
0.011722024530172348,
-0.007362474221736193,
-0.03727101907134056,
0.017274053767323494,
-0.013344182632863522,
-0.02000661939382553,
-0.002766359131783247,
0.04236922785639763,
0.03759931027889252,
-0.0590156614780426,
0.0076618012972176075,
-0.027673248201608658,
0.00044627455645240843,
0.012282055802643299,
-0.008936353959143162,
0.05102074146270752,
-0.00286050233989954,
-0.00858874898403883,
-0.015429815277457237,
0.0388159304857254,
-0.037734489887952805,
0.01149994321167469,
0.014290441758930683,
-0.05387882888317108,
-0.03732895106077194,
-0.015101521275937557,
0.012175843119621277,
0.0008237522561103106,
-0.054998889565467834,
0.03226936236023903,
0.023096444085240364,
0.003058444242924452,
0.05449679493904114,
-0.012552415020763874,
0.052295293658971786,
0.02527863346040249,
-0.08211210370063782,
0.025606926530599594,
0.07303574681282043,
0.009076361544430256,
-0.042098868638277054,
0.02323162369430065,
0.002568417228758335,
0.012822775170207024,
-0.032597657293081284,
0.038391079753637314,
0.008627371862530708,
0.03985874727368355,
-0.047351572662591934,
0.024119948968291283,
0.015738798305392265,
0.008806002326309681,
-0.00003679351357277483,
-0.01027366891503334,
-0.00562927545979619,
-0.03898973390460014,
0.036653053015470505,
0.015420159325003624,
-0.030376844108104706,
-0.049746185541152954,
0.05712314322590828,
-0.01287105306982994,
0.019794194027781487,
-0.018114101141691208,
0.034625355154275894,
0.01726439967751503,
0.03344735875725746,
-0.012793808244168758,
0.01266828365623951,
0.016231238842010498,
-0.0030367188155651093,
-0.05449679493904114,
-0.026900790631771088,
-0.021223237738013268,
0.009805367328226566,
0.04132641479372978,
0.046579115092754364,
0.04345066845417023,
-0.03261696919798851,
0.011248894967138767,
-0.08334803581237793,
-0.011799270287156105,
-0.02927609533071518,
0.001967349788174033,
0.0403994657099247,
0.01900242455303669,
0.0027929123025387526,
0.014860128052532673,
-0.0295078307390213,
-0.04808540642261505,
0.0420602448284626,
-0.004591287113726139,
-0.028213966637849808,
-0.02778911590576172,
0.015275323763489723,
0.00018934231775347143,
-0.03458673134446144,
0.008038373664021492,
0.014300097711384296,
0.02448686584830284,
0.04881924018263817,
-0.04356653615832329,
0.05094349384307861,
0.04066982492804527,
0.02257503569126129,
0.011335796676576138,
0.10829837620258331,
0.05144559219479561,
0.019041048362851143,
0.023135066032409668,
0.014232507906854153,
0.020470092073082924,
-0.07875192165374756,
-0.014058705419301987,
-0.020817697048187256,
-0.003456742037087679,
-0.02205362729728222,
0.023810965940356255,
0.03418119251728058,
0.01290967594832182,
0.09084086120128632
]
|
31,243 | networkx.readwrite.gml | write_gml | Write a graph `G` in GML format to the file or file handle `path`.
Parameters
----------
G : NetworkX graph
The graph to be converted to GML.
path : filename or filehandle
The filename or filehandle to write. Files whose names end with .gz or
.bz2 will be compressed.
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.
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
--------
read_gml, generate_gml
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`.
Note that while we allow non-standard GML to be read from a file, we make
sure to write GML format. In particular, underscores are not allowed in
attribute names.
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.path_graph(4)
>>> nx.write_gml(G, "test.gml")
Filenames ending in .gz or .bz2 will be compressed.
>>> nx.write_gml(G, "test.gml.gz")
| 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, path, stringizer=None) | [
0.04236811771988869,
0.025365402922034264,
-0.018666718155145645,
-0.03786677122116089,
0.03236275538802147,
-0.0071680196560919285,
-0.057642824947834015,
-0.0012846702011302114,
0.11502964794635773,
-0.0738135352730751,
-0.011413364671170712,
0.05363214761018753,
-0.030656084418296814,
0.08806424587965012,
0.009018691256642342,
0.022442728281021118,
-0.021173391491174698,
-0.023936064913868904,
0.05888016149401665,
0.010912030003964901,
-0.015776043757796288,
-0.012181366793811321,
0.03566943109035492,
0.010085361078381538,
0.030762750655412674,
-0.06186683848500252,
0.01817605085670948,
0.004640012979507446,
-0.04590946063399315,
0.025408070534467697,
-0.01552004273980856,
-0.12501367926597595,
-0.007600021082907915,
-0.05491214990615845,
-0.006042683497071266,
-0.026560073718428612,
-0.07970155030488968,
0.02203739434480667,
-0.1018882766366005,
-0.06186683848500252,
0.03846410661935806,
-0.01770671457052231,
-0.03690676763653755,
-0.035861432552337646,
-0.010480028577148914,
0.054570816457271576,
-0.02108805812895298,
0.07022952288389206,
-0.05713082477450371,
-0.04522679001092911,
0.01603204384446144,
-0.011840032413601875,
-0.049066800624132156,
0.04855480045080185,
-0.0449707917869091,
-0.005792015697807074,
-0.020469389855861664,
0.008896024897694588,
0.07189352810382843,
0.031189419329166412,
-0.004517345689237118,
0.031104085966944695,
-0.0056533487513661385,
-0.00936535932123661,
-0.011541364714503288,
0.0013840037863701582,
-0.04373345524072647,
-0.06310417503118515,
-0.03300275653600693,
-0.007968021556735039,
-0.026901407167315483,
-0.0023640065919607878,
0.01724804751574993,
0.010704029351472855,
-0.0003368342586327344,
0.015402709133923054,
-0.03509343042969704,
0.043989453464746475,
0.015328042209148407,
-0.01452803984284401,
-0.002314673038199544,
0.024618733674287796,
0.0010233361972495914,
-0.09292825311422348,
0.028565412387251854,
0.008213356137275696,
0.04051211103796959,
0.04192011430859566,
-0.007162686437368393,
0.014901374466717243,
-0.039253439754247665,
0.011872032657265663,
0.026944074779748917,
0.0433921180665493,
-0.02365873195230961,
-0.01886938512325287,
-0.020170722156763077,
-0.044416122138500214,
0.03272542357444763,
-0.0014866708079352975,
0.014250705949962139,
0.010384028777480125,
-0.04172811657190323,
-0.003490676172077656,
-0.04437345638871193,
-0.06459750980138779,
-0.028672078624367714,
-0.0006973352283239365,
0.045098789036273956,
-0.04424545541405678,
-0.08221889287233353,
-0.06476818025112152,
0.06976018846035004,
-0.02357339859008789,
0.06080016866326332,
0.013920038007199764,
-0.016160044819116592,
-0.0036640099715441465,
0.024064065888524055,
-0.01658671163022518,
-0.011754699051380157,
-0.021994726732373238,
-0.060160163789987564,
0.04390412196516991,
0.001898671849630773,
0.015008041635155678,
0.05585081875324249,
0.0073226867243647575,
0.04241078346967697,
-0.025898737832903862,
0.0407467782497406,
0.02545073628425598,
0.04253878444433212,
0.045866791158914566,
0.027797410264611244,
-0.038933441042900085,
-0.048597466200590134,
-0.005010680295526981,
0.0701015293598175,
0.07321619987487793,
0.0388907752931118,
-0.08025622367858887,
0.026005404070019722,
0.010106694884598255,
-0.00251067359931767,
-0.04770146310329437,
0.0010173361515626311,
0.010922696441411972,
-0.004066677764058113,
-0.05964816361665726,
0.04689079523086548,
0.006394684314727783,
0.0349227637052536,
-0.01965872012078762,
-0.007450687233358622,
0.027157407253980637,
-0.050474803894758224,
0.04345611855387688,
0.007232019677758217,
0.0012020033318549395,
0.000411667802836746,
0.0026786739472299814,
0.034624096006155014,
0.04573879390954971,
0.015658710151910782,
0.01804804988205433,
0.046421460807323456,
-0.05789882689714432,
0.011242697946727276,
0.01045336201786995,
-0.0011680031893774867,
-0.06805352121591568,
-0.08823490887880325,
-0.010576029308140278,
0.04480012506246567,
0.007706687785685062,
0.03029341623187065,
0.10368028283119202,
-0.009402692317962646,
0.05986149609088898,
-0.015104041434824467,
-0.02653873898088932,
-0.03699210286140442,
-0.007408020552247763,
-0.02333873137831688,
-0.017738714814186096,
0.05307747796177864,
-0.005552015267312527,
0.04315745085477829,
-0.024853400886058807,
0.004829346667975187,
-0.041472114622592926,
-0.01889071799814701,
0.057514823973178864,
0.025600070133805275,
-0.005176014266908169,
-0.006480017676949501,
-0.0047973464243113995,
0.01377070415765047,
0.08268822729587555,
-0.004720013123005629,
-0.028586745262145996,
0.028821412473917007,
-0.0362454317510128,
-0.05341881513595581,
-0.014314706437289715,
-0.038933441042900085,
-0.01082136295735836,
-0.04701879620552063,
0.0029280080925673246,
-0.001182669890113175,
-0.014112038537859917,
0.012405367568135262,
0.04582412540912628,
-0.01611737720668316,
-0.031530752778053284,
-0.010426695458590984,
0.05205347761511803,
-0.08145088702440262,
-0.0550401508808136,
0.010560029186308384,
-0.017002712935209274,
0.019722720608115196,
-0.03389875963330269,
0.049493469297885895,
-0.04996280372142792,
0.05990416556596756,
-0.03820810467004776,
-0.007776021491736174,
0.0021253391169011593,
0.10632562637329102,
0.011136030778288841,
0.05640548840165138,
0.03982944414019585,
0.02542940340936184,
-0.0605868324637413,
0.02643207274377346,
0.0003355009248480201,
0.017664048820734024,
0.03093341924250126,
-0.04051211103796959,
-0.05260814353823662,
-0.06818152219057083,
-0.03129608556628227,
0.03304542601108551,
0.022741395980119705,
0.009482692927122116,
0.017109381034970284,
0.016821378841996193,
0.011221364140510559,
-0.024917401373386383,
0.019253386184573174,
-0.012352033518254757,
-0.008757357485592365,
-0.027776075527071953,
-0.004434678703546524,
-0.05085880681872368,
-0.046080127358436584,
0.031637419015169144,
-0.011562698520720005,
0.013461370021104813,
-0.008170689456164837,
-0.09864560514688492,
0.07078419625759125,
0.07368553429841995,
0.012341367080807686,
0.022976063191890717,
0.010773362591862679,
0.014837373979389668,
-0.00167867133859545,
0.041557446122169495,
0.058410827070474625,
-0.023914732038974762,
-0.025621403008699417,
0.0062773507088422775,
-0.003493343014270067,
0.04334945231676102,
0.019562721252441406,
0.005466681905090809,
-0.013728037476539612,
-0.023488065227866173,
-0.001222003367729485,
-0.023168062791228294,
-0.01348270382732153,
-0.023744065314531326,
0.03016541711986065,
-0.03722677007317543,
-0.02555740438401699,
0.016522713005542755,
-0.03588276356458664,
0.061610836535692215,
-0.016234710812568665,
-0.036608099937438965,
0.035605430603027344,
0.04748813062906265,
-0.030080081894993782,
0.012458700686693192,
-0.03972277417778969,
-0.005064013879746199,
0.002126672537997365,
0.08789357542991638,
-0.01788804866373539,
0.08708290755748749,
0.00792535487562418,
-0.0114453649148345,
0.03929610922932625,
0.01965872012078762,
-0.0181227158755064,
-0.02478940226137638,
0.02389339916408062,
-0.04689079523086548,
-0.0011953365756198764,
0.042112115770578384,
0.012800035066902637,
-0.01603204384446144,
0.010896029882133007,
0.0059520164504647255,
-0.010725363157689571,
0.07266153395175934,
-0.008677356876432896,
-0.022741395980119705,
0.032106753438711166,
0.007850687950849533,
0.023637399077415466,
-0.03129608556628227,
0.010944030247628689,
0.035754766315221786,
0.05034680664539337,
0.03193608671426773,
-0.05320547893643379,
-0.0005856682546436787,
-0.024704067036509514,
-0.02162139303982258,
0.0632321760058403,
-0.04166411608457565,
0.05491214990615845,
0.027136074379086494,
-0.007498687133193016,
-0.009424026124179363,
-0.08012822270393372,
0.03328009322285652,
0.018720051273703575,
-0.009594692848622799,
0.0012440034188330173,
0.023722732439637184,
0.018805384635925293,
0.011413364671170712,
-0.05222414433956146,
0.018378717824816704,
0.04526945948600769,
-0.019594719633460045,
0.04812813177704811,
0.016202710568904877,
0.021866727620363235,
0.0160107109695673,
-0.028330745175480843,
-0.00841602310538292,
-0.046976130455732346,
-0.02021338976919651,
0.053802814334630966,
0.03315209224820137,
0.002373339841142297,
-0.0023666732013225555,
0.0642988458275795,
0.0018960052402690053,
-0.030762750655412674,
-0.008688024245202541,
0.05465615168213844,
0.08110955357551575,
0.009989360347390175,
0.015189374797046185,
-0.026005404070019722,
-0.04573879390954971,
-0.007904022000730038,
-0.02076805755496025,
0.008026688359677792,
0.016160044819116592,
0.015626709908246994,
-0.03876277431845665,
-0.006613351404666901,
-0.014720040373504162,
0.04701879620552063,
0.025792071595788002,
0.05196814239025116,
0.023061396554112434,
-0.022272061556577682,
0.09770693629980087,
0.019562721252441406,
-0.03972277417778969,
-0.05056013911962509,
-0.022954730316996574,
0.011008030734956264,
0.03961610794067383,
0.01370670460164547,
-0.03246942162513733,
-0.06425617635250092,
0.06400017440319061,
-0.029034746810793877,
-0.011008030734956264,
-0.022826729342341423,
-0.012298700399696827,
-0.0014093371573835611,
-0.07522153854370117,
0.005706682335585356,
0.006725351791828871,
-0.042901452630758286,
0.02929074689745903,
-0.015786709263920784,
0.017930716276168823,
0.012298700399696827,
0.04369078576564789,
-0.022186728194355965,
-0.06621884554624557,
-0.015413375571370125,
0.025472069159150124,
-0.018656050786376,
-0.0164053775370121,
0.04987747222185135,
-0.009578692726790905,
0.04093877971172333,
0.010112027637660503,
0.02323206327855587,
0.05068814009428024,
0.015552042983472347,
-0.04215478152036667,
0.012810701504349709,
-0.04328545182943344,
-0.010896029882133007,
-0.06882151961326599,
0.057301491498947144,
-0.025024069473147392,
-0.048512134701013565,
0.03029341623187065,
-0.0058080158196389675,
-0.00583468284457922,
-0.03910410776734352,
-0.01926405355334282,
-0.019360052421689034,
0.014773374423384666,
-0.018880052492022514,
0.0034346762113273144,
-0.038805440068244934,
0.024405401200056076,
-0.009941360913217068,
0.026581406593322754,
-0.0014893374172970653,
-0.020405389368534088,
0.039253439754247665,
0.06724285334348679,
0.03658676892518997,
-0.008661356754601002,
-0.012373367324471474,
0.0653655156493187,
0.013034702278673649,
-0.027946744114160538,
-0.022826729342341423,
0.0428587831556797,
-0.004125344567000866,
-0.03773877024650574,
0.054784148931503296,
-0.0036213432904332876,
-0.01767471618950367,
0.02941874787211418,
0.04898146912455559,
-0.018304049968719482,
0.018880052492022514,
0.014506706967949867,
0.05704548954963684,
-0.06822418421506882,
0.006528018042445183,
-0.010853363201022148,
0.020629389211535454,
-0.024085398763418198,
-0.024938736110925674,
-0.007232019677758217,
-0.018858717754483223,
-0.017813382670283318,
0.026474740356206894,
-0.03421876206994057,
-0.05602148920297623,
0.02653873898088932,
-0.039573442190885544,
0.018186716362833977,
0.008880024775862694,
0.010757362470030785,
0.039018772542476654,
0.06532284617424011,
-0.03929610922932625,
-0.007114686071872711,
0.004440012387931347,
-0.0552961528301239,
0.0030186749063432217,
0.017109381034970284,
-0.05486948415637016,
0.0052773477509617805,
0.03688543662428856,
-0.01724804751574993,
-0.03246942162513733,
-0.019968055188655853,
-0.02929074689745903,
-0.029461413621902466,
0.002305339789018035,
-0.016714712604880333,
0.00024566735373809934,
0.049066800624132156,
0.018912052735686302,
0.006384017411619425,
0.04403212293982506,
0.013098702766001225,
-0.037162769585847855,
-0.003749343566596508,
-0.02709340862929821,
0.05691748857498169,
0.030208082869648933,
-0.038058772683143616,
-0.019904054701328278,
0.027605408802628517,
0.02267739549279213,
-0.052906811237335205,
-0.032874755561351776,
0.029461413621902466,
-0.016768045723438263,
-0.0049333469942212105,
0.026389405131340027,
-0.03016541711986065,
0.030080081894993782,
0.018250716850161552,
-0.02153605967760086,
-0.016234710812568665,
-0.017920048907399178,
0.0114453649148345,
0.05043213814496994,
0.02468273416161537,
0.05956283211708069,
-0.03027208335697651,
-0.019136052578687668,
0.06899219006299973,
0.02222939394414425,
-0.02257072925567627,
0.019360052421689034,
0.038592107594013214,
-0.004898679908365011,
-0.013365370221436024,
0.04183478280901909,
0.029248081147670746,
0.0002306672977283597,
0.0685228556394577,
0.010645362548530102,
0.02455473504960537,
-0.07300286740064621,
-0.0677548497915268,
0.0016986713744699955,
-0.02809607796370983,
-0.01603204384446144,
0.03458143025636673,
-0.017877383157610893,
0.001394670456647873,
0.06809619069099426,
0.01377070415765047,
0.0003171675489284098,
-0.012330700643360615,
0.030442750081419945,
-0.06310417503118515,
-0.027157407253980637,
0.10461895167827606,
0.02741340920329094,
-0.03852810710668564,
-0.014336039312183857,
-0.0027493408415466547,
0.008800024166703224,
0.008480023592710495,
-0.03872010484337807,
0.06246417015790939,
-0.010997363366186619,
-0.030080081894993782,
0.026709407567977905,
-0.0632321760058403,
0.01658671163022518,
0.00676801847293973,
-0.04247478395700455,
-0.01520004216581583,
0.04765879735350609,
0.06310417503118515,
0.0497494712471962,
0.06250683963298798,
0.02000005543231964,
-0.012821368873119354,
0.08695490658283234,
-0.0166720449924469,
0.017002712935209274,
0.007008019369095564,
-0.005562682170420885,
0.018304049968719482,
-0.016256045550107956,
0.011008030734956264,
-0.03921077400445938,
0.028821412473917007,
-0.030208082869648933,
-0.026282738894224167,
-0.04198411479592323,
-0.03424009308218956,
0.06472551077604294,
0.028714746236801147,
0.03876277431845665,
0.010602695867419243,
0.021493392065167427,
0.035498764365911484,
-0.023168062791228294,
0.016650712117552757,
-0.040128111839294434,
-0.023850731551647186,
0.013408036902546883,
-0.034090761095285416,
-0.05806949362158775,
-0.061269503086805344,
-0.02796807698905468,
-0.013834704644978046,
0.018325382843613625,
-0.029568081721663475,
-0.10726429522037506,
0.06660284847021103,
-0.03921077400445938,
-0.06340283900499344,
-0.0021813393104821444,
0.014837373979389668,
0.005213347729295492,
-0.015456042252480984,
-0.01608537696301937,
-0.0201067216694355,
-0.04646412655711174,
-0.019626719877123833,
-0.03018674999475479,
0.0032720090821385384,
0.007328019943088293,
0.0063466839492321014,
-0.01276803482323885,
0.02828807756304741,
0.04085344448685646,
-0.03874143958091736,
-0.02764807641506195,
-0.05657615512609482,
0.027818743139505386,
-0.017397381365299225,
-0.023808065801858902,
-0.020096056163311005,
0.03349342569708824,
0.036736100912094116,
-0.025173403322696686,
0.03479476273059845,
-0.021312057971954346,
0.009733360260725021,
0.0566188208758831,
0.03850677236914635,
-0.03897610679268837,
0.020938724279403687,
0.040576111525297165,
-0.021290725097060204,
-0.025962738320231438,
-0.0513281412422657,
-0.022186728194355965,
0.007824021391570568,
-0.0018480051076039672,
0.042112115770578384,
0.0014320039190351963,
-0.06830952316522598,
0.03251209110021591,
-0.012682701461017132,
0.025365402922034264,
0.036714766174554825,
-0.018613385036587715,
-0.05644815415143967,
0.000574334932025522,
0.05149880796670914,
-0.03005874902009964,
-0.04072544351220131,
-0.05111480876803398,
0.05085880681872368,
0.053589481860399246,
-0.018421383574604988,
-0.0009426692849956453,
0.011349364183843136,
0.04162144660949707,
-0.014112038537859917,
-0.029120080173015594,
-0.021888060495257378,
-0.05627748742699623,
-0.02151472494006157,
-0.06331750750541687,
-0.0033520092256367207,
0.013898705132305622,
-0.016757380217313766,
-0.012277367524802685,
0.02862941287457943,
-0.028565412387251854,
-0.0013706703903153539,
-0.040042776614427567,
0.018666718155145645,
0.018325382843613625,
0.003997344523668289,
-0.04492812231183052,
-0.012426700443029404,
-0.024640068411827087,
0.002370673231780529,
0.04017077758908272,
0.026922740042209625,
-0.03822943940758705,
-0.031488087028265,
0.03428276255726814,
-0.007386687211692333,
0.02019205503165722,
-0.008853357285261154,
0.03987210988998413,
-0.02941874787211418,
-0.0035493432078510523,
0.001313336892053485,
-0.0653655156493187,
-0.03758943825960159,
0.06370151042938232,
-0.04932280257344246,
0.0016160043887794018,
-0.02365873195230961,
0.029440080747008324,
0.034090761095285416,
0.020992057397961617,
-0.03225608915090561,
0.02862941287457943,
-0.00031600086367689073,
-0.04320012032985687,
-0.01452803984284401,
-0.024725401774048805,
0.02333873137831688,
0.0653655156493187,
-0.021845392882823944,
0.039594776928424835,
0.0010973362950608134,
-0.04573879390954971,
-0.06702952086925507,
0.007173352874815464,
0.02905607968568802,
0.022613395005464554,
-0.02764807641506195,
0.026581406593322754,
-0.022506728768348694,
-0.028501411899924278,
-0.02325339801609516,
-0.0359894335269928,
0.035840097814798355,
0.043093450367450714,
-0.046848129481077194,
0.04650679603219032,
0.04215478152036667,
0.007856021635234356,
-0.03185075521469116,
-0.004850680008530617,
0.045866791158914566,
0.024533400312066078,
-0.01033069472759962,
-0.007914688438177109,
-0.0203733891248703,
-0.03104008547961712,
-0.030912084504961967,
-0.022080060094594955,
0.036949433386325836,
-0.03490142896771431,
-0.014730706810951233,
-0.00963202677667141,
0.010997363366186619,
0.03897610679268837
]
|
31,245 | networkx.readwrite.graphml | write_graphml_lxml | Write G in GraphML XML format to path
This function uses the LXML framework and should be faster than
the version using the xml library.
Parameters
----------
G : graph
A networkx graph
path : file or string
File or filename to write.
Filenames ending in .gz or .bz2 will be compressed.
encoding : string (optional)
Encoding for text data.
prettyprint : bool (optional)
If True use line breaks and indenting in output XML.
infer_numeric_types : boolean
Determine if numeric types should be generalized.
For example, if edges have both int and float 'weight' attributes,
we infer in GraphML that both are floats.
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)
>>> nx.write_graphml_lxml(G, "fourpath.graphml")
Notes
-----
This implementation does not support mixed graphs (directed
and unidirected edges together) hyperedges, nested graphs, or ports.
| 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
| (G, path, encoding='utf-8', prettyprint=True, infer_numeric_types=False, named_key_ids=False, edge_id_from_attribute=None) | [
0.026204342022538185,
-0.016029145568609238,
-0.02867644838988781,
0.053713954985141754,
0.007663533557206392,
-0.0023818756453692913,
-0.07281840592622757,
0.03324490413069725,
0.020508605986833572,
-0.008701818995177746,
-0.019450543448328972,
-0.021932538598775864,
0.005849006585776806,
0.0644330158829689,
-0.002924503292888403,
0.026758093386888504,
0.013161500915884972,
0.0015289986040443182,
0.003807045752182603,
0.018155159428715706,
0.005601795855909586,
-0.05584985762834549,
-0.014120679348707199,
-0.000669941189698875,
0.044497936964035034,
0.00511231878772378,
0.01565338671207428,
0.018886903300881386,
0.020904142409563065,
0.012973621487617493,
-0.0617433600127697,
-0.10829809308052063,
-0.030377259477972984,
-0.039810821413993835,
0.042006053030490875,
0.031109003350138664,
-0.03698273003101349,
0.0313858799636364,
-0.06285086274147034,
-0.002013531746342778,
0.08337924629449844,
0.005092541687190533,
-0.010659728199243546,
-0.04481436684727669,
-0.0012039163848385215,
0.04896751046180725,
-0.01703776605427265,
0.07697154581546783,
-0.011826562695205212,
-0.04414195567369461,
0.03006082959473133,
-0.020202063024044037,
-0.00325576588511467,
0.10703237354755402,
-0.052250467240810394,
-0.00018726215057540685,
-0.027568945661187172,
0.025828581303358078,
-0.006684578955173492,
0.010768501088023186,
-0.0003125671064481139,
-0.0018602610798552632,
0.05873727798461914,
0.03108922578394413,
-0.06601516157388687,
0.027924928814172745,
-0.07297661900520325,
-0.03892086446285248,
-0.018165046349167824,
0.02764805220067501,
0.025353936478495598,
-0.01623680256307125,
0.023890448734164238,
0.028004035353660583,
-0.011994666419923306,
0.044933028519153595,
-0.01946043223142624,
0.01653345674276352,
-0.012667079456150532,
0.002823146991431713,
0.0051222071051597595,
0.02359379641711712,
-0.00009363107528770342,
-0.027074523270130157,
0.05588940903544426,
0.018095828592777252,
0.0028157306369394064,
0.030238820239901543,
-0.004375630524009466,
-0.05683869868516922,
-0.024958398193120956,
0.05058921128511429,
0.01627635769546032,
0.04801822081208229,
0.062376219779253006,
-0.0486510805785656,
-0.06213890016078949,
-0.07210643589496613,
0.03389754146337509,
0.007886023260653019,
-0.04615919291973114,
0.02304004319012165,
-0.03340311720967293,
-0.05719468370079994,
-0.04465615376830101,
-0.07633868604898453,
-0.026560325175523758,
-0.017828840762376785,
0.014348112978041172,
-0.006293985992670059,
-0.04623830318450928,
-0.05430725961923599,
0.0617433600127697,
0.034688614308834076,
0.004276746418327093,
0.003043164499104023,
0.019628534093499184,
0.02640211023390293,
0.05573119595646858,
-0.012459422461688519,
-0.007876135408878326,
0.013744918629527092,
-0.02058771252632141,
0.049165278673172,
0.008172787725925446,
-0.0177793987095356,
0.08100602775812149,
0.00859799049794674,
0.009398953057825565,
-0.02808314375579357,
0.004239664878696203,
-0.012963732704520226,
-0.004595648031681776,
0.015327067114412785,
0.04853241890668869,
-0.0806104838848114,
-0.04718759283423424,
0.018184823915362358,
-0.017462968826293945,
0.09492893517017365,
0.015505059622228146,
-0.08353745937347412,
0.03512370586395264,
0.03553901985287666,
-0.0816388800740242,
-0.006768630817532539,
-0.028300689533352852,
-0.021853432059288025,
-0.04560544341802597,
-0.08148066699504852,
0.029823506250977516,
-0.031722087413072586,
-0.03466883674263954,
-0.026758093386888504,
0.01978674903512001,
-0.019282439723610878,
-0.058539509773254395,
0.08132245391607285,
-0.017017988488078117,
-0.008593046106398106,
-0.03654763847589493,
-0.0013769639190286398,
0.07867235690355301,
-0.027885373681783676,
0.015534725040197372,
0.014180009253323078,
0.018748464062809944,
0.004674755502492189,
0.03122766502201557,
0.012093550525605679,
0.02347513474524021,
-0.04374641552567482,
-0.05980522930622101,
0.004778583999723196,
-0.0044745150953531265,
0.015416063368320465,
0.056087177246809006,
0.017502522096037865,
0.0392768457531929,
0.07471698522567749,
-0.015020526014268398,
-0.019628534093499184,
-0.014298670925199986,
0.011618905700743198,
0.022407183423638344,
-0.002850340213626623,
0.04722714424133301,
-0.03943506255745888,
0.03862420842051506,
-0.03884175419807434,
0.039672382175922394,
0.020943695679306984,
0.00015520201122853905,
0.054188601672649384,
0.039731714874506,
0.012845071032643318,
0.025769250467419624,
-0.03415463864803314,
-0.005735289771109819,
0.11494311690330505,
0.05913281440734863,
-0.007441044319421053,
0.056126732379198074,
-0.006140715442597866,
-0.0025932409334927797,
0.013082393445074558,
0.0052853659726679325,
-0.01814527064561844,
-0.031840745359659195,
0.004140780307352543,
0.009305013343691826,
-0.01924288645386696,
0.059963442385196686,
0.017433302477002144,
0.0026970694307237864,
-0.023435581475496292,
-0.07827682048082352,
0.026303226128220558,
-0.04619874805212021,
-0.042480699717998505,
-0.02574947290122509,
0.00462778564542532,
-0.042006053030490875,
-0.0496794767677784,
0.01667189411818981,
-0.06178291514515877,
0.0748356431722641,
-0.05284377187490463,
-0.025116613134741783,
0.025947242975234985,
0.0681510642170906,
0.04212471470236778,
0.03423374891281128,
0.04619874805212021,
0.001991282682865858,
-0.01565338671207428,
-0.012222100049257278,
-0.0008967570611275733,
-0.0053891949355602264,
-0.03775402903556824,
0.0104619599878788,
-0.053674403578042984,
-0.039731714874506,
-0.023712456226348877,
0.0035400581546127796,
0.00027594901621341705,
0.024345315992832184,
-0.004541261587291956,
-0.022802721709012985,
-0.015851154923439026,
-0.022367630153894424,
-0.018333150073885918,
0.0017551964847370982,
-0.006289042066782713,
0.03884175419807434,
-0.04679205268621445,
-0.05616628751158714,
-0.023653125390410423,
0.009077579714357853,
-0.017245423048734665,
0.019470319151878357,
0.03294825181365013,
-0.018204601481556892,
0.055019229650497437,
0.04580321162939072,
0.00031380317523144186,
0.00826672837138176,
0.005196370184421539,
-0.033996425569057465,
-0.02165566384792328,
0.09002427011728287,
-0.0012471782974898815,
-0.032572489231824875,
0.0035993887577205896,
0.020548159256577492,
-0.008607879281044006,
-0.010323521681129932,
0.014150344766676426,
-0.019401101395487785,
0.010541067458689213,
-0.020271282643079758,
-0.03631031885743141,
-0.012192434631288052,
0.03629054129123688,
-0.037655144929885864,
0.00547819072380662,
-0.029487300664186478,
0.0027613441925495863,
0.014061348512768745,
-0.042876236140728,
0.037477150559425354,
0.014209674671292305,
-0.05430725961923599,
0.030634358525276184,
-0.027588721364736557,
-0.022031422704458237,
0.017532188445329666,
-0.018629804253578186,
0.017423415556550026,
0.012617637403309345,
0.0695749968290329,
-0.020291060209274292,
0.13203032314777374,
-0.018461700528860092,
-0.02183365449309349,
-0.006012165918946266,
0.03532147407531738,
0.006595583166927099,
0.002025892259553075,
0.016731224954128265,
-0.07796038687229156,
0.03219673037528992,
0.017344307154417038,
0.032572489231824875,
-0.057550664991140366,
0.03603344038128853,
0.04165007174015045,
-0.0366465225815773,
0.08100602775812149,
0.05549387261271477,
-0.03259226679801941,
0.02545282058417797,
-0.03217695280909538,
-0.029210424050688744,
-0.018125493079423904,
-0.00043014672701247036,
0.08709729462862015,
0.02165566384792328,
0.04042390361428261,
-0.03006082959473133,
-0.047424912452697754,
-0.007436099927872419,
-0.037318937480449677,
0.05766932666301727,
-0.058539509773254395,
0.03678496181964874,
0.0007960186921991408,
-0.05964701250195503,
0.011609017848968506,
-0.030594805255532265,
0.022624729201197624,
0.004457210190594196,
-0.03992948308587074,
0.0019195915665477514,
0.020508605986833572,
-0.01143102627247572,
-0.004672283306717873,
-0.03466883674263954,
-0.03166275471448898,
0.039731714874506,
-0.016296133399009705,
0.04853241890668869,
0.00047804383211769164,
0.04481436684727669,
0.03364044055342674,
-0.013013174757361412,
-0.013191166333854198,
-0.02881488762795925,
-0.01836281642317772,
0.05047054961323738,
-0.008983639068901539,
0.04311355948448181,
0.009611554443836212,
0.028775332495570183,
0.026856977492570877,
-0.008949030190706253,
0.03065413422882557,
0.02209075354039669,
0.05149894580245018,
-0.02794470451772213,
0.015633609145879745,
-0.06083362549543381,
-0.03678496181964874,
0.004318771883845329,
-0.004432489164173603,
0.04188739135861397,
-0.001627882942557335,
0.06229711323976517,
0.030337706208229065,
-0.06249488145112991,
-0.004209999460726976,
0.019331881776452065,
0.002171746687963605,
0.03733871504664421,
0.003243405371904373,
-0.06759731471538544,
0.11612973362207413,
-0.008064014837145805,
0.006175324786454439,
0.005858895368874073,
0.007317438721656799,
-0.0021408451721072197,
0.014427220448851585,
-0.010002147406339645,
-0.011144261807203293,
-0.006956511177122593,
0.04908616840839386,
0.00930995773524046,
-0.006832905579358339,
-0.019519763067364693,
-0.02080525830388069,
-0.0681510642170906,
-0.017008101567626,
0.07934476435184479,
0.02476062998175621,
-0.0014919169479981065,
-0.006229711230844259,
-0.02640211023390293,
0.05343708023428917,
0.04469570517539978,
0.02007351443171501,
-0.016592787578701973,
-0.012835183180868626,
-0.020686596632003784,
0.050312336534261703,
0.014882088638842106,
0.0023485023993998766,
0.011292587965726852,
0.041017211973667145,
0.025433043017983437,
-0.008291449397802353,
0.09223928302526474,
0.051301177591085434,
0.01802660897374153,
-0.019401101395487785,
-0.01656312122941017,
-0.04315311089158058,
0.032532937824726105,
-0.11035488545894623,
0.08116424083709717,
0.04176872968673706,
-0.03844621777534485,
0.013220831751823425,
-0.039296623319387436,
-0.0054683019407093525,
0.010135641321539879,
0.025907687842845917,
-0.03925706818699837,
0.04675250127911568,
0.0034387018531560898,
0.0006238981732167304,
-0.011648571118712425,
-0.02545282058417797,
-0.029566407203674316,
-0.015238071791827679,
-0.040245912969112396,
-0.04548678174614906,
0.05929103121161461,
0.03265159949660301,
0.027410730719566345,
0.0025660477112978697,
-0.011945224367082119,
0.05861861631274223,
-0.03057502768933773,
-0.05141983926296234,
-0.003802101593464613,
0.05826263502240181,
-0.04991679638624191,
0.02794470451772213,
0.00782669335603714,
0.03605321794748306,
-0.0209239199757576,
-0.028834663331508636,
0.0319000780582428,
-0.04307400435209274,
0.006363205146044493,
0.021556779742240906,
-0.0036117492709308863,
-0.03534125164151192,
0.006783463526517153,
0.0628904178738594,
-0.017492633312940598,
-0.017650848254561424,
-0.05399082973599434,
-0.017542075365781784,
-0.018184823915362358,
-0.045407675206661224,
-0.0006140097393654287,
-0.01689932867884636,
-0.032750483602285385,
0.003001138800755143,
-0.015603943727910519,
0.013754807412624359,
-0.0033645385410636663,
-0.0020061153918504715,
0.031623199582099915,
0.04528901353478432,
-0.05351618677377701,
-0.04014702886343002,
0.031583648175001144,
-0.04568454995751381,
-0.025630813091993332,
-0.028953325003385544,
0.01645434834063053,
0.041056763380765915,
0.03328445926308632,
0.007757473737001419,
-0.04263891279697418,
-0.04766223579645157,
-0.058974601328372955,
-0.01821448840200901,
-0.06368149071931839,
-0.04584276303648949,
-0.025591257959604263,
0.03587522730231285,
0.03122766502201557,
-0.020647043362259865,
0.04042390361428261,
0.02695586159825325,
0.02739095315337181,
-0.014990860596299171,
-0.05592896416783333,
-0.00018200892372988164,
0.03591477870941162,
0.010986046865582466,
-0.04370686411857605,
-0.0026550437323749065,
0.00907263532280922,
-0.009216017089784145,
-0.05058921128511429,
0.034431517124176025,
0.026599878445267677,
-0.009923039935529232,
0.014249228872358799,
-0.04908616840839386,
0.054069940000772476,
-0.05066831782460213,
-0.0372200533747673,
0.0035993887577205896,
0.02080525830388069,
0.0015747325960546732,
0.02644166350364685,
-0.0012768435990437865,
0.0361323244869709,
0.029091762378811836,
0.0045190127566456795,
0.07669466733932495,
0.010798166505992413,
-0.03101011924445629,
-0.0634046196937561,
-0.007445988245308399,
0.003243405371904373,
-0.020904142409563065,
-0.0037501873448491096,
0.03267137333750725,
0.015356732532382011,
0.034431517124176025,
0.015505059622228146,
-0.002956640673801303,
-0.06985187530517578,
-0.029170870780944824,
0.0335020050406456,
0.025907687842845917,
0.012983509339392185,
0.02661965601146221,
-0.06292997300624847,
0.0193516593426466,
-0.02321803569793701,
0.037358492612838745,
0.006580750457942486,
-0.007643756922334433,
0.0175222996622324,
-0.048295095562934875,
-0.024622192606329918,
0.043469540774822235,
-0.00027378593222238123,
0.02661965601146221,
-0.05834174156188965,
-0.046871162950992584,
0.02618456445634365,
-0.025472598150372505,
0.008879810571670532,
-0.00288989394903183,
-0.06526364386081696,
-0.014021794311702251,
0.0028429238591343164,
-0.05062876641750336,
0.045447226613759995,
0.027114076539874077,
-0.052171360701322556,
-0.03160342574119568,
0.05252734199166298,
0.041570961475372314,
0.014506327919661999,
0.08749283105134964,
-0.011984777636826038,
0.01748274452984333,
0.03846599534153938,
-0.010303745046257973,
-0.0008219758165068924,
-0.05549387261271477,
-0.07724841684103012,
-0.0024362620897591114,
-0.043034449219703674,
-0.015603943727910519,
0.005201314575970173,
0.051736269146203995,
-0.04841375723481178,
-0.03053547441959381,
-0.014110790565609932,
-0.04066122695803642,
0.009616498835384846,
0.00331509648822248,
0.018886903300881386,
-0.013557038269937038,
0.012350649572908878,
-0.033007580786943436,
0.021477671340107918,
0.0034535343293100595,
-0.002672348404303193,
-0.0014783203369006515,
0.042085159569978714,
-0.015603943727910519,
-0.02812269702553749,
-0.020745927467942238,
-0.018273819237947464,
-0.033007580786943436,
0.03112877905368805,
-0.005379306152462959,
0.0031099114567041397,
0.02592746540904045,
-0.02885444089770317,
-0.04433972388505936,
-0.021754547953605652,
-0.03919773921370506,
0.040404126048088074,
-0.017937613651156425,
-0.03456995263695717,
0.012370427139103413,
0.0066400812938809395,
0.04513079673051834,
-0.06830927729606628,
0.0471084825694561,
-0.03061458095908165,
0.021260125562548637,
-0.03474794700741768,
0.04141274839639664,
0.05889549478888512,
-0.013220831751823425,
0.0030555250123143196,
-0.004254497122019529,
0.029685068875551224,
-0.019658200442790985,
-0.029388416558504105,
-0.006753798108547926,
0.038564879447221756,
0.061426930129528046,
-0.041056763380765915,
0.018224377185106277,
-0.019519763067364693,
-0.016652116551995277,
0.013210942968726158,
0.04034479707479477,
-0.04240158945322037,
0.031366102397441864,
0.02011306770145893,
-0.034471068531274796,
-0.0010957617778331041,
-0.018006831407546997,
-0.03290869668126106,
-0.012330872938036919,
-0.010086199268698692,
0.04283668100833893,
-0.025769250467419624,
-0.02519572153687477,
-0.0040542567148804665,
0.00828650500625372,
0.004491819534450769,
0.014872199855744839,
-0.03288891911506653,
-0.06637115031480789,
-0.004741502460092306,
0.04920483008027077,
-0.007119670044630766,
-0.054149046540260315,
-0.030594805255532265,
0.019994406029582024,
0.014713984914124012,
-0.03010038286447525,
-0.0004041896027047187,
0.015742382034659386,
0.05937013775110245,
-0.008078848011791706,
-0.05577074736356735,
-0.053713954985141754,
-0.011371695436537266,
-0.008350779302418232,
-0.0554543174803257,
-0.015129298903048038,
-0.02311915159225464,
-0.026125233620405197,
-0.05232957378029823,
0.05735289677977562,
-0.03010038286447525,
0.029981721192598343,
-0.07724841684103012,
0.024365093559026718,
0.031366102397441864,
0.0020493771880865097,
-0.05213180556893349,
-0.02845890261232853,
-0.03134632483124733,
-0.01252864208072424,
0.017097096890211105,
0.025294605642557144,
0.007174056489020586,
-0.04085899516940117,
0.045012135058641434,
0.026323001831769943,
0.04952125996351242,
-0.028102919459342957,
0.011628794483840466,
-0.0019183555850759149,
-0.012103439308702946,
0.006536252796649933,
0.022585175931453705,
-0.013072505593299866,
0.017581630498170853,
-0.08258817344903946,
0.025808803737163544,
-0.042006053030490875,
0.03866376355290413,
0.02966529130935669,
0.012340761721134186,
-0.017729956656694412,
-0.008345835842192173,
0.0075250957161188126,
-0.035420358180999756,
0.005339752417057753,
-0.01730475388467312,
-0.025353936478495598,
0.0360729955136776,
-0.018451811745762825,
0.08033361285924911,
-0.01931210421025753,
-0.019905410706996918,
-0.009062746539711952,
-0.003614221466705203,
0.008736428804695606,
0.021497448906302452,
-0.017008101567626,
-0.015485282056033611,
-0.0890749841928482,
0.031207887455821037,
-0.011885893531143665,
-0.029744399711489677,
0.06107094883918762,
0.046475622802972794,
-0.05383261665701866,
0.023574018850922585,
0.04528901353478432,
-0.001703282236121595,
-0.033561334013938904,
0.03049592114984989,
0.0445374920964241,
0.010659728199243546,
0.06170380860567093,
-0.0047489190474152565,
0.01784861646592617,
-0.07578492909669876,
-0.014862311072647572,
-0.027371175587177277,
0.005918225739151239,
-0.030693689361214638,
0.03547969087958336,
0.07471698522567749,
-0.0027119021397083998,
0.06360238790512085
]
|
31,247 | networkx.readwrite.graphml | write_graphml_xml | Write G in GraphML XML format to path
Parameters
----------
G : graph
A networkx graph
path : file or string
File or filename to write.
Filenames ending in .gz or .bz2 will be compressed.
encoding : string (optional)
Encoding for text data.
prettyprint : bool (optional)
If True use line breaks and indenting in output XML.
infer_numeric_types : boolean
Determine if numeric types should be generalized.
For example, if edges have both int and float 'weight' attributes,
we infer in GraphML that both are floats.
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)
>>> nx.write_graphml(G, "test.graphml")
Notes
-----
This implementation does not support mixed graphs (directed
and unidirected edges together) hyperedges, nested graphs, or ports.
| 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
| (G, path, encoding='utf-8', prettyprint=True, infer_numeric_types=False, named_key_ids=False, edge_id_from_attribute=None) | [
0.026204342022538185,
-0.016029145568609238,
-0.02867644838988781,
0.053713954985141754,
0.007663533557206392,
-0.0023818756453692913,
-0.07281840592622757,
0.03324490413069725,
0.020508605986833572,
-0.008701818995177746,
-0.019450543448328972,
-0.021932538598775864,
0.005849006585776806,
0.0644330158829689,
-0.002924503292888403,
0.026758093386888504,
0.013161500915884972,
0.0015289986040443182,
0.003807045752182603,
0.018155159428715706,
0.005601795855909586,
-0.05584985762834549,
-0.014120679348707199,
-0.000669941189698875,
0.044497936964035034,
0.00511231878772378,
0.01565338671207428,
0.018886903300881386,
0.020904142409563065,
0.012973621487617493,
-0.0617433600127697,
-0.10829809308052063,
-0.030377259477972984,
-0.039810821413993835,
0.042006053030490875,
0.031109003350138664,
-0.03698273003101349,
0.0313858799636364,
-0.06285086274147034,
-0.002013531746342778,
0.08337924629449844,
0.005092541687190533,
-0.010659728199243546,
-0.04481436684727669,
-0.0012039163848385215,
0.04896751046180725,
-0.01703776605427265,
0.07697154581546783,
-0.011826562695205212,
-0.04414195567369461,
0.03006082959473133,
-0.020202063024044037,
-0.00325576588511467,
0.10703237354755402,
-0.052250467240810394,
-0.00018726215057540685,
-0.027568945661187172,
0.025828581303358078,
-0.006684578955173492,
0.010768501088023186,
-0.0003125671064481139,
-0.0018602610798552632,
0.05873727798461914,
0.03108922578394413,
-0.06601516157388687,
0.027924928814172745,
-0.07297661900520325,
-0.03892086446285248,
-0.018165046349167824,
0.02764805220067501,
0.025353936478495598,
-0.01623680256307125,
0.023890448734164238,
0.028004035353660583,
-0.011994666419923306,
0.044933028519153595,
-0.01946043223142624,
0.01653345674276352,
-0.012667079456150532,
0.002823146991431713,
0.0051222071051597595,
0.02359379641711712,
-0.00009363107528770342,
-0.027074523270130157,
0.05588940903544426,
0.018095828592777252,
0.0028157306369394064,
0.030238820239901543,
-0.004375630524009466,
-0.05683869868516922,
-0.024958398193120956,
0.05058921128511429,
0.01627635769546032,
0.04801822081208229,
0.062376219779253006,
-0.0486510805785656,
-0.06213890016078949,
-0.07210643589496613,
0.03389754146337509,
0.007886023260653019,
-0.04615919291973114,
0.02304004319012165,
-0.03340311720967293,
-0.05719468370079994,
-0.04465615376830101,
-0.07633868604898453,
-0.026560325175523758,
-0.017828840762376785,
0.014348112978041172,
-0.006293985992670059,
-0.04623830318450928,
-0.05430725961923599,
0.0617433600127697,
0.034688614308834076,
0.004276746418327093,
0.003043164499104023,
0.019628534093499184,
0.02640211023390293,
0.05573119595646858,
-0.012459422461688519,
-0.007876135408878326,
0.013744918629527092,
-0.02058771252632141,
0.049165278673172,
0.008172787725925446,
-0.0177793987095356,
0.08100602775812149,
0.00859799049794674,
0.009398953057825565,
-0.02808314375579357,
0.004239664878696203,
-0.012963732704520226,
-0.004595648031681776,
0.015327067114412785,
0.04853241890668869,
-0.0806104838848114,
-0.04718759283423424,
0.018184823915362358,
-0.017462968826293945,
0.09492893517017365,
0.015505059622228146,
-0.08353745937347412,
0.03512370586395264,
0.03553901985287666,
-0.0816388800740242,
-0.006768630817532539,
-0.028300689533352852,
-0.021853432059288025,
-0.04560544341802597,
-0.08148066699504852,
0.029823506250977516,
-0.031722087413072586,
-0.03466883674263954,
-0.026758093386888504,
0.01978674903512001,
-0.019282439723610878,
-0.058539509773254395,
0.08132245391607285,
-0.017017988488078117,
-0.008593046106398106,
-0.03654763847589493,
-0.0013769639190286398,
0.07867235690355301,
-0.027885373681783676,
0.015534725040197372,
0.014180009253323078,
0.018748464062809944,
0.004674755502492189,
0.03122766502201557,
0.012093550525605679,
0.02347513474524021,
-0.04374641552567482,
-0.05980522930622101,
0.004778583999723196,
-0.0044745150953531265,
0.015416063368320465,
0.056087177246809006,
0.017502522096037865,
0.0392768457531929,
0.07471698522567749,
-0.015020526014268398,
-0.019628534093499184,
-0.014298670925199986,
0.011618905700743198,
0.022407183423638344,
-0.002850340213626623,
0.04722714424133301,
-0.03943506255745888,
0.03862420842051506,
-0.03884175419807434,
0.039672382175922394,
0.020943695679306984,
0.00015520201122853905,
0.054188601672649384,
0.039731714874506,
0.012845071032643318,
0.025769250467419624,
-0.03415463864803314,
-0.005735289771109819,
0.11494311690330505,
0.05913281440734863,
-0.007441044319421053,
0.056126732379198074,
-0.006140715442597866,
-0.0025932409334927797,
0.013082393445074558,
0.0052853659726679325,
-0.01814527064561844,
-0.031840745359659195,
0.004140780307352543,
0.009305013343691826,
-0.01924288645386696,
0.059963442385196686,
0.017433302477002144,
0.0026970694307237864,
-0.023435581475496292,
-0.07827682048082352,
0.026303226128220558,
-0.04619874805212021,
-0.042480699717998505,
-0.02574947290122509,
0.00462778564542532,
-0.042006053030490875,
-0.0496794767677784,
0.01667189411818981,
-0.06178291514515877,
0.0748356431722641,
-0.05284377187490463,
-0.025116613134741783,
0.025947242975234985,
0.0681510642170906,
0.04212471470236778,
0.03423374891281128,
0.04619874805212021,
0.001991282682865858,
-0.01565338671207428,
-0.012222100049257278,
-0.0008967570611275733,
-0.0053891949355602264,
-0.03775402903556824,
0.0104619599878788,
-0.053674403578042984,
-0.039731714874506,
-0.023712456226348877,
0.0035400581546127796,
0.00027594901621341705,
0.024345315992832184,
-0.004541261587291956,
-0.022802721709012985,
-0.015851154923439026,
-0.022367630153894424,
-0.018333150073885918,
0.0017551964847370982,
-0.006289042066782713,
0.03884175419807434,
-0.04679205268621445,
-0.05616628751158714,
-0.023653125390410423,
0.009077579714357853,
-0.017245423048734665,
0.019470319151878357,
0.03294825181365013,
-0.018204601481556892,
0.055019229650497437,
0.04580321162939072,
0.00031380317523144186,
0.00826672837138176,
0.005196370184421539,
-0.033996425569057465,
-0.02165566384792328,
0.09002427011728287,
-0.0012471782974898815,
-0.032572489231824875,
0.0035993887577205896,
0.020548159256577492,
-0.008607879281044006,
-0.010323521681129932,
0.014150344766676426,
-0.019401101395487785,
0.010541067458689213,
-0.020271282643079758,
-0.03631031885743141,
-0.012192434631288052,
0.03629054129123688,
-0.037655144929885864,
0.00547819072380662,
-0.029487300664186478,
0.0027613441925495863,
0.014061348512768745,
-0.042876236140728,
0.037477150559425354,
0.014209674671292305,
-0.05430725961923599,
0.030634358525276184,
-0.027588721364736557,
-0.022031422704458237,
0.017532188445329666,
-0.018629804253578186,
0.017423415556550026,
0.012617637403309345,
0.0695749968290329,
-0.020291060209274292,
0.13203032314777374,
-0.018461700528860092,
-0.02183365449309349,
-0.006012165918946266,
0.03532147407531738,
0.006595583166927099,
0.002025892259553075,
0.016731224954128265,
-0.07796038687229156,
0.03219673037528992,
0.017344307154417038,
0.032572489231824875,
-0.057550664991140366,
0.03603344038128853,
0.04165007174015045,
-0.0366465225815773,
0.08100602775812149,
0.05549387261271477,
-0.03259226679801941,
0.02545282058417797,
-0.03217695280909538,
-0.029210424050688744,
-0.018125493079423904,
-0.00043014672701247036,
0.08709729462862015,
0.02165566384792328,
0.04042390361428261,
-0.03006082959473133,
-0.047424912452697754,
-0.007436099927872419,
-0.037318937480449677,
0.05766932666301727,
-0.058539509773254395,
0.03678496181964874,
0.0007960186921991408,
-0.05964701250195503,
0.011609017848968506,
-0.030594805255532265,
0.022624729201197624,
0.004457210190594196,
-0.03992948308587074,
0.0019195915665477514,
0.020508605986833572,
-0.01143102627247572,
-0.004672283306717873,
-0.03466883674263954,
-0.03166275471448898,
0.039731714874506,
-0.016296133399009705,
0.04853241890668869,
0.00047804383211769164,
0.04481436684727669,
0.03364044055342674,
-0.013013174757361412,
-0.013191166333854198,
-0.02881488762795925,
-0.01836281642317772,
0.05047054961323738,
-0.008983639068901539,
0.04311355948448181,
0.009611554443836212,
0.028775332495570183,
0.026856977492570877,
-0.008949030190706253,
0.03065413422882557,
0.02209075354039669,
0.05149894580245018,
-0.02794470451772213,
0.015633609145879745,
-0.06083362549543381,
-0.03678496181964874,
0.004318771883845329,
-0.004432489164173603,
0.04188739135861397,
-0.001627882942557335,
0.06229711323976517,
0.030337706208229065,
-0.06249488145112991,
-0.004209999460726976,
0.019331881776452065,
0.002171746687963605,
0.03733871504664421,
0.003243405371904373,
-0.06759731471538544,
0.11612973362207413,
-0.008064014837145805,
0.006175324786454439,
0.005858895368874073,
0.007317438721656799,
-0.0021408451721072197,
0.014427220448851585,
-0.010002147406339645,
-0.011144261807203293,
-0.006956511177122593,
0.04908616840839386,
0.00930995773524046,
-0.006832905579358339,
-0.019519763067364693,
-0.02080525830388069,
-0.0681510642170906,
-0.017008101567626,
0.07934476435184479,
0.02476062998175621,
-0.0014919169479981065,
-0.006229711230844259,
-0.02640211023390293,
0.05343708023428917,
0.04469570517539978,
0.02007351443171501,
-0.016592787578701973,
-0.012835183180868626,
-0.020686596632003784,
0.050312336534261703,
0.014882088638842106,
0.0023485023993998766,
0.011292587965726852,
0.041017211973667145,
0.025433043017983437,
-0.008291449397802353,
0.09223928302526474,
0.051301177591085434,
0.01802660897374153,
-0.019401101395487785,
-0.01656312122941017,
-0.04315311089158058,
0.032532937824726105,
-0.11035488545894623,
0.08116424083709717,
0.04176872968673706,
-0.03844621777534485,
0.013220831751823425,
-0.039296623319387436,
-0.0054683019407093525,
0.010135641321539879,
0.025907687842845917,
-0.03925706818699837,
0.04675250127911568,
0.0034387018531560898,
0.0006238981732167304,
-0.011648571118712425,
-0.02545282058417797,
-0.029566407203674316,
-0.015238071791827679,
-0.040245912969112396,
-0.04548678174614906,
0.05929103121161461,
0.03265159949660301,
0.027410730719566345,
0.0025660477112978697,
-0.011945224367082119,
0.05861861631274223,
-0.03057502768933773,
-0.05141983926296234,
-0.003802101593464613,
0.05826263502240181,
-0.04991679638624191,
0.02794470451772213,
0.00782669335603714,
0.03605321794748306,
-0.0209239199757576,
-0.028834663331508636,
0.0319000780582428,
-0.04307400435209274,
0.006363205146044493,
0.021556779742240906,
-0.0036117492709308863,
-0.03534125164151192,
0.006783463526517153,
0.0628904178738594,
-0.017492633312940598,
-0.017650848254561424,
-0.05399082973599434,
-0.017542075365781784,
-0.018184823915362358,
-0.045407675206661224,
-0.0006140097393654287,
-0.01689932867884636,
-0.032750483602285385,
0.003001138800755143,
-0.015603943727910519,
0.013754807412624359,
-0.0033645385410636663,
-0.0020061153918504715,
0.031623199582099915,
0.04528901353478432,
-0.05351618677377701,
-0.04014702886343002,
0.031583648175001144,
-0.04568454995751381,
-0.025630813091993332,
-0.028953325003385544,
0.01645434834063053,
0.041056763380765915,
0.03328445926308632,
0.007757473737001419,
-0.04263891279697418,
-0.04766223579645157,
-0.058974601328372955,
-0.01821448840200901,
-0.06368149071931839,
-0.04584276303648949,
-0.025591257959604263,
0.03587522730231285,
0.03122766502201557,
-0.020647043362259865,
0.04042390361428261,
0.02695586159825325,
0.02739095315337181,
-0.014990860596299171,
-0.05592896416783333,
-0.00018200892372988164,
0.03591477870941162,
0.010986046865582466,
-0.04370686411857605,
-0.0026550437323749065,
0.00907263532280922,
-0.009216017089784145,
-0.05058921128511429,
0.034431517124176025,
0.026599878445267677,
-0.009923039935529232,
0.014249228872358799,
-0.04908616840839386,
0.054069940000772476,
-0.05066831782460213,
-0.0372200533747673,
0.0035993887577205896,
0.02080525830388069,
0.0015747325960546732,
0.02644166350364685,
-0.0012768435990437865,
0.0361323244869709,
0.029091762378811836,
0.0045190127566456795,
0.07669466733932495,
0.010798166505992413,
-0.03101011924445629,
-0.0634046196937561,
-0.007445988245308399,
0.003243405371904373,
-0.020904142409563065,
-0.0037501873448491096,
0.03267137333750725,
0.015356732532382011,
0.034431517124176025,
0.015505059622228146,
-0.002956640673801303,
-0.06985187530517578,
-0.029170870780944824,
0.0335020050406456,
0.025907687842845917,
0.012983509339392185,
0.02661965601146221,
-0.06292997300624847,
0.0193516593426466,
-0.02321803569793701,
0.037358492612838745,
0.006580750457942486,
-0.007643756922334433,
0.0175222996622324,
-0.048295095562934875,
-0.024622192606329918,
0.043469540774822235,
-0.00027378593222238123,
0.02661965601146221,
-0.05834174156188965,
-0.046871162950992584,
0.02618456445634365,
-0.025472598150372505,
0.008879810571670532,
-0.00288989394903183,
-0.06526364386081696,
-0.014021794311702251,
0.0028429238591343164,
-0.05062876641750336,
0.045447226613759995,
0.027114076539874077,
-0.052171360701322556,
-0.03160342574119568,
0.05252734199166298,
0.041570961475372314,
0.014506327919661999,
0.08749283105134964,
-0.011984777636826038,
0.01748274452984333,
0.03846599534153938,
-0.010303745046257973,
-0.0008219758165068924,
-0.05549387261271477,
-0.07724841684103012,
-0.0024362620897591114,
-0.043034449219703674,
-0.015603943727910519,
0.005201314575970173,
0.051736269146203995,
-0.04841375723481178,
-0.03053547441959381,
-0.014110790565609932,
-0.04066122695803642,
0.009616498835384846,
0.00331509648822248,
0.018886903300881386,
-0.013557038269937038,
0.012350649572908878,
-0.033007580786943436,
0.021477671340107918,
0.0034535343293100595,
-0.002672348404303193,
-0.0014783203369006515,
0.042085159569978714,
-0.015603943727910519,
-0.02812269702553749,
-0.020745927467942238,
-0.018273819237947464,
-0.033007580786943436,
0.03112877905368805,
-0.005379306152462959,
0.0031099114567041397,
0.02592746540904045,
-0.02885444089770317,
-0.04433972388505936,
-0.021754547953605652,
-0.03919773921370506,
0.040404126048088074,
-0.017937613651156425,
-0.03456995263695717,
0.012370427139103413,
0.0066400812938809395,
0.04513079673051834,
-0.06830927729606628,
0.0471084825694561,
-0.03061458095908165,
0.021260125562548637,
-0.03474794700741768,
0.04141274839639664,
0.05889549478888512,
-0.013220831751823425,
0.0030555250123143196,
-0.004254497122019529,
0.029685068875551224,
-0.019658200442790985,
-0.029388416558504105,
-0.006753798108547926,
0.038564879447221756,
0.061426930129528046,
-0.041056763380765915,
0.018224377185106277,
-0.019519763067364693,
-0.016652116551995277,
0.013210942968726158,
0.04034479707479477,
-0.04240158945322037,
0.031366102397441864,
0.02011306770145893,
-0.034471068531274796,
-0.0010957617778331041,
-0.018006831407546997,
-0.03290869668126106,
-0.012330872938036919,
-0.010086199268698692,
0.04283668100833893,
-0.025769250467419624,
-0.02519572153687477,
-0.0040542567148804665,
0.00828650500625372,
0.004491819534450769,
0.014872199855744839,
-0.03288891911506653,
-0.06637115031480789,
-0.004741502460092306,
0.04920483008027077,
-0.007119670044630766,
-0.054149046540260315,
-0.030594805255532265,
0.019994406029582024,
0.014713984914124012,
-0.03010038286447525,
-0.0004041896027047187,
0.015742382034659386,
0.05937013775110245,
-0.008078848011791706,
-0.05577074736356735,
-0.053713954985141754,
-0.011371695436537266,
-0.008350779302418232,
-0.0554543174803257,
-0.015129298903048038,
-0.02311915159225464,
-0.026125233620405197,
-0.05232957378029823,
0.05735289677977562,
-0.03010038286447525,
0.029981721192598343,
-0.07724841684103012,
0.024365093559026718,
0.031366102397441864,
0.0020493771880865097,
-0.05213180556893349,
-0.02845890261232853,
-0.03134632483124733,
-0.01252864208072424,
0.017097096890211105,
0.025294605642557144,
0.007174056489020586,
-0.04085899516940117,
0.045012135058641434,
0.026323001831769943,
0.04952125996351242,
-0.028102919459342957,
0.011628794483840466,
-0.0019183555850759149,
-0.012103439308702946,
0.006536252796649933,
0.022585175931453705,
-0.013072505593299866,
0.017581630498170853,
-0.08258817344903946,
0.025808803737163544,
-0.042006053030490875,
0.03866376355290413,
0.02966529130935669,
0.012340761721134186,
-0.017729956656694412,
-0.008345835842192173,
0.0075250957161188126,
-0.035420358180999756,
0.005339752417057753,
-0.01730475388467312,
-0.025353936478495598,
0.0360729955136776,
-0.018451811745762825,
0.08033361285924911,
-0.01931210421025753,
-0.019905410706996918,
-0.009062746539711952,
-0.003614221466705203,
0.008736428804695606,
0.021497448906302452,
-0.017008101567626,
-0.015485282056033611,
-0.0890749841928482,
0.031207887455821037,
-0.011885893531143665,
-0.029744399711489677,
0.06107094883918762,
0.046475622802972794,
-0.05383261665701866,
0.023574018850922585,
0.04528901353478432,
-0.001703282236121595,
-0.033561334013938904,
0.03049592114984989,
0.0445374920964241,
0.010659728199243546,
0.06170380860567093,
-0.0047489190474152565,
0.01784861646592617,
-0.07578492909669876,
-0.014862311072647572,
-0.027371175587177277,
0.005918225739151239,
-0.030693689361214638,
0.03547969087958336,
0.07471698522567749,
-0.0027119021397083998,
0.06360238790512085
]
|
31,250 | networkx.readwrite.text | write_network_text | Creates a nice text representation of a graph
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.
Parameters
----------
graph : nx.DiGraph | nx.Graph
Graph to represent
path : string or file or callable or None
Filename or file handle for data output.
if a function, then it will be called for each generated line.
if None, this will default to "sys.stdout.write"
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
end : string
The line ending character
vertical_chains : Boolean
If True, chains of nodes will be drawn vertically when possible.
Examples
--------
>>> graph = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
>>> nx.write_network_text(graph)
╙── 0
├─╼ 1
│ ├─╼ 3
│ └─╼ 4
└─╼ 2
├─╼ 5
└─╼ 6
>>> # A near tree with one non-tree edge
>>> graph.add_edge(5, 1)
>>> nx.write_network_text(graph)
╙── 0
├─╼ 1 ╾ 5
│ ├─╼ 3
│ └─╼ 4
└─╼ 2
├─╼ 5
│ └─╼ ...
└─╼ 6
>>> graph = nx.cycle_graph(5)
>>> nx.write_network_text(graph)
╙── 0
├── 1
│ └── 2
│ └── 3
│ └── 4 ─ 0
└── ...
>>> graph = nx.cycle_graph(5, nx.DiGraph)
>>> nx.write_network_text(graph, vertical_chains=True)
╙── 0 ╾ 4
╽
1
╽
2
╽
3
╽
4
└─╼ ...
>>> nx.write_network_text(graph, vertical_chains=True, ascii_only=True)
+-- 0 <- 4
!
1
!
2
!
3
!
4
L-> ...
>>> graph = nx.generators.barbell_graph(4, 2)
>>> nx.write_network_text(graph, vertical_chains=False)
╙── 4
├── 5
│ └── 6
│ ├── 7
│ │ ├── 8 ─ 6
│ │ │ └── 9 ─ 6, 7
│ │ └── ...
│ └── ...
└── 3
├── 0
│ ├── 1 ─ 3
│ │ └── 2 ─ 0, 3
│ └── ...
└── ...
>>> nx.write_network_text(graph, vertical_chains=True)
╙── 4
├── 5
│ │
│ 6
│ ├── 7
│ │ ├── 8 ─ 6
│ │ │ │
│ │ │ 9 ─ 6, 7
│ │ └── ...
│ └── ...
└── 3
├── 0
│ ├── 1 ─ 3
│ │ │
│ │ 2 ─ 0, 3
│ └── ...
└── ...
>>> graph = nx.complete_graph(5, create_using=nx.Graph)
>>> nx.write_network_text(graph)
╙── 0
├── 1
│ ├── 2 ─ 0
│ │ ├── 3 ─ 0, 1
│ │ │ └── 4 ─ 0, 1, 2
│ │ └── ...
│ └── ...
└── ...
>>> graph = nx.complete_graph(3, create_using=nx.DiGraph)
>>> nx.write_network_text(graph)
╙── 0 ╾ 1, 2
├─╼ 1 ╾ 2
│ ├─╼ 2 ╾ 0
│ │ └─╼ ...
│ └─╼ ...
└─╼ ...
| def _parse_network_text(lines):
"""Reconstructs a graph from a network text representation.
This is mainly used for testing. Network text is for display, not
serialization, as such this cannot parse all network text representations
because node labels can be ambiguous with the glyphs and indentation used
to represent edge structure. Additionally, there is no way to determine if
disconnected graphs were originally directed or undirected.
Parameters
----------
lines : list or iterator of strings
Input data in network text format
Returns
-------
G: NetworkX graph
The graph corresponding to the lines in network text format.
"""
from itertools import chain
from typing import Any, NamedTuple, Union
class ParseStackFrame(NamedTuple):
node: Any
indent: int
has_vertical_child: int | None
initial_line_iter = iter(lines)
is_ascii = None
is_directed = None
##############
# Initial Pass
##############
# Do an initial pass over the lines to determine what type of graph it is.
# Remember what these lines were, so we can reiterate over them in the
# parsing pass.
initial_lines = []
try:
first_line = next(initial_line_iter)
except StopIteration:
...
else:
initial_lines.append(first_line)
# The first character indicates if it is an ASCII or UTF graph
first_char = first_line[0]
if first_char in {
UtfBaseGlyphs.empty,
UtfBaseGlyphs.newtree_mid[0],
UtfBaseGlyphs.newtree_last[0],
}:
is_ascii = False
elif first_char in {
AsciiBaseGlyphs.empty,
AsciiBaseGlyphs.newtree_mid[0],
AsciiBaseGlyphs.newtree_last[0],
}:
is_ascii = True
else:
raise AssertionError(f"Unexpected first character: {first_char}")
if is_ascii:
directed_glyphs = AsciiDirectedGlyphs.as_dict()
undirected_glyphs = AsciiUndirectedGlyphs.as_dict()
else:
directed_glyphs = UtfDirectedGlyphs.as_dict()
undirected_glyphs = UtfUndirectedGlyphs.as_dict()
# For both directed / undirected glyphs, determine which glyphs never
# appear as substrings in the other undirected / directed glyphs. Glyphs
# with this property unambiguously indicates if a graph is directed /
# undirected.
directed_items = set(directed_glyphs.values())
undirected_items = set(undirected_glyphs.values())
unambiguous_directed_items = []
for item in directed_items:
other_items = undirected_items
other_supersets = [other for other in other_items if item in other]
if not other_supersets:
unambiguous_directed_items.append(item)
unambiguous_undirected_items = []
for item in undirected_items:
other_items = directed_items
other_supersets = [other for other in other_items if item in other]
if not other_supersets:
unambiguous_undirected_items.append(item)
for line in initial_line_iter:
initial_lines.append(line)
if any(item in line for item in unambiguous_undirected_items):
is_directed = False
break
elif any(item in line for item in unambiguous_directed_items):
is_directed = True
break
if is_directed is None:
# Not enough information to determine, choose undirected by default
is_directed = False
glyphs = directed_glyphs if is_directed else undirected_glyphs
# the backedge symbol by itself can be ambiguous, but with spaces around it
# becomes unambiguous.
backedge_symbol = " " + glyphs["backedge"] + " "
# Reconstruct an iterator over all of the lines.
parsing_line_iter = chain(initial_lines, initial_line_iter)
##############
# Parsing Pass
##############
edges = []
nodes = []
is_empty = None
noparent = object() # sentinel value
# keep a stack of previous nodes that could be parents of subsequent nodes
stack = [ParseStackFrame(noparent, -1, None)]
for line in parsing_line_iter:
if line == glyphs["empty"]:
# If the line is the empty glyph, we are done.
# There shouldn't be anything else after this.
is_empty = True
continue
if backedge_symbol in line:
# This line has one or more backedges, separate those out
node_part, backedge_part = line.split(backedge_symbol)
backedge_nodes = [u.strip() for u in backedge_part.split(", ")]
# Now the node can be parsed
node_part = node_part.rstrip()
prefix, node = node_part.rsplit(" ", 1)
node = node.strip()
# Add the backedges to the edge list
edges.extend([(u, node) for u in backedge_nodes])
else:
# No backedge, the tail of this line is the node
prefix, node = line.rsplit(" ", 1)
node = node.strip()
prev = stack.pop()
if node in glyphs["vertical_edge"]:
# Previous node is still the previous node, but we know it will
# have exactly one child, which will need to have its nesting level
# adjusted.
modified_prev = ParseStackFrame(
prev.node,
prev.indent,
True,
)
stack.append(modified_prev)
continue
# The length of the string before the node characters give us a hint
# about our nesting level. The only case where this doesn't work is
# when there are vertical chains, which is handled explicitly.
indent = len(prefix)
curr = ParseStackFrame(node, indent, None)
if prev.has_vertical_child:
# In this case we know prev must be the parent of our current line,
# so we don't have to search the stack. (which is good because the
# indentation check wouldn't work in this case).
...
else:
# If the previous node nesting-level is greater than the current
# nodes nesting-level than the previous node was the end of a path,
# and is not our parent. We can safely pop nodes off the stack
# until we find one with a comparable nesting-level, which is our
# parent.
while curr.indent <= prev.indent:
prev = stack.pop()
if node == "...":
# The current previous node is no longer a valid parent,
# keep it popped from the stack.
stack.append(prev)
else:
# The previous and current nodes may still be parents, so add them
# back onto the stack.
stack.append(prev)
stack.append(curr)
# Add the node and the edge to its parent to the node / edge lists.
nodes.append(curr.node)
if prev.node is not noparent:
edges.append((prev.node, curr.node))
if is_empty:
# Sanity check
assert len(nodes) == 0
# Reconstruct the graph
cls = nx.DiGraph if is_directed else nx.Graph
new = cls()
new.add_nodes_from(nodes)
new.add_edges_from(edges)
return new
| (graph, path=None, with_labels=True, sources=None, max_depth=None, ascii_only=False, end='\n', vertical_chains=False) | [
-0.0021010010968893766,
0.02256331965327263,
-0.030431341379880905,
0.013998000882565975,
-0.06535869836807251,
-0.010084805078804493,
-0.027475630864501,
0.06585825234651566,
0.08342600613832474,
-0.0670655146241188,
0.020263276994228363,
0.0445854552090168,
-0.021730724722146988,
0.04106774181127548,
-0.041525669395923615,
0.042254187166690826,
0.000025286815798608586,
-0.008534097112715244,
-0.0051568844355642796,
0.023312656208872795,
-0.06660758703947067,
-0.025498216971755028,
0.0317843072116375,
0.03211734816431999,
0.03915277123451233,
0.0039210012182593346,
-0.004319085739552975,
0.0004335347330197692,
-0.018712569028139114,
-0.014091667719185352,
-0.002227191114798188,
-0.0511629544198513,
-0.05844815820455551,
-0.01586093194782734,
0.01355048082768917,
0.014299816451966763,
-0.03619706258177757,
-0.011333697475492954,
-0.04400263726711273,
-0.030639490112662315,
-0.02533169835805893,
-0.02042979560792446,
0.016183562576770782,
-0.004324289504438639,
-0.030472971498966217,
0.00888274610042572,
0.0025862478651106358,
0.01793201081454754,
-0.023520804941654205,
-0.06860581785440445,
0.012103847227990627,
-0.03621787577867508,
0.007389279548078775,
0.05457659438252449,
0.0008696713484823704,
-0.03788306564092636,
-0.009038858115673065,
0.040693074464797974,
0.024374214932322502,
-0.03382416442036629,
0.01815056800842285,
0.005729293450713158,
-0.012936442159116268,
0.024478288367390633,
-0.04187951982021332,
0.009959915652871132,
0.017255527898669243,
-0.076723612844944,
-0.07955443859100342,
-0.00867459736764431,
-0.03130556643009186,
0.028058446943759918,
0.0073632607236504555,
-0.015684004873037338,
0.019451497122645378,
-0.0015025734901428223,
-0.009080487303435802,
0.03176349401473999,
-0.012499330565333366,
-0.004535039886832237,
0.011031881906092167,
0.07039589434862137,
0.002579743042588234,
-0.04945613443851471,
0.05882282555103302,
-0.021272799000144005,
0.05803186073899269,
0.07818065583705902,
-0.04312841221690178,
0.012228736653923988,
-0.03600972890853882,
-0.013363147154450417,
0.017609382048249245,
0.05062176659703255,
0.0023898074869066477,
-0.007555798161774874,
0.01797364093363285,
-0.09499907493591309,
0.02360406331717968,
-0.028662078082561493,
-0.0002805129042826593,
0.0608210526406765,
-0.07197782397270203,
-0.02710096165537834,
-0.06456772983074188,
-0.000600704166572541,
-0.04708324000239372,
0.010043174959719181,
0.03865321725606918,
-0.06694062799215317,
-0.07734806090593338,
-0.07380953431129456,
0.04085959121584892,
-0.0035827597603201866,
0.04358633980154991,
-0.010381417348980904,
-0.04479360207915306,
-0.03172186389565468,
0.034885723143815994,
-0.01394596416503191,
-0.006624332629144192,
0.0019722089637070894,
-0.056699708104133606,
0.04333656281232834,
-0.018254641443490982,
-0.05819838121533394,
0.056699708104133606,
0.0039626313373446465,
0.041733816266059875,
-0.06623291969299316,
0.04783257469534874,
0.020346537232398987,
-0.013435999862849712,
0.03746676817536354,
-0.008992024697363377,
0.02028409205377102,
-0.046750202775001526,
0.005463903769850731,
-0.01883745938539505,
-0.011687550693750381,
0.04541805014014244,
-0.04720812663435936,
0.011042289435863495,
-0.009652896784245968,
-0.09183521568775177,
0.018098531290888786,
0.0269552581012249,
-0.0584065280854702,
-0.04924798384308815,
-0.0126138124614954,
-0.010397028177976608,
-0.05857304856181145,
-0.053410958498716354,
0.019430682063102722,
0.04102611169219017,
-0.028349854052066803,
-0.1012435331940651,
0.006494239903986454,
0.018546050414443016,
0.03909032791852951,
-0.04520989954471588,
-0.052203696221113205,
0.015215670689940453,
-0.009392710402607918,
0.004012066405266523,
0.011323289945721626,
0.01067802868783474,
-0.06311068683862686,
-0.05370236933231354,
0.03255445882678032,
0.018441975116729736,
0.033470313996076584,
-0.0936669185757637,
0.011635513044893742,
-0.005536755546927452,
-0.002677312819287181,
0.03222142159938812,
0.06003008782863617,
-0.014299816451966763,
0.03013993427157402,
-0.018566865473985672,
-0.0197012759745121,
-0.023687323555350304,
0.0001428583200322464,
0.04695834964513779,
0.004896698519587517,
0.04912309721112251,
0.010235712863504887,
0.06490077078342438,
-0.015840116888284683,
-0.03413638845086098,
-0.022625764831900597,
0.06873070448637009,
0.07201945781707764,
0.0715615302324295,
-0.02889104187488556,
0.012416070327162743,
0.011312882415950298,
-0.01889990270137787,
-0.008622560650110245,
-0.02705933339893818,
0.014039631001651287,
0.04662531241774559,
-0.049372874200344086,
-0.051371101289987564,
0.02187643013894558,
-0.04254559800028801,
0.03045215643942356,
-0.06148713082075119,
0.05640830099582672,
-0.07713991403579712,
-0.045293159782886505,
0.08284318447113037,
-0.0029427025001496077,
-0.0380287691950798,
-0.0784720629453659,
-0.01928497850894928,
0.08392556011676788,
0.016579044982790947,
-0.03009830415248871,
0.03480246663093567,
0.027850298210978508,
-0.039173588156700134,
-0.05224532634019852,
-0.01023050956428051,
-0.0490814670920372,
0.0032028884161263704,
0.047541167587041855,
0.05590874329209328,
-0.008336355909705162,
0.04883168637752533,
-0.04620901495218277,
0.016579044982790947,
-0.00808657705783844,
0.03424046188592911,
-0.020866908133029938,
0.023042062297463417,
-0.010599973611533642,
0.02543577365577221,
-0.004790022037923336,
-0.06689899414777756,
-0.03517713397741318,
-0.03376172110438347,
-0.04412752762436867,
0.04198359698057175,
0.025810441002249718,
0.059530530124902725,
-0.021418502554297447,
-0.045085012912750244,
0.005086634308099747,
-0.0018160975305363536,
0.012332811020314693,
0.022750655189156532,
-0.009184561669826508,
-0.005469107534736395,
-0.018327495083212852,
-0.013290295377373695,
-0.05865630879998207,
0.060529645532369614,
0.04244152083992958,
0.015496672131121159,
0.0009060973534360528,
-0.0019227737793698907,
0.0414840392768383,
0.03324135020375252,
-0.011500216089189053,
-0.002584946807473898,
0.0031274345237761736,
-0.039798032492399216,
-0.018608495593070984,
0.045085012912750244,
0.0023611870128661394,
0.004480401054024696,
0.07039589434862137,
-0.01980534940958023,
0.01297807227820158,
-0.022209467366337776,
-0.0004998821532353759,
-0.011822846718132496,
-0.011260845698416233,
-0.04358633980154991,
0.0190143845975399,
-0.01914968155324459,
-0.014716113917529583,
0.007888835854828358,
-0.03894462436437607,
-0.011375327594578266,
-0.06989634037017822,
-0.02187643013894558,
-0.034302908927202225,
0.06623291969299316,
-0.04027677699923515,
0.010423046536743641,
0.007165519520640373,
0.06968818604946136,
0.011011066846549511,
0.006999000441282988,
-0.01810893788933754,
-0.009897471405565739,
-0.0015637172618880868,
0.03193001076579094,
-0.05794860050082207,
0.11140119284391403,
-0.002971322974190116,
0.0011298572644591331,
0.025248438119888306,
-0.02699688822031021,
-0.0037258618976920843,
-0.0006462367018684745,
-0.045293159782886505,
-0.034302908927202225,
0.02474888227880001,
-0.013467221520841122,
-0.00826350413262844,
-0.019160088151693344,
0.018670938909053802,
0.01755734346807003,
0.0004540243826340884,
0.06398491561412811,
0.02318776585161686,
-0.043461449444293976,
0.018119346350431442,
-0.0216058362275362,
0.03066030517220497,
0.0031872771214693785,
0.017984049394726753,
0.05557570606470108,
0.05053850635886192,
0.03600972890853882,
-0.013998000882565975,
0.052994661033153534,
0.00043190858559682965,
-0.02139768749475479,
-0.0011669336818158627,
-0.04683345928788185,
0.026309996843338013,
-0.0009685420081950724,
0.013581703417003155,
0.023000432178378105,
-0.07480864971876144,
0.07310182601213455,
0.025206809863448143,
0.014414298348128796,
-0.008815097622573376,
0.053660739213228226,
0.006728406995534897,
0.022417616099119186,
0.005708478391170502,
-0.011375327594578266,
0.12863589823246002,
-0.0418170765042305,
0.05420192331075668,
-0.02302124723792076,
0.021199947223067284,
-0.018951939418911934,
-0.021418502554297447,
-0.02139768749475479,
-0.03661336004734039,
0.015767265111207962,
0.013914741575717926,
0.05224532634019852,
0.0252276249229908,
-0.004313881974667311,
0.018962347880005836,
0.0025159975048154593,
-0.0660247728228569,
0.008986820466816425,
0.06244461238384247,
0.027871113270521164,
-0.017359603196382523,
0.0008963404106907547,
-0.009959915652871132,
0.0034656759817153215,
-0.04579271748661995,
-0.036238692700862885,
0.024103621020913124,
0.034094758331775665,
0.0262683667242527,
0.023728953674435616,
0.01415411289781332,
-0.0038585567381232977,
0.02297961711883545,
-0.027142591774463654,
0.01815056800842285,
0.03950662538409233,
-0.01707860268652439,
0.05661645159125328,
0.00554716307669878,
0.053827255964279175,
-0.02495703101158142,
-0.047166500240564346,
-0.0035801578778773546,
0.046708572655916214,
0.016402117908000946,
-0.0008260902250185609,
-0.030493786558508873,
0.03376172110438347,
-0.0005867191939614713,
-0.03856995701789856,
0.00021595429279841483,
-0.025914514437317848,
0.02093975991010666,
-0.0052011157386004925,
0.0425039678812027,
0.024998661130666733,
0.02114790864288807,
0.061362240463495255,
0.05328607186675072,
0.005593996495008469,
0.04337819293141365,
0.05903097614645958,
-0.004753596149384975,
-0.0469999797642231,
-0.038486696779727936,
-0.029744451865553856,
-0.0025784422177821398,
0.008513282053172588,
0.028911856934428215,
0.0331789031624794,
-0.006541073322296143,
-0.018535643815994263,
0.053452588617801666,
0.016017043963074684,
0.008658986538648605,
0.023999545723199844,
0.019899016246199608,
-0.06244461238384247,
-0.008128207176923752,
-0.016391711309552193,
0.031222306191921234,
0.0222927276045084,
-0.06003008782863617,
0.03263771906495094,
-0.03638439625501633,
-0.009580044075846672,
-0.0005766369868069887,
-0.01883745938539505,
-0.04616738483309746,
0.01026173122227192,
0.021439317613840103,
-0.02302124723792076,
0.010511510074138641,
0.009111709892749786,
-0.01752612181007862,
0.029453042894601822,
-0.022542506456375122,
-0.03673824667930603,
0.027496445924043655,
-0.053660739213228226,
-0.00998593494296074,
-0.020762834697961807,
0.00277358153834939,
-0.004173381719738245,
-0.02031531371176243,
-0.08338437229394913,
0.02250087633728981,
0.05482637137174606,
0.08800527453422546,
-0.025248438119888306,
0.06993796676397324,
0.004134353715926409,
0.06781484931707382,
-0.001767963171005249,
0.04504338279366493,
-0.005854182410985231,
0.03925684839487076,
0.03877810388803482,
0.027038518339395523,
-0.054659850895404816,
-0.0111463638022542,
0.014487150125205517,
-0.05644993111491203,
-0.038902994245290756,
-0.006036312784999609,
0.03459431603550911,
-0.006457814015448093,
-0.014726521447300911,
-0.05295303091406822,
-0.04870679974555969,
-0.034469425678253174,
-0.00914293248206377,
-0.04040166363120079,
-0.003036369336768985,
-0.013810667209327221,
0.02318776585161686,
-0.0015389994950965047,
0.05191228911280632,
-0.02087731659412384,
-0.019846979528665543,
-0.029744451865553856,
-0.0736013874411583,
-0.03538528084754944,
-0.022480061277747154,
0.004352909978479147,
0.012228736653923988,
0.04579271748661995,
-0.020263276994228363,
-0.027642149478197098,
0.02710096165537834,
-0.10648888349533081,
0.010292953811585903,
-0.04179626330733299,
-0.020169610157608986,
-0.027662964537739754,
0.04025596007704735,
0.08255177736282349,
0.02533169835805893,
0.04745790734887123,
0.014528780244290829,
-0.028224965557456017,
0.00502939336001873,
0.004860272631049156,
0.04745790734887123,
0.011406549252569675,
-0.03020237758755684,
0.0490814670920372,
0.012738700956106186,
0.010069194249808788,
-0.0017926808213815093,
-0.007113482337445021,
0.011521031148731709,
-0.003949621692299843,
0.016443748027086258,
-0.023271026089787483,
0.005698070861399174,
0.024353399872779846,
0.023583250120282173,
0.025456586852669716,
0.04579271748661995,
-0.04337819293141365,
0.01828586496412754,
0.04027677699923515,
0.055242668837308884,
0.003054582281038165,
0.05878119543194771,
-0.005911423359066248,
0.0632355809211731,
-0.016443748027086258,
0.0069001298397779465,
-0.006405776832252741,
0.02826659567654133,
-0.00008691834955243394,
-0.07289367914199829,
0.004766605328768492,
-0.009673711843788624,
-0.04912309721112251,
0.07780598849058151,
-0.014414298348128796,
-0.0033850185573101044,
-0.00031905295327305794,
-0.05307792127132416,
0.002703331410884857,
0.010511510074138641,
0.01669352687895298,
0.030577046796679497,
-0.03294994309544563,
-0.006848092656582594,
0.02312532253563404,
0.0414632223546505,
0.0003883274330291897,
-0.03294994309544563,
0.02114790864288807,
-0.048540279269218445,
-0.058947715908288956,
0.04275374487042427,
0.03823691979050636,
-0.02737155556678772,
0.03600972890853882,
0.008523689582943916,
0.02156420610845089,
0.027184221893548965,
0.01548626460134983,
0.027246667072176933,
0.01242647785693407,
-0.031263936311006546,
-0.00498516159132123,
-0.04891494661569595,
0.01631885953247547,
0.04067225754261017,
-0.013092554174363613,
0.0369880273938179,
0.028641263023018837,
0.013644148595631123,
0.04267048463225365,
0.022521691396832466,
0.004652123898267746,
0.004974754061549902,
0.047749314457178116,
-0.02042979560792446,
-0.015340560115873814,
-0.018025677651166916,
-0.03394905477762222,
0.0445854552090168,
0.0034682778641581535,
-0.010344991460442543,
-0.004443975165486336,
0.07351812720298767,
0.025290068238973618,
-0.04471034184098244,
-0.06369350850582123,
-0.05232858657836914,
0.02114790864288807,
0.007425705436617136,
0.03861158713698387,
0.04036003723740578,
-0.01724512130022049,
0.03240875527262688,
-0.012301589362323284,
-0.002314353594556451,
-0.007717113476246595,
0.031201492995023727,
0.0445854552090168,
-0.008565319702029228,
-0.05844815820455551,
-0.0380079559981823,
-0.045501310378313065,
-0.013748222962021828,
0.002305246889591217,
-0.007243575062602758,
-0.00278659095056355,
0.050996433943510056,
-0.04150485247373581,
-0.02658059075474739,
0.018608495593070984,
-0.028558002784848213,
0.04662531241774559,
0.0003714153717737645,
-0.03821610286831856,
-0.014320631511509418,
-0.027871113270521164,
0.04533478990197182,
-0.02443665824830532,
-0.031014157459139824,
0.003356398083269596,
-0.028745336458086967,
-0.030223192647099495,
0.03480246663093567,
-0.008679801598191261,
-0.021543391048908234,
0.03020237758755684,
-0.030119119212031364,
-0.06931351870298386,
-0.036654990166425705,
-0.0007122588576748967,
-0.047291386872529984,
0.01109432615339756,
0.013290295377373695,
-0.06003008782863617,
0.03093089908361435,
0.05166251212358475,
0.03894462436437607,
0.05857304856181145,
0.022937988862395287,
-0.0240203607827425,
0.002306547947227955,
0.07547472417354584,
0.01073006633669138,
-0.016912082210183144,
-0.01000674907118082,
-0.00408752029761672,
0.03436535224318504,
0.00719674164429307,
0.031118232756853104,
0.05307792127132416,
0.022521691396832466,
0.0369880273938179,
0.053619109094142914,
0.03228386491537094,
0.046916719526052475,
-0.03424046188592911,
-0.04400263726711273,
-0.013581703417003155,
0.012249551713466644,
-0.021834800019860268,
-0.03272097930312157,
-0.017099415883421898,
0.016703933477401733,
0.013769037090241909,
0.0414840392768383,
-0.02287554368376732,
-0.015548708848655224,
0.05353584885597229,
-0.04479360207915306,
-0.08067844063043594,
-0.006161201745271683,
0.0005935490480624139,
-0.009590451605618,
-0.032158974558115005,
0.04749953746795654,
-0.06040475517511368,
-0.007534983567893505,
0.02156420610845089,
0.019919831305742264,
0.027288297191262245,
-0.019794942811131477,
-0.017089009284973145,
-0.021897245198488235,
-0.08463326841592789,
-0.034885723143815994,
-0.03605135530233383,
0.05374399945139885,
-0.005198514088988304,
-0.021199947223067284,
-0.02395791746675968,
0.024728067219257355,
-0.0031170269940048456,
-0.09724707901477814,
0.04475197196006775,
-0.03280423581600189,
0.050580136477947235,
-0.01627722941339016,
-0.02166828140616417,
0.0028074057772755623,
-0.006478628609329462,
0.027767037972807884,
-0.03138882666826248,
0.006770037114620209,
0.011000659316778183,
-0.035822395235300064,
0.01171877235174179,
-0.007436112966388464,
0.042358264327049255,
0.018473198637366295,
0.046750202775001526,
-0.04391937702894211,
0.020377758890390396,
-0.03934010863304138,
-0.041692186146974564,
-0.01444552093744278,
-0.033262163400650024,
-0.039277661591768265,
0.07518331706523895,
-0.012457700446248055,
0.03340786695480347,
-0.04262885823845863,
-0.07347649335861206,
-0.01834830828011036,
-0.0018720375373959541,
0.02957793138921261,
0.024103621020913124,
-0.013935556635260582,
-0.055658966302871704,
-0.0933338850736618,
0.02098139002919197,
-0.051787398755550385,
0.01109432615339756,
0.037133730947971344,
0.06510891765356064,
-0.007940873503684998,
0.0048680780455470085,
0.045501310378313065,
-0.04056818410754204,
-0.03307482972741127,
0.00851848628371954,
0.011906106024980545,
0.037175361067056656,
-0.00973095279186964,
-0.00038182278512977064,
-0.03086845390498638,
-0.027767037972807884,
-0.000022359725335263647,
-0.014549595303833485,
0.03792469576001167,
-0.006057127378880978,
0.00034832386882044375,
-0.013633741065859795,
0.009923489764332771,
0.08509119600057602
]
|
31,253 | networkx.readwrite.edgelist | write_weighted_edgelist | Write graph G as a list of edges with numeric weights.
Parameters
----------
G : graph
A NetworkX graph
path : file or string
File or filename to write. If a file is provided, it must be
opened in 'wb' mode.
Filenames ending in .gz or .bz2 will be compressed.
comments : string, optional
The character used to indicate the start of a comment
delimiter : string, optional
The string used to separate values. The default is whitespace.
encoding: string, optional
Specify which encoding to use when writing file.
Examples
--------
>>> G = nx.Graph()
>>> G.add_edge(1, 2, weight=7)
>>> nx.write_weighted_edgelist(G, "test.weighted.edgelist")
See Also
--------
read_edgelist
write_edgelist
read_weighted_edgelist
| def write_weighted_edgelist(G, path, comments="#", delimiter=" ", encoding="utf-8"):
"""Write graph G as a list of edges with numeric weights.
Parameters
----------
G : graph
A NetworkX graph
path : file or string
File or filename to write. If a file is provided, it must be
opened in 'wb' mode.
Filenames ending in .gz or .bz2 will be compressed.
comments : string, optional
The character used to indicate the start of a comment
delimiter : string, optional
The string used to separate values. The default is whitespace.
encoding: string, optional
Specify which encoding to use when writing file.
Examples
--------
>>> G = nx.Graph()
>>> G.add_edge(1, 2, weight=7)
>>> nx.write_weighted_edgelist(G, "test.weighted.edgelist")
See Also
--------
read_edgelist
write_edgelist
read_weighted_edgelist
"""
write_edgelist(
G,
path,
comments=comments,
delimiter=delimiter,
data=("weight",),
encoding=encoding,
)
| (G, path, comments='#', delimiter=' ', encoding='utf-8') | [
0.04331774637103081,
0.040650397539138794,
-0.03261278569698334,
-0.01824466697871685,
0.04210854694247246,
-0.03851651772856712,
-0.04797671362757683,
0.0005337476031854749,
0.014092492870986462,
0.03855208307504654,
0.05960635468363762,
-0.00753970630466938,
-0.007375219836831093,
0.011407362297177315,
-0.0021405473817139864,
0.055267468094825745,
-0.02942974865436554,
-0.03773409500718117,
0.033466339111328125,
0.03819643706083298,
-0.0159329641610384,
-0.12319595366716385,
-0.0019238253589719534,
0.023632710799574852,
0.02998100221157074,
-0.03006991371512413,
-0.008250999264419079,
0.012136436998844147,
0.011425144039094448,
0.006454984191805124,
-0.02905631996691227,
-0.08948066085577011,
-0.029536442831158638,
-0.0175867211073637,
0.013932452537119389,
0.02233460173010826,
-0.03872990608215332,
-0.006543895695358515,
0.006392746232450008,
-0.012829948216676712,
0.04317548871040344,
0.02477077953517437,
0.00828656367957592,
-0.012536539696156979,
0.014225861057639122,
0.05420053005218506,
-0.01336341816931963,
-0.006277161184698343,
-0.019720599055290222,
-0.012189784087240696,
0.005663670599460602,
0.025286467745900154,
-0.030692294239997864,
0.01963168755173683,
0.011958613991737366,
-0.011860811151564121,
0.03723619133234024,
-0.02208564803004265,
0.02037854492664337,
-0.002387277316302061,
0.0004806784854736179,
-0.039156682789325714,
0.050786323845386505,
-0.010865001007914543,
0.02085866779088974,
0.02299254760146141,
-0.04904365539550781,
-0.03295065090060234,
-0.005774810444563627,
0.018760353326797485,
0.041112735867500305,
-0.012492083944380283,
0.02048523910343647,
0.008873380720615387,
-0.0081042954698205,
0.0448470264673233,
0.012883295305073261,
0.028451722115278244,
-0.038018614053726196,
0.0011247320799157023,
0.02670905366539955,
0.014448139816522598,
0.019969552755355835,
0.025837719440460205,
0.07148495316505432,
-0.010616048239171505,
-0.015159432776272297,
0.009602456353604794,
0.016777625307440758,
-0.03127910941839218,
0.002010514261201024,
0.015408385545015335,
-0.009709149599075317,
-0.027171393856406212,
-0.006570569239556789,
-0.05743691325187683,
-0.02877180278301239,
-0.053667061030864716,
0.009006747975945473,
0.007424121256917715,
-0.024450698867440224,
-0.015959637239575386,
-0.04562944918870926,
0.007152940612286329,
0.014777112752199173,
-0.07390334457159042,
-0.004783445503562689,
0.015017174184322357,
-0.016982121393084526,
-0.05288463830947876,
0.039049986749887466,
0.023419322445988655,
0.08236773312091827,
-0.018760353326797485,
0.05067962780594826,
0.06294943392276764,
0.033928677439689636,
0.0214277021586895,
0.08350580185651779,
-0.0013347858330234885,
0.022850288078188896,
-0.027669299393892288,
-0.059641920030117035,
0.07397447526454926,
0.0073974477127194405,
0.026958005502820015,
-0.008682220242917538,
-0.0070106820203363895,
0.030425559729337692,
0.004494482651352882,
0.02624671347439289,
0.02215677872300148,
0.020716410130262375,
0.01833357848227024,
0.011976396664977074,
-0.01956055872142315,
-0.06255821883678436,
0.008602200075984001,
0.09581117331981659,
-0.04740767925977707,
0.01826244778931141,
-0.1094679981470108,
0.038018614053726196,
0.03620481491088867,
0.007410784251987934,
-0.03261278569698334,
-0.014492595568299294,
0.024468479678034782,
0.02541094273328781,
0.0009491316159255803,
0.033661942929029465,
0.03472888097167015,
0.005965970456600189,
-0.08805807679891586,
0.040081363171339035,
0.0014614849351346493,
-0.06191805750131607,
0.0571523942053318,
0.01675984263420105,
0.002152772853150964,
0.00207164091989398,
0.010873892344534397,
-0.009878082200884819,
0.06245153024792671,
-0.0022539098281413317,
0.03129689395427704,
0.06451427936553955,
0.014092492870986462,
-0.019596122205257416,
0.015292800031602383,
0.064834363758564,
-0.0955977812409401,
-0.03769852966070175,
0.003136357758194208,
0.027064699679613113,
0.017275528982281685,
0.010171490721404552,
0.057365782558918,
0.019329387694597244,
0.05352479964494705,
0.013585696928203106,
-0.03577803820371628,
0.017017686739563942,
-0.007553042843937874,
0.009104550816118717,
-0.03535126522183418,
0.007868679240345955,
-0.04897252470254898,
-0.016599800437688828,
-0.011158409528434277,
0.01359458826482296,
-0.028825150802731514,
0.016439760103821754,
-0.004756771959364414,
-0.012669906951487064,
0.001171410665847361,
0.013816867023706436,
0.00837547518312931,
-0.050608500838279724,
0.06938663870096207,
0.06547452509403229,
-0.0053213611245155334,
0.028345027938485146,
-0.017008794471621513,
0.023899445310235023,
0.028736239299178123,
0.003847650717943907,
-0.07674852013587952,
-0.019862858578562737,
-0.03851651772856712,
0.020894233137369156,
0.021089838817715645,
0.01113173644989729,
0.019809510558843613,
0.015479514375329018,
0.06053103879094124,
-0.052386730909347534,
0.05476956441998482,
-0.01916934736073017,
-0.05910845100879669,
-0.030301082879304886,
-0.00002801063601509668,
-0.04794115200638771,
0.02978539653122425,
0.08457273989915848,
-0.04811897501349449,
0.0200051162391901,
-0.08919614553451538,
-0.018973741680383682,
0.05235116556286812,
0.06035321578383446,
0.04402903839945793,
0.018955959007143974,
-0.007255189120769501,
0.0039032206404954195,
0.008362138643860817,
-0.0348355770111084,
-0.01122953835874796,
0.01722218282520771,
0.017355550080537796,
-0.01854696497321129,
-0.043068792670965195,
-0.009958102367818356,
-0.026744619011878967,
0.03709392994642258,
-0.009620238095521927,
0.0008079844410531223,
-0.020058464258909225,
0.015532861463725567,
0.003203041385859251,
-0.027864905074238777,
0.002509530633687973,
-0.03399980813264847,
-0.026869093999266624,
-0.009851408191025257,
0.05213778093457222,
-0.05743691325187683,
-0.019489429891109467,
-0.06853308528661728,
0.021943390369415283,
0.007246297784149647,
0.00894006434828043,
-0.01705325022339821,
-0.0007212955970317125,
0.08884049952030182,
0.02149883285164833,
0.02076975628733635,
0.016466433182358742,
-0.04182403162121773,
0.0026584577281028032,
-0.09588230401277542,
-0.013327852822840214,
-0.00042649797978810966,
-0.019133782014250755,
-0.00642386544495821,
0.0022850288078188896,
0.027918251231312752,
0.08606645464897156,
0.014172513969242573,
-0.007077365648001432,
-0.03823200240731239,
0.03638263791799545,
-0.018084624782204628,
0.0707736536860466,
-0.07952255755662918,
0.07817110419273376,
0.002087200526148081,
0.02521533891558647,
0.005428054835647345,
-0.04466920346021652,
0.08250999450683594,
0.0028473949059844017,
0.05960635468363762,
0.03862321004271507,
0.05629884451627731,
0.017257748171687126,
0.05772142857313156,
-0.023152587935328484,
0.08620871603488922,
0.013096682727336884,
0.03684497997164726,
0.008873380720615387,
0.08620871603488922,
0.00022728035401087254,
-0.03752070665359497,
-0.02980317734181881,
0.01770230568945408,
-0.02811385691165924,
-0.021907825022935867,
-0.009549109265208244,
-0.04982607811689377,
-0.005219112616032362,
-0.05484069138765335,
0.043068792670965195,
0.03983240947127342,
-0.026833530515432358,
-0.008259890601038933,
-0.017355550080537796,
0.005761473439633846,
-0.020414110273122787,
-0.029376402497291565,
0.03940563276410103,
0.059641920030117035,
0.0158262699842453,
-0.07020462304353714,
0.04783445596694946,
-0.015950746834278107,
0.029643137007951736,
0.021072056144475937,
-0.06031765043735504,
-0.0007285196334123611,
-0.0187959186732769,
-0.007455240003764629,
0.019578341394662857,
-0.012083090841770172,
0.04125499725341797,
0.042215242981910706,
0.001488158362917602,
-0.05850385129451752,
-0.029163014143705368,
-0.01826244778931141,
0.010367096401751041,
-0.00034814458922483027,
0.06209588050842285,
0.01466152723878622,
0.009060095064342022,
-0.005677007604390383,
-0.02978539653122425,
-0.021160967648029327,
0.05615658685564995,
0.046874210238456726,
0.03576025739312172,
-0.02057415060698986,
0.02987430803477764,
0.013479002751410007,
-0.07852675020694733,
-0.001493715331889689,
-0.029572008177638054,
0.00354979676194489,
0.03855208307504654,
-0.052386730909347534,
0.02169443666934967,
0.05235116556286812,
0.04029475152492523,
0.007668627891689539,
0.0021994514390826225,
0.03531569987535477,
0.02133879065513611,
0.01323004998266697,
-0.0010841662297025323,
0.0002981318102683872,
-0.052742376923561096,
-0.048083409667015076,
0.026282276958227158,
0.023045893758535385,
-0.0034119838383048773,
-0.0054413918405771255,
0.013390091247856617,
0.05412939935922623,
0.031528063118457794,
-0.05082188546657562,
0.02336597628891468,
0.04868800938129425,
0.0027206959202885628,
0.053204718977212906,
-0.012296478264033794,
0.03908555209636688,
0.00030896792304702103,
-0.02327706478536129,
-0.03638263791799545,
-0.09815844148397446,
0.049577124416828156,
-0.027580387890338898,
0.05131979286670685,
-0.049683816730976105,
-0.004018805455416441,
0.05370262265205383,
0.00444558123126626,
0.018369141966104507,
0.008908945135772228,
-0.057401347905397415,
-0.01591518148779869,
-0.08692000806331635,
0.03332407772541046,
-0.0200051162391901,
0.03922780975699425,
-0.00962912943214178,
0.03463996946811676,
0.024557391181588173,
-0.029838742688298225,
0.006108229048550129,
0.034070935100317,
-0.01228758692741394,
0.058148205280303955,
0.027171393856406212,
0.010500463657081127,
-0.052280038595199585,
-0.017817890271544456,
0.0439579077064991,
0.03734288364648819,
-0.015194997191429138,
-0.008860044181346893,
0.04676751792430878,
-0.021178750321269035,
-0.019418299198150635,
-0.03997466713190079,
-0.007668627891689539,
0.031421370804309845,
-0.06920881569385529,
0.04918591305613518,
0.02477077953517437,
-0.0072018420323729515,
0.009922537952661514,
-0.01322115957736969,
-0.0004901253851130605,
-0.020556367933750153,
0.03780522570014,
-0.01627971976995468,
0.025357596576213837,
-0.029820960015058517,
0.03620481491088867,
0.02114318497478962,
-0.011300668120384216,
-0.017942367121577263,
0.014866024255752563,
-0.06049547344446182,
-0.010847218334674835,
0.014092492870986462,
0.08663549274206161,
-0.01559509988874197,
-0.05277794227004051,
-0.03232826665043831,
0.06270048022270203,
0.0031030159443616867,
-0.08094514906406403,
0.02160552516579628,
0.020342981442809105,
-0.0646209716796875,
0.034391019493341446,
0.0018449162598699331,
0.06259378790855408,
-0.012749928049743176,
0.0034142066724598408,
-0.05821933597326279,
0.00819765217602253,
-0.024237310513854027,
0.00037787441397085786,
-0.01327450666576624,
0.002202785573899746,
0.013479002751410007,
0.04705203324556351,
0.013176703825592995,
-0.03456884250044823,
-0.06035321578383446,
0.013585696928203106,
0.05043067783117294,
-0.06664815545082092,
0.020503021776676178,
0.007126267068088055,
-0.009015639312565327,
0.008962292224168777,
-0.020876450464129448,
0.003343077376484871,
0.023241499438881874,
0.012163111008703709,
-0.01778232492506504,
-0.03855208307504654,
-0.01336341816931963,
-0.02662014216184616,
-0.032186008989810944,
0.027118047699332237,
-0.04886583238840103,
0.018849264830350876,
-0.04559388384222984,
0.03816087171435356,
0.05615658685564995,
-0.017204400151968002,
0.012652125209569931,
0.002758483402431011,
0.03092346526682377,
-0.015328364446759224,
-0.038054175674915314,
-0.02551763691008091,
-0.0200051162391901,
0.016155242919921875,
0.018191318958997726,
0.013816867023706436,
0.0020694180857390165,
0.011122845113277435,
-0.009068986400961876,
-0.027135828509926796,
0.05971305072307587,
0.03958345577120781,
0.09111663699150085,
-0.03213266283273697,
-0.02235238440334797,
-0.045202672481536865,
0.05761473625898361,
-0.017924584448337555,
0.008837816305458546,
-0.012180892750620842,
0.019436081871390343,
0.004610068164765835,
0.005948187783360481,
-0.024290656670928,
0.01425253413617611,
-0.028238333761692047,
-0.023597147315740585,
0.04648299887776375,
0.05743691325187683,
0.007370774168521166,
0.08983630686998367,
-0.0015392826171591878,
0.018369141966104507,
-0.017906801775097847,
-0.018973741680383682,
0.050039466470479965,
0.05558754876255989,
-0.00977138802409172,
0.00012628229160327464,
-0.02430843934416771,
0.008837816305458546,
-0.021392138674855232,
0.004556721076369286,
-0.015168324112892151,
0.025926630944013596,
0.012749928049743176,
-0.02503751404583454,
0.006148239132016897,
-0.11074832826852798,
-0.024557391181588173,
-0.004970159847289324,
-0.03378641977906227,
-0.0011625195620581508,
0.03837426006793976,
-0.0426420159637928,
0.04424242675304413,
0.04061483219265938,
0.008531071245670319,
-0.0010686066234484315,
-0.03819643706083298,
-0.05220890790224075,
-0.04932817071676254,
0.03460440784692764,
0.042784277349710464,
-0.008379921317100525,
0.0017971262568607926,
-0.02727808803319931,
-0.04442024976015091,
-0.03826756402850151,
0.0305500365793705,
-0.00747302221134305,
0.10605379194021225,
-0.04114830121397972,
0.002126099308952689,
-0.027527039870619774,
-0.029163014143705368,
-0.0202185045927763,
0.017942367121577263,
-0.04434911906719208,
-0.04459807276725769,
-0.010624939575791359,
-0.05548085644841194,
0.00642831064760685,
0.03501340001821518,
-0.007788658607751131,
-0.0021438817493617535,
0.037378448992967606,
-0.02608667127788067,
0.08186982572078705,
0.028327245265245438,
-0.029287490993738174,
0.04228636994957924,
-0.01257210411131382,
-0.004538938868790865,
-0.037307318300008774,
-0.01536392979323864,
0.0030496688559651375,
-0.01870700716972351,
0.004205520264804363,
-0.03744957968592644,
-0.025108644738793373,
0.021641090512275696,
-0.01108727976679802,
-0.010384878143668175,
0.031047940254211426,
0.004974605515599251,
-0.054058272391557693,
-0.003529791720211506,
-0.03567134588956833,
-0.06803517788648605,
0.0690309926867485,
0.00547251058742404,
-0.03872990608215332,
-0.04136168956756592,
0.059926439076662064,
-0.01136290654540062,
0.03490670397877693,
-0.008402149192988873,
-0.038125306367874146,
0.00012378166138660163,
-0.028825150802731514,
0.0298920888453722,
-0.029447531327605247,
-0.011238429695367813,
0.03415984660387039,
-0.061135634779930115,
-0.01788901910185814,
-0.029572008177638054,
-0.008042057044804096,
-0.019222693517804146,
-0.04662525653839111,
0.02925192564725876,
0.010980586521327496,
0.008539961650967598,
-0.05523190274834633,
-0.015861835330724716,
-0.07653512805700302,
0.04598509520292282,
-0.030318865552544594,
-0.008855598047375679,
0.07881126552820206,
-0.018884830176830292,
-0.07383221387863159,
-0.02597997896373272,
0.05188882723450661,
0.03556464985013008,
-0.03175923228263855,
0.010029232129454613,
-0.032257139682769775,
-0.03008769452571869,
0.021374356001615524,
0.007464131340384483,
-0.013985799625515938,
-0.0031741452403366566,
0.08322128653526306,
0.007304090540856123,
-0.0175867211073637,
0.021089838817715645,
-0.033110689371824265,
0.007157386280596256,
0.0230814591050148,
0.03380420058965683,
0.0003267502470407635,
-0.05615658685564995,
0.013781302608549595,
-0.02662014216184616,
0.03362637758255005,
0.051355358213186264,
-0.06042434275150299,
0.011096171103417873,
0.002831835299730301,
0.039512328803539276,
0.01817353628575802,
-0.02597997896373272,
-0.0375918373465538,
0.005739245563745499,
0.00032536100479774177,
-0.05046623945236206,
0.007428566459566355,
-0.04338887333869934,
0.057401347905397415,
0.016173025593161583,
-0.03149249777197838,
0.006063773296773434,
0.03035443089902401,
-0.08443048596382141,
0.00031952618155628443,
0.014874915592372417,
0.05537416413426399,
-0.02710026502609253,
-0.010331531055271626,
0.0026917995419353247,
-0.023294847458600998,
0.050608500838279724,
-0.037840791046619415,
0.04121943190693855,
0.04826123267412186,
0.033110689371824265,
-0.04890139773488045,
-0.038303129374980927,
0.005774810444563627,
0.02413061633706093,
0.02941196784377098,
0.04979051277041435,
-0.0776020735502243,
-0.06547452509403229,
0.01057159248739481,
-0.051248662173748016,
-0.00922013632953167,
-0.03823200240731239,
-0.028931844979524612,
-0.01368349976837635,
0.008735567331314087,
0.027260305359959602,
-0.008811142295598984,
-0.017942367121577263,
-0.02903853729367256,
-0.03250609338283539,
0.0081042954698205,
-0.02039632759988308,
-0.002087200526148081,
-0.005001279059797525,
0.016261937096714973,
-0.08649323135614395,
-0.0415395125746727,
-0.021641090512275696,
-0.01750670000910759,
-0.039049986749887466,
-0.005952633451670408,
0.019969552755355835,
0.007157386280596256,
0.030105477198958397,
0.047265421599149704,
0.031599193811416626,
0.015799596905708313,
-0.048190101981163025,
0.019062653183937073,
0.04367339238524437,
0.07468576729297638,
0.03929894044995308,
0.032363831996917725,
-0.056476667523384094,
-0.006837304215878248,
-0.023810533806681633,
-0.033288512378931046,
-0.0006090446840971708,
0.02978539653122425,
-0.03213266283273697,
0.014181405305862427,
-0.0005657002329826355,
-0.01271436270326376,
-0.02942974865436554,
-0.04797671362757683,
0.03341298922896385,
-0.008615536615252495,
-0.001131400465965271,
-0.07454351335763931,
-0.04936373606324196,
-0.05299133062362671,
-0.023045893758535385,
0.020058464258909225,
-0.017462244257330894,
-0.0448470264673233,
-0.04559388384222984,
0.04534493014216423,
0.005885949824005365,
0.02242351323366165
]
|
31,254 | quandl.api_config | ApiConfig | null | class ApiConfig:
api_key = None
api_protocol = 'https://'
api_base = '{}data.nasdaq.com/api/v3'.format(api_protocol)
api_version = None # This is not used but keeping for backwards compatibility
page_limit = 100
use_retries = True
number_of_retries = 5
retry_backoff_factor = 0.5
max_wait_between_retries = 8
retry_status_codes = [429] + list(range(500, 512))
verify_ssl = True
| () | [
-0.008712947368621826,
-0.04755333065986633,
-0.03789163753390312,
-0.0265454463660717,
0.0008319654152728617,
0.024357527494430542,
-0.07191085815429688,
-0.04468773677945137,
0.009835949167609215,
-0.022440679371356964,
-0.002339184284210205,
-0.011714073829352856,
0.014560302719473839,
0.02724248170852661,
0.03609096258878708,
-0.017929309979081154,
0.03088255785405636,
0.018171334639191628,
0.03938252106308937,
-0.024241356179118156,
0.0016191559843719006,
0.053129617124795914,
-0.058744627982378006,
0.0583961084485054,
0.013088783249258995,
0.07686755806207657,
0.03310919925570488,
-0.03775610402226448,
-0.00011685332719935104,
-0.017629196867346764,
-0.03248961269855499,
0.049412090331315994,
-0.010048932395875454,
0.055917758494615555,
-0.013534110970795155,
-0.03181193768978119,
0.023040905594825745,
-0.002314981771633029,
-0.18122930824756622,
0.009840790182352066,
-0.04325494170188904,
-0.005813471972942352,
0.027048859745264053,
-0.06153276935219765,
0.05994507670402527,
0.037736743688583374,
-0.038336966186761856,
0.06366260349750519,
-0.03696225956082344,
-0.01878124102950096,
0.0048042223788797855,
0.008558050729334354,
-0.03279940411448479,
0.034987322986125946,
-0.011820564977824688,
0.025925857946276665,
-0.04395197704434395,
0.05115468055009842,
0.03278004378080368,
-0.006941314786672592,
-0.051038507372140884,
0.02199535071849823,
0.05649862065911293,
-0.010804054327309132,
-0.0018006757600232959,
0.020194675773382187,
-0.08674222975969315,
0.03212173283100128,
0.00659279664978385,
0.002068114932626486,
0.08666478097438812,
0.00965200923383236,
-0.05560796335339546,
-0.03884038329124451,
0.05254875123500824,
-0.023873474448919296,
-0.07179468125104904,
0.02580968663096428,
-0.055956482887268066,
0.00548915658146143,
-0.0033206010702997446,
0.018026119098067284,
-0.00824341643601656,
-0.025132011622190475,
0.04499753192067146,
-0.019923605024814606,
0.0007109522703103721,
-0.0242219939827919,
0.06350770592689514,
0.037969086319208145,
-0.04267407953739166,
0.0009293810580857098,
-0.0150153124704957,
0.00231861206702888,
-0.012188444845378399,
-0.0008162337471731007,
0.017958352342247963,
-0.03870484605431557,
-0.01878124102950096,
-0.04441666975617409,
-0.045500945299863815,
-0.037872277200222015,
-0.022711748257279396,
-0.012759626843035221,
-0.007047806400805712,
-0.09572624415159225,
-0.025596702471375465,
0.006868706550449133,
0.009748820215463638,
0.011152571998536587,
-0.00865970179438591,
0.011423641815781593,
-0.026758428663015366,
0.02398964762687683,
0.0222276970744133,
0.048753779381513596,
-0.025170736014842987,
-0.015973735600709915,
0.013166231103241444,
-0.016670772805809975,
-0.01006829459220171,
0.0277071725577116,
-0.025693513453006744,
0.03241216391324997,
0.054291341453790665,
0.03580053150653839,
-0.010939589701592922,
0.024338165298104286,
0.020330209285020828,
-0.024067096412181854,
0.026661617681384087,
0.002926098182797432,
-0.012285255827009678,
0.002298039849847555,
0.05065126717090607,
-0.0069074309431016445,
0.027920154854655266,
0.0530908927321434,
-0.04468773677945137,
-0.0037465672940015793,
-0.03574244678020477,
0.0361684113740921,
-0.0007448359974659979,
-0.045462220907211304,
0.02906251884996891,
-0.01976870931684971,
-0.01976870931684971,
-0.06253959983587265,
-0.025132011622190475,
-0.004995422903448343,
0.020097864791750908,
-0.003211689181625843,
0.012217488139867783,
-0.010397450067102909,
-0.03467753157019615,
-0.04162852466106415,
-0.002737317467108369,
-0.028539743274450302,
0.046895019710063934,
-0.004627543035894632,
-0.0348324254155159,
-0.005644053686410189,
0.04166724905371666,
-0.057970140129327774,
-0.05448496341705322,
-0.008766192942857742,
-0.04681757092475891,
-0.08186297863721848,
0.005077711772173643,
0.03324473276734352,
-0.021453212946653366,
-0.03686544671654701,
-0.08441877365112305,
-0.009008219465613365,
-0.03490987420082092,
-0.0013819702435284853,
0.00816112756729126,
0.008262778632342815,
0.03698161989450455,
-0.05096105858683586,
-0.05402027443051338,
0.006950995419174433,
-0.03469689190387726,
-0.045113705098629,
-0.022285781800746918,
0.037969086319208145,
-0.005479475483298302,
0.06447581201791763,
0.014153698459267616,
0.030069349333643913,
0.01734844595193863,
-0.027165032923221588,
0.027223119512200356,
-0.005179362837225199,
-0.013921353034675121,
-0.06002252548933029,
0.031502146273851395,
0.004881670698523521,
0.061494044959545135,
0.07005209475755692,
-0.000374233175534755,
0.057970140129327774,
0.04290642589330673,
0.017590472474694252,
0.01636097952723503,
-0.020310847088694572,
-0.01635129749774933,
-0.03705906867980957,
-0.04395197704434395,
0.03893719241023064,
-0.0315215066075325,
0.02209216170012951,
-0.03146342188119888,
0.00018348619050811976,
-0.01976870931684971,
0.025170736014842987,
0.10323874652385712,
0.04631415382027626,
0.0242219939827919,
-0.006331408396363258,
0.09967611730098724,
-0.0384918637573719,
0.05436879023909569,
-0.08170808106660843,
0.004112027119845152,
0.03295430168509483,
0.019691260531544685,
-0.021240228787064552,
-0.025596702471375465,
-0.09107933938503265,
0.02013658918440342,
0.02129831537604332,
0.008930770680308342,
0.03423220291733742,
0.08581285178661346,
-0.05758289992809296,
0.010126381181180477,
-0.03320600837469101,
0.0033883682917803526,
-0.00035608120379038155,
0.05328451097011566,
0.021182142198085785,
-0.013175912201404572,
0.014202103950083256,
-0.03667182847857475,
-0.007251108065247536,
-0.04987678304314613,
0.052897270768880844,
0.024706045165657997,
-0.049683161079883575,
0.03264451026916504,
-0.06606350094079971,
-0.011259064078330994,
-0.004603340290486813,
0.01878124102950096,
0.006268481258302927,
-0.02627437561750412,
0.00031342406873591244,
0.020349571481347084,
-0.01659332402050495,
0.012401428073644638,
-0.03667182847857475,
-0.0759769007563591,
0.06513412296772003,
-0.014405406080186367,
0.0116947116330266,
0.01612863317131996,
0.011820564977824688,
0.032663870602846146,
0.013204955495893955,
0.16573961079120636,
0.0719883069396019,
-0.01775505021214485,
-0.02375730313360691,
-0.01439572498202324,
-0.00026214474928565323,
0.008896887302398682,
0.0003473077667877078,
0.031211713328957558,
-0.045462220907211304,
-0.008199851028621197,
-0.061687666922807693,
0.05254875123500824,
0.008964654989540577,
0.07136871665716171,
-0.05022529885172844,
-0.0647081509232521,
0.06130042299628258,
0.0040176366455852985,
0.019284656271338463,
-0.005915123037993908,
-0.024299440905451775,
-0.027958879247307777,
-0.02203407511115074,
0.01864570751786232,
-0.02948848530650139,
-0.04035062715411186,
0.030998729169368744,
0.05096105858683586,
-0.010397450067102909,
-0.01636097952723503,
-0.004424240905791521,
0.0074350484646856785,
0.0275329127907753,
0.014966906979680061,
-0.03105681575834751,
0.041357457637786865,
-0.013117825612425804,
0.025499891489744186,
0.010745967738330364,
-0.015150846913456917,
-0.008103040978312492,
0.04848271235823631,
0.011820564977824688,
-0.007086530327796936,
-0.06447581201791763,
-0.006767055485397577,
0.001472730073146522,
0.006931633688509464,
0.03258642181754112,
-0.04542349651455879,
0.056730967015028,
-0.02060128003358841,
-0.046701397746801376,
0.016409384086728096,
0.006341089494526386,
0.05878334864974022,
0.013505068607628345,
-0.031095540151000023,
-0.010426493361592293,
-0.013321127742528915,
-0.02302154339849949,
-0.022866645827889442,
-0.0011006146669387817,
0.009560039266943932,
-0.02677779085934162,
0.0009741559042595327,
-0.034619443118572235,
0.03171512857079506,
-0.0199042446911335,
-0.011743116192519665,
-0.03454199433326721,
-0.037136517465114594,
0.015847882255911827,
-0.008272459730505943,
-0.0507674403488636,
0.021414488554000854,
-0.026913326233625412,
0.0027469985652714968,
-0.006573434453457594,
0.00013160180242266506,
0.026487359777092934,
0.027087584137916565,
0.06656691431999207,
0.09177637845277786,
-0.05165809392929077,
0.0031051975674927235,
-0.05413644388318062,
-0.002950300695374608,
0.0036618581507354975,
-0.03310919925570488,
-0.014085931703448296,
-0.034890513867139816,
0.07984931766986847,
-0.02511264942586422,
0.013989120721817017,
-0.023912198841571808,
-0.04023445397615433,
0.09402237832546234,
-0.001183508662506938,
-0.05026402324438095,
-0.06408856809139252,
-0.01376645639538765,
0.004828425124287605,
0.043874528259038925,
0.015644580125808716,
-0.08736182004213333,
-0.01708705723285675,
-0.033554527908563614,
0.024105820804834366,
0.010048932395875454,
-0.036904171109199524,
0.025461167097091675,
0.0027929835487157106,
0.014666794799268246,
-0.043177492916584015,
-0.00031554180895909667,
0.002698593307286501,
0.025538615882396698,
0.008015911094844341,
-0.015005631372332573,
-0.003296398324891925,
-0.037543121725320816,
0.04623670503497124,
-0.09835949540138245,
-0.03775610402226448,
-0.019168483093380928,
0.031095540151000023,
0.0015041935257613659,
-0.03984721004962921,
0.028520381078124046,
-0.021240228787064552,
0.030708298087120056,
0.03642011806368828,
0.05402027443051338,
-0.02232450619339943,
0.08798140287399292,
-0.0034319330006837845,
0.005038987845182419,
0.005852196365594864,
-0.0027348974253982306,
-0.02468668296933174,
-0.03411602973937988,
0.02757163718342781,
-0.011007356457412243,
0.013466344214975834,
-0.012643454596400261,
0.053400684148073196,
0.034716252237558365,
0.004985741805285215,
0.03194747120141983,
-0.06164894253015518,
0.027223119512200356,
0.025925857946276665,
0.011956099420785904,
0.04058297351002693,
0.019391147419810295,
-0.015528407879173756,
-0.04848271235823631,
-0.019526682794094086,
0.023098990321159363,
0.07307258248329163,
-0.03142469748854637,
-0.0437970794737339,
0.017609834671020508,
-0.01658364199101925,
-0.0045767175033688545,
-0.026797153055667877,
-0.008035273291170597,
-0.063043013215065,
-0.014056888408958912,
-0.023002181202173233,
0.02999190054833889,
0.02561606466770172,
0.033651337027549744,
0.022111523896455765,
-0.05448496341705322,
-0.02050446905195713,
0.04751460626721382,
-0.046197980642318726,
-0.0474371574819088,
-0.02249876596033573,
-0.0025194939225912094,
0.01605118438601494,
-0.004852627404034138,
-0.0626944974064827,
-0.01721291057765484,
-0.0151798902079463,
-0.0037054228596389294,
-0.002128621330484748,
0.03558754920959473,
-0.028655914589762688,
-0.018819965422153473,
-0.03198619559407234,
-0.014095612801611423,
0.05080616474151611,
0.049412090331315994,
0.035645633935928345,
-0.004792120773345232,
-0.018897414207458496,
-0.02259557694196701,
0.027319930493831635,
-0.04948953911662102,
0.012043229304254055,
0.021588746458292007,
-0.004516210872679949,
-0.011501090601086617,
0.02817186340689659,
-0.02790079265832901,
-0.05065126717090607,
0.002621144987642765,
-0.021414488554000854,
0.013040377758443356,
0.004003114998340607,
0.00003204957829439081,
-0.10943461954593658,
0.0018393999198451638,
-0.014608708210289478,
-0.026487359777092934,
-0.03235407546162605,
-0.0018442404689267278,
0.03599415346980095,
0.006578275002539158,
0.039363160729408264,
-0.003519062651321292,
0.046120535582304,
0.0034343532752245665,
0.020059140399098396,
0.028210585936903954,
-0.02232450619339943,
0.05471730977296829,
-0.0242219939827919,
-0.020814262330532074,
-0.006539551075547934,
0.045772016048431396,
0.004257242660969496,
-0.08774905651807785,
0.030960004776716232,
-0.003172965021803975,
0.01476360484957695,
-0.030340418219566345,
0.011791521683335304,
0.006650883238762617,
0.0010975892655551434,
0.026680979877710342,
-0.0007738791173323989,
-0.04979933425784111,
0.0031947472598403692,
-0.0014013323234394193,
0.010775011032819748,
0.013175912201404572,
0.0414736270904541,
0.04654650017619133,
0.006796098779886961,
-0.024570511654019356,
0.05897697061300278,
0.034522633999586105,
-0.02176300622522831,
-0.03756248205900192,
0.09425472468137741,
-0.004274184815585613,
-0.004295967053622007,
0.012469195760786533,
0.04867633059620857,
0.016244806349277496,
0.027126308530569077,
-0.04646905139088631,
0.040854040533304214,
0.03696225956082344,
0.012004504911601543,
0.026758428663015366,
0.019061991944909096,
0.01076532993465662,
-0.04902485013008118,
-0.04426177218556404,
-0.02046574465930462,
0.007667393423616886,
0.10571709275245667,
0.02673906646668911,
-0.03988593444228172,
0.07086530327796936,
-0.005561764817684889,
0.06478559970855713,
-0.062423426657915115,
-0.003589250147342682,
-0.036904171109199524,
0.03558754920959473,
-0.043680910021066666,
0.05394282564520836,
-0.01752270571887493,
-0.03562627360224724,
-0.021975988522171974,
-0.04267407953739166,
-0.011336512863636017,
-0.02943039871752262,
0.015054036863148212,
0.043835803866386414,
0.009400301612913609,
-0.015102441422641277,
-0.020523831248283386,
0.019255613908171654,
-0.010048932395875454,
-0.014269871637225151,
0.023370061069726944,
-0.04004083201289177,
0.016825668513774872,
0.0040176366455852985,
0.00769643671810627,
-0.012749945744872093,
0.00016321649309247732,
0.03688481077551842,
0.009719776920974255,
0.022169610485434532,
-0.06083573400974274,
-0.017425894737243652,
-0.0006177721661515534,
0.033264096826314926,
-0.032334715127944946,
0.04007955640554428,
-0.017125781625509262,
-0.013359852135181427,
-0.0004988767323084176,
-0.028442932292819023,
-0.00935673713684082,
0.006476623937487602,
0.086277537047863,
-0.04220938682556152,
-0.05138702690601349,
0.05704076215624809,
-0.0028220268432050943,
-0.01946859620511532,
0.08852354437112808,
-0.025712875649333,
-0.023699216544628143,
0.028985070064663887,
0.021220866590738297,
-0.022305143997073174,
-0.010523304343223572,
-0.006834823172539473,
-0.022982819005846977,
0.018761878833174706,
-0.02083362452685833,
-0.02000105381011963,
-0.01824878342449665,
0.003831276437267661,
-0.006157149560749531,
-0.030301693826913834,
0.03347707912325859,
0.0004056965990457684,
-0.08589030057191849,
0.04166724905371666,
0.047359708696603775,
-0.0007690386264584959,
0.03272195905447006,
-0.08356684446334839,
0.029101243242621422,
0.01234334148466587,
-0.07036188989877701,
-0.07028444111347198,
0.0275329127907753,
0.05390410125255585,
0.028772087767720222,
0.02464795857667923,
-0.016709497198462486,
-0.06997464597225189,
-0.00008660004095872864,
0.055453069508075714,
0.021511297672986984,
0.038666121661663055,
0.018587620928883553,
0.025712875649333,
0.0277071725577116,
-0.022053437307476997,
0.021550022065639496,
0.0010177206713706255,
0.005813471972942352,
-0.06490177661180496,
-0.02189853973686695,
0.002998705953359604,
-0.03041786700487137,
-0.06981974840164185,
-0.0018502911552786827,
0.0038627400062978268,
0.0018950660014525056,
-0.041086386889219284,
-0.02249876596033573,
-0.024899667128920555,
0.05262620002031326,
0.05692458897829056,
-0.08945292234420776,
-0.04244173318147659,
-0.025829046964645386,
-0.028307396918535233,
-0.03872421011328697,
-0.0059538474306464195,
0.018268145620822906,
-0.02036893367767334,
-0.040428075939416885,
0.01396975852549076,
-0.002368227345868945,
0.06912271678447723,
0.006704128812998533,
0.02776525914669037,
0.026816515251994133,
0.044145599007606506,
0.0024856103118509054,
-0.03347707912325859,
-0.020330209285020828,
0.01878124102950096,
0.0028365482576191425,
0.026719704270362854,
0.03560690954327583,
-0.024163907393813133,
0.02408645860850811,
-0.016215762123465538,
-0.008867844007909298,
0.048056744039058685,
0.0051357983611524105,
-0.04902485013008118,
0.05030274763703346,
-0.03463880717754364,
0.022731110453605652,
-0.012246531434357166,
-0.0009263557149097323,
0.012033548206090927,
-0.10006336122751236,
0.013892310671508312,
-0.02352495677769184,
0.014318276196718216,
-0.016970884054899216,
0.044106874614953995,
-0.01313718780875206,
-0.008340226486325264,
0.01775505021214485,
0.024493062868714333,
0.015421916730701923,
0.02083362452685833,
-0.018887734040617943,
-0.030262969434261322,
-0.006747693754732609,
0.04724353551864624,
0.063043013215065,
0.02561606466770172,
-0.0341741144657135,
-0.006578275002539158,
0.0889107882976532,
0.04298387095332146,
-0.0004365549539215863,
-0.06257832050323486,
0.054562412202358246,
-0.029101243242621422,
0.04170597344636917,
-0.02203407511115074,
-0.005808631423860788,
0.018035801127552986,
0.025286909192800522,
-0.00534878158941865,
0.009743979200720787,
-0.018432723358273506,
-0.0030834150966256857,
0.029565934091806412,
0.030940644443035126,
-0.05251002684235573,
-0.005963528528809547,
-0.003940188325941563,
-0.03725269064307213,
0.041822146624326706,
0.01306942105293274,
0.01164630614221096,
0.05413644388318062,
0.009419663809239864,
-0.007362440228462219,
-0.01778409257531166,
-0.014202103950083256,
-0.0265454463660717,
0.005285854451358318,
0.03132788464426994,
-0.003843377809971571,
0.011133210733532906,
-0.011443004012107849,
-0.0009330114116892219,
0.028849536553025246,
0.01355347316712141,
0.03235407546162605,
-0.034987322986125946,
-0.04209321737289429,
-0.0052084061317145824,
0.013156550005078316,
0.01448285486549139,
-0.030630849301815033,
-0.01134619303047657,
-0.006917112041264772,
0.01688375510275364,
0.045500945299863815,
-0.014792648144066334,
0.01544127892702818,
0.03177321329712868,
0.007551220711320639
]
|
31,255 | quandl.errors.quandl_error | AuthenticationError | null | class AuthenticationError(QuandlError):
pass
| (quandl_message=None, http_status=None, http_body=None, http_headers=None, quandl_error_code=None, response_data=None) | [
-0.03280756250023842,
-0.026202378794550896,
0.023873277008533478,
0.0519680492579937,
-0.002838590880855918,
0.0029432184528559446,
-0.01493899431079626,
-0.008884243667125702,
0.019760960713028908,
-0.009425577707588673,
0.07547740638256073,
0.0008284909999929368,
0.027148574590682983,
0.026275161653757095,
-0.022490374743938446,
-0.005972868297249079,
0.0012214129092171788,
0.058009155094623566,
0.014429504051804543,
-0.06910876929759979,
-0.03730199486017227,
0.029040969908237457,
0.010280794464051723,
0.04614529758691788,
0.004235141444951296,
0.04865635931491852,
-0.019306058064103127,
0.00099396170116961,
0.02285429649055004,
0.00206298241391778,
-0.04680036008358002,
0.03655595704913139,
0.028804419562220573,
0.0706736370921135,
0.0021187078673392534,
-0.04545384645462036,
0.026657281443476677,
0.02703939937055111,
-0.03670152649283409,
-0.015539465472102165,
-0.15008139610290527,
0.02523798495531082,
-0.03431783616542816,
-0.027749046683311462,
0.03544599562883377,
0.008611302822828293,
0.0019481194904074073,
0.026420731097459793,
-0.07314830273389816,
0.03437242656946182,
-0.01680409535765648,
0.017522839829325676,
0.011945736594498158,
-0.0031683952547609806,
0.03029649890959263,
-0.010280794464051723,
-0.02503782883286476,
0.05014843866229057,
-0.05819111317396164,
-0.007633262313902378,
-0.04698231816291809,
0.04101400077342987,
-0.003971297759562731,
0.0241280235350132,
0.03533681854605675,
0.007587771862745285,
-0.01119969692081213,
0.013910915702581406,
-0.019196880981326103,
-0.0009723538532853127,
-0.021962687373161316,
0.01703154668211937,
-0.08377482742071152,
-0.0001794021372916177,
0.09098047763109207,
-0.03020551986992359,
-0.07354862242937088,
0.04003141075372696,
-0.053168993443250656,
0.04771016165614128,
0.04534466937184334,
-0.04771016165614128,
-0.002822669455781579,
0.02598402462899685,
0.021125666797161102,
-0.0043556904420256615,
0.009352792985737324,
-0.02558371052145958,
-0.016849584877490997,
-0.020434215664863586,
-0.0389760360121727,
-0.062267038971185684,
-0.043051961809396744,
0.028404105454683304,
-0.02631155401468277,
0.01645836792886257,
-0.007246595341712236,
-0.00843843910843134,
-0.03835736960172653,
-0.031770382076501846,
0.02651171199977398,
0.04905667528510094,
-0.007965341210365295,
-0.009248165413737297,
-0.020834529772400856,
-0.006209417711943388,
-0.024364572018384933,
-0.08399318158626556,
0.04789212346076965,
-0.006728006526827812,
-0.030369283631443977,
0.04148709774017334,
-0.016012564301490784,
0.05789997801184654,
-0.04447126016020775,
-0.020434215664863586,
0.03524583950638771,
-0.002447374863550067,
-0.014029189944267273,
-0.024419160559773445,
0.04599973186850548,
0.000032411797292297706,
-0.01843264512717724,
0.016449270769953728,
0.05935566499829292,
0.07525905221700668,
-0.025074219331145287,
-0.027548888698220253,
0.0032161599956452847,
0.0203432347625494,
0.020161274820566177,
0.01735907606780529,
-0.02081633359193802,
-0.07078281044960022,
0.004944789223372936,
0.021689746528863907,
0.02676645666360855,
0.023509355261921883,
-0.025874847546219826,
0.07693309336900711,
-0.0056862798519432545,
0.0780976414680481,
-0.013337737880647182,
-0.0012475698022171855,
-0.03431783616542816,
0.05964680388569832,
-0.020124882459640503,
-0.031188108026981354,
-0.0106356181204319,
-0.012218678370118141,
0.03282575681805611,
-0.02285429649055004,
0.07962611317634583,
0.005490671843290329,
-0.06059299781918526,
-0.008811459876596928,
-0.0036756114568561316,
-0.06794422119855881,
0.0007613928755745292,
-0.023472962900996208,
0.016212722286581993,
-0.07656916975975037,
0.009953264147043228,
0.006982751656323671,
-0.0315520316362381,
0.021616961807012558,
0.015594054013490677,
-0.07904384285211563,
-0.027075789868831635,
0.006314045283943415,
0.0019401587778702378,
0.005709025077521801,
-0.022745119407773018,
0.011872952803969383,
-0.04829243943095207,
0.013592483475804329,
0.017777586355805397,
0.03857572376728058,
-0.013146678917109966,
-0.05826389789581299,
0.00548612279817462,
-0.033171482384204865,
-0.001757060526870191,
0.03759313374757767,
0.03722921386361122,
0.012500718235969543,
-0.02360033616423607,
0.03020551986992359,
0.04490796476602554,
-0.010262598283588886,
-0.05003926530480385,
-0.03249822556972504,
-0.014347621239721775,
-0.03127908706665039,
-0.01624911278486252,
-0.016512956470251083,
0.001142373657785356,
-0.02418261207640171,
0.05564366281032562,
0.05862782150506973,
-0.06728916615247726,
0.06565151363611221,
-0.012073109857738018,
-0.06441418081521988,
0.005436083767563105,
0.055898405611515045,
-0.018741978332400322,
-0.012746364809572697,
-0.04574498534202576,
-0.034681759774684906,
-0.0020880019292235374,
-0.017268095165491104,
-0.030787793919444084,
0.08399318158626556,
0.0020379626657813787,
0.0535329133272171,
0.05447911098599434,
-0.029204733669757843,
0.06677967309951782,
0.04115957021713257,
0.08668620139360428,
-0.005913731176406145,
0.03107893094420433,
-0.07467677444219589,
0.004808318335562944,
0.016094446182250977,
0.03908521309494972,
-0.023291002959012985,
-0.03824819251894951,
-0.0849393755197525,
0.011982128955423832,
0.006996398791670799,
-0.008133654482662678,
0.011563618667423725,
-0.002433727728202939,
-0.008538518100976944,
0.025492729619145393,
-0.0221992377191782,
-0.01451138686388731,
0.036264818161726,
-0.02054339274764061,
-0.0004930004943162203,
-0.016949662938714027,
0.07169261574745178,
0.0034572582226246595,
-0.029404891654849052,
-0.014738837257027626,
0.06459613889455795,
-0.03477273881435394,
-0.020707156509160995,
-0.0810818001627922,
-0.016485663130879402,
-0.020397823303937912,
-0.04989369586110115,
0.06612461060285568,
-0.03835736960172653,
-0.017895860597491264,
-0.001791178248822689,
0.03082418628036976,
-0.023109041154384613,
0.009352792985737324,
-0.025219788774847984,
-0.017704801633954048,
0.007087379228323698,
0.0049493382684886456,
-0.007860713638365269,
-0.026202378794550896,
0.043961767107248306,
0.07620524615049362,
0.03699266165494919,
0.14622382819652557,
0.028804419562220573,
-0.04141431301832199,
0.03358999267220497,
-0.030005361884832382,
-0.01954260654747486,
-0.004958436358720064,
0.09884119033813477,
-0.013865425251424313,
-0.009079852141439915,
-0.011563618667423725,
-0.014020091854035854,
-0.0023814139422029257,
0.036410387605428696,
-0.011936638504266739,
0.043561454862356186,
-0.005363299045711756,
-0.014766131527721882,
-0.0017945899162441492,
-0.015029975213110447,
0.014747935347259045,
-0.011545422486960888,
-0.023418376222252846,
-0.03009634278714657,
0.005813652649521828,
-0.00013042904902249575,
-0.051858872175216675,
-0.018650997430086136,
0.04276082664728165,
0.020925510674715042,
0.013810836710035801,
0.014347621239721775,
0.029987165704369545,
0.020052097737789154,
-0.008151850663125515,
-0.06419582664966583,
0.05804554745554924,
0.02691202610731125,
-0.01896033249795437,
-0.02340018004179001,
0.006696163211017847,
0.04334310069680214,
-0.044289298355579376,
-0.0009882755111902952,
-0.008120007812976837,
0.04963894933462143,
0.015466681681573391,
-0.009871382266283035,
-0.025492729619145393,
0.041778236627578735,
-0.051385775208473206,
0.010517343878746033,
0.04832883179187775,
-0.03835736960172653,
-0.005395142361521721,
-0.003991768695414066,
-0.02982340194284916,
0.02338198386132717,
-0.032097913324832916,
0.023946061730384827,
-0.05531613156199455,
0.0573904849588871,
0.008215537294745445,
-0.015785112977027893,
-0.08952479064464569,
-0.06343159079551697,
0.05789997801184654,
-0.029332106932997704,
0.0028727087192237377,
-0.06135723367333412,
-0.009953264147043228,
-0.05120381340384483,
0.029004577547311783,
0.02299986593425274,
0.014647857286036015,
-0.03519124910235405,
-0.03792066499590874,
-0.001989060780033469,
0.023764101788401604,
-0.007942595519125462,
-0.037738703191280365,
0.034354228526353836,
0.010817578993737698,
0.006728006526827812,
0.04618168994784355,
-0.03835736960172653,
-0.053314562886953354,
-0.007833419367671013,
-0.036683328449726105,
0.02902277372777462,
0.0812273696064949,
-0.03060583397746086,
-0.018741978332400322,
0.026875633746385574,
-0.05062153935432434,
-0.005126750096678734,
-0.012091306038200855,
-0.06048382446169853,
0.03817540779709816,
0.026020416989922523,
0.023109041154384613,
-0.061721157282590866,
-0.04974812641739845,
0.029368499293923378,
-0.004758279304951429,
0.04851078987121582,
-0.0010337657295167446,
0.03035108745098114,
-0.08632227778434753,
0.02472849376499653,
0.030405675992369652,
-0.037411171942949295,
-0.012973816134035587,
-0.029040969908237457,
-0.037338387221097946,
-0.014929897151887417,
-0.035937290638685226,
0.012100404128432274,
0.025328965857625008,
0.07125591486692429,
-0.04614529758691788,
-0.06419582664966583,
0.043779805302619934,
0.01073569618165493,
-0.07391253858804703,
0.03067861683666706,
-0.07598689943552017,
-0.020197667181491852,
-0.026602692902088165,
-0.008274674415588379,
-0.015293818898499012,
0.01530291698873043,
-0.004314749035984278,
0.03473634645342827,
0.04876553639769554,
-0.014884406700730324,
0.031133519485592842,
-0.01966997981071472,
-0.0014374916208907962,
-0.014720642007887363,
0.0179140567779541,
-0.038066234439611435,
-0.05051236227154732,
0.014129268936812878,
0.004699141718447208,
0.019724568352103233,
0.018705585971474648,
-0.05313260108232498,
-0.025001436471939087,
0.054697465151548386,
0.0025110612623393536,
-0.021580569446086884,
0.049857303500175476,
0.015248328447341919,
-0.025074219331145287,
0.05997433140873909,
-0.02844049781560898,
0.03544599562883377,
0.016467466950416565,
-0.018741978332400322,
0.00954385194927454,
0.026402534916996956,
-0.02245398238301277,
-0.032771170139312744,
-0.02014307864010334,
-0.019033117219805717,
-0.06634296476840973,
0.044289298355579376,
-0.012755462899804115,
-0.016367388889193535,
0.06263095885515213,
-0.014356719329953194,
0.027949202805757523,
0.006969104520976543,
0.10954049974679947,
-0.07664195448160172,
-0.011454442515969276,
0.0680897906422615,
-0.008201890625059605,
0.011791069991886616,
-0.0002716620219871402,
-0.009270911104977131,
-0.014320327900350094,
0.010908559896051884,
0.052441149950027466,
-0.005026671569794416,
-0.046618398278951645,
0.013474209234118462,
0.039267174899578094,
0.0031433755066245794,
0.021089274436235428,
0.05699017271399498,
-0.05826389789581299,
0.005090357735753059,
0.015266524627804756,
0.06772586703300476,
0.007160163950175047,
0.017577428370714188,
0.011117815040051937,
-0.019178684800863266,
-0.01454777829349041,
0.02565649524331093,
-0.028349516913294792,
-0.0029932577162981033,
0.001791178248822689,
0.06754390895366669,
0.027403321117162704,
0.023836886510252953,
0.01143624633550644,
0.005431534722447395,
0.023163629695773125,
-0.05859142914414406,
0.029004577547311783,
-0.02272692322731018,
-0.00515404436737299,
-0.06233982369303703,
0.02292708121240139,
-0.01308299321681261,
0.017195310443639755,
-0.016094446182250977,
0.029368499293923378,
0.04720067232847214,
-0.009270911104977131,
-0.0005751672433689237,
0.025802064687013626,
-0.033153288066387177,
-0.045089926570653915,
0.02894998900592327,
-0.027858223766088486,
-0.007278438191860914,
0.02962324395775795,
-0.06557872891426086,
-0.018741978332400322,
-0.018596410751342773,
0.08843302726745605,
-0.043634239584207535,
0.07063724100589752,
0.03335344418883324,
0.07274799048900604,
-0.0022824727930128574,
-0.029659636318683624,
0.03553697466850281,
0.035555172711610794,
-0.03828458487987518,
-0.011700090020895004,
0.005759064573794603,
-0.03198873624205589,
0.016585741192102432,
0.012473423965275288,
0.08392039686441422,
-0.006227613892406225,
0.03788427263498306,
0.008629498071968555,
0.0008063145214691758,
-0.02079813741147518,
-0.03446340560913086,
-0.00013775013212580234,
-0.03984944894909859,
0.0008682949701324105,
0.07555019110441208,
0.014329425990581512,
0.01660393737256527,
0.030569441616535187,
-0.022908885031938553,
-0.017477350309491158,
0.058555036783218384,
-0.1254802793264389,
0.018578214570879936,
0.036228425800800323,
-0.012382443062961102,
-0.015484877862036228,
0.05305981636047363,
-0.030314695090055466,
0.0054679266177117825,
-0.014229346998035908,
-0.04090482369065285,
-0.06805340200662613,
0.030787793919444084,
-0.027148574590682983,
0.005272318609058857,
0.011681893840432167,
-0.001989060780033469,
0.04891110584139824,
0.001964041031897068,
-0.02618418261408806,
-0.0028840810991823673,
0.03233446180820465,
0.013037502765655518,
0.02523798495531082,
-0.005572554189711809,
0.04458043351769447,
-0.016986055299639702,
0.026857437565922737,
-0.011800168082118034,
0.00022233354684431106,
-0.04607251659035683,
0.0008108635083772242,
-0.004255611915141344,
-0.02856787107884884,
0.011208795011043549,
-0.03388113155961037,
-0.007769732736051083,
0.009370989166200161,
0.0815185084939003,
0.014902602881193161,
0.000547304458450526,
-0.008129105903208256,
0.015885191038250923,
0.027003007009625435,
-0.0111360102891922,
0.053241778165102005,
0.009571146219968796,
-0.033226072788238525,
-0.05527973920106888,
0.011854756623506546,
0.008693184703588486,
-0.010107931680977345,
0.017450055107474327,
0.027348732575774193,
0.03850293904542923,
-0.062121473252773285,
-0.03318968042731285,
-0.047673773020505905,
-0.06190311908721924,
0.05764523148536682,
0.026802849024534225,
-0.021034687757492065,
-0.08981592953205109,
-0.04418012127280235,
-0.005822750739753246,
-0.022235630080103874,
0.06739833950996399,
-0.0032184345182031393,
-0.0369744673371315,
0.028076576068997383,
-0.01358338538557291,
-0.008488479070365429,
0.007878909818828106,
-0.06332241743803024,
-0.050403185188770294,
0.01781397871673107,
-0.014347621239721775,
-0.044762395322322845,
0.01583060435950756,
-0.01291922852396965,
-0.00420102383941412,
-0.010562833398580551,
0.0053405542857944965,
0.009161734022200108,
0.046545613557100296,
-0.01309209130704403,
-0.0034208660945296288,
-0.033444423228502274,
0.050002872943878174,
-0.022490374743938446,
0.01828707568347454,
0.05047596991062164,
0.031115323305130005,
-0.08064509928226471,
-0.023218218237161636,
-0.03060583397746086,
0.08370204269886017,
0.0014374916208907962,
-0.06426861137151718,
-0.05375126749277115,
0.024346375837922096,
0.01580330915749073,
0.008606753312051296,
0.037811487913131714,
0.023309199139475822,
-0.013401424512267113,
0.021289432421326637,
-0.047018710523843765,
0.021016491577029228,
0.017513742670416832,
-0.00048219654127024114,
-0.020889118313789368,
-0.08377482742071152,
0.031843166798353195,
-0.03550058230757713,
0.0053405542857944965,
0.030696813017129898,
0.02452833764255047,
0.0049038478173315525,
-0.06230343133211136,
0.007351222913712263,
-0.05043957754969597,
0.02325461059808731,
0.029968969523906708,
-0.028349516913294792,
0.0352640338242054,
-0.020834529772400856,
0.005345103330910206,
0.013546993024647236,
-0.008847851306200027,
0.02445555292069912,
0.01216408982872963,
-0.030787793919444084,
0.015248328447341919,
0.000480774964671582,
0.006632477045059204,
-0.033098697662353516,
0.029532263055443764,
-0.022836100310087204,
-0.013692562468349934,
-0.002563375048339367,
0.01888754777610302,
-0.089379221200943,
0.02711218222975731,
-0.01765931025147438,
-0.02074354887008667,
0.011463540606200695,
-0.03286214917898178,
0.017722997814416885,
-0.025201592594385147,
0.07707866281270981,
0.018632803112268448,
0.02212645299732685,
-0.0110996188595891,
-0.06346797943115234,
-0.02676645666360855,
0.007683301344513893,
-0.06117527559399605,
0.030169127508997917,
-0.03828458487987518,
-0.01948801800608635,
-0.035154856741428375,
-0.03193414956331253,
0.024965044111013412,
0.0573904849588871,
0.031315479427576065,
0.009807695634663105,
-0.005440632812678814,
-0.002134629525244236,
0.020579785108566284,
-0.029040969908237457,
0.051385775208473206,
-0.018450841307640076,
0.018068723380565643,
-0.03366277739405632,
0.017968645319342613,
0.024164415895938873,
0.009989656507968903,
-0.018277978524565697,
0.005108553916215897,
-0.0068417321890592575,
0.014465896412730217,
0.04166905954480171,
-0.004150984343141317,
0.0006760986871086061,
-0.01687687821686268,
-0.022162845358252525,
-0.01640378125011921,
0.010353578254580498,
0.009189028292894363,
-0.008902439847588539,
0.004212396219372749,
-0.03792066499590874,
-0.0016717662801966071,
0.02107107825577259,
0.016885977238416672,
0.06059299781918526,
-0.0686720684170723,
0.0852305144071579,
-0.021435001865029335,
-0.01715891808271408,
-0.06332241743803024,
0.026784652844071388,
0.0315520316362381,
0.0663793608546257,
0.04155988246202469,
-0.006423221901059151,
0.005863691680133343,
-0.04949337989091873,
0.019906528294086456,
-0.0068917712196707726,
0.024473749101161957,
0.011563618667423725,
-0.02405523881316185,
0.04905667528510094,
0.009289107285439968,
0.009289107285439968,
-0.007155614905059338,
0.025729279965162277,
-0.037483956664800644,
-0.02425539493560791,
0.021507784724235535,
0.02438276819884777,
-0.02458292618393898,
0.008215537294745445,
-0.011900247074663639,
0.03955831378698349,
-0.007041889242827892,
0.0032184345182031393,
-0.010908559896051884,
-0.020779941231012344,
0.025620102882385254,
0.0017752565909177065
]
|
31,256 | quandl.errors.quandl_error | __init__ | null | def __init__(self, quandl_message=None, http_status=None, http_body=None, http_headers=None,
quandl_error_code=None, response_data=None):
self.http_status = http_status
self.http_body = http_body
self.http_headers = http_headers if http_headers is not None else {}
self.quandl_error_code = quandl_error_code
self.quandl_message = quandl_message if quandl_message is not None \
else self.GENERIC_ERROR_MESSAGE
self.response_data = response_data
| (self, quandl_message=None, http_status=None, http_body=None, http_headers=None, quandl_error_code=None, response_data=None) | [
-0.028930731117725372,
0.005144545342773199,
-0.021869206801056862,
-0.03718547523021698,
-0.03738108649849892,
0.0015783288981765509,
-0.04471646621823311,
0.032158296555280685,
-0.011951776221394539,
-0.006577388849109411,
0.03857430815696716,
0.023629697039723396,
0.030045708641409874,
0.03859386965632439,
-0.0028216755017638206,
0.021321499720215797,
0.006210620049387217,
-0.0008612956153228879,
0.01456317026168108,
-0.07566197961568832,
0.0007365942001342773,
0.03718547523021698,
-0.014387121424078941,
0.10148251056671143,
0.02576184831559658,
0.02476423606276512,
-0.034994643181562424,
-0.027326729148626328,
0.026348678395152092,
0.007839074358344078,
0.042799487709999084,
0.009526210837066174,
-0.023512331768870354,
0.0524626225233078,
-0.01790810376405716,
0.014230633154511452,
0.007697256747633219,
-0.06290820240974426,
-0.08121730387210846,
0.01182462926954031,
-0.0456162728369236,
-0.0041860556229949,
-0.033625371754169464,
-0.015531440265476704,
0.031845320016145706,
0.01595200225710869,
-0.009491979144513607,
0.01717456430196762,
-0.02492072433233261,
0.010416236706078053,
-0.03313634917140007,
0.055905360728502274,
0.006870804354548454,
-0.006582279223948717,
-0.03168883174657822,
0.046907298266887665,
0.003968439530581236,
0.08231272548437119,
-0.029771855100989342,
-0.0009652135195210576,
-0.06083473563194275,
0.08466004580259323,
0.0011956666130572557,
-0.0172821506857872,
0.01716478541493416,
-0.004511257633566856,
-0.023531893268227577,
0.008748660795390606,
-0.023140672594308853,
0.0326668843626976,
0.025957457721233368,
0.02943931706249714,
-0.06177366524934769,
0.009286588989198208,
0.0942058190703392,
-0.012470142915844917,
-0.07261046022176743,
0.02781575359404087,
-0.04542066156864166,
0.05281472206115723,
0.04702466353774071,
0.0055651068687438965,
-0.024666430428624153,
-0.024881603196263313,
0.025429310277104378,
-0.0631820559501648,
-0.007887976244091988,
0.006504035089164972,
0.03170839324593544,
-0.010807457379996777,
-0.03432957082986832,
-0.04131285101175308,
-0.04686817526817322,
-0.025664042681455612,
0.018358007073402405,
-0.041273728013038635,
-0.014837024733424187,
-0.00396354915574193,
-0.01716478541493416,
0.028578633442521095,
-0.03830045461654663,
0.021321499720215797,
-0.03393834829330444,
-0.016626857221126556,
0.0009847745532169938,
-0.007496756501495838,
-0.004530818667262793,
-0.09373635053634644,
0.043425437062978745,
-0.03562059625983238,
-0.0069588287733495235,
0.01382963266223669,
-0.018622079864144325,
0.04788534715771675,
-0.033742740750312805,
0.018935056403279305,
-0.0016296764370054007,
-0.03108244203031063,
-0.00993210170418024,
-0.028148291632533073,
-0.0001073563180398196,
-0.005501533392816782,
0.001248848158866167,
0.0056335702538490295,
0.0471811518073082,
0.03491640090942383,
-0.009990785270929337,
-0.05367540568113327,
0.01737995631992817,
-0.04139109328389168,
0.07480129599571228,
-0.006269303150475025,
0.029224146157503128,
0.0004468467668630183,
-0.009941882453858852,
0.0005085862358100712,
-0.026153067126870155,
0.05758760869503021,
-0.012978728860616684,
0.04064777493476868,
0.021517109125852585,
0.029087219387292862,
-0.010054358281195164,
-0.018817689269781113,
-0.013653583824634552,
0.03618786484003067,
0.005917205009609461,
-0.05692253261804581,
-0.04436436668038368,
-0.004054018761962652,
0.010827017948031425,
-0.06991104036569595,
0.04502943903207779,
0.008445465005934238,
-0.026739899069070816,
-0.031845320016145706,
0.001948765479028225,
-0.11454926431179047,
0.023101551458239555,
0.01912088505923748,
0.019570788368582726,
-0.0577440969645977,
0.04502943903207779,
-0.036735571920871735,
-0.03209961578249931,
0.008538380265235901,
-0.008264525793492794,
-0.08990239351987839,
0.00507119158282876,
0.02349277026951313,
0.013389510102570057,
-0.005658021662384272,
-0.054183993488550186,
0.00268719345331192,
-0.057861462235450745,
0.02411872334778309,
0.010181504301726818,
0.013281924650073051,
-0.028930731117725372,
-0.07276695221662521,
-0.019189348444342613,
0.0020905828569084406,
-0.02943931706249714,
0.05168018490076065,
0.006323095876723528,
0.028480827808380127,
-0.031845320016145706,
0.030358685180544853,
0.03360581025481224,
0.03354712948203087,
-0.010963944718241692,
-0.03168883174657822,
-0.0009823293657973409,
0.007325597573071718,
0.00942840613424778,
0.0031150905415415764,
0.03409483656287193,
-0.05868302285671234,
0.08911995589733124,
0.020402131602168083,
0.006371998228132725,
0.060717370361089706,
0.01996200904250145,
0.011492092162370682,
-0.031102003529667854,
0.04835481196641922,
-0.030749903991818428,
0.07707037031650543,
-0.059543710201978683,
-0.03652040287852287,
-0.02670077607035637,
-0.007711927406489849,
-0.04229089990258217,
0.048746030777692795,
0.014524048194289207,
0.024196967482566833,
-0.009311039932072163,
-0.025135895237326622,
0.03933718800544739,
0.0014108377508819103,
0.11306262761354446,
-0.028774242848157883,
-0.005330374930053949,
-0.04733764007687569,
-0.014915268868207932,
0.06955894827842712,
0.038261331617832184,
-0.0007170332246460021,
-0.023453649133443832,
-0.015736831352114677,
-0.03481859341263771,
0.016450807452201843,
0.003657908644527197,
-0.016450807452201843,
-0.036422595381736755,
-0.056648679077625275,
-0.00034934739232994616,
0.018602518364787102,
-0.07890910655260086,
-0.040804263204336166,
0.024607747793197632,
-0.03814396634697914,
-0.00699306046590209,
0.06611620634794235,
-0.0019878875464200974,
-0.03296029940247536,
-0.028891609981656075,
0.07914383709430695,
-0.020050033926963806,
-0.018103713169693947,
-0.07108470052480698,
-0.0250772126019001,
-0.015453196130692959,
-0.03249083459377289,
0.057704973965883255,
0.018670981749892235,
0.029674049466848373,
-0.023199355229735374,
0.0028779134154319763,
-0.01364380307495594,
0.034427374601364136,
-0.0418214350938797,
-0.008753551170229912,
0.05887863412499428,
-0.020460814237594604,
-0.023629697039723396,
0.01685180887579918,
0.004261854570358992,
0.025194577872753143,
0.01685180887579918,
0.18950705230236053,
-0.01377095002681017,
0.005403728689998388,
0.006127486005425453,
-0.022045256569981575,
-0.028539510443806648,
0.012978728860616684,
-0.023199355229735374,
-0.027307167649269104,
-0.019414300099015236,
0.032471273094415665,
-0.02607482299208641,
0.06224312633275986,
0.01617695391178131,
0.033155910670757294,
0.003758158767595887,
-0.027189800515770912,
0.03706810995936394,
-0.01601068489253521,
-0.03581620752811432,
-0.008391672745347023,
0.03781142830848694,
-0.02286681905388832,
0.02006959356367588,
0.021575791761279106,
0.009203454479575157,
-0.04315158352255821,
0.045225050300359726,
0.05081949755549431,
-0.01161923911422491,
0.002814339939504862,
-0.011893092654645443,
0.0912325456738472,
0.00183751224540174,
-0.014426243491470814,
-0.050858620554208755,
0.05062389001250267,
0.012783118523657322,
-0.015541221015155315,
-0.027639703825116158,
0.051171597093343735,
0.03824177011847496,
-0.03849606588482857,
0.017507102340459824,
-0.00924257654696703,
0.03677469491958618,
0.03501420468091965,
-0.026779020205140114,
-0.0043400987051427364,
0.014035023748874664,
-0.009046966210007668,
-0.06768108904361725,
0.05750936269760132,
-0.022632086649537086,
0.020773790776729584,
-0.031160686165094376,
0.008870917372405529,
-0.03475991263985634,
0.024998968467116356,
0.02875468134880066,
-0.011188896372914314,
0.03920026123523712,
0.00035973917692899704,
-0.055396776646375656,
0.012440801598131657,
-0.08645965903997421,
-0.009648467414081097,
0.004122482612729073,
-0.021047644317150116,
-0.0584874153137207,
-0.034896839410066605,
-0.0035943351686000824,
0.020304325968027115,
0.023375404998660088,
0.004014897160232067,
-0.04440348967909813,
-0.018054811283946037,
-0.04170406982302666,
0.015384732745587826,
-0.0463595911860466,
-0.054692577570676804,
-0.015541221015155315,
0.022162621840834618,
0.05081949755549431,
0.0630255714058876,
-0.05715726688504219,
-0.020949840545654297,
-0.019551226869225502,
-0.007633683271706104,
0.05547501891851425,
0.062086641788482666,
0.011355165392160416,
-0.03618786484003067,
0.04913725331425667,
-0.049019888043403625,
-0.010259748436510563,
0.0011382061056792736,
-0.026720337569713593,
-0.0022531836293637753,
0.04455997794866562,
0.009154551662504673,
-0.10289090126752853,
-0.052227891981601715,
0.012548387050628662,
0.010680310428142548,
0.024881603196263313,
-0.03260819986462593,
0.00858239270746708,
-0.04581188037991524,
-0.03366449475288391,
-0.0032984749414026737,
-0.048433057963848114,
-0.005569997243583202,
-0.030202196910977364,
-0.01712566241621971,
-0.0028167851269245148,
0.020930279046297073,
0.018935056403279305,
0.00022174236073624343,
0.06110858917236328,
-0.018367785960435867,
-0.03432957082986832,
0.02096940018236637,
0.023355843499302864,
-0.024607747793197632,
0.01145297009497881,
-0.04064777493476868,
0.05758760869503021,
-0.0311802476644516,
-0.032686445862054825,
0.012587509118020535,
-0.015208683907985687,
-0.032627761363983154,
0.031786639243364334,
0.02149754762649536,
0.0022923056967556477,
0.01838734745979309,
0.025742286816239357,
0.027091996744275093,
0.03419264405965805,
0.05281472206115723,
-0.03796791657805443,
-0.03652040287852287,
-0.002271522069349885,
-0.03565971925854683,
0.0418214350938797,
0.030749903991818428,
-0.003655463457107544,
0.02803092449903488,
0.026837702840566635,
-0.018436249345541,
0.008870917372405529,
0.07640530169010162,
0.00861173402518034,
0.0002802725648507476,
0.06052175909280777,
-0.013839413411915302,
-0.0004459298506844789,
0.03652040287852287,
-0.04440348967909813,
0.006846352946013212,
0.047650616616010666,
-0.06365151703357697,
-0.02539018914103508,
0.020245643332600594,
0.038632992655038834,
-0.06494254618883133,
0.03249083459377289,
-0.018152615055441856,
-0.007085975259542465,
0.01895461603999138,
-0.04757237061858177,
0.05273647978901863,
0.03303854167461395,
0.011658361181616783,
-0.01902308128774166,
-0.040373921394348145,
0.011012847535312176,
-0.002929260954260826,
-0.02896985225379467,
0.038691673427820206,
0.03738108649849892,
-0.0012072810204699636,
0.002926815766841173,
0.027209362015128136,
-0.04299509525299072,
-0.05105423182249069,
-0.009672918356955051,
0.016157392412424088,
-0.033214591443538666,
0.02803092449903488,
0.005428179632872343,
-0.029478440061211586,
-0.020147837698459625,
-0.0032886944245547056,
0.07335378229618073,
0.020871596410870552,
0.005036959424614906,
-0.01759512722492218,
-0.036872498691082,
-0.03630523011088371,
0.057704973965883255,
-0.007976001128554344,
0.04514680802822113,
0.015942221507430077,
0.0032397920731455088,
-0.03272556513547897,
-0.05242350324988365,
-0.011785507202148438,
-0.03176707774400711,
0.05105423182249069,
-0.00964357703924179,
0.06635093688964844,
0.008362331427633762,
-0.01493482943624258,
-0.0660770833492279,
0.03781142830848694,
-0.023453649133443832,
0.05257999151945114,
-0.01595200225710869,
0.026622531935572624,
0.06521639972925186,
-0.010729213245213032,
-0.036050938069820404,
-0.018426470458507538,
-0.021301938220858574,
-0.030828148126602173,
0.009702259674668312,
-0.0018399573164060712,
0.005746046081185341,
0.018358007073402405,
-0.06646830588579178,
-0.006460023112595081,
0.004044238477945328,
0.08027837425470352,
-0.0409998744726181,
0.02096940018236637,
0.03223654255270958,
-0.0041664945892989635,
-0.00601990008726716,
-0.052971210330724716,
0.011863751336932182,
0.00183751224540174,
-0.023003745824098587,
-0.024979406967759132,
0.04831568896770477,
-0.06439483910799026,
0.038535185158252716,
-0.010259748436510563,
0.042486511170864105,
-0.003907311242073774,
0.0881027802824974,
0.024588188156485558,
-0.012118044309318066,
-0.04549890384078026,
-0.025057651102542877,
-0.017556004226207733,
-0.005437960382550955,
0.011130213737487793,
0.05050652474164963,
-0.012294094078242779,
-0.06095210090279579,
-0.018768787384033203,
0.018886152654886246,
-0.021477986127138138,
0.08458179980516434,
-0.05747024342417717,
-0.012284313328564167,
0.02028476633131504,
-0.01669532060623169,
0.022456036880612373,
0.06998928636312485,
-0.028265656903386116,
-0.03957191854715347,
-0.05766585096716881,
-0.04956759512424469,
-0.012792899273335934,
0.07933945208787918,
0.002495251130312681,
0.026485605165362358,
0.022299548611044884,
-0.07527075707912445,
-0.011159555055201054,
-0.0015991124091669917,
-0.04268211871385574,
0.016998516395688057,
0.03472078964114189,
-0.009369722567498684,
0.04651607573032379,
-0.01627475954592228,
0.011394287459552288,
-0.00971693079918623,
-0.020265204831957817,
0.008802453987300396,
-0.012871143408119678,
0.0125581668689847,
0.016617076471447945,
-0.012088702991604805,
-0.043581925332546234,
-0.030906392261385918,
0.010582505725324154,
0.002399891149252653,
-0.01943386159837246,
0.05692253261804581,
0.03108244203031063,
-0.016734441742300987,
-0.006831682287156582,
0.0028094497974961996,
0.04397314786911011,
0.04608573392033577,
0.04424700140953064,
0.010249968618154526,
-0.07190626859664917,
-0.05410574749112129,
-0.03280381113290787,
-0.018935056403279305,
-0.010367333889007568,
0.011149774305522442,
0.07394061237573624,
-0.019512105733156204,
-0.03272556513547897,
-0.034055713564157486,
-0.018553616479039192,
-0.029889220371842384,
0.039258942008018494,
0.03401659429073334,
-0.013008070178329945,
-0.06443396210670471,
-0.008836685679852962,
-0.004066244699060917,
0.003393834922462702,
0.07718773931264877,
-0.04823744669556618,
-0.005956327077001333,
0.013008070178329945,
-0.002157823648303747,
-0.030300002545118332,
0.05363628268241882,
-0.05371452867984772,
-0.024157844483852386,
-0.0036823598202317953,
-0.03644215688109398,
-0.023942673578858376,
0.004310757387429476,
-0.01907198317348957,
-0.056805167347192764,
-0.03272556513547897,
0.054653458297252655,
-0.0008967499597929418,
-0.025096774101257324,
-0.01288092415779829,
-0.07335378229618073,
-0.018191738054156303,
0.06470781564712524,
-0.042017046362161636,
-0.015511879697442055,
0.044638220220804214,
-0.042799487709999084,
-0.07652266323566437,
0.014778342097997665,
0.022143060341477394,
0.05692253261804581,
0.00008863581751938909,
-0.05570974946022034,
0.014807683415710926,
0.037009429186582565,
0.01869054324924946,
0.026622531935572624,
0.07906559854745865,
0.03495552018284798,
0.0010269528720527887,
0.05156281590461731,
-0.0020881376694887877,
-0.033058103173971176,
0.009262137115001678,
0.018739445134997368,
-0.03086727112531662,
-0.06216488406062126,
0.049489349126815796,
-0.0345643013715744,
-0.021165011450648308,
0.023355843499302864,
0.03301898017525673,
0.016000904142856598,
-0.06639005988836288,
0.06146068871021271,
-0.05019354820251465,
0.012431020848453045,
0.025409748777747154,
-0.018358007073402405,
-0.027678826823830605,
-0.018260201439261436,
0.06505991518497467,
0.002342430641874671,
-0.00026514334604144096,
0.025214139372110367,
0.020421693101525307,
-0.03339064121246338,
0.04459909722208977,
-0.007027292158454657,
0.014612073078751564,
0.03734196349978447,
0.03409483656287193,
0.04366017132997513,
-0.007667915429919958,
0.024725114926695824,
0.013907876797020435,
-0.05289296433329582,
0.03534674271941185,
0.006137266289442778,
-0.0063622179441154,
0.04952847212553024,
-0.045068562030792236,
-0.012059361673891544,
-0.005237460136413574,
0.05078037828207016,
-0.0027140898164361715,
0.026153067126870155,
-0.010367333889007568,
-0.039963141083717346,
-0.03239303082227707,
-0.005755826830863953,
-0.030965076759457588,
0.01602046564221382,
-0.019717495888471603,
-0.031375858932733536,
-0.039161138236522675,
-0.12065229564905167,
0.010132602415978909,
0.045381538569927216,
0.03757669776678085,
-0.019189348444342613,
-0.04260387644171715,
0.016685539856553078,
-0.023883990943431854,
-0.004870690871030092,
0.02102808468043804,
-0.007301146164536476,
-0.012763557955622673,
-0.03475991263985634,
0.022103939205408096,
0.038163527846336365,
0.011560555547475815,
-0.04557714983820915,
-0.0026749679818749428,
0.02265164814889431,
0.03730284422636032,
0.01712566241621971,
-0.033781860023736954,
-0.021927889436483383,
0.025879213586449623,
0.01896439678966999,
-0.0017996127717196941,
0.007144658360630274,
0.045381538569927216,
-0.04393402487039566,
0.020930279046297073,
-0.04060865193605423,
0.036735571920871735,
-0.01395677961409092,
-0.0010801344178617,
0.04565539211034775,
-0.03477947413921356,
-0.05195403844118118,
-0.0054917531087994576,
-0.06955894827842712,
0.030886832624673843,
0.031630150973796844,
0.058174438774585724,
0.05563150718808174,
0.011335603892803192,
-0.016088929027318954,
0.04518592730164528,
-0.002841236535459757,
-0.02881336584687233,
0.005667801946401596,
0.0425647534430027,
-0.040686897933483124,
0.02227998897433281,
0.01658773422241211,
-0.010152162984013557,
-0.03303854167461395,
-0.0034574081655591726,
0.042212653905153275,
-0.0029048097785562277,
-0.028109168633818626,
-0.012734216637909412,
0.04839393496513367,
0.010758554562926292,
-0.02184964530169964,
-0.03444693610072136,
0.030476050451397896,
0.038163527846336365,
0.014778342097997665,
0.018670981749892235,
0.04060865193605423,
0.02728760614991188,
0.05277559906244278
]
|
31,257 | quandl.errors.quandl_error | __str__ | null | def __str__(self):
if self.http_status is None:
status_string = ''
else:
status_string = "(Status %(http_status)s) " % {"http_status": self.http_status}
if self.quandl_error_code is None:
quandl_error_string = ''
else:
quandl_error_string = "(Quandl Error %(quandl_error_code)s) " % {
"quandl_error_code": self.quandl_error_code}
return "%(ss)s%(qes)s%(qm)s" % {
"ss": status_string, "qes": quandl_error_string, "qm": self.quandl_message
}
| (self) | [
-0.02432783879339695,
-0.02992902882397175,
0.014945844188332558,
-0.029574288055300713,
0.036351729184389114,
-0.032580260187387466,
-0.029294228181242943,
-0.047759488224983215,
0.0753546878695488,
-0.06538456678390503,
-0.019193414598703384,
-0.019660180434584618,
-0.000598043785430491,
0.008490472100675106,
0.03894694522023201,
0.015132550150156021,
-0.01083830464631319,
-0.09716199338436127,
0.049029089510440826,
-0.026269584894180298,
0.005787897389382124,
0.05586254224181175,
0.022292738780379295,
0.01215458381921053,
0.011127699166536331,
0.016374148428440094,
0.017839793115854263,
-0.07606416940689087,
-0.01083830464631319,
0.003983846865594387,
0.02051902934908867,
-0.02079908922314644,
-0.02036966383457184,
0.012696032412350178,
-0.03685583546757698,
0.03420460596680641,
-0.025672124698758125,
-0.0331590510904789,
-0.08595960587263107,
-0.0320761539041996,
-0.05093349516391754,
0.011482440866529942,
-0.04895440861582756,
-0.03984313830733299,
0.0080190384760499,
-0.007468254305422306,
0.001946413773111999,
0.061239685863256454,
-0.007043497636914253,
-0.005465828813612461,
0.02686704508960247,
0.07946223020553589,
-0.04215829819440842,
-0.03265494108200073,
-0.04447345435619354,
-0.01982821524143219,
-0.013181469403207302,
0.022012680768966675,
-0.013890953734517097,
-0.017083631828427315,
-0.0279872827231884,
0.057580240070819855,
-0.0023186595644801855,
0.013526875525712967,
0.01104368083178997,
-0.015748681500554085,
-0.031049268320202827,
0.023300953209400177,
0.020724406465888023,
0.013592222705483437,
0.053398020565509796,
-0.035922303795814514,
-0.06676619499921799,
0.021564584225416183,
0.04977591708302498,
-0.03095591440796852,
-0.09648984670639038,
-0.0004796019638888538,
-0.030451808124780655,
-0.005741220433264971,
0.045631036162376404,
-0.02727779932320118,
-0.00693147350102663,
-0.06616873294115067,
0.0009084431221708655,
-0.07636290043592453,
-0.029182204976677895,
0.0011774169979617,
0.0028472719714045525,
0.003916165791451931,
0.00496172159910202,
-0.015104544349014759,
-0.04503357410430908,
0.014441736973822117,
-0.0022999888751655817,
-0.008187074214220047,
0.0020899444352835417,
-0.05362206697463989,
-0.02040700614452362,
-0.005829906091094017,
-0.01657952554523945,
0.014880497008562088,
-0.03366315737366676,
-0.02208736166357994,
-0.026773693040013313,
-0.020631052553653717,
-0.02081775851547718,
-0.03151603415608406,
0.03491409122943878,
-0.017410367727279663,
0.0027422497514635324,
-0.023095576092600822,
-0.02925688773393631,
-0.034092582762241364,
0.027053751051425934,
-0.020929783582687378,
-0.02992902882397175,
-0.0028052630368620157,
0.013713582418859005,
-0.04096337407827377,
0.04484686627984047,
-0.017410367727279663,
-0.044361431151628494,
-0.04458547756075859,
0.005293125286698341,
0.0596340112388134,
-0.04383865371346474,
-0.027800576761364937,
0.04574305936694145,
-0.0914861187338829,
0.01801716350018978,
0.004282576963305473,
-0.011137034744024277,
-0.007771652191877365,
0.05832706764340401,
-0.01173449493944645,
-0.0393950417637825,
0.05522774159908295,
0.04316651076078415,
0.14861826598644257,
0.009587371721863747,
0.01638348400592804,
-0.028192659839987755,
-0.0037948067765682936,
0.008299097418785095,
-0.006992153357714415,
0.02488795854151249,
0.02036966383457184,
-0.007267544977366924,
-0.030881231650710106,
0.05821504443883896,
-0.0108196334913373,
0.026493633165955544,
-0.0063573517836630344,
-0.036930520087480545,
0.023711707442998886,
0.015384604223072529,
-0.0641523078083992,
0.0279872827231884,
-0.00248086079955101,
0.003465736750513315,
-0.0824495255947113,
0.040589962154626846,
-0.033271074295043945,
0.011174376122653484,
0.036911848932504654,
0.0016908594407141209,
-0.03174008056521416,
0.03138533979654312,
0.023973096162080765,
0.0014399727806448936,
-0.017541062086820602,
-0.04884238541126251,
0.035530220717191696,
-0.016570189967751503,
0.04697532206773758,
0.003806476015597582,
0.06023147329688072,
-0.023711707442998886,
-0.0688946470618248,
-0.035959646105766296,
-0.0223860926926136,
-0.041336789727211,
0.02236742153763771,
0.04809555783867836,
-0.039731115102767944,
-0.004380598198622465,
0.009517356753349304,
0.03300968557596207,
0.024999981746077538,
0.0009866263717412949,
-0.016915597021579742,
-0.0009813753422349691,
0.023431647568941116,
-0.03590363264083862,
-0.021583255380392075,
0.0467139333486557,
-0.11404024809598923,
0.09126207232475281,
0.000409878819482401,
-0.030209088698029518,
0.06400293856859207,
-0.01711163856089115,
0.026773693040013313,
-0.004901042208075523,
0.021433889865875244,
0.00964338332414627,
0.03470871224999428,
-0.024682581424713135,
-0.007108844816684723,
-0.021994009613990784,
0.01773710362613201,
-0.06863325834274292,
0.03898428753018379,
0.03125464543700218,
0.00339338812045753,
0.013125456869602203,
0.01694360189139843,
-0.0172236617654562,
0.018530607223510742,
0.04062730446457863,
-0.09185952693223953,
0.01745704561471939,
-0.07259143143892288,
-0.047460757195949554,
0.05134424939751625,
0.0376773439347744,
0.006623408291488886,
-0.028939485549926758,
-0.00020931533072143793,
0.01851193606853485,
0.021415218710899353,
0.006147306878119707,
0.0540328212082386,
-0.029200874269008636,
0.025522759184241295,
-0.03894694522023201,
-0.016952937468886375,
-0.052688535302877426,
-0.016411488875746727,
-0.01715831458568573,
-0.005923259537667036,
0.014656449668109417,
0.04544432833790779,
0.05134424939751625,
-0.09992524236440659,
0.013797599822282791,
0.07120980322360992,
-0.032710954546928406,
-0.020481687039136887,
-0.013741588220000267,
-0.010539574548602104,
-0.027501847594976425,
-0.0512322261929512,
0.04148615524172783,
-0.033831194043159485,
-0.0037317934911698103,
0.014217689633369446,
0.005036403890699148,
-0.01903471350669861,
-0.018465260043740273,
-0.04152349382638931,
-0.03489542007446289,
0.010800963267683983,
-0.01629946567118168,
-0.0038624878507107496,
-0.030862562358379364,
0.025522759184241295,
0.035362184047698975,
0.04062730446457863,
0.11829715222120285,
-0.010698274709284306,
-0.06228524073958397,
0.010212837718427181,
-0.049850597977638245,
-0.035959646105766296,
0.0005280289333313704,
0.01982821524143219,
-0.06486178934574127,
-0.055638495832681656,
-0.007300218567252159,
-0.017102302983403206,
0.0475727804005146,
0.01217325497418642,
0.07460786402225494,
-0.01801716350018978,
0.014348383992910385,
-0.017979823052883148,
0.02167660929262638,
0.030209088698029518,
0.017083631828427315,
0.022180715575814247,
-0.04208361357450485,
-0.01892269030213356,
0.02938758209347725,
-0.0045649707317352295,
0.03547420725226402,
0.00964338332414627,
0.024253156036138535,
0.010670268908143044,
-0.018334563821554184,
0.025560101494193077,
0.05201639235019684,
-0.010212837718427181,
-0.04118742421269417,
-0.032710954546928406,
0.014497748576104641,
-0.008345774374902248,
-0.008317768573760986,
-0.02178863249719143,
-0.021975338459014893,
0.012602679431438446,
0.03435397148132324,
0.03838682919740677,
0.006922138389199972,
0.07307686656713486,
-0.014096329919993877,
-0.0013337836135178804,
0.012574673630297184,
0.06814782321453094,
-0.00841578934341669,
-0.02139654941856861,
0.050373375415802,
0.010166161693632603,
0.02546674758195877,
-0.06769972294569016,
-0.0396190881729126,
-0.004431942477822304,
0.04488420858979225,
0.03265494108200073,
-0.01173449493944645,
-0.037471964955329895,
0.003939504269510508,
-0.02432783879339695,
0.03175875172019005,
-0.04566837474703789,
0.036239705979824066,
-0.027651211246848106,
-0.03743462637066841,
-0.047460757195949554,
0.044660162180662155,
-0.00017970487533602864,
0.008854549378156662,
0.03427928686141968,
-0.02277817577123642,
-0.000024742239475017413,
-0.04805821552872658,
0.00094928516773507,
0.02828601375222206,
0.00203743320889771,
-0.05175500363111496,
-0.011230387724936008,
0.02843537926673889,
0.02617623098194599,
0.04062730446457863,
-0.02079908922314644,
-0.003379385219886899,
0.021751290187239647,
0.005615193862468004,
0.07027627527713776,
0.03737861290574074,
0.004098204430192709,
0.0009673723252490163,
0.050298694521188736,
-0.03125464543700218,
0.001470312592573464,
0.01370424684137106,
-0.03136666864156723,
0.06691555678844452,
0.014628443866968155,
-0.039469726383686066,
-0.026512302458286285,
-0.0385361947119236,
-0.018334563821554184,
-0.05388345569372177,
0.08431659638881683,
0.007692302111536264,
0.006259330548346043,
-0.04626583680510521,
-0.0764375850558281,
0.05272587761282921,
-0.02755785919725895,
-0.023375635966658592,
0.008551151491701603,
-0.0003349045291543007,
0.01518856268376112,
0.005227778106927872,
0.009615377523005009,
-0.029480934143066406,
0.04002984240651131,
-0.006572064012289047,
-0.04032857343554497,
0.010567580349743366,
0.012210596352815628,
-0.06079159304499626,
-0.022871529683470726,
-0.0109783336520195,
0.018894683569669724,
-0.04148615524172783,
-0.01756906881928444,
0.02729647047817707,
-0.034652698785066605,
-0.03629571571946144,
0.013825605623424053,
-0.007071503438055515,
-0.01525390986353159,
0.01685958355665207,
0.022722164168953896,
-0.004494955763220787,
0.050410717725753784,
0.010222173295915127,
-0.05474230647087097,
-0.07531734555959702,
0.0044972896575927734,
0.008551151491701603,
0.026811033487319946,
-0.02979833446443081,
-0.013181469403207302,
-0.005993274040520191,
0.04006718471646309,
-0.0357355959713459,
0.012294613756239414,
0.07221802324056625,
0.056198615580797195,
-0.027875259518623352,
0.05022400990128517,
-0.009162615053355694,
0.02516801841557026,
0.06060488522052765,
0.01090365182608366,
0.013713582418859005,
0.004779682960361242,
-0.03610901162028313,
-0.017989158630371094,
0.005839241668581963,
-0.01597272977232933,
0.0005446574650704861,
0.029182204976677895,
-0.029891688376665115,
-0.0036454417277127504,
0.03332708403468132,
-0.03416726365685463,
0.02361835539340973,
0.04010452702641487,
0.021004466339945793,
0.0018950696103274822,
-0.06613139063119888,
-0.04159817844629288,
-0.007612952031195164,
0.018119852989912033,
-0.006646746303886175,
0.037901390343904495,
-0.04256904870271683,
-0.014180348254740238,
0.05948464572429657,
-0.04189690575003624,
-0.006604737602174282,
-0.026213573291897774,
-0.02684837393462658,
-0.03131065517663956,
-0.009087932296097279,
0.041299447417259216,
-0.0772964358329773,
0.06430166959762573,
0.03220684826374054,
-0.019510814920067787,
0.011295734904706478,
0.03095591440796852,
-0.057580240070819855,
-0.030265100300312042,
-0.02955561690032482,
0.033140379935503006,
-0.04581774026155472,
0.046639248728752136,
0.020444346591830254,
0.06198651343584061,
-0.029182204976677895,
-0.01497384998947382,
0.007402907125651836,
0.010306190699338913,
-0.023711707442998886,
-0.050410717725753784,
0.029070179909467697,
0.006656081881374121,
0.007155521307140589,
-0.023861072957515717,
0.0477968268096447,
0.019454803317785263,
-0.012994762510061264,
0.029200874269008636,
0.05470496416091919,
0.04600444808602333,
-0.027053751051425934,
-0.024701250717043877,
-0.04346524178981781,
-0.010371538810431957,
-0.06676619499921799,
-0.026549644768238068,
-0.052688535302877426,
0.03685583546757698,
0.04320385307073593,
-0.055339764803647995,
0.0009201123029924929,
0.039021629840135574,
0.06702758371829987,
-0.02699773944914341,
0.06740099936723709,
0.06486178934574127,
0.01939879171550274,
-0.001706029404886067,
0.009405332617461681,
-0.0361650213599205,
0.041859567165374756,
-0.03306569531559944,
-0.041262105107307434,
-0.0009685392724350095,
-0.00413321191444993,
0.0220686923712492,
0.021433889865875244,
0.053510043770074844,
-0.018810665234923363,
0.03704254329204559,
-0.0160380769520998,
-0.0037831375375390053,
-0.04600444808602333,
0.024663910269737244,
-0.0026839040219783783,
0.0032953673508018255,
-0.06691555678844452,
0.09275572001934052,
-0.001921908580698073,
0.0004215479420963675,
0.02262881025671959,
-0.008961905725300312,
0.003213683143258095,
0.0951455608010292,
-0.09858095645904541,
-0.0000781832859502174,
0.0015064869076013565,
0.007986364886164665,
0.024271827191114426,
0.009452009573578835,
-0.0370238721370697,
-0.05082147195935249,
-0.03472738340497017,
-0.03489542007446289,
0.03138533979654312,
0.06292004138231277,
0.00826642382889986,
-0.02236742153763771,
-0.010548909194767475,
-0.041411470621824265,
0.00158116954844445,
-0.0172236617654562,
-0.02180730365216732,
0.047759488224983215,
0.015179227106273174,
0.04316651076078415,
0.049551866948604584,
0.025914842262864113,
0.015664663165807724,
-0.006292004603892565,
0.025821490213274956,
-0.0023630023933947086,
-0.03127331659197807,
0.035511549562215805,
0.01230394933372736,
-0.010306190699338913,
-0.02897682785987854,
-0.024962641298770905,
-0.012098572216928005,
-0.017709098756313324,
0.0012964423513039947,
0.04884238541126251,
-0.009718066081404686,
-0.02094845287501812,
0.02966764010488987,
0.024159803986549377,
0.03582895174622536,
0.10619857907295227,
-0.00328836590051651,
0.004196225665509701,
0.0020806090906262398,
-0.041150081902742386,
-0.023879744112491608,
0.033569805324077606,
-0.0064040282741189,
0.004172887187451124,
0.057468216866254807,
0.006805446930229664,
-0.04667659103870392,
-0.04167285934090614,
0.01329349260777235,
-0.017326349392533302,
0.09768477082252502,
-0.0015111545799300075,
0.0046676588244736195,
-0.06314408779144287,
-0.003610434243455529,
0.02923821657896042,
0.023300953209400177,
0.05164298042654991,
0.01512321550399065,
0.019734863191843033,
0.042979802936315536,
0.006903467699885368,
0.025634784251451492,
0.04727404937148094,
-0.07303953170776367,
0.01350820530205965,
-0.012443979270756245,
-0.018717313185334206,
-0.04238234460353851,
0.00685212342068553,
-0.03188944607973099,
-0.046601906418800354,
-0.01075428631156683,
0.02335696667432785,
-0.03364448621869087,
-0.007141518406569958,
0.015916718170046806,
0.02755785919725895,
-0.07333825528621674,
0.046639248728752136,
-0.008747193031013012,
0.028790120035409927,
0.028360696509480476,
-0.02979833446443081,
-0.03319638967514038,
-0.04768480360507965,
0.004056195728480816,
0.08857350051403046,
0.007435580715537071,
-0.03674381226301193,
-0.05556381493806839,
0.00597927113994956,
0.017102302983403206,
0.04947718605399132,
-0.006100630387663841,
0.021713949739933014,
0.023095576092600822,
0.03407391160726547,
-0.05272587761282921,
-0.011725159361958504,
-0.020294981077313423,
0.05179234594106674,
-0.05433155223727226,
-0.09439873695373535,
0.019772203639149666,
-0.057878971099853516,
-0.03426061570644379,
0.005447158124297857,
0.011650476604700089,
0.0234689898788929,
-0.02856607362627983,
0.06967881321907043,
-0.046601906418800354,
0.020463017746806145,
0.0003398639091756195,
-0.012322619557380676,
-0.0072115333750844,
-0.07531734555959702,
-0.0019335777033120394,
-0.05418218672275543,
0.031049268320202827,
0.03035845421254635,
-0.00545182591304183,
-0.015095209702849388,
0.04932782053947449,
-0.0613517090678215,
0.02600819617509842,
0.028472719714045525,
-0.0005936679081059992,
-0.023020895197987556,
-0.04637786000967026,
0.041299447417259216,
0.028622085228562355,
0.0024155136197805405,
0.026811033487319946,
-0.0684465542435646,
0.040589962154626846,
0.009129941463470459,
-0.03894694522023201,
0.002667567227035761,
0.0049710567109286785,
0.045220281928777695,
-0.019380120560526848,
0.01026885025203228,
-0.031441349536180496,
-0.03276696801185608,
-0.06755036115646362,
-0.04656456783413887,
-0.04148615524172783,
0.012266607955098152,
0.03821879252791405,
-0.0404779389500618,
0.012696032412350178,
-0.05713214725255966,
0.005008398089557886,
-0.014124336652457714,
0.02096712402999401,
-0.011911866255104542,
0.010212837718427181,
-0.016784902662038803,
0.012994762510061264,
-0.015309921465814114,
0.07654960453510284,
-0.03394321724772453,
-0.01386294700205326,
-0.018679970875382423,
0.03984313830733299,
0.06915603578090668,
-0.005895253270864487,
-0.012117242440581322,
-0.01477780845016241,
-0.035791609436273575,
0.03478339686989784,
0.01870797760784626,
0.021321866661310196,
0.013162798248231411,
-0.00090144167188555,
0.032710954546928406,
-0.0080190384760499,
-0.001112653175368905,
0.06161309778690338,
0.053808774799108505,
0.02475726418197155,
-0.021975338459014893,
0.0038671554066240788,
-0.022124703973531723,
0.009227962233126163,
0.06150107458233833,
-0.047199368476867676,
-0.0252987127751112,
0.05571317672729492,
-0.01455376110970974,
0.010455556213855743,
0.038032084703445435,
0.020743077620863914,
0.03868555650115013,
0.052949924021959305,
0.03502611443400383,
0.03334575518965721,
-0.031572043895721436,
0.03696785867214203,
0.00646937545388937,
0.06228524073958397,
0.003311704145744443,
-0.035660915076732635,
0.005209107417613268,
0.06086627393960953,
0.005867247469723225,
0.001836723880842328,
0.011725159361958504,
0.03780803829431534,
-0.054368890821933746,
-0.016140764579176903,
0.06288269907236099,
-0.0024925300385802984,
0.02742716483771801,
-0.03162805736064911,
-0.008770531043410301,
0.02768855355679989,
0.052800558507442474,
-0.028379367664456367,
0.06904400885105133,
-0.014591102488338947,
-0.007608284242451191
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.