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

Fix incorrect edges in adjacency_matrix_to_graph #1202

Merged
merged 2 commits into from
Aug 4, 2024

Conversation

rahulbshrestha
Copy link
Contributor

This PR fixes the issue of incorrect edges in adjacency_matrix_to_graph when the adjacency matrix is of type np.matrix by converting the matrix into a numpy array.

Related issue: #887

Signed-off-by: rahulbshrestha <rahulshrestha0101@gmail.com>
@rahulbshrestha
Copy link
Contributor Author

(Copying from another comment) I was a bit confused about the direction of the edges. If the adjacency matrix is

np.matrix(
    [[0, 0, 1, 0, 0],
     [0, 0, 1, 0, 0],
     [0, 0, 0, 1, 1],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0]]
)

the graph is currently,
image

isn't it supposed to be:
image
because the typical interpretation of adjacency matrices is rows represent source nodes and columns represent destination nodes. Is this a bug or a conscious decision?

This comes from the for-loop,

    for to, from_, coef in zip(dirs[0], dirs[1], adjacency_matrix[idx]):
        d.edge(names[from_], names[to], label=str(coef))

Signed-off-by: rahulbshrestha <rahulshrestha0101@gmail.com>
@rahulbshrestha
Copy link
Contributor Author

@amit-sharma If the design choice for the direction of the edges (adjacency matrix -> graph) is intentional and supposed to be the way it is, then the PR is ready to be merged!

Copy link
Member

@amit-sharma amit-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @rahulbshrestha . We can take up the direction of adjacency matrix in a separate thread. Merging as is.

@amit-sharma amit-sharma merged commit 4c3a083 into py-why:main Aug 4, 2024
30 checks passed
@rahulbshrestha rahulbshrestha deleted the matrix_bug branch August 5, 2024 13:08
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

Successfully merging this pull request may close these issues.

adjacency_matrix_to_graph fails to add all edges when adjacency_matrix is of type np.matrix
3 participants