Skip to content

Use of undirected graph in plot_msm_network #110

@jeiros

Description

@jeiros

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions