Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of undirected graph in plot_msm_network #110

Open
jeiros opened this issue Sep 26, 2017 · 4 comments
Open

Use of undirected graph in plot_msm_network #110

jeiros opened this issue Sep 26, 2017 · 4 comments

Comments

@jeiros
Copy link
Contributor

jeiros commented Sep 26, 2017

Is there a reason why an undirected graph is built from the transition matrix in the plot_msm_network function?

I've checked and the edges that are built when using an undirected graph do not match the entries of the transition matrix:

import networkx as nx
import numpy as np
tmat = np.array(
    [
        [0.8, 0.1, 0.1],
        [0.3, 0.6, 0.1],
        [0.0, 0.3, 0.7]
    ]
)
graph_di = nx.DiGraph(tmat)
graph_un = nx.Graph(tmat)
tot_un = 0
for v in graph_un.edge[0].values():
    tot_un += v['weight']
tot_di = 0
for v in graph_di.edge[0].values():
    tot_di += v['weight']
assert tot_di == tmat[0, :].sum()
assert tot_un == tmat[0, :].sum()
Traceback (most recent call last):
  File "/Users/je714/test_issue_tmat.py", line 19, in <module>
    assert tot_un == tmat[0, :].sum()
AssertionError
print(graph_di.edge)
{0: {0: {'weight': 0.8}, 1: {'weight': 0.1}, 2: {'weight': 0.1}},
 1: {0: {'weight': 0.3}, 1: {'weight': 0.6}, 2: {'weight': 0.1}},
 2: {1: {'weight': 0.3}, 2: {'weight': 0.7}}}
print(graph_un.edge)
{0: {0: {'weight': 0.8}, 1: {'weight': 0.3}, 2: {'weight': 0.1}},
 1: {0: {'weight': 0.3}, 1: {'weight': 0.6}, 2: {'weight': 0.3}},
 2: {0: {'weight': 0.1}, 1: {'weight': 0.3}, 2: {'weight': 0.7}}}

Also, as a side question: is there a way to hide the edges below a particular weight? When there are too many connections, the resulting plot is really crowded and is a bit confusing to look at.

@msultan
Copy link
Collaborator

msultan commented Sep 26, 2017

@cxhernandez can speak to this more but my guess is that a directed graph would double the number of edges and would likely look very messy.

For your side question, I dont think we have anything for that yet but I agree it would be a good idea. As a fast hack, you can clip the input transition matrix to be 0 below a certain threshold. Or maybe even feed in the clipped version of log10(matrix).

@jeiros
Copy link
Contributor Author

jeiros commented Sep 26, 2017

Thanks for replying, I'll try the numpy clip!

As for the undirected/directed, I just noticed it because I didn't see any self-connections in the node, which in turn are usually the biggest weight nodes for each microstate (at least in my simulations, that's usually the case).

@cxhernandez
Copy link
Member

Yeah, it was to cut down on the complexity of the visualization because networkx makes ugly graphs. I'm very open to moving away from networkx plots and use something nicer.

@jeiros
Copy link
Contributor Author

jeiros commented Sep 27, 2017

That's good to know then, I was just wondering if it was a small bug. I don't really know nice network plotting libraries for python, for the moment what I'm doing is saving the directed graph to disk with networkx and then inspecting it using Gephi or Cytoscape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants