SkBlaz / py3plex

Py3plex - A multilayer complex network visualization and analysis library in python3
BSD 3-Clause "New" or "Revised" License
158 stars 37 forks source link

Error loading multi-layer network #4

Closed rhhyon closed 5 years ago

rhhyon commented 5 years ago

Hi, I'm trying to load up a simple multi-layer network in order to visualize it. It's in the following format: n1 l1 n2 l2 w (node1, layer1, node2, layer2, weight)

I then use this code:

foo = multinet.multi_layer_network().load_network('multinet_k100.txt', directed = False, input_type = 'multiedgelist')
network_labels, graphs, multilinks = foo.get_layers()

I then get the following error:


Network splitting in progress

string index out of range sth string index out of range sth string index out of range sth string index out of range sth string index out of range sth string index out of range sth string index out of range sth string index out of range sth name 'ForceAtlas2' is not defined Using standard layout algorithm, fa2 not present on the system. name 'ForceAtlas2' is not defined

NameError Traceback (most recent call last) ~/venv/lib/python3.6/site-packages/py3plex/visualization/layout_algorithms.py in compute_force_directed_layout(g, layout_parameters, verbose, gravity, strongGravityMode, barnesHutTheta, edgeWeightInfluence, scalingRatio, forceImport) 17 try: ---> 18 forceatlas2 = ForceAtlas2( 19 # Behavior alternatives

NameError: name 'ForceAtlas2' is not defined

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) ~/venv/lib/python3.6/site-packages/networkx/drawing/layout.py in fruchterman_reingold_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed) 450 if len(G) < 500: # sparse solver for large graphs --> 451 raise ValueError 452 A = nx.to_scipy_sparse_matrix(G, weight=weight, dtype='f')

ValueError:

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)

in ----> 1 network_labels, graphs, multilinks = foo.get_layers() ~/venv/lib/python3.6/site-packages/py3plex/core/multinet.py in get_layers(self, style, compute_layouts, layout_parameters, verbose) 394 ## multilayer visualization 395 if style == "diagonal": --> 396 return converters.prepare_for_visualization(self.core_network,compute_layouts=compute_layouts,layout_parameters=layout_parameters,verbose=verbose) 397 398 ## hairball visualization ~/venv/lib/python3.6/site-packages/py3plex/core/converters.py in prepare_for_visualization(multinet, compute_layouts, layout_parameters, verbose, multiplex) 51 52 if compute_layouts == "force": ---> 53 tmp_pos = compute_force_directed_layout(network,layout_parameters,verbose=verbose) 54 55 elif compute_layouts == "random": ~/venv/lib/python3.6/site-packages/py3plex/visualization/layout_algorithms.py in compute_force_directed_layout(g, layout_parameters, verbose, gravity, strongGravityMode, barnesHutTheta, edgeWeightInfluence, scalingRatio, forceImport) 53 pos = nx.spring_layout(g,**layout_parameters) 54 else: ---> 55 pos = nx.spring_layout(g) 56 print("Using standard layout algorithm, fa2 not present on the system.") 57 in fruchterman_reingold_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed) ~/venv/lib/python3.6/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs) 403 new_args = list(args) 404 new_args[random_state_index] = random_state --> 405 return func(*new_args, **kwargs) 406 return _random_state 407 ~/venv/lib/python3.6/site-packages/networkx/drawing/layout.py in fruchterman_reingold_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed) 459 dim, seed) 460 except: --> 461 A = nx.to_numpy_array(G, weight=weight) 462 if k is None and fixed is not None: 463 # We must adjust k by domain size for layouts not near 1x1 ~/venv/lib/python3.6/site-packages/networkx/convert_matrix.py in to_numpy_array(G, nodelist, dtype, order, multigraph_weight, weight, nonedge) 1120 i, j = index[u], index[v] 1121 e_weight = attrs.get(weight, 1) -> 1122 A[i, j] = op([e_weight, A[i, j]]) 1123 if undirected: 1124 A[j, i] = A[i, j] ~/venv/lib/python3.6/site-packages/numpy/lib/nanfunctions.py in nansum(a, axis, dtype, out, keepdims) 612 """ 613 a, mask = _replace_nan(a, 0) --> 614 return np.sum(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims) 615 616 ~/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py in sum(a, axis, dtype, out, keepdims, initial) 2074 2075 return _wrapreduction(a, np.add, 'sum', axis, dtype, out, keepdims=keepdims, -> 2076 initial=initial) 2077 2078 ~/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs) 84 return reduction(axis=axis, out=out, **passkwargs) 85 ---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs) 87 88 TypeError: cannot perform reduce with flexible type

I've attached the text file containing the multi-layer network information. multinet_k100.txt

Not sure what's going wrong (I'm trying my best to follow the documentation). Would appreciate any tips. Thank you! Please let me know if you need anything else to diagnose the problem.

SkBlaz commented 5 years ago

Hello rhhyon, thanks for reporting this. I was able to produce a plot from your file without any problems, yet I think you pointed out an interesting issue (pr example oof as appendix)

Could you please try to install https://github.com/bhargavchippada/forceatlas2 manually? It is possible this is the problem. Thanks!

P.S.

your example is now accessible at: https://github.com/SkBlaz/Py3plex/blob/master/examples/example_multilayer_visualization.py for reproducibility purposes (first plot)

rhhyon commented 5 years ago

That worked! Will have to work on making the visualization prettier, but thanks so much for the quick help. Really great package! I'm using it to visualize brain networks FYI.

Will let you know if I run into any other issues.

SkBlaz commented 5 years ago

Awesome, thanks!

Yes, there is a ton of possibilities to tweak the visualization! Nice to hear it works now. (there are many examples in examples folder, feel free to ask for help though!)

On Fri, Mar 8, 2019 at 8:24 PM rhhyon notifications@github.com wrote:

That worked! Will have to work on making the visualization prettier, but thank so much for the quick help. Really great package! I'm using it to visualize brain networks FYI.

Will let you know if I run into any other issues.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SkBlaz/Py3plex/issues/4#issuecomment-471046085, or mute the thread https://github.com/notifications/unsubscribe-auth/AJkiRHkxwDI6SVmhaIeIMBppS4UaM7W0ks5vUrjmgaJpZM4bkveG .